@libp2p/peer-id 6.0.13 → 6.0.14-47cf9cdc1

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