@libp2p/plaintext 3.0.32-fab409544 → 3.0.32-ff95dc546

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.Libp2PPlaintext = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PPlaintext=(()=>{var Xr=Object.defineProperty;var oa=Object.getOwnPropertyDescriptor;var sa=Object.getOwnPropertyNames;var ia=Object.prototype.hasOwnProperty;var mt=(e,t)=>{for(var r in t)Xr(e,r,{get:t[r],enumerable:!0})},aa=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of sa(t))!ia.call(e,o)&&o!==r&&Xr(e,o,{get:()=>t[o],enumerable:!(n=oa(t,o))||n.enumerable});return e};var ca=e=>aa(Xr({},"__esModule",{value:!0}),e);var bf={};mt(bf,{plaintext:()=>yf});var or=class extends Error{static name="UnexpectedPeerError";constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError"}},Pe=class extends Error{static name="InvalidCryptoExchangeError";constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError"}},ot=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Qt=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var sr=class extends Error{static name="StreamBufferError";constructor(t="The stream buffer was full"){super(t),this.name="StreamBufferError"}};var le=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var de=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Jr=Symbol.for("@libp2p/peer-id");var Vo=Symbol.for("@libp2p/service-capabilities");function lt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}var nn={};mt(nn,{base58btc:()=>st,base58flickr:()=>ya});var Zf=new Uint8Array(0);function Zo(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 vt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return te(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return te(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function Yo(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var $o=4096;function Go(e){let t=e.length;if(t<=$o)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=$o));return r}function ua(e){return e?.buffer instanceof ArrayBuffer}function te(e){return ua(e)?e:e.slice()}function fa(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),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var f=e.length,l=e.charAt(0),p=Math.log(f)/Math.log(256),h=Math.log(256)/Math.log(f);function A(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 v=0,y=0,g=0,S=x.length;g!==S&&x[g]===0;)g++,v++;for(var C=(S-g)*h+1>>>0,U=new Uint8Array(C);g!==S;){for(var P=x[g],R=0,O=C-1;(P!==0||R<y)&&O!==-1;O--,R++)P+=256*U[O]>>>0,U[O]=P%f>>>0,P=P/f>>>0;if(P!==0)throw new Error("Non-zero carry");y=R,g++}for(var q=C-y;q!==C&&U[q]===0;)q++;for(var M=l.repeat(v);q<C;++q)M+=e.charAt(U[q]);return M}function w(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var v=0;if(x[v]!==" "){for(var y=0,g=0;x[v]===l;)y++,v++;for(var S=(x.length-v)*p+1>>>0,C=new Uint8Array(S);x[v];){var U=n[x.charCodeAt(v)];if(U===255)return;for(var P=0,R=S-1;(U!==0||P<g)&&R!==-1;R--,P++)U+=f*C[R]>>>0,C[R]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");g=P,v++}if(x[v]!==" "){for(var O=S-g;O!==S&&C[O]===0;)O++;for(var q=new Uint8Array(y+(S-O)),M=y;O!==S;)q[M++]=C[O++];return q}}}function I(x){var v=w(x);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:A,decodeUnsafe:w,decode:I}}var la=fa,da=la,Xo=da;var Qr=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")}},tn=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 Jo(this,t)}},en=class{decoders;constructor(t){this.decoders=t}or(t){return Jo(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 Jo(e,t){return new en({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var rn=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 Qr(t,r,n),this.decoder=new tn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function he({name:e,prefix:t,encode:r,decode:n}){return new rn(e,t,r,n)}function qt({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=Xo(r,e,n);return he({prefix:t,name:e,encode:o,decode:i=>vt(s(i))})}function ha(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 u=0;u<o;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,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 pa(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 ma(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 tt({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=ma(n,o);return he({prefix:t,name:e,encode(i){return pa(i,n,r)},decode(i){return ha(i,s,r,e)}})}var st=qt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ya=qt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var on={};mt(on,{base32:()=>pe,base32hex:()=>xa,base32hexpad:()=>Sa,base32hexpadupper:()=>va,base32hexupper:()=>Ea,base32pad:()=>ga,base32padupper:()=>wa,base32upper:()=>ba,base32z:()=>Aa});var pe=tt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),ba=tt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),ga=tt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),wa=tt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),xa=tt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Ea=tt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Sa=tt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),va=tt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Aa=tt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var sn={};mt(sn,{base36:()=>Ne,base36upper:()=>Ba});var Ne=qt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Ba=qt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Ia=es,Qo=128,Ta=127,La=~Ta,_a=Math.pow(2,31);function es(e,t,r){t=t||[],r=r||0;for(var n=r;e>=_a;)t[r++]=e&255|Qo,e/=128;for(;e&La;)t[r++]=e&255|Qo,e>>>=7;return t[r]=e|0,es.bytes=r-n+1,t}var Ra=an,Da=128,ts=127;function an(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw an.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&ts)<<o:(i&ts)*Math.pow(2,o),o+=7}while(i>=Da);return an.bytes=s-n,r}var Oa=Math.pow(2,7),Ca=Math.pow(2,14),Ka=Math.pow(2,21),Pa=Math.pow(2,28),Na=Math.pow(2,35),Ua=Math.pow(2,42),Fa=Math.pow(2,49),ka=Math.pow(2,56),Ma=Math.pow(2,63),qa=function(e){return e<Oa?1:e<Ca?2:e<Ka?3:e<Pa?4:e<Na?5:e<Ua?6:e<Fa?7:e<ka?8:e<Ma?9:10},Ha={encode:Ia,decode:Ra,encodingLength:qa},za=Ha,Ue=za;function Fe(e,t=0){let r=Ue.decode(e,t),n=Ue.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 me(e,t,r=0){return Ue.encode(e,t,r),t}function ye(e){return Ue.encodingLength(e)}function _t(e,t){let r=t.byteLength,n=ye(e),o=n+ye(r),s=new Uint8Array(o+r);return me(e,s,0),me(r,s,n),s.set(t,o),new be(e,r,t,s)}function cn(e){let t=vt(e),[r,n]=Fe(t),[o,s]=Fe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new be(r,o,i,t)}function rs(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Zo(e.bytes,r.bytes)}}var be=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=te(n),this.bytes=te(o)}};function ns(e,t){let{bytes:r,version:n}=e;return n===0?Va(r,un(e),t??st.encoder):$a(r,un(e),t??pe.encoder)}var os=new WeakMap;function un(e){let t=os.get(e);if(t==null){let r=new Map;return os.set(e,r),r}return t}var dt=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=te(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!==ke)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Za)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=_t(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&rs(t.multihash,n.multihash)}toString(t){return ns(this,t)}toJSON(){return{"/":ns(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??ss(n,o,s.bytes))}else if(r[Ya]===!0){let{version:n,multihash:o,code:s}=r,i=cn(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!==ke)throw new Error(`Version 0 CID must use dag-pb (code: ${ke}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=ss(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,ke,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=vt(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 be(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,p]=Fe(t.subarray(r));return r+=p,l},o=n(),s=ke;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(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,o]=ja(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 un(s).set(n,t),s}};function ja(e,t){switch(e[0]){case"Q":{let r=t??st;return[st.prefix,r.decode(`${st.prefix}${e}`)]}case st.prefix:{let r=t??st;return[st.prefix,r.decode(e)]}case pe.prefix:{let r=t??pe;return[pe.prefix,r.decode(e)]}case Ne.prefix:{let r=t??Ne;return[Ne.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 Va(e,t,r){let{prefix:n}=r;if(n!==st.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 $a(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 ke=112,Za=18;function ss(e,t,r){let n=ye(e),o=n+ye(t),s=new Uint8Array(o+r.byteLength);return me(e,s,0),me(t,s,n),s.set(r,o),s}var Ya=Symbol.for("@ipld/js-cid/CID");var fn={};mt(fn,{identity:()=>Rt});var is=0,Ga="identity",as=vt;function Wa(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 _t(is,as(e))}var Rt={code:is,name:Ga,encode:as,digest:Wa};function Xa(e){return e.buffer instanceof ArrayBuffer}function yt(e){return Xa(e)?e:e.slice()}async function cs(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,yt(t),yt(r.subarray()));return n?.signal?.throwIfAborted(),s}function Ct(e=0){return new Uint8Array(e)}function bt(e=0){return new Uint8Array(e)}function Ja(e){return e?.buffer instanceof ArrayBuffer}function us(e){if(Ja(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function ar(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=bt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return us(r)}var ls=Symbol.for("@achingbrain/uint8arraylist");function fs(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 cr(e){return!!e?.[ls]}var ft=class e{bufs;length;[ls]=!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(cr(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(cr(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=fs(this.bufs,t);return r.buf[r.index]}set(t,r){let n=fs(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(cr(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 ar(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:ar(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 u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){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(!cr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let p=u;p>=0;p--){let h=this.get(l+p);if(n[p]!==h){f=Math.max(1,p-a[h]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=bt(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=Ct(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=Ct(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=Ct(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=bt(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=Ct(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=Ct(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=Ct(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=Ct(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=Ct(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!lt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var ln={};mt(ln,{base10:()=>Qa});var Qa=qt({prefix:"9",name:"base10",alphabet:"0123456789"});var dn={};mt(dn,{base16:()=>tc,base16upper:()=>ec});var tc=tt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),ec=tt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var hn={};mt(hn,{base2:()=>rc});var rc=tt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var pn={};mt(pn,{base256emoji:()=>ac});var ds=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}"),nc=ds.reduce((e,t,r)=>(e[r]=t,e),[]),oc=ds.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function sc(e){return e.reduce((t,r)=>(t+=nc[r],t),"")}function ic(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=oc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var ac=he({prefix:"\u{1F680}",name:"base256emoji",encode:sc,decode:ic});var mn={};mt(mn,{base64:()=>cc,base64pad:()=>uc,base64url:()=>fc,base64urlpad:()=>lc});var cc=tt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),uc=tt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),fc=tt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),lc=tt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var yn={};mt(yn,{base8:()=>dc});var dc=tt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var bn={};mt(bn,{identity:()=>hc});var hc=he({prefix:"\0",name:"identity",encode:e=>Go(vt(e)),decode:e=>vt(Yo(e))});var Dl=new TextEncoder,Ol=new TextDecoder;var xn={};mt(xn,{sha256:()=>ur,sha512:()=>bc});var yc=20;function wn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new gn(e,t,r,n,o)}var gn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??yc,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?hs(n,this.code,r?.truncate):n.then(o=>hs(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function hs(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 _t(t,e)}function ms(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var ur=wn({name:"sha2-256",code:18,encode:ms("SHA-256")}),bc=wn({name:"sha2-512",code:19,encode:ms("SHA-512")});var En={...bn,...hn,...yn,...ln,...dn,...on,...sn,...nn,...mn,...pn},jl={...xn,...fn};function bs(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ys=bs("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Sn=bs("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=bt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),gc={utf8:ys,"utf-8":ys,hex:En.base16,latin1:Sn,ascii:Sn,binary:Sn,...En},fr=gc;function it(e,t="utf8"){let r=fr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function et(e,t="utf8"){let r=fr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var wc=parseInt("11111",2),vn=parseInt("10000000",2),xc=parseInt("01111111",2),gs={0:Me,1:Me,2:Ec,3:Ac,4:Bc,5:vc,6:Sc,16:Me,22:Me,48:Me};function Kt(e,t={offset:0}){let r=e[t.offset]&wc;if(t.offset++,gs[r]!=null)return gs[r](e,t);throw new Error("No decoder for tag "+r)}function qe(e,t){let r=0;if((e[t.offset]&vn)===vn){let n=e[t.offset]&xc,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 Me(e,t){qe(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Kt(e,t);if(n===null)break;r.push(n)}return r}function Ec(e,t){let r=qe(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 Sc(e,t){let r=qe(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 u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function vc(e,t){return t.offset++,null}function Ac(e,t){let r=qe(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Bc(e,t){let r=qe(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Ic(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ft;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function An(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Ic(e.byteLength);return new ft(Uint8Array.from([t.byteLength|vn]),t)}function gt(e){let t=new ft,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ft(Uint8Array.from([2]),An(t),t)}function lr(e){let t=Uint8Array.from([0]),r=new ft(t,e);return new ft(Uint8Array.from([3]),An(r),r)}function Ht(e,t=48){let r=new ft;for(let n of e)r.append(n);return new ft(Uint8Array.from([t]),An(r),r)}var Tc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Lc=Uint8Array.from([6,5,43,129,4,0,34]),_c=Uint8Array.from([6,5,43,129,4,0,35]),Rc={ext:!0,kty:"EC",crv:"P-256"},Dc={ext:!0,kty:"EC",crv:"P-384"},Oc={ext:!0,kty:"EC",crv:"P-521"},Bn=32,In=48,Tn=66;function ws(e){let t=Kt(e);return xs(t)}function xs(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Bn*2+1)return n=et(t.subarray(r,r+Bn),"base64url"),o=et(t.subarray(r+Bn),"base64url"),new we({...Rc,key_ops:["verify"],x:n,y:o});if(t.byteLength===In*2+1)return n=et(t.subarray(r,r+In),"base64url"),o=et(t.subarray(r+In),"base64url"),new we({...Dc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Tn*2+1)return n=et(t.subarray(r,r+Tn),"base64url"),o=et(t.subarray(r+Tn),"base64url"),new we({...Oc,key_ops:["verify"],x:n,y:o});throw new ot(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Es(e){return Ht([gt(Uint8Array.from([1])),Ht([Cc(e.crv)],160),Ht([lr(new ft(Uint8Array.from([4]),it(e.x??"","base64url"),it(e.y??"","base64url")))],161)]).subarray()}function Cc(e){if(e==="P-256")return Tc;if(e==="P-384")return Lc;if(e==="P-521")return _c;throw new ot(`Invalid curve ${e}`)}var we=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Es(this.jwk)),this._raw}toMultihash(){return Rt.digest(zt(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return st.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}async verify(t,r,n){return cs(this.jwk,r,t,n)}};var dr=BigInt(4294967295),Ss=BigInt(32);function Kc(e,t=!1){return t?{h:Number(e&dr),l:Number(e>>Ss&dr)}:{h:Number(e>>Ss&dr)|0,l:Number(e&dr)|0}}function vs(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}=Kc(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Pc=e=>e/2**32|0,Nc=e=>e>>>0;function As(e,t,r,n){let o=Pc(r),s=Nc(r);e.setUint32(t,n?s:o,n),e.setUint32(t+4,n?o:s,n)}var Ln=(e,t,r)=>e>>>r,_n=(e,t,r)=>e<<32-r|t>>>r,ee=(e,t,r)=>e>>>r|t<<32-r,re=(e,t,r)=>e<<32-r|t>>>r,He=(e,t,r)=>e<<64-r|t>>>r-32,ze=(e,t,r)=>e>>>r-32|t<<64-r;function Dt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Bs=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Is=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Ts=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Ls=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,_s=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Rs=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;function hr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}var Rn=e=>e?`"${e}" `:"";function Pt(e,t=""){if(typeof e!="number")throw new TypeError(Rn(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(Rn(t)+"expected integer >= 0, got "+e);return e}function At(e,t,r=""){if(hr(e)&&(t===void 0||e.length===t))return e;t!==void 0&&Pt(t,"length");let n=hr(e),o=t!==void 0?` of length ${t}`:"",s=n?`length=${e.length}`:`type=${typeof e}`,i=Rn(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function pr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Pt(e.outputLen),Pt(e.blockLen),e.outputLen<1||e.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Fc=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)},Ds=(e,t)=>{Fc(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 xe(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function mr(e,t){At(e,void 0,"output");let r=t.outputLen;if(!(e.length>=r))throw new RangeError('"output" expected length >= '+r)}function ne(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function yr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Tt(e,t){return e<<32-t|e>>>t}var Cs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",kc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function br(e){if(At(e),Cs)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=kc[e[r]];return t}function Os(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function gr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(Cs)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=Os(e.charCodeAt(s)),a=Os(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 Dn(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];At(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function Mc(e,t,r="opts"){return Ds(e,"defaults"),t!==void 0&&Ds(t,r),Object.assign(Object.create(null),e,t)}function On(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=Mc({},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 Ks(e=32){Pt(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 Cn=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Ps(e,t,r){return e&t^~e&r}function Ns(e,t,r){return e&t^e&r^t&r}var je=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=yr(this.buffer)}update(t){xe(this),At(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 u=yr(t);for(;o<=s-a;a+=o)this.process(u,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){xe(this),mr(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)),As(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=t===r?n:yr(t),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],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()}},Us=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Fs=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var qc=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]),jt=new Uint32Array(64),Kn=class extends je{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 l=0;l<16;l++,r+=4)jt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let p=jt[l-15],h=jt[l-2],A=Tt(p,7)^Tt(p,18)^p>>>3,w=Tt(h,17)^Tt(h,19)^h>>>10;jt[l]=w+jt[l-7]+A+jt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let p=Tt(a,6)^Tt(a,11)^Tt(a,25),h=f+p+Ps(a,c,u)+qc[l]+jt[l]|0,w=(Tt(n,2)^Tt(n,13)^Tt(n,22))+Ns(n,o,s)|0;f=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+w|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,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){ne(jt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),ne(this.buffer)}},Pn=class extends Kn{constructor(){super(32,Us)}};var ks=vs(["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))),Hc=ks[0],zc=ks[1],Vt=new Uint32Array(80),$t=new Uint32Array(80),Nn=class extends je{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:u,El:f,Fh:l,Fl:p,Gh:h,Gl:A,Hh:w,Hl:I}=this;return[t,r,n,o,s,i,a,c,u,f,l,p,h,A,w,I]}set(t,r,n,o,s,i,a,c,u,f,l,p,h,A,w,I){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=u|0,this.El=f|0,this.Fh=l|0,this.Fl=p|0,this.Gh=h|0,this.Gl=A|0,this.Hh=w|0,this.Hl=I|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let y=0;y<16;y++,r+=4)Vt[y]=t.getUint32(r),$t[y]=t.getUint32(r+=4);for(let y=16;y<80;y++){let g=Vt[y-15]|0,S=$t[y-15]|0,C=ee(g,S,1)^ee(g,S,8)^Ln(g,S,7),U=re(g,S,1)^re(g,S,8)^_n(g,S,7),P=Vt[y-2]|0,R=$t[y-2]|0,O=ee(P,R,19)^He(P,R,61)^Ln(P,R,6),q=re(P,R,19)^ze(P,R,61)^_n(P,R,6),M=Ts(U,q,$t[y-7],$t[y-16]),Z=Ls(M,C,O,Vt[y-7],Vt[y-16]);Vt[y]=Z|0,$t[y]=M|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:p,Fh:h,Fl:A,Gh:w,Gl:I,Hh:x,Hl:v}=this;for(let y=0;y<80;y++){let g=ee(l,p,14)^ee(l,p,18)^He(l,p,41),S=re(l,p,14)^re(l,p,18)^ze(l,p,41),C=l&h^~l&w,U=p&A^~p&I,P=_s(v,S,U,zc[y],$t[y]),R=Rs(P,x,g,C,Hc[y],Vt[y]),O=P|0,q=ee(n,o,28)^He(n,o,34)^He(n,o,39),M=re(n,o,28)^ze(n,o,34)^ze(n,o,39),Z=n&s^n&a^s&a,T=o&i^o&c^i&c;x=w|0,v=I|0,w=h|0,I=A|0,h=l|0,A=p|0,{h:l,l:p}=Dt(u|0,f|0,R|0,O|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let F=Bs(O,M,T);n=Is(F,R,q,Z),o=F|0}({h:n,l:o}=Dt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Dt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Dt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Dt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:p}=Dt(this.Eh|0,this.El|0,l|0,p|0),{h,l:A}=Dt(this.Fh|0,this.Fl|0,h|0,A|0),{h:w,l:I}=Dt(this.Gh|0,this.Gl|0,w|0,I|0),{h:x,l:v}=Dt(this.Hh|0,this.Hl|0,x|0,v|0),this.set(n,o,s,i,a,c,u,f,l,p,h,A,w,I,x,v)}roundClean(){ne(Vt,$t)}destroy(){this.destroyed=!0,ne(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Un=class extends Nn{constructor(){super(64,Fs)}};var Ee=On(()=>new Pn,Cn(1));var Fn=On(()=>new Un,Cn(3));function xr(e,t,r=()=>{}){if(!Array.isArray(e))throw new TypeError(`"${t}" expected array, got type=${typeof e}`);for(let n=0;n<e.length;n++)r(e[n],`${t}[${n}]`);return e}var j=(e,t,r)=>At(e,t,r),kn=Pt;function qs(e,t=""){if(typeof e!="string"){let r=t&&`"${t}" `;throw new TypeError(r+"expected string, got type="+typeof e)}return e}function Zt(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 oe(e,t){if(typeof e!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}var Ve=br,Bt=(...e)=>Dn(...e),Se=e=>gr(e),Gt=hr,se=e=>Ks(e),wr=BigInt(0),Ms=BigInt(1),jc=e=>e?`"${e}" `:"";function wt(e,t=""){if(typeof e!="boolean")throw new TypeError(jc(t)+"expected boolean, got type="+typeof e);return e}function Er(e){if(typeof e=="bigint"){if(!Yt(e))throw new RangeError("positive bigint expected, got "+e)}else kn(e);return e}function Nt(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 $e(e){let t=Er(e).toString(16);return t.length&1?"0"+t:t}function Hs(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?wr:BigInt("0x"+e)}function Ot(e){return Hs(br(e))}function ie(e){return Hs(br(Ze(At(e)).reverse()))}function Sr(e,t){if(Pt(t),t===0)throw new Error("zero output length is invalid");e=Er(e);let r=t*2,n=e.toString(16);if(n.length>r)throw new RangeError("number is too large");return gr(n.padStart(r,"0"))}function Mn(e,t){return Sr(e,t).reverse()}function Ze(e){return Uint8Array.from(j(e))}function Yt(e){return typeof e=="bigint"&&wr<=e}function qn(e,t,r){return Yt(e)&&Yt(t)&&Yt(r)&&t<=e&&e<r}function ve(e,t,r,n){if(!qn(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ae(e){if(e<wr)throw new Error("expected non-negative bigint, got "+e);return e===wr?0:e.toString(2).length}var Ye=e=>(Nt(e,"n"),(Ms<<BigInt(e))-Ms);function zs(e,t,r){if(Pt(e,"hashLen"),Pt(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=I=>new Uint8Array(I),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,l=()=>{c.fill(1),u.fill(0),f=0},p=(...I)=>r(u,Bt(c,...I)),h=(I=o)=>{u=p(s,I),c=p(),I.length!==0&&(u=p(i,I),c=p())},A=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let I=0,x=[];for(;I<t;){c=p();let v=c.slice();x.push(v),I+=c.length}return Bt(...x)};return(I,x)=>{l(),h(I);let v;for(;(v=x(A()))===void 0;)h();return l(),v}}function xt(e,t={},r={},n="object"){Zt(e,n),Zt(t,"fields"),Zt(r,"optFields");function o(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,f=e[i];if(!Object.hasOwn(e,i)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let l=typeof f;if(l!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${l}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(t,!1),s(r,!0)}var ct=BigInt(0),V=BigInt(1),Wt=BigInt(2),$s=BigInt(3),Hn=BigInt(4),Zs=BigInt(5),Vc=BigInt(7),Ys=BigInt(8),$c=BigInt(9),Zc=BigInt(15),Gs=BigInt(16),Yc=BigInt("0x10000000000000000");function Q(e,t){if(t<=ct)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=ct?r:t+r}function Ws(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<ct)throw new Error("invalid exponent, negatives unsupported");if(t===ct)return V;if(t===V)return e;let n=e%r;if(n<ct&&(n+=r),t<Yc){let a=V;for(;t>ct;)t&V&&(a=a*n%r),n=n*n%r,t>>=V;return a}let o=[];for(;t>ct;)o.push(Number(t&Zc)),t>>=Hn;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<ct)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >ct;)n*=n,n%=r;return n}function js(e,t){if(e===ct)throw new Error("invert: expected non-zero number");if(t<=V)throw new Error("invert: expected modulus > 1, got "+t);let r=Q(e,t),n=t,o=ct,s=V;for(;r!==ct;){let a=n/r,c=n-r*a,u=o-s*a;n=r,r=c,o=s,s=u}if(n!==V)throw new Error("invert: does not exist");return Q(o,t)}function Xs(e,t){if(t<=V)throw new Error("invertCt: expected prime modulus > 1, got "+t);let r=Q(e,t);if(r===ct)throw new Error("invertCt: expected non-zero number");let n=Ws(r,t-Wt,t);if(Q(r*n,t)!==V)throw new Error("invertCt: does not exist");return n}function zn(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function jn(e,t){if((e&V)===ct)throw new Error(t+": expected odd modulus, got "+e)}function Js(e,t){let r=e,n=(r.ORDER+V)/Hn,o=r.pow(t,n);return zn(r,o,t),o}function Gc(e,t){let r=e,n=(r.ORDER-Zs)/Ys,o=r.mul(t,Wt),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,Wt),s),c=r.mul(i,r.sub(a,r.ONE));return zn(r,c,t),c}function Wc(e){let t=Ie(e),r=Qs(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Vc)/Gs;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),p=u.mul(f,o),h=u.mul(f,s),A=u.eql(u.sqr(l),c),w=u.eql(u.sqr(p),c);f=u.cmov(f,l,A),l=u.cmov(h,p,w);let I=u.eql(u.sqr(l),c),x=u.cmov(f,l,I);return zn(u,x,c),x})}function Qs(e){if(e<$s)throw new Error("sqrt is not defined for small field");jn(e,"tonelliShanks");let t=e-V,r=0;for(;t%Wt===ct;)t/=Wt,r++;let n=Wt,o=Ie(e);for(;Ge(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Js;let s=o.pow(n,t),i=(t+V)/Wt;return function(c,u){let f=c;if(f.is0(u))return u;if(Ge(f,u)!==1)throw new Error("Cannot find square root");let l=r,p=f.mul(f.ONE,s),h=f.pow(u,t),A=f.pow(u,i);for(;!f.eql(h,f.ONE);){if(f.is0(h))throw new Error("Cannot find square root: probably non-prime P");let w=1,I=f.sqr(h);for(;!f.eql(I,f.ONE);)if(w++,I=f.sqr(I),w===l)throw new Error("Cannot find square root");let x=V<<BigInt(l-w-1),v=f.pow(p,x);l=w,p=f.sqr(v),h=f.mul(h,p),A=f.mul(A,v)}return A}}function Xc(e){return jn(e,"Fp.sqrt"),e%Hn===$s?Js:e%Ys===Zs?Gc:e%Gs===$c?Wc(e):Qs(e)}var ti=(e,t)=>(Q(e,t)&V)===V,Jc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Be(e){if(Zt(e,"field"),typeof e.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof e.ORDER);Nt(e.BYTES,"BYTES"),Nt(e.BITS,"BITS");for(let t of Jc)oe(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 Ar(e,t,r=!1){Be(e),xr(t,"nums"),wt(r,"passZero");let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function Ge(e,t){Be(e);let r=e;jn(r.ORDER,"FpLegendre");let n=(r.ORDER-V)/Wt,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 Qc(e,t){if(t!==void 0&&kn(t),e<=ct)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=Ae(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 Vs=new WeakMap,vr=class{ORDER;BITS;BYTES;isLE;ZERO=ct;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}=Qc(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 Q(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return ct<=t&&t<this.ORDER}is0(t){return t===ct}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&V)===V}neg(t){return Q(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return Q(t*t,this.ORDER)}add(t,r){return Q(t+r,this.ORDER)}sub(t,r){return Q(t-r,this.ORDER)}mul(t,r){return Q(t*r,this.ORDER)}pow(t,r){return Ws(t,r,this.ORDER)}div(t,r){return Q(t*js(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 js(t,this.ORDER)}sqrt(t){let r=Vs.get(this);return r||Vs.set(this,r=Xc(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?Mn(t,this.BYTES):Sr(t,this.BYTES)}fromBytes(t,r=!1){j(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 u=new Uint8Array(o);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?ie(t):Ot(t);if(a&&(c=Q(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Ar(this,t,!0)}cmov(t,r,n){return wt(n,"condition"),n?r:t}};function Ie(e,t={}){return Object.freeze(vr.prototype),new vr(e,t)}function ei(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=Ae(e-V);return Math.ceil(t/8)}function Br(e){let t=ei(e);return t+Math.ceil(t/2)}function Ir(e,t,r=!1){j(e);let n=e.length,o=ei(t),s=Math.max(Br(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?ie(e):Ot(e),a=Q(i,t-V)+V;return r?Mn(a,o):Sr(a,o)}var Zn=BigInt(0),We=BigInt(1),tu=BigInt(4),Vn=16,ri=128,eu=5,ni=2**31;function Xt(e){let t=e;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof e);oe(t.fromAffine,"Point.fromAffine"),oe(t.fromBytes,"Point.fromBytes"),oe(t.fromHex,"Point.fromHex"),Zt(t.BASE,"Point.BASE"),Zt(t.ZERO,"Point.ZERO"),Be(t.Fp),Be(t.Fn)}function Tr(e,t){Xt(e),si(t,e);let r=Ar(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function ru(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 nu(e,t){let r=e*(4*t+128);if(r>ni)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+ni/2**20+" MiB")}function Yn(e,t){if(e!==void 0){oe(e,"randomBytes");try{let r=e(t);if(!Gt(r)||r.length!==t)return}catch{return}return e}}function si(e,t){xr(e,"points"),e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function ou(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):Yt(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var ii=new WeakMap;function $n(e){return ii.get(e)||1}function su(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 iu(e,t){let r=2**t,n=r/2,o=BigInt(r-1),s=[];for(;e>Zn;){let i=0;e&We&&(i=Number(e&o),i>=n&&(i-=r),e-=BigInt(i)),s.push(i),e>>=We}return s}function au(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 u=Number(e&s);e>>=i,u>o&&(u-=n,e+=We),a.push(u)}if(e!==Zn)throw new Error("invalid wnaf");return a}function cu(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 Te=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,r){Xt(t),this.randomBytes=Yn(r,Vn),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 u=a;for(let f=0;f<s;f++)i.push(u),u=u.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=au(r,n,o),c=this.ZERO,u=this.BASE;for(let f=0;f<o;f++){let l=a[f],p=f*i,h=Math.abs(l)-1,A=s[p];for(let I=1;I<i;I++)A=I===h?s[p+I]:A;let w=A.negate();l===0?u=u.add(s[p]):c=c.add(l<0?w:A)}return{p:c,f:u}}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),!qn(r,We,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,r,n,o){let s=$n(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+ri,s=this.randomBytes(Vn);if(!Gt(s)||s.length!==Vn)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+Ot(s)*this.Point.Fn.ORDER;return this.runCT(t,i,o,n)}fixedWindowCT(t,r,n){let o=eu,s=1<<o,i=Ye(o),a=new Array(s);a[0]=this.ZERO;for(let f=1;f<s;f++)a[f]=a[f-1].add(t);let c=Math.ceil(n/o),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let h=0;h<o;h++)u=u.double();let l=Number(r>>BigInt(f*o)&i),p=a[0];for(let h=1;h<s;h++)p=h===l?a[h]:p;u=u.add(p)}return{p:u,f:u}}shouldBlind(t,r){return this.randomBytes===void 0?!1:r===We?!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),!Yt(r))throw new Error("invalid scalar");let o=$n(t);if(o===1||r>=this.Point.Fn.ORDER)return Lr(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),ru(r,this.bits);let n=Math.ceil((this.bits+ri)/r)+1;nu(n*2**(r-1),this.Point.Fp.BYTES),ii.set(t,r),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return $n(t)!==1}};function Lr(e,t,r,n=!1){if(Xt(e),si(t,e),wt(n,"allowOversized"),ou(r,e.Fn,n?e.Fn.ORDER**tu:void 0),t.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=t.map(i=>su(i,4)),s=r.map(i=>iu(i,4));return cu(e.ZERO,o,s)}function oi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Be(t),t}else return Ie(e,{isLE:r})}function _r(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`);xt(r);for(let c of["p","n","h"]){let u=t[c];if(!(Yt(u)&&u!==Zn))throw new Error(`CURVE.${c} must be positive bigint`)}let o=oi(t.p,r.Fp,n),s=oi(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 Rr(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Dr=BigInt(0),Or=BigInt(1),Cr=BigInt(2),uu=BigInt(4),ai=BigInt(8);function fu(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 ci(e,t={}){xt(t,{},{},"extraOpts");let r=t,n=_r("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(Ge(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(Ge(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");xt(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?se:r.randomBytes,u=Cr<<BigInt(o.BYTES*8)-Or;function f(v){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(v)}let l=r.uvRatio===void 0?(v,y)=>{try{return{isValid:!0,value:o.sqrt(o.div(v,y))}}catch{return{isValid:!1,value:Dr}}}:r.uvRatio;if(!fu(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let p=o.eql(i.a,o.neg(o.ONE))?v=>o.neg(v):o.eql(i.a,o.ONE)?v=>v:v=>o.mul(i.a,v);function h(v,y,g=!1){let S=g?Or:Dr;return ve("coordinate "+v,y,S,u),y}function A(v){if(!(v instanceof w))throw new Error("EdwardsPoint expected")}class w{static BASE=new w(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new w(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(y,g,S,C){this.X=h("x",y),this.Y=h("y",g),this.Z=h("z",S,!0),this.T=h("t",C),Object.freeze(this)}static CURVE(){return i}static fromAffine(y){if(y instanceof w)throw new Error("extended point not allowed");let{x:g,y:S}=y||{};return h("x",g),h("y",S),new w(g,S,o.ONE,o.mul(g,S))}static fromBytes(y,g=!1){let S=o.BYTES,{a:C,d:U}=i;y=Ze(j(y,S,"point")),wt(g,"zip215");let P=Ze(y),R=y[S-1];P[S-1]=R&-129;let O=ie(P),q=g?u:o.ORDER;ve("point.y",O,Dr,q);let M=o.sqr(O),Z=o.sub(M,o.ONE),T=o.sub(o.mulN(U,M),C),{isValid:F,value:k}=l(Z,T);if(!F)throw new Error("bad point: invalid y coordinate");let D=f(k),Y=(R&128)!==0;if(!g&&o.is0(k)&&Y)throw new Error("bad point: x=0 and x_0=1");return Y!==D&&(k=o.neg(k)),w.fromAffine({x:k,y:O})}static fromHex(y,g=!1){return w.fromBytes(Se(y),g)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=6,g=!0){return x.setWindowSize(this,y),g||this.multiply(Cr),this}assertValidity(){let y=this,{a:g,d:S}=i;if(y.is0())throw new Error("bad point: ZERO");let{X:C,Y:U,Z:P,T:R}=y,O=o.sqr(C),q=o.sqr(U),M=o.sqr(P),Z=o.sqr(M),T=o.mul(O,g),F=o.mul(o.add(T,q),M),k=o.add(Z,o.mul(S,o.mul(O,q)));if(!o.eql(F,k))throw new Error("bad point: equation left != right (1)");let D=o.mul(C,U),Y=o.mul(P,R);if(!o.eql(D,Y))throw new Error("bad point: equation left != right (2)")}equals(y){A(y);let{X:g,Y:S,Z:C}=this,{X:U,Y:P,Z:R}=y,O=o.mul(g,R),q=o.mul(U,C),M=o.mul(S,R),Z=o.mul(P,C);return o.eql(O,q)&&o.eql(M,Z)}is0(){return this.equals(w.ZERO)}negate(){return new w(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:y,Y:g,Z:S}=this,C=o.sqr(y),U=o.sqr(g),P=o.mul(o.sqr(S),Cr),R=p(C),O=o.addN(y,g),q=o.sub(o.subN(o.sqr(O),C),U),M=o.addN(R,U),Z=o.subN(M,P),T=o.subN(R,U),F=o.mul(q,Z),k=o.mul(M,T),D=o.mul(q,T),Y=o.mul(Z,M);return new w(F,k,Y,D)}add(y){A(y);let{d:g}=i,{X:S,Y:C,Z:U,T:P}=this,{X:R,Y:O,Z:q,T:M}=y,Z=o.mul(S,R),T=o.mul(C,O),F=o.mul(o.mulN(P,g),M),k=o.mul(U,q),D=o.sub(o.subN(o.mulN(o.addN(S,C),o.addN(R,O)),Z),T),Y=o.subN(k,F),J=o.addN(k,F),E=o.sub(T,p(Z)),d=o.mul(D,Y),m=o.mul(J,E),b=o.mul(D,E),B=o.mul(Y,J);return new w(d,m,B,b)}subtract(y){return A(y),this.add(y.negate())}multiply(y){if(!s.isValidNot0(y))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:g,f:S}=x.mulSecret(this,y,a,I);return I([g,S])[0]}multiplyUnsafe(y){if(!s.isValid(y))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return y===Dr?w.ZERO:this.is0()||y===Or?this:x.mulUnsafe(this,y,I)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return x.mulUnsafe(this,i.n).is0()}toAffine(y){let g=this,S=y;if(S!=null&&typeof S!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof S);let{X:C,Y:U,Z:P}=g,R=g.is0();S==null&&(S=R?o.create(ai):o.inv(P));let O=o.mul(C,S),q=o.mul(U,S),M=o.mul(P,S);if(R)return{x:o.ZERO,y:o.ONE};if(!o.eql(M,o.ONE))throw new Error("invZ was invalid");return{x:O,y:q}}clearCofactor(){return a===Or?this:a===Cr?this.double():a===uu?this.double().double():a===ai?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:y,y:g}=this.toAffine(),S=o.toBytes(g);return S[S.length-1]|=f(y)?128:0,S}toHex(){return Ve(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let I=v=>Tr(w,v),x=new Te(w,c);return x.bits>=6&&w.BASE.precompute(6),Object.freeze(w.prototype),Object.freeze(w),w}function ui(e,t,r={}){if(Xt(e),typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;xt(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,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(Nt(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?se:o.randomBytes,p=o.toMontgomery,h=o.toMontgomerySecret,A=o.adjustScalarBytes===void 0?T=>T:o.adjustScalarBytes,w=o.domain===void 0?(T,F,k)=>{if(wt(k,"phflag"),F.length||k)throw new Error("Contexts/pre-hash are not supported");return T}:o.domain;function I(T){return c.create(ie(T))}function x(T){let F=R.secretKey;j(T,R.secretKey,"secretKey");let k=j(n(T),2*F,"hashedSecretKey"),D=A(k.slice(0,F)),Y=k.slice(F,2*F),J=I(D);return{head:D,prefix:Y,scalar:J}}function v(T){let{head:F,prefix:k,scalar:D}=x(T),Y=i.multiply(D),J=Y.toBytes();return{head:F,prefix:k,scalar:D,point:Y,pointBytes:J}}function y(T){return v(T).pointBytes}function g(T=Uint8Array.of(),...F){let k=Bt(...F);return I(n(w(k,j(T,void 0,"context"),!!s)))}function S(T,F,k={}){xt(k,{},{},"options"),T=Ze(j(T,void 0,"message")),s&&(T=s(T));let{prefix:D,scalar:Y,pointBytes:J}=v(F),E=g(k.context,D,T),d=i.multiply(E).toBytes(),m=g(k.context,d,J,T),b=c.create(E+m*Y);if(!c.isValid(b))throw new Error("sign failed: invalid s");let B=Bt(d,c.toBytes(b));return j(B,R.signature,"result")}let C={zip215:o.zip215};function U(T,F,k,D=C){xt(D);let{context:Y}=D,J=D.zip215===void 0?!!C.zip215:D.zip215,E=R.signature;T=j(T,E,"signature"),F=j(F,void 0,"message"),k=j(k,R.publicKey,"publicKey"),J!==void 0&&wt(J,"zip215"),s&&(F=s(F));let d=E/2,m=T.subarray(0,d),b=ie(T.subarray(d,E)),B,L,_;try{B=e.fromBytes(k,J),L=e.fromBytes(m,J),_=i.multiplyUnsafe(b)}catch{return!1}if(!J&&B.isSmallOrder())return!1;let K=g(Y,m,k,F);return L.add(B.multiplyUnsafe(K)).subtract(_).clearCofactor().is0()}let P=a.BYTES,R={secretKey:P,publicKey:P,signature:2*P,seed:P};function O(T){return T=T===void 0?l(R.seed):T,j(T,R.seed,"seed")}function q(T){return Gt(T)&&T.length===R.secretKey}function M(T,F){try{return!!e.fromBytes(T,F===void 0?C.zip215:F)}catch{return!1}}let Z={getExtendedPublicKey:v,randomSecretKey:O,isValidSecretKey:q,isValidPublicKey:M,toMontgomery(T){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(e.fromBytes(T))},toMontgomerySecret(T){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(T)}};return Object.freeze(R),Object.freeze(Z),Object.freeze({keygen:Rr(O,y),getPublicKey:y,sign:S,verify:U,utils:Z,Point:e,lengths:R})}var Gn=BigInt(1),fi=BigInt(2);var lu=BigInt(5),du=BigInt(8),Wn=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),hu={p:Wn,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:du,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function pu(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Wn,a=e*e%s*e%s,c=X(a,fi,s)*a%s,u=X(c,Gn,s)*e%s,f=X(u,lu,s)*u%s,l=X(f,t,s)*f%s,p=X(l,r,s)*l%s,h=X(p,n,s)*p%s,A=X(h,o,s)*h%s,w=X(A,o,s)*h%s,I=X(w,t,s)*f%s;return{pow_p_5_8:X(I,fi,s)*e%s,b2:a}}function hi(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var li=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function mu(e,t){let r=Wn,n=Q(t*t*t,r),o=Q(n*n*t,r),s=pu(e*o).pow_p_5_8,i=Q(e*n*s,r),a=Q(t*i*i,r),c=i,u=Q(i*li,r),f=a===e,l=a===Q(-e,r),p=a===Q(-e*li,r);return f&&(i=c),(l||p)&&(i=u),ti(i,r)&&(i=Q(-i,r)),{isValid:f||l,value:i}}var Xn=ci(hu,{uvRatio:mu}),di=Xn.Fp;function yu(e){let{y:t}=e;return di.toBytes(di.div(Gn+t,Gn-t))}function bu(e){let t=Xn.Fp.BYTES;return At(e,t),hi(Fn(e.subarray(0,t))).subarray(0,t)}function gu(e){return ui(Xn,Fn,Object.assign({adjustScalarBytes:hi,toMontgomery:yu,toMontgomerySecret:bu,zip215:!0},e))}var pi=gu({});var Xe=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Kr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var It={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Kr("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 Pr=32;var Jn,wu=(async()=>{try{return await It.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function xu(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await It.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await It.get().subtle.verify({name:"Ed25519"},n,yt(t),yt(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Eu(e,t,r){return pi.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function mi(e,t,r){return Jn==null&&(Jn=await wu),Jn?xu(e,t,r):Eu(e,t,r)}function Nr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Ur=class{type="Ed25519";raw;constructor(t){this.raw=Qn(t,Pr)}toMultihash(){return Rt.digest(zt(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return st.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=mi(this.raw,r,t);return Nr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function bi(e){return e=Qn(e,Pr),new Ur(e)}function Qn(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new ot(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var vu=Math.pow(2,7),Au=Math.pow(2,14),Bu=Math.pow(2,21),to=Math.pow(2,28),eo=Math.pow(2,35),ro=Math.pow(2,42),no=Math.pow(2,49),$=128,ht=127;function Ut(e){if(e<vu)return 1;if(e<Au)return 2;if(e<Bu)return 3;if(e<to)return 4;if(e<eo)return 5;if(e<ro)return 6;if(e<no)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function oo(e,t,r=0){switch(Ut(e)){case 8:t[r++]=e&255|$,e/=128;case 7:t[r++]=e&255|$,e/=128;case 6:t[r++]=e&255|$,e/=128;case 5:t[r++]=e&255|$,e/=128;case 4:t[r++]=e&255|$,e>>>=7;case 3:t[r++]=e&255|$,e>>>=7;case 2:t[r++]=e&255|$,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Iu(e,t,r=0){switch(Ut(e)){case 8:t.set(r++,e&255|$),e/=128;case 7:t.set(r++,e&255|$),e/=128;case 6:t.set(r++,e&255|$),e/=128;case 5:t.set(r++,e&255|$),e/=128;case 4:t.set(r++,e&255|$),e>>>=7;case 3:t.set(r++,e&255|$),e>>>=7;case 2:t.set(r++,e&255|$),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function so(e,t){let r=e[t],n=0;if(n+=r&ht,r<$||(r=e[t+1],n+=(r&ht)<<7,r<$)||(r=e[t+2],n+=(r&ht)<<14,r<$)||(r=e[t+3],n+=(r&ht)<<21,r<$)||(r=e[t+4],n+=(r&ht)*to,r<$)||(r=e[t+5],n+=(r&ht)*eo,r<$)||(r=e[t+6],n+=(r&ht)*ro,r<$)||(r=e[t+7],n+=(r&ht)*no,r<$))return n;throw new RangeError("Could not decode varint")}function Tu(e,t){let r=e.get(t),n=0;if(n+=r&ht,r<$||(r=e.get(t+1),n+=(r&ht)<<7,r<$)||(r=e.get(t+2),n+=(r&ht)<<14,r<$)||(r=e.get(t+3),n+=(r&ht)<<21,r<$)||(r=e.get(t+4),n+=(r&ht)*to,r<$)||(r=e.get(t+5),n+=(r&ht)*eo,r<$)||(r=e.get(t+6),n+=(r&ht)*ro,r<$)||(r=e.get(t+7),n+=(r&ht)*no,r<$))return n;throw new RangeError("Could not decode varint")}function gi(e,t,r=0){return t==null&&(t=bt(Ut(e))),t instanceof Uint8Array?oo(e,t,r):Iu(e,t,r)}function wi(e,t=0){return e instanceof Uint8Array?so(e,t):Tu(e,t)}var io=new Float32Array([-0]),Jt=new Uint8Array(io.buffer);function xi(e,t,r){io[0]=e,t[r]=Jt[0],t[r+1]=Jt[1],t[r+2]=Jt[2],t[r+3]=Jt[3]}function Ei(e,t){return Jt[0]=e[t],Jt[1]=e[t+1],Jt[2]=e[t+2],Jt[3]=e[t+3],io[0]}var ao=new Float64Array([-0]),pt=new Uint8Array(ao.buffer);function Si(e,t,r){ao[0]=e,t[r]=pt[0],t[r+1]=pt[1],t[r+2]=pt[2],t[r+3]=pt[3],t[r+4]=pt[4],t[r+5]=pt[5],t[r+6]=pt[6],t[r+7]=pt[7]}function vi(e,t){return pt[0]=e[t],pt[1]=e[t+1],pt[2]=e[t+2],pt[3]=e[t+3],pt[4]=e[t+4],pt[5]=e[t+5],pt[6]=e[t+6],pt[7]=e[t+7],ao[0]}var _u=BigInt(Number.MAX_SAFE_INTEGER),Ru=BigInt(Number.MIN_SAFE_INTEGER),Et=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 ae;if(t<_u&&t>Ru)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>Ai&&(o=0n,++n>Ai&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ae;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):ae}},ae=new Et(0,0);ae.toBigInt=function(){return 0n};ae.zzEncode=ae.zzDecode=function(){return this};ae.length=function(){return 1};var Ai=4294967296n;function Bi(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 Ii(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 co(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 Lt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Fr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var uo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=yt(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,Lt(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 Lt(this,4);return Fr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Lt(this,4);return Fr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Lt(this,4);let t=Ei(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Lt(this,4);let t=vi(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 Lt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Ii(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Lt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Lt(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 Et(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 Lt(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 Lt(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 Lt(this,8);let t=Fr(this.buf,this.pos+=4),r=Fr(this.buf,this.pos+=4);return new Et(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=so(this.buf,this.pos);return this.pos+=Ut(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Je(e){return new uo(e instanceof Uint8Array?e:e.subarray())}function Le(e,t,r){let n=Je(e);return t.decode(n,void 0,r)}function fo(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return bt(i);o+i>t&&(n=bt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ce=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function lo(){}var po=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Du=fo();function Ou(e){return globalThis.Buffer!=null?bt(e):Du(e)}var tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ce(lo,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ce(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new mo((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(kr,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Et.fromBigInt(t);return this._push(kr,r.length(),r)}uint64Number(t){return this._push(oo,Ut(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=Et.fromBigInt(t).zzEncode();return this._push(kr,r.length(),r)}sint64Number(t){let r=Et.fromNumber(t).zzEncode();return this._push(kr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ho,1,t?1:0)}fixed32(t){return this._push(Qe,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Et.fromBigInt(t);return this._push(Qe,4,r.lo)._push(Qe,4,r.hi)}fixed64Number(t){let r=Et.fromNumber(t);return this._push(Qe,4,r.lo)._push(Qe,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(xi,4,t)}double(t){return this._push(Si,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(ho,1,0):this.uint32(r)._push(Ku,r,t)}string(t){let r=Bi(t);return r!==0?this.uint32(r)._push(co,r,t):this._push(ho,1,0)}fork(){return this.states=new po(this),this.head=this.tail=new ce(lo,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 ce(lo,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=Ou(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function ho(e,t,r){t[r]=e&255}function Cu(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var mo=class extends ce{next;constructor(t,r){super(Cu,t,r),this.next=void 0}};function kr(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 Qe(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 Ku(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(tr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Pu,t,e),this},tr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Nu,t,e),this});function Pu(e,t,r){t.set(e,r)}function Nu(e,t,r){e.length<40?co(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(it(e),r)}function yo(){return new tr}function _e(e,t){let r=yo();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Re(e,t,r){let n=Je(e);yield*t.stream(n,void 0,".",r)}var Mr={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function qr(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function bo(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 qr("enum",Mr.VARINT,r,n,o)}function De(e,t,r){return qr("message",Mr.LENGTH_DELIMITED,e,t,r)}var at;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(at||(at={}));var go;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(go||(go={}));(function(e){e.codec=()=>bo(go)})(at||(at={}));var Ft;(function(e){let t;e.codec=()=>(t==null&&(t=De((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),at.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={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=at.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:at.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return _e(s,e.codec())}e.encode=r;function n(s,i){return Le(s,e.codec(),i)}e.decode=n;function o(s,i){return Re(s,e.codec(),i)}e.stream=o})(Ft||(Ft={}));var wo;(function(e){let t;e.codec=()=>(t==null&&(t=De((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),at.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={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=at.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:at.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return _e(s,e.codec())}e.encode=r;function n(s,i){return Le(s,e.codec(),i)}e.decode=n;function o(s,i){return Re(s,e.codec(),i)}e.stream=o})(wo||(wo={}));var rr={};mt(rr,{MAX_RSA_KEY_SIZE:()=>xo,generateRSAKeyPair:()=>Oi,jwkToJWKKeyPair:()=>Ci,jwkToPkcs1:()=>Mu,jwkToPkix:()=>Ao,jwkToRSAPrivateKey:()=>Lo,pkcs1MessageToJwk:()=>So,pkcs1MessageToRSAPrivateKey:()=>Bo,pkcs1ToJwk:()=>ku,pkcs1ToRSAPrivateKey:()=>Di,pkixMessageToJwk:()=>vo,pkixMessageToRSAPublicKey:()=>To,pkixToJwk:()=>qu,pkixToRSAPublicKey:()=>Io});var Oe=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=rr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return dt.createV1(114,this._multihash)}toString(){return st.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,r,n){return Ri(this.jwk,r,t,n)}},er=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=rr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}sign(t,r){return _i(this.jwk,t,r)}};var xo=8192,Eo=18,Uu=1062,Fu=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function ku(e){let t=Kt(e);return So(t)}function So(e){return{n:et(e[1],"base64url"),e:et(e[2],"base64url"),d:et(e[3],"base64url"),p:et(e[4],"base64url"),q:et(e[5],"base64url"),dp:et(e[6],"base64url"),dq:et(e[7],"base64url"),qi:et(e[8],"base64url"),kty:"RSA"}}function Mu(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new ot("JWK was missing components");return Ht([gt(Uint8Array.from([0])),gt(it(e.n,"base64url")),gt(it(e.e,"base64url")),gt(it(e.d,"base64url")),gt(it(e.p,"base64url")),gt(it(e.q,"base64url")),gt(it(e.dp,"base64url")),gt(it(e.dq,"base64url")),gt(it(e.qi,"base64url"))]).subarray()}function qu(e){let t=Kt(e,{offset:0});return vo(t)}function vo(e){let t=Kt(e[1],{offset:0});return{kty:"RSA",n:et(t[0],"base64url"),e:et(t[1],"base64url")}}function Ao(e){if(e.n==null||e.e==null)throw new ot("JWK was missing components");return Ht([Fu,lr(Ht([gt(it(e.n,"base64url")),gt(it(e.e,"base64url"))]))]).subarray()}function Di(e){let t=Kt(e);return Bo(t)}function Bo(e){let t=So(e);return Lo(t)}function Io(e,t){if(e.byteLength>=Uu)throw new Qt("Key size is too large");let r=Kt(e,{offset:0});return To(r,e,t)}function To(e,t,r){let n=vo(e);if(r==null){let o=Ee(Ft.encode({Type:at.RSA,Data:t}));r=_t(Eo,o)}return new Oe(n,r)}function Lo(e){if(Pi(e)>xo)throw new ot("Key size is too large");let t=Ci(e),r=Ee(Ft.encode({Type:at.RSA,Data:Ao(t.publicKey)})),n=_t(Eo,r);return new er(t.privateKey,new Oe(t.publicKey,n))}async function Oi(e){if(e>xo)throw new ot("Key size is too large");let t=await Ki(e),r=Ee(Ft.encode({Type:at.RSA,Data:Ao(t.publicKey)})),n=_t(Eo,r);return new er(t.privateKey,new Oe(t.publicKey,n))}function Ci(e){if(e==null)throw new ot("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Ki(e,t){let r=await It.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Hu(r,t);return{privateKey:n[0],publicKey:n[1]}}async function _i(e,t,r){let n=await It.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await It.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,yt(t instanceof Uint8Array?t:t.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Ri(e,t,r,n){let o=await It.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await It.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,yt(t),yt(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function Hu(e,t){if(e.privateKey==null||e.publicKey==null)throw new ot("Private and public key are required");let r=await Promise.all([It.get().subtle.exportKey("jwk",e.privateKey),It.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Pi(e){if(e.kty!=="RSA")throw new ot("invalid key type");if(e.n==null)throw new ot("invalid key modulus");return it(e.n,"base64url").length*8}var Hr=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(pr(t),At(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),ne(o)}update(t){return xe(this),this.iHash.update(t),this}digestInto(t){xe(this),mr(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()}},Ni=(()=>{let e=((t,r,n)=>new Hr(t,r).update(n).digest());return e.create=(t,r)=>new Hr(t,r),e})();var zu=BigInt(0),_o=class extends Error{constructor(t=""){super(t)}},kt={Err:_o,_tlv:{encode:(e,t)=>{let{Err:r}=kt;if(Nt(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(qs(t,"data"),t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=$e(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?$e(o.length/2|128):"";return $e(e)+s+o+t},decode(e,t){let{Err:r}=kt;t=j(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.decode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let 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 u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=kt;if(Er(e),e<zu)throw new t("integer: negative integers are not allowed");let r=$e(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=kt;if(e.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 Ot(e)}},toSig(e,t){let{Err:r,_int:n,_tlv:o}=kt;if(t!==void 0&&(Nt(t,"maxScalarBytes"),t<1))throw new r("invalid signature: maxScalarBytes must be positive");let s=j(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:u}=o.decode(2,i),{v:f,l}=o.decode(2,u);if(l.length)throw new r("invalid signature: left bytes after parsing");if(t!==void 0&&(c.length>t||f.length>t))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=kt;xt(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)}},zr=(Object.freeze(kt._tlv),Object.freeze(kt._int),Object.freeze(kt));var Ui=(e,t)=>(e+(e>=0?t:-t)/Fi)/t;function ju(e,t,r){ve("scalar",e,Mt,r);let[[n,o],[s,i]]=t,a=Ui(i*e,r),c=Ui(-o*e,r),u=e-a*n-c*s,f=-a*o-c*i,l=u<Mt,p=f<Mt;l&&(u=-u),p&&(f=-f);let h=Ye(Math.ceil(Ae(r)/2))+ue;if(u<Mt||u>=h||f<Mt||f>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:p,k2:f}}function Oo(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Ro(e,t){xt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return wt(r.lowS,"lowS"),wt(r.prehash,"prehash"),r.format!==void 0&&Oo(r.format),r}var Mt=BigInt(0),ue=BigInt(1),Fi=BigInt(2),Do=BigInt(3),Vu=BigInt(4);function ki(e,t={}){let r=_r("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;xt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:l,fromBytes:p,toBytes:h}=t,A=t.randomBytes===void 0?se: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 w=c?{beta:c.beta,basises:c.basises.map(E=>[...E])}:void 0,I=qi(n,o);function x(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function v(E,d,m){if(d.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:b,y:B}=d.toAffine(),L=n.toBytes(b);if(wt(m,"isCompressed"),m){x();let _=!n.isOdd(B);return Bt(Mi(_),L)}else return Bt(Uint8Array.of(4),L,n.toBytes(B))}function y(E){j(E,void 0,"Point");let{publicKey:d,publicKeyUncompressed:m}=I,b=E.length,B=E[0],L=E.subarray(1);if(u&&b===1&&B===0)return{x:n.ZERO,y:n.ZERO};if(b===d&&(B===2||B===3)){let _=n.fromBytes(L);if(!n.isValid(_))throw new Error("bad point: is not on curve, wrong x");let K=P(_),N;try{N=n.sqrt(K)}catch(rt){let G=rt instanceof Error?": "+rt.message:"";throw new Error("bad point: is not on curve, sqrt error"+G)}x();let z=n.isOdd(N);return(B&1)===1!==z&&(N=n.neg(N)),{x:_,y:N}}else if(b===m&&B===4){let _=n.BYTES,K=n.fromBytes(L.subarray(0,_)),N=n.fromBytes(L.subarray(_,_*2));if(!R(K,N))throw new Error("bad point: is not on curve");return{x:K,y:N}}else throw new Error(`bad point: got length ${b}, expected compressed=${d} or uncompressed=${m}`)}let g=h===void 0?v:h,S=p===void 0?y:p,C=n.mul(s.b,Do),U=n.is0(s.a)?E=>n.ZERO:E=>n.mul(s.a,E);function P(E){let d=n.sqr(E),m=n.mul(d,E);return n.add(n.add(m,n.mul(E,s.a)),s.b)}function R(E,d){let m=n.sqr(d),b=P(E);return n.eql(m,b)}if(!R(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let O=n.mul(n.pow(s.a,Do),Vu),q=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(O,q)))throw new Error("bad curve params: a or b");function M(E,d,m=!1){if(!n.isValid(d)||m&&n.is0(d))throw new Error(`bad point coordinate ${E}`);return typeof d=="object"&&d!==null?n.create(d):d}function Z(E){if(!(E instanceof D))throw new Error("Weierstrass Point expected")}function T(E){if(!w||!w.basises)throw new Error("no endo");return ju(E,w.basises,o.ORDER)}function F(E,d,m,b){if(!o.isValid(b))throw new RangeError("invalid scalar: out of range");if(w){let{k1neg:B,k1:L,k2neg:_,k2:K}=T(b),N=new D(n.mul(m.X,w.beta),m.Y,m.Z);E.push(B?m.negate():m,_?N.negate():N),d.push(L,K)}else E.push(m),d.push(b)}let k=new WeakSet;class D{static BASE=new D(s.Gx,s.Gy,n.ONE);static ZERO=new D(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(d,m,b){this.X=M("x",d),this.Y=M("y",m,!0),this.Z=M("z",b),Object.freeze(this)}static CURVE(){return s}static fromAffine(d){let{x:m,y:b}=d||{};if(!d||!n.isValid(m)||!n.isValid(b))throw new Error("invalid affine point");if(d instanceof D)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(b)?D.ZERO:new D(m,b,n.ONE)}static fromBytes(d){let m=D.fromAffine(S(j(d,void 0,"point")));return m.assertValidity(),m}static fromHex(d){return D.fromBytes(Se(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=6,m=!0){return J.setWindowSize(this,d),m||this.multiply(Do),this}assertValidity(){let d=this;if(d.is0()){if(u&&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:m,y:b}=d.toAffine();if(!n.isValid(m)||!n.isValid(b))throw new Error("bad point: x or y not field elements");if(!R(m,b))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){Z(d);let{X:m,Y:b,Z:B}=this,{X:L,Y:_,Z:K}=d,N=n.eql(n.mul(m,K),n.mul(L,B)),z=n.eql(n.mul(b,K),n.mul(_,B));return N&&z}negate(){return new D(this.X,n.neg(this.Y),this.Z)}double(){let{X:d,Y:m,Z:b}=this,B=n.ZERO,L=n.ZERO,_=n.ZERO,K=n.mul(d,d),N=n.mul(m,m),z=n.mul(b,b),H=n.mul(d,m);return H=n.add(H,H),_=n.mul(d,b),_=n.add(_,_),B=U(_),L=n.mul(C,z),L=n.add(B,L),B=n.sub(N,L),L=n.add(N,L),L=n.mul(B,L),B=n.mul(H,B),_=n.mul(C,_),z=U(z),H=n.sub(K,z),H=U(H),H=n.add(H,_),_=n.add(K,K),K=n.add(_,K),K=n.add(K,z),K=n.mul(K,H),L=n.add(L,K),z=n.mul(m,b),z=n.add(z,z),K=n.mul(z,H),B=n.sub(B,K),_=n.mul(z,N),_=n.add(_,_),_=n.add(_,_),new D(B,L,_)}add(d){Z(d);let{X:m,Y:b,Z:B}=this,{X:L,Y:_,Z:K}=d,N=n.ZERO,z=n.ZERO,H=n.ZERO,rt=n.mul(m,L),G=n.mul(b,_),ut=n.mul(B,K),St=n.add(m,b),W=n.add(L,_);St=n.mul(St,W),W=n.add(rt,G),St=n.sub(St,W),W=n.add(m,B);let nt=n.add(L,K);return W=n.mul(W,nt),nt=n.add(rt,ut),W=n.sub(W,nt),nt=n.add(b,B),N=n.add(_,K),nt=n.mul(nt,N),N=n.add(G,ut),nt=n.sub(nt,N),H=U(W),N=n.mul(C,ut),H=n.add(N,H),N=n.sub(G,H),H=n.add(G,H),z=n.mul(N,H),G=n.add(rt,rt),G=n.add(G,rt),ut=U(ut),W=n.mul(C,W),G=n.add(G,ut),ut=n.sub(rt,ut),ut=U(ut),W=n.add(W,ut),rt=n.mul(G,W),z=n.add(z,rt),rt=n.mul(nt,W),N=n.mul(St,N),N=n.sub(N,rt),rt=n.mul(St,G),H=n.mul(nt,H),H=n.add(H,rt),new D(N,z,H)}subtract(d){return Z(d),this.add(d.negate())}is0(){return this.equals(D.ZERO)}multiply(d){if(!o.isValidNot0(d))throw new RangeError("invalid scalar: out of range");let{p:m,f:b}=J.mulSecret(this,d,i,Y);return Y([m,b])[0]}multiplyUnsafe(d){let m=this,b=d;if(!o.isValid(b))throw new RangeError("invalid scalar: out of range");if(b===Mt||m.is0())return D.ZERO;if(b===ue)return m;if(J.hasWindowSize(this))return J.mulUnsafe(m,b,Y);let B=[],L=[];return F(B,L,m,b),Lr(D,B,L)}mulAddUnsafe(d,m,b){Z(m);let B=[],L=[];return F(B,L,this,d),F(B,L,m,b),Lr(D,B,L)}toAffine(d){let m=this,b=d;if(b!=null&&!n.isValid(b))throw new RangeError('"invertedZ" expected valid field element');let{X:B,Y:L,Z:_}=m;if(n.eql(_,n.ONE))return{x:B,y:L};let K=m.is0();b==null&&(b=K?n.ONE:n.inv(_));let N=n.mul(B,b),z=n.mul(L,b),H=n.mul(_,b);if(K)return{x:n.ZERO,y:n.ZERO};if(!n.eql(H,n.ONE))throw new Error("invZ was invalid");return{x:N,y:z}}isTorsionFree(){return i===ue?!0:l?l(D,this):J.mulUnsafe(this,a).is0()}clearCofactor(){return i===ue?this:f?f(D,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===ue?this.is0():this.clearCofactor().is0()}toBytes(d=!0){return wt(d,"isCompressed"),this.assertValidity(),g(D,this,d)}toHex(d=!0){return Ve(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let Y=E=>Tr(D,E),J=new Te(D,A);return J.bits>=6&&D.BASE.precompute(6),Object.freeze(D.prototype),Object.freeze(D),D}function Mi(e){return Uint8Array.of(e?2:3)}function qi(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function $u(e,t={}){Xt(e);let{Fn:r}=e,n=t.randomBytes===void 0?se:t.randomBytes,o=Object.assign(qi(e.Fp,r),{seed:Math.max(Br(r.ORDER),16)});function s(h){try{let A=r.fromBytes(h);return r.isValidNot0(A)}catch{return!1}}function i(h,A){let{publicKey:w,publicKeyUncompressed:I}=o;try{let x=h.length;return A===!0&&x!==w||A===!1&&x!==I?!1:!e.fromBytes(h).is0()}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,Ir(j(h,o.seed,"seed"),r.ORDER)}function c(h,A=!0){return e.BASE.multiply(r.fromBytes(h)).toBytes(A)}function u(h){let{secretKey:A,publicKey:w,publicKeyUncompressed:I}=o,x=r._lengths;if(!Gt(h))return;let v=j(h,void 0,"key").length,y=v===w||v===I,g=v===A||!!x?.includes(v);if(!(y&&g))return y}function f(h,A,w=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(A)===!1)throw new Error("second arg must be public key");let I=r.fromBytes(h),x=e.fromBytes(A);if(x.is0())throw new Error("invalid public key: point at infinity");return x.multiply(I).toBytes(w)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},p=Rr(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:p,Point:e,utils:l,lengths:o})}function Hi(e,t,r={}){Xt(e);let n=t;pr(n),xt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?se:o.randomBytes,i=o.hmac===void 0?(E,d)=>Ni(n,E,d):o.hmac,{Fp:a,Fn:c}=e,{ORDER:u,BITS:f}=c,l=Br(u),p=Yn(s,l),{keygen:h,getPublicKey:A,getSharedSecret:w,utils:I,lengths:x}=$u(e,o),v={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},y=u*Fi+ue<a.ORDER;function g(E){let d=u>>ue;return E>d}function S(E,d){if(!c.isValidNot0(d))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return d}function C(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function U(E,d,m){return C(),(E===m?0:2)|Number(a.isOdd(d))}function P(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function R(E,d){Oo(d);let m=x.signature,b=d==="compact"?m:d==="recovered"?m+1:void 0;return j(E,b)}class O{r;s;recovery;constructor(d,m,b){if(this.r=S("r",d),this.s=S("s",m),b!=null){if(P(),![0,1,2,3].includes(b))throw new Error("invalid recovery id");this.recovery=b}Object.freeze(this)}static fromBytes(d,m=v.format){R(d,m);let b;if(m==="der"){if(d.length>2*c.BYTES+16)throw new zr.Err("invalid signature: DER signature too long");let{r:K,s:N}=zr.toSig(j(d),c.BYTES+1);return new O(K,N)}m==="recovered"&&(b=d[0],m="compact",d=d.subarray(1));let B=x.signature/2,L=d.subarray(0,B),_=d.subarray(B,B*2);return new O(c.fromBytes(L),c.fromBytes(_),b)}static fromHex(d,m){return this.fromBytes(Se(d),m)}assertRecovery(){let{recovery:d}=this;if(d==null)throw new Error("invalid recovery id: must be present");return d}addRecoveryBit(d){return new O(this.r,this.s,d)}recoverPublicKey(d){let{r:m,s:b}=this,B=this.assertRecovery(),L=B===2||B===3?m+u:m;if(!a.isValid(L))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let _=a.toBytes(L),K=e.fromBytes(Bt(Mi((B&1)===0),_)),N=c.inv(L),z=M(j(d,void 0,"msgHash")),H=c.create(-z*N),rt=c.create(b*N),G=e.BASE.mulAddUnsafe(H,K,rt);if(G.is0())throw new Error("invalid recovery: point at infinify");return G.assertValidity(),G}hasHighS(){return g(this.s)}toBytes(d=v.format){if(Oo(d),d==="der")return Se(zr.hexFromSig(this));let{r:m,s:b}=this,B=c.toBytes(m),L=c.toBytes(b);return d==="recovered"?(P(),Bt(Uint8Array.of(this.assertRecovery()),B,L)):Bt(B,L)}toHex(d){return Ve(this.toBytes(d))}}Object.freeze(O.prototype),Object.freeze(O);let q=o.bits2int===void 0?function(d){if(d.length>8192)throw new Error("input is too large");let m=Ot(d),b=d.length*8-f;return b>0?m>>BigInt(b):m}:o.bits2int,M=o.bits2int_modN===void 0?function(d){return c.create(q(d))}:o.bits2int_modN,Z=Ye(f);function T(E){return ve("num < 2^"+f,E,Mt,Z),c.toBytes(E)}function F(E,d){return j(E,void 0,"message"),d?j(n(E),void 0,"prehashed message"):E}function k(E,d,m){let{lowS:b,prehash:B,extraEntropy:L}=Ro(m,v);E=F(E,B);let _=M(E),K=c.fromBytes(d);if(!c.isValidNot0(K))throw new Error("invalid private key");let N=[T(K),T(_)];if(L!=null&&L!==!1){let G=L===!0?s(x.secretKey):L;N.push(j(G,void 0,"extraEntropy"))}let z=Bt(...N),H=_;function rt(G){let ut=q(G);if(!c.isValidNot0(ut))return;let St=e.BASE.multiply(ut).toAffine(),W=c.create(St.x);if(W===Mt)return;let nt;if(p!==void 0){let Ke=Ot(Ir(p(l),u)),ea=c.inv(c.mul(Ke,ut)),ra=c.mul(Ke,H),na=c.mul(Ke,K);nt=c.create(ea*c.create(ra+na*W))}else{let Ke=Xs(ut,u);nt=c.create(Ke*c.create(H+W*K))}if(nt===Mt)return;let Wr=U(St.x,St.y,W),jo=nt;return b&&g(nt)&&(jo=c.neg(nt),Wr^=1),new O(W,jo,y?void 0:Wr)}return{seed:z,k2sig:rt}}function D(E,d,m={}){let{seed:b,k2sig:B}=k(E,d,m);return zs(n.outputLen,c.BYTES,i)(b,B).toBytes(m.format)}function Y(E,d,m,b={}){let{lowS:B,prehash:L,format:_}=Ro(b,v);if(m=j(m,void 0,"publicKey"),d=F(d,L),!Gt(E)){let K=E instanceof O?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+K)}R(E,_);try{let K=O.fromBytes(E,_),N=e.fromBytes(m);if(N.is0()||B&&K.hasHighS())return!1;let{r:z,s:H}=K,rt=M(d),G=c.inv(H),ut=c.create(rt*G),St=c.create(z*G),W=e.BASE.mulAddUnsafe(ut,N,St);if(W.is0())return!1;let nt=W.toAffine();return!(c.create(nt.x)!==z||_==="recovered"&&K.recovery!==U(nt.x,nt.y,z))}catch{return!1}}function J(E,d,m={}){let{prehash:b}=Ro(m,v);return d=F(d,b),O.fromBytes(E,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:h,getPublicKey:A,getSharedSecret:w,utils:I,lengths:x,Point:e,sign:D,verify:Y,recoverPublicKey:J,Signature:O,hash:n})}var Ko={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Zu={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var zi=BigInt(2);function Yu(e){let t=Ko.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=X(f,r,t)*f%t,p=X(l,r,t)*f%t,h=X(p,zi,t)*u%t,A=X(h,o,t)*h%t,w=X(A,s,t)*A%t,I=X(w,a,t)*w%t,x=X(I,c,t)*I%t,v=X(x,a,t)*w%t,y=X(v,r,t)*f%t,g=X(y,i,t)*A%t,S=X(g,n,t)*u%t,C=X(S,zi,t);if(!Co.eql(Co.sqr(C),e))throw new Error("Cannot find square root");return C}var Co=Ie(Ko.p,{sqrt:Yu}),Gu=ki(Ko,{Fp:Co,endo:Zu}),Ce=Hi(Gu,Ee);function ji(e,t,r,n){let o=ur.digest(r instanceof Uint8Array?r:r.subarray());if(Nr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ce.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Xe(String(s))});try{return n?.signal?.throwIfAborted(),Ce.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new Xe(String(s))}}var jr=class{type="secp256k1";raw;_key;constructor(t){this._key=$i(t),this.raw=Vi(this._key)}toMultihash(){return Rt.digest(zt(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return st.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,r,n){return ji(this._key,r,t,n)}};function Zi(e){return new jr(e)}function Vi(e){return Ce.Point.fromBytes(e).toBytes()}function $i(e){try{return Ce.Point.fromBytes(e),e}catch(t){throw new Qt(String(t))}}function Yi(e,t){let{Type:r,Data:n}=Ft.decode(e),o=n??new Uint8Array;switch(r){case at.RSA:return Io(o,t);case at.Ed25519:return bi(o);case at.secp256k1:return Zi(o);case at.ECDSA:return ws(o);default:throw new de}}function zt(e){return Ft.encode({Type:at[e.type],Data:e.raw})}var Gi=Symbol.for("nodejs.util.inspect.custom"),Wu=114,nr=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()})`}[Jr]=!0;toString(){return this.string==null&&(this.string=st.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return dt.createV1(Wu,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return lt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return lt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Gi](){return`PeerId(${this.toString()})`}},Vr=class extends nr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},$r=class extends nr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Zr=class extends nr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Xu=2336,Po=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Rt.digest(it(this.url))}[Gi](){return`PeerId(${this.url})`}[Jr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return dt.createV1(Xu,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=et(t)),t.toString()===this.toString())}};function Wi(e){if(e.type==="Ed25519")return new $r({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Zr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Vr({multihash:e.toCID().multihash,publicKey:e});throw new de}var No=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},Xi=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function Uo(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,f=new Promise((l,p)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){p(Xi(i)),e.then(l,p);return}if(i&&(c=()=>{p(Xi(i))},i.addEventListener("abort",c,{once:!0})),e.then(l,p),r===Number.POSITIVE_INFINITY)return;let h=new No;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(A){p(A)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?l():o instanceof Error?p(o):(h.message=o??`Promise timed out after ${r} milliseconds`,p(h))},r)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Ji=e=>typeof e=="function"?{filter:e}:{...e},Ju=e=>e===1/0||Number.isSafeInteger(e)&&e>=0,Qu=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],tf=e=>{for(let[t,r]of Qu){let n=e?.[t],o=e?.[r];if(typeof n=="function"&&typeof o=="function")return{addListener:n.bind(e),removeListener:o.bind(e)}}throw new TypeError("Emitter is not compatible")},ef=e=>{let t=new Map;for(let[r,n]of e)for(let o of Array.isArray(r)?r:[r])t.has(o)||t.set(o,n);return t},rf=({addListener:e,removeListener:t,handlers:r,signal:n,abortHandler:o,isDone:s})=>{n?.addEventListener("abort",o,{once:!0});for(let[i,a]of r)if(e(i,a),s()){t(i,a);return}},nf=({removeListener:e,handlers:t,signal:r,abortHandler:n})=>{for(let[o,s]of t)e(o,s);r?.removeEventListener("abort",n)},of=(e,t,r)=>{let n=Promise.resolve();return(o,s)=>{n=n.then(async()=>{if(t())return;let i;try{i=e?await e(o):!0}catch(a){t()||r(a);return}t()||s(i)})}};function sf(e,t,r){let n=()=>{},o=!1,s,i=new Promise((a,c)=>{r=Ji(r);let{filter:u}=r;if(!Ju(r.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof r.timeout=="number"&&!(r.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${r.timeout}\``);r.signal?.throwIfAborted();let{addListener:f,removeListener:l}=tf(e);if(r.count===0){a([]);return}let p=[],h=g=>{n(),c(g)},A=of(u,()=>o,h),w=g=>{p.push(g),r.count===p.length&&(n(),a(p))},I=(...g)=>{if(o)return;let S=r.multiArgs?g:g[0];if(!u){w(S);return}A(S,C=>{C&&w(S)})},x=(...g)=>{h(r.rejectionMultiArgs?g:g[0])},v=()=>{h(r.signal.reason)},y={addListener:f,removeListener:l,handlers:ef([[t,I],[r.rejectionEvents??["error"],x]]),signal:r.signal,abortHandler:v,isDone:()=>o};n=()=>{o=!0,clearTimeout(s),nf(y)},rf(y),!(o||!r.resolveImmediately)&&(Number.isFinite(r.timeout)&&(s=setTimeout(n,r.timeout)),a(p))});if(i.cancel=n,typeof r.timeout=="number"&&r.timeout>0&&!r.resolveImmediately){let a=Uo(i,{milliseconds:r.timeout});return a.cancel=()=>{n(),a.clear()},a}return i}function Qi(e,t,r){let n=sf(e,t,{...Ji(r),count:1,resolveImmediately:!1}),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var fe=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function af(e){return e.reason}function Fo(e,t,r){if(t==null||e==null)return e;let n=r?.translateError??af;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;return Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})]).finally(()=>{o!=null&&t.removeEventListener("abort",o)})}var uf=4194304,Yr=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Mo=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},qo=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ho=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function ff(e){return typeof e?.closeRead=="function"}function lf(e){return typeof e?.close=="function"}function ko(e){return ff(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:lf(e)?e.status!=="open":!1}function df(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function hf(e,t){let r=t?.maxBufferSize??uf,n=new ft,o,s=!1,i;if(!df(e))throw new ot("Argument should be a Stream or a Multiaddr");let a=l=>{if(!s&&i==null){if(n.append(l.data),n.byteLength>r){let p=n.byteLength;n.consume(p);let h=new sr(`Read buffer overflow - ${p} > ${r}`);i=h,o?.reject(h),queueMicrotask(()=>{e.abort(h)});return}o?.resolve()}};e.addEventListener("message",a);let c=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};e.addEventListener("close",c);let u=()=>{o?.resolve()};e.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(l){if(s===!0)throw new Yr("Stream was unwrapped");if(i!=null)throw i;if(ko(e)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new fe(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let p=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=p){o.resolve();break}if(await Fo(o.promise,l?.signal),ko(e)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let h=l?.bytes??n.byteLength;if(n.byteLength<h){if(ko(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,h),new fe(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return f.read(l)}let A=n.sublist(0,h);return n.consume(h),A},async write(l,p){if(s===!0)throw new Yr("Stream was unwrapped");e.send(l)||await Qi(e,"drain",{signal:p?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",a),e.removeEventListener("close",c),e.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.unshift(n),n.consume(n.byteLength))),e}};return f}function pf(e,t={}){let r=hf(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Ut(t.maxDataLength));let n=t?.lengthDecoder??wi,o=t?.lengthEncoder??gi;return{async read(i){let a=-1,c=new ft;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Mo("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Ho(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new qo(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",a),new fe(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new fe(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new ft(o(i.byteLength),i),a)},async writeV(i,a){let c=new ft(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function ta(e,t){let r=pf(e,t),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i,s)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var Gr;(function(e){let t;e.codec=()=>(t==null&&(t=De((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.id!=null&&(i.uint32(10),i.bytes(s.id)),s.pubkey!=null&&(i.uint32(18),i.bytes(s.pubkey)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.id=s.bytes();break}case 2:{c.pubkey=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"Exchange"});s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}id`,value:s.bytes()};break}case 2:{yield{field:`${a}pubkey`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"Exchange"})})),t);function r(s){return _e(s,e.codec())}e.encode=r;function n(s,i){return Le(s,e.codec(),i)}e.decode=n;function o(s,i){return Re(s,e.codec(),i)}e.stream=o})(Gr||(Gr={}));var mf="/plaintext/2.0.0",zo=class{protocol=mf;privateKey;log;constructor(t){this.privateKey=t.privateKey,this.log=t.logger.forComponent("libp2p:plaintext")}[Symbol.toStringTag]="@libp2p/plaintext";[Vo]=["@libp2p/connection-encryption"];async secureInbound(t,r){return this._encrypt(t,r)}async secureOutbound(t,r){return this._encrypt(t,r)}async _encrypt(t,r){let n=t.log?.newScope("plaintext")??this.log,o=ta(t).pb(Gr);n("write pubkey exchange to peer %p",r?.remotePeer);let s=this.privateKey.publicKey;await o.write({id:s.toMultihash().bytes,pubkey:yt(zt(s))},r);let i=await o.read(r),a;try{if(i.pubkey==null)throw new le("Public key missing");if(i.pubkey.byteLength===0)throw new le("Public key data too short");if(i.id==null)throw new le("Remote id missing");let c=Yi(i.pubkey);if(!lt(c.toMultihash().bytes,i.id))throw new Pe("Public key did not match id");a=Wi(c)}catch(c){throw n.error("invalid public key - %e",c),new Pe(`Invalid public key - ${c.message}`)}if(r?.remotePeer!=null&&!a.equals(r?.remotePeer))throw new or;return n("plaintext key exchange completed successfully with peer %p",a),{connection:o.unwrap().unwrap(),remotePeer:a}}};function yf(){return e=>new zo(e)}return ca(bf);})();
2
+ "use strict";var Libp2PPlaintext=(()=>{var Xr=Object.defineProperty;var na=Object.getOwnPropertyDescriptor;var oa=Object.getOwnPropertyNames;var sa=Object.prototype.hasOwnProperty;var mt=(e,t)=>{for(var r in t)Xr(e,r,{get:t[r],enumerable:!0})},ia=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of oa(t))!sa.call(e,o)&&o!==r&&Xr(e,o,{get:()=>t[o],enumerable:!(n=na(t,o))||n.enumerable});return e};var aa=e=>ia(Xr({},"__esModule",{value:!0}),e);var wf={};mt(wf,{plaintext:()=>gf});var or=class extends Error{static name="UnexpectedPeerError";constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError"}},Pe=class extends Error{static name="InvalidCryptoExchangeError";constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError"}},ot=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Qt=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var sr=class extends Error{static name="StreamBufferError";constructor(t="The stream buffer was full"){super(t),this.name="StreamBufferError"}};var le=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var de=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Jr=Symbol.for("@libp2p/peer-id");var Vo=Symbol.for("@libp2p/service-capabilities");function lt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}var nn={};mt(nn,{base58btc:()=>st,base58flickr:()=>ma});var Gf=new Uint8Array(0);function Zo(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 vt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return te(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return te(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function Yo(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var $o=4096;function Go(e){let t=e.length;if(t<=$o)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=$o));return r}function ca(e){return e?.buffer instanceof ArrayBuffer}function te(e){return ca(e)?e:e.slice()}function ua(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),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var f=e.length,l=e.charAt(0),m=Math.log(f)/Math.log(256),h=Math.log(256)/Math.log(f);function A(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 v=0,y=0,w=0,S=x.length;w!==S&&x[w]===0;)w++,v++;for(var C=(S-w)*h+1>>>0,F=new Uint8Array(C);w!==S;){for(var D=x[w],R=0,K=C-1;(D!==0||R<y)&&K!==-1;K--,R++)D+=256*F[K]>>>0,F[K]=D%f>>>0,D=D/f>>>0;if(D!==0)throw new Error("Non-zero carry");y=R,w++}for(var k=C-y;k!==C&&F[k]===0;)k++;for(var q=l.repeat(v);k<C;++k)q+=e.charAt(F[k]);return q}function g(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var v=0;if(x[v]!==" "){for(var y=0,w=0;x[v]===l;)y++,v++;for(var S=(x.length-v)*m+1>>>0,C=new Uint8Array(S);x[v];){var F=x.charCodeAt(v);if(F>255)return;var D=n[F];if(D===255)return;for(var R=0,K=S-1;(D!==0||R<w)&&K!==-1;K--,R++)D+=f*C[K]>>>0,C[K]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");w=R,v++}if(x[v]!==" "){for(var k=S-w;k!==S&&C[k]===0;)k++;for(var q=new Uint8Array(y+(S-k)),Z=y;k!==S;)q[Z++]=C[k++];return q}}}function B(x){var v=g(x);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:A,decodeUnsafe:g,decode:B}}var fa=ua,la=fa,Xo=la;var Qr=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")}},tn=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 Jo(this,t)}},en=class{decoders;constructor(t){this.decoders=t}or(t){return Jo(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 Jo(e,t){return new en({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var rn=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 Qr(t,r,n),this.decoder=new tn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function he({name:e,prefix:t,encode:r,decode:n}){return new rn(e,t,r,n)}function qt({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=Xo(r,e,n);return he({prefix:t,name:e,encode:o,decode:i=>vt(s(i))})}function da(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 u=0;u<o;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,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 ha(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 pa(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 tt({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=pa(n,o);return he({prefix:t,name:e,encode(i){return ha(i,n,r)},decode(i){return da(i,s,r,e)}})}var st=qt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ma=qt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var on={};mt(on,{base32:()=>pe,base32hex:()=>wa,base32hexpad:()=>Ea,base32hexpadupper:()=>Sa,base32hexupper:()=>xa,base32pad:()=>ba,base32padupper:()=>ga,base32upper:()=>ya,base32z:()=>va});var pe=tt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),ya=tt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),ba=tt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),ga=tt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),wa=tt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),xa=tt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Ea=tt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Sa=tt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),va=tt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var sn={};mt(sn,{base36:()=>Ne,base36upper:()=>Aa});var Ne=qt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Aa=qt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Ba=es,Qo=128,Ia=127,Ta=~Ia,La=Math.pow(2,31);function es(e,t,r){t=t||[],r=r||0;for(var n=r;e>=La;)t[r++]=e&255|Qo,e/=128;for(;e&Ta;)t[r++]=e&255|Qo,e>>>=7;return t[r]=e|0,es.bytes=r-n+1,t}var _a=an,Ra=128,ts=127;function an(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw an.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&ts)<<o:(i&ts)*Math.pow(2,o),o+=7}while(i>=Ra);return an.bytes=s-n,r}var Da=Math.pow(2,7),Oa=Math.pow(2,14),Ca=Math.pow(2,21),Ka=Math.pow(2,28),Pa=Math.pow(2,35),Na=Math.pow(2,42),Ua=Math.pow(2,49),Fa=Math.pow(2,56),ka=Math.pow(2,63),Ma=function(e){return e<Da?1:e<Oa?2:e<Ca?3:e<Ka?4:e<Pa?5:e<Na?6:e<Ua?7:e<Fa?8:e<ka?9:10},qa={encode:Ba,decode:_a,encodingLength:Ma},Ha=qa,Ue=Ha;function Fe(e,t=0){let r=Ue.decode(e,t),n=Ue.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 me(e,t,r=0){return Ue.encode(e,t,r),t}function ye(e){return Ue.encodingLength(e)}function _t(e,t){let r=t.byteLength,n=ye(e),o=n+ye(r),s=new Uint8Array(o+r);return me(e,s,0),me(r,s,n),s.set(t,o),new be(e,r,t,s)}function cn(e){let t=vt(e),[r,n]=Fe(t),[o,s]=Fe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new be(r,o,i,t)}function rs(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Zo(e.bytes,r.bytes)}}var be=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=te(n),this.bytes=te(o)}};function ns(e,t){let{bytes:r,version:n}=e;return n===0?ja(r,un(e),t??st.encoder):Va(r,un(e),t??pe.encoder)}var os=new WeakMap;function un(e){let t=os.get(e);if(t==null){let r=new Map;return os.set(e,r),r}return t}var dt=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=te(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!==ke)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==$a)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=_t(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&rs(t.multihash,n.multihash)}toString(t){return ns(this,t)}toJSON(){return{"/":ns(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??ss(n,o,s.bytes))}else if(r[Za]===!0){let{version:n,multihash:o,code:s}=r,i=cn(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!==ke)throw new Error(`Version 0 CID must use dag-pb (code: ${ke}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=ss(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,ke,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=vt(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 be(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,m]=Fe(t.subarray(r));return r+=m,l},o=n(),s=ke;if(o===18)o=0,r=0;else if(o===1)s=n();else throw o===0?new RangeError("Invalid CID version, v0 is always implicit"):new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,o]=za(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 un(s).set(n,t),s}};function za(e,t){switch(e[0]){case"Q":{let r=t??st;return[st.prefix,r.decode(`${st.prefix}${e}`)]}case st.prefix:{let r=t??st;return[st.prefix,r.decode(e)]}case pe.prefix:{let r=t??pe;return[pe.prefix,r.decode(e)]}case Ne.prefix:{let r=t??Ne;return[Ne.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 ja(e,t,r){let{prefix:n}=r;if(n!==st.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 Va(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 ke=112,$a=18;function ss(e,t,r){let n=ye(e),o=n+ye(t),s=new Uint8Array(o+r.byteLength);return me(e,s,0),me(t,s,n),s.set(r,o),s}var Za=Symbol.for("@ipld/js-cid/CID");var fn={};mt(fn,{identity:()=>Rt});var is=0,Ya="identity",as=vt;function Ga(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 _t(is,as(e))}var Rt={code:is,name:Ya,encode:as,digest:Ga};function Wa(e){return e.buffer instanceof ArrayBuffer}function yt(e){return Wa(e)?e:e.slice()}async function cs(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,yt(t),yt(r.subarray()));return n?.signal?.throwIfAborted(),s}function Ct(e=0){return new Uint8Array(e)}function bt(e=0){return new Uint8Array(e)}function Xa(e){return e?.buffer instanceof ArrayBuffer}function us(e){if(Xa(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function ar(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=bt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return us(r)}var ls=Symbol.for("@achingbrain/uint8arraylist");function fs(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 cr(e){return!!e?.[ls]}var ft=class e{bufs;length;[ls]=!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(cr(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(cr(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=fs(this.bufs,t);return r.buf[r.index]}set(t,r){let n=fs(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(cr(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 ar(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:ar(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 u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){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(!cr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let m=u;m>=0;m--){let h=this.get(l+m);if(n[m]!==h){f=Math.max(1,m-a[h]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=bt(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=Ct(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=Ct(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=Ct(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=bt(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=Ct(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=Ct(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=Ct(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=Ct(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=Ct(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!lt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var ln={};mt(ln,{base10:()=>Ja});var Ja=qt({prefix:"9",name:"base10",alphabet:"0123456789"});var dn={};mt(dn,{base16:()=>Qa,base16upper:()=>tc});var Qa=tt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),tc=tt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var hn={};mt(hn,{base2:()=>ec});var ec=tt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var pn={};mt(pn,{base256emoji:()=>ic});var ds=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}"),rc=ds.reduce((e,t,r)=>(e[r]=t,e),[]),nc=ds.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function oc(e){return e.reduce((t,r)=>(t+=rc[r],t),"")}function sc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=nc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var ic=he({prefix:"\u{1F680}",name:"base256emoji",encode:oc,decode:sc});var mn={};mt(mn,{base64:()=>ac,base64pad:()=>cc,base64url:()=>uc,base64urlpad:()=>fc});var ac=tt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),cc=tt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),uc=tt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),fc=tt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var yn={};mt(yn,{base8:()=>lc});var lc=tt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var bn={};mt(bn,{identity:()=>dc});var dc=he({prefix:"\0",name:"identity",encode:e=>Go(vt(e)),decode:e=>vt(Yo(e))});var Cl=new TextEncoder,Kl=new TextDecoder;var xn={};mt(xn,{sha256:()=>ur,sha512:()=>yc});var mc=20;function wn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new gn(e,t,r,n,o)}var gn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??mc,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?hs(n,this.code,r?.truncate):n.then(o=>hs(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function hs(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 _t(t,e)}function ms(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var ur=wn({name:"sha2-256",code:18,encode:ms("SHA-256")}),yc=wn({name:"sha2-512",code:19,encode:ms("SHA-512")});var En={...bn,...hn,...yn,...ln,...dn,...on,...sn,...nn,...mn,...pn},$l={...xn,...fn};function bs(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ys=bs("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Sn=bs("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=bt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),bc={utf8:ys,"utf-8":ys,hex:En.base16,latin1:Sn,ascii:Sn,binary:Sn,...En},fr=bc;function it(e,t="utf8"){let r=fr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function et(e,t="utf8"){let r=fr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var gc=parseInt("11111",2),vn=parseInt("10000000",2),wc=parseInt("01111111",2),gs={0:Me,1:Me,2:xc,3:vc,4:Ac,5:Sc,6:Ec,16:Me,22:Me,48:Me};function Kt(e,t={offset:0}){let r=e[t.offset]&gc;if(t.offset++,gs[r]!=null)return gs[r](e,t);throw new Error("No decoder for tag "+r)}function qe(e,t){let r=0;if((e[t.offset]&vn)===vn){let n=e[t.offset]&wc,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 Me(e,t){qe(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Kt(e,t);if(n===null)break;r.push(n)}return r}function xc(e,t){let r=qe(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 Ec(e,t){let r=qe(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 u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Sc(e,t){return t.offset++,null}function vc(e,t){let r=qe(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 Ac(e,t){let r=qe(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Bc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ft;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function An(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Bc(e.byteLength);return new ft(Uint8Array.from([t.byteLength|vn]),t)}function gt(e){let t=new ft,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ft(Uint8Array.from([2]),An(t),t)}function lr(e){let t=Uint8Array.from([0]),r=new ft(t,e);return new ft(Uint8Array.from([3]),An(r),r)}function Ht(e,t=48){let r=new ft;for(let n of e)r.append(n);return new ft(Uint8Array.from([t]),An(r),r)}var Ic=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Tc=Uint8Array.from([6,5,43,129,4,0,34]),Lc=Uint8Array.from([6,5,43,129,4,0,35]),_c={ext:!0,kty:"EC",crv:"P-256"},Rc={ext:!0,kty:"EC",crv:"P-384"},Dc={ext:!0,kty:"EC",crv:"P-521"},Bn=32,In=48,Tn=66;function ws(e){let t=Kt(e);return xs(t)}function xs(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Bn*2+1)return n=et(t.subarray(r,r+Bn),"base64url"),o=et(t.subarray(r+Bn),"base64url"),new we({..._c,key_ops:["verify"],x:n,y:o});if(t.byteLength===In*2+1)return n=et(t.subarray(r,r+In),"base64url"),o=et(t.subarray(r+In),"base64url"),new we({...Rc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Tn*2+1)return n=et(t.subarray(r,r+Tn),"base64url"),o=et(t.subarray(r+Tn),"base64url"),new we({...Dc,key_ops:["verify"],x:n,y:o});throw new ot(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Es(e){return Ht([gt(Uint8Array.from([1])),Ht([Oc(e.crv)],160),Ht([lr(new ft(Uint8Array.from([4]),it(e.x??"","base64url"),it(e.y??"","base64url")))],161)]).subarray()}function Oc(e){if(e==="P-256")return Ic;if(e==="P-384")return Tc;if(e==="P-521")return Lc;throw new ot(`Invalid curve ${e}`)}var we=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Es(this.jwk)),this._raw}toMultihash(){return Rt.digest(zt(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return st.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}async verify(t,r,n){return cs(this.jwk,r,t,n)}};var dr=BigInt(4294967295),Ss=BigInt(32);function Cc(e,t=!1){return t?{h:Number(e&dr),l:Number(e>>Ss&dr)}:{h:Number(e>>Ss&dr)|0,l:Number(e&dr)|0}}function vs(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}=Cc(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Kc=e=>e/2**32|0,Pc=e=>e>>>0;function As(e,t,r,n){let o=Kc(r),s=Pc(r);e.setUint32(t,n?s:o,n),e.setUint32(t+4,n?o:s,n)}var Ln=(e,t,r)=>e>>>r,_n=(e,t,r)=>e<<32-r|t>>>r,ee=(e,t,r)=>e>>>r|t<<32-r,re=(e,t,r)=>e<<32-r|t>>>r,He=(e,t,r)=>e<<64-r|t>>>r-32,ze=(e,t,r)=>e>>>r-32|t<<64-r;function Dt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Bs=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Is=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Ts=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Ls=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,_s=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Rs=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;function hr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}var Rn=e=>e?`"${e}" `:"";function Pt(e,t=""){if(typeof e!="number")throw new TypeError(Rn(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(Rn(t)+"expected integer >= 0, got "+e);return e}function At(e,t,r=""){if(hr(e)&&(t===void 0||e.length===t))return e;t!==void 0&&Pt(t,"length");let n=hr(e),o=t!==void 0?` of length ${t}`:"",s=n?`length=${e.length}`:`type=${typeof e}`,i=Rn(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function pr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Pt(e.outputLen),Pt(e.blockLen),e.outputLen<1||e.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Uc=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)},Ds=(e,t)=>{Uc(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 xe(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function mr(e,t){At(e,void 0,"output");let r=t.outputLen;if(!(e.length>=r))throw new RangeError('"output" expected length >= '+r)}function ne(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function yr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Tt(e,t){return e<<32-t|e>>>t}var Cs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Fc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function br(e){if(At(e),Cs)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Fc[e[r]];return t}function Os(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function gr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(Cs)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=Os(e.charCodeAt(s)),a=Os(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 Dn(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];At(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function kc(e,t,r="opts"){return Ds(e,"defaults"),t!==void 0&&Ds(t,r),Object.assign(Object.create(null),e,t)}function On(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=kc({},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 Ks(e=32){Pt(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 Cn=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Ps(e,t,r){return e&t^~e&r}function Ns(e,t,r){return e&t^e&r^t&r}var je=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=yr(this.buffer)}update(t){xe(this),At(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 u=yr(t);for(;o<=s-a;a+=o)this.process(u,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){xe(this),mr(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)),As(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=t===r?n:yr(t),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],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()}},Us=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Fs=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Mc=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]),jt=new Uint32Array(64),Kn=class extends je{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 l=0;l<16;l++,r+=4)jt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let m=jt[l-15],h=jt[l-2],A=Tt(m,7)^Tt(m,18)^m>>>3,g=Tt(h,17)^Tt(h,19)^h>>>10;jt[l]=g+jt[l-7]+A+jt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let m=Tt(a,6)^Tt(a,11)^Tt(a,25),h=f+m+Ps(a,c,u)+Mc[l]+jt[l]|0,g=(Tt(n,2)^Tt(n,13)^Tt(n,22))+Ns(n,o,s)|0;f=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+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,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){ne(jt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),ne(this.buffer)}},Pn=class extends Kn{constructor(){super(32,Us)}};var ks=vs(["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))),qc=ks[0],Hc=ks[1],Vt=new Uint32Array(80),$t=new Uint32Array(80),Nn=class extends je{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:u,El:f,Fh:l,Fl:m,Gh:h,Gl:A,Hh:g,Hl:B}=this;return[t,r,n,o,s,i,a,c,u,f,l,m,h,A,g,B]}set(t,r,n,o,s,i,a,c,u,f,l,m,h,A,g,B){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=m|0,this.Gh=h|0,this.Gl=A|0,this.Hh=g|0,this.Hl=B|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let y=0;y<16;y++,r+=4)Vt[y]=t.getUint32(r),$t[y]=t.getUint32(r+=4);for(let y=16;y<80;y++){let w=Vt[y-15]|0,S=$t[y-15]|0,C=ee(w,S,1)^ee(w,S,8)^Ln(w,S,7),F=re(w,S,1)^re(w,S,8)^_n(w,S,7),D=Vt[y-2]|0,R=$t[y-2]|0,K=ee(D,R,19)^He(D,R,61)^Ln(D,R,6),k=re(D,R,19)^ze(D,R,61)^_n(D,R,6),q=Ts(F,k,$t[y-7],$t[y-16]),Z=Ls(q,C,K,Vt[y-7],Vt[y-16]);Vt[y]=Z|0,$t[y]=q|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:m,Fh:h,Fl:A,Gh:g,Gl:B,Hh:x,Hl:v}=this;for(let y=0;y<80;y++){let w=ee(l,m,14)^ee(l,m,18)^He(l,m,41),S=re(l,m,14)^re(l,m,18)^ze(l,m,41),C=l&h^~l&g,F=m&A^~m&B,D=_s(v,S,F,Hc[y],$t[y]),R=Rs(D,x,w,C,qc[y],Vt[y]),K=D|0,k=ee(n,o,28)^He(n,o,34)^He(n,o,39),q=re(n,o,28)^ze(n,o,34)^ze(n,o,39),Z=n&s^n&a^s&a,T=o&i^o&c^i&c;x=g|0,v=B|0,g=h|0,B=A|0,h=l|0,A=m|0,{h:l,l:m}=Dt(u|0,f|0,R|0,K|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let U=Bs(K,q,T);n=Is(U,R,k,Z),o=U|0}({h:n,l:o}=Dt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Dt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Dt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Dt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:m}=Dt(this.Eh|0,this.El|0,l|0,m|0),{h,l:A}=Dt(this.Fh|0,this.Fl|0,h|0,A|0),{h:g,l:B}=Dt(this.Gh|0,this.Gl|0,g|0,B|0),{h:x,l:v}=Dt(this.Hh|0,this.Hl|0,x|0,v|0),this.set(n,o,s,i,a,c,u,f,l,m,h,A,g,B,x,v)}roundClean(){ne(Vt,$t)}destroy(){this.destroyed=!0,ne(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Un=class extends Nn{constructor(){super(64,Fs)}};var Ee=On(()=>new Pn,Cn(1));var Fn=On(()=>new Un,Cn(3));function xr(e,t,r=()=>{}){if(!Array.isArray(e))throw new TypeError(`"${t}" expected array, got type=${typeof e}`);for(let n=0;n<e.length;n++)r(e[n],`${t}[${n}]`);return e}var j=(e,t,r)=>At(e,t,r),kn=Pt;function qs(e,t=""){if(typeof e!="string"){let r=t&&`"${t}" `;throw new TypeError(r+"expected string, got type="+typeof e)}return e}function Zt(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 oe(e,t){if(typeof e!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}var Ve=br,Bt=(...e)=>Dn(...e),Se=e=>gr(e),Gt=hr,se=e=>Ks(e),wr=BigInt(0),Ms=BigInt(1),zc=e=>e?`"${e}" `:"";function wt(e,t=""){if(typeof e!="boolean")throw new TypeError(zc(t)+"expected boolean, got type="+typeof e);return e}function Er(e){if(typeof e=="bigint"){if(!Yt(e))throw new RangeError("positive bigint expected, got "+e)}else kn(e);return e}function Nt(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 $e(e){let t=Er(e).toString(16);return t.length&1?"0"+t:t}function Hs(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?wr:BigInt("0x"+e)}function Ot(e){return Hs(br(e))}function ie(e){return Hs(br(Ze(At(e)).reverse()))}function Sr(e,t){if(Pt(t),t===0)throw new Error("zero output length is invalid");e=Er(e);let r=t*2,n=e.toString(16);if(n.length>r)throw new RangeError("number is too large");return gr(n.padStart(r,"0"))}function Mn(e,t){return Sr(e,t).reverse()}function Ze(e){return Uint8Array.from(j(e))}function Yt(e){return typeof e=="bigint"&&wr<=e}function qn(e,t,r){return Yt(e)&&Yt(t)&&Yt(r)&&t<=e&&e<r}function ve(e,t,r,n){if(!qn(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ae(e){if(e<wr)throw new Error("expected non-negative bigint, got "+e);return e===wr?0:e.toString(2).length}var Ye=e=>(Nt(e,"n"),(Ms<<BigInt(e))-Ms);function zs(e,t,r){if(Pt(e,"hashLen"),Pt(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=B=>new Uint8Array(B),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,l=()=>{c.fill(1),u.fill(0),f=0},m=(...B)=>r(u,Bt(c,...B)),h=(B=o)=>{u=m(s,B),c=m(),B.length!==0&&(u=m(i,B),c=m())},A=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let B=0,x=[];for(;B<t;){c=m();let v=c.slice();x.push(v),B+=c.length}return Bt(...x)};return(B,x)=>{l(),h(B);let v;for(;(v=x(A()))===void 0;)h();return l(),v}}function xt(e,t={},r={},n="object"){Zt(e,n),Zt(t,"fields"),Zt(r,"optFields");function o(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,f=e[i];if(!Object.hasOwn(e,i)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let l=typeof f;if(l!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${l}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(t,!1),s(r,!0)}var ct=BigInt(0),V=BigInt(1),Wt=BigInt(2),$s=BigInt(3),Hn=BigInt(4),Zs=BigInt(5),jc=BigInt(7),Ys=BigInt(8),Vc=BigInt(9),$c=BigInt(15),Gs=BigInt(16),Zc=BigInt("0x10000000000000000");function Q(e,t){if(t<=ct)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=ct?r:t+r}function Ws(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<ct)throw new Error("invalid exponent, negatives unsupported");if(t===ct)return V;if(t===V)return e;let n=e%r;if(n<ct&&(n+=r),t<Zc){let a=V;for(;t>ct;)t&V&&(a=a*n%r),n=n*n%r,t>>=V;return a}let o=[];for(;t>ct;)o.push(Number(t&$c)),t>>=Hn;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<ct)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >ct;)n*=n,n%=r;return n}function js(e,t){if(e===ct)throw new Error("invert: expected non-zero number");if(t<=V)throw new Error("invert: expected modulus > 1, got "+t);let r=Q(e,t),n=t,o=ct,s=V;for(;r!==ct;){let a=n/r,c=n-r*a,u=o-s*a;n=r,r=c,o=s,s=u}if(n!==V)throw new Error("invert: does not exist");return Q(o,t)}function Xs(e,t){if(t<=V)throw new Error("invertCt: expected prime modulus > 1, got "+t);let r=Q(e,t);if(r===ct)throw new Error("invertCt: expected non-zero number");let n=Ws(r,t-Wt,t);if(Q(r*n,t)!==V)throw new Error("invertCt: does not exist");return n}function zn(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function jn(e,t){if((e&V)===ct)throw new Error(t+": expected odd modulus, got "+e)}function Js(e,t){let r=e,n=(r.ORDER+V)/Hn,o=r.pow(t,n);return zn(r,o,t),o}function Yc(e,t){let r=e,n=(r.ORDER-Zs)/Ys,o=r.mul(t,Wt),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,Wt),s),c=r.mul(i,r.sub(a,r.ONE));return zn(r,c,t),c}function Gc(e){let t=Ie(e),r=Qs(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+jc)/Gs;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),m=u.mul(f,o),h=u.mul(f,s),A=u.eql(u.sqr(l),c),g=u.eql(u.sqr(m),c);f=u.cmov(f,l,A),l=u.cmov(h,m,g);let B=u.eql(u.sqr(l),c),x=u.cmov(f,l,B);return zn(u,x,c),x})}function Qs(e){if(e<$s)throw new Error("sqrt is not defined for small field");jn(e,"tonelliShanks");let t=e-V,r=0;for(;t%Wt===ct;)t/=Wt,r++;let n=Wt,o=Ie(e);for(;Ge(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Js;let s=o.pow(n,t),i=(t+V)/Wt;return function(c,u){let f=c;if(f.is0(u))return u;if(Ge(f,u)!==1)throw new Error("Cannot find square root");let l=r,m=f.mul(f.ONE,s),h=f.pow(u,t),A=f.pow(u,i);for(;!f.eql(h,f.ONE);){if(f.is0(h))throw new Error("Cannot find square root: probably non-prime P");let g=1,B=f.sqr(h);for(;!f.eql(B,f.ONE);)if(g++,B=f.sqr(B),g===l)throw new Error("Cannot find square root");let x=V<<BigInt(l-g-1),v=f.pow(m,x);l=g,m=f.sqr(v),h=f.mul(h,m),A=f.mul(A,v)}return A}}function Wc(e){return jn(e,"Fp.sqrt"),e%Hn===$s?Js:e%Ys===Zs?Yc:e%Gs===Vc?Gc(e):Qs(e)}var ti=(e,t)=>(Q(e,t)&V)===V,Xc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Be(e){if(Zt(e,"field"),typeof e.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof e.ORDER);Nt(e.BYTES,"BYTES"),Nt(e.BITS,"BITS");for(let t of Xc)oe(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 Ar(e,t,r=!1){Be(e),xr(t,"nums"),wt(r,"passZero");let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function Ge(e,t){Be(e);let r=e;jn(r.ORDER,"FpLegendre");let n=(r.ORDER-V)/Wt,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 Jc(e,t){if(t!==void 0&&kn(t),e<=ct)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=Ae(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 Vs=new WeakMap,vr=class{ORDER;BITS;BYTES;isLE;ZERO=ct;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}=Jc(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 Q(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return ct<=t&&t<this.ORDER}is0(t){return t===ct}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&V)===V}neg(t){return Q(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return Q(t*t,this.ORDER)}add(t,r){return Q(t+r,this.ORDER)}sub(t,r){return Q(t-r,this.ORDER)}mul(t,r){return Q(t*r,this.ORDER)}pow(t,r){return Ws(t,r,this.ORDER)}div(t,r){return Q(t*js(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 js(t,this.ORDER)}sqrt(t){let r=Vs.get(this);return r||Vs.set(this,r=Wc(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?Mn(t,this.BYTES):Sr(t,this.BYTES)}fromBytes(t,r=!1){j(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 u=new Uint8Array(o);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?ie(t):Ot(t);if(a&&(c=Q(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Ar(this,t,!0)}cmov(t,r,n){return wt(n,"condition"),n?r:t}};function Ie(e,t={}){return Object.freeze(vr.prototype),new vr(e,t)}function ei(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=Ae(e-V);return Math.ceil(t/8)}function Br(e){let t=ei(e);return t+Math.ceil(t/2)}function Ir(e,t,r=!1){j(e);let n=e.length,o=ei(t),s=Math.max(Br(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?ie(e):Ot(e),a=Q(i,t-V)+V;return r?Mn(a,o):Sr(a,o)}var Zn=BigInt(0),We=BigInt(1),Qc=BigInt(4),Vn=16,ri=128,tu=5,ni=2**31;function Xt(e){let t=e;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof e);oe(t.fromAffine,"Point.fromAffine"),oe(t.fromBytes,"Point.fromBytes"),oe(t.fromHex,"Point.fromHex"),Zt(t.BASE,"Point.BASE"),Zt(t.ZERO,"Point.ZERO"),Be(t.Fp),Be(t.Fn)}function Tr(e,t){Xt(e),si(t,e);let r=Ar(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function eu(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 ru(e,t){let r=e*(4*t+128);if(r>ni)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+ni/2**20+" MiB")}function Yn(e,t){if(e!==void 0){oe(e,"randomBytes");try{let r=e(t);if(!Gt(r)||r.length!==t)return}catch{return}return e}}function si(e,t){xr(e,"points"),e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function nu(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):Yt(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var ii=new WeakMap;function $n(e){return ii.get(e)||1}function ou(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 su(e,t){let r=2**t,n=r/2,o=BigInt(r-1),s=[];for(;e>Zn;){let i=0;e&We&&(i=Number(e&o),i>=n&&(i-=r),e-=BigInt(i)),s.push(i),e>>=We}return s}function iu(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 u=Number(e&s);e>>=i,u>o&&(u-=n,e+=We),a.push(u)}if(e!==Zn)throw new Error("invalid wnaf");return a}function au(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 Te=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,r){Xt(t),this.randomBytes=Yn(r,Vn),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 u=a;for(let f=0;f<s;f++)i.push(u),u=u.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=iu(r,n,o),c=this.ZERO,u=this.BASE;for(let f=0;f<o;f++){let l=a[f],m=f*i,h=Math.abs(l)-1,A=s[m];for(let B=1;B<i;B++)A=B===h?s[m+B]:A;let g=A.negate();l===0?u=u.add(s[m]):c=c.add(l<0?g:A)}return{p:c,f:u}}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),!qn(r,We,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,r,n,o){let s=$n(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+ri,s=this.randomBytes(Vn);if(!Gt(s)||s.length!==Vn)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+Ot(s)*this.Point.Fn.ORDER;return this.runCT(t,i,o,n)}fixedWindowCT(t,r,n){let o=tu,s=1<<o,i=Ye(o),a=new Array(s);a[0]=this.ZERO;for(let f=1;f<s;f++)a[f]=a[f-1].add(t);let c=Math.ceil(n/o),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let h=0;h<o;h++)u=u.double();let l=Number(r>>BigInt(f*o)&i),m=a[0];for(let h=1;h<s;h++)m=h===l?a[h]:m;u=u.add(m)}return{p:u,f:u}}shouldBlind(t,r){return this.randomBytes===void 0?!1:r===We?!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),!Yt(r))throw new Error("invalid scalar");let o=$n(t);if(o===1||r>=this.Point.Fn.ORDER)return Lr(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),eu(r,this.bits);let n=Math.ceil((this.bits+ri)/r)+1;ru(n*2**(r-1),this.Point.Fp.BYTES),ii.set(t,r),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return $n(t)!==1}};function Lr(e,t,r,n=!1){if(Xt(e),si(t,e),wt(n,"allowOversized"),nu(r,e.Fn,n?e.Fn.ORDER**Qc:void 0),t.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=t.map(i=>ou(i,4)),s=r.map(i=>su(i,4));return au(e.ZERO,o,s)}function oi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Be(t),t}else return Ie(e,{isLE:r})}function _r(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`);xt(r);for(let c of["p","n","h"]){let u=t[c];if(!(Yt(u)&&u!==Zn))throw new Error(`CURVE.${c} must be positive bigint`)}let o=oi(t.p,r.Fp,n),s=oi(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 Rr(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Dr=BigInt(0),Or=BigInt(1),Cr=BigInt(2),cu=BigInt(4),ai=BigInt(8);function uu(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 ci(e,t={}){xt(t,{},{},"extraOpts");let r=t,n=_r("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(Ge(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(Ge(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");xt(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?se:r.randomBytes,u=Cr<<BigInt(o.BYTES*8)-Or;function f(v){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(v)}let l=r.uvRatio===void 0?(v,y)=>{try{return{isValid:!0,value:o.sqrt(o.div(v,y))}}catch{return{isValid:!1,value:Dr}}}:r.uvRatio;if(!uu(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let m=o.eql(i.a,o.neg(o.ONE))?v=>o.neg(v):o.eql(i.a,o.ONE)?v=>v:v=>o.mul(i.a,v);function h(v,y,w=!1){let S=w?Or:Dr;return ve("coordinate "+v,y,S,u),y}function A(v){if(!(v 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(y,w,S,C){this.X=h("x",y),this.Y=h("y",w),this.Z=h("z",S,!0),this.T=h("t",C),Object.freeze(this)}static CURVE(){return i}static fromAffine(y){if(y instanceof g)throw new Error("extended point not allowed");let{x:w,y:S}=y||{};return h("x",w),h("y",S),new g(w,S,o.ONE,o.mul(w,S))}static fromBytes(y,w=!1){let S=o.BYTES,{a:C,d:F}=i;y=Ze(j(y,S,"point")),wt(w,"zip215");let D=Ze(y),R=y[S-1];D[S-1]=R&-129;let K=ie(D),k=w?u:o.ORDER;ve("point.y",K,Dr,k);let q=o.sqr(K),Z=o.sub(q,o.ONE),T=o.sub(o.mulN(F,q),C),{isValid:U,value:M}=l(Z,T);if(!U)throw new Error("bad point: invalid y coordinate");let O=f(M),Y=(R&128)!==0;if(!w&&o.is0(M)&&Y)throw new Error("bad point: x=0 and x_0=1");return Y!==O&&(M=o.neg(M)),g.fromAffine({x:M,y:K})}static fromHex(y,w=!1){return g.fromBytes(Se(y),w)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=6,w=!0){return x.setWindowSize(this,y),w||this.multiply(Cr),this}assertValidity(){let y=this,{a:w,d:S}=i;if(y.is0())throw new Error("bad point: ZERO");let{X:C,Y:F,Z:D,T:R}=y,K=o.sqr(C),k=o.sqr(F),q=o.sqr(D),Z=o.sqr(q),T=o.mul(K,w),U=o.mul(o.add(T,k),q),M=o.add(Z,o.mul(S,o.mul(K,k)));if(!o.eql(U,M))throw new Error("bad point: equation left != right (1)");let O=o.mul(C,F),Y=o.mul(D,R);if(!o.eql(O,Y))throw new Error("bad point: equation left != right (2)")}equals(y){A(y);let{X:w,Y:S,Z:C}=this,{X:F,Y:D,Z:R}=y,K=o.mul(w,R),k=o.mul(F,C),q=o.mul(S,R),Z=o.mul(D,C);return o.eql(K,k)&&o.eql(q,Z)}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:y,Y:w,Z:S}=this,C=o.sqr(y),F=o.sqr(w),D=o.mul(o.sqr(S),Cr),R=m(C),K=o.addN(y,w),k=o.sub(o.subN(o.sqr(K),C),F),q=o.addN(R,F),Z=o.subN(q,D),T=o.subN(R,F),U=o.mul(k,Z),M=o.mul(q,T),O=o.mul(k,T),Y=o.mul(Z,q);return new g(U,M,Y,O)}add(y){A(y);let{d:w}=i,{X:S,Y:C,Z:F,T:D}=this,{X:R,Y:K,Z:k,T:q}=y,Z=o.mul(S,R),T=o.mul(C,K),U=o.mul(o.mulN(D,w),q),M=o.mul(F,k),O=o.sub(o.subN(o.mulN(o.addN(S,C),o.addN(R,K)),Z),T),Y=o.subN(M,U),J=o.addN(M,U),E=o.sub(T,m(Z)),d=o.mul(O,Y),p=o.mul(J,E),b=o.mul(O,E),I=o.mul(Y,J);return new g(d,p,I,b)}subtract(y){return A(y),this.add(y.negate())}multiply(y){if(!s.isValidNot0(y))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:w,f:S}=x.mulSecret(this,y,a,B);return B([w,S])[0]}multiplyUnsafe(y){if(!s.isValid(y))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return y===Dr?g.ZERO:this.is0()||y===Or?this:x.mulUnsafe(this,y,B)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return x.mulUnsafe(this,i.n).is0()}toAffine(y){let w=this,S=y;if(S!=null&&typeof S!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof S);let{X:C,Y:F,Z:D}=w,R=w.is0();S==null&&(S=R?o.create(ai):o.inv(D));let K=o.mul(C,S),k=o.mul(F,S),q=o.mul(D,S);if(R)return{x:o.ZERO,y:o.ONE};if(!o.eql(q,o.ONE))throw new Error("invZ was invalid");return{x:K,y:k}}clearCofactor(){return a===Or?this:a===Cr?this.double():a===cu?this.double().double():a===ai?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:y,y:w}=this.toAffine(),S=o.toBytes(w);return S[S.length-1]|=f(y)?128:0,S}toHex(){return Ve(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let B=v=>Tr(g,v),x=new Te(g,c);return x.bits>=6&&g.BASE.precompute(6),Object.freeze(g.prototype),Object.freeze(g),g}function ui(e,t,r={}){if(Xt(e),typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;xt(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,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(Nt(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?se:o.randomBytes,m=o.toMontgomery,h=o.toMontgomerySecret,A=o.adjustScalarBytes===void 0?T=>T:o.adjustScalarBytes,g=o.domain===void 0?(T,U,M)=>{if(wt(M,"phflag"),U.length||M)throw new Error("Contexts/pre-hash are not supported");return T}:o.domain;function B(T){return c.create(ie(T))}function x(T){let U=R.secretKey;j(T,R.secretKey,"secretKey");let M=j(n(T),2*U,"hashedSecretKey"),O=A(M.slice(0,U)),Y=M.slice(U,2*U),J=B(O);return{head:O,prefix:Y,scalar:J}}function v(T){let{head:U,prefix:M,scalar:O}=x(T),Y=i.multiply(O),J=Y.toBytes();return{head:U,prefix:M,scalar:O,point:Y,pointBytes:J}}function y(T){return v(T).pointBytes}function w(T=Uint8Array.of(),...U){let M=Bt(...U);return B(n(g(M,j(T,void 0,"context"),!!s)))}function S(T,U,M={}){xt(M,{},{},"options"),T=Ze(j(T,void 0,"message")),s&&(T=s(T));let{prefix:O,scalar:Y,pointBytes:J}=v(U),E=w(M.context,O,T),d=i.multiply(E).toBytes(),p=w(M.context,d,J,T),b=c.create(E+p*Y);if(!c.isValid(b))throw new Error("sign failed: invalid s");let I=Bt(d,c.toBytes(b));return j(I,R.signature,"result")}let C={zip215:o.zip215};function F(T,U,M,O=C){xt(O);let{context:Y}=O,J=O.zip215===void 0?!!C.zip215:O.zip215,E=R.signature;T=j(T,E,"signature"),U=j(U,void 0,"message"),M=j(M,R.publicKey,"publicKey"),J!==void 0&&wt(J,"zip215"),s&&(U=s(U));let d=E/2,p=T.subarray(0,d),b=ie(T.subarray(d,E)),I,L,_;try{I=e.fromBytes(M,J),L=e.fromBytes(p,J),_=i.multiplyUnsafe(b)}catch{return!1}if(!J&&I.isSmallOrder())return!1;let P=w(Y,p,M,U);return L.add(I.multiplyUnsafe(P)).subtract(_).clearCofactor().is0()}let D=a.BYTES,R={secretKey:D,publicKey:D,signature:2*D,seed:D};function K(T){return T=T===void 0?l(R.seed):T,j(T,R.seed,"seed")}function k(T){return Gt(T)&&T.length===R.secretKey}function q(T,U){try{return!!e.fromBytes(T,U===void 0?C.zip215:U)}catch{return!1}}let Z={getExtendedPublicKey:v,randomSecretKey:K,isValidSecretKey:k,isValidPublicKey:q,toMontgomery(T){if(m===void 0)throw new Error("Montgomery conversion is not supported for this curve");return m(e.fromBytes(T))},toMontgomerySecret(T){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(T)}};return Object.freeze(R),Object.freeze(Z),Object.freeze({keygen:Rr(K,y),getPublicKey:y,sign:S,verify:F,utils:Z,Point:e,lengths:R})}var Gn=BigInt(1),fi=BigInt(2);var fu=BigInt(5),lu=BigInt(8),Wn=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),du={p:Wn,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:lu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function hu(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Wn,a=e*e%s*e%s,c=X(a,fi,s)*a%s,u=X(c,Gn,s)*e%s,f=X(u,fu,s)*u%s,l=X(f,t,s)*f%s,m=X(l,r,s)*l%s,h=X(m,n,s)*m%s,A=X(h,o,s)*h%s,g=X(A,o,s)*h%s,B=X(g,t,s)*f%s;return{pow_p_5_8:X(B,fi,s)*e%s,b2:a}}function hi(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var li=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function pu(e,t){let r=Wn,n=Q(t*t*t,r),o=Q(n*n*t,r),s=hu(e*o).pow_p_5_8,i=Q(e*n*s,r),a=Q(t*i*i,r),c=i,u=Q(i*li,r),f=a===e,l=a===Q(-e,r),m=a===Q(-e*li,r);return f&&(i=c),(l||m)&&(i=u),ti(i,r)&&(i=Q(-i,r)),{isValid:f||l,value:i}}var Xn=ci(du,{uvRatio:pu}),di=Xn.Fp;function mu(e){let{y:t}=e;return di.toBytes(di.div(Gn+t,Gn-t))}function yu(e){let t=Xn.Fp.BYTES;return At(e,t),hi(Fn(e.subarray(0,t))).subarray(0,t)}function bu(e){return ui(Xn,Fn,Object.assign({adjustScalarBytes:hi,toMontgomery:mu,toMontgomerySecret:yu,zip215:!0},e))}var pi=bu({});var Xe=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Kr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var It={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Kr("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 Pr=32;var Jn,gu=(async()=>{try{return await It.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function wu(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await It.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await It.get().subtle.verify({name:"Ed25519"},n,yt(t),yt(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function xu(e,t,r){return pi.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function mi(e,t,r){return Jn==null&&(Jn=await gu),Jn?wu(e,t,r):xu(e,t,r)}function Nr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Ur=class{type="Ed25519";raw;constructor(t){this.raw=Qn(t,Pr)}toMultihash(){return Rt.digest(zt(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return st.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=mi(this.raw,r,t);return Nr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function bi(e){return e=Qn(e,Pr),new Ur(e)}function Qn(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new ot(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Su=Math.pow(2,7),vu=Math.pow(2,14),Au=Math.pow(2,21),to=Math.pow(2,28),eo=Math.pow(2,35),ro=Math.pow(2,42),no=Math.pow(2,49),$=128,ht=127;function Ut(e){if(e<Su)return 1;if(e<vu)return 2;if(e<Au)return 3;if(e<to)return 4;if(e<eo)return 5;if(e<ro)return 6;if(e<no)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function oo(e,t,r=0){switch(Ut(e)){case 8:t[r++]=e&255|$,e/=128;case 7:t[r++]=e&255|$,e/=128;case 6:t[r++]=e&255|$,e/=128;case 5:t[r++]=e&255|$,e/=128;case 4:t[r++]=e&255|$,e>>>=7;case 3:t[r++]=e&255|$,e>>>=7;case 2:t[r++]=e&255|$,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Bu(e,t,r=0){switch(Ut(e)){case 8:t.set(r++,e&255|$),e/=128;case 7:t.set(r++,e&255|$),e/=128;case 6:t.set(r++,e&255|$),e/=128;case 5:t.set(r++,e&255|$),e/=128;case 4:t.set(r++,e&255|$),e>>>=7;case 3:t.set(r++,e&255|$),e>>>=7;case 2:t.set(r++,e&255|$),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function so(e,t){let r=e[t],n=0;if(n+=r&ht,r<$||(r=e[t+1],n+=(r&ht)<<7,r<$)||(r=e[t+2],n+=(r&ht)<<14,r<$)||(r=e[t+3],n+=(r&ht)<<21,r<$)||(r=e[t+4],n+=(r&ht)*to,r<$)||(r=e[t+5],n+=(r&ht)*eo,r<$)||(r=e[t+6],n+=(r&ht)*ro,r<$)||(r=e[t+7],n+=(r&ht)*no,r<$))return n;throw new RangeError("Could not decode varint")}function Iu(e,t){let r=e.get(t),n=0;if(n+=r&ht,r<$||(r=e.get(t+1),n+=(r&ht)<<7,r<$)||(r=e.get(t+2),n+=(r&ht)<<14,r<$)||(r=e.get(t+3),n+=(r&ht)<<21,r<$)||(r=e.get(t+4),n+=(r&ht)*to,r<$)||(r=e.get(t+5),n+=(r&ht)*eo,r<$)||(r=e.get(t+6),n+=(r&ht)*ro,r<$)||(r=e.get(t+7),n+=(r&ht)*no,r<$))return n;throw new RangeError("Could not decode varint")}function gi(e,t,r=0){return t==null&&(t=bt(Ut(e))),t instanceof Uint8Array?oo(e,t,r):Bu(e,t,r)}function wi(e,t=0){return e instanceof Uint8Array?so(e,t):Iu(e,t)}var io=new Float32Array([-0]),Jt=new Uint8Array(io.buffer);function xi(e,t,r){io[0]=e,t[r]=Jt[0],t[r+1]=Jt[1],t[r+2]=Jt[2],t[r+3]=Jt[3]}function Ei(e,t){return Jt[0]=e[t],Jt[1]=e[t+1],Jt[2]=e[t+2],Jt[3]=e[t+3],io[0]}var ao=new Float64Array([-0]),pt=new Uint8Array(ao.buffer);function Si(e,t,r){ao[0]=e,t[r]=pt[0],t[r+1]=pt[1],t[r+2]=pt[2],t[r+3]=pt[3],t[r+4]=pt[4],t[r+5]=pt[5],t[r+6]=pt[6],t[r+7]=pt[7]}function vi(e,t){return pt[0]=e[t],pt[1]=e[t+1],pt[2]=e[t+2],pt[3]=e[t+3],pt[4]=e[t+4],pt[5]=e[t+5],pt[6]=e[t+6],pt[7]=e[t+7],ao[0]}var Lu=BigInt(Number.MAX_SAFE_INTEGER),_u=BigInt(Number.MIN_SAFE_INTEGER),Et=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 ae;if(t<Lu&&t>_u)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>Ai&&(o=0n,++n>Ai&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ae;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):ae}},ae=new Et(0,0);ae.toBigInt=function(){return 0n};ae.zzEncode=ae.zzDecode=function(){return this};ae.length=function(){return 1};var Ai=4294967296n;function Bi(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 Ii(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 co(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 Lt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Fr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var uo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=yt(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,Lt(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 Lt(this,4);return Fr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Lt(this,4);return Fr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Lt(this,4);let t=Ei(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Lt(this,4);let t=vi(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 Lt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Ii(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Lt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Lt(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 Et(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 Lt(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 Lt(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 Lt(this,8);let t=Fr(this.buf,this.pos+=4),r=Fr(this.buf,this.pos+=4);return new Et(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=so(this.buf,this.pos);return this.pos+=Ut(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Je(e){return new uo(e instanceof Uint8Array?e:e.subarray())}function Le(e,t,r){let n=Je(e);return t.decode(n,void 0,r)}function fo(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return bt(i);o+i>t&&(n=bt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ce=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function lo(){}var po=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Ru=fo();function Du(e){return globalThis.Buffer!=null?bt(e):Ru(e)}var tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ce(lo,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ce(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new mo((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(kr,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Et.fromBigInt(t);return this._push(kr,r.length(),r)}uint64Number(t){return this._push(oo,Ut(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=Et.fromBigInt(t).zzEncode();return this._push(kr,r.length(),r)}sint64Number(t){let r=Et.fromNumber(t).zzEncode();return this._push(kr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ho,1,t?1:0)}fixed32(t){return this._push(Qe,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Et.fromBigInt(t);return this._push(Qe,4,r.lo)._push(Qe,4,r.hi)}fixed64Number(t){let r=Et.fromNumber(t);return this._push(Qe,4,r.lo)._push(Qe,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(xi,4,t)}double(t){return this._push(Si,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(ho,1,0):this.uint32(r)._push(Cu,r,t)}string(t){let r=Bi(t);return r!==0?this.uint32(r)._push(co,r,t):this._push(ho,1,0)}fork(){return this.states=new po(this),this.head=this.tail=new ce(lo,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 ce(lo,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=Du(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function ho(e,t,r){t[r]=e&255}function Ou(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var mo=class extends ce{next;constructor(t,r){super(Ou,t,r),this.next=void 0}};function kr(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 Qe(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 Cu(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(tr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Ku,t,e),this},tr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Pu,t,e),this});function Ku(e,t,r){t.set(e,r)}function Pu(e,t,r){e.length<40?co(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(it(e),r)}function yo(){return new tr}function _e(e,t){let r=yo();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Re(e,t,r){let n=Je(e);yield*t.stream(n,void 0,".",r)}var Mr={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function qr(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function bo(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 qr("enum",Mr.VARINT,r,n,o)}function De(e,t,r){return qr("message",Mr.LENGTH_DELIMITED,e,t,r)}var at;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(at||(at={}));var go;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(go||(go={}));(function(e){e.codec=()=>bo(go)})(at||(at={}));var Ft;(function(e){let t;e.codec=()=>(t==null&&(t=De((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),at.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={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=at.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:at.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return _e(s,e.codec())}e.encode=r;function n(s,i){return Le(s,e.codec(),i)}e.decode=n;function o(s,i){return Re(s,e.codec(),i)}e.stream=o})(Ft||(Ft={}));var wo;(function(e){let t;e.codec=()=>(t==null&&(t=De((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),at.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={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=at.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:at.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return _e(s,e.codec())}e.encode=r;function n(s,i){return Le(s,e.codec(),i)}e.decode=n;function o(s,i){return Re(s,e.codec(),i)}e.stream=o})(wo||(wo={}));var rr={};mt(rr,{MAX_RSA_KEY_SIZE:()=>xo,generateRSAKeyPair:()=>Oi,jwkToJWKKeyPair:()=>Ci,jwkToPkcs1:()=>ku,jwkToPkix:()=>Ao,jwkToRSAPrivateKey:()=>Lo,pkcs1MessageToJwk:()=>So,pkcs1MessageToRSAPrivateKey:()=>Bo,pkcs1ToJwk:()=>Fu,pkcs1ToRSAPrivateKey:()=>Di,pkixMessageToJwk:()=>vo,pkixMessageToRSAPublicKey:()=>To,pkixToJwk:()=>Mu,pkixToRSAPublicKey:()=>Io});var Oe=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=rr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return dt.createV1(114,this._multihash)}toString(){return st.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,r,n){return Ri(this.jwk,r,t,n)}},er=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=rr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}sign(t,r){return _i(this.jwk,t,r)}};var xo=8192,Eo=18,Nu=1062,Uu=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Fu(e){let t=Kt(e);return So(t)}function So(e){return{n:et(e[1],"base64url"),e:et(e[2],"base64url"),d:et(e[3],"base64url"),p:et(e[4],"base64url"),q:et(e[5],"base64url"),dp:et(e[6],"base64url"),dq:et(e[7],"base64url"),qi:et(e[8],"base64url"),kty:"RSA"}}function ku(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new ot("JWK was missing components");return Ht([gt(Uint8Array.from([0])),gt(it(e.n,"base64url")),gt(it(e.e,"base64url")),gt(it(e.d,"base64url")),gt(it(e.p,"base64url")),gt(it(e.q,"base64url")),gt(it(e.dp,"base64url")),gt(it(e.dq,"base64url")),gt(it(e.qi,"base64url"))]).subarray()}function Mu(e){let t=Kt(e,{offset:0});return vo(t)}function vo(e){let t=Kt(e[1],{offset:0});return{kty:"RSA",n:et(t[0],"base64url"),e:et(t[1],"base64url")}}function Ao(e){if(e.n==null||e.e==null)throw new ot("JWK was missing components");return Ht([Uu,lr(Ht([gt(it(e.n,"base64url")),gt(it(e.e,"base64url"))]))]).subarray()}function Di(e){let t=Kt(e);return Bo(t)}function Bo(e){let t=So(e);return Lo(t)}function Io(e,t){if(e.byteLength>=Nu)throw new Qt("Key size is too large");let r=Kt(e,{offset:0});return To(r,e,t)}function To(e,t,r){let n=vo(e);if(r==null){let o=Ee(Ft.encode({Type:at.RSA,Data:t}));r=_t(Eo,o)}return new Oe(n,r)}function Lo(e){if(Pi(e)>xo)throw new ot("Key size is too large");let t=Ci(e),r=Ee(Ft.encode({Type:at.RSA,Data:Ao(t.publicKey)})),n=_t(Eo,r);return new er(t.privateKey,new Oe(t.publicKey,n))}async function Oi(e){if(e>xo)throw new ot("Key size is too large");let t=await Ki(e),r=Ee(Ft.encode({Type:at.RSA,Data:Ao(t.publicKey)})),n=_t(Eo,r);return new er(t.privateKey,new Oe(t.publicKey,n))}function Ci(e){if(e==null)throw new ot("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Ki(e,t){let r=await It.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await qu(r,t);return{privateKey:n[0],publicKey:n[1]}}async function _i(e,t,r){let n=await It.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await It.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,yt(t instanceof Uint8Array?t:t.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Ri(e,t,r,n){let o=await It.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await It.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,yt(t),yt(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function qu(e,t){if(e.privateKey==null||e.publicKey==null)throw new ot("Private and public key are required");let r=await Promise.all([It.get().subtle.exportKey("jwk",e.privateKey),It.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Pi(e){if(e.kty!=="RSA")throw new ot("invalid key type");if(e.n==null)throw new ot("invalid key modulus");return it(e.n,"base64url").length*8}var Hr=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(pr(t),At(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),ne(o)}update(t){return xe(this),this.iHash.update(t),this}digestInto(t){xe(this),mr(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()}},Ni=(()=>{let e=((t,r,n)=>new Hr(t,r).update(n).digest());return e.create=(t,r)=>new Hr(t,r),e})();var Hu=BigInt(0),_o=class extends Error{constructor(t=""){super(t)}},kt={Err:_o,_tlv:{encode:(e,t)=>{let{Err:r}=kt;if(Nt(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(qs(t,"data"),t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=$e(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?$e(o.length/2|128):"";return $e(e)+s+o+t},decode(e,t){let{Err:r}=kt;t=j(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.decode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let 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 u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=kt;if(Er(e),e<Hu)throw new t("integer: negative integers are not allowed");let r=$e(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=kt;if(e.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 Ot(e)}},toSig(e,t){let{Err:r,_int:n,_tlv:o}=kt;if(t!==void 0&&(Nt(t,"maxScalarBytes"),t<1))throw new r("invalid signature: maxScalarBytes must be positive");let s=j(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:u}=o.decode(2,i),{v:f,l}=o.decode(2,u);if(l.length)throw new r("invalid signature: left bytes after parsing");if(t!==void 0&&(c.length>t||f.length>t))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=kt;xt(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)}},zr=(Object.freeze(kt._tlv),Object.freeze(kt._int),Object.freeze(kt));var Ui=(e,t)=>(e+(e>=0?t:-t)/Fi)/t;function zu(e,t,r){ve("scalar",e,Mt,r);let[[n,o],[s,i]]=t,a=Ui(i*e,r),c=Ui(-o*e,r),u=e-a*n-c*s,f=-a*o-c*i,l=u<Mt,m=f<Mt;l&&(u=-u),m&&(f=-f);let h=Ye(Math.ceil(Ae(r)/2))+ue;if(u<Mt||u>=h||f<Mt||f>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:m,k2:f}}function Oo(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Ro(e,t){xt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return wt(r.lowS,"lowS"),wt(r.prehash,"prehash"),r.format!==void 0&&Oo(r.format),r}var Mt=BigInt(0),ue=BigInt(1),Fi=BigInt(2),Do=BigInt(3),ju=BigInt(4);function ki(e,t={}){let r=_r("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;xt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:l,fromBytes:m,toBytes:h}=t,A=t.randomBytes===void 0?se: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(E=>[...E])}:void 0,B=qi(n,o);function x(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function v(E,d,p){if(d.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:b,y:I}=d.toAffine(),L=n.toBytes(b);if(wt(p,"isCompressed"),p){x();let _=!n.isOdd(I);return Bt(Mi(_),L)}else return Bt(Uint8Array.of(4),L,n.toBytes(I))}function y(E){j(E,void 0,"Point");let{publicKey:d,publicKeyUncompressed:p}=B,b=E.length,I=E[0],L=E.subarray(1);if(u&&b===1&&I===0)return{x:n.ZERO,y:n.ZERO};if(b===d&&(I===2||I===3)){let _=n.fromBytes(L);if(!n.isValid(_))throw new Error("bad point: is not on curve, wrong x");let P=D(_),N;try{N=n.sqrt(P)}catch(rt){let G=rt instanceof Error?": "+rt.message:"";throw new Error("bad point: is not on curve, sqrt error"+G)}x();let z=n.isOdd(N);return(I&1)===1!==z&&(N=n.neg(N)),{x:_,y:N}}else if(b===p&&I===4){let _=n.BYTES,P=n.fromBytes(L.subarray(0,_)),N=n.fromBytes(L.subarray(_,_*2));if(!R(P,N))throw new Error("bad point: is not on curve");return{x:P,y:N}}else throw new Error(`bad point: got length ${b}, expected compressed=${d} or uncompressed=${p}`)}let w=h===void 0?v:h,S=m===void 0?y:m,C=n.mul(s.b,Do),F=n.is0(s.a)?E=>n.ZERO:E=>n.mul(s.a,E);function D(E){let d=n.sqr(E),p=n.mul(d,E);return n.add(n.add(p,n.mul(E,s.a)),s.b)}function R(E,d){let p=n.sqr(d),b=D(E);return n.eql(p,b)}if(!R(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let K=n.mul(n.pow(s.a,Do),ju),k=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(K,k)))throw new Error("bad curve params: a or b");function q(E,d,p=!1){if(!n.isValid(d)||p&&n.is0(d))throw new Error(`bad point coordinate ${E}`);return typeof d=="object"&&d!==null?n.create(d):d}function Z(E){if(!(E instanceof O))throw new Error("Weierstrass Point expected")}function T(E){if(!g||!g.basises)throw new Error("no endo");return zu(E,g.basises,o.ORDER)}function U(E,d,p,b){if(!o.isValid(b))throw new RangeError("invalid scalar: out of range");if(g){let{k1neg:I,k1:L,k2neg:_,k2:P}=T(b),N=new O(n.mul(p.X,g.beta),p.Y,p.Z);E.push(I?p.negate():p,_?N.negate():N),d.push(L,P)}else E.push(p),d.push(b)}let M=new WeakSet;class O{static BASE=new O(s.Gx,s.Gy,n.ONE);static ZERO=new O(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(d,p,b){this.X=q("x",d),this.Y=q("y",p,!0),this.Z=q("z",b),Object.freeze(this)}static CURVE(){return s}static fromAffine(d){let{x:p,y:b}=d||{};if(!d||!n.isValid(p)||!n.isValid(b))throw new Error("invalid affine point");if(d instanceof O)throw new Error("projective point not allowed");return n.is0(p)&&n.is0(b)?O.ZERO:new O(p,b,n.ONE)}static fromBytes(d){let p=O.fromAffine(S(j(d,void 0,"point")));return p.assertValidity(),p}static fromHex(d){return O.fromBytes(Se(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=6,p=!0){return J.setWindowSize(this,d),p||this.multiply(Do),this}assertValidity(){let d=this;if(d.is0()){if(u&&n.is0(d.X)&&n.eql(d.Y,n.ONE)&&n.is0(d.Z))return;throw new Error("bad point: ZERO")}if(M.has(d))return;let{x:p,y:b}=d.toAffine();if(!n.isValid(p)||!n.isValid(b))throw new Error("bad point: x or y not field elements");if(!R(p,b))throw new Error("bad point: equation left != right");if(!d.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");M.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){Z(d);let{X:p,Y:b,Z:I}=this,{X:L,Y:_,Z:P}=d,N=n.eql(n.mul(p,P),n.mul(L,I)),z=n.eql(n.mul(b,P),n.mul(_,I));return N&&z}negate(){return new O(this.X,n.neg(this.Y),this.Z)}double(){let{X:d,Y:p,Z:b}=this,I=n.ZERO,L=n.ZERO,_=n.ZERO,P=n.mul(d,d),N=n.mul(p,p),z=n.mul(b,b),H=n.mul(d,p);return H=n.add(H,H),_=n.mul(d,b),_=n.add(_,_),I=F(_),L=n.mul(C,z),L=n.add(I,L),I=n.sub(N,L),L=n.add(N,L),L=n.mul(I,L),I=n.mul(H,I),_=n.mul(C,_),z=F(z),H=n.sub(P,z),H=F(H),H=n.add(H,_),_=n.add(P,P),P=n.add(_,P),P=n.add(P,z),P=n.mul(P,H),L=n.add(L,P),z=n.mul(p,b),z=n.add(z,z),P=n.mul(z,H),I=n.sub(I,P),_=n.mul(z,N),_=n.add(_,_),_=n.add(_,_),new O(I,L,_)}add(d){Z(d);let{X:p,Y:b,Z:I}=this,{X:L,Y:_,Z:P}=d,N=n.ZERO,z=n.ZERO,H=n.ZERO,rt=n.mul(p,L),G=n.mul(b,_),ut=n.mul(I,P),St=n.add(p,b),W=n.add(L,_);St=n.mul(St,W),W=n.add(rt,G),St=n.sub(St,W),W=n.add(p,I);let nt=n.add(L,P);return W=n.mul(W,nt),nt=n.add(rt,ut),W=n.sub(W,nt),nt=n.add(b,I),N=n.add(_,P),nt=n.mul(nt,N),N=n.add(G,ut),nt=n.sub(nt,N),H=F(W),N=n.mul(C,ut),H=n.add(N,H),N=n.sub(G,H),H=n.add(G,H),z=n.mul(N,H),G=n.add(rt,rt),G=n.add(G,rt),ut=F(ut),W=n.mul(C,W),G=n.add(G,ut),ut=n.sub(rt,ut),ut=F(ut),W=n.add(W,ut),rt=n.mul(G,W),z=n.add(z,rt),rt=n.mul(nt,W),N=n.mul(St,N),N=n.sub(N,rt),rt=n.mul(St,G),H=n.mul(nt,H),H=n.add(H,rt),new O(N,z,H)}subtract(d){return Z(d),this.add(d.negate())}is0(){return this.equals(O.ZERO)}multiply(d){if(!o.isValidNot0(d))throw new RangeError("invalid scalar: out of range");let{p,f:b}=J.mulSecret(this,d,i,Y);return Y([p,b])[0]}multiplyUnsafe(d){let p=this,b=d;if(!o.isValid(b))throw new RangeError("invalid scalar: out of range");if(b===Mt||p.is0())return O.ZERO;if(b===ue)return p;if(J.hasWindowSize(this))return J.mulUnsafe(p,b,Y);let I=[],L=[];return U(I,L,p,b),Lr(O,I,L)}mulAddUnsafe(d,p,b){Z(p);let I=[],L=[];return U(I,L,this,d),U(I,L,p,b),Lr(O,I,L)}toAffine(d){let p=this,b=d;if(b!=null&&!n.isValid(b))throw new RangeError('"invertedZ" expected valid field element');let{X:I,Y:L,Z:_}=p;if(n.eql(_,n.ONE))return{x:I,y:L};let P=p.is0();b==null&&(b=P?n.ONE:n.inv(_));let N=n.mul(I,b),z=n.mul(L,b),H=n.mul(_,b);if(P)return{x:n.ZERO,y:n.ZERO};if(!n.eql(H,n.ONE))throw new Error("invZ was invalid");return{x:N,y:z}}isTorsionFree(){return i===ue?!0:l?l(O,this):J.mulUnsafe(this,a).is0()}clearCofactor(){return i===ue?this:f?f(O,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===ue?this.is0():this.clearCofactor().is0()}toBytes(d=!0){return wt(d,"isCompressed"),this.assertValidity(),w(O,this,d)}toHex(d=!0){return Ve(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let Y=E=>Tr(O,E),J=new Te(O,A);return J.bits>=6&&O.BASE.precompute(6),Object.freeze(O.prototype),Object.freeze(O),O}function Mi(e){return Uint8Array.of(e?2:3)}function qi(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Vu(e,t={}){Xt(e);let{Fn:r}=e,n=t.randomBytes===void 0?se:t.randomBytes,o=Object.assign(qi(e.Fp,r),{seed:Math.max(Br(r.ORDER),16)});function s(h){try{let A=r.fromBytes(h);return r.isValidNot0(A)}catch{return!1}}function i(h,A){let{publicKey:g,publicKeyUncompressed:B}=o;try{let x=h.length;return A===!0&&x!==g||A===!1&&x!==B?!1:!e.fromBytes(h).is0()}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,Ir(j(h,o.seed,"seed"),r.ORDER)}function c(h,A=!0){return e.BASE.multiply(r.fromBytes(h)).toBytes(A)}function u(h){let{secretKey:A,publicKey:g,publicKeyUncompressed:B}=o,x=r._lengths;if(!Gt(h))return;let v=j(h,void 0,"key").length,y=v===g||v===B,w=v===A||!!x?.includes(v);if(!(y&&w))return y}function f(h,A,g=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(A)===!1)throw new Error("second arg must be public key");let B=r.fromBytes(h),x=e.fromBytes(A);if(x.is0())throw new Error("invalid public key: point at infinity");return x.multiply(B).toBytes(g)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},m=Rr(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:m,Point:e,utils:l,lengths:o})}function Hi(e,t,r={}){Xt(e);let n=t;pr(n),xt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?se:o.randomBytes,i=o.hmac===void 0?(E,d)=>Ni(n,E,d):o.hmac,{Fp:a,Fn:c}=e,{ORDER:u,BITS:f}=c,l=Br(u),m=Yn(s,l),{keygen:h,getPublicKey:A,getSharedSecret:g,utils:B,lengths:x}=Vu(e,o),v={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},y=u*Fi+ue<a.ORDER;function w(E){let d=u>>ue;return E>d}function S(E,d){if(!c.isValidNot0(d))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return d}function C(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function F(E,d,p){return C(),(E===p?0:2)|Number(a.isOdd(d))}function D(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function R(E,d){Oo(d);let p=x.signature,b=d==="compact"?p:d==="recovered"?p+1:void 0;return j(E,b)}class K{r;s;recovery;constructor(d,p,b){if(this.r=S("r",d),this.s=S("s",p),b!=null){if(D(),![0,1,2,3].includes(b))throw new Error("invalid recovery id");this.recovery=b}Object.freeze(this)}static fromBytes(d,p=v.format){R(d,p);let b;if(p==="der"){if(d.length>2*c.BYTES+16)throw new zr.Err("invalid signature: DER signature too long");let{r:P,s:N}=zr.toSig(j(d),c.BYTES+1);return new K(P,N)}p==="recovered"&&(b=d[0],p="compact",d=d.subarray(1));let I=x.signature/2,L=d.subarray(0,I),_=d.subarray(I,I*2);return new K(c.fromBytes(L),c.fromBytes(_),b)}static fromHex(d,p){return this.fromBytes(Se(d),p)}assertRecovery(){let{recovery:d}=this;if(d==null)throw new Error("invalid recovery id: must be present");return d}addRecoveryBit(d){return new K(this.r,this.s,d)}recoverPublicKey(d){let{r:p,s:b}=this,I=this.assertRecovery(),L=I===2||I===3?p+u:p;if(!a.isValid(L))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let _=a.toBytes(L),P=e.fromBytes(Bt(Mi((I&1)===0),_)),N=c.inv(L),z=q(j(d,void 0,"msgHash")),H=c.create(-z*N),rt=c.create(b*N),G=e.BASE.mulAddUnsafe(H,P,rt);if(G.is0())throw new Error("invalid recovery: point at infinify");return G.assertValidity(),G}hasHighS(){return w(this.s)}toBytes(d=v.format){if(Oo(d),d==="der")return Se(zr.hexFromSig(this));let{r:p,s:b}=this,I=c.toBytes(p),L=c.toBytes(b);return d==="recovered"?(D(),Bt(Uint8Array.of(this.assertRecovery()),I,L)):Bt(I,L)}toHex(d){return Ve(this.toBytes(d))}}Object.freeze(K.prototype),Object.freeze(K);let k=o.bits2int===void 0?function(d){if(d.length>8192)throw new Error("input is too large");let p=Ot(d),b=d.length*8-f;return b>0?p>>BigInt(b):p}:o.bits2int,q=o.bits2int_modN===void 0?function(d){return c.create(k(d))}:o.bits2int_modN,Z=Ye(f);function T(E){return ve("num < 2^"+f,E,Mt,Z),c.toBytes(E)}function U(E,d){return j(E,void 0,"message"),d?j(n(E),void 0,"prehashed message"):E}function M(E,d,p){let{lowS:b,prehash:I,extraEntropy:L}=Ro(p,v);E=U(E,I);let _=q(E),P=c.fromBytes(d);if(!c.isValidNot0(P))throw new Error("invalid private key");let N=[T(P),T(_)];if(L!=null&&L!==!1){let G=L===!0?s(x.secretKey):L;N.push(j(G,void 0,"extraEntropy"))}let z=Bt(...N),H=_;function rt(G){let ut=k(G);if(!c.isValidNot0(ut))return;let St=e.BASE.multiply(ut).toAffine(),W=c.create(St.x);if(W===Mt)return;let nt;if(m!==void 0){let Ke=Ot(Ir(m(l),u)),ta=c.inv(c.mul(Ke,ut)),ea=c.mul(Ke,H),ra=c.mul(Ke,P);nt=c.create(ta*c.create(ea+ra*W))}else{let Ke=Xs(ut,u);nt=c.create(Ke*c.create(H+W*P))}if(nt===Mt)return;let Wr=F(St.x,St.y,W),jo=nt;return b&&w(nt)&&(jo=c.neg(nt),Wr^=1),new K(W,jo,y?void 0:Wr)}return{seed:z,k2sig:rt}}function O(E,d,p={}){let{seed:b,k2sig:I}=M(E,d,p);return zs(n.outputLen,c.BYTES,i)(b,I).toBytes(p.format)}function Y(E,d,p,b={}){let{lowS:I,prehash:L,format:_}=Ro(b,v);if(p=j(p,void 0,"publicKey"),d=U(d,L),!Gt(E)){let P=E instanceof K?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+P)}R(E,_);try{let P=K.fromBytes(E,_),N=e.fromBytes(p);if(N.is0()||I&&P.hasHighS())return!1;let{r:z,s:H}=P,rt=q(d),G=c.inv(H),ut=c.create(rt*G),St=c.create(z*G),W=e.BASE.mulAddUnsafe(ut,N,St);if(W.is0())return!1;let nt=W.toAffine();return!(c.create(nt.x)!==z||_==="recovered"&&P.recovery!==F(nt.x,nt.y,z))}catch{return!1}}function J(E,d,p={}){let{prehash:b}=Ro(p,v);return d=U(d,b),K.fromBytes(E,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:h,getPublicKey:A,getSharedSecret:g,utils:B,lengths:x,Point:e,sign:O,verify:Y,recoverPublicKey:J,Signature:K,hash:n})}var Ko={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},$u={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var zi=BigInt(2);function Zu(e){let t=Ko.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=X(f,r,t)*f%t,m=X(l,r,t)*f%t,h=X(m,zi,t)*u%t,A=X(h,o,t)*h%t,g=X(A,s,t)*A%t,B=X(g,a,t)*g%t,x=X(B,c,t)*B%t,v=X(x,a,t)*g%t,y=X(v,r,t)*f%t,w=X(y,i,t)*A%t,S=X(w,n,t)*u%t,C=X(S,zi,t);if(!Co.eql(Co.sqr(C),e))throw new Error("Cannot find square root");return C}var Co=Ie(Ko.p,{sqrt:Zu}),Yu=ki(Ko,{Fp:Co,endo:$u}),Ce=Hi(Yu,Ee);function ji(e,t,r,n){let o=ur.digest(r instanceof Uint8Array?r:r.subarray());if(Nr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ce.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Xe(String(s))});try{return n?.signal?.throwIfAborted(),Ce.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new Xe(String(s))}}var jr=class{type="secp256k1";raw;_key;constructor(t){this._key=$i(t),this.raw=Vi(this._key)}toMultihash(){return Rt.digest(zt(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return st.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,r,n){return ji(this._key,r,t,n)}};function Zi(e){return new jr(e)}function Vi(e){return Ce.Point.fromBytes(e).toBytes()}function $i(e){try{return Ce.Point.fromBytes(e),e}catch(t){throw new Qt(String(t))}}function Yi(e,t){let{Type:r,Data:n}=Ft.decode(e),o=n??new Uint8Array;switch(r){case at.RSA:return Io(o,t);case at.Ed25519:return bi(o);case at.secp256k1:return Zi(o);case at.ECDSA:return ws(o);default:throw new de}}function zt(e){return Ft.encode({Type:at[e.type],Data:e.raw})}var Gi=Symbol.for("nodejs.util.inspect.custom"),Gu=114,nr=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()})`}[Jr]=!0;toString(){return this.string==null&&(this.string=st.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return dt.createV1(Gu,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return lt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return lt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Gi](){return`PeerId(${this.toString()})`}},Vr=class extends nr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},$r=class extends nr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Zr=class extends nr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Wu=2336,Po=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Rt.digest(it(this.url))}[Gi](){return`PeerId(${this.url})`}[Jr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return dt.createV1(Wu,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=et(t)),t.toString()===this.toString())}};function Wi(e){if(e.type==="Ed25519")return new $r({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Zr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Vr({multihash:e.toCID().multihash,publicKey:e});throw new de}var No=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},Xu=e=>"reason"in e?e.reason:new DOMException("This operation was aborted.","AbortError"),Ju=2**31-1,Qu=(e,t)=>{if(typeof e!="number"||Math.sign(e)!==1)return new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(typeof t?.setTimeout!="function"||typeof t?.clearTimeout!="function")return new TypeError("Expected `customTimers` to have a `setTimeout` and a `clearTimeout` function")};function Uo(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,u=()=>{try{e.cancel?.()}catch{}},l=new Promise((m,h)=>{let A=()=>{h(Xu(i)),u()},g=Qu(r,s);try{g?h(g):i?.aborted?A():i&&(c=A,i.addEventListener("abort",c,{once:!0}))}finally{e.then(m,h)}if(g||i?.aborted||r>Ju)return;let B=n||o===!1||o instanceof Error?void 0:new No(o??`Promise timed out after ${r} milliseconds`);a=s.setTimeout.call(void 0,()=>{if(n)try{m(n())}catch(x){h(x)}else o===!1?m():h(o instanceof Error?o:B);u()},r)}).finally(()=>{try{l.clear()}catch{}try{c&&i.removeEventListener("abort",c)}catch{}});return l.clear=()=>{a!==void 0&&(s.clearTimeout.call(void 0,a),a=void 0)},l}var Xi=e=>typeof e=="function"?{filter:e}:{...e},tf=e=>e===1/0||Number.isSafeInteger(e)&&e>=0,ef=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],rf=e=>{for(let[t,r]of ef){let n=e?.[t],o=e?.[r];if(typeof n=="function"&&typeof o=="function")return{addListener:n.bind(e),removeListener:o.bind(e)}}throw new TypeError("Emitter is not compatible")},nf=e=>{let t=new Map;for(let[r,n]of e)for(let o of Array.isArray(r)?r:[r])t.has(o)||t.set(o,n);return t},of=({addListener:e,removeListener:t,handlers:r,signal:n,abortHandler:o,isDone:s})=>{n?.addEventListener("abort",o,{once:!0});for(let[i,a]of r)if(e(i,a),s()){t(i,a);return}},sf=({removeListener:e,handlers:t,signal:r,abortHandler:n})=>{for(let[o,s]of t)e(o,s);r?.removeEventListener("abort",n)},af=(e,t,r)=>{let n=Promise.resolve();return(o,s)=>{n=n.then(async()=>{if(t())return;let i;try{i=e?await e(o):!0}catch(a){t()||r(a);return}t()||s(i)})}};function cf(e,t,r){let n=()=>{},o=!1,s,i=new Promise((a,c)=>{r=Xi(r);let{filter:u}=r;if(!tf(r.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof r.timeout=="number"&&!(r.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${r.timeout}\``);r.signal?.throwIfAborted();let{addListener:f,removeListener:l}=rf(e);if(r.count===0){a([]);return}let m=[],h=w=>{n(),c(w)},A=af(u,()=>o,h),g=w=>{m.push(w),r.count===m.length&&(n(),a(m))},B=(...w)=>{if(o)return;let S=r.multiArgs?w:w[0];if(!u){g(S);return}A(S,C=>{C&&g(S)})},x=(...w)=>{h(r.rejectionMultiArgs?w:w[0])},v=()=>{h(r.signal.reason)},y={addListener:f,removeListener:l,handlers:nf([[t,B],[r.rejectionEvents??["error"],x]]),signal:r.signal,abortHandler:v,isDone:()=>o};n=()=>{o=!0,clearTimeout(s),sf(y)},of(y),!(o||!r.resolveImmediately)&&(Number.isFinite(r.timeout)&&r.timeout<=2**31-1&&(s=setTimeout(n,r.timeout)),a(m))});if(i.cancel=n,typeof r.timeout=="number"&&r.timeout>0&&!r.resolveImmediately){let a=Uo(i,{milliseconds:r.timeout});return a.cancel=()=>{n(),a.clear()},a}return i}function Ji(e,t,r){let n=cf(e,t,{...Xi(r),count:1,resolveImmediately:!1}),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var fe=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function uf(e){return e.reason}function Fo(e,t,r){if(t==null||e==null)return e;let n=r?.translateError??uf;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;return Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})]).finally(()=>{o!=null&&t.removeEventListener("abort",o)})}var lf=4194304,Yr=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Mo=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},qo=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ho=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function df(e){return typeof e?.closeRead=="function"}function hf(e){return typeof e?.close=="function"}function ko(e){return df(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:hf(e)?e.status!=="open":!1}function pf(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function mf(e,t){let r=t?.maxBufferSize??lf,n=new ft,o,s=!1,i;if(!pf(e))throw new ot("Argument should be a Stream or a Multiaddr");let a=l=>{if(!s&&i==null){if(n.append(l.data),n.byteLength>r){let m=n.byteLength;n.consume(m);let h=new sr(`Read buffer overflow - ${m} > ${r}`);i=h,o?.reject(h),queueMicrotask(()=>{e.abort(h)});return}o?.resolve()}};e.addEventListener("message",a);let c=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};e.addEventListener("close",c);let u=()=>{o?.resolve()};e.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(l){if(s===!0)throw new Yr("Stream was unwrapped");if(i!=null)throw i;if(ko(e)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new fe(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let m=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=m){o.resolve();break}if(await Fo(o.promise,l?.signal),ko(e)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let h=l?.bytes??n.byteLength;if(n.byteLength<h){if(ko(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,h),new fe(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return f.read(l)}let A=n.sublist(0,h);return n.consume(h),A},async write(l,m){if(s===!0)throw new Yr("Stream was unwrapped");e.send(l)||await Ji(e,"drain",{signal:m?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",a),e.removeEventListener("close",c),e.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.unshift(n),n.consume(n.byteLength))),e}};return f}function yf(e,t={}){let r=mf(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Ut(t.maxDataLength));let n=t?.lengthDecoder??wi,o=t?.lengthEncoder??gi;return{async read(i){let a=-1,c=new ft;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Mo("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Ho(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new qo(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",a),new fe(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new fe(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new ft(o(i.byteLength),i),a)},async writeV(i,a){let c=new ft(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function Qi(e,t){let r=yf(e,t),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i,s)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var Gr;(function(e){let t;e.codec=()=>(t==null&&(t=De((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.id!=null&&(i.uint32(10),i.bytes(s.id)),s.pubkey!=null&&(i.uint32(18),i.bytes(s.pubkey)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.id=s.bytes();break}case 2:{c.pubkey=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"Exchange"});s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}id`,value:s.bytes()};break}case 2:{yield{field:`${a}pubkey`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"Exchange"})})),t);function r(s){return _e(s,e.codec())}e.encode=r;function n(s,i){return Le(s,e.codec(),i)}e.decode=n;function o(s,i){return Re(s,e.codec(),i)}e.stream=o})(Gr||(Gr={}));var bf="/plaintext/2.0.0",zo=class{protocol=bf;privateKey;log;constructor(t){this.privateKey=t.privateKey,this.log=t.logger.forComponent("libp2p:plaintext")}[Symbol.toStringTag]="@libp2p/plaintext";[Vo]=["@libp2p/connection-encryption"];async secureInbound(t,r){return this._encrypt(t,r)}async secureOutbound(t,r){return this._encrypt(t,r)}async _encrypt(t,r){let n=t.log?.newScope("plaintext")??this.log,o=Qi(t).pb(Gr);n("write pubkey exchange to peer %p",r?.remotePeer);let s=this.privateKey.publicKey;await o.write({id:s.toMultihash().bytes,pubkey:yt(zt(s))},r);let i=await o.read(r),a;try{if(i.pubkey==null)throw new le("Public key missing");if(i.pubkey.byteLength===0)throw new le("Public key data too short");if(i.id==null)throw new le("Remote id missing");let c=Yi(i.pubkey);if(!lt(c.toMultihash().bytes,i.id))throw new Pe("Public key did not match id");a=Wi(c)}catch(c){throw n.error("invalid public key - %e",c),new Pe(`Invalid public key - ${c.message}`)}if(r?.remotePeer!=null&&!a.equals(r?.remotePeer))throw new or;return n("plaintext key exchange completed successfully with peer %p",a),{connection:o.unwrap().unwrap(),remotePeer:a}}};function gf(){return e=>new zo(e)}return aa(wf);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/curves/utils.js: