@helia/ipns 7.2.3-ac4bdb8 → 7.2.3-e567717
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +4 -4
- package/package.json +2 -2
package/dist/index.min.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaIpns = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var HeliaIpns=(()=>{var
|
|
3
|
-
`,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return h;function h(x,T,V){var C=this;if(!(C instanceof h))return new h(x,T,V);C.time=+x||0,C.nano=+T||0,C.year=+V||0,m(C)}function m(x){var T,V,C,F=x.year,K=x.time,S=x.nano,p=((S<0||a<=S)&&(S-=(V=Math.floor(S/a))*a,K+=V,V=1),F%e);return(K<-i||i<K||p)&&((T=f(K/o))&&(F+=T*e,K-=T*o),(C=v(K)).setUTCFullYear(p+C.getUTCFullYear()),C=(K=+C)+(T=f((F-=p)/e))*o,T&&-i<=C&&C<=i&&(F-=T*e,K=C),V=1),V&&(x.year=F,x.time=K,x.nano=S),x}function v(x){var T=new Date(0);return T.setTime(x),T}function E(F,C){F=+F||0;var V=f((C=(C|0)*s)/n)+f(F/n),C=C%n+F%n,F=f(C/n);return F&&(V+=F,C-=F*n),new h(1e3*C,0,V*e)}function B(x,T,V,C,F,K){return function(p,d){var k=m(this);p=p||new Array(8),U(p,d|=0);var O=Math.floor(k.time/1e3),k=k.year*(t*r/e),A=f(k/s)+f(O/s),k=k%s+O%s,O=Math.floor(k/s);return O&&(A+=O,k-=O*s),S(p,d+F,A),S(p,d+K,k),p};function S(p,d,A){p[d+x]=A>>24&255,p[d+T]=A>>16&255,p[d+V]=A>>8&255,p[d+C]=255&A}}function L(x,T,V,C,F,K){return function(p,d){U(p,d|=0);var A=S(p,d+F);return E(S(p,d+K),A)};function S(p,d){return 16777216*p[d+x]+(p[d+T]<<16|p[d+V]<<8|p[d+C])}}function U(x,T){if(x=x&&x.length,x==null)throw new TypeError("Invalid Buffer");if(x<T+8)throw new RangeError("Out of range")}function I(x){return(9<x?"":"0")+(0|x)}function D(x,T){return(c+(0|x)).substr(-T)}}()});var af=Ln((i1,sf)=>{sf.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function o(i,s){t[i]=s,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(i){return t[i]!==void 0||n[i]!==void 0},remove:function(i){t[i]!==void 0&&(t[i]=void 0),n[i]!==void 0&&(n[i]=void 0)},get:function(i){var s=t[i];if(s!==void 0)return s;if((s=n[i])!==void 0)return o(i,s),s},set:function(i,s){t[i]!==void 0?t[i]=s:o(i,s)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var Qp={};he(Qp,{ipns:()=>Xp,ipnsSelector:()=>hi,ipnsValidator:()=>pi});var Vn=Symbol.for("@libp2p/peer-id");function fa(r){return r!=null&&!!r[Vn]}var H=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var vi={};he(vi,{base32:()=>Ct,base32hex:()=>Lf,base32hexpad:()=>Of,base32hexpadupper:()=>Ff,base32hexupper:()=>Vf,base32pad:()=>Uf,base32padupper:()=>Df,base32upper:()=>wa,base32z:()=>Pf});var ng=new Uint8Array(0);function ha(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 ft(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 da(r){return new TextEncoder().encode(r)}function pa(r){return new TextDecoder().decode(r)}function If(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var h=0,m=0,v=0,E=w.length;v!==E&&w[v]===0;)v++,h++;for(var B=(E-v)*u+1>>>0,L=new Uint8Array(B);v!==E;){for(var U=w[v],I=0,D=B-1;(U!==0||I<m)&&D!==-1;D--,I++)U+=256*L[D]>>>0,L[D]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");m=I,v++}for(var x=B-m;x!==B&&L[x]===0;)x++;for(var T=c.repeat(h);x<B;++x)T+=r.charAt(L[x]);return T}function g(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var h=0;if(w[h]!==" "){for(var m=0,v=0;w[h]===c;)m++,h++;for(var E=(w.length-h)*f+1>>>0,B=new Uint8Array(E);w[h];){var L=t[w.charCodeAt(h)];if(L===255)return;for(var U=0,I=E-1;(L!==0||U<v)&&I!==-1;I--,U++)L+=a*B[I]>>>0,B[I]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");v=U,h++}if(w[h]!==" "){for(var D=E-v;D!==E&&B[D]===0;)D++;for(var x=new Uint8Array(m+(E-D)),T=m;D!==E;)x[T++]=B[D++];return x}}}function b(w){var h=g(w);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:g,decode:b}}var Tf=If,Cf=Tf,ma=Cf;var wi=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")}},xi=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),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 ya(this,e)}},bi=class{decoders;constructor(e){this.decoders=e}or(e){return ya(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 ya(r,e){return new bi({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ei=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 wi(e,t,n),this.decoder=new xi(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function gr({name:r,prefix:e,encode:t,decode:n}){return new Ei(r,e,t,n)}function Tt({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=ma(t,r);return gr({prefix:e,name:r,encode:n,decode:i=>ft(o(i))})}function Nf(r,e,t,n){let o={};for(let u=0;u<e.length;++u)o[e[u]]=u;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),a=0,c=0,f=0;for(let u=0;u<i;++u){let l=o[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|l,a+=t,a>=8&&(a-=8,s[f++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s}function _f(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;i.length*t&7;)i+="=";return i}function oe({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return gr({prefix:e,name:r,encode(o){return _f(o,n,t)},decode(o){return Nf(o,n,t,r)}})}var Ct=oe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),wa=oe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Uf=oe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Df=oe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Lf=oe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Vf=oe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Of=oe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ff=oe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Pf=oe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Bi={};he(Bi,{base58btc:()=>me,base58flickr:()=>Mf});var me=Tt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Mf=Tt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ai={};he(Ai,{base64:()=>Zr,base64pad:()=>Hf,base64url:()=>Kf,base64urlpad:()=>$f});var Zr=oe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Hf=oe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Kf=oe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),$f=oe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function qf(r,e){try{if(typeof r=="string"&&r.length>0)return zf(r);if(typeof r=="number"&&isFinite(r))return e?.long?jf(r):Gf(r);throw new Error("Value is not a string or number.")}catch(t){let n=Yf(t)?`${t.message}. value=${JSON.stringify(r)}`:"An unknown error has occured.";throw new Error(n)}}function zf(r){if(r=String(r),r.length>100)throw new Error("Value exceeds the maximum length of 100 characters.");let e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(!e)return NaN;let t=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return t*315576e5;case"weeks":case"week":case"w":return t*6048e5;case"days":case"day":case"d":return t*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return t*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return t*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return t*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:throw new Error(`The unit ${n} was matched, but no matching case exists.`)}}var Fn=qf;function Gf(r){let e=Math.abs(r);return e>=864e5?`${Math.round(r/864e5)}d`:e>=36e5?`${Math.round(r/36e5)}h`:e>=6e4?`${Math.round(r/6e4)}m`:e>=1e3?`${Math.round(r/1e3)}s`:`${r}ms`}function jf(r){let e=Math.abs(r);return e>=864e5?On(r,e,864e5,"day"):e>=36e5?On(r,e,36e5,"hour"):e>=6e4?On(r,e,6e4,"minute"):e>=1e3?On(r,e,1e3,"second"):`${r} ms`}function On(r,e,t,n){let o=e>=t*1.5;return`${Math.round(r/t)} ${n}${o?"s":""}`}function Yf(r){return typeof r=="object"&&r!==null&&"message"in r}function Si(r){t.debug=t,t.default=t,t.coerce=c,t.disable=i,t.enable=o,t.enabled=s,t.humanize=Fn,t.destroy=f,Object.keys(r).forEach(u=>{t[u]=r[u]}),t.names=[],t.skips=[],t.formatters={};function e(u){let l=0;for(let g=0;g<u.length;g++)l=(l<<5)-l+u.charCodeAt(g),l|=0;return t.colors[Math.abs(l)%t.colors.length]}t.selectColor=e;function t(u){let l,g=null,b,w;function h(...m){if(!h.enabled)return;let v=h,E=Number(new Date),B=E-(l||E);v.diff=B,v.prev=l,v.curr=E,l=E,m[0]=t.coerce(m[0]),typeof m[0]!="string"&&m.unshift("%O");let L=0;m[0]=m[0].replace(/%([a-zA-Z%])/g,(I,D)=>{if(I==="%%")return"%";L++;let x=t.formatters[D];if(typeof x=="function"){let T=m[L];I=x.call(v,T),m.splice(L,1),L--}return I}),t.formatArgs.call(v,m),(v.log||t.log).apply(v,m)}return h.namespace=u,h.useColors=t.useColors(),h.color=t.selectColor(u),h.extend=n,h.destroy=t.destroy,Object.defineProperty(h,"enabled",{enumerable:!0,configurable:!1,get:()=>g!==null?g:(b!==t.namespaces&&(b=t.namespaces,w=t.enabled(u)),w),set:m=>{g=m}}),typeof t.init=="function"&&t.init(h),h}function n(u,l){let g=t(this.namespace+(typeof l>"u"?":":l)+u);return g.log=this.log,g}function o(u){t.save(u),t.namespaces=u,t.names=[],t.skips=[];let l,g=(typeof u=="string"?u:"").split(/[\s,]+/),b=g.length;for(l=0;l<b;l++)g[l]&&(u=g[l].replace(/\*/g,".*?"),u[0]==="-"?t.skips.push(new RegExp("^"+u.substr(1)+"$")):t.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...t.names.map(a),...t.skips.map(a).map(l=>"-"+l)].join(",");return t.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let l,g;for(l=0,g=t.skips.length;l<g;l++)if(t.skips[l].test(u))return!1;for(l=0,g=t.names.length;l<g;l++)if(t.names[l].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack??u.message:u}function f(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.setupFormatters(t.formatters),t.enable(t.load()),t}var Pn=th(),Zf=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Wf(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function Jf(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+Fn(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(t++,o==="%c"&&(n=t))}),r.splice(n,0,e)}var Xf=console.debug??console.log??(()=>{});function Qf(r){try{r?Pn?.setItem("debug",r):Pn?.removeItem("debug")}catch{}}function eh(){let r;try{r=Pn?.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function th(){try{return localStorage}catch{}}function rh(r){r.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}}var xa=Si({formatArgs:Jf,save:Qf,load:eh,useColors:Wf,setupFormatters:rh,colors:Zf,storage:Pn,log:Xf});var Ue=xa;Ue.formatters.b=r=>r==null?"undefined":me.baseEncode(r);Ue.formatters.t=r=>r==null?"undefined":Ct.baseEncode(r);Ue.formatters.m=r=>r==null?"undefined":Zr.baseEncode(r);Ue.formatters.p=r=>r==null?"undefined":r.toString();Ue.formatters.c=r=>r==null?"undefined":r.toString();Ue.formatters.k=r=>r==null?"undefined":r.toString();Ue.formatters.a=r=>r==null?"undefined":r.toString();function nh(r){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=r,e.destroy=()=>!0,e.extend=()=>e,e}function Nt(r){let e=nh(`${r}:trace`);return Ue.enabled(`${r}:trace`)&&Ue.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=Ue(`${r}:trace`)),Object.assign(Ue(r),{error:Ue(`${r}:error`),trace:e})}var Ri={};he(Ri,{base10:()=>oh});var oh=Tt({prefix:"9",name:"base10",alphabet:"0123456789"});var ki={};he(ki,{base16:()=>ih,base16upper:()=>sh});var ih=oe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),sh=oe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ii={};he(Ii,{base2:()=>ah});var ah=oe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ti={};he(Ti,{base256emoji:()=>hh});var ba=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}"),ch=ba.reduce((r,e,t)=>(r[t]=e,r),[]),uh=ba.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function lh(r){return r.reduce((e,t)=>(e+=ch[t],e),"")}function fh(r){let e=[];for(let t of r){let n=uh[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var hh=gr({prefix:"\u{1F680}",name:"base256emoji",encode:lh,decode:fh});var Ci={};he(Ci,{base36:()=>Mn,base36upper:()=>dh});var Mn=Tt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),dh=Tt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ni={};he(Ni,{base8:()=>ph});var ph=oe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var _i={};he(_i,{identity:()=>gh});var gh=gr({prefix:"\0",name:"identity",encode:r=>pa(r),decode:r=>da(r)});var _g=new TextEncoder,Ug=new TextDecoder;var Di={};he(Di,{identity:()=>ze});var wh=Ba,Ea=128,xh=127,bh=~xh,Eh=Math.pow(2,31);function Ba(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Eh;)e[t++]=r&255|Ea,r/=128;for(;r&bh;)e[t++]=r&255|Ea,r>>>=7;return e[t]=r|0,Ba.bytes=t-n+1,e}var vh=Ui,Bh=128,va=127;function Ui(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Ui.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&va)<<o:(s&va)*Math.pow(2,o),o+=7}while(s>=Bh);return Ui.bytes=i-n,t}var Ah=Math.pow(2,7),Sh=Math.pow(2,14),Rh=Math.pow(2,21),kh=Math.pow(2,28),Ih=Math.pow(2,35),Th=Math.pow(2,42),Ch=Math.pow(2,49),Nh=Math.pow(2,56),_h=Math.pow(2,63),Uh=function(r){return r<Ah?1:r<Sh?2:r<Rh?3:r<kh?4:r<Ih?5:r<Th?6:r<Ch?7:r<Nh?8:r<_h?9:10},Dh={encode:wh,decode:vh,encodingLength:Uh},Lh=Dh,Wr=Lh;function Jr(r,e=0){return[Wr.decode(r,e),Wr.decode.bytes]}function mr(r,e,t=0){return Wr.encode(r,e,t),e}function yr(r){return Wr.encodingLength(r)}function tt(r,e){let t=e.byteLength,n=yr(r),o=n+yr(t),i=new Uint8Array(o+t);return mr(r,i,0),mr(t,i,n),i.set(e,o),new wr(r,t,e,i)}function Qt(r){let e=ft(r),[t,n]=Jr(e),[o,i]=Jr(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new wr(t,o,s,e)}function Aa(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ha(r.bytes,t.bytes)}}var wr=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var Sa=0,Vh="identity",Ra=ft;function Oh(r){return tt(Sa,Ra(r))}var ze={code:Sa,name:Vh,encode:Ra,digest:Oh};var Oi={};he(Oi,{sha256:()=>ye,sha512:()=>Fh});function Vi({name:r,code:e,encode:t}){return new Li(r,e,t)}var Li=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?tt(this.code,t):t.then(n=>tt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ia(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var ye=Vi({name:"sha2-256",code:18,encode:Ia("SHA-256")}),Fh=Vi({name:"sha2-512",code:19,encode:Ia("SHA-512")});function Ta(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Mh(t,Fi(r),e??me.encoder);default:return Hh(t,Fi(r),e??Ct.encoder)}}var Ca=new WeakMap;function Fi(r){let e=Ca.get(r);if(e==null){let t=new Map;return Ca.set(r,t),t}return e}var Ee=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!==Xr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Kh)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=tt(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Aa(e.multihash,n.multihash)}toString(e){return Ta(this,e)}toJSON(){return{"/":Ta(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??Na(n,o,i.bytes))}else if(t[$h]===!0){let{version:n,multihash:o,code:i}=t,s=Qt(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Xr)throw new Error(`Version 0 CID must use dag-pb (code: ${Xr}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Na(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Xr,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=ft(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new wr(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,g]=Jr(e.subarray(t));return t+=g,l},o=n(),i=Xr;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),f=t+c,u=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,t){let[n,o]=Ph(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Fi(i).set(n,e),i}};function Ph(r,e){switch(r[0]){case"Q":{let t=e??me;return[me.prefix,t.decode(`${me.prefix}${r}`)]}case me.prefix:{let t=e??me;return[me.prefix,t.decode(r)]}case Ct.prefix:{let t=e??Ct;return[Ct.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Mh(r,e,t){let{prefix:n}=t;if(n!==me.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function Hh(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var Xr=112,Kh=18;function Na(r,e,t){let n=yr(r),o=n+yr(e),i=new Uint8Array(o+t.byteLength);return mr(r,i,0),mr(e,i,n),i.set(t,o),i}var $h=Symbol.for("@ipld/js-cid/CID");var xr={..._i,...Ii,...Ni,...Ri,...ki,...vi,...Ci,...Bi,...Ai,...Ti},em={...Oi,...Di};function ce(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 Pi(r=0){return new Uint8Array(r)}function rt(r=0){return new Uint8Array(r)}function Ua(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var _a=Ua("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Mi=Ua("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=rt(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),qh={utf8:_a,"utf-8":_a,hex:xr.base16,latin1:Mi,ascii:Mi,binary:Mi,...xr},Kn=qh;function j(r,e="utf8"){let t=Kn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function X(r,e="utf8"){let t=Kn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var La=Symbol.for("nodejs.util.inspect.custom"),Da=Object.values(xr).map(r=>r.decoder).reduce((r,e)=>r.or(e),xr.identity.decoder),Va=114,$i=36,qi=37,Qr=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Vn]=!0;toString(){return this.string==null&&(this.string=me.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Ee.createV1(Va,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ce(this.multihash.bytes,e);if(typeof e=="string")return en(e).equals(this);if(e?.multihash?.bytes!=null)return ce(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[La](){return`PeerId(${this.toString()})`}},br=class extends Qr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Er=class extends Qr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},vr=class extends Qr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}},Hi=2336,Ki=class{type="url";multihash;privateKey;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=ze.digest(j(this.url))}[La](){return`PeerId(${this.url})`}[Vn]=!0;toString(){return this.toCID().toString()}toCID(){return Ee.createV1(Hi,this.multihash)}toBytes(){return this.toCID().bytes}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=X(e)),e.toString()===this.toString())}};function en(r,e){if(e=e??Da,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=Qt(me.decode(`z${r}`));return r.startsWith("12D")?new Er({multihash:t}):r.startsWith("16U")?new vr({multihash:t}):new br({multihash:t})}return zi(Da.decode(r))}function zi(r){try{let e=Qt(r);if(e.code===ze.code){if(e.digest.length===$i)return new Er({multihash:e});if(e.digest.length===qi)return new vr({multihash:e})}if(e.code===ye.code)return new br({multihash:e})}catch{return zh(Ee.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function zh(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==Va&&r.code!==Hi)throw new Error("Supplied PeerID CID is invalid");if(r.code===Hi){let t=X(r.multihash.digest);return new Ki(new URL(t))}let e=r.multihash;if(e.code===ye.code)return new br({multihash:r.multihash});if(e.code===ze.code){if(e.digest.length===$i)return new Er({multihash:r.multihash});if(e.digest.length===qi)return new vr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function Oa(r,e){return r.length===$i?new Er({multihash:tt(ze.code,r),privateKey:e}):r.length===qi?new vr({multihash:tt(ze.code,r),privateKey:e}):new br({multihash:await ye.digest(r),publicKey:r,privateKey:e})}var bs={};he(bs,{Ed25519PrivateKey:()=>cr,Ed25519PublicKey:()=>ln,generateKeyPair:()=>d0,generateKeyPairFromSeed:()=>Bc,unmarshalEd25519PrivateKey:()=>f0,unmarshalEd25519PublicKey:()=>h0});function tr(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=rt(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}function Pe(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Br(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function Gh(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Ar(r,...e){if(!Gh(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 $n(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Br(r.outputLen),Br(r.blockLen)}function Sr(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 Fa(r,e){Ar(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var qn=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var kr=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Ge=(r,e)=>r<<32-e|r>>>e;var Um=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var jh=async()=>{};async function Pa(r,e,t){let n=Date.now();for(let o=0;o<r;o++){t(o);let i=Date.now()-n;i>=0&&i<e||(await jh(),n+=i)}}function Ma(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function _t(r){return typeof r=="string"&&(r=Ma(r)),Ar(r),r}function Gi(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];Ar(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}var Rr=class{clone(){return this._cloneInto()}},Yh={}.toString;function Ha(r,e){if(e!==void 0&&Yh.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function zn(r){let e=n=>r().update(_t(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Ir(r=32){if(qn&&typeof qn.getRandomValues=="function")return qn.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Zh(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(t>>o&i),a=Number(t&i),c=n?4:0,f=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+f,a,n)}var Ka=(r,e,t)=>r&e^~r&t,$a=(r,e,t)=>r&e^r&t^e&t,Tr=class extends Rr{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=kr(this.buffer)}update(e){Sr(this);let{view:t,buffer:n,blockLen:o}=this;e=_t(e);let i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=kr(e);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Sr(this),Fa(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)t[l]=0;Zh(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=kr(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.length=o,e.pos=a,e.finished=i,e.destroyed=s,o%t&&e.buffer.set(n),e}};var Gn=BigInt(4294967295),ji=BigInt(32);function qa(r,e=!1){return e?{h:Number(r&Gn),l:Number(r>>ji&Gn)}:{h:Number(r>>ji&Gn)|0,l:Number(r&Gn)|0}}function Wh(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:i,l:s}=qa(r[o],e);[t[o],n[o]]=[i,s]}return[t,n]}var Jh=(r,e)=>BigInt(r>>>0)<<ji|BigInt(e>>>0),Xh=(r,e,t)=>r>>>t,Qh=(r,e,t)=>r<<32-t|e>>>t,ed=(r,e,t)=>r>>>t|e<<32-t,td=(r,e,t)=>r<<32-t|e>>>t,rd=(r,e,t)=>r<<64-t|e>>>t-32,nd=(r,e,t)=>r>>>t-32|e<<64-t,od=(r,e)=>e,id=(r,e)=>r,sd=(r,e,t)=>r<<t|e>>>32-t,ad=(r,e,t)=>e<<t|r>>>32-t,cd=(r,e,t)=>e<<t-32|r>>>64-t,ud=(r,e,t)=>r<<t-32|e>>>64-t;function ld(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var fd=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),hd=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,dd=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),pd=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,gd=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),md=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var yd={fromBig:qa,split:Wh,toBig:Jh,shrSH:Xh,shrSL:Qh,rotrSH:ed,rotrSL:td,rotrBH:rd,rotrBL:nd,rotr32H:od,rotr32L:id,rotlSH:sd,rotlSL:ad,rotlBH:cd,rotlBL:ud,add:ld,add3L:fd,add3H:hd,add4L:dd,add4H:pd,add5H:md,add5L:gd},q=yd;var[wd,xd]=q.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))),Ut=new Uint32Array(80),Dt=new Uint32Array(80),Yi=class extends Tr{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:i,Cl:s,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:g,Gh:b,Gl:w,Hh:h,Hl:m}=this;return[e,t,n,o,i,s,a,c,f,u,l,g,b,w,h,m]}set(e,t,n,o,i,s,a,c,f,u,l,g,b,w,h,m){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=g|0,this.Gh=b|0,this.Gl=w|0,this.Hh=h|0,this.Hl=m|0}process(e,t){for(let B=0;B<16;B++,t+=4)Ut[B]=e.getUint32(t),Dt[B]=e.getUint32(t+=4);for(let B=16;B<80;B++){let L=Ut[B-15]|0,U=Dt[B-15]|0,I=q.rotrSH(L,U,1)^q.rotrSH(L,U,8)^q.shrSH(L,U,7),D=q.rotrSL(L,U,1)^q.rotrSL(L,U,8)^q.shrSL(L,U,7),x=Ut[B-2]|0,T=Dt[B-2]|0,V=q.rotrSH(x,T,19)^q.rotrBH(x,T,61)^q.shrSH(x,T,6),C=q.rotrSL(x,T,19)^q.rotrBL(x,T,61)^q.shrSL(x,T,6),F=q.add4L(D,C,Dt[B-7],Dt[B-16]),K=q.add4H(F,I,V,Ut[B-7],Ut[B-16]);Ut[B]=K|0,Dt[B]=F|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:g,Fh:b,Fl:w,Gh:h,Gl:m,Hh:v,Hl:E}=this;for(let B=0;B<80;B++){let L=q.rotrSH(l,g,14)^q.rotrSH(l,g,18)^q.rotrBH(l,g,41),U=q.rotrSL(l,g,14)^q.rotrSL(l,g,18)^q.rotrBL(l,g,41),I=l&b^~l&h,D=g&w^~g&m,x=q.add5L(E,U,D,xd[B],Dt[B]),T=q.add5H(x,v,L,I,wd[B],Ut[B]),V=x|0,C=q.rotrSH(n,o,28)^q.rotrBH(n,o,34)^q.rotrBH(n,o,39),F=q.rotrSL(n,o,28)^q.rotrBL(n,o,34)^q.rotrBL(n,o,39),K=n&i^n&a^i&a,S=o&s^o&c^s&c;v=h|0,E=m|0,h=b|0,m=w|0,b=l|0,w=g|0,{h:l,l:g}=q.add(f|0,u|0,T|0,V|0),f=a|0,u=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let p=q.add3L(V,F,S);n=q.add3H(p,T,C,K),o=p|0}({h:n,l:o}=q.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=q.add(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=q.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=q.add(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:g}=q.add(this.Eh|0,this.El|0,l|0,g|0),{h:b,l:w}=q.add(this.Fh|0,this.Fl|0,b|0,w|0),{h,l:m}=q.add(this.Gh|0,this.Gl|0,h|0,m|0),{h:v,l:E}=q.add(this.Hh|0,this.Hl|0,v|0,E|0),this.set(n,o,i,s,a,c,f,u,l,g,b,w,h,m,v,E)}roundClean(){Ut.fill(0),Dt.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 tn=zn(()=>new Yi);var Yn={};he(Yn,{aInRange:()=>Te,abool:()=>je,abytes:()=>Cr,bitGet:()=>Rd,bitLen:()=>Sd,bitMask:()=>nn,bitSet:()=>kd,bytesToHex:()=>dt,bytesToNumberBE:()=>pt,bytesToNumberLE:()=>Vt,concatBytes:()=>gt,createHmacDrbg:()=>Qi,ensureBytes:()=>ie,equalBytes:()=>Bd,hexToBytes:()=>rr,hexToNumber:()=>Xi,inRange:()=>rn,isBytes:()=>Lt,memoized:()=>or,notImplemented:()=>Td,numberToBytesBE:()=>Ot,numberToBytesLE:()=>nr,numberToHexUnpadded:()=>ja,numberToVarBytesBE:()=>vd,utf8ToBytes:()=>Ad,validateObject:()=>nt});var Ji=BigInt(0),jn=BigInt(1),bd=BigInt(2);function Lt(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Cr(r){if(!Lt(r))throw new Error("Uint8Array expected")}function je(r,e){if(typeof e!="boolean")throw new Error(`${r} must be valid boolean, got "${e}".`)}var Ed=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function dt(r){Cr(r);let e="";for(let t=0;t<r.length;t++)e+=Ed[r[t]];return e}function ja(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function Xi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var ht={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function za(r){if(r>=ht._0&&r<=ht._9)return r-ht._0;if(r>=ht._A&&r<=ht._F)return r-(ht._A-10);if(r>=ht._a&&r<=ht._f)return r-(ht._a-10)}function rr(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,i=0;o<t;o++,i+=2){let s=za(r.charCodeAt(i)),a=za(r.charCodeAt(i+1));if(s===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function pt(r){return Xi(dt(r))}function Vt(r){return Cr(r),Xi(dt(Uint8Array.from(r).reverse()))}function Ot(r,e){return rr(r.toString(16).padStart(e*2,"0"))}function nr(r,e){return Ot(r,e).reverse()}function vd(r){return rr(ja(r))}function ie(r,e,t){let n;if(typeof e=="string")try{n=rr(e)}catch(i){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${i}`)}else if(Lt(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 gt(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];Cr(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}function Bd(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 Ad(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}var Zi=r=>typeof r=="bigint"&&Ji<=r;function rn(r,e,t){return Zi(r)&&Zi(e)&&Zi(t)&&e<=r&&r<t}function Te(r,e,t,n){if(!rn(e,t,n))throw new Error(`expected valid ${r}: ${t} <= n < ${n}, got ${typeof e} ${e}`)}function Sd(r){let e;for(e=0;r>Ji;r>>=jn,e+=1);return e}function Rd(r,e){return r>>BigInt(e)&jn}function kd(r,e,t){return r|(t?jn:Ji)<<BigInt(e)}var nn=r=>(bd<<BigInt(r-1))-jn,Wi=r=>new Uint8Array(r),Ga=r=>Uint8Array.from(r);function Qi(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=Wi(r),o=Wi(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...l)=>t(o,n,...l),c=(l=Wi())=>{o=a(Ga([0]),l),n=a(),l.length!==0&&(o=a(Ga([1]),l),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,g=[];for(;l<e;){n=a();let b=n.slice();g.push(b),l+=n.length}return gt(...g)};return(l,g)=>{s(),c(l);let b;for(;!(b=g(f()));)c();return s(),b}}var Id={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"||Lt(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 nt(r,e,t={}){let n=(o,i,s)=>{let a=Id[i];if(typeof a!="function")throw new Error(`Invalid validator "${i}", expected function`);let c=r[o];if(!(s&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(o)}=${c} (${typeof c}), expected ${i}`)};for(let[o,i]of Object.entries(e))n(o,i,!1);for(let[o,i]of Object.entries(t))n(o,i,!0);return r}var Td=()=>{throw new Error("not implemented")};function or(r){let e=new WeakMap;return(t,...n)=>{let o=e.get(t);if(o!==void 0)return o;let i=r(t,...n);return e.set(t,i),i}}var ue=BigInt(0),Q=BigInt(1),ir=BigInt(2),Cd=BigInt(3),es=BigInt(4),Ya=BigInt(5),Za=BigInt(8),Nd=BigInt(9),_d=BigInt(16);function J(r,e){let t=r%e;return t>=ue?t:e+t}function Ud(r,e,t){if(t<=ue||e<ue)throw new Error("Expected power/modulo > 0");if(t===Q)return ue;let n=Q;for(;e>ue;)e&Q&&(n=n*r%t),r=r*r%t,e>>=Q;return n}function ee(r,e,t){let n=r;for(;e-- >ue;)n*=n,n%=t;return n}function Zn(r,e){if(r===ue||e<=ue)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=J(r,e),n=e,o=ue,i=Q,s=Q,a=ue;for(;t!==ue;){let f=n/t,u=n%t,l=o-s*f,g=i-a*f;n=t,t=u,o=s,i=a,s=l,a=g}if(n!==Q)throw new Error("invert: does not exist");return J(o,e)}function Dd(r){let e=(r-Q)/ir,t,n,o;for(t=r-Q,n=0;t%ir===ue;t/=ir,n++);for(o=ir;o<r&&Ud(o,e,r)!==r-Q;o++);if(n===1){let s=(r+Q)/es;return function(c,f){let u=c.pow(f,s);if(!c.eql(c.sqr(u),f))throw new Error("Cannot find square root");return u}}let i=(t+Q)/ir;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,u=a.pow(a.mul(a.ONE,o),t),l=a.pow(c,i),g=a.pow(c,t);for(;!a.eql(g,a.ONE);){if(a.eql(g,a.ZERO))return a.ZERO;let b=1;for(let h=a.sqr(g);b<f&&!a.eql(h,a.ONE);b++)h=a.sqr(h);let w=a.pow(u,Q<<BigInt(f-b-1));u=a.sqr(w),l=a.mul(l,w),g=a.mul(g,u),f=b}return l}}function Ld(r){if(r%es===Cd){let e=(r+Q)/es;return function(n,o){let i=n.pow(o,e);if(!n.eql(n.sqr(i),o))throw new Error("Cannot find square root");return i}}if(r%Za===Ya){let e=(r-Ya)/Za;return function(n,o){let i=n.mul(o,ir),s=n.pow(i,e),a=n.mul(o,s),c=n.mul(n.mul(a,ir),s),f=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(f),o))throw new Error("Cannot find square root");return f}}return r%_d,Dd(r)}var Wa=(r,e)=>(J(r,e)&Q)===Q,Vd=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ts(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=Vd.reduce((n,o)=>(n[o]="function",n),e);return nt(r,t)}function Od(r,e,t){if(t<ue)throw new Error("Expected power > 0");if(t===ue)return r.ONE;if(t===Q)return e;let n=r.ONE,o=e;for(;t>ue;)t&Q&&(n=r.mul(n,o)),o=r.sqr(o),t>>=Q;return n}function Fd(r,e){let t=new Array(e.length),n=e.reduce((i,s,a)=>r.is0(s)?i:(t[a]=i,r.mul(i,s)),r.ONE),o=r.inv(n);return e.reduceRight((i,s,a)=>r.is0(s)?i:(t[a]=r.mul(i,t[a]),r.mul(i,s)),o),t}function rs(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Wn(r,e,t=!1,n={}){if(r<=ue)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:o,nByteLength:i}=rs(r,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=Ld(r),a=Object.freeze({ORDER:r,BITS:o,BYTES:i,MASK:nn(o),ZERO:ue,ONE:Q,create:c=>J(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return ue<=c&&c<r},is0:c=>c===ue,isOdd:c=>(c&Q)===Q,neg:c=>J(-c,r),eql:(c,f)=>c===f,sqr:c=>J(c*c,r),add:(c,f)=>J(c+f,r),sub:(c,f)=>J(c-f,r),mul:(c,f)=>J(c*f,r),pow:(c,f)=>Od(a,c,f),div:(c,f)=>J(c*Zn(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Zn(c,r),sqrt:n.sqrt||(c=>s(a,c)),invertBatch:c=>Fd(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>t?nr(c,i):Ot(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return t?Vt(c):pt(c)}});return Object.freeze(a)}function Ja(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 ns(r){let e=Ja(r);return e+Math.ceil(e/2)}function Xa(r,e,t=!1){let n=r.length,o=Ja(e),i=ns(e);if(n<16||n<i||n>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${n}`);let s=t?pt(r):Vt(r),a=J(s,e-Q)+Q;return t?nr(a,o):Ot(a,o)}var Md=BigInt(0),os=BigInt(1),is=new WeakMap,Qa=new WeakMap;function Jn(r,e){let t=(i,s)=>{let a=s.negate();return i?a:s},n=i=>{if(!Number.isSafeInteger(i)||i<=0||i>e)throw new Error(`Wrong window size=${i}, should be [1..${e}]`)},o=i=>{n(i);let s=Math.ceil(e/i)+1,a=2**(i-1);return{windows:s,windowSize:a}};return{constTimeNegate:t,unsafeLadder(i,s){let a=r.ZERO,c=i;for(;s>Md;)s&os&&(a=a.add(c)),c=c.double(),s>>=os;return a},precomputeWindow(i,s){let{windows:a,windowSize:c}=o(s),f=[],u=i,l=u;for(let g=0;g<a;g++){l=u,f.push(l);for(let b=1;b<c;b++)l=l.add(u),f.push(l);u=l.double()}return f},wNAF(i,s,a){let{windows:c,windowSize:f}=o(i),u=r.ZERO,l=r.BASE,g=BigInt(2**i-1),b=2**i,w=BigInt(i);for(let h=0;h<c;h++){let m=h*f,v=Number(a&g);a>>=w,v>f&&(v-=b,a+=os);let E=m,B=m+Math.abs(v)-1,L=h%2!==0,U=v<0;v===0?l=l.add(t(L,s[E])):u=u.add(t(U,s[B]))}return{p:u,f:l}},wNAFCached(i,s,a){let c=Qa.get(i)||1,f=is.get(i);return f||(f=this.precomputeWindow(i,c),c!==1&&is.set(i,a(f))),this.wNAF(c,f,s)},setWindowSize(i,s){n(s),Qa.set(i,s),is.delete(i)}}}function on(r){return ts(r.Fp),nt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...rs(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ye=BigInt(0),Ce=BigInt(1),Xn=BigInt(2),Hd=BigInt(8),Kd={zip215:!0};function $d(r){let e=on(r);return nt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function ec(r){let e=$d(r),{Fp:t,n,prehash:o,hash:i,randomBytes:s,nByteLength:a,h:c}=e,f=Xn<<BigInt(a*8)-Ce,u=t.create,l=e.uvRatio||((p,d)=>{try{return{isValid:!0,value:t.sqrt(p*t.inv(d))}}catch{return{isValid:!1,value:Ye}}}),g=e.adjustScalarBytes||(p=>p),b=e.domain||((p,d,A)=>{if(je("phflag",A),d.length||A)throw new Error("Contexts/pre-hash are not supported");return p});function w(p,d){Te("coordinate "+p,d,Ye,f)}function h(p){if(!(p instanceof E))throw new Error("ExtendedPoint expected")}let m=or((p,d)=>{let{ex:A,ey:k,ez:O}=p,P=p.is0();d==null&&(d=P?Hd:t.inv(O));let $=u(A*d),Z=u(k*d),z=u(O*d);if(P)return{x:Ye,y:Ce};if(z!==Ce)throw new Error("invZ was invalid");return{x:$,y:Z}}),v=or(p=>{let{a:d,d:A}=e;if(p.is0())throw new Error("bad point: ZERO");let{ex:k,ey:O,ez:P,et:$}=p,Z=u(k*k),z=u(O*O),W=u(P*P),re=u(W*W),ne=u(Z*d),Ie=u(W*u(ne+z)),le=u(re+u(A*u(Z*z)));if(Ie!==le)throw new Error("bad point: equation left != right (1)");let ae=u(k*O),$e=u(P*$);if(ae!==$e)throw new Error("bad point: equation left != right (2)");return!0});class E{constructor(d,A,k,O){this.ex=d,this.ey=A,this.ez=k,this.et=O,w("x",d),w("y",A),w("z",k),w("t",O),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(d){if(d instanceof E)throw new Error("extended point not allowed");let{x:A,y:k}=d||{};return w("x",A),w("y",k),new E(A,k,Ce,u(A*k))}static normalizeZ(d){let A=t.invertBatch(d.map(k=>k.ez));return d.map((k,O)=>k.toAffine(A[O])).map(E.fromAffine)}_setWindowSize(d){U.setWindowSize(this,d)}assertValidity(){v(this)}equals(d){h(d);let{ex:A,ey:k,ez:O}=this,{ex:P,ey:$,ez:Z}=d,z=u(A*Z),W=u(P*O),re=u(k*Z),ne=u($*O);return z===W&&re===ne}is0(){return this.equals(E.ZERO)}negate(){return new E(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:d}=e,{ex:A,ey:k,ez:O}=this,P=u(A*A),$=u(k*k),Z=u(Xn*u(O*O)),z=u(d*P),W=A+k,re=u(u(W*W)-P-$),ne=z+$,Ie=ne-Z,le=z-$,ae=u(re*Ie),$e=u(ne*le),fe=u(re*le),qe=u(Ie*ne);return new E(ae,$e,qe,fe)}add(d){h(d);let{a:A,d:k}=e,{ex:O,ey:P,ez:$,et:Z}=this,{ex:z,ey:W,ez:re,et:ne}=d;if(A===BigInt(-1)){let na=u((P-O)*(W+z)),oa=u((P+O)*(W-z)),yi=u(oa-na);if(yi===Ye)return this.double();let ia=u($*Xn*ne),sa=u(Z*Xn*re),aa=sa+ia,ca=oa+na,ua=sa-ia,wf=u(aa*yi),xf=u(ca*ua),bf=u(aa*ua),Ef=u(yi*ca);return new E(wf,xf,Ef,bf)}let Ie=u(O*z),le=u(P*W),ae=u(Z*k*ne),$e=u($*re),fe=u((O+P)*(z+W)-Ie-le),qe=$e-ae,Xt=$e+ae,Yr=u(le-A*Ie),Un=u(fe*qe),gf=u(Xt*Yr),mf=u(fe*Yr),yf=u(qe*Xt);return new E(Un,gf,yf,mf)}subtract(d){return this.add(d.negate())}wNAF(d){return U.wNAFCached(this,d,E.normalizeZ)}multiply(d){let A=d;Te("scalar",A,Ce,n);let{p:k,f:O}=this.wNAF(A);return E.normalizeZ([k,O])[0]}multiplyUnsafe(d){let A=d;return Te("scalar",A,Ye,n),A===Ye?L:this.equals(L)||A===Ce?this:this.equals(B)?this.wNAF(A).p:U.unsafeLadder(this,A)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return U.unsafeLadder(this,n).is0()}toAffine(d){return m(this,d)}clearCofactor(){let{h:d}=e;return d===Ce?this:this.multiplyUnsafe(d)}static fromHex(d,A=!1){let{d:k,a:O}=e,P=t.BYTES;d=ie("pointHex",d,P),je("zip215",A);let $=d.slice(),Z=d[P-1];$[P-1]=Z&-129;let z=Vt($),W=A?f:t.ORDER;Te("pointHex.y",z,Ye,W);let re=u(z*z),ne=u(re-Ce),Ie=u(k*re-O),{isValid:le,value:ae}=l(ne,Ie);if(!le)throw new Error("Point.fromHex: invalid y coordinate");let $e=(ae&Ce)===Ce,fe=(Z&128)!==0;if(!A&&ae===Ye&&fe)throw new Error("Point.fromHex: x=0 and x_0=1");return fe!==$e&&(ae=u(-ae)),E.fromAffine({x:ae,y:z})}static fromPrivateKey(d){return x(d).point}toRawBytes(){let{x:d,y:A}=this.toAffine(),k=nr(A,t.BYTES);return k[k.length-1]|=d&Ce?128:0,k}toHex(){return dt(this.toRawBytes())}}E.BASE=new E(e.Gx,e.Gy,Ce,u(e.Gx*e.Gy)),E.ZERO=new E(Ye,Ce,Ce,Ye);let{BASE:B,ZERO:L}=E,U=Jn(E,a*8);function I(p){return J(p,n)}function D(p){return I(Vt(p))}function x(p){let d=a;p=ie("private key",p,d);let A=ie("hashed private key",i(p),2*d),k=g(A.slice(0,d)),O=A.slice(d,2*d),P=D(k),$=B.multiply(P),Z=$.toRawBytes();return{head:k,prefix:O,scalar:P,point:$,pointBytes:Z}}function T(p){return x(p).pointBytes}function V(p=new Uint8Array,...d){let A=gt(...d);return D(i(b(A,ie("context",p),!!o)))}function C(p,d,A={}){p=ie("message",p),o&&(p=o(p));let{prefix:k,scalar:O,pointBytes:P}=x(d),$=V(A.context,k,p),Z=B.multiply($).toRawBytes(),z=V(A.context,Z,P,p),W=I($+z*O);Te("signature.s",W,Ye,n);let re=gt(Z,nr(W,t.BYTES));return ie("result",re,a*2)}let F=Kd;function K(p,d,A,k=F){let{context:O,zip215:P}=k,$=t.BYTES;p=ie("signature",p,2*$),d=ie("message",d),P!==void 0&&je("zip215",P),o&&(d=o(d));let Z=Vt(p.slice($,2*$)),z,W,re;try{z=E.fromHex(A,P),W=E.fromHex(p.slice(0,$),P),re=B.multiplyUnsafe(Z)}catch{return!1}if(!P&&z.isSmallOrder())return!1;let ne=V(O,W.toRawBytes(),z.toRawBytes(),d);return W.add(z.multiplyUnsafe(ne)).subtract(re).clearCofactor().equals(E.ZERO)}return B._setWindowSize(8),{CURVE:e,getPublicKey:T,sign:C,verify:K,ExtendedPoint:E,utils:{getExtendedPublicKey:x,randomPrivateKey:()=>s(t.BYTES),precompute(p=8,d=E.BASE){return d._setWindowSize(p),d.multiply(BigInt(3)),d}}}}var ss=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),tc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),ry=BigInt(0),qd=BigInt(1),rc=BigInt(2),ny=BigInt(3),zd=BigInt(5),Gd=BigInt(8);function jd(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=ss,a=r*r%i*r%i,c=ee(a,rc,i)*a%i,f=ee(c,qd,i)*r%i,u=ee(f,zd,i)*f%i,l=ee(u,e,i)*u%i,g=ee(l,t,i)*l%i,b=ee(g,n,i)*g%i,w=ee(b,o,i)*b%i,h=ee(w,o,i)*b%i,m=ee(h,e,i)*u%i;return{pow_p_5_8:ee(m,rc,i)*r%i,b2:a}}function Yd(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Zd(r,e){let t=ss,n=J(e*e*e,t),o=J(n*n*e,t),i=jd(r*o).pow_p_5_8,s=J(r*n*i,t),a=J(e*s*s,t),c=s,f=J(s*tc,t),u=a===r,l=a===J(-r,t),g=a===J(-r*tc,t);return u&&(s=c),(l||g)&&(s=f),Wa(s,t)&&(s=J(-s,t)),{isValid:u||l,value:s}}var Wd=Wn(ss,void 0,!0),Jd={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Wd,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Gd,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:tn,randomBytes:Ir,adjustScalarBytes:Yd,uvRatio:Zd},Nr=ec(Jd);var _r=32,mt=64,Qn=32;function nc(){let r=Nr.utils.randomPrivateKey(),e=Nr.getPublicKey(r);return{privateKey:ac(r,e),publicKey:e}}function oc(r){if(r.length!==Qn)throw new TypeError('"seed" must be 32 bytes in length.');if(!(r instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=r,t=Nr.getPublicKey(e);return{privateKey:ac(e,t),publicKey:t}}function ic(r,e){let t=r.subarray(0,Qn);return Nr.sign(e instanceof Uint8Array?e:e.subarray(),t)}function sc(r,e,t){return Nr.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function ac(r,e){let t=new Uint8Array(mt);for(let n=0;n<Qn;n++)t[n]=r[n],t[Qn+n]=e[n];return t}var Ae={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw Object.assign(new Error("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"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var as={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function cc(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,o=r?.digest??"SHA-256",i=r?.saltLength??16,s=r?.iterations??32767,a=Ae.get();t*=8;async function c(l,g){let b=a.getRandomValues(new Uint8Array(i)),w=a.getRandomValues(new Uint8Array(n)),h={name:e,iv:w};typeof g=="string"&&(g=j(g));let m;if(g.length===0){m=await a.subtle.importKey("jwk",as,{name:"AES-GCM"},!0,["encrypt"]);try{let E={name:"PBKDF2",salt:b,iterations:s,hash:{name:o}},B=await a.subtle.importKey("raw",g,{name:"PBKDF2"},!1,["deriveKey"]);m=await a.subtle.deriveKey(E,B,{name:e,length:t},!0,["encrypt"])}catch{m=await a.subtle.importKey("jwk",as,{name:"AES-GCM"},!0,["encrypt"])}}else{let E={name:"PBKDF2",salt:b,iterations:s,hash:{name:o}},B=await a.subtle.importKey("raw",g,{name:"PBKDF2"},!1,["deriveKey"]);m=await a.subtle.deriveKey(E,B,{name:e,length:t},!0,["encrypt"])}let v=await a.subtle.encrypt(h,m,l);return tr([b,h.iv,new Uint8Array(v)])}async function f(l,g){let b=l.subarray(0,i),w=l.subarray(i,i+n),h=l.subarray(i+n),m={name:e,iv:w};typeof g=="string"&&(g=j(g));let v;if(g.length===0)try{let B={name:"PBKDF2",salt:b,iterations:s,hash:{name:o}},L=await a.subtle.importKey("raw",g,{name:"PBKDF2"},!1,["deriveKey"]);v=await a.subtle.deriveKey(B,L,{name:e,length:t},!0,["decrypt"])}catch{v=await a.subtle.importKey("jwk",as,{name:"AES-GCM"},!0,["decrypt"])}else{let B={name:"PBKDF2",salt:b,iterations:s,hash:{name:o}},L=await a.subtle.importKey("raw",g,{name:"PBKDF2"},!1,["deriveKey"]);v=await a.subtle.deriveKey(B,L,{name:e,length:t},!0,["decrypt"])}let E=await a.subtle.decrypt(m,v,h);return new Uint8Array(E)}return{encrypt:c,decrypt:f}}async function Ur(r,e){let n=await cc().encrypt(r,e);return Zr.encode(n)}var e0=Math.pow(2,7),t0=Math.pow(2,14),r0=Math.pow(2,21),uc=Math.pow(2,28),lc=Math.pow(2,35),fc=Math.pow(2,42),hc=Math.pow(2,49),Se=128,Ft=127;function sn(r){if(r<e0)return 1;if(r<t0)return 2;if(r<r0)return 3;if(r<uc)return 4;if(r<lc)return 5;if(r<fc)return 6;if(r<hc)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function dc(r,e,t=0){switch(sn(r)){case 8:e[t++]=r&255|Se,r/=128;case 7:e[t++]=r&255|Se,r/=128;case 6:e[t++]=r&255|Se,r/=128;case 5:e[t++]=r&255|Se,r/=128;case 4:e[t++]=r&255|Se,r>>>=7;case 3:e[t++]=r&255|Se,r>>>=7;case 2:e[t++]=r&255|Se,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function pc(r,e){let t=r[e],n=0;if(n+=t&Ft,t<Se||(t=r[e+1],n+=(t&Ft)<<7,t<Se)||(t=r[e+2],n+=(t&Ft)<<14,t<Se)||(t=r[e+3],n+=(t&Ft)<<21,t<Se)||(t=r[e+4],n+=(t&Ft)*uc,t<Se)||(t=r[e+5],n+=(t&Ft)*lc,t<Se)||(t=r[e+6],n+=(t&Ft)*fc,t<Se)||(t=r[e+7],n+=(t&Ft)*hc,t<Se))return n;throw new RangeError("Could not decode varint")}var cs=new Float32Array([-0]),Pt=new Uint8Array(cs.buffer);function gc(r,e,t){cs[0]=r,e[t]=Pt[0],e[t+1]=Pt[1],e[t+2]=Pt[2],e[t+3]=Pt[3]}function mc(r,e){return Pt[0]=r[e],Pt[1]=r[e+1],Pt[2]=r[e+2],Pt[3]=r[e+3],cs[0]}var us=new Float64Array([-0]),ve=new Uint8Array(us.buffer);function yc(r,e,t){us[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 wc(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],us[0]}var n0=BigInt(Number.MAX_SAFE_INTEGER),o0=BigInt(Number.MIN_SAFE_INTEGER),De=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 sr;if(e<n0&&e>o0)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>xc&&(o=0n,++n>xc&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return sr;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):sr}},sr=new De(0,0);sr.toBigInt=function(){return 0n};sr.zzEncode=sr.zzDecode=function(){return this};sr.length=function(){return 1};var xc=4294967296n;function bc(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 Ec(r,e,t){if(t-e<1)return"";let o,i=[],s=0,a;for(;e<t;)a=r[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function ls(r,e,t){let n=t,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function Ze(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function eo(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var fs=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,Ze(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 Ze(this,4);return eo(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ze(this,4);return eo(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ze(this,4);let e=mc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ze(this,4);let e=wc(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 Ze(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Ec(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ze(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ze(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 De(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 Ze(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 Ze(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 Ze(this,8);let e=eo(this.buf,this.pos+=4),t=eo(this.buf,this.pos+=4);return new De(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=pc(this.buf,this.pos);return this.pos+=sn(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 hs(r){return new fs(r instanceof Uint8Array?r:r.subarray())}function Mt(r,e,t){let n=hs(r);return e.decode(n,void 0,t)}function ds(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return rt(s);o+s>e&&(n=rt(e),o=0);let a=n.subarray(o,o+=s);return o&7&&(o=(o|7)+1),a}}var ar=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function ps(){}var ms=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},i0=ds();function s0(r){return globalThis.Buffer!=null?rt(r):i0(r)}var cn=class{len;head;tail;states;constructor(){this.len=0,this.head=new ar(ps,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new ar(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new ys((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(to,10,De.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=De.fromBigInt(e);return this._push(to,t.length(),t)}uint64Number(e){return this._push(dc,sn(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=De.fromBigInt(e).zzEncode();return this._push(to,t.length(),t)}sint64Number(e){let t=De.fromNumber(e).zzEncode();return this._push(to,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(gs,1,e?1:0)}fixed32(e){return this._push(an,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=De.fromBigInt(e);return this._push(an,4,t.lo)._push(an,4,t.hi)}fixed64Number(e){let t=De.fromNumber(e);return this._push(an,4,t.lo)._push(an,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(gc,4,e)}double(e){return this._push(yc,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(gs,1,0):this.uint32(t)._push(c0,t,e)}string(e){let t=bc(e);return t!==0?this.uint32(t)._push(ls,t,e):this._push(gs,1,0)}fork(){return this.states=new ms(this),this.head=this.tail=new ar(ps,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 ar(ps,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=s0(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function gs(r,e,t){e[t]=r&255}function a0(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var ys=class extends ar{next;constructor(e,t){super(a0,e,t),this.next=void 0}};function to(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 an(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 c0(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(cn.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(u0,e,r),this},cn.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(l0,e,r),this});function u0(r,e,t){e.set(r,t)}function l0(r,e,t){r.length<40?ls(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(j(r),t)}function ws(){return new cn}function Ht(r,e){let t=ws();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var Dr;(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"})(Dr||(Dr={}));function ro(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function un(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return ro("enum",Dr.VARINT,t,n)}function Kt(r,e){return ro("message",Dr.LENGTH_DELIMITED,r,e)}var te;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(te||(te={}));var xs;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(xs||(xs={}));(function(r){r.codec=()=>un(xs)})(te||(te={}));var ot;(function(r){let e;r.codec=()=>(e==null&&(e=Kt((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),te.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.Type=te.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>Ht(t,r.codec()),r.decode=t=>Mt(t,r.codec())})(ot||(ot={}));var it;(function(r){let e;r.codec=()=>(e==null&&(e=Kt((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),te.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.Type=te.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>Ht(t,r.codec()),r.decode=t=>Mt(t,r.codec())})(it||(it={}));var ln=class{_key;constructor(e){this._key=Lr(e,_r)}verify(e,t){return sc(this._key,t,e)}marshal(){return this._key}get bytes(){return ot.encode({Type:te.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=ye.digest(this.bytes);return Pe(e)?e.then(({bytes:t})=>t):e.bytes}},cr=class{_key;_publicKey;constructor(e,t){this._key=Lr(e,mt),this._publicKey=Lr(t,_r)}sign(e){return ic(this._key,e)}get public(){return new ln(this._publicKey)}marshal(){return this._key}get bytes(){return it.encode({Type:te.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}async hash(){let e=ye.digest(this.bytes),t;return Pe(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=ze.digest(this.public.bytes);return me.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return Ur(this.bytes,e);throw new H(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function f0(r){if(r.length>mt){r=Lr(r,mt+_r);let n=r.subarray(0,mt),o=r.subarray(mt,r.length);return new cr(n,o)}r=Lr(r,mt);let e=r.subarray(0,mt),t=r.subarray(_r);return new cr(e,t)}function h0(r){return r=Lr(r,_r),new ln(r)}async function d0(){let{privateKey:r,publicKey:e}=nc();return new cr(r,e)}async function Bc(r){let{privateKey:e,publicKey:t}=oc(r);return new cr(e,t)}function Lr(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new H(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}var Cs={};he(Cs,{MAX_RSA_KEY_SIZE:()=>vn,RsaPrivateKey:()=>Mr,RsaPublicKey:()=>En,fromJwk:()=>M0,generateKeyPair:()=>H0,unmarshalRsaPrivateKey:()=>Is,unmarshalRsaPublicKey:()=>P0});function ur(r){if(isNaN(r)||r<=0)throw new H("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return Ir(r)}var Gt={};he(Gt,{exportToPem:()=>D0,importFromPem:()=>L0,jwkToPkcs1:()=>C0,jwkToPkix:()=>_0,pkcs1ToJwk:()=>T0,pkixToJwk:()=>N0});var oo=class extends Rr{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,$n(e);let n=_t(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(e){return Sr(this),this.iHash.update(e),this}digestInto(e){Sr(this),Ar(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},fn=(r,e,t)=>new oo(r,e).update(t).digest();fn.create=(r,e)=>new oo(r,e);function p0(r,e,t,n){$n(r);let o=Ha({dkLen:32,asyncTick:10},n),{c:i,dkLen:s,asyncTick:a}=o;if(Br(i),Br(s),Br(a),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=_t(e),f=_t(t),u=new Uint8Array(s),l=fn.create(r,c),g=l._cloneInto().update(f);return{c:i,dkLen:s,asyncTick:a,DK:u,PRF:l,PRFSalt:g}}function g0(r,e,t,n,o){return r.destroy(),e.destroy(),n&&n.destroy(),o.fill(0),t}async function Es(r,e,t,n){let{c:o,dkLen:i,asyncTick:s,DK:a,PRF:c,PRFSalt:f}=p0(r,e,t,n),u,l=new Uint8Array(4),g=kr(l),b=new Uint8Array(c.outputLen);for(let w=1,h=0;h<i;w++,h+=c.outputLen){let m=a.subarray(h,h+c.outputLen);g.setInt32(0,w,!1),(u=f._cloneInto(u)).update(l).digestInto(b),m.set(b.subarray(0,m.length)),await Pa(o-1,s,()=>{c._cloneInto(u).update(b).digestInto(b);for(let v=0;v<m.length;v++)m[v]^=b[v]})}return g0(c,f,a,u,b)}var G=It(Ac());function lr(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,i=0,s=Math.pow(2,e);for(let a=1;a<8;a++){if(r<s){let c;if(n<0)c=new ArrayBuffer(a),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let f=new Uint8Array(c);for(let u=a-1;u>=0;u--){let l=Math.pow(2,u*e);f[i-u-1]=Math.floor(o/l),o-=f[i-u-1]*l}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function ao(...r){let e=0,t=0;for(let i of r)e+=i.length;let n=new ArrayBuffer(e),o=new Uint8Array(n);for(let i of r)o.set(i,t),t+=i.length;return o}function Bs(){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=lr(t,8),o=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(o);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=r[a];return i[0]&=127,lr(i,8)-n}function Sc(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let s=t-e,a=$t(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=$t(e,8,n),i=new Uint8Array(o);if(i[0]&128){let s=o.slice(0),a=new Uint8Array(s);o=new ArrayBuffer(o.byteLength+1),i=new Uint8Array(o);for(let c=0;c<s.byteLength;c++)i[c+1]=a[c];i[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function Rc(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 Ne(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,o=new Array(n);for(let s=0;s<n;s++)o[s]="0";return o.join("").concat(t)}var lw=Math.log(2);function co(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function As(r){let e=0,t=0;for(let o=0;o<r.length;o++){let i=r[o];e+=i.byteLength}let n=new Uint8Array(e);for(let o=0;o<r.length;o++){let i=r[o];n.set(new Uint8Array(i),t),t+=i.byteLength}return n.buffer}function Et(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 dn=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return As(this.items)}},hn=[new Uint8Array([1])],kc="0123456789";var Fr="",Je=new ArrayBuffer(0),Ss=new Uint8Array(0),pn="EndOfContent",Tc="OCTET STRING",Cc="BIT STRING";function vt(r){var e;return e=class extends r{constructor(...n){var o;super(...n);let i=n[0]||{};this.isHexOnly=(o=i.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=i.valueHex?G.BufferSourceConverter.toUint8Array(i.valueHex):Ss}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Et(this,s,o,i))return-1;let a=o+i;return this.valueHexView=s.subarray(o,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),o)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",Je)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:G.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var wt=class{constructor({blockLength:e=0,error:t=Fr,warnings:n=[],valueBeforeDecode:o=Ss}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=G.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:G.Convert.ToHex(this.valueBeforeDecodeView)}}};wt.NAME="baseBlock";var Be=class extends wt{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'")}};Be.NAME="valueBlock";var uo=class extends vt(wt){constructor({idBlock:e={}}={}){var t,n,o,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?G.BufferSourceConverter.toUint8Array(e.valueHex):Ss,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",Je}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let o=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,o[0]=t}return o.buffer}if(!this.isHexOnly){let o=$t(this.tagNumber,7),i=new Uint8Array(o),s=o.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=i[c]|128;a[s]=i[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let i=0;i<o.length-1;i++)n[i+1]=o[i]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=G.BufferSourceConverter.toUint8Array(e);if(!Et(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,f=this.valueHexView=new Uint8Array(255),u=255;for(;i[c]&128;){if(f[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===u){u+=255;let g=new Uint8Array(u);for(let b=0;b<f.length;b++)g[b]=f[b];f=this.valueHexView=new Uint8Array(u)}}this.blockLength=c+1,f[c-1]=i[c]&127;let l=new Uint8Array(c);for(let g=0;g<c;g++)l[g]=f[g];f=this.valueHexView=new Uint8Array(c),f.set(l),this.blockLength<=9?this.tagNumber=lr(f,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};uo.NAME="identificationBlock";var lo=class extends wt{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=G.BufferSourceConverter.toUint8Array(e);if(!Et(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,t+this.blockLength;let s=i[0]&127;if(s>8)return this.error="Too big integer",-1;if(s+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=o.subarray(a,a+s);return c[s-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=lr(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=s+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let o=$t(this.length,8);if(o.byteLength>127)return this.error="Too big length",Je;if(t=new ArrayBuffer(o.byteLength+1),e)return t;let i=new Uint8Array(o);n=new Uint8Array(t),n[0]=o.byteLength|128;for(let s=0;s<o.byteLength;s++)n[s+1]=i[s];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};lo.NAME="lengthBlock";var N={},we=class extends wt{constructor({name:e=Fr,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new uo(o),this.lenBlock=new lo(o),this.valueBlock=i?new i(o):new Be(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 dn;t||Nc(this);let o=this.idBlock.toBER(e);if(n.write(o),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(i)}return t?Je: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():G.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${G.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 Rc(t,n)}};we.NAME="BaseBlock";function Nc(r){if(r instanceof N.Constructed)for(let e of r.valueBlock.value)Nc(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var fo=class extends we{constructor({value:e=Fr,...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}'`}};fo.NAME="BaseStringBlock";var ho=class extends vt(Be){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};ho.NAME="PrimitiveValueBlock";var _c,po=class extends we{constructor(e={}){super(e,ho),this.idBlock.isConstructed=!1}};_c=po;N.Primitive=_c;po.NAME="PRIMITIVE";function A0(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 jo(r,e=0,t=r.length){let n=e,o=new we({},Be),i=new wt;if(!Et(i,r,e,t))return o.error=i.error,{offset:-1,result:o};if(!r.subarray(e,e+t).length)return o.error="Zero buffer length",{offset:-1,result:o};let a=o.idBlock.fromBER(r,e,t);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),a===-1)return o.error=o.idBlock.error,{offset:-1,result:o};if(e=a,t-=o.idBlock.blockLength,a=o.lenBlock.fromBER(r,e,t),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),a===-1)return o.error=o.lenBlock.error,{offset:-1,result:o};if(e=a,t-=o.lenBlock.blockLength,!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let c=we;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=N.EndOfContent;break;case 1:c=N.Boolean;break;case 2:c=N.Integer;break;case 3:c=N.BitString;break;case 4:c=N.OctetString;break;case 5:c=N.Null;break;case 6:c=N.ObjectIdentifier;break;case 10:c=N.Enumerated;break;case 12:c=N.Utf8String;break;case 13:c=N.RelativeObjectIdentifier;break;case 14:c=N.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=N.Sequence;break;case 17:c=N.Set;break;case 18:c=N.NumericString;break;case 19:c=N.PrintableString;break;case 20:c=N.TeletexString;break;case 21:c=N.VideotexString;break;case 22:c=N.IA5String;break;case 23:c=N.UTCTime;break;case 24:c=N.GeneralizedTime;break;case 25:c=N.GraphicString;break;case 26:c=N.VisibleString;break;case 27:c=N.GeneralString;break;case 28:c=N.UniversalString;break;case 29:c=N.CharacterString;break;case 30:c=N.BmpString;break;case 31:c=N.DATE;break;case 32:c=N.TimeOfDay;break;case 33:c=N.DateTime;break;case 34:c=N.Duration;break;default:{let f=o.idBlock.isConstructed?new N.Constructed:new N.Primitive;f.idBlock=o.idBlock,f.lenBlock=o.lenBlock,f.warnings=o.warnings,o=f}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?N.Constructed:N.Primitive}return o=A0(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 Pr(r){if(!r.byteLength){let e=new we({},Be);return e.error="Input buffer has zero length",{offset:-1,result:e}}return jo(G.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function S0(r,e){return r?1:e}var st=class extends Be{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=G.BufferSourceConverter.toUint8Array(e);if(!Et(this,o,t,n))return-1;if(this.valueBeforeDecodeView=o.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;S0(this.isIndefiniteForm,n)>0;){let s=jo(o,i,n);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(i=s.offset,this.blockLength+=s.result.blockLength,n-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===pn)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===pn?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new dn;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?Je:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};st.NAME="ConstructedValueBlock";var Uc,qt=class extends we{constructor(e={}){super(e,st),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
|
|
2
|
+
"use strict";var HeliaIpns=(()=>{var Sf=Object.create;var On=Object.defineProperty;var Rf=Object.getOwnPropertyDescriptor;var kf=Object.getOwnPropertyNames;var If=Object.getPrototypeOf,Tf=Object.prototype.hasOwnProperty;var Fn=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),he=(r,e)=>{for(var t in e)On(r,t,{get:e[t],enumerable:!0})},da=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of kf(e))!Tf.call(r,o)&&o!==t&&On(r,o,{get:()=>e[o],enumerable:!(n=Rf(e,o))||n.enumerable});return r};var Nt=(r,e,t)=>(t=r!=null?Sf(If(r)):{},da(e||!r||!r.__esModule?On(t,"default",{value:r,enumerable:!0}):t,r)),Cf=r=>da(On({},"__esModule",{value:!0}),r);var Rc=Fn(Mr=>{"use strict";var w0="[object ArrayBuffer]",wt=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===w0}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),o=r.toUint8Array(t);if(n.length!==o.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==o[i])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let s of t)n+=s.byteLength;let o=new Uint8Array(n),i=0;for(let s of t){let a=this.toUint8Array(s);o.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(o,e[e.length-1]):o.buffer}},Ss="string",x0=/^[0-9a-f]+$/i,b0=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,E0=/^[a-zA-Z0-9-_]+$/,ao=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=wt.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},Ke=class{static toString(e,t=!1){let n=wt.toArrayBuffer(e),o=new DataView(n),i="";for(let s=0;s<n.byteLength;s+=2){let a=o.getUint16(s,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),o=new DataView(n);for(let i=0;i<e.length;i++)o.setUint16(i*2,e.charCodeAt(i),t);return n}},co=class r{static isHex(e){return typeof e===Ss&&x0.test(e)}static isBase64(e){return typeof e===Ss&&b0.test(e)}static isBase64Url(e){return typeof e===Ss&&E0.test(e)}static ToString(e,t="utf8"){let n=wt.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 Ke.toString(n,!0);case"utf16":case"utf16be":return Ke.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 Ke.fromString(e,!0);case"utf16":case"utf16be":return Ke.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=wt.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 ao.fromString(e);case"utf16":case"utf16be":return Ke.fromString(e);case"utf16le":case"usc2":return Ke.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 ao.toString(e);case"utf16":case"utf16be":return Ke.toString(e);case"utf16le":case"usc2":return Ke.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=wt.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=wt.toUint8Array(e),n="",o=t.length;for(let i=0;i<o;i++){let s=t[i];s<16&&(n+="0"),n+=s.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let o=0;o<t.length;o=o+2){let i=t.slice(o,o+2);n[o/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return Ke.toString(e,t)}static FromUtf16String(e,t=!1){return Ke.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,"")||""}};co.DEFAULT_UTF8_ENCODING="utf8";function v0(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let o=arguments[n];for(let i in o)t[i]=o[i]}return t}function B0(...r){let e=r.map(o=>o.byteLength).reduce((o,i)=>o+i),t=new Uint8Array(e),n=0;return r.map(o=>new Uint8Array(o)).forEach(o=>{for(let i of o)t[n++]=i}),t.buffer}function A0(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}Mr.BufferSourceConverter=wt;Mr.Convert=co;Mr.assign=v0;Mr.combine=B0;Mr.isEqual=A0});var Jo=Fn((ux,Du)=>{"use strict";function Lu(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function np(r,e,t){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");t||(t={}),typeof e=="object"&&(t=e,e=""),e&&(t.code=e);try{return Lu(r,t)}catch{t.message=r.message,t.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),Lu(new o,t)}}Du.exports=np});var Qo=Fn((px,Ps)=>{var dx=function(){typeof Ps<"u"&&(Ps.exports=p);var r=86400,e=3200,t=146097*e/400,n=r*t,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",f=Math.trunc||function(x){var v=x-x%1;return v==0&&(x<0||x===0&&1/x!=1/0)?-0:v},u=p.prototype,l=(p.fromDate=function(x){return new p(+x)},p.fromInt64BE=I(0,1,2,3,0,4),p.fromInt64LE=I(3,2,1,0,4,0),p.fromString=function(_){var v,F=new p,_=(_+="").replace(/^\s*[+\-]?\d+/,function($){var $=+$,S=1970+($-1970)%400;return F.year=$-S,S}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(C,$,S){return $<0&&(S*=-1),v=6e4*(60*+$+ +S),""}).replace(/\.\d+$/,function(C){return F.nano=+(C+c).substr(1,9),""}).split(/\D+/);if(1<_.length?_[1]--:_[1]=0,F.time=v=Date.UTC.apply(Date,_)-(v||0),isNaN(v))throw new TypeError("Invalid Date");return d(F)},p.fromTimeT=function(x){return k(x,0)},u.year=0,u.time=0,u.nano=0,u.addNano=function(x){return this.nano+=+x||0,this},u.getNano=function(){var x=d(this);return(x.time%1e3*a+ +x.nano+1e9)%1e9},u.getTimeT=function(){var v=d(this),x=Math.floor(v.time/1e3),v=v.year;return v&&(x+=v*t*r/e),x},u.getYear=function(){return this.toDate().getUTCFullYear()+this.year},u.toDate=function(){return b(d(this).time)},u.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},u.toString=function(x){var v=this,F=v.toDate(),_={H:function(){return D(F.getUTCHours())},L:function(){return N(F.getUTCMilliseconds(),3)},M:function(){return D(F.getUTCMinutes())},N:function(){return N(v.getNano(),9)},S:function(){return D(F.getUTCSeconds())},Y:function(){var C=v.getYear();return 999999<C?"+"+C:9999<C?"+"+N(C,6):0<=C?N(C,4):-999999<=C?"-"+N(-C,6):C},a:function(){return E[F.getUTCDay()]},b:function(){return h[F.getUTCMonth()]},d:function(){return D(F.getUTCDate())},e:function(){return function(C){return(9<C?"":" ")+(0|C)}(F.getUTCDate())},m:function(){return D(F.getUTCMonth()+1)}};return function C($){return $.replace(/%./g,function(S){var y=S[1],R=B[y],y=_[y];return R?C(R):y?y():S})}(x||l)},u.writeInt64BE=w(0,1,2,3,0,4),u.writeInt64LE=w(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],E=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],B={"%":"%",F:"%Y-%m-%d",n:`
|
|
3
|
+
`,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return p;function p(x,v,F){var _=this;if(!(_ instanceof p))return new p(x,v,F);_.time=+x||0,_.nano=+v||0,_.year=+F||0,d(_)}function d(x){var v,F,_,C=x.year,$=x.time,S=x.nano,R=((S<0||a<=S)&&(S-=(F=Math.floor(S/a))*a,$+=F,F=1),C%e);return($<-i||i<$||R)&&((v=f($/o))&&(C+=v*e,$-=v*o),(_=b($)).setUTCFullYear(R+_.getUTCFullYear()),_=($=+_)+(v=f((C-=R)/e))*o,v&&-i<=_&&_<=i&&(C-=v*e,$=_),F=1),F&&(x.year=C,x.time=$,x.nano=S),x}function b(x){var v=new Date(0);return v.setTime(x),v}function k(C,_){C=+C||0;var F=f((_=(_|0)*s)/n)+f(C/n),_=_%n+C%n,C=f(_/n);return C&&(F+=C,_-=C*n),new p(1e3*_,0,F*e)}function w(x,v,F,_,C,$){return function(R,y){var A=d(this);R=R||new Array(8),O(R,y|=0);var V=Math.floor(A.time/1e3),A=A.year*(t*r/e),g=f(A/s)+f(V/s),A=A%s+V%s,V=Math.floor(A/s);return V&&(g+=V,A-=V*s),S(R,y+C,g),S(R,y+$,A),R};function S(R,y,g){R[y+x]=g>>24&255,R[y+v]=g>>16&255,R[y+F]=g>>8&255,R[y+_]=255&g}}function I(x,v,F,_,C,$){return function(R,y){O(R,y|=0);var g=S(R,y+C);return k(S(R,y+$),g)};function S(R,y){return 16777216*R[y+x]+(R[y+v]<<16|R[y+F]<<8|R[y+_])}}function O(x,v){if(x=x&&x.length,x==null)throw new TypeError("Invalid Buffer");if(x<v+8)throw new RangeError("Out of range")}function D(x){return(9<x?"":"0")+(0|x)}function N(x,v){return(c+(0|x)).substr(-v)}}()});var uf=Fn((a1,cf)=>{cf.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function o(i,s){t[i]=s,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(i){return t[i]!==void 0||n[i]!==void 0},remove:function(i){t[i]!==void 0&&(t[i]=void 0),n[i]!==void 0&&(n[i]=void 0)},get:function(i){var s=t[i];if(s!==void 0)return s;if((s=n[i])!==void 0)return o(i,s),s},set:function(i,s){t[i]!==void 0?t[i]=s:o(i,s)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var tg={};he(tg,{ipns:()=>eg,ipnsSelector:()=>pi,ipnsValidator:()=>mi});var Mn=Symbol.for("@libp2p/peer-id");function pa(r){return r!=null&&!!r[Mn]}var K=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var Ai={};he(Ai,{base32:()=>Ut,base32hex:()=>Ff,base32hexpad:()=>Pf,base32hexpadupper:()=>Hf,base32hexupper:()=>Mf,base32pad:()=>Vf,base32padupper:()=>Of,base32upper:()=>Ea,base32z:()=>Kf});var ig=new Uint8Array(0);function ga(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 ht(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 ma(r){return new TextEncoder().encode(r)}function ya(r){return new TextDecoder().decode(r)}function Nf(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(B){if(B instanceof Uint8Array||(ArrayBuffer.isView(B)?B=new Uint8Array(B.buffer,B.byteOffset,B.byteLength):Array.isArray(B)&&(B=Uint8Array.from(B))),!(B instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(B.length===0)return"";for(var p=0,d=0,b=0,k=B.length;b!==k&&B[b]===0;)b++,p++;for(var w=(k-b)*u+1>>>0,I=new Uint8Array(w);b!==k;){for(var O=B[b],D=0,N=w-1;(O!==0||D<d)&&N!==-1;N--,D++)O+=256*I[N]>>>0,I[N]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");d=D,b++}for(var x=w-d;x!==w&&I[x]===0;)x++;for(var v=c.repeat(p);x<w;++x)v+=r.charAt(I[x]);return v}function h(B){if(typeof B!="string")throw new TypeError("Expected String");if(B.length===0)return new Uint8Array;var p=0;if(B[p]!==" "){for(var d=0,b=0;B[p]===c;)d++,p++;for(var k=(B.length-p)*f+1>>>0,w=new Uint8Array(k);B[p];){var I=t[B.charCodeAt(p)];if(I===255)return;for(var O=0,D=k-1;(I!==0||O<b)&&D!==-1;D--,O++)I+=a*w[D]>>>0,w[D]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");b=O,p++}if(B[p]!==" "){for(var N=k-b;N!==k&&w[N]===0;)N++;for(var x=new Uint8Array(d+(k-N)),v=d;N!==k;)x[v++]=w[N++];return x}}}function E(B){var p=h(B);if(p)return p;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:h,decode:E}}var _f=Nf,Uf=_f,xa=Uf;var bi=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")}},Ei=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),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 ba(this,e)}},vi=class{decoders;constructor(e){this.decoders=e}or(e){return ba(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 ba(r,e){return new vi({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Bi=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 bi(e,t,n),this.decoder=new Ei(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function wr({name:r,prefix:e,encode:t,decode:n}){return new Bi(r,e,t,n)}function _t({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=xa(t,r);return wr({prefix:e,name:r,encode:n,decode:i=>ht(o(i))})}function Lf(r,e,t,n){let o={};for(let u=0;u<e.length;++u)o[e[u]]=u;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),a=0,c=0,f=0;for(let u=0;u<i;++u){let l=o[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|l,a+=t,a>=8&&(a-=8,s[f++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s}function Df(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;i.length*t&7;)i+="=";return i}function oe({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return wr({prefix:e,name:r,encode(o){return Df(o,n,t)},decode(o){return Lf(o,n,t,r)}})}var Ut=oe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ea=oe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Vf=oe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Of=oe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ff=oe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Mf=oe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Pf=oe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Hf=oe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Kf=oe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Si={};he(Si,{base58btc:()=>ye,base58flickr:()=>$f});var ye=_t({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),$f=_t({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ri={};he(Ri,{base64:()=>Qr,base64pad:()=>qf,base64url:()=>zf,base64urlpad:()=>Gf});var Qr=oe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),qf=oe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),zf=oe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Gf=oe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function jf(r,e){try{if(typeof r=="string"&&r.length>0)return Yf(r);if(typeof r=="number"&&isFinite(r))return e?.long?Wf(r):Zf(r);throw new Error("Value is not a string or number.")}catch(t){let n=Jf(t)?`${t.message}. value=${JSON.stringify(r)}`:"An unknown error has occured.";throw new Error(n)}}function Yf(r){if(r=String(r),r.length>100)throw new Error("Value exceeds the maximum length of 100 characters.");let e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(!e)return NaN;let t=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return t*315576e5;case"weeks":case"week":case"w":return t*6048e5;case"days":case"day":case"d":return t*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return t*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return t*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return t*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:throw new Error(`The unit ${n} was matched, but no matching case exists.`)}}var Hn=jf;function Zf(r){let e=Math.abs(r);return e>=864e5?`${Math.round(r/864e5)}d`:e>=36e5?`${Math.round(r/36e5)}h`:e>=6e4?`${Math.round(r/6e4)}m`:e>=1e3?`${Math.round(r/1e3)}s`:`${r}ms`}function Wf(r){let e=Math.abs(r);return e>=864e5?Pn(r,e,864e5,"day"):e>=36e5?Pn(r,e,36e5,"hour"):e>=6e4?Pn(r,e,6e4,"minute"):e>=1e3?Pn(r,e,1e3,"second"):`${r} ms`}function Pn(r,e,t,n){let o=e>=t*1.5;return`${Math.round(r/t)} ${n}${o?"s":""}`}function Jf(r){return typeof r=="object"&&r!==null&&"message"in r}function ki(r){t.debug=t,t.default=t,t.coerce=c,t.disable=i,t.enable=o,t.enabled=s,t.humanize=Hn,t.destroy=f,Object.keys(r).forEach(u=>{t[u]=r[u]}),t.names=[],t.skips=[],t.formatters={};function e(u){let l=0;for(let h=0;h<u.length;h++)l=(l<<5)-l+u.charCodeAt(h),l|=0;return t.colors[Math.abs(l)%t.colors.length]}t.selectColor=e;function t(u){let l,h=null,E,B;function p(...d){if(!p.enabled)return;let b=p,k=Number(new Date),w=k-(l||k);b.diff=w,b.prev=l,b.curr=k,l=k,d[0]=t.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let I=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(D,N)=>{if(D==="%%")return"%";I++;let x=t.formatters[N];if(typeof x=="function"){let v=d[I];D=x.call(b,v),d.splice(I,1),I--}return D}),t.formatArgs.call(b,d),(b.log||t.log).apply(b,d)}return p.namespace=u,p.useColors=t.useColors(),p.color=t.selectColor(u),p.extend=n,p.destroy=t.destroy,Object.defineProperty(p,"enabled",{enumerable:!0,configurable:!1,get:()=>h!==null?h:(E!==t.namespaces&&(E=t.namespaces,B=t.enabled(u)),B),set:d=>{h=d}}),typeof t.init=="function"&&t.init(p),p}function n(u,l){let h=t(this.namespace+(typeof l>"u"?":":l)+u);return h.log=this.log,h}function o(u){t.save(u),t.namespaces=u,t.names=[],t.skips=[];let l,h=(typeof u=="string"?u:"").split(/[\s,]+/),E=h.length;for(l=0;l<E;l++)h[l]&&(u=h[l].replace(/\*/g,".*?"),u[0]==="-"?t.skips.push(new RegExp("^"+u.substr(1)+"$")):t.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...t.names.map(a),...t.skips.map(a).map(l=>"-"+l)].join(",");return t.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let l,h;for(l=0,h=t.skips.length;l<h;l++)if(t.skips[l].test(u))return!1;for(l=0,h=t.names.length;l<h;l++)if(t.names[l].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack??u.message:u}function f(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.setupFormatters(t.formatters),t.enable(t.load()),t}var Kn=oh(),Xf=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Qf(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function eh(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+Hn(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(t++,o==="%c"&&(n=t))}),r.splice(n,0,e)}var th=console.debug??console.log??(()=>{});function rh(r){try{r?Kn?.setItem("debug",r):Kn?.removeItem("debug")}catch{}}function nh(){let r;try{r=Kn?.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function oh(){try{return localStorage}catch{}}function ih(r){r.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}}var va=ki({formatArgs:eh,save:rh,load:nh,useColors:Qf,setupFormatters:ih,colors:Xf,storage:Kn,log:th});var De=va;De.formatters.b=r=>r==null?"undefined":ye.baseEncode(r);De.formatters.t=r=>r==null?"undefined":Ut.baseEncode(r);De.formatters.m=r=>r==null?"undefined":Qr.baseEncode(r);De.formatters.p=r=>r==null?"undefined":r.toString();De.formatters.c=r=>r==null?"undefined":r.toString();De.formatters.k=r=>r==null?"undefined":r.toString();De.formatters.a=r=>r==null?"undefined":r.toString();function sh(r){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=r,e.destroy=()=>!0,e.extend=()=>e,e}function Lt(r){let e=sh(`${r}:trace`);return De.enabled(`${r}:trace`)&&De.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=De(`${r}:trace`)),Object.assign(De(r),{error:De(`${r}:error`),trace:e})}var Ii={};he(Ii,{base10:()=>ah});var ah=_t({prefix:"9",name:"base10",alphabet:"0123456789"});var Ti={};he(Ti,{base16:()=>ch,base16upper:()=>uh});var ch=oe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),uh=oe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ci={};he(Ci,{base2:()=>lh});var lh=oe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ni={};he(Ni,{base256emoji:()=>gh});var Ba=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}"),fh=Ba.reduce((r,e,t)=>(r[t]=e,r),[]),hh=Ba.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function dh(r){return r.reduce((e,t)=>(e+=fh[t],e),"")}function ph(r){let e=[];for(let t of r){let n=hh[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var gh=wr({prefix:"\u{1F680}",name:"base256emoji",encode:dh,decode:ph});var _i={};he(_i,{base36:()=>$n,base36upper:()=>mh});var $n=_t({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),mh=_t({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ui={};he(Ui,{base8:()=>yh});var yh=oe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Li={};he(Li,{identity:()=>wh});var wh=wr({prefix:"\0",name:"identity",encode:r=>ya(r),decode:r=>ma(r)});var Lg=new TextEncoder,Dg=new TextDecoder;var Vi={};he(Vi,{identity:()=>ze});var Eh=Ra,Aa=128,vh=127,Bh=~vh,Ah=Math.pow(2,31);function Ra(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Ah;)e[t++]=r&255|Aa,r/=128;for(;r&Bh;)e[t++]=r&255|Aa,r>>>=7;return e[t]=r|0,Ra.bytes=t-n+1,e}var Sh=Di,Rh=128,Sa=127;function Di(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Di.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&Sa)<<o:(s&Sa)*Math.pow(2,o),o+=7}while(s>=Rh);return Di.bytes=i-n,t}var kh=Math.pow(2,7),Ih=Math.pow(2,14),Th=Math.pow(2,21),Ch=Math.pow(2,28),Nh=Math.pow(2,35),_h=Math.pow(2,42),Uh=Math.pow(2,49),Lh=Math.pow(2,56),Dh=Math.pow(2,63),Vh=function(r){return r<kh?1:r<Ih?2:r<Th?3:r<Ch?4:r<Nh?5:r<_h?6:r<Uh?7:r<Lh?8:r<Dh?9:10},Oh={encode:Eh,decode:Sh,encodingLength:Vh},Fh=Oh,en=Fh;function tn(r,e=0){return[en.decode(r,e),en.decode.bytes]}function xr(r,e,t=0){return en.encode(r,e,t),e}function br(r){return en.encodingLength(r)}function tt(r,e){let t=e.byteLength,n=br(r),o=n+br(t),i=new Uint8Array(o+t);return xr(r,i,0),xr(t,i,n),i.set(e,o),new Er(r,t,e,i)}function tr(r){let e=ht(r),[t,n]=tn(e),[o,i]=tn(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Er(t,o,s,e)}function ka(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ga(r.bytes,t.bytes)}}var Er=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var Ia=0,Mh="identity",Ta=ht;function Ph(r){return tt(Ia,Ta(r))}var ze={code:Ia,name:Mh,encode:Ta,digest:Ph};var Mi={};he(Mi,{sha256:()=>we,sha512:()=>Hh});function Fi({name:r,code:e,encode:t}){return new Oi(r,e,t)}var Oi=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?tt(this.code,t):t.then(n=>tt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Na(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var we=Fi({name:"sha2-256",code:18,encode:Na("SHA-256")}),Hh=Fi({name:"sha2-512",code:19,encode:Na("SHA-512")});function _a(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return $h(t,Pi(r),e??ye.encoder);default:return qh(t,Pi(r),e??Ut.encoder)}}var Ua=new WeakMap;function Pi(r){let e=Ua.get(r);if(e==null){let t=new Map;return Ua.set(r,t),t}return e}var ve=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!==rn)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==zh)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=tt(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&ka(e.multihash,n.multihash)}toString(e){return _a(this,e)}toJSON(){return{"/":_a(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??La(n,o,i.bytes))}else if(t[Gh]===!0){let{version:n,multihash:o,code:i}=t,s=tr(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==rn)throw new Error(`Version 0 CID must use dag-pb (code: ${rn}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=La(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,rn,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=ht(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new Er(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,h]=tn(e.subarray(t));return t+=h,l},o=n(),i=rn;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),f=t+c,u=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,t){let[n,o]=Kh(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Pi(i).set(n,e),i}};function Kh(r,e){switch(r[0]){case"Q":{let t=e??ye;return[ye.prefix,t.decode(`${ye.prefix}${r}`)]}case ye.prefix:{let t=e??ye;return[ye.prefix,t.decode(r)]}case Ut.prefix:{let t=e??Ut;return[Ut.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function $h(r,e,t){let{prefix:n}=t;if(n!==ye.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function qh(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var rn=112,zh=18;function La(r,e,t){let n=br(r),o=n+br(e),i=new Uint8Array(o+t.byteLength);return xr(r,i,0),xr(e,i,n),i.set(t,o),i}var Gh=Symbol.for("@ipld/js-cid/CID");var vr={...Li,...Ci,...Ui,...Ii,...Ti,...Ai,..._i,...Si,...Ri,...Ni},rm={...Mi,...Vi};function ce(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 Hi(r=0){return new Uint8Array(r)}function rt(r=0){return new Uint8Array(r)}function Va(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Da=Va("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ki=Va("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=rt(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),jh={utf8:Da,"utf-8":Da,hex:vr.base16,latin1:Ki,ascii:Ki,binary:Ki,...vr},zn=jh;function Z(r,e="utf8"){let t=zn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function Q(r,e="utf8"){let t=zn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Fa=Symbol.for("nodejs.util.inspect.custom"),Oa=Object.values(vr).map(r=>r.decoder).reduce((r,e)=>r.or(e),vr.identity.decoder),Ma=114,zi=36,Gi=37,nn=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Mn]=!0;toString(){return this.string==null&&(this.string=ye.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return ve.createV1(Ma,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ce(this.multihash.bytes,e);if(typeof e=="string")return on(e).equals(this);if(e?.multihash?.bytes!=null)return ce(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[Fa](){return`PeerId(${this.toString()})`}},Br=class extends nn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Ar=class extends nn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},Sr=class extends nn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}},$i=2336,qi=class{type="url";multihash;privateKey;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=ze.digest(Z(this.url))}[Fa](){return`PeerId(${this.url})`}[Mn]=!0;toString(){return this.toCID().toString()}toCID(){return ve.createV1($i,this.multihash)}toBytes(){return this.toCID().bytes}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=Q(e)),e.toString()===this.toString())}};function on(r,e){if(e=e??Oa,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=tr(ye.decode(`z${r}`));return r.startsWith("12D")?new Ar({multihash:t}):r.startsWith("16U")?new Sr({multihash:t}):new Br({multihash:t})}return ji(Oa.decode(r))}function ji(r){try{let e=tr(r);if(e.code===ze.code){if(e.digest.length===zi)return new Ar({multihash:e});if(e.digest.length===Gi)return new Sr({multihash:e})}if(e.code===we.code)return new Br({multihash:e})}catch{return Yh(ve.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Yh(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==Ma&&r.code!==$i)throw new Error("Supplied PeerID CID is invalid");if(r.code===$i){let t=Q(r.multihash.digest);return new qi(new URL(t))}let e=r.multihash;if(e.code===we.code)return new Br({multihash:r.multihash});if(e.code===ze.code){if(e.digest.length===zi)return new Ar({multihash:r.multihash});if(e.digest.length===Gi)return new Sr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function Pa(r,e){return r.length===zi?new Ar({multihash:tt(ze.code,r),privateKey:e}):r.length===Gi?new Sr({multihash:tt(ze.code,r),privateKey:e}):new Br({multihash:await we.digest(r),publicKey:r,privateKey:e})}var Bs={};he(Bs,{Ed25519PrivateKey:()=>hr,Ed25519PublicKey:()=>pn,generateKeyPair:()=>g0,generateKeyPairFromSeed:()=>Sc,unmarshalEd25519PrivateKey:()=>d0,unmarshalEd25519PublicKey:()=>p0});function nr(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=rt(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}function He(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Rr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function Zh(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function kr(r,...e){if(!Zh(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 Gn(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Rr(r.outputLen),Rr(r.blockLen)}function Ir(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 Ha(r,e){kr(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var or=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var Cr=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Ge=(r,e)=>r<<32-e|r>>>e;var Dm=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Wh=async()=>{};async function Ka(r,e,t){let n=Date.now();for(let o=0;o<r;o++){t(o);let i=Date.now()-n;i>=0&&i<e||(await Wh(),n+=i)}}function $a(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Dt(r){return typeof r=="string"&&(r=$a(r)),kr(r),r}function Yi(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];kr(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}var Tr=class{clone(){return this._cloneInto()}},Jh={}.toString;function qa(r,e){if(e!==void 0&&Jh.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function jn(r){let e=n=>r().update(Dt(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Nr(r=32){if(or&&typeof or.getRandomValues=="function")return or.getRandomValues(new Uint8Array(r));if(or&&typeof or.randomBytes=="function")return or.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function Xh(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(t>>o&i),a=Number(t&i),c=n?4:0,f=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+f,a,n)}var za=(r,e,t)=>r&e^~r&t,Ga=(r,e,t)=>r&e^r&t^e&t,_r=class extends Tr{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=Cr(this.buffer)}update(e){Ir(this);let{view:t,buffer:n,blockLen:o}=this;e=Dt(e);let i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=Cr(e);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ir(this),Ha(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)t[l]=0;Xh(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=Cr(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.length=o,e.pos=a,e.finished=i,e.destroyed=s,o%t&&e.buffer.set(n),e}};var Yn=BigInt(4294967295),Zi=BigInt(32);function ja(r,e=!1){return e?{h:Number(r&Yn),l:Number(r>>Zi&Yn)}:{h:Number(r>>Zi&Yn)|0,l:Number(r&Yn)|0}}function Qh(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:i,l:s}=ja(r[o],e);[t[o],n[o]]=[i,s]}return[t,n]}var ed=(r,e)=>BigInt(r>>>0)<<Zi|BigInt(e>>>0),td=(r,e,t)=>r>>>t,rd=(r,e,t)=>r<<32-t|e>>>t,nd=(r,e,t)=>r>>>t|e<<32-t,od=(r,e,t)=>r<<32-t|e>>>t,id=(r,e,t)=>r<<64-t|e>>>t-32,sd=(r,e,t)=>r>>>t-32|e<<64-t,ad=(r,e)=>e,cd=(r,e)=>r,ud=(r,e,t)=>r<<t|e>>>32-t,ld=(r,e,t)=>e<<t|r>>>32-t,fd=(r,e,t)=>e<<t-32|r>>>64-t,hd=(r,e,t)=>r<<t-32|e>>>64-t;function dd(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var pd=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),gd=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,md=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),yd=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,wd=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),xd=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var bd={fromBig:ja,split:Qh,toBig:ed,shrSH:td,shrSL:rd,rotrSH:nd,rotrSL:od,rotrBH:id,rotrBL:sd,rotr32H:ad,rotr32L:cd,rotlSH:ud,rotlSL:ld,rotlBH:fd,rotlBL:hd,add:dd,add3L:pd,add3H:gd,add4L:md,add4H:yd,add5H:xd,add5L:wd},q=bd;var[Ed,vd]=q.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))),Vt=new Uint32Array(80),Ot=new Uint32Array(80),Wi=class extends _r{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:i,Cl:s,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:h,Gh:E,Gl:B,Hh:p,Hl:d}=this;return[e,t,n,o,i,s,a,c,f,u,l,h,E,B,p,d]}set(e,t,n,o,i,s,a,c,f,u,l,h,E,B,p,d){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=h|0,this.Gh=E|0,this.Gl=B|0,this.Hh=p|0,this.Hl=d|0}process(e,t){for(let w=0;w<16;w++,t+=4)Vt[w]=e.getUint32(t),Ot[w]=e.getUint32(t+=4);for(let w=16;w<80;w++){let I=Vt[w-15]|0,O=Ot[w-15]|0,D=q.rotrSH(I,O,1)^q.rotrSH(I,O,8)^q.shrSH(I,O,7),N=q.rotrSL(I,O,1)^q.rotrSL(I,O,8)^q.shrSL(I,O,7),x=Vt[w-2]|0,v=Ot[w-2]|0,F=q.rotrSH(x,v,19)^q.rotrBH(x,v,61)^q.shrSH(x,v,6),_=q.rotrSL(x,v,19)^q.rotrBL(x,v,61)^q.shrSL(x,v,6),C=q.add4L(N,_,Ot[w-7],Ot[w-16]),$=q.add4H(C,D,F,Vt[w-7],Vt[w-16]);Vt[w]=$|0,Ot[w]=C|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:h,Fh:E,Fl:B,Gh:p,Gl:d,Hh:b,Hl:k}=this;for(let w=0;w<80;w++){let I=q.rotrSH(l,h,14)^q.rotrSH(l,h,18)^q.rotrBH(l,h,41),O=q.rotrSL(l,h,14)^q.rotrSL(l,h,18)^q.rotrBL(l,h,41),D=l&E^~l&p,N=h&B^~h&d,x=q.add5L(k,O,N,vd[w],Ot[w]),v=q.add5H(x,b,I,D,Ed[w],Vt[w]),F=x|0,_=q.rotrSH(n,o,28)^q.rotrBH(n,o,34)^q.rotrBH(n,o,39),C=q.rotrSL(n,o,28)^q.rotrBL(n,o,34)^q.rotrBL(n,o,39),$=n&i^n&a^i&a,S=o&s^o&c^s&c;b=p|0,k=d|0,p=E|0,d=B|0,E=l|0,B=h|0,{h:l,l:h}=q.add(f|0,u|0,v|0,F|0),f=a|0,u=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let R=q.add3L(F,C,S);n=q.add3H(R,v,_,$),o=R|0}({h:n,l:o}=q.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=q.add(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=q.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=q.add(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:h}=q.add(this.Eh|0,this.El|0,l|0,h|0),{h:E,l:B}=q.add(this.Fh|0,this.Fl|0,E|0,B|0),{h:p,l:d}=q.add(this.Gh|0,this.Gl|0,p|0,d|0),{h:b,l:k}=q.add(this.Hh|0,this.Hl|0,b|0,k|0),this.set(n,o,i,s,a,c,f,u,l,h,E,B,p,d,b,k)}roundClean(){Vt.fill(0),Ot.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 sn=jn(()=>new Wi);var Wn={};he(Wn,{aInRange:()=>Ne,abool:()=>je,abytes:()=>Ur,bitGet:()=>Id,bitLen:()=>ts,bitMask:()=>cn,bitSet:()=>Td,bytesToHex:()=>pt,bytesToNumberBE:()=>gt,bytesToNumberLE:()=>Mt,concatBytes:()=>mt,createHmacDrbg:()=>rs,ensureBytes:()=>ie,equalBytes:()=>Rd,hexToBytes:()=>sr,hexToNumber:()=>es,inRange:()=>an,isBytes:()=>Ft,memoized:()=>cr,notImplemented:()=>Nd,numberToBytesBE:()=>Pt,numberToBytesLE:()=>ar,numberToHexUnpadded:()=>ir,numberToVarBytesBE:()=>Sd,utf8ToBytes:()=>kd,validateObject:()=>nt});var Qi=BigInt(0),Zn=BigInt(1),Bd=BigInt(2);function Ft(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Ur(r){if(!Ft(r))throw new Error("Uint8Array expected")}function je(r,e){if(typeof e!="boolean")throw new Error(`${r} must be valid boolean, got "${e}".`)}var Ad=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function pt(r){Ur(r);let e="";for(let t=0;t<r.length;t++)e+=Ad[r[t]];return e}function ir(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function es(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var dt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Ya(r){if(r>=dt._0&&r<=dt._9)return r-dt._0;if(r>=dt._A&&r<=dt._F)return r-(dt._A-10);if(r>=dt._a&&r<=dt._f)return r-(dt._a-10)}function sr(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,i=0;o<t;o++,i+=2){let s=Ya(r.charCodeAt(i)),a=Ya(r.charCodeAt(i+1));if(s===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function gt(r){return es(pt(r))}function Mt(r){return Ur(r),es(pt(Uint8Array.from(r).reverse()))}function Pt(r,e){return sr(r.toString(16).padStart(e*2,"0"))}function ar(r,e){return Pt(r,e).reverse()}function Sd(r){return sr(ir(r))}function ie(r,e,t){let n;if(typeof e=="string")try{n=sr(e)}catch(i){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${i}`)}else if(Ft(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 mt(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];Ur(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}function Rd(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 kd(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}var Ji=r=>typeof r=="bigint"&&Qi<=r;function an(r,e,t){return Ji(r)&&Ji(e)&&Ji(t)&&e<=r&&r<t}function Ne(r,e,t,n){if(!an(e,t,n))throw new Error(`expected valid ${r}: ${t} <= n < ${n}, got ${typeof e} ${e}`)}function ts(r){let e;for(e=0;r>Qi;r>>=Zn,e+=1);return e}function Id(r,e){return r>>BigInt(e)&Zn}function Td(r,e,t){return r|(t?Zn:Qi)<<BigInt(e)}var cn=r=>(Bd<<BigInt(r-1))-Zn,Xi=r=>new Uint8Array(r),Za=r=>Uint8Array.from(r);function rs(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=Xi(r),o=Xi(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...l)=>t(o,n,...l),c=(l=Xi())=>{o=a(Za([0]),l),n=a(),l.length!==0&&(o=a(Za([1]),l),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,h=[];for(;l<e;){n=a();let E=n.slice();h.push(E),l+=n.length}return mt(...h)};return(l,h)=>{s(),c(l);let E;for(;!(E=h(f()));)c();return s(),E}}var Cd={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"||Ft(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 nt(r,e,t={}){let n=(o,i,s)=>{let a=Cd[i];if(typeof a!="function")throw new Error(`Invalid validator "${i}", expected function`);let c=r[o];if(!(s&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(o)}=${c} (${typeof c}), expected ${i}`)};for(let[o,i]of Object.entries(e))n(o,i,!1);for(let[o,i]of Object.entries(t))n(o,i,!0);return r}var Nd=()=>{throw new Error("not implemented")};function cr(r){let e=new WeakMap;return(t,...n)=>{let o=e.get(t);if(o!==void 0)return o;let i=r(t,...n);return e.set(t,i),i}}var ue=BigInt(0),te=BigInt(1),ur=BigInt(2),_d=BigInt(3),ns=BigInt(4),Wa=BigInt(5),Ja=BigInt(8),Ud=BigInt(9),Ld=BigInt(16);function X(r,e){let t=r%e;return t>=ue?t:e+t}function Dd(r,e,t){if(t<=ue||e<ue)throw new Error("Expected power/modulo > 0");if(t===te)return ue;let n=te;for(;e>ue;)e&te&&(n=n*r%t),r=r*r%t,e>>=te;return n}function re(r,e,t){let n=r;for(;e-- >ue;)n*=n,n%=t;return n}function Jn(r,e){if(r===ue||e<=ue)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=X(r,e),n=e,o=ue,i=te,s=te,a=ue;for(;t!==ue;){let f=n/t,u=n%t,l=o-s*f,h=i-a*f;n=t,t=u,o=s,i=a,s=l,a=h}if(n!==te)throw new Error("invert: does not exist");return X(o,e)}function Vd(r){let e=(r-te)/ur,t,n,o;for(t=r-te,n=0;t%ur===ue;t/=ur,n++);for(o=ur;o<r&&Dd(o,e,r)!==r-te;o++);if(n===1){let s=(r+te)/ns;return function(c,f){let u=c.pow(f,s);if(!c.eql(c.sqr(u),f))throw new Error("Cannot find square root");return u}}let i=(t+te)/ur;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,u=a.pow(a.mul(a.ONE,o),t),l=a.pow(c,i),h=a.pow(c,t);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let E=1;for(let p=a.sqr(h);E<f&&!a.eql(p,a.ONE);E++)p=a.sqr(p);let B=a.pow(u,te<<BigInt(f-E-1));u=a.sqr(B),l=a.mul(l,B),h=a.mul(h,u),f=E}return l}}function Od(r){if(r%ns===_d){let e=(r+te)/ns;return function(n,o){let i=n.pow(o,e);if(!n.eql(n.sqr(i),o))throw new Error("Cannot find square root");return i}}if(r%Ja===Wa){let e=(r-Wa)/Ja;return function(n,o){let i=n.mul(o,ur),s=n.pow(i,e),a=n.mul(o,s),c=n.mul(n.mul(a,ur),s),f=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(f),o))throw new Error("Cannot find square root");return f}}return r%Ld,Vd(r)}var Xa=(r,e)=>(X(r,e)&te)===te,Fd=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function os(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=Fd.reduce((n,o)=>(n[o]="function",n),e);return nt(r,t)}function Md(r,e,t){if(t<ue)throw new Error("Expected power > 0");if(t===ue)return r.ONE;if(t===te)return e;let n=r.ONE,o=e;for(;t>ue;)t&te&&(n=r.mul(n,o)),o=r.sqr(o),t>>=te;return n}function Pd(r,e){let t=new Array(e.length),n=e.reduce((i,s,a)=>r.is0(s)?i:(t[a]=i,r.mul(i,s)),r.ONE),o=r.inv(n);return e.reduceRight((i,s,a)=>r.is0(s)?i:(t[a]=r.mul(i,t[a]),r.mul(i,s)),o),t}function is(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Ht(r,e,t=!1,n={}){if(r<=ue)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:o,nByteLength:i}=is(r,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=Od(r),a=Object.freeze({ORDER:r,BITS:o,BYTES:i,MASK:cn(o),ZERO:ue,ONE:te,create:c=>X(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return ue<=c&&c<r},is0:c=>c===ue,isOdd:c=>(c&te)===te,neg:c=>X(-c,r),eql:(c,f)=>c===f,sqr:c=>X(c*c,r),add:(c,f)=>X(c+f,r),sub:(c,f)=>X(c-f,r),mul:(c,f)=>X(c*f,r),pow:(c,f)=>Md(a,c,f),div:(c,f)=>X(c*Jn(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Jn(c,r),sqrt:n.sqrt||(c=>s(a,c)),invertBatch:c=>Pd(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>t?ar(c,i):Pt(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return t?Mt(c):gt(c)}});return Object.freeze(a)}function Qa(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 ss(r){let e=Qa(r);return e+Math.ceil(e/2)}function ec(r,e,t=!1){let n=r.length,o=Qa(e),i=ss(e);if(n<16||n<i||n>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${n}`);let s=t?gt(r):Mt(r),a=X(s,e-te)+te;return t?ar(a,o):Pt(a,o)}var Kd=BigInt(0),as=BigInt(1),cs=new WeakMap,tc=new WeakMap;function Xn(r,e){let t=(i,s)=>{let a=s.negate();return i?a:s},n=i=>{if(!Number.isSafeInteger(i)||i<=0||i>e)throw new Error(`Wrong window size=${i}, should be [1..${e}]`)},o=i=>{n(i);let s=Math.ceil(e/i)+1,a=2**(i-1);return{windows:s,windowSize:a}};return{constTimeNegate:t,unsafeLadder(i,s){let a=r.ZERO,c=i;for(;s>Kd;)s&as&&(a=a.add(c)),c=c.double(),s>>=as;return a},precomputeWindow(i,s){let{windows:a,windowSize:c}=o(s),f=[],u=i,l=u;for(let h=0;h<a;h++){l=u,f.push(l);for(let E=1;E<c;E++)l=l.add(u),f.push(l);u=l.double()}return f},wNAF(i,s,a){let{windows:c,windowSize:f}=o(i),u=r.ZERO,l=r.BASE,h=BigInt(2**i-1),E=2**i,B=BigInt(i);for(let p=0;p<c;p++){let d=p*f,b=Number(a&h);a>>=B,b>f&&(b-=E,a+=as);let k=d,w=d+Math.abs(b)-1,I=p%2!==0,O=b<0;b===0?l=l.add(t(I,s[k])):u=u.add(t(O,s[w]))}return{p:u,f:l}},wNAFCached(i,s,a){let c=tc.get(i)||1,f=cs.get(i);return f||(f=this.precomputeWindow(i,c),c!==1&&cs.set(i,a(f))),this.wNAF(c,f,s)},setWindowSize(i,s){n(s),tc.set(i,s),cs.delete(i)}}}function Qn(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((u,l)=>{if(!e.isValid(u))throw new Error(`wrong scalar at index ${l}`)}),t.forEach((u,l)=>{if(!(u instanceof r))throw new Error(`wrong point at index ${l}`)});let o=ts(BigInt(t.length)),i=o>12?o-3:o>4?o-2:o?2:1,s=(1<<i)-1,a=new Array(s+1).fill(r.ZERO),c=Math.floor((e.BITS-1)/i)*i,f=r.ZERO;for(let u=c;u>=0;u-=i){a.fill(r.ZERO);for(let h=0;h<n.length;h++){let E=n[h],B=Number(E>>BigInt(u)&BigInt(s));a[B]=a[B].add(t[h])}let l=r.ZERO;for(let h=a.length-1,E=r.ZERO;h>0;h--)E=E.add(a[h]),l=l.add(E);if(f=f.add(l),u!==0)for(let h=0;h<i;h++)f=f.double()}return f}function un(r){return os(r.Fp),nt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...is(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ye=BigInt(0),_e=BigInt(1),eo=BigInt(2),$d=BigInt(8),qd={zip215:!0};function zd(r){let e=un(r);return nt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function rc(r){let e=zd(r),{Fp:t,n,prehash:o,hash:i,randomBytes:s,nByteLength:a,h:c}=e,f=eo<<BigInt(a*8)-_e,u=t.create,l=Ht(e.n,e.nBitLength),h=e.uvRatio||((y,g)=>{try{return{isValid:!0,value:t.sqrt(y*t.inv(g))}}catch{return{isValid:!1,value:Ye}}}),E=e.adjustScalarBytes||(y=>y),B=e.domain||((y,g,A)=>{if(je("phflag",A),g.length||A)throw new Error("Contexts/pre-hash are not supported");return y});function p(y,g){Ne("coordinate "+y,g,Ye,f)}function d(y){if(!(y instanceof w))throw new Error("ExtendedPoint expected")}let b=cr((y,g)=>{let{ex:A,ey:V,ez:M}=y,P=y.is0();g==null&&(g=P?$d:t.inv(M));let z=u(A*g),Y=u(V*g),G=u(M*g);if(P)return{x:Ye,y:_e};if(G!==_e)throw new Error("invZ was invalid");return{x:z,y:Y}}),k=cr(y=>{let{a:g,d:A}=e;if(y.is0())throw new Error("bad point: ZERO");let{ex:V,ey:M,ez:P,et:z}=y,Y=u(V*V),G=u(M*M),J=u(P*P),ee=u(J*J),le=u(Y*g),fe=u(J*u(le+G)),me=u(ee+u(A*u(Y*G)));if(fe!==me)throw new Error("bad point: equation left != right (1)");let Se=u(V*M),ae=u(P*z);if(Se!==ae)throw new Error("bad point: equation left != right (2)");return!0});class w{constructor(g,A,V,M){this.ex=g,this.ey=A,this.ez=V,this.et=M,p("x",g),p("y",A),p("z",V),p("t",M),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(g){if(g instanceof w)throw new Error("extended point not allowed");let{x:A,y:V}=g||{};return p("x",A),p("y",V),new w(A,V,_e,u(A*V))}static normalizeZ(g){let A=t.invertBatch(g.map(V=>V.ez));return g.map((V,M)=>V.toAffine(A[M])).map(w.fromAffine)}static msm(g,A){return Qn(w,l,g,A)}_setWindowSize(g){D.setWindowSize(this,g)}assertValidity(){k(this)}equals(g){d(g);let{ex:A,ey:V,ez:M}=this,{ex:P,ey:z,ez:Y}=g,G=u(A*Y),J=u(P*M),ee=u(V*Y),le=u(z*M);return G===J&&ee===le}is0(){return this.equals(w.ZERO)}negate(){return new w(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:g}=e,{ex:A,ey:V,ez:M}=this,P=u(A*A),z=u(V*V),Y=u(eo*u(M*M)),G=u(g*P),J=A+V,ee=u(u(J*J)-P-z),le=G+z,fe=le-Y,me=G-z,Se=u(ee*fe),ae=u(le*me),Ce=u(ee*me),ft=u(fe*le);return new w(Se,ae,ft,Ce)}add(g){d(g);let{a:A,d:V}=e,{ex:M,ey:P,ez:z,et:Y}=this,{ex:G,ey:J,ez:ee,et:le}=g;if(A===BigInt(-1)){let sa=u((P-M)*(J+G)),aa=u((P+M)*(J-G)),xi=u(aa-sa);if(xi===Ye)return this.double();let ca=u(z*eo*le),ua=u(Y*eo*ee),la=ua+ca,fa=aa+sa,ha=ua-ca,Ef=u(la*xi),vf=u(fa*ha),Bf=u(la*ha),Af=u(xi*fa);return new w(Ef,vf,Af,Bf)}let fe=u(M*G),me=u(P*J),Se=u(Y*V*le),ae=u(z*ee),Ce=u((M+P)*(G+J)-fe-me),ft=ae-Se,Jr=ae+Se,Xr=u(me-A*fe),yf=u(Ce*ft),wf=u(Jr*Xr),xf=u(Ce*Xr),bf=u(ft*Jr);return new w(yf,wf,bf,xf)}subtract(g){return this.add(g.negate())}wNAF(g){return D.wNAFCached(this,g,w.normalizeZ)}multiply(g){let A=g;Ne("scalar",A,_e,n);let{p:V,f:M}=this.wNAF(A);return w.normalizeZ([V,M])[0]}multiplyUnsafe(g){let A=g;return Ne("scalar",A,Ye,n),A===Ye?O:this.equals(O)||A===_e?this:this.equals(I)?this.wNAF(A).p:D.unsafeLadder(this,A)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return D.unsafeLadder(this,n).is0()}toAffine(g){return b(this,g)}clearCofactor(){let{h:g}=e;return g===_e?this:this.multiplyUnsafe(g)}static fromHex(g,A=!1){let{d:V,a:M}=e,P=t.BYTES;g=ie("pointHex",g,P),je("zip215",A);let z=g.slice(),Y=g[P-1];z[P-1]=Y&-129;let G=Mt(z),J=A?f:t.ORDER;Ne("pointHex.y",G,Ye,J);let ee=u(G*G),le=u(ee-_e),fe=u(V*ee-M),{isValid:me,value:Se}=h(le,fe);if(!me)throw new Error("Point.fromHex: invalid y coordinate");let ae=(Se&_e)===_e,Ce=(Y&128)!==0;if(!A&&Se===Ye&&Ce)throw new Error("Point.fromHex: x=0 and x_0=1");return Ce!==ae&&(Se=u(-Se)),w.fromAffine({x:Se,y:G})}static fromPrivateKey(g){return v(g).point}toRawBytes(){let{x:g,y:A}=this.toAffine(),V=ar(A,t.BYTES);return V[V.length-1]|=g&_e?128:0,V}toHex(){return pt(this.toRawBytes())}}w.BASE=new w(e.Gx,e.Gy,_e,u(e.Gx*e.Gy)),w.ZERO=new w(Ye,_e,_e,Ye);let{BASE:I,ZERO:O}=w,D=Xn(w,a*8);function N(y){return X(y,n)}function x(y){return N(Mt(y))}function v(y){let g=a;y=ie("private key",y,g);let A=ie("hashed private key",i(y),2*g),V=E(A.slice(0,g)),M=A.slice(g,2*g),P=x(V),z=I.multiply(P),Y=z.toRawBytes();return{head:V,prefix:M,scalar:P,point:z,pointBytes:Y}}function F(y){return v(y).pointBytes}function _(y=new Uint8Array,...g){let A=mt(...g);return x(i(B(A,ie("context",y),!!o)))}function C(y,g,A={}){y=ie("message",y),o&&(y=o(y));let{prefix:V,scalar:M,pointBytes:P}=v(g),z=_(A.context,V,y),Y=I.multiply(z).toRawBytes(),G=_(A.context,Y,P,y),J=N(z+G*M);Ne("signature.s",J,Ye,n);let ee=mt(Y,ar(J,t.BYTES));return ie("result",ee,a*2)}let $=qd;function S(y,g,A,V=$){let{context:M,zip215:P}=V,z=t.BYTES;y=ie("signature",y,2*z),g=ie("message",g),P!==void 0&&je("zip215",P),o&&(g=o(g));let Y=Mt(y.slice(z,2*z)),G,J,ee;try{G=w.fromHex(A,P),J=w.fromHex(y.slice(0,z),P),ee=I.multiplyUnsafe(Y)}catch{return!1}if(!P&&G.isSmallOrder())return!1;let le=_(M,J.toRawBytes(),G.toRawBytes(),g);return J.add(G.multiplyUnsafe(le)).subtract(ee).clearCofactor().equals(w.ZERO)}return I._setWindowSize(8),{CURVE:e,getPublicKey:F,sign:C,verify:S,ExtendedPoint:w,utils:{getExtendedPublicKey:v,randomPrivateKey:()=>s(t.BYTES),precompute(y=8,g=w.BASE){return g._setWindowSize(y),g.multiply(BigInt(3)),g}}}}var us=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),nc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),oy=BigInt(0),Gd=BigInt(1),oc=BigInt(2),iy=BigInt(3),jd=BigInt(5),Yd=BigInt(8);function Zd(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=us,a=r*r%i*r%i,c=re(a,oc,i)*a%i,f=re(c,Gd,i)*r%i,u=re(f,jd,i)*f%i,l=re(u,e,i)*u%i,h=re(l,t,i)*l%i,E=re(h,n,i)*h%i,B=re(E,o,i)*E%i,p=re(B,o,i)*E%i,d=re(p,e,i)*u%i;return{pow_p_5_8:re(d,oc,i)*r%i,b2:a}}function Wd(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Jd(r,e){let t=us,n=X(e*e*e,t),o=X(n*n*e,t),i=Zd(r*o).pow_p_5_8,s=X(r*n*i,t),a=X(e*s*s,t),c=s,f=X(s*nc,t),u=a===r,l=a===X(-r,t),h=a===X(-r*nc,t);return u&&(s=c),(l||h)&&(s=f),Xa(s,t)&&(s=X(-s,t)),{isValid:u||l,value:s}}var Xd=Ht(us,void 0,!0),Qd={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Xd,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Yd,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:sn,randomBytes:Nr,adjustScalarBytes:Wd,uvRatio:Jd},Lr=rc(Qd);var Dr=32,yt=64,to=32;function ic(){let r=Lr.utils.randomPrivateKey(),e=Lr.getPublicKey(r);return{privateKey:uc(r,e),publicKey:e}}function sc(r){if(r.length!==to)throw new TypeError('"seed" must be 32 bytes in length.');if(!(r instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=r,t=Lr.getPublicKey(e);return{privateKey:uc(e,t),publicKey:t}}function ac(r,e){let t=r.subarray(0,to);return Lr.sign(e instanceof Uint8Array?e:e.subarray(),t)}function cc(r,e,t){return Lr.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function uc(r,e){let t=new Uint8Array(yt);for(let n=0;n<to;n++)t[n]=r[n],t[to+n]=e[n];return t}var Re={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw Object.assign(new Error("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"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var ls={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function lc(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,o=r?.digest??"SHA-256",i=r?.saltLength??16,s=r?.iterations??32767,a=Re.get();t*=8;async function c(l,h){let E=a.getRandomValues(new Uint8Array(i)),B=a.getRandomValues(new Uint8Array(n)),p={name:e,iv:B};typeof h=="string"&&(h=Z(h));let d;if(h.length===0){d=await a.subtle.importKey("jwk",ls,{name:"AES-GCM"},!0,["encrypt"]);try{let k={name:"PBKDF2",salt:E,iterations:s,hash:{name:o}},w=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);d=await a.subtle.deriveKey(k,w,{name:e,length:t},!0,["encrypt"])}catch{d=await a.subtle.importKey("jwk",ls,{name:"AES-GCM"},!0,["encrypt"])}}else{let k={name:"PBKDF2",salt:E,iterations:s,hash:{name:o}},w=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);d=await a.subtle.deriveKey(k,w,{name:e,length:t},!0,["encrypt"])}let b=await a.subtle.encrypt(p,d,l);return nr([E,p.iv,new Uint8Array(b)])}async function f(l,h){let E=l.subarray(0,i),B=l.subarray(i,i+n),p=l.subarray(i+n),d={name:e,iv:B};typeof h=="string"&&(h=Z(h));let b;if(h.length===0)try{let w={name:"PBKDF2",salt:E,iterations:s,hash:{name:o}},I=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);b=await a.subtle.deriveKey(w,I,{name:e,length:t},!0,["decrypt"])}catch{b=await a.subtle.importKey("jwk",ls,{name:"AES-GCM"},!0,["decrypt"])}else{let w={name:"PBKDF2",salt:E,iterations:s,hash:{name:o}},I=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);b=await a.subtle.deriveKey(w,I,{name:e,length:t},!0,["decrypt"])}let k=await a.subtle.decrypt(d,b,p);return new Uint8Array(k)}return{encrypt:c,decrypt:f}}async function Vr(r,e){let n=await lc().encrypt(r,e);return Qr.encode(n)}var r0=Math.pow(2,7),n0=Math.pow(2,14),o0=Math.pow(2,21),fc=Math.pow(2,28),hc=Math.pow(2,35),dc=Math.pow(2,42),pc=Math.pow(2,49),ke=128,Kt=127;function ln(r){if(r<r0)return 1;if(r<n0)return 2;if(r<o0)return 3;if(r<fc)return 4;if(r<hc)return 5;if(r<dc)return 6;if(r<pc)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function gc(r,e,t=0){switch(ln(r)){case 8:e[t++]=r&255|ke,r/=128;case 7:e[t++]=r&255|ke,r/=128;case 6:e[t++]=r&255|ke,r/=128;case 5:e[t++]=r&255|ke,r/=128;case 4:e[t++]=r&255|ke,r>>>=7;case 3:e[t++]=r&255|ke,r>>>=7;case 2:e[t++]=r&255|ke,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function mc(r,e){let t=r[e],n=0;if(n+=t&Kt,t<ke||(t=r[e+1],n+=(t&Kt)<<7,t<ke)||(t=r[e+2],n+=(t&Kt)<<14,t<ke)||(t=r[e+3],n+=(t&Kt)<<21,t<ke)||(t=r[e+4],n+=(t&Kt)*fc,t<ke)||(t=r[e+5],n+=(t&Kt)*hc,t<ke)||(t=r[e+6],n+=(t&Kt)*dc,t<ke)||(t=r[e+7],n+=(t&Kt)*pc,t<ke))return n;throw new RangeError("Could not decode varint")}var fs=new Float32Array([-0]),$t=new Uint8Array(fs.buffer);function yc(r,e,t){fs[0]=r,e[t]=$t[0],e[t+1]=$t[1],e[t+2]=$t[2],e[t+3]=$t[3]}function wc(r,e){return $t[0]=r[e],$t[1]=r[e+1],$t[2]=r[e+2],$t[3]=r[e+3],fs[0]}var hs=new Float64Array([-0]),Be=new Uint8Array(hs.buffer);function xc(r,e,t){hs[0]=r,e[t]=Be[0],e[t+1]=Be[1],e[t+2]=Be[2],e[t+3]=Be[3],e[t+4]=Be[4],e[t+5]=Be[5],e[t+6]=Be[6],e[t+7]=Be[7]}function bc(r,e){return Be[0]=r[e],Be[1]=r[e+1],Be[2]=r[e+2],Be[3]=r[e+3],Be[4]=r[e+4],Be[5]=r[e+5],Be[6]=r[e+6],Be[7]=r[e+7],hs[0]}var i0=BigInt(Number.MAX_SAFE_INTEGER),s0=BigInt(Number.MIN_SAFE_INTEGER),Ve=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 lr;if(e<i0&&e>s0)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>Ec&&(o=0n,++n>Ec&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return lr;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):lr}},lr=new Ve(0,0);lr.toBigInt=function(){return 0n};lr.zzEncode=lr.zzDecode=function(){return this};lr.length=function(){return 1};var Ec=4294967296n;function vc(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 Bc(r,e,t){if(t-e<1)return"";let o,i=[],s=0,a;for(;e<t;)a=r[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function ds(r,e,t){let n=t,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function Ze(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function ro(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var ps=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,Ze(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 Ze(this,4);return ro(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ze(this,4);return ro(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ze(this,4);let e=wc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ze(this,4);let e=bc(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 Ze(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Bc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ze(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ze(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 Ve(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 Ze(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 Ze(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 Ze(this,8);let e=ro(this.buf,this.pos+=4),t=ro(this.buf,this.pos+=4);return new Ve(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=mc(this.buf,this.pos);return this.pos+=ln(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 gs(r){return new ps(r instanceof Uint8Array?r:r.subarray())}function qt(r,e,t){let n=gs(r);return e.decode(n,void 0,t)}function ms(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return rt(s);o+s>e&&(n=rt(e),o=0);let a=n.subarray(o,o+=s);return o&7&&(o=(o|7)+1),a}}var fr=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function ys(){}var xs=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},a0=ms();function c0(r){return globalThis.Buffer!=null?rt(r):a0(r)}var hn=class{len;head;tail;states;constructor(){this.len=0,this.head=new fr(ys,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new fr(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new bs((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(no,10,Ve.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Ve.fromBigInt(e);return this._push(no,t.length(),t)}uint64Number(e){return this._push(gc,ln(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=Ve.fromBigInt(e).zzEncode();return this._push(no,t.length(),t)}sint64Number(e){let t=Ve.fromNumber(e).zzEncode();return this._push(no,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(ws,1,e?1:0)}fixed32(e){return this._push(fn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Ve.fromBigInt(e);return this._push(fn,4,t.lo)._push(fn,4,t.hi)}fixed64Number(e){let t=Ve.fromNumber(e);return this._push(fn,4,t.lo)._push(fn,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(yc,4,e)}double(e){return this._push(xc,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(ws,1,0):this.uint32(t)._push(l0,t,e)}string(e){let t=vc(e);return t!==0?this.uint32(t)._push(ds,t,e):this._push(ws,1,0)}fork(){return this.states=new xs(this),this.head=this.tail=new fr(ys,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 fr(ys,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=c0(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function ws(r,e,t){e[t]=r&255}function u0(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var bs=class extends fr{next;constructor(e,t){super(u0,e,t),this.next=void 0}};function no(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 fn(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 l0(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(hn.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(f0,e,r),this},hn.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(h0,e,r),this});function f0(r,e,t){e.set(r,t)}function h0(r,e,t){r.length<40?ds(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(Z(r),t)}function Es(){return new hn}function zt(r,e){let t=Es();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var Or;(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"})(Or||(Or={}));function oo(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function dn(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return oo("enum",Or.VARINT,t,n)}function Gt(r,e){return oo("message",Or.LENGTH_DELIMITED,r,e)}var ne;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(ne||(ne={}));var vs;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(vs||(vs={}));(function(r){r.codec=()=>dn(vs)})(ne||(ne={}));var ot;(function(r){let e;r.codec=()=>(e==null&&(e=Gt((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),ne.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.Type=ne.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>zt(t,r.codec()),r.decode=t=>qt(t,r.codec())})(ot||(ot={}));var it;(function(r){let e;r.codec=()=>(e==null&&(e=Gt((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),ne.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let s=t.uint32();switch(s>>>3){case 1:o.Type=ne.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(s&7);break}}return o})),e),r.encode=t=>zt(t,r.codec()),r.decode=t=>qt(t,r.codec())})(it||(it={}));var pn=class{_key;constructor(e){this._key=Fr(e,Dr)}verify(e,t){return cc(this._key,t,e)}marshal(){return this._key}get bytes(){return ot.encode({Type:ne.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=we.digest(this.bytes);return He(e)?e.then(({bytes:t})=>t):e.bytes}},hr=class{_key;_publicKey;constructor(e,t){this._key=Fr(e,yt),this._publicKey=Fr(t,Dr)}sign(e){return ac(this._key,e)}get public(){return new pn(this._publicKey)}marshal(){return this._key}get bytes(){return it.encode({Type:ne.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}async hash(){let e=we.digest(this.bytes),t;return He(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=ze.digest(this.public.bytes);return ye.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return Vr(this.bytes,e);throw new K(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function d0(r){if(r.length>yt){r=Fr(r,yt+Dr);let n=r.subarray(0,yt),o=r.subarray(yt,r.length);return new hr(n,o)}r=Fr(r,yt);let e=r.subarray(0,yt),t=r.subarray(Dr);return new hr(e,t)}function p0(r){return r=Fr(r,Dr),new pn(r)}async function g0(){let{privateKey:r,publicKey:e}=ic();return new hr(r,e)}async function Sc(r){let{privateKey:e,publicKey:t}=sc(r);return new hr(e,t)}function Fr(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new K(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}var Us={};he(Us,{MAX_RSA_KEY_SIZE:()=>Rn,RsaPrivateKey:()=>$r,RsaPublicKey:()=>Sn,fromJwk:()=>K0,generateKeyPair:()=>$0,unmarshalRsaPrivateKey:()=>Ns,unmarshalRsaPublicKey:()=>H0});function dr(r){if(isNaN(r)||r<=0)throw new K("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return Nr(r)}var Wt={};he(Wt,{exportToPem:()=>V0,importFromPem:()=>O0,jwkToPkcs1:()=>_0,jwkToPkix:()=>L0,pkcs1ToJwk:()=>N0,pkixToJwk:()=>U0});var so=class extends Tr{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Gn(e);let n=Dt(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(e){return Ir(this),this.iHash.update(e),this}digestInto(e){Ir(this),kr(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},gn=(r,e,t)=>new so(r,e).update(t).digest();gn.create=(r,e)=>new so(r,e);function m0(r,e,t,n){Gn(r);let o=qa({dkLen:32,asyncTick:10},n),{c:i,dkLen:s,asyncTick:a}=o;if(Rr(i),Rr(s),Rr(a),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=Dt(e),f=Dt(t),u=new Uint8Array(s),l=gn.create(r,c),h=l._cloneInto().update(f);return{c:i,dkLen:s,asyncTick:a,DK:u,PRF:l,PRFSalt:h}}function y0(r,e,t,n,o){return r.destroy(),e.destroy(),n&&n.destroy(),o.fill(0),t}async function As(r,e,t,n){let{c:o,dkLen:i,asyncTick:s,DK:a,PRF:c,PRFSalt:f}=m0(r,e,t,n),u,l=new Uint8Array(4),h=Cr(l),E=new Uint8Array(c.outputLen);for(let B=1,p=0;p<i;B++,p+=c.outputLen){let d=a.subarray(p,p+c.outputLen);h.setInt32(0,B,!1),(u=f._cloneInto(u)).update(l).digestInto(E),d.set(E.subarray(0,d.length)),await Ka(o-1,s,()=>{c._cloneInto(u).update(E).digestInto(E);for(let b=0;b<d.length;b++)d[b]^=E[b]})}return y0(c,f,a,u,E)}var j=Nt(Rc());function pr(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 jt(r,e,t=-1){let n=t,o=r,i=0,s=Math.pow(2,e);for(let a=1;a<8;a++){if(r<s){let c;if(n<0)c=new ArrayBuffer(a),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let f=new Uint8Array(c);for(let u=a-1;u>=0;u--){let l=Math.pow(2,u*e);f[i-u-1]=Math.floor(o/l),o-=f[i-u-1]*l}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function uo(...r){let e=0,t=0;for(let i of r)e+=i.length;let n=new ArrayBuffer(e),o=new Uint8Array(n);for(let i of r)o.set(i,t),t+=i.length;return o}function Rs(){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=pr(t,8),o=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(o);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=r[a];return i[0]&=127,pr(i,8)-n}function kc(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let s=t-e,a=jt(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=jt(e,8,n),i=new Uint8Array(o);if(i[0]&128){let s=o.slice(0),a=new Uint8Array(s);o=new ArrayBuffer(o.byteLength+1),i=new Uint8Array(o);for(let c=0;c<s.byteLength;c++)i[c+1]=a[c];i[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function Ic(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 s=0;s<n;s++)o[s]="0";return o.join("").concat(t)}var hw=Math.log(2);function lo(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function ks(r){let e=0,t=0;for(let o=0;o<r.length;o++){let i=r[o];e+=i.byteLength}let n=new Uint8Array(e);for(let o=0;o<r.length;o++){let i=r[o];n.set(new Uint8Array(i),t),t+=i.byteLength}return n.buffer}function vt(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 yn=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return ks(this.items)}},mn=[new Uint8Array([1])],Tc="0123456789";var Hr="",Je=new ArrayBuffer(0),Is=new Uint8Array(0),wn="EndOfContent",Nc="OCTET STRING",_c="BIT STRING";function Bt(r){var e;return e=class extends r{constructor(...n){var o;super(...n);let i=n[0]||{};this.isHexOnly=(o=i.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=i.valueHex?j.BufferSourceConverter.toUint8Array(i.valueHex):Is}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!vt(this,s,o,i))return-1;let a=o+i;return this.valueHexView=s.subarray(o,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),o)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",Je)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:j.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var xt=class{constructor({blockLength:e=0,error:t=Hr,warnings:n=[],valueBeforeDecode:o=Is}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=j.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:j.Convert.ToHex(this.valueBeforeDecodeView)}}};xt.NAME="baseBlock";var Ae=class extends xt{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'")}};Ae.NAME="valueBlock";var fo=class extends Bt(xt){constructor({idBlock:e={}}={}){var t,n,o,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?j.BufferSourceConverter.toUint8Array(e.valueHex):Is,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",Je}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let o=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,o[0]=t}return o.buffer}if(!this.isHexOnly){let o=jt(this.tagNumber,7),i=new Uint8Array(o),s=o.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=i[c]|128;a[s]=i[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let i=0;i<o.length-1;i++)n[i+1]=o[i]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=j.BufferSourceConverter.toUint8Array(e);if(!vt(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,f=this.valueHexView=new Uint8Array(255),u=255;for(;i[c]&128;){if(f[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===u){u+=255;let h=new Uint8Array(u);for(let E=0;E<f.length;E++)h[E]=f[E];f=this.valueHexView=new Uint8Array(u)}}this.blockLength=c+1,f[c-1]=i[c]&127;let l=new Uint8Array(c);for(let h=0;h<c;h++)l[h]=f[h];f=this.valueHexView=new Uint8Array(c),f.set(l),this.blockLength<=9?this.tagNumber=pr(f,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};fo.NAME="identificationBlock";var ho=class extends xt{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=j.BufferSourceConverter.toUint8Array(e);if(!vt(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,t+this.blockLength;let s=i[0]&127;if(s>8)return this.error="Too big integer",-1;if(s+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=o.subarray(a,a+s);return c[s-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=pr(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=s+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let o=jt(this.length,8);if(o.byteLength>127)return this.error="Too big length",Je;if(t=new ArrayBuffer(o.byteLength+1),e)return t;let i=new Uint8Array(o);n=new Uint8Array(t),n[0]=o.byteLength|128;for(let s=0;s<o.byteLength;s++)n[s+1]=i[s];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};ho.NAME="lengthBlock";var U={},xe=class extends xt{constructor({name:e=Hr,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new fo(o),this.lenBlock=new ho(o),this.valueBlock=i?new i(o):new Ae(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 yn;t||Uc(this);let o=this.idBlock.toBER(e);if(n.write(o),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(i)}return t?Je: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():j.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${j.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 Ic(t,n)}};xe.NAME="BaseBlock";function Uc(r){if(r instanceof U.Constructed)for(let e of r.valueBlock.value)Uc(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var po=class extends xe{constructor({value:e=Hr,...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}'`}};po.NAME="BaseStringBlock";var go=class extends Bt(Ae){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};go.NAME="PrimitiveValueBlock";var Lc,mo=class extends xe{constructor(e={}){super(e,go),this.idBlock.isConstructed=!1}};Lc=mo;U.Primitive=Lc;mo.NAME="PRIMITIVE";function R0(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 Zo(r,e=0,t=r.length){let n=e,o=new xe({},Ae),i=new xt;if(!vt(i,r,e,t))return o.error=i.error,{offset:-1,result:o};if(!r.subarray(e,e+t).length)return o.error="Zero buffer length",{offset:-1,result:o};let a=o.idBlock.fromBER(r,e,t);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),a===-1)return o.error=o.idBlock.error,{offset:-1,result:o};if(e=a,t-=o.idBlock.blockLength,a=o.lenBlock.fromBER(r,e,t),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),a===-1)return o.error=o.lenBlock.error,{offset:-1,result:o};if(e=a,t-=o.lenBlock.blockLength,!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let c=xe;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=U.EndOfContent;break;case 1:c=U.Boolean;break;case 2:c=U.Integer;break;case 3:c=U.BitString;break;case 4:c=U.OctetString;break;case 5:c=U.Null;break;case 6:c=U.ObjectIdentifier;break;case 10:c=U.Enumerated;break;case 12:c=U.Utf8String;break;case 13:c=U.RelativeObjectIdentifier;break;case 14:c=U.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=U.Sequence;break;case 17:c=U.Set;break;case 18:c=U.NumericString;break;case 19:c=U.PrintableString;break;case 20:c=U.TeletexString;break;case 21:c=U.VideotexString;break;case 22:c=U.IA5String;break;case 23:c=U.UTCTime;break;case 24:c=U.GeneralizedTime;break;case 25:c=U.GraphicString;break;case 26:c=U.VisibleString;break;case 27:c=U.GeneralString;break;case 28:c=U.UniversalString;break;case 29:c=U.CharacterString;break;case 30:c=U.BmpString;break;case 31:c=U.DATE;break;case 32:c=U.TimeOfDay;break;case 33:c=U.DateTime;break;case 34:c=U.Duration;break;default:{let f=o.idBlock.isConstructed?new U.Constructed:new U.Primitive;f.idBlock=o.idBlock,f.lenBlock=o.lenBlock,f.warnings=o.warnings,o=f}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?U.Constructed:U.Primitive}return o=R0(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 Kr(r){if(!r.byteLength){let e=new xe({},Ae);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Zo(j.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function k0(r,e){return r?1:e}var st=class extends Ae{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=j.BufferSourceConverter.toUint8Array(e);if(!vt(this,o,t,n))return-1;if(this.valueBeforeDecodeView=o.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;k0(this.isIndefiniteForm,n)>0;){let s=Zo(o,i,n);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(i=s.offset,this.blockLength+=s.result.blockLength,n-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===wn)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===wn?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new yn;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?Je:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};st.NAME="ConstructedValueBlock";var Dc,Yt=class extends xe{constructor(e={}){super(e,st),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(`
|
|
4
4
|
`).map(o=>` ${o}`).join(`
|
|
5
5
|
`));let t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :
|
|
6
6
|
${e.join(`
|
|
7
|
-
`)}`:`${t} :`}};Uc=qt;N.Constructed=Uc;qt.NAME="CONSTRUCTED";var go=class extends Be{fromBER(e,t,n){return t}toBER(e){return Je}};go.override="EndOfContentValueBlock";var Dc,mo=class extends we{constructor(e={}){super(e,go),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Dc=mo;N.EndOfContent=Dc;mo.NAME=pn;var Lc,zt=class extends we{constructor(e={}){super(e,Be),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}`}};Lc=zt;N.Null=Lc;zt.NAME="NULL";var yo=class extends vt(Be){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=G.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=G.BufferSourceConverter.toUint8Array(e);return Et(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,Bs.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};yo.NAME="BooleanValueBlock";var Vc,wo=class extends we{constructor(e={}){super(e,yo),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}`}};Vc=wo;N.Boolean=Vc;wo.NAME="BOOLEAN";var xo=class extends vt(st){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=st.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let i=0;i<this.value.length;i++){let s=this.value[i].constructor.NAME;if(s===pn){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==Tc)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?st.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};xo.NAME="OctetStringValueBlock";var Oc,xt=class r extends we{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},xo),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){let i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(i.byteLength){let s=jo(i,0,i.byteLength);s.offset!==-1&&s.offset===n&&(this.valueBlock.value=[s.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?qt.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${G.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 G.BufferSourceConverter.concat(e)}};Oc=xt;N.OctetString=Oc;xt.NAME=Tc;var bo=class extends vt(st){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=st.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===pn){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Cc)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let f=a.valueBlock;if(this.unusedBits>0&&f.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=f.unusedBits}return o}let i=G.BufferSourceConverter.toUint8Array(e);if(!Et(this,i,t,n))return-1;let s=i.subarray(t,t+n);if(this.unusedBits=s[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=s.subarray(1);try{if(a.byteLength){let c=jo(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=s.subarray(1),this.blockLength=s.length,t+n}toBER(e,t){if(this.isConstructed)return st.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Je;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}}};bo.NAME="BitStringValueBlock";var Fc,Or=class extends we{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},bo),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 qt.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)}`}}};Fc=Or;N.BitString=Fc;Or.NAME=Cc;var Pc;function R0(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,f=0,u=c<s?s:c,l=0;for(let g=u;g>=0;g--,l++){switch(!0){case l<a.length:f=i[s-l]+a[c-l]+t[0];break;default:f=i[s-l]+t[0]}switch(t[0]=f/10,!0){case l>=i.length:i=ao(new Uint8Array([f%10]),i);break;default:i[s-l]=f%10}}return t[0]>0&&(i=ao(t,i)),i}function Ic(r){if(r>=hn.length)for(let e=hn.length;e<=r;e++){let t=new Uint8Array([0]),n=hn[e-1].slice(0);for(let o=n.length-1;o>=0;o--){let i=new Uint8Array([(n[o]<<1)+t[0]]);t[0]=i[0]/10,n[o]=i[0]%10}t[0]>0&&(n=ao(t,n)),hn.push(n)}return hn[r]}function k0(r,e){let t=0,n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,f,u=0;for(let l=c;l>=0;l--,u++)switch(f=i[s-u]-a[c-u]-t,!0){case f<0:t=1,i[s-u]=f+10;break;default:t=0,i[s-u]=f}if(t>0)for(let l=s-c+1;l>=0;l--,u++)if(f=i[s-u]-t,f<0)t=1,i[s-u]=f+10;else{t=0,i[s-u]=f;break}return i.slice()}var gn=class extends vt(Be){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=Bs.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Sc(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,o=0){let i=this.fromBER(e,t,n);if(i===-1)return i;let s=this.valueHexView;return s[0]===0&&s[1]&128?this.valueHexView=s.subarray(1):o!==0&&s.length<o&&(o-s.length>1&&(o=s.length+1),this.valueHexView=s.subarray(o-s.length)),i}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let o=super.fromBER(e,t,n);return o===-1||this.setValueHex(),o}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,o,i=this.valueHexView,s="",a=!1;for(let c=i.byteLength-1;c>=0;c--){o=i[c];for(let f=0;f<8;f++){if((o&1)===1)switch(n){case e:t=k0(Ic(n),t),s="-";break;default:t=R0(t,Ic(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=kc.charAt(t[c]));return a===!1&&(s+=kc.charAt(0)),s}};Pc=gn;gn.NAME="IntegerValueBlock";Object.defineProperty(Pc.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Mc,se=class r extends we{constructor(e={}){super(e,gn),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return co(),BigInt(this.valueBlock.toString())}static fromBigInt(e){co();let t=BigInt(e),n=new dn,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(G.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let f=BigInt(`0x${G.Convert.ToHex(a)}`)+t,u=G.BufferSourceConverter.toUint8Array(G.Convert.FromHex(f.toString(16)));u[0]|=128,n.write(u)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);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()}`}};Mc=se;N.Integer=Mc;se.NAME="INTEGER";var Hc,Eo=class extends se{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Hc=Eo;N.Enumerated=Hc;Eo.NAME="ENUMERATED";var mn=class extends vt(Be){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=G.BufferSourceConverter.toUint8Array(e);if(!Et(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,i[this.blockLength-1]&128?(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=lr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){co();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let o=0;o<n.length;o++)n[o]=parseInt(t.slice(o*7,o*7+7),2)+(o+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=$t(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Je;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n}toString(){let e="";if(this.isHexOnly)e=G.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}}};mn.NAME="sidBlock";var vo=class extends Be{constructor({value:e=Fr,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new mn;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let o=this.value[n].toBER(e);if(o.byteLength===0)return this.error=this.value[n].error,Je;t.push(o)}return As(t)}fromString(e){this.value=[];let t=0,n=0,o="",i=!1;do if(n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1,i){let s=this.value[0],a=0;switch(s.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(o,10);if(isNaN(c))return;s.valueDec=c+a,i=!1}else{let s=new mn;if(o>Number.MAX_SAFE_INTEGER){co();let a=BigInt(o);s.valueBigInt=a}else if(s.valueDec=parseInt(o,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,i=!0),this.value.push(s)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t?(o=`{${o}}`,this.value[n].isFirstSid?e=`2.{${o} - 80}`:e+=o):e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};vo.NAME="ObjectIdentifierValueBlock";var Kc,We=class extends we{constructor(e={}){super(e,vo),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()}}};Kc=We;N.ObjectIdentifier=Kc;We.NAME="OBJECT IDENTIFIER";var yn=class extends vt(wt){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=G.BufferSourceConverter.toUint8Array(e);if(!Et(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,i[this.blockLength-1]&128?(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=lr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=$t(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Je;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=G.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};yn.NAME="relativeSidBlock";var Bo=class extends Be{constructor({value:e=Fr,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new yn;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e,t){let n=[];for(let o=0;o<this.value.length;o++){let i=this.value[o].toBER(e);if(i.byteLength===0)return this.error=this.value[o].error,Je;n.push(i)}return As(n)}fromString(e){this.value=[];let t=0,n=0,o="";do{n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1;let i=new yn;if(i.valueDec=parseInt(o,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(o=`{${o}}`),e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Bo.NAME="RelativeObjectIdentifierValueBlock";var $c,Ao=class extends we{constructor(e={}){super(e,Bo),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()}}};$c=Ao;N.RelativeObjectIdentifier=$c;Ao.NAME="RelativeObjectIdentifier";var qc,de=class extends qt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};qc=de;N.Sequence=qc;de.NAME="SEQUENCE";var zc,So=class extends qt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};zc=So;N.Set=zc;So.NAME="SET";var Ro=class extends vt(Be){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Fr}toJSON(){return{...super.toJSON(),value:this.value}}};Ro.NAME="StringValueBlock";var ko=class extends Ro{};ko.NAME="SimpleStringValueBlock";var Re=class extends fo{constructor({...e}={}){super(e,ko)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,G.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}};Re.NAME="SIMPLE STRING";var Io=class extends Re{fromBuffer(e){this.valueBlock.valueHexView=G.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=G.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=G.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(G.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Io.NAME="Utf8StringValueBlock";var Gc,bt=class extends Io{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Gc=bt;N.Utf8String=Gc;bt.NAME="UTF8String";var To=class extends Re{fromBuffer(e){this.valueBlock.value=G.Convert.ToUtf16String(e),this.valueBlock.valueHexView=G.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(G.Convert.FromUtf16String(e))}};To.NAME="BmpStringValueBlock";var jc,Co=class extends To{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};jc=Co;N.BmpString=jc;Co.NAME="BMPString";var No=class extends Re{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let o=0;o<n.length;o+=4)n[o]=n[o+3],n[o+1]=n[o+2],n[o+2]=0,n[o+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let o=0;o<t;o++){let i=$t(e.charCodeAt(o),8),s=new Uint8Array(i);if(s.length>4)continue;let a=4-s.length;for(let c=s.length-1;c>=0;c--)n[o*4+c+a]=s[c]}this.valueBlock.value=e}};No.NAME="UniversalStringValueBlock";var Yc,_o=class extends No{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Yc=_o;N.UniversalString=Yc;_o.NAME="UniversalString";var Zc,Uo=class extends Re{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Zc=Uo;N.NumericString=Zc;Uo.NAME="NumericString";var Wc,Do=class extends Re{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Wc=Do;N.PrintableString=Wc;Do.NAME="PrintableString";var Jc,Lo=class extends Re{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Jc=Lo;N.TeletexString=Jc;Lo.NAME="TeletexString";var Xc,Vo=class extends Re{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Xc=Vo;N.VideotexString=Xc;Vo.NAME="VideotexString";var Qc,Oo=class extends Re{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Qc=Oo;N.IA5String=Qc;Oo.NAME="IA5String";var eu,Fo=class extends Re{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};eu=Fo;N.GraphicString=eu;Fo.NAME="GraphicString";var tu,wn=class extends Re{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};tu=wn;N.VisibleString=tu;wn.NAME="VisibleString";var ru,Po=class extends Re{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};ru=Po;N.GeneralString=ru;Po.NAME="GeneralString";var nu,Mo=class extends Re{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};nu=Mo;N.CharacterString=nu;Mo.NAME="CharacterString";var ou,xn=class extends wn{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,G.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]=Ne(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Ne(this.month,2),t[2]=Ne(this.day,2),t[3]=Ne(this.hour,2),t[4]=Ne(this.minute,2),t[5]=Ne(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}}};ou=xn;N.UTCTime=ou;xn.NAME="UTCTime";var iu,Ho=class extends xn{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="",i=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let l=new Number(e[e.length-1]);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let l=1,g=n.indexOf("+"),b="";if(g===-1&&(g=n.indexOf("-"),l=-1),g!==-1){if(b=n.substring(g+1),n=n.substring(0,g),b.length!==2&&b.length!==4)throw new Error("Wrong input string for conversion");let w=parseInt(b.substring(0,2),10);if(isNaN(w.valueOf()))throw new Error("Wrong input string for conversion");if(a=l*w,b.length===4){if(w=parseInt(b.substring(2,4),10),isNaN(w.valueOf()))throw new Error("Wrong input string for conversion");c=l*w}}}let f=n.indexOf(".");if(f===-1&&(f=n.indexOf(",")),f!==-1){let l=new Number(`0${n.substring(f)}`);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");i=l.valueOf(),o=n.substring(0,f)}else o=n;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,f!==-1)throw new Error("Wrong input string for conversion");break;case o.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*i;this.minute=Math.floor(l),l=60*(l-this.minute),this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*i;this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=1e3*i;this.millisecond=Math.floor(l)}break;default:throw new Error("Wrong input string for conversion")}let u=s.exec(o);if(u===null)throw new Error("Wrong input string for conversion");for(let l=1;l<u.length;l++)switch(l){case 1:this.year=parseInt(u[l],10);break;case 2:this.month=parseInt(u[l],10);break;case 3:this.day=parseInt(u[l],10);break;case 4:this.hour=parseInt(u[l],10)+a;break;case 5:this.minute=parseInt(u[l],10)+c;break;case 6:this.second=parseInt(u[l],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let l=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=l.getUTCFullYear(),this.month=l.getUTCMonth(),this.day=l.getUTCDay(),this.hour=l.getUTCHours(),this.minute=l.getUTCMinutes(),this.second=l.getUTCSeconds(),this.millisecond=l.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(Ne(this.year,4)),t.push(Ne(this.month,2)),t.push(Ne(this.day,2)),t.push(Ne(this.hour,2)),t.push(Ne(this.minute,2)),t.push(Ne(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Ne(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};iu=Ho;N.GeneralizedTime=iu;Ho.NAME="GeneralizedTime";var su,Ko=class extends bt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};su=Ko;N.DATE=su;Ko.NAME="DATE";var au,$o=class extends bt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};au=$o;N.TimeOfDay=au;$o.NAME="TimeOfDay";var cu,qo=class extends bt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};cu=qo;N.DateTime=cu;qo.NAME="DateTime";var uu,zo=class extends bt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};uu=zo;N.Duration=uu;zo.NAME="Duration";var lu,Go=class extends bt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};lu=Go;N.TIME=lu;Go.NAME="TIME";function T0(r){let{result:e}=Pr(r),t=e.valueBlock.value;return{n:X(at(t[1].toBigInt()),"base64url"),e:X(at(t[2].toBigInt()),"base64url"),d:X(at(t[3].toBigInt()),"base64url"),p:X(at(t[4].toBigInt()),"base64url"),q:X(at(t[5].toBigInt()),"base64url"),dp:X(at(t[6].toBigInt()),"base64url"),dq:X(at(t[7].toBigInt()),"base64url"),qi:X(at(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function C0(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 H("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new de({value:[new se({value:0}),se.fromBigInt(ct(j(r.n,"base64url"))),se.fromBigInt(ct(j(r.e,"base64url"))),se.fromBigInt(ct(j(r.d,"base64url"))),se.fromBigInt(ct(j(r.p,"base64url"))),se.fromBigInt(ct(j(r.q,"base64url"))),se.fromBigInt(ct(j(r.dp,"base64url"))),se.fromBigInt(ct(j(r.dq,"base64url"))),se.fromBigInt(ct(j(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function N0(r){let{result:e}=Pr(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:X(at(t[0].toBigInt()),"base64url"),e:X(at(t[1].toBigInt()),"base64url")}}function _0(r){if(r.n==null||r.e==null)throw new H("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new de({value:[new de({value:[new We({value:"1.2.840.113549.1.1.1"}),new zt]}),new Or({valueHex:new de({value:[se.fromBigInt(ct(j(r.n,"base64url"))),se.fromBigInt(ct(j(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function at(r){let e=r.toString(16);e.length%2>0&&(e=`0${e}`);let t=e.length/2,n=new Uint8Array(t),o=0,i=0;for(;o<t;)n[o]=parseInt(e.slice(i,i+2),16),o+=1,i+=2;return n}function ct(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(""))}var U0=16,Rs=32,ks=1e4;async function D0(r,e){let t=Ae.get(),o=new de({value:[new se({value:0}),new de({value:[new We({value:"1.2.840.113549.1.1.1"}),new zt]}),new xt({valueHex:r.marshal()})]}).toBER(),i=new Uint8Array(o,0,o.byteLength),s=ur(U0),a=await Es(tn,e,s,{c:ks,dkLen:Rs}),c=ur(16),f=await t.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),u=await t.subtle.encrypt({name:"AES-CBC",iv:c},f,i),l=new de({value:[new xt({valueHex:s}),new se({value:ks}),new se({value:Rs}),new de({value:[new We({value:"1.2.840.113549.2.11"}),new zt]})]}),g=new de({value:[new We({value:"1.2.840.113549.1.5.13"}),new de({value:[new de({value:[new We({value:"1.2.840.113549.1.5.12"}),l]}),new de({value:[new We({value:"2.16.840.1.101.3.4.1.42"}),new xt({valueHex:c})]})]})]}),w=new de({value:[g,new xt({valueHex:u})]}).toBER(),h=new Uint8Array(w,0,w.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...X(h,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
|
|
8
|
-
`)}async function L0(r,e){let t=Ae.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let o=j(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=Pr(o),{iv:s,salt:a,iterations:c,keySize:f,cipherText:u}=V0(i),l=await Es(tn,e,a,{c,dkLen:f}),g=await t.subtle.importKey("raw",l,"AES-CBC",!1,["decrypt"]),b=bn(await t.subtle.decrypt({name:"AES-CBC",iv:s},g,u)),{result:w}=Pr(b);n=fu(w)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let o=j(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=Pr(o);n=fu(i)}else throw new H("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return Is(n)}function V0(r){let e=r.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new H("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=e.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new H("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let i=n.valueBlock.value[1],s=bn(i.valueBlock.value[0].getValue()),a=ks,c=Rs;if(i.valueBlock.value.length===3)a=Number(i.valueBlock.value[1].toBigInt()),c=Number(i.valueBlock.value[2].toBigInt());else if(i.valueBlock.value.length===2)throw new H("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let f=e.valueBlock.value[1].valueBlock.value[1],u=f.valueBlock.value[0].toString();if(u!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(u!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new H("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let l=bn(f.valueBlock.value[1].getValue());return{cipherText:bn(r.valueBlock.value[1].getValue()),salt:s,iterations:a,keySize:c,iv:l}}function fu(r){return bn(r.valueBlock.value[2].getValue())}function bn(r){return new Uint8Array(r,0,r.byteLength)}async function hu(r){let e=await Ae.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 gu(e);return{privateKey:t[0],publicKey:t[1]}}async function Ts(r){let t=[await Ae.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await O0(r)],n=await gu({privateKey:t[0],publicKey:t[1]});return{privateKey:n[0],publicKey:n[1]}}async function du(r,e){let t=await Ae.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Ae.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function pu(r,e,t){let n=await Ae.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Ae.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function gu(r){if(r.privateKey==null||r.publicKey==null)throw new H("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([Ae.get().subtle.exportKey("jwk",r.privateKey),Ae.get().subtle.exportKey("jwk",r.publicKey)])}async function O0(r){return Ae.get().subtle.importKey("jwk",{kty:r.kty,n:r.n,e:r.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function Yo(r){if(r.kty!=="RSA")throw new H("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new H("invalid key modulus","ERR_INVALID_KEY_MODULUS");return j(r.n,"base64url").length*8}var vn=8192,En=class{_key;constructor(e){this._key=e}verify(e,t){return pu(this._key,t,e)}marshal(){return Gt.jwkToPkix(this._key)}get bytes(){return ot.encode({Type:te.RSA,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=ye.digest(this.bytes);return Pe(e)?e.then(({bytes:t})=>t):e.bytes}},Mr=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return ur(16)}sign(e){return du(this._key,e)}get public(){if(this._publicKey==null)throw new H("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new En(this._publicKey)}marshal(){return Gt.jwkToPkcs1(this._key)}get bytes(){return it.encode({Type:te.RSA,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=ye.digest(this.bytes);return Pe(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return X(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return Gt.exportToPem(this,e);if(t==="libp2p-key")return Ur(this.bytes,e);throw new H(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Is(r){let e=Gt.pkcs1ToJwk(r);if(Yo(e)>vn)throw new H("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Ts(e);return new Mr(t.privateKey,t.publicKey)}function P0(r){let e=Gt.pkixToJwk(r);if(Yo(e)>vn)throw new H("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new En(e)}async function M0(r){if(Yo(r)>vn)throw new H("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Ts(r);return new Mr(e.privateKey,e.publicKey)}async function H0(r){if(r>vn)throw new H("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await hu(r);return new Mr(e.privateKey,e.publicKey)}var Ls={};he(Ls,{Secp256k1PrivateKey:()=>An,Secp256k1PublicKey:()=>Bn,generateKeyPair:()=>ep,unmarshalSecp256k1PrivateKey:()=>X0,unmarshalSecp256k1PublicKey:()=>Q0});var K0=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]),jt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Yt=new Uint32Array(64),Ns=class extends Tr{constructor(){super(64,32,8,!1),this.A=jt[0]|0,this.B=jt[1]|0,this.C=jt[2]|0,this.D=jt[3]|0,this.E=jt[4]|0,this.F=jt[5]|0,this.G=jt[6]|0,this.H=jt[7]|0}get(){let{A:e,B:t,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,t,n,o,i,s,a,c]}set(e,t,n,o,i,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let l=0;l<16;l++,t+=4)Yt[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let g=Yt[l-15],b=Yt[l-2],w=Ge(g,7)^Ge(g,18)^g>>>3,h=Ge(b,17)^Ge(b,19)^b>>>10;Yt[l]=h+Yt[l-7]+w+Yt[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let g=Ge(a,6)^Ge(a,11)^Ge(a,25),b=u+g+Ka(a,c,f)+K0[l]+Yt[l]|0,h=(Ge(n,2)^Ge(n,13)^Ge(n,22))+$a(n,o,i)|0;u=f,f=c,c=a,a=s+b|0,s=i,i=o,o=n,n=b+h|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,i,s,a,c,f,u)}roundClean(){Yt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var mu=zn(()=>new Ns);function yu(r){r.lowS!==void 0&&je("lowS",r.lowS),r.prehash!==void 0&&je("prehash",r.prehash)}function $0(r){let e=on(r);nt(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:q0,hexToBytes:z0}=Yn,fr={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=fr;if(r.length<2||r[0]!==2)throw new e("Invalid signature integer tag");let t=r[1],n=r.subarray(2,t+2);if(!t||n.length!==t)throw new e("Invalid signature integer: wrong length");if(n[0]&128)throw new e("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:q0(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=fr,t=typeof r=="string"?z0(r):r;Cr(t);let n=t.length;if(n<2||t[0]!=48)throw new e("Invalid signature tag");if(t[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:o,l:i}=fr._parseInt(t.subarray(2)),{d:s,l:a}=fr._parseInt(i);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:o,s}},hexFromSig(r){let e=f=>Number.parseInt(f[0],16)&8?"00"+f:f,t=f=>{let u=f.toString(16);return u.length&1?`0${u}`:u},n=e(t(r.s)),o=e(t(r.r)),i=n.length/2,s=o.length/2,a=t(i),c=t(s);return`30${t(s+i+4)}02${c}${o}02${a}${n}`}},Zt=BigInt(0),pe=BigInt(1),Vw=BigInt(2),wu=BigInt(3),Ow=BigInt(4);function G0(r){let e=$0(r),{Fp:t}=e,n=e.toBytes||((w,h,m)=>{let v=h.toAffine();return gt(Uint8Array.from([4]),t.toBytes(v.x),t.toBytes(v.y))}),o=e.fromBytes||(w=>{let h=w.subarray(1),m=t.fromBytes(h.subarray(0,t.BYTES)),v=t.fromBytes(h.subarray(t.BYTES,2*t.BYTES));return{x:m,y:v}});function i(w){let{a:h,b:m}=e,v=t.sqr(w),E=t.mul(v,w);return t.add(t.add(E,t.mul(w,h)),m)}if(!t.eql(t.sqr(e.Gy),i(e.Gx)))throw new Error("bad generator point: equation left != right");function s(w){return rn(w,pe,e.n)}function a(w){let{allowedPrivateKeyLengths:h,nByteLength:m,wrapPrivateKey:v,n:E}=e;if(h&&typeof w!="bigint"){if(Lt(w)&&(w=dt(w)),typeof w!="string"||!h.includes(w.length))throw new Error("Invalid key");w=w.padStart(m*2,"0")}let B;try{B=typeof w=="bigint"?w:pt(ie("private key",w,m))}catch{throw new Error(`private key must be ${m} bytes, hex or bigint, not ${typeof w}`)}return v&&(B=J(B,E)),Te("private key",B,pe,E),B}function c(w){if(!(w instanceof l))throw new Error("ProjectivePoint expected")}let f=or((w,h)=>{let{px:m,py:v,pz:E}=w;if(t.eql(E,t.ONE))return{x:m,y:v};let B=w.is0();h==null&&(h=B?t.ONE:t.inv(E));let L=t.mul(m,h),U=t.mul(v,h),I=t.mul(E,h);if(B)return{x:t.ZERO,y:t.ZERO};if(!t.eql(I,t.ONE))throw new Error("invZ was invalid");return{x:L,y:U}}),u=or(w=>{if(w.is0()){if(e.allowInfinityPoint&&!t.is0(w.py))return;throw new Error("bad point: ZERO")}let{x:h,y:m}=w.toAffine();if(!t.isValid(h)||!t.isValid(m))throw new Error("bad point: x or y not FE");let v=t.sqr(m),E=i(h);if(!t.eql(v,E))throw new Error("bad point: equation left != right");if(!w.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class l{constructor(h,m,v){if(this.px=h,this.py=m,this.pz=v,h==null||!t.isValid(h))throw new Error("x required");if(m==null||!t.isValid(m))throw new Error("y required");if(v==null||!t.isValid(v))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:m,y:v}=h||{};if(!h||!t.isValid(m)||!t.isValid(v))throw new Error("invalid affine point");if(h instanceof l)throw new Error("projective point not allowed");let E=B=>t.eql(B,t.ZERO);return E(m)&&E(v)?l.ZERO:new l(m,v,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let m=t.invertBatch(h.map(v=>v.pz));return h.map((v,E)=>v.toAffine(m[E])).map(l.fromAffine)}static fromHex(h){let m=l.fromAffine(o(ie("pointHex",h)));return m.assertValidity(),m}static fromPrivateKey(h){return l.BASE.multiply(a(h))}_setWindowSize(h){b.setWindowSize(this,h)}assertValidity(){u(this)}hasEvenY(){let{y:h}=this.toAffine();if(t.isOdd)return!t.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){c(h);let{px:m,py:v,pz:E}=this,{px:B,py:L,pz:U}=h,I=t.eql(t.mul(m,U),t.mul(B,E)),D=t.eql(t.mul(v,U),t.mul(L,E));return I&&D}negate(){return new l(this.px,t.neg(this.py),this.pz)}double(){let{a:h,b:m}=e,v=t.mul(m,wu),{px:E,py:B,pz:L}=this,U=t.ZERO,I=t.ZERO,D=t.ZERO,x=t.mul(E,E),T=t.mul(B,B),V=t.mul(L,L),C=t.mul(E,B);return C=t.add(C,C),D=t.mul(E,L),D=t.add(D,D),U=t.mul(h,D),I=t.mul(v,V),I=t.add(U,I),U=t.sub(T,I),I=t.add(T,I),I=t.mul(U,I),U=t.mul(C,U),D=t.mul(v,D),V=t.mul(h,V),C=t.sub(x,V),C=t.mul(h,C),C=t.add(C,D),D=t.add(x,x),x=t.add(D,x),x=t.add(x,V),x=t.mul(x,C),I=t.add(I,x),V=t.mul(B,L),V=t.add(V,V),x=t.mul(V,C),U=t.sub(U,x),D=t.mul(V,T),D=t.add(D,D),D=t.add(D,D),new l(U,I,D)}add(h){c(h);let{px:m,py:v,pz:E}=this,{px:B,py:L,pz:U}=h,I=t.ZERO,D=t.ZERO,x=t.ZERO,T=e.a,V=t.mul(e.b,wu),C=t.mul(m,B),F=t.mul(v,L),K=t.mul(E,U),S=t.add(m,v),p=t.add(B,L);S=t.mul(S,p),p=t.add(C,F),S=t.sub(S,p),p=t.add(m,E);let d=t.add(B,U);return p=t.mul(p,d),d=t.add(C,K),p=t.sub(p,d),d=t.add(v,E),I=t.add(L,U),d=t.mul(d,I),I=t.add(F,K),d=t.sub(d,I),x=t.mul(T,p),I=t.mul(V,K),x=t.add(I,x),I=t.sub(F,x),x=t.add(F,x),D=t.mul(I,x),F=t.add(C,C),F=t.add(F,C),K=t.mul(T,K),p=t.mul(V,p),F=t.add(F,K),K=t.sub(C,K),K=t.mul(T,K),p=t.add(p,K),C=t.mul(F,p),D=t.add(D,C),C=t.mul(d,p),I=t.mul(S,I),I=t.sub(I,C),C=t.mul(S,F),x=t.mul(d,x),x=t.add(x,C),new l(I,D,x)}subtract(h){return this.add(h.negate())}is0(){return this.equals(l.ZERO)}wNAF(h){return b.wNAFCached(this,h,l.normalizeZ)}multiplyUnsafe(h){Te("scalar",h,Zt,e.n);let m=l.ZERO;if(h===Zt)return m;if(h===pe)return this;let{endo:v}=e;if(!v)return b.unsafeLadder(this,h);let{k1neg:E,k1:B,k2neg:L,k2:U}=v.splitScalar(h),I=m,D=m,x=this;for(;B>Zt||U>Zt;)B&pe&&(I=I.add(x)),U&pe&&(D=D.add(x)),x=x.double(),B>>=pe,U>>=pe;return E&&(I=I.negate()),L&&(D=D.negate()),D=new l(t.mul(D.px,v.beta),D.py,D.pz),I.add(D)}multiply(h){let{endo:m,n:v}=e;Te("scalar",h,pe,v);let E,B;if(m){let{k1neg:L,k1:U,k2neg:I,k2:D}=m.splitScalar(h),{p:x,f:T}=this.wNAF(U),{p:V,f:C}=this.wNAF(D);x=b.constTimeNegate(L,x),V=b.constTimeNegate(I,V),V=new l(t.mul(V.px,m.beta),V.py,V.pz),E=x.add(V),B=T.add(C)}else{let{p:L,f:U}=this.wNAF(h);E=L,B=U}return l.normalizeZ([E,B])[0]}multiplyAndAddUnsafe(h,m,v){let E=l.BASE,B=(U,I)=>I===Zt||I===pe||!U.equals(E)?U.multiplyUnsafe(I):U.multiply(I),L=B(this,m).add(B(h,v));return L.is0()?void 0:L}toAffine(h){return f(this,h)}isTorsionFree(){let{h,isTorsionFree:m}=e;if(h===pe)return!0;if(m)return m(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:m}=e;return h===pe?this:m?m(l,this):this.multiplyUnsafe(e.h)}toRawBytes(h=!0){return je("isCompressed",h),this.assertValidity(),n(l,this,h)}toHex(h=!0){return je("isCompressed",h),dt(this.toRawBytes(h))}}l.BASE=new l(e.Gx,e.Gy,t.ONE),l.ZERO=new l(t.ZERO,t.ONE,t.ZERO);let g=e.nBitLength,b=Jn(l,e.endo?Math.ceil(g/2):g);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:a,weierstrassEquation:i,isWithinCurveOrder:s}}function j0(r){let e=on(r);return nt(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function xu(r){let e=j0(r),{Fp:t,n}=e,o=t.BYTES+1,i=2*t.BYTES+1;function s(S){return J(S,n)}function a(S){return Zn(S,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:l}=G0({...e,toBytes(S,p,d){let A=p.toAffine(),k=t.toBytes(A.x),O=gt;return je("isCompressed",d),d?O(Uint8Array.from([p.hasEvenY()?2:3]),k):O(Uint8Array.from([4]),k,t.toBytes(A.y))},fromBytes(S){let p=S.length,d=S[0],A=S.subarray(1);if(p===o&&(d===2||d===3)){let k=pt(A);if(!rn(k,pe,t.ORDER))throw new Error("Point is not on curve");let O=u(k),P;try{P=t.sqrt(O)}catch(z){let W=z instanceof Error?": "+z.message:"";throw new Error("Point is not on curve"+W)}let $=(P&pe)===pe;return(d&1)===1!==$&&(P=t.neg(P)),{x:k,y:P}}else if(p===i&&d===4){let k=t.fromBytes(A.subarray(0,t.BYTES)),O=t.fromBytes(A.subarray(t.BYTES,2*t.BYTES));return{x:k,y:O}}else throw new Error(`Point of length ${p} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}}),g=S=>dt(Ot(S,e.nByteLength));function b(S){let p=n>>pe;return S>p}function w(S){return b(S)?s(-S):S}let h=(S,p,d)=>pt(S.slice(p,d));class m{constructor(p,d,A){this.r=p,this.s=d,this.recovery=A,this.assertValidity()}static fromCompact(p){let d=e.nByteLength;return p=ie("compactSignature",p,d*2),new m(h(p,0,d),h(p,d,2*d))}static fromDER(p){let{r:d,s:A}=fr.toSig(ie("DER",p));return new m(d,A)}assertValidity(){Te("r",this.r,pe,n),Te("s",this.s,pe,n)}addRecoveryBit(p){return new m(this.r,this.s,p)}recoverPublicKey(p){let{r:d,s:A,recovery:k}=this,O=I(ie("msgHash",p));if(k==null||![0,1,2,3].includes(k))throw new Error("recovery id invalid");let P=k===2||k===3?d+e.n:d;if(P>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let $=k&1?"03":"02",Z=c.fromHex($+g(P)),z=a(P),W=s(-O*z),re=s(A*z),ne=c.BASE.multiplyAndAddUnsafe(Z,W,re);if(!ne)throw new Error("point at infinify");return ne.assertValidity(),ne}hasHighS(){return b(this.s)}normalizeS(){return this.hasHighS()?new m(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return rr(this.toDERHex())}toDERHex(){return fr.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return rr(this.toCompactHex())}toCompactHex(){return g(this.r)+g(this.s)}}let v={isValidPrivateKey(S){try{return f(S),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let S=ns(e.n);return Xa(e.randomBytes(S),e.n)},precompute(S=8,p=c.BASE){return p._setWindowSize(S),p.multiply(BigInt(3)),p}};function E(S,p=!0){return c.fromPrivateKey(S).toRawBytes(p)}function B(S){let p=Lt(S),d=typeof S=="string",A=(p||d)&&S.length;return p?A===o||A===i:d?A===2*o||A===2*i:S instanceof c}function L(S,p,d=!0){if(B(S))throw new Error("first arg must be private key");if(!B(p))throw new Error("second arg must be public key");return c.fromHex(p).multiply(f(S)).toRawBytes(d)}let U=e.bits2int||function(S){let p=pt(S),d=S.length*8-e.nBitLength;return d>0?p>>BigInt(d):p},I=e.bits2int_modN||function(S){return s(U(S))},D=nn(e.nBitLength);function x(S){return Te(`num < 2^${e.nBitLength}`,S,Zt,D),Ot(S,e.nByteLength)}function T(S,p,d=V){if(["recovered","canonical"].some(le=>le in d))throw new Error("sign() legacy options not supported");let{hash:A,randomBytes:k}=e,{lowS:O,prehash:P,extraEntropy:$}=d;O==null&&(O=!0),S=ie("msgHash",S),yu(d),P&&(S=ie("prehashed msgHash",A(S)));let Z=I(S),z=f(p),W=[x(z),x(Z)];if($!=null&&$!==!1){let le=$===!0?k(t.BYTES):$;W.push(ie("extraEntropy",le))}let re=gt(...W),ne=Z;function Ie(le){let ae=U(le);if(!l(ae))return;let $e=a(ae),fe=c.BASE.multiply(ae).toAffine(),qe=s(fe.x);if(qe===Zt)return;let Xt=s($e*s(ne+qe*z));if(Xt===Zt)return;let Yr=(fe.x===qe?0:2)|Number(fe.y&pe),Un=Xt;return O&&b(Xt)&&(Un=w(Xt),Yr^=1),new m(qe,Un,Yr)}return{seed:re,k2sig:Ie}}let V={lowS:e.lowS,prehash:!1},C={lowS:e.lowS,prehash:!1};function F(S,p,d=V){let{seed:A,k2sig:k}=T(S,p,d),O=e;return Qi(O.hash.outputLen,O.nByteLength,O.hmac)(A,k)}c.BASE._setWindowSize(8);function K(S,p,d,A=C){let k=S;if(p=ie("msgHash",p),d=ie("publicKey",d),"strict"in A)throw new Error("options.strict was renamed to lowS");yu(A);let{lowS:O,prehash:P}=A,$,Z;try{if(typeof k=="string"||Lt(k))try{$=m.fromDER(k)}catch(fe){if(!(fe instanceof fr.Err))throw fe;$=m.fromCompact(k)}else if(typeof k=="object"&&typeof k.r=="bigint"&&typeof k.s=="bigint"){let{r:fe,s:qe}=k;$=new m(fe,qe)}else throw new Error("PARSE");Z=c.fromHex(d)}catch(fe){if(fe.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(O&&$.hasHighS())return!1;P&&(p=e.hash(p));let{r:z,s:W}=$,re=I(p),ne=a(W),Ie=s(re*ne),le=s(z*ne),ae=c.BASE.multiplyAndAddUnsafe(Z,Ie,le)?.toAffine();return ae?s(ae.x)===z:!1}return{CURVE:e,getPublicKey:E,getSharedSecret:L,sign:F,verify:K,ProjectivePoint:c,Signature:m,utils:v}}function Y0(r){return{hash:r,hmac:(e,...t)=>fn(r,e,Gi(...t)),randomBytes:Ir}}function bu(r,e){let t=n=>xu({...r,...Y0(n)});return Object.freeze({...t(e),create:t})}var Bu=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Eu=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Z0=BigInt(1),_s=BigInt(2),vu=(r,e)=>(r+e/_s)/e;function W0(r){let e=Bu,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%e,u=f*f*r%e,l=ee(u,t,e)*u%e,g=ee(l,t,e)*u%e,b=ee(g,_s,e)*f%e,w=ee(b,o,e)*b%e,h=ee(w,i,e)*w%e,m=ee(h,a,e)*h%e,v=ee(m,c,e)*m%e,E=ee(v,a,e)*h%e,B=ee(E,t,e)*u%e,L=ee(B,s,e)*w%e,U=ee(L,n,e)*f%e,I=ee(U,_s,e);if(!Us.eql(Us.sqr(I),r))throw new Error("Cannot find square root");return I}var Us=Wn(Bu,void 0,void 0,{sqrt:W0}),Xe=bu({a:BigInt(0),b:BigInt(7),Fp:Us,n:Eu,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=Eu,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Z0*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=vu(i*r,e),c=vu(-n*r,e),f=J(r-a*t-c*o,e),u=J(-a*n-c*i,e),l=f>s,g=u>s;if(l&&(f=e-f),g&&(u=e-u),f>s||u>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:g,k2:u}}}},mu),Gw=BigInt(0);var jw=Xe.ProjectivePoint;function Au(){return Xe.utils.randomPrivateKey()}function Su(r,e){let t=ye.digest(e instanceof Uint8Array?e:e.subarray());if(Pe(t))return t.then(({digest:n})=>Xe.sign(n,r).toDERRawBytes()).catch(n=>{throw new H(String(n),"ERR_INVALID_INPUT")});try{return Xe.sign(t.digest,r).toDERRawBytes()}catch(n){throw new H(String(n),"ERR_INVALID_INPUT")}}function Ru(r,e,t){let n=ye.digest(t instanceof Uint8Array?t:t.subarray());if(Pe(n))return n.then(({digest:o})=>Xe.verify(e,o,r)).catch(o=>{throw new H(String(o),"ERR_INVALID_INPUT")});try{return Xe.verify(e,n.digest,r)}catch(o){throw new H(String(o),"ERR_INVALID_INPUT")}}function ku(r){return Xe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Iu(r){try{Xe.getPublicKey(r,!0)}catch(e){throw new H(String(e),"ERR_INVALID_PRIVATE_KEY")}}function Ds(r){try{Xe.ProjectivePoint.fromHex(r)}catch(e){throw new H(String(e),"ERR_INVALID_PUBLIC_KEY")}}function Tu(r){try{return Xe.getPublicKey(r,!0)}catch(e){throw new H(String(e),"ERR_INVALID_PRIVATE_KEY")}}var Bn=class{_key;constructor(e){Ds(e),this._key=e}verify(e,t){return Ru(this._key,t,e)}marshal(){return ku(this._key)}get bytes(){return ot.encode({Type:te.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}async hash(){let e=ye.digest(this.bytes),t;return Pe(e)?{bytes:t}=await e:t=e.bytes,t}},An=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??Tu(e),Iu(this._key),Ds(this._publicKey)}sign(e){return Su(this._key,e)}get public(){return new Bn(this._publicKey)}marshal(){return this._key}get bytes(){return it.encode({Type:te.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=ye.digest(this.bytes);return Pe(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return X(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return Ur(this.bytes,e);throw new H(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function X0(r){return new An(r)}function Q0(r){return new Bn(r)}async function ep(){let r=Au();return new An(r)}var hr={rsa:Cs,ed25519:bs,secp256k1:Ls};function Cu(r){let e=Object.keys(hr).join(" / ");return new H(`invalid or unsupported key type ${r}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function Vs(r){let e=ot.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case te.RSA:return hr.rsa.unmarshalRsaPublicKey(t);case te.Ed25519:return hr.ed25519.unmarshalEd25519PublicKey(t);case te.Secp256k1:return hr.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw Cu(e.Type??"unknown")}}async function Nu(r){let e=it.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case te.RSA:return hr.rsa.unmarshalRsaPrivateKey(t);case te.Ed25519:return hr.ed25519.unmarshalEd25519PrivateKey(t);case te.Secp256k1:return hr.secp256k1.unmarshalSecp256k1PrivateKey(t);default:throw Cu(e.Type??"RSA")}}var Js=It(Zo(),1);var Bt="/",Du=new TextEncoder().encode(Bt),Wo=Du[0],Hr=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=j(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Wo)throw new Error("Invalid key")}toString(e="utf8"){return X(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(Bt))}static random(){return new r(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new r(e):typeof e.uint8Array=="function"?new r(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Du),this._buf[0]!==Wo){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Wo,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Wo;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let o=0;o<t.length;o++){if(n.length<o+1)return!1;let i=t[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(Bt).slice(1)}type(){return rp(this.baseNamespace())}name(){return np(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Bt)||(e+=Bt),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Bt):new r(e.slice(0,-1).join(Bt))}child(e){return this.toString()===Bt?e:e.toString()===Bt?this:new r(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return r.withNamespaces([...this.namespaces(),...op(e.map(t=>t.namespaces()))])}};function rp(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function np(r){let e=r.split(":");return e[e.length-1]}function op(r){return[].concat(...r)}var ef=It(Jo(),1);var Lu="ERR_IPNS_EXPIRED_RECORD",Sn="ERR_UNRECOGNIZED_VALIDITY",Vu="ERR_SIGNATURE_CREATION",At="ERR_SIGNATURE_VERIFICATION";var Fs="ERR_UNDEFINED_PARAMETER",Ou="ERR_INVALID_RECORD_DATA",Fu="ERR_INVALID_VALUE",Pu="ERR_INVALID_EMBEDDED_KEY",Mu="ERR_MISSING_PRIVATE_KEY",Hu="ERR_RECORD_TOO_LARGE";var xe;(function(r){let e;(function(o){o.EOL="EOL"})(e=r.ValidityType||(r.ValidityType={}));let t;(function(o){o[o.EOL=0]="EOL"})(t||(t={})),function(o){o.codec=()=>un(t)}(e=r.ValidityType||(r.ValidityType={}));let n;r.codec=()=>(n==null&&(n=Kt((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.value!=null&&(i.uint32(10),i.bytes(o.value)),o.signatureV1!=null&&(i.uint32(18),i.bytes(o.signatureV1)),o.validityType!=null&&(i.uint32(24),r.ValidityType.codec().encode(o.validityType,i)),o.validity!=null&&(i.uint32(34),i.bytes(o.validity)),o.sequence!=null&&(i.uint32(40),i.uint64(o.sequence)),o.ttl!=null&&(i.uint32(48),i.uint64(o.ttl)),o.pubKey!=null&&(i.uint32(58),i.bytes(o.pubKey)),o.signatureV2!=null&&(i.uint32(66),i.bytes(o.signatureV2)),o.data!=null&&(i.uint32(74),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:s.value=o.bytes();break;case 2:s.signatureV1=o.bytes();break;case 3:s.validityType=r.ValidityType.codec().decode(o);break;case 4:s.validity=o.bytes();break;case 5:s.sequence=o.uint64();break;case 6:s.ttl=o.uint64();break;case 7:s.pubKey=o.bytes();break;case 8:s.signatureV2=o.bytes();break;case 9:s.data=o.bytes();break;default:o.skipType(c&7);break}}return s})),n),r.encode=o=>Ht(o,r.codec()),r.decode=o=>Mt(o,r.codec())})(xe||(xe={}));var ip=["string","number","bigint","symbol"],sp=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Ku(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(ip.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(ap(r))return"Buffer";let t=cp(r);return t||"Object"}function ap(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function cp(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(sp.includes(e))return e}var y=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};y.uint=new y(0,"uint",!0);y.negint=new y(1,"negint",!0);y.bytes=new y(2,"bytes",!0);y.string=new y(3,"string",!0);y.array=new y(4,"array",!1);y.map=new y(5,"map",!1);y.tag=new y(6,"tag",!1);y.float=new y(7,"float",!0);y.false=new y(7,"false",!0);y.true=new y(7,"true",!0);y.null=new y(7,"null",!0);y.undefined=new y(7,"undefined",!0);y.break=new y(7,"break",!0);var _=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Kr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",up=new TextDecoder,lp=new TextEncoder;function Xo(r){return Kr&&globalThis.Buffer.isBuffer(r)}function Ms(r){return r instanceof Uint8Array?Xo(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var Gu=Kr?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):qu(r,e,t):(r,e,t)=>t-e>64?up.decode(r.subarray(e,t)):qu(r,e,t),ju=Kr?r=>r.length>64?globalThis.Buffer.from(r):$u(r):r=>r.length>64?lp.encode(r):$u(r),ut=r=>Uint8Array.from(r),$r=Kr?(r,e,t)=>Xo(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),Yu=Kr?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),Ms(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let o of r)n+o.length>t.length&&(o=o.subarray(0,t.length-n)),t.set(o,n),n+=o.length;return t},Zu=Kr?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function Wu(r,e){if(Xo(r)&&Xo(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function $u(r){let e=[],t=0;for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(r.charCodeAt(++n)&1023),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 e}function qu(r,e,t){let n=[];for(;e<t;){let o=r[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=t){let a,c,f,u;switch(s){case 1:o<128&&(i=o);break;case 2:a=r[e+1],(a&192)===128&&(u=(o&31)<<6|a&63,u>127&&(i=u));break;case 3:a=r[e+1],c=r[e+2],(a&192)===128&&(c&192)===128&&(u=(o&15)<<12|(a&63)<<6|c&63,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:a=r[e+1],c=r[e+2],f=r[e+3],(a&192)===128&&(c&192)===128&&(f&192)===128&&(u=(o&15)<<18|(a&63)<<12|(c&63)<<6|f&63,u>65535&&u<1114112&&(i=u))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return fp(n)}var zu=4096;function fp(r){let e=r.length;if(e<=zu)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=zu));return t}var hp=256,Rn=class{constructor(e=hp){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=t.length-(this.maxCursor-this.cursor)-1;t.set(e,o)}else{if(t){let o=t.length-(this.maxCursor-this.cursor)-1;o<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=Zu(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=$r(n,0,this.cursor)}else t=Yu(this.chunks,this.cursor);return e&&this.reset(),t}};var M="CBOR decode error:",Hs="CBOR encode error:",kn=[];kn[23]=1;kn[24]=2;kn[25]=3;kn[26]=5;kn[27]=9;function St(r,e,t){if(r.length-e<t)throw new Error(`${M} not enough data for type`)}var ge=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Le(r,e,t){St(r,e,1);let n=r[e];if(t.strict===!0&&n<ge[0])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);return n}function Ve(r,e,t){St(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<ge[1])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);return n}function Oe(r,e,t){St(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<ge[2])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);return n}function Fe(r,e,t){St(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],o=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(t.strict===!0&&i<ge[3])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(t.allowBigInt===!0)return i;throw new Error(`${M} integers outside of the safe integer range are not supported`)}function Ju(r,e,t,n){return new _(y.uint,Le(r,e+1,n),2)}function Xu(r,e,t,n){return new _(y.uint,Ve(r,e+1,n),3)}function Qu(r,e,t,n){return new _(y.uint,Oe(r,e+1,n),5)}function el(r,e,t,n){return new _(y.uint,Fe(r,e+1,n),9)}function He(r,e){return be(r,0,e.value)}function be(r,e,t){if(t<ge[0]){let n=Number(t);r.push([e|n])}else if(t<ge[1]){let n=Number(t);r.push([e|24,n])}else if(t<ge[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<ge[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<ge[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,r.push(o)}else throw new Error(`${M} encountered BigInt larger than allowable range`)}}He.encodedSize=function(e){return be.encodedSize(e.value)};be.encodedSize=function(e){return e<ge[0]?1:e<ge[1]?2:e<ge[2]?3:e<ge[3]?5:9};He.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function tl(r,e,t,n){return new _(y.negint,-1-Le(r,e+1,n),2)}function rl(r,e,t,n){return new _(y.negint,-1-Ve(r,e+1,n),3)}function nl(r,e,t,n){return new _(y.negint,-1-Oe(r,e+1,n),5)}var Ks=BigInt(-1),ol=BigInt(1);function il(r,e,t,n){let o=Fe(r,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new _(y.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${M} integers outside of the safe integer range are not supported`);return new _(y.negint,Ks-BigInt(o),9)}function Qo(r,e){let t=e.value,n=typeof t=="bigint"?t*Ks-ol:t*-1-1;be(r,e.type.majorEncoded,n)}Qo.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*Ks-ol:t*-1-1;return n<ge[0]?1:n<ge[1]?2:n<ge[2]?3:n<ge[3]?5:9};Qo.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function In(r,e,t,n){St(r,e,t+n);let o=$r(r,e+t,e+t+n);return new _(y.bytes,o,t+n)}function sl(r,e,t,n){return In(r,e,1,t)}function al(r,e,t,n){return In(r,e,2,Le(r,e+1,n))}function cl(r,e,t,n){return In(r,e,3,Ve(r,e+1,n))}function ul(r,e,t,n){return In(r,e,5,Oe(r,e+1,n))}function ll(r,e,t,n){let o=Fe(r,e+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer bytes lengths not supported`);return In(r,e,9,o)}function ei(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===y.string?ju(r.value):r.value),r.encodedBytes}function qr(r,e){let t=ei(e);be(r,e.type.majorEncoded,t.length),r.push(t)}qr.encodedSize=function(e){let t=ei(e);return be.encodedSize(t.length)+t.length};qr.compareTokens=function(e,t){return pp(ei(e),ei(t))};function pp(r,e){return r.length<e.length?-1:r.length>e.length?1:Wu(r,e)}function Tn(r,e,t,n,o){let i=t+n;St(r,e,i);let s=new _(y.string,Gu(r,e+t,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=$r(r,e+t,e+i)),s}function fl(r,e,t,n){return Tn(r,e,1,t,n)}function hl(r,e,t,n){return Tn(r,e,2,Le(r,e+1,n),n)}function dl(r,e,t,n){return Tn(r,e,3,Ve(r,e+1,n),n)}function pl(r,e,t,n){return Tn(r,e,5,Oe(r,e+1,n),n)}function gl(r,e,t,n){let o=Fe(r,e+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer string lengths not supported`);return Tn(r,e,9,o,n)}var ml=qr;function zr(r,e,t,n){return new _(y.array,n,t)}function yl(r,e,t,n){return zr(r,e,1,t)}function wl(r,e,t,n){return zr(r,e,2,Le(r,e+1,n))}function xl(r,e,t,n){return zr(r,e,3,Ve(r,e+1,n))}function bl(r,e,t,n){return zr(r,e,5,Oe(r,e+1,n))}function El(r,e,t,n){let o=Fe(r,e+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer array lengths not supported`);return zr(r,e,9,o)}function vl(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${M} indefinite length items not allowed`);return zr(r,e,1,1/0)}function ti(r,e){be(r,y.array.majorEncoded,e.value)}ti.compareTokens=He.compareTokens;ti.encodedSize=function(e){return be.encodedSize(e.value)};function Gr(r,e,t,n){return new _(y.map,n,t)}function Bl(r,e,t,n){return Gr(r,e,1,t)}function Al(r,e,t,n){return Gr(r,e,2,Le(r,e+1,n))}function Sl(r,e,t,n){return Gr(r,e,3,Ve(r,e+1,n))}function Rl(r,e,t,n){return Gr(r,e,5,Oe(r,e+1,n))}function kl(r,e,t,n){let o=Fe(r,e+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer map lengths not supported`);return Gr(r,e,9,o)}function Il(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${M} indefinite length items not allowed`);return Gr(r,e,1,1/0)}function ri(r,e){be(r,y.map.majorEncoded,e.value)}ri.compareTokens=He.compareTokens;ri.encodedSize=function(e){return be.encodedSize(e.value)};function Tl(r,e,t,n){return new _(y.tag,t,1)}function Cl(r,e,t,n){return new _(y.tag,Le(r,e+1,n),2)}function Nl(r,e,t,n){return new _(y.tag,Ve(r,e+1,n),3)}function _l(r,e,t,n){return new _(y.tag,Oe(r,e+1,n),5)}function Ul(r,e,t,n){return new _(y.tag,Fe(r,e+1,n),9)}function ni(r,e){be(r,y.tag.majorEncoded,e.value)}ni.compareTokens=He.compareTokens;ni.encodedSize=function(e){return be.encodedSize(e.value)};var bp=20,Ep=21,vp=22,Bp=23;function Dl(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${M} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new _(y.null,null,1):new _(y.undefined,void 0,1)}function Ll(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${M} indefinite length items not allowed`);return new _(y.break,void 0,1)}function $s(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${M} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${M} Infinity values are not supported`)}return new _(y.float,r,e)}function Vl(r,e,t,n){return $s(qs(r,e+1),3,n)}function Ol(r,e,t,n){return $s(zs(r,e+1),5,n)}function Fl(r,e,t,n){return $s(Kl(r,e+1),9,n)}function oi(r,e,t){let n=e.value;if(n===!1)r.push([y.float.majorEncoded|bp]);else if(n===!0)r.push([y.float.majorEncoded|Ep]);else if(n===null)r.push([y.float.majorEncoded|vp]);else if(n===void 0)r.push([y.float.majorEncoded|Bp]);else{let o,i=!1;(!t||t.float64!==!0)&&(Ml(n),o=qs(Qe,1),n===o||Number.isNaN(n)?(Qe[0]=249,r.push(Qe.slice(0,3)),i=!0):(Hl(n),o=zs(Qe,1),n===o&&(Qe[0]=250,r.push(Qe.slice(0,5)),i=!0))),i||(Ap(n),o=Kl(Qe,1),Qe[0]=251,r.push(Qe.slice(0,9)))}}oi.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){Ml(n);let o=qs(Qe,1);if(n===o||Number.isNaN(n))return 3;if(Hl(n),o=zs(Qe,1),n===o)return 5}return 9};var Pl=new ArrayBuffer(9),Ke=new DataView(Pl,1),Qe=new Uint8Array(Pl,0);function Ml(r){if(r===1/0)Ke.setUint16(0,31744,!1);else if(r===-1/0)Ke.setUint16(0,64512,!1);else if(Number.isNaN(r))Ke.setUint16(0,32256,!1);else{Ke.setFloat32(0,r);let e=Ke.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)Ke.setUint16(0,31744,!1);else if(t===0)Ke.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=t-127;o<-24?Ke.setUint16(0,0):o<-14?Ke.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):Ke.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function qs(r,e){if(r.length-e<2)throw new Error(`${M} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,o=t&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,t&32768?-i:i}function Hl(r){Ke.setFloat32(0,r,!1)}function zs(r,e){if(r.length-e<4)throw new Error(`${M} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function Ap(r){Ke.setFloat64(0,r,!1)}function Kl(r,e){if(r.length-e<8)throw new Error(`${M} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}oi.compareTokens=He.compareTokens;function Y(r,e,t){throw new Error(`${M} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function ii(r){return()=>{throw new Error(`${M} ${r}`)}}var R=[];for(let r=0;r<=23;r++)R[r]=Y;R[24]=Ju;R[25]=Xu;R[26]=Qu;R[27]=el;R[28]=Y;R[29]=Y;R[30]=Y;R[31]=Y;for(let r=32;r<=55;r++)R[r]=Y;R[56]=tl;R[57]=rl;R[58]=nl;R[59]=il;R[60]=Y;R[61]=Y;R[62]=Y;R[63]=Y;for(let r=64;r<=87;r++)R[r]=sl;R[88]=al;R[89]=cl;R[90]=ul;R[91]=ll;R[92]=Y;R[93]=Y;R[94]=Y;R[95]=ii("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)R[r]=fl;R[120]=hl;R[121]=dl;R[122]=pl;R[123]=gl;R[124]=Y;R[125]=Y;R[126]=Y;R[127]=ii("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)R[r]=yl;R[152]=wl;R[153]=xl;R[154]=bl;R[155]=El;R[156]=Y;R[157]=Y;R[158]=Y;R[159]=vl;for(let r=160;r<=183;r++)R[r]=Bl;R[184]=Al;R[185]=Sl;R[186]=Rl;R[187]=kl;R[188]=Y;R[189]=Y;R[190]=Y;R[191]=Il;for(let r=192;r<=215;r++)R[r]=Tl;R[216]=Cl;R[217]=Nl;R[218]=_l;R[219]=Ul;R[220]=Y;R[221]=Y;R[222]=Y;R[223]=Y;for(let r=224;r<=243;r++)R[r]=ii("simple values are not supported");R[244]=Y;R[245]=Y;R[246]=Y;R[247]=Dl;R[248]=ii("simple values are not supported");R[249]=Vl;R[250]=Ol;R[251]=Fl;R[252]=Y;R[253]=Y;R[254]=Y;R[255]=Ll;var et=[];for(let r=0;r<24;r++)et[r]=new _(y.uint,r,1);for(let r=-1;r>=-24;r--)et[31-r]=new _(y.negint,r,1);et[64]=new _(y.bytes,new Uint8Array(0),1);et[96]=new _(y.string,"",1);et[128]=new _(y.array,0,1);et[160]=new _(y.map,0,1);et[244]=new _(y.false,!1,1);et[245]=new _(y.true,!0,1);et[246]=new _(y.null,null,1);function $l(r){switch(r.type){case y.false:return ut([244]);case y.true:return ut([245]);case y.null:return ut([246]);case y.bytes:return r.value.length?void 0:ut([64]);case y.string:return r.value===""?ut([96]):void 0;case y.array:return r.value===0?ut([128]):void 0;case y.map:return r.value===0?ut([160]):void 0;case y.uint:return r.value<24?ut([Number(r.value)]):void 0;case y.negint:if(r.value>=-24)return ut([31-Number(r.value)])}}var Rp={float64:!1,mapSorter:Tp,quickEncodeToken:$l};function kp(){let r=[];return r[y.uint.major]=He,r[y.negint.major]=Qo,r[y.bytes.major]=qr,r[y.string.major]=ml,r[y.array.major]=ti,r[y.map.major]=ri,r[y.tag.major]=ni,r[y.float.major]=oi,r}var ql=kp(),Gs=new Rn,ai=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${Hs} object contains circular references`);return new r(t,e)}},Wt={null:new _(y.null,null),undefined:new _(y.undefined,void 0),true:new _(y.true,!0),false:new _(y.false,!1),emptyArray:new _(y.array,0),emptyMap:new _(y.map,0)},Jt={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new _(y.float,r):r>=0?new _(y.uint,r):new _(y.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new _(y.uint,r):new _(y.negint,r)},Uint8Array(r,e,t,n){return new _(y.bytes,r)},string(r,e,t,n){return new _(y.string,r)},boolean(r,e,t,n){return r?Wt.true:Wt.false},null(r,e,t,n){return Wt.null},undefined(r,e,t,n){return Wt.undefined},ArrayBuffer(r,e,t,n){return new _(y.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new _(y.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[Wt.emptyArray,new _(y.break)]:Wt.emptyArray;n=ai.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=si(s,t,n);return t.addBreakTokens?[new _(y.array,r.length),o,new _(y.break)]:[new _(y.array,r.length),o]},Object(r,e,t,n){let o=e!=="Object",i=o?r.keys():Object.keys(r),s=o?r.size:i.length;if(!s)return t.addBreakTokens===!0?[Wt.emptyMap,new _(y.break)]:Wt.emptyMap;n=ai.createCheck(n,r);let a=[],c=0;for(let f of i)a[c++]=[si(f,t,n),si(o?r.get(f):r[f],t,n)];return Ip(a,t),t.addBreakTokens?[new _(y.map,s),a,new _(y.break)]:[new _(y.map,s),a]}};Jt.Map=Jt.Object;Jt.Buffer=Jt.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Jt[`${r}Array`]=Jt.DataView;function si(r,e={},t){let n=Ku(r),o=e&&e.typeEncoders&&e.typeEncoders[n]||Jt[n];if(typeof o=="function"){let s=o(r,n,e,t);if(s!=null)return s}let i=Jt[n];if(!i)throw new Error(`${Hs} unsupported type: ${n}`);return i(r,n,e,t)}function Ip(r,e){e.mapSorter&&r.sort(e.mapSorter)}function Tp(r,e){let t=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(t.type!==n.type)return t.type.compare(n.type);let o=t.type.major,i=ql[o].compareTokens(t,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function zl(r,e,t,n){if(Array.isArray(e))for(let o of e)zl(r,o,t,n);else t[e.type.major](r,e,n)}function Cp(r,e,t){let n=si(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let o=t.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,t),a=new Rn(s);if(i(a,n,t),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Ms(a.chunks[0])}}return Gs.reset(),zl(Gs,n,e,t),Gs.toBytes(!0)}function js(r,e){return e=Object.assign({},Rp,e),Cp(r,ql,e)}var Np={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},ci=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=et[e];if(t===void 0){let n=R[e];if(!n)throw new Error(`${M} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;t=n(this.data,this._pos,o,this.options)}return this._pos+=t.encodedLength,t}},Cn=Symbol.for("DONE"),ui=Symbol.for("BREAK");function _p(r,e,t){let n=[];for(let o=0;o<r.value;o++){let i=jr(e,t);if(i===ui){if(r.value===1/0)break;throw new Error(`${M} got unexpected break to lengthed array`)}if(i===Cn)throw new Error(`${M} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function Up(r,e,t){let n=t.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<r.value;s++){let a=jr(e,t);if(a===ui){if(r.value===1/0)break;throw new Error(`${M} got unexpected break to lengthed map`)}if(a===Cn)throw new Error(`${M} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${M} non-string keys not supported (got ${typeof a})`);if(t.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${M} found repeat map key "${a}"`);let c=jr(e,t);if(c===Cn)throw new Error(`${M} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(a,c):o[a]=c}return n?i:o}function jr(r,e){if(r.done())return Cn;let t=r.next();if(t.type===y.break)return ui;if(t.type.terminal)return t.value;if(t.type===y.array)return _p(t,r,e);if(t.type===y.map)return Up(t,r,e);if(t.type===y.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=jr(r,e);return e.tags[t.value](n)}throw new Error(`${M} tag not supported (${t.value})`)}throw new Error("unsupported")}function Gl(r,e){if(!(r instanceof Uint8Array))throw new Error(`${M} data to decode must be a Uint8Array`);e=Object.assign({},Np,e);let t=e.tokenizer||new ci(r,e),n=jr(t,e);if(n===Cn)throw new Error(`${M} did not find any content to decode`);if(n===ui)throw new Error(`${M} got unexpected break`);return[n,r.subarray(t.pos())]}function Ys(r,e){let[t,n]=Gl(r,e);if(n.length>0)throw new Error(`${M} too many terminals, data makes no sense`);return t}var _e=It(Zo(),1);var jl=Nt("ipns:utils"),Yl=j("/ipns/"),Lp=114,Zl=async(r,e)=>{if(e==null||r==null){let n=new Error("one or more of the provided parameters are not defined");throw jl.error(n),(0,_e.default)(n,Fs)}let t;if(e.pubKey!=null){try{t=Vs(e.pubKey)}catch(o){throw jl.error(o),o}if(!(await Oa(e.pubKey)).equals(r))throw(0,_e.default)(new Error("Embedded public key did not match PeerID"),Pu)}else r.publicKey!=null&&(t=Vs(r.publicKey));if(t!=null)return t;throw(0,_e.default)(new Error("no public key is available"),Fs)},Wl=(r,e,t)=>{let n=j(e);return tr([r,t,n])},li=r=>{let e=j("ipns-signature:");return tr([e,r])},Zs=r=>"signatureV1"in r?xe.encode({value:j(r.value),signatureV1:r.signatureV1,validityType:r.validityType,validity:j(r.validity),sequence:r.sequence,ttl:r.ttl,pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data}):xe.encode({pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data});function lt(r){let e=xe.decode(r);if(e.sequence!=null&&(e.sequence=BigInt(e.sequence)),e.ttl!=null&&(e.ttl=BigInt(e.ttl)),e.signatureV2==null||e.data==null)throw(0,_e.default)(new Error("missing data or signatureV2"),At);let t=Ql(e.data),n=Ws(t.Value),o=X(t.Validity);if(e.value!=null&&e.signatureV1!=null)return Vp(e),{value:n,validityType:xe.ValidityType.EOL,validity:o,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV1:e.signatureV1,signatureV2:e.signatureV2,data:e.data};if(e.signatureV2!=null)return{value:n,validityType:xe.ValidityType.EOL,validity:o,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}var fi=r=>tr([Yl,r.toBytes()]),Jl=r=>zi(r.slice(Yl.length)),Xl=(r,e,t,n,o)=>{let i;if(e===xe.ValidityType.EOL)i=0;else throw(0,_e.default)(new Error("Unknown validity type"),Sn);return js({Value:r,Validity:t,ValidityType:i,Sequence:n,TTL:o})},Ql=r=>{let e=Ys(r);if(e.ValidityType===0)e.ValidityType=xe.ValidityType.EOL;else throw(0,_e.default)(new Error("Unknown validity type"),Sn);return Number.isInteger(e.Sequence)&&(e.Sequence=BigInt(e.Sequence)),Number.isInteger(e.TTL)&&(e.TTL=BigInt(e.TTL)),e},Ws=r=>{if(r!=null){if(fa(r))return`/ipns/${r.toCID().toString(Mn)}`;if(r instanceof Uint8Array){let n=X(r);n.startsWith("/")&&(r=n)}let e=r.toString().trim();if(e.startsWith("/")&&e.length>1)return e;let t=Ee.asCID(r);if(t!=null)return t.code===Lp?`/ipns/${t.toString(Mn)}`:`/ipfs/${t.toV1().toString()}`;try{return r instanceof Uint8Array?`/ipfs/${Ee.decode(r).toV1().toString()}`:`/ipfs/${Ee.parse(e).toV1().toString()}`}catch{}}throw(0,_e.default)(new Error("Value must be a valid content path starting with /"),Fu)},Vp=r=>{if(r.data==null)throw(0,_e.default)(new Error("Record data is missing"),Ou);let e=Ql(r.data);if(!ce(e.Value,r.value??new Uint8Array(0)))throw(0,_e.default)(new Error('Field "value" did not match between protobuf and CBOR'),At);if(!ce(e.Validity,r.validity??new Uint8Array(0)))throw(0,_e.default)(new Error('Field "validity" did not match between protobuf and CBOR'),At);if(e.ValidityType!==r.validityType)throw(0,_e.default)(new Error('Field "validityType" did not match between protobuf and CBOR'),At);if(e.Sequence!==r.sequence)throw(0,_e.default)(new Error('Field "sequence" did not match between protobuf and CBOR'),At);if(e.TTL!==r.ttl)throw(0,_e.default)(new Error('Field "ttl" did not match between protobuf and CBOR'),At)};var Op=Nt("ipns"),Fp=ze.code,tf=60*60*1e9,Pp="/ipns/",Ub=Pp.length,rf={v1Compatible:!0,ttlNs:tf};async function nf(r,e,t,n,o=rf){let i=new ef.default(Date.now()+Number(n)),s=xe.ValidityType.EOL,a=BigInt(o.ttlNs!=null?o.ttlNs:tf);return Mp(r,e,t,s,i.toString(),a,o)}var Mp=async(r,e,t,n,o,i,s=rf)=>{t=BigInt(t);let a=j(o),c=Ws(e),f=j(c);if(r.privateKey==null)throw(0,Js.default)(new Error("Missing private key"),Mu);let u=await Nu(r.privateKey),l=Xl(f,n,a,t,i),g=li(l),b=await u.sign(g),w;if(r.publicKey!=null){let h=Qt(r.toBytes());(h.code!==Fp||!ce(r.publicKey,h.digest))&&(w=r.publicKey)}if(s.v1Compatible===!0){let h=await Hp(u,f,n,a),m={value:c,signatureV1:h,validity:o,validityType:n,sequence:t,ttl:i,signatureV2:b,data:l};return w!=null&&(m.pubKey=w),m}else{let h={value:c,validity:o,validityType:n,sequence:t,ttl:i,signatureV2:b,data:l};return w!=null&&(h.pubKey=w),h}};var Hp=async(r,e,t,n)=>{try{let o=Wl(e,t,n);return await r.sign(o)}catch(o){throw Op.error("record signature creation failed",o),(0,Js.default)(new Error("record signature creation failed"),Vu)}};var Xs=It(Jo(),1);function hi(r,e){let t=e.map((n,o)=>({record:lt(n),index:o}));return t.sort((n,o)=>{let i=n.record.sequence,s=o.record.sequence;if(i>s)return-1;if(i<s)return 1;if(n.record.validityType===xe.ValidityType.EOL&&o.record.validityType===xe.ValidityType.EOL){let a=Xs.default.fromString(n.record.validity).toDate(),c=Xs.default.fromString(o.record.validity).toDate();if(a.getTime()>c.getTime())return-1;if(a.getTime()<c.getTime())return 1}return 0}),t[0].index}var Nn=It(Zo(),1),of=It(Jo(),1);var di=Nt("ipns:validator"),Kp=1024*10,$p=async(r,e)=>{let t=lt(e),n;try{let o=li(t.data);n=await r.verify(o,t.signatureV2)}catch{n=!1}if(!n)throw di.error("record signature verification failed"),(0,Nn.default)(new Error("record signature verification failed"),At);if(t.validityType===xe.ValidityType.EOL){if(of.default.fromString(t.validity).toDate().getTime()<Date.now())throw di.error("record has expired"),(0,Nn.default)(new Error("record has expired"),Lu)}else if(t.validityType!=null)throw di.error("unrecognized validity type"),(0,Nn.default)(new Error("unrecognized validity type"),Sn);di("ipns record for %s is valid",t.value)};async function pi(r,e){if(e.byteLength>Kp)throw(0,Nn.default)(new Error("record too large"),Hu);let t=Jl(r),n=lt(e),o=await Zl(t,n);await $p(o,e)}var ke=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Gp=It(af(),1);var Rt;(function(r){r[r.A=1]="A",r[r.CNAME=5]="CNAME",r[r.TXT=16]="TXT",r[r.AAAA=28]="AAAA"})(Rt||(Rt={}));var jp=32;async function cf(r,e,t,n,o={}){if(e===0)throw new Error("recursion limit exceeded");n("query %s for TXT and CNAME records",r);let s=(await t.query(r,{...o,types:[Rt.TXT]})).Answer.sort((f,u)=>f.data.localeCompare(u.data));n("found %d TXT records for %s",s.length,r);for(let f of s)try{let u=f.data;if(u.startsWith('"')&&u.endsWith('"')&&(u=u.substring(1,u.length-1)),!u.startsWith("dnslink="))continue;n("%s TXT %s",f.name,u),u=u.replace("dnslink=","");let[,l,g,...b]=u.split("/");if(l==="ipfs")try{return{value:`/ipfs/${Ee.parse(g)}${b.length>0?`/${b.join("/")}`:""}`,answer:f}}catch{}else if(l==="ipns"){try{return{value:`/ipns/${en(g)}${b.length>0?`/${b.join("/")}`:""}`,answer:f}}catch{}return await gi(g,e-1,t,n,o)}else{if(l==="dnslink")return await gi(g,e-1,t,n,o);n('unknown protocol "%s" in DNSLink record for domain: %s',l,r);continue}}catch(u){n.error("could not parse DNS link record for domain %s, %s",r,f.data,u)}n("no DNSLink records found for %s, falling back to CNAME",r);let c=(await t.query(r,{...o,types:[Rt.CNAME]})).Answer.sort((f,u)=>f.data.localeCompare(u.data));n("found %d CNAME records for %s",c.length,r);for(let f of c)try{return await gi(f.data,e-1,t,n,o)}catch(u){n.error("domain %s cname %s had no DNSLink records",r,f.data,u)}throw new H(`No DNSLink records found for domain: ${r}`,"ERR_DNSLINK_NOT_FOUND")}async function gi(r,e,t,n,o={}){if(e===0)throw new Error("recursion limit exceeded");r.startsWith("_dnslink.")||(r=`_dnslink.${r}`);try{return await cf(r,e,t,n,o)}catch(i){if(i.code!=="ENOTFOUND"&&i.code!=="ERR_DNSLINK_NOT_FOUND"&&i.code!=="ENODATA")throw i;return r.startsWith("_dnslink.")?r=r.replace("_dnslink.",""):r=`_dnslink.${r}`,cf(r,e,t,n,o)}}async function uf(r,e,t,n={}){return gi(r,n.maxRecursiveDepth??jp,e,t,n)}var Qs=class{routing;constructor(e){this.routing=e}async put(e,t,n={}){try{await this.routing.put(e,t,n)}catch(o){n.onProgress?.(new ke("ipns:routing:helia:error",o))}}async get(e,t={}){try{return await this.routing.get(e,t)}catch(n){t.onProgress?.(new ke("ipns:routing:helia:error",n))}throw new Error("Not found")}};function lf(r){return new Qs(r)}var _n;(function(r){let e;r.codec=()=>(e==null&&(e=Kt((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.key!=null&&t.key.byteLength>0&&(n.uint32(10),n.bytes(t.key)),t.value!=null&&t.value.byteLength>0&&(n.uint32(18),n.bytes(t.value)),t.timeReceived!=null&&t.timeReceived!==""&&(n.uint32(42),n.string(t.timeReceived)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={key:Pi(0),value:Pi(0),timeReceived:""},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.key=t.bytes();break}case 2:{i.value=t.bytes();break}case 5:{i.timeReceived=t.string();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Ht(t,r.codec()),r.decode=(t,n)=>Mt(t,r.codec(),n)})(_n||(_n={}));function ff(r){let e=r.getUTCFullYear(),t=String(r.getUTCMonth()+1).padStart(2,"0"),n=String(r.getUTCDate()).padStart(2,"0"),o=String(r.getUTCHours()).padStart(2,"0"),i=String(r.getUTCMinutes()).padStart(2,"0"),s=String(r.getUTCSeconds()).padStart(2,"0"),a=r.getUTCMilliseconds(),c=String(a*1e3*1e3).padStart(9,"0");return`${e}-${t}-${n}T${o}:${i}:${s}.${c}Z`}function hf(r){let e=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),t=String(r).trim().match(e);if(t==null)throw new Error("Invalid format");let n=parseInt(t[1],10),o=parseInt(t[2],10)-1,i=parseInt(t[3],10),s=parseInt(t[4],10),a=parseInt(t[5],10),c=parseInt(t[6],10),f=parseInt(t[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,c,f))}var pr=class r{key;value;timeReceived;constructor(e,t,n){if(!(e instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(t instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=e,this.value=t,this.timeReceived=n}serialize(){return _n.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:ff(this.timeReceived)}}static deserialize(e){let t=_n.decode(e);return new r(t.key,t.value,new Date(t.timeReceived))}static fromDeserialized(e){let t=hf(e.timeReceived);if(e.key==null)throw new Error("key missing from deserialized object");if(e.value==null)throw new Error("value missing from deserialized object");return new r(e.key,e.value,t)}};var df;(function(r){r[r.SEND_QUERY=0]="SEND_QUERY",r[r.PEER_RESPONSE=1]="PEER_RESPONSE",r[r.FINAL_PEER=2]="FINAL_PEER",r[r.QUERY_ERROR=3]="QUERY_ERROR",r[r.PROVIDER=4]="PROVIDER",r[r.VALUE=5]="VALUE",r[r.ADD_PEER=6]="ADD_PEER",r[r.DIAL_PEER=7]="DIAL_PEER"})(df||(df={}));function mi(r){return new Hr("/dht/record/"+X(r,"base32"),!1)}function pf(r){return{async put(e,t,n={}){try{let o=mi(e);try{let s=await r.get(o),a=pr.deserialize(s);if(ce(a.value,t))return}catch(s){if(s.code!=="ERR_NOT_FOUND")throw s}let i=new pr(e,t,new Date);n.onProgress?.(new ke("ipns:routing:datastore:put")),await r.put(o,i.serialize(),n)}catch(o){throw n.onProgress?.(new ke("ipns:routing:datastore:error",o)),o}},async get(e,t={}){try{let n=mi(e);t.onProgress?.(new ke("ipns:routing:datastore:get"));let o=await r.get(n,t),i=pr.deserialize(o);return{record:i.value,created:i.timeReceived}}catch(n){throw t.onProgress?.(new ke("ipns:routing:datastore:error",n)),n}},async has(e,t={}){let n=mi(e);return r.has(n,t)},async delete(e,t){let n=mi(e);return r.delete(n,t)}}}var kt=Nt("helia:ipns"),Zp=60*1e3,ra=60*Zp,Wp=24*ra,ea=23*ra,Jp=BigInt(ra)*1000000n,ta=class{routers;localStore;timeout;dns;log;constructor(e,t=[]){this.routers=[lf(e.routing),...t],this.localStore=pf(e.datastore),this.dns=e.dns,this.log=e.logger.forComponent("helia:ipns")}async publish(e,t,n={}){try{let o=1n,i=fi(e);if(await this.localStore.has(i,n)){let{record:c}=await this.localStore.get(i,n);o=lt(c).sequence+1n}let s=await nf(e,t,o,n.lifetime??Wp,n),a=Zs(s);return await this.localStore.put(i,a,n),n.offline!==!0&&await Promise.all(this.routers.map(async c=>{await c.put(i,a,n)})),s}catch(o){throw n.onProgress?.(new ke("ipns:publish:error",o)),o}}async resolve(e,t={}){let n=fi(e),o=await this.#t(n,t);return{...await this.#e(o.value,t),record:o}}async resolveDNSLink(e,t={}){let n=await uf(e,this.dns,this.log,t);return{...await this.#e(n.value,t),answer:n.answer}}republish(e={}){if(this.timeout!=null)throw new Error("Republish is already running");e.signal?.addEventListener("abort",()=>{clearTimeout(this.timeout)});async function t(){let n=Date.now();e.onProgress?.(new ke("ipns:republish:start"));let i=Date.now()-n,s=ea-i;s<0&&(s=e.interval??ea),setTimeout(()=>{t().catch(a=>{kt.error("error republishing",a)})},s)}this.timeout=setTimeout(()=>{t().catch(n=>{kt.error("error republishing",n)})},e.interval??ea)}async#e(e,t={}){let n=e.split("/");try{let o=n[1];if(o==="ipns"){let{cid:i}=await this.resolve(en(n[2]),t),s=n.slice(3).join("/");return{cid:i,path:s}}else if(o==="ipfs"){let i=Ee.parse(n[2]),s=n.slice(3).join("/");return{cid:i,path:s}}}catch(o){kt.error("error parsing ipfs path",o)}throw kt.error("invalid ipfs path %s",e),new Error("Invalid value")}async#t(e,t={}){let n=[];if(await this.localStore.has(e,t))if(kt("record is present in the cache"),t.nocache!==!0)try{let{record:a,created:c}=await this.localStore.get(e,t);this.log("record retrieved from cache"),await pi(e,a),this.log("record was valid");let f=lt(a),u=Number((f.ttl??Jp)/1000000n);if(c.getTime()+u>Date.now())return this.log("record TTL was valid"),f;if(t.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),f;this.log("record TTL has been reached, searching routing for updates"),n.push(a)}catch(a){this.log("cached record was invalid",a),await this.localStore.delete(e,t)}else kt("ignoring local cache due to nocache=true option");if(t.offline===!0)throw new H("Record was not present in the cache or has expired","ERR_NOT_FOUND");kt("did not have record locally");let i=0;if(await Promise.all(this.routers.map(async a=>{let c;try{c=await a.get(e,{...t,validate:!1})}catch(f){kt.error("error finding IPNS record",f);return}try{await pi(e,c),n.push(c)}catch(f){i++,kt.error("error finding IPNS record",f)}})),n.length===0)throw i>0?new H(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`,"ERR_RECORDS_FAILED_VALIDATION"):new H("Could not find record for routing key","ERR_NOT_FOUND");let s=n[hi(e,n)];return await this.localStore.put(e,s,t),lt(s)}};function Xp(r,{routers:e=[]}={}){return new ta(r,e)}return kf(Qp);})();
|
|
7
|
+
`)}`:`${t} :`}};Dc=Yt;U.Constructed=Dc;Yt.NAME="CONSTRUCTED";var yo=class extends Ae{fromBER(e,t,n){return t}toBER(e){return Je}};yo.override="EndOfContentValueBlock";var Vc,wo=class extends xe{constructor(e={}){super(e,yo),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Vc=wo;U.EndOfContent=Vc;wo.NAME=wn;var Oc,Zt=class extends xe{constructor(e={}){super(e,Ae),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}`}};Oc=Zt;U.Null=Oc;Zt.NAME="NULL";var xo=class extends Bt(Ae){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=j.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=j.BufferSourceConverter.toUint8Array(e);return vt(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,Rs.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};xo.NAME="BooleanValueBlock";var Fc,bo=class extends xe{constructor(e={}){super(e,xo),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}`}};Fc=bo;U.Boolean=Fc;bo.NAME="BOOLEAN";var Eo=class extends Bt(st){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=st.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let i=0;i<this.value.length;i++){let s=this.value[i].constructor.NAME;if(s===wn){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==Nc)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?st.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Eo.NAME="OctetStringValueBlock";var Mc,bt=class r extends xe{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Eo),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){let i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(i.byteLength){let s=Zo(i,0,i.byteLength);s.offset!==-1&&s.offset===n&&(this.valueBlock.value=[s.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?Yt.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${j.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 j.BufferSourceConverter.concat(e)}};Mc=bt;U.OctetString=Mc;bt.NAME=Nc;var vo=class extends Bt(st){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=st.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===wn){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==_c)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let f=a.valueBlock;if(this.unusedBits>0&&f.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=f.unusedBits}return o}let i=j.BufferSourceConverter.toUint8Array(e);if(!vt(this,i,t,n))return-1;let s=i.subarray(t,t+n);if(this.unusedBits=s[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=s.subarray(1);try{if(a.byteLength){let c=Zo(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=s.subarray(1),this.blockLength=s.length,t+n}toBER(e,t){if(this.isConstructed)return st.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Je;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}}};vo.NAME="BitStringValueBlock";var Pc,Pr=class extends xe{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},vo),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 Yt.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)}`}}};Pc=Pr;U.BitString=Pc;Pr.NAME=_c;var Hc;function I0(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,f=0,u=c<s?s:c,l=0;for(let h=u;h>=0;h--,l++){switch(!0){case l<a.length:f=i[s-l]+a[c-l]+t[0];break;default:f=i[s-l]+t[0]}switch(t[0]=f/10,!0){case l>=i.length:i=uo(new Uint8Array([f%10]),i);break;default:i[s-l]=f%10}}return t[0]>0&&(i=uo(t,i)),i}function Cc(r){if(r>=mn.length)for(let e=mn.length;e<=r;e++){let t=new Uint8Array([0]),n=mn[e-1].slice(0);for(let o=n.length-1;o>=0;o--){let i=new Uint8Array([(n[o]<<1)+t[0]]);t[0]=i[0]/10,n[o]=i[0]%10}t[0]>0&&(n=uo(t,n)),mn.push(n)}return mn[r]}function T0(r,e){let t=0,n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,f,u=0;for(let l=c;l>=0;l--,u++)switch(f=i[s-u]-a[c-u]-t,!0){case f<0:t=1,i[s-u]=f+10;break;default:t=0,i[s-u]=f}if(t>0)for(let l=s-c+1;l>=0;l--,u++)if(f=i[s-u]-t,f<0)t=1,i[s-u]=f+10;else{t=0,i[s-u]=f;break}return i.slice()}var xn=class extends Bt(Ae){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=Rs.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(kc(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,o=0){let i=this.fromBER(e,t,n);if(i===-1)return i;let s=this.valueHexView;return s[0]===0&&s[1]&128?this.valueHexView=s.subarray(1):o!==0&&s.length<o&&(o-s.length>1&&(o=s.length+1),this.valueHexView=s.subarray(o-s.length)),i}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let o=super.fromBER(e,t,n);return o===-1||this.setValueHex(),o}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,o,i=this.valueHexView,s="",a=!1;for(let c=i.byteLength-1;c>=0;c--){o=i[c];for(let f=0;f<8;f++){if((o&1)===1)switch(n){case e:t=T0(Cc(n),t),s="-";break;default:t=I0(t,Cc(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=Tc.charAt(t[c]));return a===!1&&(s+=Tc.charAt(0)),s}};Hc=xn;xn.NAME="IntegerValueBlock";Object.defineProperty(Hc.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Kc,se=class r extends xe{constructor(e={}){super(e,xn),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return lo(),BigInt(this.valueBlock.toString())}static fromBigInt(e){lo();let t=BigInt(e),n=new yn,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(j.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let f=BigInt(`0x${j.Convert.ToHex(a)}`)+t,u=j.BufferSourceConverter.toUint8Array(j.Convert.FromHex(f.toString(16)));u[0]|=128,n.write(u)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);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()}`}};Kc=se;U.Integer=Kc;se.NAME="INTEGER";var $c,Bo=class extends se{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};$c=Bo;U.Enumerated=$c;Bo.NAME="ENUMERATED";var bn=class extends Bt(Ae){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=j.BufferSourceConverter.toUint8Array(e);if(!vt(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,i[this.blockLength-1]&128?(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=pr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){lo();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let o=0;o<n.length;o++)n[o]=parseInt(t.slice(o*7,o*7+7),2)+(o+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=jt(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Je;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n}toString(){let e="";if(this.isHexOnly)e=j.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}}};bn.NAME="sidBlock";var Ao=class extends Ae{constructor({value:e=Hr,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new bn;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let o=this.value[n].toBER(e);if(o.byteLength===0)return this.error=this.value[n].error,Je;t.push(o)}return ks(t)}fromString(e){this.value=[];let t=0,n=0,o="",i=!1;do if(n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1,i){let s=this.value[0],a=0;switch(s.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(o,10);if(isNaN(c))return;s.valueDec=c+a,i=!1}else{let s=new bn;if(o>Number.MAX_SAFE_INTEGER){lo();let a=BigInt(o);s.valueBigInt=a}else if(s.valueDec=parseInt(o,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,i=!0),this.value.push(s)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t?(o=`{${o}}`,this.value[n].isFirstSid?e=`2.{${o} - 80}`:e+=o):e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Ao.NAME="ObjectIdentifierValueBlock";var qc,We=class extends xe{constructor(e={}){super(e,Ao),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()}}};qc=We;U.ObjectIdentifier=qc;We.NAME="OBJECT IDENTIFIER";var En=class extends Bt(xt){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=j.BufferSourceConverter.toUint8Array(e);if(!vt(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,i[this.blockLength-1]&128?(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=pr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=jt(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Je;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=j.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};En.NAME="relativeSidBlock";var So=class extends Ae{constructor({value:e=Hr,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new En;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e,t){let n=[];for(let o=0;o<this.value.length;o++){let i=this.value[o].toBER(e);if(i.byteLength===0)return this.error=this.value[o].error,Je;n.push(i)}return ks(n)}fromString(e){this.value=[];let t=0,n=0,o="";do{n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1;let i=new En;if(i.valueDec=parseInt(o,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(o=`{${o}}`),e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};So.NAME="RelativeObjectIdentifierValueBlock";var zc,Ro=class extends xe{constructor(e={}){super(e,So),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()}}};zc=Ro;U.RelativeObjectIdentifier=zc;Ro.NAME="RelativeObjectIdentifier";var Gc,de=class extends Yt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Gc=de;U.Sequence=Gc;de.NAME="SEQUENCE";var jc,ko=class extends Yt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};jc=ko;U.Set=jc;ko.NAME="SET";var Io=class extends Bt(Ae){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Hr}toJSON(){return{...super.toJSON(),value:this.value}}};Io.NAME="StringValueBlock";var To=class extends Io{};To.NAME="SimpleStringValueBlock";var Ie=class extends po{constructor({...e}={}){super(e,To)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,j.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 Co=class extends Ie{fromBuffer(e){this.valueBlock.valueHexView=j.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=j.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=j.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(j.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Co.NAME="Utf8StringValueBlock";var Yc,Et=class extends Co{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Yc=Et;U.Utf8String=Yc;Et.NAME="UTF8String";var No=class extends Ie{fromBuffer(e){this.valueBlock.value=j.Convert.ToUtf16String(e),this.valueBlock.valueHexView=j.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(j.Convert.FromUtf16String(e))}};No.NAME="BmpStringValueBlock";var Zc,_o=class extends No{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Zc=_o;U.BmpString=Zc;_o.NAME="BMPString";var Uo=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 i=jt(e.charCodeAt(o),8),s=new Uint8Array(i);if(s.length>4)continue;let a=4-s.length;for(let c=s.length-1;c>=0;c--)n[o*4+c+a]=s[c]}this.valueBlock.value=e}};Uo.NAME="UniversalStringValueBlock";var Wc,Lo=class extends Uo{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Wc=Lo;U.UniversalString=Wc;Lo.NAME="UniversalString";var Jc,Do=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Jc=Do;U.NumericString=Jc;Do.NAME="NumericString";var Xc,Vo=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Xc=Vo;U.PrintableString=Xc;Vo.NAME="PrintableString";var Qc,Oo=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Qc=Oo;U.TeletexString=Qc;Oo.NAME="TeletexString";var eu,Fo=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};eu=Fo;U.VideotexString=eu;Fo.NAME="VideotexString";var tu,Mo=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};tu=Mo;U.IA5String=tu;Mo.NAME="IA5String";var ru,Po=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};ru=Po;U.GraphicString=ru;Po.NAME="GraphicString";var nu,vn=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};nu=vn;U.VisibleString=nu;vn.NAME="VisibleString";var ou,Ho=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};ou=Ho;U.GeneralString=ou;Ho.NAME="GeneralString";var iu,Ko=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};iu=Ko;U.CharacterString=iu;Ko.NAME="CharacterString";var su,Bn=class extends vn{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,j.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}}};su=Bn;U.UTCTime=su;Bn.NAME="UTCTime";var au,$o=class extends Bn{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="",i=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let l=new Number(e[e.length-1]);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let l=1,h=n.indexOf("+"),E="";if(h===-1&&(h=n.indexOf("-"),l=-1),h!==-1){if(E=n.substring(h+1),n=n.substring(0,h),E.length!==2&&E.length!==4)throw new Error("Wrong input string for conversion");let B=parseInt(E.substring(0,2),10);if(isNaN(B.valueOf()))throw new Error("Wrong input string for conversion");if(a=l*B,E.length===4){if(B=parseInt(E.substring(2,4),10),isNaN(B.valueOf()))throw new Error("Wrong input string for conversion");c=l*B}}}let f=n.indexOf(".");if(f===-1&&(f=n.indexOf(",")),f!==-1){let l=new Number(`0${n.substring(f)}`);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");i=l.valueOf(),o=n.substring(0,f)}else o=n;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,f!==-1)throw new Error("Wrong input string for conversion");break;case o.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*i;this.minute=Math.floor(l),l=60*(l-this.minute),this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*i;this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=1e3*i;this.millisecond=Math.floor(l)}break;default:throw new Error("Wrong input string for conversion")}let u=s.exec(o);if(u===null)throw new Error("Wrong input string for conversion");for(let l=1;l<u.length;l++)switch(l){case 1:this.year=parseInt(u[l],10);break;case 2:this.month=parseInt(u[l],10);break;case 3:this.day=parseInt(u[l],10);break;case 4:this.hour=parseInt(u[l],10)+a;break;case 5:this.minute=parseInt(u[l],10)+c;break;case 6:this.second=parseInt(u[l],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let l=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=l.getUTCFullYear(),this.month=l.getUTCMonth(),this.day=l.getUTCDay(),this.hour=l.getUTCHours(),this.minute=l.getUTCMinutes(),this.second=l.getUTCSeconds(),this.millisecond=l.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(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}}};au=$o;U.GeneralizedTime=au;$o.NAME="GeneralizedTime";var cu,qo=class extends Et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};cu=qo;U.DATE=cu;qo.NAME="DATE";var uu,zo=class extends Et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};uu=zo;U.TimeOfDay=uu;zo.NAME="TimeOfDay";var lu,Go=class extends Et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};lu=Go;U.DateTime=lu;Go.NAME="DateTime";var fu,jo=class extends Et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};fu=jo;U.Duration=fu;jo.NAME="Duration";var hu,Yo=class extends Et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};hu=Yo;U.TIME=hu;Yo.NAME="TIME";function N0(r){let{result:e}=Kr(r),t=e.valueBlock.value;return{n:Q(at(t[1].toBigInt()),"base64url"),e:Q(at(t[2].toBigInt()),"base64url"),d:Q(at(t[3].toBigInt()),"base64url"),p:Q(at(t[4].toBigInt()),"base64url"),q:Q(at(t[5].toBigInt()),"base64url"),dp:Q(at(t[6].toBigInt()),"base64url"),dq:Q(at(t[7].toBigInt()),"base64url"),qi:Q(at(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function _0(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 K("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new de({value:[new se({value:0}),se.fromBigInt(ct(Z(r.n,"base64url"))),se.fromBigInt(ct(Z(r.e,"base64url"))),se.fromBigInt(ct(Z(r.d,"base64url"))),se.fromBigInt(ct(Z(r.p,"base64url"))),se.fromBigInt(ct(Z(r.q,"base64url"))),se.fromBigInt(ct(Z(r.dp,"base64url"))),se.fromBigInt(ct(Z(r.dq,"base64url"))),se.fromBigInt(ct(Z(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function U0(r){let{result:e}=Kr(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:Q(at(t[0].toBigInt()),"base64url"),e:Q(at(t[1].toBigInt()),"base64url")}}function L0(r){if(r.n==null||r.e==null)throw new K("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new de({value:[new de({value:[new We({value:"1.2.840.113549.1.1.1"}),new Zt]}),new Pr({valueHex:new de({value:[se.fromBigInt(ct(Z(r.n,"base64url"))),se.fromBigInt(ct(Z(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function at(r){let e=r.toString(16);e.length%2>0&&(e=`0${e}`);let t=e.length/2,n=new Uint8Array(t),o=0,i=0;for(;o<t;)n[o]=parseInt(e.slice(i,i+2),16),o+=1,i+=2;return n}function ct(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(""))}var D0=16,Ts=32,Cs=1e4;async function V0(r,e){let t=Re.get(),o=new de({value:[new se({value:0}),new de({value:[new We({value:"1.2.840.113549.1.1.1"}),new Zt]}),new bt({valueHex:r.marshal()})]}).toBER(),i=new Uint8Array(o,0,o.byteLength),s=dr(D0),a=await As(sn,e,s,{c:Cs,dkLen:Ts}),c=dr(16),f=await t.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),u=await t.subtle.encrypt({name:"AES-CBC",iv:c},f,i),l=new de({value:[new bt({valueHex:s}),new se({value:Cs}),new se({value:Ts}),new de({value:[new We({value:"1.2.840.113549.2.11"}),new Zt]})]}),h=new de({value:[new We({value:"1.2.840.113549.1.5.13"}),new de({value:[new de({value:[new We({value:"1.2.840.113549.1.5.12"}),l]}),new de({value:[new We({value:"2.16.840.1.101.3.4.1.42"}),new bt({valueHex:c})]})]})]}),B=new de({value:[h,new bt({valueHex:u})]}).toBER(),p=new Uint8Array(B,0,B.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...Q(p,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
|
|
8
|
+
`)}async function O0(r,e){let t=Re.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let o=Z(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=Kr(o),{iv:s,salt:a,iterations:c,keySize:f,cipherText:u}=F0(i),l=await As(sn,e,a,{c,dkLen:f}),h=await t.subtle.importKey("raw",l,"AES-CBC",!1,["decrypt"]),E=An(await t.subtle.decrypt({name:"AES-CBC",iv:s},h,u)),{result:B}=Kr(E);n=du(B)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let o=Z(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=Kr(o);n=du(i)}else throw new K("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return Ns(n)}function F0(r){let e=r.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new K("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=e.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new K("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let i=n.valueBlock.value[1],s=An(i.valueBlock.value[0].getValue()),a=Cs,c=Ts;if(i.valueBlock.value.length===3)a=Number(i.valueBlock.value[1].toBigInt()),c=Number(i.valueBlock.value[2].toBigInt());else if(i.valueBlock.value.length===2)throw new K("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let f=e.valueBlock.value[1].valueBlock.value[1],u=f.valueBlock.value[0].toString();if(u!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(u!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new K("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let l=An(f.valueBlock.value[1].getValue());return{cipherText:An(r.valueBlock.value[1].getValue()),salt:s,iterations:a,keySize:c,iv:l}}function du(r){return An(r.valueBlock.value[2].getValue())}function An(r){return new Uint8Array(r,0,r.byteLength)}async function pu(r){let e=await Re.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 yu(e);return{privateKey:t[0],publicKey:t[1]}}async function _s(r){let t=[await Re.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await M0(r)],n=await yu({privateKey:t[0],publicKey:t[1]});return{privateKey:n[0],publicKey:n[1]}}async function gu(r,e){let t=await Re.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Re.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function mu(r,e,t){let n=await Re.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Re.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function yu(r){if(r.privateKey==null||r.publicKey==null)throw new K("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([Re.get().subtle.exportKey("jwk",r.privateKey),Re.get().subtle.exportKey("jwk",r.publicKey)])}async function M0(r){return Re.get().subtle.importKey("jwk",{kty:r.kty,n:r.n,e:r.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function Wo(r){if(r.kty!=="RSA")throw new K("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new K("invalid key modulus","ERR_INVALID_KEY_MODULUS");return Z(r.n,"base64url").length*8}var Rn=8192,Sn=class{_key;constructor(e){this._key=e}verify(e,t){return mu(this._key,t,e)}marshal(){return Wt.jwkToPkix(this._key)}get bytes(){return ot.encode({Type:ne.RSA,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=we.digest(this.bytes);return He(e)?e.then(({bytes:t})=>t):e.bytes}},$r=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return dr(16)}sign(e){return gu(this._key,e)}get public(){if(this._publicKey==null)throw new K("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new Sn(this._publicKey)}marshal(){return Wt.jwkToPkcs1(this._key)}get bytes(){return it.encode({Type:ne.RSA,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=we.digest(this.bytes);return He(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return Q(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return Wt.exportToPem(this,e);if(t==="libp2p-key")return Vr(this.bytes,e);throw new K(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Ns(r){let e=Wt.pkcs1ToJwk(r);if(Wo(e)>Rn)throw new K("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await _s(e);return new $r(t.privateKey,t.publicKey)}function H0(r){let e=Wt.pkixToJwk(r);if(Wo(e)>Rn)throw new K("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new Sn(e)}async function K0(r){if(Wo(r)>Rn)throw new K("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await _s(r);return new $r(e.privateKey,e.publicKey)}async function $0(r){if(r>Rn)throw new K("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await pu(r);return new $r(e.privateKey,e.publicKey)}var Fs={};he(Fs,{Secp256k1PrivateKey:()=>In,Secp256k1PublicKey:()=>kn,generateKeyPair:()=>rp,unmarshalSecp256k1PrivateKey:()=>ep,unmarshalSecp256k1PublicKey:()=>tp});var q0=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]),Jt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Xt=new Uint32Array(64),Ls=class extends _r{constructor(){super(64,32,8,!1),this.A=Jt[0]|0,this.B=Jt[1]|0,this.C=Jt[2]|0,this.D=Jt[3]|0,this.E=Jt[4]|0,this.F=Jt[5]|0,this.G=Jt[6]|0,this.H=Jt[7]|0}get(){let{A:e,B:t,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,t,n,o,i,s,a,c]}set(e,t,n,o,i,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let l=0;l<16;l++,t+=4)Xt[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let h=Xt[l-15],E=Xt[l-2],B=Ge(h,7)^Ge(h,18)^h>>>3,p=Ge(E,17)^Ge(E,19)^E>>>10;Xt[l]=p+Xt[l-7]+B+Xt[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let h=Ge(a,6)^Ge(a,11)^Ge(a,25),E=u+h+za(a,c,f)+q0[l]+Xt[l]|0,p=(Ge(n,2)^Ge(n,13)^Ge(n,22))+Ga(n,o,i)|0;u=f,f=c,c=a,a=s+E|0,s=i,i=o,o=n,n=E+p|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,i,s,a,c,f,u)}roundClean(){Xt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var wu=jn(()=>new Ls);function xu(r){r.lowS!==void 0&&je("lowS",r.lowS),r.prehash!==void 0&&je("prehash",r.prehash)}function z0(r){let e=un(r);nt(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:G0,hexToBytes:j0}=Wn,At={Err:class extends Error{constructor(e=""){super(e)}},_tlv:{encode:(r,e)=>{let{Err:t}=At;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=ir(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?ir(o.length/2|128):"";return`${ir(r)}${i}${o}${e}`},decode(r,e){let{Err:t}=At,n=0;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new t("tlv.decode: length bytes not complete");if(f[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let u of f)s=s<<8|u;if(n+=c,s<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(r){let{Err:e}=At;if(r<St)throw new e("integer: negative integers are not allowed");let t=ir(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}=At;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 G0(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=At,o=typeof r=="string"?j0(r):r;Ur(o);let{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("Invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l:u}=n.decode(2,c);if(u.length)throw new e("Invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(f)}},hexFromSig(r){let{_tlv:e,_int:t}=At,n=`${e.encode(2,t.encode(r.r))}${e.encode(2,t.encode(r.s))}`;return e.encode(48,n)}},St=BigInt(0),pe=BigInt(1),Fw=BigInt(2),bu=BigInt(3),Mw=BigInt(4);function Y0(r){let e=z0(r),{Fp:t}=e,n=Ht(e.n,e.nBitLength),o=e.toBytes||((p,d,b)=>{let k=d.toAffine();return mt(Uint8Array.from([4]),t.toBytes(k.x),t.toBytes(k.y))}),i=e.fromBytes||(p=>{let d=p.subarray(1),b=t.fromBytes(d.subarray(0,t.BYTES)),k=t.fromBytes(d.subarray(t.BYTES,2*t.BYTES));return{x:b,y:k}});function s(p){let{a:d,b}=e,k=t.sqr(p),w=t.mul(k,p);return t.add(t.add(w,t.mul(p,d)),b)}if(!t.eql(t.sqr(e.Gy),s(e.Gx)))throw new Error("bad generator point: equation left != right");function a(p){return an(p,pe,e.n)}function c(p){let{allowedPrivateKeyLengths:d,nByteLength:b,wrapPrivateKey:k,n:w}=e;if(d&&typeof p!="bigint"){if(Ft(p)&&(p=pt(p)),typeof p!="string"||!d.includes(p.length))throw new Error("Invalid key");p=p.padStart(b*2,"0")}let I;try{I=typeof p=="bigint"?p:gt(ie("private key",p,b))}catch{throw new Error(`private key must be ${b} bytes, hex or bigint, not ${typeof p}`)}return k&&(I=X(I,w)),Ne("private key",I,pe,w),I}function f(p){if(!(p instanceof h))throw new Error("ProjectivePoint expected")}let u=cr((p,d)=>{let{px:b,py:k,pz:w}=p;if(t.eql(w,t.ONE))return{x:b,y:k};let I=p.is0();d==null&&(d=I?t.ONE:t.inv(w));let O=t.mul(b,d),D=t.mul(k,d),N=t.mul(w,d);if(I)return{x:t.ZERO,y:t.ZERO};if(!t.eql(N,t.ONE))throw new Error("invZ was invalid");return{x:O,y:D}}),l=cr(p=>{if(p.is0()){if(e.allowInfinityPoint&&!t.is0(p.py))return;throw new Error("bad point: ZERO")}let{x:d,y:b}=p.toAffine();if(!t.isValid(d)||!t.isValid(b))throw new Error("bad point: x or y not FE");let k=t.sqr(b),w=s(d);if(!t.eql(k,w))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,b,k){if(this.px=d,this.py=b,this.pz=k,d==null||!t.isValid(d))throw new Error("x required");if(b==null||!t.isValid(b))throw new Error("y required");if(k==null||!t.isValid(k))throw new Error("z required");Object.freeze(this)}static fromAffine(d){let{x:b,y:k}=d||{};if(!d||!t.isValid(b)||!t.isValid(k))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let w=I=>t.eql(I,t.ZERO);return w(b)&&w(k)?h.ZERO:new h(b,k,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let b=t.invertBatch(d.map(k=>k.pz));return d.map((k,w)=>k.toAffine(b[w])).map(h.fromAffine)}static fromHex(d){let b=h.fromAffine(i(ie("pointHex",d)));return b.assertValidity(),b}static fromPrivateKey(d){return h.BASE.multiply(c(d))}static msm(d,b){return Qn(h,n,d,b)}_setWindowSize(d){B.setWindowSize(this,d)}assertValidity(){l(this)}hasEvenY(){let{y:d}=this.toAffine();if(t.isOdd)return!t.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){f(d);let{px:b,py:k,pz:w}=this,{px:I,py:O,pz:D}=d,N=t.eql(t.mul(b,D),t.mul(I,w)),x=t.eql(t.mul(k,D),t.mul(O,w));return N&&x}negate(){return new h(this.px,t.neg(this.py),this.pz)}double(){let{a:d,b}=e,k=t.mul(b,bu),{px:w,py:I,pz:O}=this,D=t.ZERO,N=t.ZERO,x=t.ZERO,v=t.mul(w,w),F=t.mul(I,I),_=t.mul(O,O),C=t.mul(w,I);return C=t.add(C,C),x=t.mul(w,O),x=t.add(x,x),D=t.mul(d,x),N=t.mul(k,_),N=t.add(D,N),D=t.sub(F,N),N=t.add(F,N),N=t.mul(D,N),D=t.mul(C,D),x=t.mul(k,x),_=t.mul(d,_),C=t.sub(v,_),C=t.mul(d,C),C=t.add(C,x),x=t.add(v,v),v=t.add(x,v),v=t.add(v,_),v=t.mul(v,C),N=t.add(N,v),_=t.mul(I,O),_=t.add(_,_),v=t.mul(_,C),D=t.sub(D,v),x=t.mul(_,F),x=t.add(x,x),x=t.add(x,x),new h(D,N,x)}add(d){f(d);let{px:b,py:k,pz:w}=this,{px:I,py:O,pz:D}=d,N=t.ZERO,x=t.ZERO,v=t.ZERO,F=e.a,_=t.mul(e.b,bu),C=t.mul(b,I),$=t.mul(k,O),S=t.mul(w,D),R=t.add(b,k),y=t.add(I,O);R=t.mul(R,y),y=t.add(C,$),R=t.sub(R,y),y=t.add(b,w);let g=t.add(I,D);return y=t.mul(y,g),g=t.add(C,S),y=t.sub(y,g),g=t.add(k,w),N=t.add(O,D),g=t.mul(g,N),N=t.add($,S),g=t.sub(g,N),v=t.mul(F,y),N=t.mul(_,S),v=t.add(N,v),N=t.sub($,v),v=t.add($,v),x=t.mul(N,v),$=t.add(C,C),$=t.add($,C),S=t.mul(F,S),y=t.mul(_,y),$=t.add($,S),S=t.sub(C,S),S=t.mul(F,S),y=t.add(y,S),C=t.mul($,y),x=t.add(x,C),C=t.mul(g,y),N=t.mul(R,N),N=t.sub(N,C),C=t.mul(R,$),v=t.mul(g,v),v=t.add(v,C),new h(N,x,v)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return B.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){Ne("scalar",d,St,e.n);let b=h.ZERO;if(d===St)return b;if(d===pe)return this;let{endo:k}=e;if(!k)return B.unsafeLadder(this,d);let{k1neg:w,k1:I,k2neg:O,k2:D}=k.splitScalar(d),N=b,x=b,v=this;for(;I>St||D>St;)I&pe&&(N=N.add(v)),D&pe&&(x=x.add(v)),v=v.double(),I>>=pe,D>>=pe;return w&&(N=N.negate()),O&&(x=x.negate()),x=new h(t.mul(x.px,k.beta),x.py,x.pz),N.add(x)}multiply(d){let{endo:b,n:k}=e;Ne("scalar",d,pe,k);let w,I;if(b){let{k1neg:O,k1:D,k2neg:N,k2:x}=b.splitScalar(d),{p:v,f:F}=this.wNAF(D),{p:_,f:C}=this.wNAF(x);v=B.constTimeNegate(O,v),_=B.constTimeNegate(N,_),_=new h(t.mul(_.px,b.beta),_.py,_.pz),w=v.add(_),I=F.add(C)}else{let{p:O,f:D}=this.wNAF(d);w=O,I=D}return h.normalizeZ([w,I])[0]}multiplyAndAddUnsafe(d,b,k){let w=h.BASE,I=(D,N)=>N===St||N===pe||!D.equals(w)?D.multiplyUnsafe(N):D.multiply(N),O=I(this,b).add(I(d,k));return O.is0()?void 0:O}toAffine(d){return u(this,d)}isTorsionFree(){let{h:d,isTorsionFree:b}=e;if(d===pe)return!0;if(b)return b(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:b}=e;return d===pe?this:b?b(h,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return je("isCompressed",d),this.assertValidity(),o(h,this,d)}toHex(d=!0){return je("isCompressed",d),pt(this.toRawBytes(d))}}h.BASE=new h(e.Gx,e.Gy,t.ONE),h.ZERO=new h(t.ZERO,t.ONE,t.ZERO);let E=e.nBitLength,B=Xn(h,e.endo?Math.ceil(E/2):E);return{CURVE:e,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:s,isWithinCurveOrder:a}}function Z0(r){let e=un(r);return nt(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Eu(r){let e=Z0(r),{Fp:t,n}=e,o=t.BYTES+1,i=2*t.BYTES+1;function s(S){return X(S,n)}function a(S){return Jn(S,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:l}=Y0({...e,toBytes(S,R,y){let g=R.toAffine(),A=t.toBytes(g.x),V=mt;return je("isCompressed",y),y?V(Uint8Array.from([R.hasEvenY()?2:3]),A):V(Uint8Array.from([4]),A,t.toBytes(g.y))},fromBytes(S){let R=S.length,y=S[0],g=S.subarray(1);if(R===o&&(y===2||y===3)){let A=gt(g);if(!an(A,pe,t.ORDER))throw new Error("Point is not on curve");let V=u(A),M;try{M=t.sqrt(V)}catch(Y){let G=Y instanceof Error?": "+Y.message:"";throw new Error("Point is not on curve"+G)}let P=(M&pe)===pe;return(y&1)===1!==P&&(M=t.neg(M)),{x:A,y:M}}else if(R===i&&y===4){let A=t.fromBytes(g.subarray(0,t.BYTES)),V=t.fromBytes(g.subarray(t.BYTES,2*t.BYTES));return{x:A,y:V}}else throw new Error(`Point of length ${R} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}}),h=S=>pt(Pt(S,e.nByteLength));function E(S){let R=n>>pe;return S>R}function B(S){return E(S)?s(-S):S}let p=(S,R,y)=>gt(S.slice(R,y));class d{constructor(R,y,g){this.r=R,this.s=y,this.recovery=g,this.assertValidity()}static fromCompact(R){let y=e.nByteLength;return R=ie("compactSignature",R,y*2),new d(p(R,0,y),p(R,y,2*y))}static fromDER(R){let{r:y,s:g}=At.toSig(ie("DER",R));return new d(y,g)}assertValidity(){Ne("r",this.r,pe,n),Ne("s",this.s,pe,n)}addRecoveryBit(R){return new d(this.r,this.s,R)}recoverPublicKey(R){let{r:y,s:g,recovery:A}=this,V=D(ie("msgHash",R));if(A==null||![0,1,2,3].includes(A))throw new Error("recovery id invalid");let M=A===2||A===3?y+e.n:y;if(M>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let P=A&1?"03":"02",z=c.fromHex(P+h(M)),Y=a(M),G=s(-V*Y),J=s(g*Y),ee=c.BASE.multiplyAndAddUnsafe(z,G,J);if(!ee)throw new Error("point at infinify");return ee.assertValidity(),ee}hasHighS(){return E(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return sr(this.toDERHex())}toDERHex(){return At.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return sr(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let b={isValidPrivateKey(S){try{return f(S),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let S=ss(e.n);return ec(e.randomBytes(S),e.n)},precompute(S=8,R=c.BASE){return R._setWindowSize(S),R.multiply(BigInt(3)),R}};function k(S,R=!0){return c.fromPrivateKey(S).toRawBytes(R)}function w(S){let R=Ft(S),y=typeof S=="string",g=(R||y)&&S.length;return R?g===o||g===i:y?g===2*o||g===2*i:S instanceof c}function I(S,R,y=!0){if(w(S))throw new Error("first arg must be private key");if(!w(R))throw new Error("second arg must be public key");return c.fromHex(R).multiply(f(S)).toRawBytes(y)}let O=e.bits2int||function(S){let R=gt(S),y=S.length*8-e.nBitLength;return y>0?R>>BigInt(y):R},D=e.bits2int_modN||function(S){return s(O(S))},N=cn(e.nBitLength);function x(S){return Ne(`num < 2^${e.nBitLength}`,S,St,N),Pt(S,e.nByteLength)}function v(S,R,y=F){if(["recovered","canonical"].some(fe=>fe in y))throw new Error("sign() legacy options not supported");let{hash:g,randomBytes:A}=e,{lowS:V,prehash:M,extraEntropy:P}=y;V==null&&(V=!0),S=ie("msgHash",S),xu(y),M&&(S=ie("prehashed msgHash",g(S)));let z=D(S),Y=f(R),G=[x(Y),x(z)];if(P!=null&&P!==!1){let fe=P===!0?A(t.BYTES):P;G.push(ie("extraEntropy",fe))}let J=mt(...G),ee=z;function le(fe){let me=O(fe);if(!l(me))return;let Se=a(me),ae=c.BASE.multiply(me).toAffine(),Ce=s(ae.x);if(Ce===St)return;let ft=s(Se*s(ee+Ce*Y));if(ft===St)return;let Jr=(ae.x===Ce?0:2)|Number(ae.y&pe),Xr=ft;return V&&E(ft)&&(Xr=B(ft),Jr^=1),new d(Ce,Xr,Jr)}return{seed:J,k2sig:le}}let F={lowS:e.lowS,prehash:!1},_={lowS:e.lowS,prehash:!1};function C(S,R,y=F){let{seed:g,k2sig:A}=v(S,R,y),V=e;return rs(V.hash.outputLen,V.nByteLength,V.hmac)(g,A)}c.BASE._setWindowSize(8);function $(S,R,y,g=_){let A=S;if(R=ie("msgHash",R),y=ie("publicKey",y),"strict"in g)throw new Error("options.strict was renamed to lowS");xu(g);let{lowS:V,prehash:M}=g,P,z;try{if(typeof A=="string"||Ft(A))try{P=d.fromDER(A)}catch(ae){if(!(ae instanceof At.Err))throw ae;P=d.fromCompact(A)}else if(typeof A=="object"&&typeof A.r=="bigint"&&typeof A.s=="bigint"){let{r:ae,s:Ce}=A;P=new d(ae,Ce)}else throw new Error("PARSE");z=c.fromHex(y)}catch(ae){if(ae.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(V&&P.hasHighS())return!1;M&&(R=e.hash(R));let{r:Y,s:G}=P,J=D(R),ee=a(G),le=s(J*ee),fe=s(Y*ee),me=c.BASE.multiplyAndAddUnsafe(z,le,fe)?.toAffine();return me?s(me.x)===Y:!1}return{CURVE:e,getPublicKey:k,getSharedSecret:I,sign:C,verify:$,ProjectivePoint:c,Signature:d,utils:b}}function W0(r){return{hash:r,hmac:(e,...t)=>gn(r,e,Yi(...t)),randomBytes:Nr}}function vu(r,e){let t=n=>Eu({...r,...W0(n)});return Object.freeze({...t(e),create:t})}var Su=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Bu=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),J0=BigInt(1),Ds=BigInt(2),Au=(r,e)=>(r+e/Ds)/e;function X0(r){let e=Su,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%e,u=f*f*r%e,l=re(u,t,e)*u%e,h=re(l,t,e)*u%e,E=re(h,Ds,e)*f%e,B=re(E,o,e)*E%e,p=re(B,i,e)*B%e,d=re(p,a,e)*p%e,b=re(d,c,e)*d%e,k=re(b,a,e)*p%e,w=re(k,t,e)*u%e,I=re(w,s,e)*B%e,O=re(I,n,e)*f%e,D=re(O,Ds,e);if(!Vs.eql(Vs.sqr(D),r))throw new Error("Cannot find square root");return D}var Vs=Ht(Su,void 0,void 0,{sqrt:X0}),Xe=vu({a:BigInt(0),b:BigInt(7),Fp:Vs,n:Bu,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=Bu,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-J0*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=Au(i*r,e),c=Au(-n*r,e),f=X(r-a*t-c*o,e),u=X(-a*n-c*i,e),l=f>s,h=u>s;if(l&&(f=e-f),h&&(u=e-u),f>s||u>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:h,k2:u}}}},wu),Yw=BigInt(0);var Zw=Xe.ProjectivePoint;function Ru(){return Xe.utils.randomPrivateKey()}function ku(r,e){let t=we.digest(e instanceof Uint8Array?e:e.subarray());if(He(t))return t.then(({digest:n})=>Xe.sign(n,r).toDERRawBytes()).catch(n=>{throw new K(String(n),"ERR_INVALID_INPUT")});try{return Xe.sign(t.digest,r).toDERRawBytes()}catch(n){throw new K(String(n),"ERR_INVALID_INPUT")}}function Iu(r,e,t){let n=we.digest(t instanceof Uint8Array?t:t.subarray());if(He(n))return n.then(({digest:o})=>Xe.verify(e,o,r)).catch(o=>{throw new K(String(o),"ERR_INVALID_INPUT")});try{return Xe.verify(e,n.digest,r)}catch(o){throw new K(String(o),"ERR_INVALID_INPUT")}}function Tu(r){return Xe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Cu(r){try{Xe.getPublicKey(r,!0)}catch(e){throw new K(String(e),"ERR_INVALID_PRIVATE_KEY")}}function Os(r){try{Xe.ProjectivePoint.fromHex(r)}catch(e){throw new K(String(e),"ERR_INVALID_PUBLIC_KEY")}}function Nu(r){try{return Xe.getPublicKey(r,!0)}catch(e){throw new K(String(e),"ERR_INVALID_PRIVATE_KEY")}}var kn=class{_key;constructor(e){Os(e),this._key=e}verify(e,t){return Iu(this._key,t,e)}marshal(){return Tu(this._key)}get bytes(){return ot.encode({Type:ne.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}async hash(){let e=we.digest(this.bytes),t;return He(e)?{bytes:t}=await e:t=e.bytes,t}},In=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??Nu(e),Cu(this._key),Os(this._publicKey)}sign(e){return ku(this._key,e)}get public(){return new kn(this._publicKey)}marshal(){return this._key}get bytes(){return it.encode({Type:ne.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ce(this.bytes,e.bytes)}hash(){let e=we.digest(this.bytes);return He(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return Q(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return Vr(this.bytes,e);throw new K(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function ep(r){return new In(r)}function tp(r){return new kn(r)}async function rp(){let r=Ru();return new In(r)}var gr={rsa:Us,ed25519:Bs,secp256k1:Fs};function _u(r){let e=Object.keys(gr).join(" / ");return new K(`invalid or unsupported key type ${r}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function Ms(r){let e=ot.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case ne.RSA:return gr.rsa.unmarshalRsaPublicKey(t);case ne.Ed25519:return gr.ed25519.unmarshalEd25519PublicKey(t);case ne.Secp256k1:return gr.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw _u(e.Type??"unknown")}}async function Uu(r){let e=it.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case ne.RSA:return gr.rsa.unmarshalRsaPrivateKey(t);case ne.Ed25519:return gr.ed25519.unmarshalEd25519PrivateKey(t);case ne.Secp256k1:return gr.secp256k1.unmarshalSecp256k1PrivateKey(t);default:throw _u(e.Type??"RSA")}}var ea=Nt(Jo(),1);var Rt="/",Vu=new TextEncoder().encode(Rt),Xo=Vu[0],qr=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=Z(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Xo)throw new Error("Invalid key")}toString(e="utf8"){return Q(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(Rt))}static random(){return new r(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new r(e):typeof e.uint8Array=="function"?new r(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Vu),this._buf[0]!==Xo){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Xo,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Xo;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let o=0;o<t.length;o++){if(n.length<o+1)return!1;let i=t[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(Rt).slice(1)}type(){return op(this.baseNamespace())}name(){return ip(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Rt)||(e+=Rt),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Rt):new r(e.slice(0,-1).join(Rt))}child(e){return this.toString()===Rt?e:e.toString()===Rt?this:new r(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return r.withNamespaces([...this.namespaces(),...sp(e.map(t=>t.namespaces()))])}};function op(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function ip(r){let e=r.split(":");return e[e.length-1]}function sp(r){return[].concat(...r)}var rf=Nt(Qo(),1);var Ou="ERR_IPNS_EXPIRED_RECORD",Tn="ERR_UNRECOGNIZED_VALIDITY",Fu="ERR_SIGNATURE_CREATION",kt="ERR_SIGNATURE_VERIFICATION";var Hs="ERR_UNDEFINED_PARAMETER",Mu="ERR_INVALID_RECORD_DATA",Pu="ERR_INVALID_VALUE",Hu="ERR_INVALID_EMBEDDED_KEY",Ku="ERR_MISSING_PRIVATE_KEY",$u="ERR_RECORD_TOO_LARGE";var be;(function(r){let e;(function(o){o.EOL="EOL"})(e=r.ValidityType||(r.ValidityType={}));let t;(function(o){o[o.EOL=0]="EOL"})(t||(t={})),function(o){o.codec=()=>dn(t)}(e=r.ValidityType||(r.ValidityType={}));let n;r.codec=()=>(n==null&&(n=Gt((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.value!=null&&(i.uint32(10),i.bytes(o.value)),o.signatureV1!=null&&(i.uint32(18),i.bytes(o.signatureV1)),o.validityType!=null&&(i.uint32(24),r.ValidityType.codec().encode(o.validityType,i)),o.validity!=null&&(i.uint32(34),i.bytes(o.validity)),o.sequence!=null&&(i.uint32(40),i.uint64(o.sequence)),o.ttl!=null&&(i.uint32(48),i.uint64(o.ttl)),o.pubKey!=null&&(i.uint32(58),i.bytes(o.pubKey)),o.signatureV2!=null&&(i.uint32(66),i.bytes(o.signatureV2)),o.data!=null&&(i.uint32(74),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i)=>{let s={},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:s.value=o.bytes();break;case 2:s.signatureV1=o.bytes();break;case 3:s.validityType=r.ValidityType.codec().decode(o);break;case 4:s.validity=o.bytes();break;case 5:s.sequence=o.uint64();break;case 6:s.ttl=o.uint64();break;case 7:s.pubKey=o.bytes();break;case 8:s.signatureV2=o.bytes();break;case 9:s.data=o.bytes();break;default:o.skipType(c&7);break}}return s})),n),r.encode=o=>zt(o,r.codec()),r.decode=o=>qt(o,r.codec())})(be||(be={}));var ap=["string","number","bigint","symbol"],cp=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function qu(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(ap.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(up(r))return"Buffer";let t=lp(r);return t||"Object"}function up(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function lp(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(cp.includes(e))return e}var m=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};m.uint=new m(0,"uint",!0);m.negint=new m(1,"negint",!0);m.bytes=new m(2,"bytes",!0);m.string=new m(3,"string",!0);m.array=new m(4,"array",!1);m.map=new m(5,"map",!1);m.tag=new m(6,"tag",!1);m.float=new m(7,"float",!0);m.false=new m(7,"false",!0);m.true=new m(7,"true",!0);m.null=new m(7,"null",!0);m.undefined=new m(7,"undefined",!0);m.break=new m(7,"break",!0);var L=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var zr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",fp=new TextDecoder,hp=new TextEncoder;function ei(r){return zr&&globalThis.Buffer.isBuffer(r)}function $s(r){return r instanceof Uint8Array?ei(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var Yu=zr?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):Gu(r,e,t):(r,e,t)=>t-e>64?fp.decode(r.subarray(e,t)):Gu(r,e,t),Zu=zr?r=>r.length>64?globalThis.Buffer.from(r):zu(r):r=>r.length>64?hp.encode(r):zu(r),ut=r=>Uint8Array.from(r),Gr=zr?(r,e,t)=>ei(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),Wu=zr?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),$s(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let o of r)n+o.length>t.length&&(o=o.subarray(0,t.length-n)),t.set(o,n),n+=o.length;return t},Ju=zr?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function Xu(r,e){if(ei(r)&&ei(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function zu(r){let e=[],t=0;for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(r.charCodeAt(++n)&1023),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 e}function Gu(r,e,t){let n=[];for(;e<t;){let o=r[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=t){let a,c,f,u;switch(s){case 1:o<128&&(i=o);break;case 2:a=r[e+1],(a&192)===128&&(u=(o&31)<<6|a&63,u>127&&(i=u));break;case 3:a=r[e+1],c=r[e+2],(a&192)===128&&(c&192)===128&&(u=(o&15)<<12|(a&63)<<6|c&63,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:a=r[e+1],c=r[e+2],f=r[e+3],(a&192)===128&&(c&192)===128&&(f&192)===128&&(u=(o&15)<<18|(a&63)<<12|(c&63)<<6|f&63,u>65535&&u<1114112&&(i=u))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return dp(n)}var ju=4096;function dp(r){let e=r.length;if(e<=ju)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=ju));return t}var pp=256,Cn=class{constructor(e=pp){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=t.length-(this.maxCursor-this.cursor)-1;t.set(e,o)}else{if(t){let o=t.length-(this.maxCursor-this.cursor)-1;o<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=Ju(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=Gr(n,0,this.cursor)}else t=Wu(this.chunks,this.cursor);return e&&this.reset(),t}};var H="CBOR decode error:",qs="CBOR encode error:",Nn=[];Nn[23]=1;Nn[24]=2;Nn[25]=3;Nn[26]=5;Nn[27]=9;function It(r,e,t){if(r.length-e<t)throw new Error(`${H} not enough data for type`)}var ge=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Oe(r,e,t){It(r,e,1);let n=r[e];if(t.strict===!0&&n<ge[0])throw new Error(`${H} integer encoded in more bytes than necessary (strict decode)`);return n}function Fe(r,e,t){It(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<ge[1])throw new Error(`${H} integer encoded in more bytes than necessary (strict decode)`);return n}function Me(r,e,t){It(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<ge[2])throw new Error(`${H} integer encoded in more bytes than necessary (strict decode)`);return n}function Pe(r,e,t){It(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],o=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(t.strict===!0&&i<ge[3])throw new Error(`${H} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(t.allowBigInt===!0)return i;throw new Error(`${H} integers outside of the safe integer range are not supported`)}function Qu(r,e,t,n){return new L(m.uint,Oe(r,e+1,n),2)}function el(r,e,t,n){return new L(m.uint,Fe(r,e+1,n),3)}function tl(r,e,t,n){return new L(m.uint,Me(r,e+1,n),5)}function rl(r,e,t,n){return new L(m.uint,Pe(r,e+1,n),9)}function $e(r,e){return Ee(r,0,e.value)}function Ee(r,e,t){if(t<ge[0]){let n=Number(t);r.push([e|n])}else if(t<ge[1]){let n=Number(t);r.push([e|24,n])}else if(t<ge[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<ge[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<ge[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,r.push(o)}else throw new Error(`${H} encountered BigInt larger than allowable range`)}}$e.encodedSize=function(e){return Ee.encodedSize(e.value)};Ee.encodedSize=function(e){return e<ge[0]?1:e<ge[1]?2:e<ge[2]?3:e<ge[3]?5:9};$e.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function nl(r,e,t,n){return new L(m.negint,-1-Oe(r,e+1,n),2)}function ol(r,e,t,n){return new L(m.negint,-1-Fe(r,e+1,n),3)}function il(r,e,t,n){return new L(m.negint,-1-Me(r,e+1,n),5)}var zs=BigInt(-1),sl=BigInt(1);function al(r,e,t,n){let o=Pe(r,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new L(m.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${H} integers outside of the safe integer range are not supported`);return new L(m.negint,zs-BigInt(o),9)}function ti(r,e){let t=e.value,n=typeof t=="bigint"?t*zs-sl:t*-1-1;Ee(r,e.type.majorEncoded,n)}ti.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*zs-sl:t*-1-1;return n<ge[0]?1:n<ge[1]?2:n<ge[2]?3:n<ge[3]?5:9};ti.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function _n(r,e,t,n){It(r,e,t+n);let o=Gr(r,e+t,e+t+n);return new L(m.bytes,o,t+n)}function cl(r,e,t,n){return _n(r,e,1,t)}function ul(r,e,t,n){return _n(r,e,2,Oe(r,e+1,n))}function ll(r,e,t,n){return _n(r,e,3,Fe(r,e+1,n))}function fl(r,e,t,n){return _n(r,e,5,Me(r,e+1,n))}function hl(r,e,t,n){let o=Pe(r,e+1,n);if(typeof o=="bigint")throw new Error(`${H} 64-bit integer bytes lengths not supported`);return _n(r,e,9,o)}function ri(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===m.string?Zu(r.value):r.value),r.encodedBytes}function jr(r,e){let t=ri(e);Ee(r,e.type.majorEncoded,t.length),r.push(t)}jr.encodedSize=function(e){let t=ri(e);return Ee.encodedSize(t.length)+t.length};jr.compareTokens=function(e,t){return mp(ri(e),ri(t))};function mp(r,e){return r.length<e.length?-1:r.length>e.length?1:Xu(r,e)}function Un(r,e,t,n,o){let i=t+n;It(r,e,i);let s=new L(m.string,Yu(r,e+t,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=Gr(r,e+t,e+i)),s}function dl(r,e,t,n){return Un(r,e,1,t,n)}function pl(r,e,t,n){return Un(r,e,2,Oe(r,e+1,n),n)}function gl(r,e,t,n){return Un(r,e,3,Fe(r,e+1,n),n)}function ml(r,e,t,n){return Un(r,e,5,Me(r,e+1,n),n)}function yl(r,e,t,n){let o=Pe(r,e+1,n);if(typeof o=="bigint")throw new Error(`${H} 64-bit integer string lengths not supported`);return Un(r,e,9,o,n)}var wl=jr;function Yr(r,e,t,n){return new L(m.array,n,t)}function xl(r,e,t,n){return Yr(r,e,1,t)}function bl(r,e,t,n){return Yr(r,e,2,Oe(r,e+1,n))}function El(r,e,t,n){return Yr(r,e,3,Fe(r,e+1,n))}function vl(r,e,t,n){return Yr(r,e,5,Me(r,e+1,n))}function Bl(r,e,t,n){let o=Pe(r,e+1,n);if(typeof o=="bigint")throw new Error(`${H} 64-bit integer array lengths not supported`);return Yr(r,e,9,o)}function Al(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${H} indefinite length items not allowed`);return Yr(r,e,1,1/0)}function ni(r,e){Ee(r,m.array.majorEncoded,e.value)}ni.compareTokens=$e.compareTokens;ni.encodedSize=function(e){return Ee.encodedSize(e.value)};function Zr(r,e,t,n){return new L(m.map,n,t)}function Sl(r,e,t,n){return Zr(r,e,1,t)}function Rl(r,e,t,n){return Zr(r,e,2,Oe(r,e+1,n))}function kl(r,e,t,n){return Zr(r,e,3,Fe(r,e+1,n))}function Il(r,e,t,n){return Zr(r,e,5,Me(r,e+1,n))}function Tl(r,e,t,n){let o=Pe(r,e+1,n);if(typeof o=="bigint")throw new Error(`${H} 64-bit integer map lengths not supported`);return Zr(r,e,9,o)}function Cl(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${H} indefinite length items not allowed`);return Zr(r,e,1,1/0)}function oi(r,e){Ee(r,m.map.majorEncoded,e.value)}oi.compareTokens=$e.compareTokens;oi.encodedSize=function(e){return Ee.encodedSize(e.value)};function Nl(r,e,t,n){return new L(m.tag,t,1)}function _l(r,e,t,n){return new L(m.tag,Oe(r,e+1,n),2)}function Ul(r,e,t,n){return new L(m.tag,Fe(r,e+1,n),3)}function Ll(r,e,t,n){return new L(m.tag,Me(r,e+1,n),5)}function Dl(r,e,t,n){return new L(m.tag,Pe(r,e+1,n),9)}function ii(r,e){Ee(r,m.tag.majorEncoded,e.value)}ii.compareTokens=$e.compareTokens;ii.encodedSize=function(e){return Ee.encodedSize(e.value)};var vp=20,Bp=21,Ap=22,Sp=23;function Vl(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${H} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new L(m.null,null,1):new L(m.undefined,void 0,1)}function Ol(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${H} indefinite length items not allowed`);return new L(m.break,void 0,1)}function Gs(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${H} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${H} Infinity values are not supported`)}return new L(m.float,r,e)}function Fl(r,e,t,n){return Gs(js(r,e+1),3,n)}function Ml(r,e,t,n){return Gs(Ys(r,e+1),5,n)}function Pl(r,e,t,n){return Gs(ql(r,e+1),9,n)}function si(r,e,t){let n=e.value;if(n===!1)r.push([m.float.majorEncoded|vp]);else if(n===!0)r.push([m.float.majorEncoded|Bp]);else if(n===null)r.push([m.float.majorEncoded|Ap]);else if(n===void 0)r.push([m.float.majorEncoded|Sp]);else{let o,i=!1;(!t||t.float64!==!0)&&(Kl(n),o=js(Qe,1),n===o||Number.isNaN(n)?(Qe[0]=249,r.push(Qe.slice(0,3)),i=!0):($l(n),o=Ys(Qe,1),n===o&&(Qe[0]=250,r.push(Qe.slice(0,5)),i=!0))),i||(Rp(n),o=ql(Qe,1),Qe[0]=251,r.push(Qe.slice(0,9)))}}si.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){Kl(n);let o=js(Qe,1);if(n===o||Number.isNaN(n))return 3;if($l(n),o=Ys(Qe,1),n===o)return 5}return 9};var Hl=new ArrayBuffer(9),qe=new DataView(Hl,1),Qe=new Uint8Array(Hl,0);function Kl(r){if(r===1/0)qe.setUint16(0,31744,!1);else if(r===-1/0)qe.setUint16(0,64512,!1);else if(Number.isNaN(r))qe.setUint16(0,32256,!1);else{qe.setFloat32(0,r);let e=qe.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)qe.setUint16(0,31744,!1);else if(t===0)qe.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=t-127;o<-24?qe.setUint16(0,0):o<-14?qe.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):qe.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function js(r,e){if(r.length-e<2)throw new Error(`${H} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,o=t&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,t&32768?-i:i}function $l(r){qe.setFloat32(0,r,!1)}function Ys(r,e){if(r.length-e<4)throw new Error(`${H} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function Rp(r){qe.setFloat64(0,r,!1)}function ql(r,e){if(r.length-e<8)throw new Error(`${H} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}si.compareTokens=$e.compareTokens;function W(r,e,t){throw new Error(`${H} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function ai(r){return()=>{throw new Error(`${H} ${r}`)}}var T=[];for(let r=0;r<=23;r++)T[r]=W;T[24]=Qu;T[25]=el;T[26]=tl;T[27]=rl;T[28]=W;T[29]=W;T[30]=W;T[31]=W;for(let r=32;r<=55;r++)T[r]=W;T[56]=nl;T[57]=ol;T[58]=il;T[59]=al;T[60]=W;T[61]=W;T[62]=W;T[63]=W;for(let r=64;r<=87;r++)T[r]=cl;T[88]=ul;T[89]=ll;T[90]=fl;T[91]=hl;T[92]=W;T[93]=W;T[94]=W;T[95]=ai("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)T[r]=dl;T[120]=pl;T[121]=gl;T[122]=ml;T[123]=yl;T[124]=W;T[125]=W;T[126]=W;T[127]=ai("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)T[r]=xl;T[152]=bl;T[153]=El;T[154]=vl;T[155]=Bl;T[156]=W;T[157]=W;T[158]=W;T[159]=Al;for(let r=160;r<=183;r++)T[r]=Sl;T[184]=Rl;T[185]=kl;T[186]=Il;T[187]=Tl;T[188]=W;T[189]=W;T[190]=W;T[191]=Cl;for(let r=192;r<=215;r++)T[r]=Nl;T[216]=_l;T[217]=Ul;T[218]=Ll;T[219]=Dl;T[220]=W;T[221]=W;T[222]=W;T[223]=W;for(let r=224;r<=243;r++)T[r]=ai("simple values are not supported");T[244]=W;T[245]=W;T[246]=W;T[247]=Vl;T[248]=ai("simple values are not supported");T[249]=Fl;T[250]=Ml;T[251]=Pl;T[252]=W;T[253]=W;T[254]=W;T[255]=Ol;var et=[];for(let r=0;r<24;r++)et[r]=new L(m.uint,r,1);for(let r=-1;r>=-24;r--)et[31-r]=new L(m.negint,r,1);et[64]=new L(m.bytes,new Uint8Array(0),1);et[96]=new L(m.string,"",1);et[128]=new L(m.array,0,1);et[160]=new L(m.map,0,1);et[244]=new L(m.false,!1,1);et[245]=new L(m.true,!0,1);et[246]=new L(m.null,null,1);function zl(r){switch(r.type){case m.false:return ut([244]);case m.true:return ut([245]);case m.null:return ut([246]);case m.bytes:return r.value.length?void 0:ut([64]);case m.string:return r.value===""?ut([96]):void 0;case m.array:return r.value===0?ut([128]):void 0;case m.map:return r.value===0?ut([160]):void 0;case m.uint:return r.value<24?ut([Number(r.value)]):void 0;case m.negint:if(r.value>=-24)return ut([31-Number(r.value)])}}var Ip={float64:!1,mapSorter:Np,quickEncodeToken:zl};function Tp(){let r=[];return r[m.uint.major]=$e,r[m.negint.major]=ti,r[m.bytes.major]=jr,r[m.string.major]=wl,r[m.array.major]=ni,r[m.map.major]=oi,r[m.tag.major]=ii,r[m.float.major]=si,r}var Gl=Tp(),Zs=new Cn,ui=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${qs} object contains circular references`);return new r(t,e)}},Qt={null:new L(m.null,null),undefined:new L(m.undefined,void 0),true:new L(m.true,!0),false:new L(m.false,!1),emptyArray:new L(m.array,0),emptyMap:new L(m.map,0)},er={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new L(m.float,r):r>=0?new L(m.uint,r):new L(m.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new L(m.uint,r):new L(m.negint,r)},Uint8Array(r,e,t,n){return new L(m.bytes,r)},string(r,e,t,n){return new L(m.string,r)},boolean(r,e,t,n){return r?Qt.true:Qt.false},null(r,e,t,n){return Qt.null},undefined(r,e,t,n){return Qt.undefined},ArrayBuffer(r,e,t,n){return new L(m.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new L(m.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[Qt.emptyArray,new L(m.break)]:Qt.emptyArray;n=ui.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=ci(s,t,n);return t.addBreakTokens?[new L(m.array,r.length),o,new L(m.break)]:[new L(m.array,r.length),o]},Object(r,e,t,n){let o=e!=="Object",i=o?r.keys():Object.keys(r),s=o?r.size:i.length;if(!s)return t.addBreakTokens===!0?[Qt.emptyMap,new L(m.break)]:Qt.emptyMap;n=ui.createCheck(n,r);let a=[],c=0;for(let f of i)a[c++]=[ci(f,t,n),ci(o?r.get(f):r[f],t,n)];return Cp(a,t),t.addBreakTokens?[new L(m.map,s),a,new L(m.break)]:[new L(m.map,s),a]}};er.Map=er.Object;er.Buffer=er.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))er[`${r}Array`]=er.DataView;function ci(r,e={},t){let n=qu(r),o=e&&e.typeEncoders&&e.typeEncoders[n]||er[n];if(typeof o=="function"){let s=o(r,n,e,t);if(s!=null)return s}let i=er[n];if(!i)throw new Error(`${qs} unsupported type: ${n}`);return i(r,n,e,t)}function Cp(r,e){e.mapSorter&&r.sort(e.mapSorter)}function Np(r,e){let t=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(t.type!==n.type)return t.type.compare(n.type);let o=t.type.major,i=Gl[o].compareTokens(t,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function jl(r,e,t,n){if(Array.isArray(e))for(let o of e)jl(r,o,t,n);else t[e.type.major](r,e,n)}function _p(r,e,t){let n=ci(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let o=t.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,t),a=new Cn(s);if(i(a,n,t),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return $s(a.chunks[0])}}return Zs.reset(),jl(Zs,n,e,t),Zs.toBytes(!0)}function Ws(r,e){return e=Object.assign({},Ip,e),_p(r,Gl,e)}var Up={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},li=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=et[e];if(t===void 0){let n=T[e];if(!n)throw new Error(`${H} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;t=n(this.data,this._pos,o,this.options)}return this._pos+=t.encodedLength,t}},Ln=Symbol.for("DONE"),fi=Symbol.for("BREAK");function Lp(r,e,t){let n=[];for(let o=0;o<r.value;o++){let i=Wr(e,t);if(i===fi){if(r.value===1/0)break;throw new Error(`${H} got unexpected break to lengthed array`)}if(i===Ln)throw new Error(`${H} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function Dp(r,e,t){let n=t.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<r.value;s++){let a=Wr(e,t);if(a===fi){if(r.value===1/0)break;throw new Error(`${H} got unexpected break to lengthed map`)}if(a===Ln)throw new Error(`${H} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${H} non-string keys not supported (got ${typeof a})`);if(t.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${H} found repeat map key "${a}"`);let c=Wr(e,t);if(c===Ln)throw new Error(`${H} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(a,c):o[a]=c}return n?i:o}function Wr(r,e){if(r.done())return Ln;let t=r.next();if(t.type===m.break)return fi;if(t.type.terminal)return t.value;if(t.type===m.array)return Lp(t,r,e);if(t.type===m.map)return Dp(t,r,e);if(t.type===m.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=Wr(r,e);return e.tags[t.value](n)}throw new Error(`${H} tag not supported (${t.value})`)}throw new Error("unsupported")}function Yl(r,e){if(!(r instanceof Uint8Array))throw new Error(`${H} data to decode must be a Uint8Array`);e=Object.assign({},Up,e);let t=e.tokenizer||new li(r,e),n=Wr(t,e);if(n===Ln)throw new Error(`${H} did not find any content to decode`);if(n===fi)throw new Error(`${H} got unexpected break`);return[n,r.subarray(t.pos())]}function Js(r,e){let[t,n]=Yl(r,e);if(n.length>0)throw new Error(`${H} too many terminals, data makes no sense`);return t}var Le=Nt(Jo(),1);var Zl=Lt("ipns:utils"),Wl=Z("/ipns/"),Op=114,Jl=async(r,e)=>{if(e==null||r==null){let n=new Error("one or more of the provided parameters are not defined");throw Zl.error(n),(0,Le.default)(n,Hs)}let t;if(e.pubKey!=null){try{t=Ms(e.pubKey)}catch(o){throw Zl.error(o),o}if(!(await Pa(e.pubKey)).equals(r))throw(0,Le.default)(new Error("Embedded public key did not match PeerID"),Hu)}else r.publicKey!=null&&(t=Ms(r.publicKey));if(t!=null)return t;throw(0,Le.default)(new Error("no public key is available"),Hs)},Xl=(r,e,t)=>{let n=Z(e);return nr([r,t,n])},hi=r=>{let e=Z("ipns-signature:");return nr([e,r])},Xs=r=>"signatureV1"in r?be.encode({value:Z(r.value),signatureV1:r.signatureV1,validityType:r.validityType,validity:Z(r.validity),sequence:r.sequence,ttl:r.ttl,pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data}):be.encode({pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data});function lt(r){let e=be.decode(r);if(e.sequence!=null&&(e.sequence=BigInt(e.sequence)),e.ttl!=null&&(e.ttl=BigInt(e.ttl)),e.signatureV2==null||e.data==null)throw(0,Le.default)(new Error("missing data or signatureV2"),kt);let t=tf(e.data),n=Qs(t.Value),o=Q(t.Validity);if(e.value!=null&&e.signatureV1!=null)return Fp(e),{value:n,validityType:be.ValidityType.EOL,validity:o,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV1:e.signatureV1,signatureV2:e.signatureV2,data:e.data};if(e.signatureV2!=null)return{value:n,validityType:be.ValidityType.EOL,validity:o,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}var di=r=>nr([Wl,r.toBytes()]),Ql=r=>ji(r.slice(Wl.length)),ef=(r,e,t,n,o)=>{let i;if(e===be.ValidityType.EOL)i=0;else throw(0,Le.default)(new Error("Unknown validity type"),Tn);return Ws({Value:r,Validity:t,ValidityType:i,Sequence:n,TTL:o})},tf=r=>{let e=Js(r);if(e.ValidityType===0)e.ValidityType=be.ValidityType.EOL;else throw(0,Le.default)(new Error("Unknown validity type"),Tn);return Number.isInteger(e.Sequence)&&(e.Sequence=BigInt(e.Sequence)),Number.isInteger(e.TTL)&&(e.TTL=BigInt(e.TTL)),e},Qs=r=>{if(r!=null){if(pa(r))return`/ipns/${r.toCID().toString($n)}`;if(r instanceof Uint8Array){let n=Q(r);n.startsWith("/")&&(r=n)}let e=r.toString().trim();if(e.startsWith("/")&&e.length>1)return e;let t=ve.asCID(r);if(t!=null)return t.code===Op?`/ipns/${t.toString($n)}`:`/ipfs/${t.toV1().toString()}`;try{return r instanceof Uint8Array?`/ipfs/${ve.decode(r).toV1().toString()}`:`/ipfs/${ve.parse(e).toV1().toString()}`}catch{}}throw(0,Le.default)(new Error("Value must be a valid content path starting with /"),Pu)},Fp=r=>{if(r.data==null)throw(0,Le.default)(new Error("Record data is missing"),Mu);let e=tf(r.data);if(!ce(e.Value,r.value??new Uint8Array(0)))throw(0,Le.default)(new Error('Field "value" did not match between protobuf and CBOR'),kt);if(!ce(e.Validity,r.validity??new Uint8Array(0)))throw(0,Le.default)(new Error('Field "validity" did not match between protobuf and CBOR'),kt);if(e.ValidityType!==r.validityType)throw(0,Le.default)(new Error('Field "validityType" did not match between protobuf and CBOR'),kt);if(e.Sequence!==r.sequence)throw(0,Le.default)(new Error('Field "sequence" did not match between protobuf and CBOR'),kt);if(e.TTL!==r.ttl)throw(0,Le.default)(new Error('Field "ttl" did not match between protobuf and CBOR'),kt)};var Mp=Lt("ipns"),Pp=ze.code,nf=60*60*1e9,Hp="/ipns/",Db=Hp.length,of={v1Compatible:!0,ttlNs:nf};async function sf(r,e,t,n,o=of){let i=new rf.default(Date.now()+Number(n)),s=be.ValidityType.EOL,a=BigInt(o.ttlNs!=null?o.ttlNs:nf);return Kp(r,e,t,s,i.toString(),a,o)}var Kp=async(r,e,t,n,o,i,s=of)=>{t=BigInt(t);let a=Z(o),c=Qs(e),f=Z(c);if(r.privateKey==null)throw(0,ea.default)(new Error("Missing private key"),Ku);let u=await Uu(r.privateKey),l=ef(f,n,a,t,i),h=hi(l),E=await u.sign(h),B;if(r.publicKey!=null){let p=tr(r.toBytes());(p.code!==Pp||!ce(r.publicKey,p.digest))&&(B=r.publicKey)}if(s.v1Compatible===!0){let p=await $p(u,f,n,a),d={value:c,signatureV1:p,validity:o,validityType:n,sequence:t,ttl:i,signatureV2:E,data:l};return B!=null&&(d.pubKey=B),d}else{let p={value:c,validity:o,validityType:n,sequence:t,ttl:i,signatureV2:E,data:l};return B!=null&&(p.pubKey=B),p}};var $p=async(r,e,t,n)=>{try{let o=Xl(e,t,n);return await r.sign(o)}catch(o){throw Mp.error("record signature creation failed",o),(0,ea.default)(new Error("record signature creation failed"),Fu)}};var ta=Nt(Qo(),1);function pi(r,e){let t=e.map((n,o)=>({record:lt(n),index:o}));return t.sort((n,o)=>{let i=n.record.sequence,s=o.record.sequence;if(i>s)return-1;if(i<s)return 1;if(n.record.validityType===be.ValidityType.EOL&&o.record.validityType===be.ValidityType.EOL){let a=ta.default.fromString(n.record.validity).toDate(),c=ta.default.fromString(o.record.validity).toDate();if(a.getTime()>c.getTime())return-1;if(a.getTime()<c.getTime())return 1}return 0}),t[0].index}var Dn=Nt(Jo(),1),af=Nt(Qo(),1);var gi=Lt("ipns:validator"),qp=1024*10,zp=async(r,e)=>{let t=lt(e),n;try{let o=hi(t.data);n=await r.verify(o,t.signatureV2)}catch{n=!1}if(!n)throw gi.error("record signature verification failed"),(0,Dn.default)(new Error("record signature verification failed"),kt);if(t.validityType===be.ValidityType.EOL){if(af.default.fromString(t.validity).toDate().getTime()<Date.now())throw gi.error("record has expired"),(0,Dn.default)(new Error("record has expired"),Ou)}else if(t.validityType!=null)throw gi.error("unrecognized validity type"),(0,Dn.default)(new Error("unrecognized validity type"),Tn);gi("ipns record for %s is valid",t.value)};async function mi(r,e){if(e.byteLength>qp)throw(0,Dn.default)(new Error("record too large"),$u);let t=Ql(r),n=lt(e),o=await Jl(t,n);await zp(o,e)}var Te=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Yp=Nt(uf(),1);var Tt;(function(r){r[r.A=1]="A",r[r.CNAME=5]="CNAME",r[r.TXT=16]="TXT",r[r.AAAA=28]="AAAA"})(Tt||(Tt={}));var Zp=32;async function lf(r,e,t,n,o={}){if(e===0)throw new Error("recursion limit exceeded");n("query %s for TXT and CNAME records",r);let s=(await t.query(r,{...o,types:[Tt.TXT]})).Answer.sort((f,u)=>f.data.localeCompare(u.data));n("found %d TXT records for %s",s.length,r);for(let f of s)try{let u=f.data;if(u.startsWith('"')&&u.endsWith('"')&&(u=u.substring(1,u.length-1)),!u.startsWith("dnslink="))continue;n("%s TXT %s",f.name,u),u=u.replace("dnslink=","");let[,l,h,...E]=u.split("/");if(l==="ipfs")try{return{value:`/ipfs/${ve.parse(h)}${E.length>0?`/${E.join("/")}`:""}`,answer:f}}catch{}else if(l==="ipns"){try{return{value:`/ipns/${on(h)}${E.length>0?`/${E.join("/")}`:""}`,answer:f}}catch{}return await yi(h,e-1,t,n,o)}else{if(l==="dnslink")return await yi(h,e-1,t,n,o);n('unknown protocol "%s" in DNSLink record for domain: %s',l,r);continue}}catch(u){n.error("could not parse DNS link record for domain %s, %s",r,f.data,u)}n("no DNSLink records found for %s, falling back to CNAME",r);let c=(await t.query(r,{...o,types:[Tt.CNAME]})).Answer.sort((f,u)=>f.data.localeCompare(u.data));n("found %d CNAME records for %s",c.length,r);for(let f of c)try{return await yi(f.data,e-1,t,n,o)}catch(u){n.error("domain %s cname %s had no DNSLink records",r,f.data,u)}throw new K(`No DNSLink records found for domain: ${r}`,"ERR_DNSLINK_NOT_FOUND")}async function yi(r,e,t,n,o={}){if(e===0)throw new Error("recursion limit exceeded");r.startsWith("_dnslink.")||(r=`_dnslink.${r}`);try{return await lf(r,e,t,n,o)}catch(i){if(i.code!=="ENOTFOUND"&&i.code!=="ERR_DNSLINK_NOT_FOUND"&&i.code!=="ENODATA")throw i;return r.startsWith("_dnslink.")?r=r.replace("_dnslink.",""):r=`_dnslink.${r}`,lf(r,e,t,n,o)}}async function ff(r,e,t,n={}){return yi(r,n.maxRecursiveDepth??Zp,e,t,n)}var ra=class{routing;constructor(e){this.routing=e}async put(e,t,n={}){try{await this.routing.put(e,t,n)}catch(o){n.onProgress?.(new Te("ipns:routing:helia:error",o))}}async get(e,t={}){try{return await this.routing.get(e,t)}catch(n){t.onProgress?.(new Te("ipns:routing:helia:error",n))}throw new Error("Not found")}};function hf(r){return new ra(r)}var Vn;(function(r){let e;r.codec=()=>(e==null&&(e=Gt((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.key!=null&&t.key.byteLength>0&&(n.uint32(10),n.bytes(t.key)),t.value!=null&&t.value.byteLength>0&&(n.uint32(18),n.bytes(t.value)),t.timeReceived!=null&&t.timeReceived!==""&&(n.uint32(42),n.string(t.timeReceived)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={key:Hi(0),value:Hi(0),timeReceived:""},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.key=t.bytes();break}case 2:{i.value=t.bytes();break}case 5:{i.timeReceived=t.string();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>zt(t,r.codec()),r.decode=(t,n)=>qt(t,r.codec(),n)})(Vn||(Vn={}));function df(r){let e=r.getUTCFullYear(),t=String(r.getUTCMonth()+1).padStart(2,"0"),n=String(r.getUTCDate()).padStart(2,"0"),o=String(r.getUTCHours()).padStart(2,"0"),i=String(r.getUTCMinutes()).padStart(2,"0"),s=String(r.getUTCSeconds()).padStart(2,"0"),a=r.getUTCMilliseconds(),c=String(a*1e3*1e3).padStart(9,"0");return`${e}-${t}-${n}T${o}:${i}:${s}.${c}Z`}function pf(r){let e=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),t=String(r).trim().match(e);if(t==null)throw new Error("Invalid format");let n=parseInt(t[1],10),o=parseInt(t[2],10)-1,i=parseInt(t[3],10),s=parseInt(t[4],10),a=parseInt(t[5],10),c=parseInt(t[6],10),f=parseInt(t[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,c,f))}var yr=class r{key;value;timeReceived;constructor(e,t,n){if(!(e instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(t instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=e,this.value=t,this.timeReceived=n}serialize(){return Vn.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:df(this.timeReceived)}}static deserialize(e){let t=Vn.decode(e);return new r(t.key,t.value,new Date(t.timeReceived))}static fromDeserialized(e){let t=pf(e.timeReceived);if(e.key==null)throw new Error("key missing from deserialized object");if(e.value==null)throw new Error("value missing from deserialized object");return new r(e.key,e.value,t)}};var gf;(function(r){r[r.SEND_QUERY=0]="SEND_QUERY",r[r.PEER_RESPONSE=1]="PEER_RESPONSE",r[r.FINAL_PEER=2]="FINAL_PEER",r[r.QUERY_ERROR=3]="QUERY_ERROR",r[r.PROVIDER=4]="PROVIDER",r[r.VALUE=5]="VALUE",r[r.ADD_PEER=6]="ADD_PEER",r[r.DIAL_PEER=7]="DIAL_PEER"})(gf||(gf={}));function wi(r){return new qr("/dht/record/"+Q(r,"base32"),!1)}function mf(r){return{async put(e,t,n={}){try{let o=wi(e);try{let s=await r.get(o),a=yr.deserialize(s);if(ce(a.value,t))return}catch(s){if(s.code!=="ERR_NOT_FOUND")throw s}let i=new yr(e,t,new Date);n.onProgress?.(new Te("ipns:routing:datastore:put")),await r.put(o,i.serialize(),n)}catch(o){throw n.onProgress?.(new Te("ipns:routing:datastore:error",o)),o}},async get(e,t={}){try{let n=wi(e);t.onProgress?.(new Te("ipns:routing:datastore:get"));let o=await r.get(n,t),i=yr.deserialize(o);return{record:i.value,created:i.timeReceived}}catch(n){throw t.onProgress?.(new Te("ipns:routing:datastore:error",n)),n}},async has(e,t={}){let n=wi(e);return r.has(n,t)},async delete(e,t){let n=wi(e);return r.delete(n,t)}}}var Ct=Lt("helia:ipns"),Jp=60*1e3,ia=60*Jp,Xp=24*ia,na=23*ia,Qp=BigInt(ia)*1000000n,oa=class{routers;localStore;timeout;dns;log;constructor(e,t=[]){this.routers=[hf(e.routing),...t],this.localStore=mf(e.datastore),this.dns=e.dns,this.log=e.logger.forComponent("helia:ipns")}async publish(e,t,n={}){try{let o=1n,i=di(e);if(await this.localStore.has(i,n)){let{record:c}=await this.localStore.get(i,n);o=lt(c).sequence+1n}let s=await sf(e,t,o,n.lifetime??Xp,n),a=Xs(s);return await this.localStore.put(i,a,n),n.offline!==!0&&await Promise.all(this.routers.map(async c=>{await c.put(i,a,n)})),s}catch(o){throw n.onProgress?.(new Te("ipns:publish:error",o)),o}}async resolve(e,t={}){let n=di(e),o=await this.#t(n,t);return{...await this.#e(o.value,t),record:o}}async resolveDNSLink(e,t={}){let n=await ff(e,this.dns,this.log,t);return{...await this.#e(n.value,t),answer:n.answer}}republish(e={}){if(this.timeout!=null)throw new Error("Republish is already running");e.signal?.addEventListener("abort",()=>{clearTimeout(this.timeout)});async function t(){let n=Date.now();e.onProgress?.(new Te("ipns:republish:start"));let i=Date.now()-n,s=na-i;s<0&&(s=e.interval??na),setTimeout(()=>{t().catch(a=>{Ct.error("error republishing",a)})},s)}this.timeout=setTimeout(()=>{t().catch(n=>{Ct.error("error republishing",n)})},e.interval??na)}async#e(e,t={}){let n=e.split("/");try{let o=n[1];if(o==="ipns"){let{cid:i}=await this.resolve(on(n[2]),t),s=n.slice(3).join("/");return{cid:i,path:s}}else if(o==="ipfs"){let i=ve.parse(n[2]),s=n.slice(3).join("/");return{cid:i,path:s}}}catch(o){Ct.error("error parsing ipfs path",o)}throw Ct.error("invalid ipfs path %s",e),new Error("Invalid value")}async#t(e,t={}){let n=[];if(await this.localStore.has(e,t))if(Ct("record is present in the cache"),t.nocache!==!0)try{let{record:a,created:c}=await this.localStore.get(e,t);this.log("record retrieved from cache"),await mi(e,a),this.log("record was valid");let f=lt(a),u=Number((f.ttl??Qp)/1000000n);if(c.getTime()+u>Date.now())return this.log("record TTL was valid"),f;if(t.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),f;this.log("record TTL has been reached, searching routing for updates"),n.push(a)}catch(a){this.log("cached record was invalid",a),await this.localStore.delete(e,t)}else Ct("ignoring local cache due to nocache=true option");if(t.offline===!0)throw new K("Record was not present in the cache or has expired","ERR_NOT_FOUND");Ct("did not have record locally");let i=0;if(await Promise.all(this.routers.map(async a=>{let c;try{c=await a.get(e,{...t,validate:!1})}catch(f){Ct.error("error finding IPNS record",f);return}try{await mi(e,c),n.push(c)}catch(f){i++,Ct.error("error finding IPNS record",f)}})),n.length===0)throw i>0?new K(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`,"ERR_RECORDS_FAILED_VALIDATION"):new K("Could not find record for routing key","ERR_NOT_FOUND");let s=n[pi(e,n)];return await this.localStore.put(e,s,t),lt(s)}};function eg(r,{routers:e=[]}={}){return new oa(r,e)}return Cf(tg);})();
|
|
9
9
|
/*! Bundled license information:
|
|
10
10
|
|
|
11
11
|
pvtsutils/build/index.js:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/ipns",
|
|
3
|
-
"version": "7.2.3-
|
|
3
|
+
"version": "7.2.3-e567717",
|
|
4
4
|
"description": "An implementation of IPNS for Helia",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/ipns#readme",
|
|
@@ -164,7 +164,7 @@
|
|
|
164
164
|
"release": "aegir release"
|
|
165
165
|
},
|
|
166
166
|
"dependencies": {
|
|
167
|
-
"@helia/interface": "4.3.1-
|
|
167
|
+
"@helia/interface": "4.3.1-e567717",
|
|
168
168
|
"@libp2p/interface": "^1.1.4",
|
|
169
169
|
"@libp2p/kad-dht": "^12.0.8",
|
|
170
170
|
"@libp2p/logger": "^4.0.7",
|