@libp2p/peer-id 6.0.0-55b7e5fea → 6.0.0
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 +10 -9
- package/dist/index.min.js.map +4 -4
- package/dist/typedoc-urls.json +12 -0
- package/package.json +3 -3
package/dist/index.min.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPeerId = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PPeerId=(()=>{var br=Object.defineProperty;var Ps=Object.getOwnPropertyDescriptor;var Ms=Object.getOwnPropertyNames;var Hs=Object.prototype.hasOwnProperty;var st=(e,t)=>{for(var r in t)br(e,r,{get:t[r],enumerable:!0})},qs=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ms(t))!Hs.call(e,o)&&o!==r&&br(e,o,{get:()=>t[o],enumerable:!(n=Ps(t,o))||n.enumerable});return e};var Vs=e=>qs(br({},"__esModule",{value:!0}),e);var la={};st(la,{peerIdFromCID:()=>ks,peerIdFromMultihash:()=>kn,peerIdFromPrivateKey:()=>fa,peerIdFromPublicKey:()=>Os,peerIdFromString:()=>aa});var bt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},He=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var qe=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Ve=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var zt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var yr=Symbol.for("@libp2p/peer-id");var Sr={};st(Sr,{base58btc:()=>Y,base58flickr:()=>Xs});var ba=new Uint8Array(0);function Hn(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 gt(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 qn(e){return new TextEncoder().encode(e)}function Vn(e){return new TextDecoder().decode(e)}function Zs(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 s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,c=e.charAt(0),f=Math.log(a)/Math.log(256),m=Math.log(256)/Math.log(a);function u(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var v=0,A=0,b=0,B=p.length;b!==B&&p[b]===0;)b++,v++;for(var y=(B-b)*m+1>>>0,I=new Uint8Array(y);b!==B;){for(var C=p[b],k=0,P=y-1;(C!==0||k<A)&&P!==-1;P--,k++)C+=256*I[P]>>>0,I[P]=C%a>>>0,C=C/a>>>0;if(C!==0)throw new Error("Non-zero carry");A=k,b++}for(var g=y-A;g!==y&&I[g]===0;)g++;for(var x=c.repeat(v);g<y;++g)x+=e.charAt(I[g]);return x}function w(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var v=0;if(p[v]!==" "){for(var A=0,b=0;p[v]===c;)A++,v++;for(var B=(p.length-v)*f+1>>>0,y=new Uint8Array(B);p[v];){var I=r[p.charCodeAt(v)];if(I===255)return;for(var C=0,k=B-1;(I!==0||C<b)&&k!==-1;k--,C++)I+=a*y[k]>>>0,y[k]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");b=C,v++}if(p[v]!==" "){for(var P=B-b;P!==B&&y[P]===0;)P++;for(var g=new Uint8Array(A+(B-P)),x=A;P!==B;)g[x++]=y[P++];return g}}}function S(p){var v=w(p);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:w,decode:S}}var Fs=Zs,js=Fs,Fn=js;var xr=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")}},gr=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 jn(this,t)}},wr=class{decoders;constructor(t){this.decoders=t}or(t){return jn(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 jn(e,t){return new wr({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Er=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 xr(t,r,n),this.decoder=new gr(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Yt({name:e,prefix:t,encode:r,decode:n}){return new Er(e,t,r,n)}function _t({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Fn(r,e);return Yt({prefix:t,name:e,encode:n,decode:s=>gt(o(s))})}function Gs(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let m=t[e[f]];if(m===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|m,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function zs(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Ys(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function G({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Ys(n);return Yt({prefix:t,name:e,encode(s){return zs(s,n,r)},decode(s){return Gs(s,o,r,e)}})}var Y=_t({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Xs=_t({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ar={};st(Ar,{base32:()=>Xt,base32hex:()=>Qs,base32hexpad:()=>ei,base32hexpadupper:()=>ri,base32hexupper:()=>ti,base32pad:()=>Ws,base32padupper:()=>Js,base32upper:()=>$s,base32z:()=>ni});var Xt=G({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),$s=G({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ws=G({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Js=G({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Qs=G({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ti=G({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ei=G({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ri=G({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ni=G({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Br={};st(Br,{base36:()=>de,base36upper:()=>oi});var de=_t({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),oi=_t({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var si=Yn,Gn=128,ii=127,ci=~ii,ai=Math.pow(2,31);function Yn(e,t,r){t=t||[],r=r||0;for(var n=r;e>=ai;)t[r++]=e&255|Gn,e/=128;for(;e&ci;)t[r++]=e&255|Gn,e>>>=7;return t[r]=e|0,Yn.bytes=r-n+1,t}var fi=vr,ui=128,zn=127;function vr(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw vr.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&zn)<<o:(i&zn)*Math.pow(2,o),o+=7}while(i>=ui);return vr.bytes=s-n,r}var hi=Math.pow(2,7),li=Math.pow(2,14),di=Math.pow(2,21),pi=Math.pow(2,28),mi=Math.pow(2,35),bi=Math.pow(2,42),yi=Math.pow(2,49),xi=Math.pow(2,56),gi=Math.pow(2,63),wi=function(e){return e<hi?1:e<li?2:e<di?3:e<pi?4:e<mi?5:e<bi?6:e<yi?7:e<xi?8:e<gi?9:10},Ei={encode:si,decode:fi,encodingLength:wi},Si=Ei,pe=Si;function me(e,t=0){return[pe.decode(e,t),pe.decode.bytes]}function $t(e,t,r=0){return pe.encode(e,t,r),t}function Wt(e){return pe.encodingLength(e)}function Qt(e,t){let r=t.byteLength,n=Wt(e),o=n+Wt(r),s=new Uint8Array(o+r);return $t(e,s,0),$t(r,s,n),s.set(t,o),new Jt(e,r,t,s)}function be(e){let t=gt(e),[r,n]=me(t),[o,s]=me(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Jt(r,o,i,t)}function Xn(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Hn(e.bytes,r.bytes)}}var Jt=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function $n(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Bi(r,Ir(e),t??Y.encoder);default:return vi(r,Ir(e),t??Xt.encoder)}}var Wn=new WeakMap;function Ir(e){let t=Wn.get(e);if(t==null){let r=new Map;return Wn.set(e,r),r}return t}var et=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!==ye)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ii)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=Qt(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&&Xn(t.multihash,n.multihash)}toString(t){return $n(this,t)}toJSON(){return{"/":$n(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:s,bytes:i}=r;return new e(n,o,s,i??Jn(n,o,s.bytes))}else if(r[Li]===!0){let{version:n,multihash:o,code:s}=r,i=be(o);return e.create(n,s,i)}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!==ye)throw new Error(`Version 0 CID must use dag-pb (code: ${ye}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Jn(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,ye,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=gt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Jt(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[u,w]=me(t.subarray(r));return r+=w,u},o=n(),s=ye;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),f=r+c,m=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:m,size:f}}static parse(t,r){let[n,o]=Ai(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ir(s).set(n,t),s}};function Ai(e,t){switch(e[0]){case"Q":{let r=t??Y;return[Y.prefix,r.decode(`${Y.prefix}${e}`)]}case Y.prefix:{let r=t??Y;return[Y.prefix,r.decode(e)]}case Xt.prefix:{let r=t??Xt;return[Xt.prefix,r.decode(e)]}case de.prefix:{let r=t??de;return[de.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 Bi(e,t,r){let{prefix:n}=r;if(n!==Y.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function vi(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var ye=112,Ii=18;function Jn(e,t,r){let n=Wt(e),o=n+Wt(t),s=new Uint8Array(o+r.byteLength);return $t(e,s,0),$t(t,s,n),s.set(r,o),s}var Li=Symbol.for("@ipld/js-cid/CID");var Lr={};st(Lr,{identity:()=>ht});var Qn=0,_i="identity",to=gt;function Di(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Qt(Qn,to(e))}var ht={code:Qn,name:_i,encode:to,digest:Di};function lt(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 wt(e=0){return new Uint8Array(e)}function it(e=0){return new Uint8Array(e)}function Fe(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=it(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var ro=Symbol.for("@achingbrain/uint8arraylist");function eo(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 je(e){return!!e?.[ro]}var ct=class e{bufs;length;[ro]=!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(je(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(je(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=eo(this.bufs,t);return r.buf[r.index]}set(t,r){let n=eo(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(je(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 Fe(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Fe(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_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 s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,m=r>a&&r<=c;if(f&&m){if(t===a&&r===c){n.push(i);break}let u=t-a;n.push(i.subarray(u,u+(r-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(m){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!je(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 s=256,i=new Int32Array(s);for(let u=0;u<s;u++)i[u]=-1;for(let u=0;u<o;u++)i[n[u]]=u;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,m;for(let u=r;u<=c;u+=m){m=0;for(let w=f;w>=0;w--){let S=this.get(u+w);if(n[w]!==S){m=Math.max(1,w-a[S]);break}}if(m===0)return u}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=it(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=wt(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=wt(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=wt(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=it(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=wt(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=wt(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=wt(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=wt(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=wt(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(!lt(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,s)=>o+s.byteLength,0)),n.length=r,n}};var _r={};st(_r,{base10:()=>Ti});var Ti=_t({prefix:"9",name:"base10",alphabet:"0123456789"});var Dr={};st(Dr,{base16:()=>Ui,base16upper:()=>Ri});var Ui=G({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ri=G({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Tr={};st(Tr,{base2:()=>Ci});var Ci=G({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ur={};st(Ur,{base256emoji:()=>Pi});var no=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}"),Ki=no.reduce((e,t,r)=>(e[r]=t,e),[]),Ni=no.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Oi(e){return e.reduce((t,r)=>(t+=Ki[r],t),"")}function ki(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ni[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Pi=Yt({prefix:"\u{1F680}",name:"base256emoji",encode:Oi,decode:ki});var Rr={};st(Rr,{base64:()=>Mi,base64pad:()=>Hi,base64url:()=>qi,base64urlpad:()=>Vi});var Mi=G({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Hi=G({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),qi=G({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Vi=G({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Cr={};st(Cr,{base8:()=>Zi});var Zi=G({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Kr={};st(Kr,{identity:()=>Fi});var Fi=Yt({prefix:"\0",name:"identity",encode:e=>Vn(e),decode:e=>qn(e)});var Qa=new TextEncoder,tf=new TextDecoder;var kr={};st(kr,{sha256:()=>xe,sha512:()=>Yi});var zi=20;function Or({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Nr(e,t,r,n,o)}var Nr=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??zi,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?oo(n,this.code,r?.truncate):n.then(o=>oo(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function oo(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Qt(t,e)}function io(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var xe=Or({name:"sha2-256",code:18,encode:io("SHA-256")}),Yi=Or({name:"sha2-512",code:19,encode:io("SHA-512")});var Pr={...Kr,...Tr,...Cr,..._r,...Dr,...Ar,...Br,...Sr,...Rr,...Ur},df={...kr,...Lr};function ao(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var co=ao("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Mr=ao("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=it(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Xi={utf8:co,"utf-8":co,hex:Pr.base16,latin1:Mr,ascii:Mr,binary:Mr,...Pr},Ge=Xi;function Dt(e,t="utf8"){let r=Ge[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function at(e,t="utf8"){let r=Ge[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var $i=parseInt("11111",2),Hr=parseInt("10000000",2),Wi=parseInt("01111111",2),fo={0:ge,1:ge,2:Ji,3:ec,4:rc,5:tc,6:Qi,16:ge,22:ge,48:ge};function qr(e,t={offset:0}){let r=e[t.offset]&$i;if(t.offset++,fo[r]!=null)return fo[r](e,t);throw new Error("No decoder for tag "+r)}function we(e,t){let r=0;if((e[t.offset]&Hr)===Hr){let n=e[t.offset]&Wi,o="0x";t.offset++;for(let s=0;s<n;s++,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 ge(e,t){we(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=qr(e,t);if(n===null)break;r.push(n)}return r}function Ji(e,t){let r=we(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Qi(e,t){let r=we(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let f=e[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let m=0;for(let u=0;u<c.length;u++)m+=c[u]<<u*7;a+=`.${m}`,c=[]}}return a}function tc(e,t){return t.offset++,null}function ec(e,t){let r=we(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 rc(e,t){let r=we(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function nc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ct;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Vr(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=nc(e.byteLength);return new ct(Uint8Array.from([t.byteLength|Hr]),t)}function uo(e){let t=new ct,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ct(Uint8Array.from([2]),Vr(t),t)}function ho(e){let t=Uint8Array.from([0]),r=new ct(t,e);return new ct(Uint8Array.from([3]),Vr(r),r)}function ze(e,t=48){let r=new ct;for(let n of e)r.append(n);return new ct(Uint8Array.from([t]),Vr(r),r)}async function lo(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 s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var oc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),sc=Uint8Array.from([6,5,43,129,4,0,34]),ic=Uint8Array.from([6,5,43,129,4,0,35]),cc={ext:!0,kty:"EC",crv:"P-256"},ac={ext:!0,kty:"EC",crv:"P-384"},fc={ext:!0,kty:"EC",crv:"P-521"},Zr=32,Fr=48,jr=66;function po(e){let t=qr(e);return mo(t)}function mo(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Zr*2+1)return n=at(t.subarray(r,r+Zr),"base64url"),o=at(t.subarray(r+Zr),"base64url"),new ee({...cc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Fr*2+1)return n=at(t.subarray(r,r+Fr),"base64url"),o=at(t.subarray(r+Fr),"base64url"),new ee({...ac,key_ops:["verify"],x:n,y:o});if(t.byteLength===jr*2+1)return n=at(t.subarray(r,r+jr),"base64url"),o=at(t.subarray(r+jr),"base64url"),new ee({...fc,key_ops:["verify"],x:n,y:o});throw new bt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function bo(e){return ze([uo(Uint8Array.from([1])),ze([uc(e.crv)],160),ze([ho(new ct(Uint8Array.from([4]),Dt(e.x??"","base64url"),Dt(e.y??"","base64url")))],161)]).subarray()}function uc(e){if(e==="P-256")return oc;if(e==="P-384")return sc;if(e==="P-521")return ic;throw new bt(`Invalid curve ${e}`)}var ee=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=bo(this.jwk)),this._raw}toMultihash(){return ht.digest(re(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}async verify(t,r,n){return lo(this.jwk,r,t,n)}};function Pt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function yt(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function O(e,t,r=""){let n=Pt(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function Ye(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");yt(e.outputLen),yt(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 xo(e,t){O(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function St(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Xe(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function dt(e,t){return e<<32-t|e>>>t}var go=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",hc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function At(e){if(O(e),go)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=hc[e[r]];return t}var Et={_0:48,_9:57,A:65,F:70,a:97,f:102};function yo(e){if(e>=Et._0&&e<=Et._9)return e-Et._0;if(e>=Et.A&&e<=Et.F)return e-(Et.A-10);if(e>=Et.a&&e<=Et.f)return e-(Et.a-10)}function Bt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(go)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,s=0;o<r;o++,s+=2){let i=yo(e.charCodeAt(s)),a=yo(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function ot(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];O(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function Gr(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function oe(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var zr=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function wo(e,t,r){return e&t^~e&r}function Eo(e,t,r){return e&t^e&r^t&r}var Ee=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Xe(this.buffer)}update(t){ne(this),O(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Xe(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ne(this),xo(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,St(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let u=i;u<o;u++)r[u]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Xe(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,m=this.get();if(f>m.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<f;u++)a.setUint32(4*u,m[u],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},vt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var J=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var $e=BigInt(4294967295),So=BigInt(32);function lc(e,t=!1){return t?{h:Number(e&$e),l:Number(e>>So&$e)}:{h:Number(e>>So&$e)|0,l:Number(e&$e)|0}}function Ao(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=lc(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Yr=(e,t,r)=>e>>>r,Xr=(e,t,r)=>e<<32-r|t>>>r,Mt=(e,t,r)=>e>>>r|t<<32-r,Ht=(e,t,r)=>e<<32-r|t>>>r,Se=(e,t,r)=>e<<64-r|t>>>r-32,Ae=(e,t,r)=>e>>>r-32|t<<64-r;function xt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Bo=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),vo=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Io=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Lo=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,_o=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Do=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var pc=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]),Tt=new Uint32Array(64),$r=class extends Ee{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let u=0;u<16;u++,r+=4)Tt[u]=t.getUint32(r,!1);for(let u=16;u<64;u++){let w=Tt[u-15],S=Tt[u-2],p=dt(w,7)^dt(w,18)^w>>>3,v=dt(S,17)^dt(S,19)^S>>>10;Tt[u]=v+Tt[u-7]+p+Tt[u-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:m}=this;for(let u=0;u<64;u++){let w=dt(a,6)^dt(a,11)^dt(a,25),S=m+w+wo(a,c,f)+pc[u]+Tt[u]|0,v=(dt(n,2)^dt(n,13)^dt(n,22))+Eo(n,o,s)|0;m=f,f=c,c=a,a=i+S|0,i=s,s=o,o=n,n=S+v|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,m=m+this.H|0,this.set(n,o,s,i,a,c,f,m)}roundClean(){St(Tt)}destroy(){this.set(0,0,0,0,0,0,0,0),St(this.buffer)}},Wr=class extends $r{A=vt[0]|0;B=vt[1]|0;C=vt[2]|0;D=vt[3]|0;E=vt[4]|0;F=vt[5]|0;G=vt[6]|0;H=vt[7]|0;constructor(){super(32)}};var To=Ao(["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))),mc=To[0],bc=To[1],Ut=new Uint32Array(80),Rt=new Uint32Array(80),Jr=class extends Ee{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:m,Fh:u,Fl:w,Gh:S,Gl:p,Hh:v,Hl:A}=this;return[t,r,n,o,s,i,a,c,f,m,u,w,S,p,v,A]}set(t,r,n,o,s,i,a,c,f,m,u,w,S,p,v,A){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=m|0,this.Fh=u|0,this.Fl=w|0,this.Gh=S|0,this.Gl=p|0,this.Hh=v|0,this.Hl=A|0}process(t,r){for(let y=0;y<16;y++,r+=4)Ut[y]=t.getUint32(r),Rt[y]=t.getUint32(r+=4);for(let y=16;y<80;y++){let I=Ut[y-15]|0,C=Rt[y-15]|0,k=Mt(I,C,1)^Mt(I,C,8)^Yr(I,C,7),P=Ht(I,C,1)^Ht(I,C,8)^Xr(I,C,7),g=Ut[y-2]|0,x=Rt[y-2]|0,K=Mt(g,x,19)^Se(g,x,61)^Yr(g,x,6),M=Ht(g,x,19)^Ae(g,x,61)^Xr(g,x,6),T=Io(P,M,Rt[y-7],Rt[y-16]),l=Lo(T,k,K,Ut[y-7],Ut[y-16]);Ut[y]=l|0,Rt[y]=T|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:m,Eh:u,El:w,Fh:S,Fl:p,Gh:v,Gl:A,Hh:b,Hl:B}=this;for(let y=0;y<80;y++){let I=Mt(u,w,14)^Mt(u,w,18)^Se(u,w,41),C=Ht(u,w,14)^Ht(u,w,18)^Ae(u,w,41),k=u&S^~u&v,P=w&p^~w&A,g=_o(B,C,P,bc[y],Rt[y]),x=Do(g,b,I,k,mc[y],Ut[y]),K=g|0,M=Mt(n,o,28)^Se(n,o,34)^Se(n,o,39),T=Ht(n,o,28)^Ae(n,o,34)^Ae(n,o,39),l=n&s^n&a^s&a,d=o&i^o&c^i&c;b=v|0,B=A|0,v=S|0,A=p|0,S=u|0,p=w|0,{h:u,l:w}=xt(f|0,m|0,x|0,K|0),f=a|0,m=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let h=Bo(K,T,d);n=vo(h,x,M,l),o=h|0}({h:n,l:o}=xt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=xt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=xt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:m}=xt(this.Dh|0,this.Dl|0,f|0,m|0),{h:u,l:w}=xt(this.Eh|0,this.El|0,u|0,w|0),{h:S,l:p}=xt(this.Fh|0,this.Fl|0,S|0,p|0),{h:v,l:A}=xt(this.Gh|0,this.Gl|0,v|0,A|0),{h:b,l:B}=xt(this.Hh|0,this.Hl|0,b|0,B|0),this.set(n,o,s,i,a,c,f,m,u,w,S,p,v,A,b,B)}roundClean(){St(Ut,Rt)}destroy(){St(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Qr=class extends Jr{Ah=J[0]|0;Al=J[1]|0;Bh=J[2]|0;Bl=J[3]|0;Ch=J[4]|0;Cl=J[5]|0;Dh=J[6]|0;Dl=J[7]|0;Eh=J[8]|0;El=J[9]|0;Fh=J[10]|0;Fl=J[11]|0;Gh=J[12]|0;Gl=J[13]|0;Hh=J[14]|0;Hl=J[15]|0;constructor(){super(64)}};var Uo=Gr(()=>new Wr,zr(1));var Ro=Gr(()=>new Qr,zr(3));var en=BigInt(0),tn=BigInt(1);function It(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function Co(e){if(typeof e=="bigint"){if(!We(e))throw new Error("positive bigint expected, got "+e)}else yt(e);return e}function Be(e){let t=Co(e).toString(16);return t.length&1?"0"+t:t}function Ko(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?en:BigInt("0x"+e)}function se(e){return Ko(At(e))}function qt(e){return Ko(At(Qe(O(e)).reverse()))}function Je(e,t){yt(t),e=Co(e);let r=Bt(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function rn(e,t){return Je(e,t).reverse()}function Qe(e){return Uint8Array.from(e)}var We=e=>typeof e=="bigint"&&en<=e;function yc(e,t,r){return We(e)&&We(t)&&We(r)&&t<=e&&e<r}function ve(e,t,r,n){if(!yc(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function nn(e){let t;for(t=0;e>en;e>>=tn,t+=1);return t}var Ie=e=>(tn<<BigInt(e))-tn;function No(e,t,r){if(yt(e,"hashLen"),yt(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=A=>new Uint8Array(A),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),f=n(e),m=0,u=()=>{c.fill(1),f.fill(0),m=0},w=(...A)=>r(f,ot(c,...A)),S=(A=o)=>{f=w(s,A),c=w(),A.length!==0&&(f=w(i,A),c=w())},p=()=>{if(m++>=a)throw new Error("drbg: tried max amount of iterations");let A=0,b=[];for(;A<t;){c=w();let B=c.slice();b.push(B),A+=c.length}return ot(...b)};return(A,b)=>{u(),S(A);let B;for(;!(B=b(p()));)S();return u(),B}}function Ct(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(s,i,a){let c=e[s];if(a&&c===void 0)return;let f=typeof c;if(f!==i||c===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${f}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(r,!0)}function ie(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var rt=BigInt(0),X=BigInt(1),Vt=BigInt(2),Po=BigInt(3),Mo=BigInt(4),Ho=BigInt(5),xc=BigInt(7),qo=BigInt(8),gc=BigInt(9),Vo=BigInt(16);function z(e,t){let r=e%t;return r>=rt?r:t+r}function V(e,t,r){let n=e;for(;t-- >rt;)n*=n,n%=r;return n}function Oo(e,t){if(e===rt)throw new Error("invert: expected non-zero number");if(t<=rt)throw new Error("invert: expected positive modulus, got "+t);let r=z(e,t),n=t,o=rt,s=X,i=X,a=rt;for(;r!==rt;){let f=n/r,m=n%r,u=o-i*f,w=s-a*f;n=r,r=m,o=i,s=a,i=u,a=w}if(n!==X)throw new Error("invert: does not exist");return z(o,t)}function sn(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Zo(e,t){let r=(e.ORDER+X)/Mo,n=e.pow(t,r);return sn(e,n,t),n}function wc(e,t){let r=(e.ORDER-Ho)/qo,n=e.mul(t,Vt),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,Vt),o),a=e.mul(s,e.sub(i,e.ONE));return sn(e,a,t),a}function Ec(e){let t=ce(e),r=Fo(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+xc)/Vo;return(a,c)=>{let f=a.pow(c,i),m=a.mul(f,n),u=a.mul(f,o),w=a.mul(f,s),S=a.eql(a.sqr(m),c),p=a.eql(a.sqr(u),c);f=a.cmov(f,m,S),m=a.cmov(w,u,p);let v=a.eql(a.sqr(m),c),A=a.cmov(f,m,v);return sn(a,A,c),A}}function Fo(e){if(e<Po)throw new Error("sqrt is not defined for small field");let t=e-X,r=0;for(;t%Vt===rt;)t/=Vt,r++;let n=Vt,o=ce(e);for(;ko(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Zo;let s=o.pow(n,t),i=(t+X)/Vt;return function(c,f){if(c.is0(f))return f;if(ko(c,f)!==1)throw new Error("Cannot find square root");let m=r,u=c.mul(c.ONE,s),w=c.pow(f,t),S=c.pow(f,i);for(;!c.eql(w,c.ONE);){if(c.is0(w))return c.ZERO;let p=1,v=c.sqr(w);for(;!c.eql(v,c.ONE);)if(p++,v=c.sqr(v),p===m)throw new Error("Cannot find square root");let A=X<<BigInt(m-p-1),b=c.pow(u,A);m=p,u=c.sqr(b),w=c.mul(w,u),S=c.mul(S,b)}return S}}function Sc(e){return e%Mo===Po?Zo:e%qo===Ho?wc:e%Vo===gc?Ec(e):Fo(e)}var jo=(e,t)=>(z(e,t)&X)===X,Ac=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function cn(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Ac.reduce((n,o)=>(n[o]="function",n),t);return Ct(e,r),e}function Bc(e,t,r){if(r<rt)throw new Error("invalid exponent, negatives unsupported");if(r===rt)return e.ONE;if(r===X)return t;let n=e.ONE,o=t;for(;r>rt;)r&X&&(n=e.mul(n,o)),o=e.sqr(o),r>>=X;return n}function Le(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),s),n}function ko(e,t){let r=(e.ORDER-X)/Vt,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function vc(e,t){t!==void 0&&yt(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var on=class{ORDER;BITS;BYTES;isLE;ZERO=rt;ONE=X;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=rt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=vc(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return z(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return rt<=t&&t<this.ORDER}is0(t){return t===rt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&X)===X}neg(t){return z(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return z(t*t,this.ORDER)}add(t,r){return z(t+r,this.ORDER)}sub(t,r){return z(t-r,this.ORDER)}mul(t,r){return z(t*r,this.ORDER)}pow(t,r){return Bc(this,t,r)}div(t,r){return z(t*Oo(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return Oo(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Sc(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?rn(t,this.BYTES):Je(t,this.BYTES)}fromBytes(t,r=!1){O(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(o);f.set(t,s?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?qt(t):se(t);if(a&&(c=z(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Le(this,t)}cmov(t,r,n){return n?r:t}};function ce(e,t={}){return new on(e,t)}function Go(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 an(e){let t=Go(e);return t+Math.ceil(t/2)}function fn(e,t,r=!1){O(e);let n=e.length,o=Go(t),s=an(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?qt(e):se(e),a=z(i,t-X)+X;return r?rn(a,o):Je(a,o)}var ae=BigInt(0),Zt=BigInt(1);function _e(e,t){let r=t.negate();return e?r:t}function Ft(e,t){let r=Le(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function $o(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function un(e,t){$o(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Ie(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function zo(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),c=e>>i;a>n&&(a-=s,c+=Zt);let f=t*n,m=f+Math.abs(a)-1,u=a===0,w=a<0,S=t%2!==0;return{nextN:c,offset:m,isZero:u,isNeg:w,isNegF:S,offsetF:f}}var hn=new WeakMap,Wo=new WeakMap;function ln(e){return Wo.get(e)||1}function Yo(e){if(e!==ae)throw new Error("invalid wNAF")}var fe=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>ae;)r&Zt&&(n=n.add(o)),o=o.double(),r>>=Zt;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=un(r,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let f=1;f<o;f++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=un(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:m,isNeg:u,isNegF:w,offsetF:S}=zo(n,a,i);n=c,m?s=s.add(_e(w,r[S])):o=o.add(_e(u,r[f]))}return Yo(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=un(t,this.bits);for(let i=0;i<s.windows&&n!==ae;i++){let{nextN:a,offset:c,isZero:f,isNeg:m}=zo(n,i,s);if(n=a,!f){let u=r[c];o=o.add(m?u.negate():u)}}return Yo(n),o}getPrecomputes(t,r,n){let o=hn.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),hn.set(r,o))),o}cached(t,r,n){let o=ln(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=ln(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){$o(r,this.bits),Wo.set(t,r),hn.delete(t)}hasCache(t){return ln(t)!==1}};function Jo(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>ae||n>ae;)r&Zt&&(s=s.add(o)),n&Zt&&(i=i.add(o)),o=o.double(),r>>=Zt,n>>=Zt;return{p1:s,p2:i}}function Xo(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return cn(t),t}else return ce(e,{isLE:r})}function tr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let f=t[c];if(!(typeof f=="bigint"&&f>ae))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Xo(t.p,r.Fp,n),s=Xo(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function er(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Kt=BigInt(0),$=BigInt(1),dn=BigInt(2),Ic=BigInt(8);function Lc(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),a=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,a)}function Qo(e,t={}){let r=tr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;Ct(t,{},{uvRatio:"function"});let a=dn<<BigInt(o.BYTES*8)-$,c=A=>n.create(A),f=t.uvRatio||((A,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(A,b))}}catch{return{isValid:!1,value:Kt}}});if(!Lc(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function m(A,b,B=!1){let y=B?$:Kt;return ve("coordinate "+A,b,y,a),b}function u(A){if(!(A instanceof p))throw new Error("EdwardsPoint expected")}let w=ie((A,b)=>{let{X:B,Y:y,Z:I}=A,C=A.is0();b==null&&(b=C?Ic:n.inv(I));let k=c(B*b),P=c(y*b),g=n.mul(I,b);if(C)return{x:Kt,y:$};if(g!==$)throw new Error("invZ was invalid");return{x:k,y:P}}),S=ie(A=>{let{a:b,d:B}=s;if(A.is0())throw new Error("bad point: ZERO");let{X:y,Y:I,Z:C,T:k}=A,P=c(y*y),g=c(I*I),x=c(C*C),K=c(x*x),M=c(P*b),T=c(x*c(M+g)),l=c(K+c(B*c(P*g)));if(T!==l)throw new Error("bad point: equation left != right (1)");let d=c(y*I),h=c(C*k);if(d!==h)throw new Error("bad point: equation left != right (2)");return!0});class p{static BASE=new p(s.Gx,s.Gy,$,c(s.Gx*s.Gy));static ZERO=new p(Kt,$,$,Kt);static Fp=n;static Fn=o;X;Y;Z;T;constructor(b,B,y,I){this.X=m("x",b),this.Y=m("y",B),this.Z=m("z",y,!0),this.T=m("t",I),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof p)throw new Error("extended point not allowed");let{x:B,y}=b||{};return m("x",B),m("y",y),new p(B,y,$,c(B*y))}static fromBytes(b,B=!1){let y=n.BYTES,{a:I,d:C}=s;b=Qe(O(b,y,"point")),It(B,"zip215");let k=Qe(b),P=b[y-1];k[y-1]=P&-129;let g=qt(k),x=B?a:n.ORDER;ve("point.y",g,Kt,x);let K=c(g*g),M=c(K-$),T=c(C*K-I),{isValid:l,value:d}=f(M,T);if(!l)throw new Error("bad point: invalid y coordinate");let h=(d&$)===$,E=(P&128)!==0;if(!B&&d===Kt&&E)throw new Error("bad point: x=0 and x_0=1");return E!==h&&(d=c(-d)),p.fromAffine({x:d,y:g})}static fromHex(b,B=!1){return p.fromBytes(Bt(b),B)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,B=!0){return v.createCache(this,b),B||this.multiply(dn),this}assertValidity(){S(this)}equals(b){u(b);let{X:B,Y:y,Z:I}=this,{X:C,Y:k,Z:P}=b,g=c(B*P),x=c(C*I),K=c(y*P),M=c(k*I);return g===x&&K===M}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:b}=s,{X:B,Y:y,Z:I}=this,C=c(B*B),k=c(y*y),P=c(dn*c(I*I)),g=c(b*C),x=B+y,K=c(c(x*x)-C-k),M=g+k,T=M-P,l=g-k,d=c(K*T),h=c(M*l),E=c(K*l),L=c(T*M);return new p(d,h,L,E)}add(b){u(b);let{a:B,d:y}=s,{X:I,Y:C,Z:k,T:P}=this,{X:g,Y:x,Z:K,T:M}=b,T=c(I*g),l=c(C*x),d=c(P*y*M),h=c(k*K),E=c((I+C)*(g+x)-T-l),L=h-d,D=h+d,U=c(l-B*T),_=c(E*L),R=c(D*U),N=c(E*U),Z=c(L*D);return new p(_,R,Z,N)}subtract(b){return this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:B,f:y}=v.cached(this,b,I=>Ft(p,I));return Ft(p,[B,y])[0]}multiplyUnsafe(b,B=p.ZERO){if(!o.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===Kt?p.ZERO:this.is0()||b===$?this:v.unsafe(this,b,y=>Ft(p,y),B)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return v.unsafe(this,s.n).is0()}toAffine(b){return w(this,b)}clearCofactor(){return i===$?this:this.multiplyUnsafe(i)}toBytes(){let{x:b,y:B}=this.toAffine(),y=n.toBytes(B);return y[y.length-1]|=b&$?128:0,y}toHex(){return At(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let v=new fe(p,o.BITS);return p.BASE.precompute(8),p}function ts(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');Ct(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,a=r.randomBytes||oe,c=r.adjustScalarBytes||(g=>g),f=r.domain||((g,x,K)=>{if(It(K,"phflag"),x.length||K)throw new Error("Contexts/pre-hash are not supported");return g});function m(g){return i.create(qt(g))}function u(g){let x=y.secretKey;O(g,y.secretKey,"secretKey");let K=O(t(g),2*x,"hashedSecretKey"),M=c(K.slice(0,x)),T=K.slice(x,2*x),l=m(M);return{head:M,prefix:T,scalar:l}}function w(g){let{head:x,prefix:K,scalar:M}=u(g),T=o.multiply(M),l=T.toBytes();return{head:x,prefix:K,scalar:M,point:T,pointBytes:l}}function S(g){return w(g).pointBytes}function p(g=Uint8Array.of(),...x){let K=ot(...x);return m(t(f(K,O(g,void 0,"context"),!!n)))}function v(g,x,K={}){g=O(g,void 0,"message"),n&&(g=n(g));let{prefix:M,scalar:T,pointBytes:l}=w(x),d=p(K.context,M,g),h=o.multiply(d).toBytes(),E=p(K.context,h,l,g),L=i.create(d+E*T);if(!i.isValid(L))throw new Error("sign failed: invalid s");let D=ot(h,i.toBytes(L));return O(D,y.signature,"result")}let A={zip215:!0};function b(g,x,K,M=A){let{context:T,zip215:l}=M,d=y.signature;g=O(g,d,"signature"),x=O(x,void 0,"message"),K=O(K,y.publicKey,"publicKey"),l!==void 0&&It(l,"zip215"),n&&(x=n(x));let h=d/2,E=g.subarray(0,h),L=qt(g.subarray(h,d)),D,U,_;try{D=e.fromBytes(K,l),U=e.fromBytes(E,l),_=o.multiplyUnsafe(L)}catch{return!1}if(!l&&D.isSmallOrder())return!1;let R=p(T,U.toBytes(),D.toBytes(),x);return U.add(D.multiplyUnsafe(R)).subtract(_).clearCofactor().is0()}let B=s.BYTES,y={secretKey:B,publicKey:B,signature:2*B,seed:B};function I(g=a(y.seed)){return O(g,y.seed,"seed")}function C(g){return Pt(g)&&g.length===i.BYTES}function k(g,x){try{return!!e.fromBytes(g,x)}catch{return!1}}let P={getExtendedPublicKey:w,randomSecretKey:I,isValidSecretKey:C,isValidPublicKey:k,toMontgomery(g){let{y:x}=e.fromBytes(g),K=y.publicKey,M=K===32;if(!M&&K!==57)throw new Error("only defined for 25519 and 448");let T=M?s.div($+x,$-x):s.div(x-$,x+$);return s.toBytes(T)},toMontgomerySecret(g){let x=y.secretKey;O(g,x);let K=t(g.subarray(0,x));return c(K).subarray(0,x)}};return Object.freeze({keygen:er(I,S),getPublicKey:S,sign:v,verify:b,utils:P,Point:e,lengths:y})}var _c=BigInt(1),es=BigInt(2);var Dc=BigInt(5),Tc=BigInt(8),pn=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Uc={p:pn,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Tc,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Rc(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=pn,a=e*e%s*e%s,c=V(a,es,s)*a%s,f=V(c,_c,s)*e%s,m=V(f,Dc,s)*f%s,u=V(m,t,s)*m%s,w=V(u,r,s)*u%s,S=V(w,n,s)*w%s,p=V(S,o,s)*S%s,v=V(p,o,s)*S%s,A=V(v,t,s)*m%s;return{pow_p_5_8:V(A,es,s)*e%s,b2:a}}function Cc(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var rs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Kc(e,t){let r=pn,n=z(t*t*t,r),o=z(n*n*t,r),s=Rc(e*o).pow_p_5_8,i=z(e*n*s,r),a=z(t*i*i,r),c=i,f=z(i*rs,r),m=a===e,u=a===z(-e,r),w=a===z(-e*rs,r);return m&&(i=c),(u||w)&&(i=f),jo(i,r)&&(i=z(-i,r)),{isValid:m||u,value:i}}var Nc=Qo(Uc,{uvRatio:Kc});function Oc(e){return ts(Nc,Ro,Object.assign({adjustScalarBytes:Cc},e))}var ns=Oc({});var De=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},rr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var os={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new rr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var nr=os;var or=32;var mn,kc=(async()=>{try{return await nr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Pc(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await nr.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await nr.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Mc(e,t,r){return ns.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function ss(e,t,r){return mn==null&&(mn=await kc),mn?Pc(e,t,r):Mc(e,t,r)}function sr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var ir=class{type="Ed25519";raw;constructor(t){this.raw=bn(t,or)}toMultihash(){return ht.digest(re(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=ss(this.raw,r,t);return sr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function cs(e){return e=bn(e,or),new ir(e)}function bn(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new bt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var qc=Math.pow(2,7),Vc=Math.pow(2,14),Zc=Math.pow(2,21),as=Math.pow(2,28),fs=Math.pow(2,35),us=Math.pow(2,42),hs=Math.pow(2,49),nt=128,Nt=127;function Te(e){if(e<qc)return 1;if(e<Vc)return 2;if(e<Zc)return 3;if(e<as)return 4;if(e<fs)return 5;if(e<us)return 6;if(e<hs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ls(e,t,r=0){switch(Te(e)){case 8:t[r++]=e&255|nt,e/=128;case 7:t[r++]=e&255|nt,e/=128;case 6:t[r++]=e&255|nt,e/=128;case 5:t[r++]=e&255|nt,e/=128;case 4:t[r++]=e&255|nt,e>>>=7;case 3:t[r++]=e&255|nt,e>>>=7;case 2:t[r++]=e&255|nt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function ds(e,t){let r=e[t],n=0;if(n+=r&Nt,r<nt||(r=e[t+1],n+=(r&Nt)<<7,r<nt)||(r=e[t+2],n+=(r&Nt)<<14,r<nt)||(r=e[t+3],n+=(r&Nt)<<21,r<nt)||(r=e[t+4],n+=(r&Nt)*as,r<nt)||(r=e[t+5],n+=(r&Nt)*fs,r<nt)||(r=e[t+6],n+=(r&Nt)*us,r<nt)||(r=e[t+7],n+=(r&Nt)*hs,r<nt))return n;throw new RangeError("Could not decode varint")}var yn=new Float32Array([-0]),Ot=new Uint8Array(yn.buffer);function ps(e,t,r){yn[0]=e,t[r]=Ot[0],t[r+1]=Ot[1],t[r+2]=Ot[2],t[r+3]=Ot[3]}function ms(e,t){return Ot[0]=e[t],Ot[1]=e[t+1],Ot[2]=e[t+2],Ot[3]=e[t+3],yn[0]}var xn=new Float64Array([-0]),tt=new Uint8Array(xn.buffer);function bs(e,t,r){xn[0]=e,t[r]=tt[0],t[r+1]=tt[1],t[r+2]=tt[2],t[r+3]=tt[3],t[r+4]=tt[4],t[r+5]=tt[5],t[r+6]=tt[6],t[r+7]=tt[7]}function ys(e,t){return tt[0]=e[t],tt[1]=e[t+1],tt[2]=e[t+2],tt[3]=e[t+3],tt[4]=e[t+4],tt[5]=e[t+5],tt[6]=e[t+6],tt[7]=e[t+7],xn[0]}var Fc=BigInt(Number.MAX_SAFE_INTEGER),jc=BigInt(Number.MIN_SAFE_INTEGER),ft=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return jt;if(t<Fc&&t>jc)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>xs&&(o=0n,++n>xs&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return jt;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):jt}},jt=new ft(0,0);jt.toBigInt=function(){return 0n};jt.zzEncode=jt.zzDecode=function(){return this};jt.length=function(){return 1};var xs=4294967296n;function gs(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function ws(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function gn(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function pt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function cr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var wn=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,pt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw pt(this,4);return cr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw pt(this,4);return cr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw pt(this,4);let t=ms(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw pt(this,4);let t=ys(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw pt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return ws(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw pt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw pt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new ft(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw pt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw pt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw pt(this,8);let t=cr(this.buf,this.pos+=4),r=cr(this.buf,this.pos+=4);return new ft(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=ds(this.buf,this.pos);return this.pos+=Te(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function En(e){return new wn(e instanceof Uint8Array?e:e.subarray())}function ar(e,t,r){let n=En(e);return t.decode(n,void 0,r)}function Sn(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return it(i);o+i>t&&(n=it(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Gt=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function An(){}var vn=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Gc=Sn();function zc(e){return globalThis.Buffer!=null?it(e):Gc(e)}var Re=class{len;head;tail;states;constructor(){this.len=0,this.head=new Gt(An,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Gt(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new In((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(fr,10,ft.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=ft.fromBigInt(t);return this._push(fr,r.length(),r)}uint64Number(t){return this._push(ls,Te(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=ft.fromBigInt(t).zzEncode();return this._push(fr,r.length(),r)}sint64Number(t){let r=ft.fromNumber(t).zzEncode();return this._push(fr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Bn,1,t?1:0)}fixed32(t){return this._push(Ue,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=ft.fromBigInt(t);return this._push(Ue,4,r.lo)._push(Ue,4,r.hi)}fixed64Number(t){let r=ft.fromNumber(t);return this._push(Ue,4,r.lo)._push(Ue,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ps,4,t)}double(t){return this._push(bs,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Bn,1,0):this.uint32(r)._push(Xc,r,t)}string(t){let r=gs(t);return r!==0?this.uint32(r)._push(gn,r,t):this._push(Bn,1,0)}fork(){return this.states=new vn(this),this.head=this.tail=new Gt(An,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 Gt(An,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=zc(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Bn(e,t,r){t[r]=e&255}function Yc(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var In=class extends Gt{next;constructor(t,r){super(Yc,t,r),this.next=void 0}};function fr(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Ue(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Xc(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Re.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push($c,t,e),this},Re.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Wc,t,e),this});function $c(e,t,r){t.set(e,r)}function Wc(e,t,r){e.length<40?gn(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Dt(e),r)}function Ln(){return new Re}function ur(e,t){let r=Ln();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var ue;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(ue||(ue={}));function hr(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function _n(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return hr("enum",ue.VARINT,r,n)}function lr(e,t){return hr("message",ue.LENGTH_DELIMITED,e,t)}var ut;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(ut||(ut={}));var Dn;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Dn||(Dn={}));(function(e){e.codec=()=>_n(Dn)})(ut||(ut={}));var Ce;(function(e){let t;e.codec=()=>(t==null&&(t=lr((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),ut.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=ut.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>ur(r,e.codec()),e.decode=(r,n)=>ar(r,e.codec(),n)})(Ce||(Ce={}));var Tn;(function(e){let t;e.codec=()=>(t==null&&(t=lr((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),ut.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=ut.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>ur(r,e.codec()),e.decode=(r,n)=>ar(r,e.codec(),n)})(Tn||(Tn={}));var dr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(Ye(t),O(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),St(o)}update(t){return ne(this),this.iHash.update(t),this}digestInto(t){ne(this),O(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Un=(e,t,r)=>new dr(e,t).update(r).digest();Un.create=(e,t)=>new dr(e,t);var Ss=(e,t)=>(e+(e>=0?t:-t)/As)/t;function Qc(e,t,r){let[[n,o],[s,i]]=t,a=Ss(i*e,r),c=Ss(-o*e,r),f=e-a*n-c*s,m=-a*o-c*i,u=f<Lt,w=m<Lt;u&&(f=-f),w&&(m=-m);let S=Ie(Math.ceil(nn(r)/2))+he;if(f<Lt||f>=S||m<Lt||m>=S)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:u,k1:f,k2neg:w,k2:m}}function Cn(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Rn(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return It(r.lowS,"lowS"),It(r.prehash,"prehash"),r.format!==void 0&&Cn(r.format),r}var Kn=class extends Error{constructor(t=""){super(t)}},kt={Err:Kn,_tlv:{encode:(e,t)=>{let{Err:r}=kt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Be(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Be(o.length/2|128):"";return Be(e)+s+o+t},decode(e,t){let{Err:r}=kt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let m of f)i=i<<8|m;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=kt;if(e<Lt)throw new t("integer: negative integers are not allowed");let r=Be(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=kt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return se(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=kt,o=O(e,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:m}=n.decode(2,c);if(m.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=kt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Lt=BigInt(0),he=BigInt(1),As=BigInt(2),pr=BigInt(3),ta=BigInt(4);function Bs(e,t={}){let r=tr("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:a}=s;Ct(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=Is(n,o);function m(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function u(T,l,d){let{x:h,y:E}=l.toAffine(),L=n.toBytes(h);if(It(d,"isCompressed"),d){m();let D=!n.isOdd(E);return ot(vs(D),L)}else return ot(Uint8Array.of(4),L,n.toBytes(E))}function w(T){O(T,void 0,"Point");let{publicKey:l,publicKeyUncompressed:d}=f,h=T.length,E=T[0],L=T.subarray(1);if(h===l&&(E===2||E===3)){let D=n.fromBytes(L);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let U=v(D),_;try{_=n.sqrt(U)}catch(Z){let q=Z instanceof Error?": "+Z.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}m();let R=n.isOdd(_);return(E&1)===1!==R&&(_=n.neg(_)),{x:D,y:_}}else if(h===d&&E===4){let D=n.BYTES,U=n.fromBytes(L.subarray(0,D)),_=n.fromBytes(L.subarray(D,D*2));if(!A(U,_))throw new Error("bad point: is not on curve");return{x:U,y:_}}else throw new Error(`bad point: got length ${h}, expected compressed=${l} or uncompressed=${d}`)}let S=t.toBytes||u,p=t.fromBytes||w;function v(T){let l=n.sqr(T),d=n.mul(l,T);return n.add(n.add(d,n.mul(T,s.a)),s.b)}function A(T,l){let d=n.sqr(l),h=v(T);return n.eql(d,h)}if(!A(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(s.a,pr),ta),B=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(b,B)))throw new Error("bad curve params: a or b");function y(T,l,d=!1){if(!n.isValid(l)||d&&n.is0(l))throw new Error(`bad point coordinate ${T}`);return l}function I(T){if(!(T instanceof x))throw new Error("Weierstrass Point expected")}function C(T){if(!c||!c.basises)throw new Error("no endo");return Qc(T,c.basises,o.ORDER)}let k=ie((T,l)=>{let{X:d,Y:h,Z:E}=T;if(n.eql(E,n.ONE))return{x:d,y:h};let L=T.is0();l==null&&(l=L?n.ONE:n.inv(E));let D=n.mul(d,l),U=n.mul(h,l),_=n.mul(E,l);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(_,n.ONE))throw new Error("invZ was invalid");return{x:D,y:U}}),P=ie(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:l,y:d}=T.toAffine();if(!n.isValid(l)||!n.isValid(d))throw new Error("bad point: x or y not field elements");if(!A(l,d))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function g(T,l,d,h,E){return d=new x(n.mul(d.X,T),d.Y,d.Z),l=_e(h,l),d=_e(E,d),l.add(d)}class x{static BASE=new x(s.Gx,s.Gy,n.ONE);static ZERO=new x(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(l,d,h){this.X=y("x",l),this.Y=y("y",d,!0),this.Z=y("z",h),Object.freeze(this)}static CURVE(){return s}static fromAffine(l){let{x:d,y:h}=l||{};if(!l||!n.isValid(d)||!n.isValid(h))throw new Error("invalid affine point");if(l instanceof x)throw new Error("projective point not allowed");return n.is0(d)&&n.is0(h)?x.ZERO:new x(d,h,n.ONE)}static fromBytes(l){let d=x.fromAffine(p(O(l,void 0,"point")));return d.assertValidity(),d}static fromHex(l){return x.fromBytes(Bt(l))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(l=8,d=!0){return M.createCache(this,l),d||this.multiply(pr),this}assertValidity(){P(this)}hasEvenY(){let{y:l}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(l)}equals(l){I(l);let{X:d,Y:h,Z:E}=this,{X:L,Y:D,Z:U}=l,_=n.eql(n.mul(d,U),n.mul(L,E)),R=n.eql(n.mul(h,U),n.mul(D,E));return _&&R}negate(){return new x(this.X,n.neg(this.Y),this.Z)}double(){let{a:l,b:d}=s,h=n.mul(d,pr),{X:E,Y:L,Z:D}=this,U=n.ZERO,_=n.ZERO,R=n.ZERO,N=n.mul(E,E),Z=n.mul(L,L),q=n.mul(D,D),H=n.mul(E,L);return H=n.add(H,H),R=n.mul(E,D),R=n.add(R,R),U=n.mul(l,R),_=n.mul(h,q),_=n.add(U,_),U=n.sub(Z,_),_=n.add(Z,_),_=n.mul(U,_),U=n.mul(H,U),R=n.mul(h,R),q=n.mul(l,q),H=n.sub(N,q),H=n.mul(l,H),H=n.add(H,R),R=n.add(N,N),N=n.add(R,N),N=n.add(N,q),N=n.mul(N,H),_=n.add(_,N),q=n.mul(L,D),q=n.add(q,q),N=n.mul(q,H),U=n.sub(U,N),R=n.mul(q,Z),R=n.add(R,R),R=n.add(R,R),new x(U,_,R)}add(l){I(l);let{X:d,Y:h,Z:E}=this,{X:L,Y:D,Z:U}=l,_=n.ZERO,R=n.ZERO,N=n.ZERO,Z=s.a,q=n.mul(s.b,pr),H=n.mul(d,L),F=n.mul(h,D),W=n.mul(E,U),mt=n.add(d,h),j=n.add(L,D);mt=n.mul(mt,j),j=n.add(H,F),mt=n.sub(mt,j),j=n.add(d,E);let Q=n.add(L,U);return j=n.mul(j,Q),Q=n.add(H,W),j=n.sub(j,Q),Q=n.add(h,E),_=n.add(D,U),Q=n.mul(Q,_),_=n.add(F,W),Q=n.sub(Q,_),N=n.mul(Z,j),_=n.mul(q,W),N=n.add(_,N),_=n.sub(F,N),N=n.add(F,N),R=n.mul(_,N),F=n.add(H,H),F=n.add(F,H),W=n.mul(Z,W),j=n.mul(q,j),F=n.add(F,W),W=n.sub(H,W),W=n.mul(Z,W),j=n.add(j,W),H=n.mul(F,j),R=n.add(R,H),H=n.mul(Q,j),_=n.mul(mt,_),_=n.sub(_,H),H=n.mul(mt,F),N=n.mul(Q,N),N=n.add(N,H),new x(_,R,N)}subtract(l){return this.add(l.negate())}is0(){return this.equals(x.ZERO)}multiply(l){let{endo:d}=t;if(!o.isValidNot0(l))throw new Error("invalid scalar: out of range");let h,E,L=D=>M.cached(this,D,U=>Ft(x,U));if(d){let{k1neg:D,k1:U,k2neg:_,k2:R}=C(l),{p:N,f:Z}=L(U),{p:q,f:H}=L(R);E=Z.add(H),h=g(d.beta,N,q,D,_)}else{let{p:D,f:U}=L(l);h=D,E=U}return Ft(x,[h,E])[0]}multiplyUnsafe(l){let{endo:d}=t,h=this;if(!o.isValid(l))throw new Error("invalid scalar: out of range");if(l===Lt||h.is0())return x.ZERO;if(l===he)return h;if(M.hasCache(this))return this.multiply(l);if(d){let{k1neg:E,k1:L,k2neg:D,k2:U}=C(l),{p1:_,p2:R}=Jo(x,h,L,U);return g(d.beta,_,R,E,D)}else return M.unsafe(h,l)}toAffine(l){return k(this,l)}isTorsionFree(){let{isTorsionFree:l}=t;return i===he?!0:l?l(x,this):M.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:l}=t;return i===he?this:l?l(x,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(l=!0){return It(l,"isCompressed"),this.assertValidity(),S(x,this,l)}toHex(l=!0){return At(this.toBytes(l))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let K=o.BITS,M=new fe(x,t.endo?Math.ceil(K/2):K);return x.BASE.precompute(8),x}function vs(e){return Uint8Array.of(e?2:3)}function Is(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function ea(e,t={}){let{Fn:r}=e,n=t.randomBytes||oe,o=Object.assign(Is(e.Fp,r),{seed:an(r.ORDER)});function s(S){try{let p=r.fromBytes(S);return r.isValidNot0(p)}catch{return!1}}function i(S,p){let{publicKey:v,publicKeyUncompressed:A}=o;try{let b=S.length;return p===!0&&b!==v||p===!1&&b!==A?!1:!!e.fromBytes(S)}catch{return!1}}function a(S=n(o.seed)){return fn(O(S,o.seed,"seed"),r.ORDER)}function c(S,p=!0){return e.BASE.multiply(r.fromBytes(S)).toBytes(p)}function f(S){let{secretKey:p,publicKey:v,publicKeyUncompressed:A}=o;if(!Pt(S)||"_lengths"in r&&r._lengths||p===v)return;let b=O(S,void 0,"key").length;return b===v||b===A}function m(S,p,v=!0){if(f(S)===!0)throw new Error("first arg must be private key");if(f(p)===!1)throw new Error("second arg must be public key");let A=r.fromBytes(S);return e.fromBytes(p).multiply(A).toBytes(v)}let u={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},w=er(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:m,keygen:w,Point:e,utils:u,lengths:o})}function Ls(e,t,r={}){Ye(t),Ct(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||oe,o=r.hmac||((d,h)=>Un(t,d,h)),{Fp:s,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:f,getPublicKey:m,getSharedSecret:u,utils:w,lengths:S}=ea(e,r),p={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},v=a*As<s.ORDER;function A(d){let h=a>>he;return d>h}function b(d,h){if(!i.isValidNot0(h))throw new Error(`invalid signature ${d}: out of range 1..Point.Fn.ORDER`);return h}function B(){if(v)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function y(d,h){Cn(h);let E=S.signature,L=h==="compact"?E:h==="recovered"?E+1:void 0;return O(d,L)}class I{r;s;recovery;constructor(h,E,L){if(this.r=b("r",h),this.s=b("s",E),L!=null){if(B(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(h,E=p.format){y(h,E);let L;if(E==="der"){let{r:R,s:N}=kt.toSig(O(h));return new I(R,N)}E==="recovered"&&(L=h[0],E="compact",h=h.subarray(1));let D=S.signature/2,U=h.subarray(0,D),_=h.subarray(D,D*2);return new I(i.fromBytes(U),i.fromBytes(_),L)}static fromHex(h,E){return this.fromBytes(Bt(h),E)}assertRecovery(){let{recovery:h}=this;if(h==null)throw new Error("invalid recovery id: must be present");return h}addRecoveryBit(h){return new I(this.r,this.s,h)}recoverPublicKey(h){let{r:E,s:L}=this,D=this.assertRecovery(),U=D===2||D===3?E+a:E;if(!s.isValid(U))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let _=s.toBytes(U),R=e.fromBytes(ot(vs((D&1)===0),_)),N=i.inv(U),Z=k(O(h,void 0,"msgHash")),q=i.create(-Z*N),H=i.create(L*N),F=e.BASE.multiplyUnsafe(q).add(R.multiplyUnsafe(H));if(F.is0())throw new Error("invalid recovery: point at infinify");return F.assertValidity(),F}hasHighS(){return A(this.s)}toBytes(h=p.format){if(Cn(h),h==="der")return Bt(kt.hexFromSig(this));let{r:E,s:L}=this,D=i.toBytes(E),U=i.toBytes(L);return h==="recovered"?(B(),ot(Uint8Array.of(this.assertRecovery()),D,U)):ot(D,U)}toHex(h){return At(this.toBytes(h))}}let C=r.bits2int||function(h){if(h.length>8192)throw new Error("input is too large");let E=se(h),L=h.length*8-c;return L>0?E>>BigInt(L):E},k=r.bits2int_modN||function(h){return i.create(C(h))},P=Ie(c);function g(d){return ve("num < 2^"+c,d,Lt,P),i.toBytes(d)}function x(d,h){return O(d,void 0,"message"),h?O(t(d),void 0,"prehashed message"):d}function K(d,h,E){let{lowS:L,prehash:D,extraEntropy:U}=Rn(E,p);d=x(d,D);let _=k(d),R=i.fromBytes(h);if(!i.isValidNot0(R))throw new Error("invalid private key");let N=[g(R),g(_)];if(U!=null&&U!==!1){let F=U===!0?n(S.secretKey):U;N.push(O(F,void 0,"extraEntropy"))}let Z=ot(...N),q=_;function H(F){let W=C(F);if(!i.isValidNot0(W))return;let mt=i.inv(W),j=e.BASE.multiply(W).toAffine(),Q=i.create(j.x);if(Q===Lt)return;let Me=i.create(mt*i.create(q+Q*R));if(Me===Lt)return;let Pn=(j.x===Q?0:2)|Number(j.y&he),Mn=Me;return L&&A(Me)&&(Mn=i.neg(Me),Pn^=1),new I(Q,Mn,v?void 0:Pn)}return{seed:Z,k2sig:H}}function M(d,h,E={}){let{seed:L,k2sig:D}=K(d,h,E);return No(t.outputLen,i.BYTES,o)(L,D).toBytes(E.format)}function T(d,h,E,L={}){let{lowS:D,prehash:U,format:_}=Rn(L,p);if(E=O(E,void 0,"publicKey"),h=x(h,U),!Pt(d)){let R=d instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+R)}y(d,_);try{let R=I.fromBytes(d,_),N=e.fromBytes(E);if(D&&R.hasHighS())return!1;let{r:Z,s:q}=R,H=k(h),F=i.inv(q),W=i.create(H*F),mt=i.create(Z*F),j=e.BASE.multiplyUnsafe(W).add(N.multiplyUnsafe(mt));return j.is0()?!1:i.create(j.x)===Z}catch{return!1}}function l(d,h,E={}){let{prehash:L}=Rn(E,p);return h=x(h,L),I.fromBytes(d,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:f,getPublicKey:m,getSharedSecret:u,utils:w,lengths:S,Point:e,sign:M,verify:T,recoverPublicKey:l,Signature:I,hash:t})}var On={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ra={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var _s=BigInt(2);function na(e){let t=On.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=e*e*e%t,m=f*f*e%t,u=V(m,r,t)*m%t,w=V(u,r,t)*m%t,S=V(w,_s,t)*f%t,p=V(S,o,t)*S%t,v=V(p,s,t)*p%t,A=V(v,a,t)*v%t,b=V(A,c,t)*A%t,B=V(b,a,t)*v%t,y=V(B,r,t)*m%t,I=V(y,i,t)*p%t,C=V(I,n,t)*f%t,k=V(C,_s,t);if(!Nn.eql(Nn.sqr(k),e))throw new Error("Cannot find square root");return k}var Nn=ce(On.p,{sqrt:na}),oa=Bs(On,{Fp:Nn,endo:ra}),le=Ls(oa,Uo);function Ds(e,t,r,n){let o=xe.digest(r instanceof Uint8Array?r:r.subarray());if(sr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),le.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new De(String(s))});try{return n?.signal?.throwIfAborted(),le.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new De(String(s))}}var mr=class{type="secp256k1";raw;_key;constructor(t){this._key=Us(t),this.raw=Ts(this._key)}toMultihash(){return ht.digest(re(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,r,n){return Ds(this._key,r,t,n)}};function Rs(e){return new mr(e)}function Ts(e){return le.Point.fromBytes(e).toBytes()}function Us(e){try{return le.Point.fromBytes(e),e}catch(t){throw new He(String(t))}}function Cs(e){let{Type:t,Data:r}=Ce.decode(e.digest),n=r??new Uint8Array;switch(t){case ut.Ed25519:return cs(n);case ut.secp256k1:return Rs(n);case ut.ECDSA:return po(n);default:throw new zt}}function re(e){return Ce.encode({Type:ut[e.type],Data:e.raw})}var Ks=Symbol.for("nodejs.util.inspect.custom"),sa=114,Ke=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[yr]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return et.createV1(sa,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return lt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return lt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ks](){return`PeerId(${this.toString()})`}},Ne=class extends Ke{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Oe=class extends Ke{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},ke=class extends Ke{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},ia=2336,Pe=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=ht.digest(Dt(this.url))}[Ks](){return`PeerId(${this.url})`}[yr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return et.createV1(ia,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=at(t)),t.toString()===this.toString())}};var ca=114,Ns=2336;function aa(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=be(Y.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return ks(et.parse(e));if(t==null)throw new bt('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=be(t.decode(e))}return kn(r)}function Os(e){if(e.type==="Ed25519")return new Oe({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new ke({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Ne({multihash:e.toCID().multihash,publicKey:e});throw new zt}function fa(e){return Os(e.publicKey)}function kn(e){if(ha(e))return new Ne({multihash:e});if(ua(e))try{let t=Cs(e);if(t.type==="Ed25519")return new Oe({multihash:e,publicKey:t});if(t.type==="secp256k1")return new ke({multihash:e,publicKey:t})}catch{let r=at(e.digest);return new Pe(new URL(r))}throw new Ve("Supplied PeerID Multihash is invalid")}function ks(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==ca&&e.code!==Ns)throw new qe("Supplied PeerID CID is invalid");if(e.code===Ns){let t=at(e.multihash.digest);return new Pe(new URL(t))}return kn(e.multihash)}function ua(e){return e.code===ht.code}function ha(e){return e.code===xe.code}return Vs(la);})();
|
|
2
|
+
"use strict";var Libp2PPeerId=(()=>{var Cr=Object.defineProperty;var Qs=Object.getOwnPropertyDescriptor;var ti=Object.getOwnPropertyNames;var ei=Object.prototype.hasOwnProperty;var ct=(e,t)=>{for(var r in t)Cr(e,r,{get:t[r],enumerable:!0})},ri=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ti(t))!ei.call(e,o)&&o!==r&&Cr(e,o,{get:()=>t[o],enumerable:!(n=Qs(t,o))||n.enumerable});return e};var ni=e=>ri(Cr({},"__esModule",{value:!0}),e);var Ha={};ct(Ha,{peerIdFromCID:()=>Js,peerIdFromMultihash:()=>Qn,peerIdFromPrivateKey:()=>Oa,peerIdFromPublicKey:()=>Ws,peerIdFromString:()=>Pa});var wt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},tr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var er=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},rr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var re=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Dr=Symbol.for("@libp2p/peer-id");var Pr={};ct(Pr,{base58btc:()=>Y,base58flickr:()=>ui});var ja=new Uint8Array(0);function ro(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 St(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 no(e){return new TextEncoder().encode(e)}function oo(e){return new TextDecoder().decode(e)}function oi(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 s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=e.length,a=e.charAt(0),u=Math.log(c)/Math.log(256),y=Math.log(256)/Math.log(c);function l(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var E=0,B=0,g=0,A=h.length;g!==A&&h[g]===0;)g++,E++;for(var w=(A-g)*y+1>>>0,C=new Uint8Array(w);g!==A;){for(var K=h[g],k=0,O=w-1;(K!==0||k<B)&&O!==-1;O--,k++)K+=256*C[O]>>>0,C[O]=K%c>>>0,K=K/c>>>0;if(K!==0)throw new Error("Non-zero carry");B=k,g++}for(var R=w-B;R!==w&&C[R]===0;)R++;for(var x=a.repeat(E);R<w;++R)x+=e.charAt(C[R]);return x}function f(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var E=0;if(h[E]!==" "){for(var B=0,g=0;h[E]===a;)B++,E++;for(var A=(h.length-E)*u+1>>>0,w=new Uint8Array(A);h[E];){var C=r[h.charCodeAt(E)];if(C===255)return;for(var K=0,k=A-1;(C!==0||K<g)&&k!==-1;k--,K++)C+=c*w[k]>>>0,w[k]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");g=K,E++}if(h[E]!==" "){for(var O=A-g;O!==A&&w[O]===0;)O++;for(var R=new Uint8Array(B+(A-O)),x=B;O!==A;)R[x++]=w[O++];return R}}}function d(h){var E=f(h);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:f,decode:d}}var si=oi,ii=si,io=ii;var Ur=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")}},Kr=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 co(this,t)}},Rr=class{decoders;constructor(t){this.decoders=t}or(t){return co(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 co(e,t){return new Rr({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Nr=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 Ur(t,r,n),this.decoder=new Kr(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ne({name:e,prefix:t,encode:r,decode:n}){return new Nr(e,t,r,n)}function Ot({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=io(r,e);return ne({prefix:t,name:e,encode:n,decode:s=>St(o(s))})}function ci(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let u=0;u<o;++u){let y=t[e[u]];if(y===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|y,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ai(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function fi(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function G({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=fi(n);return ne({prefix:t,name:e,encode(s){return ai(s,n,r)},decode(s){return ci(s,o,r,e)}})}var Y=Ot({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ui=Ot({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Or={};ct(Or,{base32:()=>oe,base32hex:()=>pi,base32hexpad:()=>yi,base32hexpadupper:()=>bi,base32hexupper:()=>mi,base32pad:()=>li,base32padupper:()=>di,base32upper:()=>hi,base32z:()=>gi});var oe=G({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),hi=G({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),li=G({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),di=G({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),pi=G({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),mi=G({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),yi=G({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),bi=G({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),gi=G({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var kr={};ct(kr,{base36:()=>ve,base36upper:()=>xi});var ve=Ot({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),xi=Ot({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var wi=uo,ao=128,Ei=127,Si=~Ei,Bi=Math.pow(2,31);function uo(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Bi;)t[r++]=e&255|ao,e/=128;for(;e&Si;)t[r++]=e&255|ao,e>>>=7;return t[r]=e|0,uo.bytes=r-n+1,t}var Ai=Mr,vi=128,fo=127;function Mr(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw Mr.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&fo)<<o:(i&fo)*Math.pow(2,o),o+=7}while(i>=vi);return Mr.bytes=s-n,r}var Ii=Math.pow(2,7),_i=Math.pow(2,14),Li=Math.pow(2,21),Ti=Math.pow(2,28),Ci=Math.pow(2,35),Di=Math.pow(2,42),Ui=Math.pow(2,49),Ki=Math.pow(2,56),Ri=Math.pow(2,63),Ni=function(e){return e<Ii?1:e<_i?2:e<Li?3:e<Ti?4:e<Ci?5:e<Di?6:e<Ui?7:e<Ki?8:e<Ri?9:10},Pi={encode:wi,decode:Ai,encodingLength:Ni},Oi=Pi,Ie=Oi;function _e(e,t=0){return[Ie.decode(e,t),Ie.decode.bytes]}function se(e,t,r=0){return Ie.encode(e,t,r),t}function ie(e){return Ie.encodingLength(e)}function ae(e,t){let r=t.byteLength,n=ie(e),o=n+ie(r),s=new Uint8Array(o+r);return se(e,s,0),se(r,s,n),s.set(t,o),new ce(e,r,t,s)}function Le(e){let t=St(e),[r,n]=_e(t),[o,s]=_e(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ce(r,o,i,t)}function ho(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&ro(e.bytes,r.bytes)}}var ce=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function lo(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Mi(r,Hr(e),t??Y.encoder);default:return Hi(r,Hr(e),t??oe.encoder)}}var po=new WeakMap;function Hr(e){let t=po.get(e);if(t==null){let r=new Map;return po.set(e,r),r}return t}var et=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!==Te)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==qi)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=ae(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&&ho(t.multihash,n.multihash)}toString(t){return lo(this,t)}toJSON(){return{"/":lo(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:s,bytes:i}=r;return new e(n,o,s,i??mo(n,o,s.bytes))}else if(r[Vi]===!0){let{version:n,multihash:o,code:s}=r,i=Le(o);return e.create(n,s,i)}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!==Te)throw new Error(`Version 0 CID must use dag-pb (code: ${Te}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=mo(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Te,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=St(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new ce(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,f]=_e(t.subarray(r));return r+=f,l},o=n(),s=Te;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),u=r+a,y=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:y,size:u}}static parse(t,r){let[n,o]=ki(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Hr(s).set(n,t),s}};function ki(e,t){switch(e[0]){case"Q":{let r=t??Y;return[Y.prefix,r.decode(`${Y.prefix}${e}`)]}case Y.prefix:{let r=t??Y;return[Y.prefix,r.decode(e)]}case oe.prefix:{let r=t??oe;return[oe.prefix,r.decode(e)]}case ve.prefix:{let r=t??ve;return[ve.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 Mi(e,t,r){let{prefix:n}=r;if(n!==Y.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function Hi(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var Te=112,qi=18;function mo(e,t,r){let n=ie(e),o=n+ie(t),s=new Uint8Array(o+r.byteLength);return se(e,s,0),se(t,s,n),s.set(r,o),s}var Vi=Symbol.for("@ipld/js-cid/CID");var qr={};ct(qr,{identity:()=>yt});var yo=0,Fi="identity",bo=St;function ji(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return ae(yo,bo(e))}var yt={code:yo,name:Fi,encode:bo,digest:ji};function bt(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 Bt(e=0){return new Uint8Array(e)}function at(e=0){return new Uint8Array(e)}function or(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=at(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var xo=Symbol.for("@achingbrain/uint8arraylist");function go(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 sr(e){return!!e?.[xo]}var ft=class e{bufs;length;[xo]=!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(sr(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(sr(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=go(this.bufs,t);return r.buf[r.index]}set(t,r){let n=go(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(sr(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 or(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:or(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_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 s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let u=t>=c&&t<a,y=r>c&&r<=a;if(u&&y){if(t===c&&r===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(y){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!sr(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 s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,y;for(let l=r;l<=a;l+=y){y=0;for(let f=u;f>=0;f--){let d=this.get(l+f);if(n[f]!==d){y=Math.max(1,f-c[d]);break}}if(y===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=at(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=Bt(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=Bt(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=Bt(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=at(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=Bt(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=Bt(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=Bt(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=Bt(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=Bt(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(!bt(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,s)=>o+s.byteLength,0)),n.length=r,n}};var Vr={};ct(Vr,{base10:()=>Zi});var Zi=Ot({prefix:"9",name:"base10",alphabet:"0123456789"});var Fr={};ct(Fr,{base16:()=>Gi,base16upper:()=>zi});var Gi=G({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),zi=G({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var jr={};ct(jr,{base2:()=>Yi});var Yi=G({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Zr={};ct(Zr,{base256emoji:()=>Qi});var wo=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}"),Xi=wo.reduce((e,t,r)=>(e[r]=t,e),[]),$i=wo.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Wi(e){return e.reduce((t,r)=>(t+=Xi[r],t),"")}function Ji(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=$i[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Qi=ne({prefix:"\u{1F680}",name:"base256emoji",encode:Wi,decode:Ji});var Gr={};ct(Gr,{base64:()=>tc,base64pad:()=>ec,base64url:()=>rc,base64urlpad:()=>nc});var tc=G({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ec=G({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),rc=G({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),nc=G({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var zr={};ct(zr,{base8:()=>oc});var oc=G({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Yr={};ct(Yr,{identity:()=>sc});var sc=ne({prefix:"\0",name:"identity",encode:e=>oo(e),decode:e=>no(e)});var Lf=new TextEncoder,Tf=new TextDecoder;var Wr={};ct(Wr,{sha256:()=>Ce,sha512:()=>fc});var ac=20;function $r({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Xr(e,t,r,n,o)}var Xr=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??ac,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Eo(n,this.code,r?.truncate):n.then(o=>Eo(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Eo(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return ae(t,e)}function Bo(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Ce=$r({name:"sha2-256",code:18,encode:Bo("SHA-256")}),fc=$r({name:"sha2-512",code:19,encode:Bo("SHA-512")});var Jr={...Yr,...jr,...zr,...Vr,...Fr,...Or,...kr,...Pr,...Gr,...Zr},qf={...Wr,...qr};function vo(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Ao=vo("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Qr=vo("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=at(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),uc={utf8:Ao,"utf-8":Ao,hex:Jr.base16,latin1:Qr,ascii:Qr,binary:Qr,...Jr},ir=uc;function kt(e,t="utf8"){let r=ir[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function ut(e,t="utf8"){let r=ir[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var hc=parseInt("11111",2),tn=parseInt("10000000",2),lc=parseInt("01111111",2),Io={0:De,1:De,2:dc,3:yc,4:bc,5:mc,6:pc,16:De,22:De,48:De};function en(e,t={offset:0}){let r=e[t.offset]&hc;if(t.offset++,Io[r]!=null)return Io[r](e,t);throw new Error("No decoder for tag "+r)}function Ue(e,t){let r=0;if((e[t.offset]&tn)===tn){let n=e[t.offset]&lc,o="0x";t.offset++;for(let s=0;s<n;s++,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 De(e,t){Ue(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=en(e,t);if(n===null)break;r.push(n)}return r}function dc(e,t){let r=Ue(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function pc(e,t){let r=Ue(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let y=0;for(let l=0;l<a.length;l++)y+=a[l]<<l*7;c+=`.${y}`,a=[]}}return c}function mc(e,t){return t.offset++,null}function yc(e,t){let r=Ue(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 bc(e,t){let r=Ue(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function gc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ft;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function rn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=gc(e.byteLength);return new ft(Uint8Array.from([t.byteLength|tn]),t)}function _o(e){let t=new ft,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ft(Uint8Array.from([2]),rn(t),t)}function Lo(e){let t=Uint8Array.from([0]),r=new ft(t,e);return new ft(Uint8Array.from([3]),rn(r),r)}function cr(e,t=48){let r=new ft;for(let n of e)r.append(n);return new ft(Uint8Array.from([t]),rn(r),r)}async function To(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 s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var xc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),wc=Uint8Array.from([6,5,43,129,4,0,34]),Ec=Uint8Array.from([6,5,43,129,4,0,35]),Sc={ext:!0,kty:"EC",crv:"P-256"},Bc={ext:!0,kty:"EC",crv:"P-384"},Ac={ext:!0,kty:"EC",crv:"P-521"},nn=32,on=48,sn=66;function Co(e){let t=en(e);return Do(t)}function Do(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===nn*2+1)return n=ut(t.subarray(r,r+nn),"base64url"),o=ut(t.subarray(r+nn),"base64url"),new ue({...Sc,key_ops:["verify"],x:n,y:o});if(t.byteLength===on*2+1)return n=ut(t.subarray(r,r+on),"base64url"),o=ut(t.subarray(r+on),"base64url"),new ue({...Bc,key_ops:["verify"],x:n,y:o});if(t.byteLength===sn*2+1)return n=ut(t.subarray(r,r+sn),"base64url"),o=ut(t.subarray(r+sn),"base64url"),new ue({...Ac,key_ops:["verify"],x:n,y:o});throw new wt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Uo(e){return cr([_o(Uint8Array.from([1])),cr([vc(e.crv)],160),cr([Lo(new ft(Uint8Array.from([4]),kt(e.x??"","base64url"),kt(e.y??"","base64url")))],161)]).subarray()}function vc(e){if(e==="P-256")return xc;if(e==="P-384")return wc;if(e==="P-521")return Ec;throw new wt(`Invalid curve ${e}`)}var ue=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Uo(this.jwk)),this._raw}toMultihash(){return yt.digest(he(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}async verify(t,r,n){return To(this.jwk,r,t,n)}};var Yt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function vt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ke(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function it(e,...t){if(!vt(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 ar(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Ke(e.outputLen),Ke(e.blockLen)}function de(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 Ro(e,t){it(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function It(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function fr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function gt(e,t){return e<<32-t|e>>>t}var No=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Ic=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function mt(e){if(it(e),No)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Ic[e[r]];return t}var At={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ko(e){if(e>=At._0&&e<=At._9)return e-At._0;if(e>=At.A&&e<=At.F)return e-(At.A-10);if(e>=At.a&&e<=At.f)return e-(At.a-10)}function Xt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(No)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,s=0;o<r;o++,s+=2){let i=Ko(e.charCodeAt(s)),c=Ko(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function cn(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Re(e){return typeof e=="string"&&(e=cn(e)),it(e),e}function rt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];it(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var le=class{};function an(e){let t=n=>e().update(Re(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function pe(e=32){if(Yt&&typeof Yt.getRandomValues=="function")return Yt.getRandomValues(new Uint8Array(e));if(Yt&&typeof Yt.randomBytes=="function")return Uint8Array.from(Yt.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function _c(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),a=n?4:0,u=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+u,c,n)}function Po(e,t,r){return e&t^~e&r}function Oo(e,t,r){return e&t^e&r^t&r}var Ne=class extends le{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=fr(this.buffer)}update(t){de(this),t=Re(t),it(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=fr(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){de(this),Ro(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,It(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;_c(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=fr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,y=this.get();if(u>y.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,y[l],s)}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:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},_t=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var J=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var ur=BigInt(4294967295),ko=BigInt(32);function Lc(e,t=!1){return t?{h:Number(e&ur),l:Number(e>>ko&ur)}:{h:Number(e>>ko&ur)|0,l:Number(e&ur)|0}}function Mo(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=Lc(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var fn=(e,t,r)=>e>>>r,un=(e,t,r)=>e<<32-r|t>>>r,$t=(e,t,r)=>e>>>r|t<<32-r,Wt=(e,t,r)=>e<<32-r|t>>>r,Pe=(e,t,r)=>e<<64-r|t>>>r-32,Oe=(e,t,r)=>e>>>r-32|t<<64-r;function Et(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Ho=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),qo=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Vo=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Fo=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,jo=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Zo=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Cc=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]),Mt=new Uint32Array(64),hn=class extends Ne{constructor(t=32){super(64,t,8,!1),this.A=_t[0]|0,this.B=_t[1]|0,this.C=_t[2]|0,this.D=_t[3]|0,this.E=_t[4]|0,this.F=_t[5]|0,this.G=_t[6]|0,this.H=_t[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let l=0;l<16;l++,r+=4)Mt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let f=Mt[l-15],d=Mt[l-2],h=gt(f,7)^gt(f,18)^f>>>3,E=gt(d,17)^gt(d,19)^d>>>10;Mt[l]=E+Mt[l-7]+h+Mt[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:y}=this;for(let l=0;l<64;l++){let f=gt(c,6)^gt(c,11)^gt(c,25),d=y+f+Po(c,a,u)+Cc[l]+Mt[l]|0,E=(gt(n,2)^gt(n,13)^gt(n,22))+Oo(n,o,s)|0;y=u,u=a,a=c,c=i+d|0,i=s,s=o,o=n,n=d+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,y=y+this.H|0,this.set(n,o,s,i,c,a,u,y)}roundClean(){It(Mt)}destroy(){this.set(0,0,0,0,0,0,0,0),It(this.buffer)}};var Go=Mo(["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))),Dc=Go[0],Uc=Go[1],Ht=new Uint32Array(80),qt=new Uint32Array(80),ln=class extends Ne{constructor(t=64){super(128,t,16,!1),this.Ah=J[0]|0,this.Al=J[1]|0,this.Bh=J[2]|0,this.Bl=J[3]|0,this.Ch=J[4]|0,this.Cl=J[5]|0,this.Dh=J[6]|0,this.Dl=J[7]|0,this.Eh=J[8]|0,this.El=J[9]|0,this.Fh=J[10]|0,this.Fl=J[11]|0,this.Gh=J[12]|0,this.Gl=J[13]|0,this.Hh=J[14]|0,this.Hl=J[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:y,Fh:l,Fl:f,Gh:d,Gl:h,Hh:E,Hl:B}=this;return[t,r,n,o,s,i,c,a,u,y,l,f,d,h,E,B]}set(t,r,n,o,s,i,c,a,u,y,l,f,d,h,E,B){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=y|0,this.Fh=l|0,this.Fl=f|0,this.Gh=d|0,this.Gl=h|0,this.Hh=E|0,this.Hl=B|0}process(t,r){for(let w=0;w<16;w++,r+=4)Ht[w]=t.getUint32(r),qt[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let C=Ht[w-15]|0,K=qt[w-15]|0,k=$t(C,K,1)^$t(C,K,8)^fn(C,K,7),O=Wt(C,K,1)^Wt(C,K,8)^un(C,K,7),R=Ht[w-2]|0,x=qt[w-2]|0,L=$t(R,x,19)^Pe(R,x,61)^fn(R,x,6),N=Wt(R,x,19)^Oe(R,x,61)^un(R,x,6),T=Vo(O,N,qt[w-7],qt[w-16]),b=Fo(T,k,L,Ht[w-7],Ht[w-16]);Ht[w]=b|0,qt[w]=T|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:y,Eh:l,El:f,Fh:d,Fl:h,Gh:E,Gl:B,Hh:g,Hl:A}=this;for(let w=0;w<80;w++){let C=$t(l,f,14)^$t(l,f,18)^Pe(l,f,41),K=Wt(l,f,14)^Wt(l,f,18)^Oe(l,f,41),k=l&d^~l&E,O=f&h^~f&B,R=jo(A,K,O,Uc[w],qt[w]),x=Zo(R,g,C,k,Dc[w],Ht[w]),L=R|0,N=$t(n,o,28)^Pe(n,o,34)^Pe(n,o,39),T=Wt(n,o,28)^Oe(n,o,34)^Oe(n,o,39),b=n&s^n&c^s&c,p=o&i^o&a^i&a;g=E|0,A=B|0,E=d|0,B=h|0,d=l|0,h=f|0,{h:l,l:f}=Et(u|0,y|0,x|0,L|0),u=c|0,y=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let m=Ho(L,T,p);n=qo(m,x,N,b),o=m|0}({h:n,l:o}=Et(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Et(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Et(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:y}=Et(this.Dh|0,this.Dl|0,u|0,y|0),{h:l,l:f}=Et(this.Eh|0,this.El|0,l|0,f|0),{h:d,l:h}=Et(this.Fh|0,this.Fl|0,d|0,h|0),{h:E,l:B}=Et(this.Gh|0,this.Gl|0,E|0,B|0),{h:g,l:A}=Et(this.Hh|0,this.Hl|0,g|0,A|0),this.set(n,o,s,i,c,a,u,y,l,f,d,h,E,B,g,A)}roundClean(){It(Ht,qt)}destroy(){It(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var zo=an(()=>new hn);var Yo=an(()=>new ln);var mn=BigInt(0),pn=BigInt(1);function Lt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function ht(e,t,r=""){let n=vt(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function ke(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Xo(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?mn:BigInt("0x"+e)}function me(e){return Xo(mt(e))}function Tt(e){return it(e),Xo(mt(Uint8Array.from(e).reverse()))}function hr(e,t){return Xt(e.toString(16).padStart(t*2,"0"))}function yn(e,t){return hr(e,t).reverse()}function H(e,t,r){let n;if(typeof t=="string")try{n=Xt(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(vt(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}function $o(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function bn(e){return Uint8Array.from(e)}var dn=e=>typeof e=="bigint"&&mn<=e;function Wo(e,t,r){return dn(e)&&dn(t)&&dn(r)&&t<=e&&e<r}function Me(e,t,r,n){if(!Wo(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function lr(e){let t;for(t=0;e>mn;e>>=pn,t+=1);return t}var Vt=e=>(pn<<BigInt(e))-pn;function Jo(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=d=>new Uint8Array(d),o=d=>Uint8Array.of(d),s=n(e),i=n(e),c=0,a=()=>{s.fill(1),i.fill(0),c=0},u=(...d)=>r(i,s,...d),y=(d=n(0))=>{i=u(o(0),d),s=u(),d.length!==0&&(i=u(o(1),d),s=u())},l=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let d=0,h=[];for(;d<t;){s=u();let E=s.slice();h.push(E),d+=s.length}return rt(...h)};return(d,h)=>{a(),y(d);let E;for(;!(E=h(l()));)y();return a(),E}}function Ft(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let c=e[o];if(i&&c===void 0)return;let a=typeof c;if(a!==s||c===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var gn=()=>{throw new Error("not implemented")};function ye(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var nt=BigInt(0),$=BigInt(1),Jt=BigInt(2),es=BigInt(3),rs=BigInt(4),ns=BigInt(5),Kc=BigInt(7),os=BigInt(8),Rc=BigInt(9),ss=BigInt(16);function z(e,t){let r=e%t;return r>=nt?r:t+r}function V(e,t,r){let n=e;for(;t-- >nt;)n*=n,n%=r;return n}function Qo(e,t){if(e===nt)throw new Error("invert: expected non-zero number");if(t<=nt)throw new Error("invert: expected positive modulus, got "+t);let r=z(e,t),n=t,o=nt,s=$,i=$,c=nt;for(;r!==nt;){let u=n/r,y=n%r,l=o-i*u,f=s-c*u;n=r,r=y,o=i,s=c,i=l,c=f}if(n!==$)throw new Error("invert: does not exist");return z(o,t)}function xn(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function is(e,t){let r=(e.ORDER+$)/rs,n=e.pow(t,r);return xn(e,n,t),n}function Nc(e,t){let r=(e.ORDER-ns)/os,n=e.mul(t,Jt),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,Jt),o),c=e.mul(s,e.sub(i,e.ONE));return xn(e,c,t),c}function Pc(e){let t=lt(e),r=cs(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Kc)/ss;return(c,a)=>{let u=c.pow(a,i),y=c.mul(u,n),l=c.mul(u,o),f=c.mul(u,s),d=c.eql(c.sqr(y),a),h=c.eql(c.sqr(l),a);u=c.cmov(u,y,d),y=c.cmov(f,l,h);let E=c.eql(c.sqr(y),a),B=c.cmov(u,y,E);return xn(c,B,a),B}}function cs(e){if(e<es)throw new Error("sqrt is not defined for small field");let t=e-$,r=0;for(;t%Jt===nt;)t/=Jt,r++;let n=Jt,o=lt(e);for(;ts(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return is;let s=o.pow(n,t),i=(t+$)/Jt;return function(a,u){if(a.is0(u))return u;if(ts(a,u)!==1)throw new Error("Cannot find square root");let y=r,l=a.mul(a.ONE,s),f=a.pow(u,t),d=a.pow(u,i);for(;!a.eql(f,a.ONE);){if(a.is0(f))return a.ZERO;let h=1,E=a.sqr(f);for(;!a.eql(E,a.ONE);)if(h++,E=a.sqr(E),h===y)throw new Error("Cannot find square root");let B=$<<BigInt(y-h-1),g=a.pow(l,B);y=h,l=a.sqr(g),f=a.mul(f,l),d=a.mul(d,g)}return d}}function Oc(e){return e%rs===es?is:e%os===ns?Nc:e%ss===Rc?Pc(e):cs(e)}var Ct=(e,t)=>(z(e,t)&$)===$,kc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function wn(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=kc.reduce((n,o)=>(n[o]="function",n),t);return Ft(e,r),e}function Mc(e,t,r){if(r<nt)throw new Error("invalid exponent, negatives unsupported");if(r===nt)return e.ONE;if(r===$)return t;let n=e.ONE,o=t;for(;r>nt;)r&$&&(n=e.mul(n,o)),o=e.sqr(o),r>>=$;return n}function He(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function ts(e,t){let r=(e.ORDER-$)/Jt,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function dr(e,t){t!==void 0&&Ke(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<=nt)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,c;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE),typeof f.modFromBytes=="boolean"&&(i=f.modFromBytes),c=f.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:a,nByteLength:u}=dr(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let y,l=Object.freeze({ORDER:e,isLE:r,BITS:a,BYTES:u,MASK:Vt(a),ZERO:nt,ONE:$,allowedLengths:c,create:f=>z(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return nt<=f&&f<e},is0:f=>f===nt,isValidNot0:f=>!l.is0(f)&&l.isValid(f),isOdd:f=>(f&$)===$,neg:f=>z(-f,e),eql:(f,d)=>f===d,sqr:f=>z(f*f,e),add:(f,d)=>z(f+d,e),sub:(f,d)=>z(f-d,e),mul:(f,d)=>z(f*d,e),pow:(f,d)=>Mc(l,f,d),div:(f,d)=>z(f*Qo(d,e),e),sqrN:f=>f*f,addN:(f,d)=>f+d,subN:(f,d)=>f-d,mulN:(f,d)=>f*d,inv:f=>Qo(f,e),sqrt:s||(f=>(y||(y=Oc(e)),y(l,f))),toBytes:f=>r?yn(f,u):hr(f,u),fromBytes:(f,d=!0)=>{if(c){if(!c.includes(f.length)||f.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+f.length);let E=new Uint8Array(u);E.set(f,r?0:E.length-f.length),f=E}if(f.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+f.length);let h=r?Tt(f):me(f);if(i&&(h=z(h,e)),!d&&!l.isValid(h))throw new Error("invalid field element: outside of range 0..ORDER");return h},invertBatch:f=>He(l,f),cmov:(f,d,h)=>h?d:f});return Object.freeze(l)}function as(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 En(e){let t=as(e);return t+Math.ceil(t/2)}function Sn(e,t,r=!1){let n=e.length,o=as(t),s=En(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Tt(e):me(e),c=z(i,t-$)+$;return r?yn(c,o):hr(c,o)}var be=BigInt(0),Qt=BigInt(1);function qe(e,t){let r=t.negate();return e?r:t}function Dt(e,t){let r=He(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function ls(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Bn(e,t){ls(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Vt(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function fs(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=Qt);let u=t*n,y=u+Math.abs(c)-1,l=c===0,f=c<0,d=t%2!==0;return{nextN:a,offset:y,isZero:l,isNeg:f,isNegF:d,offsetF:u}}function Hc(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function qc(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var An=new WeakMap,ds=new WeakMap;function vn(e){return ds.get(e)||1}function us(e){if(e!==be)throw new Error("invalid wNAF")}var ge=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>be;)r&Qt&&(n=n.add(o)),o=o.double(),r>>=Qt;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Bn(r,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let u=1;u<o;u++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Bn(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:u,isZero:y,isNeg:l,isNegF:f,offsetF:d}=fs(n,c,i);n=a,y?s=s.add(qe(f,r[d])):o=o.add(qe(l,r[u]))}return us(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Bn(t,this.bits);for(let i=0;i<s.windows&&n!==be;i++){let{nextN:c,offset:a,isZero:u,isNeg:y}=fs(n,i,s);if(n=c,!u){let l=r[a];o=o.add(y?l.negate():l)}}return us(n),o}getPrecomputes(t,r,n){let o=An.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),An.set(r,o))),o}cached(t,r,n){let o=vn(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=vn(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){ls(r,this.bits),ds.set(t,r),An.delete(t)}hasCache(t){return vn(t)!==1}};function ps(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>be||n>be;)r&Qt&&(s=s.add(o)),n&Qt&&(i=i.add(o)),o=o.double(),r>>=Qt,n>>=Qt;return{p1:s,p2:i}}function xe(e,t,r,n){Hc(r,e),qc(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=lr(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let u=Vt(a),y=new Array(Number(u)+1).fill(i),l=Math.floor((t.BITS-1)/a)*a,f=i;for(let d=l;d>=0;d-=a){y.fill(i);for(let E=0;E<s;E++){let B=n[E],g=Number(B>>BigInt(d)&u);y[g]=y[g].add(r[E])}let h=i;for(let E=y.length-1,B=i;E>0;E--)B=B.add(y[E]),h=h.add(B);if(f=f.add(h),d!==0)for(let E=0;E<a;E++)f=f.double()}return f}function hs(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return wn(t),t}else return lt(e,{isLE:r})}function pr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>be))throw new Error(`CURVE.${a} must be positive bigint`)}let o=hs(t.p,r.Fp,n),s=hs(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var jt=BigInt(0),W=BigInt(1),In=BigInt(2),Vc=BigInt(8);function Fc(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function jc(e,t={}){let r=pr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;Ft(t,{},{uvRatio:"function"});let c=In<<BigInt(o.BYTES*8)-W,a=B=>n.create(B),u=t.uvRatio||((B,g)=>{try{return{isValid:!0,value:n.sqrt(n.div(B,g))}}catch{return{isValid:!1,value:jt}}});if(!Fc(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function y(B,g,A=!1){let w=A?W:jt;return Me("coordinate "+B,g,w,c),g}function l(B){if(!(B instanceof h))throw new Error("ExtendedPoint expected")}let f=ye((B,g)=>{let{X:A,Y:w,Z:C}=B,K=B.is0();g==null&&(g=K?Vc:n.inv(C));let k=a(A*g),O=a(w*g),R=n.mul(C,g);if(K)return{x:jt,y:W};if(R!==W)throw new Error("invZ was invalid");return{x:k,y:O}}),d=ye(B=>{let{a:g,d:A}=s;if(B.is0())throw new Error("bad point: ZERO");let{X:w,Y:C,Z:K,T:k}=B,O=a(w*w),R=a(C*C),x=a(K*K),L=a(x*x),N=a(O*g),T=a(x*a(N+R)),b=a(L+a(A*a(O*R)));if(T!==b)throw new Error("bad point: equation left != right (1)");let p=a(w*C),m=a(K*k);if(p!==m)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(g,A,w,C){this.X=y("x",g),this.Y=y("y",A),this.Z=y("z",w,!0),this.T=y("t",C),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){if(g instanceof h)throw new Error("extended point not allowed");let{x:A,y:w}=g||{};return y("x",A),y("y",w),new h(A,w,W,a(A*w))}static fromBytes(g,A=!1){let w=n.BYTES,{a:C,d:K}=s;g=bn(ht(g,w,"point")),Lt(A,"zip215");let k=bn(g),O=g[w-1];k[w-1]=O&-129;let R=Tt(k),x=A?c:n.ORDER;Me("point.y",R,jt,x);let L=a(R*R),N=a(L-W),T=a(K*L-C),{isValid:b,value:p}=u(N,T);if(!b)throw new Error("bad point: invalid y coordinate");let m=(p&W)===W,S=(O&128)!==0;if(!A&&p===jt&&S)throw new Error("bad point: x=0 and x_0=1");return S!==m&&(p=a(-p)),h.fromAffine({x:p,y:R})}static fromHex(g,A=!1){return h.fromBytes(H("point",g),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,A=!0){return E.createCache(this,g),A||this.multiply(In),this}assertValidity(){d(this)}equals(g){l(g);let{X:A,Y:w,Z:C}=this,{X:K,Y:k,Z:O}=g,R=a(A*O),x=a(K*C),L=a(w*O),N=a(k*C);return R===x&&L===N}is0(){return this.equals(h.ZERO)}negate(){return new h(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:g}=s,{X:A,Y:w,Z:C}=this,K=a(A*A),k=a(w*w),O=a(In*a(C*C)),R=a(g*K),x=A+w,L=a(a(x*x)-K-k),N=R+k,T=N-O,b=R-k,p=a(L*T),m=a(N*b),S=a(L*b),v=a(T*N);return new h(p,m,v,S)}add(g){l(g);let{a:A,d:w}=s,{X:C,Y:K,Z:k,T:O}=this,{X:R,Y:x,Z:L,T:N}=g,T=a(C*R),b=a(K*x),p=a(O*w*N),m=a(k*L),S=a((C+K)*(R+x)-T-b),v=m-p,D=m+p,I=a(b-A*T),_=a(S*v),U=a(D*I),P=a(S*I),F=a(v*D);return new h(_,U,F,P)}subtract(g){return this.add(g.negate())}multiply(g){if(!o.isValidNot0(g))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=E.cached(this,g,C=>Dt(h,C));return Dt(h,[A,w])[0]}multiplyUnsafe(g,A=h.ZERO){if(!o.isValid(g))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return g===jt?h.ZERO:this.is0()||g===W?this:E.unsafe(this,g,w=>Dt(h,w),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(g){return f(this,g)}clearCofactor(){return i===W?this:this.multiplyUnsafe(i)}toBytes(){let{x:g,y:A}=this.toAffine(),w=n.toBytes(A);return w[w.length-1]|=g&W?128:0,w}toHex(){return mt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(g){return Dt(h,g)}static msm(g,A){return xe(h,o,g,A)}_setWindowSize(g){this.precompute(g)}toRawBytes(){return this.toBytes()}}h.BASE=new h(s.Gx,s.Gy,W,a(s.Gx*s.Gy)),h.ZERO=new h(jt,W,W,jt),h.Fp=n,h.Fn=o;let E=new ge(h,o.BITS);return h.BASE.precompute(8),h}var mr=class{constructor(t){this.ep=t}static fromBytes(t){gn()}static fromHex(t){gn()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return mt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function Zc(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');Ft(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,c=r.randomBytes||pe,a=r.adjustScalarBytes||(x=>x),u=r.domain||((x,L,N)=>{if(Lt(N,"phflag"),L.length||N)throw new Error("Contexts/pre-hash are not supported");return x});function y(x){return i.create(Tt(x))}function l(x){let L=w.secretKey;x=H("private key",x,L);let N=H("hashed private key",t(x),2*L),T=a(N.slice(0,L)),b=N.slice(L,2*L),p=y(T);return{head:T,prefix:b,scalar:p}}function f(x){let{head:L,prefix:N,scalar:T}=l(x),b=o.multiply(T),p=b.toBytes();return{head:L,prefix:N,scalar:T,point:b,pointBytes:p}}function d(x){return f(x).pointBytes}function h(x=Uint8Array.of(),...L){let N=rt(...L);return y(t(u(N,H("context",x),!!n)))}function E(x,L,N={}){x=H("message",x),n&&(x=n(x));let{prefix:T,scalar:b,pointBytes:p}=f(L),m=h(N.context,T,x),S=o.multiply(m).toBytes(),v=h(N.context,S,p,x),D=i.create(m+v*b);if(!i.isValid(D))throw new Error("sign failed: invalid s");let I=rt(S,i.toBytes(D));return ht(I,w.signature,"result")}let B={zip215:!0};function g(x,L,N,T=B){let{context:b,zip215:p}=T,m=w.signature;x=H("signature",x,m),L=H("message",L),N=H("publicKey",N,w.publicKey),p!==void 0&&Lt(p,"zip215"),n&&(L=n(L));let S=m/2,v=x.subarray(0,S),D=Tt(x.subarray(S,m)),I,_,U;try{I=e.fromBytes(N,p),_=e.fromBytes(v,p),U=o.multiplyUnsafe(D)}catch{return!1}if(!p&&I.isSmallOrder())return!1;let P=h(b,_.toBytes(),I.toBytes(),L);return _.add(I.multiplyUnsafe(P)).subtract(U).clearCofactor().is0()}let A=s.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function C(x=c(w.seed)){return ht(x,w.seed,"seed")}function K(x){let L=R.randomSecretKey(x);return{secretKey:L,publicKey:d(L)}}function k(x){return vt(x)&&x.length===i.BYTES}function O(x,L){try{return!!e.fromBytes(x,L)}catch{return!1}}let R={getExtendedPublicKey:f,randomSecretKey:C,isValidSecretKey:k,isValidPublicKey:O,toMontgomery(x){let{y:L}=e.fromBytes(x),N=w.publicKey,T=N===32;if(!T&&N!==57)throw new Error("only defined for 25519 and 448");let b=T?s.div(W+L,W-L):s.div(L-W,L+W);return s.toBytes(b)},toMontgomerySecret(x){let L=w.secretKey;ht(x,L);let N=t(x.subarray(0,L));return a(N).subarray(0,L)},randomPrivateKey:C,precompute(x=8,L=e.BASE){return L.precompute(x,!1)}};return Object.freeze({keygen:K,getPublicKey:d,sign:E,verify:g,utils:R,Point:e,lengths:w})}function Gc(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=lt(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function zc(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function ms(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=Gc(e),s=jc(t,r),i=Zc(s,n,o);return zc(e,i)}var Yc=BigInt(0),Ut=BigInt(1),ys=BigInt(2),Xu=BigInt(3),Xc=BigInt(5),$c=BigInt(8),we=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Ve={p:we,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:$c,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Wc(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=we,c=e*e%s*e%s,a=V(c,ys,s)*c%s,u=V(a,Ut,s)*e%s,y=V(u,Xc,s)*u%s,l=V(y,t,s)*y%s,f=V(l,r,s)*l%s,d=V(f,n,s)*f%s,h=V(d,o,s)*d%s,E=V(h,o,s)*d%s,B=V(E,t,s)*y%s;return{pow_p_5_8:V(B,ys,s)*e%s,b2:c}}function Jc(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var _n=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Cn(e,t){let r=we,n=z(t*t*t,r),o=z(n*n*t,r),s=Wc(e*o).pow_p_5_8,i=z(e*n*s,r),c=z(t*i*i,r),a=i,u=z(i*_n,r),y=c===e,l=c===z(-e,r),f=c===z(-e*_n,r);return y&&(i=a),(l||f)&&(i=u),Ct(i,r)&&(i=z(-i,r)),{isValid:y||l,value:i}}var Zt=lt(Ve.p,{isLE:!0}),Qc=lt(Ve.n,{isLE:!0}),ta={...Ve,Fp:Zt,hash:Yo,adjustScalarBytes:Jc,uvRatio:Cn},Kt=ms(ta);var Ln=_n,ea=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),ra=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),na=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),oa=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),bs=e=>Cn(Ut,e),sa=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Tn=e=>Kt.Point.Fp.create(Tt(e)&sa);function gs(e){let{d:t}=Ve,r=we,n=g=>Zt.create(g),o=n(Ln*e*e),s=n((o+Ut)*na),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:a,value:u}=Cn(s,c),y=n(u*e);Ct(y,r)||(y=n(-y)),a||(u=y),a||(i=o);let l=n(i*(o-Ut)*oa-c),f=u*u,d=n((u+u)*c),h=n(l*ea),E=n(Ut-f),B=n(Ut+f);return new Kt.Point(n(d*B),n(E*h),n(h*B),n(d*E))}function ia(e){it(e,64);let t=Tn(e.subarray(0,32)),r=gs(t),n=Tn(e.subarray(32,64)),o=gs(n);return new Rt(r.add(o))}var Rt=class e extends mr{constructor(t){super(t)}static fromAffine(t){return new e(Kt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return ia(H("ristrettoHash",t,64))}static fromBytes(t){it(t,32);let{a:r,d:n}=Ve,o=we,s=C=>Zt.create(C),i=Tn(t);if(!$o(Zt.toBytes(i),t)||Ct(i,o))throw new Error("invalid ristretto255 encoding 1");let c=s(i*i),a=s(Ut+r*c),u=s(Ut-r*c),y=s(a*a),l=s(u*u),f=s(r*n*y-l),{isValid:d,value:h}=bs(s(f*l)),E=s(h*u),B=s(h*E*f),g=s((i+i)*E);Ct(g,o)&&(g=s(-g));let A=s(a*B),w=s(g*A);if(!d||Ct(w,o)||A===Yc)throw new Error("invalid ristretto255 encoding 2");return new e(new Kt.Point(g,A,Ut,w))}static fromHex(t){return e.fromBytes(H("ristrettoHex",t,32))}static msm(t,r){return xe(e,Kt.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=we,i=B=>Zt.create(B),c=i(i(n+r)*i(n-r)),a=i(t*r),u=i(a*a),{value:y}=bs(i(c*u)),l=i(y*c),f=i(y*a),d=i(l*f*o),h;if(Ct(o*d,s)){let B=i(r*Ln),g=i(t*Ln);t=B,r=g,h=i(l*ra)}else h=f;Ct(t*d,s)&&(r=i(-r));let E=i((n-r)*h);return Ct(E,s)&&(E=i(-E)),Zt.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>Zt.create(u),c=i(r*s)===i(n*o),a=i(n*s)===i(r*o);return c||a}is0(){return this.equals(e.ZERO)}};Rt.BASE=new Rt(Kt.Point.BASE);Rt.ZERO=new Rt(Kt.Point.ZERO);Rt.Fp=Zt;Rt.Fn=Qc;var Fe=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},yr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var xs={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new yr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var br=xs;var gr=32;var Dn,ca=(async()=>{try{return await br.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function aa(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await br.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await br.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function fa(e,t,r){return Kt.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function ws(e,t,r){return Dn==null&&(Dn=await ca),Dn?aa(e,t,r):fa(e,t,r)}function xr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var wr=class{type="Ed25519";raw;constructor(t){this.raw=Un(t,gr)}toMultihash(){return yt.digest(he(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=ws(this.raw,r,t);return xr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Ss(e){return e=Un(e,gr),new wr(e)}function Un(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new wt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var ha=Math.pow(2,7),la=Math.pow(2,14),da=Math.pow(2,21),Bs=Math.pow(2,28),As=Math.pow(2,35),vs=Math.pow(2,42),Is=Math.pow(2,49),ot=128,Gt=127;function je(e){if(e<ha)return 1;if(e<la)return 2;if(e<da)return 3;if(e<Bs)return 4;if(e<As)return 5;if(e<vs)return 6;if(e<Is)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function _s(e,t,r=0){switch(je(e)){case 8:t[r++]=e&255|ot,e/=128;case 7:t[r++]=e&255|ot,e/=128;case 6:t[r++]=e&255|ot,e/=128;case 5:t[r++]=e&255|ot,e/=128;case 4:t[r++]=e&255|ot,e>>>=7;case 3:t[r++]=e&255|ot,e>>>=7;case 2:t[r++]=e&255|ot,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Ls(e,t){let r=e[t],n=0;if(n+=r&Gt,r<ot||(r=e[t+1],n+=(r&Gt)<<7,r<ot)||(r=e[t+2],n+=(r&Gt)<<14,r<ot)||(r=e[t+3],n+=(r&Gt)<<21,r<ot)||(r=e[t+4],n+=(r&Gt)*Bs,r<ot)||(r=e[t+5],n+=(r&Gt)*As,r<ot)||(r=e[t+6],n+=(r&Gt)*vs,r<ot)||(r=e[t+7],n+=(r&Gt)*Is,r<ot))return n;throw new RangeError("Could not decode varint")}var Kn=new Float32Array([-0]),zt=new Uint8Array(Kn.buffer);function Ts(e,t,r){Kn[0]=e,t[r]=zt[0],t[r+1]=zt[1],t[r+2]=zt[2],t[r+3]=zt[3]}function Cs(e,t){return zt[0]=e[t],zt[1]=e[t+1],zt[2]=e[t+2],zt[3]=e[t+3],Kn[0]}var Rn=new Float64Array([-0]),tt=new Uint8Array(Rn.buffer);function Ds(e,t,r){Rn[0]=e,t[r]=tt[0],t[r+1]=tt[1],t[r+2]=tt[2],t[r+3]=tt[3],t[r+4]=tt[4],t[r+5]=tt[5],t[r+6]=tt[6],t[r+7]=tt[7]}function Us(e,t){return tt[0]=e[t],tt[1]=e[t+1],tt[2]=e[t+2],tt[3]=e[t+3],tt[4]=e[t+4],tt[5]=e[t+5],tt[6]=e[t+6],tt[7]=e[t+7],Rn[0]}var pa=BigInt(Number.MAX_SAFE_INTEGER),ma=BigInt(Number.MIN_SAFE_INTEGER),dt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return te;if(t<pa&&t>ma)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Ks&&(o=0n,++n>Ks&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return te;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):te}},te=new dt(0,0);te.toBigInt=function(){return 0n};te.zzEncode=te.zzDecode=function(){return this};te.length=function(){return 1};var Ks=4294967296n;function Rs(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Ns(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Nn(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function xt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Er(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Pn=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,xt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw xt(this,4);return Er(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw xt(this,4);return Er(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw xt(this,4);let t=Cs(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw xt(this,4);let t=Us(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw xt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Ns(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw xt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw xt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new dt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw xt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw xt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw xt(this,8);let t=Er(this.buf,this.pos+=4),r=Er(this.buf,this.pos+=4);return new dt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Ls(this.buf,this.pos);return this.pos+=je(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function On(e){return new Pn(e instanceof Uint8Array?e:e.subarray())}function Sr(e,t,r){let n=On(e);return t.decode(n,void 0,r)}function kn(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return at(i);o+i>t&&(n=at(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var ee=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Mn(){}var qn=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},ya=kn();function ba(e){return globalThis.Buffer!=null?at(e):ya(e)}var Ge=class{len;head;tail;states;constructor(){this.len=0,this.head=new ee(Mn,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ee(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Vn((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Br,10,dt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=dt.fromBigInt(t);return this._push(Br,r.length(),r)}uint64Number(t){return this._push(_s,je(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=dt.fromBigInt(t).zzEncode();return this._push(Br,r.length(),r)}sint64Number(t){let r=dt.fromNumber(t).zzEncode();return this._push(Br,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Hn,1,t?1:0)}fixed32(t){return this._push(Ze,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=dt.fromBigInt(t);return this._push(Ze,4,r.lo)._push(Ze,4,r.hi)}fixed64Number(t){let r=dt.fromNumber(t);return this._push(Ze,4,r.lo)._push(Ze,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Ts,4,t)}double(t){return this._push(Ds,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Hn,1,0):this.uint32(r)._push(xa,r,t)}string(t){let r=Rs(t);return r!==0?this.uint32(r)._push(Nn,r,t):this._push(Hn,1,0)}fork(){return this.states=new qn(this),this.head=this.tail=new ee(Mn,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 ee(Mn,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=ba(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Hn(e,t,r){t[r]=e&255}function ga(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Vn=class extends ee{next;constructor(t,r){super(ga,t,r),this.next=void 0}};function Br(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Ze(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function xa(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Ge.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(wa,t,e),this},Ge.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Ea,t,e),this});function wa(e,t,r){t.set(e,r)}function Ea(e,t,r){e.length<40?Nn(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(kt(e),r)}function Fn(){return new Ge}function Ar(e,t){let r=Fn();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Ee;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(Ee||(Ee={}));function vr(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function jn(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return vr("enum",Ee.VARINT,r,n)}function Ir(e,t){return vr("message",Ee.LENGTH_DELIMITED,e,t)}var pt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(pt||(pt={}));var Zn;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Zn||(Zn={}));(function(e){e.codec=()=>jn(Zn)})(pt||(pt={}));var ze;(function(e){let t;e.codec=()=>(t==null&&(t=Ir((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),pt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=pt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Ar(r,e.codec()),e.decode=(r,n)=>Sr(r,e.codec(),n)})(ze||(ze={}));var Gn;(function(e){let t;e.codec=()=>(t==null&&(t=Ir((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),pt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=pt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Ar(r,e.codec()),e.decode=(r,n)=>Sr(r,e.codec(),n)})(Gn||(Gn={}));var _r=class extends le{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,ar(t);let n=Re(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),It(s)}update(t){return de(this),this.iHash.update(t),this}digestInto(t){de(this),it(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},zn=(e,t,r)=>new _r(e,t).update(r).digest();zn.create=(e,t)=>new _r(e,t);var Os=(e,t)=>(e+(e>=0?t:-t)/ks)/t;function Ba(e,t,r){let[[n,o],[s,i]]=t,c=Os(i*e,r),a=Os(-o*e,r),u=e-c*n-a*s,y=-c*o-a*i,l=u<Pt,f=y<Pt;l&&(u=-u),f&&(y=-y);let d=Vt(Math.ceil(lr(r)/2))+Be;if(u<Pt||u>=d||y<Pt||y>=d)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:u,k2neg:f,k2:y}}function Xn(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Yn(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Lt(r.lowS,"lowS"),Lt(r.prehash,"prehash"),r.format!==void 0&&Xn(r.format),r}var $n=class extends Error{constructor(t=""){super(t)}},Nt={Err:$n,_tlv:{encode:(e,t)=>{let{Err:r}=Nt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=ke(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?ke(o.length/2|128):"";return ke(e)+s+o+t},decode(e,t){let{Err:r}=Nt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let y of u)i=i<<8|y;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Nt;if(e<Pt)throw new t("integer: negative integers are not allowed");let r=ke(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Nt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return me(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Nt,o=H("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:u,l:y}=n.decode(2,a);if(y.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Nt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Pt=BigInt(0),Be=BigInt(1),ks=BigInt(2),Lr=BigInt(3),Aa=BigInt(4);function Se(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=H("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function va(e,t={}){let r=pr("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;Ft(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Hs(n,o);function y(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(T,b,p){let{x:m,y:S}=b.toAffine(),v=n.toBytes(m);if(Lt(p,"isCompressed"),p){y();let D=!n.isOdd(S);return rt(Ms(D),v)}else return rt(Uint8Array.of(4),v,n.toBytes(S))}function f(T){ht(T,void 0,"Point");let{publicKey:b,publicKeyUncompressed:p}=u,m=T.length,S=T[0],v=T.subarray(1);if(m===b&&(S===2||S===3)){let D=n.fromBytes(v);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let I=E(D),_;try{_=n.sqrt(I)}catch(F){let q=F instanceof Error?": "+F.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}y();let U=n.isOdd(_);return(S&1)===1!==U&&(_=n.neg(_)),{x:D,y:_}}else if(m===p&&S===4){let D=n.BYTES,I=n.fromBytes(v.subarray(0,D)),_=n.fromBytes(v.subarray(D,D*2));if(!B(I,_))throw new Error("bad point: is not on curve");return{x:I,y:_}}else throw new Error(`bad point: got length ${m}, expected compressed=${b} or uncompressed=${p}`)}let d=t.toBytes||l,h=t.fromBytes||f;function E(T){let b=n.sqr(T),p=n.mul(b,T);return n.add(n.add(p,n.mul(T,s.a)),s.b)}function B(T,b){let p=n.sqr(b),m=E(T);return n.eql(p,m)}if(!B(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let g=n.mul(n.pow(s.a,Lr),Aa),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(g,A)))throw new Error("bad curve params: a or b");function w(T,b,p=!1){if(!n.isValid(b)||p&&n.is0(b))throw new Error(`bad point coordinate ${T}`);return b}function C(T){if(!(T instanceof x))throw new Error("ProjectivePoint expected")}function K(T){if(!a||!a.basises)throw new Error("no endo");return Ba(T,a.basises,o.ORDER)}let k=ye((T,b)=>{let{X:p,Y:m,Z:S}=T;if(n.eql(S,n.ONE))return{x:p,y:m};let v=T.is0();b==null&&(b=v?n.ONE:n.inv(S));let D=n.mul(p,b),I=n.mul(m,b),_=n.mul(S,b);if(v)return{x:n.ZERO,y:n.ZERO};if(!n.eql(_,n.ONE))throw new Error("invZ was invalid");return{x:D,y:I}}),O=ye(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:b,y:p}=T.toAffine();if(!n.isValid(b)||!n.isValid(p))throw new Error("bad point: x or y not field elements");if(!B(b,p))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function R(T,b,p,m,S){return p=new x(n.mul(p.X,T),p.Y,p.Z),b=qe(m,b),p=qe(S,p),b.add(p)}class x{constructor(b,p,m){this.X=w("x",b),this.Y=w("y",p,!0),this.Z=w("z",m),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){let{x:p,y:m}=b||{};if(!b||!n.isValid(p)||!n.isValid(m))throw new Error("invalid affine point");if(b instanceof x)throw new Error("projective point not allowed");return n.is0(p)&&n.is0(m)?x.ZERO:new x(p,m,n.ONE)}static fromBytes(b){let p=x.fromAffine(h(ht(b,void 0,"point")));return p.assertValidity(),p}static fromHex(b){return x.fromBytes(H("pointHex",b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,p=!0){return N.createCache(this,b),p||this.multiply(Lr),this}assertValidity(){O(this)}hasEvenY(){let{y:b}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(b)}equals(b){C(b);let{X:p,Y:m,Z:S}=this,{X:v,Y:D,Z:I}=b,_=n.eql(n.mul(p,I),n.mul(v,S)),U=n.eql(n.mul(m,I),n.mul(D,S));return _&&U}negate(){return new x(this.X,n.neg(this.Y),this.Z)}double(){let{a:b,b:p}=s,m=n.mul(p,Lr),{X:S,Y:v,Z:D}=this,I=n.ZERO,_=n.ZERO,U=n.ZERO,P=n.mul(S,S),F=n.mul(v,v),q=n.mul(D,D),M=n.mul(S,v);return M=n.add(M,M),U=n.mul(S,D),U=n.add(U,U),I=n.mul(b,U),_=n.mul(m,q),_=n.add(I,_),I=n.sub(F,_),_=n.add(F,_),_=n.mul(I,_),I=n.mul(M,I),U=n.mul(m,U),q=n.mul(b,q),M=n.sub(P,q),M=n.mul(b,M),M=n.add(M,U),U=n.add(P,P),P=n.add(U,P),P=n.add(P,q),P=n.mul(P,M),_=n.add(_,P),q=n.mul(v,D),q=n.add(q,q),P=n.mul(q,M),I=n.sub(I,P),U=n.mul(q,F),U=n.add(U,U),U=n.add(U,U),new x(I,_,U)}add(b){C(b);let{X:p,Y:m,Z:S}=this,{X:v,Y:D,Z:I}=b,_=n.ZERO,U=n.ZERO,P=n.ZERO,F=s.a,q=n.mul(s.b,Lr),M=n.mul(p,v),j=n.mul(m,D),X=n.mul(S,I),st=n.add(p,m),Z=n.add(v,D);st=n.mul(st,Z),Z=n.add(M,j),st=n.sub(st,Z),Z=n.add(p,S);let Q=n.add(v,I);return Z=n.mul(Z,Q),Q=n.add(M,X),Z=n.sub(Z,Q),Q=n.add(m,S),_=n.add(D,I),Q=n.mul(Q,_),_=n.add(j,X),Q=n.sub(Q,_),P=n.mul(F,Z),_=n.mul(q,X),P=n.add(_,P),_=n.sub(j,P),P=n.add(j,P),U=n.mul(_,P),j=n.add(M,M),j=n.add(j,M),X=n.mul(F,X),Z=n.mul(q,Z),j=n.add(j,X),X=n.sub(M,X),X=n.mul(F,X),Z=n.add(Z,X),M=n.mul(j,Z),U=n.add(U,M),M=n.mul(Q,Z),_=n.mul(st,_),_=n.sub(_,M),M=n.mul(st,j),P=n.mul(Q,P),P=n.add(P,M),new x(_,U,P)}subtract(b){return this.add(b.negate())}is0(){return this.equals(x.ZERO)}multiply(b){let{endo:p}=t;if(!o.isValidNot0(b))throw new Error("invalid scalar: out of range");let m,S,v=D=>N.cached(this,D,I=>Dt(x,I));if(p){let{k1neg:D,k1:I,k2neg:_,k2:U}=K(b),{p:P,f:F}=v(I),{p:q,f:M}=v(U);S=F.add(M),m=R(p.beta,P,q,D,_)}else{let{p:D,f:I}=v(b);m=D,S=I}return Dt(x,[m,S])[0]}multiplyUnsafe(b){let{endo:p}=t,m=this;if(!o.isValid(b))throw new Error("invalid scalar: out of range");if(b===Pt||m.is0())return x.ZERO;if(b===Be)return m;if(N.hasCache(this))return this.multiply(b);if(p){let{k1neg:S,k1:v,k2neg:D,k2:I}=K(b),{p1:_,p2:U}=ps(x,m,v,I);return R(p.beta,_,U,S,D)}else return N.unsafe(m,b)}multiplyAndAddUnsafe(b,p,m){let S=this.multiplyUnsafe(p).add(b.multiplyUnsafe(m));return S.is0()?void 0:S}toAffine(b){return k(this,b)}isTorsionFree(){let{isTorsionFree:b}=t;return i===Be?!0:b?b(x,this):N.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:b}=t;return i===Be?this:b?b(x,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(b=!0){return Lt(b,"isCompressed"),this.assertValidity(),d(x,this,b)}toHex(b=!0){return mt(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(b=!0){return this.toBytes(b)}_setWindowSize(b){this.precompute(b)}static normalizeZ(b){return Dt(x,b)}static msm(b,p){return xe(x,o,b,p)}static fromPrivateKey(b){return x.BASE.multiply(Se(o,b))}}x.BASE=new x(s.Gx,s.Gy,n.ONE),x.ZERO=new x(n.ZERO,n.ONE,n.ZERO),x.Fp=n,x.Fn=o;let L=o.BITS,N=new ge(x,t.endo?Math.ceil(L/2):L);return x.BASE.precompute(8),x}function Ms(e){return Uint8Array.of(e?2:3)}function Hs(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Ia(e,t={}){let{Fn:r}=e,n=t.randomBytes||pe,o=Object.assign(Hs(e.Fp,r),{seed:En(r.ORDER)});function s(d){try{return!!Se(r,d)}catch{return!1}}function i(d,h){let{publicKey:E,publicKeyUncompressed:B}=o;try{let g=d.length;return h===!0&&g!==E||h===!1&&g!==B?!1:!!e.fromBytes(d)}catch{return!1}}function c(d=n(o.seed)){return Sn(ht(d,o.seed,"seed"),r.ORDER)}function a(d,h=!0){return e.BASE.multiply(Se(r,d)).toBytes(h)}function u(d){let h=c(d);return{secretKey:h,publicKey:a(h)}}function y(d){if(typeof d=="bigint")return!1;if(d instanceof e)return!0;let{secretKey:h,publicKey:E,publicKeyUncompressed:B}=o;if(r.allowedLengths||h===E)return;let g=H("key",d).length;return g===E||g===B}function l(d,h,E=!0){if(y(d)===!0)throw new Error("first arg must be private key");if(y(h)===!1)throw new Error("second arg must be public key");let B=Se(r,d);return e.fromHex(h).multiply(B).toBytes(E)}return Object.freeze({getPublicKey:a,getSharedSecret:l,keygen:u,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:d=>Se(r,d),precompute(d=8,h=e.BASE){return h.precompute(d,!1)}},lengths:o})}function _a(e,t,r={}){ar(t),Ft(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||pe,o=r.hmac||((p,...m)=>zn(t,p,rt(...m))),{Fp:s,Fn:i}=e,{ORDER:c,BITS:a}=i,{keygen:u,getPublicKey:y,getSharedSecret:l,utils:f,lengths:d}=Ia(e,r),h={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},E="compact";function B(p){let m=c>>Be;return p>m}function g(p,m){if(!i.isValidNot0(m))throw new Error(`invalid signature ${p}: out of range 1..Point.Fn.ORDER`);return m}function A(p,m){Xn(m);let S=d.signature,v=m==="compact"?S:m==="recovered"?S+1:void 0;return ht(p,v,`${m} signature`)}class w{constructor(m,S,v){this.r=g("r",m),this.s=g("s",S),v!=null&&(this.recovery=v),Object.freeze(this)}static fromBytes(m,S=E){A(m,S);let v;if(S==="der"){let{r:U,s:P}=Nt.toSig(ht(m));return new w(U,P)}S==="recovered"&&(v=m[0],S="compact",m=m.subarray(1));let D=i.BYTES,I=m.subarray(0,D),_=m.subarray(D,D*2);return new w(i.fromBytes(I),i.fromBytes(_),v)}static fromHex(m,S){return this.fromBytes(Xt(m),S)}addRecoveryBit(m){return new w(this.r,this.s,m)}recoverPublicKey(m){let S=s.ORDER,{r:v,s:D,recovery:I}=this;if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");if(c*ks<S&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");let U=I===2||I===3?v+c:v;if(!s.isValid(U))throw new Error("recovery id 2 or 3 invalid");let P=s.toBytes(U),F=e.fromBytes(rt(Ms((I&1)===0),P)),q=i.inv(U),M=K(H("msgHash",m)),j=i.create(-M*q),X=i.create(D*q),st=e.BASE.multiplyUnsafe(j).add(F.multiplyUnsafe(X));if(st.is0())throw new Error("point at infinify");return st.assertValidity(),st}hasHighS(){return B(this.s)}toBytes(m=E){if(Xn(m),m==="der")return Xt(Nt.hexFromSig(this));let S=i.toBytes(this.r),v=i.toBytes(this.s);if(m==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return rt(Uint8Array.of(this.recovery),S,v)}return rt(S,v)}toHex(m){return mt(this.toBytes(m))}assertValidity(){}static fromCompact(m){return w.fromBytes(H("sig",m),"compact")}static fromDER(m){return w.fromBytes(H("sig",m),"der")}normalizeS(){return this.hasHighS()?new w(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return mt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return mt(this.toBytes("compact"))}}let C=r.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");let S=me(m),v=m.length*8-a;return v>0?S>>BigInt(v):S},K=r.bits2int_modN||function(m){return i.create(C(m))},k=Vt(a);function O(p){return Me("num < 2^"+a,p,Pt,k),i.toBytes(p)}function R(p,m){return ht(p,void 0,"message"),m?ht(t(p),void 0,"prehashed message"):p}function x(p,m,S){if(["recovered","canonical"].some(j=>j in S))throw new Error("sign() legacy options not supported");let{lowS:v,prehash:D,extraEntropy:I}=Yn(S,h);p=R(p,D);let _=K(p),U=Se(i,m),P=[O(U),O(_)];if(I!=null&&I!==!1){let j=I===!0?n(d.secretKey):I;P.push(H("extraEntropy",j))}let F=rt(...P),q=_;function M(j){let X=C(j);if(!i.isValidNot0(X))return;let st=i.inv(X),Z=e.BASE.multiply(X).toAffine(),Q=i.create(Z.x);if(Q===Pt)return;let Qe=i.create(st*i.create(q+Q*U));if(Qe===Pt)return;let to=(Z.x===Q?0:2)|Number(Z.y&Be),eo=Qe;return v&&B(Qe)&&(eo=i.neg(Qe),to^=1),new w(Q,eo,to)}return{seed:F,k2sig:M}}function L(p,m,S={}){p=H("message",p);let{seed:v,k2sig:D}=x(p,m,S);return Jo(t.outputLen,i.BYTES,o)(v,D)}function N(p){let m,S=typeof p=="string"||vt(p),v=!S&&p!==null&&typeof p=="object"&&typeof p.r=="bigint"&&typeof p.s=="bigint";if(!S&&!v)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(v)m=new w(p.r,p.s);else if(S){try{m=w.fromBytes(H("sig",p),"der")}catch(D){if(!(D instanceof Nt.Err))throw D}if(!m)try{m=w.fromBytes(H("sig",p),"compact")}catch{return!1}}return m||!1}function T(p,m,S,v={}){let{lowS:D,prehash:I,format:_}=Yn(v,h);if(S=H("publicKey",S),m=R(H("message",m),I),"strict"in v)throw new Error("options.strict was renamed to lowS");let U=_===void 0?N(p):w.fromBytes(H("sig",p),_);if(U===!1)return!1;try{let P=e.fromBytes(S);if(D&&U.hasHighS())return!1;let{r:F,s:q}=U,M=K(m),j=i.inv(q),X=i.create(M*j),st=i.create(F*j),Z=e.BASE.multiplyUnsafe(X).add(P.multiplyUnsafe(st));return Z.is0()?!1:i.create(Z.x)===F}catch{return!1}}function b(p,m,S={}){let{prehash:v}=Yn(S,h);return m=R(m,v),w.fromBytes(p,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:u,getPublicKey:y,getSharedSecret:l,utils:f,lengths:d,Point:e,sign:L,verify:T,recoverPublicKey:b,Signature:w,hash:t})}function La(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=lt(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function Ta(e){let{CURVE:t,curveOpts:r}=La(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function Ca(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,dr(r.Fn.ORDER,r.Fn.BITS))})}function qs(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=Ta(e),s=va(t,r),i=_a(s,n,o);return Ca(e,i)}function Vs(e,t){let r=n=>qs({...e,hash:n});return{...r(t),create:r}}var Jn={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Da={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Fs=BigInt(2);function Ua(e){let t=Jn.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=e*e*e%t,y=u*u*e%t,l=V(y,r,t)*y%t,f=V(l,r,t)*y%t,d=V(f,Fs,t)*u%t,h=V(d,o,t)*d%t,E=V(h,s,t)*h%t,B=V(E,c,t)*E%t,g=V(B,a,t)*B%t,A=V(g,c,t)*E%t,w=V(A,r,t)*y%t,C=V(w,i,t)*h%t,K=V(C,n,t)*u%t,k=V(K,Fs,t);if(!Wn.eql(Wn.sqr(k),e))throw new Error("Cannot find square root");return k}var Wn=lt(Jn.p,{sqrt:Ua}),Ae=Vs({...Jn,Fp:Wn,lowS:!0,endo:Da},zo);function js(e,t,r,n){let o=Ce.digest(r instanceof Uint8Array?r:r.subarray());if(xr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ae.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new Fe(String(s))});try{return n?.signal?.throwIfAborted(),Ae.verify(t,o.digest,e)}catch(s){throw new Fe(String(s))}}var Tr=class{type="secp256k1";raw;_key;constructor(t){this._key=Gs(t),this.raw=Zs(this._key)}toMultihash(){return yt.digest(he(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,r,n){return js(this._key,r,t,n)}};function zs(e){return new Tr(e)}function Zs(e){return Ae.ProjectivePoint.fromHex(e).toRawBytes(!0)}function Gs(e){try{return Ae.ProjectivePoint.fromHex(e),e}catch(t){throw new tr(String(t))}}function Ys(e){let{Type:t,Data:r}=ze.decode(e.digest),n=r??new Uint8Array;switch(t){case pt.Ed25519:return Ss(n);case pt.secp256k1:return zs(n);case pt.ECDSA:return Co(n);default:throw new re}}function he(e){return ze.encode({Type:pt[e.type],Data:e.raw})}var Xs=Symbol.for("nodejs.util.inspect.custom"),Ka=114,Ye=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Dr]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return et.createV1(Ka,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return bt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return bt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Xs](){return`PeerId(${this.toString()})`}},Xe=class extends Ye{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},$e=class extends Ye{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},We=class extends Ye{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ra=2336,Je=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=yt.digest(kt(this.url))}[Xs](){return`PeerId(${this.url})`}[Dr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return et.createV1(Ra,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=ut(t)),t.toString()===this.toString())}};var Na=114,$s=2336;function Pa(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=Le(Y.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return Js(et.parse(e));if(t==null)throw new wt('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=Le(t.decode(e))}return Qn(r)}function Ws(e){if(e.type==="Ed25519")return new $e({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new We({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Xe({multihash:e.toCID().multihash,publicKey:e});throw new re}function Oa(e){return Ws(e.publicKey)}function Qn(e){if(Ma(e))return new Xe({multihash:e});if(ka(e))try{let t=Ys(e);if(t.type==="Ed25519")return new $e({multihash:e,publicKey:t});if(t.type==="secp256k1")return new We({multihash:e,publicKey:t})}catch{let r=ut(e.digest);return new Je(new URL(r))}throw new rr("Supplied PeerID Multihash is invalid")}function Js(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Na&&e.code!==$s)throw new er("Supplied PeerID CID is invalid");if(e.code===$s){let t=ut(e.multihash.digest);return new Je(new URL(t))}return Qn(e.multihash)}function ka(e){return e.code===yt.code}function Ma(e){return e.code===Ce.code}return ni(Ha);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
|
-
@noble/hashes/utils.js:
|
|
5
|
+
@noble/hashes/esm/utils.js:
|
|
6
6
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
7
7
|
|
|
8
|
-
@noble/curves/utils.js:
|
|
9
|
-
@noble/curves/abstract/modular.js:
|
|
10
|
-
@noble/curves/abstract/curve.js:
|
|
11
|
-
@noble/curves/abstract/edwards.js:
|
|
12
|
-
@noble/curves/ed25519.js:
|
|
13
|
-
@noble/curves/abstract/weierstrass.js:
|
|
14
|
-
@noble/curves/
|
|
8
|
+
@noble/curves/esm/utils.js:
|
|
9
|
+
@noble/curves/esm/abstract/modular.js:
|
|
10
|
+
@noble/curves/esm/abstract/curve.js:
|
|
11
|
+
@noble/curves/esm/abstract/edwards.js:
|
|
12
|
+
@noble/curves/esm/ed25519.js:
|
|
13
|
+
@noble/curves/esm/abstract/weierstrass.js:
|
|
14
|
+
@noble/curves/esm/_shortw_utils.js:
|
|
15
|
+
@noble/curves/esm/secp256k1.js:
|
|
15
16
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
16
17
|
*/
|
|
17
18
|
return Libp2PPeerId}));
|