ipns
Version:
IPNS record definitions
3 lines • 134 kB
JavaScript
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Ipns = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var Ipns=(()=>{var Sc=Object.create;var _r=Object.defineProperty;var Ac=Object.getOwnPropertyDescriptor;var Bc=Object.getOwnPropertyNames;var vc=Object.getPrototypeOf,Cc=Object.prototype.hasOwnProperty;var Tc=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ht=(e,t)=>{for(var r in t)_r(e,r,{get:t[r],enumerable:!0})},ri=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Bc(t))!Cc.call(e,o)&&o!==r&&_r(e,o,{get:()=>t[o],enumerable:!(n=Ac(t,o))||n.enumerable});return e};var Ic=(e,t,r)=>(r=e!=null?Sc(vc(e)):{},ri(t||!e||!e.__esModule?_r(r,"default",{value:e,enumerable:!0}):r,e)),_c=e=>ri(_r({},"__esModule",{value:!0}),e);var ra=Tc((Qm,qo)=>{var Jm=function(){typeof qo<"u"&&(qo.exports=A);var e=86400,t=3200,r=146097*t/400,n=e*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,u="000000000",h=Math.trunc||function(y){var f=y-y%1;return f==0&&(y<0||y===0&&1/y!=1/0)?-0:f},c=A.prototype,l=(A.fromDate=function(y){return new A(+y)},A.fromInt64BE=P(0,1,2,3,0,4),A.fromInt64LE=P(3,2,1,0,4,0),A.fromString=function(d){var f,g=new A,d=(d+="").replace(/^\s*[+\-]?\d+/,function(S){var S=+S,v=1970+(S-1970)%400;return g.year=S-v,v}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(p,S,v){return S<0&&(v*=-1),f=6e4*(60*+S+ +v),""}).replace(/\.\d+$/,function(p){return g.nano=+(p+u).substr(1,9),""}).split(/\D+/);if(1<d.length?d[1]--:d[1]=0,g.time=f=Date.UTC.apply(Date,d)-(f||0),isNaN(f))throw new TypeError("Invalid Date");return x(g)},A.fromTimeT=function(y){return L(y,0)},c.year=0,c.time=0,c.nano=0,c.addNano=function(y){return this.nano+=+y||0,this},c.getNano=function(){var y=x(this);return(y.time%1e3*a+ +y.nano+1e9)%1e9},c.getTimeT=function(){var f=x(this),y=Math.floor(f.time/1e3),f=f.year;return f&&(y+=f*r*e/t),y},c.getYear=function(){return this.toDate().getUTCFullYear()+this.year},c.toDate=function(){return I(x(this).time)},c.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},c.toString=function(y){var f=this,g=f.toDate(),d={H:function(){return D(g.getUTCHours())},L:function(){return k(g.getUTCMilliseconds(),3)},M:function(){return D(g.getUTCMinutes())},N:function(){return k(f.getNano(),9)},S:function(){return D(g.getUTCSeconds())},Y:function(){var p=f.getYear();return 999999<p?"+"+p:9999<p?"+"+k(p,6):0<=p?k(p,4):-999999<=p?"-"+k(-p,6):p},a:function(){return w[g.getUTCDay()]},b:function(){return b[g.getUTCMonth()]},d:function(){return D(g.getUTCDate())},e:function(){return function(p){return(9<p?"":" ")+(0|p)}(g.getUTCDate())},m:function(){return D(g.getUTCMonth()+1)}};return function p(S){return S.replace(/%./g,function(v){var T=v[1],B=C[T],T=d[T];return B?p(B):T?T():v})}(y||l)},c.writeInt64BE=U(0,1,2,3,0,4),c.writeInt64LE=U(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),b=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],w=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],C={"%":"%",F:"%Y-%m-%d",n:`
`,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return A;function A(y,f,g){var d=this;if(!(d instanceof A))return new A(y,f,g);d.time=+y||0,d.nano=+f||0,d.year=+g||0,x(d)}function x(y){var f,g,d,p=y.year,S=y.time,v=y.nano,B=((v<0||a<=v)&&(v-=(g=Math.floor(v/a))*a,S+=g,g=1),p%t);return(S<-i||i<S||B)&&((f=h(S/o))&&(p+=f*t,S-=f*o),(d=I(S)).setUTCFullYear(B+d.getUTCFullYear()),d=(S=+d)+(f=h((p-=B)/t))*o,f&&-i<=d&&d<=i&&(p-=f*t,S=d),g=1),g&&(y.year=p,y.time=S,y.nano=v),y}function I(y){var f=new Date(0);return f.setTime(y),f}function L(p,d){p=+p||0;var g=h((d=(d|0)*s)/n)+h(p/n),d=d%n+p%n,p=h(d/n);return p&&(g+=p,d-=p*n),new A(1e3*d,0,g*t)}function U(y,f,g,d,p,S){return function(B,T){var K=x(this);B=B||new Array(8),E(B,T|=0);var H=Math.floor(K.time/1e3),K=K.year*(r*e/t),R=h(K/s)+h(H/s),K=K%s+H%s,H=Math.floor(K/s);return H&&(R+=H,K-=H*s),v(B,T+p,R),v(B,T+S,K),B};function v(B,T,R){B[T+y]=R>>24&255,B[T+f]=R>>16&255,B[T+g]=R>>8&255,B[T+d]=255&R}}function P(y,f,g,d,p,S){return function(B,T){E(B,T|=0);var R=v(B,T+p);return L(v(B,T+S),R)};function v(B,T){return 16777216*B[T+y]+(B[T+f]<<16|B[T+g]<<8|B[T+d])}}function E(y,f){if(y=y&&y.length,y==null)throw new TypeError("Invalid Buffer");if(y<f+8)throw new RangeError("Out of range")}function D(y){return(9<y?"":"0")+(0|y)}function k(y,f){return(u+(0|y)).substr(-f)}}()});var cd={};ht(cd,{createIPNSRecord:()=>id,createIPNSRecordWithExpiration:()=>sd,extractPublicKeyFromIPNSRecord:()=>fc,marshalIPNSRecord:()=>hc,multihashFromIPNSRoutingKey:()=>yc,multihashToIPNSRoutingKey:()=>mc,namespace:()=>wc,namespaceLength:()=>od,unmarshalIPNSRecord:()=>pc});var Q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ve=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Ur=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Lr=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var _n={};ht(_n,{base58btc:()=>X,base58flickr:()=>Rc});var ld=new Uint8Array(0);function ni(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Ft(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function oi(e){return new TextEncoder().encode(e)}function ii(e){return new TextDecoder().decode(e)}function Uc(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=e.length,u=e.charAt(0),h=Math.log(a)/Math.log(256),c=Math.log(256)/Math.log(a);function l(C){if(C instanceof Uint8Array||(ArrayBuffer.isView(C)?C=new Uint8Array(C.buffer,C.byteOffset,C.byteLength):Array.isArray(C)&&(C=Uint8Array.from(C))),!(C instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(C.length===0)return"";for(var A=0,x=0,I=0,L=C.length;I!==L&&C[I]===0;)I++,A++;for(var U=(L-I)*c+1>>>0,P=new Uint8Array(U);I!==L;){for(var E=C[I],D=0,k=U-1;(E!==0||D<x)&&k!==-1;k--,D++)E+=256*P[k]>>>0,P[k]=E%a>>>0,E=E/a>>>0;if(E!==0)throw new Error("Non-zero carry");x=D,I++}for(var y=U-x;y!==U&&P[y]===0;)y++;for(var f=u.repeat(A);y<U;++y)f+=e.charAt(P[y]);return f}function b(C){if(typeof C!="string")throw new TypeError("Expected String");if(C.length===0)return new Uint8Array;var A=0;if(C[A]!==" "){for(var x=0,I=0;C[A]===u;)x++,A++;for(var L=(C.length-A)*h+1>>>0,U=new Uint8Array(L);C[A];){var P=r[C.charCodeAt(A)];if(P===255)return;for(var E=0,D=L-1;(P!==0||E<I)&&D!==-1;D--,E++)P+=a*U[D]>>>0,U[D]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");I=E,A++}if(C[A]!==" "){for(var k=L-I;k!==L&&U[k]===0;)k++;for(var y=new Uint8Array(x+(L-k)),f=x;k!==L;)y[f++]=U[k++];return y}}}function w(C){var A=b(C);if(A)return A;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:b,decode:w}}var Lc=Uc,Dc=Lc,ai=Dc;var vn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Cn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ci(this,t)}},Tn=class{decoders;constructor(t){this.decoders=t}or(t){return ci(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ci(e,t){return new Tn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var In=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new vn(t,r,n),this.decoder=new Cn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ce({name:e,prefix:t,encode:r,decode:n}){return new In(e,t,r,n)}function Wt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=ai(r,e);return Ce({prefix:t,name:e,encode:n,decode:i=>Ft(o(i))})}function kc(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,u=0;for(let h=0;h<o;++h){let c=t[e[h]];if(c===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|c,s+=r,s>=8&&(s-=8,i[u++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Nc(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let u=0;u<e.length;++u)for(a=a<<8|e[u],s+=8;s>r;)s-=r,i+=t[o&a>>s];if(s!==0&&(i+=t[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function Kc(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function Z({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Kc(n);return Ce({prefix:t,name:e,encode(i){return Nc(i,n,r)},decode(i){return kc(i,o,r,e)}})}var X=Wt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Rc=Wt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Un={};ht(Un,{base32:()=>Xt,base32hex:()=>Mc,base32hexpad:()=>Hc,base32hexpadupper:()=>qc,base32hexupper:()=>Vc,base32pad:()=>Oc,base32padupper:()=>Fc,base32upper:()=>Pc,base32z:()=>zc});var Xt=Z({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Pc=Z({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Oc=Z({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Fc=Z({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Mc=Z({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Vc=Z({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Hc=Z({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qc=Z({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),zc=Z({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ln={};ht(Ln,{base36:()=>Jt,base36upper:()=>$c});var Jt=Wt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),$c=Wt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Gc=li,ui=128,jc=127,Zc=~jc,Yc=Math.pow(2,31);function li(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Yc;)t[r++]=e&255|ui,e/=128;for(;e&Zc;)t[r++]=e&255|ui,e>>>=7;return t[r]=e|0,li.bytes=r-n+1,t}var Wc=Dn,Xc=128,fi=127;function Dn(e,n){var r=0,n=n||0,o=0,i=n,s,a=e.length;do{if(i>=a)throw Dn.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&fi)<<o:(s&fi)*Math.pow(2,o),o+=7}while(s>=Xc);return Dn.bytes=i-n,r}var Jc=Math.pow(2,7),Qc=Math.pow(2,14),tu=Math.pow(2,21),eu=Math.pow(2,28),ru=Math.pow(2,35),nu=Math.pow(2,42),ou=Math.pow(2,49),iu=Math.pow(2,56),su=Math.pow(2,63),au=function(e){return e<Jc?1:e<Qc?2:e<tu?3:e<eu?4:e<ru?5:e<nu?6:e<ou?7:e<iu?8:e<su?9:10},cu={encode:Gc,decode:Wc,encodingLength:au},uu=cu,tr=uu;function er(e,t=0){return[tr.decode(e,t),tr.decode.bytes]}function Te(e,t,r=0){return tr.encode(e,t,r),t}function Ie(e){return tr.encodingLength(e)}function _t(e,t){let r=t.byteLength,n=Ie(e),o=n+Ie(r),i=new Uint8Array(o+r);return Te(e,i,0),Te(r,i,n),i.set(t,o),new _e(e,r,t,i)}function kr(e){let t=Ft(e),[r,n]=er(t),[o,i]=er(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new _e(r,o,s,t)}function di(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&ni(e.bytes,r.bytes)}}var _e=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function hi(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return lu(r,kn(e),t??X.encoder);default:return du(r,kn(e),t??Xt.encoder)}}var pi=new WeakMap;function kn(e){let t=pi.get(e);if(t==null){let r=new Map;return pi.set(e,r),r}return t}var nt=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,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:t,multihash:r}=this;if(t!==rr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==hu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=_t(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&di(t.multihash,n.multihash)}toString(t){return hi(this,t)}toJSON(){return{"/":hi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new e(n,o,i,s??mi(n,o,i.bytes))}else if(r[pu]===!0){let{version:n,multihash:o,code:i}=r,s=kr(o);return e.create(n,i,s)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==rr)throw new Error(`Version 0 CID must use dag-pb (code: ${rr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=mi(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,rr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Ft(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new _e(r.multihashCode,r.digestSize,i,o);return[r.version===0?e.createV0(s):e.createV1(r.codec,s),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,b]=er(t.subarray(r));return r+=b,l},o=n(),i=rr;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),u=n(),h=r+u,c=h-s;return{version:o,codec:i,multihashCode:a,digestSize:u,multihashSize:c,size:h}}static parse(t,r){let[n,o]=fu(t,r),i=e.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return kn(i).set(n,t),i}};function fu(e,t){switch(e[0]){case"Q":{let r=t??X;return[X.prefix,r.decode(`${X.prefix}${e}`)]}case X.prefix:{let r=t??X;return[X.prefix,r.decode(e)]}case Xt.prefix:{let r=t??Xt;return[Xt.prefix,r.decode(e)]}case Jt.prefix:{let r=t??Jt;return[Jt.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function lu(e,t,r){let{prefix:n}=r;if(n!==X.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o}function du(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o}var rr=112,hu=18;function mi(e,t,r){let n=Ie(e),o=n+Ie(t),i=new Uint8Array(o+r.byteLength);return Te(e,i,0),Te(t,i,n),i.set(r,o),i}var pu=Symbol.for("@ipld/js-cid/CID");var Nn={};ht(Nn,{identity:()=>de});var yi=0,mu="identity",gi=Ft;function yu(e){return _t(yi,gi(e))}var de={code:yi,name:mu,encode:gi,digest:yu};function pt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Mt(e=0){return new Uint8Array(e)}function gt(e=0){return new Uint8Array(e)}function Qt(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=gt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var bi=Symbol.for("@achingbrain/uint8arraylist");function xi(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Nr(e){return!!e?.[bi]}var xt=class e{bufs;length;[bi]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Nr(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Nr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=xi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=xi(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Nr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Qt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Qt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),i=new e;return i.length=o,i.bufs=[...n],i}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,u=a+s.byteLength;if(o=u,t>=u)continue;let h=t>=a&&t<u,c=r>a&&r<=u;if(h&&c){if(t===a&&r===u){n.push(s);break}let l=t-a;n.push(s.subarray(l,l+(r-t)));break}if(h){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(c){if(r===u){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Nr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,u=this.byteLength-n.byteLength,h=n.byteLength-1,c;for(let l=r;l<=u;l+=c){c=0;for(let b=h;b>=0;b--){let w=this.get(l+b);if(n[b]!==w){c=Math.max(1,b-a[w]);break}}if(c===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=gt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Mt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Mt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Mt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=gt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Mt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Mt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Mt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Mt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Mt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!pt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};var Kn={};ht(Kn,{base10:()=>gu});var gu=Wt({prefix:"9",name:"base10",alphabet:"0123456789"});var Rn={};ht(Rn,{base16:()=>xu,base16upper:()=>bu});var xu=Z({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),bu=Z({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Pn={};ht(Pn,{base2:()=>wu});var wu=Z({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var On={};ht(On,{base256emoji:()=>vu});var wi=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}"),Eu=wi.reduce((e,t,r)=>(e[r]=t,e),[]),Su=wi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Au(e){return e.reduce((t,r)=>(t+=Eu[r],t),"")}function Bu(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Su[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var vu=Ce({prefix:"\u{1F680}",name:"base256emoji",encode:Au,decode:Bu});var Mn={};ht(Mn,{base64:()=>Fn,base64pad:()=>Cu,base64url:()=>Tu,base64urlpad:()=>Iu});var Fn=Z({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Cu=Z({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Tu=Z({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Iu=Z({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Vn={};ht(Vn,{base8:()=>_u});var _u=Z({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Hn={};ht(Hn,{identity:()=>Uu});var Uu=Ce({prefix:"\0",name:"identity",encode:e=>ii(e),decode:e=>oi(e)});var Zd=new TextEncoder,Yd=new TextDecoder;var Gn={};ht(Gn,{sha256:()=>$n,sha512:()=>ku});function zn({name:e,code:t,encode:r}){return new qn(e,t,r)}var qn=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?_t(this.code,r):r.then(n=>_t(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Si(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var $n=zn({name:"sha2-256",code:18,encode:Si("SHA-256")}),ku=zn({name:"sha2-512",code:19,encode:Si("SHA-512")});var jn={...Hn,...Pn,...Vn,...Kn,...Rn,...Un,...Ln,..._n,...Mn,...On},ah={...Gn,...Nn};function Bi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Ai=Bi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Zn=Bi("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=gt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Nu={utf8:Ai,"utf-8":Ai,hex:jn.base16,latin1:Zn,ascii:Zn,binary:Zn,...jn},Kr=Nu;function q(e,t="utf8"){let r=Kr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function Y(e,t="utf8"){let r=Kr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Ku=parseInt("11111",2),Yn=parseInt("10000000",2),Ru=parseInt("01111111",2),vi={0:nr,1:nr,2:Pu,3:Mu,4:Vu,5:Fu,6:Ou,16:nr,22:nr,48:nr};function Vt(e,t={offset:0}){let r=e[t.offset]&Ku;if(t.offset++,vi[r]!=null)return vi[r](e,t);throw new Error("No decoder for tag "+r)}function or(e,t){let r=0;if((e[t.offset]&Yn)===Yn){let n=e[t.offset]&Ru,o="0x";t.offset++;for(let i=0;i<n;i++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function nr(e,t){or(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Vt(e,t);if(n===null)break;r.push(n)}return r}function Pu(e,t){let r=or(e,t),n=t.offset,o=t.offset+r,i=[];for(let s=n;s<o;s++)s===n&&e[s]===0||i.push(e[s]);return t.offset+=r,Uint8Array.from(i)}function Ou(e,t){let r=or(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,u=[];for(;t.offset<n;){let h=e[t.offset];if(t.offset++,u.push(h&127),h<128){u.reverse();let c=0;for(let l=0;l<u.length;l++)c+=u[l]<<l*7;a+=`.${c}`,u=[]}}return a}function Fu(e,t){return t.offset++,null}function Mu(e,t){let r=or(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Vu(e,t){let r=or(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Hu(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new xt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Wn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Hu(e.byteLength);return new xt(Uint8Array.from([t.byteLength|Yn]),t)}function mt(e){let t=new xt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new xt(Uint8Array.from([2]),Wn(t),t)}function Rr(e){let t=Uint8Array.from([0]),r=new xt(t,e);return new xt(Uint8Array.from([3]),Wn(r),r)}function te(e,t=48){let r=new xt;for(let n of e)r.append(n);return new xt(Uint8Array.from([t]),Wn(r),r)}async function Ci(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),i}var qu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),zu=Uint8Array.from([6,5,43,129,4,0,34]),$u=Uint8Array.from([6,5,43,129,4,0,35]),Gu={ext:!0,kty:"EC",crv:"P-256"},ju={ext:!0,kty:"EC",crv:"P-384"},Zu={ext:!0,kty:"EC",crv:"P-521"},Xn=32,Jn=48,Qn=66;function Ti(e){let t=Vt(e);return Ii(t)}function Ii(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Xn*2+1)return n=Y(t.subarray(r,r+Xn),"base64url"),o=Y(t.subarray(r+Xn),"base64url"),new Le({...Gu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Jn*2+1)return n=Y(t.subarray(r,r+Jn),"base64url"),o=Y(t.subarray(r+Jn),"base64url"),new Le({...ju,key_ops:["verify"],x:n,y:o});if(t.byteLength===Qn*2+1)return n=Y(t.subarray(r,r+Qn),"base64url"),o=Y(t.subarray(r+Qn),"base64url"),new Le({...Zu,key_ops:["verify"],x:n,y:o});throw new Q(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function _i(e){return te([mt(Uint8Array.from([1])),te([Yu(e.crv)],160),te([Rr(new xt(Uint8Array.from([4]),q(e.x??"","base64url"),q(e.y??"","base64url")))],161)]).subarray()}function Yu(e){if(e==="P-256")return qu;if(e==="P-384")return zu;if(e==="P-521")return $u;throw new Q(`Invalid curve ${e}`)}var Le=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=_i(this.jwk)),this._raw}toMultihash(){return de.digest(ee(this))}toCID(){return nt.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}async verify(t,r,n){return Ci(this.jwk,r,t,n)}};var he=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function ke(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function ir(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function at(e,...t){if(!ke(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Li(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");ir(e.outputLen),ir(e.blockLen)}function Ne(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Di(e,t){at(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function qt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Pr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ut(e,t){return e<<32-t|e>>>t}var ki=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Wu=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Kt(e){if(at(e),ki)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Wu[e[r]];return t}var Ht={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ui(e){if(e>=Ht._0&&e<=Ht._9)return e-Ht._0;if(e>=Ht.A&&e<=Ht.F)return e-(Ht.A-10);if(e>=Ht.a&&e<=Ht.f)return e-(Ht.a-10)}function Ke(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ki)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=Ui(e.charCodeAt(i)),a=Ui(e.charCodeAt(i+1));if(s===void 0||a===void 0){let u=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+u+'" at index '+i)}n[o]=s*16+a}return n}function Ni(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function sr(e){return typeof e=="string"&&(e=Ni(e)),at(e),e}function bt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];at(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let i=e[n];r.set(i,o),o+=i.length}return r}var De=class{};function to(e){let t=n=>e().update(sr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function ar(e=32){if(he&&typeof he.getRandomValues=="function")return he.getRandomValues(new Uint8Array(e));if(he&&typeof he.randomBytes=="function")return Uint8Array.from(he.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Xu(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),a=Number(r&i),u=n?4:0,h=n?0:4;e.setUint32(t+u,s,n),e.setUint32(t+h,a,n)}function Ki(e,t,r){return e&t^~e&r}function Ri(e,t,r){return e&t^e&r^t&r}var cr=class extends De{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Pr(this.buffer)}update(t){Ne(this),t=sr(t),at(t);let{view:r,buffer:n,blockLen:o}=this,i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let u=Pr(t);for(;o<=i-s;s+=o)this.process(u,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ne(this),Di(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,qt(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)r[l]=0;Xu(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=Pr(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let h=u/4,c=this.get();if(h>c.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<h;l++)a.setUint32(4*l,c[l],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return t.destroyed=s,t.finished=i,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},zt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ot=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Or=BigInt(4294967295),Pi=BigInt(32);function Ju(e,t=!1){return t?{h:Number(e&Or),l:Number(e>>Pi&Or)}:{h:Number(e>>Pi&Or)|0,l:Number(e&Or)|0}}function Oi(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:a}=Ju(e[i],t);[n[i],o[i]]=[s,a]}return[n,o]}var eo=(e,t,r)=>e>>>r,ro=(e,t,r)=>e<<32-r|t>>>r,pe=(e,t,r)=>e>>>r|t<<32-r,me=(e,t,r)=>e<<32-r|t>>>r,ur=(e,t,r)=>e<<64-r|t>>>r-32,fr=(e,t,r)=>e>>>r-32|t<<64-r;function Rt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Fi=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Mi=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Vi=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Hi=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,qi=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),zi=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var tf=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),re=new Uint32Array(64),Fr=class extends cr{constructor(t=32){super(64,t,8,!1),this.A=zt[0]|0,this.B=zt[1]|0,this.C=zt[2]|0,this.D=zt[3]|0,this.E=zt[4]|0,this.F=zt[5]|0,this.G=zt[6]|0,this.H=zt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:a,H:u}=this;return[t,r,n,o,i,s,a,u]}set(t,r,n,o,i,s,a,u){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=u|0}process(t,r){for(let l=0;l<16;l++,r+=4)re[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let b=re[l-15],w=re[l-2],C=Ut(b,7)^Ut(b,18)^b>>>3,A=Ut(w,17)^Ut(w,19)^w>>>10;re[l]=A+re[l-7]+C+re[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:u,G:h,H:c}=this;for(let l=0;l<64;l++){let b=Ut(a,6)^Ut(a,11)^Ut(a,25),w=c+b+Ki(a,u,h)+tf[l]+re[l]|0,A=(Ut(n,2)^Ut(n,13)^Ut(n,22))+Ri(n,o,i)|0;c=h,h=u,u=a,a=s+w|0,s=i,i=o,o=n,n=w+A|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,u=u+this.F|0,h=h+this.G|0,c=c+this.H|0,this.set(n,o,i,s,a,u,h,c)}roundClean(){qt(re)}destroy(){this.set(0,0,0,0,0,0,0,0),qt(this.buffer)}};var $i=Oi(["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(e=>BigInt(e))),ef=$i[0],rf=$i[1],ne=new Uint32Array(80),oe=new Uint32Array(80),no=class extends cr{constructor(t=64){super(128,t,16,!1),this.Ah=ot[0]|0,this.Al=ot[1]|0,this.Bh=ot[2]|0,this.Bl=ot[3]|0,this.Ch=ot[4]|0,this.Cl=ot[5]|0,this.Dh=ot[6]|0,this.Dl=ot[7]|0,this.Eh=ot[8]|0,this.El=ot[9]|0,this.Fh=ot[10]|0,this.Fl=ot[11]|0,this.Gh=ot[12]|0,this.Gl=ot[13]|0,this.Hh=ot[14]|0,this.Hl=ot[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:u,Eh:h,El:c,Fh:l,Fl:b,Gh:w,Gl:C,Hh:A,Hl:x}=this;return[t,r,n,o,i,s,a,u,h,c,l,b,w,C,A,x]}set(t,r,n,o,i,s,a,u,h,c,l,b,w,C,A,x){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=u|0,this.Eh=h|0,this.El=c|0,this.Fh=l|0,this.Fl=b|0,this.Gh=w|0,this.Gl=C|0,this.Hh=A|0,this.Hl=x|0}process(t,r){for(let U=0;U<16;U++,r+=4)ne[U]=t.getUint32(r),oe[U]=t.getUint32(r+=4);for(let U=16;U<80;U++){let P=ne[U-15]|0,E=oe[U-15]|0,D=pe(P,E,1)^pe(P,E,8)^eo(P,E,7),k=me(P,E,1)^me(P,E,8)^ro(P,E,7),y=ne[U-2]|0,f=oe[U-2]|0,g=pe(y,f,19)^ur(y,f,61)^eo(y,f,6),d=me(y,f,19)^fr(y,f,61)^ro(y,f,6),p=Vi(k,d,oe[U-7],oe[U-16]),S=Hi(p,D,g,ne[U-7],ne[U-16]);ne[U]=S|0,oe[U]=p|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:u,Dh:h,Dl:c,Eh:l,El:b,Fh:w,Fl:C,Gh:A,Gl:x,Hh:I,Hl:L}=this;for(let U=0;U<80;U++){let P=pe(l,b,14)^pe(l,b,18)^ur(l,b,41),E=me(l,b,14)^me(l,b,18)^fr(l,b,41),D=l&w^~l&A,k=b&C^~b&x,y=qi(L,E,k,rf[U],oe[U]),f=zi(y,I,P,D,ef[U],ne[U]),g=y|0,d=pe(n,o,28)^ur(n,o,34)^ur(n,o,39),p=me(n,o,28)^fr(n,o,34)^fr(n,o,39),S=n&i^n&a^i&a,v=o&s^o&u^s&u;I=A|0,L=x|0,A=w|0,x=C|0,w=l|0,C=b|0,{h:l,l:b}=Rt(h|0,c|0,f|0,g|0),h=a|0,c=u|0,a=i|0,u=s|0,i=n|0,s=o|0;let B=Fi(g,p,v);n=Mi(B,f,d,S),o=B|0}({h:n,l:o}=Rt(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Rt(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:u}=Rt(this.Ch|0,this.Cl|0,a|0,u|0),{h,l:c}=Rt(this.Dh|0,this.Dl|0,h|0,c|0),{h:l,l:b}=Rt(this.Eh|0,this.El|0,l|0,b|0),{h:w,l:C}=Rt(this.Fh|0,this.Fl|0,w|0,C|0),{h:A,l:x}=Rt(this.Gh|0,this.Gl|0,A|0,x|0),{h:I,l:L}=Rt(this.Hh|0,this.Hl|0,I|0,L|0),this.set(n,o,i,s,a,u,h,c,l,b,w,C,A,x,I,L)}roundClean(){qt(ne,oe)}destroy(){qt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Mr=to(()=>new Fr);var Gi=to(()=>new no);var so=BigInt(0),io=BigInt(1);function $t(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}function lr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function ji(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?so:BigInt("0x"+e)}function Re(e){return ji(Kt(e))}function ye(e){return at(e),ji(Kt(Uint8Array.from(e).reverse()))}function Vr(e,t){return Ke(e.toString(16).padStart(t*2,"0"))}function Pe(e,t){return Vr(e,t).reverse()}function $(e,t,r){let n;if(typeof t=="string")try{n=Ke(t)}catch(i){throw new Error(e+" must be hex string or Uint8Array, cause: "+i)}else if(ke(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}var oo=e=>typeof e=="bigint"&&so<=e;function Zi(e,t,r){return oo(e)&&oo(t)&&oo(r)&&t<=e&&e<r}function ie(e,t,r,n){if(!Zi(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Yi(e){let t;for(t=0;e>so;e>>=io,t+=1);return t}var ge=e=>(io<<BigInt(e))-io;function Wi(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=w=>new Uint8Array(w),o=w=>Uint8Array.of(w),i=n(e),s=n(e),a=0,u=()=>{i.fill(1),s.fill(0),a=0},h=(...w)=>r(s,i,...w),c=(w=n(0))=>{s=h(o(0),w),i=h(),w.length!==0&&(s=h(o(1),w),i=h())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let w=0,C=[];for(;w<t;){i=h();let A=i.slice();C.push(A),w+=i.length}return bt(...C)};return(w,C)=>{u(),c(w);let A;for(;!(A=C(l()));)c();return u(),A}}function se(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,i,s){let a=e[o];if(s&&a===void 0)return;let u=typeof a;if(u!==i||a===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${u}`)}Object.entries(t).forEach(([o,i])=>n(o,i,!1)),Object.entries(r).forEach(([o,i])=>n(o,i,!0))}function Oe(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let i=e(r,...n);return t.set(r,i),i}}var ft=BigInt(0),tt=BigInt(1),xe=BigInt(2),nf=BigInt(3),Qi=BigInt(4),ts=BigInt(5),es=BigInt(8);function j(e,t){let r=e%t;return r>=ft?r:t+r}function G(e,t,r){let n=e;for(;t-- >ft;)n*=n,n%=r;return n}function Xi(e,t){if(e===ft)throw new Error("invert: expected non-zero number");if(t<=ft)throw new Error("invert: expected positive modulus, got "+t);let r=j(e,t),n=t,o=ft,i=tt,s=tt,a=ft;for(;r!==ft;){let h=n/r,c=n%r,l=o-s*h,b=i-a*h;n=r,r=c,o=s,i=a,s=l,a=b}if(n!==tt)throw new Error("invert: does not exist");return j(o,t)}function rs(e,t){let r=(e.ORDER+tt)/Qi,n=e.pow(t,r);if(!e.eql(e.sqr(n),t))throw new Error("Cannot find square root");return n}function of(e,t){let r=(e.ORDER-ts)/es,n=e.mul(t,xe),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,xe),o),a=e.mul(i,e.sub(s,e.ONE));if(!e.eql(e.sqr(a),t))throw new Error("Cannot find square root");return a}function sf(e){if(e<BigInt(3))throw new Error("sqrt is not defined for small field");let t=e-tt,r=0;for(;t%xe===ft;)t/=xe,r++;let n=xe,o=Lt(e);for(;Ji(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return rs;let i=o.pow(n,t),s=(t+tt)/xe;return function(u,h){if(u.is0(h))return h;if(Ji(u,h)!==1)throw new Error("Cannot find square root");let c=r,l=u.mul(u.ONE,i),b=u.pow(h,t),w=u.pow(h,s);for(;!u.eql(b,u.ONE);){if(u.is0(b))return u.ZERO;let C=1,A=u.sqr(b);for(;!u.eql(A,u.ONE);)if(C++,A=u.sqr(A),C===c)throw new Error("Cannot find square root");let x=tt<<BigInt(c-C-1),I=u.pow(l,x);c=C,l=u.sqr(I),b=u.mul(b,l),w=u.mul(w,I)}return w}}function af(e){return e%Qi===nf?rs:e%es===ts?of:sf(e)}var ns=(e,t)=>(j(e,t)&tt)===tt,cf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ao(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=cf.reduce((n,o)=>(n[o]="function",n),t);return se(e,r),e}function uf(e,t,r){if(r<ft)throw new Error("invalid exponent, negatives unsupported");if(r===ft)return e.ONE;if(r===tt)return t;let n=e.ONE,o=t;for(;r>ft;)r&tt&&(n=e.mul(n,o)),o=e.sqr(o),r>>=tt;return n}function dr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((s,a,u)=>e.is0(a)?s:(n[u]=s,e.mul(s,a)),e.ONE),i=e.inv(o);return t.reduceRight((s,a,u)=>e.is0(a)?s:(n[u]=e.mul(s,n[u]),e.mul(s,a)),i),n}function Ji(e,t){let r=(e.ORDER-tt)/xe,n=e.pow(t,r),o=e.eql(n,e.ONE),i=e.eql(n,e.ZERO),s=e.eql(n,e.neg(e.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function os(e,t){t!==void 0&&ir(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Lt(e,t,r=!1,n={}){if(e<=ft)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,i;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let c=t;c.BITS&&(o=c.BITS),c.sqrt&&(i=c.sqrt),typeof c.isLE=="boolean"&&(r=c.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(i=n.sqrt);let{nBitLength:s,nByteLength:a}=os(e,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let u,h=Object.freeze({ORDER:e,isLE:r,BITS:s,BYTES:a,MASK:ge(s),ZERO:ft,ONE:tt,create:c=>j(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return ft<=c&&c<e},is0:c=>c===ft,isValidNot0:c=>!h.is0(c)&&h.isValid(c),isOdd:c=>(c&tt)===tt,neg:c=>j(-c,e),eql:(c,l)=>c===l,sqr:c=>j(c*c,e),add:(c,l)=>j(c+l,e),sub:(c,l)=>j(c-l,e),mul:(c,l)=>j(c*l,e),pow:(c,l)=>uf(h,c,l),div:(c,l)=>j(c*Xi(l,e),e),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>Xi(c,e),sqrt:i||(c=>(u||(u=af(e)),u(h,c))),toBytes:c=>r?Pe(c,a):Vr(c,a),fromBytes:c=>{if(c.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+c.length);return r?ye(c):Re(c)},invertBatch:c=>dr(h,c),cmov:(c,l,b)=>b?l:c});return Object.freeze(h)}function is(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function co(e){let t=is(e);return t+Math.ceil(t/2)}function ss(e,t,r=!1){let n=e.length,o=is(t),i=co(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?ye(