@libp2p/peer-id 6.0.15-cef4d32cf → 6.0.15-fb139d1c8

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