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