@libp2p/webrtc 5.2.14 → 5.2.15-3528df829
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 +1 -1
- package/dist/index.min.js.map +3 -3
- package/package.json +12 -12
- package/dist/typedoc-urls.json +0 -14
package/dist/index.min.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PWebrtc = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
2
|
-
"use strict";var Libp2PWebrtc=(()=>{var mA=Object.create;var Au=Object.defineProperty;var yA=Object.getOwnPropertyDescriptor;var gA=Object.getOwnPropertyNames;var wA=Object.getPrototypeOf,xA=Object.prototype.hasOwnProperty;var Sp=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),bt=(r,e)=>{for(var t in e)Au(r,t,{get:e[t],enumerable:!0})},Zy=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of gA(e))!xA.call(r,o)&&o!==t&&Au(r,o,{get:()=>e[o],enumerable:!(n=yA(e,o))||n.enumerable});return r};var Lr=(r,e,t)=>(t=r!=null?mA(wA(r)):{},Zy(e||!r||!r.__esModule?Au(t,"default",{value:r,enumerable:!0}):t,r)),bA=r=>Zy(Au({},"__esModule",{value:!0}),r);var rx=Sp(()=>{var tx;(function(r){(function(e){var t=typeof globalThis=="object"||typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof this=="object"?this:a(),n=o(r);typeof t.Reflect<"u"&&(n=o(t.Reflect,n)),e(n,t),typeof t.Reflect>"u"&&(t.Reflect=r);function o(c,f){return function(h,p){Object.defineProperty(c,h,{configurable:!0,writable:!0,value:p}),f&&f(h,p)}}function i(){try{return Function("return this;")()}catch{}}function s(){try{return(0,eval)("(function() { return this; })()")}catch{}}function a(){return i()||s()}})(function(e,t){var n=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",i=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",s=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",a=typeof Object.create=="function",c={__proto__:[]}instanceof Array,f=!a&&!c,h={create:a?function(){return Ap(Object.create(null))}:c?function(){return Ap({__proto__:null})}:function(){return Ap({})},has:f?function(x,E){return n.call(x,E)}:function(x,E){return E in x},get:f?function(x,E){return n.call(x,E)?x[E]:void 0}:function(x,E){return x[E]}},p=Object.getPrototypeOf(Function),m=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:lA(),v=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:fA(),g=typeof WeakMap=="function"?WeakMap:pA(),w=o?Symbol.for("@reflect-metadata:registry"):void 0,S=aA(),O=cA(S);function Y(x,E,B,W){if(I(B)){if(!ut(x))throw new TypeError;if(!et(E))throw new TypeError;return G(x,E)}else{if(!ut(x))throw new TypeError;if(!Q(E))throw new TypeError;if(!Q(W)&&!I(W)&&!re(W))throw new TypeError;return re(W)&&(W=void 0),B=ke(B),F(x,E,B,W)}}e("decorate",Y);function T(x,E){function B(W,ae){if(!Q(W))throw new TypeError;if(!I(ae)&&!Tt(ae))throw new TypeError;P(x,E,W,ae)}return B}e("metadata",T);function b(x,E,B,W){if(!Q(B))throw new TypeError;return I(W)||(W=ke(W)),P(x,E,B,W)}e("defineMetadata",b);function D(x,E,B){if(!Q(E))throw new TypeError;return I(B)||(B=ke(B)),ie(x,E,B)}e("hasMetadata",D);function V(x,E,B){if(!Q(E))throw new TypeError;return I(B)||(B=ke(B)),k(x,E,B)}e("hasOwnMetadata",V);function N(x,E,B){if(!Q(E))throw new TypeError;return I(B)||(B=ke(B)),R(x,E,B)}e("getMetadata",N);function U(x,E,B){if(!Q(E))throw new TypeError;return I(B)||(B=ke(B)),K(x,E,B)}e("getOwnMetadata",U);function $(x,E){if(!Q(x))throw new TypeError;return I(E)||(E=ke(E)),y(x,E)}e("getMetadataKeys",$);function X(x,E){if(!Q(x))throw new TypeError;return I(E)||(E=ke(E)),C(x,E)}e("getOwnMetadataKeys",X);function M(x,E,B){if(!Q(E))throw new TypeError;if(I(B)||(B=ke(B)),!Q(E))throw new TypeError;I(B)||(B=ke(B));var W=aa(E,B,!1);return I(W)?!1:W.OrdinaryDeleteMetadata(x,E,B)}e("deleteMetadata",M);function G(x,E){for(var B=x.length-1;B>=0;--B){var W=x[B],ae=W(E);if(!I(ae)&&!re(ae)){if(!et(ae))throw new TypeError;E=ae}}return E}function F(x,E,B,W){for(var ae=x.length-1;ae>=0;--ae){var Ge=x[ae],tt=Ge(E,B,W);if(!I(tt)&&!re(tt)){if(!Q(tt))throw new TypeError;W=tt}}return W}function ie(x,E,B){var W=k(x,E,B);if(W)return!0;var ae=sa(E);return re(ae)?!1:ie(x,ae,B)}function k(x,E,B){var W=aa(E,B,!1);return I(W)?!1:Ee(W.OrdinaryHasOwnMetadata(x,E,B))}function R(x,E,B){var W=k(x,E,B);if(W)return K(x,E,B);var ae=sa(E);if(!re(ae))return R(x,ae,B)}function K(x,E,B){var W=aa(E,B,!1);if(!I(W))return W.OrdinaryGetOwnMetadata(x,E,B)}function P(x,E,B,W){var ae=aa(B,W,!0);ae.OrdinaryDefineOwnMetadata(x,E,B,W)}function y(x,E){var B=C(x,E),W=sa(x);if(W===null)return B;var ae=y(W,E);if(ae.length<=0)return B;if(B.length<=0)return ae;for(var Ge=new v,tt=[],we=0,z=B;we<z.length;we++){var J=z[we],te=Ge.has(J);te||(Ge.add(J),tt.push(J))}for(var ne=0,xe=ae;ne<xe.length;ne++){var J=xe[ne],te=Ge.has(J);te||(Ge.add(J),tt.push(J))}return tt}function C(x,E){var B=aa(x,E,!1);return B?B.OrdinaryOwnMetadataKeys(x,E):[]}function L(x){if(x===null)return 1;switch(typeof x){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return x===null?1:6;default:return 6}}function I(x){return x===void 0}function re(x){return x===null}function le(x){return typeof x=="symbol"}function Q(x){return typeof x=="object"?x!==null:typeof x=="function"}function pe(x,E){switch(L(x)){case 0:return x;case 1:return x;case 2:return x;case 3:return x;case 4:return x;case 5:return x}var B=E===3?"string":E===5?"number":"default",W=Un(x,i);if(W!==void 0){var ae=W.call(x,B);if(Q(ae))throw new TypeError;return ae}return he(x,B==="default"?"number":B)}function he(x,E){if(E==="string"){var B=x.toString;if(Ue(B)){var W=B.call(x);if(!Q(W))return W}var ae=x.valueOf;if(Ue(ae)){var W=ae.call(x);if(!Q(W))return W}}else{var ae=x.valueOf;if(Ue(ae)){var W=ae.call(x);if(!Q(W))return W}var Ge=x.toString;if(Ue(Ge)){var W=Ge.call(x);if(!Q(W))return W}}throw new TypeError}function Ee(x){return!!x}function _e(x){return""+x}function ke(x){var E=pe(x,3);return le(E)?E:_e(E)}function ut(x){return Array.isArray?Array.isArray(x):x instanceof Object?x instanceof Array:Object.prototype.toString.call(x)==="[object Array]"}function Ue(x){return typeof x=="function"}function et(x){return typeof x=="function"}function Tt(x){switch(L(x)){case 3:return!0;case 4:return!0;default:return!1}}function Bt(x,E){return x===E||x!==x&&E!==E}function Un(x,E){var B=x[E];if(B!=null){if(!Ue(B))throw new TypeError;return B}}function ia(x){var E=Un(x,s);if(!Ue(E))throw new TypeError;var B=E.call(x);if(!Q(B))throw new TypeError;return B}function xu(x){return x.value}function bu(x){var E=x.next();return E.done?!1:E}function vu(x){var E=x.return;E&&E.call(x)}function sa(x){var E=Object.getPrototypeOf(x);if(typeof x!="function"||x===p||E!==p)return E;var B=x.prototype,W=B&&Object.getPrototypeOf(B);if(W==null||W===Object.prototype)return E;var ae=W.constructor;return typeof ae!="function"||ae===x?E:ae}function sA(){var x;!I(w)&&typeof t.Reflect<"u"&&!(w in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(x=uA(t.Reflect));var E,B,W,ae=new g,Ge={registerProvider:tt,getProvider:z,setProvider:te};return Ge;function tt(ne){if(!Object.isExtensible(Ge))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case x===ne:break;case I(E):E=ne;break;case E===ne:break;case I(B):B=ne;break;case B===ne:break;default:W===void 0&&(W=new v),W.add(ne);break}}function we(ne,xe){if(!I(E)){if(E.isProviderFor(ne,xe))return E;if(!I(B)){if(B.isProviderFor(ne,xe))return E;if(!I(W))for(var je=ia(W);;){var ze=bu(je);if(!ze)return;var mr=xu(ze);if(mr.isProviderFor(ne,xe))return vu(je),mr}}}if(!I(x)&&x.isProviderFor(ne,xe))return x}function z(ne,xe){var je=ae.get(ne),ze;return I(je)||(ze=je.get(xe)),I(ze)&&(ze=we(ne,xe),I(ze)||(I(je)&&(je=new m,ae.set(ne,je)),je.set(xe,ze))),ze}function J(ne){if(I(ne))throw new TypeError;return E===ne||B===ne||!I(W)&&W.has(ne)}function te(ne,xe,je){if(!J(je))throw new Error("Metadata provider not registered.");var ze=z(ne,xe);if(ze!==je){if(!I(ze))return!1;var mr=ae.get(ne);I(mr)&&(mr=new m,ae.set(ne,mr)),mr.set(xe,je)}return!0}}function aA(){var x;return!I(w)&&Q(t.Reflect)&&Object.isExtensible(t.Reflect)&&(x=t.Reflect[w]),I(x)&&(x=sA()),!I(w)&&Q(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,w,{enumerable:!1,configurable:!1,writable:!1,value:x}),x}function cA(x){var E=new g,B={isProviderFor:function(J,te){var ne=E.get(J);return I(ne)?!1:ne.has(te)},OrdinaryDefineOwnMetadata:tt,OrdinaryHasOwnMetadata:ae,OrdinaryGetOwnMetadata:Ge,OrdinaryOwnMetadataKeys:we,OrdinaryDeleteMetadata:z};return S.registerProvider(B),B;function W(J,te,ne){var xe=E.get(J),je=!1;if(I(xe)){if(!ne)return;xe=new m,E.set(J,xe),je=!0}var ze=xe.get(te);if(I(ze)){if(!ne)return;if(ze=new m,xe.set(te,ze),!x.setProvider(J,te,B))throw xe.delete(te),je&&E.delete(J),new Error("Wrong provider for target.")}return ze}function ae(J,te,ne){var xe=W(te,ne,!1);return I(xe)?!1:Ee(xe.has(J))}function Ge(J,te,ne){var xe=W(te,ne,!1);if(!I(xe))return xe.get(J)}function tt(J,te,ne,xe){var je=W(ne,xe,!0);je.set(J,te)}function we(J,te){var ne=[],xe=W(J,te,!1);if(I(xe))return ne;for(var je=xe.keys(),ze=ia(je),mr=0;;){var Yy=bu(ze);if(!Yy)return ne.length=mr,ne;var hA=xu(Yy);try{ne[mr]=hA}catch(dA){try{vu(ze)}finally{throw dA}}mr++}}function z(J,te,ne){var xe=W(te,ne,!1);if(I(xe)||!xe.delete(J))return!1;if(xe.size===0){var je=E.get(te);I(je)||(je.delete(ne),je.size===0&&E.delete(je))}return!0}}function uA(x){var E=x.defineMetadata,B=x.hasOwnMetadata,W=x.getOwnMetadata,ae=x.getOwnMetadataKeys,Ge=x.deleteMetadata,tt=new g,we={isProviderFor:function(z,J){var te=tt.get(z);return!I(te)&&te.has(J)?!0:ae(z,J).length?(I(te)&&(te=new v,tt.set(z,te)),te.add(J),!0):!1},OrdinaryDefineOwnMetadata:E,OrdinaryHasOwnMetadata:B,OrdinaryGetOwnMetadata:W,OrdinaryOwnMetadataKeys:ae,OrdinaryDeleteMetadata:Ge};return we}function aa(x,E,B){var W=S.getProvider(x,E);if(!I(W))return W;if(B){if(S.setProvider(x,E,O))return O;throw new Error("Illegal state.")}}function lA(){var x={},E=[],B=function(){function we(z,J,te){this._index=0,this._keys=z,this._values=J,this._selector=te}return we.prototype["@@iterator"]=function(){return this},we.prototype[s]=function(){return this},we.prototype.next=function(){var z=this._index;if(z>=0&&z<this._keys.length){var J=this._selector(this._keys[z],this._values[z]);return z+1>=this._keys.length?(this._index=-1,this._keys=E,this._values=E):this._index++,{value:J,done:!1}}return{value:void 0,done:!0}},we.prototype.throw=function(z){throw this._index>=0&&(this._index=-1,this._keys=E,this._values=E),z},we.prototype.return=function(z){return this._index>=0&&(this._index=-1,this._keys=E,this._values=E),{value:z,done:!0}},we}(),W=function(){function we(){this._keys=[],this._values=[],this._cacheKey=x,this._cacheIndex=-2}return Object.defineProperty(we.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),we.prototype.has=function(z){return this._find(z,!1)>=0},we.prototype.get=function(z){var J=this._find(z,!1);return J>=0?this._values[J]:void 0},we.prototype.set=function(z,J){var te=this._find(z,!0);return this._values[te]=J,this},we.prototype.delete=function(z){var J=this._find(z,!1);if(J>=0){for(var te=this._keys.length,ne=J+1;ne<te;ne++)this._keys[ne-1]=this._keys[ne],this._values[ne-1]=this._values[ne];return this._keys.length--,this._values.length--,Bt(z,this._cacheKey)&&(this._cacheKey=x,this._cacheIndex=-2),!0}return!1},we.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=x,this._cacheIndex=-2},we.prototype.keys=function(){return new B(this._keys,this._values,ae)},we.prototype.values=function(){return new B(this._keys,this._values,Ge)},we.prototype.entries=function(){return new B(this._keys,this._values,tt)},we.prototype["@@iterator"]=function(){return this.entries()},we.prototype[s]=function(){return this.entries()},we.prototype._find=function(z,J){if(!Bt(this._cacheKey,z)){this._cacheIndex=-1;for(var te=0;te<this._keys.length;te++)if(Bt(this._keys[te],z)){this._cacheIndex=te;break}}return this._cacheIndex<0&&J&&(this._cacheIndex=this._keys.length,this._keys.push(z),this._values.push(void 0)),this._cacheIndex},we}();return W;function ae(we,z){return we}function Ge(we,z){return z}function tt(we,z){return[we,z]}}function fA(){var x=function(){function E(){this._map=new m}return Object.defineProperty(E.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),E.prototype.has=function(B){return this._map.has(B)},E.prototype.add=function(B){return this._map.set(B,B),this},E.prototype.delete=function(B){return this._map.delete(B)},E.prototype.clear=function(){this._map.clear()},E.prototype.keys=function(){return this._map.keys()},E.prototype.values=function(){return this._map.keys()},E.prototype.entries=function(){return this._map.entries()},E.prototype["@@iterator"]=function(){return this.keys()},E.prototype[s]=function(){return this.keys()},E}();return x}function pA(){var x=16,E=h.create(),B=W();return function(){function z(){this._key=W()}return z.prototype.has=function(J){var te=ae(J,!1);return te!==void 0?h.has(te,this._key):!1},z.prototype.get=function(J){var te=ae(J,!1);return te!==void 0?h.get(te,this._key):void 0},z.prototype.set=function(J,te){var ne=ae(J,!0);return ne[this._key]=te,this},z.prototype.delete=function(J){var te=ae(J,!1);return te!==void 0?delete te[this._key]:!1},z.prototype.clear=function(){this._key=W()},z}();function W(){var z;do z="@@WeakMap@@"+we();while(h.has(E,z));return E[z]=!0,z}function ae(z,J){if(!n.call(z,B)){if(!J)return;Object.defineProperty(z,B,{value:h.create()})}return z[B]}function Ge(z,J){for(var te=0;te<J;++te)z[te]=Math.random()*255|0;return z}function tt(z){if(typeof Uint8Array=="function"){var J=new Uint8Array(z);return typeof crypto<"u"?crypto.getRandomValues(J):typeof msCrypto<"u"?msCrypto.getRandomValues(J):Ge(J,z),J}return Ge(new Array(z),z)}function we(){var z=tt(x);z[6]=z[6]&79|64,z[8]=z[8]&191|128;for(var J="",te=0;te<x;++te){var ne=z[te];(te===4||te===6||te===8)&&(J+="-"),ne<16&&(J+="0"),J+=ne.toString(16).toLowerCase()}return J}}function Ap(x){return x.__=void 0,delete x.__,x}})})(tx||(tx={}))});var gn=Sp(ms=>{"use strict";var F2="[object ArrayBuffer]",yn=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===F2}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),o=r.toUint8Array(t);if(n.length!==o.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==o[i])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let s of t)n+=s.byteLength;let o=new Uint8Array(n),i=0;for(let s of t){let a=this.toUint8Array(s);o.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(o,e[e.length-1]):o.buffer}},Rd="string",W2=/^[0-9a-f\s]+$/i,q2=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,G2=/^[a-zA-Z0-9-_]+$/,Vl=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n.buffer}static toString(e){let t=yn.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},or=class{static toString(e,t=!1){let n=yn.toArrayBuffer(e),o=new DataView(n),i="";for(let s=0;s<n.byteLength;s+=2){let a=o.getUint16(s,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),o=new DataView(n);for(let i=0;i<e.length;i++)o.setUint16(i*2,e.charCodeAt(i),t);return n}},$l=class r{static isHex(e){return typeof e===Rd&&W2.test(e)}static isBase64(e){return typeof e===Rd&&q2.test(e)}static isBase64Url(e){return typeof e===Rd&&G2.test(e)}static ToString(e,t="utf8"){let n=yn.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return or.toString(n,!0);case"utf16":case"utf16be":return or.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return or.fromString(e,!0);case"utf16":case"utf16be":return or.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=yn.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return Vl.fromString(e);case"utf16":case"utf16be":return or.fromString(e);case"utf16le":case"usc2":return or.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return Vl.toString(e);case"utf16":case"utf16be":return or.toString(e);case"utf16le":case"usc2":return or.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return n.buffer}static ToBinary(e){let t=yn.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=yn.toUint8Array(e),n="",o=t.length;for(let i=0;i<o;i++){let s=t[i];s<16&&(n+="0"),n+=s.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let o=0;o<t.length;o=o+2){let i=t.slice(o,o+2);n[o/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return or.toString(e,t)}static FromUtf16String(e,t=!1){return or.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};$l.DEFAULT_UTF8_ENCODING="utf8";function z2(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let o=arguments[n];for(let i in o)t[i]=o[i]}return t}function X2(...r){let e=r.map(o=>o.byteLength).reduce((o,i)=>o+i),t=new Uint8Array(e),n=0;return r.map(o=>new Uint8Array(o)).forEach(o=>{for(let i of o)t[n++]=i}),t.buffer}function Y2(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==n[o])return!1;return!0}ms.BufferSourceConverter=yn;ms.Convert=$l;ms.assign=z2;ms.combine=X2;ms.isEqual=Y2});var Yb=Sp((H7,jf)=>{var kb,Pb,Nb,Ob,Rb,Db,Lb,Ub,jb,Uf,Hm,Mb,Kb,Ws,Hb,Vb,$b,Fb,Wb,qb,Gb,zb,Xb;(function(r){var e=typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof this=="object"?this:{};typeof define=="function"&&define.amd?define("tslib",["exports"],function(n){r(t(e,t(n)))}):typeof jf=="object"&&typeof jf.exports=="object"?r(t(e,t(jf.exports))):r(t(e));function t(n,o){return n!==e&&(typeof Object.create=="function"?Object.defineProperty(n,"__esModule",{value:!0}):n.__esModule=!0),function(i,s){return n[i]=o?o(i,s):s}}})(function(r){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var o in n)n.hasOwnProperty(o)&&(t[o]=n[o])};kb=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},Pb=Object.assign||function(t){for(var n,o=1,i=arguments.length;o<i;o++){n=arguments[o];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},Nb=function(t,n){var o={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&n.indexOf(i)<0&&(o[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,i=Object.getOwnPropertySymbols(t);s<i.length;s++)n.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(t,i[s])&&(o[i[s]]=t[i[s]]);return o},Ob=function(t,n,o,i){var s=arguments.length,a=s<3?n:i===null?i=Object.getOwnPropertyDescriptor(n,o):i,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,n,o,i);else for(var f=t.length-1;f>=0;f--)(c=t[f])&&(a=(s<3?c(a):s>3?c(n,o,a):c(n,o))||a);return s>3&&a&&Object.defineProperty(n,o,a),a},Rb=function(t,n){return function(o,i){n(o,i,t)}},Db=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},Lb=function(t,n,o,i){function s(a){return a instanceof o?a:new o(function(c){c(a)})}return new(o||(o=Promise))(function(a,c){function f(m){try{p(i.next(m))}catch(v){c(v)}}function h(m){try{p(i.throw(m))}catch(v){c(v)}}function p(m){m.done?a(m.value):s(m.value).then(f,h)}p((i=i.apply(t,n||[])).next())})},Ub=function(t,n){var o={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,s,a,c;return c={next:f(0),throw:f(1),return:f(2)},typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function f(p){return function(m){return h([p,m])}}function h(p){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,s&&(a=p[0]&2?s.return:p[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,p[1])).done)return a;switch(s=0,a&&(p=[p[0]&2,a.value]),p[0]){case 0:case 1:a=p;break;case 4:return o.label++,{value:p[1],done:!1};case 5:o.label++,s=p[1],p=[0];continue;case 7:p=o.ops.pop(),o.trys.pop();continue;default:if(a=o.trys,!(a=a.length>0&&a[a.length-1])&&(p[0]===6||p[0]===2)){o=0;continue}if(p[0]===3&&(!a||p[1]>a[0]&&p[1]<a[3])){o.label=p[1];break}if(p[0]===6&&o.label<a[1]){o.label=a[1],a=p;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(p);break}a[2]&&o.ops.pop(),o.trys.pop();continue}p=n.call(t,o)}catch(m){p=[6,m],s=0}finally{i=a=0}if(p[0]&5)throw p[1];return{value:p[0]?p[1]:void 0,done:!0}}},Xb=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},jb=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},Uf=function(t){var n=typeof Symbol=="function"&&Symbol.iterator,o=n&&t[n],i=0;if(o)return o.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},Hm=function(t,n){var o=typeof Symbol=="function"&&t[Symbol.iterator];if(!o)return t;var i=o.call(t),s,a=[],c;try{for(;(n===void 0||n-- >0)&&!(s=i.next()).done;)a.push(s.value)}catch(f){c={error:f}}finally{try{s&&!s.done&&(o=i.return)&&o.call(i)}finally{if(c)throw c.error}}return a},Mb=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(Hm(arguments[n]));return t},Kb=function(){for(var t=0,n=0,o=arguments.length;n<o;n++)t+=arguments[n].length;for(var i=Array(t),s=0,n=0;n<o;n++)for(var a=arguments[n],c=0,f=a.length;c<f;c++,s++)i[s]=a[c];return i},Ws=function(t){return this instanceof Ws?(this.v=t,this):new Ws(t)},Hb=function(t,n,o){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i=o.apply(t,n||[]),s,a=[];return s={},c("next"),c("throw"),c("return"),s[Symbol.asyncIterator]=function(){return this},s;function c(g){i[g]&&(s[g]=function(w){return new Promise(function(S,O){a.push([g,w,S,O])>1||f(g,w)})})}function f(g,w){try{h(i[g](w))}catch(S){v(a[0][3],S)}}function h(g){g.value instanceof Ws?Promise.resolve(g.value.v).then(p,m):v(a[0][2],g)}function p(g){f("next",g)}function m(g){f("throw",g)}function v(g,w){g(w),a.shift(),a.length&&f(a[0][0],a[0][1])}},Vb=function(t){var n,o;return n={},i("next"),i("throw",function(s){throw s}),i("return"),n[Symbol.iterator]=function(){return this},n;function i(s,a){n[s]=t[s]?function(c){return(o=!o)?{value:Ws(t[s](c)),done:s==="return"}:a?a(c):c}:a}},$b=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t[Symbol.asyncIterator],o;return n?n.call(t):(t=typeof Uf=="function"?Uf(t):t[Symbol.iterator](),o={},i("next"),i("throw"),i("return"),o[Symbol.asyncIterator]=function(){return this},o);function i(a){o[a]=t[a]&&function(c){return new Promise(function(f,h){c=t[a](c),s(f,h,c.done,c.value)})}}function s(a,c,f,h){Promise.resolve(h).then(function(p){a({value:p,done:f})},c)}},Fb=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},Wb=function(t){if(t&&t.__esModule)return t;var n={};if(t!=null)for(var o in t)Object.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n.default=t,n},qb=function(t){return t&&t.__esModule?t:{default:t}},Gb=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},zb=function(t,n,o){if(!n.has(t))throw new TypeError("attempted to set private field on non-instance");return n.set(t,o),o},r("__extends",kb),r("__assign",Pb),r("__rest",Nb),r("__decorate",Ob),r("__param",Rb),r("__metadata",Db),r("__awaiter",Lb),r("__generator",Ub),r("__exportStar",jb),r("__createBinding",Xb),r("__values",Uf),r("__read",Hm),r("__spread",Mb),r("__spreadArrays",Kb),r("__await",Ws),r("__asyncGenerator",Hb),r("__asyncDelegator",Vb),r("__asyncValues",$b),r("__makeTemplateObject",Fb),r("__importStar",Wb),r("__importDefault",qb),r("__classPrivateFieldGet",Gb),r("__classPrivateFieldSet",zb)})});var QC={};bt(QC,{webRTC:()=>JC,webRTCDirect:()=>ZC});var Ep=Symbol.for("@libp2p/peer-id");var Su=Symbol.for("@libp2p/transport");var Jy;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Jy||(Jy={}));var Eu=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},_u=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},Ae=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Fi=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},ca=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var Cu=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var Iu=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}},Io=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},To=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Tu=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Bu=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var ku=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Pu=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},Nu=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var jn=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Mn=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Wi=Symbol.for("@libp2p/service-capabilities"),Qy=Symbol.for("@libp2p/service-dependencies");var Bp={};bt(Bp,{base58btc:()=>Pe,base58flickr:()=>IA});var II=new Uint8Array(0);function eg(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function sn(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function tg(r){return new TextEncoder().encode(r)}function rg(r){return new TextDecoder().decode(r)}function vA(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function p(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var w=0,S=0,O=0,Y=g.length;O!==Y&&g[O]===0;)O++,w++;for(var T=(Y-O)*h+1>>>0,b=new Uint8Array(T);O!==Y;){for(var D=g[O],V=0,N=T-1;(D!==0||V<S)&&N!==-1;N--,V++)D+=256*b[N]>>>0,b[N]=D%a>>>0,D=D/a>>>0;if(D!==0)throw new Error("Non-zero carry");S=V,O++}for(var U=T-S;U!==T&&b[U]===0;)U++;for(var $=c.repeat(w);U<T;++U)$+=r.charAt(b[U]);return $}function m(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var w=0;if(g[w]!==" "){for(var S=0,O=0;g[w]===c;)S++,w++;for(var Y=(g.length-w)*f+1>>>0,T=new Uint8Array(Y);g[w];){var b=t[g.charCodeAt(w)];if(b===255)return;for(var D=0,V=Y-1;(b!==0||D<O)&&V!==-1;V--,D++)b+=a*T[V]>>>0,T[V]=b%256>>>0,b=b/256>>>0;if(b!==0)throw new Error("Non-zero carry");O=D,w++}if(g[w]!==" "){for(var N=Y-O;N!==Y&&T[N]===0;)N++;for(var U=new Uint8Array(S+(Y-N)),$=S;N!==Y;)U[$++]=T[N++];return U}}}function v(g){var w=m(g);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:p,decodeUnsafe:m,decode:v}}var AA=vA,SA=AA,og=SA;var _p=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Cp=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return ig(this,e)}},Ip=class{decoders;constructor(e){this.decoders=e}or(e){return ig(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ig(r,e){return new Ip({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Tp=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new _p(e,t,n),this.decoder=new Cp(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function qi({name:r,prefix:e,encode:t,decode:n}){return new Tp(r,e,t,n)}function Kn({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=og(t,r);return qi({prefix:e,name:r,encode:n,decode:i=>sn(o(i))})}function EA(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),s=0,a=0,c=0;for(let f=0;f<o;++f){let h=e[r[f]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|h,s+=t,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=t||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function _A(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function CA(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function $e({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=CA(n);return qi({prefix:e,name:r,encode(i){return _A(i,n,t)},decode(i){return EA(i,o,t,r)}})}var Pe=Kn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),IA=Kn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var kp={};bt(kp,{base32:()=>an,base32hex:()=>PA,base32hexpad:()=>OA,base32hexpadupper:()=>RA,base32hexupper:()=>NA,base32pad:()=>BA,base32padupper:()=>kA,base32upper:()=>TA,base32z:()=>DA});var an=$e({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),TA=$e({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),BA=$e({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),kA=$e({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),PA=$e({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),NA=$e({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),OA=$e({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),RA=$e({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),DA=$e({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Pp={};bt(Pp,{base36:()=>ua,base36upper:()=>LA});var ua=Kn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),LA=Kn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var er={};bt(er,{Digest:()=>Bo,create:()=>vt,decode:()=>Hn,equals:()=>Op,hasCode:()=>tS});var UA=cg,sg=128,jA=127,MA=~jA,KA=Math.pow(2,31);function cg(r,e,t){e=e||[],t=t||0;for(var n=t;r>=KA;)e[t++]=r&255|sg,r/=128;for(;r&MA;)e[t++]=r&255|sg,r>>>=7;return e[t]=r|0,cg.bytes=t-n+1,e}var HA=Np,VA=128,ag=127;function Np(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Np.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&ag)<<o:(s&ag)*Math.pow(2,o),o+=7}while(s>=VA);return Np.bytes=i-n,t}var $A=Math.pow(2,7),FA=Math.pow(2,14),WA=Math.pow(2,21),qA=Math.pow(2,28),GA=Math.pow(2,35),zA=Math.pow(2,42),XA=Math.pow(2,49),YA=Math.pow(2,56),ZA=Math.pow(2,63),JA=function(r){return r<$A?1:r<FA?2:r<WA?3:r<qA?4:r<GA?5:r<zA?6:r<XA?7:r<YA?8:r<ZA?9:10},QA={encode:UA,decode:HA,encodingLength:JA},eS=QA,la=eS;function fa(r,e=0){return[la.decode(r,e),la.decode.bytes]}function Gi(r,e,t=0){return la.encode(r,e,t),e}function zi(r){return la.encodingLength(r)}function vt(r,e){let t=e.byteLength,n=zi(r),o=n+zi(t),i=new Uint8Array(o+t);return Gi(r,i,0),Gi(t,i,n),i.set(e,o),new Bo(r,t,e,i)}function Hn(r){let e=sn(r),[t,n]=fa(e),[o,i]=fa(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Bo(t,o,s,e)}function Op(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&eg(r.bytes,t.bytes)}}var Bo=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function tS(r,e){return r.code===e}function ug(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return nS(t,Rp(r),e??Pe.encoder);default:return oS(t,Rp(r),e??an.encoder)}}var lg=new WeakMap;function Rp(r){let e=lg.get(r);if(e==null){let t=new Map;return lg.set(r,t),t}return e}var Xe=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==pa)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==iS)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=vt(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Op(e.multihash,n.multihash)}toString(e){return ug(this,e)}toJSON(){return{"/":ug(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??fg(n,o,i.bytes))}else if(t[sS]===!0){let{version:n,multihash:o,code:i}=t,s=Hn(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==pa)throw new Error(`Version 0 CID must use dag-pb (code: ${pa}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=fg(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,pa,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=sn(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new Bo(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[p,m]=fa(e.subarray(t));return t+=m,p},o=n(),i=pa;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),f=t+c,h=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:h,size:f}}static parse(e,t){let[n,o]=rS(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Rp(i).set(n,e),i}};function rS(r,e){switch(r[0]){case"Q":{let t=e??Pe;return[Pe.prefix,t.decode(`${Pe.prefix}${r}`)]}case Pe.prefix:{let t=e??Pe;return[Pe.prefix,t.decode(r)]}case an.prefix:{let t=e??an;return[an.prefix,t.decode(r)]}case ua.prefix:{let t=e??ua;return[ua.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function nS(r,e,t){let{prefix:n}=t;if(n!==Pe.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function oS(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var pa=112,iS=18;function fg(r,e,t){let n=zi(r),o=n+zi(e),i=new Uint8Array(o+t.byteLength);return Gi(r,i,0),Gi(e,i,n),i.set(t,o),i}var sS=Symbol.for("@ipld/js-cid/CID");var Dp={};bt(Dp,{identity:()=>yr});var pg=0,aS="identity",hg=sn;function cS(r){return vt(pg,hg(r))}var yr={code:pg,name:aS,encode:hg,digest:cS};function Fe(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function rt(r=0){return new Uint8Array(r)}function nt(r=0){return new Uint8Array(r)}function ot(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=nt(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var mg=Symbol.for("@achingbrain/uint8arraylist");function dg(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function Ru(r){return!!r?.[mg]}var be=class r{bufs;length;[mg]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(Ru(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(Ru(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=dg(this.bufs,e);return t.buf[t.index]}set(e,t){let n=dg(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(Ru(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return ot(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:ot(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),i=new r;return i.length=o,i.bufs=[...n],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let f=e>=a&&e<c,h=t>a&&t<=c;if(f&&h){if(e===a&&t===c){n.push(s);break}let p=e-a;n.push(s.subarray(p,p+(t-e)));break}if(f){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(h){if(t===c){n.push(s);break}n.push(s.subarray(0,t-a));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!Ru(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let p=0;p<i;p++)s[p]=-1;for(let p=0;p<o;p++)s[n[p]]=p;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,h;for(let p=t;p<=c;p+=h){h=0;for(let m=f;m>=0;m--){let v=this.get(p+m);if(n[m]!==v){h=Math.max(1,m-a[v]);break}}if(h===0)return p}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=nt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=nt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!Fe(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,i)=>o+i.byteLength,0)),n.length=t,n}};var Lp={};bt(Lp,{base10:()=>lS});var lS=Kn({prefix:"9",name:"base10",alphabet:"0123456789"});var Up={};bt(Up,{base16:()=>fS,base16upper:()=>pS});var fS=$e({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),pS=$e({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var jp={};bt(jp,{base2:()=>hS});var hS=$e({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Mp={};bt(Mp,{base256emoji:()=>wS});var yg=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),dS=yg.reduce((r,e,t)=>(r[t]=e,r),[]),mS=yg.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function yS(r){return r.reduce((e,t)=>(e+=dS[t],e),"")}function gS(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=mS[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var wS=qi({prefix:"\u{1F680}",name:"base256emoji",encode:yS,decode:gS});var Kp={};bt(Kp,{base64:()=>xS,base64pad:()=>bS,base64url:()=>ko,base64urlpad:()=>vS});var xS=$e({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),bS=$e({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ko=$e({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),vS=$e({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Hp={};bt(Hp,{base8:()=>AS});var AS=$e({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Vp={};bt(Vp,{identity:()=>SS});var SS=qi({prefix:"\0",name:"identity",encode:r=>rg(r),decode:r=>tg(r)});var uT=new TextEncoder,lT=new TextDecoder;var Wp={};bt(Wp,{sha256:()=>tr,sha512:()=>CS});function Fp({name:r,code:e,encode:t}){return new $p(r,e,t)}var $p=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?vt(this.code,t):t.then(n=>vt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function wg(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var tr=Fp({name:"sha2-256",code:18,encode:wg("SHA-256")}),CS=Fp({name:"sha2-512",code:19,encode:wg("SHA-512")});var Po={...Vp,...jp,...Hp,...Lp,...Up,...kp,...Pp,...Bp,...Kp,...Mp},AT={...Wp,...Dp};function bg(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var xg=bg("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),qp=bg("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=nt(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),IS={utf8:xg,"utf-8":xg,hex:Po.base16,latin1:qp,ascii:qp,binary:qp,...Po},Du=IS;function de(r,e="utf8"){let t=Du[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function ue(r,e="utf8"){let t=Du[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var TS=parseInt("11111",2),Gp=parseInt("10000000",2),BS=parseInt("01111111",2),vg={0:ha,1:ha,2:kS,3:OS,4:RS,5:NS,6:PS,16:ha,22:ha,48:ha};function cn(r,e={offset:0}){let t=r[e.offset]&TS;if(e.offset++,vg[t]!=null)return vg[t](r,e);throw new Error("No decoder for tag "+t)}function da(r,e){let t=0;if((r[e.offset]&Gp)===Gp){let n=r[e.offset]&BS,o="0x";e.offset++;for(let i=0;i<n;i++,e.offset++)o+=r[e.offset].toString(16).padStart(2,"0");t=parseInt(o,16)}else t=r[e.offset],e.offset++;return t}function ha(r,e){da(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=cn(r,e);if(n===null)break;t.push(n)}return t}function kS(r,e){let t=da(r,e),n=e.offset,o=e.offset+t,i=[];for(let s=n;s<o;s++)s===n&&r[s]===0||i.push(r[s]);return e.offset+=t,Uint8Array.from(i)}function PS(r,e){let t=da(r,e),n=e.offset+t,o=r[e.offset];e.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;e.offset<n;){let f=r[e.offset];if(e.offset++,c.push(f&127),f<128){c.reverse();let h=0;for(let p=0;p<c.length;p++)h+=c[p]<<p*7;a+=`.${h}`,c=[]}}return a}function NS(r,e){return e.offset++,null}function OS(r,e){let t=da(r,e),n=r[e.offset];e.offset++;let o=r.subarray(e.offset,e.offset+t-1);if(e.offset+=t,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function RS(r,e){let t=da(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function DS(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new be;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function Lu(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=DS(r.byteLength);return new be(Uint8Array.from([e.byteLength|Gp]),e)}function kt(r){let e=new be,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new be(Uint8Array.from([2]),Lu(e),e)}function ma(r){let e=Uint8Array.from([0]),t=new be(e,r);return new be(Uint8Array.from([3]),Lu(t),t)}function Ag(r){return new be(Uint8Array.from([4]),Lu(r),r)}function gr(r,e=48){let t=new be;for(let n of r)t.append(n);return new be(Uint8Array.from([e]),Lu(t),t)}async function Sg(r="P-256"){let e=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:r},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",e.publicKey),privateKey:await crypto.subtle.exportKey("jwk",e.privateKey)}}async function Eg(r,e){let t=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["sign"]),n=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},t,e.subarray());return new Uint8Array(n,0,n.byteLength)}async function _g(r,e,t){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,e,t.subarray())}var LS=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),US=Uint8Array.from([6,5,43,129,4,0,34]),jS=Uint8Array.from([6,5,43,129,4,0,35]),MS={ext:!0,kty:"EC",crv:"P-256"},KS={ext:!0,kty:"EC",crv:"P-384"},HS={ext:!0,kty:"EC",crv:"P-521"},zp=32,Xp=48,Yp=66;function Zp(r){let e=cn(r);return Cg(e)}function Cg(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===zp*2+1)return n=ue(e.subarray(t,t+zp),"base64url"),o=ue(e.subarray(t+zp),"base64url"),new No({...MS,key_ops:["verify"],x:n,y:o});if(e.byteLength===Xp*2+1)return n=ue(e.subarray(t,t+Xp),"base64url"),o=ue(e.subarray(t+Xp),"base64url"),new No({...KS,key_ops:["verify"],x:n,y:o});if(e.byteLength===Yp*2+1)return n=ue(e.subarray(t,t+Yp),"base64url"),o=ue(e.subarray(t+Yp),"base64url"),new No({...HS,key_ops:["verify"],x:n,y:o});throw new Ae(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Ig(r){return gr([kt(Uint8Array.from([1])),Ag(de(r.d??"","base64url")),gr([Bg(r.crv)],160),gr([ma(new be(Uint8Array.from([4]),de(r.x??"","base64url"),de(r.y??"","base64url")))],161)]).subarray()}function Tg(r){return gr([kt(Uint8Array.from([1])),gr([Bg(r.crv)],160),gr([ma(new be(Uint8Array.from([4]),de(r.x??"","base64url"),de(r.y??"","base64url")))],161)]).subarray()}function Bg(r){if(r==="P-256")return LS;if(r==="P-384")return US;if(r==="P-521")return jS;throw new Ae(`Invalid curve ${r}`)}async function kg(r="P-256"){let e=await Sg(r);return new Uu(e.privateKey)}var No=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Tg(this.jwk)),this._raw}toMultihash(){return yr.digest(Vn(this))}toCID(){return Xe.createV1(114,this.toMultihash())}toString(){return Pe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}async verify(e,t){return _g(this.jwk,t,e)}},Uu=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new No({crv:e.crv,ext:e.ext,key_ops:["verify"],kty:"EC",x:e.x,y:e.y})}get raw(){return this._raw==null&&(this._raw=Ig(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}async sign(e){return Eg(this.jwk,e)}};var Oo=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function VS(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Xi(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Ro(r,...e){if(!VS(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error("Uint8Array expected of length "+e+", got length="+r.length)}function ya(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Xi(r.outputLen),Xi(r.blockLen)}function Zi(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Pg(r,e){Ro(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function wr(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function ju(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function xr(r,e){return r<<32-e|r>>>e}function Ng(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function $n(r){return typeof r=="string"&&(r=Ng(r)),Ro(r),r}function Jp(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];Ro(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}var Yi=class{};function Qp(r){let e=n=>r().update($n(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function ga(r=32){if(Oo&&typeof Oo.getRandomValues=="function")return Oo.getRandomValues(new Uint8Array(r));if(Oo&&typeof Oo.randomBytes=="function")return Uint8Array.from(Oo.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function $S(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(t>>o&i),a=Number(t&i),c=n?4:0,f=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+f,a,n)}function Og(r,e,t){return r&e^~r&t}function Rg(r,e,t){return r&e^r&t^e&t}var wa=class extends Yi{constructor(e,t,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=ju(this.buffer)}update(e){Zi(this),e=$n(e),Ro(e);let{view:t,buffer:n,blockLen:o}=this,i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=ju(e);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Zi(this),Pg(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,wr(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let p=s;p<o;p++)t[p]=0;$S(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=ju(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,h=this.get();if(f>h.length)throw new Error("_sha2: outputLen bigger than state");for(let p=0;p<f;p++)a.setUint32(4*p,h[p],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.destroyed=s,e.finished=i,e.length=o,e.pos=a,o%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},un=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var lt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Mu=BigInt(4294967295),Dg=BigInt(32);function FS(r,e=!1){return e?{h:Number(r&Mu),l:Number(r>>Dg&Mu)}:{h:Number(r>>Dg&Mu)|0,l:Number(r&Mu)|0}}function Lg(r,e=!1){let t=r.length,n=new Uint32Array(t),o=new Uint32Array(t);for(let i=0;i<t;i++){let{h:s,l:a}=FS(r[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var eh=(r,e,t)=>r>>>t,th=(r,e,t)=>r<<32-t|e>>>t,Do=(r,e,t)=>r>>>t|e<<32-t,Lo=(r,e,t)=>r<<32-t|e>>>t,xa=(r,e,t)=>r<<64-t|e>>>t-32,ba=(r,e,t)=>r>>>t-32|e<<64-t;function Ur(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var Ug=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),jg=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Mg=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Kg=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,Hg=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),Vg=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var qS=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Fn=new Uint32Array(64),Ku=class extends wa{constructor(e=32){super(64,e,8,!1),this.A=un[0]|0,this.B=un[1]|0,this.C=un[2]|0,this.D=un[3]|0,this.E=un[4]|0,this.F=un[5]|0,this.G=un[6]|0,this.H=un[7]|0}get(){let{A:e,B:t,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,t,n,o,i,s,a,c]}set(e,t,n,o,i,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let p=0;p<16;p++,t+=4)Fn[p]=e.getUint32(t,!1);for(let p=16;p<64;p++){let m=Fn[p-15],v=Fn[p-2],g=xr(m,7)^xr(m,18)^m>>>3,w=xr(v,17)^xr(v,19)^v>>>10;Fn[p]=w+Fn[p-7]+g+Fn[p-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:h}=this;for(let p=0;p<64;p++){let m=xr(a,6)^xr(a,11)^xr(a,25),v=h+m+Og(a,c,f)+qS[p]+Fn[p]|0,w=(xr(n,2)^xr(n,13)^xr(n,22))+Rg(n,o,i)|0;h=f,f=c,c=a,a=s+v|0,s=i,i=o,o=n,n=v+w|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,h=h+this.H|0,this.set(n,o,i,s,a,c,f,h)}roundClean(){wr(Fn)}destroy(){this.set(0,0,0,0,0,0,0,0),wr(this.buffer)}};var $g=Lg(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),GS=$g[0],zS=$g[1],Wn=new Uint32Array(80),qn=new Uint32Array(80),rh=class extends wa{constructor(e=64){super(128,e,16,!1),this.Ah=lt[0]|0,this.Al=lt[1]|0,this.Bh=lt[2]|0,this.Bl=lt[3]|0,this.Ch=lt[4]|0,this.Cl=lt[5]|0,this.Dh=lt[6]|0,this.Dl=lt[7]|0,this.Eh=lt[8]|0,this.El=lt[9]|0,this.Fh=lt[10]|0,this.Fl=lt[11]|0,this.Gh=lt[12]|0,this.Gl=lt[13]|0,this.Hh=lt[14]|0,this.Hl=lt[15]|0}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:h,Fh:p,Fl:m,Gh:v,Gl:g,Hh:w,Hl:S}=this;return[e,t,n,o,i,s,a,c,f,h,p,m,v,g,w,S]}set(e,t,n,o,i,s,a,c,f,h,p,m,v,g,w,S){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=h|0,this.Fh=p|0,this.Fl=m|0,this.Gh=v|0,this.Gl=g|0,this.Hh=w|0,this.Hl=S|0}process(e,t){for(let T=0;T<16;T++,t+=4)Wn[T]=e.getUint32(t),qn[T]=e.getUint32(t+=4);for(let T=16;T<80;T++){let b=Wn[T-15]|0,D=qn[T-15]|0,V=Do(b,D,1)^Do(b,D,8)^eh(b,D,7),N=Lo(b,D,1)^Lo(b,D,8)^th(b,D,7),U=Wn[T-2]|0,$=qn[T-2]|0,X=Do(U,$,19)^xa(U,$,61)^eh(U,$,6),M=Lo(U,$,19)^ba(U,$,61)^th(U,$,6),G=Mg(N,M,qn[T-7],qn[T-16]),F=Kg(G,V,X,Wn[T-7],Wn[T-16]);Wn[T]=F|0,qn[T]=G|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:h,Eh:p,El:m,Fh:v,Fl:g,Gh:w,Gl:S,Hh:O,Hl:Y}=this;for(let T=0;T<80;T++){let b=Do(p,m,14)^Do(p,m,18)^xa(p,m,41),D=Lo(p,m,14)^Lo(p,m,18)^ba(p,m,41),V=p&v^~p&w,N=m&g^~m&S,U=Hg(Y,D,N,zS[T],qn[T]),$=Vg(U,O,b,V,GS[T],Wn[T]),X=U|0,M=Do(n,o,28)^xa(n,o,34)^xa(n,o,39),G=Lo(n,o,28)^ba(n,o,34)^ba(n,o,39),F=n&i^n&a^i&a,ie=o&s^o&c^s&c;O=w|0,Y=S|0,w=v|0,S=g|0,v=p|0,g=m|0,{h:p,l:m}=Ur(f|0,h|0,$|0,X|0),f=a|0,h=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let k=Ug(X,G,ie);n=jg(k,$,M,F),o=k|0}({h:n,l:o}=Ur(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Ur(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Ur(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:h}=Ur(this.Dh|0,this.Dl|0,f|0,h|0),{h:p,l:m}=Ur(this.Eh|0,this.El|0,p|0,m|0),{h:v,l:g}=Ur(this.Fh|0,this.Fl|0,v|0,g|0),{h:w,l:S}=Ur(this.Gh|0,this.Gl|0,w|0,S|0),{h:O,l:Y}=Ur(this.Hh|0,this.Hl|0,O|0,Y|0),this.set(n,o,i,s,a,c,f,h,p,m,v,g,w,S,O,Y)}roundClean(){wr(Wn,qn)}destroy(){wr(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Hu=Qp(()=>new Ku);var Fg=Qp(()=>new rh);var sh=BigInt(0),ih=BigInt(1);function Ji(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function ah(r){if(!Ji(r))throw new Error("Uint8Array expected")}function jr(r,e){if(typeof e!="boolean")throw new Error(r+" boolean expected, got "+e)}function va(r){let e=r.toString(16);return e.length&1?"0"+e:e}function Gg(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?sh:BigInt("0x"+r)}var zg=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",XS=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Gn(r){if(ah(r),zg)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=XS[r[t]];return e}var ln={_0:48,_9:57,A:65,F:70,a:97,f:102};function Wg(r){if(r>=ln._0&&r<=ln._9)return r-ln._0;if(r>=ln.A&&r<=ln.F)return r-(ln.A-10);if(r>=ln.a&&r<=ln.f)return r-(ln.a-10)}function Aa(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(zg)return Uint8Array.fromHex(r);let e=r.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,i=0;o<t;o++,i+=2){let s=Wg(r.charCodeAt(i)),a=Wg(r.charCodeAt(i+1));if(s===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function fn(r){return Gg(Gn(r))}function Mr(r){return ah(r),Gg(Gn(Uint8Array.from(r).reverse()))}function Uo(r,e){return Aa(r.toString(16).padStart(e*2,"0"))}function zn(r,e){return Uo(r,e).reverse()}function Oe(r,e,t){let n;if(typeof e=="string")try{n=Aa(e)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(Ji(e))n=Uint8Array.from(e);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof t=="number"&&o!==t)throw new Error(r+" of length "+t+" expected, got "+o);return n}function Xn(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];ah(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}var nh=r=>typeof r=="bigint"&&sh<=r;function Vu(r,e,t){return nh(r)&&nh(e)&&nh(t)&&e<=r&&r<t}function At(r,e,t,n){if(!Vu(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function Xg(r){let e;for(e=0;r>sh;r>>=ih,e+=1);return e}var jo=r=>(ih<<BigInt(r))-ih,oh=r=>new Uint8Array(r),qg=r=>Uint8Array.from(r);function Yg(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=oh(r),o=oh(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...p)=>t(o,n,...p),c=(p=oh(0))=>{o=a(qg([0]),p),n=a(),p.length!==0&&(o=a(qg([1]),p),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let p=0,m=[];for(;p<e;){n=a();let v=n.slice();m.push(v),p+=n.length}return Xn(...m)};return(p,m)=>{s(),c(p);let v;for(;!(v=m(f()));)c();return s(),v}}var YS={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Ji(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function br(r,e,t={}){let n=(o,i,s)=>{let a=YS[i];if(typeof a!="function")throw new Error("invalid validator function");let c=r[o];if(!(s&&c===void 0)&&!a(c,r))throw new Error("param "+String(o)+" is invalid. Expected "+i+", got "+c)};for(let[o,i]of Object.entries(e))n(o,i,!1);for(let[o,i]of Object.entries(t))n(o,i,!0);return r}function Qi(r){let e=new WeakMap;return(t,...n)=>{let o=e.get(t);if(o!==void 0)return o;let i=r(t,...n);return e.set(t,i),i}}var Pt=BigInt(0),at=BigInt(1),Mo=BigInt(2),ZS=BigInt(3),Jg=BigInt(4),Qg=BigInt(5),e0=BigInt(8);function Ce(r,e){let t=r%e;return t>=Pt?t:e+t}function Me(r,e,t){let n=r;for(;e-- >Pt;)n*=n,n%=t;return n}function $u(r,e){if(r===Pt)throw new Error("invert: expected non-zero number");if(e<=Pt)throw new Error("invert: expected positive modulus, got "+e);let t=Ce(r,e),n=e,o=Pt,i=at,s=at,a=Pt;for(;t!==Pt;){let f=n/t,h=n%t,p=o-s*f,m=i-a*f;n=t,t=h,o=s,i=a,s=p,a=m}if(n!==at)throw new Error("invert: does not exist");return Ce(o,e)}function t0(r,e){let t=(r.ORDER+at)/Jg,n=r.pow(e,t);if(!r.eql(r.sqr(n),e))throw new Error("Cannot find square root");return n}function JS(r,e){let t=(r.ORDER-Qg)/e0,n=r.mul(e,Mo),o=r.pow(n,t),i=r.mul(e,o),s=r.mul(r.mul(i,Mo),o),a=r.mul(i,r.sub(s,r.ONE));if(!r.eql(r.sqr(a),e))throw new Error("Cannot find square root");return a}function QS(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let e=r-at,t=0;for(;e%Mo===Pt;)e/=Mo,t++;let n=Mo,o=pn(r);for(;Zg(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return t0;let i=o.pow(n,e),s=(e+at)/Mo;return function(c,f){if(c.is0(f))return f;if(Zg(c,f)!==1)throw new Error("Cannot find square root");let h=t,p=c.mul(c.ONE,i),m=c.pow(f,e),v=c.pow(f,s);for(;!c.eql(m,c.ONE);){if(c.is0(m))return c.ZERO;let g=1,w=c.sqr(m);for(;!c.eql(w,c.ONE);)if(g++,w=c.sqr(w),g===h)throw new Error("Cannot find square root");let S=at<<BigInt(h-g-1),O=c.pow(p,S);h=g,p=c.sqr(O),m=c.mul(m,p),v=c.mul(v,O)}return v}}function eE(r){return r%Jg===ZS?t0:r%e0===Qg?JS:QS(r)}var r0=(r,e)=>(Ce(r,e)&at)===at,tE=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ch(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=tE.reduce((n,o)=>(n[o]="function",n),e);return br(r,t)}function rE(r,e,t){if(t<Pt)throw new Error("invalid exponent, negatives unsupported");if(t===Pt)return r.ONE;if(t===at)return e;let n=r.ONE,o=e;for(;t>Pt;)t&at&&(n=r.mul(n,o)),o=r.sqr(o),t>>=at;return n}function es(r,e,t=!1){let n=new Array(e.length).fill(t?r.ZERO:void 0),o=e.reduce((s,a,c)=>r.is0(a)?s:(n[c]=s,r.mul(s,a)),r.ONE),i=r.inv(o);return e.reduceRight((s,a,c)=>r.is0(a)?s:(n[c]=r.mul(s,n[c]),r.mul(s,a)),i),n}function Zg(r,e){let t=(r.ORDER-at)/Mo,n=r.pow(e,t),o=r.eql(n,r.ONE),i=r.eql(n,r.ZERO),s=r.eql(n,r.neg(r.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function uh(r,e){e!==void 0&&Xi(e);let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function pn(r,e,t=!1,n={}){if(r<=Pt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:i}=uh(r,e);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s,a=Object.freeze({ORDER:r,isLE:t,BITS:o,BYTES:i,MASK:jo(o),ZERO:Pt,ONE:at,create:c=>Ce(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return Pt<=c&&c<r},is0:c=>c===Pt,isOdd:c=>(c&at)===at,neg:c=>Ce(-c,r),eql:(c,f)=>c===f,sqr:c=>Ce(c*c,r),add:(c,f)=>Ce(c+f,r),sub:(c,f)=>Ce(c-f,r),mul:(c,f)=>Ce(c*f,r),pow:(c,f)=>rE(a,c,f),div:(c,f)=>Ce(c*$u(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>$u(c,r),sqrt:n.sqrt||(c=>(s||(s=eE(r)),s(a,c))),toBytes:c=>t?zn(c,i):Uo(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return t?Mr(c):fn(c)},invertBatch:c=>es(a,c),cmov:(c,f,h)=>h?f:c});return Object.freeze(a)}function n0(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function lh(r){let e=n0(r);return e+Math.ceil(e/2)}function o0(r,e,t=!1){let n=r.length,o=n0(e),i=lh(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?Mr(r):fn(r),a=Ce(s,e-at)+at;return t?zn(a,o):Uo(a,o)}var i0=BigInt(0),mh=BigInt(1);function fh(r,e){let t=e.negate();return r?t:e}function a0(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function ph(r,e){a0(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=jo(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function s0(r,e,t){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=t,a=Number(r&o),c=r>>s;a>n&&(a-=i,c+=mh);let f=e*n,h=f+Math.abs(a)-1,p=a===0,m=a<0,v=e%2!==0;return{nextN:c,offset:h,isZero:p,isNeg:m,isNegF:v,offsetF:f}}function nE(r,e){if(!Array.isArray(r))throw new Error("array expected");r.forEach((t,n)=>{if(!(t instanceof e))throw new Error("invalid point at index "+n)})}function oE(r,e){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((t,n)=>{if(!e.isValid(t))throw new Error("invalid scalar at index "+n)})}var hh=new WeakMap,c0=new WeakMap;function dh(r){return c0.get(r)||1}function Fu(r,e){return{constTimeNegate:fh,hasPrecomputes(t){return dh(t)!==1},unsafeLadder(t,n,o=r.ZERO){let i=t;for(;n>i0;)n&mh&&(o=o.add(i)),i=i.double(),n>>=mh;return o},precomputeWindow(t,n){let{windows:o,windowSize:i}=ph(n,e),s=[],a=t,c=a;for(let f=0;f<o;f++){c=a,s.push(c);for(let h=1;h<i;h++)c=c.add(a),s.push(c);a=c.double()}return s},wNAF(t,n,o){let i=r.ZERO,s=r.BASE,a=ph(t,e);for(let c=0;c<a.windows;c++){let{nextN:f,offset:h,isZero:p,isNeg:m,isNegF:v,offsetF:g}=s0(o,c,a);o=f,p?s=s.add(fh(v,n[g])):i=i.add(fh(m,n[h]))}return{p:i,f:s}},wNAFUnsafe(t,n,o,i=r.ZERO){let s=ph(t,e);for(let a=0;a<s.windows&&o!==i0;a++){let{nextN:c,offset:f,isZero:h,isNeg:p}=s0(o,a,s);if(o=c,!h){let m=n[f];i=i.add(p?m.negate():m)}}return i},getPrecomputes(t,n,o){let i=hh.get(n);return i||(i=this.precomputeWindow(n,t),t!==1&&hh.set(n,o(i))),i},wNAFCached(t,n,o){let i=dh(t);return this.wNAF(i,this.getPrecomputes(i,t,o),n)},wNAFCachedUnsafe(t,n,o,i){let s=dh(t);return s===1?this.unsafeLadder(t,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,t,o),n,i)},setWindowSize(t,n){a0(n,e),c0.set(t,n),hh.delete(t)}}}function Wu(r,e,t,n){nE(t,r),oE(n,e);let o=t.length,i=n.length;if(o!==i)throw new Error("arrays of points and scalars must have equal length");let s=r.ZERO,a=Xg(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let f=jo(c),h=new Array(Number(f)+1).fill(s),p=Math.floor((e.BITS-1)/c)*c,m=s;for(let v=p;v>=0;v-=c){h.fill(s);for(let w=0;w<i;w++){let S=n[w],O=Number(S>>BigInt(v)&f);h[O]=h[O].add(t[w])}let g=s;for(let w=h.length-1,S=s;w>0;w--)S=S.add(h[w]),g=g.add(S);if(m=m.add(g),v!==0)for(let w=0;w<c;w++)m=m.double()}return m}function Sa(r){return ch(r.Fp),br(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...uh(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Kr=BigInt(0),Nt=BigInt(1),u0=BigInt(2),iE=BigInt(8),sE={zip215:!0};function aE(r){let e=Sa(r);return br(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function l0(r){let e=aE(r),{Fp:t,n,prehash:o,hash:i,randomBytes:s,nByteLength:a,h:c}=e,f=u0<<BigInt(a*8)-Nt,h=t.create,p=pn(e.n,e.nBitLength);function m(P,y){let C=t.sqr(P),L=t.sqr(y),I=t.add(t.mul(e.a,C),L),re=t.add(t.ONE,t.mul(e.d,t.mul(C,L)));return t.eql(I,re)}if(!m(e.Gx,e.Gy))throw new Error("bad curve params: generator point");let v=e.uvRatio||((P,y)=>{try{return{isValid:!0,value:t.sqrt(P*t.inv(y))}}catch{return{isValid:!1,value:Kr}}}),g=e.adjustScalarBytes||(P=>P),w=e.domain||((P,y,C)=>{if(jr("phflag",C),y.length||C)throw new Error("Contexts/pre-hash are not supported");return P});function S(P,y,C=!1){let L=C?Nt:Kr;At("coordinate "+P,y,L,f)}function O(P){if(!(P instanceof b))throw new Error("ExtendedPoint expected")}let Y=Qi((P,y)=>{let{ex:C,ey:L,ez:I}=P,re=P.is0();y==null&&(y=re?iE:t.inv(I));let le=h(C*y),Q=h(L*y),pe=h(I*y);if(re)return{x:Kr,y:Nt};if(pe!==Nt)throw new Error("invZ was invalid");return{x:le,y:Q}}),T=Qi(P=>{let{a:y,d:C}=e;if(P.is0())throw new Error("bad point: ZERO");let{ex:L,ey:I,ez:re,et:le}=P,Q=h(L*L),pe=h(I*I),he=h(re*re),Ee=h(he*he),_e=h(Q*y),ke=h(he*h(_e+pe)),ut=h(Ee+h(C*h(Q*pe)));if(ke!==ut)throw new Error("bad point: equation left != right (1)");let Ue=h(L*I),et=h(re*le);if(Ue!==et)throw new Error("bad point: equation left != right (2)");return!0});class b{constructor(y,C,L,I){S("x",y),S("y",C),S("z",L,!0),S("t",I),this.ex=y,this.ey=C,this.ez=L,this.et=I,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(y){if(y instanceof b)throw new Error("extended point not allowed");let{x:C,y:L}=y||{};return S("x",C),S("y",L),new b(C,L,Nt,h(C*L))}static normalizeZ(y){let C=es(t,y.map(L=>L.ez));return y.map((L,I)=>L.toAffine(C[I])).map(b.fromAffine)}static msm(y,C){return Wu(b,p,y,C)}_setWindowSize(y){N.setWindowSize(this,y)}assertValidity(){T(this)}equals(y){O(y);let{ex:C,ey:L,ez:I}=this,{ex:re,ey:le,ez:Q}=y,pe=h(C*Q),he=h(re*I),Ee=h(L*Q),_e=h(le*I);return pe===he&&Ee===_e}is0(){return this.equals(b.ZERO)}negate(){return new b(h(-this.ex),this.ey,this.ez,h(-this.et))}double(){let{a:y}=e,{ex:C,ey:L,ez:I}=this,re=h(C*C),le=h(L*L),Q=h(u0*h(I*I)),pe=h(y*re),he=C+L,Ee=h(h(he*he)-re-le),_e=pe+le,ke=_e-Q,ut=pe-le,Ue=h(Ee*ke),et=h(_e*ut),Tt=h(Ee*ut),Bt=h(ke*_e);return new b(Ue,et,Bt,Tt)}add(y){O(y);let{a:C,d:L}=e,{ex:I,ey:re,ez:le,et:Q}=this,{ex:pe,ey:he,ez:Ee,et:_e}=y,ke=h(I*pe),ut=h(re*he),Ue=h(Q*L*_e),et=h(le*Ee),Tt=h((I+re)*(pe+he)-ke-ut),Bt=et-Ue,Un=et+Ue,ia=h(ut-C*ke),xu=h(Tt*Bt),bu=h(Un*ia),vu=h(Tt*ia),sa=h(Bt*Un);return new b(xu,bu,sa,vu)}subtract(y){return this.add(y.negate())}wNAF(y){return N.wNAFCached(this,y,b.normalizeZ)}multiply(y){let C=y;At("scalar",C,Nt,n);let{p:L,f:I}=this.wNAF(C);return b.normalizeZ([L,I])[0]}multiplyUnsafe(y,C=b.ZERO){let L=y;return At("scalar",L,Kr,n),L===Kr?V:this.is0()||L===Nt?this:N.wNAFCachedUnsafe(this,L,b.normalizeZ,C)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return N.unsafeLadder(this,n).is0()}toAffine(y){return Y(this,y)}clearCofactor(){let{h:y}=e;return y===Nt?this:this.multiplyUnsafe(y)}static fromHex(y,C=!1){let{d:L,a:I}=e,re=t.BYTES;y=Oe("pointHex",y,re),jr("zip215",C);let le=y.slice(),Q=y[re-1];le[re-1]=Q&-129;let pe=Mr(le),he=C?f:t.ORDER;At("pointHex.y",pe,Kr,he);let Ee=h(pe*pe),_e=h(Ee-Nt),ke=h(L*Ee-I),{isValid:ut,value:Ue}=v(_e,ke);if(!ut)throw new Error("Point.fromHex: invalid y coordinate");let et=(Ue&Nt)===Nt,Tt=(Q&128)!==0;if(!C&&Ue===Kr&&Tt)throw new Error("Point.fromHex: x=0 and x_0=1");return Tt!==et&&(Ue=h(-Ue)),b.fromAffine({x:Ue,y:pe})}static fromPrivateKey(y){let{scalar:C}=X(y);return D.multiply(C)}toRawBytes(){let{x:y,y:C}=this.toAffine(),L=zn(C,t.BYTES);return L[L.length-1]|=y&Nt?128:0,L}toHex(){return Gn(this.toRawBytes())}}b.BASE=new b(e.Gx,e.Gy,Nt,h(e.Gx*e.Gy)),b.ZERO=new b(Kr,Nt,Nt,Kr);let{BASE:D,ZERO:V}=b,N=Fu(b,a*8);function U(P){return Ce(P,n)}function $(P){return U(Mr(P))}function X(P){let y=t.BYTES;P=Oe("private key",P,y);let C=Oe("hashed private key",i(P),2*y),L=g(C.slice(0,y)),I=C.slice(y,2*y),re=$(L);return{head:L,prefix:I,scalar:re}}function M(P){let{head:y,prefix:C,scalar:L}=X(P),I=D.multiply(L),re=I.toRawBytes();return{head:y,prefix:C,scalar:L,point:I,pointBytes:re}}function G(P){return M(P).pointBytes}function F(P=Uint8Array.of(),...y){let C=Xn(...y);return $(i(w(C,Oe("context",P),!!o)))}function ie(P,y,C={}){P=Oe("message",P),o&&(P=o(P));let{prefix:L,scalar:I,pointBytes:re}=M(y),le=F(C.context,L,P),Q=D.multiply(le).toRawBytes(),pe=F(C.context,Q,re,P),he=U(le+pe*I);At("signature.s",he,Kr,n);let Ee=Xn(Q,zn(he,t.BYTES));return Oe("result",Ee,t.BYTES*2)}let k=sE;function R(P,y,C,L=k){let{context:I,zip215:re}=L,le=t.BYTES;P=Oe("signature",P,2*le),y=Oe("message",y),C=Oe("publicKey",C,le),re!==void 0&&jr("zip215",re),o&&(y=o(y));let Q=Mr(P.slice(le,2*le)),pe,he,Ee;try{pe=b.fromHex(C,re),he=b.fromHex(P.slice(0,le),re),Ee=D.multiplyUnsafe(Q)}catch{return!1}if(!re&&pe.isSmallOrder())return!1;let _e=F(I,he.toRawBytes(),pe.toRawBytes(),y);return he.add(pe.multiplyUnsafe(_e)).subtract(Ee).clearCofactor().equals(b.ZERO)}return D._setWindowSize(8),{CURVE:e,getPublicKey:G,sign:ie,verify:R,ExtendedPoint:b,utils:{getExtendedPublicKey:M,randomPrivateKey:()=>s(t.BYTES),precompute(P=8,y=b.BASE){return y._setWindowSize(P),y.multiply(BigInt(3)),y}}}}var Ea=BigInt(0),ts=BigInt(1),qu=BigInt(2);function cE(r){return br(r,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r})}function f0(r){let e=cE(r),{P:t,type:n,adjustScalarBytes:o,powPminus2:i}=e,s=n==="x25519";if(!s&&n!=="x448")throw new Error("invalid type");let a=s?255:448,c=s?32:56,f=BigInt(s?9:5),h=BigInt(s?121665:39081),p=s?qu**BigInt(254):qu**BigInt(447),m=s?BigInt(8)*qu**BigInt(251)-ts:BigInt(4)*qu**BigInt(445)-ts,v=p+m+ts,g=N=>Ce(N,t),w=S(f);function S(N){return zn(g(N),c)}function O(N){let U=Oe("u coordinate",N,c);return s&&(U[31]&=127),g(Mr(U))}function Y(N){return Mr(o(Oe("scalar",N,c)))}function T(N,U){let $=V(O(U),Y(N));if($===Ea)throw new Error("invalid private or public key received");return S($)}function b(N){return T(N,w)}function D(N,U,$){let X=g(N*(U-$));return U=g(U-X),$=g($+X),{x_2:U,x_3:$}}function V(N,U){At("u",N,Ea,t),At("scalar",U,p,v);let $=U,X=N,M=ts,G=Ea,F=N,ie=ts,k=Ea;for(let K=BigInt(a-1);K>=Ea;K--){let P=$>>K&ts;k^=P,{x_2:M,x_3:F}=D(k,M,F),{x_2:G,x_3:ie}=D(k,G,ie),k=P;let y=M+G,C=g(y*y),L=M-G,I=g(L*L),re=C-I,le=F+ie,Q=F-ie,pe=g(Q*y),he=g(le*L),Ee=pe+he,_e=pe-he;F=g(Ee*Ee),ie=g(X*g(_e*_e)),M=g(C*I),G=g(re*(C+g(h*re)))}({x_2:M,x_3:F}=D(k,M,F)),{x_2:G,x_3:ie}=D(k,G,ie);let R=i(G);return g(M*R)}return{scalarMult:T,scalarMultBase:b,getSharedSecret:(N,U)=>T(N,U),getPublicKey:N=>b(N),utils:{randomPrivateKey:()=>e.randomBytes(c)},GuBytes:w.slice()}}var _a=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),p0=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),CB=BigInt(0),uE=BigInt(1),h0=BigInt(2),lE=BigInt(3),fE=BigInt(5),pE=BigInt(8);function m0(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=_a,a=r*r%i*r%i,c=Me(a,h0,i)*a%i,f=Me(c,uE,i)*r%i,h=Me(f,fE,i)*f%i,p=Me(h,e,i)*h%i,m=Me(p,t,i)*p%i,v=Me(m,n,i)*m%i,g=Me(v,o,i)*v%i,w=Me(g,o,i)*v%i,S=Me(w,e,i)*h%i;return{pow_p_5_8:Me(S,h0,i)*r%i,b2:a}}function y0(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function hE(r,e){let t=_a,n=Ce(e*e*e,t),o=Ce(n*n*e,t),i=m0(r*o).pow_p_5_8,s=Ce(r*n*i,t),a=Ce(e*s*s,t),c=s,f=Ce(s*p0,t),h=a===r,p=a===Ce(-r,t),m=a===Ce(-r*p0,t);return h&&(s=c),(p||m)&&(s=f),r0(s,t)&&(s=Ce(-s,t)),{isValid:h||p,value:s}}var d0=pn(_a,void 0,!0),dE={a:d0.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:d0,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:pE,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Fg,randomBytes:ga,adjustScalarBytes:y0,uvRatio:hE},Ca=l0(dE);var Ia=f0({P:_a,type:"x25519",powPminus2:r=>{let e=_a,{pow_p_5_8:t,b2:n}=m0(r);return Ce(Me(t,lE,e)*n,e)},adjustScalarBytes:y0,randomBytes:ga});var Gu=32,zu=64,yh=32;function g0(){let r=Ca.utils.randomPrivateKey(),e=Ca.getPublicKey(r);return{privateKey:mE(r,e),publicKey:e}}function w0(r,e){let t=r.subarray(0,yh);return Ca.sign(e instanceof Uint8Array?e:e.subarray(),t)}function x0(r,e,t){return Ca.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function mE(r,e){let t=new Uint8Array(zu);for(let n=0;n<yh;n++)t[n]=r[n],t[yh+n]=e[n];return t}var Ta=class{type="Ed25519";raw;constructor(e){this.raw=Yu(e,Gu)}toMultihash(){return yr.digest(Vn(this))}toCID(){return Xe.createV1(114,this.toMultihash())}toString(){return Pe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}verify(e,t){return x0(this.raw,t,e)}},Xu=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=Yu(e,zu),this.publicKey=new Ta(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}sign(e){return w0(this.raw,e)}};function gh(r){return r=Yu(r,Gu),new Ta(r)}async function v0(){let{privateKey:r,publicKey:e}=g0();return new Xu(r,e)}function Yu(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new Ae(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var yE=Math.pow(2,7),gE=Math.pow(2,14),wE=Math.pow(2,21),wh=Math.pow(2,28),xh=Math.pow(2,35),bh=Math.pow(2,42),vh=Math.pow(2,49),Te=128,St=127;function Ke(r){if(r<yE)return 1;if(r<gE)return 2;if(r<wE)return 3;if(r<wh)return 4;if(r<xh)return 5;if(r<bh)return 6;if(r<vh)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ah(r,e,t=0){switch(Ke(r)){case 8:e[t++]=r&255|Te,r/=128;case 7:e[t++]=r&255|Te,r/=128;case 6:e[t++]=r&255|Te,r/=128;case 5:e[t++]=r&255|Te,r/=128;case 4:e[t++]=r&255|Te,r>>>=7;case 3:e[t++]=r&255|Te,r>>>=7;case 2:e[t++]=r&255|Te,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function xE(r,e,t=0){switch(Ke(r)){case 8:e.set(t++,r&255|Te),r/=128;case 7:e.set(t++,r&255|Te),r/=128;case 6:e.set(t++,r&255|Te),r/=128;case 5:e.set(t++,r&255|Te),r/=128;case 4:e.set(t++,r&255|Te),r>>>=7;case 3:e.set(t++,r&255|Te),r>>>=7;case 2:e.set(t++,r&255|Te),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Sh(r,e){let t=r[e],n=0;if(n+=t&St,t<Te||(t=r[e+1],n+=(t&St)<<7,t<Te)||(t=r[e+2],n+=(t&St)<<14,t<Te)||(t=r[e+3],n+=(t&St)<<21,t<Te)||(t=r[e+4],n+=(t&St)*wh,t<Te)||(t=r[e+5],n+=(t&St)*xh,t<Te)||(t=r[e+6],n+=(t&St)*bh,t<Te)||(t=r[e+7],n+=(t&St)*vh,t<Te))return n;throw new RangeError("Could not decode varint")}function bE(r,e){let t=r.get(e),n=0;if(n+=t&St,t<Te||(t=r.get(e+1),n+=(t&St)<<7,t<Te)||(t=r.get(e+2),n+=(t&St)<<14,t<Te)||(t=r.get(e+3),n+=(t&St)<<21,t<Te)||(t=r.get(e+4),n+=(t&St)*wh,t<Te)||(t=r.get(e+5),n+=(t&St)*xh,t<Te)||(t=r.get(e+6),n+=(t&St)*bh,t<Te)||(t=r.get(e+7),n+=(t&St)*vh,t<Te))return n;throw new RangeError("Could not decode varint")}function Hr(r,e,t=0){return e==null&&(e=nt(Ke(r))),e instanceof Uint8Array?Ah(r,e,t):xE(r,e,t)}function vr(r,e=0){return r instanceof Uint8Array?Sh(r,e):bE(r,e)}var Eh=new Float32Array([-0]),Yn=new Uint8Array(Eh.buffer);function A0(r,e,t){Eh[0]=r,e[t]=Yn[0],e[t+1]=Yn[1],e[t+2]=Yn[2],e[t+3]=Yn[3]}function S0(r,e){return Yn[0]=r[e],Yn[1]=r[e+1],Yn[2]=r[e+2],Yn[3]=r[e+3],Eh[0]}var _h=new Float64Array([-0]),Et=new Uint8Array(_h.buffer);function E0(r,e,t){_h[0]=r,e[t]=Et[0],e[t+1]=Et[1],e[t+2]=Et[2],e[t+3]=Et[3],e[t+4]=Et[4],e[t+5]=Et[5],e[t+6]=Et[6],e[t+7]=Et[7]}function _0(r,e){return Et[0]=r[e],Et[1]=r[e+1],Et[2]=r[e+2],Et[3]=r[e+3],Et[4]=r[e+4],Et[5]=r[e+5],Et[6]=r[e+6],Et[7]=r[e+7],_h[0]}var vE=BigInt(Number.MAX_SAFE_INTEGER),AE=BigInt(Number.MIN_SAFE_INTEGER),Xt=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Ko;if(e<vE&&e>AE)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>C0&&(o=0n,++n>C0&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return Ko;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):Ko}},Ko=new Xt(0,0);Ko.toBigInt=function(){return 0n};Ko.zzEncode=Ko.zzDecode=function(){return this};Ko.length=function(){return 1};var C0=4294967296n;function I0(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function T0(r,e,t){if(t-e<1)return"";let o,i=[],s=0,a;for(;e<t;)a=r[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Ch(r,e,t){let n=t,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function Ar(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Zu(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Ih=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ar(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ar(this,4);return Zu(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ar(this,4);return Zu(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ar(this,4);let e=S0(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ar(this,4);let e=_0(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw Ar(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return T0(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ar(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ar(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Xt(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw Ar(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw Ar(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ar(this,8);let e=Zu(this.buf,this.pos+=4),t=Zu(this.buf,this.pos+=4);return new Xt(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Sh(this.buf,this.pos);return this.pos+=Ke(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Th(r){return new Ih(r instanceof Uint8Array?r:r.subarray())}function Sr(r,e,t){let n=Th(r);return e.decode(n,void 0,t)}function Bh(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return nt(s);o+s>e&&(n=nt(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Ho=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function kh(){}var Nh=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},SE=Bh();function EE(r){return globalThis.Buffer!=null?nt(r):SE(r)}var Pa=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ho(kh,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Ho(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Oh((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Ju,10,Xt.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Xt.fromBigInt(e);return this._push(Ju,t.length(),t)}uint64Number(e){return this._push(Ah,Ke(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Xt.fromBigInt(e).zzEncode();return this._push(Ju,t.length(),t)}sint64Number(e){let t=Xt.fromNumber(e).zzEncode();return this._push(Ju,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ph,1,e?1:0)}fixed32(e){return this._push(ka,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Xt.fromBigInt(e);return this._push(ka,4,t.lo)._push(ka,4,t.hi)}fixed64Number(e){let t=Xt.fromNumber(e);return this._push(ka,4,t.lo)._push(ka,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(A0,4,e)}double(e){return this._push(E0,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Ph,1,0):this.uint32(t)._push(CE,t,e)}string(e){let t=I0(e);return t!==0?this.uint32(t)._push(Ch,t,e):this._push(Ph,1,0)}fork(){return this.states=new Nh(this),this.head=this.tail=new Ho(kh,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Ho(kh,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=EE(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Ph(r,e,t){e[t]=r&255}function _E(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Oh=class extends Ho{next;constructor(e,t){super(_E,e,t),this.next=void 0}};function Ju(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function ka(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function CE(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Pa.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(IE,e,r),this},Pa.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(TE,e,r),this});function IE(r,e,t){e.set(r,t)}function TE(r,e,t){r.length<40?Ch(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(de(r),t)}function Rh(){return new Pa}function Er(r,e){let t=Rh();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var rs;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(rs||(rs={}));function Qu(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Vo(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return Qu("enum",rs.VARINT,t,n)}function _r(r,e){return Qu("message",rs.LENGTH_DELIMITED,r,e)}var Na=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Ye;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Ye||(Ye={}));var Dh;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Dh||(Dh={}));(function(r){r.codec=()=>Vo(Dh)})(Ye||(Ye={}));var Vr;(function(r){let e;r.codec=()=>(e==null&&(e=_r((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Ye.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=Ye.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Er(t,r.codec()),r.decode=(t,n)=>Sr(t,r.codec(),n)})(Vr||(Vr={}));var Lh;(function(r){let e;r.codec=()=>(e==null&&(e=_r((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Ye.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=Ye.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Er(t,r.codec()),r.decode=(t,n)=>Sr(t,r.codec(),n)})(Lh||(Lh={}));var Oa=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},Ra=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},el=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var P0={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new el("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Zn=P0;var La={};bt(La,{MAX_RSA_KEY_SIZE:()=>Uh,generateRSAKeyPair:()=>qh,jwkToJWKKeyPair:()=>D0,jwkToPkcs1:()=>NE,jwkToPkix:()=>Hh,jwkToRSAPrivateKey:()=>Wh,pkcs1MessageToJwk:()=>Mh,pkcs1MessageToRSAPrivateKey:()=>Vh,pkcs1ToJwk:()=>PE,pkcs1ToRSAPrivateKey:()=>R0,pkixMessageToJwk:()=>Kh,pkixMessageToRSAPublicKey:()=>Fh,pkixToJwk:()=>OE,pkixToRSAPublicKey:()=>$h});var Jn=Hu;var ns=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=La.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return Xe.createV1(114,this._multihash)}toString(){return Pe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}verify(e,t){return O0(this.jwk,t,e)}},Da=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=La.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}sign(e){return N0(this.jwk,e)}};var Uh=8192,jh=18,BE=1062,kE=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function PE(r){let e=cn(r);return Mh(e)}function Mh(r){return{n:ue(r[1],"base64url"),e:ue(r[2],"base64url"),d:ue(r[3],"base64url"),p:ue(r[4],"base64url"),q:ue(r[5],"base64url"),dp:ue(r[6],"base64url"),dq:ue(r[7],"base64url"),qi:ue(r[8],"base64url"),kty:"RSA"}}function NE(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new Ae("JWK was missing components");return gr([kt(Uint8Array.from([0])),kt(de(r.n,"base64url")),kt(de(r.e,"base64url")),kt(de(r.d,"base64url")),kt(de(r.p,"base64url")),kt(de(r.q,"base64url")),kt(de(r.dp,"base64url")),kt(de(r.dq,"base64url")),kt(de(r.qi,"base64url"))]).subarray()}function OE(r){let e=cn(r,{offset:0});return Kh(e)}function Kh(r){let e=cn(r[1],{offset:0});return{kty:"RSA",n:ue(e[0],"base64url"),e:ue(e[1],"base64url")}}function Hh(r){if(r.n==null||r.e==null)throw new Ae("JWK was missing components");return gr([kE,ma(gr([kt(de(r.n,"base64url")),kt(de(r.e,"base64url"))]))]).subarray()}function R0(r){let e=cn(r);return Vh(e)}function Vh(r){let e=Mh(r);return Wh(e)}function $h(r,e){if(r.byteLength>=BE)throw new Fi("Key size is too large");let t=cn(r,{offset:0});return Fh(t,r,e)}function Fh(r,e,t){let n=Kh(r);if(t==null){let o=Jn(Vr.encode({Type:Ye.RSA,Data:e}));t=vt(jh,o)}return new ns(n,t)}function Wh(r){if(U0(r)>Uh)throw new Ae("Key size is too large");let e=D0(r),t=Jn(Vr.encode({Type:Ye.RSA,Data:Hh(e.publicKey)})),n=vt(jh,t);return new Da(e.privateKey,new ns(e.publicKey,n))}async function qh(r){if(r>Uh)throw new Ae("Key size is too large");let e=await L0(r),t=Jn(Vr.encode({Type:Ye.RSA,Data:Hh(e.publicKey)})),n=vt(jh,t);return new Da(e.privateKey,new ns(e.publicKey,n))}function D0(r){if(r==null)throw new Ae("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function L0(r){let e=await Zn.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),t=await RE(e);return{privateKey:t[0],publicKey:t[1]}}async function N0(r,e){let t=await Zn.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Zn.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function O0(r,e,t){let n=await Zn.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Zn.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function RE(r){if(r.privateKey==null||r.publicKey==null)throw new Ae("Private and public key are required");return Promise.all([Zn.get().subtle.exportKey("jwk",r.privateKey),Zn.get().subtle.exportKey("jwk",r.publicKey)])}function U0(r){if(r.kty!=="RSA")throw new Ae("invalid key type");if(r.n==null)throw new Ae("invalid key modulus");return de(r.n,"base64url").length*8}var tl=class extends Yi{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,ya(e);let n=$n(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),wr(i)}update(e){return Zi(this),this.iHash.update(e),this}digestInto(e){Zi(this),Ro(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},os=(r,e,t)=>new tl(r,e).update(t).digest();os.create=(r,e)=>new tl(r,e);function j0(r){r.lowS!==void 0&&jr("lowS",r.lowS),r.prehash!==void 0&&jr("prehash",r.prehash)}function DE(r){let e=Sa(r);br(e,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});let{endo:t,Fp:n,a:o}=e;if(t){if(!n.eql(o,n.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...e})}var Xh=class extends Error{constructor(e=""){super(e)}},hn={Err:Xh,_tlv:{encode:(r,e)=>{let{Err:t}=hn;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");let n=e.length/2,o=va(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?va(o.length/2|128):"";return va(r)+i+o+e},decode(r,e){let{Err:t}=hn,n=0;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new t("tlv.decode: length bytes not complete");if(f[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let h of f)s=s<<8|h;if(n+=c,s<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(r){let{Err:e}=hn;if(r<dn)throw new e("integer: negative integers are not allowed");let t=va(r);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return t},decode(r){let{Err:e}=hn;if(r[0]&128)throw new e("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return fn(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=hn,o=Oe("signature",r),{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l:h}=n.decode(2,c);if(h.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(f)}},hexFromSig(r){let{_tlv:e,_int:t}=hn,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),i=n+o;return e.encode(48,i)}};function Gh(r,e){return Gn(Uo(r,e))}var dn=BigInt(0),ct=BigInt(1),Y8=BigInt(2),zh=BigInt(3),LE=BigInt(4);function UE(r){let e=DE(r),{Fp:t}=e,n=pn(e.n,e.nBitLength),o=e.toBytes||((T,b,D)=>{let V=b.toAffine();return Xn(Uint8Array.from([4]),t.toBytes(V.x),t.toBytes(V.y))}),i=e.fromBytes||(T=>{let b=T.subarray(1),D=t.fromBytes(b.subarray(0,t.BYTES)),V=t.fromBytes(b.subarray(t.BYTES,2*t.BYTES));return{x:D,y:V}});function s(T){let{a:b,b:D}=e,V=t.sqr(T),N=t.mul(V,T);return t.add(t.add(N,t.mul(T,b)),D)}function a(T,b){let D=t.sqr(b),V=s(T);return t.eql(D,V)}if(!a(e.Gx,e.Gy))throw new Error("bad curve params: generator point");let c=t.mul(t.pow(e.a,zh),LE),f=t.mul(t.sqr(e.b),BigInt(27));if(t.is0(t.add(c,f)))throw new Error("bad curve params: a or b");function h(T){return Vu(T,ct,e.n)}function p(T){let{allowedPrivateKeyLengths:b,nByteLength:D,wrapPrivateKey:V,n:N}=e;if(b&&typeof T!="bigint"){if(Ji(T)&&(T=Gn(T)),typeof T!="string"||!b.includes(T.length))throw new Error("invalid private key");T=T.padStart(D*2,"0")}let U;try{U=typeof T=="bigint"?T:fn(Oe("private key",T,D))}catch{throw new Error("invalid private key, expected hex or "+D+" bytes, got "+typeof T)}return V&&(U=Ce(U,N)),At("private key",U,ct,N),U}function m(T){if(!(T instanceof w))throw new Error("ProjectivePoint expected")}let v=Qi((T,b)=>{let{px:D,py:V,pz:N}=T;if(t.eql(N,t.ONE))return{x:D,y:V};let U=T.is0();b==null&&(b=U?t.ONE:t.inv(N));let $=t.mul(D,b),X=t.mul(V,b),M=t.mul(N,b);if(U)return{x:t.ZERO,y:t.ZERO};if(!t.eql(M,t.ONE))throw new Error("invZ was invalid");return{x:$,y:X}}),g=Qi(T=>{if(T.is0()){if(e.allowInfinityPoint&&!t.is0(T.py))return;throw new Error("bad point: ZERO")}let{x:b,y:D}=T.toAffine();if(!t.isValid(b)||!t.isValid(D))throw new Error("bad point: x or y not FE");if(!a(b,D))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class w{constructor(b,D,V){if(b==null||!t.isValid(b))throw new Error("x required");if(D==null||!t.isValid(D)||t.is0(D))throw new Error("y required");if(V==null||!t.isValid(V))throw new Error("z required");this.px=b,this.py=D,this.pz=V,Object.freeze(this)}static fromAffine(b){let{x:D,y:V}=b||{};if(!b||!t.isValid(D)||!t.isValid(V))throw new Error("invalid affine point");if(b instanceof w)throw new Error("projective point not allowed");let N=U=>t.eql(U,t.ZERO);return N(D)&&N(V)?w.ZERO:new w(D,V,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(b){let D=es(t,b.map(V=>V.pz));return b.map((V,N)=>V.toAffine(D[N])).map(w.fromAffine)}static fromHex(b){let D=w.fromAffine(i(Oe("pointHex",b)));return D.assertValidity(),D}static fromPrivateKey(b){return w.BASE.multiply(p(b))}static msm(b,D){return Wu(w,n,b,D)}_setWindowSize(b){Y.setWindowSize(this,b)}assertValidity(){g(this)}hasEvenY(){let{y:b}=this.toAffine();if(t.isOdd)return!t.isOdd(b);throw new Error("Field doesn't support isOdd")}equals(b){m(b);let{px:D,py:V,pz:N}=this,{px:U,py:$,pz:X}=b,M=t.eql(t.mul(D,X),t.mul(U,N)),G=t.eql(t.mul(V,X),t.mul($,N));return M&&G}negate(){return new w(this.px,t.neg(this.py),this.pz)}double(){let{a:b,b:D}=e,V=t.mul(D,zh),{px:N,py:U,pz:$}=this,X=t.ZERO,M=t.ZERO,G=t.ZERO,F=t.mul(N,N),ie=t.mul(U,U),k=t.mul($,$),R=t.mul(N,U);return R=t.add(R,R),G=t.mul(N,$),G=t.add(G,G),X=t.mul(b,G),M=t.mul(V,k),M=t.add(X,M),X=t.sub(ie,M),M=t.add(ie,M),M=t.mul(X,M),X=t.mul(R,X),G=t.mul(V,G),k=t.mul(b,k),R=t.sub(F,k),R=t.mul(b,R),R=t.add(R,G),G=t.add(F,F),F=t.add(G,F),F=t.add(F,k),F=t.mul(F,R),M=t.add(M,F),k=t.mul(U,$),k=t.add(k,k),F=t.mul(k,R),X=t.sub(X,F),G=t.mul(k,ie),G=t.add(G,G),G=t.add(G,G),new w(X,M,G)}add(b){m(b);let{px:D,py:V,pz:N}=this,{px:U,py:$,pz:X}=b,M=t.ZERO,G=t.ZERO,F=t.ZERO,ie=e.a,k=t.mul(e.b,zh),R=t.mul(D,U),K=t.mul(V,$),P=t.mul(N,X),y=t.add(D,V),C=t.add(U,$);y=t.mul(y,C),C=t.add(R,K),y=t.sub(y,C),C=t.add(D,N);let L=t.add(U,X);return C=t.mul(C,L),L=t.add(R,P),C=t.sub(C,L),L=t.add(V,N),M=t.add($,X),L=t.mul(L,M),M=t.add(K,P),L=t.sub(L,M),F=t.mul(ie,C),M=t.mul(k,P),F=t.add(M,F),M=t.sub(K,F),F=t.add(K,F),G=t.mul(M,F),K=t.add(R,R),K=t.add(K,R),P=t.mul(ie,P),C=t.mul(k,C),K=t.add(K,P),P=t.sub(R,P),P=t.mul(ie,P),C=t.add(C,P),R=t.mul(K,C),G=t.add(G,R),R=t.mul(L,C),M=t.mul(y,M),M=t.sub(M,R),R=t.mul(y,K),F=t.mul(L,F),F=t.add(F,R),new w(M,G,F)}subtract(b){return this.add(b.negate())}is0(){return this.equals(w.ZERO)}wNAF(b){return Y.wNAFCached(this,b,w.normalizeZ)}multiplyUnsafe(b){let{endo:D,n:V}=e;At("scalar",b,dn,V);let N=w.ZERO;if(b===dn)return N;if(this.is0()||b===ct)return this;if(!D||Y.hasPrecomputes(this))return Y.wNAFCachedUnsafe(this,b,w.normalizeZ);let{k1neg:U,k1:$,k2neg:X,k2:M}=D.splitScalar(b),G=N,F=N,ie=this;for(;$>dn||M>dn;)$&ct&&(G=G.add(ie)),M&ct&&(F=F.add(ie)),ie=ie.double(),$>>=ct,M>>=ct;return U&&(G=G.negate()),X&&(F=F.negate()),F=new w(t.mul(F.px,D.beta),F.py,F.pz),G.add(F)}multiply(b){let{endo:D,n:V}=e;At("scalar",b,ct,V);let N,U;if(D){let{k1neg:$,k1:X,k2neg:M,k2:G}=D.splitScalar(b),{p:F,f:ie}=this.wNAF(X),{p:k,f:R}=this.wNAF(G);F=Y.constTimeNegate($,F),k=Y.constTimeNegate(M,k),k=new w(t.mul(k.px,D.beta),k.py,k.pz),N=F.add(k),U=ie.add(R)}else{let{p:$,f:X}=this.wNAF(b);N=$,U=X}return w.normalizeZ([N,U])[0]}multiplyAndAddUnsafe(b,D,V){let N=w.BASE,U=(X,M)=>M===dn||M===ct||!X.equals(N)?X.multiplyUnsafe(M):X.multiply(M),$=U(this,D).add(U(b,V));return $.is0()?void 0:$}toAffine(b){return v(this,b)}isTorsionFree(){let{h:b,isTorsionFree:D}=e;if(b===ct)return!0;if(D)return D(w,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:b,clearCofactor:D}=e;return b===ct?this:D?D(w,this):this.multiplyUnsafe(e.h)}toRawBytes(b=!0){return jr("isCompressed",b),this.assertValidity(),o(w,this,b)}toHex(b=!0){return jr("isCompressed",b),Gn(this.toRawBytes(b))}}w.BASE=new w(e.Gx,e.Gy,t.ONE),w.ZERO=new w(t.ZERO,t.ONE,t.ZERO);let{endo:S,nBitLength:O}=e,Y=Fu(w,S?Math.ceil(O/2):O);return{CURVE:e,ProjectivePoint:w,normPrivateKeyToScalar:p,weierstrassEquation:s,isWithinCurveOrder:h}}function jE(r){let e=Sa(r);return br(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function M0(r){let e=jE(r),{Fp:t,n,nByteLength:o,nBitLength:i}=e,s=t.BYTES+1,a=2*t.BYTES+1;function c(k){return Ce(k,n)}function f(k){return $u(k,n)}let{ProjectivePoint:h,normPrivateKeyToScalar:p,weierstrassEquation:m,isWithinCurveOrder:v}=UE({...e,toBytes(k,R,K){let P=R.toAffine(),y=t.toBytes(P.x),C=Xn;return jr("isCompressed",K),K?C(Uint8Array.from([R.hasEvenY()?2:3]),y):C(Uint8Array.from([4]),y,t.toBytes(P.y))},fromBytes(k){let R=k.length,K=k[0],P=k.subarray(1);if(R===s&&(K===2||K===3)){let y=fn(P);if(!Vu(y,ct,t.ORDER))throw new Error("Point is not on curve");let C=m(y),L;try{L=t.sqrt(C)}catch(le){let Q=le instanceof Error?": "+le.message:"";throw new Error("Point is not on curve"+Q)}let I=(L&ct)===ct;return(K&1)===1!==I&&(L=t.neg(L)),{x:y,y:L}}else if(R===a&&K===4){let y=t.fromBytes(P.subarray(0,t.BYTES)),C=t.fromBytes(P.subarray(t.BYTES,2*t.BYTES));return{x:y,y:C}}else{let y=s,C=a;throw new Error("invalid Point, expected length of "+y+", or uncompressed "+C+", got "+R)}}});function g(k){let R=n>>ct;return k>R}function w(k){return g(k)?c(-k):k}let S=(k,R,K)=>fn(k.slice(R,K));class O{constructor(R,K,P){At("r",R,ct,n),At("s",K,ct,n),this.r=R,this.s=K,P!=null&&(this.recovery=P),Object.freeze(this)}static fromCompact(R){let K=o;return R=Oe("compactSignature",R,K*2),new O(S(R,0,K),S(R,K,2*K))}static fromDER(R){let{r:K,s:P}=hn.toSig(Oe("DER",R));return new O(K,P)}assertValidity(){}addRecoveryBit(R){return new O(this.r,this.s,R)}recoverPublicKey(R){let{r:K,s:P,recovery:y}=this,C=N(Oe("msgHash",R));if(y==null||![0,1,2,3].includes(y))throw new Error("recovery id invalid");let L=y===2||y===3?K+e.n:K;if(L>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let I=(y&1)===0?"02":"03",re=h.fromHex(I+Gh(L,t.BYTES)),le=f(L),Q=c(-C*le),pe=c(P*le),he=h.BASE.multiplyAndAddUnsafe(re,Q,pe);if(!he)throw new Error("point at infinify");return he.assertValidity(),he}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new O(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return Aa(this.toDERHex())}toDERHex(){return hn.hexFromSig(this)}toCompactRawBytes(){return Aa(this.toCompactHex())}toCompactHex(){let R=o;return Gh(this.r,R)+Gh(this.s,R)}}let Y={isValidPrivateKey(k){try{return p(k),!0}catch{return!1}},normPrivateKeyToScalar:p,randomPrivateKey:()=>{let k=lh(e.n);return o0(e.randomBytes(k),e.n)},precompute(k=8,R=h.BASE){return R._setWindowSize(k),R.multiply(BigInt(3)),R}};function T(k,R=!0){return h.fromPrivateKey(k).toRawBytes(R)}function b(k){if(typeof k=="bigint")return!1;if(k instanceof h)return!0;let K=Oe("key",k).length,P=t.BYTES,y=P+1,C=2*P+1;if(!(e.allowedPrivateKeyLengths||o===y))return K===y||K===C}function D(k,R,K=!0){if(b(k)===!0)throw new Error("first arg must be private key");if(b(R)===!1)throw new Error("second arg must be public key");return h.fromHex(R).multiply(p(k)).toRawBytes(K)}let V=e.bits2int||function(k){if(k.length>8192)throw new Error("input is too large");let R=fn(k),K=k.length*8-i;return K>0?R>>BigInt(K):R},N=e.bits2int_modN||function(k){return c(V(k))},U=jo(i);function $(k){return At("num < 2^"+i,k,dn,U),Uo(k,o)}function X(k,R,K=M){if(["recovered","canonical"].some(_e=>_e in K))throw new Error("sign() legacy options not supported");let{hash:P,randomBytes:y}=e,{lowS:C,prehash:L,extraEntropy:I}=K;C==null&&(C=!0),k=Oe("msgHash",k),j0(K),L&&(k=Oe("prehashed msgHash",P(k)));let re=N(k),le=p(R),Q=[$(le),$(re)];if(I!=null&&I!==!1){let _e=I===!0?y(t.BYTES):I;Q.push(Oe("extraEntropy",_e))}let pe=Xn(...Q),he=re;function Ee(_e){let ke=V(_e);if(!v(ke))return;let ut=f(ke),Ue=h.BASE.multiply(ke).toAffine(),et=c(Ue.x);if(et===dn)return;let Tt=c(ut*c(he+et*le));if(Tt===dn)return;let Bt=(Ue.x===et?0:2)|Number(Ue.y&ct),Un=Tt;return C&&g(Tt)&&(Un=w(Tt),Bt^=1),new O(et,Un,Bt)}return{seed:pe,k2sig:Ee}}let M={lowS:e.lowS,prehash:!1},G={lowS:e.lowS,prehash:!1};function F(k,R,K=M){let{seed:P,k2sig:y}=X(k,R,K),C=e;return Yg(C.hash.outputLen,C.nByteLength,C.hmac)(P,y)}h.BASE._setWindowSize(8);function ie(k,R,K,P=G){let y=k;R=Oe("msgHash",R),K=Oe("publicKey",K);let{lowS:C,prehash:L,format:I}=P;if(j0(P),"strict"in P)throw new Error("options.strict was renamed to lowS");if(I!==void 0&&I!=="compact"&&I!=="der")throw new Error("format must be compact or der");let re=typeof y=="string"||Ji(y),le=!re&&!I&&typeof y=="object"&&y!==null&&typeof y.r=="bigint"&&typeof y.s=="bigint";if(!re&&!le)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let Q,pe;try{if(le&&(Q=new O(y.r,y.s)),re){try{I!=="compact"&&(Q=O.fromDER(y))}catch(Bt){if(!(Bt instanceof hn.Err))throw Bt}!Q&&I!=="der"&&(Q=O.fromCompact(y))}pe=h.fromHex(K)}catch{return!1}if(!Q||C&&Q.hasHighS())return!1;L&&(R=e.hash(R));let{r:he,s:Ee}=Q,_e=N(R),ke=f(Ee),ut=c(_e*ke),Ue=c(he*ke),et=h.BASE.multiplyAndAddUnsafe(pe,ut,Ue)?.toAffine();return et?c(et.x)===he:!1}return{CURVE:e,getPublicKey:T,getSharedSecret:D,sign:F,verify:ie,ProjectivePoint:h,Signature:O,utils:Y}}function ME(r){return{hash:r,hmac:(e,...t)=>os(r,e,Jp(...t)),randomBytes:ga}}function K0(r,e){let t=n=>M0({...r,...ME(n)});return{...t(e),create:t}}var $0=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),H0=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),KE=BigInt(0),HE=BigInt(1),Yh=BigInt(2),V0=(r,e)=>(r+e/Yh)/e;function VE(r){let e=$0,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%e,h=f*f*r%e,p=Me(h,t,e)*h%e,m=Me(p,t,e)*h%e,v=Me(m,Yh,e)*f%e,g=Me(v,o,e)*v%e,w=Me(g,i,e)*g%e,S=Me(w,a,e)*w%e,O=Me(S,c,e)*S%e,Y=Me(O,a,e)*w%e,T=Me(Y,t,e)*h%e,b=Me(T,s,e)*g%e,D=Me(b,n,e)*f%e,V=Me(D,Yh,e);if(!Zh.eql(Zh.sqr(V),r))throw new Error("Cannot find square root");return V}var Zh=pn($0,void 0,void 0,{sqrt:VE}),Cr=K0({a:KE,b:BigInt(7),Fp:Zh,n:H0,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=H0,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-HE*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=V0(i*r,e),c=V0(-n*r,e),f=Ce(r-a*t-c*o,e),h=Ce(-a*n-c*i,e),p=f>s,m=h>s;if(p&&(f=e-f),m&&(h=e-h),f>s||h>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:p,k1:f,k2neg:m,k2:h}}}},Hu);function Jh(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function F0(r,e){let t=tr.digest(e instanceof Uint8Array?e:e.subarray());if(Jh(t))return t.then(({digest:n})=>Cr.sign(n,r).toDERRawBytes()).catch(n=>{throw new Oa(String(n))});try{return Cr.sign(t.digest,r).toDERRawBytes()}catch(n){throw new Oa(String(n))}}function W0(r,e,t){let n=tr.digest(t instanceof Uint8Array?t:t.subarray());if(Jh(n))return n.then(({digest:o})=>Cr.verify(e,o,r)).catch(o=>{throw new Ra(String(o))});try{return Cr.verify(e,n.digest,r)}catch(o){throw new Ra(String(o))}}var Ua=class{type="secp256k1";raw;_key;constructor(e){this._key=z0(e),this.raw=q0(this._key)}toMultihash(){return yr.digest(Vn(this))}toCID(){return Xe.createV1(114,this.toMultihash())}toString(){return Pe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}verify(e,t){return W0(this._key,t,e)}},rl=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=G0(e),this.publicKey=new Ua(t??X0(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}sign(e){return F0(this.raw,e)}};function Qh(r){return new Ua(r)}async function Y0(){let r=$E();return new rl(r)}function q0(r){return Cr.ProjectivePoint.fromHex(r).toRawBytes(!0)}function G0(r){try{return Cr.getPublicKey(r,!0),r}catch(e){throw new ca(String(e))}}function z0(r){try{return Cr.ProjectivePoint.fromHex(r),r}catch(e){throw new Fi(String(e))}}function X0(r){try{return Cr.getPublicKey(r,!0)}catch(e){throw new ca(String(e))}}function $E(){return Cr.utils.randomPrivateKey()}async function Z0(r,e){if(r==="Ed25519")return v0();if(r==="secp256k1")return Y0();if(r==="RSA")return qh(FE(e));if(r==="ECDSA")return kg(WE(e));throw new jn}function ja(r,e){let{Type:t,Data:n}=Vr.decode(r),o=n??new Uint8Array;switch(t){case Ye.RSA:return $h(o,e);case Ye.Ed25519:return gh(o);case Ye.secp256k1:return Qh(o);case Ye.ECDSA:return Zp(o);default:throw new jn}}function J0(r){let{Type:e,Data:t}=Vr.decode(r.digest),n=t??new Uint8Array;switch(e){case Ye.Ed25519:return gh(n);case Ye.secp256k1:return Qh(n);case Ye.ECDSA:return Zp(n);default:throw new jn}}function Vn(r){return Vr.encode({Type:Ye[r.type],Data:r.raw})}function FE(r){return r==null?2048:parseInt(r,10)}function WE(r){if(r==="P-256"||r==null)return"P-256";if(r==="P-384")return"P-384";if(r==="P-521")return"P-521";throw new Ae("Unsupported curve, should be P-256, P-384 or P-521")}async function nl(r){if(r.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(r.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"ECDSA",namedCurve:r.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"ECDSA",namedCurve:r.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new Ae("Only RSA and ECDSA keys are supported")}var Q0=Symbol.for("nodejs.util.inspect.custom"),qE=114,Ma=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Ep]=!0;toString(){return this.string==null&&(this.string=Pe.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Xe.createV1(qE,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Fe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return Fe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Q0](){return`PeerId(${this.toString()})`}},Ka=class extends Ma{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Ha=class extends Ma{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Va=class extends Ma{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},GE=2336,$a=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=yr.digest(de(this.url))}[Q0](){return`PeerId(${this.url})`}[Ep]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Xe.createV1(GE,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ue(e)),e.toString()===this.toString())}};var zE=114,ew=2336;function is(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=Hn(Pe.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return XE(Xe.parse(r));if(e==null)throw new Ae('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=Hn(e.decode(r))}return tw(t)}function ed(r){if(r.type==="Ed25519")return new Ha({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Va({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new Ka({multihash:r.toCID().multihash,publicKey:r});throw new jn}function tw(r){if(ZE(r))return new Ka({multihash:r});if(YE(r))try{let e=J0(r);if(e.type==="Ed25519")return new Ha({multihash:r,publicKey:e});if(e.type==="secp256k1")return new Va({multihash:r,publicKey:e})}catch{let t=ue(r.digest);return new $a(new URL(t))}throw new Bu("Supplied PeerID Multihash is invalid")}function XE(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==zE&&r.code!==ew)throw new Tu("Supplied PeerID CID is invalid");if(r.code===ew){let e=ue(r.multihash.digest);return new $a(new URL(e))}return tw(r.multihash)}function YE(r){return r.code===yr.code}function ZE(r){return r.code===tr.code}var ol=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let p=this.readChar();if(p===void 0)return;let m=Number.parseInt(p,e);if(!Number.isNaN(m))return m});if(h===void 0)break;if(i*=e,i+=h,i>f||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var rw=45,JE=15,ss=new ol;function td(r){if(!(r.length>JE))return ss.new(r).parseWith(()=>ss.readIPv4Addr())}function rd(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>rw))return ss.new(r).parseWith(()=>ss.readIPv6Addr())}function il(r,e=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>rw)return;let t=ss.new(r).parseWith(()=>ss.readIPAddr());if(t)return e&&t.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,t[0],t[1],t[2],t[3]]):t}var u4=parseInt("0xFFFF",16),l4=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function sl(r){return!!td(r)}function al(r){return!!rd(r)}function cl(r){return!!il(r)}var iw=sl,n2=al,nd=function(r){let e=0;if(r=r.toString().trim(),iw(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(n2(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=iw(t[n]),s;i&&(s=nd(t[n]),t[n]=ue(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,ue(s.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);o[e++]=i>>8&255,o[e++]=i&255}return o}throw new Error("invalid ip address")},sw=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let i=0;i<t;i++)o.push(r[e+i]);return o.join(".")}if(t===16){let o=[];for(let i=0;i<t;i+=2)o.push(n.getUint16(e+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var as={},od={},i2=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];i2.forEach(r=>{let e=s2(...r);od[e.code]=e,as[e.name]=e});function s2(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function Re(r){if(typeof r=="number"){if(od[r]!=null)return od[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(as[r]!=null)return as[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var G4=Re("ip4"),z4=Re("ip6"),X4=Re("ipcidr");function cd(r,e){switch(Re(r).code){case 4:case 41:return c2(e);case 42:return ad(e);case 43:return ue(e,"base10");case 6:case 273:case 33:case 132:return uw(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ad(e);case 421:return p2(e);case 444:return cw(e);case 445:return cw(e);case 466:return f2(e);case 481:return globalThis.encodeURIComponent(ad(e));default:return ue(e,"base16")}}function ud(r,e){switch(Re(r).code){case 4:return aw(e);case 41:return aw(e);case 42:return sd(e);case 43:return de(e,"base10");case 6:case 273:case 33:case 132:return ld(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return sd(e);case 421:return u2(e);case 444:return h2(e);case 445:return d2(e);case 466:return l2(e);case 481:return sd(globalThis.decodeURIComponent(e));default:return de(e,"base16")}}var id=Object.values(Po).map(r=>r.decoder),a2=function(){let r=id[0].or(id[1]);return id.slice(2).forEach(e=>r=r.or(e)),r}();function aw(r){if(!cl(r))throw new Error("invalid ip address");return nd(r)}function c2(r){let e=sw(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!cl(e))throw new Error("invalid ip address");return e}function ld(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function uw(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function sd(r){let e=de(r),t=Uint8Array.from(Hr(e.length));return ot([t,e],t.length+e.length)}function ad(r){let e=vr(r);if(r=r.slice(Ke(e)),r.length!==e)throw new Error("inconsistent lengths");return ue(r)}function u2(r){let e;r[0]==="Q"||r[0]==="1"?e=Hn(Pe.decode(`z${r}`)).bytes:e=Xe.parse(r).multihash.bytes;let t=Uint8Array.from(Hr(e.length));return ot([t,e],t.length+e.length)}function l2(r){let e=a2.decode(r),t=Uint8Array.from(Hr(e.length));return ot([t,e],t.length+e.length)}function f2(r){let e=vr(r),t=r.slice(Ke(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+ue(t,"base64url")}function p2(r){let e=vr(r),t=r.slice(Ke(e));if(t.length!==e)throw new Error("inconsistent lengths");return ue(t,"base58btc")}function h2(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=an.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ld(n);return ot([t,o],t.length+o.length)}function d2(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=an.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ld(n);return ot([t,o],t.length+o.length)}function cw(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=ue(e,"base32"),o=uw(t);return`${n}:${o}`}function lw(r){r=fd(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let s=o[i],a=Re(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=o.length)throw new ul("invalid address: "+r);if(a.path===!0){n=fd(o.slice(i).join("/")),e.push([a.code,ud(a.code,n)]),t.push([a.code,n]);break}let c=ud(a.code,o[i]);e.push([a.code,c]),t.push([a.code,cd(a.code,c)])}return{string:fw(t),bytes:ll(e),tuples:e,stringTuples:t,path:n}}function pd(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let i=vr(r,o),s=Ke(i),a=Re(i),c=m2(a,r.slice(o+s));if(c===0){e.push([i]),t.push([i]),o+=s;continue}let f=r.slice(o+s,o+s+c);if(o+=c+s,o>r.length)throw new ul("Invalid address Uint8Array: "+ue(r,"base16"));e.push([i,f]);let h=cd(i,f);if(t.push([i,h]),a.path===!0){n=h;break}}return{bytes:Uint8Array.from(r),string:fw(t),tuples:e,stringTuples:t,path:n}}function fw(r){let e=[];return r.map(t=>{let n=Re(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),fd(e.join("/"))}function ll(r){return ot(r.map(e=>{let t=Re(e[0]),n=Uint8Array.from(Hr(t.code));return e.length>1&&e[1]!=null&&(n=ot([n,e[1]])),n}))}function m2(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=vr(e instanceof Uint8Array?e:Uint8Array.from(e));return t+Ke(t)}}function fd(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}var ul=class extends Error{static name="ParseError";name="ParseError";constructor(e){super(`Error parsing address: ${e}`)}};var y2=Symbol.for("nodejs.util.inspect.custom"),dd=Symbol.for("@multiformats/js-multiaddr/multiaddr"),g2=[Re("dns").code,Re("dns4").code,Re("dns6").code,Re("dnsaddr").code],hd=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},fl=class r{bytes;#e;#t;#r;#n;[dd]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=pd(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=lw(e)}else if(hw(e))t=pd(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,i="",s=Re("tcp"),a=Re("udp"),c=Re("ip4"),f=Re("ip6"),h=Re("dns6"),p=Re("ip6zone");for(let[v,g]of this.stringTuples())v===p.code&&(i=`%${g??""}`),g2.includes(v)&&(t=s.name==="tcp"?"tcp":"udp",o=443,n=`${g??""}${i}`,e=v===h.code?6:4),(v===s.code||v===a.code)&&(t=Re(v).name==="tcp"?"tcp":"udp",o=parseInt(g??"")),(v===c.code||v===f.code)&&(t=Re(v).name==="tcp"?"tcp":"udp",n=`${g??""}${i}`,e=v===f.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},Re(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>Re(e).name)}tuples(){return this.#t.map(([e,t])=>t==null?[e]:[e,t])}stringTuples(){return this.#r.map(([e,t])=>t==null?[e]:[e,t])}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(ll(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===as.p2p.code&&e.push([n,o]),n===as["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?ue(Pe.decode(`z${n}`),"base58btc"):ue(Xe.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return Fe(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=pw.get(t.name);if(n==null)throw new hd(`no available resolver for ${t.name}`);return(await n(this,e)).map(i=>$r(i))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[y2](){return`Multiaddr(${this.#e})`}};var pw=new Map;function hw(r){return!!r?.[dd]}function $r(r){return new fl(r)}var w2=r=>r.toString().split("/").slice(1),cs=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),ye=r=>({match:e=>cs(t=>t===r).match(e),pattern:r}),$o=()=>({match:r=>cs(e=>typeof e=="string").match(r),pattern:"{string}"}),us=()=>({match:r=>cs(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),Be=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{Pe.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Fa=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{ko.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),Ie=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),_t=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),ve=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${r.map(e=>e.pattern).join(", ")})`});function De(...r){function e(o){let i=w2(o);for(let s of r){let a=s.match(i);if(a===!1)return!1;i=a}return i}function t(o){return e(o)!==!1}function n(o){let i=e(o);return i===!1?!1:i.length===0}return{matchers:r,matches:t,exactMatch:n}}var x2=Be(),C5=De(x2),hl=ve(ye("dns4"),$o()),dl=ve(ye("dns6"),$o()),ml=ve(ye("dnsaddr"),$o()),yd=ve(ye("dns"),$o()),I5=De(hl,Ie(Be())),T5=De(dl,Ie(Be())),B5=De(ml,Ie(Be())),k5=De(_t(yd,ml,hl,dl),Ie(Be())),dw=ve(ye("ip4"),cs(sl)),mw=ve(ye("ip6"),cs(al)),gd=_t(dw,mw),mn=_t(gd,yd,hl,dl,ml),P5=De(_t(gd,ve(_t(yd,ml,hl,dl),Ie(Be())))),N5=De(dw),O5=De(mw),R5=De(gd),wd=ve(mn,ye("tcp"),us()),Wa=ve(mn,ye("udp"),us()),D5=De(ve(wd,Ie(Be()))),L5=De(Wa),xd=ve(Wa,ye("quic"),Ie(Be())),yl=ve(Wa,ye("quic-v1"),Ie(Be())),b2=_t(xd,yl),U5=De(xd),j5=De(yl),md=_t(mn,wd,Wa,xd,yl),yw=_t(ve(md,ye("ws"),Ie(Be()))),M5=De(yw),gw=_t(ve(md,ye("wss"),Ie(Be())),ve(md,ye("tls"),Ie(ve(ye("sni"),$o())),ye("ws"),Ie(Be()))),K5=De(gw),ww=ve(Wa,ye("webrtc-direct"),Ie(Fa()),Ie(Fa()),Ie(Be())),xw=De(ww),bw=ve(yl,ye("webtransport"),Ie(Fa()),Ie(Fa()),Ie(Be())),H5=De(bw),pl=_t(yw,gw,ve(wd,Ie(Be())),ve(b2,Ie(Be())),ve(mn,Ie(Be())),ww,bw,Be()),vw=De(pl),v2=ve(pl,ye("p2p-circuit"),Be()),V5=De(v2),A2=_t(ve(pl,ye("p2p-circuit"),ye("webrtc"),Ie(Be())),ve(pl,ye("webrtc"),Ie(Be())),ve(ye("webrtc"),Ie(Be()))),Aw=De(A2),S2=_t(ve(mn,ye("tcp"),us(),ye("http"),Ie(Be())),ve(mn,ye("http"),Ie(Be()))),$5=De(S2),E2=_t(ve(mn,ye("tcp"),_t(ve(ye("443"),ye("http")),ve(us(),ye("https")),ve(us(),ye("tls"),ye("http"))),Ie(Be())),ve(mn,ye("tls"),ye("http"),Ie(Be())),ve(mn,ye("https"),Ie(Be()))),F5=De(E2),_2=_t(ve(ye("memory"),$o(),Ie(Be()))),W5=De(_2);var Ct;(function(r){let e;(function(o){o.FIN="FIN",o.STOP_SENDING="STOP_SENDING",o.RESET="RESET",o.FIN_ACK="FIN_ACK"})(e=r.Flag||(r.Flag={}));let t;(function(o){o[o.FIN=0]="FIN",o[o.STOP_SENDING=1]="STOP_SENDING",o[o.RESET=2]="RESET",o[o.FIN_ACK=3]="FIN_ACK"})(t||(t={})),function(o){o.codec=()=>Vo(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=_r((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.flag!=null&&(i.uint32(8),r.Flag.codec().encode(o.flag,i)),o.message!=null&&(i.uint32(18),i.bytes(o.message)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let f=o.uint32();switch(f>>>3){case 1:{a.flag=r.Flag.codec().decode(o);break}case 2:{a.message=o.bytes();break}default:{o.skipType(f&7);break}}}return a})),n),r.encode=o=>Er(o,r.codec()),r.decode=(o,i)=>Sr(o,r.codec(),i)})(Ct||(Ct={}));var Sw=["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478"],bd=Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"),Ew="libp2p+webrtc+v1/";var _w=466,Cw=2*1024*1024,Iw=30*1e3,ls=16*1024;function C2(r=ls){let e=Ke(r-Ke(r)),t=1+Ke(Object.keys(Ct.Flag).length-1),n=1,o=r-e-t-n,i=Ke(o);return e+t+n+i}var Tw=C2(),Bw=5e3,kw=5e3,Pw=3e4,vd="/webrtc",qa="/webrtc-signaling/0.0.1",Nw="/libp2p/webrtc-direct/certificate",Ow="webrtc-direct-certificate-private-key";var Rw=12096e5,Ad=864e5;var Dw=function(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,i;n<o;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return r.concat(i||Array.prototype.slice.call(e))},I2=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var T2=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var B2=function(){function r(e,t,n,o){this.name=e,this.version=t,this.os=n,this.bot=o,this.type="bot-device"}return r}();var k2=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var P2=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var N2=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,O2=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,Lw=3,R2=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["edge-ios",/EdgiOS\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["silk",/\bSilk\/([0-9._-]+)\b/],["miui",/MiuiBrowser\/([0-9\.]+)$/],["beaker",/BeakerBrowser\/([0-9\.]+)/],["edge-chromium",/EdgA?\/([0-9\.]+)/],["chromium-webview",/(?!Chrom.*OPR)wv\).*Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera-mini",/Opera Mini.*Version\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)/],["pie",/^Microsoft Pocket Internet Explorer\/(\d+\.\d+)$/],["pie",/^Mozilla\/\d\.\d+\s\(compatible;\s(?:MSP?IE|MSInternet Explorer) (\d+\.\d+);.*Windows CE.*\)$/],["netfront",/^Mozilla\/\d\.\d+.*NetFront\/(\d.\d)/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FB[AS]V\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Gecko\)$/],["curl",/^curl\/([0-9\.]+)$/],["searchbot",N2]],Uw=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Windows CE",/Windows CE|WinCE|Microsoft Pocket Internet Explorer/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Chrome OS",/CrOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/]];function Mw(r){return r?jw(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new P2:typeof navigator<"u"?jw(navigator.userAgent):U2()}function D2(r){return r!==""&&R2.reduce(function(e,t){var n=t[0],o=t[1];if(e)return e;var i=o.exec(r);return!!i&&[n,i]},!1)}function jw(r){var e=D2(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new k2;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<Lw&&(o=Dw(Dw([],o,!0),j2(Lw-o.length),!0)):o=[];var i=o.join("."),s=L2(r),a=O2.exec(r);return a&&a[1]?new B2(t,i,s,a[1]):new I2(t,i,s)}function L2(r){for(var e=0,t=Uw.length;e<t;e++){var n=Uw[e],o=n[0],i=n[1],s=i.exec(r);if(s)return o}return null}function U2(){var r=typeof process<"u"&&process.version;return r?new T2(process.version.slice(1)):null}function j2(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function Ze(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Sd=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ed=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Kw=r=>globalThis.DOMException===void 0?new Ed(r):new DOMException(r),Hw=r=>{let e=r.reason===void 0?Kw("This operation was aborted."):r.reason;return e instanceof Error?e:Kw(e)};function Ga(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,f=new Promise((h,p)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:v}=e;v.aborted&&p(Hw(v)),a=()=>{p(Hw(v))},v.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(h,p);return}let m=new Sd;s=i.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(v){p(v)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?p(o):(m.message=o??`Promise timed out after ${t} milliseconds`,p(m))},t),(async()=>{try{h(await r)}catch(v){p(v)}})()}).finally(()=>{f.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return f.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},f}var Vw=Mw(),za=Vw!=null&&Vw.name==="firefox",gl=async function*(){},wl=async r=>{};function $w(r,e,t=Pw,n){r.readyState==="open"&&Promise.resolve().then(async()=>{if(r.bufferedAmount>0){n.log("%s drain channel with %d buffered bytes",e,r.bufferedAmount);let o=Ze(),i=!1;r.bufferedAmountLowThreshold=0;let s=()=>{i||(n.log("%s drain channel closed before drain",e),o.resolve())};r.addEventListener("close",s,{once:!0}),r.addEventListener("bufferedamountlow",()=>{i=!0,r.removeEventListener("close",s),o.resolve()}),await Ga(o.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(o=>{n.log.error("error closing outbound stream",o)})}async function _d(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??Sw.map(e=>({urls:[e]})),r}var Fw=(r=32)=>Ew+[...Array(r)].map(()=>bd.at(Math.floor(Math.random()*bd.length))).join("");var Fo=class{log;peerConnection;remoteAddr;timeline;metrics;source=gl();sink=wl;constructor(e,t){this.log=e.logger.forComponent("libp2p:webrtc:maconn"),this.remoteAddr=t.remoteAddr,this.timeline=t.timeline,this.peerConnection=t.peerConnection;let n=this.peerConnection,o=n.connectionState;this.peerConnection.onconnectionstatechange=()=>{this.log.trace("peer connection state change",n.connectionState,"initial state",o),(n.connectionState==="disconnected"||n.connectionState==="failed"||n.connectionState==="closed")&&(this.timeline.close=Date.now())}}async close(e){this.log.trace("closing connection"),this.peerConnection.close(),this.timeline.close=Date.now(),this.metrics?.increment({close:!0})}abort(e){this.log.error("closing connection due to error",e),this.peerConnection.close(),this.timeline.close=Date.now(),this.metrics?.increment({abort:!0})}};var xl=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},fs=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new xl(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new xl(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Cd=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function ps(r={}){return M2(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function M2(r,e){e=e??{};let t=e.onEnd,n=new fs,o,i,s,a=Ze(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((S,O)=>{i=Y=>{i=null,n.push(Y);try{S(r(n))}catch(T){O(T)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ze()})}},f=S=>i!=null?i(S):(n.push(S),o),h=S=>(n=new fs,i!=null?i({error:S}):(n.push({error:S}),o)),p=S=>{if(s)return o;if(e?.objectMode!==!0&&S?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:S})},m=S=>s?o:(s=!0,S!=null?h(S):f({done:!0})),v=()=>(n=new fs,m(),{done:!0}),g=S=>(m(S),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:v,throw:g,push:p,end:m,get readableLength(){return n.size},onEmpty:async S=>{let O=S?.signal;if(O?.throwIfAborted(),n.isEmpty())return;let Y,T;O!=null&&(Y=new Promise((b,D)=>{T=()=>{D(new Cd)},O.addEventListener("abort",T)}));try{await Promise.race([a.promise,Y])}finally{T!=null&&O!=null&&O?.removeEventListener("abort",T)}}},t==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(S){return w.throw(S),t!=null&&(t(S),t=void 0),{done:!0}},return(){return w.return(),t!=null&&(t(),t=void 0),{done:!0}},push:p,end(S){return w.end(S),t!=null&&(t(S),t=void 0),o},get readableLength(){return w.readableLength},onEmpty:S=>w.onEmpty(S)},o}var bl=class extends Error{type;code;constructor(e,t,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=t??"ABORT_ERR"}};async function rr(r,e,t){if(e==null)return r;if(e.aborted)return r.catch(()=>{}),Promise.reject(new bl(t?.errorMessage,t?.errorCode,t?.errorName));let n,o=new bl(t?.errorMessage,t?.errorCode,t?.errorName);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}function Ww(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function qw(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Gw(r,e){let t=Ww(r).return?.();qw(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var K2=5e3;function Id(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var vl=class{id;direction;timeline;protocol;metadata;source;status;readStatus;writeStatus;log;sinkController;sinkEnd;closed;endErr;streamSource;onEnd;onCloseRead;onCloseWrite;onReset;onAbort;sendCloseWriteTimeout;sendingData;constructor(e){this.sinkController=new AbortController,this.sinkEnd=Ze(),this.closed=Ze(),this.log=e.log,this.status="open",this.readStatus="ready",this.writeStatus="ready",this.id=e.id,this.metadata=e.metadata??{},this.direction=e.direction,this.timeline={open:Date.now()},this.sendCloseWriteTimeout=e.sendCloseWriteTimeout??K2,this.onEnd=e.onEnd,this.onCloseRead=e.onCloseRead,this.onCloseWrite=e.onCloseWrite,this.onReset=e.onReset,this.onAbort=e.onAbort,this.source=this.streamSource=ps({onEnd:t=>{t!=null?this.log.trace("source ended with error",t):this.log.trace("source ended"),this.onSourceEnd(t)}}),this.sink=this.sink.bind(this)}async sink(e){if(this.writeStatus!=="ready")throw new Io(`writable end state is "${this.writeStatus}" not "ready"`);try{this.writeStatus="writing";let t={signal:this.sinkController.signal};if(this.direction==="outbound"){let o=this.sendNewStream(t);Id(o)&&await o}let n=()=>{Gw(e,this.log)};try{this.sinkController.signal.addEventListener("abort",n),this.log.trace("sink reading from source");for await(let o of e){o=o instanceof Uint8Array?new be(o):o;let i=this.sendData(o,t);Id(i)&&(this.sendingData=Ze(),await i,this.sendingData.resolve(),this.sendingData=void 0)}}finally{this.sinkController.signal.removeEventListener("abort",n)}this.log.trace('sink finished reading from source, write status is "%s"',this.writeStatus),this.writeStatus==="writing"&&(this.writeStatus="closing",this.log.trace("send close write to remote"),await this.sendCloseWrite({signal:AbortSignal.timeout(this.sendCloseWriteTimeout)}),this.writeStatus="closed"),this.onSinkEnd()}catch(t){throw this.log.trace("sink ended with error, calling abort with error",t),this.abort(t),t}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(e){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),this.readStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(e){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),this.writeStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("sink ended, waiting for source to end"))}async close(e){this.status==="open"&&(this.log.trace("closing gracefully"),this.status="closing",await rr(Promise.all([this.closeWrite(e),this.closeRead(e),this.closed.promise]),e?.signal),this.status="closed",this.log.trace("closed gracefully"))}async closeRead(e={}){if(this.readStatus==="closing"||this.readStatus==="closed")return;this.log.trace('closing readable end of stream with starting read status "%s"',this.readStatus);let t=this.readStatus;this.readStatus="closing",this.status!=="reset"&&this.status!=="aborted"&&this.timeline.closeRead==null&&(this.log.trace("send close read to remote"),await this.sendCloseRead(e)),t==="ready"&&(this.log.trace("ending internal source queue with %d queued bytes",this.streamSource.readableLength),this.streamSource.end()),this.log.trace("closed readable end of stream")}async closeWrite(e={}){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.log.trace('closing writable end of stream with starting write status "%s"',this.writeStatus),this.writeStatus==="ready"&&(this.log.trace("sink was never sunk, sink an empty array"),await rr(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await rr(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await rr(this.sinkEnd.promise,e.signal)),this.writeStatus="closed",this.log.trace("closed writable end of stream"))}abort(e){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;this.log("abort with error",e),this.log("try to send reset to remote");let t=this.sendReset();Id(t)&&t.catch(n=>{this.log.error("error sending reset message",n)}),this.status="aborted",this.timeline.abort=Date.now(),this._closeSinkAndSource(e),this.onAbort?.(e)}reset(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;let e=new Iu("stream reset");this.status="reset",this.timeline.reset=Date.now(),this._closeSinkAndSource(e),this.onReset?.()}_closeSinkAndSource(e){this._closeSink(e),this._closeSource(e)}_closeSink(e){this.writeStatus==="writing"&&(this.log.trace("end sink source"),this.sinkController.abort()),this.onSinkEnd(e)}_closeSource(e){this.readStatus!=="closing"&&this.readStatus!=="closed"&&(this.log.trace("ending source with %d bytes to be read by consumer",this.streamSource.readableLength),this.readStatus="closing",this.streamSource.end(e))}remoteCloseWrite(){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("received remote close write but local source is already closed");return}this.log.trace("remote close write"),this._closeSource()}remoteCloseRead(){if(this.writeStatus==="closing"||this.writeStatus==="closed"){this.log("received remote close read but local sink is already closed");return}this.log.trace("remote close read"),this._closeSink()}destroy(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset"){this.log("received destroy but we are already closed");return}this.log.trace("stream destroyed"),this._closeSinkAndSource()}sourcePush(e){this.streamSource.push(e)}sourceReadableLength(){return this.streamSource.readableLength}};function Td(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}var Al=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},hs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Sl=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Xa=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function El(r){return r[Symbol.asyncIterator]!=null}function zw(r,e){if(r.byteLength>e)throw new hs("Message length too long")}var Cl=r=>{let e=Ke(r),t=nt(e);return Hr(r,t),Cl.bytes=e,t};Cl.bytes=0;function Ya(r,e){e=e??{};let t=e.lengthEncoder??Cl,n=e?.maxDataLength??4194304;function*o(i){zw(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return El(r)?async function*(){for await(let i of r)yield*o(i)}():function*(){for(let i of r)yield*o(i)}()}Ya.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??Cl,n=e?.maxDataLength??4194304;return zw(r,n),new be(t(r.byteLength),r)};var Wo;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Wo||(Wo={}));var Bd=r=>{let e=vr(r);return Bd.bytes=Ke(e),e};Bd.bytes=0;function qo(r,e){let t=new be,n=Wo.LENGTH,o=-1,i=e?.lengthDecoder??Bd,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===Wo.LENGTH)try{if(o=i(t),o<0)throw new Al("Invalid message length");if(o>a)throw new hs("Message length too long");let f=i.bytes;t.consume(f),e?.onLength!=null&&e.onLength(o),n=Wo.DATA}catch(f){if(f instanceof RangeError){if(t.byteLength>s)throw new Sl("Message length length too long");break}throw f}if(n===Wo.DATA){if(t.byteLength<o)break;let f=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(f),yield f,n=Wo.LENGTH}}}return El(r)?async function*(){for await(let f of r)t.append(f),yield*c();if(t.byteLength>0)throw new Xa("Unexpected end of input")}():function*(){for(let f of r)t.append(f),yield*c();if(t.byteLength>0)throw new Xa("Unexpected end of input")}()}qo.fromReader=(r,e)=>{let t=1,n=async function*(){for(;;)try{let{done:i,value:s}=await r.next(t);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{t=1}}();return qo(n,{...e??{},onLength:i=>{t=i}})};var kd=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Za(r,e,t,n){let o=new kd(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((i,s)=>{function a(){t?.removeEventListener("abort",h),r.removeEventListener(e,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,f)}let c=p=>{try{if(n?.filter?.(p)===!1)return}catch(m){a(),s(m);return}a(),i(p)},f=p=>{a(),s(p.detail)},h=()=>{a(),s(o)};t?.addEventListener("abort",h),r.addEventListener(e,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,f)})}var Pd=class extends vl{channel;incomingData;maxBufferedAmount;bufferedAmountLowEventTimeout;maxMessageSize;receiveFinAck;finAckTimeout;openTimeout;closeController;constructor(e){let t=e.onEnd;switch(e.onEnd=o=>{this.log.trace('readable and writeable ends closed with status "%s"',this.status),Promise.resolve(async()=>{if(!(this.timeline.abort!=null||this.timeline.reset!==null))try{await Ga(this.receiveFinAck.promise,{milliseconds:this.finAckTimeout})}catch(i){this.log.error("error receiving FIN_ACK",i)}}).then(()=>{this.incomingData.end(),t?.(o)}).catch(i=>{this.log.error("error ending stream",i)}).finally(()=>{this.channel.close()})},super(e),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=ps(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??Iw,this.maxBufferedAmount=e.maxBufferedAmount??Cw,this.maxMessageSize=(e.maxMessageSize??ls)-Tw,this.receiveFinAck=Ze(),this.finAckTimeout=e.closeTimeout??Bw,this.openTimeout=e.openTimeout??kw,this.closeController=new AbortController,this.channel.readyState){case"open":this.timeline.open=new Date().getTime();break;case"closed":case"closing":(this.timeline.close===void 0||this.timeline.close===0)&&(this.timeline.close=Date.now());break;case"connecting":break;default:throw this.log.error("unknown datachannel state %s",this.channel.readyState),new Io("Unknown datachannel state")}this.channel.onopen=o=>{this.timeline.open=new Date().getTime()},this.channel.onclose=o=>{this.log.trace("received onclose event"),this.closeController.abort(),this.receiveFinAck.resolve(),this.close().catch(i=>{this.log.error("error closing stream after channel closed",i)})},this.channel.onerror=o=>{this.log.trace("received onerror event"),this.closeController.abort();let i=o.error;this.abort(i)},this.channel.onmessage=async o=>{let{data:i}=o;i===null||i.byteLength===0||this.incomingData.push(new Uint8Array(i,0,i.byteLength))};let n=this;Promise.resolve().then(async()=>{for await(let o of qo(this.incomingData)){let i=n.processIncomingProtobuf(o);i!=null&&n.sourcePush(new be(i))}}).catch(o=>{this.log.error("error processing incoming data channel messages",o)})}sendNewStream(){}async _sendMessage(e,t=!0){if(this.channel.readyState==="closed"||this.channel.readyState==="closing")throw new Io(`Invalid datachannel state - ${this.channel.readyState}`);if(this.channel.readyState!=="open"){let n=AbortSignal.timeout(this.openTimeout),o=Td([this.closeController.signal,n]);try{this.log('channel state is "%s" and not "open", waiting for "open" event before sending data',this.channel.readyState),await Za(this.channel,"open",o)}finally{o.clear()}this.log('channel state is now "%s", sending data',this.channel.readyState)}if(t&&this.channel.bufferedAmount>this.maxBufferedAmount){let n=AbortSignal.timeout(this.bufferedAmountLowEventTimeout),o=Td([this.closeController.signal,n]);try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await Za(this.channel,"bufferedamountlow",o)}catch(i){throw n.aborted?new Pu(`Timed out waiting for DataChannel buffer to clear after ${this.bufferedAmountLowEventTimeout}ms`):i}finally{o.clear()}}try{this.log.trace('sending message, channel state "%s"',this.channel.readyState),this.channel.send(e.subarray())}catch(n){this.log.error("error while sending message",n)}}async sendData(e){let t=e.byteLength;for(e=e.sublist();e.byteLength>0;){let n=Math.min(e.byteLength,this.maxMessageSize),o=e.subarray(0,n),i=Ct.encode({message:o}),s=Ya.single(i);this.log.trace("sending %d/%d bytes on channel",o.byteLength,t),await this._sendMessage(s),e.consume(n)}this.log.trace('finished sending data, channel state "%s"',this.channel.readyState)}async sendReset(){try{await this._sendFlag(Ct.Flag.RESET)}catch(e){this.log.error("failed to send reset - %e",e)}finally{this.channel.close()}}async sendCloseWrite(e){if(this.channel.readyState!=="open"){this.receiveFinAck.resolve();return}if(await this._sendFlag(Ct.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await rr(this.receiveFinAck.promise,e?.signal,{errorMessage:"sending close-write was aborted before FIN_ACK was received",errorName:"FinAckNotReceivedError"})}catch(n){this.log.error("failed to await FIN_ACK",n)}}else this.log.trace("sending FIN failed, not awaiting FIN_ACK");this.receiveFinAck.resolve()}async sendCloseRead(){this.channel.readyState==="open"&&await this._sendFlag(Ct.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=Ct.decode(e);if(t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===Ct.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag(Ct.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===Ct.Flag.RESET&&this.reset(),t.flag===Ct.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===Ct.Flag.FIN_ACK&&(this.log.trace("received FIN_ACK"),this.receiveFinAck.resolve())),this.readStatus==="ready")return t.message}async _sendFlag(e){if(this.channel.readyState!=="open")return this.log.trace('not sending flag %s because channel is "%s" and not "open"',e.toString(),this.channel.readyState),!1;this.log.trace("sending flag %s",e.toString());let t=Ct.encode({flag:e}),n=Ya.single(t);try{return await this._sendMessage(n,!1),!0}catch(o){this.log.error("could not send flag %s - %e",e.toString(),o)}return!1}};function ds(r){let{channel:e,direction:t,handshake:n}=r;return new Pd({id:`${e.id}`,log:r.logger.forComponent(`libp2p:webrtc:stream:${n===!0?"handshake":t}:${e.id}`),...r})}var Qn=class{protocol;peerConnection;bufferedStreams=[];metrics;dataChannelOptions;components;log;constructor(e,t){this.components=e,this.peerConnection=t.peerConnection,this.metrics=t.metrics,this.protocol=t.protocol??vd,this.dataChannelOptions=t.dataChannelOptions??{},this.log=e.logger.forComponent("libp2p:webrtc:muxerfactory"),this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace('incoming early datachannel with channel id %d and label "%s"',n.id),n.label==="init"){this.log.trace("closing early init channel"),n.close();return}let o={},i=ds({channel:n,direction:"inbound",onEnd:s=>{o.onEnd(s)},logger:e.logger,...this.dataChannelOptions});o.stream=i,o.channel=n,o.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(s=>s.stream.id!==i.id)},this.bufferedStreams.push(o)}}createStreamMuxer(e){return new Nd(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},Nd=class{init;streams;protocol;log;peerConnection;dataChannelOptions;metrics;logger;constructor(e,t){this.init=t,this.log=e.logger.forComponent("libp2p:webrtc:muxer"),this.logger=e.logger,this.streams=t.streams.map(n=>n.stream),this.peerConnection=t.peerConnection,this.protocol=t.protocol??vd,this.metrics=t.metrics,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming datachannel with channel id %d",n.id),n.label==="init"){this.log.trace("closing init channel"),n.close();return}let o=n.id,i=ds({channel:n,direction:"inbound",onEnd:()=>{this.#e(i,n),this.log("incoming channel %s ended",o)},logger:this.logger,...this.dataChannelOptions});this.streams.push(i),this.metrics?.increment({incoming_stream:!0}),t?.onIncomingStream?.(i)},this.init.streams.length>0&&queueMicrotask(()=>{this.init.streams.forEach(n=>{n.onEnd=()=>{this.log("incoming early channel %s ended with state %s",n.channel.id,n.channel.readyState),this.#e(n.stream,n.channel)},this.metrics?.increment({incoming_stream:!0}),this.init?.onIncomingStream?.(n.stream)})})}#e(e,t){this.log.trace("stream %s %s %s onEnd",e.direction,e.id,e.protocol),$w(t,`${e.direction} ${e.id} ${e.protocol}`,this.dataChannelOptions.drainTimeout,{log:this.log}),this.streams=this.streams.filter(n=>n.id!==e.id),this.metrics?.increment({stream_end:!0}),this.init?.onStreamEnd?.(e)}async close(e){try{await Promise.all(this.streams.map(async t=>t.close(e)))}catch(t){this.abort(t)}}abort(e){for(let t of this.streams)t.abort(e)}source=gl();sink=wl;newStream(){let e=this.peerConnection.createDataChannel(""),t=e.id;this.log.trace("opened outgoing datachannel with channel id %s",t);let n=ds({channel:e,direction:"outbound",onEnd:()=>{this.#e(n,e),this.log("outgoing channel %s ended",t)},logger:this.logger,...this.dataChannelOptions});return this.streams.push(n),this.metrics?.increment({outgoing_stream:!0}),n}};var Il=globalThis.RTCPeerConnection,Tl=globalThis.RTCSessionDescription,Xw=globalThis.RTCIceCandidate;var Od=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Ze(),this.haveNext=Ze()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Ze(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Ze(),await rr(this.readNext.promise,t?.signal,t)}};function Bl(){return new Od}var kl=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Yw(r,e){let t=Bl();r.sink(t).catch(async s=>{await t.end(s)}),r.sink=async s=>{for await(let a of s)await t.push(a);await t.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new be;return{read:async s=>{if(s?.signal?.throwIfAborted(),s?.bytes==null){let{done:c,value:f}=await rr(n.next(),s?.signal);return c===!0?null:f}for(;o.byteLength<s.bytes;){let{value:c,done:f}=await rr(n.next(),s?.signal);if(f===!0)throw new kl("unexpected end of input");o.append(c)}let a=o.sublist(0,s.bytes);return o.consume(s.bytes),a},write:async(s,a)=>{a?.signal?.throwIfAborted(),s instanceof Uint8Array?await t.push(s,a):await t.push(s.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let s=r.source;r.source=async function*(){e?.yieldBytes===!1?yield o:yield*o,yield*s}()}return r}}}var Pl=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Nl=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ol=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ja(r,e={}){let t=Yw(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ke(e.maxDataLength));let n=e?.lengthDecoder??vr,o=e?.lengthEncoder??Hr;return{read:async s=>{let a=-1,c=new be;for(;;){c.append(await t.read({...s,bytes:1}));try{a=n(c)}catch(f){if(f instanceof RangeError)continue;throw f}if(a<0)throw new Pl("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new Ol("message length length too long");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Nl("message length too long");return t.read({...s,bytes:a})},write:async(s,a)=>{await t.write(new be(o(s.byteLength),s),a)},writeV:async(s,a)=>{let c=new be(...s.flatMap(f=>[o(f.byteLength),f]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function Rl(r,e){let t=Ja(r,e),n={read:async(o,i)=>{let s=await t.read(i);return o.decode(s)},write:async(o,i,s)=>{await t.write(i.encode(o),s)},writeV:async(o,i,s)=>{await t.writeV(o.map(a=>i.encode(a)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var Yt=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var eo=class extends Error{constructor(e){super(`WebRTC transport error: ${e}`),this.name="WebRTCTransportError"}},nr=class extends eo{constructor(e="SDP handshake failed"){super(e),this.name="SDPHandshakeFailedError"}};var Dl=class extends eo{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`),this.name="WebRTC/InvalidFingerprintError"}};var Ll=class extends eo{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`),this.name="WebRTC/UnimplementedError"}},Ul=class extends eo{constructor(e){super(`unsupported hash algorithm code: ${e} please see the codes at https://github.com/multiformats/multicodec/blob/master/table.csv `),this.name="WebRTC/UnsupportedHashAlgorithmError"}};var Lt;(function(r){let e;(function(o){o.SDP_OFFER="SDP_OFFER",o.SDP_ANSWER="SDP_ANSWER",o.ICE_CANDIDATE="ICE_CANDIDATE"})(e=r.Type||(r.Type={}));let t;(function(o){o[o.SDP_OFFER=0]="SDP_OFFER",o[o.SDP_ANSWER=1]="SDP_ANSWER",o[o.ICE_CANDIDATE=2]="ICE_CANDIDATE"})(t||(t={})),function(o){o.codec=()=>Vo(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=_r((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.data!=null&&(i.uint32(18),i.string(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let f=o.uint32();switch(f>>>3){case 1:{a.type=r.Type.codec().decode(o);break}case 2:{a.data=o.string();break}default:{o.skipType(f&7);break}}}return a})),n),r.encode=o=>Er(o,r.codec()),r.decode=(o,i)=>Sr(o,r.codec(),i)})(Lt||(Lt={}));var jl=async(r,e,t)=>{try{let n=Ze();for($2(r,n);;){let o=await Promise.race([n.promise,e.read({signal:t.signal}).catch(()=>{})]);if(o==null){t.signal?.throwIfAborted();break}if(o.type!==Lt.Type.ICE_CANDIDATE)throw new ku("ICE candidate message expected");let i=JSON.parse(o.data??"null");if(i===""||i===null){t.onProgress?.(new Yt("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let s=new Xw(i);t.log.trace("%s received new ICE candidate %o",t.direction,i);try{t.onProgress?.(new Yt("webrtc:add-ice-candidate",s.candidate)),await r.addIceCandidate(s)}catch(a){t.log.error("%s bad candidate received",t.direction,i,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate",t.direction,n),t.signal?.aborted===!0&&Ml(r)!=="connected")throw n}};function Ml(r){return za?r.iceConnectionState:r.connectionState}function $2(r,e){r[za?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(Ml(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new Cu("RTCPeerConnection was closed"));break;default:break}}}async function Zw({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:i,transportManager:s,log:a,logger:c,onProgress:f}){let{baseAddr:h}=Jw(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing base address: %a",h);let p=h.getPeerId();if(p==null)throw new Ae("Relay peer was missing");let m=i.getConnections(is(p)),v,g=!1;m.length===0?(f?.(new Yt("webrtc:dial-relay")),v=await s.dial(h,{signal:t,onProgress:f}),g=!0):(f?.(new Yt("webrtc:reuse-relay-connection")),v=m[0]);try{f?.(new Yt("webrtc:open-signaling-stream"));let w=await v.newStream(qa,{signal:t,runOnLimitedConnection:!0}),S=Rl(w).pb(Lt),O=new Il(r),Y=new Qn({logger:c},{peerConnection:O,dataChannelOptions:e});try{let T=O.createDataChannel("init");O.onicecandidate=({candidate:N})=>{let U=JSON.stringify(N?.toJSON()??null);a.trace("initiator sending ICE candidate %o",N),S.write({type:Lt.Type.ICE_CANDIDATE,data:U},{signal:t}).catch($=>{a.error("error sending ICE candidate",$)})},O.onicecandidateerror=N=>{a.error("initiator ICE candidate error",N)};let b=await O.createOffer().catch(N=>{throw a.error("could not execute createOffer",N),new nr("Failed to set createOffer")});a.trace("initiator send SDP offer %s",b.sdp),f?.(new Yt("webrtc:send-sdp-offer")),await S.write({type:Lt.Type.SDP_OFFER,data:b.sdp},{signal:t}),await O.setLocalDescription(b).catch(N=>{throw a.error("could not execute setLocalDescription",N),new nr("Failed to set localDescription")}),f?.(new Yt("webrtc:read-sdp-answer")),a.trace("initiator read SDP answer");let D=await S.read({signal:t});if(D.type!==Lt.Type.SDP_ANSWER)throw new nr("Remote should send an SDP answer");a.trace("initiator received SDP answer %s",D.data);let V=new Tl({type:"answer",sdp:D.data});return await O.setRemoteDescription(V).catch(N=>{throw a.error("could not execute setRemoteDescription",N),new nr("Failed to set remoteDescription")}),a.trace("initiator read candidates until connected"),f?.(new Yt("webrtc:read-ice-candidates")),await jl(O,S,{direction:"initiator",signal:t,log:a,onProgress:f}),a.trace("initiator connected, closing init channel"),T.close(),f?.(new Yt("webrtc:close-signaling-stream")),a.trace("closing signaling channel"),await w.close({signal:t}),a.trace("initiator connected to remote address %s",o),{remoteAddress:o,peerConnection:O,muxerFactory:Y}}catch(T){throw a.error("outgoing signaling error",T),O.close(),w.abort(T),T}finally{O.onicecandidate=null,O.onicecandidateerror=null}}finally{if(g)try{await v.close({signal:t})}catch(w){v.abort(w)}}}var Qw=De(vw.matchers[0],ye("p2p-circuit")),Kl=class r extends Mn{transportManager;shutdownController;events;constructor(e,t){super(),this.transportManager=e.transportManager,this.events=e.events,this.shutdownController=t.shutdownController,this.onTransportListening=this.onTransportListening.bind(this)}async listen(){this.events.addEventListener("transport:listening",this.onTransportListening)}onTransportListening(e){e.detail.getAddrs().filter(n=>Qw.exactMatch(n)).map(n=>n.encapsulate("/webrtc")).length>0&&this.safeDispatchEvent("listening")}getAddrs(){return this.transportManager.getListeners().filter(e=>!(e instanceof r)).map(e=>e.getAddrs().filter(t=>Qw.exactMatch(t)).map(t=>t.encapsulate("/webrtc"))).flat()}updateAnnounceAddrs(){}async close(){this.events.removeEventListener("transport:listening",this.onTransportListening),this.shutdownController.abort(),queueMicrotask(()=>{this.safeDispatchEvent("close")})}};async function ex({peerConnection:r,stream:e,signal:t,connection:n,log:o}){o.trace("new inbound signaling stream");let i=Rl(e).pb(Lt);try{r.onicecandidate=({candidate:h})=>{let p=JSON.stringify(h?.toJSON()??null);o.trace("recipient sending ICE candidate %s",p),i.write({type:Lt.Type.ICE_CANDIDATE,data:p},{signal:t}).catch(m=>{o.error("error sending ICE candidate",m)})},o.trace("recipient read SDP offer");let a=await i.read({signal:t});if(a.type!==Lt.Type.SDP_OFFER)throw new nr(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `);o.trace("recipient received SDP offer %s",a.data);let c=new Tl({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(h=>{throw o.error("could not execute setRemoteDescription",h),new nr("Failed to set remoteDescription")});let f=await r.createAnswer().catch(h=>{throw o.error("could not execute createAnswer",h),new nr("Failed to create answer")});o.trace("recipient send SDP answer %s",f.sdp),await i.write({type:Lt.Type.SDP_ANSWER,data:f.sdp},{signal:t}),await r.setLocalDescription(f).catch(h=>{throw o.error("could not execute setLocalDescription",h),new nr("Failed to set localDescription")}),o.trace("recipient read candidates until connected"),await jl(r,i,{direction:"recipient",signal:t,log:o})}catch(a){if(Ml(r)!=="connected")throw o.error("error while handling signaling stream from peer %a",n.remoteAddr,a),r.close(),a;o("error while handling signaling stream from peer %a, ignoring as the RTCPeerConnection is already connected",n.remoteAddr,a)}let s=$r(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return o.trace("recipient connected to remote address %s",s),{remoteAddress:s}}var Hl=class{components;init;log;_started=!1;metrics;shutdownController;constructor(e,t={}){this.components=e,this.init=t,this.log=e.logger.forComponent("libp2p:webrtc"),this.shutdownController=new AbortController,this.shutdownController.signal,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_dialer_events_total",{label:"event",help:"Total count of WebRTC dialer events by type"}),listenerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_listener_events_total",{label:"event",help:"Total count of WebRTC listener events by type"})})}[Su]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[Wi]=["@libp2p/transport"];[Qy]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(qa,e=>{let t=this.components.upgrader.createInboundAbortSignal(this.shutdownController.signal);this._onProtocol(e,t).catch(n=>{this.log.error("failed to handle incoming connect from %p",e.connection.remotePeer,n)}).finally(()=>{t.clear()})},{runOnLimitedConnection:!0}),this._started=!0}async stop(){await this.components.registrar.unhandle(qa),this._started=!1}createListener(e){return new Kl(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(Aw.exactMatch)}dialFilter(e){return this.listenFilter(e)}async dial(e,t){this.log.trace("dialing address: %a",e);let{remoteAddress:n,peerConnection:o,muxerFactory:i}=await Zw({rtcConfiguration:await _d(this.init.rtcConfiguration),dataChannel:this.init.dataChannel,multiaddr:e,dataChannelOptions:this.init.dataChannel,signal:t.signal,connectionManager:this.components.connectionManager,transportManager:this.components.transportManager,log:this.log,logger:this.components.logger,onProgress:t.onProgress}),s=new Fo(this.components,{peerConnection:o,timeline:{open:Date.now()},remoteAddr:n,metrics:this.metrics?.dialerEvents}),a=await t.upgrader.upgradeOutbound(s,{skipProtection:!0,skipEncryption:!0,muxerFactory:i,onProgress:t.onProgress,signal:t.signal});return this._closeOnShutdown(o,s),a}async _onProtocol({connection:e,stream:t},n){let o=new Il(await _d(this.init.rtcConfiguration)),i=new Qn(this.components,{peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:s}=await ex({peerConnection:o,connection:e,stream:t,signal:n,log:this.log});await t.close({signal:n});let a=new Fo(this.components,{peerConnection:o,timeline:{open:new Date().getTime()},remoteAddr:s,metrics:this.metrics?.listenerEvents});await this.components.upgrader.upgradeInbound(a,{skipEncryption:!0,skipProtection:!0,muxerFactory:i,signal:n}),this._closeOnShutdown(o,a)}catch(s){throw this.log.error("incoming signaling error",s),o.close(),t.abort(s),s}}_closeOnShutdown(e,t){let n=()=>{t.close().catch(o=>{this.log.error("could not close WebRTCMultiaddrConnection",o)})};this.shutdownController.signal.addEventListener("abort",n),e.addEventListener("close",()=>{this.shutdownController.signal.removeEventListener("abort",n)})}};function Jw(r){let e=r.toString().split("/webrtc/");if(e.length!==2)throw new Ae("webrtc protocol was not present in multiaddr");if(!e[0].includes("/p2p-circuit"))throw new Ae("p2p-circuit protocol was not present in multiaddr");let t=$r(e[0]),o=$r("/"+e[1]).getPeerId();if(o==null)throw new Ae("destination peer id was missing");let i=t.protos().pop();if(i===void 0)throw new Ae("invalid multiaddr");return i.name!=="p2p"&&(t=t.encapsulate(`/p2p/${o}`)),{baseAddr:t,peerId:is(o)}}var cG=Lr(rx());var Gr={};bt(Gr,{Any:()=>Wr,BaseBlock:()=>Je,BaseStringBlock:()=>rc,BitString:()=>Br,BmpString:()=>Zo,Boolean:()=>zo,CharacterString:()=>si,Choice:()=>gs,Constructed:()=>it,DATE:()=>cc,DateTime:()=>lc,Duration:()=>fc,EndOfContent:()=>nc,Enumerated:()=>Xo,GeneralString:()=>ii,GeneralizedTime:()=>ai,GraphicString:()=>oi,HexBlock:()=>qr,IA5String:()=>ni,Integer:()=>bn,Null:()=>Ir,NumericString:()=>Qo,ObjectIdentifier:()=>Yo,OctetString:()=>Tr,Primitive:()=>xn,PrintableString:()=>ei,RawData:()=>Ud,RelativeObjectIdentifier:()=>ac,Repeated:()=>ci,Sequence:()=>Mt,Set:()=>Kt,TIME:()=>pc,TeletexString:()=>ti,TimeOfDay:()=>uc,UTCTime:()=>oo,UniversalString:()=>Jo,Utf8String:()=>ir,ValueBlock:()=>ft,VideotexString:()=>ri,ViewWriter:()=>ys,VisibleString:()=>no,compareSchema:()=>ro,fromBER:()=>An,verifySchema:()=>l_});var me=Lr(gn());function Go(r,e){let t=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)t+=r[r.length-1-n]*Math.pow(2,e*n);return t}function to(r,e,t=-1){let n=t,o=r,i=0,s=Math.pow(2,e);for(let a=1;a<8;a++){if(r<s){let c;if(n<0)c=new ArrayBuffer(a),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let f=new Uint8Array(c);for(let h=a-1;h>=0;h--){let p=Math.pow(2,h*e);f[i-h-1]=Math.floor(o/p),o-=f[i-h-1]*p}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function Fl(...r){let e=0,t=0;for(let i of r)e+=i.length;let n=new ArrayBuffer(e),o=new Uint8Array(n);for(let i of r)o.set(i,t),t+=i.length;return o}function Dd(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=Go(t,8),o=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(o);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=r[a];return i[0]&=127,Go(i,8)-n}function nx(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let s=t-e,a=to(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=to(e,8,n),i=new Uint8Array(o);if(i[0]&128){let s=o.slice(0),a=new Uint8Array(s);o=new ArrayBuffer(o.byteLength+1),i=new Uint8Array(o);for(let c=0;c<s.byteLength;c++)i[c+1]=a[c];i[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function ox(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function Ut(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,o=new Array(n);for(let s=0;s<n;s++)o[s]="0";return o.join("").concat(t)}var xP=Math.log(2);function Wl(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function jd(r){let e=0,t=0;for(let o=0;o<r.length;o++){let i=r[o];e+=i.byteLength}let n=new Uint8Array(e);for(let o=0;o<r.length;o++){let i=r[o];n.set(new Uint8Array(i),t),t+=i.byteLength}return n.buffer}function vn(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var ys=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return jd(this.items)}},Qa=[new Uint8Array([1])],ix="0123456789",Ld="name",sx="valueHexView",J2="isHexOnly",Q2="idBlock",e_="tagClass",t_="tagNumber",r_="isConstructed",n_="fromBER",o_="toBER",i_="local",jt="",kr=new ArrayBuffer(0),af=new Uint8Array(0),tc="EndOfContent",cx="OCTET STRING",ux="BIT STRING";function qr(r){var e;return e=class extends r{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}constructor(...n){var o;super(...n);let i=n[0]||{};this.isHexOnly=(o=i.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=i.valueHex?me.BufferSourceConverter.toUint8Array(i.valueHex):af}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!vn(this,s,o,i))return-1;let a=o+i;return this.valueHexView=s.subarray(o,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),o)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",kr)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:me.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var wn=class{static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}constructor({blockLength:e=0,error:t=jt,warnings:n=[],valueBeforeDecode:o=af}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=me.BufferSourceConverter.toUint8Array(o)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:me.Convert.ToHex(this.valueBeforeDecodeView)}}};wn.NAME="baseBlock";var ft=class extends wn{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};ft.NAME="valueBlock";var ql=class extends qr(wn){constructor({idBlock:e={}}={}){var t,n,o,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?me.BufferSourceConverter.toUint8Array(e.valueHex):af,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",kr}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let o=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,o[0]=t}return o.buffer}if(!this.isHexOnly){let o=to(this.tagNumber,7),i=new Uint8Array(o),s=o.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=i[c]|128;a[s]=i[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let i=0;i<o.length-1;i++)n[i+1]=o[i]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=me.BufferSourceConverter.toUint8Array(e);if(!vn(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,f=this.valueHexView=new Uint8Array(255),h=255;for(;i[c]&128;){if(f[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===h){h+=255;let m=new Uint8Array(h);for(let v=0;v<f.length;v++)m[v]=f[v];f=this.valueHexView=new Uint8Array(h)}}this.blockLength=c+1,f[c-1]=i[c]&127;let p=new Uint8Array(c);for(let m=0;m<c;m++)p[m]=f[m];f=this.valueHexView=new Uint8Array(c),f.set(p),this.blockLength<=9?this.tagNumber=Go(f,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};ql.NAME="identificationBlock";var Gl=class extends wn{constructor({lenBlock:e={}}={}){var t,n,o;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=me.BufferSourceConverter.toUint8Array(e);if(!vn(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,t+this.blockLength;let s=i[0]&127;if(s>8)return this.error="Too big integer",-1;if(s+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=o.subarray(a,a+s);return c[s-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Go(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=s+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let o=to(this.length,8);if(o.byteLength>127)return this.error="Too big length",kr;if(t=new ArrayBuffer(o.byteLength+1),e)return t;let i=new Uint8Array(o);n=new Uint8Array(t),n[0]=o.byteLength|128;for(let s=0;s<o.byteLength;s++)n[s+1]=i[s];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Gl.NAME="lengthBlock";var Z={},Je=class extends wn{constructor({name:e=jt,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new ql(o),this.lenBlock=new Gl(o),this.valueBlock=i?new i(o):new ft(o)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}toBER(e,t){let n=t||new ys;t||lx(this);let o=this.idBlock.toBER(e);if(n.write(o),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(i)}return t?kr:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():me.Convert.ToHex(this.toBER())}onAsciiEncoding(){let e=this.constructor.NAME,t=me.Convert.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${t}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return ox(t,n)}};Je.NAME="BaseBlock";function lx(r){var e;if(r instanceof Z.Constructed)for(let t of r.valueBlock.value)lx(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}var rc=class extends Je{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=jt,...t}={},n){super(t,n),e&&this.fromString(e)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};rc.NAME="BaseStringBlock";var zl=class extends qr(ft){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};zl.NAME="PrimitiveValueBlock";var fx,xn=class extends Je{constructor(e={}){super(e,zl),this.idBlock.isConstructed=!1}};fx=xn;Z.Primitive=fx;xn.NAME="PRIMITIVE";function s_(r,e){if(r instanceof e)return r;let t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function ws(r,e=0,t=r.length){let n=e,o=new Je({},ft),i=new wn;if(!vn(i,r,e,t))return o.error=i.error,{offset:-1,result:o};if(!r.subarray(e,e+t).length)return o.error="Zero buffer length",{offset:-1,result:o};let a=o.idBlock.fromBER(r,e,t);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),a===-1)return o.error=o.idBlock.error,{offset:-1,result:o};if(e=a,t-=o.idBlock.blockLength,a=o.lenBlock.fromBER(r,e,t),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),a===-1)return o.error=o.lenBlock.error,{offset:-1,result:o};if(e=a,t-=o.lenBlock.blockLength,!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let c=Je;switch(o.idBlock.tagClass){case 1:if(o.idBlock.tagNumber>=37&&o.idBlock.isHexOnly===!1)return o.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:o};switch(o.idBlock.tagNumber){case 0:if(o.idBlock.isConstructed&&o.lenBlock.length>0)return o.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:o};c=Z.EndOfContent;break;case 1:c=Z.Boolean;break;case 2:c=Z.Integer;break;case 3:c=Z.BitString;break;case 4:c=Z.OctetString;break;case 5:c=Z.Null;break;case 6:c=Z.ObjectIdentifier;break;case 10:c=Z.Enumerated;break;case 12:c=Z.Utf8String;break;case 13:c=Z.RelativeObjectIdentifier;break;case 14:c=Z.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=Z.Sequence;break;case 17:c=Z.Set;break;case 18:c=Z.NumericString;break;case 19:c=Z.PrintableString;break;case 20:c=Z.TeletexString;break;case 21:c=Z.VideotexString;break;case 22:c=Z.IA5String;break;case 23:c=Z.UTCTime;break;case 24:c=Z.GeneralizedTime;break;case 25:c=Z.GraphicString;break;case 26:c=Z.VisibleString;break;case 27:c=Z.GeneralString;break;case 28:c=Z.UniversalString;break;case 29:c=Z.CharacterString;break;case 30:c=Z.BmpString;break;case 31:c=Z.DATE;break;case 32:c=Z.TimeOfDay;break;case 33:c=Z.DateTime;break;case 34:c=Z.Duration;break;default:{let f=o.idBlock.isConstructed?new Z.Constructed:new Z.Primitive;f.idBlock=o.idBlock,f.lenBlock=o.lenBlock,f.warnings=o.warnings,o=f}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?Z.Constructed:Z.Primitive}return o=s_(o,c),a=o.fromBER(r,e,o.lenBlock.isIndefiniteForm?t:o.lenBlock.length),o.valueBeforeDecodeView=r.subarray(n,n+o.blockLength),{offset:a,result:o}}function An(r){if(!r.byteLength){let e=new Je({},ft);return e.error="Input buffer has zero length",{offset:-1,result:e}}return ws(me.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function a_(r,e){return r?1:e}var Fr=class extends ft{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=me.BufferSourceConverter.toUint8Array(e);if(!vn(this,o,t,n))return-1;if(this.valueBeforeDecodeView=o.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;a_(this.isIndefiniteForm,n)>0;){let s=ws(o,i,n);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(i=s.offset,this.blockLength+=s.result.blockLength,n-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===tc)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===tc?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new ys;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?kr:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Fr.NAME="ConstructedValueBlock";var px,it=class extends Je{constructor(e={}){super(e,Fr),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
|
2
|
+
"use strict";var Libp2PWebrtc=(()=>{var mA=Object.create;var Au=Object.defineProperty;var yA=Object.getOwnPropertyDescriptor;var gA=Object.getOwnPropertyNames;var wA=Object.getPrototypeOf,xA=Object.prototype.hasOwnProperty;var Sp=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),bt=(r,e)=>{for(var t in e)Au(r,t,{get:e[t],enumerable:!0})},Zy=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of gA(e))!xA.call(r,o)&&o!==t&&Au(r,o,{get:()=>e[o],enumerable:!(n=yA(e,o))||n.enumerable});return r};var Lr=(r,e,t)=>(t=r!=null?mA(wA(r)):{},Zy(e||!r||!r.__esModule?Au(t,"default",{value:r,enumerable:!0}):t,r)),bA=r=>Zy(Au({},"__esModule",{value:!0}),r);var rx=Sp(()=>{var tx;(function(r){(function(e){var t=typeof globalThis=="object"||typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof this=="object"?this:a(),n=o(r);typeof t.Reflect<"u"&&(n=o(t.Reflect,n)),e(n,t),typeof t.Reflect>"u"&&(t.Reflect=r);function o(c,f){return function(h,p){Object.defineProperty(c,h,{configurable:!0,writable:!0,value:p}),f&&f(h,p)}}function i(){try{return Function("return this;")()}catch{}}function s(){try{return(0,eval)("(function() { return this; })()")}catch{}}function a(){return i()||s()}})(function(e,t){var n=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",i=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",s=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",a=typeof Object.create=="function",c={__proto__:[]}instanceof Array,f=!a&&!c,h={create:a?function(){return Ap(Object.create(null))}:c?function(){return Ap({__proto__:null})}:function(){return Ap({})},has:f?function(x,E){return n.call(x,E)}:function(x,E){return E in x},get:f?function(x,E){return n.call(x,E)?x[E]:void 0}:function(x,E){return x[E]}},p=Object.getPrototypeOf(Function),m=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:lA(),v=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:fA(),g=typeof WeakMap=="function"?WeakMap:pA(),w=o?Symbol.for("@reflect-metadata:registry"):void 0,S=aA(),O=cA(S);function Y(x,E,B,W){if(I(B)){if(!ut(x))throw new TypeError;if(!et(E))throw new TypeError;return G(x,E)}else{if(!ut(x))throw new TypeError;if(!Q(E))throw new TypeError;if(!Q(W)&&!I(W)&&!re(W))throw new TypeError;return re(W)&&(W=void 0),B=ke(B),F(x,E,B,W)}}e("decorate",Y);function T(x,E){function B(W,ae){if(!Q(W))throw new TypeError;if(!I(ae)&&!Tt(ae))throw new TypeError;P(x,E,W,ae)}return B}e("metadata",T);function b(x,E,B,W){if(!Q(B))throw new TypeError;return I(W)||(W=ke(W)),P(x,E,B,W)}e("defineMetadata",b);function D(x,E,B){if(!Q(E))throw new TypeError;return I(B)||(B=ke(B)),ie(x,E,B)}e("hasMetadata",D);function V(x,E,B){if(!Q(E))throw new TypeError;return I(B)||(B=ke(B)),k(x,E,B)}e("hasOwnMetadata",V);function N(x,E,B){if(!Q(E))throw new TypeError;return I(B)||(B=ke(B)),R(x,E,B)}e("getMetadata",N);function U(x,E,B){if(!Q(E))throw new TypeError;return I(B)||(B=ke(B)),K(x,E,B)}e("getOwnMetadata",U);function $(x,E){if(!Q(x))throw new TypeError;return I(E)||(E=ke(E)),y(x,E)}e("getMetadataKeys",$);function X(x,E){if(!Q(x))throw new TypeError;return I(E)||(E=ke(E)),C(x,E)}e("getOwnMetadataKeys",X);function M(x,E,B){if(!Q(E))throw new TypeError;if(I(B)||(B=ke(B)),!Q(E))throw new TypeError;I(B)||(B=ke(B));var W=aa(E,B,!1);return I(W)?!1:W.OrdinaryDeleteMetadata(x,E,B)}e("deleteMetadata",M);function G(x,E){for(var B=x.length-1;B>=0;--B){var W=x[B],ae=W(E);if(!I(ae)&&!re(ae)){if(!et(ae))throw new TypeError;E=ae}}return E}function F(x,E,B,W){for(var ae=x.length-1;ae>=0;--ae){var Ge=x[ae],tt=Ge(E,B,W);if(!I(tt)&&!re(tt)){if(!Q(tt))throw new TypeError;W=tt}}return W}function ie(x,E,B){var W=k(x,E,B);if(W)return!0;var ae=sa(E);return re(ae)?!1:ie(x,ae,B)}function k(x,E,B){var W=aa(E,B,!1);return I(W)?!1:Ee(W.OrdinaryHasOwnMetadata(x,E,B))}function R(x,E,B){var W=k(x,E,B);if(W)return K(x,E,B);var ae=sa(E);if(!re(ae))return R(x,ae,B)}function K(x,E,B){var W=aa(E,B,!1);if(!I(W))return W.OrdinaryGetOwnMetadata(x,E,B)}function P(x,E,B,W){var ae=aa(B,W,!0);ae.OrdinaryDefineOwnMetadata(x,E,B,W)}function y(x,E){var B=C(x,E),W=sa(x);if(W===null)return B;var ae=y(W,E);if(ae.length<=0)return B;if(B.length<=0)return ae;for(var Ge=new v,tt=[],we=0,z=B;we<z.length;we++){var J=z[we],te=Ge.has(J);te||(Ge.add(J),tt.push(J))}for(var ne=0,xe=ae;ne<xe.length;ne++){var J=xe[ne],te=Ge.has(J);te||(Ge.add(J),tt.push(J))}return tt}function C(x,E){var B=aa(x,E,!1);return B?B.OrdinaryOwnMetadataKeys(x,E):[]}function L(x){if(x===null)return 1;switch(typeof x){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return x===null?1:6;default:return 6}}function I(x){return x===void 0}function re(x){return x===null}function le(x){return typeof x=="symbol"}function Q(x){return typeof x=="object"?x!==null:typeof x=="function"}function pe(x,E){switch(L(x)){case 0:return x;case 1:return x;case 2:return x;case 3:return x;case 4:return x;case 5:return x}var B=E===3?"string":E===5?"number":"default",W=Un(x,i);if(W!==void 0){var ae=W.call(x,B);if(Q(ae))throw new TypeError;return ae}return he(x,B==="default"?"number":B)}function he(x,E){if(E==="string"){var B=x.toString;if(Ue(B)){var W=B.call(x);if(!Q(W))return W}var ae=x.valueOf;if(Ue(ae)){var W=ae.call(x);if(!Q(W))return W}}else{var ae=x.valueOf;if(Ue(ae)){var W=ae.call(x);if(!Q(W))return W}var Ge=x.toString;if(Ue(Ge)){var W=Ge.call(x);if(!Q(W))return W}}throw new TypeError}function Ee(x){return!!x}function _e(x){return""+x}function ke(x){var E=pe(x,3);return le(E)?E:_e(E)}function ut(x){return Array.isArray?Array.isArray(x):x instanceof Object?x instanceof Array:Object.prototype.toString.call(x)==="[object Array]"}function Ue(x){return typeof x=="function"}function et(x){return typeof x=="function"}function Tt(x){switch(L(x)){case 3:return!0;case 4:return!0;default:return!1}}function Bt(x,E){return x===E||x!==x&&E!==E}function Un(x,E){var B=x[E];if(B!=null){if(!Ue(B))throw new TypeError;return B}}function ia(x){var E=Un(x,s);if(!Ue(E))throw new TypeError;var B=E.call(x);if(!Q(B))throw new TypeError;return B}function xu(x){return x.value}function bu(x){var E=x.next();return E.done?!1:E}function vu(x){var E=x.return;E&&E.call(x)}function sa(x){var E=Object.getPrototypeOf(x);if(typeof x!="function"||x===p||E!==p)return E;var B=x.prototype,W=B&&Object.getPrototypeOf(B);if(W==null||W===Object.prototype)return E;var ae=W.constructor;return typeof ae!="function"||ae===x?E:ae}function sA(){var x;!I(w)&&typeof t.Reflect<"u"&&!(w in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(x=uA(t.Reflect));var E,B,W,ae=new g,Ge={registerProvider:tt,getProvider:z,setProvider:te};return Ge;function tt(ne){if(!Object.isExtensible(Ge))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case x===ne:break;case I(E):E=ne;break;case E===ne:break;case I(B):B=ne;break;case B===ne:break;default:W===void 0&&(W=new v),W.add(ne);break}}function we(ne,xe){if(!I(E)){if(E.isProviderFor(ne,xe))return E;if(!I(B)){if(B.isProviderFor(ne,xe))return E;if(!I(W))for(var je=ia(W);;){var ze=bu(je);if(!ze)return;var mr=xu(ze);if(mr.isProviderFor(ne,xe))return vu(je),mr}}}if(!I(x)&&x.isProviderFor(ne,xe))return x}function z(ne,xe){var je=ae.get(ne),ze;return I(je)||(ze=je.get(xe)),I(ze)&&(ze=we(ne,xe),I(ze)||(I(je)&&(je=new m,ae.set(ne,je)),je.set(xe,ze))),ze}function J(ne){if(I(ne))throw new TypeError;return E===ne||B===ne||!I(W)&&W.has(ne)}function te(ne,xe,je){if(!J(je))throw new Error("Metadata provider not registered.");var ze=z(ne,xe);if(ze!==je){if(!I(ze))return!1;var mr=ae.get(ne);I(mr)&&(mr=new m,ae.set(ne,mr)),mr.set(xe,je)}return!0}}function aA(){var x;return!I(w)&&Q(t.Reflect)&&Object.isExtensible(t.Reflect)&&(x=t.Reflect[w]),I(x)&&(x=sA()),!I(w)&&Q(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,w,{enumerable:!1,configurable:!1,writable:!1,value:x}),x}function cA(x){var E=new g,B={isProviderFor:function(J,te){var ne=E.get(J);return I(ne)?!1:ne.has(te)},OrdinaryDefineOwnMetadata:tt,OrdinaryHasOwnMetadata:ae,OrdinaryGetOwnMetadata:Ge,OrdinaryOwnMetadataKeys:we,OrdinaryDeleteMetadata:z};return S.registerProvider(B),B;function W(J,te,ne){var xe=E.get(J),je=!1;if(I(xe)){if(!ne)return;xe=new m,E.set(J,xe),je=!0}var ze=xe.get(te);if(I(ze)){if(!ne)return;if(ze=new m,xe.set(te,ze),!x.setProvider(J,te,B))throw xe.delete(te),je&&E.delete(J),new Error("Wrong provider for target.")}return ze}function ae(J,te,ne){var xe=W(te,ne,!1);return I(xe)?!1:Ee(xe.has(J))}function Ge(J,te,ne){var xe=W(te,ne,!1);if(!I(xe))return xe.get(J)}function tt(J,te,ne,xe){var je=W(ne,xe,!0);je.set(J,te)}function we(J,te){var ne=[],xe=W(J,te,!1);if(I(xe))return ne;for(var je=xe.keys(),ze=ia(je),mr=0;;){var Yy=bu(ze);if(!Yy)return ne.length=mr,ne;var hA=xu(Yy);try{ne[mr]=hA}catch(dA){try{vu(ze)}finally{throw dA}}mr++}}function z(J,te,ne){var xe=W(te,ne,!1);if(I(xe)||!xe.delete(J))return!1;if(xe.size===0){var je=E.get(te);I(je)||(je.delete(ne),je.size===0&&E.delete(je))}return!0}}function uA(x){var E=x.defineMetadata,B=x.hasOwnMetadata,W=x.getOwnMetadata,ae=x.getOwnMetadataKeys,Ge=x.deleteMetadata,tt=new g,we={isProviderFor:function(z,J){var te=tt.get(z);return!I(te)&&te.has(J)?!0:ae(z,J).length?(I(te)&&(te=new v,tt.set(z,te)),te.add(J),!0):!1},OrdinaryDefineOwnMetadata:E,OrdinaryHasOwnMetadata:B,OrdinaryGetOwnMetadata:W,OrdinaryOwnMetadataKeys:ae,OrdinaryDeleteMetadata:Ge};return we}function aa(x,E,B){var W=S.getProvider(x,E);if(!I(W))return W;if(B){if(S.setProvider(x,E,O))return O;throw new Error("Illegal state.")}}function lA(){var x={},E=[],B=function(){function we(z,J,te){this._index=0,this._keys=z,this._values=J,this._selector=te}return we.prototype["@@iterator"]=function(){return this},we.prototype[s]=function(){return this},we.prototype.next=function(){var z=this._index;if(z>=0&&z<this._keys.length){var J=this._selector(this._keys[z],this._values[z]);return z+1>=this._keys.length?(this._index=-1,this._keys=E,this._values=E):this._index++,{value:J,done:!1}}return{value:void 0,done:!0}},we.prototype.throw=function(z){throw this._index>=0&&(this._index=-1,this._keys=E,this._values=E),z},we.prototype.return=function(z){return this._index>=0&&(this._index=-1,this._keys=E,this._values=E),{value:z,done:!0}},we}(),W=function(){function we(){this._keys=[],this._values=[],this._cacheKey=x,this._cacheIndex=-2}return Object.defineProperty(we.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),we.prototype.has=function(z){return this._find(z,!1)>=0},we.prototype.get=function(z){var J=this._find(z,!1);return J>=0?this._values[J]:void 0},we.prototype.set=function(z,J){var te=this._find(z,!0);return this._values[te]=J,this},we.prototype.delete=function(z){var J=this._find(z,!1);if(J>=0){for(var te=this._keys.length,ne=J+1;ne<te;ne++)this._keys[ne-1]=this._keys[ne],this._values[ne-1]=this._values[ne];return this._keys.length--,this._values.length--,Bt(z,this._cacheKey)&&(this._cacheKey=x,this._cacheIndex=-2),!0}return!1},we.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=x,this._cacheIndex=-2},we.prototype.keys=function(){return new B(this._keys,this._values,ae)},we.prototype.values=function(){return new B(this._keys,this._values,Ge)},we.prototype.entries=function(){return new B(this._keys,this._values,tt)},we.prototype["@@iterator"]=function(){return this.entries()},we.prototype[s]=function(){return this.entries()},we.prototype._find=function(z,J){if(!Bt(this._cacheKey,z)){this._cacheIndex=-1;for(var te=0;te<this._keys.length;te++)if(Bt(this._keys[te],z)){this._cacheIndex=te;break}}return this._cacheIndex<0&&J&&(this._cacheIndex=this._keys.length,this._keys.push(z),this._values.push(void 0)),this._cacheIndex},we}();return W;function ae(we,z){return we}function Ge(we,z){return z}function tt(we,z){return[we,z]}}function fA(){var x=function(){function E(){this._map=new m}return Object.defineProperty(E.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),E.prototype.has=function(B){return this._map.has(B)},E.prototype.add=function(B){return this._map.set(B,B),this},E.prototype.delete=function(B){return this._map.delete(B)},E.prototype.clear=function(){this._map.clear()},E.prototype.keys=function(){return this._map.keys()},E.prototype.values=function(){return this._map.keys()},E.prototype.entries=function(){return this._map.entries()},E.prototype["@@iterator"]=function(){return this.keys()},E.prototype[s]=function(){return this.keys()},E}();return x}function pA(){var x=16,E=h.create(),B=W();return function(){function z(){this._key=W()}return z.prototype.has=function(J){var te=ae(J,!1);return te!==void 0?h.has(te,this._key):!1},z.prototype.get=function(J){var te=ae(J,!1);return te!==void 0?h.get(te,this._key):void 0},z.prototype.set=function(J,te){var ne=ae(J,!0);return ne[this._key]=te,this},z.prototype.delete=function(J){var te=ae(J,!1);return te!==void 0?delete te[this._key]:!1},z.prototype.clear=function(){this._key=W()},z}();function W(){var z;do z="@@WeakMap@@"+we();while(h.has(E,z));return E[z]=!0,z}function ae(z,J){if(!n.call(z,B)){if(!J)return;Object.defineProperty(z,B,{value:h.create()})}return z[B]}function Ge(z,J){for(var te=0;te<J;++te)z[te]=Math.random()*255|0;return z}function tt(z){if(typeof Uint8Array=="function"){var J=new Uint8Array(z);return typeof crypto<"u"?crypto.getRandomValues(J):typeof msCrypto<"u"?msCrypto.getRandomValues(J):Ge(J,z),J}return Ge(new Array(z),z)}function we(){var z=tt(x);z[6]=z[6]&79|64,z[8]=z[8]&191|128;for(var J="",te=0;te<x;++te){var ne=z[te];(te===4||te===6||te===8)&&(J+="-"),ne<16&&(J+="0"),J+=ne.toString(16).toLowerCase()}return J}}function Ap(x){return x.__=void 0,delete x.__,x}})})(tx||(tx={}))});var gn=Sp(ms=>{"use strict";var F2="[object ArrayBuffer]",yn=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===F2}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),o=r.toUint8Array(t);if(n.length!==o.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==o[i])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let s of t)n+=s.byteLength;let o=new Uint8Array(n),i=0;for(let s of t){let a=this.toUint8Array(s);o.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(o,e[e.length-1]):o.buffer}},Rd="string",W2=/^[0-9a-f\s]+$/i,q2=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,G2=/^[a-zA-Z0-9-_]+$/,Vl=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n.buffer}static toString(e){let t=yn.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},or=class{static toString(e,t=!1){let n=yn.toArrayBuffer(e),o=new DataView(n),i="";for(let s=0;s<n.byteLength;s+=2){let a=o.getUint16(s,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),o=new DataView(n);for(let i=0;i<e.length;i++)o.setUint16(i*2,e.charCodeAt(i),t);return n}},$l=class r{static isHex(e){return typeof e===Rd&&W2.test(e)}static isBase64(e){return typeof e===Rd&&q2.test(e)}static isBase64Url(e){return typeof e===Rd&&G2.test(e)}static ToString(e,t="utf8"){let n=yn.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return or.toString(n,!0);case"utf16":case"utf16be":return or.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return or.fromString(e,!0);case"utf16":case"utf16be":return or.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=yn.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return Vl.fromString(e);case"utf16":case"utf16be":return or.fromString(e);case"utf16le":case"usc2":return or.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return Vl.toString(e);case"utf16":case"utf16be":return or.toString(e);case"utf16le":case"usc2":return or.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return n.buffer}static ToBinary(e){let t=yn.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=yn.toUint8Array(e),n="",o=t.length;for(let i=0;i<o;i++){let s=t[i];s<16&&(n+="0"),n+=s.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let o=0;o<t.length;o=o+2){let i=t.slice(o,o+2);n[o/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return or.toString(e,t)}static FromUtf16String(e,t=!1){return or.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};$l.DEFAULT_UTF8_ENCODING="utf8";function z2(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let o=arguments[n];for(let i in o)t[i]=o[i]}return t}function X2(...r){let e=r.map(o=>o.byteLength).reduce((o,i)=>o+i),t=new Uint8Array(e),n=0;return r.map(o=>new Uint8Array(o)).forEach(o=>{for(let i of o)t[n++]=i}),t.buffer}function Y2(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==n[o])return!1;return!0}ms.BufferSourceConverter=yn;ms.Convert=$l;ms.assign=z2;ms.combine=X2;ms.isEqual=Y2});var Yb=Sp((H7,jf)=>{var kb,Pb,Nb,Ob,Rb,Db,Lb,Ub,jb,Uf,Hm,Mb,Kb,Ws,Hb,Vb,$b,Fb,Wb,qb,Gb,zb,Xb;(function(r){var e=typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof this=="object"?this:{};typeof define=="function"&&define.amd?define("tslib",["exports"],function(n){r(t(e,t(n)))}):typeof jf=="object"&&typeof jf.exports=="object"?r(t(e,t(jf.exports))):r(t(e));function t(n,o){return n!==e&&(typeof Object.create=="function"?Object.defineProperty(n,"__esModule",{value:!0}):n.__esModule=!0),function(i,s){return n[i]=o?o(i,s):s}}})(function(r){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var o in n)n.hasOwnProperty(o)&&(t[o]=n[o])};kb=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},Pb=Object.assign||function(t){for(var n,o=1,i=arguments.length;o<i;o++){n=arguments[o];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},Nb=function(t,n){var o={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&n.indexOf(i)<0&&(o[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,i=Object.getOwnPropertySymbols(t);s<i.length;s++)n.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(t,i[s])&&(o[i[s]]=t[i[s]]);return o},Ob=function(t,n,o,i){var s=arguments.length,a=s<3?n:i===null?i=Object.getOwnPropertyDescriptor(n,o):i,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,n,o,i);else for(var f=t.length-1;f>=0;f--)(c=t[f])&&(a=(s<3?c(a):s>3?c(n,o,a):c(n,o))||a);return s>3&&a&&Object.defineProperty(n,o,a),a},Rb=function(t,n){return function(o,i){n(o,i,t)}},Db=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},Lb=function(t,n,o,i){function s(a){return a instanceof o?a:new o(function(c){c(a)})}return new(o||(o=Promise))(function(a,c){function f(m){try{p(i.next(m))}catch(v){c(v)}}function h(m){try{p(i.throw(m))}catch(v){c(v)}}function p(m){m.done?a(m.value):s(m.value).then(f,h)}p((i=i.apply(t,n||[])).next())})},Ub=function(t,n){var o={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,s,a,c;return c={next:f(0),throw:f(1),return:f(2)},typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function f(p){return function(m){return h([p,m])}}function h(p){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,s&&(a=p[0]&2?s.return:p[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,p[1])).done)return a;switch(s=0,a&&(p=[p[0]&2,a.value]),p[0]){case 0:case 1:a=p;break;case 4:return o.label++,{value:p[1],done:!1};case 5:o.label++,s=p[1],p=[0];continue;case 7:p=o.ops.pop(),o.trys.pop();continue;default:if(a=o.trys,!(a=a.length>0&&a[a.length-1])&&(p[0]===6||p[0]===2)){o=0;continue}if(p[0]===3&&(!a||p[1]>a[0]&&p[1]<a[3])){o.label=p[1];break}if(p[0]===6&&o.label<a[1]){o.label=a[1],a=p;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(p);break}a[2]&&o.ops.pop(),o.trys.pop();continue}p=n.call(t,o)}catch(m){p=[6,m],s=0}finally{i=a=0}if(p[0]&5)throw p[1];return{value:p[0]?p[1]:void 0,done:!0}}},Xb=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},jb=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},Uf=function(t){var n=typeof Symbol=="function"&&Symbol.iterator,o=n&&t[n],i=0;if(o)return o.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},Hm=function(t,n){var o=typeof Symbol=="function"&&t[Symbol.iterator];if(!o)return t;var i=o.call(t),s,a=[],c;try{for(;(n===void 0||n-- >0)&&!(s=i.next()).done;)a.push(s.value)}catch(f){c={error:f}}finally{try{s&&!s.done&&(o=i.return)&&o.call(i)}finally{if(c)throw c.error}}return a},Mb=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(Hm(arguments[n]));return t},Kb=function(){for(var t=0,n=0,o=arguments.length;n<o;n++)t+=arguments[n].length;for(var i=Array(t),s=0,n=0;n<o;n++)for(var a=arguments[n],c=0,f=a.length;c<f;c++,s++)i[s]=a[c];return i},Ws=function(t){return this instanceof Ws?(this.v=t,this):new Ws(t)},Hb=function(t,n,o){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i=o.apply(t,n||[]),s,a=[];return s={},c("next"),c("throw"),c("return"),s[Symbol.asyncIterator]=function(){return this},s;function c(g){i[g]&&(s[g]=function(w){return new Promise(function(S,O){a.push([g,w,S,O])>1||f(g,w)})})}function f(g,w){try{h(i[g](w))}catch(S){v(a[0][3],S)}}function h(g){g.value instanceof Ws?Promise.resolve(g.value.v).then(p,m):v(a[0][2],g)}function p(g){f("next",g)}function m(g){f("throw",g)}function v(g,w){g(w),a.shift(),a.length&&f(a[0][0],a[0][1])}},Vb=function(t){var n,o;return n={},i("next"),i("throw",function(s){throw s}),i("return"),n[Symbol.iterator]=function(){return this},n;function i(s,a){n[s]=t[s]?function(c){return(o=!o)?{value:Ws(t[s](c)),done:s==="return"}:a?a(c):c}:a}},$b=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t[Symbol.asyncIterator],o;return n?n.call(t):(t=typeof Uf=="function"?Uf(t):t[Symbol.iterator](),o={},i("next"),i("throw"),i("return"),o[Symbol.asyncIterator]=function(){return this},o);function i(a){o[a]=t[a]&&function(c){return new Promise(function(f,h){c=t[a](c),s(f,h,c.done,c.value)})}}function s(a,c,f,h){Promise.resolve(h).then(function(p){a({value:p,done:f})},c)}},Fb=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},Wb=function(t){if(t&&t.__esModule)return t;var n={};if(t!=null)for(var o in t)Object.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n.default=t,n},qb=function(t){return t&&t.__esModule?t:{default:t}},Gb=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},zb=function(t,n,o){if(!n.has(t))throw new TypeError("attempted to set private field on non-instance");return n.set(t,o),o},r("__extends",kb),r("__assign",Pb),r("__rest",Nb),r("__decorate",Ob),r("__param",Rb),r("__metadata",Db),r("__awaiter",Lb),r("__generator",Ub),r("__exportStar",jb),r("__createBinding",Xb),r("__values",Uf),r("__read",Hm),r("__spread",Mb),r("__spreadArrays",Kb),r("__await",Ws),r("__asyncGenerator",Hb),r("__asyncDelegator",Vb),r("__asyncValues",$b),r("__makeTemplateObject",Fb),r("__importStar",Wb),r("__importDefault",qb),r("__classPrivateFieldGet",Gb),r("__classPrivateFieldSet",zb)})});var QC={};bt(QC,{webRTC:()=>JC,webRTCDirect:()=>ZC});var Ep=Symbol.for("@libp2p/peer-id");var Su=Symbol.for("@libp2p/transport");var Jy;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Jy||(Jy={}));var Eu=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},_u=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},Ae=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Fi=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},ca=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var Cu=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var Iu=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}},Io=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},To=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Tu=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Bu=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var ku=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Pu=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},Nu=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var jn=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Mn=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Wi=Symbol.for("@libp2p/service-capabilities"),Qy=Symbol.for("@libp2p/service-dependencies");var Bp={};bt(Bp,{base58btc:()=>Pe,base58flickr:()=>IA});var II=new Uint8Array(0);function eg(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function sn(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function tg(r){return new TextEncoder().encode(r)}function rg(r){return new TextDecoder().decode(r)}function vA(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function p(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var w=0,S=0,O=0,Y=g.length;O!==Y&&g[O]===0;)O++,w++;for(var T=(Y-O)*h+1>>>0,b=new Uint8Array(T);O!==Y;){for(var D=g[O],V=0,N=T-1;(D!==0||V<S)&&N!==-1;N--,V++)D+=256*b[N]>>>0,b[N]=D%a>>>0,D=D/a>>>0;if(D!==0)throw new Error("Non-zero carry");S=V,O++}for(var U=T-S;U!==T&&b[U]===0;)U++;for(var $=c.repeat(w);U<T;++U)$+=r.charAt(b[U]);return $}function m(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var w=0;if(g[w]!==" "){for(var S=0,O=0;g[w]===c;)S++,w++;for(var Y=(g.length-w)*f+1>>>0,T=new Uint8Array(Y);g[w];){var b=t[g.charCodeAt(w)];if(b===255)return;for(var D=0,V=Y-1;(b!==0||D<O)&&V!==-1;V--,D++)b+=a*T[V]>>>0,T[V]=b%256>>>0,b=b/256>>>0;if(b!==0)throw new Error("Non-zero carry");O=D,w++}if(g[w]!==" "){for(var N=Y-O;N!==Y&&T[N]===0;)N++;for(var U=new Uint8Array(S+(Y-N)),$=S;N!==Y;)U[$++]=T[N++];return U}}}function v(g){var w=m(g);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:p,decodeUnsafe:m,decode:v}}var AA=vA,SA=AA,og=SA;var _p=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Cp=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return ig(this,e)}},Ip=class{decoders;constructor(e){this.decoders=e}or(e){return ig(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ig(r,e){return new Ip({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Tp=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new _p(e,t,n),this.decoder=new Cp(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function qi({name:r,prefix:e,encode:t,decode:n}){return new Tp(r,e,t,n)}function Kn({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=og(t,r);return qi({prefix:e,name:r,encode:n,decode:i=>sn(o(i))})}function EA(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),s=0,a=0,c=0;for(let f=0;f<o;++f){let h=e[r[f]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|h,s+=t,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=t||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function _A(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function CA(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function $e({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=CA(n);return qi({prefix:e,name:r,encode(i){return _A(i,n,t)},decode(i){return EA(i,o,t,r)}})}var Pe=Kn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),IA=Kn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var kp={};bt(kp,{base32:()=>an,base32hex:()=>PA,base32hexpad:()=>OA,base32hexpadupper:()=>RA,base32hexupper:()=>NA,base32pad:()=>BA,base32padupper:()=>kA,base32upper:()=>TA,base32z:()=>DA});var an=$e({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),TA=$e({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),BA=$e({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),kA=$e({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),PA=$e({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),NA=$e({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),OA=$e({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),RA=$e({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),DA=$e({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Pp={};bt(Pp,{base36:()=>ua,base36upper:()=>LA});var ua=Kn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),LA=Kn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var er={};bt(er,{Digest:()=>Bo,create:()=>vt,decode:()=>Hn,equals:()=>Op,hasCode:()=>tS});var UA=cg,sg=128,jA=127,MA=~jA,KA=Math.pow(2,31);function cg(r,e,t){e=e||[],t=t||0;for(var n=t;r>=KA;)e[t++]=r&255|sg,r/=128;for(;r&MA;)e[t++]=r&255|sg,r>>>=7;return e[t]=r|0,cg.bytes=t-n+1,e}var HA=Np,VA=128,ag=127;function Np(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Np.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&ag)<<o:(s&ag)*Math.pow(2,o),o+=7}while(s>=VA);return Np.bytes=i-n,t}var $A=Math.pow(2,7),FA=Math.pow(2,14),WA=Math.pow(2,21),qA=Math.pow(2,28),GA=Math.pow(2,35),zA=Math.pow(2,42),XA=Math.pow(2,49),YA=Math.pow(2,56),ZA=Math.pow(2,63),JA=function(r){return r<$A?1:r<FA?2:r<WA?3:r<qA?4:r<GA?5:r<zA?6:r<XA?7:r<YA?8:r<ZA?9:10},QA={encode:UA,decode:HA,encodingLength:JA},eS=QA,la=eS;function fa(r,e=0){return[la.decode(r,e),la.decode.bytes]}function Gi(r,e,t=0){return la.encode(r,e,t),e}function zi(r){return la.encodingLength(r)}function vt(r,e){let t=e.byteLength,n=zi(r),o=n+zi(t),i=new Uint8Array(o+t);return Gi(r,i,0),Gi(t,i,n),i.set(e,o),new Bo(r,t,e,i)}function Hn(r){let e=sn(r),[t,n]=fa(e),[o,i]=fa(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Bo(t,o,s,e)}function Op(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&eg(r.bytes,t.bytes)}}var Bo=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function tS(r,e){return r.code===e}function ug(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return nS(t,Rp(r),e??Pe.encoder);default:return oS(t,Rp(r),e??an.encoder)}}var lg=new WeakMap;function Rp(r){let e=lg.get(r);if(e==null){let t=new Map;return lg.set(r,t),t}return e}var Xe=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==pa)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==iS)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=vt(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Op(e.multihash,n.multihash)}toString(e){return ug(this,e)}toJSON(){return{"/":ug(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??fg(n,o,i.bytes))}else if(t[sS]===!0){let{version:n,multihash:o,code:i}=t,s=Hn(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==pa)throw new Error(`Version 0 CID must use dag-pb (code: ${pa}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=fg(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,pa,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=sn(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new Bo(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[p,m]=fa(e.subarray(t));return t+=m,p},o=n(),i=pa;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),f=t+c,h=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:h,size:f}}static parse(e,t){let[n,o]=rS(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Rp(i).set(n,e),i}};function rS(r,e){switch(r[0]){case"Q":{let t=e??Pe;return[Pe.prefix,t.decode(`${Pe.prefix}${r}`)]}case Pe.prefix:{let t=e??Pe;return[Pe.prefix,t.decode(r)]}case an.prefix:{let t=e??an;return[an.prefix,t.decode(r)]}case ua.prefix:{let t=e??ua;return[ua.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function nS(r,e,t){let{prefix:n}=t;if(n!==Pe.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function oS(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var pa=112,iS=18;function fg(r,e,t){let n=zi(r),o=n+zi(e),i=new Uint8Array(o+t.byteLength);return Gi(r,i,0),Gi(e,i,n),i.set(t,o),i}var sS=Symbol.for("@ipld/js-cid/CID");var Dp={};bt(Dp,{identity:()=>yr});var pg=0,aS="identity",hg=sn;function cS(r){return vt(pg,hg(r))}var yr={code:pg,name:aS,encode:hg,digest:cS};function Fe(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function rt(r=0){return new Uint8Array(r)}function nt(r=0){return new Uint8Array(r)}function ot(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=nt(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var mg=Symbol.for("@achingbrain/uint8arraylist");function dg(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function Ru(r){return!!r?.[mg]}var be=class r{bufs;length;[mg]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(Ru(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(Ru(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=dg(this.bufs,e);return t.buf[t.index]}set(e,t){let n=dg(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(Ru(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return ot(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:ot(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),i=new r;return i.length=o,i.bufs=[...n],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let f=e>=a&&e<c,h=t>a&&t<=c;if(f&&h){if(e===a&&t===c){n.push(s);break}let p=e-a;n.push(s.subarray(p,p+(t-e)));break}if(f){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(h){if(t===c){n.push(s);break}n.push(s.subarray(0,t-a));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!Ru(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let p=0;p<i;p++)s[p]=-1;for(let p=0;p<o;p++)s[n[p]]=p;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,h;for(let p=t;p<=c;p+=h){h=0;for(let m=f;m>=0;m--){let v=this.get(p+m);if(n[m]!==v){h=Math.max(1,m-a[v]);break}}if(h===0)return p}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=nt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=nt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!Fe(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,i)=>o+i.byteLength,0)),n.length=t,n}};var Lp={};bt(Lp,{base10:()=>lS});var lS=Kn({prefix:"9",name:"base10",alphabet:"0123456789"});var Up={};bt(Up,{base16:()=>fS,base16upper:()=>pS});var fS=$e({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),pS=$e({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var jp={};bt(jp,{base2:()=>hS});var hS=$e({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Mp={};bt(Mp,{base256emoji:()=>wS});var yg=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),dS=yg.reduce((r,e,t)=>(r[t]=e,r),[]),mS=yg.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function yS(r){return r.reduce((e,t)=>(e+=dS[t],e),"")}function gS(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=mS[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var wS=qi({prefix:"\u{1F680}",name:"base256emoji",encode:yS,decode:gS});var Kp={};bt(Kp,{base64:()=>xS,base64pad:()=>bS,base64url:()=>ko,base64urlpad:()=>vS});var xS=$e({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),bS=$e({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ko=$e({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),vS=$e({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Hp={};bt(Hp,{base8:()=>AS});var AS=$e({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Vp={};bt(Vp,{identity:()=>SS});var SS=qi({prefix:"\0",name:"identity",encode:r=>rg(r),decode:r=>tg(r)});var uT=new TextEncoder,lT=new TextDecoder;var Wp={};bt(Wp,{sha256:()=>tr,sha512:()=>CS});function Fp({name:r,code:e,encode:t}){return new $p(r,e,t)}var $p=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?vt(this.code,t):t.then(n=>vt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function wg(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var tr=Fp({name:"sha2-256",code:18,encode:wg("SHA-256")}),CS=Fp({name:"sha2-512",code:19,encode:wg("SHA-512")});var Po={...Vp,...jp,...Hp,...Lp,...Up,...kp,...Pp,...Bp,...Kp,...Mp},AT={...Wp,...Dp};function bg(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var xg=bg("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),qp=bg("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=nt(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),IS={utf8:xg,"utf-8":xg,hex:Po.base16,latin1:qp,ascii:qp,binary:qp,...Po},Du=IS;function de(r,e="utf8"){let t=Du[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function ue(r,e="utf8"){let t=Du[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var TS=parseInt("11111",2),Gp=parseInt("10000000",2),BS=parseInt("01111111",2),vg={0:ha,1:ha,2:kS,3:OS,4:RS,5:NS,6:PS,16:ha,22:ha,48:ha};function cn(r,e={offset:0}){let t=r[e.offset]&TS;if(e.offset++,vg[t]!=null)return vg[t](r,e);throw new Error("No decoder for tag "+t)}function da(r,e){let t=0;if((r[e.offset]&Gp)===Gp){let n=r[e.offset]&BS,o="0x";e.offset++;for(let i=0;i<n;i++,e.offset++)o+=r[e.offset].toString(16).padStart(2,"0");t=parseInt(o,16)}else t=r[e.offset],e.offset++;return t}function ha(r,e){da(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=cn(r,e);if(n===null)break;t.push(n)}return t}function kS(r,e){let t=da(r,e),n=e.offset,o=e.offset+t,i=[];for(let s=n;s<o;s++)s===n&&r[s]===0||i.push(r[s]);return e.offset+=t,Uint8Array.from(i)}function PS(r,e){let t=da(r,e),n=e.offset+t,o=r[e.offset];e.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;e.offset<n;){let f=r[e.offset];if(e.offset++,c.push(f&127),f<128){c.reverse();let h=0;for(let p=0;p<c.length;p++)h+=c[p]<<p*7;a+=`.${h}`,c=[]}}return a}function NS(r,e){return e.offset++,null}function OS(r,e){let t=da(r,e),n=r[e.offset];e.offset++;let o=r.subarray(e.offset,e.offset+t-1);if(e.offset+=t,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function RS(r,e){let t=da(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function DS(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new be;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function Lu(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=DS(r.byteLength);return new be(Uint8Array.from([e.byteLength|Gp]),e)}function kt(r){let e=new be,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new be(Uint8Array.from([2]),Lu(e),e)}function ma(r){let e=Uint8Array.from([0]),t=new be(e,r);return new be(Uint8Array.from([3]),Lu(t),t)}function Ag(r){return new be(Uint8Array.from([4]),Lu(r),r)}function gr(r,e=48){let t=new be;for(let n of r)t.append(n);return new be(Uint8Array.from([e]),Lu(t),t)}async function Sg(r="P-256"){let e=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:r},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",e.publicKey),privateKey:await crypto.subtle.exportKey("jwk",e.privateKey)}}async function Eg(r,e,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 _g(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 LS=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),US=Uint8Array.from([6,5,43,129,4,0,34]),jS=Uint8Array.from([6,5,43,129,4,0,35]),MS={ext:!0,kty:"EC",crv:"P-256"},KS={ext:!0,kty:"EC",crv:"P-384"},HS={ext:!0,kty:"EC",crv:"P-521"},zp=32,Xp=48,Yp=66;function Zp(r){let e=cn(r);return Cg(e)}function Cg(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===zp*2+1)return n=ue(e.subarray(t,t+zp),"base64url"),o=ue(e.subarray(t+zp),"base64url"),new No({...MS,key_ops:["verify"],x:n,y:o});if(e.byteLength===Xp*2+1)return n=ue(e.subarray(t,t+Xp),"base64url"),o=ue(e.subarray(t+Xp),"base64url"),new No({...KS,key_ops:["verify"],x:n,y:o});if(e.byteLength===Yp*2+1)return n=ue(e.subarray(t,t+Yp),"base64url"),o=ue(e.subarray(t+Yp),"base64url"),new No({...HS,key_ops:["verify"],x:n,y:o});throw new Ae(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Ig(r){return gr([kt(Uint8Array.from([1])),Ag(de(r.d??"","base64url")),gr([Bg(r.crv)],160),gr([ma(new be(Uint8Array.from([4]),de(r.x??"","base64url"),de(r.y??"","base64url")))],161)]).subarray()}function Tg(r){return gr([kt(Uint8Array.from([1])),gr([Bg(r.crv)],160),gr([ma(new be(Uint8Array.from([4]),de(r.x??"","base64url"),de(r.y??"","base64url")))],161)]).subarray()}function Bg(r){if(r==="P-256")return LS;if(r==="P-384")return US;if(r==="P-521")return jS;throw new Ae(`Invalid curve ${r}`)}async function kg(r="P-256"){let e=await Sg(r);return new Uu(e.privateKey)}var No=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Tg(this.jwk)),this._raw}toMultihash(){return yr.digest(Vn(this))}toCID(){return Xe.createV1(114,this.toMultihash())}toString(){return Pe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}async verify(e,t,n){return _g(this.jwk,t,e,n)}},Uu=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new No({crv:e.crv,ext:e.ext,key_ops:["verify"],kty:"EC",x:e.x,y:e.y})}get raw(){return this._raw==null&&(this._raw=Ig(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}async sign(e,t){return Eg(this.jwk,e,t)}};var Oo=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function VS(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Xi(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Ro(r,...e){if(!VS(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error("Uint8Array expected of length "+e+", got length="+r.length)}function ya(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Xi(r.outputLen),Xi(r.blockLen)}function Zi(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Pg(r,e){Ro(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function wr(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function ju(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function xr(r,e){return r<<32-e|r>>>e}function Ng(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function $n(r){return typeof r=="string"&&(r=Ng(r)),Ro(r),r}function Jp(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];Ro(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}var Yi=class{};function Qp(r){let e=n=>r().update($n(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function ga(r=32){if(Oo&&typeof Oo.getRandomValues=="function")return Oo.getRandomValues(new Uint8Array(r));if(Oo&&typeof Oo.randomBytes=="function")return Uint8Array.from(Oo.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function $S(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(t>>o&i),a=Number(t&i),c=n?4:0,f=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+f,a,n)}function Og(r,e,t){return r&e^~r&t}function Rg(r,e,t){return r&e^r&t^e&t}var wa=class extends Yi{constructor(e,t,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=ju(this.buffer)}update(e){Zi(this),e=$n(e),Ro(e);let{view:t,buffer:n,blockLen:o}=this,i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=ju(e);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Zi(this),Pg(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,wr(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let p=s;p<o;p++)t[p]=0;$S(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=ju(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,h=this.get();if(f>h.length)throw new Error("_sha2: outputLen bigger than state");for(let p=0;p<f;p++)a.setUint32(4*p,h[p],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.destroyed=s,e.finished=i,e.length=o,e.pos=a,o%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},un=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var lt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Mu=BigInt(4294967295),Dg=BigInt(32);function FS(r,e=!1){return e?{h:Number(r&Mu),l:Number(r>>Dg&Mu)}:{h:Number(r>>Dg&Mu)|0,l:Number(r&Mu)|0}}function Lg(r,e=!1){let t=r.length,n=new Uint32Array(t),o=new Uint32Array(t);for(let i=0;i<t;i++){let{h:s,l:a}=FS(r[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var eh=(r,e,t)=>r>>>t,th=(r,e,t)=>r<<32-t|e>>>t,Do=(r,e,t)=>r>>>t|e<<32-t,Lo=(r,e,t)=>r<<32-t|e>>>t,xa=(r,e,t)=>r<<64-t|e>>>t-32,ba=(r,e,t)=>r>>>t-32|e<<64-t;function Ur(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var Ug=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),jg=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Mg=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Kg=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,Hg=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),Vg=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var qS=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Fn=new Uint32Array(64),Ku=class extends wa{constructor(e=32){super(64,e,8,!1),this.A=un[0]|0,this.B=un[1]|0,this.C=un[2]|0,this.D=un[3]|0,this.E=un[4]|0,this.F=un[5]|0,this.G=un[6]|0,this.H=un[7]|0}get(){let{A:e,B:t,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,t,n,o,i,s,a,c]}set(e,t,n,o,i,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let p=0;p<16;p++,t+=4)Fn[p]=e.getUint32(t,!1);for(let p=16;p<64;p++){let m=Fn[p-15],v=Fn[p-2],g=xr(m,7)^xr(m,18)^m>>>3,w=xr(v,17)^xr(v,19)^v>>>10;Fn[p]=w+Fn[p-7]+g+Fn[p-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:h}=this;for(let p=0;p<64;p++){let m=xr(a,6)^xr(a,11)^xr(a,25),v=h+m+Og(a,c,f)+qS[p]+Fn[p]|0,w=(xr(n,2)^xr(n,13)^xr(n,22))+Rg(n,o,i)|0;h=f,f=c,c=a,a=s+v|0,s=i,i=o,o=n,n=v+w|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,h=h+this.H|0,this.set(n,o,i,s,a,c,f,h)}roundClean(){wr(Fn)}destroy(){this.set(0,0,0,0,0,0,0,0),wr(this.buffer)}};var $g=Lg(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),GS=$g[0],zS=$g[1],Wn=new Uint32Array(80),qn=new Uint32Array(80),rh=class extends wa{constructor(e=64){super(128,e,16,!1),this.Ah=lt[0]|0,this.Al=lt[1]|0,this.Bh=lt[2]|0,this.Bl=lt[3]|0,this.Ch=lt[4]|0,this.Cl=lt[5]|0,this.Dh=lt[6]|0,this.Dl=lt[7]|0,this.Eh=lt[8]|0,this.El=lt[9]|0,this.Fh=lt[10]|0,this.Fl=lt[11]|0,this.Gh=lt[12]|0,this.Gl=lt[13]|0,this.Hh=lt[14]|0,this.Hl=lt[15]|0}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:h,Fh:p,Fl:m,Gh:v,Gl:g,Hh:w,Hl:S}=this;return[e,t,n,o,i,s,a,c,f,h,p,m,v,g,w,S]}set(e,t,n,o,i,s,a,c,f,h,p,m,v,g,w,S){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=h|0,this.Fh=p|0,this.Fl=m|0,this.Gh=v|0,this.Gl=g|0,this.Hh=w|0,this.Hl=S|0}process(e,t){for(let T=0;T<16;T++,t+=4)Wn[T]=e.getUint32(t),qn[T]=e.getUint32(t+=4);for(let T=16;T<80;T++){let b=Wn[T-15]|0,D=qn[T-15]|0,V=Do(b,D,1)^Do(b,D,8)^eh(b,D,7),N=Lo(b,D,1)^Lo(b,D,8)^th(b,D,7),U=Wn[T-2]|0,$=qn[T-2]|0,X=Do(U,$,19)^xa(U,$,61)^eh(U,$,6),M=Lo(U,$,19)^ba(U,$,61)^th(U,$,6),G=Mg(N,M,qn[T-7],qn[T-16]),F=Kg(G,V,X,Wn[T-7],Wn[T-16]);Wn[T]=F|0,qn[T]=G|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:h,Eh:p,El:m,Fh:v,Fl:g,Gh:w,Gl:S,Hh:O,Hl:Y}=this;for(let T=0;T<80;T++){let b=Do(p,m,14)^Do(p,m,18)^xa(p,m,41),D=Lo(p,m,14)^Lo(p,m,18)^ba(p,m,41),V=p&v^~p&w,N=m&g^~m&S,U=Hg(Y,D,N,zS[T],qn[T]),$=Vg(U,O,b,V,GS[T],Wn[T]),X=U|0,M=Do(n,o,28)^xa(n,o,34)^xa(n,o,39),G=Lo(n,o,28)^ba(n,o,34)^ba(n,o,39),F=n&i^n&a^i&a,ie=o&s^o&c^s&c;O=w|0,Y=S|0,w=v|0,S=g|0,v=p|0,g=m|0,{h:p,l:m}=Ur(f|0,h|0,$|0,X|0),f=a|0,h=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let k=Ug(X,G,ie);n=jg(k,$,M,F),o=k|0}({h:n,l:o}=Ur(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Ur(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Ur(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:h}=Ur(this.Dh|0,this.Dl|0,f|0,h|0),{h:p,l:m}=Ur(this.Eh|0,this.El|0,p|0,m|0),{h:v,l:g}=Ur(this.Fh|0,this.Fl|0,v|0,g|0),{h:w,l:S}=Ur(this.Gh|0,this.Gl|0,w|0,S|0),{h:O,l:Y}=Ur(this.Hh|0,this.Hl|0,O|0,Y|0),this.set(n,o,i,s,a,c,f,h,p,m,v,g,w,S,O,Y)}roundClean(){wr(Wn,qn)}destroy(){wr(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Hu=Qp(()=>new Ku);var Fg=Qp(()=>new rh);var sh=BigInt(0),ih=BigInt(1);function Ji(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function ah(r){if(!Ji(r))throw new Error("Uint8Array expected")}function jr(r,e){if(typeof e!="boolean")throw new Error(r+" boolean expected, got "+e)}function va(r){let e=r.toString(16);return e.length&1?"0"+e:e}function Gg(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?sh:BigInt("0x"+r)}var zg=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",XS=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Gn(r){if(ah(r),zg)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=XS[r[t]];return e}var ln={_0:48,_9:57,A:65,F:70,a:97,f:102};function Wg(r){if(r>=ln._0&&r<=ln._9)return r-ln._0;if(r>=ln.A&&r<=ln.F)return r-(ln.A-10);if(r>=ln.a&&r<=ln.f)return r-(ln.a-10)}function Aa(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(zg)return Uint8Array.fromHex(r);let e=r.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,i=0;o<t;o++,i+=2){let s=Wg(r.charCodeAt(i)),a=Wg(r.charCodeAt(i+1));if(s===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function fn(r){return Gg(Gn(r))}function Mr(r){return ah(r),Gg(Gn(Uint8Array.from(r).reverse()))}function Uo(r,e){return Aa(r.toString(16).padStart(e*2,"0"))}function zn(r,e){return Uo(r,e).reverse()}function Oe(r,e,t){let n;if(typeof e=="string")try{n=Aa(e)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(Ji(e))n=Uint8Array.from(e);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof t=="number"&&o!==t)throw new Error(r+" of length "+t+" expected, got "+o);return n}function Xn(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];ah(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}var nh=r=>typeof r=="bigint"&&sh<=r;function Vu(r,e,t){return nh(r)&&nh(e)&&nh(t)&&e<=r&&r<t}function At(r,e,t,n){if(!Vu(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function Xg(r){let e;for(e=0;r>sh;r>>=ih,e+=1);return e}var jo=r=>(ih<<BigInt(r))-ih,oh=r=>new Uint8Array(r),qg=r=>Uint8Array.from(r);function Yg(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=oh(r),o=oh(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...p)=>t(o,n,...p),c=(p=oh(0))=>{o=a(qg([0]),p),n=a(),p.length!==0&&(o=a(qg([1]),p),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let p=0,m=[];for(;p<e;){n=a();let v=n.slice();m.push(v),p+=n.length}return Xn(...m)};return(p,m)=>{s(),c(p);let v;for(;!(v=m(f()));)c();return s(),v}}var YS={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Ji(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function br(r,e,t={}){let n=(o,i,s)=>{let a=YS[i];if(typeof a!="function")throw new Error("invalid validator function");let c=r[o];if(!(s&&c===void 0)&&!a(c,r))throw new Error("param "+String(o)+" is invalid. Expected "+i+", got "+c)};for(let[o,i]of Object.entries(e))n(o,i,!1);for(let[o,i]of Object.entries(t))n(o,i,!0);return r}function Qi(r){let e=new WeakMap;return(t,...n)=>{let o=e.get(t);if(o!==void 0)return o;let i=r(t,...n);return e.set(t,i),i}}var Pt=BigInt(0),at=BigInt(1),Mo=BigInt(2),ZS=BigInt(3),Jg=BigInt(4),Qg=BigInt(5),e0=BigInt(8);function Ce(r,e){let t=r%e;return t>=Pt?t:e+t}function Me(r,e,t){let n=r;for(;e-- >Pt;)n*=n,n%=t;return n}function $u(r,e){if(r===Pt)throw new Error("invert: expected non-zero number");if(e<=Pt)throw new Error("invert: expected positive modulus, got "+e);let t=Ce(r,e),n=e,o=Pt,i=at,s=at,a=Pt;for(;t!==Pt;){let f=n/t,h=n%t,p=o-s*f,m=i-a*f;n=t,t=h,o=s,i=a,s=p,a=m}if(n!==at)throw new Error("invert: does not exist");return Ce(o,e)}function t0(r,e){let t=(r.ORDER+at)/Jg,n=r.pow(e,t);if(!r.eql(r.sqr(n),e))throw new Error("Cannot find square root");return n}function JS(r,e){let t=(r.ORDER-Qg)/e0,n=r.mul(e,Mo),o=r.pow(n,t),i=r.mul(e,o),s=r.mul(r.mul(i,Mo),o),a=r.mul(i,r.sub(s,r.ONE));if(!r.eql(r.sqr(a),e))throw new Error("Cannot find square root");return a}function QS(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let e=r-at,t=0;for(;e%Mo===Pt;)e/=Mo,t++;let n=Mo,o=pn(r);for(;Zg(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return t0;let i=o.pow(n,e),s=(e+at)/Mo;return function(c,f){if(c.is0(f))return f;if(Zg(c,f)!==1)throw new Error("Cannot find square root");let h=t,p=c.mul(c.ONE,i),m=c.pow(f,e),v=c.pow(f,s);for(;!c.eql(m,c.ONE);){if(c.is0(m))return c.ZERO;let g=1,w=c.sqr(m);for(;!c.eql(w,c.ONE);)if(g++,w=c.sqr(w),g===h)throw new Error("Cannot find square root");let S=at<<BigInt(h-g-1),O=c.pow(p,S);h=g,p=c.sqr(O),m=c.mul(m,p),v=c.mul(v,O)}return v}}function eE(r){return r%Jg===ZS?t0:r%e0===Qg?JS:QS(r)}var r0=(r,e)=>(Ce(r,e)&at)===at,tE=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ch(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=tE.reduce((n,o)=>(n[o]="function",n),e);return br(r,t)}function rE(r,e,t){if(t<Pt)throw new Error("invalid exponent, negatives unsupported");if(t===Pt)return r.ONE;if(t===at)return e;let n=r.ONE,o=e;for(;t>Pt;)t&at&&(n=r.mul(n,o)),o=r.sqr(o),t>>=at;return n}function es(r,e,t=!1){let n=new Array(e.length).fill(t?r.ZERO:void 0),o=e.reduce((s,a,c)=>r.is0(a)?s:(n[c]=s,r.mul(s,a)),r.ONE),i=r.inv(o);return e.reduceRight((s,a,c)=>r.is0(a)?s:(n[c]=r.mul(s,n[c]),r.mul(s,a)),i),n}function Zg(r,e){let t=(r.ORDER-at)/Mo,n=r.pow(e,t),o=r.eql(n,r.ONE),i=r.eql(n,r.ZERO),s=r.eql(n,r.neg(r.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function uh(r,e){e!==void 0&&Xi(e);let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function pn(r,e,t=!1,n={}){if(r<=Pt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:i}=uh(r,e);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s,a=Object.freeze({ORDER:r,isLE:t,BITS:o,BYTES:i,MASK:jo(o),ZERO:Pt,ONE:at,create:c=>Ce(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return Pt<=c&&c<r},is0:c=>c===Pt,isOdd:c=>(c&at)===at,neg:c=>Ce(-c,r),eql:(c,f)=>c===f,sqr:c=>Ce(c*c,r),add:(c,f)=>Ce(c+f,r),sub:(c,f)=>Ce(c-f,r),mul:(c,f)=>Ce(c*f,r),pow:(c,f)=>rE(a,c,f),div:(c,f)=>Ce(c*$u(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>$u(c,r),sqrt:n.sqrt||(c=>(s||(s=eE(r)),s(a,c))),toBytes:c=>t?zn(c,i):Uo(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return t?Mr(c):fn(c)},invertBatch:c=>es(a,c),cmov:(c,f,h)=>h?f:c});return Object.freeze(a)}function n0(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function lh(r){let e=n0(r);return e+Math.ceil(e/2)}function o0(r,e,t=!1){let n=r.length,o=n0(e),i=lh(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?Mr(r):fn(r),a=Ce(s,e-at)+at;return t?zn(a,o):Uo(a,o)}var i0=BigInt(0),mh=BigInt(1);function fh(r,e){let t=e.negate();return r?t:e}function a0(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function ph(r,e){a0(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=jo(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function s0(r,e,t){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=t,a=Number(r&o),c=r>>s;a>n&&(a-=i,c+=mh);let f=e*n,h=f+Math.abs(a)-1,p=a===0,m=a<0,v=e%2!==0;return{nextN:c,offset:h,isZero:p,isNeg:m,isNegF:v,offsetF:f}}function nE(r,e){if(!Array.isArray(r))throw new Error("array expected");r.forEach((t,n)=>{if(!(t instanceof e))throw new Error("invalid point at index "+n)})}function oE(r,e){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((t,n)=>{if(!e.isValid(t))throw new Error("invalid scalar at index "+n)})}var hh=new WeakMap,c0=new WeakMap;function dh(r){return c0.get(r)||1}function Fu(r,e){return{constTimeNegate:fh,hasPrecomputes(t){return dh(t)!==1},unsafeLadder(t,n,o=r.ZERO){let i=t;for(;n>i0;)n&mh&&(o=o.add(i)),i=i.double(),n>>=mh;return o},precomputeWindow(t,n){let{windows:o,windowSize:i}=ph(n,e),s=[],a=t,c=a;for(let f=0;f<o;f++){c=a,s.push(c);for(let h=1;h<i;h++)c=c.add(a),s.push(c);a=c.double()}return s},wNAF(t,n,o){let i=r.ZERO,s=r.BASE,a=ph(t,e);for(let c=0;c<a.windows;c++){let{nextN:f,offset:h,isZero:p,isNeg:m,isNegF:v,offsetF:g}=s0(o,c,a);o=f,p?s=s.add(fh(v,n[g])):i=i.add(fh(m,n[h]))}return{p:i,f:s}},wNAFUnsafe(t,n,o,i=r.ZERO){let s=ph(t,e);for(let a=0;a<s.windows&&o!==i0;a++){let{nextN:c,offset:f,isZero:h,isNeg:p}=s0(o,a,s);if(o=c,!h){let m=n[f];i=i.add(p?m.negate():m)}}return i},getPrecomputes(t,n,o){let i=hh.get(n);return i||(i=this.precomputeWindow(n,t),t!==1&&hh.set(n,o(i))),i},wNAFCached(t,n,o){let i=dh(t);return this.wNAF(i,this.getPrecomputes(i,t,o),n)},wNAFCachedUnsafe(t,n,o,i){let s=dh(t);return s===1?this.unsafeLadder(t,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,t,o),n,i)},setWindowSize(t,n){a0(n,e),c0.set(t,n),hh.delete(t)}}}function Wu(r,e,t,n){nE(t,r),oE(n,e);let o=t.length,i=n.length;if(o!==i)throw new Error("arrays of points and scalars must have equal length");let s=r.ZERO,a=Xg(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let f=jo(c),h=new Array(Number(f)+1).fill(s),p=Math.floor((e.BITS-1)/c)*c,m=s;for(let v=p;v>=0;v-=c){h.fill(s);for(let w=0;w<i;w++){let S=n[w],O=Number(S>>BigInt(v)&f);h[O]=h[O].add(t[w])}let g=s;for(let w=h.length-1,S=s;w>0;w--)S=S.add(h[w]),g=g.add(S);if(m=m.add(g),v!==0)for(let w=0;w<c;w++)m=m.double()}return m}function Sa(r){return ch(r.Fp),br(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...uh(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Kr=BigInt(0),Nt=BigInt(1),u0=BigInt(2),iE=BigInt(8),sE={zip215:!0};function aE(r){let e=Sa(r);return br(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function l0(r){let e=aE(r),{Fp:t,n,prehash:o,hash:i,randomBytes:s,nByteLength:a,h:c}=e,f=u0<<BigInt(a*8)-Nt,h=t.create,p=pn(e.n,e.nBitLength);function m(P,y){let C=t.sqr(P),L=t.sqr(y),I=t.add(t.mul(e.a,C),L),re=t.add(t.ONE,t.mul(e.d,t.mul(C,L)));return t.eql(I,re)}if(!m(e.Gx,e.Gy))throw new Error("bad curve params: generator point");let v=e.uvRatio||((P,y)=>{try{return{isValid:!0,value:t.sqrt(P*t.inv(y))}}catch{return{isValid:!1,value:Kr}}}),g=e.adjustScalarBytes||(P=>P),w=e.domain||((P,y,C)=>{if(jr("phflag",C),y.length||C)throw new Error("Contexts/pre-hash are not supported");return P});function S(P,y,C=!1){let L=C?Nt:Kr;At("coordinate "+P,y,L,f)}function O(P){if(!(P instanceof b))throw new Error("ExtendedPoint expected")}let Y=Qi((P,y)=>{let{ex:C,ey:L,ez:I}=P,re=P.is0();y==null&&(y=re?iE:t.inv(I));let le=h(C*y),Q=h(L*y),pe=h(I*y);if(re)return{x:Kr,y:Nt};if(pe!==Nt)throw new Error("invZ was invalid");return{x:le,y:Q}}),T=Qi(P=>{let{a:y,d:C}=e;if(P.is0())throw new Error("bad point: ZERO");let{ex:L,ey:I,ez:re,et:le}=P,Q=h(L*L),pe=h(I*I),he=h(re*re),Ee=h(he*he),_e=h(Q*y),ke=h(he*h(_e+pe)),ut=h(Ee+h(C*h(Q*pe)));if(ke!==ut)throw new Error("bad point: equation left != right (1)");let Ue=h(L*I),et=h(re*le);if(Ue!==et)throw new Error("bad point: equation left != right (2)");return!0});class b{constructor(y,C,L,I){S("x",y),S("y",C),S("z",L,!0),S("t",I),this.ex=y,this.ey=C,this.ez=L,this.et=I,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(y){if(y instanceof b)throw new Error("extended point not allowed");let{x:C,y:L}=y||{};return S("x",C),S("y",L),new b(C,L,Nt,h(C*L))}static normalizeZ(y){let C=es(t,y.map(L=>L.ez));return y.map((L,I)=>L.toAffine(C[I])).map(b.fromAffine)}static msm(y,C){return Wu(b,p,y,C)}_setWindowSize(y){N.setWindowSize(this,y)}assertValidity(){T(this)}equals(y){O(y);let{ex:C,ey:L,ez:I}=this,{ex:re,ey:le,ez:Q}=y,pe=h(C*Q),he=h(re*I),Ee=h(L*Q),_e=h(le*I);return pe===he&&Ee===_e}is0(){return this.equals(b.ZERO)}negate(){return new b(h(-this.ex),this.ey,this.ez,h(-this.et))}double(){let{a:y}=e,{ex:C,ey:L,ez:I}=this,re=h(C*C),le=h(L*L),Q=h(u0*h(I*I)),pe=h(y*re),he=C+L,Ee=h(h(he*he)-re-le),_e=pe+le,ke=_e-Q,ut=pe-le,Ue=h(Ee*ke),et=h(_e*ut),Tt=h(Ee*ut),Bt=h(ke*_e);return new b(Ue,et,Bt,Tt)}add(y){O(y);let{a:C,d:L}=e,{ex:I,ey:re,ez:le,et:Q}=this,{ex:pe,ey:he,ez:Ee,et:_e}=y,ke=h(I*pe),ut=h(re*he),Ue=h(Q*L*_e),et=h(le*Ee),Tt=h((I+re)*(pe+he)-ke-ut),Bt=et-Ue,Un=et+Ue,ia=h(ut-C*ke),xu=h(Tt*Bt),bu=h(Un*ia),vu=h(Tt*ia),sa=h(Bt*Un);return new b(xu,bu,sa,vu)}subtract(y){return this.add(y.negate())}wNAF(y){return N.wNAFCached(this,y,b.normalizeZ)}multiply(y){let C=y;At("scalar",C,Nt,n);let{p:L,f:I}=this.wNAF(C);return b.normalizeZ([L,I])[0]}multiplyUnsafe(y,C=b.ZERO){let L=y;return At("scalar",L,Kr,n),L===Kr?V:this.is0()||L===Nt?this:N.wNAFCachedUnsafe(this,L,b.normalizeZ,C)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return N.unsafeLadder(this,n).is0()}toAffine(y){return Y(this,y)}clearCofactor(){let{h:y}=e;return y===Nt?this:this.multiplyUnsafe(y)}static fromHex(y,C=!1){let{d:L,a:I}=e,re=t.BYTES;y=Oe("pointHex",y,re),jr("zip215",C);let le=y.slice(),Q=y[re-1];le[re-1]=Q&-129;let pe=Mr(le),he=C?f:t.ORDER;At("pointHex.y",pe,Kr,he);let Ee=h(pe*pe),_e=h(Ee-Nt),ke=h(L*Ee-I),{isValid:ut,value:Ue}=v(_e,ke);if(!ut)throw new Error("Point.fromHex: invalid y coordinate");let et=(Ue&Nt)===Nt,Tt=(Q&128)!==0;if(!C&&Ue===Kr&&Tt)throw new Error("Point.fromHex: x=0 and x_0=1");return Tt!==et&&(Ue=h(-Ue)),b.fromAffine({x:Ue,y:pe})}static fromPrivateKey(y){let{scalar:C}=X(y);return D.multiply(C)}toRawBytes(){let{x:y,y:C}=this.toAffine(),L=zn(C,t.BYTES);return L[L.length-1]|=y&Nt?128:0,L}toHex(){return Gn(this.toRawBytes())}}b.BASE=new b(e.Gx,e.Gy,Nt,h(e.Gx*e.Gy)),b.ZERO=new b(Kr,Nt,Nt,Kr);let{BASE:D,ZERO:V}=b,N=Fu(b,a*8);function U(P){return Ce(P,n)}function $(P){return U(Mr(P))}function X(P){let y=t.BYTES;P=Oe("private key",P,y);let C=Oe("hashed private key",i(P),2*y),L=g(C.slice(0,y)),I=C.slice(y,2*y),re=$(L);return{head:L,prefix:I,scalar:re}}function M(P){let{head:y,prefix:C,scalar:L}=X(P),I=D.multiply(L),re=I.toRawBytes();return{head:y,prefix:C,scalar:L,point:I,pointBytes:re}}function G(P){return M(P).pointBytes}function F(P=Uint8Array.of(),...y){let C=Xn(...y);return $(i(w(C,Oe("context",P),!!o)))}function ie(P,y,C={}){P=Oe("message",P),o&&(P=o(P));let{prefix:L,scalar:I,pointBytes:re}=M(y),le=F(C.context,L,P),Q=D.multiply(le).toRawBytes(),pe=F(C.context,Q,re,P),he=U(le+pe*I);At("signature.s",he,Kr,n);let Ee=Xn(Q,zn(he,t.BYTES));return Oe("result",Ee,t.BYTES*2)}let k=sE;function R(P,y,C,L=k){let{context:I,zip215:re}=L,le=t.BYTES;P=Oe("signature",P,2*le),y=Oe("message",y),C=Oe("publicKey",C,le),re!==void 0&&jr("zip215",re),o&&(y=o(y));let Q=Mr(P.slice(le,2*le)),pe,he,Ee;try{pe=b.fromHex(C,re),he=b.fromHex(P.slice(0,le),re),Ee=D.multiplyUnsafe(Q)}catch{return!1}if(!re&&pe.isSmallOrder())return!1;let _e=F(I,he.toRawBytes(),pe.toRawBytes(),y);return he.add(pe.multiplyUnsafe(_e)).subtract(Ee).clearCofactor().equals(b.ZERO)}return D._setWindowSize(8),{CURVE:e,getPublicKey:G,sign:ie,verify:R,ExtendedPoint:b,utils:{getExtendedPublicKey:M,randomPrivateKey:()=>s(t.BYTES),precompute(P=8,y=b.BASE){return y._setWindowSize(P),y.multiply(BigInt(3)),y}}}}var Ea=BigInt(0),ts=BigInt(1),qu=BigInt(2);function cE(r){return br(r,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r})}function f0(r){let e=cE(r),{P:t,type:n,adjustScalarBytes:o,powPminus2:i}=e,s=n==="x25519";if(!s&&n!=="x448")throw new Error("invalid type");let a=s?255:448,c=s?32:56,f=BigInt(s?9:5),h=BigInt(s?121665:39081),p=s?qu**BigInt(254):qu**BigInt(447),m=s?BigInt(8)*qu**BigInt(251)-ts:BigInt(4)*qu**BigInt(445)-ts,v=p+m+ts,g=N=>Ce(N,t),w=S(f);function S(N){return zn(g(N),c)}function O(N){let U=Oe("u coordinate",N,c);return s&&(U[31]&=127),g(Mr(U))}function Y(N){return Mr(o(Oe("scalar",N,c)))}function T(N,U){let $=V(O(U),Y(N));if($===Ea)throw new Error("invalid private or public key received");return S($)}function b(N){return T(N,w)}function D(N,U,$){let X=g(N*(U-$));return U=g(U-X),$=g($+X),{x_2:U,x_3:$}}function V(N,U){At("u",N,Ea,t),At("scalar",U,p,v);let $=U,X=N,M=ts,G=Ea,F=N,ie=ts,k=Ea;for(let K=BigInt(a-1);K>=Ea;K--){let P=$>>K&ts;k^=P,{x_2:M,x_3:F}=D(k,M,F),{x_2:G,x_3:ie}=D(k,G,ie),k=P;let y=M+G,C=g(y*y),L=M-G,I=g(L*L),re=C-I,le=F+ie,Q=F-ie,pe=g(Q*y),he=g(le*L),Ee=pe+he,_e=pe-he;F=g(Ee*Ee),ie=g(X*g(_e*_e)),M=g(C*I),G=g(re*(C+g(h*re)))}({x_2:M,x_3:F}=D(k,M,F)),{x_2:G,x_3:ie}=D(k,G,ie);let R=i(G);return g(M*R)}return{scalarMult:T,scalarMultBase:b,getSharedSecret:(N,U)=>T(N,U),getPublicKey:N=>b(N),utils:{randomPrivateKey:()=>e.randomBytes(c)},GuBytes:w.slice()}}var _a=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),p0=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),CB=BigInt(0),uE=BigInt(1),h0=BigInt(2),lE=BigInt(3),fE=BigInt(5),pE=BigInt(8);function m0(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=_a,a=r*r%i*r%i,c=Me(a,h0,i)*a%i,f=Me(c,uE,i)*r%i,h=Me(f,fE,i)*f%i,p=Me(h,e,i)*h%i,m=Me(p,t,i)*p%i,v=Me(m,n,i)*m%i,g=Me(v,o,i)*v%i,w=Me(g,o,i)*v%i,S=Me(w,e,i)*h%i;return{pow_p_5_8:Me(S,h0,i)*r%i,b2:a}}function y0(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function hE(r,e){let t=_a,n=Ce(e*e*e,t),o=Ce(n*n*e,t),i=m0(r*o).pow_p_5_8,s=Ce(r*n*i,t),a=Ce(e*s*s,t),c=s,f=Ce(s*p0,t),h=a===r,p=a===Ce(-r,t),m=a===Ce(-r*p0,t);return h&&(s=c),(p||m)&&(s=f),r0(s,t)&&(s=Ce(-s,t)),{isValid:h||p,value:s}}var d0=pn(_a,void 0,!0),dE={a:d0.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:d0,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:pE,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Fg,randomBytes:ga,adjustScalarBytes:y0,uvRatio:hE},Ca=l0(dE);var Ia=f0({P:_a,type:"x25519",powPminus2:r=>{let e=_a,{pow_p_5_8:t,b2:n}=m0(r);return Ce(Me(t,lE,e)*n,e)},adjustScalarBytes:y0,randomBytes:ga});var Gu=32,zu=64,yh=32;function g0(){let r=Ca.utils.randomPrivateKey(),e=Ca.getPublicKey(r);return{privateKey:mE(r,e),publicKey:e}}function w0(r,e){let t=r.subarray(0,yh);return Ca.sign(e instanceof Uint8Array?e:e.subarray(),t)}function x0(r,e,t){return Ca.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function mE(r,e){let t=new Uint8Array(zu);for(let n=0;n<yh;n++)t[n]=r[n],t[yh+n]=e[n];return t}var Ta=class{type="Ed25519";raw;constructor(e){this.raw=Yu(e,Gu)}toMultihash(){return yr.digest(Vn(this))}toCID(){return Xe.createV1(114,this.toMultihash())}toString(){return Pe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}verify(e,t,n){return n?.signal?.throwIfAborted(),x0(this.raw,t,e)}},Xu=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=Yu(e,zu),this.publicKey=new Ta(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}sign(e,t){return t?.signal?.throwIfAborted(),w0(this.raw,e)}};function gh(r){return r=Yu(r,Gu),new Ta(r)}async function v0(){let{privateKey:r,publicKey:e}=g0();return new Xu(r,e)}function Yu(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new Ae(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var yE=Math.pow(2,7),gE=Math.pow(2,14),wE=Math.pow(2,21),wh=Math.pow(2,28),xh=Math.pow(2,35),bh=Math.pow(2,42),vh=Math.pow(2,49),Te=128,St=127;function Ke(r){if(r<yE)return 1;if(r<gE)return 2;if(r<wE)return 3;if(r<wh)return 4;if(r<xh)return 5;if(r<bh)return 6;if(r<vh)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ah(r,e,t=0){switch(Ke(r)){case 8:e[t++]=r&255|Te,r/=128;case 7:e[t++]=r&255|Te,r/=128;case 6:e[t++]=r&255|Te,r/=128;case 5:e[t++]=r&255|Te,r/=128;case 4:e[t++]=r&255|Te,r>>>=7;case 3:e[t++]=r&255|Te,r>>>=7;case 2:e[t++]=r&255|Te,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function xE(r,e,t=0){switch(Ke(r)){case 8:e.set(t++,r&255|Te),r/=128;case 7:e.set(t++,r&255|Te),r/=128;case 6:e.set(t++,r&255|Te),r/=128;case 5:e.set(t++,r&255|Te),r/=128;case 4:e.set(t++,r&255|Te),r>>>=7;case 3:e.set(t++,r&255|Te),r>>>=7;case 2:e.set(t++,r&255|Te),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Sh(r,e){let t=r[e],n=0;if(n+=t&St,t<Te||(t=r[e+1],n+=(t&St)<<7,t<Te)||(t=r[e+2],n+=(t&St)<<14,t<Te)||(t=r[e+3],n+=(t&St)<<21,t<Te)||(t=r[e+4],n+=(t&St)*wh,t<Te)||(t=r[e+5],n+=(t&St)*xh,t<Te)||(t=r[e+6],n+=(t&St)*bh,t<Te)||(t=r[e+7],n+=(t&St)*vh,t<Te))return n;throw new RangeError("Could not decode varint")}function bE(r,e){let t=r.get(e),n=0;if(n+=t&St,t<Te||(t=r.get(e+1),n+=(t&St)<<7,t<Te)||(t=r.get(e+2),n+=(t&St)<<14,t<Te)||(t=r.get(e+3),n+=(t&St)<<21,t<Te)||(t=r.get(e+4),n+=(t&St)*wh,t<Te)||(t=r.get(e+5),n+=(t&St)*xh,t<Te)||(t=r.get(e+6),n+=(t&St)*bh,t<Te)||(t=r.get(e+7),n+=(t&St)*vh,t<Te))return n;throw new RangeError("Could not decode varint")}function Hr(r,e,t=0){return e==null&&(e=nt(Ke(r))),e instanceof Uint8Array?Ah(r,e,t):xE(r,e,t)}function vr(r,e=0){return r instanceof Uint8Array?Sh(r,e):bE(r,e)}var Eh=new Float32Array([-0]),Yn=new Uint8Array(Eh.buffer);function A0(r,e,t){Eh[0]=r,e[t]=Yn[0],e[t+1]=Yn[1],e[t+2]=Yn[2],e[t+3]=Yn[3]}function S0(r,e){return Yn[0]=r[e],Yn[1]=r[e+1],Yn[2]=r[e+2],Yn[3]=r[e+3],Eh[0]}var _h=new Float64Array([-0]),Et=new Uint8Array(_h.buffer);function E0(r,e,t){_h[0]=r,e[t]=Et[0],e[t+1]=Et[1],e[t+2]=Et[2],e[t+3]=Et[3],e[t+4]=Et[4],e[t+5]=Et[5],e[t+6]=Et[6],e[t+7]=Et[7]}function _0(r,e){return Et[0]=r[e],Et[1]=r[e+1],Et[2]=r[e+2],Et[3]=r[e+3],Et[4]=r[e+4],Et[5]=r[e+5],Et[6]=r[e+6],Et[7]=r[e+7],_h[0]}var vE=BigInt(Number.MAX_SAFE_INTEGER),AE=BigInt(Number.MIN_SAFE_INTEGER),Xt=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Ko;if(e<vE&&e>AE)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>C0&&(o=0n,++n>C0&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return Ko;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):Ko}},Ko=new Xt(0,0);Ko.toBigInt=function(){return 0n};Ko.zzEncode=Ko.zzDecode=function(){return this};Ko.length=function(){return 1};var C0=4294967296n;function I0(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function T0(r,e,t){if(t-e<1)return"";let o,i=[],s=0,a;for(;e<t;)a=r[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Ch(r,e,t){let n=t,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function Ar(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Zu(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Ih=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ar(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ar(this,4);return Zu(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ar(this,4);return Zu(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ar(this,4);let e=S0(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ar(this,4);let e=_0(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw Ar(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return T0(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ar(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ar(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Xt(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw Ar(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw Ar(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ar(this,8);let e=Zu(this.buf,this.pos+=4),t=Zu(this.buf,this.pos+=4);return new Xt(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Sh(this.buf,this.pos);return this.pos+=Ke(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Th(r){return new Ih(r instanceof Uint8Array?r:r.subarray())}function Sr(r,e,t){let n=Th(r);return e.decode(n,void 0,t)}function Bh(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return nt(s);o+s>e&&(n=nt(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Ho=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function kh(){}var Nh=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},SE=Bh();function EE(r){return globalThis.Buffer!=null?nt(r):SE(r)}var Pa=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ho(kh,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Ho(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Oh((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Ju,10,Xt.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Xt.fromBigInt(e);return this._push(Ju,t.length(),t)}uint64Number(e){return this._push(Ah,Ke(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Xt.fromBigInt(e).zzEncode();return this._push(Ju,t.length(),t)}sint64Number(e){let t=Xt.fromNumber(e).zzEncode();return this._push(Ju,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ph,1,e?1:0)}fixed32(e){return this._push(ka,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Xt.fromBigInt(e);return this._push(ka,4,t.lo)._push(ka,4,t.hi)}fixed64Number(e){let t=Xt.fromNumber(e);return this._push(ka,4,t.lo)._push(ka,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(A0,4,e)}double(e){return this._push(E0,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Ph,1,0):this.uint32(t)._push(CE,t,e)}string(e){let t=I0(e);return t!==0?this.uint32(t)._push(Ch,t,e):this._push(Ph,1,0)}fork(){return this.states=new Nh(this),this.head=this.tail=new Ho(kh,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Ho(kh,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=EE(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Ph(r,e,t){e[t]=r&255}function _E(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Oh=class extends Ho{next;constructor(e,t){super(_E,e,t),this.next=void 0}};function Ju(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function ka(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function CE(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Pa.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(IE,e,r),this},Pa.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(TE,e,r),this});function IE(r,e,t){e.set(r,t)}function TE(r,e,t){r.length<40?Ch(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(de(r),t)}function Rh(){return new Pa}function Er(r,e){let t=Rh();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var rs;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(rs||(rs={}));function Qu(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Vo(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return Qu("enum",rs.VARINT,t,n)}function _r(r,e){return Qu("message",rs.LENGTH_DELIMITED,r,e)}var Na=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Ye;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Ye||(Ye={}));var Dh;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Dh||(Dh={}));(function(r){r.codec=()=>Vo(Dh)})(Ye||(Ye={}));var Vr;(function(r){let e;r.codec=()=>(e==null&&(e=_r((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Ye.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=Ye.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Er(t,r.codec()),r.decode=(t,n)=>Sr(t,r.codec(),n)})(Vr||(Vr={}));var Lh;(function(r){let e;r.codec=()=>(e==null&&(e=_r((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Ye.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=Ye.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Er(t,r.codec()),r.decode=(t,n)=>Sr(t,r.codec(),n)})(Lh||(Lh={}));var Oa=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},Ra=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},el=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var P0={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new el("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Zn=P0;var La={};bt(La,{MAX_RSA_KEY_SIZE:()=>Uh,generateRSAKeyPair:()=>qh,jwkToJWKKeyPair:()=>D0,jwkToPkcs1:()=>NE,jwkToPkix:()=>Hh,jwkToRSAPrivateKey:()=>Wh,pkcs1MessageToJwk:()=>Mh,pkcs1MessageToRSAPrivateKey:()=>Vh,pkcs1ToJwk:()=>PE,pkcs1ToRSAPrivateKey:()=>R0,pkixMessageToJwk:()=>Kh,pkixMessageToRSAPublicKey:()=>Fh,pkixToJwk:()=>OE,pkixToRSAPublicKey:()=>$h});var Jn=Hu;var ns=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=La.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return Xe.createV1(114,this._multihash)}toString(){return Pe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}verify(e,t,n){return O0(this.jwk,t,e,n)}},Da=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=La.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}sign(e,t){return N0(this.jwk,e,t)}};var Uh=8192,jh=18,BE=1062,kE=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function PE(r){let e=cn(r);return Mh(e)}function Mh(r){return{n:ue(r[1],"base64url"),e:ue(r[2],"base64url"),d:ue(r[3],"base64url"),p:ue(r[4],"base64url"),q:ue(r[5],"base64url"),dp:ue(r[6],"base64url"),dq:ue(r[7],"base64url"),qi:ue(r[8],"base64url"),kty:"RSA"}}function NE(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new Ae("JWK was missing components");return gr([kt(Uint8Array.from([0])),kt(de(r.n,"base64url")),kt(de(r.e,"base64url")),kt(de(r.d,"base64url")),kt(de(r.p,"base64url")),kt(de(r.q,"base64url")),kt(de(r.dp,"base64url")),kt(de(r.dq,"base64url")),kt(de(r.qi,"base64url"))]).subarray()}function OE(r){let e=cn(r,{offset:0});return Kh(e)}function Kh(r){let e=cn(r[1],{offset:0});return{kty:"RSA",n:ue(e[0],"base64url"),e:ue(e[1],"base64url")}}function Hh(r){if(r.n==null||r.e==null)throw new Ae("JWK was missing components");return gr([kE,ma(gr([kt(de(r.n,"base64url")),kt(de(r.e,"base64url"))]))]).subarray()}function R0(r){let e=cn(r);return Vh(e)}function Vh(r){let e=Mh(r);return Wh(e)}function $h(r,e){if(r.byteLength>=BE)throw new Fi("Key size is too large");let t=cn(r,{offset:0});return Fh(t,r,e)}function Fh(r,e,t){let n=Kh(r);if(t==null){let o=Jn(Vr.encode({Type:Ye.RSA,Data:e}));t=vt(jh,o)}return new ns(n,t)}function Wh(r){if(U0(r)>Uh)throw new Ae("Key size is too large");let e=D0(r),t=Jn(Vr.encode({Type:Ye.RSA,Data:Hh(e.publicKey)})),n=vt(jh,t);return new Da(e.privateKey,new ns(e.publicKey,n))}async function qh(r){if(r>Uh)throw new Ae("Key size is too large");let e=await L0(r),t=Jn(Vr.encode({Type:Ye.RSA,Data:Hh(e.publicKey)})),n=vt(jh,t);return new Da(e.privateKey,new ns(e.publicKey,n))}function D0(r){if(r==null)throw new Ae("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function L0(r,e){let t=await Zn.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await RE(t,e);return{privateKey:n[0],publicKey:n[1]}}async function N0(r,e,t){let n=await Zn.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);t?.signal?.throwIfAborted();let o=await Zn.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 O0(r,e,t,n){let o=await Zn.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Zn.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,t instanceof Uint8Array?t:t.subarray());return n?.signal?.throwIfAborted(),i}async function RE(r,e){if(r.privateKey==null||r.publicKey==null)throw new Ae("Private and public key are required");let t=await Promise.all([Zn.get().subtle.exportKey("jwk",r.privateKey),Zn.get().subtle.exportKey("jwk",r.publicKey)]);return e?.signal?.throwIfAborted(),t}function U0(r){if(r.kty!=="RSA")throw new Ae("invalid key type");if(r.n==null)throw new Ae("invalid key modulus");return de(r.n,"base64url").length*8}var tl=class extends Yi{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,ya(e);let n=$n(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),wr(i)}update(e){return Zi(this),this.iHash.update(e),this}digestInto(e){Zi(this),Ro(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},os=(r,e,t)=>new tl(r,e).update(t).digest();os.create=(r,e)=>new tl(r,e);function j0(r){r.lowS!==void 0&&jr("lowS",r.lowS),r.prehash!==void 0&&jr("prehash",r.prehash)}function DE(r){let e=Sa(r);br(e,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});let{endo:t,Fp:n,a:o}=e;if(t){if(!n.eql(o,n.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...e})}var Xh=class extends Error{constructor(e=""){super(e)}},hn={Err:Xh,_tlv:{encode:(r,e)=>{let{Err:t}=hn;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");let n=e.length/2,o=va(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?va(o.length/2|128):"";return va(r)+i+o+e},decode(r,e){let{Err:t}=hn,n=0;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new t("tlv.decode: length bytes not complete");if(f[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let h of f)s=s<<8|h;if(n+=c,s<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(r){let{Err:e}=hn;if(r<dn)throw new e("integer: negative integers are not allowed");let t=va(r);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return t},decode(r){let{Err:e}=hn;if(r[0]&128)throw new e("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return fn(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=hn,o=Oe("signature",r),{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l:h}=n.decode(2,c);if(h.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(f)}},hexFromSig(r){let{_tlv:e,_int:t}=hn,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),i=n+o;return e.encode(48,i)}};function Gh(r,e){return Gn(Uo(r,e))}var dn=BigInt(0),ct=BigInt(1),Y8=BigInt(2),zh=BigInt(3),LE=BigInt(4);function UE(r){let e=DE(r),{Fp:t}=e,n=pn(e.n,e.nBitLength),o=e.toBytes||((T,b,D)=>{let V=b.toAffine();return Xn(Uint8Array.from([4]),t.toBytes(V.x),t.toBytes(V.y))}),i=e.fromBytes||(T=>{let b=T.subarray(1),D=t.fromBytes(b.subarray(0,t.BYTES)),V=t.fromBytes(b.subarray(t.BYTES,2*t.BYTES));return{x:D,y:V}});function s(T){let{a:b,b:D}=e,V=t.sqr(T),N=t.mul(V,T);return t.add(t.add(N,t.mul(T,b)),D)}function a(T,b){let D=t.sqr(b),V=s(T);return t.eql(D,V)}if(!a(e.Gx,e.Gy))throw new Error("bad curve params: generator point");let c=t.mul(t.pow(e.a,zh),LE),f=t.mul(t.sqr(e.b),BigInt(27));if(t.is0(t.add(c,f)))throw new Error("bad curve params: a or b");function h(T){return Vu(T,ct,e.n)}function p(T){let{allowedPrivateKeyLengths:b,nByteLength:D,wrapPrivateKey:V,n:N}=e;if(b&&typeof T!="bigint"){if(Ji(T)&&(T=Gn(T)),typeof T!="string"||!b.includes(T.length))throw new Error("invalid private key");T=T.padStart(D*2,"0")}let U;try{U=typeof T=="bigint"?T:fn(Oe("private key",T,D))}catch{throw new Error("invalid private key, expected hex or "+D+" bytes, got "+typeof T)}return V&&(U=Ce(U,N)),At("private key",U,ct,N),U}function m(T){if(!(T instanceof w))throw new Error("ProjectivePoint expected")}let v=Qi((T,b)=>{let{px:D,py:V,pz:N}=T;if(t.eql(N,t.ONE))return{x:D,y:V};let U=T.is0();b==null&&(b=U?t.ONE:t.inv(N));let $=t.mul(D,b),X=t.mul(V,b),M=t.mul(N,b);if(U)return{x:t.ZERO,y:t.ZERO};if(!t.eql(M,t.ONE))throw new Error("invZ was invalid");return{x:$,y:X}}),g=Qi(T=>{if(T.is0()){if(e.allowInfinityPoint&&!t.is0(T.py))return;throw new Error("bad point: ZERO")}let{x:b,y:D}=T.toAffine();if(!t.isValid(b)||!t.isValid(D))throw new Error("bad point: x or y not FE");if(!a(b,D))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class w{constructor(b,D,V){if(b==null||!t.isValid(b))throw new Error("x required");if(D==null||!t.isValid(D)||t.is0(D))throw new Error("y required");if(V==null||!t.isValid(V))throw new Error("z required");this.px=b,this.py=D,this.pz=V,Object.freeze(this)}static fromAffine(b){let{x:D,y:V}=b||{};if(!b||!t.isValid(D)||!t.isValid(V))throw new Error("invalid affine point");if(b instanceof w)throw new Error("projective point not allowed");let N=U=>t.eql(U,t.ZERO);return N(D)&&N(V)?w.ZERO:new w(D,V,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(b){let D=es(t,b.map(V=>V.pz));return b.map((V,N)=>V.toAffine(D[N])).map(w.fromAffine)}static fromHex(b){let D=w.fromAffine(i(Oe("pointHex",b)));return D.assertValidity(),D}static fromPrivateKey(b){return w.BASE.multiply(p(b))}static msm(b,D){return Wu(w,n,b,D)}_setWindowSize(b){Y.setWindowSize(this,b)}assertValidity(){g(this)}hasEvenY(){let{y:b}=this.toAffine();if(t.isOdd)return!t.isOdd(b);throw new Error("Field doesn't support isOdd")}equals(b){m(b);let{px:D,py:V,pz:N}=this,{px:U,py:$,pz:X}=b,M=t.eql(t.mul(D,X),t.mul(U,N)),G=t.eql(t.mul(V,X),t.mul($,N));return M&&G}negate(){return new w(this.px,t.neg(this.py),this.pz)}double(){let{a:b,b:D}=e,V=t.mul(D,zh),{px:N,py:U,pz:$}=this,X=t.ZERO,M=t.ZERO,G=t.ZERO,F=t.mul(N,N),ie=t.mul(U,U),k=t.mul($,$),R=t.mul(N,U);return R=t.add(R,R),G=t.mul(N,$),G=t.add(G,G),X=t.mul(b,G),M=t.mul(V,k),M=t.add(X,M),X=t.sub(ie,M),M=t.add(ie,M),M=t.mul(X,M),X=t.mul(R,X),G=t.mul(V,G),k=t.mul(b,k),R=t.sub(F,k),R=t.mul(b,R),R=t.add(R,G),G=t.add(F,F),F=t.add(G,F),F=t.add(F,k),F=t.mul(F,R),M=t.add(M,F),k=t.mul(U,$),k=t.add(k,k),F=t.mul(k,R),X=t.sub(X,F),G=t.mul(k,ie),G=t.add(G,G),G=t.add(G,G),new w(X,M,G)}add(b){m(b);let{px:D,py:V,pz:N}=this,{px:U,py:$,pz:X}=b,M=t.ZERO,G=t.ZERO,F=t.ZERO,ie=e.a,k=t.mul(e.b,zh),R=t.mul(D,U),K=t.mul(V,$),P=t.mul(N,X),y=t.add(D,V),C=t.add(U,$);y=t.mul(y,C),C=t.add(R,K),y=t.sub(y,C),C=t.add(D,N);let L=t.add(U,X);return C=t.mul(C,L),L=t.add(R,P),C=t.sub(C,L),L=t.add(V,N),M=t.add($,X),L=t.mul(L,M),M=t.add(K,P),L=t.sub(L,M),F=t.mul(ie,C),M=t.mul(k,P),F=t.add(M,F),M=t.sub(K,F),F=t.add(K,F),G=t.mul(M,F),K=t.add(R,R),K=t.add(K,R),P=t.mul(ie,P),C=t.mul(k,C),K=t.add(K,P),P=t.sub(R,P),P=t.mul(ie,P),C=t.add(C,P),R=t.mul(K,C),G=t.add(G,R),R=t.mul(L,C),M=t.mul(y,M),M=t.sub(M,R),R=t.mul(y,K),F=t.mul(L,F),F=t.add(F,R),new w(M,G,F)}subtract(b){return this.add(b.negate())}is0(){return this.equals(w.ZERO)}wNAF(b){return Y.wNAFCached(this,b,w.normalizeZ)}multiplyUnsafe(b){let{endo:D,n:V}=e;At("scalar",b,dn,V);let N=w.ZERO;if(b===dn)return N;if(this.is0()||b===ct)return this;if(!D||Y.hasPrecomputes(this))return Y.wNAFCachedUnsafe(this,b,w.normalizeZ);let{k1neg:U,k1:$,k2neg:X,k2:M}=D.splitScalar(b),G=N,F=N,ie=this;for(;$>dn||M>dn;)$&ct&&(G=G.add(ie)),M&ct&&(F=F.add(ie)),ie=ie.double(),$>>=ct,M>>=ct;return U&&(G=G.negate()),X&&(F=F.negate()),F=new w(t.mul(F.px,D.beta),F.py,F.pz),G.add(F)}multiply(b){let{endo:D,n:V}=e;At("scalar",b,ct,V);let N,U;if(D){let{k1neg:$,k1:X,k2neg:M,k2:G}=D.splitScalar(b),{p:F,f:ie}=this.wNAF(X),{p:k,f:R}=this.wNAF(G);F=Y.constTimeNegate($,F),k=Y.constTimeNegate(M,k),k=new w(t.mul(k.px,D.beta),k.py,k.pz),N=F.add(k),U=ie.add(R)}else{let{p:$,f:X}=this.wNAF(b);N=$,U=X}return w.normalizeZ([N,U])[0]}multiplyAndAddUnsafe(b,D,V){let N=w.BASE,U=(X,M)=>M===dn||M===ct||!X.equals(N)?X.multiplyUnsafe(M):X.multiply(M),$=U(this,D).add(U(b,V));return $.is0()?void 0:$}toAffine(b){return v(this,b)}isTorsionFree(){let{h:b,isTorsionFree:D}=e;if(b===ct)return!0;if(D)return D(w,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:b,clearCofactor:D}=e;return b===ct?this:D?D(w,this):this.multiplyUnsafe(e.h)}toRawBytes(b=!0){return jr("isCompressed",b),this.assertValidity(),o(w,this,b)}toHex(b=!0){return jr("isCompressed",b),Gn(this.toRawBytes(b))}}w.BASE=new w(e.Gx,e.Gy,t.ONE),w.ZERO=new w(t.ZERO,t.ONE,t.ZERO);let{endo:S,nBitLength:O}=e,Y=Fu(w,S?Math.ceil(O/2):O);return{CURVE:e,ProjectivePoint:w,normPrivateKeyToScalar:p,weierstrassEquation:s,isWithinCurveOrder:h}}function jE(r){let e=Sa(r);return br(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function M0(r){let e=jE(r),{Fp:t,n,nByteLength:o,nBitLength:i}=e,s=t.BYTES+1,a=2*t.BYTES+1;function c(k){return Ce(k,n)}function f(k){return $u(k,n)}let{ProjectivePoint:h,normPrivateKeyToScalar:p,weierstrassEquation:m,isWithinCurveOrder:v}=UE({...e,toBytes(k,R,K){let P=R.toAffine(),y=t.toBytes(P.x),C=Xn;return jr("isCompressed",K),K?C(Uint8Array.from([R.hasEvenY()?2:3]),y):C(Uint8Array.from([4]),y,t.toBytes(P.y))},fromBytes(k){let R=k.length,K=k[0],P=k.subarray(1);if(R===s&&(K===2||K===3)){let y=fn(P);if(!Vu(y,ct,t.ORDER))throw new Error("Point is not on curve");let C=m(y),L;try{L=t.sqrt(C)}catch(le){let Q=le instanceof Error?": "+le.message:"";throw new Error("Point is not on curve"+Q)}let I=(L&ct)===ct;return(K&1)===1!==I&&(L=t.neg(L)),{x:y,y:L}}else if(R===a&&K===4){let y=t.fromBytes(P.subarray(0,t.BYTES)),C=t.fromBytes(P.subarray(t.BYTES,2*t.BYTES));return{x:y,y:C}}else{let y=s,C=a;throw new Error("invalid Point, expected length of "+y+", or uncompressed "+C+", got "+R)}}});function g(k){let R=n>>ct;return k>R}function w(k){return g(k)?c(-k):k}let S=(k,R,K)=>fn(k.slice(R,K));class O{constructor(R,K,P){At("r",R,ct,n),At("s",K,ct,n),this.r=R,this.s=K,P!=null&&(this.recovery=P),Object.freeze(this)}static fromCompact(R){let K=o;return R=Oe("compactSignature",R,K*2),new O(S(R,0,K),S(R,K,2*K))}static fromDER(R){let{r:K,s:P}=hn.toSig(Oe("DER",R));return new O(K,P)}assertValidity(){}addRecoveryBit(R){return new O(this.r,this.s,R)}recoverPublicKey(R){let{r:K,s:P,recovery:y}=this,C=N(Oe("msgHash",R));if(y==null||![0,1,2,3].includes(y))throw new Error("recovery id invalid");let L=y===2||y===3?K+e.n:K;if(L>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let I=(y&1)===0?"02":"03",re=h.fromHex(I+Gh(L,t.BYTES)),le=f(L),Q=c(-C*le),pe=c(P*le),he=h.BASE.multiplyAndAddUnsafe(re,Q,pe);if(!he)throw new Error("point at infinify");return he.assertValidity(),he}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new O(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return Aa(this.toDERHex())}toDERHex(){return hn.hexFromSig(this)}toCompactRawBytes(){return Aa(this.toCompactHex())}toCompactHex(){let R=o;return Gh(this.r,R)+Gh(this.s,R)}}let Y={isValidPrivateKey(k){try{return p(k),!0}catch{return!1}},normPrivateKeyToScalar:p,randomPrivateKey:()=>{let k=lh(e.n);return o0(e.randomBytes(k),e.n)},precompute(k=8,R=h.BASE){return R._setWindowSize(k),R.multiply(BigInt(3)),R}};function T(k,R=!0){return h.fromPrivateKey(k).toRawBytes(R)}function b(k){if(typeof k=="bigint")return!1;if(k instanceof h)return!0;let K=Oe("key",k).length,P=t.BYTES,y=P+1,C=2*P+1;if(!(e.allowedPrivateKeyLengths||o===y))return K===y||K===C}function D(k,R,K=!0){if(b(k)===!0)throw new Error("first arg must be private key");if(b(R)===!1)throw new Error("second arg must be public key");return h.fromHex(R).multiply(p(k)).toRawBytes(K)}let V=e.bits2int||function(k){if(k.length>8192)throw new Error("input is too large");let R=fn(k),K=k.length*8-i;return K>0?R>>BigInt(K):R},N=e.bits2int_modN||function(k){return c(V(k))},U=jo(i);function $(k){return At("num < 2^"+i,k,dn,U),Uo(k,o)}function X(k,R,K=M){if(["recovered","canonical"].some(_e=>_e in K))throw new Error("sign() legacy options not supported");let{hash:P,randomBytes:y}=e,{lowS:C,prehash:L,extraEntropy:I}=K;C==null&&(C=!0),k=Oe("msgHash",k),j0(K),L&&(k=Oe("prehashed msgHash",P(k)));let re=N(k),le=p(R),Q=[$(le),$(re)];if(I!=null&&I!==!1){let _e=I===!0?y(t.BYTES):I;Q.push(Oe("extraEntropy",_e))}let pe=Xn(...Q),he=re;function Ee(_e){let ke=V(_e);if(!v(ke))return;let ut=f(ke),Ue=h.BASE.multiply(ke).toAffine(),et=c(Ue.x);if(et===dn)return;let Tt=c(ut*c(he+et*le));if(Tt===dn)return;let Bt=(Ue.x===et?0:2)|Number(Ue.y&ct),Un=Tt;return C&&g(Tt)&&(Un=w(Tt),Bt^=1),new O(et,Un,Bt)}return{seed:pe,k2sig:Ee}}let M={lowS:e.lowS,prehash:!1},G={lowS:e.lowS,prehash:!1};function F(k,R,K=M){let{seed:P,k2sig:y}=X(k,R,K),C=e;return Yg(C.hash.outputLen,C.nByteLength,C.hmac)(P,y)}h.BASE._setWindowSize(8);function ie(k,R,K,P=G){let y=k;R=Oe("msgHash",R),K=Oe("publicKey",K);let{lowS:C,prehash:L,format:I}=P;if(j0(P),"strict"in P)throw new Error("options.strict was renamed to lowS");if(I!==void 0&&I!=="compact"&&I!=="der")throw new Error("format must be compact or der");let re=typeof y=="string"||Ji(y),le=!re&&!I&&typeof y=="object"&&y!==null&&typeof y.r=="bigint"&&typeof y.s=="bigint";if(!re&&!le)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let Q,pe;try{if(le&&(Q=new O(y.r,y.s)),re){try{I!=="compact"&&(Q=O.fromDER(y))}catch(Bt){if(!(Bt instanceof hn.Err))throw Bt}!Q&&I!=="der"&&(Q=O.fromCompact(y))}pe=h.fromHex(K)}catch{return!1}if(!Q||C&&Q.hasHighS())return!1;L&&(R=e.hash(R));let{r:he,s:Ee}=Q,_e=N(R),ke=f(Ee),ut=c(_e*ke),Ue=c(he*ke),et=h.BASE.multiplyAndAddUnsafe(pe,ut,Ue)?.toAffine();return et?c(et.x)===he:!1}return{CURVE:e,getPublicKey:T,getSharedSecret:D,sign:F,verify:ie,ProjectivePoint:h,Signature:O,utils:Y}}function ME(r){return{hash:r,hmac:(e,...t)=>os(r,e,Jp(...t)),randomBytes:ga}}function K0(r,e){let t=n=>M0({...r,...ME(n)});return{...t(e),create:t}}var $0=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),H0=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),KE=BigInt(0),HE=BigInt(1),Yh=BigInt(2),V0=(r,e)=>(r+e/Yh)/e;function VE(r){let e=$0,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%e,h=f*f*r%e,p=Me(h,t,e)*h%e,m=Me(p,t,e)*h%e,v=Me(m,Yh,e)*f%e,g=Me(v,o,e)*v%e,w=Me(g,i,e)*g%e,S=Me(w,a,e)*w%e,O=Me(S,c,e)*S%e,Y=Me(O,a,e)*w%e,T=Me(Y,t,e)*h%e,b=Me(T,s,e)*g%e,D=Me(b,n,e)*f%e,V=Me(D,Yh,e);if(!Zh.eql(Zh.sqr(V),r))throw new Error("Cannot find square root");return V}var Zh=pn($0,void 0,void 0,{sqrt:VE}),Cr=K0({a:KE,b:BigInt(7),Fp:Zh,n:H0,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=H0,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-HE*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=V0(i*r,e),c=V0(-n*r,e),f=Ce(r-a*t-c*o,e),h=Ce(-a*n-c*i,e),p=f>s,m=h>s;if(p&&(f=e-f),m&&(h=e-h),f>s||h>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:p,k1:f,k2neg:m,k2:h}}}},Hu);function Jh(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function F0(r,e,t){let n=tr.digest(e instanceof Uint8Array?e:e.subarray());if(Jh(n))return n.then(({digest:o})=>(t?.signal?.throwIfAborted(),Cr.sign(o,r).toDERRawBytes())).catch(o=>{throw o.name==="AbortError"?o:new Oa(String(o))});try{return Cr.sign(n.digest,r).toDERRawBytes()}catch(o){throw new Oa(String(o))}}function W0(r,e,t,n){let o=tr.digest(t instanceof Uint8Array?t:t.subarray());if(Jh(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Cr.verify(e,i,r))).catch(i=>{throw i.name==="AbortError"?i:new Ra(String(i))});try{return n?.signal?.throwIfAborted(),Cr.verify(e,o.digest,r)}catch(i){throw new Ra(String(i))}}var Ua=class{type="secp256k1";raw;_key;constructor(e){this._key=z0(e),this.raw=q0(this._key)}toMultihash(){return yr.digest(Vn(this))}toCID(){return Xe.createV1(114,this.toMultihash())}toString(){return Pe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}verify(e,t,n){return W0(this._key,t,e,n)}},rl=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=G0(e),this.publicKey=new Ua(t??X0(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}sign(e,t){return F0(this.raw,e,t)}};function Qh(r){return new Ua(r)}async function Y0(){let r=$E();return new rl(r)}function q0(r){return Cr.ProjectivePoint.fromHex(r).toRawBytes(!0)}function G0(r){try{return Cr.getPublicKey(r,!0),r}catch(e){throw new ca(String(e))}}function z0(r){try{return Cr.ProjectivePoint.fromHex(r),r}catch(e){throw new Fi(String(e))}}function X0(r){try{return Cr.getPublicKey(r,!0)}catch(e){throw new ca(String(e))}}function $E(){return Cr.utils.randomPrivateKey()}async function Z0(r,e){if(r==="Ed25519")return v0();if(r==="secp256k1")return Y0();if(r==="RSA")return qh(FE(e));if(r==="ECDSA")return kg(WE(e));throw new jn}function ja(r,e){let{Type:t,Data:n}=Vr.decode(r),o=n??new Uint8Array;switch(t){case Ye.RSA:return $h(o,e);case Ye.Ed25519:return gh(o);case Ye.secp256k1:return Qh(o);case Ye.ECDSA:return Zp(o);default:throw new jn}}function J0(r){let{Type:e,Data:t}=Vr.decode(r.digest),n=t??new Uint8Array;switch(e){case Ye.Ed25519:return gh(n);case Ye.secp256k1:return Qh(n);case Ye.ECDSA:return Zp(n);default:throw new jn}}function Vn(r){return Vr.encode({Type:Ye[r.type],Data:r.raw})}function FE(r){return r==null?2048:parseInt(r,10)}function WE(r){if(r==="P-256"||r==null)return"P-256";if(r==="P-384")return"P-384";if(r==="P-521")return"P-521";throw new Ae("Unsupported curve, should be P-256, P-384 or P-521")}async function nl(r){if(r.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(r.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"ECDSA",namedCurve:r.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"ECDSA",namedCurve:r.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new Ae("Only RSA and ECDSA keys are supported")}var Q0=Symbol.for("nodejs.util.inspect.custom"),qE=114,Ma=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Ep]=!0;toString(){return this.string==null&&(this.string=Pe.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Xe.createV1(qE,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Fe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return Fe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Q0](){return`PeerId(${this.toString()})`}},Ka=class extends Ma{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Ha=class extends Ma{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Va=class extends Ma{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},GE=2336,$a=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=yr.digest(de(this.url))}[Q0](){return`PeerId(${this.url})`}[Ep]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Xe.createV1(GE,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ue(e)),e.toString()===this.toString())}};var zE=114,ew=2336;function is(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=Hn(Pe.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return XE(Xe.parse(r));if(e==null)throw new Ae('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=Hn(e.decode(r))}return tw(t)}function ed(r){if(r.type==="Ed25519")return new Ha({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Va({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new Ka({multihash:r.toCID().multihash,publicKey:r});throw new jn}function tw(r){if(ZE(r))return new Ka({multihash:r});if(YE(r))try{let e=J0(r);if(e.type==="Ed25519")return new Ha({multihash:r,publicKey:e});if(e.type==="secp256k1")return new Va({multihash:r,publicKey:e})}catch{let t=ue(r.digest);return new $a(new URL(t))}throw new Bu("Supplied PeerID Multihash is invalid")}function XE(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==zE&&r.code!==ew)throw new Tu("Supplied PeerID CID is invalid");if(r.code===ew){let e=ue(r.multihash.digest);return new $a(new URL(e))}return tw(r.multihash)}function YE(r){return r.code===yr.code}function ZE(r){return r.code===tr.code}var ol=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let p=this.readChar();if(p===void 0)return;let m=Number.parseInt(p,e);if(!Number.isNaN(m))return m});if(h===void 0)break;if(i*=e,i+=h,i>f||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var rw=45,JE=15,ss=new ol;function td(r){if(!(r.length>JE))return ss.new(r).parseWith(()=>ss.readIPv4Addr())}function rd(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>rw))return ss.new(r).parseWith(()=>ss.readIPv6Addr())}function il(r,e=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>rw)return;let t=ss.new(r).parseWith(()=>ss.readIPAddr());if(t)return e&&t.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,t[0],t[1],t[2],t[3]]):t}var u4=parseInt("0xFFFF",16),l4=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function sl(r){return!!td(r)}function al(r){return!!rd(r)}function cl(r){return!!il(r)}var iw=sl,n2=al,nd=function(r){let e=0;if(r=r.toString().trim(),iw(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(n2(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=iw(t[n]),s;i&&(s=nd(t[n]),t[n]=ue(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,ue(s.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);o[e++]=i>>8&255,o[e++]=i&255}return o}throw new Error("invalid ip address")},sw=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let i=0;i<t;i++)o.push(r[e+i]);return o.join(".")}if(t===16){let o=[];for(let i=0;i<t;i+=2)o.push(n.getUint16(e+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var as={},od={},i2=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];i2.forEach(r=>{let e=s2(...r);od[e.code]=e,as[e.name]=e});function s2(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function Re(r){if(typeof r=="number"){if(od[r]!=null)return od[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(as[r]!=null)return as[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var G4=Re("ip4"),z4=Re("ip6"),X4=Re("ipcidr");function cd(r,e){switch(Re(r).code){case 4:case 41:return c2(e);case 42:return ad(e);case 43:return ue(e,"base10");case 6:case 273:case 33:case 132:return uw(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ad(e);case 421:return p2(e);case 444:return cw(e);case 445:return cw(e);case 466:return f2(e);case 481:return globalThis.encodeURIComponent(ad(e));default:return ue(e,"base16")}}function ud(r,e){switch(Re(r).code){case 4:return aw(e);case 41:return aw(e);case 42:return sd(e);case 43:return de(e,"base10");case 6:case 273:case 33:case 132:return ld(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return sd(e);case 421:return u2(e);case 444:return h2(e);case 445:return d2(e);case 466:return l2(e);case 481:return sd(globalThis.decodeURIComponent(e));default:return de(e,"base16")}}var id=Object.values(Po).map(r=>r.decoder),a2=function(){let r=id[0].or(id[1]);return id.slice(2).forEach(e=>r=r.or(e)),r}();function aw(r){if(!cl(r))throw new Error("invalid ip address");return nd(r)}function c2(r){let e=sw(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!cl(e))throw new Error("invalid ip address");return e}function ld(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function uw(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function sd(r){let e=de(r),t=Uint8Array.from(Hr(e.length));return ot([t,e],t.length+e.length)}function ad(r){let e=vr(r);if(r=r.slice(Ke(e)),r.length!==e)throw new Error("inconsistent lengths");return ue(r)}function u2(r){let e;r[0]==="Q"||r[0]==="1"?e=Hn(Pe.decode(`z${r}`)).bytes:e=Xe.parse(r).multihash.bytes;let t=Uint8Array.from(Hr(e.length));return ot([t,e],t.length+e.length)}function l2(r){let e=a2.decode(r),t=Uint8Array.from(Hr(e.length));return ot([t,e],t.length+e.length)}function f2(r){let e=vr(r),t=r.slice(Ke(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+ue(t,"base64url")}function p2(r){let e=vr(r),t=r.slice(Ke(e));if(t.length!==e)throw new Error("inconsistent lengths");return ue(t,"base58btc")}function h2(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=an.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ld(n);return ot([t,o],t.length+o.length)}function d2(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=an.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ld(n);return ot([t,o],t.length+o.length)}function cw(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=ue(e,"base32"),o=uw(t);return`${n}:${o}`}function lw(r){r=fd(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let s=o[i],a=Re(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=o.length)throw new ul("invalid address: "+r);if(a.path===!0){n=fd(o.slice(i).join("/")),e.push([a.code,ud(a.code,n)]),t.push([a.code,n]);break}let c=ud(a.code,o[i]);e.push([a.code,c]),t.push([a.code,cd(a.code,c)])}return{string:fw(t),bytes:ll(e),tuples:e,stringTuples:t,path:n}}function pd(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let i=vr(r,o),s=Ke(i),a=Re(i),c=m2(a,r.slice(o+s));if(c===0){e.push([i]),t.push([i]),o+=s;continue}let f=r.slice(o+s,o+s+c);if(o+=c+s,o>r.length)throw new ul("Invalid address Uint8Array: "+ue(r,"base16"));e.push([i,f]);let h=cd(i,f);if(t.push([i,h]),a.path===!0){n=h;break}}return{bytes:Uint8Array.from(r),string:fw(t),tuples:e,stringTuples:t,path:n}}function fw(r){let e=[];return r.map(t=>{let n=Re(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),fd(e.join("/"))}function ll(r){return ot(r.map(e=>{let t=Re(e[0]),n=Uint8Array.from(Hr(t.code));return e.length>1&&e[1]!=null&&(n=ot([n,e[1]])),n}))}function m2(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=vr(e instanceof Uint8Array?e:Uint8Array.from(e));return t+Ke(t)}}function fd(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}var ul=class extends Error{static name="ParseError";name="ParseError";constructor(e){super(`Error parsing address: ${e}`)}};var y2=Symbol.for("nodejs.util.inspect.custom"),dd=Symbol.for("@multiformats/js-multiaddr/multiaddr"),g2=[Re("dns").code,Re("dns4").code,Re("dns6").code,Re("dnsaddr").code],hd=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},fl=class r{bytes;#e;#t;#r;#n;[dd]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=pd(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=lw(e)}else if(hw(e))t=pd(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,i="",s=Re("tcp"),a=Re("udp"),c=Re("ip4"),f=Re("ip6"),h=Re("dns6"),p=Re("ip6zone");for(let[v,g]of this.stringTuples())v===p.code&&(i=`%${g??""}`),g2.includes(v)&&(t=s.name==="tcp"?"tcp":"udp",o=443,n=`${g??""}${i}`,e=v===h.code?6:4),(v===s.code||v===a.code)&&(t=Re(v).name==="tcp"?"tcp":"udp",o=parseInt(g??"")),(v===c.code||v===f.code)&&(t=Re(v).name==="tcp"?"tcp":"udp",n=`${g??""}${i}`,e=v===f.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},Re(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>Re(e).name)}tuples(){return this.#t.map(([e,t])=>t==null?[e]:[e,t])}stringTuples(){return this.#r.map(([e,t])=>t==null?[e]:[e,t])}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(ll(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===as.p2p.code&&e.push([n,o]),n===as["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?ue(Pe.decode(`z${n}`),"base58btc"):ue(Xe.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return Fe(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=pw.get(t.name);if(n==null)throw new hd(`no available resolver for ${t.name}`);return(await n(this,e)).map(i=>$r(i))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[y2](){return`Multiaddr(${this.#e})`}};var pw=new Map;function hw(r){return!!r?.[dd]}function $r(r){return new fl(r)}var w2=r=>r.toString().split("/").slice(1),cs=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),ye=r=>({match:e=>cs(t=>t===r).match(e),pattern:r}),$o=()=>({match:r=>cs(e=>typeof e=="string").match(r),pattern:"{string}"}),us=()=>({match:r=>cs(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),Be=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{Pe.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Fa=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{ko.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),Ie=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),_t=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),ve=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${r.map(e=>e.pattern).join(", ")})`});function De(...r){function e(o){let i=w2(o);for(let s of r){let a=s.match(i);if(a===!1)return!1;i=a}return i}function t(o){return e(o)!==!1}function n(o){let i=e(o);return i===!1?!1:i.length===0}return{matchers:r,matches:t,exactMatch:n}}var x2=Be(),C5=De(x2),hl=ve(ye("dns4"),$o()),dl=ve(ye("dns6"),$o()),ml=ve(ye("dnsaddr"),$o()),yd=ve(ye("dns"),$o()),I5=De(hl,Ie(Be())),T5=De(dl,Ie(Be())),B5=De(ml,Ie(Be())),k5=De(_t(yd,ml,hl,dl),Ie(Be())),dw=ve(ye("ip4"),cs(sl)),mw=ve(ye("ip6"),cs(al)),gd=_t(dw,mw),mn=_t(gd,yd,hl,dl,ml),P5=De(_t(gd,ve(_t(yd,ml,hl,dl),Ie(Be())))),N5=De(dw),O5=De(mw),R5=De(gd),wd=ve(mn,ye("tcp"),us()),Wa=ve(mn,ye("udp"),us()),D5=De(ve(wd,Ie(Be()))),L5=De(Wa),xd=ve(Wa,ye("quic"),Ie(Be())),yl=ve(Wa,ye("quic-v1"),Ie(Be())),b2=_t(xd,yl),U5=De(xd),j5=De(yl),md=_t(mn,wd,Wa,xd,yl),yw=_t(ve(md,ye("ws"),Ie(Be()))),M5=De(yw),gw=_t(ve(md,ye("wss"),Ie(Be())),ve(md,ye("tls"),Ie(ve(ye("sni"),$o())),ye("ws"),Ie(Be()))),K5=De(gw),ww=ve(Wa,ye("webrtc-direct"),Ie(Fa()),Ie(Fa()),Ie(Be())),xw=De(ww),bw=ve(yl,ye("webtransport"),Ie(Fa()),Ie(Fa()),Ie(Be())),H5=De(bw),pl=_t(yw,gw,ve(wd,Ie(Be())),ve(b2,Ie(Be())),ve(mn,Ie(Be())),ww,bw,Be()),vw=De(pl),v2=ve(pl,ye("p2p-circuit"),Be()),V5=De(v2),A2=_t(ve(pl,ye("p2p-circuit"),ye("webrtc"),Ie(Be())),ve(pl,ye("webrtc"),Ie(Be())),ve(ye("webrtc"),Ie(Be()))),Aw=De(A2),S2=_t(ve(mn,ye("tcp"),us(),ye("http"),Ie(Be())),ve(mn,ye("http"),Ie(Be()))),$5=De(S2),E2=_t(ve(mn,ye("tcp"),_t(ve(ye("443"),ye("http")),ve(us(),ye("https")),ve(us(),ye("tls"),ye("http"))),Ie(Be())),ve(mn,ye("tls"),ye("http"),Ie(Be())),ve(mn,ye("https"),Ie(Be()))),F5=De(E2),_2=_t(ve(ye("memory"),$o(),Ie(Be()))),W5=De(_2);var Ct;(function(r){let e;(function(o){o.FIN="FIN",o.STOP_SENDING="STOP_SENDING",o.RESET="RESET",o.FIN_ACK="FIN_ACK"})(e=r.Flag||(r.Flag={}));let t;(function(o){o[o.FIN=0]="FIN",o[o.STOP_SENDING=1]="STOP_SENDING",o[o.RESET=2]="RESET",o[o.FIN_ACK=3]="FIN_ACK"})(t||(t={})),function(o){o.codec=()=>Vo(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=_r((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.flag!=null&&(i.uint32(8),r.Flag.codec().encode(o.flag,i)),o.message!=null&&(i.uint32(18),i.bytes(o.message)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let f=o.uint32();switch(f>>>3){case 1:{a.flag=r.Flag.codec().decode(o);break}case 2:{a.message=o.bytes();break}default:{o.skipType(f&7);break}}}return a})),n),r.encode=o=>Er(o,r.codec()),r.decode=(o,i)=>Sr(o,r.codec(),i)})(Ct||(Ct={}));var Sw=["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478"],bd=Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"),Ew="libp2p+webrtc+v1/";var _w=466,Cw=2*1024*1024,Iw=30*1e3,ls=16*1024;function C2(r=ls){let e=Ke(r-Ke(r)),t=1+Ke(Object.keys(Ct.Flag).length-1),n=1,o=r-e-t-n,i=Ke(o);return e+t+n+i}var Tw=C2(),Bw=5e3,kw=5e3,Pw=3e4,vd="/webrtc",qa="/webrtc-signaling/0.0.1",Nw="/libp2p/webrtc-direct/certificate",Ow="webrtc-direct-certificate-private-key";var Rw=12096e5,Ad=864e5;var Dw=function(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,i;n<o;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return r.concat(i||Array.prototype.slice.call(e))},I2=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var T2=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var B2=function(){function r(e,t,n,o){this.name=e,this.version=t,this.os=n,this.bot=o,this.type="bot-device"}return r}();var k2=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var P2=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var N2=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,O2=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,Lw=3,R2=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["edge-ios",/EdgiOS\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["silk",/\bSilk\/([0-9._-]+)\b/],["miui",/MiuiBrowser\/([0-9\.]+)$/],["beaker",/BeakerBrowser\/([0-9\.]+)/],["edge-chromium",/EdgA?\/([0-9\.]+)/],["chromium-webview",/(?!Chrom.*OPR)wv\).*Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera-mini",/Opera Mini.*Version\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)/],["pie",/^Microsoft Pocket Internet Explorer\/(\d+\.\d+)$/],["pie",/^Mozilla\/\d\.\d+\s\(compatible;\s(?:MSP?IE|MSInternet Explorer) (\d+\.\d+);.*Windows CE.*\)$/],["netfront",/^Mozilla\/\d\.\d+.*NetFront\/(\d.\d)/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FB[AS]V\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Gecko\)$/],["curl",/^curl\/([0-9\.]+)$/],["searchbot",N2]],Uw=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Windows CE",/Windows CE|WinCE|Microsoft Pocket Internet Explorer/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Chrome OS",/CrOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/]];function Mw(r){return r?jw(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new P2:typeof navigator<"u"?jw(navigator.userAgent):U2()}function D2(r){return r!==""&&R2.reduce(function(e,t){var n=t[0],o=t[1];if(e)return e;var i=o.exec(r);return!!i&&[n,i]},!1)}function jw(r){var e=D2(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new k2;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<Lw&&(o=Dw(Dw([],o,!0),j2(Lw-o.length),!0)):o=[];var i=o.join("."),s=L2(r),a=O2.exec(r);return a&&a[1]?new B2(t,i,s,a[1]):new I2(t,i,s)}function L2(r){for(var e=0,t=Uw.length;e<t;e++){var n=Uw[e],o=n[0],i=n[1],s=i.exec(r);if(s)return o}return null}function U2(){var r=typeof process<"u"&&process.version;return r?new T2(process.version.slice(1)):null}function j2(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function Ze(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Sd=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ed=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Kw=r=>globalThis.DOMException===void 0?new Ed(r):new DOMException(r),Hw=r=>{let e=r.reason===void 0?Kw("This operation was aborted."):r.reason;return e instanceof Error?e:Kw(e)};function Ga(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,f=new Promise((h,p)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:v}=e;v.aborted&&p(Hw(v)),a=()=>{p(Hw(v))},v.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(h,p);return}let m=new Sd;s=i.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(v){p(v)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?p(o):(m.message=o??`Promise timed out after ${t} milliseconds`,p(m))},t),(async()=>{try{h(await r)}catch(v){p(v)}})()}).finally(()=>{f.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return f.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},f}var Vw=Mw(),za=Vw!=null&&Vw.name==="firefox",gl=async function*(){},wl=async r=>{};function $w(r,e,t=Pw,n){r.readyState==="open"&&Promise.resolve().then(async()=>{if(r.bufferedAmount>0){n.log("%s drain channel with %d buffered bytes",e,r.bufferedAmount);let o=Ze(),i=!1;r.bufferedAmountLowThreshold=0;let s=()=>{i||(n.log("%s drain channel closed before drain",e),o.resolve())};r.addEventListener("close",s,{once:!0}),r.addEventListener("bufferedamountlow",()=>{i=!0,r.removeEventListener("close",s),o.resolve()}),await Ga(o.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(o=>{n.log.error("error closing outbound stream",o)})}async function _d(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??Sw.map(e=>({urls:[e]})),r}var Fw=(r=32)=>Ew+[...Array(r)].map(()=>bd.at(Math.floor(Math.random()*bd.length))).join("");var Fo=class{log;peerConnection;remoteAddr;timeline;metrics;source=gl();sink=wl;constructor(e,t){this.log=e.logger.forComponent("libp2p:webrtc:maconn"),this.remoteAddr=t.remoteAddr,this.timeline=t.timeline,this.peerConnection=t.peerConnection;let n=this.peerConnection,o=n.connectionState;this.peerConnection.onconnectionstatechange=()=>{this.log.trace("peer connection state change",n.connectionState,"initial state",o),(n.connectionState==="disconnected"||n.connectionState==="failed"||n.connectionState==="closed")&&(this.timeline.close=Date.now())}}async close(e){this.log.trace("closing connection"),this.peerConnection.close(),this.timeline.close=Date.now(),this.metrics?.increment({close:!0})}abort(e){this.log.error("closing connection due to error",e),this.peerConnection.close(),this.timeline.close=Date.now(),this.metrics?.increment({abort:!0})}};var xl=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},fs=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new xl(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new xl(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Cd=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function ps(r={}){return M2(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function M2(r,e){e=e??{};let t=e.onEnd,n=new fs,o,i,s,a=Ze(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((S,O)=>{i=Y=>{i=null,n.push(Y);try{S(r(n))}catch(T){O(T)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ze()})}},f=S=>i!=null?i(S):(n.push(S),o),h=S=>(n=new fs,i!=null?i({error:S}):(n.push({error:S}),o)),p=S=>{if(s)return o;if(e?.objectMode!==!0&&S?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:S})},m=S=>s?o:(s=!0,S!=null?h(S):f({done:!0})),v=()=>(n=new fs,m(),{done:!0}),g=S=>(m(S),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:v,throw:g,push:p,end:m,get readableLength(){return n.size},onEmpty:async S=>{let O=S?.signal;if(O?.throwIfAborted(),n.isEmpty())return;let Y,T;O!=null&&(Y=new Promise((b,D)=>{T=()=>{D(new Cd)},O.addEventListener("abort",T)}));try{await Promise.race([a.promise,Y])}finally{T!=null&&O!=null&&O?.removeEventListener("abort",T)}}},t==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(S){return w.throw(S),t!=null&&(t(S),t=void 0),{done:!0}},return(){return w.return(),t!=null&&(t(),t=void 0),{done:!0}},push:p,end(S){return w.end(S),t!=null&&(t(S),t=void 0),o},get readableLength(){return w.readableLength},onEmpty:S=>w.onEmpty(S)},o}var bl=class extends Error{type;code;constructor(e,t,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=t??"ABORT_ERR"}};async function rr(r,e,t){if(e==null)return r;if(e.aborted)return r.catch(()=>{}),Promise.reject(new bl(t?.errorMessage,t?.errorCode,t?.errorName));let n,o=new bl(t?.errorMessage,t?.errorCode,t?.errorName);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}function Ww(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function qw(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Gw(r,e){let t=Ww(r).return?.();qw(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var K2=5e3;function Id(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var vl=class{id;direction;timeline;protocol;metadata;source;status;readStatus;writeStatus;log;sinkController;sinkEnd;closed;endErr;streamSource;onEnd;onCloseRead;onCloseWrite;onReset;onAbort;sendCloseWriteTimeout;sendingData;constructor(e){this.sinkController=new AbortController,this.sinkEnd=Ze(),this.closed=Ze(),this.log=e.log,this.status="open",this.readStatus="ready",this.writeStatus="ready",this.id=e.id,this.metadata=e.metadata??{},this.direction=e.direction,this.timeline={open:Date.now()},this.sendCloseWriteTimeout=e.sendCloseWriteTimeout??K2,this.onEnd=e.onEnd,this.onCloseRead=e.onCloseRead,this.onCloseWrite=e.onCloseWrite,this.onReset=e.onReset,this.onAbort=e.onAbort,this.source=this.streamSource=ps({onEnd:t=>{t!=null?this.log.trace("source ended with error",t):this.log.trace("source ended"),this.onSourceEnd(t)}}),this.sink=this.sink.bind(this)}async sink(e){if(this.writeStatus!=="ready")throw new Io(`writable end state is "${this.writeStatus}" not "ready"`);try{this.writeStatus="writing";let t={signal:this.sinkController.signal};if(this.direction==="outbound"){let o=this.sendNewStream(t);Id(o)&&await o}let n=()=>{Gw(e,this.log)};try{this.sinkController.signal.addEventListener("abort",n),this.log.trace("sink reading from source");for await(let o of e){o=o instanceof Uint8Array?new be(o):o;let i=this.sendData(o,t);Id(i)&&(this.sendingData=Ze(),await i,this.sendingData.resolve(),this.sendingData=void 0)}}finally{this.sinkController.signal.removeEventListener("abort",n)}this.log.trace('sink finished reading from source, write status is "%s"',this.writeStatus),this.writeStatus==="writing"&&(this.writeStatus="closing",this.log.trace("send close write to remote"),await this.sendCloseWrite({signal:AbortSignal.timeout(this.sendCloseWriteTimeout)}),this.writeStatus="closed"),this.onSinkEnd()}catch(t){throw this.log.trace("sink ended with error, calling abort with error",t),this.abort(t),t}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(e){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),this.readStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(e){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),this.writeStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("sink ended, waiting for source to end"))}async close(e){this.status==="open"&&(this.log.trace("closing gracefully"),this.status="closing",await rr(Promise.all([this.closeWrite(e),this.closeRead(e),this.closed.promise]),e?.signal),this.status="closed",this.log.trace("closed gracefully"))}async closeRead(e={}){if(this.readStatus==="closing"||this.readStatus==="closed")return;this.log.trace('closing readable end of stream with starting read status "%s"',this.readStatus);let t=this.readStatus;this.readStatus="closing",this.status!=="reset"&&this.status!=="aborted"&&this.timeline.closeRead==null&&(this.log.trace("send close read to remote"),await this.sendCloseRead(e)),t==="ready"&&(this.log.trace("ending internal source queue with %d queued bytes",this.streamSource.readableLength),this.streamSource.end()),this.log.trace("closed readable end of stream")}async closeWrite(e={}){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.log.trace('closing writable end of stream with starting write status "%s"',this.writeStatus),this.writeStatus==="ready"&&(this.log.trace("sink was never sunk, sink an empty array"),await rr(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await rr(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await rr(this.sinkEnd.promise,e.signal)),this.writeStatus="closed",this.log.trace("closed writable end of stream"))}abort(e){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;this.log("abort with error",e),this.log("try to send reset to remote");let t=this.sendReset();Id(t)&&t.catch(n=>{this.log.error("error sending reset message",n)}),this.status="aborted",this.timeline.abort=Date.now(),this._closeSinkAndSource(e),this.onAbort?.(e)}reset(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;let e=new Iu("stream reset");this.status="reset",this.timeline.reset=Date.now(),this._closeSinkAndSource(e),this.onReset?.()}_closeSinkAndSource(e){this._closeSink(e),this._closeSource(e)}_closeSink(e){this.writeStatus==="writing"&&(this.log.trace("end sink source"),this.sinkController.abort()),this.onSinkEnd(e)}_closeSource(e){this.readStatus!=="closing"&&this.readStatus!=="closed"&&(this.log.trace("ending source with %d bytes to be read by consumer",this.streamSource.readableLength),this.readStatus="closing",this.streamSource.end(e))}remoteCloseWrite(){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("received remote close write but local source is already closed");return}this.log.trace("remote close write"),this._closeSource()}remoteCloseRead(){if(this.writeStatus==="closing"||this.writeStatus==="closed"){this.log("received remote close read but local sink is already closed");return}this.log.trace("remote close read"),this._closeSink()}destroy(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset"){this.log("received destroy but we are already closed");return}this.log.trace("stream destroyed"),this._closeSinkAndSource()}sourcePush(e){this.streamSource.push(e)}sourceReadableLength(){return this.streamSource.readableLength}};function Td(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}var Al=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},hs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Sl=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Xa=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function El(r){return r[Symbol.asyncIterator]!=null}function zw(r,e){if(r.byteLength>e)throw new hs("Message length too long")}var Cl=r=>{let e=Ke(r),t=nt(e);return Hr(r,t),Cl.bytes=e,t};Cl.bytes=0;function Ya(r,e){e=e??{};let t=e.lengthEncoder??Cl,n=e?.maxDataLength??4194304;function*o(i){zw(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return El(r)?async function*(){for await(let i of r)yield*o(i)}():function*(){for(let i of r)yield*o(i)}()}Ya.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??Cl,n=e?.maxDataLength??4194304;return zw(r,n),new be(t(r.byteLength),r)};var Wo;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Wo||(Wo={}));var Bd=r=>{let e=vr(r);return Bd.bytes=Ke(e),e};Bd.bytes=0;function qo(r,e){let t=new be,n=Wo.LENGTH,o=-1,i=e?.lengthDecoder??Bd,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===Wo.LENGTH)try{if(o=i(t),o<0)throw new Al("Invalid message length");if(o>a)throw new hs("Message length too long");let f=i.bytes;t.consume(f),e?.onLength!=null&&e.onLength(o),n=Wo.DATA}catch(f){if(f instanceof RangeError){if(t.byteLength>s)throw new Sl("Message length length too long");break}throw f}if(n===Wo.DATA){if(t.byteLength<o)break;let f=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(f),yield f,n=Wo.LENGTH}}}return El(r)?async function*(){for await(let f of r)t.append(f),yield*c();if(t.byteLength>0)throw new Xa("Unexpected end of input")}():function*(){for(let f of r)t.append(f),yield*c();if(t.byteLength>0)throw new Xa("Unexpected end of input")}()}qo.fromReader=(r,e)=>{let t=1,n=async function*(){for(;;)try{let{done:i,value:s}=await r.next(t);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{t=1}}();return qo(n,{...e??{},onLength:i=>{t=i}})};var kd=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Za(r,e,t,n){let o=new kd(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((i,s)=>{function a(){t?.removeEventListener("abort",h),r.removeEventListener(e,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,f)}let c=p=>{try{if(n?.filter?.(p)===!1)return}catch(m){a(),s(m);return}a(),i(p)},f=p=>{a(),s(p.detail)},h=()=>{a(),s(o)};t?.addEventListener("abort",h),r.addEventListener(e,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,f)})}var Pd=class extends vl{channel;incomingData;maxBufferedAmount;bufferedAmountLowEventTimeout;maxMessageSize;receiveFinAck;finAckTimeout;openTimeout;closeController;constructor(e){let t=e.onEnd;switch(e.onEnd=o=>{this.log.trace('readable and writeable ends closed with status "%s"',this.status),Promise.resolve(async()=>{if(!(this.timeline.abort!=null||this.timeline.reset!==null))try{await Ga(this.receiveFinAck.promise,{milliseconds:this.finAckTimeout})}catch(i){this.log.error("error receiving FIN_ACK",i)}}).then(()=>{this.incomingData.end(),t?.(o)}).catch(i=>{this.log.error("error ending stream",i)}).finally(()=>{this.channel.close()})},super(e),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=ps(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??Iw,this.maxBufferedAmount=e.maxBufferedAmount??Cw,this.maxMessageSize=(e.maxMessageSize??ls)-Tw,this.receiveFinAck=Ze(),this.finAckTimeout=e.closeTimeout??Bw,this.openTimeout=e.openTimeout??kw,this.closeController=new AbortController,this.channel.readyState){case"open":this.timeline.open=new Date().getTime();break;case"closed":case"closing":(this.timeline.close===void 0||this.timeline.close===0)&&(this.timeline.close=Date.now());break;case"connecting":break;default:throw this.log.error("unknown datachannel state %s",this.channel.readyState),new Io("Unknown datachannel state")}this.channel.onopen=o=>{this.timeline.open=new Date().getTime()},this.channel.onclose=o=>{this.log.trace("received onclose event"),this.closeController.abort(),this.receiveFinAck.resolve(),this.close().catch(i=>{this.log.error("error closing stream after channel closed",i)})},this.channel.onerror=o=>{this.log.trace("received onerror event"),this.closeController.abort();let i=o.error;this.abort(i)},this.channel.onmessage=async o=>{let{data:i}=o;i===null||i.byteLength===0||this.incomingData.push(new Uint8Array(i,0,i.byteLength))};let n=this;Promise.resolve().then(async()=>{for await(let o of qo(this.incomingData)){let i=n.processIncomingProtobuf(o);i!=null&&n.sourcePush(new be(i))}}).catch(o=>{this.log.error("error processing incoming data channel messages",o)})}sendNewStream(){}async _sendMessage(e,t=!0){if(this.channel.readyState==="closed"||this.channel.readyState==="closing")throw new Io(`Invalid datachannel state - ${this.channel.readyState}`);if(this.channel.readyState!=="open"){let n=AbortSignal.timeout(this.openTimeout),o=Td([this.closeController.signal,n]);try{this.log('channel state is "%s" and not "open", waiting for "open" event before sending data',this.channel.readyState),await Za(this.channel,"open",o)}finally{o.clear()}this.log('channel state is now "%s", sending data',this.channel.readyState)}if(t&&this.channel.bufferedAmount>this.maxBufferedAmount){let n=AbortSignal.timeout(this.bufferedAmountLowEventTimeout),o=Td([this.closeController.signal,n]);try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await Za(this.channel,"bufferedamountlow",o)}catch(i){throw n.aborted?new Pu(`Timed out waiting for DataChannel buffer to clear after ${this.bufferedAmountLowEventTimeout}ms`):i}finally{o.clear()}}try{this.log.trace('sending message, channel state "%s"',this.channel.readyState),this.channel.send(e.subarray())}catch(n){this.log.error("error while sending message",n)}}async sendData(e){let t=e.byteLength;for(e=e.sublist();e.byteLength>0;){let n=Math.min(e.byteLength,this.maxMessageSize),o=e.subarray(0,n),i=Ct.encode({message:o}),s=Ya.single(i);this.log.trace("sending %d/%d bytes on channel",o.byteLength,t),await this._sendMessage(s),e.consume(n)}this.log.trace('finished sending data, channel state "%s"',this.channel.readyState)}async sendReset(){try{await this._sendFlag(Ct.Flag.RESET)}catch(e){this.log.error("failed to send reset - %e",e)}finally{this.channel.close()}}async sendCloseWrite(e){if(this.channel.readyState!=="open"){this.receiveFinAck.resolve();return}if(await this._sendFlag(Ct.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await rr(this.receiveFinAck.promise,e?.signal,{errorMessage:"sending close-write was aborted before FIN_ACK was received",errorName:"FinAckNotReceivedError"})}catch(n){this.log.error("failed to await FIN_ACK",n)}}else this.log.trace("sending FIN failed, not awaiting FIN_ACK");this.receiveFinAck.resolve()}async sendCloseRead(){this.channel.readyState==="open"&&await this._sendFlag(Ct.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=Ct.decode(e);if(t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===Ct.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag(Ct.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===Ct.Flag.RESET&&this.reset(),t.flag===Ct.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===Ct.Flag.FIN_ACK&&(this.log.trace("received FIN_ACK"),this.receiveFinAck.resolve())),this.readStatus==="ready")return t.message}async _sendFlag(e){if(this.channel.readyState!=="open")return this.log.trace('not sending flag %s because channel is "%s" and not "open"',e.toString(),this.channel.readyState),!1;this.log.trace("sending flag %s",e.toString());let t=Ct.encode({flag:e}),n=Ya.single(t);try{return await this._sendMessage(n,!1),!0}catch(o){this.log.error("could not send flag %s - %e",e.toString(),o)}return!1}};function ds(r){let{channel:e,direction:t,handshake:n}=r;return new Pd({id:`${e.id}`,log:r.logger.forComponent(`libp2p:webrtc:stream:${n===!0?"handshake":t}:${e.id}`),...r})}var Qn=class{protocol;peerConnection;bufferedStreams=[];metrics;dataChannelOptions;components;log;constructor(e,t){this.components=e,this.peerConnection=t.peerConnection,this.metrics=t.metrics,this.protocol=t.protocol??vd,this.dataChannelOptions=t.dataChannelOptions??{},this.log=e.logger.forComponent("libp2p:webrtc:muxerfactory"),this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace('incoming early datachannel with channel id %d and label "%s"',n.id),n.label==="init"){this.log.trace("closing early init channel"),n.close();return}let o={},i=ds({channel:n,direction:"inbound",onEnd:s=>{o.onEnd(s)},logger:e.logger,...this.dataChannelOptions});o.stream=i,o.channel=n,o.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(s=>s.stream.id!==i.id)},this.bufferedStreams.push(o)}}createStreamMuxer(e){return new Nd(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},Nd=class{init;streams;protocol;log;peerConnection;dataChannelOptions;metrics;logger;constructor(e,t){this.init=t,this.log=e.logger.forComponent("libp2p:webrtc:muxer"),this.logger=e.logger,this.streams=t.streams.map(n=>n.stream),this.peerConnection=t.peerConnection,this.protocol=t.protocol??vd,this.metrics=t.metrics,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming datachannel with channel id %d",n.id),n.label==="init"){this.log.trace("closing init channel"),n.close();return}let o=n.id,i=ds({channel:n,direction:"inbound",onEnd:()=>{this.#e(i,n),this.log("incoming channel %s ended",o)},logger:this.logger,...this.dataChannelOptions});this.streams.push(i),this.metrics?.increment({incoming_stream:!0}),t?.onIncomingStream?.(i)},this.init.streams.length>0&&queueMicrotask(()=>{this.init.streams.forEach(n=>{n.onEnd=()=>{this.log("incoming early channel %s ended with state %s",n.channel.id,n.channel.readyState),this.#e(n.stream,n.channel)},this.metrics?.increment({incoming_stream:!0}),this.init?.onIncomingStream?.(n.stream)})})}#e(e,t){this.log.trace("stream %s %s %s onEnd",e.direction,e.id,e.protocol),$w(t,`${e.direction} ${e.id} ${e.protocol}`,this.dataChannelOptions.drainTimeout,{log:this.log}),this.streams=this.streams.filter(n=>n.id!==e.id),this.metrics?.increment({stream_end:!0}),this.init?.onStreamEnd?.(e)}async close(e){try{await Promise.all(this.streams.map(async t=>t.close(e)))}catch(t){this.abort(t)}}abort(e){for(let t of this.streams)t.abort(e)}source=gl();sink=wl;newStream(){let e=this.peerConnection.createDataChannel(""),t=e.id;this.log.trace("opened outgoing datachannel with channel id %s",t);let n=ds({channel:e,direction:"outbound",onEnd:()=>{this.#e(n,e),this.log("outgoing channel %s ended",t)},logger:this.logger,...this.dataChannelOptions});return this.streams.push(n),this.metrics?.increment({outgoing_stream:!0}),n}};var Il=globalThis.RTCPeerConnection,Tl=globalThis.RTCSessionDescription,Xw=globalThis.RTCIceCandidate;var Od=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Ze(),this.haveNext=Ze()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Ze(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Ze(),await rr(this.readNext.promise,t?.signal,t)}};function Bl(){return new Od}var kl=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Yw(r,e){let t=Bl();r.sink(t).catch(async s=>{await t.end(s)}),r.sink=async s=>{for await(let a of s)await t.push(a);await t.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new be;return{read:async s=>{if(s?.signal?.throwIfAborted(),s?.bytes==null){let{done:c,value:f}=await rr(n.next(),s?.signal);return c===!0?null:f}for(;o.byteLength<s.bytes;){let{value:c,done:f}=await rr(n.next(),s?.signal);if(f===!0)throw new kl("unexpected end of input");o.append(c)}let a=o.sublist(0,s.bytes);return o.consume(s.bytes),a},write:async(s,a)=>{a?.signal?.throwIfAborted(),s instanceof Uint8Array?await t.push(s,a):await t.push(s.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let s=r.source;r.source=async function*(){e?.yieldBytes===!1?yield o:yield*o,yield*s}()}return r}}}var Pl=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Nl=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ol=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ja(r,e={}){let t=Yw(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ke(e.maxDataLength));let n=e?.lengthDecoder??vr,o=e?.lengthEncoder??Hr;return{read:async s=>{let a=-1,c=new be;for(;;){c.append(await t.read({...s,bytes:1}));try{a=n(c)}catch(f){if(f instanceof RangeError)continue;throw f}if(a<0)throw new Pl("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new Ol("message length length too long");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Nl("message length too long");return t.read({...s,bytes:a})},write:async(s,a)=>{await t.write(new be(o(s.byteLength),s),a)},writeV:async(s,a)=>{let c=new be(...s.flatMap(f=>[o(f.byteLength),f]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function Rl(r,e){let t=Ja(r,e),n={read:async(o,i)=>{let s=await t.read(i);return o.decode(s)},write:async(o,i,s)=>{await t.write(i.encode(o),s)},writeV:async(o,i,s)=>{await t.writeV(o.map(a=>i.encode(a)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var Yt=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var eo=class extends Error{constructor(e){super(`WebRTC transport error: ${e}`),this.name="WebRTCTransportError"}},nr=class extends eo{constructor(e="SDP handshake failed"){super(e),this.name="SDPHandshakeFailedError"}};var Dl=class extends eo{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`),this.name="WebRTC/InvalidFingerprintError"}};var Ll=class extends eo{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`),this.name="WebRTC/UnimplementedError"}},Ul=class extends eo{constructor(e){super(`unsupported hash algorithm code: ${e} please see the codes at https://github.com/multiformats/multicodec/blob/master/table.csv `),this.name="WebRTC/UnsupportedHashAlgorithmError"}};var Lt;(function(r){let e;(function(o){o.SDP_OFFER="SDP_OFFER",o.SDP_ANSWER="SDP_ANSWER",o.ICE_CANDIDATE="ICE_CANDIDATE"})(e=r.Type||(r.Type={}));let t;(function(o){o[o.SDP_OFFER=0]="SDP_OFFER",o[o.SDP_ANSWER=1]="SDP_ANSWER",o[o.ICE_CANDIDATE=2]="ICE_CANDIDATE"})(t||(t={})),function(o){o.codec=()=>Vo(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=_r((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.data!=null&&(i.uint32(18),i.string(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let f=o.uint32();switch(f>>>3){case 1:{a.type=r.Type.codec().decode(o);break}case 2:{a.data=o.string();break}default:{o.skipType(f&7);break}}}return a})),n),r.encode=o=>Er(o,r.codec()),r.decode=(o,i)=>Sr(o,r.codec(),i)})(Lt||(Lt={}));var jl=async(r,e,t)=>{try{let n=Ze();for($2(r,n);;){let o=await Promise.race([n.promise,e.read({signal:t.signal}).catch(()=>{})]);if(o==null){t.signal?.throwIfAborted();break}if(o.type!==Lt.Type.ICE_CANDIDATE)throw new ku("ICE candidate message expected");let i=JSON.parse(o.data??"null");if(i===""||i===null){t.onProgress?.(new Yt("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let s=new Xw(i);t.log.trace("%s received new ICE candidate %o",t.direction,i);try{t.onProgress?.(new Yt("webrtc:add-ice-candidate",s.candidate)),await r.addIceCandidate(s)}catch(a){t.log.error("%s bad candidate received",t.direction,i,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate",t.direction,n),t.signal?.aborted===!0&&Ml(r)!=="connected")throw n}};function Ml(r){return za?r.iceConnectionState:r.connectionState}function $2(r,e){r[za?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(Ml(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new Cu("RTCPeerConnection was closed"));break;default:break}}}async function Zw({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:i,transportManager:s,log:a,logger:c,onProgress:f}){let{baseAddr:h}=Jw(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing base address: %a",h);let p=h.getPeerId();if(p==null)throw new Ae("Relay peer was missing");let m=i.getConnections(is(p)),v,g=!1;m.length===0?(f?.(new Yt("webrtc:dial-relay")),v=await s.dial(h,{signal:t,onProgress:f}),g=!0):(f?.(new Yt("webrtc:reuse-relay-connection")),v=m[0]);try{f?.(new Yt("webrtc:open-signaling-stream"));let w=await v.newStream(qa,{signal:t,runOnLimitedConnection:!0}),S=Rl(w).pb(Lt),O=new Il(r),Y=new Qn({logger:c},{peerConnection:O,dataChannelOptions:e});try{let T=O.createDataChannel("init");O.onicecandidate=({candidate:N})=>{let U=JSON.stringify(N?.toJSON()??null);a.trace("initiator sending ICE candidate %o",N),S.write({type:Lt.Type.ICE_CANDIDATE,data:U},{signal:t}).catch($=>{a.error("error sending ICE candidate",$)})},O.onicecandidateerror=N=>{a.error("initiator ICE candidate error",N)};let b=await O.createOffer().catch(N=>{throw a.error("could not execute createOffer",N),new nr("Failed to set createOffer")});a.trace("initiator send SDP offer %s",b.sdp),f?.(new Yt("webrtc:send-sdp-offer")),await S.write({type:Lt.Type.SDP_OFFER,data:b.sdp},{signal:t}),await O.setLocalDescription(b).catch(N=>{throw a.error("could not execute setLocalDescription",N),new nr("Failed to set localDescription")}),f?.(new Yt("webrtc:read-sdp-answer")),a.trace("initiator read SDP answer");let D=await S.read({signal:t});if(D.type!==Lt.Type.SDP_ANSWER)throw new nr("Remote should send an SDP answer");a.trace("initiator received SDP answer %s",D.data);let V=new Tl({type:"answer",sdp:D.data});return await O.setRemoteDescription(V).catch(N=>{throw a.error("could not execute setRemoteDescription",N),new nr("Failed to set remoteDescription")}),a.trace("initiator read candidates until connected"),f?.(new Yt("webrtc:read-ice-candidates")),await jl(O,S,{direction:"initiator",signal:t,log:a,onProgress:f}),a.trace("initiator connected, closing init channel"),T.close(),f?.(new Yt("webrtc:close-signaling-stream")),a.trace("closing signaling channel"),await w.close({signal:t}),a.trace("initiator connected to remote address %s",o),{remoteAddress:o,peerConnection:O,muxerFactory:Y}}catch(T){throw a.error("outgoing signaling error",T),O.close(),w.abort(T),T}finally{O.onicecandidate=null,O.onicecandidateerror=null}}finally{if(g)try{await v.close({signal:t})}catch(w){v.abort(w)}}}var Qw=De(vw.matchers[0],ye("p2p-circuit")),Kl=class r extends Mn{transportManager;shutdownController;events;constructor(e,t){super(),this.transportManager=e.transportManager,this.events=e.events,this.shutdownController=t.shutdownController,this.onTransportListening=this.onTransportListening.bind(this)}async listen(){this.events.addEventListener("transport:listening",this.onTransportListening)}onTransportListening(e){e.detail.getAddrs().filter(n=>Qw.exactMatch(n)).map(n=>n.encapsulate("/webrtc")).length>0&&this.safeDispatchEvent("listening")}getAddrs(){return this.transportManager.getListeners().filter(e=>!(e instanceof r)).map(e=>e.getAddrs().filter(t=>Qw.exactMatch(t)).map(t=>t.encapsulate("/webrtc"))).flat()}updateAnnounceAddrs(){}async close(){this.events.removeEventListener("transport:listening",this.onTransportListening),this.shutdownController.abort(),queueMicrotask(()=>{this.safeDispatchEvent("close")})}};async function ex({peerConnection:r,stream:e,signal:t,connection:n,log:o}){o.trace("new inbound signaling stream");let i=Rl(e).pb(Lt);try{r.onicecandidate=({candidate:h})=>{let p=JSON.stringify(h?.toJSON()??null);o.trace("recipient sending ICE candidate %s",p),i.write({type:Lt.Type.ICE_CANDIDATE,data:p},{signal:t}).catch(m=>{o.error("error sending ICE candidate",m)})},o.trace("recipient read SDP offer");let a=await i.read({signal:t});if(a.type!==Lt.Type.SDP_OFFER)throw new nr(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `);o.trace("recipient received SDP offer %s",a.data);let c=new Tl({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(h=>{throw o.error("could not execute setRemoteDescription",h),new nr("Failed to set remoteDescription")});let f=await r.createAnswer().catch(h=>{throw o.error("could not execute createAnswer",h),new nr("Failed to create answer")});o.trace("recipient send SDP answer %s",f.sdp),await i.write({type:Lt.Type.SDP_ANSWER,data:f.sdp},{signal:t}),await r.setLocalDescription(f).catch(h=>{throw o.error("could not execute setLocalDescription",h),new nr("Failed to set localDescription")}),o.trace("recipient read candidates until connected"),await jl(r,i,{direction:"recipient",signal:t,log:o})}catch(a){if(Ml(r)!=="connected")throw o.error("error while handling signaling stream from peer %a",n.remoteAddr,a),r.close(),a;o("error while handling signaling stream from peer %a, ignoring as the RTCPeerConnection is already connected",n.remoteAddr,a)}let s=$r(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return o.trace("recipient connected to remote address %s",s),{remoteAddress:s}}var Hl=class{components;init;log;_started=!1;metrics;shutdownController;constructor(e,t={}){this.components=e,this.init=t,this.log=e.logger.forComponent("libp2p:webrtc"),this.shutdownController=new AbortController,this.shutdownController.signal,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_dialer_events_total",{label:"event",help:"Total count of WebRTC dialer events by type"}),listenerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_listener_events_total",{label:"event",help:"Total count of WebRTC listener events by type"})})}[Su]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[Wi]=["@libp2p/transport"];[Qy]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(qa,e=>{let t=this.components.upgrader.createInboundAbortSignal(this.shutdownController.signal);this._onProtocol(e,t).catch(n=>{this.log.error("failed to handle incoming connect from %p",e.connection.remotePeer,n)}).finally(()=>{t.clear()})},{runOnLimitedConnection:!0}),this._started=!0}async stop(){await this.components.registrar.unhandle(qa),this._started=!1}createListener(e){return new Kl(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(Aw.exactMatch)}dialFilter(e){return this.listenFilter(e)}async dial(e,t){this.log.trace("dialing address: %a",e);let{remoteAddress:n,peerConnection:o,muxerFactory:i}=await Zw({rtcConfiguration:await _d(this.init.rtcConfiguration),dataChannel:this.init.dataChannel,multiaddr:e,dataChannelOptions:this.init.dataChannel,signal:t.signal,connectionManager:this.components.connectionManager,transportManager:this.components.transportManager,log:this.log,logger:this.components.logger,onProgress:t.onProgress}),s=new Fo(this.components,{peerConnection:o,timeline:{open:Date.now()},remoteAddr:n,metrics:this.metrics?.dialerEvents}),a=await t.upgrader.upgradeOutbound(s,{skipProtection:!0,skipEncryption:!0,muxerFactory:i,onProgress:t.onProgress,signal:t.signal});return this._closeOnShutdown(o,s),a}async _onProtocol({connection:e,stream:t},n){let o=new Il(await _d(this.init.rtcConfiguration)),i=new Qn(this.components,{peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:s}=await ex({peerConnection:o,connection:e,stream:t,signal:n,log:this.log});await t.close({signal:n});let a=new Fo(this.components,{peerConnection:o,timeline:{open:new Date().getTime()},remoteAddr:s,metrics:this.metrics?.listenerEvents});await this.components.upgrader.upgradeInbound(a,{skipEncryption:!0,skipProtection:!0,muxerFactory:i,signal:n}),this._closeOnShutdown(o,a)}catch(s){throw this.log.error("incoming signaling error",s),o.close(),t.abort(s),s}}_closeOnShutdown(e,t){let n=()=>{t.close().catch(o=>{this.log.error("could not close WebRTCMultiaddrConnection",o)})};this.shutdownController.signal.addEventListener("abort",n),e.addEventListener("close",()=>{this.shutdownController.signal.removeEventListener("abort",n)})}};function Jw(r){let e=r.toString().split("/webrtc/");if(e.length!==2)throw new Ae("webrtc protocol was not present in multiaddr");if(!e[0].includes("/p2p-circuit"))throw new Ae("p2p-circuit protocol was not present in multiaddr");let t=$r(e[0]),o=$r("/"+e[1]).getPeerId();if(o==null)throw new Ae("destination peer id was missing");let i=t.protos().pop();if(i===void 0)throw new Ae("invalid multiaddr");return i.name!=="p2p"&&(t=t.encapsulate(`/p2p/${o}`)),{baseAddr:t,peerId:is(o)}}var cG=Lr(rx());var Gr={};bt(Gr,{Any:()=>Wr,BaseBlock:()=>Je,BaseStringBlock:()=>rc,BitString:()=>Br,BmpString:()=>Zo,Boolean:()=>zo,CharacterString:()=>si,Choice:()=>gs,Constructed:()=>it,DATE:()=>cc,DateTime:()=>lc,Duration:()=>fc,EndOfContent:()=>nc,Enumerated:()=>Xo,GeneralString:()=>ii,GeneralizedTime:()=>ai,GraphicString:()=>oi,HexBlock:()=>qr,IA5String:()=>ni,Integer:()=>bn,Null:()=>Ir,NumericString:()=>Qo,ObjectIdentifier:()=>Yo,OctetString:()=>Tr,Primitive:()=>xn,PrintableString:()=>ei,RawData:()=>Ud,RelativeObjectIdentifier:()=>ac,Repeated:()=>ci,Sequence:()=>Mt,Set:()=>Kt,TIME:()=>pc,TeletexString:()=>ti,TimeOfDay:()=>uc,UTCTime:()=>oo,UniversalString:()=>Jo,Utf8String:()=>ir,ValueBlock:()=>ft,VideotexString:()=>ri,ViewWriter:()=>ys,VisibleString:()=>no,compareSchema:()=>ro,fromBER:()=>An,verifySchema:()=>l_});var me=Lr(gn());function Go(r,e){let t=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)t+=r[r.length-1-n]*Math.pow(2,e*n);return t}function to(r,e,t=-1){let n=t,o=r,i=0,s=Math.pow(2,e);for(let a=1;a<8;a++){if(r<s){let c;if(n<0)c=new ArrayBuffer(a),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let f=new Uint8Array(c);for(let h=a-1;h>=0;h--){let p=Math.pow(2,h*e);f[i-h-1]=Math.floor(o/p),o-=f[i-h-1]*p}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function Fl(...r){let e=0,t=0;for(let i of r)e+=i.length;let n=new ArrayBuffer(e),o=new Uint8Array(n);for(let i of r)o.set(i,t),t+=i.length;return o}function Dd(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=Go(t,8),o=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(o);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=r[a];return i[0]&=127,Go(i,8)-n}function nx(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let s=t-e,a=to(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=to(e,8,n),i=new Uint8Array(o);if(i[0]&128){let s=o.slice(0),a=new Uint8Array(s);o=new ArrayBuffer(o.byteLength+1),i=new Uint8Array(o);for(let c=0;c<s.byteLength;c++)i[c+1]=a[c];i[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function ox(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function Ut(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,o=new Array(n);for(let s=0;s<n;s++)o[s]="0";return o.join("").concat(t)}var xP=Math.log(2);function Wl(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function jd(r){let e=0,t=0;for(let o=0;o<r.length;o++){let i=r[o];e+=i.byteLength}let n=new Uint8Array(e);for(let o=0;o<r.length;o++){let i=r[o];n.set(new Uint8Array(i),t),t+=i.byteLength}return n.buffer}function vn(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var ys=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return jd(this.items)}},Qa=[new Uint8Array([1])],ix="0123456789",Ld="name",sx="valueHexView",J2="isHexOnly",Q2="idBlock",e_="tagClass",t_="tagNumber",r_="isConstructed",n_="fromBER",o_="toBER",i_="local",jt="",kr=new ArrayBuffer(0),af=new Uint8Array(0),tc="EndOfContent",cx="OCTET STRING",ux="BIT STRING";function qr(r){var e;return e=class extends r{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}constructor(...n){var o;super(...n);let i=n[0]||{};this.isHexOnly=(o=i.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=i.valueHex?me.BufferSourceConverter.toUint8Array(i.valueHex):af}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!vn(this,s,o,i))return-1;let a=o+i;return this.valueHexView=s.subarray(o,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),o)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",kr)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:me.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var wn=class{static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}constructor({blockLength:e=0,error:t=jt,warnings:n=[],valueBeforeDecode:o=af}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=me.BufferSourceConverter.toUint8Array(o)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:me.Convert.ToHex(this.valueBeforeDecodeView)}}};wn.NAME="baseBlock";var ft=class extends wn{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};ft.NAME="valueBlock";var ql=class extends qr(wn){constructor({idBlock:e={}}={}){var t,n,o,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?me.BufferSourceConverter.toUint8Array(e.valueHex):af,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",kr}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let o=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,o[0]=t}return o.buffer}if(!this.isHexOnly){let o=to(this.tagNumber,7),i=new Uint8Array(o),s=o.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=i[c]|128;a[s]=i[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let i=0;i<o.length-1;i++)n[i+1]=o[i]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=me.BufferSourceConverter.toUint8Array(e);if(!vn(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,f=this.valueHexView=new Uint8Array(255),h=255;for(;i[c]&128;){if(f[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===h){h+=255;let m=new Uint8Array(h);for(let v=0;v<f.length;v++)m[v]=f[v];f=this.valueHexView=new Uint8Array(h)}}this.blockLength=c+1,f[c-1]=i[c]&127;let p=new Uint8Array(c);for(let m=0;m<c;m++)p[m]=f[m];f=this.valueHexView=new Uint8Array(c),f.set(p),this.blockLength<=9?this.tagNumber=Go(f,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};ql.NAME="identificationBlock";var Gl=class extends wn{constructor({lenBlock:e={}}={}){var t,n,o;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=me.BufferSourceConverter.toUint8Array(e);if(!vn(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,t+this.blockLength;let s=i[0]&127;if(s>8)return this.error="Too big integer",-1;if(s+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=o.subarray(a,a+s);return c[s-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Go(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=s+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let o=to(this.length,8);if(o.byteLength>127)return this.error="Too big length",kr;if(t=new ArrayBuffer(o.byteLength+1),e)return t;let i=new Uint8Array(o);n=new Uint8Array(t),n[0]=o.byteLength|128;for(let s=0;s<o.byteLength;s++)n[s+1]=i[s];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Gl.NAME="lengthBlock";var Z={},Je=class extends wn{constructor({name:e=jt,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new ql(o),this.lenBlock=new Gl(o),this.valueBlock=i?new i(o):new ft(o)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}toBER(e,t){let n=t||new ys;t||lx(this);let o=this.idBlock.toBER(e);if(n.write(o),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(i)}return t?kr:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():me.Convert.ToHex(this.toBER())}onAsciiEncoding(){let e=this.constructor.NAME,t=me.Convert.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${t}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return ox(t,n)}};Je.NAME="BaseBlock";function lx(r){var e;if(r instanceof Z.Constructed)for(let t of r.valueBlock.value)lx(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}var rc=class extends Je{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=jt,...t}={},n){super(t,n),e&&this.fromString(e)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};rc.NAME="BaseStringBlock";var zl=class extends qr(ft){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};zl.NAME="PrimitiveValueBlock";var fx,xn=class extends Je{constructor(e={}){super(e,zl),this.idBlock.isConstructed=!1}};fx=xn;Z.Primitive=fx;xn.NAME="PRIMITIVE";function s_(r,e){if(r instanceof e)return r;let t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function ws(r,e=0,t=r.length){let n=e,o=new Je({},ft),i=new wn;if(!vn(i,r,e,t))return o.error=i.error,{offset:-1,result:o};if(!r.subarray(e,e+t).length)return o.error="Zero buffer length",{offset:-1,result:o};let a=o.idBlock.fromBER(r,e,t);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),a===-1)return o.error=o.idBlock.error,{offset:-1,result:o};if(e=a,t-=o.idBlock.blockLength,a=o.lenBlock.fromBER(r,e,t),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),a===-1)return o.error=o.lenBlock.error,{offset:-1,result:o};if(e=a,t-=o.lenBlock.blockLength,!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let c=Je;switch(o.idBlock.tagClass){case 1:if(o.idBlock.tagNumber>=37&&o.idBlock.isHexOnly===!1)return o.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:o};switch(o.idBlock.tagNumber){case 0:if(o.idBlock.isConstructed&&o.lenBlock.length>0)return o.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:o};c=Z.EndOfContent;break;case 1:c=Z.Boolean;break;case 2:c=Z.Integer;break;case 3:c=Z.BitString;break;case 4:c=Z.OctetString;break;case 5:c=Z.Null;break;case 6:c=Z.ObjectIdentifier;break;case 10:c=Z.Enumerated;break;case 12:c=Z.Utf8String;break;case 13:c=Z.RelativeObjectIdentifier;break;case 14:c=Z.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=Z.Sequence;break;case 17:c=Z.Set;break;case 18:c=Z.NumericString;break;case 19:c=Z.PrintableString;break;case 20:c=Z.TeletexString;break;case 21:c=Z.VideotexString;break;case 22:c=Z.IA5String;break;case 23:c=Z.UTCTime;break;case 24:c=Z.GeneralizedTime;break;case 25:c=Z.GraphicString;break;case 26:c=Z.VisibleString;break;case 27:c=Z.GeneralString;break;case 28:c=Z.UniversalString;break;case 29:c=Z.CharacterString;break;case 30:c=Z.BmpString;break;case 31:c=Z.DATE;break;case 32:c=Z.TimeOfDay;break;case 33:c=Z.DateTime;break;case 34:c=Z.Duration;break;default:{let f=o.idBlock.isConstructed?new Z.Constructed:new Z.Primitive;f.idBlock=o.idBlock,f.lenBlock=o.lenBlock,f.warnings=o.warnings,o=f}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?Z.Constructed:Z.Primitive}return o=s_(o,c),a=o.fromBER(r,e,o.lenBlock.isIndefiniteForm?t:o.lenBlock.length),o.valueBeforeDecodeView=r.subarray(n,n+o.blockLength),{offset:a,result:o}}function An(r){if(!r.byteLength){let e=new Je({},ft);return e.error="Input buffer has zero length",{offset:-1,result:e}}return ws(me.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function a_(r,e){return r?1:e}var Fr=class extends ft{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=me.BufferSourceConverter.toUint8Array(e);if(!vn(this,o,t,n))return-1;if(this.valueBeforeDecodeView=o.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;a_(this.isIndefiniteForm,n)>0;){let s=ws(o,i,n);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(i=s.offset,this.blockLength+=s.result.blockLength,n-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===tc)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===tc?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new ys;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?kr:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Fr.NAME="ConstructedValueBlock";var px,it=class extends Je{constructor(e={}){super(e,Fr),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
|
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(`
|