@libp2p/identify 3.0.4 → 3.0.5-82bd42bcf
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 +5 -5
- package/dist/src/identify-push.js +1 -1
- package/dist/src/identify-push.js.map +1 -1
- package/dist/src/identify.d.ts.map +1 -1
- package/dist/src/identify.js +19 -8
- package/dist/src/identify.js.map +1 -1
- package/dist/src/utils.js +3 -3
- package/dist/src/utils.js.map +1 -1
- package/package.json +9 -8
- package/src/identify-push.ts +1 -1
- package/src/identify.ts +20 -8
- package/src/utils.ts +3 -3
- package/dist/typedoc-urls.json +0 -18
package/dist/index.min.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PIdentify = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PIdentify=(()=>{var ou=Object.create;var tn=Object.defineProperty;var su=Object.getOwnPropertyDescriptor;var iu=Object.getOwnPropertyNames;var au=Object.getPrototypeOf,cu=Object.prototype.hasOwnProperty;var $i=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Ae=(r,e)=>{for(var t in e)tn(r,t,{get:e[t],enumerable:!0})},zi=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of iu(e))!cu.call(r,o)&&o!==t&&tn(r,o,{get:()=>e[o],enumerable:!(n=su(e,o))||n.enumerable});return r};var Gi=(r,e,t)=>(t=r!=null?ou(au(r)):{},zi(e||!r||!r.__esModule?tn(t,"default",{value:r,enumerable:!0}):t,r)),lu=r=>zi(tn({},"__esModule",{value:!0}),r);var $a=$i(lr=>{"use strict";var Rh="[object ArrayBuffer]",pt=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Rh}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 s=0;s<n.length;s++)if(n[s]!==o[s])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 i of t)n+=i.byteLength;let o=new Uint8Array(n),s=0;for(let i of t){let a=this.toUint8Array(i);o.set(a,s),s+=a.length}return e[e.length-1]instanceof Function?this.toView(o,e[e.length-1]):o.buffer}},Js="string",_h=/^[0-9a-f]+$/i,Oh=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Vh=/^[a-zA-Z0-9-_]+$/,An=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=pt.toUint8Array(e),n="";for(let s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);return decodeURIComponent(escape(n))}},Ve=class{static toString(e,t=!1){let n=pt.toArrayBuffer(e),o=new DataView(n),s="";for(let i=0;i<n.byteLength;i+=2){let a=o.getUint16(i,t);s+=String.fromCharCode(a)}return s}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),o=new DataView(n);for(let s=0;s<e.length;s++)o.setUint16(s*2,e.charCodeAt(s),t);return n}},Sn=class r{static isHex(e){return typeof e===Js&&_h.test(e)}static isBase64(e){return typeof e===Js&&Oh.test(e)}static isBase64Url(e){return typeof e===Js&&Vh.test(e)}static ToString(e,t="utf8"){let n=pt.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 Ve.toString(n,!0);case"utf16":case"utf16be":return Ve.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 Ve.fromString(e,!0);case"utf16":case"utf16be":return Ve.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=pt.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 An.fromString(e);case"utf16":case"utf16be":return Ve.fromString(e);case"utf16le":case"usc2":return Ve.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 An.toString(e);case"utf16":case"utf16be":return Ve.toString(e);case"utf16le":case"usc2":return Ve.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=pt.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=pt.toUint8Array(e),n="",o=t.length;for(let s=0;s<o;s++){let i=t[s];i<16&&(n+="0"),n+=i.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 s=t.slice(o,o+2);n[o/2]=parseInt(s,16)}return n.buffer}static ToUtf16String(e,t=!1){return Ve.toString(e,t)}static FromUtf16String(e,t=!1){return Ve.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,"")||""}};Sn.DEFAULT_UTF8_ENCODING="utf8";function Ph(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let o=arguments[n];for(let s in o)t[s]=o[s]}return t}function Dh(...r){let e=r.map(o=>o.byteLength).reduce((o,s)=>o+s),t=new Uint8Array(e),n=0;return r.map(o=>new Uint8Array(o)).forEach(o=>{for(let s of o)t[n++]=s}),t.buffer}function Mh(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}lr.BufferSourceConverter=pt;lr.Convert=Sn;lr.assign=Ph;lr.combine=Dh;lr.isEqual=Mh});var Ll=$i((Xw,Ul)=>{function Cd(){return!!(typeof window<"u"&&typeof window.process=="object"&&window.process.type==="renderer"||typeof process<"u"&&typeof process.versions=="object"&&process.versions.electron||typeof navigator=="object"&&typeof navigator.userAgent=="string"&&navigator.userAgent.indexOf("Electron")>=0)}Ul.exports=Cd});var Fd={};Ae(Fd,{identify:()=>Md,identifyPush:()=>Hd});var qo=Symbol.for("@libp2p/peer-id");var Se=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Jt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var rn=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},nn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var De=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Dt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Er=(r,...e)=>{try{[...e]}catch{}};var on=Symbol.for("@libp2p/service-capabilities"),Gd=Symbol.for("@libp2p/service-dependencies");var jo={};Ae(jo,{base58btc:()=>J,base58flickr:()=>gu});var mp=new Uint8Array(0);function Wi(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 it(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 ji(r){return new TextEncoder().encode(r)}function Zi(r){return new TextDecoder().decode(r)}function uu(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 s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var y=0,d=0,x=0,B=m.length;x!==B&&m[x]===0;)x++,y++;for(var g=(B-x)*l+1>>>0,S=new Uint8Array(g);x!==B;){for(var L=m[x],U=0,I=g-1;(L!==0||U<d)&&I!==-1;I--,U++)L+=256*S[I]>>>0,S[I]=L%a>>>0,L=L/a>>>0;if(L!==0)throw new Error("Non-zero carry");d=U,x++}for(var k=g-d;k!==g&&S[k]===0;)k++;for(var T=c.repeat(y);k<g;++k)T+=r.charAt(S[k]);return T}function h(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var y=0;if(m[y]!==" "){for(var d=0,x=0;m[y]===c;)d++,y++;for(var B=(m.length-y)*u+1>>>0,g=new Uint8Array(B);m[y];){var S=t[m.charCodeAt(y)];if(S===255)return;for(var L=0,U=B-1;(S!==0||L<x)&&U!==-1;U--,L++)S+=a*g[U]>>>0,g[U]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");x=L,y++}if(m[y]!==" "){for(var I=B-x;I!==B&&g[I]===0;)I++;for(var k=new Uint8Array(d+(B-I)),T=d;I!==B;)k[T++]=g[I++];return k}}}function w(m){var y=h(m);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:h,decode:w}}var fu=uu,hu=fu,Ji=hu;var $o=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")}},zo=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 Xi(this,e)}},Go=class{decoders;constructor(e){this.decoders=e}or(e){return Xi(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 Xi(r,e){return new Go({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Wo=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 $o(e,t,n),this.decoder=new zo(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Xt({name:r,prefix:e,encode:t,decode:n}){return new Wo(r,e,t,n)}function Et({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Ji(t,r);return Xt({prefix:e,name:r,encode:n,decode:s=>it(o(s))})}function du(r,e,t,n){let o={};for(let l=0;l<e.length;++l)o[e[l]]=l;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,c=0,u=0;for(let l=0;l<s;++l){let f=o[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|f,a+=t,a>=8&&(a-=8,i[u++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function pu(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;s.length*t&7;)s+="=";return s}function ee({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Xt({prefix:e,name:r,encode(o){return pu(o,n,t)},decode(o){return du(o,n,t,r)}})}var J=Et({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),gu=Et({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Zo={};Ae(Zo,{base32:()=>at,base32hex:()=>wu,base32hexpad:()=>vu,base32hexpadupper:()=>Eu,base32hexupper:()=>xu,base32pad:()=>yu,base32padupper:()=>bu,base32upper:()=>mu,base32z:()=>Bu});var at=ee({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),mu=ee({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),yu=ee({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),bu=ee({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),wu=ee({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),xu=ee({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),vu=ee({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Eu=ee({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Bu=ee({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Yo={};Ae(Yo,{base36:()=>Br,base36upper:()=>Au});var Br=Et({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Au=Et({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Su=ta,Qi=128,Iu=127,ku=~Iu,Nu=Math.pow(2,31);function ta(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Nu;)e[t++]=r&255|Qi,r/=128;for(;r&ku;)e[t++]=r&255|Qi,r>>>=7;return e[t]=r|0,ta.bytes=t-n+1,e}var Cu=Jo,Tu=128,ea=127;function Jo(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Jo.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&ea)<<o:(i&ea)*Math.pow(2,o),o+=7}while(i>=Tu);return Jo.bytes=s-n,t}var Uu=Math.pow(2,7),Lu=Math.pow(2,14),Ru=Math.pow(2,21),_u=Math.pow(2,28),Ou=Math.pow(2,35),Vu=Math.pow(2,42),Pu=Math.pow(2,49),Du=Math.pow(2,56),Mu=Math.pow(2,63),Hu=function(r){return r<Uu?1:r<Lu?2:r<Ru?3:r<_u?4:r<Ou?5:r<Vu?6:r<Pu?7:r<Du?8:r<Mu?9:10},Fu={encode:Su,decode:Cu,encodingLength:Hu},Ku=Fu,Ar=Ku;function Sr(r,e=0){return[Ar.decode(r,e),Ar.decode.bytes]}function Qt(r,e,t=0){return Ar.encode(r,e,t),e}function er(r){return Ar.encodingLength(r)}function Me(r,e){let t=e.byteLength,n=er(r),o=n+er(t),s=new Uint8Array(o+t);return Qt(r,s,0),Qt(t,s,n),s.set(e,o),new tr(r,t,e,s)}function Mt(r){let e=it(r),[t,n]=Sr(e),[o,s]=Sr(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new tr(t,o,i,e)}function ra(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Wi(r.bytes,t.bytes)}}var tr=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function na(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return $u(t,Xo(r),e??J.encoder);default:return zu(t,Xo(r),e??at.encoder)}}var oa=new WeakMap;function Xo(r){let e=oa.get(r);if(e==null){let t=new Map;return oa.set(r,t),t}return e}var de=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!==Ir)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Gu)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=Me(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&&ra(e.multihash,n.multihash)}toString(e){return na(this,e)}toJSON(){return{"/":na(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:s,bytes:i}=t;return new r(n,o,s,i??sa(n,o,s.bytes))}else if(t[Wu]===!0){let{version:n,multihash:o,code:s}=t,i=Mt(o);return r.create(n,s,i)}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!==Ir)throw new Error(`Version 0 CID must use dag-pb (code: ${Ir}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=sa(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Ir,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=it(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new tr(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,h]=Sr(e.subarray(t));return t+=h,f},o=n(),s=Ir;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),c=n(),u=t+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,o]=qu(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Xo(s).set(n,e),s}};function qu(r,e){switch(r[0]){case"Q":{let t=e??J;return[J.prefix,t.decode(`${J.prefix}${r}`)]}case J.prefix:{let t=e??J;return[J.prefix,t.decode(r)]}case at.prefix:{let t=e??at;return[at.prefix,t.decode(r)]}case Br.prefix:{let t=e??Br;return[Br.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 $u(r,e,t){let{prefix:n}=t;if(n!==J.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function zu(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var Ir=112,Gu=18;function sa(r,e,t){let n=er(r),o=n+er(e),s=new Uint8Array(o+t.byteLength);return Qt(r,s,0),Qt(e,s,n),s.set(t,o),s}var Wu=Symbol.for("@ipld/js-cid/CID");var Qo={};Ae(Qo,{identity:()=>ct});var ia=0,ju="identity",aa=it;function Zu(r){return Me(ia,aa(r))}var ct={code:ia,name:ju,encode:aa,digest:Zu};function be(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 ca(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function Yu(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function rr(r,...e){if(!Yu(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function la(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ca(r.outputLen),ca(r.blockLen)}function nr(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 ua(r,e){rr(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var Ht=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var an=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),He=(r,e)=>r<<32-e|r>>>e;var Mp=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function fa(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function kr(r){return typeof r=="string"&&(r=fa(r)),rr(r),r}function es(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];rr(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let s=r[n];t.set(s,o),o+=s.length}return t}var or=class{clone(){return this._cloneInto()}},Hp={}.toString;function cn(r){let e=n=>r().update(kr(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function ln(r=32){if(Ht&&typeof Ht.getRandomValues=="function")return Ht.getRandomValues(new Uint8Array(r));if(Ht&&typeof Ht.randomBytes=="function")return Ht.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function Ju(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(t>>o&s),a=Number(t&s),c=n?4:0,u=n?0:4;r.setUint32(e+c,i,n),r.setUint32(e+u,a,n)}var ha=(r,e,t)=>r&e^~r&t,da=(r,e,t)=>r&e^r&t^e&t,sr=class extends or{constructor(e,t,n,o){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=an(this.buffer)}update(e){nr(this);let{view:t,buffer:n,blockLen:o}=this;e=kr(e);let s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=an(e);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){nr(this),ua(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;t[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)t[f]=0;Ju(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=an(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],s)}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:s,destroyed:i,pos:a}=this;return e.length=o,e.pos=a,e.finished=s,e.destroyed=i,o%t&&e.buffer.set(n),e}};var un=BigInt(4294967295),ts=BigInt(32);function pa(r,e=!1){return e?{h:Number(r&un),l:Number(r>>ts&un)}:{h:Number(r>>ts&un)|0,l:Number(r&un)|0}}function Xu(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=pa(r[o],e);[t[o],n[o]]=[s,i]}return[t,n]}var Qu=(r,e)=>BigInt(r>>>0)<<ts|BigInt(e>>>0),ef=(r,e,t)=>r>>>t,tf=(r,e,t)=>r<<32-t|e>>>t,rf=(r,e,t)=>r>>>t|e<<32-t,nf=(r,e,t)=>r<<32-t|e>>>t,of=(r,e,t)=>r<<64-t|e>>>t-32,sf=(r,e,t)=>r>>>t-32|e<<64-t,af=(r,e)=>e,cf=(r,e)=>r,lf=(r,e,t)=>r<<t|e>>>32-t,uf=(r,e,t)=>e<<t|r>>>32-t,ff=(r,e,t)=>e<<t-32|r>>>64-t,hf=(r,e,t)=>r<<t-32|e>>>64-t;function df(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var pf=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),gf=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,mf=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),yf=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,bf=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),wf=(r,e,t,n,o,s)=>e+t+n+o+s+(r/2**32|0)|0;var xf={fromBig:pa,split:Xu,toBig:Qu,shrSH:ef,shrSL:tf,rotrSH:rf,rotrSL:nf,rotrBH:of,rotrBL:sf,rotr32H:af,rotr32L:cf,rotlSH:lf,rotlSL:uf,rotlBH:ff,rotlBL:hf,add:df,add3L:pf,add3H:gf,add4L:mf,add4H:yf,add5H:wf,add5L:bf},O=xf;var[vf,Ef]=O.split(["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))),At=new Uint32Array(80),St=new Uint32Array(80),rs=class extends sr{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:h,Gh:w,Gl:m,Hh:y,Hl:d}=this;return[e,t,n,o,s,i,a,c,u,l,f,h,w,m,y,d]}set(e,t,n,o,s,i,a,c,u,l,f,h,w,m,y,d){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=h|0,this.Gh=w|0,this.Gl=m|0,this.Hh=y|0,this.Hl=d|0}process(e,t){for(let g=0;g<16;g++,t+=4)At[g]=e.getUint32(t),St[g]=e.getUint32(t+=4);for(let g=16;g<80;g++){let S=At[g-15]|0,L=St[g-15]|0,U=O.rotrSH(S,L,1)^O.rotrSH(S,L,8)^O.shrSH(S,L,7),I=O.rotrSL(S,L,1)^O.rotrSL(S,L,8)^O.shrSL(S,L,7),k=At[g-2]|0,T=St[g-2]|0,ne=O.rotrSH(k,T,19)^O.rotrBH(k,T,61)^O.shrSH(k,T,6),K=O.rotrSL(k,T,19)^O.rotrBL(k,T,61)^O.shrSL(k,T,6),V=O.add4L(I,K,St[g-7],St[g-16]),oe=O.add4H(V,U,ne,At[g-7],At[g-16]);At[g]=oe|0,St[g]=V|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:h,Fh:w,Fl:m,Gh:y,Gl:d,Hh:x,Hl:B}=this;for(let g=0;g<80;g++){let S=O.rotrSH(f,h,14)^O.rotrSH(f,h,18)^O.rotrBH(f,h,41),L=O.rotrSL(f,h,14)^O.rotrSL(f,h,18)^O.rotrBL(f,h,41),U=f&w^~f&y,I=h&m^~h&d,k=O.add5L(B,L,I,Ef[g],St[g]),T=O.add5H(k,x,S,U,vf[g],At[g]),ne=k|0,K=O.rotrSH(n,o,28)^O.rotrBH(n,o,34)^O.rotrBH(n,o,39),V=O.rotrSL(n,o,28)^O.rotrBL(n,o,34)^O.rotrBL(n,o,39),oe=n&s^n&a^s&a,E=o&i^o&c^i&c;x=y|0,B=d|0,y=w|0,d=m|0,w=f|0,m=h|0,{h:f,l:h}=O.add(u|0,l|0,T|0,ne|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let N=O.add3L(ne,V,E);n=O.add3H(N,T,K,oe),o=N|0}({h:n,l:o}=O.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=O.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=O.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=O.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:h}=O.add(this.Eh|0,this.El|0,f|0,h|0),{h:w,l:m}=O.add(this.Fh|0,this.Fl|0,w|0,m|0),{h:y,l:d}=O.add(this.Gh|0,this.Gl|0,y|0,d|0),{h:x,l:B}=O.add(this.Hh|0,this.Hl|0,x|0,B|0),this.set(n,o,s,i,a,c,u,l,f,h,w,m,y,d,x,B)}roundClean(){At.fill(0),St.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ga=cn(()=>new rs);var hn={};Ae(hn,{aInRange:()=>Ne,abool:()=>Fe,abytes:()=>ir,bitGet:()=>Nf,bitLen:()=>as,bitMask:()=>Cr,bitSet:()=>Cf,bytesToHex:()=>ut,bytesToNumberBE:()=>ft,bytesToNumberLE:()=>kt,concatBytes:()=>ht,createHmacDrbg:()=>cs,ensureBytes:()=>te,equalBytes:()=>If,hexToBytes:()=>Kt,hexToNumber:()=>is,inRange:()=>Nr,isBytes:()=>It,memoized:()=>$t,notImplemented:()=>Uf,numberToBytesBE:()=>Nt,numberToBytesLE:()=>qt,numberToHexUnpadded:()=>Ft,numberToVarBytesBE:()=>Sf,utf8ToBytes:()=>kf,validateObject:()=>Je});var ss=BigInt(0),fn=BigInt(1),Bf=BigInt(2);function It(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function ir(r){if(!It(r))throw new Error("Uint8Array expected")}function Fe(r,e){if(typeof e!="boolean")throw new Error(`${r} must be valid boolean, got "${e}".`)}var Af=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function ut(r){ir(r);let e="";for(let t=0;t<r.length;t++)e+=Af[r[t]];return e}function Ft(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function is(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var lt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function ma(r){if(r>=lt._0&&r<=lt._9)return r-lt._0;if(r>=lt._A&&r<=lt._F)return r-(lt._A-10);if(r>=lt._a&&r<=lt._f)return r-(lt._a-10)}function Kt(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,s=0;o<t;o++,s+=2){let i=ma(r.charCodeAt(s)),a=ma(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function ft(r){return is(ut(r))}function kt(r){return ir(r),is(ut(Uint8Array.from(r).reverse()))}function Nt(r,e){return Kt(r.toString(16).padStart(e*2,"0"))}function qt(r,e){return Nt(r,e).reverse()}function Sf(r){return Kt(Ft(r))}function te(r,e,t){let n;if(typeof e=="string")try{n=Kt(e)}catch(s){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${s}`)}else if(It(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} expected ${t} bytes, got ${o}`);return n}function ht(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];ir(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let s=r[n];t.set(s,o),o+=s.length}return t}function If(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function kf(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}var ns=r=>typeof r=="bigint"&&ss<=r;function Nr(r,e,t){return ns(r)&&ns(e)&&ns(t)&&e<=r&&r<t}function Ne(r,e,t,n){if(!Nr(e,t,n))throw new Error(`expected valid ${r}: ${t} <= n < ${n}, got ${typeof e} ${e}`)}function as(r){let e;for(e=0;r>ss;r>>=fn,e+=1);return e}function Nf(r,e){return r>>BigInt(e)&fn}function Cf(r,e,t){return r|(t?fn:ss)<<BigInt(e)}var Cr=r=>(Bf<<BigInt(r-1))-fn,os=r=>new Uint8Array(r),ya=r=>Uint8Array.from(r);function cs(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=os(r),o=os(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...f)=>t(o,n,...f),c=(f=os())=>{o=a(ya([0]),f),n=a(),f.length!==0&&(o=a(ya([1]),f),n=a())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<e;){n=a();let w=n.slice();h.push(w),f+=n.length}return ht(...h)};return(f,h)=>{i(),c(f);let w;for(;!(w=h(u()));)c();return i(),w}}var Tf={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"||It(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 Je(r,e,t={}){let n=(o,s,i)=>{let a=Tf[s];if(typeof a!="function")throw new Error(`Invalid validator "${s}", expected function`);let c=r[o];if(!(i&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(o)}=${c} (${typeof c}), expected ${s}`)};for(let[o,s]of Object.entries(e))n(o,s,!1);for(let[o,s]of Object.entries(t))n(o,s,!0);return r}var Uf=()=>{throw new Error("not implemented")};function $t(r){let e=new WeakMap;return(t,...n)=>{let o=e.get(t);if(o!==void 0)return o;let s=r(t,...n);return e.set(t,s),s}}var ie=BigInt(0),X=BigInt(1),zt=BigInt(2),Lf=BigInt(3),ls=BigInt(4),ba=BigInt(5),wa=BigInt(8),Rf=BigInt(9),_f=BigInt(16);function j(r,e){let t=r%e;return t>=ie?t:e+t}function Of(r,e,t){if(t<=ie||e<ie)throw new Error("Expected power/modulo > 0");if(t===X)return ie;let n=X;for(;e>ie;)e&X&&(n=n*r%t),r=r*r%t,e>>=X;return n}function Q(r,e,t){let n=r;for(;e-- >ie;)n*=n,n%=t;return n}function dn(r,e){if(r===ie||e<=ie)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=j(r,e),n=e,o=ie,s=X,i=X,a=ie;for(;t!==ie;){let u=n/t,l=n%t,f=o-i*u,h=s-a*u;n=t,t=l,o=i,s=a,i=f,a=h}if(n!==X)throw new Error("invert: does not exist");return j(o,e)}function Vf(r){let e=(r-X)/zt,t,n,o;for(t=r-X,n=0;t%zt===ie;t/=zt,n++);for(o=zt;o<r&&Of(o,e,r)!==r-X;o++);if(n===1){let i=(r+X)/ls;return function(c,u){let l=c.pow(u,i);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}let s=(t+X)/zt;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,l=a.pow(a.mul(a.ONE,o),t),f=a.pow(c,s),h=a.pow(c,t);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let w=1;for(let y=a.sqr(h);w<u&&!a.eql(y,a.ONE);w++)y=a.sqr(y);let m=a.pow(l,X<<BigInt(u-w-1));l=a.sqr(m),f=a.mul(f,m),h=a.mul(h,l),u=w}return f}}function Pf(r){if(r%ls===Lf){let e=(r+X)/ls;return function(n,o){let s=n.pow(o,e);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%wa===ba){let e=(r-ba)/wa;return function(n,o){let s=n.mul(o,zt),i=n.pow(s,e),a=n.mul(o,i),c=n.mul(n.mul(a,zt),i),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),o))throw new Error("Cannot find square root");return u}}return r%_f,Vf(r)}var xa=(r,e)=>(j(r,e)&X)===X,Df=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function us(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=Df.reduce((n,o)=>(n[o]="function",n),e);return Je(r,t)}function Mf(r,e,t){if(t<ie)throw new Error("Expected power > 0");if(t===ie)return r.ONE;if(t===X)return e;let n=r.ONE,o=e;for(;t>ie;)t&X&&(n=r.mul(n,o)),o=r.sqr(o),t>>=X;return n}function Hf(r,e){let t=new Array(e.length),n=e.reduce((s,i,a)=>r.is0(i)?s:(t[a]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return e.reduceRight((s,i,a)=>r.is0(i)?s:(t[a]=r.mul(s,t[a]),r.mul(s,i)),o),t}function fs(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Ct(r,e,t=!1,n={}){if(r<=ie)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:o,nByteLength:s}=fs(r,e);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=Pf(r),a=Object.freeze({ORDER:r,BITS:o,BYTES:s,MASK:Cr(o),ZERO:ie,ONE:X,create:c=>j(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return ie<=c&&c<r},is0:c=>c===ie,isOdd:c=>(c&X)===X,neg:c=>j(-c,r),eql:(c,u)=>c===u,sqr:c=>j(c*c,r),add:(c,u)=>j(c+u,r),sub:(c,u)=>j(c-u,r),mul:(c,u)=>j(c*u,r),pow:(c,u)=>Mf(a,c,u),div:(c,u)=>j(c*dn(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>dn(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>Hf(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>t?qt(c,s):Nt(c,s),fromBytes:c=>{if(c.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${c.length}`);return t?kt(c):ft(c)}});return Object.freeze(a)}function va(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 hs(r){let e=va(r);return e+Math.ceil(e/2)}function Ea(r,e,t=!1){let n=r.length,o=va(e),s=hs(e);if(n<16||n<s||n>1024)throw new Error(`expected ${s}-1024 bytes of input, got ${n}`);let i=t?ft(r):kt(r),a=j(i,e-X)+X;return t?qt(a,o):Nt(a,o)}var Kf=BigInt(0),ds=BigInt(1),ps=new WeakMap,Ba=new WeakMap;function pn(r,e){let t=(s,i)=>{let a=i.negate();return s?a:i},n=s=>{if(!Number.isSafeInteger(s)||s<=0||s>e)throw new Error(`Wrong window size=${s}, should be [1..${e}]`)},o=s=>{n(s);let i=Math.ceil(e/s)+1,a=2**(s-1);return{windows:i,windowSize:a}};return{constTimeNegate:t,unsafeLadder(s,i){let a=r.ZERO,c=s;for(;i>Kf;)i&ds&&(a=a.add(c)),c=c.double(),i>>=ds;return a},precomputeWindow(s,i){let{windows:a,windowSize:c}=o(i),u=[],l=s,f=l;for(let h=0;h<a;h++){f=l,u.push(f);for(let w=1;w<c;w++)f=f.add(l),u.push(f);l=f.double()}return u},wNAF(s,i,a){let{windows:c,windowSize:u}=o(s),l=r.ZERO,f=r.BASE,h=BigInt(2**s-1),w=2**s,m=BigInt(s);for(let y=0;y<c;y++){let d=y*u,x=Number(a&h);a>>=m,x>u&&(x-=w,a+=ds);let B=d,g=d+Math.abs(x)-1,S=y%2!==0,L=x<0;x===0?f=f.add(t(S,i[B])):l=l.add(t(L,i[g]))}return{p:l,f}},wNAFCached(s,i,a){let c=Ba.get(s)||1,u=ps.get(s);return u||(u=this.precomputeWindow(s,c),c!==1&&ps.set(s,a(u))),this.wNAF(c,u,i)},setWindowSize(s,i){n(i),Ba.set(s,i),ps.delete(s)}}}function gn(r,e,t,n){if(!Array.isArray(t)||!Array.isArray(n)||n.length!==t.length)throw new Error("arrays of points and scalars must have equal length");n.forEach((l,f)=>{if(!e.isValid(l))throw new Error(`wrong scalar at index ${f}`)}),t.forEach((l,f)=>{if(!(l instanceof r))throw new Error(`wrong point at index ${f}`)});let o=as(BigInt(t.length)),s=o>12?o-3:o>4?o-2:o?2:1,i=(1<<s)-1,a=new Array(i+1).fill(r.ZERO),c=Math.floor((e.BITS-1)/s)*s,u=r.ZERO;for(let l=c;l>=0;l-=s){a.fill(r.ZERO);for(let h=0;h<n.length;h++){let w=n[h],m=Number(w>>BigInt(l)&BigInt(i));a[m]=a[m].add(t[h])}let f=r.ZERO;for(let h=a.length-1,w=r.ZERO;h>0;h--)w=w.add(a[h]),f=f.add(w);if(u=u.add(f),l!==0)for(let h=0;h<s;h++)u=u.double()}return u}function Tr(r){return us(r.Fp),Je(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...fs(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ke=BigInt(0),Ce=BigInt(1),mn=BigInt(2),qf=BigInt(8),$f={zip215:!0};function zf(r){let e=Tr(r);return Je(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Aa(r){let e=zf(r),{Fp:t,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=e,u=mn<<BigInt(a*8)-Ce,l=t.create,f=Ct(e.n,e.nBitLength),h=e.uvRatio||((b,p)=>{try{return{isValid:!0,value:t.sqrt(b*t.inv(p))}}catch{return{isValid:!1,value:Ke}}}),w=e.adjustScalarBytes||(b=>b),m=e.domain||((b,p,v)=>{if(Fe("phflag",v),p.length||v)throw new Error("Contexts/pre-hash are not supported");return b});function y(b,p){Ne("coordinate "+b,p,Ke,u)}function d(b){if(!(b instanceof g))throw new Error("ExtendedPoint expected")}let x=$t((b,p)=>{let{ex:v,ey:C,ez:R}=b,_=b.is0();p==null&&(p=_?qf:t.inv(R));let P=l(v*p),H=l(C*p),D=l(R*p);if(_)return{x:Ke,y:Ce};if(D!==Ce)throw new Error("invZ was invalid");return{x:P,y:H}}),B=$t(b=>{let{a:p,d:v}=e;if(b.is0())throw new Error("bad point: ZERO");let{ex:C,ey:R,ez:_,et:P}=b,H=l(C*C),D=l(R*R),W=l(_*_),Y=l(W*W),le=l(H*p),ue=l(W*l(le+D)),he=l(Y+l(v*l(H*D)));if(ue!==he)throw new Error("bad point: equation left != right (1)");let Be=l(C*R),se=l(_*P);if(Be!==se)throw new Error("bad point: equation left != right (2)");return!0});class g{constructor(p,v,C,R){this.ex=p,this.ey=v,this.ez=C,this.et=R,y("x",p),y("y",v),y("z",C),y("t",R),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof g)throw new Error("extended point not allowed");let{x:v,y:C}=p||{};return y("x",v),y("y",C),new g(v,C,Ce,l(v*C))}static normalizeZ(p){let v=t.invertBatch(p.map(C=>C.ez));return p.map((C,R)=>C.toAffine(v[R])).map(g.fromAffine)}static msm(p,v){return gn(g,f,p,v)}_setWindowSize(p){U.setWindowSize(this,p)}assertValidity(){B(this)}equals(p){d(p);let{ex:v,ey:C,ez:R}=this,{ex:_,ey:P,ez:H}=p,D=l(v*H),W=l(_*R),Y=l(C*H),le=l(P*R);return D===W&&Y===le}is0(){return this.equals(g.ZERO)}negate(){return new g(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:p}=e,{ex:v,ey:C,ez:R}=this,_=l(v*v),P=l(C*C),H=l(mn*l(R*R)),D=l(p*_),W=v+C,Y=l(l(W*W)-_-P),le=D+P,ue=le-H,he=D-P,Be=l(Y*ue),se=l(le*he),ke=l(Y*he),st=l(ue*le);return new g(Be,se,st,ke)}add(p){d(p);let{a:v,d:C}=e,{ex:R,ey:_,ez:P,et:H}=this,{ex:D,ey:W,ez:Y,et:le}=p;if(v===BigInt(-1)){let Pi=l((_-R)*(W+D)),Di=l((_+R)*(W-D)),Ko=l(Di-Pi);if(Ko===Ke)return this.double();let Mi=l(P*mn*le),Hi=l(H*mn*Y),Fi=Hi+Mi,Ki=Di+Pi,qi=Hi-Mi,eu=l(Fi*Ko),tu=l(Ki*qi),ru=l(Fi*qi),nu=l(Ko*Ki);return new g(eu,tu,nu,ru)}let ue=l(R*D),he=l(_*W),Be=l(H*C*le),se=l(P*Y),ke=l((R+_)*(D+W)-ue-he),st=se-Be,xr=se+Be,vr=l(he-v*ue),Yl=l(ke*st),Jl=l(xr*vr),Xl=l(ke*vr),Ql=l(st*xr);return new g(Yl,Jl,Ql,Xl)}subtract(p){return this.add(p.negate())}wNAF(p){return U.wNAFCached(this,p,g.normalizeZ)}multiply(p){let v=p;Ne("scalar",v,Ce,n);let{p:C,f:R}=this.wNAF(v);return g.normalizeZ([C,R])[0]}multiplyUnsafe(p){let v=p;return Ne("scalar",v,Ke,n),v===Ke?L:this.equals(L)||v===Ce?this:this.equals(S)?this.wNAF(v).p:U.unsafeLadder(this,v)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return U.unsafeLadder(this,n).is0()}toAffine(p){return x(this,p)}clearCofactor(){let{h:p}=e;return p===Ce?this:this.multiplyUnsafe(p)}static fromHex(p,v=!1){let{d:C,a:R}=e,_=t.BYTES;p=te("pointHex",p,_),Fe("zip215",v);let P=p.slice(),H=p[_-1];P[_-1]=H&-129;let D=kt(P),W=v?u:t.ORDER;Ne("pointHex.y",D,Ke,W);let Y=l(D*D),le=l(Y-Ce),ue=l(C*Y-R),{isValid:he,value:Be}=h(le,ue);if(!he)throw new Error("Point.fromHex: invalid y coordinate");let se=(Be&Ce)===Ce,ke=(H&128)!==0;if(!v&&Be===Ke&&ke)throw new Error("Point.fromHex: x=0 and x_0=1");return ke!==se&&(Be=l(-Be)),g.fromAffine({x:Be,y:D})}static fromPrivateKey(p){return T(p).point}toRawBytes(){let{x:p,y:v}=this.toAffine(),C=qt(v,t.BYTES);return C[C.length-1]|=p&Ce?128:0,C}toHex(){return ut(this.toRawBytes())}}g.BASE=new g(e.Gx,e.Gy,Ce,l(e.Gx*e.Gy)),g.ZERO=new g(Ke,Ce,Ce,Ke);let{BASE:S,ZERO:L}=g,U=pn(g,a*8);function I(b){return j(b,n)}function k(b){return I(kt(b))}function T(b){let p=a;b=te("private key",b,p);let v=te("hashed private key",s(b),2*p),C=w(v.slice(0,p)),R=v.slice(p,2*p),_=k(C),P=S.multiply(_),H=P.toRawBytes();return{head:C,prefix:R,scalar:_,point:P,pointBytes:H}}function ne(b){return T(b).pointBytes}function K(b=new Uint8Array,...p){let v=ht(...p);return k(s(m(v,te("context",b),!!o)))}function V(b,p,v={}){b=te("message",b),o&&(b=o(b));let{prefix:C,scalar:R,pointBytes:_}=T(p),P=K(v.context,C,b),H=S.multiply(P).toRawBytes(),D=K(v.context,H,_,b),W=I(P+D*R);Ne("signature.s",W,Ke,n);let Y=ht(H,qt(W,t.BYTES));return te("result",Y,a*2)}let oe=$f;function E(b,p,v,C=oe){let{context:R,zip215:_}=C,P=t.BYTES;b=te("signature",b,2*P),p=te("message",p),_!==void 0&&Fe("zip215",_),o&&(p=o(p));let H=kt(b.slice(P,2*P)),D,W,Y;try{D=g.fromHex(v,_),W=g.fromHex(b.slice(0,P),_),Y=S.multiplyUnsafe(H)}catch{return!1}if(!_&&D.isSmallOrder())return!1;let le=K(R,W.toRawBytes(),D.toRawBytes(),p);return W.add(D.multiplyUnsafe(le)).subtract(Y).clearCofactor().equals(g.ZERO)}return S._setWindowSize(8),{CURVE:e,getPublicKey:ne,sign:V,verify:E,ExtendedPoint:g,utils:{getExtendedPublicKey:T,randomPrivateKey:()=>i(t.BYTES),precompute(b=8,p=g.BASE){return p._setWindowSize(b),p.multiply(BigInt(3)),p}}}}var gs=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Sa=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),l0=BigInt(0),Gf=BigInt(1),Ia=BigInt(2),u0=BigInt(3),Wf=BigInt(5),jf=BigInt(8);function Zf(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),s=gs,a=r*r%s*r%s,c=Q(a,Ia,s)*a%s,u=Q(c,Gf,s)*r%s,l=Q(u,Wf,s)*u%s,f=Q(l,e,s)*l%s,h=Q(f,t,s)*f%s,w=Q(h,n,s)*h%s,m=Q(w,o,s)*w%s,y=Q(m,o,s)*w%s,d=Q(y,e,s)*l%s;return{pow_p_5_8:Q(d,Ia,s)*r%s,b2:a}}function Yf(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Jf(r,e){let t=gs,n=j(e*e*e,t),o=j(n*n*e,t),s=Zf(r*o).pow_p_5_8,i=j(r*n*s,t),a=j(e*i*i,t),c=i,u=j(i*Sa,t),l=a===r,f=a===j(-r,t),h=a===j(-r*Sa,t);return l&&(i=c),(f||h)&&(i=u),xa(i,t)&&(i=j(-i,t)),{isValid:l||f,value:i}}var Xf=Ct(gs,void 0,!0),Qf={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Xf,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:jf,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ga,randomBytes:ln,adjustScalarBytes:Yf,uvRatio:Jf},ka=Aa(Qf);var yn=32;function Na(r,e,t){return ka.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}var bn=class{type="Ed25519";raw;constructor(e){this.raw=ms(e,yn)}toMultihash(){return ct.digest(Tt(this))}toCID(){return de.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:be(this.raw,e.raw)}verify(e,t){return Na(this.raw,t,e)}};function ys(r){return r=ms(r,yn),new bn(r)}function ms(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new Se(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}function pe(r=0){return new Uint8Array(r)}function Te(r=0){return new Uint8Array(r)}var th=Math.pow(2,7),rh=Math.pow(2,14),nh=Math.pow(2,21),bs=Math.pow(2,28),ws=Math.pow(2,35),xs=Math.pow(2,42),vs=Math.pow(2,49),G=128,we=127;function xe(r){if(r<th)return 1;if(r<rh)return 2;if(r<nh)return 3;if(r<bs)return 4;if(r<ws)return 5;if(r<xs)return 6;if(r<vs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Es(r,e,t=0){switch(xe(r)){case 8:e[t++]=r&255|G,r/=128;case 7:e[t++]=r&255|G,r/=128;case 6:e[t++]=r&255|G,r/=128;case 5:e[t++]=r&255|G,r/=128;case 4:e[t++]=r&255|G,r>>>=7;case 3:e[t++]=r&255|G,r>>>=7;case 2:e[t++]=r&255|G,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function oh(r,e,t=0){switch(xe(r)){case 8:e.set(t++,r&255|G),r/=128;case 7:e.set(t++,r&255|G),r/=128;case 6:e.set(t++,r&255|G),r/=128;case 5:e.set(t++,r&255|G),r/=128;case 4:e.set(t++,r&255|G),r>>>=7;case 3:e.set(t++,r&255|G),r>>>=7;case 2:e.set(t++,r&255|G),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Bs(r,e){let t=r[e],n=0;if(n+=t&we,t<G||(t=r[e+1],n+=(t&we)<<7,t<G)||(t=r[e+2],n+=(t&we)<<14,t<G)||(t=r[e+3],n+=(t&we)<<21,t<G)||(t=r[e+4],n+=(t&we)*bs,t<G)||(t=r[e+5],n+=(t&we)*ws,t<G)||(t=r[e+6],n+=(t&we)*xs,t<G)||(t=r[e+7],n+=(t&we)*vs,t<G))return n;throw new RangeError("Could not decode varint")}function sh(r,e){let t=r.get(e),n=0;if(n+=t&we,t<G||(t=r.get(e+1),n+=(t&we)<<7,t<G)||(t=r.get(e+2),n+=(t&we)<<14,t<G)||(t=r.get(e+3),n+=(t&we)<<21,t<G)||(t=r.get(e+4),n+=(t&we)*bs,t<G)||(t=r.get(e+5),n+=(t&we)*ws,t<G)||(t=r.get(e+6),n+=(t&we)*xs,t<G)||(t=r.get(e+7),n+=(t&we)*vs,t<G))return n;throw new RangeError("Could not decode varint")}function Oe(r,e,t=0){return e==null&&(e=Te(xe(r))),e instanceof Uint8Array?Es(r,e,t):oh(r,e,t)}function dt(r,e=0){return r instanceof Uint8Array?Bs(r,e):sh(r,e)}var As=new Float32Array([-0]),Ut=new Uint8Array(As.buffer);function Ta(r,e,t){As[0]=r,e[t]=Ut[0],e[t+1]=Ut[1],e[t+2]=Ut[2],e[t+3]=Ut[3]}function Ua(r,e){return Ut[0]=r[e],Ut[1]=r[e+1],Ut[2]=r[e+2],Ut[3]=r[e+3],As[0]}var Ss=new Float64Array([-0]),ve=new Uint8Array(Ss.buffer);function La(r,e,t){Ss[0]=r,e[t]=ve[0],e[t+1]=ve[1],e[t+2]=ve[2],e[t+3]=ve[3],e[t+4]=ve[4],e[t+5]=ve[5],e[t+6]=ve[6],e[t+7]=ve[7]}function Ra(r,e){return ve[0]=r[e],ve[1]=r[e+1],ve[2]=r[e+2],ve[3]=r[e+3],ve[4]=r[e+4],ve[5]=r[e+5],ve[6]=r[e+6],ve[7]=r[e+7],Ss[0]}var ih=BigInt(Number.MAX_SAFE_INTEGER),ah=BigInt(Number.MIN_SAFE_INTEGER),Re=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 Gt;if(e<ih&&e>ah)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>_a&&(o=0n,++n>_a&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return Gt;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):Gt}},Gt=new Re(0,0);Gt.toBigInt=function(){return 0n};Gt.zzEncode=Gt.zzDecode=function(){return this};Gt.length=function(){return 1};var _a=4294967296n;function Oa(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 Va(r,e,t){if(t-e<1)return"";let o,s=[],i=0,a;for(;e<t;)a=r[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(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,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Is(r,e,t){let n=t,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,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 qe(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function xn(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var ks=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,qe(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 qe(this,4);return xn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw qe(this,4);return xn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw qe(this,4);let e=Ua(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw qe(this,4);let e=Ra(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 qe(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Va(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw qe(this,e);this.pos+=e}else do if(this.pos>=this.len)throw qe(this);while(this.buf[this.pos++]&128);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 Re(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 qe(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 qe(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 qe(this,8);let e=xn(this.buf,this.pos+=4),t=xn(this.buf,this.pos+=4);return new Re(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=Bs(this.buf,this.pos);return this.pos+=xe(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 Ns(r){return new ks(r instanceof Uint8Array?r:r.subarray())}function $e(r,e,t){let n=Ns(r);return e.decode(n,void 0,t)}var Cs={};Ae(Cs,{base10:()=>ch});var ch=Et({prefix:"9",name:"base10",alphabet:"0123456789"});var Ts={};Ae(Ts,{base16:()=>lh,base16upper:()=>uh});var lh=ee({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),uh=ee({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Us={};Ae(Us,{base2:()=>fh});var fh=ee({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ls={};Ae(Ls,{base256emoji:()=>mh});var Da=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}"),hh=Da.reduce((r,e,t)=>(r[t]=e,r),[]),dh=Da.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function ph(r){return r.reduce((e,t)=>(e+=hh[t],e),"")}function gh(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=dh[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var mh=Xt({prefix:"\u{1F680}",name:"base256emoji",encode:ph,decode:gh});var _s={};Ae(_s,{base64:()=>yh,base64pad:()=>bh,base64url:()=>Rs,base64urlpad:()=>wh});var yh=ee({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),bh=ee({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Rs=ee({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),wh=ee({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Os={};Ae(Os,{base8:()=>xh});var xh=ee({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Vs={};Ae(Vs,{identity:()=>vh});var vh=Xt({prefix:"\0",name:"identity",encode:r=>Zi(r),decode:r=>ji(r)});var G0=new TextEncoder,W0=new TextDecoder;var Ms={};Ae(Ms,{sha256:()=>Ur,sha512:()=>Ah});function Ds({name:r,code:e,encode:t}){return new Ps(r,e,t)}var Ps=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?Me(this.code,t):t.then(n=>Me(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ha(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Ur=Ds({name:"sha2-256",code:18,encode:Ha("SHA-256")}),Ah=Ds({name:"sha2-512",code:19,encode:Ha("SHA-512")});var Lr={...Vs,...Us,...Os,...Cs,...Ts,...Zo,...Yo,...jo,..._s,...Ls},sg={...Ms,...Qo};function Ka(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Fa=Ka("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Hs=Ka("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=Te(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Sh={utf8:Fa,"utf-8":Fa,hex:Lr.base16,latin1:Hs,ascii:Hs,binary:Hs,...Lr},vn=Sh;function q(r,e="utf8"){let t=vn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function Fs(r){let e=r??8192,t=e>>>1,n,o=e;return function(i){if(i<1||i>t)return Te(i);o+i>e&&(n=Te(e),o=0);let a=n.subarray(o,o+=i);return o&7&&(o=(o|7)+1),a}}var Wt=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Ks(){}var $s=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Ih=Fs();function kh(r){return globalThis.Buffer!=null?Te(r):Ih(r)}var _r=class{len;head;tail;states;constructor(){this.len=0,this.head=new Wt(Ks,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Wt(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new zs((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(En,10,Re.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Re.fromBigInt(e);return this._push(En,t.length(),t)}uint64Number(e){return this._push(Es,xe(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=Re.fromBigInt(e).zzEncode();return this._push(En,t.length(),t)}sint64Number(e){let t=Re.fromNumber(e).zzEncode();return this._push(En,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(qs,1,e?1:0)}fixed32(e){return this._push(Rr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Re.fromBigInt(e);return this._push(Rr,4,t.lo)._push(Rr,4,t.hi)}fixed64Number(e){let t=Re.fromNumber(e);return this._push(Rr,4,t.lo)._push(Rr,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(Ta,4,e)}double(e){return this._push(La,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(qs,1,0):this.uint32(t)._push(Ch,t,e)}string(e){let t=Oa(e);return t!==0?this.uint32(t)._push(Is,t,e):this._push(qs,1,0)}fork(){return this.states=new $s(this),this.head=this.tail=new Wt(Ks,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 Wt(Ks,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=kh(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function qs(r,e,t){e[t]=r&255}function Nh(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var zs=class extends Wt{next;constructor(e,t){super(Nh,e,t),this.next=void 0}};function En(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 Rr(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 Ch(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(_r.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(Th,e,r),this},_r.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(Uh,e,r),this});function Th(r,e,t){e.set(r,t)}function Uh(r,e,t){r.length<40?Is(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(q(r),t)}function Gs(){return new _r}function ze(r,e){let t=Gs();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var ar;(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"})(ar||(ar={}));function Bn(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Ws(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(s,i){let a=e(s);i.int32(a)},n=function(s){let i=s.int32();return e(i)};return Bn("enum",ar.VARINT,t,n)}function Ge(r,e){return Bn("message",ar.LENGTH_DELIMITED,r,e)}var jt=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var ae;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(ae||(ae={}));var js;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(js||(js={}));(function(r){r.codec=()=>Ws(js)})(ae||(ae={}));var Xe;(function(r){let e;r.codec=()=>(e==null&&(e=Ge((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),ae.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let s={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let a=t.uint32();switch(a>>>3){case 1:{s.Type=ae.codec().decode(t);break}case 2:{s.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return s})),e),r.encode=t=>ze(t,r.codec()),r.decode=(t,n)=>$e(t,r.codec(),n)})(Xe||(Xe={}));var Zs;(function(r){let e;r.codec=()=>(e==null&&(e=Ge((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),ae.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let s={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let a=t.uint32();switch(a>>>3){case 1:{s.Type=ae.codec().decode(t);break}case 2:{s.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return s})),e),r.encode=t=>ze(t,r.codec()),r.decode=(t,n)=>$e(t,r.codec(),n)})(Zs||(Zs={}));var $r={};Ae($r,{MAX_RSA_KEY_SIZE:()=>go,generateRSAKeyPair:()=>Mc,jwkToJWKKeyPair:()=>Hc,jwkToPkcs1:()=>Wh,jwkToPkix:()=>oi,jwkToRSAPrivateKey:()=>Dc,pkcs1ToJwk:()=>Oc,pkcs1ToRSAPrivateKey:()=>Pc,pkixToJwk:()=>Vc,pkixToRSAPublicKey:()=>si});var Lh=new Uint32Array([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]),Lt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Rt=new Uint32Array(64),Ys=class extends sr{constructor(){super(64,32,8,!1),this.A=Lt[0]|0,this.B=Lt[1]|0,this.C=Lt[2]|0,this.D=Lt[3]|0,this.E=Lt[4]|0,this.F=Lt[5]|0,this.G=Lt[6]|0,this.H=Lt[7]|0}get(){let{A:e,B:t,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,t,n,o,s,i,a,c]}set(e,t,n,o,s,i,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(e,t){for(let f=0;f<16;f++,t+=4)Rt[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let h=Rt[f-15],w=Rt[f-2],m=He(h,7)^He(h,18)^h>>>3,y=He(w,17)^He(w,19)^w>>>10;Rt[f]=y+Rt[f-7]+m+Rt[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let h=He(a,6)^He(a,11)^He(a,25),w=l+h+ha(a,c,u)+Lh[f]+Rt[f]|0,y=(He(n,2)^He(n,13)^He(n,22))+da(n,o,s)|0;l=u,u=c,c=a,a=i+w|0,i=s,s=o,o=n,n=w+y|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,c,u,l)}roundClean(){Rt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var cr=cn(()=>new Ys);var M=Gi($a());function Zt(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 _t(r,e,t=-1){let n=t,o=r,s=0,i=Math.pow(2,e);for(let a=1;a<8;a++){if(r<i){let c;if(n<0)c=new ArrayBuffer(a),s=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),s=n}let u=new Uint8Array(c);for(let l=a-1;l>=0;l--){let f=Math.pow(2,l*e);u[s-l-1]=Math.floor(o/f),o-=u[s-l-1]*f}return c}i*=Math.pow(2,e)}return new ArrayBuffer(0)}function In(...r){let e=0,t=0;for(let s of r)e+=s.length;let n=new ArrayBuffer(e),o=new Uint8Array(n);for(let s of r)o.set(s,t),t+=s.length;return o}function Xs(){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=Zt(t,8),o=new ArrayBuffer(this.valueHex.byteLength),s=new Uint8Array(o);for(let a=0;a<this.valueHex.byteLength;a++)s[a]=r[a];return s[0]&=127,Zt(s,8)-n}function za(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let i=t-e,a=_t(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=_t(e,8,n),s=new Uint8Array(o);if(s[0]&128){let i=o.slice(0),a=new Uint8Array(i);o=new ArrayBuffer(o.byteLength+1),s=new Uint8Array(o);for(let c=0;c<i.byteLength;c++)s[c+1]=a[c];s[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function Ga(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 Ue(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,o=new Array(n);for(let i=0;i<n;i++)o[i]="0";return o.join("").concat(t)}var Hg=Math.log(2);function kn(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Qs(r){let e=0,t=0;for(let o=0;o<r.length;o++){let s=r[o];e+=s.byteLength}let n=new Uint8Array(e);for(let o=0;o<r.length;o++){let s=r[o];n.set(new Uint8Array(s),t),t+=s.byteLength}return n.buffer}function bt(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 Vr=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Qs(this.items)}},Or=[new Uint8Array([1])],Wa="0123456789";var dr="",We=new ArrayBuffer(0),ei=new Uint8Array(0),Pr="EndOfContent",Za="OCTET STRING",Ya="BIT STRING";function wt(r){var e;return e=class extends r{constructor(...n){var o;super(...n);let s=n[0]||{};this.isHexOnly=(o=s.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=s.valueHex?M.BufferSourceConverter.toUint8Array(s.valueHex):ei}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,o,s){let i=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!bt(this,i,o,s))return-1;let a=o+s;return this.valueHexView=i.subarray(o,a),this.valueHexView.length?(this.blockLength=s,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",We)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:M.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var gt=class{constructor({blockLength:e=0,error:t=dr,warnings:n=[],valueBeforeDecode:o=ei}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=M.BufferSourceConverter.toUint8Array(o)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:M.Convert.ToHex(this.valueBeforeDecodeView)}}};gt.NAME="baseBlock";var Ee=class extends gt{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'")}};Ee.NAME="valueBlock";var Nn=class extends wt(gt){constructor({idBlock:e={}}={}){var t,n,o,s;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?M.BufferSourceConverter.toUint8Array(e.valueHex):ei,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(s=e.isConstructed)!==null&&s!==void 0?s:!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",We}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let o=new Uint8Array(1);if(!e){let s=this.tagNumber;s&=31,t|=s,o[0]=t}return o.buffer}if(!this.isHexOnly){let o=_t(this.tagNumber,7),s=new Uint8Array(o),i=o.byteLength,a=new Uint8Array(i+1);if(a[0]=t|31,!e){for(let c=0;c<i-1;c++)a[c+1]=s[c]|128;a[i]=s[i-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let s=0;s<o.length-1;s++)n[s+1]=o[s]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=M.BufferSourceConverter.toUint8Array(e);if(!bt(this,o,t,n))return-1;let s=o.subarray(t,t+n);if(s.length===0)return this.error="Zero buffer length",-1;switch(s[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=(s[0]&32)===32,this.isHexOnly=!1;let a=s[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,u=this.valueHexView=new Uint8Array(255),l=255;for(;s[c]&128;){if(u[c-1]=s[c]&127,c++,c>=s.length)return this.error="End of input reached before message was fully decoded",-1;if(c===l){l+=255;let h=new Uint8Array(l);for(let w=0;w<u.length;w++)h[w]=u[w];u=this.valueHexView=new Uint8Array(l)}}this.blockLength=c+1,u[c-1]=s[c]&127;let f=new Uint8Array(c);for(let h=0;h<c;h++)f[h]=u[h];u=this.valueHexView=new Uint8Array(c),u.set(f),this.blockLength<=9?this.tagNumber=Zt(u,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};Nn.NAME="identificationBlock";var Cn=class extends gt{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=M.BufferSourceConverter.toUint8Array(e);if(!bt(this,o,t,n))return-1;let s=o.subarray(t,t+n);if(s.length===0)return this.error="Zero buffer length",-1;if(s[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=s[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(s[0]&128),this.longFormUsed===!1)return this.length=s[0],this.blockLength=1,t+this.blockLength;let i=s[0]&127;if(i>8)return this.error="Too big integer",-1;if(i+1>s.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=o.subarray(a,a+i);return c[i-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Zt(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=i+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=_t(this.length,8);if(o.byteLength>127)return this.error="Too big length",We;if(t=new ArrayBuffer(o.byteLength+1),e)return t;let s=new Uint8Array(o);n=new Uint8Array(t),n[0]=o.byteLength|128;for(let i=0;i<o.byteLength;i++)n[i+1]=s[i];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}}};Cn.NAME="lengthBlock";var A={},ge=class extends gt{constructor({name:e=dr,optional:t=!1,primitiveSchema:n,...o}={},s){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new Nn(o),this.lenBlock=new Cn(o),this.valueBlock=s?new s(o):new Ee(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 Vr;t||Ja(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 s=this.valueBlock.toBER(e);this.lenBlock.length=s.byteLength;let i=this.lenBlock.toBER(e);n.write(i),n.write(s)}return t?We: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():M.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${M.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return Ga(t,n)}};ge.NAME="BaseBlock";function Ja(r){if(r instanceof A.Constructed)for(let e of r.valueBlock.value)Ja(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Tn=class extends ge{constructor({value:e=dr,...t}={},n){super(t,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=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}'`}};Tn.NAME="BaseStringBlock";var Un=class extends wt(Ee){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Un.NAME="PrimitiveValueBlock";var Xa,Ln=class extends ge{constructor(e={}){super(e,Un),this.idBlock.isConstructed=!1}};Xa=Ln;A.Primitive=Xa;Ln.NAME="PRIMITIVE";function Fh(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 ho(r,e=0,t=r.length){let n=e,o=new ge({},Ee),s=new gt;if(!bt(s,r,e,t))return o.error=s.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=ge;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=A.EndOfContent;break;case 1:c=A.Boolean;break;case 2:c=A.Integer;break;case 3:c=A.BitString;break;case 4:c=A.OctetString;break;case 5:c=A.Null;break;case 6:c=A.ObjectIdentifier;break;case 10:c=A.Enumerated;break;case 12:c=A.Utf8String;break;case 13:c=A.RelativeObjectIdentifier;break;case 14:c=A.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=A.Sequence;break;case 17:c=A.Set;break;case 18:c=A.NumericString;break;case 19:c=A.PrintableString;break;case 20:c=A.TeletexString;break;case 21:c=A.VideotexString;break;case 22:c=A.IA5String;break;case 23:c=A.UTCTime;break;case 24:c=A.GeneralizedTime;break;case 25:c=A.GraphicString;break;case 26:c=A.VisibleString;break;case 27:c=A.GeneralString;break;case 28:c=A.UniversalString;break;case 29:c=A.CharacterString;break;case 30:c=A.BmpString;break;case 31:c=A.DATE;break;case 32:c=A.TimeOfDay;break;case 33:c=A.DateTime;break;case 34:c=A.Duration;break;default:{let u=o.idBlock.isConstructed?new A.Constructed:new A.Primitive;u.idBlock=o.idBlock,u.lenBlock=o.lenBlock,u.warnings=o.warnings,o=u}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?A.Constructed:A.Primitive}return o=Fh(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 ti(r){if(!r.byteLength){let e=new ge({},Ee);return e.error="Input buffer has zero length",{offset:-1,result:e}}return ho(M.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function Kh(r,e){return r?1:e}var Qe=class extends Ee{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=M.BufferSourceConverter.toUint8Array(e);if(!bt(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 s=t;for(;Kh(this.isIndefiniteForm,n)>0;){let i=ho(o,s,n);if(i.offset===-1)return this.error=i.result.error,this.warnings.concat(i.result.warnings),-1;if(s=i.offset,this.blockLength+=i.result.blockLength,n-=i.result.blockLength,this.value.push(i.result),this.isIndefiniteForm&&i.result.constructor.NAME===Pr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Pr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),s}toBER(e,t){let n=t||new Vr;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?We:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Qe.NAME="ConstructedValueBlock";var Qa,Ot=class extends ge{constructor(e={}){super(e,Qe),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
|
-
`).map(
|
|
4
|
-
`));let
|
|
5
|
-
${
|
|
6
|
-
`)}`:`${t} :`}};Qa=Ot;A.Constructed=Qa;Ot.NAME="CONSTRUCTED";var Rn=class extends Ee{fromBER(e,t,n){return t}toBER(e){return We}};Rn.override="EndOfContentValueBlock";var ec,_n=class extends ge{constructor(e={}){super(e,Rn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};ec=_n;A.EndOfContent=ec;_n.NAME=Pr;var tc,ur=class extends ge{constructor(e={}){super(e,Ee),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let o=new Uint8Array(n);o[0]=5,o[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};tc=ur;A.Null=tc;ur.NAME="NULL";var On=class extends wt(Ee){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=M.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,t,n){let o=M.BufferSourceConverter.toUint8Array(e);return bt(this,o,t,n)?(this.valueHexView=o.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Xs.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};On.NAME="BooleanValueBlock";var rc,Vn=class extends ge{constructor(e={}){super(e,On),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};rc=Vn;A.Boolean=rc;Vn.NAME="BOOLEAN";var Pn=class extends wt(Qe){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let o=0;if(this.isConstructed){if(this.isHexOnly=!1,o=Qe.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let s=0;s<this.value.length;s++){let i=this.value[s].constructor.NAME;if(i===Pr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==Za)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,o=super.fromBER(e,t,n),this.blockLength=n;return o}toBER(e,t){return this.isConstructed?Qe.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Pn.NAME="OctetStringValueBlock";var nc,Dn=class r extends ge{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,s;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((s=n.value)===null||s===void 0)&&s.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Pn),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){let s=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(s.byteLength){let i=ho(s,0,s.byteLength);i.offset!==-1&&i.offset===n&&(this.valueBlock.value=[i.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?Ot.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${M.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof r&&e.push(t.valueBlock.valueHexView);return M.BufferSourceConverter.concat(e)}};nc=Dn;A.OctetString=nc;Dn.NAME=Za;var Mn=class extends wt(Qe){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let o=-1;if(this.isConstructed){if(o=Qe.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===Pr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Ya)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let u=a.valueBlock;if(this.unusedBits>0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return o}let s=M.BufferSourceConverter.toUint8Array(e);if(!bt(this,s,t,n))return-1;let i=s.subarray(t,t+n);if(this.unusedBits=i[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=i.subarray(1);try{if(a.byteLength){let c=ho(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=i.subarray(1),this.blockLength=i.length,t+n}toBER(e,t){if(this.isConstructed)return Qe.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return We;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};Mn.NAME="BitStringValueBlock";var oc,fr=class extends ge{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,s;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((s=n.value)===null||s===void 0)&&s.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Mn),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Ot.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let o of t)e.push(o.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};oc=fr;A.BitString=oc;fr.NAME=Ya;var sc;function qh(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),o=new Uint8Array(e),s=n.slice(0),i=s.length-1,a=o.slice(0),c=a.length-1,u=0,l=c<i?i:c,f=0;for(let h=l;h>=0;h--,f++){switch(!0){case f<a.length:u=s[i-f]+a[c-f]+t[0];break;default:u=s[i-f]+t[0]}switch(t[0]=u/10,!0){case f>=s.length:s=In(new Uint8Array([u%10]),s);break;default:s[i-f]=u%10}}return t[0]>0&&(s=In(t,s)),s}function ja(r){if(r>=Or.length)for(let e=Or.length;e<=r;e++){let t=new Uint8Array([0]),n=Or[e-1].slice(0);for(let o=n.length-1;o>=0;o--){let s=new Uint8Array([(n[o]<<1)+t[0]]);t[0]=s[0]/10,n[o]=s[0]%10}t[0]>0&&(n=In(t,n)),Or.push(n)}return Or[r]}function $h(r,e){let t=0,n=new Uint8Array(r),o=new Uint8Array(e),s=n.slice(0),i=s.length-1,a=o.slice(0),c=a.length-1,u,l=0;for(let f=c;f>=0;f--,l++)switch(u=s[i-l]-a[c-l]-t,!0){case u<0:t=1,s[i-l]=u+10;break;default:t=0,s[i-l]=u}if(t>0)for(let f=i-c+1;f>=0;f--,l++)if(u=s[i-l]-t,u<0)t=1,s[i-l]=u+10;else{t=0,s[i-l]=u;break}return s.slice()}var Dr=class extends wt(Ee){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Xs.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(za(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,o=0){let s=this.fromBER(e,t,n);if(s===-1)return s;let i=this.valueHexView;return i[0]===0&&i[1]&128?this.valueHexView=i.subarray(1):o!==0&&i.length<o&&(o-i.length>1&&(o=i.length+1),this.valueHexView=i.subarray(o-i.length)),s}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let o=super.fromBER(e,t,n);return o===-1||this.setValueHex(),o}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,o,s=this.valueHexView,i="",a=!1;for(let c=s.byteLength-1;c>=0;c--){o=s[c];for(let u=0;u<8;u++){if((o&1)===1)switch(n){case e:t=$h(ja(n),t),i="-";break;default:t=qh(t,ja(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(i+=Wa.charAt(t[c]));return a===!1&&(i+=Wa.charAt(0)),i}};sc=Dr;Dr.NAME="IntegerValueBlock";Object.defineProperty(sc.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var ic,me=class r extends ge{constructor(e={}){super(e,Dr),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return kn(),BigInt(this.valueBlock.toString())}static fromBigInt(e){kn();let t=BigInt(e),n=new Vr,o=t.toString(16).replace(/^-/,""),s=new Uint8Array(M.Convert.FromHex(o));if(t<0){let a=new Uint8Array(s.length+(s[0]&128?1:0));a[0]|=128;let u=BigInt(`0x${M.Convert.ToHex(a)}`)+t,l=M.BufferSourceConverter.toUint8Array(M.Convert.FromHex(u.toString(16)));l[0]|=128,n.write(l)}else s[0]&128&&n.write(new Uint8Array([0])),n.write(s);return new r({valueHex:n.final()})}convertToDER(){let e=new r({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new r({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};ic=me;A.Integer=ic;me.NAME="INTEGER";var ac,Hn=class extends me{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};ac=Hn;A.Enumerated=ac;Hn.NAME="ENUMERATED";var Mr=class extends wt(Ee){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let o=M.BufferSourceConverter.toUint8Array(e);if(!bt(this,o,t,n))return-1;let s=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=s[a]&127,this.blockLength++,!!(s[a]&128));a++);let i=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)i[a]=this.valueHexView[a];return this.valueHexView=i,s[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Zt(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){kn();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let o=0;o<n.length;o++)n[o]=parseInt(t.slice(o*7,o*7+7),2)+(o+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,s=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)s[i]=o[i]|128;return s[this.blockLength-1]=o[this.blockLength-1],s.buffer}let t=_t(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",We;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),s=t.byteLength-1;for(let i=0;i<s;i++)n[i]=o[i]|128;n[s]=o[s]}return n}toString(){let e="";if(this.isHexOnly)e=M.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};Mr.NAME="sidBlock";var Fn=class extends Ee{constructor({value:e=dr,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let s=new Mr;if(o=s.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=s.error,o;this.value.length===0&&(s.isFirstSid=!0),this.blockLength+=s.blockLength,n-=s.blockLength,this.value.push(s)}return o}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let o=this.value[n].toBER(e);if(o.byteLength===0)return this.error=this.value[n].error,We;t.push(o)}return Qs(t)}fromString(e){this.value=[];let t=0,n=0,o="",s=!1;do if(n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1,s){let i=this.value[0],a=0;switch(i.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(o,10);if(isNaN(c))return;i.valueDec=c+a,s=!1}else{let i=new Mr;if(o>Number.MAX_SAFE_INTEGER){kn();let a=BigInt(o);i.valueBigInt=a}else if(i.valueDec=parseInt(o,10),isNaN(i.valueDec))return;this.value.length||(i.isFirstSid=!0,s=!0),this.value.push(i)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t?(o=`{${o}}`,this.value[n].isFirstSid?e=`2.{${o} - 80}`:e+=o):e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Fn.NAME="ObjectIdentifierValueBlock";var cc,hr=class extends ge{constructor(e={}){super(e,Fn),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};cc=hr;A.ObjectIdentifier=cc;hr.NAME="OBJECT IDENTIFIER";var Hr=class extends wt(gt){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=M.BufferSourceConverter.toUint8Array(e);if(!bt(this,o,t,n))return-1;let s=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=s[a]&127,this.blockLength++,!!(s[a]&128));a++);let i=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)i[a]=this.valueHexView[a];return this.valueHexView=i,s[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Zt(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,s=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)s[i]=o[i]|128;return s[this.blockLength-1]=o[this.blockLength-1],s.buffer}let t=_t(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",We;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),s=t.byteLength-1;for(let i=0;i<s;i++)n[i]=o[i]|128;n[s]=o[s]}return n.buffer}toString(){let e="";return this.isHexOnly?e=M.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Hr.NAME="relativeSidBlock";var Kn=class extends Ee{constructor({value:e=dr,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let s=new Hr;if(o=s.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=s.error,o;this.blockLength+=s.blockLength,n-=s.blockLength,this.value.push(s)}return o}toBER(e,t){let n=[];for(let o=0;o<this.value.length;o++){let s=this.value[o].toBER(e);if(s.byteLength===0)return this.error=this.value[o].error,We;n.push(s)}return Qs(n)}fromString(e){this.value=[];let t=0,n=0,o="";do{n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1;let s=new Hr;if(s.valueDec=parseInt(o,10),isNaN(s.valueDec))return!0;this.value.push(s)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(o=`{${o}}`),e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Kn.NAME="RelativeObjectIdentifierValueBlock";var lc,qn=class extends ge{constructor(e={}){super(e,Kn),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};lc=qn;A.RelativeObjectIdentifier=lc;qn.NAME="RelativeObjectIdentifier";var uc,mt=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};uc=mt;A.Sequence=uc;mt.NAME="SEQUENCE";var fc,$n=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};fc=$n;A.Set=fc;$n.NAME="SET";var zn=class extends wt(Ee){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=dr}toJSON(){return{...super.toJSON(),value:this.value}}};zn.NAME="StringValueBlock";var Gn=class extends zn{};Gn.NAME="SimpleStringValueBlock";var Ie=class extends Tn{constructor({...e}={}){super(e,Gn)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,M.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);this.valueBlock.value=e}};Ie.NAME="SIMPLE STRING";var Wn=class extends Ie{fromBuffer(e){this.valueBlock.valueHexView=M.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=M.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=M.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(M.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Wn.NAME="Utf8StringValueBlock";var hc,yt=class extends Wn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};hc=yt;A.Utf8String=hc;yt.NAME="UTF8String";var jn=class extends Ie{fromBuffer(e){this.valueBlock.value=M.Convert.ToUtf16String(e),this.valueBlock.valueHexView=M.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(M.Convert.FromUtf16String(e))}};jn.NAME="BmpStringValueBlock";var dc,Zn=class extends jn{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};dc=Zn;A.BmpString=dc;Zn.NAME="BMPString";var Yn=class extends Ie{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let o=0;o<n.length;o+=4)n[o]=n[o+3],n[o+1]=n[o+2],n[o+2]=0,n[o+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let o=0;o<t;o++){let s=_t(e.charCodeAt(o),8),i=new Uint8Array(s);if(i.length>4)continue;let a=4-i.length;for(let c=i.length-1;c>=0;c--)n[o*4+c+a]=i[c]}this.valueBlock.value=e}};Yn.NAME="UniversalStringValueBlock";var pc,Jn=class extends Yn{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};pc=Jn;A.UniversalString=pc;Jn.NAME="UniversalString";var gc,Xn=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};gc=Xn;A.NumericString=gc;Xn.NAME="NumericString";var mc,Qn=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};mc=Qn;A.PrintableString=mc;Qn.NAME="PrintableString";var yc,eo=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};yc=eo;A.TeletexString=yc;eo.NAME="TeletexString";var bc,to=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};bc=to;A.VideotexString=bc;to.NAME="VideotexString";var wc,ro=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};wc=ro;A.IA5String=wc;ro.NAME="IA5String";var xc,no=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};xc=no;A.GraphicString=xc;no.NAME="GraphicString";var vc,Fr=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};vc=Fr;A.VisibleString=vc;Fr.NAME="VisibleString";var Ec,oo=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Ec=oo;A.GeneralString=Ec;oo.NAME="GeneralString";var Bc,so=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Bc=so;A.CharacterString=Bc;so.NAME="CharacterString";var Ac,Kr=class extends Fr{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let o=0;o<e.length;o++)this.valueBlock.valueHexView[o]=e.charCodeAt(o)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,M.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let o=parseInt(n[1],10);o>=50?this.year=1900+o:this.year=2e3+o,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=Ue(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Ue(this.month,2),t[2]=Ue(this.day,2),t[3]=Ue(this.hour,2),t[4]=Ue(this.minute,2),t[5]=Ue(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Ac=Kr;A.UTCTime=Ac;Kr.NAME="UTCTime";var Sc,io=class extends Kr{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(e){let t=!1,n="",o="",s=0,i,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let f=new Number(e[e.length-1]);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let f=1,h=n.indexOf("+"),w="";if(h===-1&&(h=n.indexOf("-"),f=-1),h!==-1){if(w=n.substring(h+1),n=n.substring(0,h),w.length!==2&&w.length!==4)throw new Error("Wrong input string for conversion");let m=parseInt(w.substring(0,2),10);if(isNaN(m.valueOf()))throw new Error("Wrong input string for conversion");if(a=f*m,w.length===4){if(m=parseInt(w.substring(2,4),10),isNaN(m.valueOf()))throw new Error("Wrong input string for conversion");c=f*m}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let f=new Number(`0${n.substring(u)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");s=f.valueOf(),o=n.substring(0,u)}else o=n;switch(!0){case o.length===8:if(i=/(\d{4})(\d{2})(\d{2})/ig,u!==-1)throw new Error("Wrong input string for conversion");break;case o.length===10:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*s;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case o.length===12:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*s;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case o.length===14:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=1e3*s;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}let l=i.exec(o);if(l===null)throw new Error("Wrong input string for conversion");for(let f=1;f<l.length;f++)switch(f){case 1:this.year=parseInt(l[f],10);break;case 2:this.month=parseInt(l[f],10);break;case 3:this.day=parseInt(l[f],10);break;case 4:this.hour=parseInt(l[f],10)+a;break;case 5:this.minute=parseInt(l[f],10)+c;break;case 6:this.second=parseInt(l[f],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(Ue(this.year,4)),t.push(Ue(this.month,2)),t.push(Ue(this.day,2)),t.push(Ue(this.hour,2)),t.push(Ue(this.minute,2)),t.push(Ue(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Ue(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Sc=io;A.GeneralizedTime=Sc;io.NAME="GeneralizedTime";var Ic,ao=class extends yt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Ic=ao;A.DATE=Ic;ao.NAME="DATE";var kc,co=class extends yt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};kc=co;A.TimeOfDay=kc;co.NAME="TimeOfDay";var Nc,lo=class extends yt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Nc=lo;A.DateTime=Nc;lo.NAME="DateTime";var Cc,uo=class extends yt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Cc=uo;A.Duration=Cc;uo.NAME="Duration";var Tc,fo=class extends yt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Tc=fo;A.TIME=Tc;fo.NAME="TIME";function F(r,e="utf8"){let t=vn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var qr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},po=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Uc={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new po("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Vt=Uc;async function Lc(r){let e=await Vt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),t=await Gh(e);return{privateKey:t[0],publicKey:t[1]}}async function Rc(r,e){let t=await Vt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Vt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function _c(r,e,t){let n=await Vt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Vt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function Gh(r){if(r.privateKey==null||r.publicKey==null)throw new Se("Private and public key are required");return Promise.all([Vt.get().subtle.exportKey("jwk",r.privateKey),Vt.get().subtle.exportKey("jwk",r.publicKey)])}function ri(r){if(r.kty!=="RSA")throw new Se("invalid key type");if(r.n==null)throw new Se("invalid key modulus");return q(r.n,"base64url").length*8}var pr=class{type="RSA";_key;_raw;_multihash;constructor(e,t){this._key=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=$r.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return de.createV1(114,this._multihash)}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:be(this.raw,e.raw)}verify(e,t){return _c(this._key,t,e)}},zr=class{type="RSA";_key;_raw;publicKey;constructor(e,t){this._key=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=$r.jwkToPkcs1(this._key)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:be(this.raw,e.raw)}sign(e){return Rc(this._key,e)}};var go=8192,ni=18;function Oc(r){let{result:e}=ti(r),t=e.valueBlock.value;return{n:F(et(t[1].toBigInt()),"base64url"),e:F(et(t[2].toBigInt()),"base64url"),d:F(et(t[3].toBigInt()),"base64url"),p:F(et(t[4].toBigInt()),"base64url"),q:F(et(t[5].toBigInt()),"base64url"),dp:F(et(t[6].toBigInt()),"base64url"),dq:F(et(t[7].toBigInt()),"base64url"),qi:F(et(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function Wh(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new Se("JWK was missing components");let t=new mt({value:[new me({value:0}),me.fromBigInt(tt(q(r.n,"base64url"))),me.fromBigInt(tt(q(r.e,"base64url"))),me.fromBigInt(tt(q(r.d,"base64url"))),me.fromBigInt(tt(q(r.p,"base64url"))),me.fromBigInt(tt(q(r.q,"base64url"))),me.fromBigInt(tt(q(r.dp,"base64url"))),me.fromBigInt(tt(q(r.dq,"base64url"))),me.fromBigInt(tt(q(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function Vc(r){let{result:e}=ti(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:F(et(t[0].toBigInt()),"base64url"),e:F(et(t[1].toBigInt()),"base64url")}}function oi(r){if(r.n==null||r.e==null)throw new Se("JWK was missing components");let t=new mt({value:[new mt({value:[new hr({value:"1.2.840.113549.1.1.1"}),new ur]}),new fr({valueHex:new mt({value:[me.fromBigInt(tt(q(r.n,"base64url"))),me.fromBigInt(tt(q(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function et(r){let e=r.toString(16);e.length%2>0&&(e=`0${e}`);let t=e.length/2,n=new Uint8Array(t),o=0,s=0;for(;o<t;)n[o]=parseInt(e.slice(s,s+2),16),o+=1,s+=2;return n}function tt(r){let e=[];return r.forEach(function(t){let n=t.toString(16);n.length%2>0&&(n=`0${n}`),e.push(n)}),BigInt("0x"+e.join(""))}function Pc(r){let e=Oc(r);return Dc(e)}function si(r){let e=Vc(r);if(ri(e)>go)throw new Jt("Key size is too large");let t=cr(Xe.encode({Type:ae.RSA,Data:r})),n=Me(ni,t);return new pr(e,n)}function Dc(r){if(ri(r)>go)throw new Se("Key size is too large");let e=Hc(r),t=cr(Xe.encode({Type:ae.RSA,Data:oi(e.publicKey)})),n=Me(ni,t);return new zr(e.privateKey,new pr(e.publicKey,n))}async function Mc(r){if(r>go)throw new Se("Key size is too large");let e=await Lc(r),t=cr(Xe.encode({Type:ae.RSA,Data:oi(e.publicKey)})),n=Me(ni,t);return new zr(e.privateKey,new pr(e.publicKey,n))}function Hc(r){if(r==null)throw new Se("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}var mo=class extends or{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,la(e);let n=kr(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,s=new Uint8Array(o);s.set(n.length>o?e.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=e.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(e){return nr(this),this.iHash.update(e),this}digestInto(e){nr(this),rr(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:s,blockLen:i,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ii=(r,e,t)=>new mo(r,e).update(t).digest();ii.create=(r,e)=>new mo(r,e);function Fc(r){r.lowS!==void 0&&Fe("lowS",r.lowS),r.prehash!==void 0&&Fe("prehash",r.prehash)}function jh(r){let e=Tr(r);Je(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:o}=e;if(t){if(!n.eql(o,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:Zh,hexToBytes:Yh}=hn,xt={Err:class extends Error{constructor(e=""){super(e)}},_tlv:{encode:(r,e)=>{let{Err:t}=xt;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=Ft(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let s=n>127?Ft(o.length/2|128):"";return`${Ft(r)}${s}${o}${e}`},decode(r,e){let{Err:t}=xt,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++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new t("tlv.decode: length bytes not complete");if(u[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=c,i<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(r){let{Err:e}=xt;if(r<vt)throw new e("integer: negative integers are not allowed");let t=Ft(r);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected assertion");return t},decode(r){let{Err:e}=xt;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 Zh(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=xt,o=typeof r=="string"?Yh(r):r;ir(o);let{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("Invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l}=n.decode(2,c);if(l.length)throw new e("Invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(u)}},hexFromSig(r){let{_tlv:e,_int:t}=xt,n=`${e.encode(2,t.encode(r.r))}${e.encode(2,t.encode(r.s))}`;return e.encode(48,n)}},vt=BigInt(0),fe=BigInt(1),bm=BigInt(2),Kc=BigInt(3),wm=BigInt(4);function Jh(r){let e=jh(r),{Fp:t}=e,n=Ct(e.n,e.nBitLength),o=e.toBytes||((y,d,x)=>{let B=d.toAffine();return ht(Uint8Array.from([4]),t.toBytes(B.x),t.toBytes(B.y))}),s=e.fromBytes||(y=>{let d=y.subarray(1),x=t.fromBytes(d.subarray(0,t.BYTES)),B=t.fromBytes(d.subarray(t.BYTES,2*t.BYTES));return{x,y:B}});function i(y){let{a:d,b:x}=e,B=t.sqr(y),g=t.mul(B,y);return t.add(t.add(g,t.mul(y,d)),x)}if(!t.eql(t.sqr(e.Gy),i(e.Gx)))throw new Error("bad generator point: equation left != right");function a(y){return Nr(y,fe,e.n)}function c(y){let{allowedPrivateKeyLengths:d,nByteLength:x,wrapPrivateKey:B,n:g}=e;if(d&&typeof y!="bigint"){if(It(y)&&(y=ut(y)),typeof y!="string"||!d.includes(y.length))throw new Error("Invalid key");y=y.padStart(x*2,"0")}let S;try{S=typeof y=="bigint"?y:ft(te("private key",y,x))}catch{throw new Error(`private key must be ${x} bytes, hex or bigint, not ${typeof y}`)}return B&&(S=j(S,g)),Ne("private key",S,fe,g),S}function u(y){if(!(y instanceof h))throw new Error("ProjectivePoint expected")}let l=$t((y,d)=>{let{px:x,py:B,pz:g}=y;if(t.eql(g,t.ONE))return{x,y:B};let S=y.is0();d==null&&(d=S?t.ONE:t.inv(g));let L=t.mul(x,d),U=t.mul(B,d),I=t.mul(g,d);if(S)return{x:t.ZERO,y:t.ZERO};if(!t.eql(I,t.ONE))throw new Error("invZ was invalid");return{x:L,y:U}}),f=$t(y=>{if(y.is0()){if(e.allowInfinityPoint&&!t.is0(y.py))return;throw new Error("bad point: ZERO")}let{x:d,y:x}=y.toAffine();if(!t.isValid(d)||!t.isValid(x))throw new Error("bad point: x or y not FE");let B=t.sqr(x),g=i(d);if(!t.eql(B,g))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,x,B){if(this.px=d,this.py=x,this.pz=B,d==null||!t.isValid(d))throw new Error("x required");if(x==null||!t.isValid(x))throw new Error("y required");if(B==null||!t.isValid(B))throw new Error("z required");Object.freeze(this)}static fromAffine(d){let{x,y:B}=d||{};if(!d||!t.isValid(x)||!t.isValid(B))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let g=S=>t.eql(S,t.ZERO);return g(x)&&g(B)?h.ZERO:new h(x,B,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let x=t.invertBatch(d.map(B=>B.pz));return d.map((B,g)=>B.toAffine(x[g])).map(h.fromAffine)}static fromHex(d){let x=h.fromAffine(s(te("pointHex",d)));return x.assertValidity(),x}static fromPrivateKey(d){return h.BASE.multiply(c(d))}static msm(d,x){return gn(h,n,d,x)}_setWindowSize(d){m.setWindowSize(this,d)}assertValidity(){f(this)}hasEvenY(){let{y:d}=this.toAffine();if(t.isOdd)return!t.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){u(d);let{px:x,py:B,pz:g}=this,{px:S,py:L,pz:U}=d,I=t.eql(t.mul(x,U),t.mul(S,g)),k=t.eql(t.mul(B,U),t.mul(L,g));return I&&k}negate(){return new h(this.px,t.neg(this.py),this.pz)}double(){let{a:d,b:x}=e,B=t.mul(x,Kc),{px:g,py:S,pz:L}=this,U=t.ZERO,I=t.ZERO,k=t.ZERO,T=t.mul(g,g),ne=t.mul(S,S),K=t.mul(L,L),V=t.mul(g,S);return V=t.add(V,V),k=t.mul(g,L),k=t.add(k,k),U=t.mul(d,k),I=t.mul(B,K),I=t.add(U,I),U=t.sub(ne,I),I=t.add(ne,I),I=t.mul(U,I),U=t.mul(V,U),k=t.mul(B,k),K=t.mul(d,K),V=t.sub(T,K),V=t.mul(d,V),V=t.add(V,k),k=t.add(T,T),T=t.add(k,T),T=t.add(T,K),T=t.mul(T,V),I=t.add(I,T),K=t.mul(S,L),K=t.add(K,K),T=t.mul(K,V),U=t.sub(U,T),k=t.mul(K,ne),k=t.add(k,k),k=t.add(k,k),new h(U,I,k)}add(d){u(d);let{px:x,py:B,pz:g}=this,{px:S,py:L,pz:U}=d,I=t.ZERO,k=t.ZERO,T=t.ZERO,ne=e.a,K=t.mul(e.b,Kc),V=t.mul(x,S),oe=t.mul(B,L),E=t.mul(g,U),N=t.add(x,B),b=t.add(S,L);N=t.mul(N,b),b=t.add(V,oe),N=t.sub(N,b),b=t.add(x,g);let p=t.add(S,U);return b=t.mul(b,p),p=t.add(V,E),b=t.sub(b,p),p=t.add(B,g),I=t.add(L,U),p=t.mul(p,I),I=t.add(oe,E),p=t.sub(p,I),T=t.mul(ne,b),I=t.mul(K,E),T=t.add(I,T),I=t.sub(oe,T),T=t.add(oe,T),k=t.mul(I,T),oe=t.add(V,V),oe=t.add(oe,V),E=t.mul(ne,E),b=t.mul(K,b),oe=t.add(oe,E),E=t.sub(V,E),E=t.mul(ne,E),b=t.add(b,E),V=t.mul(oe,b),k=t.add(k,V),V=t.mul(p,b),I=t.mul(N,I),I=t.sub(I,V),V=t.mul(N,oe),T=t.mul(p,T),T=t.add(T,V),new h(I,k,T)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return m.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){Ne("scalar",d,vt,e.n);let x=h.ZERO;if(d===vt)return x;if(d===fe)return this;let{endo:B}=e;if(!B)return m.unsafeLadder(this,d);let{k1neg:g,k1:S,k2neg:L,k2:U}=B.splitScalar(d),I=x,k=x,T=this;for(;S>vt||U>vt;)S&fe&&(I=I.add(T)),U&fe&&(k=k.add(T)),T=T.double(),S>>=fe,U>>=fe;return g&&(I=I.negate()),L&&(k=k.negate()),k=new h(t.mul(k.px,B.beta),k.py,k.pz),I.add(k)}multiply(d){let{endo:x,n:B}=e;Ne("scalar",d,fe,B);let g,S;if(x){let{k1neg:L,k1:U,k2neg:I,k2:k}=x.splitScalar(d),{p:T,f:ne}=this.wNAF(U),{p:K,f:V}=this.wNAF(k);T=m.constTimeNegate(L,T),K=m.constTimeNegate(I,K),K=new h(t.mul(K.px,x.beta),K.py,K.pz),g=T.add(K),S=ne.add(V)}else{let{p:L,f:U}=this.wNAF(d);g=L,S=U}return h.normalizeZ([g,S])[0]}multiplyAndAddUnsafe(d,x,B){let g=h.BASE,S=(U,I)=>I===vt||I===fe||!U.equals(g)?U.multiplyUnsafe(I):U.multiply(I),L=S(this,x).add(S(d,B));return L.is0()?void 0:L}toAffine(d){return l(this,d)}isTorsionFree(){let{h:d,isTorsionFree:x}=e;if(d===fe)return!0;if(x)return x(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:x}=e;return d===fe?this:x?x(h,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return Fe("isCompressed",d),this.assertValidity(),o(h,this,d)}toHex(d=!0){return Fe("isCompressed",d),ut(this.toRawBytes(d))}}h.BASE=new h(e.Gx,e.Gy,t.ONE),h.ZERO=new h(t.ZERO,t.ONE,t.ZERO);let w=e.nBitLength,m=pn(h,e.endo?Math.ceil(w/2):w);return{CURVE:e,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function Xh(r){let e=Tr(r);return Je(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function qc(r){let e=Xh(r),{Fp:t,n}=e,o=t.BYTES+1,s=2*t.BYTES+1;function i(E){return j(E,n)}function a(E){return dn(E,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:f}=Jh({...e,toBytes(E,N,b){let p=N.toAffine(),v=t.toBytes(p.x),C=ht;return Fe("isCompressed",b),b?C(Uint8Array.from([N.hasEvenY()?2:3]),v):C(Uint8Array.from([4]),v,t.toBytes(p.y))},fromBytes(E){let N=E.length,b=E[0],p=E.subarray(1);if(N===o&&(b===2||b===3)){let v=ft(p);if(!Nr(v,fe,t.ORDER))throw new Error("Point is not on curve");let C=l(v),R;try{R=t.sqrt(C)}catch(H){let D=H instanceof Error?": "+H.message:"";throw new Error("Point is not on curve"+D)}let _=(R&fe)===fe;return(b&1)===1!==_&&(R=t.neg(R)),{x:v,y:R}}else if(N===s&&b===4){let v=t.fromBytes(p.subarray(0,t.BYTES)),C=t.fromBytes(p.subarray(t.BYTES,2*t.BYTES));return{x:v,y:C}}else throw new Error(`Point of length ${N} was invalid. Expected ${o} compressed bytes or ${s} uncompressed bytes`)}}),h=E=>ut(Nt(E,e.nByteLength));function w(E){let N=n>>fe;return E>N}function m(E){return w(E)?i(-E):E}let y=(E,N,b)=>ft(E.slice(N,b));class d{constructor(N,b,p){this.r=N,this.s=b,this.recovery=p,this.assertValidity()}static fromCompact(N){let b=e.nByteLength;return N=te("compactSignature",N,b*2),new d(y(N,0,b),y(N,b,2*b))}static fromDER(N){let{r:b,s:p}=xt.toSig(te("DER",N));return new d(b,p)}assertValidity(){Ne("r",this.r,fe,n),Ne("s",this.s,fe,n)}addRecoveryBit(N){return new d(this.r,this.s,N)}recoverPublicKey(N){let{r:b,s:p,recovery:v}=this,C=U(te("msgHash",N));if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");let R=v===2||v===3?b+e.n:b;if(R>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let _=v&1?"03":"02",P=c.fromHex(_+h(R)),H=a(R),D=i(-C*H),W=i(p*H),Y=c.BASE.multiplyAndAddUnsafe(P,D,W);if(!Y)throw new Error("point at infinify");return Y.assertValidity(),Y}hasHighS(){return w(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return Kt(this.toDERHex())}toDERHex(){return xt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Kt(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let x={isValidPrivateKey(E){try{return u(E),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let E=hs(e.n);return Ea(e.randomBytes(E),e.n)},precompute(E=8,N=c.BASE){return N._setWindowSize(E),N.multiply(BigInt(3)),N}};function B(E,N=!0){return c.fromPrivateKey(E).toRawBytes(N)}function g(E){let N=It(E),b=typeof E=="string",p=(N||b)&&E.length;return N?p===o||p===s:b?p===2*o||p===2*s:E instanceof c}function S(E,N,b=!0){if(g(E))throw new Error("first arg must be private key");if(!g(N))throw new Error("second arg must be public key");return c.fromHex(N).multiply(u(E)).toRawBytes(b)}let L=e.bits2int||function(E){let N=ft(E),b=E.length*8-e.nBitLength;return b>0?N>>BigInt(b):N},U=e.bits2int_modN||function(E){return i(L(E))},I=Cr(e.nBitLength);function k(E){return Ne(`num < 2^${e.nBitLength}`,E,vt,I),Nt(E,e.nByteLength)}function T(E,N,b=ne){if(["recovered","canonical"].some(ue=>ue in b))throw new Error("sign() legacy options not supported");let{hash:p,randomBytes:v}=e,{lowS:C,prehash:R,extraEntropy:_}=b;C==null&&(C=!0),E=te("msgHash",E),Fc(b),R&&(E=te("prehashed msgHash",p(E)));let P=U(E),H=u(N),D=[k(H),k(P)];if(_!=null&&_!==!1){let ue=_===!0?v(t.BYTES):_;D.push(te("extraEntropy",ue))}let W=ht(...D),Y=P;function le(ue){let he=L(ue);if(!f(he))return;let Be=a(he),se=c.BASE.multiply(he).toAffine(),ke=i(se.x);if(ke===vt)return;let st=i(Be*i(Y+ke*H));if(st===vt)return;let xr=(se.x===ke?0:2)|Number(se.y&fe),vr=st;return C&&w(st)&&(vr=m(st),xr^=1),new d(ke,vr,xr)}return{seed:W,k2sig:le}}let ne={lowS:e.lowS,prehash:!1},K={lowS:e.lowS,prehash:!1};function V(E,N,b=ne){let{seed:p,k2sig:v}=T(E,N,b),C=e;return cs(C.hash.outputLen,C.nByteLength,C.hmac)(p,v)}c.BASE._setWindowSize(8);function oe(E,N,b,p=K){let v=E;if(N=te("msgHash",N),b=te("publicKey",b),"strict"in p)throw new Error("options.strict was renamed to lowS");Fc(p);let{lowS:C,prehash:R}=p,_,P;try{if(typeof v=="string"||It(v))try{_=d.fromDER(v)}catch(se){if(!(se instanceof xt.Err))throw se;_=d.fromCompact(v)}else if(typeof v=="object"&&typeof v.r=="bigint"&&typeof v.s=="bigint"){let{r:se,s:ke}=v;_=new d(se,ke)}else throw new Error("PARSE");P=c.fromHex(b)}catch(se){if(se.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(C&&_.hasHighS())return!1;R&&(N=e.hash(N));let{r:H,s:D}=_,W=U(N),Y=a(D),le=i(W*Y),ue=i(H*Y),he=c.BASE.multiplyAndAddUnsafe(P,le,ue)?.toAffine();return he?i(he.x)===H:!1}return{CURVE:e,getPublicKey:B,getSharedSecret:S,sign:V,verify:oe,ProjectivePoint:c,Signature:d,utils:x}}function Qh(r){return{hash:r,hmac:(e,...t)=>ii(r,e,es(...t)),randomBytes:ln}}function $c(r,e){let t=n=>qc({...r,...Qh(n)});return Object.freeze({...t(e),create:t})}var Wc=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),zc=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),ed=BigInt(1),ai=BigInt(2),Gc=(r,e)=>(r+e/ai)/e;function td(r){let e=Wc,t=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,l=u*u*r%e,f=Q(l,t,e)*l%e,h=Q(f,t,e)*l%e,w=Q(h,ai,e)*u%e,m=Q(w,o,e)*w%e,y=Q(m,s,e)*m%e,d=Q(y,a,e)*y%e,x=Q(d,c,e)*d%e,B=Q(x,a,e)*y%e,g=Q(B,t,e)*l%e,S=Q(g,i,e)*m%e,L=Q(S,n,e)*u%e,U=Q(L,ai,e);if(!ci.eql(ci.sqr(U),r))throw new Error("Cannot find square root");return U}var ci=Ct(Wc,void 0,void 0,{sqrt:td}),Yt=$c({a:BigInt(0),b:BigInt(7),Fp:ci,n:zc,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=zc,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-ed*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=t,i=BigInt("0x100000000000000000000000000000000"),a=Gc(s*r,e),c=Gc(-n*r,e),u=j(r-a*t-c*o,e),l=j(-a*n-c*s,e),f=u>i,h=l>i;if(f&&(u=e-u),h&&(l=e-l),u>i||l>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:u,k2neg:h,k2:l}}}},cr),Nm=BigInt(0);var Cm=Yt.ProjectivePoint;function _e(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=Te(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}function jc(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Zc(r,e,t){let n=Ur.digest(t instanceof Uint8Array?t:t.subarray());if(jc(n))return n.then(({digest:o})=>Yt.verify(e,o,r)).catch(o=>{throw new qr(String(o))});try{return Yt.verify(e,n.digest,r)}catch(o){throw new qr(String(o))}}var yo=class{type="secp256k1";raw;_key;constructor(e){this._key=Jc(e),this.raw=Yc(this._key)}toMultihash(){return ct.digest(Tt(this))}toCID(){return de.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:be(this.raw,e.raw)}verify(e,t){return Zc(this._key,t,e)}};function li(r){return new yo(r)}function Yc(r){return Yt.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Jc(r){try{return Yt.ProjectivePoint.fromHex(r),r}catch(e){throw new Jt(String(e))}}function gr(r){let{Type:e,Data:t}=Xe.decode(r),n=t??new Uint8Array;switch(e){case ae.RSA:return si(n);case ae.Ed25519:return ys(n);case ae.secp256k1:return li(n);default:throw new Dt}}function Xc(r){let{Type:e,Data:t}=Xe.decode(r.digest),n=t??new Uint8Array;switch(e){case ae.Ed25519:return ys(n);case ae.secp256k1:return li(n);default:throw new Dt}}function Tt(r){return Xe.encode({Type:ae[r.type],Data:r.raw})}var el=Symbol.for("@achingbrain/uint8arraylist");function Qc(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 bo(r){return!!r?.[el]}var je=class r{bufs;length;[el]=!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(bo(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(bo(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=Qc(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Qc(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(bo(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 _e(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:_e(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),s=new r;return s.length=o,s.bufs=[...n],s}_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 s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,l=t>a&&t<=c;if(u&&l){if(e===a&&t===c){n.push(i);break}let f=e-a;n.push(i.subarray(f,f+(t-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(l){if(t===c){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!bo(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 s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=t;f<=c;f+=l){l=0;for(let h=u;h>=0;h--){let w=this.get(f+h);if(n[h]!==w){l=Math.max(1,h-a[w]);break}}if(l===0)return f}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=Te(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=pe(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=pe(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=pe(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=Te(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=pe(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=pe(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=pe(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=pe(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=pe(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(!be(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,s)=>o+s.byteLength,0)),n.length=t,n}};var Gr;(function(r){let e;r.codec=()=>(e==null&&(e=Ge((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.publicKey!=null&&t.publicKey.byteLength>0&&(n.uint32(10),n.bytes(t.publicKey)),t.payloadType!=null&&t.payloadType.byteLength>0&&(n.uint32(18),n.bytes(t.payloadType)),t.payload!=null&&t.payload.byteLength>0&&(n.uint32(26),n.bytes(t.payload)),t.signature!=null&&t.signature.byteLength>0&&(n.uint32(42),n.bytes(t.signature)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let s={publicKey:pe(0),payloadType:pe(0),payload:pe(0),signature:pe(0)},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let a=t.uint32();switch(a>>>3){case 1:{s.publicKey=t.bytes();break}case 2:{s.payloadType=t.bytes();break}case 3:{s.payload=t.bytes();break}case 5:{s.signature=t.bytes();break}default:{t.skipType(a&7);break}}}return s})),e),r.encode=t=>ze(t,r.codec()),r.decode=(t,n)=>$e(t,r.codec(),n)})(Gr||(Gr={}));var wo=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var rt=class r{static createFromProtobuf=async e=>{let t=Gr.decode(e),n=gr(t.publicKey);return new r({publicKey:n,payloadType:t.payloadType,payload:t.payload,signature:t.signature})};static seal=async(e,t)=>{if(t==null)throw new Error("Missing private key");let n=e.domain,o=e.codec,s=e.marshal(),i=tl(n,o,s),a=await t.sign(i.subarray());return new r({publicKey:t.publicKey,payloadType:o,payload:s,signature:a})};static openAndCertify=async(e,t)=>{let n=await r.createFromProtobuf(e);if(!await n.validate(t))throw new wo("Envelope signature is not valid for the given domain");return n};publicKey;payloadType;payload;signature;marshaled;constructor(e){let{publicKey:t,payloadType:n,payload:o,signature:s}=e;this.publicKey=t,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Gr.encode({publicKey:Tt(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return be(this.marshal(),e.marshal())}async validate(e){let t=tl(e,this.payloadType,this.payload);return this.publicKey.verify(t.subarray(),this.signature)}},tl=(r,e,t)=>{let n=q(r),o=Oe(n.byteLength),s=Oe(e.length),i=Oe(t.length);return new je(o,n,s,e,i,t)};var rl=Symbol.for("nodejs.util.inspect.custom"),rd=114,Wr=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()})`}[qo]=!0;toString(){return this.string==null&&(this.string=J.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return de.createV1(rd,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return be(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return be(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[rl](){return`PeerId(${this.toString()})`}},jr=class extends Wr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Zr=class extends Wr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Yr=class extends Wr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},nd=2336,Jr=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=ct.digest(q(this.url))}[rl](){return`PeerId(${this.url})`}[qo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return de.createV1(nd,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=F(e)),e.toString()===this.toString())}};var od=114,nl=2336;function ol(r){if(r.type==="Ed25519")return new Zr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Yr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new jr({multihash:r.toCID().multihash,publicKey:r});throw new Dt}function ui(r){if(id(r))return new jr({multihash:r});if(sd(r))try{let e=Xc(r);if(e.type==="Ed25519")return new Zr({multihash:r,publicKey:e});if(e.type==="secp256k1")return new Yr({multihash:r,publicKey:e})}catch{let t=F(r.digest);return new Jr(new URL(t))}throw new nn("Supplied PeerID Multihash is invalid")}function xo(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==od&&r.code!==nl)throw new rn("Supplied PeerID CID is invalid");if(r.code===nl){let e=F(r.multihash.digest);return new Jr(new URL(e))}return ui(r.multihash)}function sd(r){return r.code===ct.code}function id(r){return r.code===Ur.code}function sl(r,e){let t=(n,o)=>n.toString().localeCompare(o.toString());return r.length!==e.length?!1:(e.sort(t),r.sort(t).every((n,o)=>e[o].equals(n)))}var vo=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 s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let h=Number.parseInt(f,e);if(!Number.isNaN(h))return h});if(l===void 0)break;if(s*=e,s+=l,s>u||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&c&&i>1?void 0:s})}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 i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];t[o]=s>>8,t[o+1]=s&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 s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var il=45,ad=15,mr=new vo;function fi(r){if(!(r.length>ad))return mr.new(r).parseWith(()=>mr.readIPv4Addr())}function hi(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>il))return mr.new(r).parseWith(()=>mr.readIPv6Addr())}function Eo(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>il))return mr.new(r).parseWith(()=>mr.readIPAddr())}var ib=parseInt("0xFFFF",16),ab=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Bo(r){return!!fi(r)}function Ao(r){return!!hi(r)}function So(r){return!!Eo(r)}var ll=Bo,hd=Ao,di=function(r){let e=0;if(r=r.toString().trim(),ll(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(hd(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=ll(t[n]),i;s&&(i=di(t[n]),t[n]=F(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,F(i.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 s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let s=parseInt(t[n],16);o[e++]=s>>8&255,o[e++]=s&255}return o}throw new Error("invalid ip address")},ul=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 s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var yr={},pi={},pd=[[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"]];pd.forEach(r=>{let e=gd(...r);pi[e.code]=e,yr[e.name]=e});function gd(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function $(r){if(typeof r=="number"){if(pi[r]!=null)return pi[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(yr[r]!=null)return yr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var $b=$("ip4"),zb=$("ip6"),Gb=$("ipcidr");function bi(r,e){switch($(r).code){case 4:case 41:return yd(e);case 42:return yi(e);case 6:case 273:case 33:case 132:return dl(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return yi(e);case 421:return vd(e);case 444:return hl(e);case 445:return hl(e);case 466:return xd(e);case 481:return globalThis.encodeURIComponent(yi(e));default:return F(e,"base16")}}function wi(r,e){switch($(r).code){case 4:return fl(e);case 41:return fl(e);case 42:return mi(e);case 6:case 273:case 33:case 132:return xi(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return mi(e);case 421:return bd(e);case 444:return Ed(e);case 445:return Bd(e);case 466:return wd(e);case 481:return mi(globalThis.decodeURIComponent(e));default:return q(e,"base16")}}var gi=Object.values(Lr).map(r=>r.decoder),md=function(){let r=gi[0].or(gi[1]);return gi.slice(2).forEach(e=>r=r.or(e)),r}();function fl(r){if(!So(r))throw new Error("invalid ip address");return di(r)}function yd(r){let e=ul(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!So(e))throw new Error("invalid ip address");return e}function xi(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function dl(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function mi(r){let e=q(r),t=Uint8Array.from(Oe(e.length));return _e([t,e],t.length+e.length)}function yi(r){let e=dt(r);if(r=r.slice(xe(e)),r.length!==e)throw new Error("inconsistent lengths");return F(r)}function bd(r){let e;r[0]==="Q"||r[0]==="1"?e=Mt(J.decode(`z${r}`)).bytes:e=de.parse(r).multihash.bytes;let t=Uint8Array.from(Oe(e.length));return _e([t,e],t.length+e.length)}function wd(r){let e=md.decode(r),t=Uint8Array.from(Oe(e.length));return _e([t,e],t.length+e.length)}function xd(r){let e=dt(r),t=r.slice(xe(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+F(t,"base64url")}function vd(r){let e=dt(r),t=r.slice(xe(e));if(t.length!==e)throw new Error("inconsistent lengths");return F(t,"base58btc")}function Ed(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=at.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=xi(n);return _e([t,o],t.length+o.length)}function Bd(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=at.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=xi(n);return _e([t,o],t.length+o.length)}function hl(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=F(e,"base32"),o=dl(t);return`${n}:${o}`}function pl(r){r=vi(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 s=0;s<o.length;s++){let i=o[s],a=$(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(s++,s>=o.length)throw ml("invalid address: "+r);if(a.path===!0){n=vi(o.slice(s).join("/")),e.push([a.code,wi(a.code,n)]),t.push([a.code,n]);break}let c=wi(a.code,o[s]);e.push([a.code,c]),t.push([a.code,bi(a.code,c)])}return{string:gl(t),bytes:Bi(e),tuples:e,stringTuples:t,path:n}}function Ei(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=dt(r,o),i=xe(s),a=$(s),c=Ad(a,r.slice(o+i));if(c===0){e.push([s]),t.push([s]),o+=i;continue}let u=r.slice(o+i,o+i+c);if(o+=c+i,o>r.length)throw ml("Invalid address Uint8Array: "+F(r,"base16"));e.push([s,u]);let l=bi(s,u);if(t.push([s,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:gl(t),tuples:e,stringTuples:t,path:n}}function gl(r){let e=[];return r.map(t=>{let n=$(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),vi(e.join("/"))}function Bi(r){return _e(r.map(e=>{let t=$(e[0]),n=Uint8Array.from(Oe(t.code));return e.length>1&&e[1]!=null&&(n=_e([n,e[1]])),n}))}function Ad(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=dt(e instanceof Uint8Array?e:Uint8Array.from(e));return t+xe(t)}}function vi(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function ml(r){return new Error("Error parsing address: "+r)}var Sd=Symbol.for("nodejs.util.inspect.custom"),Si=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Id=[$("dns").code,$("dns4").code,$("dns6").code,$("dnsaddr").code],Ai=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},Io=class r{bytes;#t;#e;#r;#n;[Si]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=Ei(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=pl(e)}else if(bl(e))t=Ei(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#t=t.string,this.#e=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="",i=$("tcp"),a=$("udp"),c=$("ip4"),u=$("ip6"),l=$("dns6"),f=$("ip6zone");for(let[w,m]of this.stringTuples())w===f.code&&(s=`%${m??""}`),Id.includes(w)&&(t=i.name,o=443,n=`${m??""}${s}`,e=w===l.code?6:4),(w===i.code||w===a.code)&&(t=$(w).name,o=parseInt(m??"")),(w===c.code||w===u.code)&&(t=$(w).name,n=`${m??""}${s}`,e=w===u.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.#e.map(([e])=>Object.assign({},$(e)))}protoCodes(){return this.#e.map(([e])=>e)}protoNames(){return this.#e.map(([e])=>$(e).name)}tuples(){return this.#e}stringTuples(){return this.#r}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(Bi(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===yr.p2p.code&&e.push([n,o]),n===yr["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?F(J.decode(`z${n}`),"base58btc"):F(de.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return be(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=yl.get(t.name);if(n==null)throw new Ai(`no available resolver for ${t.name}`);return(await n(this,e)).map(s=>nt(s))}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)}[Sd](){return`Multiaddr(${this.#t})`}};var yl=new Map;function bl(r){return!!r?.[Si]}function nt(r){return new Io(r)}var wl="libp2p-peer-record",xl=Uint8Array.from([3,1]);var Xr;(function(r){let e;(function(n){let o;n.codec=()=>(o==null&&(o=Ge((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:pe(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{c.multiaddr=s.bytes();break}default:{s.skipType(l&7);break}}}return c})),o),n.encode=s=>ze(s,n.codec()),n.decode=(s,i)=>$e(s,n.codec(),i)})(e=r.AddressInfo||(r.AddressInfo={}));let t;r.codec=()=>(t==null&&(t=Ge((n,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(o.uint32(10),o.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(o.uint32(16),o.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)o.uint32(26),r.AddressInfo.codec().encode(i,o);s.lengthDelimited!==!1&&o.ldelim()},(n,o,s={})=>{let i={peerId:pe(0),seq:0n,addresses:[]},a=o==null?n.len:n.pos+o;for(;n.pos<a;){let c=n.uint32();switch(c>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(s.limits?.addresses!=null&&i.addresses.length===s.limits.addresses)throw new jt('Decode error - map field "addresses" had too many elements');i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:s.limits?.addresses$}));break}default:{n.skipType(c&7);break}}}return i})),t),r.encode=n=>ze(n,r.codec()),r.decode=(n,o)=>$e(n,r.codec(),o)})(Xr||(Xr={}));var Ze=class r{static createFromProtobuf=e=>{let t=Xr.decode(e),n=ui(Mt(t.peerId)),o=(t.addresses??[]).map(i=>nt(i.multiaddr)),s=t.seq;return new r({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=wl;static CODEC=xl;peerId;multiaddrs;seqNumber;domain=r.DOMAIN;codec=r.CODEC;marshaled;constructor(e){let{peerId:t,multiaddrs:n,seqNumber:o}=e;this.peerId=t,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=Xr.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof r)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!sl(this.multiaddrs,e.multiaddrs))}};function kd(r){return r[Symbol.asyncIterator]!=null}function Nd(r){if(kd(r))return(async()=>{for await(let e of r);})();for(let e of r);}var vl=Nd;function Ye(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var ko=globalThis.CustomEvent??Event;async function*Ii(r,e={}){let t=e.concurrency??1/0;t<1&&(t=1/0);let n=e.ordered==null?!1:e.ordered,o=new EventTarget,s=[],i=Ye(),a=Ye(),c=!1,u,l=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let m of r){if(s.length===t&&(i=Ye(),await i.promise),l)break;let y={done:!1};s.push(y),m().then(d=>{y.done=!0,y.ok=!0,y.value=d,o.dispatchEvent(new ko("task-complete"))},d=>{y.done=!0,y.err=d,o.dispatchEvent(new ko("task-complete"))})}c=!0,o.dispatchEvent(new ko("task-complete"))}catch(m){u=m,o.dispatchEvent(new ko("task-complete"))}});function f(){return n?s[0]?.done:!!s.find(m=>m.done)}function*h(){for(;s.length>0&&s[0].done;){let m=s[0];if(s.shift(),m.ok)yield m.value;else throw l=!0,i.resolve(),m.err;i.resolve()}}function*w(){for(;f();)for(let m=0;m<s.length;m++)if(s[m].done){let y=s[m];if(s.splice(m,1),m--,y.ok)yield y.value;else throw l=!0,i.resolve(),y.err;i.resolve()}}for(;;){if(f()||(a=Ye(),await a.promise),u!=null)throw u;if(n?yield*h():yield*w(),c&&s.length===0)break}}var No=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 El(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new No(t?.errorMessage,t?.errorCode,t?.errorName));let n,o=new No(t?.errorMessage,t?.errorCode,t?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var ki=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=Ye(),this.haveNext=Ye()}[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=Ye(),e}async throw(e){return this.ended=!0,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 await this._push(void 0),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 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=Ye(),await El(this.readNext.promise,t?.signal,t)}};function Bl(){return new ki}var Co=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var Ni=class extends Error{code;constructor(e,t){super(e),this.code=t}},Ci=class extends Ni{type;constructor(e){super(e,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function Al(r,e){let t=Bl();r.sink(t).catch(async i=>{await t.end(i)}),r.sink=async i=>{for await(let a of i)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 je;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,u=new Promise((l,f)=>{c=()=>{f(new Ci("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(i==null){let{done:f,value:h}=await Promise.race([n.next(),u]);return f===!0?new je:h}for(;o.byteLength<i;){let{value:f,done:h}=await Promise.race([n.next(),u]);if(h===!0)throw new Co("unexpected end of input");o.append(f)}let l=o.sublist(0,i);return o.consume(i),l}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await t.push(i,a):await t.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=r.source;r.source=async function*(){e?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var To=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Uo=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Lo=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Sl(r,e={}){let t=Al(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=xe(e.maxDataLength));let n=e?.lengthDecoder??dt,o=e?.lengthEncoder??Oe;return{read:async i=>{let a=-1,c=new je;for(;;){c.append(await t.read(1,i));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new To("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new Lo("message length length too long");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Uo("message length too long");return t.read(a,i)},write:async(i,a)=>{await t.write(new je(o(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new je(...i.flatMap(u=>[o(u.byteLength),u]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function br(r,e){let t=Sl(r,e),n={read:async(o,s)=>{let i=await t.read(s);return o.decode(i)},write:async(o,s,i)=>{await t.write(s.encode(o),i)},writeV:async(o,s,i)=>{await t.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var Il="0.1.0",kl="id",Nl="id/push",Cl="1.0.0",Tl="1.0.0";var Pt;(function(r){let e;r.codec=()=>(e==null&&(e=Ge((t,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),t.protocolVersion!=null&&(n.uint32(42),n.string(t.protocolVersion)),t.agentVersion!=null&&(n.uint32(50),n.string(t.agentVersion)),t.publicKey!=null&&(n.uint32(10),n.bytes(t.publicKey)),t.listenAddrs!=null)for(let s of t.listenAddrs)n.uint32(18),n.bytes(s);if(t.observedAddr!=null&&(n.uint32(34),n.bytes(t.observedAddr)),t.protocols!=null)for(let s of t.protocols)n.uint32(26),n.string(s);t.signedPeerRecord!=null&&(n.uint32(66),n.bytes(t.signedPeerRecord)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let s={listenAddrs:[],protocols:[]},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let a=t.uint32();switch(a>>>3){case 5:{s.protocolVersion=t.string();break}case 6:{s.agentVersion=t.string();break}case 1:{s.publicKey=t.bytes();break}case 2:{if(o.limits?.listenAddrs!=null&&s.listenAddrs.length===o.limits.listenAddrs)throw new jt('Decode error - map field "listenAddrs" had too many elements');s.listenAddrs.push(t.bytes());break}case 4:{s.observedAddr=t.bytes();break}case 3:{if(o.limits?.protocols!=null&&s.protocols.length===o.limits.protocols)throw new jt('Decode error - map field "protocols" had too many elements');s.protocols.push(t.string());break}case 8:{s.signedPeerRecord=t.bytes();break}default:{t.skipType(a&7);break}}}return s})),e),r.encode=t=>ze(t,r.codec()),r.decode=(t,n)=>$e(t,r.codec(),n)})(Pt||(Pt={}));var Rl=Gi(Ll(),1),Ti=typeof window=="object"&&typeof document=="object"&&document.nodeType===9,Ro=(0,Rl.default)(),_l=Ti&&!Ro,Ol=Ro&&!Ti,Vl=Ro&&Ti,Pl=typeof globalThis.process<"u"&&typeof globalThis.process.release<"u"&&globalThis.process.release.name==="node"&&!Ro,Dl=typeof importScripts=="function"&&typeof self<"u"&&typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,Qw=typeof globalThis.process<"u"&&typeof globalThis.process.env<"u"&&globalThis.process.env["NODE"+"_"+"ENV"]==="test",Ml=typeof navigator<"u"&&navigator.product==="ReactNative";var Le={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function Hl(r){if(r!=null&&r.length>0)try{return nt(r)}catch{}}function Ld(r,e){return e!=null||(e=`${r.name}/${r.version}`,Pl||Ol?e+=` UserAgent=${globalThis.process.version}`:(_l||Dl||Vl||Ml)&&(e+=` UserAgent=${globalThis.navigator.userAgent}`)),e}async function _o(r,e,t,n,o){if(t("received identify from %p",n.remotePeer),o==null)throw new De("message was null or undefined");let s={};if(o.listenAddrs.length>0&&(s.addresses=o.listenAddrs.map(c=>({isCertified:!1,multiaddr:nt(c)}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let c=gr(o.publicKey);if(!ol(c).equals(n.remotePeer))throw new De("public key did not match remote PeerId");s.publicKey=c}let i;if(o.signedPeerRecord!=null){t("received signedPeerRecord from %p",n.remotePeer);let c=o.signedPeerRecord,u=await rt.openAndCertify(c,Ze.DOMAIN),l=Ze.createFromProtobuf(u.payload),f=xo(u.publicKey.toCID());if(!l.peerId.equals(f))throw new De("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(l.peerId))throw new De("signing key does not match remote PeerId");let h;try{h=await r.get(l.peerId)}catch(w){if(w.name!=="NotFoundError")throw w}if(h!=null&&(s.metadata=h.metadata,h.peerRecordEnvelope!=null)){let w=await rt.createFromProtobuf(h.peerRecordEnvelope),m=Ze.createFromProtobuf(w.payload);m.seqNumber>=l.seqNumber&&(t("sequence number was lower or equal to existing sequence number - stored: %d received: %d",m.seqNumber,l.seqNumber),l=m,c=h.peerRecordEnvelope)}s.peerRecordEnvelope=c,s.addresses=l.multiaddrs.map(w=>({isCertified:!0,multiaddr:w})),i={seq:l.seqNumber,addresses:l.multiaddrs}}else t("%p did not send a signed peer record",n.remotePeer);if(t("patching %p with",n.remotePeer,s),await r.patch(n.remotePeer,s),o.agentVersion!=null||o.protocolVersion!=null){let c={};o.agentVersion!=null&&(c.AgentVersion=q(o.agentVersion)),o.protocolVersion!=null&&(c.ProtocolVersion=q(o.protocolVersion)),t("merging %p metadata",n.remotePeer,c),await r.merge(n.remotePeer,{metadata:c})}let a={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:o.listenAddrs.map(c=>nt(c)),observedAddr:o.observedAddr==null?void 0:nt(o.observedAddr),protocols:o.protocols,signedPeerRecord:i,connection:n};return e.safeDispatchEvent("peer:identify",{detail:a}),a}var wr=class{host;protocol;started;timeout;peerId;privateKey;peerStore;registrar;addressManager;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;events;runOnLimitedConnection;log;constructor(e,t){this.protocol=t.protocol,this.started=!1,this.peerId=e.peerId,this.privateKey=e.privateKey,this.peerStore=e.peerStore,this.registrar=e.registrar,this.addressManager=e.addressManager,this.events=e.events,this.log=t.log,this.timeout=t.timeout??Le.timeout,this.maxInboundStreams=t.maxInboundStreams??Le.maxInboundStreams,this.maxOutboundStreams=t.maxOutboundStreams??Le.maxOutboundStreams,this.maxMessageSize=t.maxMessageSize??Le.maxMessageSize,this.maxObservedAddresses=t.maxObservedAddresses??Le.maxObservedAddresses,this.runOnLimitedConnection=t.runOnLimitedConnection??Le.runOnLimitedConnection,this.host={protocolVersion:`${t.protocolPrefix??Le.protocolPrefix}/${Il}`,agentVersion:Ld(e.nodeInfo,t.agentVersion)}}isStarted(){return this.started}async start(){this.started||(await this.peerStore.merge(this.peerId,{metadata:{AgentVersion:q(this.host.agentVersion),ProtocolVersion:q(this.host.protocolVersion)}}),await this.registrar.handle(this.protocol,e=>{this.handleProtocol(e).catch(t=>{this.log.error(t)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.registrar.unhandle(this.protocol),this.started=!1}};var Oo=class extends wr{connectionManager;concurrency;constructor(e,t={}){super(e,{...t,protocol:`/${t.protocolPrefix??Le.protocolPrefix}/${Nl}/${Tl}`,log:e.logger.forComponent("libp2p:identify-push")}),this.connectionManager=e.connectionManager,this.concurrency=t.concurrency??Le.concurrency,(t.runOnSelfUpdate??Le.runOnSelfUpdate)&&e.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error(o)})})}[on]=["@libp2p/identify-push"];async push(){if(!this.isStarted())return;let e=this.addressManager.getAddresses().map(l=>l.decapsulateCode($("p2p").code)),t=new Ze({peerId:this.peerId,multiaddrs:e}),n=await rt.seal(t,this.privateKey),o=this.registrar.getProtocols(),s=await this.peerStore.get(this.peerId),i=F(s.metadata.get("AgentVersion")??q(this.host.agentVersion)),a=F(s.metadata.get("ProtocolVersion")??q(this.host.protocolVersion)),c=this;async function*u(){for(let l of c.connectionManager.getConnections())(await c.peerStore.get(l.remotePeer)).protocols.includes(c.protocol)&&(yield async()=>{let h,w=AbortSignal.timeout(c.timeout);Er(1/0,w);try{h=await l.newStream(c.protocol,{signal:w,runOnLimitedConnection:c.runOnLimitedConnection}),await br(h,{maxDataLength:c.maxMessageSize}).pb(Pt).write({listenAddrs:e.map(y=>y.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:a},{signal:w}),await h.close({signal:w})}catch(m){c.log.error("could not push identify update to peer",m),h?.abort(m)}})}await vl(Ii(u(),{concurrency:this.concurrency}))}async handleProtocol(e){let{connection:t,stream:n}=e;try{if(this.peerId.equals(t.remotePeer))throw new Error("received push from ourselves?");let o={signal:AbortSignal.timeout(this.timeout)},i=await br(n,{maxDataLength:this.maxMessageSize}).pb(Pt).read(o);await n.close(o),await _o(this.peerStore,this.events,this.log,t,i)}catch(o){this.log.error("received invalid message",o),n.abort(o);return}this.log("handled push from %p",t.remotePeer)}};var Rd=r=>r.toString().split("/").slice(1),Qr=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),z=r=>({match:e=>Qr(t=>t===r).match(e),pattern:r}),Do=()=>({match:r=>Qr(e=>typeof e=="string").match(r),pattern:"{string}"}),Mo=()=>({match:r=>Qr(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),ye=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{J.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Vo=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Rs.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),ce=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),Pe=(...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(", ")})`}),Z=(...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 re(...r){function e(o){let s=Rd(o);for(let i of r){let a=i.match(s);if(a===!1)return!1;s=a}return s}function t(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matches:t,exactMatch:n}}var Li=Z(z("dns4"),Do()),Ri=Z(z("dns6"),Do()),_i=Z(z("dnsaddr"),Do()),Fl=Z(z("dns"),Do()),Ix=re(Li),kx=re(Ri),Nx=re(_i),Cx=re(Pe(Fl,_i,Li,Ri)),Kl=Z(z("ip4"),Qr(Bo)),ql=Z(z("ip6"),Qr(Ao)),$l=Pe(Kl,ql),ot=Pe($l,Fl,Li,Ri,_i),zl=re(ot),Tx=re(Kl),Ux=re(ql),Lx=re($l),Oi=Z(ot,z("tcp"),Mo()),en=Z(ot,z("udp"),Mo()),Rx=re(Oi),_x=re(en),Vi=Z(en,z("quic")),Ho=Z(en,z("quic-v1")),_d=Pe(Vi,Ho),Ox=re(Vi),Vx=re(Ho),Ui=Pe(ot,Oi,en,Vi,Ho),Gl=Pe(Z(Ui,z("ws"),ce(ye()))),Px=re(Gl),Wl=Pe(Z(Ui,z("wss"),ce(ye())),Z(Ui,z("tls"),z("ws"),ce(ye()))),Dx=re(Wl),jl=Z(en,z("webrtc-direct"),ce(Vo()),ce(Vo()),ce(ye())),Mx=re(jl),Zl=Z(Ho,z("webtransport"),ce(Vo()),ce(Vo()),ce(ye())),Hx=re(Zl),Po=Pe(Gl,Wl,Z(Oi,ce(ye())),Z(_d,ce(ye())),Z(ot,ce(ye())),jl,Zl,ye()),Fx=re(Po),Od=Z(Po,z("p2p-circuit"),ye()),Kx=re(Od),Vd=Pe(Z(Po,z("p2p-circuit"),z("webrtc"),ce(ye())),Z(Po,z("webrtc"),ce(ye())),z("webrtc")),qx=re(Vd),Pd=Pe(Z(ot,z("tcp"),Mo(),z("http"),ce(ye())),Z(ot,z("http"),ce(ye()))),$x=re(Pd),Dd=Pe(Z(ot,z("tcp"),Pe(Z(z("443"),z("http")),Z(Mo(),z("https"))),ce(ye())),Z(ot,z("tls"),z("http"),ce(ye())),Z(ot,z("https"),ce(ye()))),zx=re(Dd);var Fo=class extends wr{constructor(e,t={}){super(e,{...t,protocol:`/${t.protocolPrefix??Le.protocolPrefix}/${kl}/${Cl}`,log:e.logger.forComponent("libp2p:identify")}),(t.runOnConnectionOpen??Le.runOnConnectionOpen)&&e.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(s=>{this.log.error("error during identify trigged by connection:open",s)})})}[on]=["@libp2p/identify"];async _identify(e,t={}){let n;if(t.signal==null){let o=AbortSignal.timeout(this.timeout);Er(1/0,o),t={...t,signal:o}}try{n=await e.newStream(this.protocol,{...t,runOnLimitedConnection:this.runOnLimitedConnection});let s=await br(n,{maxDataLength:this.maxMessageSize}).pb(Pt).read(t);return await n.close(t),s}catch(o){throw this.log.error("error while reading identify message",o),n?.abort(o),o}}async identify(e,t={}){let n=await this._identify(e,t),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new De("public key was missing from identify message");let a=gr(o),c=xo(a.toCID());if(!e.remotePeer.equals(c))throw new De("identified peer does not match the expected peer");if(this.peerId.equals(c))throw new De("identified peer is our own peer id?");let u=Hl(i);return this.log("identify completed for peer %p and protocols %o",c,s),this.log("our observed address is %a",u),u!=null&&this.addressManager.getObservedAddrs().length<(this.maxObservedAddresses??1/0)&&(this.log("storing our observed address %a",u),this.addressManager.addObservedAddr(u)),_o(this.peerStore,this.events,this.log,e,n)}async handleProtocol(e){let{connection:t,stream:n}=e,o=AbortSignal.timeout(this.timeout);Er(1/0,o);try{let s=await this.peerStore.get(this.peerId),i=this.addressManager.getAddresses().map(l=>l.decapsulateCode($("p2p").code)),a=s.peerRecordEnvelope;if(i.length>0&&a==null){let l=new Ze({peerId:this.peerId,multiaddrs:i});a=(await rt.seal(l,this.privateKey)).marshal().subarray()}let c=t.remoteAddr.bytes;zl.matches(t.remoteAddr)||(c=void 0),await br(n).pb(Pt).write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Tt(this.privateKey.publicKey),listenAddrs:i.map(l=>l.bytes),signedPeerRecord:a,observedAddr:c,protocols:s.protocols},{signal:o}),await n.close({signal:o})}catch(s){this.log.error("could not respond to identify request",s),n.abort(s)}}};function Md(r={}){return e=>new Fo(e,r)}function Hd(r={}){return e=>new Oo(e,r)}return lu(Fd);})();
|
|
2
|
+
"use strict";var Libp2PIdentify=(()=>{var uu=Object.create;var sn=Object.defineProperty;var fu=Object.getOwnPropertyDescriptor;var hu=Object.getOwnPropertyNames;var du=Object.getPrototypeOf,pu=Object.prototype.hasOwnProperty;var qs=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),At=(r,t)=>{for(var e in t)sn(r,e,{get:t[e],enumerable:!0})},Zi=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of hu(t))!pu.call(r,s)&&s!==e&&sn(r,s,{get:()=>t[s],enumerable:!(n=fu(t,s))||n.enumerable});return r};var zs=(r,t,e)=>(e=r!=null?uu(du(r)):{},Zi(t||!r||!r.__esModule?sn(e,"default",{value:r,enumerable:!0}):e,r)),gu=r=>Zi(sn({},"__esModule",{value:!0}),r);var Wa=qs(lr=>{"use strict";var Mh="[object ArrayBuffer]",pe=class r{static isArrayBuffer(t){return Object.prototype.toString.call(t)===Mh}static toArrayBuffer(t){return this.isArrayBuffer(t)?t:t.byteLength===t.buffer.byteLength||t.byteOffset===0&&t.byteLength===t.buffer.byteLength?t.buffer:this.toUint8Array(t.buffer).slice(t.byteOffset,t.byteOffset+t.byteLength).buffer}static toUint8Array(t){return this.toView(t,Uint8Array)}static toView(t,e){if(t.constructor===e)return t;if(this.isArrayBuffer(t))return new e(t);if(this.isArrayBufferView(t))return new e(t.buffer,t.byteOffset,t.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(t){return this.isArrayBufferView(t)||this.isArrayBuffer(t)}static isArrayBufferView(t){return ArrayBuffer.isView(t)||t&&this.isArrayBuffer(t.buffer)}static isEqual(t,e){let n=r.toUint8Array(t),s=r.toUint8Array(e);if(n.length!==s.byteLength)return!1;for(let o=0;o<n.length;o++)if(n[o]!==s[o])return!1;return!0}static concat(...t){let e;Array.isArray(t[0])&&!(t[1]instanceof Function)||Array.isArray(t[0])&&t[1]instanceof Function?e=t[0]:t[t.length-1]instanceof Function?e=t.slice(0,t.length-1):e=t;let n=0;for(let i of e)n+=i.byteLength;let s=new Uint8Array(n),o=0;for(let i of e){let a=this.toUint8Array(i);s.set(a,o),o+=a.length}return t[t.length-1]instanceof Function?this.toView(s,t[t.length-1]):s.buffer}},ei="string",Fh=/^[0-9a-f]+$/i,Hh=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Kh=/^[a-zA-Z0-9-_]+$/,Nn=class{static fromString(t){let e=unescape(encodeURIComponent(t)),n=new Uint8Array(e.length);for(let s=0;s<e.length;s++)n[s]=e.charCodeAt(s);return n.buffer}static toString(t){let e=pe.toUint8Array(t),n="";for(let o=0;o<e.length;o++)n+=String.fromCharCode(e[o]);return decodeURIComponent(escape(n))}},Ot=class{static toString(t,e=!1){let n=pe.toArrayBuffer(t),s=new DataView(n),o="";for(let i=0;i<n.byteLength;i+=2){let a=s.getUint16(i,e);o+=String.fromCharCode(a)}return o}static fromString(t,e=!1){let n=new ArrayBuffer(t.length*2),s=new DataView(n);for(let o=0;o<t.length;o++)s.setUint16(o*2,t.charCodeAt(o),e);return n}},Cn=class r{static isHex(t){return typeof t===ei&&Fh.test(t)}static isBase64(t){return typeof t===ei&&Hh.test(t)}static isBase64Url(t){return typeof t===ei&&Kh.test(t)}static ToString(t,e="utf8"){let n=pe.toUint8Array(t);switch(e.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 Ot.toString(n,!0);case"utf16":case"utf16be":return Ot.toString(n);default:throw new Error(`Unknown type of encoding '${e}'`)}}static FromString(t,e="utf8"){if(!t)return new ArrayBuffer(0);switch(e.toLowerCase()){case"utf8":return this.FromUtf8String(t);case"binary":return this.FromBinary(t);case"hex":return this.FromHex(t);case"base64":return this.FromBase64(t);case"base64url":return this.FromBase64Url(t);case"utf16le":return Ot.fromString(t,!0);case"utf16":case"utf16be":return Ot.fromString(t);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToBase64(t){let e=pe.toUint8Array(t);if(typeof btoa<"u"){let n=this.ToString(e,"binary");return btoa(n)}else return Buffer.from(e).toString("base64")}static FromBase64(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isBase64(e))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(e)):new Uint8Array(Buffer.from(e,"base64")).buffer}static FromBase64Url(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isBase64Url(e))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(e.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(t){return this.ToBase64(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(t,e=r.DEFAULT_UTF8_ENCODING){switch(e){case"ascii":return this.FromBinary(t);case"utf8":return Nn.fromString(t);case"utf16":case"utf16be":return Ot.fromString(t);case"utf16le":case"usc2":return Ot.fromString(t,!0);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToUtf8String(t,e=r.DEFAULT_UTF8_ENCODING){switch(e){case"ascii":return this.ToBinary(t);case"utf8":return Nn.toString(t);case"utf16":case"utf16be":return Ot.toString(t);case"utf16le":case"usc2":return Ot.toString(t,!0);default:throw new Error(`Unknown type of encoding '${e}'`)}}static FromBinary(t){let e=t.length,n=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=t.charCodeAt(s);return n.buffer}static ToBinary(t){let e=pe.toUint8Array(t),n="";for(let s=0;s<e.length;s++)n+=String.fromCharCode(e[s]);return n}static ToHex(t){let e=pe.toUint8Array(t),n="",s=e.length;for(let o=0;o<s;o++){let i=e[o];i<16&&(n+="0"),n+=i.toString(16)}return n}static FromHex(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isHex(e))throw new TypeError("Argument 'hexString' is not HEX encoded");e.length%2&&(e=`0${e}`);let n=new Uint8Array(e.length/2);for(let s=0;s<e.length;s=s+2){let o=e.slice(s,s+2);n[s/2]=parseInt(o,16)}return n.buffer}static ToUtf16String(t,e=!1){return Ot.toString(t,e)}static FromUtf16String(t,e=!1){return Ot.fromString(t,e)}static Base64Padding(t){let e=4-t.length%4;if(e<4)for(let n=0;n<e;n++)t+="=";return t}static formatString(t){return t?.replace(/[\n\r\t ]/g,"")||""}};Cn.DEFAULT_UTF8_ENCODING="utf8";function $h(r,...t){let e=arguments[0];for(let n=1;n<arguments.length;n++){let s=arguments[n];for(let o in s)e[o]=s[o]}return e}function qh(...r){let t=r.map(s=>s.byteLength).reduce((s,o)=>s+o),e=new Uint8Array(t),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let o of s)e[n++]=o}),e.buffer}function zh(r,t){if(!(r&&t)||r.byteLength!==t.byteLength)return!1;let e=new Uint8Array(r),n=new Uint8Array(t);for(let s=0;s<r.byteLength;s++)if(e[s]!==n[s])return!1;return!0}lr.BufferSourceConverter=pe;lr.Convert=Cn;lr.assign=$h;lr.combine=qh;lr.isEqual=zh});var Pl=qs((fx,_l)=>{function Pd(){return!!(typeof window<"u"&&typeof window.process=="object"&&window.process.type==="renderer"||typeof process<"u"&&typeof process.versions=="object"&&process.versions.electron||typeof navigator=="object"&&typeof navigator.userAgent=="string"&&navigator.userAgent.indexOf("Electron")>=0)}_l.exports=Pd});var ql=qs(en=>{(function(){var r,t,e,n,s,o,i,a;a=function(c){var l,u,f,h;return l=(c&255<<24)>>>24,u=(c&255<<16)>>>16,f=(c&65280)>>>8,h=c&255,[l,u,f,h].join(".")},i=function(c){var l,u,f,h,m,g;for(l=[],f=h=0;h<=3&&c.length!==0;f=++h){if(f>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}g=t(c),m=g[0],u=g[1],c=c.substring(u),l.push(m)}if(c.length!==0)throw new Error("Invalid IP");switch(l.length){case 1:if(l[0]>4294967295)throw new Error("Invalid IP");return l[0]>>>0;case 2:if(l[0]>255||l[1]>16777215)throw new Error("Invalid IP");return(l[0]<<24|l[1])>>>0;case 3:if(l[0]>255||l[1]>255||l[2]>65535)throw new Error("Invalid IP");return(l[0]<<24|l[1]<<16|l[2])>>>0;case 4:if(l[0]>255||l[1]>255||l[2]>255||l[3]>255)throw new Error("Invalid IP");return(l[0]<<24|l[1]<<16|l[2]<<8|l[3])>>>0;default:throw new Error("Invalid IP")}},e=function(c){return c.charCodeAt(0)},n=e("0"),o=e("a"),s=e("A"),t=function(c){var l,u,f,h,m;for(h=0,l=10,u="9",f=0,c.length>1&&c[f]==="0"&&(c[f+1]==="x"||c[f+1]==="X"?(f+=2,l=16):"0"<=c[f+1]&&c[f+1]<="9"&&(f++,l=8,u="7")),m=f;f<c.length;){if("0"<=c[f]&&c[f]<=u)h=h*l+(e(c[f])-n)>>>0;else if(l===16)if("a"<=c[f]&&c[f]<="f")h=h*l+(10+e(c[f])-o)>>>0;else if("A"<=c[f]&&c[f]<="F")h=h*l+(10+e(c[f])-s)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");f++}if(f===m)throw new Error("empty octet");return[h,f]},r=function(){function c(l,u){var f,h,m,g;if(typeof l!="string")throw new Error("Missing `net' parameter");if(u||(g=l.split("/",2),l=g[0],u=g[1]),u||(u=32),typeof u=="string"&&u.indexOf(".")>-1){try{this.maskLong=i(u)}catch(b){throw f=b,new Error("Invalid mask: "+u)}for(h=m=32;m>=0;h=--m)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(u||u===0)this.bitmask=parseInt(u,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(l)&this.maskLong)>>>0}catch(b){throw f=b,new Error("Invalid net address: "+l)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+u);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(l){return typeof l=="string"&&(l.indexOf("/")>0||l.split(".").length!==4)&&(l=new c(l)),l instanceof c?this.contains(l.base)&&this.contains(l.broadcast||l.last):(i(l)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(l){return l==null&&(l=1),new c(a(this.netLong+this.size*l),this.mask)},c.prototype.forEach=function(l){var u,f,h;for(h=i(this.first),f=i(this.last),u=0;h<=f;)l(a(h),h,u),u++,h++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),en.ip2long=i,en.long2ip=a,en.Netmask=r}).call(en)});var t0={};At(t0,{identify:()=>Xd,identifyPush:()=>Qd});var Gs=Symbol.for("@libp2p/peer-id");var St=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Je=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var on=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},an=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}},cn=class extends Error{static name="UnsupportedProtocolError";constructor(t="Unsupported protocol error"){super(t),this.name="UnsupportedProtocolError"}},Dt=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var De=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Ar=(r,...t)=>{try{[...t]}catch{}};var ln=Symbol.for("@libp2p/service-capabilities"),o0=Symbol.for("@libp2p/service-dependencies");var Js={};At(Js,{base58btc:()=>J,base58flickr:()=>vu});var C0=new Uint8Array(0);function Yi(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function ie(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 Ji(r){return new TextEncoder().encode(r)}function Xi(r){return new TextDecoder().decode(r)}function mu(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var s=0;s<r.length;s++){var o=r.charAt(s),i=o.charCodeAt(0);if(e[i]!==255)throw new TypeError(o+" is ambiguous");e[i]=s}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var b=0,d=0,x=0,B=g.length;x!==B&&g[x]===0;)x++,b++;for(var y=(B-x)*u+1>>>0,S=new Uint8Array(y);x!==B;){for(var U=g[x],L=0,I=y-1;(U!==0||L<d)&&I!==-1;I--,L++)U+=256*S[I]>>>0,S[I]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");d=L,x++}for(var k=y-d;k!==y&&S[k]===0;)k++;for(var T=c.repeat(b);k<y;++k)T+=r.charAt(S[k]);return T}function h(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var b=0;if(g[b]!==" "){for(var d=0,x=0;g[b]===c;)d++,b++;for(var B=(g.length-b)*l+1>>>0,y=new Uint8Array(B);g[b];){var S=e[g.charCodeAt(b)];if(S===255)return;for(var U=0,L=B-1;(S!==0||U<x)&&L!==-1;L--,U++)S+=a*y[L]>>>0,y[L]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");x=U,b++}if(g[b]!==" "){for(var I=B-x;I!==B&&y[I]===0;)I++;for(var k=new Uint8Array(d+(B-I)),T=d;I!==B;)k[T++]=y[I++];return k}}}function m(g){var b=h(g);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:h,decode:m}}var yu=mu,bu=yu,ta=bu;var Ws=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},js=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let s=e.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ea(this,t)}},Zs=class{decoders;constructor(t){this.decoders=t}or(t){return ea(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ea(r,t){return new Zs({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Ys=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,s){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=s,this.encoder=new Ws(t,e,n),this.decoder=new js(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Xe({name:r,prefix:t,encode:e,decode:n}){return new Ys(r,t,e,n)}function Ee({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=ta(e,r);return Xe({prefix:t,name:r,encode:n,decode:o=>ie(s(o))})}function wu(r,t,e,n){let s={};for(let u=0;u<t.length;++u)s[t[u]]=u;let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*e/8|0),a=0,c=0,l=0;for(let u=0;u<o;++u){let f=s[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|f,a+=e,a>=8&&(a-=8,i[l++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function xu(r,t,e){let n=t[t.length-1]==="=",s=(1<<e)-1,o="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,o+=t[s&a>>i];if(i!==0&&(o+=t[s&a<<e-i]),n)for(;o.length*e&7;)o+="=";return o}function tt({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Xe({prefix:t,name:r,encode(s){return xu(s,n,e)},decode(s){return wu(s,n,e,r)}})}var J=Ee({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),vu=Ee({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Xs={};At(Xs,{base32:()=>ae,base32hex:()=>Su,base32hexpad:()=>ku,base32hexpadupper:()=>Nu,base32hexupper:()=>Iu,base32pad:()=>Bu,base32padupper:()=>Au,base32upper:()=>Eu,base32z:()=>Cu});var ae=tt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Eu=tt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Bu=tt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Au=tt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Su=tt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Iu=tt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ku=tt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Nu=tt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Cu=tt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Qs={};At(Qs,{base36:()=>Sr,base36upper:()=>Tu});var Sr=Ee({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Tu=Ee({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Lu=sa,ra=128,Uu=127,Ru=~Uu,_u=Math.pow(2,31);function sa(r,t,e){t=t||[],e=e||0;for(var n=e;r>=_u;)t[e++]=r&255|ra,r/=128;for(;r&Ru;)t[e++]=r&255|ra,r>>>=7;return t[e]=r|0,sa.bytes=e-n+1,t}var Pu=to,Ou=128,na=127;function to(r,n){var e=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw to.bytes=0,new RangeError("Could not decode varint");i=r[o++],e+=s<28?(i&na)<<s:(i&na)*Math.pow(2,s),s+=7}while(i>=Ou);return to.bytes=o-n,e}var Vu=Math.pow(2,7),Du=Math.pow(2,14),Mu=Math.pow(2,21),Fu=Math.pow(2,28),Hu=Math.pow(2,35),Ku=Math.pow(2,42),$u=Math.pow(2,49),qu=Math.pow(2,56),zu=Math.pow(2,63),Gu=function(r){return r<Vu?1:r<Du?2:r<Mu?3:r<Fu?4:r<Hu?5:r<Ku?6:r<$u?7:r<qu?8:r<zu?9:10},Wu={encode:Lu,decode:Pu,encodingLength:Gu},ju=Wu,Ir=ju;function kr(r,t=0){return[Ir.decode(r,t),Ir.decode.bytes]}function Qe(r,t,e=0){return Ir.encode(r,t,e),t}function tr(r){return Ir.encodingLength(r)}function Mt(r,t){let e=t.byteLength,n=tr(r),s=n+tr(e),o=new Uint8Array(s+e);return Qe(r,o,0),Qe(e,o,n),o.set(t,s),new er(r,e,t,o)}function Me(r){let t=ie(r),[e,n]=kr(t),[s,o]=kr(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new er(e,s,i,t)}function oa(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Yi(r.bytes,e.bytes)}}var er=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};function ia(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Yu(e,eo(r),t??J.encoder);default:return Ju(e,eo(r),t??ae.encoder)}}var aa=new WeakMap;function eo(r){let t=aa.get(r);if(t==null){let e=new Map;return aa.set(r,e),e}return t}var dt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,s){this.code=e,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}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:t,multihash:e}=this;if(t!==Nr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Xu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:t,digest:e}=this.multihash,n=Mt(t,e);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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&oa(t.multihash,n.multihash)}toString(t){return ia(this,t)}toJSON(){return{"/":ia(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:s,multihash:o,bytes:i}=e;return new r(n,s,o,i??ca(n,s,o.bytes))}else if(e[Qu]===!0){let{version:n,multihash:s,code:o}=e,i=Me(s);return r.create(n,o,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Nr)throw new Error(`Version 0 CID must use dag-pb (code: ${Nr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=ca(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Nr,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,s=ie(t.subarray(n,n+e.multihashSize));if(s.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=s.subarray(e.multihashSize-e.digestSize),i=new er(e.multihashCode,e.digestSize,o,s);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,h]=kr(t.subarray(e));return e+=h,f},s=n(),o=Nr;if(s===18?(s=0,e=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=e,a=n(),c=n(),l=e+c,u=l-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(t,e){let[n,s]=Zu(t,e),o=r.decode(s);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return eo(o).set(n,t),o}};function Zu(r,t){switch(r[0]){case"Q":{let e=t??J;return[J.prefix,e.decode(`${J.prefix}${r}`)]}case J.prefix:{let e=t??J;return[J.prefix,e.decode(r)]}case ae.prefix:{let e=t??ae;return[ae.prefix,e.decode(r)]}case Sr.prefix:{let e=t??Sr;return[Sr.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Yu(r,t,e){let{prefix:n}=e;if(n!==J.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return s}function Ju(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let o=e.encode(r);return t.set(n,o),o}else return s}var Nr=112,Xu=18;function ca(r,t,e){let n=tr(r),s=n+tr(t),o=new Uint8Array(s+e.byteLength);return Qe(r,o,0),Qe(t,o,n),o.set(e,s),o}var Qu=Symbol.for("@ipld/js-cid/CID");var ro={};At(ro,{identity:()=>ce});var la=0,tf="identity",ua=ie;function ef(r){return Mt(la,ua(r))}var ce={code:la,name:tf,encode:ua,digest:ef};function bt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function fa(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function rf(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function rr(r,...t){if(!rf(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function ha(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");fa(r.outputLen),fa(r.blockLen)}function nr(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function da(r,t){rr(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var Fe=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var fn=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Ft=(r,t)=>r<<32-t|r>>>t;var X0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function pa(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Cr(r){return typeof r=="string"&&(r=pa(r)),rr(r),r}function no(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];rr(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let o=r[n];e.set(o,s),s+=o.length}return e}var sr=class{clone(){return this._cloneInto()}},Q0={}.toString;function hn(r){let t=n=>r().update(Cr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function dn(r=32){if(Fe&&typeof Fe.getRandomValues=="function")return Fe.getRandomValues(new Uint8Array(r));if(Fe&&typeof Fe.randomBytes=="function")return Fe.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function nf(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(e>>s&o),a=Number(e&o),c=n?4:0,l=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+l,a,n)}var ga=(r,t,e)=>r&t^~r&e,ma=(r,t,e)=>r&t^r&e^t&e,or=class extends sr{constructor(t,e,n,s){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=fn(this.buffer)}update(t){nr(this);let{view:e,buffer:n,blockLen:s}=this;t=Cr(t);let o=t.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=fn(t);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){nr(this),da(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>s-i&&(this.process(n,0),i=0);for(let f=i;f<s;f++)e[f]=0;nf(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=fn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,u[f],o)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:s,finished:o,destroyed:i,pos:a}=this;return t.length=s,t.pos=a,t.finished=o,t.destroyed=i,s%e&&t.buffer.set(n),t}};var pn=BigInt(4294967295),so=BigInt(32);function ya(r,t=!1){return t?{h:Number(r&pn),l:Number(r>>so&pn)}:{h:Number(r>>so&pn)|0,l:Number(r&pn)|0}}function sf(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:o,l:i}=ya(r[s],t);[e[s],n[s]]=[o,i]}return[e,n]}var of=(r,t)=>BigInt(r>>>0)<<so|BigInt(t>>>0),af=(r,t,e)=>r>>>e,cf=(r,t,e)=>r<<32-e|t>>>e,lf=(r,t,e)=>r>>>e|t<<32-e,uf=(r,t,e)=>r<<32-e|t>>>e,ff=(r,t,e)=>r<<64-e|t>>>e-32,hf=(r,t,e)=>r>>>e-32|t<<64-e,df=(r,t)=>t,pf=(r,t)=>r,gf=(r,t,e)=>r<<e|t>>>32-e,mf=(r,t,e)=>t<<e|r>>>32-e,yf=(r,t,e)=>t<<e-32|r>>>64-e,bf=(r,t,e)=>r<<e-32|t>>>64-e;function wf(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var xf=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),vf=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ef=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Bf=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,Af=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),Sf=(r,t,e,n,s,o)=>t+e+n+s+o+(r/2**32|0)|0;var If={fromBig:ya,split:sf,toBig:of,shrSH:af,shrSL:cf,rotrSH:lf,rotrSL:uf,rotrBH:ff,rotrBL:hf,rotr32H:df,rotr32L:pf,rotlSH:gf,rotlSL:mf,rotlBH:yf,rotlBL:bf,add:wf,add3L:xf,add3H:vf,add4L:Ef,add4H:Bf,add5H:Sf,add5L:Af},P=If;var[kf,Nf]=P.split(["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))),Ae=new Uint32Array(80),Se=new Uint32Array(80),oo=class extends or{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:l,El:u,Fh:f,Fl:h,Gh:m,Gl:g,Hh:b,Hl:d}=this;return[t,e,n,s,o,i,a,c,l,u,f,h,m,g,b,d]}set(t,e,n,s,o,i,a,c,l,u,f,h,m,g,b,d){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=h|0,this.Gh=m|0,this.Gl=g|0,this.Hh=b|0,this.Hl=d|0}process(t,e){for(let y=0;y<16;y++,e+=4)Ae[y]=t.getUint32(e),Se[y]=t.getUint32(e+=4);for(let y=16;y<80;y++){let S=Ae[y-15]|0,U=Se[y-15]|0,L=P.rotrSH(S,U,1)^P.rotrSH(S,U,8)^P.shrSH(S,U,7),I=P.rotrSL(S,U,1)^P.rotrSL(S,U,8)^P.shrSL(S,U,7),k=Ae[y-2]|0,T=Se[y-2]|0,nt=P.rotrSH(k,T,19)^P.rotrBH(k,T,61)^P.shrSH(k,T,6),K=P.rotrSL(k,T,19)^P.rotrBL(k,T,61)^P.shrSL(k,T,6),O=P.add4L(I,K,Se[y-7],Se[y-16]),st=P.add4H(O,L,nt,Ae[y-7],Ae[y-16]);Ae[y]=st|0,Se[y]=O|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:h,Fh:m,Fl:g,Gh:b,Gl:d,Hh:x,Hl:B}=this;for(let y=0;y<80;y++){let S=P.rotrSH(f,h,14)^P.rotrSH(f,h,18)^P.rotrBH(f,h,41),U=P.rotrSL(f,h,14)^P.rotrSL(f,h,18)^P.rotrBL(f,h,41),L=f&m^~f&b,I=h&g^~h&d,k=P.add5L(B,U,I,Nf[y],Se[y]),T=P.add5H(k,x,S,L,kf[y],Ae[y]),nt=k|0,K=P.rotrSH(n,s,28)^P.rotrBH(n,s,34)^P.rotrBH(n,s,39),O=P.rotrSL(n,s,28)^P.rotrBL(n,s,34)^P.rotrBL(n,s,39),st=n&o^n&a^o&a,E=s&i^s&c^i&c;x=b|0,B=d|0,b=m|0,d=g|0,m=f|0,g=h|0,{h:f,l:h}=P.add(l|0,u|0,T|0,nt|0),l=a|0,u=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let N=P.add3L(nt,O,E);n=P.add3H(N,T,K,st),s=N|0}({h:n,l:s}=P.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=P.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=P.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=P.add(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:h}=P.add(this.Eh|0,this.El|0,f|0,h|0),{h:m,l:g}=P.add(this.Fh|0,this.Fl|0,m|0,g|0),{h:b,l:d}=P.add(this.Gh|0,this.Gl|0,b|0,d|0),{h:x,l:B}=P.add(this.Hh|0,this.Hl|0,x|0,B|0),this.set(n,s,o,i,a,c,l,u,f,h,m,g,b,d,x,B)}roundClean(){Ae.fill(0),Se.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ba=hn(()=>new oo);var mn={};At(mn,{aInRange:()=>Nt,abool:()=>Ht,abytes:()=>ir,bitGet:()=>_f,bitLen:()=>uo,bitMask:()=>Lr,bitSet:()=>Pf,bytesToHex:()=>ue,bytesToNumberBE:()=>fe,bytesToNumberLE:()=>ke,concatBytes:()=>he,createHmacDrbg:()=>fo,ensureBytes:()=>et,equalBytes:()=>Uf,hexToBytes:()=>Ke,hexToNumber:()=>lo,inRange:()=>Tr,isBytes:()=>Ie,memoized:()=>qe,notImplemented:()=>Vf,numberToBytesBE:()=>Ne,numberToBytesLE:()=>$e,numberToHexUnpadded:()=>He,numberToVarBytesBE:()=>Lf,utf8ToBytes:()=>Rf,validateObject:()=>Jt});var co=BigInt(0),gn=BigInt(1),Cf=BigInt(2);function Ie(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function ir(r){if(!Ie(r))throw new Error("Uint8Array expected")}function Ht(r,t){if(typeof t!="boolean")throw new Error(`${r} must be valid boolean, got "${t}".`)}var Tf=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function ue(r){ir(r);let t="";for(let e=0;e<r.length;e++)t+=Tf[r[e]];return t}function He(r){let t=r.toString(16);return t.length&1?`0${t}`:t}function lo(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var le={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function wa(r){if(r>=le._0&&r<=le._9)return r-le._0;if(r>=le._A&&r<=le._F)return r-(le._A-10);if(r>=le._a&&r<=le._f)return r-(le._a-10)}function Ke(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let s=0,o=0;s<e;s++,o+=2){let i=wa(r.charCodeAt(o)),a=wa(r.charCodeAt(o+1));if(i===void 0||a===void 0){let c=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function fe(r){return lo(ue(r))}function ke(r){return ir(r),lo(ue(Uint8Array.from(r).reverse()))}function Ne(r,t){return Ke(r.toString(16).padStart(t*2,"0"))}function $e(r,t){return Ne(r,t).reverse()}function Lf(r){return Ke(He(r))}function et(r,t,e){let n;if(typeof t=="string")try{n=Ke(t)}catch(o){throw new Error(`${r} must be valid hex string, got "${t}". Cause: ${o}`)}else if(Ie(t))n=Uint8Array.from(t);else throw new Error(`${r} must be hex string or Uint8Array`);let s=n.length;if(typeof e=="number"&&s!==e)throw new Error(`${r} expected ${e} bytes, got ${s}`);return n}function he(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];ir(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let o=r[n];e.set(o,s),s+=o.length}return e}function Uf(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function Rf(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}var io=r=>typeof r=="bigint"&&co<=r;function Tr(r,t,e){return io(r)&&io(t)&&io(e)&&t<=r&&r<e}function Nt(r,t,e,n){if(!Tr(t,e,n))throw new Error(`expected valid ${r}: ${e} <= n < ${n}, got ${typeof t} ${t}`)}function uo(r){let t;for(t=0;r>co;r>>=gn,t+=1);return t}function _f(r,t){return r>>BigInt(t)&gn}function Pf(r,t,e){return r|(e?gn:co)<<BigInt(t)}var Lr=r=>(Cf<<BigInt(r-1))-gn,ao=r=>new Uint8Array(r),xa=r=>Uint8Array.from(r);function fo(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=ao(r),s=ao(r),o=0,i=()=>{n.fill(1),s.fill(0),o=0},a=(...f)=>e(s,n,...f),c=(f=ao())=>{s=a(xa([0]),f),n=a(),f.length!==0&&(s=a(xa([1]),f),n=a())},l=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<t;){n=a();let m=n.slice();h.push(m),f+=n.length}return he(...h)};return(f,h)=>{i(),c(f);let m;for(;!(m=h(l()));)c();return i(),m}}var Of={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"||Ie(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Jt(r,t,e={}){let n=(s,o,i)=>{let a=Of[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);let c=r[s];if(!(i&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${o}`)};for(let[s,o]of Object.entries(t))n(s,o,!1);for(let[s,o]of Object.entries(e))n(s,o,!0);return r}var Vf=()=>{throw new Error("not implemented")};function qe(r){let t=new WeakMap;return(e,...n)=>{let s=t.get(e);if(s!==void 0)return s;let o=r(e,...n);return t.set(e,o),o}}var it=BigInt(0),X=BigInt(1),ze=BigInt(2),Df=BigInt(3),ho=BigInt(4),va=BigInt(5),Ea=BigInt(8),Mf=BigInt(9),Ff=BigInt(16);function j(r,t){let e=r%t;return e>=it?e:t+e}function Hf(r,t,e){if(e<=it||t<it)throw new Error("Expected power/modulo > 0");if(e===X)return it;let n=X;for(;t>it;)t&X&&(n=n*r%e),r=r*r%e,t>>=X;return n}function Q(r,t,e){let n=r;for(;t-- >it;)n*=n,n%=e;return n}function yn(r,t){if(r===it||t<=it)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=j(r,t),n=t,s=it,o=X,i=X,a=it;for(;e!==it;){let l=n/e,u=n%e,f=s-i*l,h=o-a*l;n=e,e=u,s=i,o=a,i=f,a=h}if(n!==X)throw new Error("invert: does not exist");return j(s,t)}function Kf(r){let t=(r-X)/ze,e,n,s;for(e=r-X,n=0;e%ze===it;e/=ze,n++);for(s=ze;s<r&&Hf(s,t,r)!==r-X;s++);if(n===1){let i=(r+X)/ho;return function(c,l){let u=c.pow(l,i);if(!c.eql(c.sqr(u),l))throw new Error("Cannot find square root");return u}}let o=(e+X)/ze;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=n,u=a.pow(a.mul(a.ONE,s),e),f=a.pow(c,o),h=a.pow(c,e);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let m=1;for(let b=a.sqr(h);m<l&&!a.eql(b,a.ONE);m++)b=a.sqr(b);let g=a.pow(u,X<<BigInt(l-m-1));u=a.sqr(g),f=a.mul(f,g),h=a.mul(h,u),l=m}return f}}function $f(r){if(r%ho===Df){let t=(r+X)/ho;return function(n,s){let o=n.pow(s,t);if(!n.eql(n.sqr(o),s))throw new Error("Cannot find square root");return o}}if(r%Ea===va){let t=(r-va)/Ea;return function(n,s){let o=n.mul(s,ze),i=n.pow(o,t),a=n.mul(s,i),c=n.mul(n.mul(a,ze),i),l=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(l),s))throw new Error("Cannot find square root");return l}}return r%Ff,Kf(r)}var Ba=(r,t)=>(j(r,t)&X)===X,qf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function po(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=qf.reduce((n,s)=>(n[s]="function",n),t);return Jt(r,e)}function zf(r,t,e){if(e<it)throw new Error("Expected power > 0");if(e===it)return r.ONE;if(e===X)return t;let n=r.ONE,s=t;for(;e>it;)e&X&&(n=r.mul(n,s)),s=r.sqr(s),e>>=X;return n}function Gf(r,t){let e=new Array(t.length),n=t.reduce((o,i,a)=>r.is0(i)?o:(e[a]=o,r.mul(o,i)),r.ONE),s=r.inv(n);return t.reduceRight((o,i,a)=>r.is0(i)?o:(e[a]=r.mul(o,e[a]),r.mul(o,i)),s),e}function go(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Ce(r,t,e=!1,n={}){if(r<=it)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:o}=go(r,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=$f(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:o,MASK:Lr(s),ZERO:it,ONE:X,create:c=>j(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return it<=c&&c<r},is0:c=>c===it,isOdd:c=>(c&X)===X,neg:c=>j(-c,r),eql:(c,l)=>c===l,sqr:c=>j(c*c,r),add:(c,l)=>j(c+l,r),sub:(c,l)=>j(c-l,r),mul:(c,l)=>j(c*l,r),pow:(c,l)=>zf(a,c,l),div:(c,l)=>j(c*yn(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>yn(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>Gf(a,c),cmov:(c,l,u)=>u?l:c,toBytes:c=>e?$e(c,o):Ne(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return e?ke(c):fe(c)}});return Object.freeze(a)}function Aa(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function mo(r){let t=Aa(r);return t+Math.ceil(t/2)}function Sa(r,t,e=!1){let n=r.length,s=Aa(t),o=mo(t);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let i=e?fe(r):ke(r),a=j(i,t-X)+X;return e?$e(a,s):Ne(a,s)}var jf=BigInt(0),yo=BigInt(1),bo=new WeakMap,Ia=new WeakMap;function bn(r,t){let e=(o,i)=>{let a=i.negate();return o?a:i},n=o=>{if(!Number.isSafeInteger(o)||o<=0||o>t)throw new Error(`Wrong window size=${o}, should be [1..${t}]`)},s=o=>{n(o);let i=Math.ceil(t/o)+1,a=2**(o-1);return{windows:i,windowSize:a}};return{constTimeNegate:e,unsafeLadder(o,i){let a=r.ZERO,c=o;for(;i>jf;)i&yo&&(a=a.add(c)),c=c.double(),i>>=yo;return a},precomputeWindow(o,i){let{windows:a,windowSize:c}=s(i),l=[],u=o,f=u;for(let h=0;h<a;h++){f=u,l.push(f);for(let m=1;m<c;m++)f=f.add(u),l.push(f);u=f.double()}return l},wNAF(o,i,a){let{windows:c,windowSize:l}=s(o),u=r.ZERO,f=r.BASE,h=BigInt(2**o-1),m=2**o,g=BigInt(o);for(let b=0;b<c;b++){let d=b*l,x=Number(a&h);a>>=g,x>l&&(x-=m,a+=yo);let B=d,y=d+Math.abs(x)-1,S=b%2!==0,U=x<0;x===0?f=f.add(e(S,i[B])):u=u.add(e(U,i[y]))}return{p:u,f}},wNAFCached(o,i,a){let c=Ia.get(o)||1,l=bo.get(o);return l||(l=this.precomputeWindow(o,c),c!==1&&bo.set(o,a(l))),this.wNAF(c,l,i)},setWindowSize(o,i){n(i),Ia.set(o,i),bo.delete(o)}}}function wn(r,t,e,n){if(!Array.isArray(e)||!Array.isArray(n)||n.length!==e.length)throw new Error("arrays of points and scalars must have equal length");n.forEach((u,f)=>{if(!t.isValid(u))throw new Error(`wrong scalar at index ${f}`)}),e.forEach((u,f)=>{if(!(u instanceof r))throw new Error(`wrong point at index ${f}`)});let s=uo(BigInt(e.length)),o=s>12?s-3:s>4?s-2:s?2:1,i=(1<<o)-1,a=new Array(i+1).fill(r.ZERO),c=Math.floor((t.BITS-1)/o)*o,l=r.ZERO;for(let u=c;u>=0;u-=o){a.fill(r.ZERO);for(let h=0;h<n.length;h++){let m=n[h],g=Number(m>>BigInt(u)&BigInt(i));a[g]=a[g].add(e[h])}let f=r.ZERO;for(let h=a.length-1,m=r.ZERO;h>0;h--)m=m.add(a[h]),f=f.add(m);if(l=l.add(f),u!==0)for(let h=0;h<o;h++)l=l.double()}return l}function Ur(r){return po(r.Fp),Jt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...go(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Kt=BigInt(0),Ct=BigInt(1),xn=BigInt(2),Zf=BigInt(8),Yf={zip215:!0};function Jf(r){let t=Ur(r);return Jt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function ka(r){let t=Jf(r),{Fp:e,n,prehash:s,hash:o,randomBytes:i,nByteLength:a,h:c}=t,l=xn<<BigInt(a*8)-Ct,u=e.create,f=Ce(t.n,t.nBitLength),h=t.uvRatio||((w,p)=>{try{return{isValid:!0,value:e.sqrt(w*e.inv(p))}}catch{return{isValid:!1,value:Kt}}}),m=t.adjustScalarBytes||(w=>w),g=t.domain||((w,p,v)=>{if(Ht("phflag",v),p.length||v)throw new Error("Contexts/pre-hash are not supported");return w});function b(w,p){Nt("coordinate "+w,p,Kt,l)}function d(w){if(!(w instanceof y))throw new Error("ExtendedPoint expected")}let x=qe((w,p)=>{let{ex:v,ey:C,ez:R}=w,_=w.is0();p==null&&(p=_?Zf:e.inv(R));let V=u(v*p),F=u(C*p),D=u(R*p);if(_)return{x:Kt,y:Ct};if(D!==Ct)throw new Error("invZ was invalid");return{x:V,y:F}}),B=qe(w=>{let{a:p,d:v}=t;if(w.is0())throw new Error("bad point: ZERO");let{ex:C,ey:R,ez:_,et:V}=w,F=u(C*C),D=u(R*R),W=u(_*_),Y=u(W*W),lt=u(F*p),ut=u(W*u(lt+D)),ht=u(Y+u(v*u(F*D)));if(ut!==ht)throw new Error("bad point: equation left != right (1)");let Bt=u(C*R),ot=u(_*V);if(Bt!==ot)throw new Error("bad point: equation left != right (2)");return!0});class y{constructor(p,v,C,R){this.ex=p,this.ey=v,this.ez=C,this.et=R,b("x",p),b("y",v),b("z",C),b("t",R),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof y)throw new Error("extended point not allowed");let{x:v,y:C}=p||{};return b("x",v),b("y",C),new y(v,C,Ct,u(v*C))}static normalizeZ(p){let v=e.invertBatch(p.map(C=>C.ez));return p.map((C,R)=>C.toAffine(v[R])).map(y.fromAffine)}static msm(p,v){return wn(y,f,p,v)}_setWindowSize(p){L.setWindowSize(this,p)}assertValidity(){B(this)}equals(p){d(p);let{ex:v,ey:C,ez:R}=this,{ex:_,ey:V,ez:F}=p,D=u(v*F),W=u(_*R),Y=u(C*F),lt=u(V*R);return D===W&&Y===lt}is0(){return this.equals(y.ZERO)}negate(){return new y(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:p}=t,{ex:v,ey:C,ez:R}=this,_=u(v*v),V=u(C*C),F=u(xn*u(R*R)),D=u(p*_),W=v+C,Y=u(u(W*W)-_-V),lt=D+V,ut=lt-F,ht=D-V,Bt=u(Y*ut),ot=u(lt*ht),kt=u(Y*ht),oe=u(ut*lt);return new y(Bt,ot,oe,kt)}add(p){d(p);let{a:v,d:C}=t,{ex:R,ey:_,ez:V,et:F}=this,{ex:D,ey:W,ez:Y,et:lt}=p;if(v===BigInt(-1)){let Ki=u((_-R)*(W+D)),$i=u((_+R)*(W-D)),$s=u($i-Ki);if($s===Kt)return this.double();let qi=u(V*xn*lt),zi=u(F*xn*Y),Gi=zi+qi,Wi=$i+Ki,ji=zi-qi,iu=u(Gi*$s),au=u(Wi*ji),cu=u(Gi*ji),lu=u($s*Wi);return new y(iu,au,lu,cu)}let ut=u(R*D),ht=u(_*W),Bt=u(F*C*lt),ot=u(V*Y),kt=u((R+_)*(D+W)-ut-ht),oe=ot-Bt,Er=ot+Bt,Br=u(ht-v*ut),ru=u(kt*oe),nu=u(Er*Br),su=u(kt*Br),ou=u(oe*Er);return new y(ru,nu,ou,su)}subtract(p){return this.add(p.negate())}wNAF(p){return L.wNAFCached(this,p,y.normalizeZ)}multiply(p){let v=p;Nt("scalar",v,Ct,n);let{p:C,f:R}=this.wNAF(v);return y.normalizeZ([C,R])[0]}multiplyUnsafe(p){let v=p;return Nt("scalar",v,Kt,n),v===Kt?U:this.equals(U)||v===Ct?this:this.equals(S)?this.wNAF(v).p:L.unsafeLadder(this,v)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return L.unsafeLadder(this,n).is0()}toAffine(p){return x(this,p)}clearCofactor(){let{h:p}=t;return p===Ct?this:this.multiplyUnsafe(p)}static fromHex(p,v=!1){let{d:C,a:R}=t,_=e.BYTES;p=et("pointHex",p,_),Ht("zip215",v);let V=p.slice(),F=p[_-1];V[_-1]=F&-129;let D=ke(V),W=v?l:e.ORDER;Nt("pointHex.y",D,Kt,W);let Y=u(D*D),lt=u(Y-Ct),ut=u(C*Y-R),{isValid:ht,value:Bt}=h(lt,ut);if(!ht)throw new Error("Point.fromHex: invalid y coordinate");let ot=(Bt&Ct)===Ct,kt=(F&128)!==0;if(!v&&Bt===Kt&&kt)throw new Error("Point.fromHex: x=0 and x_0=1");return kt!==ot&&(Bt=u(-Bt)),y.fromAffine({x:Bt,y:D})}static fromPrivateKey(p){return T(p).point}toRawBytes(){let{x:p,y:v}=this.toAffine(),C=$e(v,e.BYTES);return C[C.length-1]|=p&Ct?128:0,C}toHex(){return ue(this.toRawBytes())}}y.BASE=new y(t.Gx,t.Gy,Ct,u(t.Gx*t.Gy)),y.ZERO=new y(Kt,Ct,Ct,Kt);let{BASE:S,ZERO:U}=y,L=bn(y,a*8);function I(w){return j(w,n)}function k(w){return I(ke(w))}function T(w){let p=a;w=et("private key",w,p);let v=et("hashed private key",o(w),2*p),C=m(v.slice(0,p)),R=v.slice(p,2*p),_=k(C),V=S.multiply(_),F=V.toRawBytes();return{head:C,prefix:R,scalar:_,point:V,pointBytes:F}}function nt(w){return T(w).pointBytes}function K(w=new Uint8Array,...p){let v=he(...p);return k(o(g(v,et("context",w),!!s)))}function O(w,p,v={}){w=et("message",w),s&&(w=s(w));let{prefix:C,scalar:R,pointBytes:_}=T(p),V=K(v.context,C,w),F=S.multiply(V).toRawBytes(),D=K(v.context,F,_,w),W=I(V+D*R);Nt("signature.s",W,Kt,n);let Y=he(F,$e(W,e.BYTES));return et("result",Y,a*2)}let st=Yf;function E(w,p,v,C=st){let{context:R,zip215:_}=C,V=e.BYTES;w=et("signature",w,2*V),p=et("message",p),_!==void 0&&Ht("zip215",_),s&&(p=s(p));let F=ke(w.slice(V,2*V)),D,W,Y;try{D=y.fromHex(v,_),W=y.fromHex(w.slice(0,V),_),Y=S.multiplyUnsafe(F)}catch{return!1}if(!_&&D.isSmallOrder())return!1;let lt=K(R,W.toRawBytes(),D.toRawBytes(),p);return W.add(D.multiplyUnsafe(lt)).subtract(Y).clearCofactor().equals(y.ZERO)}return S._setWindowSize(8),{CURVE:t,getPublicKey:nt,sign:O,verify:E,ExtendedPoint:y,utils:{getExtendedPublicKey:T,randomPrivateKey:()=>i(e.BYTES),precompute(w=8,p=y.BASE){return p._setWindowSize(w),p.multiply(BigInt(3)),p}}}}var wo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Na=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Ep=BigInt(0),Xf=BigInt(1),Ca=BigInt(2),Bp=BigInt(3),Qf=BigInt(5),th=BigInt(8);function eh(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),s=BigInt(80),o=wo,a=r*r%o*r%o,c=Q(a,Ca,o)*a%o,l=Q(c,Xf,o)*r%o,u=Q(l,Qf,o)*l%o,f=Q(u,t,o)*u%o,h=Q(f,e,o)*f%o,m=Q(h,n,o)*h%o,g=Q(m,s,o)*m%o,b=Q(g,s,o)*m%o,d=Q(b,t,o)*u%o;return{pow_p_5_8:Q(d,Ca,o)*r%o,b2:a}}function rh(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function nh(r,t){let e=wo,n=j(t*t*t,e),s=j(n*n*t,e),o=eh(r*s).pow_p_5_8,i=j(r*n*o,e),a=j(t*i*i,e),c=i,l=j(i*Na,e),u=a===r,f=a===j(-r,e),h=a===j(-r*Na,e);return u&&(i=c),(f||h)&&(i=l),Ba(i,e)&&(i=j(-i,e)),{isValid:u||f,value:i}}var sh=Ce(wo,void 0,!0),oh={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:sh,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:th,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ba,randomBytes:dn,adjustScalarBytes:rh,uvRatio:nh},Ta=ka(oh);var vn=32;function La(r,t,e){return Ta.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var En=class{type="Ed25519";raw;constructor(t){this.raw=xo(t,vn)}toMultihash(){return ce.digest(Te(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e){return La(this.raw,e,t)}};function vo(r){return r=xo(r,vn),new En(r)}function xo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new St(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function pt(r=0){return new Uint8Array(r)}function Tt(r=0){return new Uint8Array(r)}var ah=Math.pow(2,7),ch=Math.pow(2,14),lh=Math.pow(2,21),Eo=Math.pow(2,28),Bo=Math.pow(2,35),Ao=Math.pow(2,42),So=Math.pow(2,49),G=128,wt=127;function xt(r){if(r<ah)return 1;if(r<ch)return 2;if(r<lh)return 3;if(r<Eo)return 4;if(r<Bo)return 5;if(r<Ao)return 6;if(r<So)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Io(r,t,e=0){switch(xt(r)){case 8:t[e++]=r&255|G,r/=128;case 7:t[e++]=r&255|G,r/=128;case 6:t[e++]=r&255|G,r/=128;case 5:t[e++]=r&255|G,r/=128;case 4:t[e++]=r&255|G,r>>>=7;case 3:t[e++]=r&255|G,r>>>=7;case 2:t[e++]=r&255|G,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function uh(r,t,e=0){switch(xt(r)){case 8:t.set(e++,r&255|G),r/=128;case 7:t.set(e++,r&255|G),r/=128;case 6:t.set(e++,r&255|G),r/=128;case 5:t.set(e++,r&255|G),r/=128;case 4:t.set(e++,r&255|G),r>>>=7;case 3:t.set(e++,r&255|G),r>>>=7;case 2:t.set(e++,r&255|G),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function ko(r,t){let e=r[t],n=0;if(n+=e&wt,e<G||(e=r[t+1],n+=(e&wt)<<7,e<G)||(e=r[t+2],n+=(e&wt)<<14,e<G)||(e=r[t+3],n+=(e&wt)<<21,e<G)||(e=r[t+4],n+=(e&wt)*Eo,e<G)||(e=r[t+5],n+=(e&wt)*Bo,e<G)||(e=r[t+6],n+=(e&wt)*Ao,e<G)||(e=r[t+7],n+=(e&wt)*So,e<G))return n;throw new RangeError("Could not decode varint")}function fh(r,t){let e=r.get(t),n=0;if(n+=e&wt,e<G||(e=r.get(t+1),n+=(e&wt)<<7,e<G)||(e=r.get(t+2),n+=(e&wt)<<14,e<G)||(e=r.get(t+3),n+=(e&wt)<<21,e<G)||(e=r.get(t+4),n+=(e&wt)*Eo,e<G)||(e=r.get(t+5),n+=(e&wt)*Bo,e<G)||(e=r.get(t+6),n+=(e&wt)*Ao,e<G)||(e=r.get(t+7),n+=(e&wt)*So,e<G))return n;throw new RangeError("Could not decode varint")}function Pt(r,t,e=0){return t==null&&(t=Tt(xt(r))),t instanceof Uint8Array?Io(r,t,e):uh(r,t,e)}function de(r,t=0){return r instanceof Uint8Array?ko(r,t):fh(r,t)}var No=new Float32Array([-0]),Le=new Uint8Array(No.buffer);function Ra(r,t,e){No[0]=r,t[e]=Le[0],t[e+1]=Le[1],t[e+2]=Le[2],t[e+3]=Le[3]}function _a(r,t){return Le[0]=r[t],Le[1]=r[t+1],Le[2]=r[t+2],Le[3]=r[t+3],No[0]}var Co=new Float64Array([-0]),vt=new Uint8Array(Co.buffer);function Pa(r,t,e){Co[0]=r,t[e]=vt[0],t[e+1]=vt[1],t[e+2]=vt[2],t[e+3]=vt[3],t[e+4]=vt[4],t[e+5]=vt[5],t[e+6]=vt[6],t[e+7]=vt[7]}function Oa(r,t){return vt[0]=r[t],vt[1]=r[t+1],vt[2]=r[t+2],vt[3]=r[t+3],vt[4]=r[t+4],vt[5]=r[t+5],vt[6]=r[t+6],vt[7]=r[t+7],Co[0]}var hh=BigInt(Number.MAX_SAFE_INTEGER),dh=BigInt(Number.MIN_SAFE_INTEGER),Rt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Ge;if(t<hh&&t>dh)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,s=t-(n<<32n);return e&&(n=~n|0n,s=~s|0n,++s>Va&&(s=0n,++n>Va&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return Ge;let e=t<0;e&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return e&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):Ge}},Ge=new Rt(0,0);Ge.toBigInt=function(){return 0n};Ge.zzEncode=Ge.zzDecode=function(){return this};Ge.length=function(){return 1};var Va=4294967296n;function Da(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Ma(r,t,e){if(e-t<1)return"";let s,o=[],i=0,a;for(;t<e;)a=r[t++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function To(r,t,e){let n=e,s,o;for(let i=0;i<r.length;++i)s=r.charCodeAt(i),s<128?t[e++]=s:s<2048?(t[e++]=s>>6|192,t[e++]=s&63|128):(s&64512)===55296&&((o=r.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,t[e++]=s>>18|240,t[e++]=s>>12&63|128,t[e++]=s>>6&63|128,t[e++]=s&63|128):(t[e++]=s>>12|224,t[e++]=s>>6&63|128,t[e++]=s&63|128);return e-n}function $t(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function An(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Lo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,$t(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw $t(this,4);return An(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw $t(this,4);return An(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw $t(this,4);let t=_a(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw $t(this,4);let t=Oa(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw $t(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Ma(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw $t(this,t);this.pos+=t}else do if(this.pos>=this.len)throw $t(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Rt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw $t(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw $t(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw $t(this,8);let t=An(this.buf,this.pos+=4),e=An(this.buf,this.pos+=4);return new Rt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=ko(this.buf,this.pos);return this.pos+=xt(t),t}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 Uo(r){return new Lo(r instanceof Uint8Array?r:r.subarray())}function qt(r,t,e){let n=Uo(r);return t.decode(n,void 0,e)}var Ro={};At(Ro,{base10:()=>ph});var ph=Ee({prefix:"9",name:"base10",alphabet:"0123456789"});var _o={};At(_o,{base16:()=>gh,base16upper:()=>mh});var gh=tt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),mh=tt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Po={};At(Po,{base2:()=>yh});var yh=tt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Oo={};At(Oo,{base256emoji:()=>Eh});var Ha=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}"),bh=Ha.reduce((r,t,e)=>(r[e]=t,r),[]),wh=Ha.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function xh(r){return r.reduce((t,e)=>(t+=bh[e],t),"")}function vh(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let s=wh[n];if(s==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(s)}return new Uint8Array(t)}var Eh=Xe({prefix:"\u{1F680}",name:"base256emoji",encode:xh,decode:vh});var Do={};At(Do,{base64:()=>Bh,base64pad:()=>Ah,base64url:()=>Vo,base64urlpad:()=>Sh});var Bh=tt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ah=tt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Vo=tt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Sh=tt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Mo={};At(Mo,{base8:()=>Ih});var Ih=tt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Fo={};At(Fo,{identity:()=>kh});var kh=Xe({prefix:"\0",name:"identity",encode:r=>Xi(r),decode:r=>Ji(r)});var og=new TextEncoder,ig=new TextDecoder;var $o={};At($o,{sha256:()=>Rr,sha512:()=>Th});function Ko({name:r,code:t,encode:e}){return new Ho(r,t,e)}var Ho=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Mt(this.code,e):e.then(n=>Mt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function $a(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Rr=Ko({name:"sha2-256",code:18,encode:$a("SHA-256")}),Th=Ko({name:"sha2-512",code:19,encode:$a("SHA-512")});var _r={...Fo,...Po,...Mo,...Ro,..._o,...Xs,...Qs,...Js,...Do,...Oo},bg={...$o,...ro};function za(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var qa=za("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),qo=za("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=Tt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Lh={utf8:qa,"utf-8":qa,hex:_r.base16,latin1:qo,ascii:qo,binary:qo,..._r},Sn=Lh;function $(r,t="utf8"){let e=Sn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function zo(r){let t=r??8192,e=t>>>1,n,s=t;return function(i){if(i<1||i>e)return Tt(i);s+i>t&&(n=Tt(t),s=0);let a=n.subarray(s,s+=i);return s&7&&(s=(s|7)+1),a}}var We=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Go(){}var jo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Uh=zo();function Rh(r){return globalThis.Buffer!=null?Tt(r):Uh(r)}var Or=class{len;head;tail;states;constructor(){this.len=0,this.head=new We(Go,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new We(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Zo((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(In,10,Rt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Rt.fromBigInt(t);return this._push(In,e.length(),e)}uint64Number(t){return this._push(Io,xt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Rt.fromBigInt(t).zzEncode();return this._push(In,e.length(),e)}sint64Number(t){let e=Rt.fromNumber(t).zzEncode();return this._push(In,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Wo,1,t?1:0)}fixed32(t){return this._push(Pr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Rt.fromBigInt(t);return this._push(Pr,4,e.lo)._push(Pr,4,e.hi)}fixed64Number(t){let e=Rt.fromNumber(t);return this._push(Pr,4,e.lo)._push(Pr,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Ra,4,t)}double(t){return this._push(Pa,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Wo,1,0):this.uint32(e)._push(Ph,e,t)}string(t){let e=Da(t);return e!==0?this.uint32(e)._push(To,e,t):this._push(Wo,1,0)}fork(){return this.states=new jo(this),this.head=this.tail=new We(Go,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 We(Go,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Rh(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Wo(r,t,e){t[e]=r&255}function _h(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Zo=class extends We{next;constructor(t,e){super(_h,t,e),this.next=void 0}};function In(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Pr(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Ph(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Or.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Oh,t,r),this},Or.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Vh,t,r),this});function Oh(r,t,e){t.set(r,e)}function Vh(r,t,e){r.length<40?To(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set($(r),e)}function Yo(){return new Or}function zt(r,t){let e=Yo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var ar;(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"})(ar||(ar={}));function kn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Jo(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(o,i){let a=t(o);i.int32(a)},n=function(o){let i=o.int32();return t(i)};return kn("enum",ar.VARINT,e,n)}function Gt(r,t){return kn("message",ar.LENGTH_DELIMITED,r,t)}var je=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var at;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(at||(at={}));var Xo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(Xo||(Xo={}));(function(r){r.codec=()=>Jo(Xo)})(at||(at={}));var Xt;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),at.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.Type=at.codec().decode(e);break}case 2:{o.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>qt(e,r.codec(),n)})(Xt||(Xt={}));var Qo;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),at.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.Type=at.codec().decode(e);break}case 2:{o.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>qt(e,r.codec(),n)})(Qo||(Qo={}));var Gr={};At(Gr,{MAX_RSA_KEY_SIZE:()=>bs,generateRSAKeyPair:()=>Kc,jwkToJWKKeyPair:()=>$c,jwkToPkcs1:()=>Qh,jwkToPkix:()=>ci,jwkToRSAPrivateKey:()=>Hc,pkcs1ToJwk:()=>Dc,pkcs1ToRSAPrivateKey:()=>Fc,pkixToJwk:()=>Mc,pkixToRSAPublicKey:()=>li});var Dh=new Uint32Array([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]),Ue=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Re=new Uint32Array(64),ti=class extends or{constructor(){super(64,32,8,!1),this.A=Ue[0]|0,this.B=Ue[1]|0,this.C=Ue[2]|0,this.D=Ue[3]|0,this.E=Ue[4]|0,this.F=Ue[5]|0,this.G=Ue[6]|0,this.H=Ue[7]|0}get(){let{A:t,B:e,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[t,e,n,s,o,i,a,c]}set(t,e,n,s,o,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)Re[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let h=Re[f-15],m=Re[f-2],g=Ft(h,7)^Ft(h,18)^h>>>3,b=Ft(m,17)^Ft(m,19)^m>>>10;Re[f]=b+Re[f-7]+g+Re[f-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let h=Ft(a,6)^Ft(a,11)^Ft(a,25),m=u+h+ga(a,c,l)+Dh[f]+Re[f]|0,b=(Ft(n,2)^Ft(n,13)^Ft(n,22))+ma(n,s,o)|0;u=l,l=c,c=a,a=i+m|0,i=o,o=s,s=n,n=m+b|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,s,o,i,a,c,l,u)}roundClean(){Re.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var cr=hn(()=>new ti);var M=zs(Wa());function Ze(r,t){let e=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)e+=r[r.length-1-n]*Math.pow(2,t*n);return e}function _e(r,t,e=-1){let n=e,s=r,o=0,i=Math.pow(2,t);for(let a=1;a<8;a++){if(r<i){let c;if(n<0)c=new ArrayBuffer(a),o=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),o=n}let l=new Uint8Array(c);for(let u=a-1;u>=0;u--){let f=Math.pow(2,u*t);l[o-u-1]=Math.floor(s/f),s-=l[o-u-1]*f}return c}i*=Math.pow(2,t)}return new ArrayBuffer(0)}function Tn(...r){let t=0,e=0;for(let o of r)t+=o.length;let n=new ArrayBuffer(t),s=new Uint8Array(n);for(let o of r)s.set(o,e),e+=o.length;return s}function ri(){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 t=new ArrayBuffer(this.valueHex.byteLength),e=new Uint8Array(t);for(let a=0;a<this.valueHex.byteLength;a++)e[a]=0;e[0]=r[0]&128;let n=Ze(e,8),s=new ArrayBuffer(this.valueHex.byteLength),o=new Uint8Array(s);for(let a=0;a<this.valueHex.byteLength;a++)o[a]=r[a];return o[0]&=127,Ze(o,8)-n}function ja(r){let t=r<0?r*-1:r,e=128;for(let n=1;n<8;n++){if(t<=e){if(r<0){let i=e-t,a=_e(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=_e(t,8,n),o=new Uint8Array(s);if(o[0]&128){let i=s.slice(0),a=new Uint8Array(i);s=new ArrayBuffer(s.byteLength+1),o=new Uint8Array(s);for(let c=0;c<i.byteLength;c++)o[c+1]=a[c];o[0]=0}return s}e*=Math.pow(2,8)}return new ArrayBuffer(0)}function Za(r,t){if(r.byteLength!==t.byteLength)return!1;let e=new Uint8Array(r),n=new Uint8Array(t);for(let s=0;s<e.length;s++)if(e[s]!==n[s])return!1;return!0}function Lt(r,t){let e=r.toString(10);if(t<e.length)return"";let n=t-e.length,s=new Array(n);for(let i=0;i<n;i++)s[i]="0";return s.join("").concat(e)}var Qg=Math.log(2);function Ln(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function ni(r){let t=0,e=0;for(let s=0;s<r.length;s++){let o=r[s];t+=o.byteLength}let n=new Uint8Array(t);for(let s=0;s<r.length;s++){let o=r[s];n.set(new Uint8Array(o),e),e+=o.byteLength}return n.buffer}function be(r,t,e,n){return t instanceof Uint8Array?t.byteLength?e<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):t.byteLength-e-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 Dr=class{constructor(){this.items=[]}write(t){this.items.push(t)}final(){return ni(this.items)}},Vr=[new Uint8Array([1])],Ya="0123456789";var dr="",Wt=new ArrayBuffer(0),si=new Uint8Array(0),Mr="EndOfContent",Xa="OCTET STRING",Qa="BIT STRING";function we(r){var t;return t=class extends r{constructor(...n){var s;super(...n);let o=n[0]||{};this.isHexOnly=(s=o.isHexOnly)!==null&&s!==void 0?s:!1,this.valueHexView=o.valueHex?M.BufferSourceConverter.toUint8Array(o.valueHex):si}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,s,o){let i=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!be(this,i,s,o))return-1;let a=s+o;return this.valueHexView=i.subarray(s,a),this.valueHexView.length?(this.blockLength=o,a):(this.warnings.push("Zero buffer length"),s)}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",Wt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:M.Convert.ToHex(this.valueHexView)}}},t.NAME="hexBlock",t}var ge=class{constructor({blockLength:t=0,error:e=dr,warnings:n=[],valueBeforeDecode:s=si}={}){this.blockLength=t,this.error=e,this.warnings=n,this.valueBeforeDecodeView=M.BufferSourceConverter.toUint8Array(s)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(t){this.valueBeforeDecodeView=new Uint8Array(t)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:M.Convert.ToHex(this.valueBeforeDecodeView)}}};ge.NAME="baseBlock";var Et=class extends ge{fromBER(t,e,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(t,e){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};Et.NAME="valueBlock";var Un=class extends we(ge){constructor({idBlock:t={}}={}){var e,n,s,o;super(),t?(this.isHexOnly=(e=t.isHexOnly)!==null&&e!==void 0?e:!1,this.valueHexView=t.valueHex?M.BufferSourceConverter.toUint8Array(t.valueHex):si,this.tagClass=(n=t.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=t.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(o=t.isConstructed)!==null&&o!==void 0?o:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(t=!1){let e=0;switch(this.tagClass){case 1:e|=0;break;case 2:e|=64;break;case 3:e|=128;break;case 4:e|=192;break;default:return this.error="Unknown tag class",Wt}if(this.isConstructed&&(e|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!t){let o=this.tagNumber;o&=31,e|=o,s[0]=e}return s.buffer}if(!this.isHexOnly){let s=_e(this.tagNumber,7),o=new Uint8Array(s),i=s.byteLength,a=new Uint8Array(i+1);if(a[0]=e|31,!t){for(let c=0;c<i-1;c++)a[c+1]=o[c]|128;a[i]=o[i-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=e|31,!t){let s=this.valueHexView;for(let o=0;o<s.length-1;o++)n[o+1]=s[o]|128;n[this.valueHexView.byteLength]=s[s.length-1]}return n.buffer}fromBER(t,e,n){let s=M.BufferSourceConverter.toUint8Array(t);if(!be(this,s,e,n))return-1;let o=s.subarray(e,e+n);if(o.length===0)return this.error="Zero buffer length",-1;switch(o[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=(o[0]&32)===32,this.isHexOnly=!1;let a=o[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,l=this.valueHexView=new Uint8Array(255),u=255;for(;o[c]&128;){if(l[c-1]=o[c]&127,c++,c>=o.length)return this.error="End of input reached before message was fully decoded",-1;if(c===u){u+=255;let h=new Uint8Array(u);for(let m=0;m<l.length;m++)h[m]=l[m];l=this.valueHexView=new Uint8Array(u)}}this.blockLength=c+1,l[c-1]=o[c]&127;let f=new Uint8Array(c);for(let h=0;h<c;h++)f[h]=l[h];l=this.valueHexView=new Uint8Array(c),l.set(f),this.blockLength<=9?this.tagNumber=Ze(l,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return e+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};Un.NAME="identificationBlock";var Rn=class extends ge{constructor({lenBlock:t={}}={}){var e,n,s;super(),this.isIndefiniteForm=(e=t.isIndefiniteForm)!==null&&e!==void 0?e:!1,this.longFormUsed=(n=t.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(s=t.length)!==null&&s!==void 0?s:0}fromBER(t,e,n){let s=M.BufferSourceConverter.toUint8Array(t);if(!be(this,s,e,n))return-1;let o=s.subarray(e,e+n);if(o.length===0)return this.error="Zero buffer length",-1;if(o[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=o[0]===128,this.isIndefiniteForm)return this.blockLength=1,e+this.blockLength;if(this.longFormUsed=!!(o[0]&128),this.longFormUsed===!1)return this.length=o[0],this.blockLength=1,e+this.blockLength;let i=o[0]&127;if(i>8)return this.error="Too big integer",-1;if(i+1>o.length)return this.error="End of input reached before message was fully decoded",-1;let a=e+1,c=s.subarray(a,a+i);return c[i-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Ze(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=i+1,e+this.blockLength}toBER(t=!1){let e,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return e=new ArrayBuffer(1),t===!1&&(n=new Uint8Array(e),n[0]=128),e;if(this.longFormUsed){let s=_e(this.length,8);if(s.byteLength>127)return this.error="Too big length",Wt;if(e=new ArrayBuffer(s.byteLength+1),t)return e;let o=new Uint8Array(s);n=new Uint8Array(e),n[0]=s.byteLength|128;for(let i=0;i<s.byteLength;i++)n[i+1]=o[i];return e}return e=new ArrayBuffer(1),t===!1&&(n=new Uint8Array(e),n[0]=this.length),e}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Rn.NAME="lengthBlock";var A={},gt=class extends ge{constructor({name:t=dr,optional:e=!1,primitiveSchema:n,...s}={},o){super(s),this.name=t,this.optional=e,n&&(this.primitiveSchema=n),this.idBlock=new Un(s),this.lenBlock=new Rn(s),this.valueBlock=o?new o(s):new Et(s)}fromBER(t,e,n){let s=this.valueBlock.fromBER(t,e,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(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),s)}toBER(t,e){let n=e||new Dr;e||tc(this);let s=this.idBlock.toBER(t);if(n.write(s),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(t,n),n.write(new ArrayBuffer(2));else{let o=this.valueBlock.toBER(t);this.lenBlock.length=o.byteLength;let i=this.lenBlock.toBER(t);n.write(i),n.write(o)}return e?Wt:n.final()}toJSON(){let t={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(t.primitiveSchema=this.primitiveSchema.toJSON()),t}toString(t="ascii"){return t==="ascii"?this.onAsciiEncoding():M.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${M.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(t){if(this===t)return!0;if(!(t instanceof this.constructor))return!1;let e=this.toBER(),n=t.toBER();return Za(e,n)}};gt.NAME="BaseBlock";function tc(r){if(r instanceof A.Constructed)for(let t of r.valueBlock.value)tc(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var _n=class extends gt{constructor({value:t=dr,...e}={},n){super(e,n),t&&this.fromString(t)}getValue(){return this.valueBlock.value}setValue(t){this.valueBlock.value=t}fromBER(t,e,n){let s=this.valueBlock.fromBER(t,e,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(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),s)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};_n.NAME="BaseStringBlock";var Pn=class extends we(Et){constructor({isHexOnly:t=!0,...e}={}){super(e),this.isHexOnly=t}};Pn.NAME="PrimitiveValueBlock";var ec,On=class extends gt{constructor(t={}){super(t,Pn),this.idBlock.isConstructed=!1}};ec=On;A.Primitive=ec;On.NAME="PRIMITIVE";function Wh(r,t){if(r instanceof t)return r;let e=new t;return e.idBlock=r.idBlock,e.lenBlock=r.lenBlock,e.warnings=r.warnings,e.valueBeforeDecodeView=r.valueBeforeDecodeView,e}function ms(r,t=0,e=r.length){let n=t,s=new gt({},Et),o=new ge;if(!be(o,r,t,e))return s.error=o.error,{offset:-1,result:s};if(!r.subarray(t,t+e).length)return s.error="Zero buffer length",{offset:-1,result:s};let a=s.idBlock.fromBER(r,t,e);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),a===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(t=a,e-=s.idBlock.blockLength,a=s.lenBlock.fromBER(r,t,e),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),a===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(t=a,e-=s.lenBlock.blockLength,!s.idBlock.isConstructed&&s.lenBlock.isIndefiniteForm)return s.error="Indefinite length form used for primitive encoding form",{offset:-1,result:s};let c=gt;switch(s.idBlock.tagClass){case 1:if(s.idBlock.tagNumber>=37&&s.idBlock.isHexOnly===!1)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};c=A.EndOfContent;break;case 1:c=A.Boolean;break;case 2:c=A.Integer;break;case 3:c=A.BitString;break;case 4:c=A.OctetString;break;case 5:c=A.Null;break;case 6:c=A.ObjectIdentifier;break;case 10:c=A.Enumerated;break;case 12:c=A.Utf8String;break;case 13:c=A.RelativeObjectIdentifier;break;case 14:c=A.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=A.Sequence;break;case 17:c=A.Set;break;case 18:c=A.NumericString;break;case 19:c=A.PrintableString;break;case 20:c=A.TeletexString;break;case 21:c=A.VideotexString;break;case 22:c=A.IA5String;break;case 23:c=A.UTCTime;break;case 24:c=A.GeneralizedTime;break;case 25:c=A.GraphicString;break;case 26:c=A.VisibleString;break;case 27:c=A.GeneralString;break;case 28:c=A.UniversalString;break;case 29:c=A.CharacterString;break;case 30:c=A.BmpString;break;case 31:c=A.DATE;break;case 32:c=A.TimeOfDay;break;case 33:c=A.DateTime;break;case 34:c=A.Duration;break;default:{let l=s.idBlock.isConstructed?new A.Constructed:new A.Primitive;l.idBlock=s.idBlock,l.lenBlock=s.lenBlock,l.warnings=s.warnings,s=l}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?A.Constructed:A.Primitive}return s=Wh(s,c),a=s.fromBER(r,t,s.lenBlock.isIndefiniteForm?e:s.lenBlock.length),s.valueBeforeDecodeView=r.subarray(n,n+s.blockLength),{offset:a,result:s}}function oi(r){if(!r.byteLength){let t=new gt({},Et);return t.error="Input buffer has zero length",{offset:-1,result:t}}return ms(M.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function jh(r,t){return r?1:t}var Qt=class extends Et{constructor({value:t=[],isIndefiniteForm:e=!1,...n}={}){super(n),this.value=t,this.isIndefiniteForm=e}fromBER(t,e,n){let s=M.BufferSourceConverter.toUint8Array(t);if(!be(this,s,e,n))return-1;if(this.valueBeforeDecodeView=s.subarray(e,e+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),e;let o=e;for(;jh(this.isIndefiniteForm,n)>0;){let i=ms(s,o,n);if(i.offset===-1)return this.error=i.result.error,this.warnings.concat(i.result.warnings),-1;if(o=i.offset,this.blockLength+=i.result.blockLength,n-=i.result.blockLength,this.value.push(i.result),this.isIndefiniteForm&&i.result.constructor.NAME===Mr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Mr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(t,e){let n=e||new Dr;for(let s=0;s<this.value.length;s++)this.value[s].toBER(t,n);return e?Wt:n.final()}toJSON(){let t={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let e of this.value)t.value.push(e.toJSON());return t}};Qt.NAME="ConstructedValueBlock";var rc,Pe=class extends gt{constructor(t={}){super(t,Qt),this.idBlock.isConstructed=!0}fromBER(t,e,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let s=this.valueBlock.fromBER(t,e,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(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),s)}onAsciiEncoding(){let t=[];for(let n of this.valueBlock.value)t.push(n.toString("ascii").split(`
|
|
3
|
+
`).map(s=>` ${s}`).join(`
|
|
4
|
+
`));let e=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return t.length?`${e} :
|
|
5
|
+
${t.join(`
|
|
6
|
+
`)}`:`${e} :`}};rc=Pe;A.Constructed=rc;Pe.NAME="CONSTRUCTED";var Vn=class extends Et{fromBER(t,e,n){return e}toBER(t){return Wt}};Vn.override="EndOfContentValueBlock";var nc,Dn=class extends gt{constructor(t={}){super(t,Vn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};nc=Dn;A.EndOfContent=nc;Dn.NAME=Mr;var sc,ur=class extends gt{constructor(t={}){super(t,Et),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(t,e,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,e+n>t.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):e+n}toBER(t,e){let n=new ArrayBuffer(2);if(!t){let s=new Uint8Array(n);s[0]=5,s[1]=0}return e&&e.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};sc=ur;A.Null=sc;ur.NAME="NULL";var Mn=class extends we(Et){constructor({value:t,...e}={}){super(e),e.valueHex?this.valueHexView=M.BufferSourceConverter.toUint8Array(e.valueHex):this.valueHexView=new Uint8Array(1),t&&(this.value=t)}get value(){for(let t of this.valueHexView)if(t>0)return!0;return!1}set value(t){this.valueHexView[0]=t?255:0}fromBER(t,e,n){let s=M.BufferSourceConverter.toUint8Array(t);return be(this,s,e,n)?(this.valueHexView=s.subarray(e,e+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,ri.call(this),this.blockLength=n,e+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Mn.NAME="BooleanValueBlock";var oc,Fn=class extends gt{constructor(t={}){super(t,Mn),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(t){this.valueBlock.value=t}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};oc=Fn;A.Boolean=oc;Fn.NAME="BOOLEAN";var Hn=class extends we(Qt){constructor({isConstructed:t=!1,...e}={}){super(e),this.isConstructed=t}fromBER(t,e,n){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=Qt.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let o=0;o<this.value.length;o++){let i=this.value[o].constructor.NAME;if(i===Mr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==Xa)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,s=super.fromBER(t,e,n),this.blockLength=n;return s}toBER(t,e){return this.isConstructed?Qt.prototype.toBER.call(this,t,e):t?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Hn.NAME="OctetStringValueBlock";var ic,Kn=class r extends gt{constructor({idBlock:t={},lenBlock:e={},...n}={}){var s,o;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},Hn),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(t,e,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),e;if(!this.valueBlock.isConstructed){let o=(t instanceof ArrayBuffer?new Uint8Array(t):t).subarray(e,e+n);try{if(o.byteLength){let i=ms(o,0,o.byteLength);i.offset!==-1&&i.offset===n&&(this.valueBlock.value=[i.result])}}catch{}}return super.fromBER(t,e,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?Pe.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${M.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let t=[];for(let e of this.valueBlock.value)e instanceof r&&t.push(e.valueBlock.valueHexView);return M.BufferSourceConverter.concat(t)}};ic=Kn;A.OctetString=ic;Kn.NAME=Xa;var $n=class extends we(Qt){constructor({unusedBits:t=0,isConstructed:e=!1,...n}={}){super(n),this.unusedBits=t,this.isConstructed=e,this.blockLength=this.valueHexView.byteLength}fromBER(t,e,n){if(!n)return e;let s=-1;if(this.isConstructed){if(s=Qt.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===Mr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Qa)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let l=a.valueBlock;if(this.unusedBits>0&&l.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=l.unusedBits}return s}let o=M.BufferSourceConverter.toUint8Array(t);if(!be(this,o,e,n))return-1;let i=o.subarray(e,e+n);if(this.unusedBits=i[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=i.subarray(1);try{if(a.byteLength){let c=ms(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=i.subarray(1),this.blockLength=i.length,e+n}toBER(t,e){if(this.isConstructed)return Qt.prototype.toBER.call(this,t,e);if(t)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Wt;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};$n.NAME="BitStringValueBlock";var ac,fr=class extends gt{constructor({idBlock:t={},lenBlock:e={},...n}={}){var s,o;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},$n),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(t,e,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(t,e,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Pe.prototype.onAsciiEncoding.call(this);{let t=[],e=this.valueBlock.valueHexView;for(let s of e)t.push(s.toString(2).padStart(8,"0"));let n=t.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};ac=fr;A.BitString=ac;fr.NAME=Qa;var cc;function Zh(r,t){let e=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,l=0,u=c<i?i:c,f=0;for(let h=u;h>=0;h--,f++){switch(!0){case f<a.length:l=o[i-f]+a[c-f]+e[0];break;default:l=o[i-f]+e[0]}switch(e[0]=l/10,!0){case f>=o.length:o=Tn(new Uint8Array([l%10]),o);break;default:o[i-f]=l%10}}return e[0]>0&&(o=Tn(e,o)),o}function Ja(r){if(r>=Vr.length)for(let t=Vr.length;t<=r;t++){let e=new Uint8Array([0]),n=Vr[t-1].slice(0);for(let s=n.length-1;s>=0;s--){let o=new Uint8Array([(n[s]<<1)+e[0]]);e[0]=o[0]/10,n[s]=o[0]%10}e[0]>0&&(n=Tn(e,n)),Vr.push(n)}return Vr[r]}function Yh(r,t){let e=0,n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,l,u=0;for(let f=c;f>=0;f--,u++)switch(l=o[i-u]-a[c-u]-e,!0){case l<0:e=1,o[i-u]=l+10;break;default:e=0,o[i-u]=l}if(e>0)for(let f=i-c+1;f>=0;f--,u++)if(l=o[i-u]-e,l<0)e=1,o[i-u]=l+10;else{e=0,o[i-u]=l;break}return o.slice()}var Fr=class extends we(Et){constructor({value:t,...e}={}){super(e),this._valueDec=0,e.valueHex&&this.setValueHex(),t!==void 0&&(this.valueDec=t)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=ri.call(this)))}set valueDec(t){this._valueDec=t,this.isHexOnly=!1,this.valueHexView=new Uint8Array(ja(t))}get valueDec(){return this._valueDec}fromDER(t,e,n,s=0){let o=this.fromBER(t,e,n);if(o===-1)return o;let i=this.valueHexView;return i[0]===0&&i[1]&128?this.valueHexView=i.subarray(1):s!==0&&i.length<s&&(s-i.length>1&&(s=i.length+1),this.valueHexView=i.subarray(s-i.length)),o}toDER(t=!1){let e=this.valueHexView;switch(!0){case(e[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(e,1),this.valueHexView=n}break;case(e[0]===0&&(e[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(t)}fromBER(t,e,n){let s=super.fromBER(t,e,n);return s===-1||this.setValueHex(),s}toBER(t){return t?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let t=this.valueHexView.length*8-1,e=new Uint8Array(this.valueHexView.length*8/3),n=0,s,o=this.valueHexView,i="",a=!1;for(let c=o.byteLength-1;c>=0;c--){s=o[c];for(let l=0;l<8;l++){if((s&1)===1)switch(n){case t:e=Yh(Ja(n),e),i="-";break;default:e=Zh(e,Ja(n))}n++,s>>=1}}for(let c=0;c<e.length;c++)e[c]&&(a=!0),a&&(i+=Ya.charAt(e[c]));return a===!1&&(i+=Ya.charAt(0)),i}};cc=Fr;Fr.NAME="IntegerValueBlock";Object.defineProperty(cc.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var lc,mt=class r extends gt{constructor(t={}){super(t,Fr),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Ln(),BigInt(this.valueBlock.toString())}static fromBigInt(t){Ln();let e=BigInt(t),n=new Dr,s=e.toString(16).replace(/^-/,""),o=new Uint8Array(M.Convert.FromHex(s));if(e<0){let a=new Uint8Array(o.length+(o[0]&128?1:0));a[0]|=128;let l=BigInt(`0x${M.Convert.ToHex(a)}`)+e,u=M.BufferSourceConverter.toUint8Array(M.Convert.FromHex(l.toString(16)));u[0]|=128,n.write(u)}else o[0]&128&&n.write(new Uint8Array([0])),n.write(o);return new r({valueHex:n.final()})}convertToDER(){let t=new r({valueHex:this.valueBlock.valueHexView});return t.valueBlock.toDER(),t}convertFromDER(){return new r({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};lc=mt;A.Integer=lc;mt.NAME="INTEGER";var uc,qn=class extends mt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};uc=qn;A.Enumerated=uc;qn.NAME="ENUMERATED";var Hr=class extends we(Et){constructor({valueDec:t=-1,isFirstSid:e=!1,...n}={}){super(n),this.valueDec=t,this.isFirstSid=e}fromBER(t,e,n){if(!n)return e;let s=M.BufferSourceConverter.toUint8Array(t);if(!be(this,s,e,n))return-1;let o=s.subarray(e,e+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let i=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)i[a]=this.valueHexView[a];return this.valueHexView=i,o[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Ze(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}set valueBigInt(t){Ln();let e=BigInt(t).toString(2);for(;e.length%7;)e="0"+e;let n=new Uint8Array(e.length/7);for(let s=0;s<n.length;s++)n[s]=parseInt(e.slice(s*7,s*7+7),2)+(s+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(t){if(this.isHexOnly){if(t)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,o=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)o[i]=s[i]|128;return o[this.blockLength-1]=s[this.blockLength-1],o.buffer}let e=_e(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Wt;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),o=e.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n}toString(){let t="";if(this.isHexOnly)t=M.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let e=this.valueDec;this.valueDec<=39?t="0.":this.valueDec<=79?(t="1.",e-=40):(t="2.",e-=80),t+=e.toString()}else t=this.valueDec.toString();return t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};Hr.NAME="sidBlock";var zn=class extends Et{constructor({value:t=dr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Hr;if(s=o.fromBER(t,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.value.length===0&&(o.isFirstSid=!0),this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return s}toBER(t){let e=[];for(let n=0;n<this.value.length;n++){let s=this.value[n].toBER(t);if(s.byteLength===0)return this.error=this.value[n].error,Wt;e.push(s)}return ni(e)}fromString(t){this.value=[];let e=0,n=0,s="",o=!1;do if(n=t.indexOf(".",e),n===-1?s=t.substring(e):s=t.substring(e,n),e=n+1,o){let i=this.value[0],a=0;switch(i.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(s,10);if(isNaN(c))return;i.valueDec=c+a,o=!1}else{let i=new Hr;if(s>Number.MAX_SAFE_INTEGER){Ln();let a=BigInt(s);i.valueBigInt=a}else if(i.valueDec=parseInt(s,10),isNaN(i.valueDec))return;this.value.length||(i.isFirstSid=!0,o=!0),this.value.push(i)}while(n!==-1)}toString(){let t="",e=!1;for(let n=0;n<this.value.length;n++){e=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(t=`${t}.`),e?(s=`{${s}}`,this.value[n].isFirstSid?t=`2.{${s} - 80}`:t+=s):t+=s}return t}toJSON(){let t={...super.toJSON(),value:this.toString(),sidArray:[]};for(let e=0;e<this.value.length;e++)t.sidArray.push(this.value[e].toJSON());return t}};zn.NAME="ObjectIdentifierValueBlock";var fc,hr=class extends gt{constructor(t={}){super(t,zn),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(t){this.valueBlock.fromString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};fc=hr;A.ObjectIdentifier=fc;hr.NAME="OBJECT IDENTIFIER";var Kr=class extends we(ge){constructor({valueDec:t=0,...e}={}){super(e),this.valueDec=t}fromBER(t,e,n){if(n===0)return e;let s=M.BufferSourceConverter.toUint8Array(t);if(!be(this,s,e,n))return-1;let o=s.subarray(e,e+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let i=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)i[a]=this.valueHexView[a];return this.valueHexView=i,o[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Ze(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}toBER(t){if(this.isHexOnly){if(t)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,o=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)o[i]=s[i]|128;return o[this.blockLength-1]=s[this.blockLength-1],o.buffer}let e=_e(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Wt;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),o=e.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n.buffer}toString(){let t="";return this.isHexOnly?t=M.Convert.ToHex(this.valueHexView):t=this.valueDec.toString(),t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Kr.NAME="relativeSidBlock";var Gn=class extends Et{constructor({value:t=dr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Kr;if(s=o.fromBER(t,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return s}toBER(t,e){let n=[];for(let s=0;s<this.value.length;s++){let o=this.value[s].toBER(t);if(o.byteLength===0)return this.error=this.value[s].error,Wt;n.push(o)}return ni(n)}fromString(t){this.value=[];let e=0,n=0,s="";do{n=t.indexOf(".",e),n===-1?s=t.substring(e):s=t.substring(e,n),e=n+1;let o=new Kr;if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return!0;this.value.push(o)}while(n!==-1);return!0}toString(){let t="",e=!1;for(let n=0;n<this.value.length;n++){e=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(t=`${t}.`),e&&(s=`{${s}}`),t+=s}return t}toJSON(){let t={...super.toJSON(),value:this.toString(),sidArray:[]};for(let e=0;e<this.value.length;e++)t.sidArray.push(this.value[e].toJSON());return t}};Gn.NAME="RelativeObjectIdentifierValueBlock";var hc,Wn=class extends gt{constructor(t={}){super(t,Gn),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(t){this.valueBlock.fromString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};hc=Wn;A.RelativeObjectIdentifier=hc;Wn.NAME="RelativeObjectIdentifier";var dc,me=class extends Pe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};dc=me;A.Sequence=dc;me.NAME="SEQUENCE";var pc,jn=class extends Pe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};pc=jn;A.Set=pc;jn.NAME="SET";var Zn=class extends we(Et){constructor({...t}={}){super(t),this.isHexOnly=!0,this.value=dr}toJSON(){return{...super.toJSON(),value:this.value}}};Zn.NAME="StringValueBlock";var Yn=class extends Zn{};Yn.NAME="SimpleStringValueBlock";var It=class extends _n{constructor({...t}={}){super(t,Yn)}fromBuffer(t){this.valueBlock.value=String.fromCharCode.apply(null,M.BufferSourceConverter.toUint8Array(t))}fromString(t){let e=t.length,n=this.valueBlock.valueHexView=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=t.charCodeAt(s);this.valueBlock.value=t}};It.NAME="SIMPLE STRING";var Jn=class extends It{fromBuffer(t){this.valueBlock.valueHexView=M.BufferSourceConverter.toUint8Array(t);try{this.valueBlock.value=M.Convert.ToUtf8String(t)}catch(e){this.warnings.push(`Error during "decodeURIComponent": ${e}, using raw string`),this.valueBlock.value=M.Convert.ToBinary(t)}}fromString(t){this.valueBlock.valueHexView=new Uint8Array(M.Convert.FromUtf8String(t)),this.valueBlock.value=t}};Jn.NAME="Utf8StringValueBlock";var gc,ye=class extends Jn{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};gc=ye;A.Utf8String=gc;ye.NAME="UTF8String";var Xn=class extends It{fromBuffer(t){this.valueBlock.value=M.Convert.ToUtf16String(t),this.valueBlock.valueHexView=M.BufferSourceConverter.toUint8Array(t)}fromString(t){this.valueBlock.value=t,this.valueBlock.valueHexView=new Uint8Array(M.Convert.FromUtf16String(t))}};Xn.NAME="BmpStringValueBlock";var mc,Qn=class extends Xn{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};mc=Qn;A.BmpString=mc;Qn.NAME="BMPString";var ts=class extends It{fromBuffer(t){let e=ArrayBuffer.isView(t)?t.slice().buffer:t.slice(0),n=new Uint8Array(e);for(let s=0;s<n.length;s+=4)n[s]=n[s+3],n[s+1]=n[s+2],n[s+2]=0,n[s+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(e))}fromString(t){let e=t.length,n=this.valueBlock.valueHexView=new Uint8Array(e*4);for(let s=0;s<e;s++){let o=_e(t.charCodeAt(s),8),i=new Uint8Array(o);if(i.length>4)continue;let a=4-i.length;for(let c=i.length-1;c>=0;c--)n[s*4+c+a]=i[c]}this.valueBlock.value=t}};ts.NAME="UniversalStringValueBlock";var yc,es=class extends ts{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};yc=es;A.UniversalString=yc;es.NAME="UniversalString";var bc,rs=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};bc=rs;A.NumericString=bc;rs.NAME="NumericString";var wc,ns=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};wc=ns;A.PrintableString=wc;ns.NAME="PrintableString";var xc,ss=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};xc=ss;A.TeletexString=xc;ss.NAME="TeletexString";var vc,os=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};vc=os;A.VideotexString=vc;os.NAME="VideotexString";var Ec,is=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Ec=is;A.IA5String=Ec;is.NAME="IA5String";var Bc,as=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Bc=as;A.GraphicString=Bc;as.NAME="GraphicString";var Ac,$r=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Ac=$r;A.VisibleString=Ac;$r.NAME="VisibleString";var Sc,cs=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Sc=cs;A.GeneralString=Sc;cs.NAME="GeneralString";var Ic,ls=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Ic=ls;A.CharacterString=Ic;ls.NAME="CharacterString";var kc,qr=class extends $r{constructor({value:t,valueDate:e,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,t){this.fromString(t),this.valueBlock.valueHexView=new Uint8Array(t.length);for(let s=0;s<t.length;s++)this.valueBlock.valueHexView[s]=t.charCodeAt(s)}e&&(this.fromDate(e),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(t){this.fromString(String.fromCharCode.apply(null,M.BufferSourceConverter.toUint8Array(t)))}toBuffer(){let t=this.toString(),e=new ArrayBuffer(t.length),n=new Uint8Array(e);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return e}fromDate(t){this.year=t.getUTCFullYear(),this.month=t.getUTCMonth()+1,this.day=t.getUTCDate(),this.hour=t.getUTCHours(),this.minute=t.getUTCMinutes(),this.second=t.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(t){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(t);if(n===null){this.error="Wrong input string for conversion";return}let s=parseInt(n[1],10);s>=50?this.year=1900+s:this.year=2e3+s,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(t="iso"){if(t==="iso"){let e=new Array(7);return e[0]=Lt(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=Lt(this.month,2),e[2]=Lt(this.day,2),e[3]=Lt(this.hour,2),e[4]=Lt(this.minute,2),e[5]=Lt(this.second,2),e[6]="Z",e.join("")}return super.toString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};kc=qr;A.UTCTime=kc;qr.NAME="UTCTime";var Nc,us=class extends qr{constructor(t={}){var e;super(t),(e=this.millisecond)!==null&&e!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(t){super.fromDate(t),this.millisecond=t.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(t){let e=!1,n="",s="",o=0,i,a=0,c=0;if(t[t.length-1]==="Z")n=t.substring(0,t.length-1),e=!0;else{let f=new Number(t[t.length-1]);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");n=t}if(e){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let f=1,h=n.indexOf("+"),m="";if(h===-1&&(h=n.indexOf("-"),f=-1),h!==-1){if(m=n.substring(h+1),n=n.substring(0,h),m.length!==2&&m.length!==4)throw new Error("Wrong input string for conversion");let g=parseInt(m.substring(0,2),10);if(isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");if(a=f*g,m.length===4){if(g=parseInt(m.substring(2,4),10),isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");c=f*g}}}let l=n.indexOf(".");if(l===-1&&(l=n.indexOf(",")),l!==-1){let f=new Number(`0${n.substring(l)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");o=f.valueOf(),s=n.substring(0,l)}else s=n;switch(!0){case s.length===8:if(i=/(\d{4})(\d{2})(\d{2})/ig,l!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let f=60*o;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===12:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let f=60*o;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===14:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let f=1e3*o;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}let u=i.exec(s);if(u===null)throw new Error("Wrong input string for conversion");for(let f=1;f<u.length;f++)switch(f){case 1:this.year=parseInt(u[f],10);break;case 2:this.month=parseInt(u[f],10);break;case 3:this.day=parseInt(u[f],10);break;case 4:this.hour=parseInt(u[f],10)+a;break;case 5:this.minute=parseInt(u[f],10)+c;break;case 6:this.second=parseInt(u[f],10);break;default:throw new Error("Wrong input string for conversion")}if(e===!1){let f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(t="iso"){if(t==="iso"){let e=[];return e.push(Lt(this.year,4)),e.push(Lt(this.month,2)),e.push(Lt(this.day,2)),e.push(Lt(this.hour,2)),e.push(Lt(this.minute,2)),e.push(Lt(this.second,2)),this.millisecond!==0&&(e.push("."),e.push(Lt(this.millisecond,3))),e.push("Z"),e.join("")}return super.toString(t)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Nc=us;A.GeneralizedTime=Nc;us.NAME="GeneralizedTime";var Cc,fs=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Cc=fs;A.DATE=Cc;fs.NAME="DATE";var Tc,hs=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Tc=hs;A.TimeOfDay=Tc;hs.NAME="TimeOfDay";var Lc,ds=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Lc=ds;A.DateTime=Lc;ds.NAME="DateTime";var Uc,ps=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Uc=ps;A.Duration=Uc;ps.NAME="Duration";var Rc,gs=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Rc=gs;A.TIME=Rc;gs.NAME="TIME";function H(r,t="utf8"){let e=Sn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var zr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},ys=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var _c={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new ys("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 t}};var Oe=_c;async function Pc(r){let t=await Oe.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await Xh(t);return{privateKey:e[0],publicKey:e[1]}}async function Oc(r,t){let e=await Oe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Oe.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Vc(r,t,e){let n=await Oe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Oe.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Xh(r){if(r.privateKey==null||r.publicKey==null)throw new St("Private and public key are required");return Promise.all([Oe.get().subtle.exportKey("jwk",r.privateKey),Oe.get().subtle.exportKey("jwk",r.publicKey)])}function ii(r){if(r.kty!=="RSA")throw new St("invalid key type");if(r.n==null)throw new St("invalid key modulus");return $(r.n,"base64url").length*8}var pr=class{type="RSA";_key;_raw;_multihash;constructor(t,e){this._key=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=Gr.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return dt.createV1(114,this._multihash)}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e){return Vc(this._key,e,t)}},Wr=class{type="RSA";_key;_raw;publicKey;constructor(t,e){this._key=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=Gr.jwkToPkcs1(this._key)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}sign(t){return Oc(this._key,t)}};var bs=8192,ai=18;function Dc(r){let{result:t}=oi(r),e=t.valueBlock.value;return{n:H(te(e[1].toBigInt()),"base64url"),e:H(te(e[2].toBigInt()),"base64url"),d:H(te(e[3].toBigInt()),"base64url"),p:H(te(e[4].toBigInt()),"base64url"),q:H(te(e[5].toBigInt()),"base64url"),dp:H(te(e[6].toBigInt()),"base64url"),dq:H(te(e[7].toBigInt()),"base64url"),qi:H(te(e[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function Qh(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 St("JWK was missing components");let e=new me({value:[new mt({value:0}),mt.fromBigInt(ee($(r.n,"base64url"))),mt.fromBigInt(ee($(r.e,"base64url"))),mt.fromBigInt(ee($(r.d,"base64url"))),mt.fromBigInt(ee($(r.p,"base64url"))),mt.fromBigInt(ee($(r.q,"base64url"))),mt.fromBigInt(ee($(r.dp,"base64url"))),mt.fromBigInt(ee($(r.dq,"base64url"))),mt.fromBigInt(ee($(r.qi,"base64url")))]}).toBER();return new Uint8Array(e,0,e.byteLength)}function Mc(r){let{result:t}=oi(r),e=t.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:H(te(e[0].toBigInt()),"base64url"),e:H(te(e[1].toBigInt()),"base64url")}}function ci(r){if(r.n==null||r.e==null)throw new St("JWK was missing components");let e=new me({value:[new me({value:[new hr({value:"1.2.840.113549.1.1.1"}),new ur]}),new fr({valueHex:new me({value:[mt.fromBigInt(ee($(r.n,"base64url"))),mt.fromBigInt(ee($(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(e,0,e.byteLength)}function te(r){let t=r.toString(16);t.length%2>0&&(t=`0${t}`);let e=t.length/2,n=new Uint8Array(e),s=0,o=0;for(;s<e;)n[s]=parseInt(t.slice(o,o+2),16),s+=1,o+=2;return n}function ee(r){let t=[];return r.forEach(function(e){let n=e.toString(16);n.length%2>0&&(n=`0${n}`),t.push(n)}),BigInt("0x"+t.join(""))}function Fc(r){let t=Dc(r);return Hc(t)}function li(r){let t=Mc(r);if(ii(t)>bs)throw new Je("Key size is too large");let e=cr(Xt.encode({Type:at.RSA,Data:r})),n=Mt(ai,e);return new pr(t,n)}function Hc(r){if(ii(r)>bs)throw new St("Key size is too large");let t=$c(r),e=cr(Xt.encode({Type:at.RSA,Data:ci(t.publicKey)})),n=Mt(ai,e);return new Wr(t.privateKey,new pr(t.publicKey,n))}async function Kc(r){if(r>bs)throw new St("Key size is too large");let t=await Pc(r),e=cr(Xt.encode({Type:at.RSA,Data:ci(t.publicKey)})),n=Mt(ai,e);return new Wr(t.privateKey,new pr(t.publicKey,n))}function $c(r){if(r==null)throw new St("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}var ws=class extends sr{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,ha(t);let n=Cr(e);if(this.iHash=t.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 s=this.blockLen,o=new Uint8Array(s);o.set(n.length>s?t.create().update(n).digest():n);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),o.fill(0)}update(t){return nr(this),this.iHash.update(t),this}digestInto(t){nr(this),rr(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=o,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ui=(r,t,e)=>new ws(r,t).update(e).digest();ui.create=(r,t)=>new ws(r,t);function qc(r){r.lowS!==void 0&&Ht("lowS",r.lowS),r.prehash!==void 0&&Ht("prehash",r.prehash)}function td(r){let t=Ur(r);Jt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:s}=t;if(e){if(!n.eql(s,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:ed,hexToBytes:rd}=mn,xe={Err:class extends Error{constructor(t=""){super(t)}},_tlv:{encode:(r,t)=>{let{Err:e}=xe;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,s=He(n);if(s.length/2&128)throw new e("tlv.encode: long form length too big");let o=n>127?He(s.length/2|128):"";return`${He(r)}${o}${s}${t}`},decode(r,t){let{Err:e}=xe,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let s=t[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+c);if(l.length!==c)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of l)i=i<<8|u;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=xe;if(r<ve)throw new t("integer: negative integers are not allowed");let e=He(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected assertion");return e},decode(r){let{Err:t}=xe;if(r[0]&128)throw new t("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return ed(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=xe,s=typeof r=="string"?rd(r):r;ir(s);let{v:o,l:i}=n.decode(48,s);if(i.length)throw new t("Invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,o),{v:l,l:u}=n.decode(2,c);if(u.length)throw new t("Invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=xe,n=`${t.encode(2,e.encode(r.r))}${t.encode(2,e.encode(r.s))}`;return t.encode(48,n)}},ve=BigInt(0),ft=BigInt(1),Lm=BigInt(2),zc=BigInt(3),Um=BigInt(4);function nd(r){let t=td(r),{Fp:e}=t,n=Ce(t.n,t.nBitLength),s=t.toBytes||((b,d,x)=>{let B=d.toAffine();return he(Uint8Array.from([4]),e.toBytes(B.x),e.toBytes(B.y))}),o=t.fromBytes||(b=>{let d=b.subarray(1),x=e.fromBytes(d.subarray(0,e.BYTES)),B=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x,y:B}});function i(b){let{a:d,b:x}=t,B=e.sqr(b),y=e.mul(B,b);return e.add(e.add(y,e.mul(b,d)),x)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(b){return Tr(b,ft,t.n)}function c(b){let{allowedPrivateKeyLengths:d,nByteLength:x,wrapPrivateKey:B,n:y}=t;if(d&&typeof b!="bigint"){if(Ie(b)&&(b=ue(b)),typeof b!="string"||!d.includes(b.length))throw new Error("Invalid key");b=b.padStart(x*2,"0")}let S;try{S=typeof b=="bigint"?b:fe(et("private key",b,x))}catch{throw new Error(`private key must be ${x} bytes, hex or bigint, not ${typeof b}`)}return B&&(S=j(S,y)),Nt("private key",S,ft,y),S}function l(b){if(!(b instanceof h))throw new Error("ProjectivePoint expected")}let u=qe((b,d)=>{let{px:x,py:B,pz:y}=b;if(e.eql(y,e.ONE))return{x,y:B};let S=b.is0();d==null&&(d=S?e.ONE:e.inv(y));let U=e.mul(x,d),L=e.mul(B,d),I=e.mul(y,d);if(S)return{x:e.ZERO,y:e.ZERO};if(!e.eql(I,e.ONE))throw new Error("invZ was invalid");return{x:U,y:L}}),f=qe(b=>{if(b.is0()){if(t.allowInfinityPoint&&!e.is0(b.py))return;throw new Error("bad point: ZERO")}let{x:d,y:x}=b.toAffine();if(!e.isValid(d)||!e.isValid(x))throw new Error("bad point: x or y not FE");let B=e.sqr(x),y=i(d);if(!e.eql(B,y))throw new Error("bad point: equation left != right");if(!b.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,x,B){if(this.px=d,this.py=x,this.pz=B,d==null||!e.isValid(d))throw new Error("x required");if(x==null||!e.isValid(x))throw new Error("y required");if(B==null||!e.isValid(B))throw new Error("z required");Object.freeze(this)}static fromAffine(d){let{x,y:B}=d||{};if(!d||!e.isValid(x)||!e.isValid(B))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let y=S=>e.eql(S,e.ZERO);return y(x)&&y(B)?h.ZERO:new h(x,B,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let x=e.invertBatch(d.map(B=>B.pz));return d.map((B,y)=>B.toAffine(x[y])).map(h.fromAffine)}static fromHex(d){let x=h.fromAffine(o(et("pointHex",d)));return x.assertValidity(),x}static fromPrivateKey(d){return h.BASE.multiply(c(d))}static msm(d,x){return wn(h,n,d,x)}_setWindowSize(d){g.setWindowSize(this,d)}assertValidity(){f(this)}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){l(d);let{px:x,py:B,pz:y}=this,{px:S,py:U,pz:L}=d,I=e.eql(e.mul(x,L),e.mul(S,y)),k=e.eql(e.mul(B,L),e.mul(U,y));return I&&k}negate(){return new h(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:x}=t,B=e.mul(x,zc),{px:y,py:S,pz:U}=this,L=e.ZERO,I=e.ZERO,k=e.ZERO,T=e.mul(y,y),nt=e.mul(S,S),K=e.mul(U,U),O=e.mul(y,S);return O=e.add(O,O),k=e.mul(y,U),k=e.add(k,k),L=e.mul(d,k),I=e.mul(B,K),I=e.add(L,I),L=e.sub(nt,I),I=e.add(nt,I),I=e.mul(L,I),L=e.mul(O,L),k=e.mul(B,k),K=e.mul(d,K),O=e.sub(T,K),O=e.mul(d,O),O=e.add(O,k),k=e.add(T,T),T=e.add(k,T),T=e.add(T,K),T=e.mul(T,O),I=e.add(I,T),K=e.mul(S,U),K=e.add(K,K),T=e.mul(K,O),L=e.sub(L,T),k=e.mul(K,nt),k=e.add(k,k),k=e.add(k,k),new h(L,I,k)}add(d){l(d);let{px:x,py:B,pz:y}=this,{px:S,py:U,pz:L}=d,I=e.ZERO,k=e.ZERO,T=e.ZERO,nt=t.a,K=e.mul(t.b,zc),O=e.mul(x,S),st=e.mul(B,U),E=e.mul(y,L),N=e.add(x,B),w=e.add(S,U);N=e.mul(N,w),w=e.add(O,st),N=e.sub(N,w),w=e.add(x,y);let p=e.add(S,L);return w=e.mul(w,p),p=e.add(O,E),w=e.sub(w,p),p=e.add(B,y),I=e.add(U,L),p=e.mul(p,I),I=e.add(st,E),p=e.sub(p,I),T=e.mul(nt,w),I=e.mul(K,E),T=e.add(I,T),I=e.sub(st,T),T=e.add(st,T),k=e.mul(I,T),st=e.add(O,O),st=e.add(st,O),E=e.mul(nt,E),w=e.mul(K,w),st=e.add(st,E),E=e.sub(O,E),E=e.mul(nt,E),w=e.add(w,E),O=e.mul(st,w),k=e.add(k,O),O=e.mul(p,w),I=e.mul(N,I),I=e.sub(I,O),O=e.mul(N,st),T=e.mul(p,T),T=e.add(T,O),new h(I,k,T)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return g.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){Nt("scalar",d,ve,t.n);let x=h.ZERO;if(d===ve)return x;if(d===ft)return this;let{endo:B}=t;if(!B)return g.unsafeLadder(this,d);let{k1neg:y,k1:S,k2neg:U,k2:L}=B.splitScalar(d),I=x,k=x,T=this;for(;S>ve||L>ve;)S&ft&&(I=I.add(T)),L&ft&&(k=k.add(T)),T=T.double(),S>>=ft,L>>=ft;return y&&(I=I.negate()),U&&(k=k.negate()),k=new h(e.mul(k.px,B.beta),k.py,k.pz),I.add(k)}multiply(d){let{endo:x,n:B}=t;Nt("scalar",d,ft,B);let y,S;if(x){let{k1neg:U,k1:L,k2neg:I,k2:k}=x.splitScalar(d),{p:T,f:nt}=this.wNAF(L),{p:K,f:O}=this.wNAF(k);T=g.constTimeNegate(U,T),K=g.constTimeNegate(I,K),K=new h(e.mul(K.px,x.beta),K.py,K.pz),y=T.add(K),S=nt.add(O)}else{let{p:U,f:L}=this.wNAF(d);y=U,S=L}return h.normalizeZ([y,S])[0]}multiplyAndAddUnsafe(d,x,B){let y=h.BASE,S=(L,I)=>I===ve||I===ft||!L.equals(y)?L.multiplyUnsafe(I):L.multiply(I),U=S(this,x).add(S(d,B));return U.is0()?void 0:U}toAffine(d){return u(this,d)}isTorsionFree(){let{h:d,isTorsionFree:x}=t;if(d===ft)return!0;if(x)return x(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:x}=t;return d===ft?this:x?x(h,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return Ht("isCompressed",d),this.assertValidity(),s(h,this,d)}toHex(d=!0){return Ht("isCompressed",d),ue(this.toRawBytes(d))}}h.BASE=new h(t.Gx,t.Gy,e.ONE),h.ZERO=new h(e.ZERO,e.ONE,e.ZERO);let m=t.nBitLength,g=bn(h,t.endo?Math.ceil(m/2):m);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function sd(r){let t=Ur(r);return Jt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Gc(r){let t=sd(r),{Fp:e,n}=t,s=e.BYTES+1,o=2*e.BYTES+1;function i(E){return j(E,n)}function a(E){return yn(E,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:l,weierstrassEquation:u,isWithinCurveOrder:f}=nd({...t,toBytes(E,N,w){let p=N.toAffine(),v=e.toBytes(p.x),C=he;return Ht("isCompressed",w),w?C(Uint8Array.from([N.hasEvenY()?2:3]),v):C(Uint8Array.from([4]),v,e.toBytes(p.y))},fromBytes(E){let N=E.length,w=E[0],p=E.subarray(1);if(N===s&&(w===2||w===3)){let v=fe(p);if(!Tr(v,ft,e.ORDER))throw new Error("Point is not on curve");let C=u(v),R;try{R=e.sqrt(C)}catch(F){let D=F instanceof Error?": "+F.message:"";throw new Error("Point is not on curve"+D)}let _=(R&ft)===ft;return(w&1)===1!==_&&(R=e.neg(R)),{x:v,y:R}}else if(N===o&&w===4){let v=e.fromBytes(p.subarray(0,e.BYTES)),C=e.fromBytes(p.subarray(e.BYTES,2*e.BYTES));return{x:v,y:C}}else throw new Error(`Point of length ${N} was invalid. Expected ${s} compressed bytes or ${o} uncompressed bytes`)}}),h=E=>ue(Ne(E,t.nByteLength));function m(E){let N=n>>ft;return E>N}function g(E){return m(E)?i(-E):E}let b=(E,N,w)=>fe(E.slice(N,w));class d{constructor(N,w,p){this.r=N,this.s=w,this.recovery=p,this.assertValidity()}static fromCompact(N){let w=t.nByteLength;return N=et("compactSignature",N,w*2),new d(b(N,0,w),b(N,w,2*w))}static fromDER(N){let{r:w,s:p}=xe.toSig(et("DER",N));return new d(w,p)}assertValidity(){Nt("r",this.r,ft,n),Nt("s",this.s,ft,n)}addRecoveryBit(N){return new d(this.r,this.s,N)}recoverPublicKey(N){let{r:w,s:p,recovery:v}=this,C=L(et("msgHash",N));if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");let R=v===2||v===3?w+t.n:w;if(R>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let _=v&1?"03":"02",V=c.fromHex(_+h(R)),F=a(R),D=i(-C*F),W=i(p*F),Y=c.BASE.multiplyAndAddUnsafe(V,D,W);if(!Y)throw new Error("point at infinify");return Y.assertValidity(),Y}hasHighS(){return m(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return Ke(this.toDERHex())}toDERHex(){return xe.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ke(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let x={isValidPrivateKey(E){try{return l(E),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let E=mo(t.n);return Sa(t.randomBytes(E),t.n)},precompute(E=8,N=c.BASE){return N._setWindowSize(E),N.multiply(BigInt(3)),N}};function B(E,N=!0){return c.fromPrivateKey(E).toRawBytes(N)}function y(E){let N=Ie(E),w=typeof E=="string",p=(N||w)&&E.length;return N?p===s||p===o:w?p===2*s||p===2*o:E instanceof c}function S(E,N,w=!0){if(y(E))throw new Error("first arg must be private key");if(!y(N))throw new Error("second arg must be public key");return c.fromHex(N).multiply(l(E)).toRawBytes(w)}let U=t.bits2int||function(E){let N=fe(E),w=E.length*8-t.nBitLength;return w>0?N>>BigInt(w):N},L=t.bits2int_modN||function(E){return i(U(E))},I=Lr(t.nBitLength);function k(E){return Nt(`num < 2^${t.nBitLength}`,E,ve,I),Ne(E,t.nByteLength)}function T(E,N,w=nt){if(["recovered","canonical"].some(ut=>ut in w))throw new Error("sign() legacy options not supported");let{hash:p,randomBytes:v}=t,{lowS:C,prehash:R,extraEntropy:_}=w;C==null&&(C=!0),E=et("msgHash",E),qc(w),R&&(E=et("prehashed msgHash",p(E)));let V=L(E),F=l(N),D=[k(F),k(V)];if(_!=null&&_!==!1){let ut=_===!0?v(e.BYTES):_;D.push(et("extraEntropy",ut))}let W=he(...D),Y=V;function lt(ut){let ht=U(ut);if(!f(ht))return;let Bt=a(ht),ot=c.BASE.multiply(ht).toAffine(),kt=i(ot.x);if(kt===ve)return;let oe=i(Bt*i(Y+kt*F));if(oe===ve)return;let Er=(ot.x===kt?0:2)|Number(ot.y&ft),Br=oe;return C&&m(oe)&&(Br=g(oe),Er^=1),new d(kt,Br,Er)}return{seed:W,k2sig:lt}}let nt={lowS:t.lowS,prehash:!1},K={lowS:t.lowS,prehash:!1};function O(E,N,w=nt){let{seed:p,k2sig:v}=T(E,N,w),C=t;return fo(C.hash.outputLen,C.nByteLength,C.hmac)(p,v)}c.BASE._setWindowSize(8);function st(E,N,w,p=K){let v=E;if(N=et("msgHash",N),w=et("publicKey",w),"strict"in p)throw new Error("options.strict was renamed to lowS");qc(p);let{lowS:C,prehash:R}=p,_,V;try{if(typeof v=="string"||Ie(v))try{_=d.fromDER(v)}catch(ot){if(!(ot instanceof xe.Err))throw ot;_=d.fromCompact(v)}else if(typeof v=="object"&&typeof v.r=="bigint"&&typeof v.s=="bigint"){let{r:ot,s:kt}=v;_=new d(ot,kt)}else throw new Error("PARSE");V=c.fromHex(w)}catch(ot){if(ot.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(C&&_.hasHighS())return!1;R&&(N=t.hash(N));let{r:F,s:D}=_,W=L(N),Y=a(D),lt=i(W*Y),ut=i(F*Y),ht=c.BASE.multiplyAndAddUnsafe(V,lt,ut)?.toAffine();return ht?i(ht.x)===F:!1}return{CURVE:t,getPublicKey:B,getSharedSecret:S,sign:O,verify:st,ProjectivePoint:c,Signature:d,utils:x}}function od(r){return{hash:r,hmac:(t,...e)=>ui(r,t,no(...e)),randomBytes:dn}}function Wc(r,t){let e=n=>Gc({...r,...od(n)});return Object.freeze({...e(t),create:e})}var Yc=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),jc=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),id=BigInt(1),fi=BigInt(2),Zc=(r,t)=>(r+t/fi)/t;function ad(r){let t=Yc,e=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%t,u=l*l*r%t,f=Q(u,e,t)*u%t,h=Q(f,e,t)*u%t,m=Q(h,fi,t)*l%t,g=Q(m,s,t)*m%t,b=Q(g,o,t)*g%t,d=Q(b,a,t)*b%t,x=Q(d,c,t)*d%t,B=Q(x,a,t)*b%t,y=Q(B,e,t)*u%t,S=Q(y,i,t)*g%t,U=Q(S,n,t)*l%t,L=Q(U,fi,t);if(!hi.eql(hi.sqr(L),r))throw new Error("Cannot find square root");return L}var hi=Ce(Yc,void 0,void 0,{sqrt:ad}),Ye=Wc({a:BigInt(0),b:BigInt(7),Fp:hi,n:jc,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=jc,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-id*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,i=BigInt("0x100000000000000000000000000000000"),a=Zc(o*r,t),c=Zc(-n*r,t),l=j(r-a*e-c*s,t),u=j(-a*n-c*o,t),f=l>i,h=u>i;if(f&&(l=t-l),h&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:h,k2:u}}}},cr),Hm=BigInt(0);var Km=Ye.ProjectivePoint;function _t(r,t){t==null&&(t=r.reduce((s,o)=>s+o.length,0));let e=Tt(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}function Jc(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Xc(r,t,e){let n=Rr.digest(e instanceof Uint8Array?e:e.subarray());if(Jc(n))return n.then(({digest:s})=>Ye.verify(t,s,r)).catch(s=>{throw new zr(String(s))});try{return Ye.verify(t,n.digest,r)}catch(s){throw new zr(String(s))}}var xs=class{type="secp256k1";raw;_key;constructor(t){this._key=tl(t),this.raw=Qc(this._key)}toMultihash(){return ce.digest(Te(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e){return Xc(this._key,e,t)}};function di(r){return new xs(r)}function Qc(r){return Ye.ProjectivePoint.fromHex(r).toRawBytes(!0)}function tl(r){try{return Ye.ProjectivePoint.fromHex(r),r}catch(t){throw new Je(String(t))}}function gr(r){let{Type:t,Data:e}=Xt.decode(r),n=e??new Uint8Array;switch(t){case at.RSA:return li(n);case at.Ed25519:return vo(n);case at.secp256k1:return di(n);default:throw new De}}function el(r){let{Type:t,Data:e}=Xt.decode(r.digest),n=e??new Uint8Array;switch(t){case at.Ed25519:return vo(n);case at.secp256k1:return di(n);default:throw new De}}function Te(r){return Xt.encode({Type:at[r.type],Data:r.raw})}var nl=Symbol.for("@achingbrain/uint8arraylist");function rl(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let s=e+n.byteLength;if(t<s)return{buf:n,index:t-e};e=s}throw new RangeError("index is out of bounds")}function vs(r){return!!r?.[nl]}var jt=class r{bufs;length;[nl]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(vs(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(vs(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=rl(this.bufs,t);return e.buf[e.index]}set(t,e){let n=rl(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(vs(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:s}=this._subList(t,e);return _t(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:_t(n,s)}sublist(t,e){let{bufs:n,length:s}=this._subList(t,e),o=new r;return o.length=s,o.bufs=[...n],o}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,t>=c)continue;let l=t>=a&&t<c,u=e>a&&e<=c;if(l&&u){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!vs(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let f=0;f<o;f++)i[f]=-1;for(let f=0;f<s;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=c;f+=u){u=0;for(let h=l;h>=0;h--){let m=this.get(f+h);if(n[h]!==m){u=Math.max(1,h-a[m]);break}}if(u===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=Tt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let s=pt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,e,n),this.write(s,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let s=pt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,e,n),this.write(s,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let s=pt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,e,n),this.write(s,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=Tt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let s=pt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,e,n),this.write(s,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let s=pt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,e,n),this.write(s,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let s=pt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,e,n),this.write(s,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let s=pt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,e,n),this.write(s,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let s=pt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,e,n),this.write(s,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!bt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((s,o)=>s+o.byteLength,0)),n.length=e,n}};var jr;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.publicKey!=null&&e.publicKey.byteLength>0&&(n.uint32(10),n.bytes(e.publicKey)),e.payloadType!=null&&e.payloadType.byteLength>0&&(n.uint32(18),n.bytes(e.payloadType)),e.payload!=null&&e.payload.byteLength>0&&(n.uint32(26),n.bytes(e.payload)),e.signature!=null&&e.signature.byteLength>0&&(n.uint32(42),n.bytes(e.signature)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={publicKey:pt(0),payloadType:pt(0),payload:pt(0),signature:pt(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.publicKey=e.bytes();break}case 2:{o.payloadType=e.bytes();break}case 3:{o.payload=e.bytes();break}case 5:{o.signature=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>qt(e,r.codec(),n)})(jr||(jr={}));var Es=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var re=class r{static createFromProtobuf=async t=>{let e=jr.decode(t),n=gr(e.publicKey);return new r({publicKey:n,payloadType:e.payloadType,payload:e.payload,signature:e.signature})};static seal=async(t,e)=>{if(e==null)throw new Error("Missing private key");let n=t.domain,s=t.codec,o=t.marshal(),i=sl(n,s,o),a=await e.sign(i.subarray());return new r({publicKey:e.publicKey,payloadType:s,payload:o,signature:a})};static openAndCertify=async(t,e)=>{let n=await r.createFromProtobuf(t);if(!await n.validate(e))throw new Es("Envelope signature is not valid for the given domain");return n};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:s,signature:o}=t;this.publicKey=e,this.payloadType=n,this.payload=s,this.signature=o}marshal(){return this.marshaled==null&&(this.marshaled=jr.encode({publicKey:Te(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return bt(this.marshal(),t.marshal())}async validate(t){let e=sl(t,this.payloadType,this.payload);return this.publicKey.verify(e.subarray(),this.signature)}},sl=(r,t,e)=>{let n=$(r),s=Pt(n.byteLength),o=Pt(t.length),i=Pt(e.length);return new jt(s,n,o,t,i,e)};var ol=Symbol.for("nodejs.util.inspect.custom"),cd=114,Zr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Gs]=!0;toString(){return this.string==null&&(this.string=J.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return dt.createV1(cd,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return bt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return bt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[ol](){return`PeerId(${this.toString()})`}},Yr=class extends Zr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Jr=class extends Zr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Xr=class extends Zr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},ld=2336,Qr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=ce.digest($(this.url))}[ol](){return`PeerId(${this.url})`}[Gs]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return dt.createV1(ld,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=H(t)),t.toString()===this.toString())}};var ud=114,il=2336;function al(r){if(r.type==="Ed25519")return new Jr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Xr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new Yr({multihash:r.toCID().multihash,publicKey:r});throw new De}function pi(r){if(hd(r))return new Yr({multihash:r});if(fd(r))try{let t=el(r);if(t.type==="Ed25519")return new Jr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Xr({multihash:r,publicKey:t})}catch{let e=H(r.digest);return new Qr(new URL(e))}throw new an("Supplied PeerID Multihash is invalid")}function Bs(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==ud&&r.code!==il)throw new on("Supplied PeerID CID is invalid");if(r.code===il){let t=H(r.multihash.digest);return new Qr(new URL(t))}return pi(r.multihash)}function fd(r){return r.code===ce.code}function hd(r){return r.code===Rr.code}function cl(r,t){let e=(n,s)=>n.toString().localeCompare(s.toString());return r.length!==t.length?!1:(t.sort(e),r.sort(e).every((n,s)=>t[s].equals(n)))}var As=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}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(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,s){return this.readAtomically(()=>{let o=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*s)-1;for(;;){let u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let h=Number.parseInt(f,t);if(!Number.isNaN(h))return h});if(u===void 0)break;if(o*=t,o+=u,o>l||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:o})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let s=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[s]=i[0],e[s+1]=i[1],e[s+2]=i[2],e[s+3]=i[3],[s+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[s,!1];e[s]=o>>8,e[s+1]=o&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,s]=t(e);if(n===16)return e;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),i=16-(n+2),[a]=t(o.subarray(0,i));return e.set(o.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var ll=45,dd=15,mr=new As;function gi(r){if(!(r.length>dd))return mr.new(r).parseWith(()=>mr.readIPv4Addr())}function mi(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>ll))return mr.new(r).parseWith(()=>mr.readIPv6Addr())}function Ss(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>ll))return mr.new(r).parseWith(()=>mr.readIPAddr())}var wb=parseInt("0xFFFF",16),xb=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function yr(r){return!!gi(r)}function br(r){return!!mi(r)}function Is(r){return!!Ss(r)}var hl=yr,bd=br,yi=function(r){let t=0;if(r=r.toString().trim(),hl(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(bd(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let o=hl(e[n]),i;o&&(i=yi(e[n]),e[n]=H(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,H(i.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let o=[n,1];for(n=9-e.length;n>0;n--)o.push("0");e.splice.apply(e,o)}let s=new Uint8Array(t+16);for(n=0;n<e.length;n++){let o=parseInt(e[n],16);s[t++]=o>>8&255,s[t++]=o&255}return s}throw new Error("invalid ip address")},dl=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let s=[];for(let o=0;o<e;o++)s.push(r[t+o]);return s.join(".")}if(e===16){let s=[];for(let o=0;o<e;o+=2)s.push(n.getUint16(t+o).toString(16));return s.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var wr={},bi={},xd=[[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"]];xd.forEach(r=>{let t=vd(...r);bi[t.code]=t,wr[t.name]=t});function vd(r,t,e,n,s){return{code:r,size:t,name:e,resolvable:!!n,path:!!s}}function q(r){if(typeof r=="number"){if(bi[r]!=null)return bi[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(wr[r]!=null)return wr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var nw=q("ip4"),sw=q("ip6"),ow=q("ipcidr");function Ei(r,t){switch(q(r).code){case 4:case 41:return Bd(t);case 42:return vi(t);case 6:case 273:case 33:case 132:return ml(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return vi(t);case 421:return kd(t);case 444:return gl(t);case 445:return gl(t);case 466:return Id(t);case 481:return globalThis.encodeURIComponent(vi(t));default:return H(t,"base16")}}function Bi(r,t){switch(q(r).code){case 4:return pl(t);case 41:return pl(t);case 42:return xi(t);case 6:case 273:case 33:case 132:return Ai(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return xi(t);case 421:return Ad(t);case 444:return Nd(t);case 445:return Cd(t);case 466:return Sd(t);case 481:return xi(globalThis.decodeURIComponent(t));default:return $(t,"base16")}}var wi=Object.values(_r).map(r=>r.decoder),Ed=function(){let r=wi[0].or(wi[1]);return wi.slice(2).forEach(t=>r=r.or(t)),r}();function pl(r){if(!Is(r))throw new Error("invalid ip address");return yi(r)}function Bd(r){let t=dl(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Is(t))throw new Error("invalid ip address");return t}function Ai(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function ml(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function xi(r){let t=$(r),e=Uint8Array.from(Pt(t.length));return _t([e,t],e.length+t.length)}function vi(r){let t=de(r);if(r=r.slice(xt(t)),r.length!==t)throw new Error("inconsistent lengths");return H(r)}function Ad(r){let t;r[0]==="Q"||r[0]==="1"?t=Me(J.decode(`z${r}`)).bytes:t=dt.parse(r).multihash.bytes;let e=Uint8Array.from(Pt(t.length));return _t([e,t],e.length+t.length)}function Sd(r){let t=Ed.decode(r),e=Uint8Array.from(Pt(t.length));return _t([e,t],e.length+t.length)}function Id(r){let t=de(r),e=r.slice(xt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+H(e,"base64url")}function kd(r){let t=de(r),e=r.slice(xt(t));if(e.length!==t)throw new Error("inconsistent lengths");return H(e,"base58btc")}function Nd(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=ae.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Ai(n);return _t([e,s],e.length+s.length)}function Cd(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=ae.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Ai(n);return _t([e,s],e.length+s.length)}function gl(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=H(t,"base32"),s=ml(e);return`${n}:${s}`}function yl(r){r=Si(r);let t=[],e=[],n=null,s=r.split("/").slice(1);if(s.length===1&&s[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let o=0;o<s.length;o++){let i=s[o],a=q(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(o++,o>=s.length)throw wl("invalid address: "+r);if(a.path===!0){n=Si(s.slice(o).join("/")),t.push([a.code,Bi(a.code,n)]),e.push([a.code,n]);break}let c=Bi(a.code,s[o]);t.push([a.code,c]),e.push([a.code,Ei(a.code,c)])}return{string:bl(e),bytes:ki(t),tuples:t,stringTuples:e,path:n}}function Ii(r){let t=[],e=[],n=null,s=0;for(;s<r.length;){let o=de(r,s),i=xt(o),a=q(o),c=Td(a,r.slice(s+i));if(c===0){t.push([o]),e.push([o]),s+=i;continue}let l=r.slice(s+i,s+i+c);if(s+=c+i,s>r.length)throw wl("Invalid address Uint8Array: "+H(r,"base16"));t.push([o,l]);let u=Ei(o,l);if(e.push([o,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:bl(e),tuples:t,stringTuples:e,path:n}}function bl(r){let t=[];return r.map(e=>{let n=q(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Si(t.join("/"))}function ki(r){return _t(r.map(t=>{let e=q(t[0]),n=Uint8Array.from(Pt(e.code));return t.length>1&&t[1]!=null&&(n=_t([n,t[1]])),n}))}function Td(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=de(t instanceof Uint8Array?t:Uint8Array.from(t));return e+xt(e)}}function Si(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function wl(r){return new Error("Error parsing address: "+r)}var Ld=Symbol.for("nodejs.util.inspect.custom"),Ci=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Ud=[q("dns").code,q("dns4").code,q("dns6").code,q("dnsaddr").code],Ni=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},ks=class r{bytes;#e;#t;#r;#n;[Ci]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Ii(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=yl(t)}else if(vl(t))e=Ii(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#e=e.string,this.#t=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,s,o="",i=q("tcp"),a=q("udp"),c=q("ip4"),l=q("ip6"),u=q("dns6"),f=q("ip6zone");for(let[m,g]of this.stringTuples())m===f.code&&(o=`%${g??""}`),Ud.includes(m)&&(e=i.name,s=443,n=`${g??""}${o}`,t=m===u.code?6:4),(m===i.code||m===a.code)&&(e=q(m).name,s=parseInt(g??"")),(m===c.code||m===l.code)&&(e=q(m).name,n=`${g??""}${o}`,t=m===l.code?6:4);if(t==null||e==null||n==null||s==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:s}}protos(){return this.#t.map(([t])=>Object.assign({},q(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>q(t).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),s=n.lastIndexOf(e);if(s<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,s))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(ki(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,s])=>{n===wr.p2p.code&&t.push([n,s]),n===wr["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?H(J.decode(`z${n}`),"base58btc"):H(dt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return bt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(o=>o.resolvable);if(e==null)return[this];let n=xl.get(e.name);if(n==null)throw new Ni(`no available resolver for ${e.name}`);return(await n(this,t)).map(o=>ne(o))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[Ld](){return`Multiaddr(${this.#e})`}};var xl=new Map;function vl(r){return!!r?.[Ci]}function ne(r){return new ks(r)}var El="libp2p-peer-record",Bl=Uint8Array.from([3,1]);var tn;(function(r){let t;(function(n){let s;n.codec=()=>(s==null&&(s=Gt((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.multiaddr!=null&&o.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(o.multiaddr)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={multiaddr:pt(0)},l=i==null?o.len:o.pos+i;for(;o.pos<l;){let u=o.uint32();switch(u>>>3){case 1:{c.multiaddr=o.bytes();break}default:{o.skipType(u&7);break}}}return c})),s),n.encode=o=>zt(o,n.codec()),n.decode=(o,i)=>qt(o,n.codec(),i)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=Gt((n,s,o={})=>{if(o.lengthDelimited!==!1&&s.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(s.uint32(10),s.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(s.uint32(16),s.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)s.uint32(26),r.AddressInfo.codec().encode(i,s);o.lengthDelimited!==!1&&s.ldelim()},(n,s,o={})=>{let i={peerId:pt(0),seq:0n,addresses:[]},a=s==null?n.len:n.pos+s;for(;n.pos<a;){let c=n.uint32();switch(c>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(o.limits?.addresses!=null&&i.addresses.length===o.limits.addresses)throw new je('Decode error - map field "addresses" had too many elements');i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:o.limits?.addresses$}));break}default:{n.skipType(c&7);break}}}return i})),e),r.encode=n=>zt(n,r.codec()),r.decode=(n,s)=>qt(n,r.codec(),s)})(tn||(tn={}));var Zt=class r{static createFromProtobuf=t=>{let e=tn.decode(t),n=pi(Me(e.peerId)),s=(e.addresses??[]).map(i=>ne(i.multiaddr)),o=e.seq;return new r({peerId:n,multiaddrs:s,seqNumber:o})};static DOMAIN=El;static CODEC=Bl;peerId;multiaddrs;seqNumber;domain=r.DOMAIN;codec=r.CODEC;marshaled;constructor(t){let{peerId:e,multiaddrs:n,seqNumber:s}=t;this.peerId=e,this.multiaddrs=n??[],this.seqNumber=s??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=tn.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(t=>({multiaddr:t.bytes}))})),this.marshaled}equals(t){return!(!(t instanceof r)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!cl(this.multiaddrs,t.multiaddrs))}};function Rd(r){return r[Symbol.asyncIterator]!=null}function _d(r){if(Rd(r))return(async()=>{for await(let t of r);})();for(let t of r);}var Al=_d;function Yt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Ns=globalThis.CustomEvent??Event;async function*Ti(r,t={}){let e=t.concurrency??1/0;e<1&&(e=1/0);let n=t.ordered==null?!1:t.ordered,s=new EventTarget,o=[],i=Yt(),a=Yt(),c=!1,l,u=!1;s.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let g of r){if(o.length===e&&(i=Yt(),await i.promise),u)break;let b={done:!1};o.push(b),g().then(d=>{b.done=!0,b.ok=!0,b.value=d,s.dispatchEvent(new Ns("task-complete"))},d=>{b.done=!0,b.err=d,s.dispatchEvent(new Ns("task-complete"))})}c=!0,s.dispatchEvent(new Ns("task-complete"))}catch(g){l=g,s.dispatchEvent(new Ns("task-complete"))}});function f(){return n?o[0]?.done:!!o.find(g=>g.done)}function*h(){for(;o.length>0&&o[0].done;){let g=o[0];if(o.shift(),g.ok)yield g.value;else throw u=!0,i.resolve(),g.err;i.resolve()}}function*m(){for(;f();)for(let g=0;g<o.length;g++)if(o[g].done){let b=o[g];if(o.splice(g,1),g--,b.ok)yield b.value;else throw u=!0,i.resolve(),b.err;i.resolve()}}for(;;){if(f()||(a=Yt(),await a.promise),l!=null)throw l;if(n?yield*h():yield*m(),c&&o.length===0)break}}var Cs=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function Sl(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new Cs(e?.errorMessage,e?.errorCode,e?.errorName));let n,s=new Cs(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((o,i)=>{n=()=>{i(s)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Li=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=Yt(),this.haveNext=Yt()}[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 t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Yt(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Yt(),await Sl(this.readNext.promise,e?.signal,e)}};function Il(){return new Li}var Ts=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var Ui=class extends Error{code;constructor(t,e){super(t),this.code=e}},Ri=class extends Ui{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function kl(r,t){let e=Il();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let a of i)await e.push(a);await e.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 s=new jt;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,l=new Promise((u,f)=>{c=()=>{f(new Ri("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(i==null){let{done:f,value:h}=await Promise.race([n.next(),l]);return f===!0?new jt:h}for(;s.byteLength<i;){let{value:f,done:h}=await Promise.race([n.next(),l]);if(h===!0)throw new Ts("unexpected end of input");s.append(f)}let u=s.sublist(0,i);return s.consume(i),u}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,a):await e.push(i.subarray(),a)},unwrap:()=>{if(s.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield s:yield*s,yield*i}()}return r}}}var Ls=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Us=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Rs=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Nl(r,t={}){let e=kl(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=xt(t.maxDataLength));let n=t?.lengthDecoder??de,s=t?.lengthEncoder??Pt;return{read:async i=>{let a=-1,c=new jt;for(;;){c.append(await e.read(1,i));try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Ls("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Rs("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Us("message length too long");return e.read(a,i)},write:async(i,a)=>{await e.write(new jt(s(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new jt(...i.flatMap(l=>[s(l.byteLength),l]));await e.write(c,a)},unwrap:()=>e.unwrap()}}function xr(r,t){let e=Nl(r,t),n={read:async(s,o)=>{let i=await e.read(o);return s.decode(i)},write:async(s,o,i)=>{await e.write(o.encode(s),i)},writeV:async(s,o,i)=>{await e.writeV(s.map(a=>o.encode(a)),i)},pb:s=>({read:async o=>n.read(s,o),write:async(o,i)=>n.write(o,s,i),writeV:async(o,i)=>n.writeV(o,s,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var Cl="0.1.0",Tl="id",Ll="id/push",Ul="1.0.0",Rl="1.0.0";var Ve;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.protocolVersion!=null&&(n.uint32(42),n.string(e.protocolVersion)),e.agentVersion!=null&&(n.uint32(50),n.string(e.agentVersion)),e.publicKey!=null&&(n.uint32(10),n.bytes(e.publicKey)),e.listenAddrs!=null)for(let o of e.listenAddrs)n.uint32(18),n.bytes(o);if(e.observedAddr!=null&&(n.uint32(34),n.bytes(e.observedAddr)),e.protocols!=null)for(let o of e.protocols)n.uint32(26),n.string(o);e.signedPeerRecord!=null&&(n.uint32(66),n.bytes(e.signedPeerRecord)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={listenAddrs:[],protocols:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 5:{o.protocolVersion=e.string();break}case 6:{o.agentVersion=e.string();break}case 1:{o.publicKey=e.bytes();break}case 2:{if(s.limits?.listenAddrs!=null&&o.listenAddrs.length===s.limits.listenAddrs)throw new je('Decode error - map field "listenAddrs" had too many elements');o.listenAddrs.push(e.bytes());break}case 4:{o.observedAddr=e.bytes();break}case 3:{if(s.limits?.protocols!=null&&o.protocols.length===s.limits.protocols)throw new je('Decode error - map field "protocols" had too many elements');o.protocols.push(e.string());break}case 8:{o.signedPeerRecord=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>qt(e,r.codec(),n)})(Ve||(Ve={}));var Ol=zs(Pl(),1),_i=typeof window=="object"&&typeof document=="object"&&document.nodeType===9,_s=(0,Ol.default)(),Vl=_i&&!_s,Dl=_s&&!_i,Ml=_s&&_i,Fl=typeof globalThis.process<"u"&&typeof globalThis.process.release<"u"&&globalThis.process.release.name==="node"&&!_s,Hl=typeof importScripts=="function"&&typeof self<"u"&&typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,hx=typeof globalThis.process<"u"&&typeof globalThis.process.env<"u"&&globalThis.process.env["NODE"+"_"+"ENV"]==="test",Kl=typeof navigator<"u"&&navigator.product==="ReactNative";var Ut={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function $l(r){if(r!=null&&r.length>0)try{return ne(r)}catch{}}function Dd(r,t){return t!=null||(t=`${r.name}/${r.version}`,Fl||Dl?t+=` UserAgent=${globalThis.process.version}`:(Vl||Hl||Ml||Kl)&&(t+=` UserAgent=${globalThis.navigator.userAgent}`)),t}async function Ps(r,t,e,n,s){if(e("received identify from %p",n.remotePeer),s==null)throw new Dt("message was null or undefined");let o={};if(s.listenAddrs.length>0&&(o.addresses=s.listenAddrs.map(c=>({isCertified:!1,multiaddr:ne(c)}))),s.protocols.length>0&&(o.protocols=s.protocols),s.publicKey!=null){let c=gr(s.publicKey);if(!al(c).equals(n.remotePeer))throw new Dt("public key did not match remote PeerId");o.publicKey=c}let i;if(s.signedPeerRecord!=null){e.trace("received signedPeerRecord from %p",n.remotePeer);let c=s.signedPeerRecord,l=await re.openAndCertify(c,Zt.DOMAIN),u=Zt.createFromProtobuf(l.payload),f=Bs(l.publicKey.toCID());if(!u.peerId.equals(f))throw new Dt("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(u.peerId))throw new Dt("signing key does not match remote PeerId");let h;try{h=await r.get(u.peerId)}catch(m){if(m.name!=="NotFoundError")throw m}if(h!=null&&(o.metadata=h.metadata,h.peerRecordEnvelope!=null)){let m=await re.createFromProtobuf(h.peerRecordEnvelope),g=Zt.createFromProtobuf(m.payload);g.seqNumber>=u.seqNumber&&(e("sequence number was lower or equal to existing sequence number - stored: %d received: %d",g.seqNumber,u.seqNumber),u=g,c=h.peerRecordEnvelope)}o.peerRecordEnvelope=c,o.addresses=u.multiaddrs.map(m=>({isCertified:!0,multiaddr:m})),i={seq:u.seqNumber,addresses:u.multiaddrs}}else e("%p did not send a signed peer record",n.remotePeer);if(e.trace("patching %p with",n.remotePeer,o),await r.patch(n.remotePeer,o),s.agentVersion!=null||s.protocolVersion!=null){let c={};s.agentVersion!=null&&(c.AgentVersion=$(s.agentVersion)),s.protocolVersion!=null&&(c.ProtocolVersion=$(s.protocolVersion)),e.trace("merging %p metadata",n.remotePeer,c),await r.merge(n.remotePeer,{metadata:c})}let a={peerId:n.remotePeer,protocolVersion:s.protocolVersion,agentVersion:s.agentVersion,publicKey:s.publicKey,listenAddrs:s.listenAddrs.map(c=>ne(c)),observedAddr:s.observedAddr==null?void 0:ne(s.observedAddr),protocols:s.protocols,signedPeerRecord:i,connection:n};return t.safeDispatchEvent("peer:identify",{detail:a}),a}var vr=class{host;protocol;started;timeout;peerId;privateKey;peerStore;registrar;addressManager;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;events;runOnLimitedConnection;log;constructor(t,e){this.protocol=e.protocol,this.started=!1,this.peerId=t.peerId,this.privateKey=t.privateKey,this.peerStore=t.peerStore,this.registrar=t.registrar,this.addressManager=t.addressManager,this.events=t.events,this.log=e.log,this.timeout=e.timeout??Ut.timeout,this.maxInboundStreams=e.maxInboundStreams??Ut.maxInboundStreams,this.maxOutboundStreams=e.maxOutboundStreams??Ut.maxOutboundStreams,this.maxMessageSize=e.maxMessageSize??Ut.maxMessageSize,this.maxObservedAddresses=e.maxObservedAddresses??Ut.maxObservedAddresses,this.runOnLimitedConnection=e.runOnLimitedConnection??Ut.runOnLimitedConnection,this.host={protocolVersion:`${e.protocolPrefix??Ut.protocolPrefix}/${Cl}`,agentVersion:Dd(t.nodeInfo,e.agentVersion)}}isStarted(){return this.started}async start(){this.started||(await this.peerStore.merge(this.peerId,{metadata:{AgentVersion:$(this.host.agentVersion),ProtocolVersion:$(this.host.protocolVersion)}}),await this.registrar.handle(this.protocol,t=>{this.handleProtocol(t).catch(e=>{this.log.error(e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.registrar.unhandle(this.protocol),this.started=!1}};var Os=class extends vr{connectionManager;concurrency;constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Ut.protocolPrefix}/${Ll}/${Rl}`,log:t.logger.forComponent("libp2p:identify-push")}),this.connectionManager=t.connectionManager,this.concurrency=e.concurrency??Ut.concurrency,(e.runOnSelfUpdate??Ut.runOnSelfUpdate)&&t.events.addEventListener("self:peer:update",n=>{this.push().catch(s=>{this.log.error(s)})})}[ln]=["@libp2p/identify-push"];async push(){if(!this.isStarted())return;let t=this.addressManager.getAddresses().map(u=>u.decapsulateCode(q("p2p").code)),e=new Zt({peerId:this.peerId,multiaddrs:t}),n=await re.seal(e,this.privateKey),s=this.registrar.getProtocols(),o=await this.peerStore.get(this.peerId),i=H(o.metadata.get("AgentVersion")??$(this.host.agentVersion)),a=H(o.metadata.get("ProtocolVersion")??$(this.host.protocolVersion)),c=this;async function*l(){for(let u of c.connectionManager.getConnections())(await c.peerStore.get(u.remotePeer)).protocols.includes(c.protocol)&&(yield async()=>{let h,m=AbortSignal.timeout(c.timeout);Ar(1/0,m);try{h=await u.newStream(c.protocol,{signal:m,runOnLimitedConnection:c.runOnLimitedConnection}),await xr(h,{maxDataLength:c.maxMessageSize}).pb(Ve).write({listenAddrs:t.map(b=>b.bytes),signedPeerRecord:n.marshal(),protocols:s,agentVersion:i,protocolVersion:a},{signal:m}),await h.close({signal:m})}catch(g){c.log.error("could not push identify update to peer",g),h?.abort(g)}})}await Al(Ti(l(),{concurrency:this.concurrency}))}async handleProtocol(t){let{connection:e,stream:n}=t;try{if(this.peerId.equals(e.remotePeer))throw new Error("received push from ourselves?");let s={signal:AbortSignal.timeout(this.timeout)},i=await xr(n,{maxDataLength:this.maxMessageSize}).pb(Ve).read(s);await n.close(s),await Ps(this.peerStore,this.events,this.log,e,i)}catch(s){this.log.error("received invalid message",s),n.abort(s);return}this.log.trace("handled push from %p",e.remotePeer)}};var zl=zs(ql(),1),Md=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],Fd=Md.map(r=>new zl.Netmask(r));function Pi(r){for(let t of Fd)if(t.contains(r))return!0;return!1}function Hd(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Kd(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),s=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return Pi(s)}function $d(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function qd(r){let t=r.split(":"),e=t[t.length-1];return Pi(e)}function zd(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function Gl(r){return yr(r)?Pi(r):Hd(r)?Kd(r):$d(r)?qd(r):br(r)?zd(r):void 0}var Gd=r=>r.toString().split("/").slice(1),rn=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),z=r=>({match:t=>rn(e=>e===r).match(t),pattern:r}),Ms=()=>({match:r=>rn(t=>typeof t=="string").match(r),pattern:"{string}"}),Fs=()=>({match:r=>rn(t=>!isNaN(parseInt(t))).match(r),pattern:"{number}"}),yt=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{J.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Vs=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Vo.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),ct=r=>({match:t=>{let e=r.match(t);return e===!1?t:e},pattern:`optional(${r.pattern})`}),Vt=(...r)=>({match:t=>{let e;for(let n of r){let s=n.match(t);s!==!1&&(e==null||s.length<e.length)&&(e=s)}return e??!1},pattern:`or(${r.map(t=>t.pattern).join(", ")})`}),Z=(...r)=>({match:t=>{for(let e of r){let n=e.match(t);if(n===!1)return!1;t=n}return t},pattern:`and(${r.map(t=>t.pattern).join(", ")})`});function rt(...r){function t(s){let o=Gd(s);for(let i of r){let a=i.match(o);if(a===!1)return!1;o=a}return o}function e(s){return t(s)!==!1}function n(s){let o=t(s);return o===!1?!1:o.length===0}return{matches:e,exactMatch:n}}var Vi=Z(z("dns4"),Ms()),Di=Z(z("dns6"),Ms()),Mi=Z(z("dnsaddr"),Ms()),Wl=Z(z("dns"),Ms()),Kx=rt(Vi),$x=rt(Di),qx=rt(Mi),zx=rt(Vt(Wl,Mi,Vi,Di)),jl=Z(z("ip4"),rn(yr)),Zl=Z(z("ip6"),rn(br)),Yl=Vt(jl,Zl),se=Vt(Yl,Wl,Vi,Di,Mi),Jl=rt(se),Gx=rt(jl),Wx=rt(Zl),jx=rt(Yl),Fi=Z(se,z("tcp"),Fs()),nn=Z(se,z("udp"),Fs()),Zx=rt(Fi),Yx=rt(nn),Hi=Z(nn,z("quic")),Hs=Z(nn,z("quic-v1")),Wd=Vt(Hi,Hs),Jx=rt(Hi),Xx=rt(Hs),Oi=Vt(se,Fi,nn,Hi,Hs),Xl=Vt(Z(Oi,z("ws"),ct(yt()))),Qx=rt(Xl),Ql=Vt(Z(Oi,z("wss"),ct(yt())),Z(Oi,z("tls"),z("ws"),ct(yt()))),t1=rt(Ql),tu=Z(nn,z("webrtc-direct"),ct(Vs()),ct(Vs()),ct(yt())),e1=rt(tu),eu=Z(Hs,z("webtransport"),ct(Vs()),ct(Vs()),ct(yt())),r1=rt(eu),Ds=Vt(Xl,Ql,Z(Fi,ct(yt())),Z(Wd,ct(yt())),Z(se,ct(yt())),tu,eu,yt()),n1=rt(Ds),jd=Z(Ds,z("p2p-circuit"),yt()),s1=rt(jd),Zd=Vt(Z(Ds,z("p2p-circuit"),z("webrtc"),ct(yt())),Z(Ds,z("webrtc"),ct(yt())),z("webrtc")),o1=rt(Zd),Yd=Vt(Z(se,z("tcp"),Fs(),z("http"),ct(yt())),Z(se,z("http"),ct(yt()))),i1=rt(Yd),Jd=Vt(Z(se,z("tcp"),Vt(Z(z("443"),z("http")),Z(Fs(),z("https"))),ct(yt())),Z(se,z("tls"),z("http"),ct(yt())),Z(se,z("https"),ct(yt()))),a1=rt(Jd);var Ks=class extends vr{constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Ut.protocolPrefix}/${Tl}/${Ul}`,log:t.logger.forComponent("libp2p:identify")}),(e.runOnConnectionOpen??Ut.runOnConnectionOpen)&&t.events.addEventListener("connection:open",n=>{let s=n.detail;this.identify(s).catch(o=>{o.name!==cn.name&&this.log.error("error during identify trigged by connection:open",o)})})}[ln]=["@libp2p/identify"];async _identify(t,e={}){let n;if(e.signal==null){let s=AbortSignal.timeout(this.timeout);Ar(1/0,s),e={...e,signal:s}}try{n=await t.newStream(this.protocol,{...e,runOnLimitedConnection:this.runOnLimitedConnection});let o=await xr(n,{maxDataLength:this.maxMessageSize}).pb(Ve).read(e);return await n.close(e),o}catch(s){throw n?.abort(s),s}}async identify(t,e={}){let n=await this._identify(t,e),{publicKey:s,protocols:o,observedAddr:i}=n;if(s==null)throw new Dt("public key was missing from identify message");let a=gr(s),c=Bs(a.toCID());if(!t.remotePeer.equals(c))throw new Dt("identified peer does not match the expected peer");if(this.peerId.equals(c))throw new Dt("identified peer is our own peer id?");let l=$l(i);return this.log("identify completed for peer %p and protocols %o",c,o),l!=null&&(this.log("our observed address was %a",l),Gl(l?.nodeAddress().address)===!0?this.log("our observed address was private"):this.addressManager.getObservedAddrs().length<(this.maxObservedAddresses??1/0)&&(this.log("storing our observed address"),this.addressManager.addObservedAddr(l))),Ps(this.peerStore,this.events,this.log,t,n)}async handleProtocol(t){let{connection:e,stream:n}=t,s=AbortSignal.timeout(this.timeout);Ar(1/0,s);try{let o=await this.peerStore.get(this.peerId),i=this.addressManager.getAddresses().map(u=>u.decapsulateCode(q("p2p").code)),a=o.peerRecordEnvelope;if(i.length>0&&a==null){let u=new Zt({peerId:this.peerId,multiaddrs:i});a=(await re.seal(u,this.privateKey)).marshal().subarray()}let c=e.remoteAddr.bytes;Jl.matches(e.remoteAddr)||(c=void 0),await xr(n).pb(Ve).write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Te(this.privateKey.publicKey),listenAddrs:i.map(u=>u.bytes),signedPeerRecord:a,observedAddr:c,protocols:o.protocols},{signal:s}),await n.close({signal:s})}catch(o){this.log.error("could not respond to identify request",o),n.abort(o)}}};function Xd(r={}){return t=>new Ks(t,r)}function Qd(r={}){return t=>new Os(t,r)}return gu(t0);})();
|
|
7
7
|
/*! Bundled license information:
|
|
8
8
|
|
|
9
9
|
pvtsutils/build/index.js:
|