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