@libp2p/crypto 5.1.19-a34745c01 → 5.1.20-08898d7df

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PCrypto = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PCrypto=(()=>{var Kn=Object.defineProperty;var Nc=Object.getOwnPropertyDescriptor;var Pc=Object.getOwnPropertyNames;var Mc=Object.prototype.hasOwnProperty;var z=(e,t)=>{for(var r in t)Kn(e,r,{get:t[r],enumerable:!0})},Hc=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Pc(t))!Mc.call(e,o)&&o!==r&&Kn(e,o,{get:()=>t[o],enumerable:!(n=Nc(t,o))||n.enumerable});return e};var qc=e=>Hc(Kn({},"__esModule",{value:!0}),e);var jd={};z(jd,{hmac:()=>zr,keys:()=>Ms,pbkdf2:()=>qs,randomBytes:()=>vs});var zr={};z(zr,{create:()=>On});function Vc(e){return e.buffer instanceof ArrayBuffer}function ft(e){return Vc(e)?e:e.slice()}var nr=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},or=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Vr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var $={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Vr("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 js={SHA1:20,SHA256:32,SHA512:64};var zc={SHA1:"SHA-1",SHA256:"SHA-256",SHA512:"SHA-512"},jc=async(e,t)=>{let r=await $.get().subtle.sign({name:"HMAC"},e,ft(t));return new Uint8Array(r,0,r.byteLength)};async function On(e,t){let r=zc[e],n=await $.get().subtle.importKey("raw",ft(t),{name:"HMAC",hash:{name:r}},!1,["sign"]);return{async digest(o){return jc(n,o)},length:js[e]}}var Ms={};z(Ms,{generateEphemeralKeyPair:()=>Uc,generateKeyPair:()=>Cd,generateKeyPairFromSeed:()=>Ud,keyStretcher:()=>Kc,privateKeyFromCryptoKeyPair:()=>qd,privateKeyFromProtobuf:()=>Fd,privateKeyFromRaw:()=>kd,privateKeyToCryptoKeyPair:()=>Hd,privateKeyToProtobuf:()=>Nd,publicKeyFromMultihash:()=>Od,publicKeyFromProtobuf:()=>Rd,publicKeyFromRaw:()=>Kd,publicKeyToProtobuf:()=>fe});var k=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ve=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},sr=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var zt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Mn={};z(Mn,{base58btc:()=>ot,base58flickr:()=>Qc});var rl=new Uint8Array(0);function Zs(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 Ft(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return ie(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return ie(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function $s(e){return new TextEncoder().encode(e)}function Ys(e){return new TextDecoder().decode(e)}function Zc(e){return e?.buffer instanceof ArrayBuffer}function ie(e){return Zc(e)?e:e.slice()}function $c(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,f=e.charAt(0),c=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function h(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var x=0,p=0,b=0,E=l.length;b!==E&&l[b]===0;)b++,x++;for(var A=(E-b)*u+1>>>0,L=new Uint8Array(A);b!==E;){for(var T=l[b],R=0,C=A-1;(T!==0||R<p)&&C!==-1;C--,R++)T+=256*L[C]>>>0,L[C]=T%a>>>0,T=T/a>>>0;if(T!==0)throw new Error("Non-zero carry");p=R,b++}for(var I=A-p;I!==A&&L[I]===0;)I++;for(var O=f.repeat(x);I<A;++I)O+=e.charAt(L[I]);return O}function y(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;var x=0;if(l[x]!==" "){for(var p=0,b=0;l[x]===f;)p++,x++;for(var E=(l.length-x)*c+1>>>0,A=new Uint8Array(E);l[x];){var L=r[l.charCodeAt(x)];if(L===255)return;for(var T=0,R=E-1;(L!==0||T<b)&&R!==-1;R--,T++)L+=a*A[R]>>>0,A[R]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");b=T,x++}if(l[x]!==" "){for(var C=E-b;C!==E&&A[C]===0;)C++;for(var I=new Uint8Array(p+(E-C)),O=p;C!==E;)I[O++]=A[C++];return I}}}function m(l){var x=y(l);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:y,decode:m}}var Yc=$c,Gc=Yc,Xs=Gc;var Fn=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")}},kn=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 Ws(this,t)}},Nn=class{decoders;constructor(t){this.decoders=t}or(t){return Ws(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 Ws(e,t){return new Nn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Pn=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 Fn(t,r,n),this.decoder=new kn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Be({name:e,prefix:t,encode:r,decode:n}){return new Pn(e,t,r,n)}function jt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Xs(r,e);return Be({prefix:t,name:e,encode:n,decode:s=>Ft(o(s))})}function Xc(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,f=0;for(let c=0;c<o;++c){let u=t[e[c]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,i+=r,i>=8&&(i-=8,s[f++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Wc(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let f=0;f<e.length;++f)for(a=a<<8|e[f],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 Jc(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function G({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Jc(n);return Be({prefix:t,name:e,encode(s){return Wc(s,n,r)},decode(s){return Xc(s,o,r,e)}})}var ot=jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Qc=jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Hn={};z(Hn,{base32:()=>Ie,base32hex:()=>nf,base32hexpad:()=>sf,base32hexpadupper:()=>af,base32hexupper:()=>of,base32pad:()=>ef,base32padupper:()=>rf,base32upper:()=>tf,base32z:()=>cf});var Ie=G({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),tf=G({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ef=G({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),rf=G({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),nf=G({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),of=G({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),sf=G({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),af=G({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),cf=G({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var qn={};z(qn,{base36:()=>ir,base36upper:()=>ff});var ir=jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ff=jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var uf=ti,Js=128,hf=127,df=~hf,lf=Math.pow(2,31);function ti(e,t,r){t=t||[],r=r||0;for(var n=r;e>=lf;)t[r++]=e&255|Js,e/=128;for(;e&df;)t[r++]=e&255|Js,e>>>=7;return t[r]=e|0,ti.bytes=r-n+1,t}var pf=Vn,mf=128,Qs=127;function Vn(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw Vn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Qs)<<o:(i&Qs)*Math.pow(2,o),o+=7}while(i>=mf);return Vn.bytes=s-n,r}var bf=Math.pow(2,7),yf=Math.pow(2,14),xf=Math.pow(2,21),gf=Math.pow(2,28),wf=Math.pow(2,35),Ef=Math.pow(2,42),Sf=Math.pow(2,49),Af=Math.pow(2,56),vf=Math.pow(2,63),Bf=function(e){return e<bf?1:e<yf?2:e<xf?3:e<gf?4:e<wf?5:e<Ef?6:e<Sf?7:e<Af?8:e<vf?9:10},If={encode:uf,decode:pf,encodingLength:Bf},Tf=If,ar=Tf;function cr(e,t=0){return[ar.decode(e,t),ar.decode.bytes]}function Te(e,t,r=0){return ar.encode(e,t,r),t}function Le(e){return ar.encodingLength(e)}function Dt(e,t){let r=t.byteLength,n=Le(e),o=n+Le(r),s=new Uint8Array(o+r);return Te(e,s,0),Te(r,s,n),s.set(t,o),new _e(e,r,t,s)}function ei(e){let t=Ft(e),[r,n]=cr(t),[o,s]=cr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new _e(r,o,i,t)}function ri(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Zs(e.bytes,r.bytes)}}var _e=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=ie(n),this.bytes=ie(o)}};function ni(e,t){let{bytes:r,version:n}=e;return n===0?_f(r,zn(e),t??ot.encoder):Df(r,zn(e),t??Ie.encoder)}var oi=new WeakMap;function zn(e){let t=oi.get(e);if(t==null){let r=new Map;return oi.set(e,r),r}return t}var wt=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=ie(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!==ur)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Cf)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=Dt(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&&ri(t.multihash,n.multihash)}toString(t){return ni(this,t)}toJSON(){return{"/":ni(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??si(n,o,s.bytes))}else if(r[Uf]===!0){let{version:n,multihash:o,code:s}=r,i=ei(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!==ur)throw new Error(`Version 0 CID must use dag-pb (code: ${ur}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=si(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,ur,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=Ft(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 _e(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[h,y]=cr(t.subarray(r));return r+=y,h},o=n(),s=ur;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(),f=n(),c=r+f,u=c-i;return{version:o,codec:s,multihashCode:a,digestSize:f,multihashSize:u,size:c}}static parse(t,r){let[n,o]=Lf(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 zn(s).set(n,t),s}};function Lf(e,t){switch(e[0]){case"Q":{let r=t??ot;return[ot.prefix,r.decode(`${ot.prefix}${e}`)]}case ot.prefix:{let r=t??ot;return[ot.prefix,r.decode(e)]}case Ie.prefix:{let r=t??Ie;return[Ie.prefix,r.decode(e)]}case ir.prefix:{let r=t??ir;return[ir.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 _f(e,t,r){let{prefix:n}=r;if(n!==ot.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 Df(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 ur=112,Cf=18;function si(e,t,r){let n=Le(e),o=n+Le(t),s=new Uint8Array(o+r.byteLength);return Te(e,s,0),Te(t,s,n),s.set(r,o),s}var Uf=Symbol.for("@ipld/js-cid/CID");var jn={};z(jn,{identity:()=>ae});var ii=0,Rf="identity",ai=Ft;function Kf(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 Dt(ii,ai(e))}var ae={code:ii,name:Rf,encode:ai,digest:Kf};function pt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}var Zn="1.2.840.10045.3.1.7",$n="1.3.132.0.34",Yn="1.3.132.0.35";async function ci(e="P-256"){let t=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:e},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",t.publicKey),privateKey:await crypto.subtle.exportKey("jwk",t.privateKey)}}async function fi(e,t,r){let n=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["sign"]);r?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,ft(t.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function ui(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,ft(t),ft(r.subarray()));return n?.signal?.throwIfAborted(),s}function kt(e=0){return new Uint8Array(e)}function hr(e=0){return new Uint8Array(e)}function Gn(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=hr(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}function hi(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}var li=Symbol.for("@achingbrain/uint8arraylist");function di(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 Zr(e){return!!e?.[li]}var ut=class e{bufs;length;[li]=!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(Zr(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(Zr(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=di(this.bufs,t);return r.buf[r.index]}set(t,r){let n=di(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(Zr(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 Gn(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Gn(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,f=a+i.byteLength;if(o=f,t>=f)continue;let c=t>=a&&t<f,u=r>a&&r<=f;if(c&&u){if(t===a&&r===f){n.push(i);break}let h=t-a;n.push(i.subarray(h,h+(r-t)));break}if(c){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(r===f){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(!Zr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,f=this.byteLength-n.byteLength,c=n.byteLength-1,u;for(let h=r;h<=f;h+=u){u=0;for(let y=c;y>=0;y--){let m=this.get(h+y);if(n[y]!==m){u=Math.max(1,y-a[m]);break}}if(u===0)return h}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=hr(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=kt(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=kt(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=kt(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=hr(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=kt(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=kt(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=kt(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=kt(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=kt(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(!hi(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 Xn={};z(Xn,{base10:()=>Of});var Of=jt({prefix:"9",name:"base10",alphabet:"0123456789"});var Wn={};z(Wn,{base16:()=>Ff,base16upper:()=>kf});var Ff=G({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),kf=G({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Jn={};z(Jn,{base2:()=>Nf});var Nf=G({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Qn={};z(Qn,{base256emoji:()=>Vf});var pi=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}"),Pf=pi.reduce((e,t,r)=>(e[r]=t,e),[]),Mf=pi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Hf(e){return e.reduce((t,r)=>(t+=Pf[r],t),"")}function qf(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Mf[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Vf=Be({prefix:"\u{1F680}",name:"base256emoji",encode:Hf,decode:qf});var eo={};z(eo,{base64:()=>to,base64pad:()=>zf,base64url:()=>jf,base64urlpad:()=>Zf});var to=G({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),zf=G({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),jf=G({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Zf=G({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ro={};z(ro,{base8:()=>$f});var $f=G({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var no={};z(no,{identity:()=>Yf});var Yf=Be({prefix:"\0",name:"identity",encode:e=>Ys(e),decode:e=>$s(e)});var ql=new TextEncoder,Vl=new TextDecoder;var io={};z(io,{sha256:()=>$r,sha512:()=>Jf});var Wf=20;function so({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new oo(e,t,r,n,o)}var oo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Wf,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?mi(n,this.code,r?.truncate):n.then(o=>mi(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function mi(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 Dt(t,e)}function yi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var $r=so({name:"sha2-256",code:18,encode:yi("SHA-256")}),Jf=so({name:"sha2-512",code:19,encode:yi("SHA-512")});var ao={...no,...Jn,...ro,...Xn,...Wn,...Hn,...qn,...Mn,...eo,...Qn},e0={...io,...jn};function Yr(e=0){return new Uint8Array(e)}function gi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var xi=gi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),co=gi("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=Yr(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Qf={utf8:xi,"utf-8":xi,hex:ao.base16,latin1:co,ascii:co,binary:co,...ao},Gr=Qf;function Y(e,t="utf8"){let r=Gr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function H(e,t="utf8"){let r=Gr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var tu=parseInt("11111",2),fo=parseInt("10000000",2),eu=parseInt("01111111",2),wi={0:dr,1:dr,2:ru,3:su,4:iu,5:ou,6:nu,16:dr,22:dr,48:dr};function yt(e,t={offset:0}){let r=e[t.offset]&tu;if(t.offset++,wi[r]!=null)return wi[r](e,t);throw new Error("No decoder for tag "+r)}function lr(e,t){let r=0;if((e[t.offset]&fo)===fo){let n=e[t.offset]&eu,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function dr(e,t){lr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=yt(e,t);if(n===null)break;r.push(n)}return r}function ru(e,t){let r=lr(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 nu(e,t){let r=lr(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}`,f=[];for(;t.offset<n;){let c=e[t.offset];if(t.offset++,f.push(c&127),c<128){f.reverse();let u=0;for(let h=0;h<f.length;h++)u+=f[h]<<h*7;a+=`.${u}`,f=[]}}return a}function ou(e,t){return t.offset++,null}function su(e,t){let r=lr(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 iu(e,t){let r=lr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function au(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ut;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Xr(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=au(e.byteLength);return new ut(Uint8Array.from([t.byteLength|fo]),t)}function ht(e){let t=new ut,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ut(Uint8Array.from([2]),Xr(t),t)}function pr(e){let t=Uint8Array.from([0]),r=new ut(t,e);return new ut(Uint8Array.from([3]),Xr(r),r)}function Ei(e){return new ut(Uint8Array.from([4]),Xr(e),e)}function St(e,t=48){let r=new ut;for(let n of e)r.append(n);return new ut(Uint8Array.from([t]),Xr(r),r)}var cu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),fu=Uint8Array.from([6,5,43,129,4,0,34]),uu=Uint8Array.from([6,5,43,129,4,0,35]),Si={ext:!0,kty:"EC",crv:"P-256"},Ai={ext:!0,kty:"EC",crv:"P-384"},vi={ext:!0,kty:"EC",crv:"P-521"},De=32,Ce=48,Ue=66;function Bi(e){let t=yt(e);return uo(t)}function uo(e){let t=e[1],r=H(t,"base64url"),n=e[2][1][0],o=1,s,i;if(t.byteLength===De)return s=H(n.subarray(o,o+De),"base64url"),i=H(n.subarray(o+De),"base64url"),new Nt({...Si,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===Ce)return s=H(n.subarray(o,o+Ce),"base64url"),i=H(n.subarray(o+Ce),"base64url"),new Nt({...Ai,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===Ue)return s=H(n.subarray(o,o+Ue),"base64url"),i=H(n.subarray(o+Ue),"base64url"),new Nt({...vi,key_ops:["sign"],d:r,x:s,y:i});throw new k(`Private key length was wrong length, got ${t.byteLength}, expected 32, 48 or 66`)}function ho(e){let t=yt(e);return lo(t)}function lo(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===De*2+1)return n=H(t.subarray(r,r+De),"base64url"),o=H(t.subarray(r+De),"base64url"),new ce({...Si,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ce*2+1)return n=H(t.subarray(r,r+Ce),"base64url"),o=H(t.subarray(r+Ce),"base64url"),new ce({...Ai,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ue*2+1)return n=H(t.subarray(r,r+Ue),"base64url"),o=H(t.subarray(r+Ue),"base64url"),new ce({...vi,key_ops:["verify"],x:n,y:o});throw new k(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ii(e){return St([ht(Uint8Array.from([1])),Ei(Y(e.d??"","base64url")),St([Li(e.crv)],160),St([pr(new ut(Uint8Array.from([4]),Y(e.x??"","base64url"),Y(e.y??"","base64url")))],161)]).subarray()}function Ti(e){return St([ht(Uint8Array.from([1])),St([Li(e.crv)],160),St([pr(new ut(Uint8Array.from([4]),Y(e.x??"","base64url"),Y(e.y??"","base64url")))],161)]).subarray()}function Li(e){if(e==="P-256")return cu;if(e==="P-384")return fu;if(e==="P-521")return uu;throw new k(`Invalid curve ${e}`)}async function _i(e="P-256"){let t=await ci(e);return new Nt(t.privateKey)}var ce=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ti(this.jwk)),this._raw}toMultihash(){return ae.digest(fe(this))}toCID(){return wt.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}async verify(t,r,n){return ui(this.jwk,r,t,n)}},Nt=class{type="ECDSA";jwk;publicKey;_raw;constructor(t){this.jwk=t,this.publicKey=new ce({crv:t.crv,ext:t.ext,key_ops:["verify"],kty:"EC",x:t.x,y:t.y})}get raw(){return this._raw==null&&(this._raw=Ii(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}async sign(t,r){return fi(this.jwk,t,r)}};function po(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function Et(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(`${r}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new RangeError(`${r}expected integer >= 0, got ${e}`)}}function mt(e,t,r=""){let n=po(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",f=n?`length=${o}`:`type=${typeof e}`,c=i+"expected Uint8Array"+a+", got "+f;throw n?new RangeError(c):new TypeError(c)}return e}function Re(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Et(e.outputLen),Et(e.blockLen),e.outputLen<1)throw new Error('"outputLen" must be >= 1');if(e.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Ke(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Wr(e,t){mt(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function bt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Oe(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function At(e,t){return e<<32-t|e>>>t}function Jr(e,t){return e<<t|e>>>32-t>>>0}var Ci=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",hu=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Qr(e){if(mt(e),Ci)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=hu[e[r]];return t}var Pt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Di(e){if(e>=Pt._0&&e<=Pt._9)return e-Pt._0;if(e>=Pt.A&&e<=Pt.F)return e-(Pt.A-10);if(e>=Pt.a&&e<=Pt.f)return e-(Pt.a-10)}function mr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(Ci)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=Di(e.charCodeAt(s)),a=Di(e.charCodeAt(s+1));if(i===void 0||a===void 0){let f=e[s]+e[s+1];throw new RangeError('hex string expected, got non-hex character "'+f+'" at index '+s)}n[o]=i*16+a}return n}function du(e){if(typeof e!="string")throw new TypeError("string expected");return new Uint8Array(new TextEncoder().encode(e))}function mo(e,t=""){return typeof e=="string"?du(e):mt(e,void 0,t)}function bo(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];mt(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 Ui(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new TypeError("options must be object or undefined");return Object.assign(e,t)}function br(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function tn(e=32){Et(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 yo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function en(e,t,r){return e&t^~e&r}function rn(e,t,r){return e&t^e&r^t&r}var ue=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=Oe(this.buffer)}update(t){Ke(this),mt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let f=Oe(t);for(;o<=s-i;i+=o)this.process(f,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ke(this),Wr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,bt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let h=i;h<o;h++)r[h]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Oe(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let c=f/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<c;h++)a.setUint32(4*h,u[h],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Mt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var it=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var nn=BigInt(4294967295),Ri=BigInt(32);function lu(e,t=!1){return t?{h:Number(e&nn),l:Number(e>>Ri&nn)}:{h:Number(e>>Ri&nn)|0,l:Number(e&nn)|0}}function Ki(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}=lu(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var xo=(e,t,r)=>e>>>r,go=(e,t,r)=>e<<32-r|t>>>r,he=(e,t,r)=>e>>>r|t<<32-r,de=(e,t,r)=>e<<32-r|t>>>r,yr=(e,t,r)=>e<<64-r|t>>>r-32,xr=(e,t,r)=>e>>>r-32|t<<64-r;function Ct(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Oi=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Fi=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ki=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Ni=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Pi=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Mi=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var mu=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]),Zt=new Uint32Array(64),wo=class extends ue{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:f}=this;return[t,r,n,o,s,i,a,f]}set(t,r,n,o,s,i,a,f){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=f|0}process(t,r){for(let h=0;h<16;h++,r+=4)Zt[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){let y=Zt[h-15],m=Zt[h-2],l=At(y,7)^At(y,18)^y>>>3,x=At(m,17)^At(m,19)^m>>>10;Zt[h]=x+Zt[h-7]+l+Zt[h-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:f,G:c,H:u}=this;for(let h=0;h<64;h++){let y=At(a,6)^At(a,11)^At(a,25),m=u+y+en(a,f,c)+mu[h]+Zt[h]|0,x=(At(n,2)^At(n,13)^At(n,22))+rn(n,o,s)|0;u=c,c=f,f=a,a=i+m|0,i=s,s=o,o=n,n=m+x|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,f=f+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,f,c,u)}roundClean(){bt(Zt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),bt(this.buffer)}},Eo=class extends wo{A=Mt[0]|0;B=Mt[1]|0;C=Mt[2]|0;D=Mt[3]|0;E=Mt[4]|0;F=Mt[5]|0;G=Mt[6]|0;H=Mt[7]|0;constructor(){super(32)}};var Hi=Ki(["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))),bu=Hi[0],yu=Hi[1],$t=new Uint32Array(80),Yt=new Uint32Array(80),So=class extends ue{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:f,Eh:c,El:u,Fh:h,Fl:y,Gh:m,Gl:l,Hh:x,Hl:p}=this;return[t,r,n,o,s,i,a,f,c,u,h,y,m,l,x,p]}set(t,r,n,o,s,i,a,f,c,u,h,y,m,l,x,p){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=f|0,this.Eh=c|0,this.El=u|0,this.Fh=h|0,this.Fl=y|0,this.Gh=m|0,this.Gl=l|0,this.Hh=x|0,this.Hl=p|0}process(t,r){for(let A=0;A<16;A++,r+=4)$t[A]=t.getUint32(r),Yt[A]=t.getUint32(r+=4);for(let A=16;A<80;A++){let L=$t[A-15]|0,T=Yt[A-15]|0,R=he(L,T,1)^he(L,T,8)^xo(L,T,7),C=de(L,T,1)^de(L,T,8)^go(L,T,7),I=$t[A-2]|0,O=Yt[A-2]|0,V=he(I,O,19)^yr(I,O,61)^xo(I,O,6),F=de(I,O,19)^xr(I,O,61)^go(I,O,6),d=ki(C,F,Yt[A-7],Yt[A-16]),g=Ni(d,R,V,$t[A-7],$t[A-16]);$t[A]=g|0,Yt[A]=d|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:f,Dh:c,Dl:u,Eh:h,El:y,Fh:m,Fl:l,Gh:x,Gl:p,Hh:b,Hl:E}=this;for(let A=0;A<80;A++){let L=he(h,y,14)^he(h,y,18)^yr(h,y,41),T=de(h,y,14)^de(h,y,18)^xr(h,y,41),R=h&m^~h&x,C=y&l^~y&p,I=Pi(E,T,C,yu[A],Yt[A]),O=Mi(I,b,L,R,bu[A],$t[A]),V=I|0,F=he(n,o,28)^yr(n,o,34)^yr(n,o,39),d=de(n,o,28)^xr(n,o,34)^xr(n,o,39),g=n&s^n&a^s&a,v=o&i^o&f^i&f;b=x|0,E=p|0,x=m|0,p=l|0,m=h|0,l=y|0,{h,l:y}=Ct(c|0,u|0,O|0,V|0),c=a|0,u=f|0,a=s|0,f=i|0,s=n|0,i=o|0;let S=Oi(V,d,v);n=Fi(S,O,F,g),o=S|0}({h:n,l:o}=Ct(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ct(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:f}=Ct(this.Ch|0,this.Cl|0,a|0,f|0),{h:c,l:u}=Ct(this.Dh|0,this.Dl|0,c|0,u|0),{h,l:y}=Ct(this.Eh|0,this.El|0,h|0,y|0),{h:m,l}=Ct(this.Fh|0,this.Fl|0,m|0,l|0),{h:x,l:p}=Ct(this.Gh|0,this.Gl|0,x|0,p|0),{h:b,l:E}=Ct(this.Hh|0,this.Hl|0,b|0,E|0),this.set(n,o,s,i,a,f,c,u,h,y,m,l,x,p,b,E)}roundClean(){bt($t,Yt)}destroy(){this.destroyed=!0,bt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Ao=class extends So{Ah=it[0]|0;Al=it[1]|0;Bh=it[2]|0;Bl=it[3]|0;Ch=it[4]|0;Cl=it[5]|0;Dh=it[6]|0;Dl=it[7]|0;Eh=it[8]|0;El=it[9]|0;Fh=it[10]|0;Fl=it[11]|0;Gh=it[12]|0;Gl=it[13]|0;Hh=it[14]|0;Hl=it[15]|0;constructor(){super(64)}};var Gt=br(()=>new Eo,yo(1));var Fe=br(()=>new Ao,yo(3));var M=(e,t,r)=>mt(e,t,r),Bo=Et,ke=Qr,et=(...e)=>bo(...e),Ne=e=>mr(e),le=po,gr=e=>tn(e),sn=BigInt(0),vo=BigInt(1);function vt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function an(e){if(typeof e=="bigint"){if(!on(e))throw new RangeError("positive bigint expected, got "+e)}else Bo(e);return e}function Bt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function wr(e){let t=an(e).toString(16);return t.length&1?"0"+t:t}function qi(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?sn:BigInt("0x"+e)}function pe(e){return qi(Qr(e))}function Ut(e){return qi(Qr(Er(mt(e)).reverse()))}function cn(e,t){if(Et(t),t===0)throw new RangeError("zero length");e=an(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return mr(r.padStart(t*2,"0"))}function Io(e,t){return cn(e,t).reverse()}function Vi(e,t){if(e=M(e),t=M(t),e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function Er(e){return Uint8Array.from(M(e))}function fn(e){if(typeof e!="string")throw new TypeError("ascii string expected, got "+typeof e);return Uint8Array.from(e,(t,r)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${e[r]}" with code ${n} at position ${r}`);return n})}var on=e=>typeof e=="bigint"&&sn<=e;function xu(e,t,r){return on(e)&&on(t)&&on(r)&&t<=e&&e<r}function Pe(e,t,r,n){if(!xu(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Me(e){if(e<sn)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>sn;e>>=vo,t+=1);return t}var Sr=e=>(vo<<BigInt(e))-vo;function zi(e,t,r){if(Et(e,"hashLen"),Et(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=p=>new Uint8Array(p),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,f=n(e),c=n(e),u=0,h=()=>{f.fill(1),c.fill(0),u=0},y=(...p)=>r(c,et(f,...p)),m=(p=o)=>{c=y(s,p),f=y(),p.length!==0&&(c=y(i,p),f=y())},l=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let p=0,b=[];for(;p<t;){f=y();let E=f.slice();b.push(E),p+=f.length}return et(...b)};return(p,b)=>{h(),m(p);let E;for(;(E=b(l()))===void 0;)m();return h(),E}}function It(e,t={},r={}){if(Object.prototype.toString.call(e)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(e,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let f=e[s];if(a&&f===void 0)return;let c=typeof f;if(c!==i||f===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${c}`)}let o=(s,i)=>Object.entries(s).forEach(([a,f])=>n(a,f,i));o(t,!1),o(r,!0)}var To=()=>{throw new Error("not implemented")};var at=BigInt(0),X=BigInt(1),me=BigInt(2),Yi=BigInt(3),Gi=BigInt(4),Xi=BigInt(5),gu=BigInt(7),Wi=BigInt(8),wu=BigInt(9),Ji=BigInt(16);function Q(e,t){if(t<=at)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=at?r:t+r}function Z(e,t,r){if(t<at)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >at;)n*=n,n%=r;return n}function ji(e,t){if(e===at)throw new Error("invert: expected non-zero number");if(t<=at)throw new Error("invert: expected positive modulus, got "+t);let r=Q(e,t),n=t,o=at,s=X,i=X,a=at;for(;r!==at;){let c=n/r,u=n-r*c,h=o-i*c,y=s-a*c;n=r,r=u,o=i,s=a,i=h,a=y}if(n!==X)throw new Error("invert: does not exist");return Q(o,t)}function Lo(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function Qi(e,t){let r=e,n=(r.ORDER+X)/Gi,o=r.pow(t,n);return Lo(r,o,t),o}function Eu(e,t){let r=e,n=(r.ORDER-Xi)/Wi,o=r.mul(t,me),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,me),s),f=r.mul(i,r.sub(a,r.ONE));return Lo(r,f,t),f}function Su(e){let t=He(e),r=ta(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+gu)/Ji;return((a,f)=>{let c=a,u=c.pow(f,i),h=c.mul(u,n),y=c.mul(u,o),m=c.mul(u,s),l=c.eql(c.sqr(h),f),x=c.eql(c.sqr(y),f);u=c.cmov(u,h,l),h=c.cmov(m,y,x);let p=c.eql(c.sqr(h),f),b=c.cmov(u,h,p);return Lo(c,b,f),b})}function ta(e){if(e<Yi)throw new Error("sqrt is not defined for small field");let t=e-X,r=0;for(;t%me===at;)t/=me,r++;let n=me,o=He(e);for(;Zi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Qi;let s=o.pow(n,t),i=(t+X)/me;return function(f,c){let u=f;if(u.is0(c))return c;if(Zi(u,c)!==1)throw new Error("Cannot find square root");let h=r,y=u.mul(u.ONE,s),m=u.pow(c,t),l=u.pow(c,i);for(;!u.eql(m,u.ONE);){if(u.is0(m))return u.ZERO;let x=1,p=u.sqr(m);for(;!u.eql(p,u.ONE);)if(x++,p=u.sqr(p),x===h)throw new Error("Cannot find square root");let b=X<<BigInt(h-x-1),E=u.pow(y,b);h=x,y=u.sqr(E),m=u.mul(m,y),l=u.mul(l,E)}return l}}function Au(e){return e%Gi===Yi?Qi:e%Wi===Xi?Eu:e%Ji===wu?Su(e):ta(e)}var Ht=(e,t)=>(Q(e,t)&X)===X,vu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function _o(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=vu.reduce((n,o)=>(n[o]="function",n),t);if(It(e,r),Bt(e.BYTES,"BYTES"),Bt(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function Bu(e,t,r){let n=e;if(r<at)throw new Error("invalid exponent, negatives unsupported");if(r===at)return n.ONE;if(r===X)return t;let o=n.ONE,s=t;for(;r>at;)r&X&&(o=n.mul(o,s)),s=n.sqr(s),r>>=X;return o}function Ar(e,t,r=!1){let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((a,f,c)=>n.is0(f)?a:(o[c]=a,n.mul(a,f)),n.ONE),i=n.inv(s);return t.reduceRight((a,f,c)=>n.is0(f)?a:(o[c]=n.mul(a,o[c]),n.mul(a,f)),i),o}function Zi(e,t){let r=e,n=(r.ORDER-X)/me,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 Iu(e,t){if(t!==void 0&&Bo(t),e<=at)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=Me(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${t})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var $i=new WeakMap,un=class{ORDER;BITS;BYTES;isLE;ZERO=at;ONE=X;_lengths;_mod;constructor(t,r={}){if(t<=X)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}=Iu(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return Q(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return at<=t&&t<this.ORDER}is0(t){return t===at}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&X)===X}neg(t){return Q(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return Q(t*t,this.ORDER)}add(t,r){return Q(t+r,this.ORDER)}sub(t,r){return Q(t-r,this.ORDER)}mul(t,r){return Q(t*r,this.ORDER)}pow(t,r){return Bu(this,t,r)}div(t,r){return Q(t*ji(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 ji(t,this.ORDER)}sqrt(t){let r=$i.get(this);return r||$i.set(this,r=Au(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?Io(t,this.BYTES):cn(t,this.BYTES)}fromBytes(t,r=!1){M(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 c=new Uint8Array(o);c.set(t,s?0:c.length-t.length),t=c}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let f=s?Ut(t):pe(t);if(a&&(f=Q(f,i)),!r&&!this.isValid(f))throw new Error("invalid field element: outside of range 0..ORDER");return f}invertBatch(t){return Ar(this,t)}cmov(t,r,n){return vt(n,"condition"),n?r:t}};Object.freeze(un.prototype);function He(e,t={}){return new un(e,t)}function ea(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=X)throw new Error("field order must be greater than 1");let t=Me(e-X);return Math.ceil(t/8)}function Do(e){let t=ea(e);return t+Math.ceil(t/2)}function Co(e,t,r=!1){M(e);let n=e.length,o=ea(t),s=Math.max(Do(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Ut(e):pe(e),a=Q(i,t-X)+X;return r?Io(a,o):cn(a,o)}var qe=BigInt(0),be=BigInt(1);function vr(e,t){let r=t.negate();return e?r:t}function ye(e,t){let r=Ar(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function sa(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Uo(e,t){sa(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Sr(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ra(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),f=e>>i;a>n&&(a-=s,f+=be);let c=t*n,u=c+Math.abs(a)-1,h=a===0,y=a<0,m=t%2!==0;return{nextN:f,offset:u,isZero:h,isNeg:y,isNegF:m,offsetF:c}}var Ro=new WeakMap,ia=new WeakMap;function Ko(e){return ia.get(e)||1}function na(e){if(e!==qe)throw new Error("invalid wNAF")}var Ve=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>qe;)r&be&&(n=n.add(o)),o=o.double(),r>>=be;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Uo(r,this.bits),s=[],i=t,a=i;for(let f=0;f<n;f++){a=i,s.push(a);for(let c=1;c<o;c++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Uo(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:f,offset:c,isZero:u,isNeg:h,isNegF:y,offsetF:m}=ra(n,a,i);n=f,u?s=s.add(vr(y,r[m])):o=o.add(vr(h,r[c]))}return na(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Uo(t,this.bits);for(let i=0;i<s.windows&&n!==qe;i++){let{nextN:a,offset:f,isZero:c,isNeg:u}=ra(n,i,s);if(n=a,!c){let h=r[f];o=o.add(u?h.negate():h)}}return na(n),o}getPrecomputes(t,r,n){let o=Ro.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Ro.set(r,o))),o}cached(t,r,n){let o=Ko(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Ko(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){sa(r,this.bits),ia.set(t,r),Ro.delete(t)}hasCache(t){return Ko(t)!==1}};function aa(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>qe||n>qe;)r&be&&(s=s.add(o)),n&be&&(i=i.add(o)),o=o.double(),r>>=be,n>>=be;return{p1:s,p2:i}}function oa(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return _o(t),t}else return He(e,{isLE:r})}function hn(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let f of["p","n","h"]){let c=t[f];if(!(typeof c=="bigint"&&c>qe))throw new Error(`CURVE.${f} must be positive bigint`)}let o=oa(t.p,r.Fp,n),s=oa(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let f of a)if(!o.isValid(t[f]))throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function dn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Xt=BigInt(0),st=BigInt(1),Oo=BigInt(2),Tu=BigInt(8);function Lu(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 ca(e,t={}){let r=t,n=hn("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;It(r,{},{uvRatio:"function"});let f=Oo<<BigInt(s.BYTES*8)-st,c=x=>o.create(x),u=r.uvRatio===void 0?(x,p)=>{try{return{isValid:!0,value:o.sqrt(o.div(x,p))}}catch{return{isValid:!1,value:Xt}}}:r.uvRatio;if(!Lu(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function h(x,p,b=!1){let E=b?st:Xt;return Pe("coordinate "+x,p,E,f),p}function y(x){if(!(x instanceof m))throw new Error("EdwardsPoint expected")}class m{static BASE=new m(i.Gx,i.Gy,st,c(i.Gx*i.Gy));static ZERO=new m(Xt,st,st,Xt);static Fp=o;static Fn=s;X;Y;Z;T;constructor(p,b,E,A){this.X=h("x",p),this.Y=h("y",b),this.Z=h("z",E,!0),this.T=h("t",A),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){if(p instanceof m)throw new Error("extended point not allowed");let{x:b,y:E}=p||{};return h("x",b),h("y",E),new m(b,E,st,c(b*E))}static fromBytes(p,b=!1){let E=o.BYTES,{a:A,d:L}=i;p=Er(M(p,E,"point")),vt(b,"zip215");let T=Er(p),R=p[E-1];T[E-1]=R&-129;let C=Ut(T),I=b?f:o.ORDER;Pe("point.y",C,Xt,I);let O=c(C*C),V=c(O-st),F=c(L*O-A),{isValid:d,value:g}=u(V,F);if(!d)throw new Error("bad point: invalid y coordinate");let v=(g&st)===st,S=(R&128)!==0;if(!b&&g===Xt&&S)throw new Error("bad point: x=0 and x_0=1");return S!==v&&(g=c(-g)),m.fromAffine({x:g,y:C})}static fromHex(p,b=!1){return m.fromBytes(Ne(p),b)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,b=!0){return l.createCache(this,p),b||this.multiply(Oo),this}assertValidity(){let p=this,{a:b,d:E}=i;if(p.is0())throw new Error("bad point: ZERO");let{X:A,Y:L,Z:T,T:R}=p,C=c(A*A),I=c(L*L),O=c(T*T),V=c(O*O),F=c(C*b),d=c(O*c(F+I)),g=c(V+c(E*c(C*I)));if(d!==g)throw new Error("bad point: equation left != right (1)");let v=c(A*L),S=c(T*R);if(v!==S)throw new Error("bad point: equation left != right (2)")}equals(p){y(p);let{X:b,Y:E,Z:A}=this,{X:L,Y:T,Z:R}=p,C=c(b*R),I=c(L*A),O=c(E*R),V=c(T*A);return C===I&&O===V}is0(){return this.equals(m.ZERO)}negate(){return new m(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:p}=i,{X:b,Y:E,Z:A}=this,L=c(b*b),T=c(E*E),R=c(Oo*c(A*A)),C=c(p*L),I=b+E,O=c(c(I*I)-L-T),V=C+T,F=V-R,d=C-T,g=c(O*F),v=c(V*d),S=c(O*d),w=c(F*V);return new m(g,v,w,S)}add(p){y(p);let{a:b,d:E}=i,{X:A,Y:L,Z:T,T:R}=this,{X:C,Y:I,Z:O,T:V}=p,F=c(A*C),d=c(L*I),g=c(R*E*V),v=c(T*O),S=c((A+L)*(C+I)-F-d),w=v-g,B=v+g,D=c(d-b*F),_=c(S*w),U=c(B*D),K=c(S*D),P=c(w*B);return new m(_,U,P,K)}subtract(p){return y(p),this.add(p.negate())}multiply(p){if(!s.isValidNot0(p))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:b,f:E}=l.cached(this,p,A=>ye(m,A));return ye(m,[b,E])[0]}multiplyUnsafe(p){if(!s.isValid(p))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return p===Xt?m.ZERO:this.is0()||p===st?this:l.unsafe(this,p,b=>ye(m,b))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return l.unsafe(this,i.n).is0()}toAffine(p){let b=this,E=p,{X:A,Y:L,Z:T}=b,R=b.is0();E==null&&(E=R?Tu:o.inv(T));let C=c(A*E),I=c(L*E),O=o.mul(T,E);if(R)return{x:Xt,y:st};if(O!==st)throw new Error("invZ was invalid");return{x:C,y:I}}clearCofactor(){return a===st?this:this.multiplyUnsafe(a)}toBytes(){let{x:p,y:b}=this.toAffine(),E=o.toBytes(b);return E[E.length-1]|=p&st?128:0,E}toHex(){return ke(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let l=new Ve(m,s.BITS);return s.BITS>=8&&m.BASE.precompute(8),Object.freeze(m.prototype),Object.freeze(m),m}var ln=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){To()}static fromHex(t){To()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return ke(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.ep.precompute(t,r),this}};function fa(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;It(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:f}=e,c=n.outputLen,u=2*a.BYTES;if(c!==void 0&&(Bt(c,"hash.outputLen"),c!==u))throw new Error(`hash.outputLen must be ${u}, got ${c}`);let h=o.randomBytes===void 0?gr:o.randomBytes,y=o.adjustScalarBytes===void 0?d=>d:o.adjustScalarBytes,m=o.domain===void 0?(d,g,v)=>{if(vt(v,"phflag"),g.length||v)throw new Error("Contexts/pre-hash are not supported");return d}:o.domain;function l(d){return f.create(Ut(d))}function x(d){let g=C.secretKey;M(d,C.secretKey,"secretKey");let v=M(n(d),2*g,"hashedSecretKey"),S=y(v.slice(0,g)),w=v.slice(g,2*g),B=l(S);return{head:S,prefix:w,scalar:B}}function p(d){let{head:g,prefix:v,scalar:S}=x(d),w=i.multiply(S),B=w.toBytes();return{head:g,prefix:v,scalar:S,point:w,pointBytes:B}}function b(d){return p(d).pointBytes}function E(d=Uint8Array.of(),...g){let v=et(...g);return l(n(m(v,M(d,void 0,"context"),!!s)))}function A(d,g,v={}){d=M(d,void 0,"message"),s&&(d=s(d));let{prefix:S,scalar:w,pointBytes:B}=p(g),D=E(v.context,S,d),_=i.multiply(D).toBytes(),U=E(v.context,_,B,d),K=f.create(D+U*w);if(!f.isValid(K))throw new Error("sign failed: invalid s");let P=et(_,f.toBytes(K));return M(P,C.signature,"result")}let L={zip215:o.zip215};function T(d,g,v,S=L){let{context:w}=S,B=S.zip215===void 0?!!L.zip215:S.zip215,D=C.signature;d=M(d,D,"signature"),g=M(g,void 0,"message"),v=M(v,C.publicKey,"publicKey"),B!==void 0&&vt(B,"zip215"),s&&(g=s(g));let _=D/2,U=d.subarray(0,_),K=Ut(d.subarray(_,D)),P,q,N;try{P=e.fromBytes(v,B),q=e.fromBytes(U,B),N=i.multiplyUnsafe(K)}catch{return!1}if(!B&&P.isSmallOrder())return!1;let tt=E(w,U,v,g);return q.add(P.multiplyUnsafe(tt)).subtract(N).clearCofactor().is0()}let R=a.BYTES,C={secretKey:R,publicKey:R,signature:2*R,seed:R};function I(d){return d=d===void 0?h(C.seed):d,M(d,C.seed,"seed")}function O(d){return le(d)&&d.length===C.secretKey}function V(d,g){try{return!!e.fromBytes(d,g===void 0?L.zip215:g)}catch{return!1}}let F={getExtendedPublicKey:p,randomSecretKey:I,isValidSecretKey:O,isValidPublicKey:V,toMontgomery(d){let{y:g}=e.fromBytes(d),v=C.publicKey,S=v===32;if(!S&&v!==57)throw new Error("only defined for 25519 and 448");let w=S?a.div(st+g,st-g):a.div(g-st,g+st);return a.toBytes(w)},toMontgomerySecret(d){let g=C.secretKey;M(d,g);let v=n(d.subarray(0,g));return y(v).subarray(0,g)}};return Object.freeze(C),Object.freeze(F),Object.freeze({keygen:dn(I,b),getPublicKey:b,sign:A,verify:T,utils:F,Point:e,lengths:C})}function Br(e,t){if(Bt(e),Bt(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(e<0||e>2**(8*t)-1)throw new Error("invalid I2OSP input: "+e);let r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function _u(e,t){let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}function Du(e){if(!le(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?fn(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function Fo(e,t,r,n){M(e),Bt(r),t=Du(t),t.length>255&&(t=n(et(fn("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=et(t,Br(t.length,1)),f=new Uint8Array(s),c=Br(r,2),u=new Array(i),h=n(et(f,e,c,Br(0,1),a));u[0]=n(et(h,Br(1,1),a));for(let m=1;m<i;m++){let l=[_u(h,u[m-1]),Br(m+1,1),a];u[m]=n(et(...l))}return et(...u).slice(0,r)}var ua="HashToScalar-";var Cu=BigInt(0),qt=BigInt(1),ha=BigInt(2);var Uu=BigInt(5),Ru=BigInt(8),ze=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Mo={p:ze,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Ru,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Ku(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=ze,a=e*e%s*e%s,f=Z(a,ha,s)*a%s,c=Z(f,qt,s)*e%s,u=Z(c,Uu,s)*c%s,h=Z(u,t,s)*u%s,y=Z(h,r,s)*h%s,m=Z(y,n,s)*y%s,l=Z(m,o,s)*m%s,x=Z(l,o,s)*m%s,p=Z(x,t,s)*u%s;return{pow_p_5_8:Z(p,ha,s)*e%s,b2:a}}function Ou(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var ko=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Ho(e,t){let r=ze,n=Q(t*t*t,r),o=Q(n*n*t,r),s=Ku(e*o).pow_p_5_8,i=Q(e*n*s,r),a=Q(t*i*i,r),f=i,c=Q(i*ko,r),u=a===e,h=a===Q(-e,r),y=a===Q(-e*ko,r);return u&&(i=f),(h||y)&&(i=c),Ht(i,r)&&(i=Q(-i,r)),{isValid:u||h,value:i}}var Jt=ca(Mo,{uvRatio:Ho}),Wt=Jt.Fp,pa=Jt.Fn;function Fu(e){return fa(Jt,Fe,Object.assign({adjustScalarBytes:Ou,zip215:!0},e))}var je=Fu({});var No=ko,ku=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Nu=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Pu=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Mu=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),da=e=>Ho(qt,e),Hu=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Po=e=>Wt.create(Ut(e)&Hu);function la(e){let{d:t}=Mo,r=ze,n=b=>Wt.create(b),o=n(No*e*e),s=n((o+qt)*Pu),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:f,value:c}=Ho(s,a),u=n(c*e);Ht(u,r)||(u=n(-u)),f||(c=u),f||(i=o);let h=n(i*(o-qt)*Mu-a),y=c*c,m=n((c+c)*a),l=n(h*ku),x=n(qt-y),p=n(qt+y);return new Jt(n(m*p),n(x*l),n(l*p),n(m*x))}var Qt=class e extends ln{static BASE=new e(Jt.BASE);static ZERO=new e(Jt.ZERO);static Fp=Wt;static Fn=pa;constructor(t){super(t)}static fromAffine(t){return new e(Jt.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static fromBytes(t){mt(t,32);let{a:r,d:n}=Mo,o=ze,s=L=>Wt.create(L),i=Po(t);if(!Vi(Wt.toBytes(i),t)||Ht(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),f=s(qt+r*a),c=s(qt-r*a),u=s(f*f),h=s(c*c),y=s(r*n*u-h),{isValid:m,value:l}=da(s(y*h)),x=s(l*c),p=s(l*x*y),b=s((i+i)*x);Ht(b,o)&&(b=s(-b));let E=s(f*p),A=s(b*E);if(!m||Ht(A,o)||E===Cu)throw new Error("invalid ristretto255 encoding 2");return new e(new Jt(b,E,qt,A))}static fromHex(t){return e.fromBytes(mr(t))}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=ze,i=p=>Wt.create(p),a=i(i(n+r)*i(n-r)),f=i(t*r),c=i(f*f),{value:u}=da(i(a*c)),h=i(u*a),y=i(u*f),m=i(h*y*o),l;if(Ht(o*m,s)){let p=i(r*No),b=i(t*No);t=p,r=b,l=i(h*Nu)}else l=y;Ht(t*m,s)&&(r=i(-r));let x=i((n-r)*l);return Ht(x,s)&&(x=i(-x)),Wt.toBytes(x)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=c=>Wt.create(c),a=i(r*s)===i(n*o),f=i(n*s)===i(r*o);return a||f}is0(){return this.equals(e.ZERO)}};Object.freeze(Qt.BASE);Object.freeze(Qt.ZERO);Object.freeze(Qt.prototype);Object.freeze(Qt);var qu=Object.freeze({Point:Qt,hashToCurve(e,t){let r=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=Fo(e,r,64,Fe);return qu.deriveToCurve(n)},hashToScalar(e,t={DST:ua}){let r=Fo(e,t.DST,64,Fe);return pa.create(Ut(r))},deriveToCurve(e){mt(e,64);let t=Po(e.subarray(0,32)),r=la(t),n=Po(e.subarray(32,64)),o=la(n);return new Qt(r.add(o))}});var te=32,xt=64,pn=32;var Ze,ma=(async()=>{try{return await $.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function ba(){let e=je.utils.randomSecretKey(),t=je.getPublicKey(e);return{privateKey:wa(e,t),publicKey:t}}function ya(e){if(e.length!==pn)throw new TypeError('"seed" must be 32 bytes in length.');if(!(e instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let t=e,r=je.getPublicKey(t);return{privateKey:wa(t,r),publicKey:r}}async function Vu(e,t){let r;e.length===xt?r=e.subarray(0,32):r=e;let n={crv:"Ed25519",kty:"OKP",x:H(e.subarray(32),"base64url"),d:H(r,"base64url"),ext:!0,key_ops:["sign"]},o=await $.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),s=await $.get().subtle.sign({name:"Ed25519"},o,ft(t instanceof Uint8Array?t:t.subarray()));return new Uint8Array(s,0,s.byteLength)}function zu(e,t){let r=e.subarray(0,pn);return je.sign(t instanceof Uint8Array?t:t.subarray(),r)}async function xa(e,t){return Ze==null&&(Ze=await ma),Ze?Vu(e,t):zu(e,t)}async function ju(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await $.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await $.get().subtle.verify({name:"Ed25519"},n,ft(t),ft(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Zu(e,t,r){return je.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function ga(e,t,r){return Ze==null&&(Ze=await ma),Ze?ju(e,t,r):Zu(e,t,r)}function wa(e,t){let r=new Uint8Array(xt);for(let n=0;n<pn;n++)r[n]=e[n],r[pn+n]=t[n];return r}function $u(e){return e?.buffer instanceof ArrayBuffer}function Sa(e){if($u(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function xe(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=Yr(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return Sa(r)}function qo(e,t){let r=Y(e,"base64urlpad");if(t!=null){if(r.length>t)throw new Error("byte array longer than desired length");r=xe([new Uint8Array(t-r.length),r])}return r}function $e(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Ir=class{type="Ed25519";raw;constructor(t){this.raw=Ye(t,te)}toMultihash(){return ae.digest(fe(this))}toCID(){return wt.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=ga(this.raw,r,t);return $e(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}},ge=class{type="Ed25519";raw;publicKey;constructor(t,r){this.raw=Ye(t,xt),this.publicKey=new Ir(r)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}sign(t,r){r?.signal?.throwIfAborted();let n=xa(this.raw,t);return $e(n)?n.then(o=>(r?.signal?.throwIfAborted(),o)):(r?.signal?.throwIfAborted(),n)}};function Vo(e){if(e.length>xt){e=Ye(e,xt+te);let n=e.subarray(0,xt),o=e.subarray(xt,e.length);return new ge(n,o)}e=Ye(e,xt);let t=e.subarray(0,xt),r=e.subarray(te);return new ge(t,r)}function mn(e){return e=Ye(e,te),new Ir(e)}async function Aa(){let{privateKey:e,publicKey:t}=ba();return new ge(e,t)}async function va(e){let{privateKey:t,publicKey:r}=ya(e);return new ge(t,r)}function Ye(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new k(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Yu=Math.pow(2,7),Gu=Math.pow(2,14),Xu=Math.pow(2,21),Ba=Math.pow(2,28),Ia=Math.pow(2,35),Ta=Math.pow(2,42),La=Math.pow(2,49),dt=128,ee=127;function Tr(e){if(e<Yu)return 1;if(e<Gu)return 2;if(e<Xu)return 3;if(e<Ba)return 4;if(e<Ia)return 5;if(e<Ta)return 6;if(e<La)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function _a(e,t,r=0){switch(Tr(e)){case 8:t[r++]=e&255|dt,e/=128;case 7:t[r++]=e&255|dt,e/=128;case 6:t[r++]=e&255|dt,e/=128;case 5:t[r++]=e&255|dt,e/=128;case 4:t[r++]=e&255|dt,e>>>=7;case 3:t[r++]=e&255|dt,e>>>=7;case 2:t[r++]=e&255|dt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Da(e,t){let r=e[t],n=0;if(n+=r&ee,r<dt||(r=e[t+1],n+=(r&ee)<<7,r<dt)||(r=e[t+2],n+=(r&ee)<<14,r<dt)||(r=e[t+3],n+=(r&ee)<<21,r<dt)||(r=e[t+4],n+=(r&ee)*Ba,r<dt)||(r=e[t+5],n+=(r&ee)*Ia,r<dt)||(r=e[t+6],n+=(r&ee)*Ta,r<dt)||(r=e[t+7],n+=(r&ee)*La,r<dt))return n;throw new RangeError("Could not decode varint")}var zo=new Float32Array([-0]),re=new Uint8Array(zo.buffer);function Ca(e,t,r){zo[0]=e,t[r]=re[0],t[r+1]=re[1],t[r+2]=re[2],t[r+3]=re[3]}function Ua(e,t){return re[0]=e[t],re[1]=e[t+1],re[2]=e[t+2],re[3]=e[t+3],zo[0]}var jo=new Float64Array([-0]),ct=new Uint8Array(jo.buffer);function Ra(e,t,r){jo[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 Ka(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],jo[0]}var Wu=BigInt(Number.MAX_SAFE_INTEGER),Ju=BigInt(Number.MIN_SAFE_INTEGER),gt=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 we;if(t<Wu&&t>Ju)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>Oa&&(o=0n,++n>Oa&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return we;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):we}},we=new gt(0,0);we.toBigInt=function(){return 0n};we.zzEncode=we.zzDecode=function(){return this};we.length=function(){return 1};var Oa=4294967296n;function Fa(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 ka(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 Zo(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 Tt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function bn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var $o=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=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,Tt(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 Tt(this,4);return bn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tt(this,4);return bn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tt(this,4);let t=Ua(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Tt(this,4);let t=Ka(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 Tt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return ka(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Tt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Tt(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 gt(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 Tt(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 Tt(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 Tt(this,8);let t=bn(this.buf,this.pos+=4),r=bn(this.buf,this.pos+=4);return new gt(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=Da(this.buf,this.pos);return this.pos+=Tr(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 Lr(e){return new $o(e instanceof Uint8Array?e:e.subarray())}function yn(e,t,r){let n=Lr(e);return t.decode(n,void 0,r)}function Ee(e=0){return new Uint8Array(e)}var Jo={};z(Jo,{base10:()=>sh});var Pp=new Uint8Array(0);function Pa(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Vt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Ma(e){return new TextEncoder().encode(e)}function Ha(e){return new TextDecoder().decode(e)}function Qu(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,f=e.charAt(0),c=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function h(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var x=0,p=0,b=0,E=l.length;b!==E&&l[b]===0;)b++,x++;for(var A=(E-b)*u+1>>>0,L=new Uint8Array(A);b!==E;){for(var T=l[b],R=0,C=A-1;(T!==0||R<p)&&C!==-1;C--,R++)T+=256*L[C]>>>0,L[C]=T%a>>>0,T=T/a>>>0;if(T!==0)throw new Error("Non-zero carry");p=R,b++}for(var I=A-p;I!==A&&L[I]===0;)I++;for(var O=f.repeat(x);I<A;++I)O+=e.charAt(L[I]);return O}function y(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;var x=0;if(l[x]!==" "){for(var p=0,b=0;l[x]===f;)p++,x++;for(var E=(l.length-x)*c+1>>>0,A=new Uint8Array(E);l[x];){var L=r[l.charCodeAt(x)];if(L===255)return;for(var T=0,R=E-1;(L!==0||T<b)&&R!==-1;R--,T++)L+=a*A[R]>>>0,A[R]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");b=T,x++}if(l[x]!==" "){for(var C=E-b;C!==E&&A[C]===0;)C++;for(var I=new Uint8Array(p+(E-C)),O=p;C!==E;)I[O++]=A[C++];return I}}}function m(l){var x=y(l);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:y,decode:m}}var th=Qu,eh=th,Va=eh;var Yo=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")}},Go=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 za(this,t)}},Xo=class{decoders;constructor(t){this.decoders=t}or(t){return za(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 za(e,t){return new Xo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Wo=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 Yo(t,r,n),this.decoder=new Go(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ge({name:e,prefix:t,encode:r,decode:n}){return new Wo(e,t,r,n)}function ne({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Va(r,e);return Ge({prefix:t,name:e,encode:n,decode:s=>Vt(o(s))})}function rh(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,f=0;for(let c=0;c<o;++c){let u=t[e[c]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,i+=r,i>=8&&(i-=8,s[f++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function nh(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let f=0;f<e.length;++f)for(a=a<<8|e[f],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 oh(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function W({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=oh(n);return Ge({prefix:t,name:e,encode(s){return nh(s,n,r)},decode(s){return rh(s,o,r,e)}})}var sh=ne({prefix:"9",name:"base10",alphabet:"0123456789"});var Qo={};z(Qo,{base16:()=>ih,base16upper:()=>ah});var ih=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ah=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ts={};z(ts,{base2:()=>ch});var ch=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var es={};z(es,{base256emoji:()=>lh});var ja=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}"),fh=ja.reduce((e,t,r)=>(e[r]=t,e),[]),uh=ja.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function hh(e){return e.reduce((t,r)=>(t+=fh[r],t),"")}function dh(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=uh[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var lh=Ge({prefix:"\u{1F680}",name:"base256emoji",encode:hh,decode:dh});var rs={};z(rs,{base32:()=>Xe,base32hex:()=>yh,base32hexpad:()=>gh,base32hexpadupper:()=>wh,base32hexupper:()=>xh,base32pad:()=>mh,base32padupper:()=>bh,base32upper:()=>ph,base32z:()=>Eh});var Xe=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ph=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),mh=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),bh=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),yh=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),xh=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),gh=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),wh=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Eh=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ns={};z(ns,{base36:()=>_r,base36upper:()=>Sh});var _r=ne({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Sh=ne({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var os={};z(os,{base58btc:()=>Rt,base58flickr:()=>Ah});var Rt=ne({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ah=ne({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ss={};z(ss,{base64:()=>vh,base64pad:()=>Bh,base64url:()=>Ih,base64urlpad:()=>Th});var vh=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Bh=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ih=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Th=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var is={};z(is,{base8:()=>Lh});var Lh=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var as={};z(as,{identity:()=>_h});var _h=Ge({prefix:"\0",name:"identity",encode:e=>Ha(e),decode:e=>Ma(e)});var em=new TextEncoder,rm=new TextDecoder;var fs={};z(fs,{identity:()=>Jh});var Uh=Ya,Za=128,Rh=127,Kh=~Rh,Oh=Math.pow(2,31);function Ya(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Oh;)t[r++]=e&255|Za,e/=128;for(;e&Kh;)t[r++]=e&255|Za,e>>>=7;return t[r]=e|0,Ya.bytes=r-n+1,t}var Fh=cs,kh=128,$a=127;function cs(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw cs.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&$a)<<o:(i&$a)*Math.pow(2,o),o+=7}while(i>=kh);return cs.bytes=s-n,r}var Nh=Math.pow(2,7),Ph=Math.pow(2,14),Mh=Math.pow(2,21),Hh=Math.pow(2,28),qh=Math.pow(2,35),Vh=Math.pow(2,42),zh=Math.pow(2,49),jh=Math.pow(2,56),Zh=Math.pow(2,63),$h=function(e){return e<Nh?1:e<Ph?2:e<Mh?3:e<Hh?4:e<qh?5:e<Vh?6:e<zh?7:e<jh?8:e<Zh?9:10},Yh={encode:Uh,decode:Fh,encodingLength:$h},Gh=Yh,Dr=Gh;function Cr(e,t=0){return[Dr.decode(e,t),Dr.decode.bytes]}function We(e,t,r=0){return Dr.encode(e,t,r),t}function Je(e){return Dr.encodingLength(e)}function tr(e,t){let r=t.byteLength,n=Je(e),o=n+Je(r),s=new Uint8Array(o+r);return We(e,s,0),We(r,s,n),s.set(t,o),new Qe(e,r,t,s)}function Ga(e){let t=Vt(e),[r,n]=Cr(t),[o,s]=Cr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Qe(r,o,i,t)}function Xa(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Pa(e.bytes,r.bytes)}}var Qe=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};var Wa=0,Xh="identity",Ja=Vt;function Wh(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 tr(Wa,Ja(e))}var Jh={code:Wa,name:Xh,encode:Ja,digest:Wh};var ds={};z(ds,{sha256:()=>td,sha512:()=>ed});var Qh=20;function hs({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new us(e,t,r,n,o)}var us=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Qh,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?Qa(n,this.code,r?.truncate):n.then(o=>Qa(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Qa(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 tr(t,e)}function ec(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var td=hs({name:"sha2-256",code:18,encode:ec("SHA-256")}),ed=hs({name:"sha2-512",code:19,encode:ec("SHA-512")});function rc(e,t){let{bytes:r,version:n}=e;return n===0?nd(r,ls(e),t??Rt.encoder):od(r,ls(e),t??Xe.encoder)}var nc=new WeakMap;function ls(e){let t=nc.get(e);if(t==null){let r=new Map;return nc.set(e,r),r}return t}var gn=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}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!==Rr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==sd)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=tr(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&&Xa(t.multihash,n.multihash)}toString(t){return rc(this,t)}toJSON(){return{"/":rc(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??oc(n,o,s.bytes))}else if(r[id]===!0){let{version:n,multihash:o,code:s}=r,i=Ga(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!==Rr)throw new Error(`Version 0 CID must use dag-pb (code: ${Rr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=oc(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Rr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Vt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Qe(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[h,y]=Cr(t.subarray(r));return r+=y,h},o=n(),s=Rr;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(),f=n(),c=r+f,u=c-i;return{version:o,codec:s,multihashCode:a,digestSize:f,multihashSize:u,size:c}}static parse(t,r){let[n,o]=rd(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 ls(s).set(n,t),s}};function rd(e,t){switch(e[0]){case"Q":{let r=t??Rt;return[Rt.prefix,r.decode(`${Rt.prefix}${e}`)]}case Rt.prefix:{let r=t??Rt;return[Rt.prefix,r.decode(e)]}case Xe.prefix:{let r=t??Xe;return[Xe.prefix,r.decode(e)]}case _r.prefix:{let r=t??_r;return[_r.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 nd(e,t,r){let{prefix:n}=r;if(n!==Rt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function od(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 Rr=112,sd=18;function oc(e,t,r){let n=Je(e),o=n+Je(t),s=new Uint8Array(o+r.byteLength);return We(e,s,0),We(t,s,n),s.set(r,o),s}var id=Symbol.for("@ipld/js-cid/CID");var ps={...as,...ts,...is,...Jo,...Qo,...rs,...ns,...os,...ss,...es},vm={...ds,...fs};function ic(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var sc=ic("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),ms=ic("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=Ee(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),ad={utf8:sc,"utf-8":sc,hex:ps.base16,latin1:ms,ascii:ms,binary:ms,...ps},ac=ad;function cc(e,t="utf8"){let r=ac[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function bs(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return Ee(i);o+i>t&&(n=Ee(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Se=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function ys(){}var gs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},cd=bs();function fd(e){return globalThis.Buffer!=null?Ee(e):cd(e)}var Or=class{len;head;tail;states;constructor(){this.len=0,this.head=new Se(ys,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Se(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ws((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(wn,10,gt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=gt.fromBigInt(t);return this._push(wn,r.length(),r)}uint64Number(t){return this._push(_a,Tr(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=gt.fromBigInt(t).zzEncode();return this._push(wn,r.length(),r)}sint64Number(t){let r=gt.fromNumber(t).zzEncode();return this._push(wn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(xs,1,t?1:0)}fixed32(t){return this._push(Kr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=gt.fromBigInt(t);return this._push(Kr,4,r.lo)._push(Kr,4,r.hi)}fixed64Number(t){let r=gt.fromNumber(t);return this._push(Kr,4,r.lo)._push(Kr,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(Ca,4,t)}double(t){return this._push(Ra,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(xs,1,0):this.uint32(r)._push(hd,r,t)}string(t){let r=Fa(t);return r!==0?this.uint32(r)._push(Zo,r,t):this._push(xs,1,0)}fork(){return this.states=new gs(this),this.head=this.tail=new Se(ys,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 Se(ys,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=fd(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function xs(e,t,r){t[r]=e&255}function ud(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var ws=class extends Se{next;constructor(t,r){super(ud,t,r),this.next=void 0}};function wn(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 Kr(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 hd(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Or.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(dd,t,e),this},Or.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(ld,t,e),this});function dd(e,t,r){t.set(e,r)}function ld(e,t,r){e.length<40?Zo(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(cc(e),r)}function Es(){return new Or}function En(e,t){let r=Es();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Sn(e,t,r){let n=Lr(e);yield*t.stream(n,void 0,"$",r)}var An={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function vn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function Ss(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,a){let f=t(i);a.int32(f)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return vn("enum",An.VARINT,r,n,o)}function Bn(e,t,r){return vn("message",An.LENGTH_DELIMITED,e,t,r)}var j;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(j||(j={}));var As;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(As||(As={}));(function(e){e.codec=()=>Ss(As)})(j||(j={}));var Kt;(function(e){let t;e.codec=()=>(t==null&&(t=Bn((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),j.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let f={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{f.Type=j.codec().decode(s);break}case 2:{f.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return f},function*(s,i,a,f={}){let c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:j.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return En(s,e.codec())}e.encode=r;function n(s,i){return yn(s,e.codec(),i)}e.decode=n;function o(s,i){return Sn(s,e.codec(),i)}e.stream=o})(Kt||(Kt={}));var Fr;(function(e){let t;e.codec=()=>(t==null&&(t=Bn((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),j.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let f={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{f.Type=j.codec().decode(s);break}case 2:{f.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return f},function*(s,i,a,f={}){let c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:j.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return En(s,e.codec())}e.encode=r;function n(s,i){return yn(s,e.codec(),i)}e.decode=n;function o(s,i){return Sn(s,e.codec(),i)}e.stream=o})(Fr||(Fr={}));function vs(e){if(isNaN(e)||e<=0)throw new k("random bytes length must be a Number bigger than 0");return tn(e)}var Nr={};z(Nr,{MAX_RSA_KEY_SIZE:()=>Bs,generateRSAKeyPair:()=>Us,jwkToJWKKeyPair:()=>dc,jwkToPkcs1:()=>yd,jwkToPkix:()=>_s,jwkToRSAPrivateKey:()=>Ln,pkcs1MessageToJwk:()=>Ts,pkcs1MessageToRSAPrivateKey:()=>In,pkcs1ToJwk:()=>bd,pkcs1ToRSAPrivateKey:()=>Ds,pkixMessageToJwk:()=>Ls,pkixMessageToRSAPublicKey:()=>Tn,pkixToJwk:()=>xd,pkixToRSAPublicKey:()=>Cs});var er=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Nr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return wt.createV1(114,this._multihash)}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,r,n){return hc(this.jwk,r,t,n)}},kr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Nr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}sign(t,r){return uc(this.jwk,t,r)}};var Bs=8192,Is=18,pd=1062,md=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function bd(e){let t=yt(e);return Ts(t)}function Ts(e){return{n:H(e[1],"base64url"),e:H(e[2],"base64url"),d:H(e[3],"base64url"),p:H(e[4],"base64url"),q:H(e[5],"base64url"),dp:H(e[6],"base64url"),dq:H(e[7],"base64url"),qi:H(e[8],"base64url"),kty:"RSA"}}function yd(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 k("JWK was missing components");return St([ht(Uint8Array.from([0])),ht(Y(e.n,"base64url")),ht(Y(e.e,"base64url")),ht(Y(e.d,"base64url")),ht(Y(e.p,"base64url")),ht(Y(e.q,"base64url")),ht(Y(e.dp,"base64url")),ht(Y(e.dq,"base64url")),ht(Y(e.qi,"base64url"))]).subarray()}function xd(e){let t=yt(e,{offset:0});return Ls(t)}function Ls(e){let t=yt(e[1],{offset:0});return{kty:"RSA",n:H(t[0],"base64url"),e:H(t[1],"base64url")}}function _s(e){if(e.n==null||e.e==null)throw new k("JWK was missing components");return St([md,pr(St([ht(Y(e.n,"base64url")),ht(Y(e.e,"base64url"))]))]).subarray()}function Ds(e){let t=yt(e);return In(t)}function In(e){let t=Ts(e);return Ln(t)}function Cs(e,t){if(e.byteLength>=pd)throw new ve("Key size is too large");let r=yt(e,{offset:0});return Tn(r,e,t)}function Tn(e,t,r){let n=Ls(e);if(r==null){let o=Gt(Kt.encode({Type:j.RSA,Data:t}));r=Dt(Is,o)}return new er(n,r)}function Ln(e){if(pc(e)>Bs)throw new k("Key size is too large");let t=dc(e),r=Gt(Kt.encode({Type:j.RSA,Data:_s(t.publicKey)})),n=Dt(Is,r);return new kr(t.privateKey,new er(t.publicKey,n))}async function Us(e){if(e>Bs)throw new k("Key size is too large");let t=await lc(e),r=Gt(Kt.encode({Type:j.RSA,Data:_s(t.publicKey)})),n=Dt(Is,r);return new kr(t.privateKey,new er(t.publicKey,n))}function dc(e){if(e==null)throw new k("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var mc="1.2.840.113549.1.1.1";async function lc(e,t){let r=await $.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 gd(r,t);return{privateKey:n[0],publicKey:n[1]}}async function uc(e,t,r){let n=await $.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await $.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,ft(t instanceof Uint8Array?t:t.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function hc(e,t,r,n){let o=await $.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await $.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,ft(t),ft(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function gd(e,t){if(e.privateKey==null||e.publicKey==null)throw new k("Private and public key are required");let r=await Promise.all([$.get().subtle.exportKey("jwk",e.privateKey),$.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function pc(e){if(e.kty!=="RSA")throw new k("invalid key type");if(e.n==null)throw new k("invalid key modulus");return Y(e.n,"base64url").length*8}var _n=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(Re(t),mt(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),bt(o)}update(t){return Ke(this),this.iHash.update(t),this}digestInto(t){Ke(this),Wr(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Dn=(()=>{let e=((t,r,n)=>new _n(t,r).update(n).digest());return e.create=(t,r)=>new _n(t,r),e})();var bc=(e,t)=>(e+(e>=0?t:-t)/yc)/t;function wd(e,t,r){Pe("scalar",e,Ot,r);let[[n,o],[s,i]]=t,a=bc(i*e,r),f=bc(-o*e,r),c=e-a*n-f*s,u=-a*o-f*i,h=c<Ot,y=u<Ot;h&&(c=-c),y&&(u=-u);let m=Sr(Math.ceil(Me(r)/2))+oe;if(c<Ot||c>=m||u<Ot||u>=m)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:c,k2neg:y,k2:u}}function Ks(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Rs(e,t){It(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return vt(r.lowS,"lowS"),vt(r.prehash,"prehash"),r.format!==void 0&&Ks(r.format),r}var Os=class extends Error{constructor(t=""){super(t)}},Lt={Err:Os,_tlv:{encode:(e,t)=>{let{Err:r}=Lt;if(Bt(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=wr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?wr(o.length/2|128):"";return wr(e)+s+o+t},decode(e,t){let{Err:r}=Lt;t=M(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let f=o&127;if(!f)throw new r("tlv.decode(long): indefinite length not supported");if(f>4)throw new r("tlv.decode(long): byte length is too big");let c=t.subarray(n,n+f);if(c.length!==f)throw new r("tlv.decode: length bytes not complete");if(c[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of c)i=i<<8|u;if(n+=f,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}=Lt;if(an(e),e<Ot)throw new t("integer: negative integers are not allowed");let r=wr(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}=Lt;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 pe(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Lt,o=M(e,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:f}=n.decode(2,s),{v:c,l:u}=n.decode(2,f);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(c)}},hexFromSig(e){let{_tlv:t,_int:r}=Lt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}};Object.freeze(Lt._tlv);Object.freeze(Lt._int);Object.freeze(Lt);var Ot=BigInt(0),oe=BigInt(1),yc=BigInt(2),Cn=BigInt(3),Ed=BigInt(4);function xc(e,t={}){let r=hn("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;It(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:f,allowInfinityPoint:c}=t;if(f&&(!n.is0(s.a)||typeof f.beta!="bigint"||!Array.isArray(f.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=wc(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function y(F,d,g){if(c&&d.is0())return Uint8Array.of(0);let{x:v,y:S}=d.toAffine(),w=n.toBytes(v);if(vt(g,"isCompressed"),g){h();let B=!n.isOdd(S);return et(gc(B),w)}else return et(Uint8Array.of(4),w,n.toBytes(S))}function m(F){M(F,void 0,"Point");let{publicKey:d,publicKeyUncompressed:g}=u,v=F.length,S=F[0],w=F.subarray(1);if(c&&v===1&&S===0)return{x:n.ZERO,y:n.ZERO};if(v===d&&(S===2||S===3)){let B=n.fromBytes(w);if(!n.isValid(B))throw new Error("bad point: is not on curve, wrong x");let D=p(B),_;try{_=n.sqrt(D)}catch(P){let q=P instanceof Error?": "+P.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}h();let U=n.isOdd(_);return(S&1)===1!==U&&(_=n.neg(_)),{x:B,y:_}}else if(v===g&&S===4){let B=n.BYTES,D=n.fromBytes(w.subarray(0,B)),_=n.fromBytes(w.subarray(B,B*2));if(!b(D,_))throw new Error("bad point: is not on curve");return{x:D,y:_}}else throw new Error(`bad point: got length ${v}, expected compressed=${d} or uncompressed=${g}`)}let l=t.toBytes===void 0?y:t.toBytes,x=t.fromBytes===void 0?m:t.fromBytes;function p(F){let d=n.sqr(F),g=n.mul(d,F);return n.add(n.add(g,n.mul(F,s.a)),s.b)}function b(F,d){let g=n.sqr(d),v=p(F);return n.eql(g,v)}if(!b(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let E=n.mul(n.pow(s.a,Cn),Ed),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(E,A)))throw new Error("bad curve params: a or b");function L(F,d,g=!1){if(!n.isValid(d)||g&&n.is0(d))throw new Error(`bad point coordinate ${F}`);return d}function T(F){if(!(F instanceof I))throw new Error("Weierstrass Point expected")}function R(F){if(!f||!f.basises)throw new Error("no endo");return wd(F,f.basises,o.ORDER)}function C(F,d,g,v,S){return g=new I(n.mul(g.X,F),g.Y,g.Z),d=vr(v,d),g=vr(S,g),d.add(g)}class I{static BASE=new I(s.Gx,s.Gy,n.ONE);static ZERO=new I(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(d,g,v){this.X=L("x",d),this.Y=L("y",g,!0),this.Z=L("z",v),Object.freeze(this)}static CURVE(){return s}static fromAffine(d){let{x:g,y:v}=d||{};if(!d||!n.isValid(g)||!n.isValid(v))throw new Error("invalid affine point");if(d instanceof I)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(v)?I.ZERO:new I(g,v,n.ONE)}static fromBytes(d){let g=I.fromAffine(x(M(d,void 0,"point")));return g.assertValidity(),g}static fromHex(d){return I.fromBytes(Ne(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,g=!0){return V.createCache(this,d),g||this.multiply(Cn),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")}let{x:g,y:v}=d.toAffine();if(!n.isValid(g)||!n.isValid(v))throw new Error("bad point: x or y not field elements");if(!b(g,v))throw new Error("bad point: equation left != right");if(!d.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:d}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(d)}equals(d){T(d);let{X:g,Y:v,Z:S}=this,{X:w,Y:B,Z:D}=d,_=n.eql(n.mul(g,D),n.mul(w,S)),U=n.eql(n.mul(v,D),n.mul(B,S));return _&&U}negate(){return new I(this.X,n.neg(this.Y),this.Z)}double(){let{a:d,b:g}=s,v=n.mul(g,Cn),{X:S,Y:w,Z:B}=this,D=n.ZERO,_=n.ZERO,U=n.ZERO,K=n.mul(S,S),P=n.mul(w,w),q=n.mul(B,B),N=n.mul(S,w);return N=n.add(N,N),U=n.mul(S,B),U=n.add(U,U),D=n.mul(d,U),_=n.mul(v,q),_=n.add(D,_),D=n.sub(P,_),_=n.add(P,_),_=n.mul(D,_),D=n.mul(N,D),U=n.mul(v,U),q=n.mul(d,q),N=n.sub(K,q),N=n.mul(d,N),N=n.add(N,U),U=n.add(K,K),K=n.add(U,K),K=n.add(K,q),K=n.mul(K,N),_=n.add(_,K),q=n.mul(w,B),q=n.add(q,q),K=n.mul(q,N),D=n.sub(D,K),U=n.mul(q,P),U=n.add(U,U),U=n.add(U,U),new I(D,_,U)}add(d){T(d);let{X:g,Y:v,Z:S}=this,{X:w,Y:B,Z:D}=d,_=n.ZERO,U=n.ZERO,K=n.ZERO,P=s.a,q=n.mul(s.b,Cn),N=n.mul(g,w),tt=n.mul(v,B),rt=n.mul(S,D),nt=n.add(g,v),J=n.add(w,B);nt=n.mul(nt,J),J=n.add(N,tt),nt=n.sub(nt,J),J=n.add(g,S);let lt=n.add(w,D);return J=n.mul(J,lt),lt=n.add(N,rt),J=n.sub(J,lt),lt=n.add(v,S),_=n.add(B,D),lt=n.mul(lt,_),_=n.add(tt,rt),lt=n.sub(lt,_),K=n.mul(P,J),_=n.mul(q,rt),K=n.add(_,K),_=n.sub(tt,K),K=n.add(tt,K),U=n.mul(_,K),tt=n.add(N,N),tt=n.add(tt,N),rt=n.mul(P,rt),J=n.mul(q,J),tt=n.add(tt,rt),rt=n.sub(N,rt),rt=n.mul(P,rt),J=n.add(J,rt),N=n.mul(tt,J),U=n.add(U,N),N=n.mul(lt,J),_=n.mul(nt,_),_=n.sub(_,N),N=n.mul(nt,tt),K=n.mul(lt,K),K=n.add(K,N),new I(_,U,K)}subtract(d){return T(d),this.add(d.negate())}is0(){return this.equals(I.ZERO)}multiply(d){let{endo:g}=t;if(!o.isValidNot0(d))throw new RangeError("invalid scalar: out of range");let v,S,w=B=>V.cached(this,B,D=>ye(I,D));if(g){let{k1neg:B,k1:D,k2neg:_,k2:U}=R(d),{p:K,f:P}=w(D),{p:q,f:N}=w(U);S=P.add(N),v=C(g.beta,K,q,B,_)}else{let{p:B,f:D}=w(d);v=B,S=D}return ye(I,[v,S])[0]}multiplyUnsafe(d){let{endo:g}=t,v=this,S=d;if(!o.isValid(S))throw new RangeError("invalid scalar: out of range");if(S===Ot||v.is0())return I.ZERO;if(S===oe)return v;if(V.hasCache(this))return this.multiply(S);if(g){let{k1neg:w,k1:B,k2neg:D,k2:_}=R(S),{p1:U,p2:K}=aa(I,v,B,_);return C(g.beta,U,K,w,D)}else return V.unsafe(v,S)}toAffine(d){let g=this,v=d,{X:S,Y:w,Z:B}=g;if(n.eql(B,n.ONE))return{x:S,y:w};let D=g.is0();v==null&&(v=D?n.ONE:n.inv(B));let _=n.mul(S,v),U=n.mul(w,v),K=n.mul(B,v);if(D)return{x:n.ZERO,y:n.ZERO};if(!n.eql(K,n.ONE))throw new Error("invZ was invalid");return{x:_,y:U}}isTorsionFree(){let{isTorsionFree:d}=t;return i===oe?!0:d?d(I,this):V.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:d}=t;return i===oe?this:d?d(I,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===oe?this.is0():this.clearCofactor().is0()}toBytes(d=!0){return vt(d,"isCompressed"),this.assertValidity(),l(I,this,d)}toHex(d=!0){return ke(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let O=o.BITS,V=new Ve(I,t.endo?Math.ceil(O/2):O);return O>=8&&I.BASE.precompute(8),Object.freeze(I.prototype),Object.freeze(I),I}function gc(e){return Uint8Array.of(e?2:3)}function wc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Sd(e,t={}){let{Fn:r}=e,n=t.randomBytes===void 0?gr:t.randomBytes,o=Object.assign(wc(e.Fp,r),{seed:Math.max(Do(r.ORDER),16)});function s(m){try{let l=r.fromBytes(m);return r.isValidNot0(l)}catch{return!1}}function i(m,l){let{publicKey:x,publicKeyUncompressed:p}=o;try{let b=m.length;return l===!0&&b!==x||l===!1&&b!==p?!1:!!e.fromBytes(m)}catch{return!1}}function a(m){return m=m===void 0?n(o.seed):m,Co(M(m,o.seed,"seed"),r.ORDER)}function f(m,l=!0){return e.BASE.multiply(r.fromBytes(m)).toBytes(l)}function c(m){let{secretKey:l,publicKey:x,publicKeyUncompressed:p}=o,b=r._lengths;if(!le(m))return;let E=M(m,void 0,"key").length,A=E===x||E===p,L=E===l||!!b?.includes(E);if(!(A&&L))return A}function u(m,l,x=!0){if(c(m)===!0)throw new Error("first arg must be private key");if(c(l)===!1)throw new Error("second arg must be public key");let p=r.fromBytes(m);return e.fromBytes(l).multiply(p).toBytes(x)}let h={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},y=dn(a,f);return Object.freeze(h),Object.freeze(o),Object.freeze({getPublicKey:f,getSharedSecret:u,keygen:y,Point:e,utils:h,lengths:o})}function Ec(e,t,r={}){let n=t;Re(n),It(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?gr:r.randomBytes,s=r.hmac===void 0?(S,w)=>Dn(n,S,w):r.hmac,{Fp:i,Fn:a}=e,{ORDER:f,BITS:c}=a,{keygen:u,getPublicKey:h,getSharedSecret:y,utils:m,lengths:l}=Sd(e,r),x={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},p=f*yc+oe<i.ORDER;function b(S){let w=f>>oe;return S>w}function E(S,w){if(!a.isValidNot0(w))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return w}function A(){if(p)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function L(S,w){Ks(w);let B=l.signature,D=w==="compact"?B:w==="recovered"?B+1:void 0;return M(S,D)}class T{r;s;recovery;constructor(w,B,D){if(this.r=E("r",w),this.s=E("s",B),D!=null){if(A(),![0,1,2,3].includes(D))throw new Error("invalid recovery id");this.recovery=D}Object.freeze(this)}static fromBytes(w,B=x.format){L(w,B);let D;if(B==="der"){let{r:P,s:q}=Lt.toSig(M(w));return new T(P,q)}B==="recovered"&&(D=w[0],B="compact",w=w.subarray(1));let _=l.signature/2,U=w.subarray(0,_),K=w.subarray(_,_*2);return new T(a.fromBytes(U),a.fromBytes(K),D)}static fromHex(w,B){return this.fromBytes(Ne(w),B)}assertRecovery(){let{recovery:w}=this;if(w==null)throw new Error("invalid recovery id: must be present");return w}addRecoveryBit(w){return new T(this.r,this.s,w)}recoverPublicKey(w){let{r:B,s:D}=this,_=this.assertRecovery(),U=_===2||_===3?B+f:B;if(!i.isValid(U))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let K=i.toBytes(U),P=e.fromBytes(et(gc((_&1)===0),K)),q=a.inv(U),N=C(M(w,void 0,"msgHash")),tt=a.create(-N*q),rt=a.create(D*q),nt=e.BASE.multiplyUnsafe(tt).add(P.multiplyUnsafe(rt));if(nt.is0())throw new Error("invalid recovery: point at infinify");return nt.assertValidity(),nt}hasHighS(){return b(this.s)}toBytes(w=x.format){if(Ks(w),w==="der")return Ne(Lt.hexFromSig(this));let{r:B,s:D}=this,_=a.toBytes(B),U=a.toBytes(D);return w==="recovered"?(A(),et(Uint8Array.of(this.assertRecovery()),_,U)):et(_,U)}toHex(w){return ke(this.toBytes(w))}}Object.freeze(T.prototype),Object.freeze(T);let R=r.bits2int===void 0?function(w){if(w.length>8192)throw new Error("input is too large");let B=pe(w),D=w.length*8-c;return D>0?B>>BigInt(D):B}:r.bits2int,C=r.bits2int_modN===void 0?function(w){return a.create(R(w))}:r.bits2int_modN,I=Sr(c);function O(S){return Pe("num < 2^"+c,S,Ot,I),a.toBytes(S)}function V(S,w){return M(S,void 0,"message"),w?M(n(S),void 0,"prehashed message"):S}function F(S,w,B){let{lowS:D,prehash:_,extraEntropy:U}=Rs(B,x);S=V(S,_);let K=C(S),P=a.fromBytes(w);if(!a.isValidNot0(P))throw new Error("invalid private key");let q=[O(P),O(K)];if(U!=null&&U!==!1){let nt=U===!0?o(l.secretKey):U;q.push(M(nt,void 0,"extraEntropy"))}let N=et(...q),tt=K;function rt(nt){let J=R(nt);if(!a.isValidNot0(J))return;let lt=a.inv(J),Ae=e.BASE.multiply(J).toAffine(),rr=a.create(Ae.x);if(rr===Ot)return;let qr=a.create(lt*a.create(tt+rr*P));if(qr===Ot)return;let Vs=(Ae.x===rr?0:2)|Number(Ae.y&oe),zs=qr;return D&&b(qr)&&(zs=a.neg(qr),Vs^=1),new T(rr,zs,p?void 0:Vs)}return{seed:N,k2sig:rt}}function d(S,w,B={}){let{seed:D,k2sig:_}=F(S,w,B);return zi(n.outputLen,a.BYTES,s)(D,_).toBytes(B.format)}function g(S,w,B,D={}){let{lowS:_,prehash:U,format:K}=Rs(D,x);if(B=M(B,void 0,"publicKey"),w=V(w,U),!le(S)){let P=S instanceof T?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+P)}L(S,K);try{let P=T.fromBytes(S,K),q=e.fromBytes(B);if(_&&P.hasHighS())return!1;let{r:N,s:tt}=P,rt=C(w),nt=a.inv(tt),J=a.create(rt*nt),lt=a.create(N*nt),Ae=e.BASE.multiplyUnsafe(J).add(q.multiplyUnsafe(lt));return Ae.is0()?!1:a.create(Ae.x)===N}catch{return!1}}function v(S,w,B={}){let{prehash:D}=Rs(B,x);return w=V(w,D),T.fromBytes(S,"recovered").recoverPublicKey(w).toBytes()}return Object.freeze({keygen:u,getPublicKey:h,getSharedSecret:y,utils:m,lengths:l,Point:e,sign:d,verify:g,recoverPublicKey:v,Signature:T,hash:n})}var ks={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ad={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Sc=BigInt(2);function vd(e){let t=ks.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),f=BigInt(88),c=e*e*e%t,u=c*c*e%t,h=Z(u,r,t)*u%t,y=Z(h,r,t)*u%t,m=Z(y,Sc,t)*c%t,l=Z(m,o,t)*m%t,x=Z(l,s,t)*l%t,p=Z(x,a,t)*x%t,b=Z(p,f,t)*p%t,E=Z(b,a,t)*x%t,A=Z(E,r,t)*u%t,L=Z(A,i,t)*l%t,T=Z(L,n,t)*c%t,R=Z(T,Sc,t);if(!Fs.eql(Fs.sqr(R),e))throw new Error("Cannot find square root");return R}var Fs=He(ks.p,{sqrt:vd}),Bd=xc(ks,{Fp:Fs,endo:Ad}),_t=Ec(Bd,Gt);var Ac=33,vc=32;function Bc(e,t,r){let n=$r.digest(t instanceof Uint8Array?t:t.subarray());if($e(n))return n.then(({digest:o})=>(r?.signal?.throwIfAborted(),_t.sign(o,e,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new nr(String(o))});try{return _t.sign(n.digest,e,{prehash:!1,format:"der"})}catch(o){throw new nr(String(o))}}function Ic(e,t,r,n){let o=$r.digest(r instanceof Uint8Array?r:r.subarray());if($e(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),_t.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new or(String(s))});try{return n?.signal?.throwIfAborted(),_t.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new or(String(s))}}var Pr=class{type="secp256k1";raw;_key;constructor(t){this._key=_c(t),this.raw=Tc(this._key)}toMultihash(){return ae.digest(fe(this))}toCID(){return wt.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,r,n){return Ic(this._key,r,t,n)}},Mr=class{type="secp256k1";raw;publicKey;constructor(t,r){this.raw=Lc(t),this.publicKey=new Pr(r??Dc(t))}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}sign(t,r){return Bc(this.raw,t,r)}};function Ns(e){return new Mr(e)}function Un(e){return new Pr(e)}async function Cc(){let e=Id();return new Mr(e)}function Tc(e){return _t.Point.fromBytes(e).toBytes()}function Lc(e){try{return _t.getPublicKey(e,!0),e}catch(t){throw new sr(String(t))}}function _c(e){try{return _t.Point.fromBytes(e),e}catch(t){throw new ve(String(t))}}function Dc(e){try{return _t.getPublicKey(e,!0)}catch(t){throw new sr(String(t))}}function Id(){return _t.utils.randomSecretKey()}var Rn={"P-256":32,"P-384":48,"P-521":66},Td=Object.keys(Rn),Ps=Td.join(" / ");async function Uc(e){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new k(`Unknown curve: ${e}. Must be ${Ps}`);let t=await $.get().subtle.generateKey({name:"ECDH",namedCurve:e},!0,["deriveBits"]),r=async(s,i)=>{let a;i!=null?a=await $.get().subtle.importKey("jwk",_d(e,i),{name:"ECDH",namedCurve:e},!1,["deriveBits"]):a=t.privateKey;let f=await $.get().subtle.importKey("jwk",Rc(e,s),{name:"ECDH",namedCurve:e},!1,[]),c=await $.get().subtle.deriveBits({name:"ECDH",public:f},a,Rn[e]*8);return new Uint8Array(c,0,c.byteLength)},n=await $.get().subtle.exportKey("jwk",t.publicKey);return{key:Ld(n),genSharedKey:r}}function Ld(e){if(e.crv==null||e.x==null||e.y==null)throw new k("JWK was missing components");if(e.crv!=="P-256"&&e.crv!=="P-384"&&e.crv!=="P-521")throw new k(`Unknown curve: ${e.crv}. Must be ${Ps}`);let t=Rn[e.crv];return xe([Uint8Array.from([4]),qo(e.x,t),qo(e.y,t)],1+t*2)}function Rc(e,t){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new k(`Unknown curve: ${e}. Must be ${Ps}`);let r=Rn[e];if(!pt(t.subarray(0,1),Uint8Array.from([4])))throw new k("Cannot unmarshal public key - invalid key format");return{kty:"EC",crv:e,x:H(t.subarray(1,r+1),"base64url"),y:H(t.subarray(1+r),"base64url"),ext:!0}}var _d=(e,t)=>({...Rc(e,t.public),d:H(t.private,"base64url")});var Dd={"AES-128":{ivSize:16,keySize:16},"AES-256":{ivSize:16,keySize:32},Blowfish:{ivSize:8,keySize:32}};async function Kc(e,t,r){if(e!=="AES-128"&&e!=="AES-256"&&e!=="Blowfish")throw new k("Cipher type was missing or unsupported");if(t!=="SHA1"&&t!=="SHA256"&&t!=="SHA512")throw new k("Hash type was missing or unsupported");if(r==null||!(r instanceof Uint8Array))throw new k("Secret was missing or an incorrect type");let n=Dd[e],o=n.keySize,s=n.ivSize,i=20,a=Y("key expansion"),f=2*(s+o+i),c=await On(t,r),u=await c.digest(a),h=[],y=0;for(;y<f;){let E=await c.digest(xe([u,a])),A=E.length;y+A>f&&(A=f-y),h.push(E),y+=A,u=await c.digest(u)}let m=f/2,l=xe(h),x=l.subarray(0,m),p=l.subarray(m,f),b=E=>({iv:E.subarray(0,s),cipherKey:E.subarray(s,s+o),macKey:E.subarray(s+o)});return{k1:b(x),k2:b(p)}}async function Cd(e,t){if(e==="Ed25519")return Aa();if(e==="secp256k1")return Cc();if(e==="RSA")return Us(Pd(t));if(e==="ECDSA")return _i(Md(t));throw new zt}async function Ud(e,t){if(e!=="Ed25519")throw new zt("Seed key derivation only supported for Ed25519 keys");return va(t)}function Rd(e,t){let{Type:r,Data:n}=Kt.decode(e),o=n??new Uint8Array;switch(r){case j.RSA:return Cs(o,t);case j.Ed25519:return mn(o);case j.secp256k1:return Un(o);case j.ECDSA:return ho(o);default:throw new zt}}function Kd(e){if(e.byteLength===te)return mn(e);if(e.byteLength===Ac)return Un(e);let t=yt(e),r=t[1]?.[0];if(r===Zn||r===$n||r===Yn)return lo(t);if(t[0]?.[0]===mc)return Tn(t,e);throw new k("Could not extract public key from raw bytes")}function Od(e){let{Type:t,Data:r}=Kt.decode(e.digest),n=r??new Uint8Array;switch(t){case j.Ed25519:return mn(n);case j.secp256k1:return Un(n);case j.ECDSA:return ho(n);default:throw new zt}}function fe(e){return Kt.encode({Type:j[e.type],Data:e.raw})}function Fd(e){let t=Fr.decode(e),r=t.Data??new Uint8Array;switch(t.Type){case j.RSA:return Ds(r);case j.Ed25519:return Vo(r);case j.secp256k1:return Ns(r);case j.ECDSA:return Bi(r);default:throw new zt}}function kd(e){if(e.byteLength===xt)return Vo(e);if(e.byteLength===vc)return Ns(e);let t=yt(e),r=t[2]?.[0];if(r===Zn||r===$n||r===Yn)return uo(t);if(t.length>8)return In(t);throw new k("Could not extract private key from raw bytes")}function Nd(e){return Fr.encode({Type:j[e.type],Data:e.raw})}function Pd(e){return e==null?2048:parseInt(e,10)}function Md(e){if(e==="P-256"||e==null)return"P-256";if(e==="P-384")return"P-384";if(e==="P-521")return"P-521";throw new k("Unsupported curve, should be P-256, P-384 or P-521")}async function Hd(e){if(e.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(e.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"ECDSA",namedCurve:e.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"ECDSA",namedCurve:e.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new k("Only RSA and ECDSA keys are supported")}async function qd(e){if(e.privateKey.algorithm.name==="RSASSA-PKCS1-v1_5"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return Ln(t)}if(e.privateKey.algorithm.name==="ECDSA"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return new Nt(t)}throw new k("Only RSA and ECDSA keys are supported")}var Hr=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),se=new Uint32Array(80),Hs=class extends ue{A=Hr[0]|0;B=Hr[1]|0;C=Hr[2]|0;D=Hr[3]|0;E=Hr[4]|0;constructor(){super(64,20,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s}=this;return[t,r,n,o,s]}set(t,r,n,o,s){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0}process(t,r){for(let f=0;f<16;f++,r+=4)se[f]=t.getUint32(r,!1);for(let f=16;f<80;f++)se[f]=Jr(se[f-3]^se[f-8]^se[f-14]^se[f-16],1);let{A:n,B:o,C:s,D:i,E:a}=this;for(let f=0;f<80;f++){let c,u;f<20?(c=en(o,s,i),u=1518500249):f<40?(c=o^s^i,u=1859775393):f<60?(c=rn(o,s,i),u=2400959708):(c=o^s^i,u=3395469782);let h=Jr(n,5)+c+a+u+se[f]|0;a=i,i=s,s=Jr(o,30),o=n,n=h}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,this.set(n,o,s,i,a)}roundClean(){bt(se)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0),bt(this.buffer)}},Oc=br(()=>new Hs);function Vd(e,t,r,n){Re(e);let o=Ui({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:a}=o;if(Et(s,"c"),Et(i,"dkLen"),Et(a,"asyncTick"),s<1)throw new Error("iterations (c) must be >= 1");if(i<1)throw new Error('"dkLen" must be >= 1');if(i>(2**32-1)*e.outputLen)throw new Error("derived key too long");let f=mo(t,"password"),c=mo(r,"salt"),u=new Uint8Array(i),h=Dn.create(e,f),y=h._cloneInto().update(c);return{c:s,dkLen:i,asyncTick:a,DK:u,PRF:h,PRFSalt:y}}function zd(e,t,r,n,o){return e.destroy(),t.destroy(),n&&n.destroy(),bt(o),r}function Fc(e,t,r,n){let{c:o,dkLen:s,DK:i,PRF:a,PRFSalt:f}=Vd(e,t,r,n),c,u=new Uint8Array(4),h=Oe(u),y=new Uint8Array(a.outputLen);for(let m=1,l=0;l<s;m++,l+=a.outputLen){let x=i.subarray(l,l+a.outputLen);h.setInt32(0,m,!1),(c=f._cloneInto(c)).update(u).digestInto(y),x.set(y.subarray(0,x.length));for(let p=1;p<o;p++){a._cloneInto(c).update(y).digestInto(y);for(let b=0;b<x.length;b++)x[b]^=y[b]}}return zd(a,f,i,c,y)}var kc={sha1:Oc,"sha2-256":Gt,"sha2-512":Fe};function qs(e,t,r,n,o){if(o!=="sha1"&&o!=="sha2-256"&&o!=="sha2-512"){let a=Object.keys(kc).join(" / ");throw new k(`Hash '${o}' is unknown or not supported. Must be ${a}`)}let s=kc[o],i=Fc(s,e,t,{c:r,dkLen:n});return to.encode(i).substring(1)}return qc(jd);})();
2
+ "use strict";var Libp2PCrypto=(()=>{var pn=Object.defineProperty;var _a=Object.getOwnPropertyDescriptor;var Ia=Object.getOwnPropertyNames;var Ta=Object.prototype.hasOwnProperty;var at=(e,t)=>{for(var r in t)pn(e,r,{get:t[r],enumerable:!0})},La=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ia(t))!Ta.call(e,o)&&o!==r&&pn(e,o,{get:()=>t[o],enumerable:!(n=_a(t,o))||n.enumerable});return e};var Ra=e=>La(pn({},"__esModule",{value:!0}),e);var Bu={};at(Bu,{hmac:()=>Tr,keys:()=>Wo,pbkdf2:()=>Qo,randomBytes:()=>Fo});var Tr={};at(Tr,{create:()=>mn});function Da(e){return e.buffer instanceof ArrayBuffer}function ot(e){return Da(e)?e:e.slice()}var Ye=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},$e=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Ir=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Y={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Ir("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 rs={SHA1:20,SHA256:32,SHA512:64};var Ka={SHA1:"SHA-1",SHA256:"SHA-256",SHA512:"SHA-512"},Ca=async(e,t)=>{let r=await Y.get().subtle.sign({name:"HMAC"},e,ot(t));return new Uint8Array(r,0,r.byteLength)};async function mn(e,t){let r=Ka[e],n=await Y.get().subtle.importKey("raw",ot(t),{name:"HMAC",hash:{name:r}},!1,["sign"]);return{async digest(o){return Ca(n,o)},length:rs[e]}}var Wo={};at(Wo,{generateEphemeralKeyPair:()=>wa,generateKeyPair:()=>uu,generateKeyPairFromSeed:()=>lu,keyStretcher:()=>Sa,privateKeyFromCryptoKeyPair:()=>Eu,privateKeyFromProtobuf:()=>mu,privateKeyFromRaw:()=>yu,privateKeyToCryptoKeyPair:()=>wu,privateKeyToProtobuf:()=>bu,publicKeyFromMultihash:()=>pu,publicKeyFromProtobuf:()=>hu,publicKeyFromRaw:()=>du,publicKeyToProtobuf:()=>ae});var P=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},we=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},Ge=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var Vt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var wn={};at(wn,{base58btc:()=>rt,base58flickr:()=>Ma});var Fu=new Uint8Array(0);function os(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 wt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return oe(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return oe(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function ss(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var ns=4096;function is(e){let t=e.length;if(t<=ns)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=ns));return r}function Ua(e){return e?.buffer instanceof ArrayBuffer}function oe(e){return Ua(e)?e:e.slice()}function Fa(e,t,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<e.length;s++){var i=e.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,r){var f=i.toLowerCase().charCodeAt(0),c=i.toUpperCase().charCodeAt(0);f!==a&&(n[f]=s),c!==a&&(n[c]=s)}}var u=e.length,l=e.charAt(0),b=Math.log(u)/Math.log(256),p=Math.log(256)/Math.log(u);function S(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var w=0,v=0,K=0,L=d.length;K!==L&&d[K]===0;)K++,w++;for(var F=(L-K)*p+1>>>0,D=new Uint8Array(F);K!==L;){for(var _=d[K],O=0,k=F-1;(_!==0||O<v)&&k!==-1;k--,O++)_+=256*D[k]>>>0,D[k]=_%u>>>0,_=_/u>>>0;if(_!==0)throw new Error("Non-zero carry");v=O,K++}for(var U=F-v;U!==F&&D[U]===0;)U++;for(var h=l.repeat(w);U<F;++U)h+=e.charAt(D[U]);return h}function B(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var w=0;if(d[w]!==" "){for(var v=0,K=0;d[w]===l;)v++,w++;for(var L=(d.length-w)*b+1>>>0,F=new Uint8Array(L);d[w];){var D=n[d.charCodeAt(w)];if(D===255)return;for(var _=0,O=L-1;(D!==0||_<K)&&O!==-1;O--,_++)D+=u*F[O]>>>0,F[O]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");K=_,w++}if(d[w]!==" "){for(var k=L-K;k!==L&&F[k]===0;)k++;for(var U=new Uint8Array(v+(L-k)),h=v;k!==L;)U[h++]=F[k++];return U}}}function m(d){var w=B(d);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:S,decodeUnsafe:B,decode:m}}var Oa=Fa,ka=Oa,cs=ka;var yn=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")}},bn=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 fs(this,t)}},gn=class{decoders;constructor(t){this.decoders=t}or(t){return fs(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 fs(e,t){return new gn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var xn=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 yn(t,r,n),this.decoder=new bn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ee({name:e,prefix:t,encode:r,decode:n}){return new xn(e,t,r,n)}function jt({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=cs(r,e,n);return Ee({prefix:t,name:e,encode:o,decode:i=>wt(s(i))})}function Pa(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,f=0;for(let c=0;c<o;++c){let u=t[e[c]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,i+=r,i>=8&&(i-=8,s[f++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Na(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let f=0;f<e.length;++f)for(a=a<<8|e[f],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 Ha(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 $({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=Ha(n,o);return Ee({prefix:t,name:e,encode(i){return Na(i,n,r)},decode(i){return Pa(i,s,r,e)}})}var rt=jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ma=jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var En={};at(En,{base32:()=>Se,base32hex:()=>za,base32hexpad:()=>Ya,base32hexpadupper:()=>$a,base32hexupper:()=>Za,base32pad:()=>Va,base32padupper:()=>ja,base32upper:()=>qa,base32z:()=>Ga});var Se=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),qa=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Va=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),ja=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),za=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Za=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Ya=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),$a=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Ga=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Sn={};at(Sn,{base36:()=>Xe,base36upper:()=>Xa});var Xe=jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Xa=jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Wa=hs,us=128,Ja=127,Qa=~Ja,tc=Math.pow(2,31);function hs(e,t,r){t=t||[],r=r||0;for(var n=r;e>=tc;)t[r++]=e&255|us,e/=128;for(;e&Qa;)t[r++]=e&255|us,e>>>=7;return t[r]=e|0,hs.bytes=r-n+1,t}var ec=An,rc=128,ls=127;function An(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw An.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&ls)<<o:(i&ls)*Math.pow(2,o),o+=7}while(i>=rc);return An.bytes=s-n,r}var nc=Math.pow(2,7),oc=Math.pow(2,14),sc=Math.pow(2,21),ic=Math.pow(2,28),ac=Math.pow(2,35),cc=Math.pow(2,42),fc=Math.pow(2,49),uc=Math.pow(2,56),lc=Math.pow(2,63),hc=function(e){return e<nc?1:e<oc?2:e<sc?3:e<ic?4:e<ac?5:e<cc?6:e<fc?7:e<uc?8:e<lc?9:10},dc={encode:Wa,decode:ec,encodingLength:hc},pc=dc,We=pc;function Je(e,t=0){return[We.decode(e,t),We.decode.bytes]}function Ae(e,t,r=0){return We.encode(e,t,r),t}function Be(e){return We.encodingLength(e)}function Dt(e,t){let r=t.byteLength,n=Be(e),o=n+Be(r),s=new Uint8Array(o+r);return Ae(e,s,0),Ae(r,s,n),s.set(t,o),new ve(e,r,t,s)}function ds(e){let t=wt(e),[r,n]=Je(t),[o,s]=Je(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ve(r,o,i,t)}function ps(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&os(e.bytes,r.bytes)}}var ve=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=oe(n),this.bytes=oe(o)}};function ms(e,t){let{bytes:r,version:n}=e;return n===0?yc(r,Bn(e),t??rt.encoder):bc(r,Bn(e),t??Se.encoder)}var ys=new WeakMap;function Bn(e){let t=ys.get(e);if(t==null){let r=new Map;return ys.set(e,r),r}return t}var Et=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=oe(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!==tr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==gc)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=Dt(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&&ps(t.multihash,n.multihash)}toString(t){return ms(this,t)}toJSON(){return{"/":ms(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??bs(n,o,s.bytes))}else if(r[xc]===!0){let{version:n,multihash:o,code:s}=r,i=ds(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!==tr)throw new Error(`Version 0 CID must use dag-pb (code: ${tr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=bs(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,tr,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=wt(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 ve(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,b]=Je(t.subarray(r));return r+=b,l},o=n(),s=tr;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(),f=n(),c=r+f,u=c-i;return{version:o,codec:s,multihashCode:a,digestSize:f,multihashSize:u,size:c}}static parse(t,r){let[n,o]=mc(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 Bn(s).set(n,t),s}};function mc(e,t){switch(e[0]){case"Q":{let r=t??rt;return[rt.prefix,r.decode(`${rt.prefix}${e}`)]}case rt.prefix:{let r=t??rt;return[rt.prefix,r.decode(e)]}case Se.prefix:{let r=t??Se;return[Se.prefix,r.decode(e)]}case Xe.prefix:{let r=t??Xe;return[Xe.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 yc(e,t,r){let{prefix:n}=r;if(n!==rt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function bc(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 tr=112,gc=18;function bs(e,t,r){let n=Be(e),o=n+Be(t),s=new Uint8Array(o+r.byteLength);return Ae(e,s,0),Ae(t,s,n),s.set(r,o),s}var xc=Symbol.for("@ipld/js-cid/CID");var vn={};at(vn,{identity:()=>se});var gs=0,wc="identity",xs=wt;function Ec(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 Dt(gs,xs(e))}var se={code:gs,name:wc,encode:xs,digest:Ec};function ct(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}var _n="1.2.840.10045.3.1.7",In="1.3.132.0.34",Tn="1.3.132.0.35";async function ws(e="P-256"){let t=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:e},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",t.publicKey),privateKey:await crypto.subtle.exportKey("jwk",t.privateKey)}}async function Es(e,t,r){let n=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["sign"]);r?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,ot(t.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Ss(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,ot(t),ot(r.subarray()));return n?.signal?.throwIfAborted(),s}function kt(e=0){return new Uint8Array(e)}function yt(e=0){return new Uint8Array(e)}function Sc(e){return e?.buffer instanceof ArrayBuffer}function As(e){if(Sc(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Kt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=yt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return As(r)}var vs=Symbol.for("@achingbrain/uint8arraylist");function Bs(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 Rr(e){return!!e?.[vs]}var ut=class e{bufs;length;[vs]=!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(Rr(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(Rr(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=Bs(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Bs(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(Rr(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 Kt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Kt(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,f=a+i.byteLength;if(o=f,t>=f)continue;let c=t>=a&&t<f,u=r>a&&r<=f;if(c&&u){if(t===a&&r===f){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(c){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(r===f){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(!Rr(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,f=this.byteLength-n.byteLength,c=n.byteLength-1,u;for(let l=r;l<=f;l+=u){u=0;for(let b=c;b>=0;b--){let p=this.get(l+b);if(n[b]!==p){u=Math.max(1,b-a[p]);break}}if(u===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=yt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=kt(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=kt(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=kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=yt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=kt(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=kt(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=kt(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=kt(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=kt(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(!ct(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Ln={};at(Ln,{base10:()=>Ac});var Ac=jt({prefix:"9",name:"base10",alphabet:"0123456789"});var Rn={};at(Rn,{base16:()=>Bc,base16upper:()=>vc});var Bc=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),vc=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Dn={};at(Dn,{base2:()=>_c});var _c=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Kn={};at(Kn,{base256emoji:()=>Dc});var _s=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}"),Ic=_s.reduce((e,t,r)=>(e[r]=t,e),[]),Tc=_s.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+=Ic[r],t),"")}function Rc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Tc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Dc=Ee({prefix:"\u{1F680}",name:"base256emoji",encode:Lc,decode:Rc});var Un={};at(Un,{base64:()=>Cn,base64pad:()=>Kc,base64url:()=>Cc,base64urlpad:()=>Uc});var Cn=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Kc=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Cc=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Uc=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Fn={};at(Fn,{base8:()=>Fc});var Fc=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var On={};at(On,{identity:()=>Oc});var Oc=Ee({prefix:"\0",name:"identity",encode:e=>is(wt(e)),decode:e=>wt(ss(e))});var xl=new TextEncoder,wl=new TextDecoder;var Nn={};at(Nn,{sha256:()=>Dr,sha512:()=>Hc});var Nc=20;function Pn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new kn(e,t,r,n,o)}var kn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Nc,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?Is(n,this.code,r?.truncate):n.then(o=>Is(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Is(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 Dt(t,e)}function Ls(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Dr=Pn({name:"sha2-256",code:18,encode:Ls("SHA-256")}),Hc=Pn({name:"sha2-512",code:19,encode:Ls("SHA-512")});var Hn={...On,...Dn,...Fn,...Ln,...Rn,...En,...Sn,...wn,...Un,...Kn},Kl={...Nn,...vn};function Ds(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Rs=Ds("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Mn=Ds("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=yt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Mc={utf8:Rs,"utf-8":Rs,hex:Hn.base16,latin1:Mn,ascii:Mn,binary:Mn,...Hn},Kr=Mc;function z(e,t="utf8"){let r=Kr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function q(e,t="utf8"){let r=Kr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var qc=parseInt("11111",2),qn=parseInt("10000000",2),Vc=parseInt("01111111",2),Ks={0:er,1:er,2:jc,3:Yc,4:$c,5:Zc,6:zc,16:er,22:er,48:er};function bt(e,t={offset:0}){let r=e[t.offset]&qc;if(t.offset++,Ks[r]!=null)return Ks[r](e,t);throw new Error("No decoder for tag "+r)}function rr(e,t){let r=0;if((e[t.offset]&qn)===qn){let n=e[t.offset]&Vc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function er(e,t){rr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=bt(e,t);if(n===null)break;r.push(n)}return r}function jc(e,t){let r=rr(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 zc(e,t){let r=rr(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}`,f=[];for(;t.offset<n;){let c=e[t.offset];if(t.offset++,f.push(c&127),c<128){f.reverse();let u=0;for(let l=0;l<f.length;l++)u+=f[l]<<l*7;a+=`.${u}`,f=[]}}return a}function Zc(e,t){return t.offset++,null}function Yc(e,t){let r=rr(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 $c(e,t){let r=rr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Gc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ut;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Cr(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Gc(e.byteLength);return new ut(Uint8Array.from([t.byteLength|qn]),t)}function lt(e){let t=new ut,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ut(Uint8Array.from([2]),Cr(t),t)}function nr(e){let t=Uint8Array.from([0]),r=new ut(t,e);return new ut(Uint8Array.from([3]),Cr(r),r)}function Cs(e){return new ut(Uint8Array.from([4]),Cr(e),e)}function At(e,t=48){let r=new ut;for(let n of e)r.append(n);return new ut(Uint8Array.from([t]),Cr(r),r)}var Xc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Wc=Uint8Array.from([6,5,43,129,4,0,34]),Jc=Uint8Array.from([6,5,43,129,4,0,35]),Us={ext:!0,kty:"EC",crv:"P-256"},Fs={ext:!0,kty:"EC",crv:"P-384"},Os={ext:!0,kty:"EC",crv:"P-521"},_e=32,Ie=48,Te=66;function ks(e){let t=bt(e);return Vn(t)}function Vn(e){let t=e[1],r=q(t,"base64url"),n=e[2][1][0],o=1,s,i;if(t.byteLength===_e)return s=q(n.subarray(o,o+_e),"base64url"),i=q(n.subarray(o+_e),"base64url"),new Pt({...Us,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===Ie)return s=q(n.subarray(o,o+Ie),"base64url"),i=q(n.subarray(o+Ie),"base64url"),new Pt({...Fs,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===Te)return s=q(n.subarray(o,o+Te),"base64url"),i=q(n.subarray(o+Te),"base64url"),new Pt({...Os,key_ops:["sign"],d:r,x:s,y:i});throw new P(`Private key length was wrong length, got ${t.byteLength}, expected 32, 48 or 66`)}function jn(e){let t=bt(e);return zn(t)}function zn(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===_e*2+1)return n=q(t.subarray(r,r+_e),"base64url"),o=q(t.subarray(r+_e),"base64url"),new ie({...Us,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ie*2+1)return n=q(t.subarray(r,r+Ie),"base64url"),o=q(t.subarray(r+Ie),"base64url"),new ie({...Fs,key_ops:["verify"],x:n,y:o});if(t.byteLength===Te*2+1)return n=q(t.subarray(r,r+Te),"base64url"),o=q(t.subarray(r+Te),"base64url"),new ie({...Os,key_ops:["verify"],x:n,y:o});throw new P(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ps(e){return At([lt(Uint8Array.from([1])),Cs(z(e.d??"","base64url")),At([Hs(e.crv)],160),At([nr(new ut(Uint8Array.from([4]),z(e.x??"","base64url"),z(e.y??"","base64url")))],161)]).subarray()}function Ns(e){return At([lt(Uint8Array.from([1])),At([Hs(e.crv)],160),At([nr(new ut(Uint8Array.from([4]),z(e.x??"","base64url"),z(e.y??"","base64url")))],161)]).subarray()}function Hs(e){if(e==="P-256")return Xc;if(e==="P-384")return Wc;if(e==="P-521")return Jc;throw new P(`Invalid curve ${e}`)}async function Ms(e="P-256"){let t=await ws(e);return new Pt(t.privateKey)}var ie=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ns(this.jwk)),this._raw}toMultihash(){return se.digest(ae(this))}toCID(){return Et.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}async verify(t,r,n){return Ss(this.jwk,r,t,n)}},Pt=class{type="ECDSA";jwk;publicKey;_raw;constructor(t){this.jwk=t,this.publicKey=new ie({crv:t.crv,ext:t.ext,key_ops:["verify"],kty:"EC",x:t.x,y:t.y})}get raw(){return this._raw==null&&(this._raw=Ps(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}async sign(t,r){return Es(this.jwk,t,r)}};function Zn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function St(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(`${r}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new RangeError(`${r}expected integer >= 0, got ${e}`)}}function pt(e,t,r=""){let n=Zn(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",f=n?`length=${o}`:`type=${typeof e}`,c=i+"expected Uint8Array"+a+", got "+f;throw n?new RangeError(c):new TypeError(c)}return e}function Le(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(St(e.outputLen),St(e.blockLen),e.outputLen<1)throw new Error('"outputLen" must be >= 1');if(e.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Re(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Ur(e,t){pt(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function mt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function De(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Bt(e,t){return e<<32-t|e>>>t}function Fr(e,t){return e<<t|e>>>32-t>>>0}var Vs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Qc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Or(e){if(pt(e),Vs)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Qc[e[r]];return t}var Nt={_0:48,_9:57,A:65,F:70,a:97,f:102};function qs(e){if(e>=Nt._0&&e<=Nt._9)return e-Nt._0;if(e>=Nt.A&&e<=Nt.F)return e-(Nt.A-10);if(e>=Nt.a&&e<=Nt.f)return e-(Nt.a-10)}function or(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(Vs)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=qs(e.charCodeAt(s)),a=qs(e.charCodeAt(s+1));if(i===void 0||a===void 0){let f=e[s]+e[s+1];throw new RangeError('hex string expected, got non-hex character "'+f+'" at index '+s)}n[o]=i*16+a}return n}function tf(e){if(typeof e!="string")throw new TypeError("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Yn(e,t=""){return typeof e=="string"?tf(e):pt(e,void 0,t)}function $n(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];pt(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 js(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new TypeError("options must be object or undefined");return Object.assign(e,t)}function sr(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function zs(e=32){St(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 Gn=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function kr(e,t,r){return e&t^~e&r}function Pr(e,t,r){return e&t^e&r^t&r}var ce=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=De(this.buffer)}update(t){Re(this),pt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let f=De(t);for(;o<=s-i;i+=o)this.process(f,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Re(this),Ur(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,mt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=De(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let c=f/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<c;l++)a.setUint32(4*l,u[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ht=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var st=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Nr=BigInt(4294967295),Zs=BigInt(32);function ef(e,t=!1){return t?{h:Number(e&Nr),l:Number(e>>Zs&Nr)}:{h:Number(e>>Zs&Nr)|0,l:Number(e&Nr)|0}}function Ys(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}=ef(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Xn=(e,t,r)=>e>>>r,Wn=(e,t,r)=>e<<32-r|t>>>r,fe=(e,t,r)=>e>>>r|t<<32-r,ue=(e,t,r)=>e<<32-r|t>>>r,ir=(e,t,r)=>e<<64-r|t>>>r-32,ar=(e,t,r)=>e>>>r-32|t<<64-r;function Ct(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var $s=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Gs=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Xs=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Ws=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Js=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Qs=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var nf=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]),zt=new Uint32Array(64),Jn=class extends ce{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:f}=this;return[t,r,n,o,s,i,a,f]}set(t,r,n,o,s,i,a,f){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=f|0}process(t,r){for(let l=0;l<16;l++,r+=4)zt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let b=zt[l-15],p=zt[l-2],S=Bt(b,7)^Bt(b,18)^b>>>3,B=Bt(p,17)^Bt(p,19)^p>>>10;zt[l]=B+zt[l-7]+S+zt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:f,G:c,H:u}=this;for(let l=0;l<64;l++){let b=Bt(a,6)^Bt(a,11)^Bt(a,25),p=u+b+kr(a,f,c)+nf[l]+zt[l]|0,B=(Bt(n,2)^Bt(n,13)^Bt(n,22))+Pr(n,o,s)|0;u=c,c=f,f=a,a=i+p|0,i=s,s=o,o=n,n=p+B|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,f=f+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,f,c,u)}roundClean(){mt(zt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),mt(this.buffer)}},Qn=class extends Jn{A=Ht[0]|0;B=Ht[1]|0;C=Ht[2]|0;D=Ht[3]|0;E=Ht[4]|0;F=Ht[5]|0;G=Ht[6]|0;H=Ht[7]|0;constructor(){super(32)}};var ti=Ys(["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))),of=ti[0],sf=ti[1],Zt=new Uint32Array(80),Yt=new Uint32Array(80),to=class extends ce{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:f,Eh:c,El:u,Fh:l,Fl:b,Gh:p,Gl:S,Hh:B,Hl:m}=this;return[t,r,n,o,s,i,a,f,c,u,l,b,p,S,B,m]}set(t,r,n,o,s,i,a,f,c,u,l,b,p,S,B,m){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=f|0,this.Eh=c|0,this.El=u|0,this.Fh=l|0,this.Fl=b|0,this.Gh=p|0,this.Gl=S|0,this.Hh=B|0,this.Hl=m|0}process(t,r){for(let v=0;v<16;v++,r+=4)Zt[v]=t.getUint32(r),Yt[v]=t.getUint32(r+=4);for(let v=16;v<80;v++){let K=Zt[v-15]|0,L=Yt[v-15]|0,F=fe(K,L,1)^fe(K,L,8)^Xn(K,L,7),D=ue(K,L,1)^ue(K,L,8)^Wn(K,L,7),_=Zt[v-2]|0,O=Yt[v-2]|0,k=fe(_,O,19)^ir(_,O,61)^Xn(_,O,6),U=ue(_,O,19)^ar(_,O,61)^Wn(_,O,6),h=Xs(D,U,Yt[v-7],Yt[v-16]),y=Ws(h,F,k,Zt[v-7],Zt[v-16]);Zt[v]=y|0,Yt[v]=h|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:f,Dh:c,Dl:u,Eh:l,El:b,Fh:p,Fl:S,Gh:B,Gl:m,Hh:d,Hl:w}=this;for(let v=0;v<80;v++){let K=fe(l,b,14)^fe(l,b,18)^ir(l,b,41),L=ue(l,b,14)^ue(l,b,18)^ar(l,b,41),F=l&p^~l&B,D=b&S^~b&m,_=Js(w,L,D,sf[v],Yt[v]),O=Qs(_,d,K,F,of[v],Zt[v]),k=_|0,U=fe(n,o,28)^ir(n,o,34)^ir(n,o,39),h=ue(n,o,28)^ar(n,o,34)^ar(n,o,39),y=n&s^n&a^s&a,E=o&i^o&f^i&f;d=B|0,w=m|0,B=p|0,m=S|0,p=l|0,S=b|0,{h:l,l:b}=Ct(c|0,u|0,O|0,k|0),c=a|0,u=f|0,a=s|0,f=i|0,s=n|0,i=o|0;let x=$s(k,h,E);n=Gs(x,O,U,y),o=x|0}({h:n,l:o}=Ct(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ct(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:f}=Ct(this.Ch|0,this.Cl|0,a|0,f|0),{h:c,l:u}=Ct(this.Dh|0,this.Dl|0,c|0,u|0),{h:l,l:b}=Ct(this.Eh|0,this.El|0,l|0,b|0),{h:p,l:S}=Ct(this.Fh|0,this.Fl|0,p|0,S|0),{h:B,l:m}=Ct(this.Gh|0,this.Gl|0,B|0,m|0),{h:d,l:w}=Ct(this.Hh|0,this.Hl|0,d|0,w|0),this.set(n,o,s,i,a,f,c,u,l,b,p,S,B,m,d,w)}roundClean(){mt(Zt,Yt)}destroy(){this.destroyed=!0,mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},eo=class extends to{Ah=st[0]|0;Al=st[1]|0;Bh=st[2]|0;Bl=st[3]|0;Ch=st[4]|0;Cl=st[5]|0;Dh=st[6]|0;Dl=st[7]|0;Eh=st[8]|0;El=st[9]|0;Fh=st[10]|0;Fl=st[11]|0;Gh=st[12]|0;Gl=st[13]|0;Hh=st[14]|0;Hl=st[15]|0;constructor(){super(64)}};var $t=sr(()=>new Qn,Gn(1));var Ke=sr(()=>new eo,Gn(3));var M=(e,t,r)=>pt(e,t,r),no=St,Ce=Or,Q=(...e)=>$n(...e),Ue=e=>or(e),le=Zn,cr=e=>zs(e),Mr=BigInt(0),ro=BigInt(1);function vt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function qr(e){if(typeof e=="bigint"){if(!Hr(e))throw new RangeError("positive bigint expected, got "+e)}else no(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 fr(e){let t=qr(e).toString(16);return t.length&1?"0"+t:t}function ei(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?Mr:BigInt("0x"+e)}function he(e){return ei(Or(e))}function Ut(e){return ei(Or(ur(pt(e)).reverse()))}function Vr(e,t){if(St(t),t===0)throw new RangeError("zero length");e=qr(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return or(r.padStart(t*2,"0"))}function oo(e,t){return Vr(e,t).reverse()}function ri(e,t){if(e=M(e),t=M(t),e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function ur(e){return Uint8Array.from(M(e))}function jr(e){if(typeof e!="string")throw new TypeError("ascii string expected, got "+typeof e);return Uint8Array.from(e,(t,r)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${e[r]}" with code ${n} at position ${r}`);return n})}var Hr=e=>typeof e=="bigint"&&Mr<=e;function af(e,t,r){return Hr(e)&&Hr(t)&&Hr(r)&&t<=e&&e<r}function Fe(e,t,r,n){if(!af(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Oe(e){if(e<Mr)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>Mr;e>>=ro,t+=1);return t}var lr=e=>(ro<<BigInt(e))-ro;function ni(e,t,r){if(St(e,"hashLen"),St(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=m=>new Uint8Array(m),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,f=n(e),c=n(e),u=0,l=()=>{f.fill(1),c.fill(0),u=0},b=(...m)=>r(c,Q(f,...m)),p=(m=o)=>{c=b(s,m),f=b(),m.length!==0&&(c=b(i,m),f=b())},S=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let m=0,d=[];for(;m<t;){f=b();let w=f.slice();d.push(w),m+=f.length}return Q(...d)};return(m,d)=>{l(),p(m);let w;for(;(w=d(S()))===void 0;)p();return l(),w}}function It(e,t={},r={}){if(Object.prototype.toString.call(e)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(e,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let f=e[s];if(a&&f===void 0)return;let c=typeof f;if(c!==i||f===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${c}`)}let o=(s,i)=>Object.entries(s).forEach(([a,f])=>n(a,f,i));o(t,!1),o(r,!0)}var so=()=>{throw new Error("not implemented")};var it=BigInt(0),G=BigInt(1),de=BigInt(2),ai=BigInt(3),ci=BigInt(4),fi=BigInt(5),cf=BigInt(7),ui=BigInt(8),ff=BigInt(9),li=BigInt(16);function W(e,t){if(t<=it)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=it?r:t+r}function Z(e,t,r){if(t<it)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >it;)n*=n,n%=r;return n}function oi(e,t){if(e===it)throw new Error("invert: expected non-zero number");if(t<=it)throw new Error("invert: expected positive modulus, got "+t);let r=W(e,t),n=t,o=it,s=G,i=G,a=it;for(;r!==it;){let c=n/r,u=n-r*c,l=o-i*c,b=s-a*c;n=r,r=u,o=i,s=a,i=l,a=b}if(n!==G)throw new Error("invert: does not exist");return W(o,t)}function io(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function hi(e,t){let r=e,n=(r.ORDER+G)/ci,o=r.pow(t,n);return io(r,o,t),o}function uf(e,t){let r=e,n=(r.ORDER-fi)/ui,o=r.mul(t,de),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,de),s),f=r.mul(i,r.sub(a,r.ONE));return io(r,f,t),f}function lf(e){let t=ke(e),r=di(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+cf)/li;return((a,f)=>{let c=a,u=c.pow(f,i),l=c.mul(u,n),b=c.mul(u,o),p=c.mul(u,s),S=c.eql(c.sqr(l),f),B=c.eql(c.sqr(b),f);u=c.cmov(u,l,S),l=c.cmov(p,b,B);let m=c.eql(c.sqr(l),f),d=c.cmov(u,l,m);return io(c,d,f),d})}function di(e){if(e<ai)throw new Error("sqrt is not defined for small field");let t=e-G,r=0;for(;t%de===it;)t/=de,r++;let n=de,o=ke(e);for(;si(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return hi;let s=o.pow(n,t),i=(t+G)/de;return function(f,c){let u=f;if(u.is0(c))return c;if(si(u,c)!==1)throw new Error("Cannot find square root");let l=r,b=u.mul(u.ONE,s),p=u.pow(c,t),S=u.pow(c,i);for(;!u.eql(p,u.ONE);){if(u.is0(p))return u.ZERO;let B=1,m=u.sqr(p);for(;!u.eql(m,u.ONE);)if(B++,m=u.sqr(m),B===l)throw new Error("Cannot find square root");let d=G<<BigInt(l-B-1),w=u.pow(b,d);l=B,b=u.sqr(w),p=u.mul(p,b),S=u.mul(S,w)}return S}}function hf(e){return e%ci===ai?hi:e%ui===fi?uf:e%li===ff?lf(e):di(e)}var Mt=(e,t)=>(W(e,t)&G)===G,df=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ao(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=df.reduce((n,o)=>(n[o]="function",n),t);if(It(e,r),_t(e.BYTES,"BYTES"),_t(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=G)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function pf(e,t,r){let n=e;if(r<it)throw new Error("invalid exponent, negatives unsupported");if(r===it)return n.ONE;if(r===G)return t;let o=n.ONE,s=t;for(;r>it;)r&G&&(o=n.mul(o,s)),s=n.sqr(s),r>>=G;return o}function hr(e,t,r=!1){let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((a,f,c)=>n.is0(f)?a:(o[c]=a,n.mul(a,f)),n.ONE),i=n.inv(s);return t.reduceRight((a,f,c)=>n.is0(f)?a:(o[c]=n.mul(a,o[c]),n.mul(a,f)),i),o}function si(e,t){let r=e,n=(r.ORDER-G)/de,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 mf(e,t){if(t!==void 0&&no(t),e<=it)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=Oe(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${t})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var ii=new WeakMap,zr=class{ORDER;BITS;BYTES;isLE;ZERO=it;ONE=G;_lengths;_mod;constructor(t,r={}){if(t<=G)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}=mf(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 W(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return it<=t&&t<this.ORDER}is0(t){return t===it}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&G)===G}neg(t){return W(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return W(t*t,this.ORDER)}add(t,r){return W(t+r,this.ORDER)}sub(t,r){return W(t-r,this.ORDER)}mul(t,r){return W(t*r,this.ORDER)}pow(t,r){return pf(this,t,r)}div(t,r){return W(t*oi(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 oi(t,this.ORDER)}sqrt(t){let r=ii.get(this);return r||ii.set(this,r=hf(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?oo(t,this.BYTES):Vr(t,this.BYTES)}fromBytes(t,r=!1){M(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 c=new Uint8Array(o);c.set(t,s?0:c.length-t.length),t=c}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let f=s?Ut(t):he(t);if(a&&(f=W(f,i)),!r&&!this.isValid(f))throw new Error("invalid field element: outside of range 0..ORDER");return f}invertBatch(t){return hr(this,t)}cmov(t,r,n){return vt(n,"condition"),n?r:t}};Object.freeze(zr.prototype);function ke(e,t={}){return new zr(e,t)}function pi(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=G)throw new Error("field order must be greater than 1");let t=Oe(e-G);return Math.ceil(t/8)}function co(e){let t=pi(e);return t+Math.ceil(t/2)}function fo(e,t,r=!1){M(e);let n=e.length,o=pi(t),s=Math.max(co(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Ut(e):he(e),a=W(i,t-G)+G;return r?oo(a,o):Vr(a,o)}var Pe=BigInt(0),pe=BigInt(1);function dr(e,t){let r=t.negate();return e?r:t}function me(e,t){let r=hr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function gi(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function uo(e,t){gi(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=lr(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function mi(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),f=e>>i;a>n&&(a-=s,f+=pe);let c=t*n,u=c+Math.abs(a)-1,l=a===0,b=a<0,p=t%2!==0;return{nextN:f,offset:u,isZero:l,isNeg:b,isNegF:p,offsetF:c}}var lo=new WeakMap,xi=new WeakMap;function ho(e){return xi.get(e)||1}function yi(e){if(e!==Pe)throw new Error("invalid wNAF")}var Ne=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Pe;)r&pe&&(n=n.add(o)),o=o.double(),r>>=pe;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=uo(r,this.bits),s=[],i=t,a=i;for(let f=0;f<n;f++){a=i,s.push(a);for(let c=1;c<o;c++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=uo(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:f,offset:c,isZero:u,isNeg:l,isNegF:b,offsetF:p}=mi(n,a,i);n=f,u?s=s.add(dr(b,r[p])):o=o.add(dr(l,r[c]))}return yi(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=uo(t,this.bits);for(let i=0;i<s.windows&&n!==Pe;i++){let{nextN:a,offset:f,isZero:c,isNeg:u}=mi(n,i,s);if(n=a,!c){let l=r[f];o=o.add(u?l.negate():l)}}return yi(n),o}getPrecomputes(t,r,n){let o=lo.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),lo.set(r,o))),o}cached(t,r,n){let o=ho(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=ho(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){gi(r,this.bits),xi.set(t,r),lo.delete(t)}hasCache(t){return ho(t)!==1}};function wi(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Pe||n>Pe;)r&pe&&(s=s.add(o)),n&pe&&(i=i.add(o)),o=o.double(),r>>=pe,n>>=pe;return{p1:s,p2:i}}function bi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ao(t),t}else return ke(e,{isLE:r})}function Zr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let f of["p","n","h"]){let c=t[f];if(!(typeof c=="bigint"&&c>Pe))throw new Error(`CURVE.${f} must be positive bigint`)}let o=bi(t.p,r.Fp,n),s=bi(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let f of a)if(!o.isValid(t[f]))throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function Yr(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Gt=BigInt(0),nt=BigInt(1),po=BigInt(2),yf=BigInt(8);function bf(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 Ei(e,t={}){let r=t,n=Zr("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;It(r,{},{uvRatio:"function"});let f=po<<BigInt(s.BYTES*8)-nt,c=B=>o.create(B),u=r.uvRatio===void 0?(B,m)=>{try{return{isValid:!0,value:o.sqrt(o.div(B,m))}}catch{return{isValid:!1,value:Gt}}}:r.uvRatio;if(!bf(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(B,m,d=!1){let w=d?nt:Gt;return Fe("coordinate "+B,m,w,f),m}function b(B){if(!(B instanceof p))throw new Error("EdwardsPoint expected")}class p{static BASE=new p(i.Gx,i.Gy,nt,c(i.Gx*i.Gy));static ZERO=new p(Gt,nt,nt,Gt);static Fp=o;static Fn=s;X;Y;Z;T;constructor(m,d,w,v){this.X=l("x",m),this.Y=l("y",d),this.Z=l("z",w,!0),this.T=l("t",v),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){if(m instanceof p)throw new Error("extended point not allowed");let{x:d,y:w}=m||{};return l("x",d),l("y",w),new p(d,w,nt,c(d*w))}static fromBytes(m,d=!1){let w=o.BYTES,{a:v,d:K}=i;m=ur(M(m,w,"point")),vt(d,"zip215");let L=ur(m),F=m[w-1];L[w-1]=F&-129;let D=Ut(L),_=d?f:o.ORDER;Fe("point.y",D,Gt,_);let O=c(D*D),k=c(O-nt),U=c(K*O-v),{isValid:h,value:y}=u(k,U);if(!h)throw new Error("bad point: invalid y coordinate");let E=(y&nt)===nt,x=(F&128)!==0;if(!d&&y===Gt&&x)throw new Error("bad point: x=0 and x_0=1");return x!==E&&(y=c(-y)),p.fromAffine({x:y,y:D})}static fromHex(m,d=!1){return p.fromBytes(Ue(m),d)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,d=!0){return S.createCache(this,m),d||this.multiply(po),this}assertValidity(){let m=this,{a:d,d:w}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:v,Y:K,Z:L,T:F}=m,D=c(v*v),_=c(K*K),O=c(L*L),k=c(O*O),U=c(D*d),h=c(O*c(U+_)),y=c(k+c(w*c(D*_)));if(h!==y)throw new Error("bad point: equation left != right (1)");let E=c(v*K),x=c(L*F);if(E!==x)throw new Error("bad point: equation left != right (2)")}equals(m){b(m);let{X:d,Y:w,Z:v}=this,{X:K,Y:L,Z:F}=m,D=c(d*F),_=c(K*v),O=c(w*F),k=c(L*v);return D===_&&O===k}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:m}=i,{X:d,Y:w,Z:v}=this,K=c(d*d),L=c(w*w),F=c(po*c(v*v)),D=c(m*K),_=d+w,O=c(c(_*_)-K-L),k=D+L,U=k-F,h=D-L,y=c(O*U),E=c(k*h),x=c(O*h),g=c(U*k);return new p(y,E,g,x)}add(m){b(m);let{a:d,d:w}=i,{X:v,Y:K,Z:L,T:F}=this,{X:D,Y:_,Z:O,T:k}=m,U=c(v*D),h=c(K*_),y=c(F*w*k),E=c(L*O),x=c((v+K)*(D+_)-U-h),g=E-y,A=E+y,T=c(h-d*U),I=c(x*g),R=c(A*T),C=c(x*T),H=c(g*A);return new p(I,R,H,C)}subtract(m){return b(m),this.add(m.negate())}multiply(m){if(!s.isValidNot0(m))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:d,f:w}=S.cached(this,m,v=>me(p,v));return me(p,[d,w])[0]}multiplyUnsafe(m){if(!s.isValid(m))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return m===Gt?p.ZERO:this.is0()||m===nt?this:S.unsafe(this,m,d=>me(p,d))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return S.unsafe(this,i.n).is0()}toAffine(m){let d=this,w=m,{X:v,Y:K,Z:L}=d,F=d.is0();w==null&&(w=F?yf:o.inv(L));let D=c(v*w),_=c(K*w),O=o.mul(L,w);if(F)return{x:Gt,y:nt};if(O!==nt)throw new Error("invZ was invalid");return{x:D,y:_}}clearCofactor(){return a===nt?this:this.multiplyUnsafe(a)}toBytes(){let{x:m,y:d}=this.toAffine(),w=o.toBytes(d);return w[w.length-1]|=m&nt?128:0,w}toHex(){return Ce(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let S=new Ne(p,s.BITS);return s.BITS>=8&&p.BASE.precompute(8),Object.freeze(p.prototype),Object.freeze(p),p}var $r=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){so()}static fromHex(t){so()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return Ce(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.ep.precompute(t,r),this}};function Si(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;It(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:f}=e,c=n.outputLen,u=2*a.BYTES;if(c!==void 0&&(_t(c,"hash.outputLen"),c!==u))throw new Error(`hash.outputLen must be ${u}, got ${c}`);let l=o.randomBytes===void 0?cr:o.randomBytes,b=o.adjustScalarBytes===void 0?h=>h:o.adjustScalarBytes,p=o.domain===void 0?(h,y,E)=>{if(vt(E,"phflag"),y.length||E)throw new Error("Contexts/pre-hash are not supported");return h}:o.domain;function S(h){return f.create(Ut(h))}function B(h){let y=D.secretKey;M(h,D.secretKey,"secretKey");let E=M(n(h),2*y,"hashedSecretKey"),x=b(E.slice(0,y)),g=E.slice(y,2*y),A=S(x);return{head:x,prefix:g,scalar:A}}function m(h){let{head:y,prefix:E,scalar:x}=B(h),g=i.multiply(x),A=g.toBytes();return{head:y,prefix:E,scalar:x,point:g,pointBytes:A}}function d(h){return m(h).pointBytes}function w(h=Uint8Array.of(),...y){let E=Q(...y);return S(n(p(E,M(h,void 0,"context"),!!s)))}function v(h,y,E={}){h=M(h,void 0,"message"),s&&(h=s(h));let{prefix:x,scalar:g,pointBytes:A}=m(y),T=w(E.context,x,h),I=i.multiply(T).toBytes(),R=w(E.context,I,A,h),C=f.create(T+R*g);if(!f.isValid(C))throw new Error("sign failed: invalid s");let H=Q(I,f.toBytes(C));return M(H,D.signature,"result")}let K={zip215:o.zip215};function L(h,y,E,x=K){let{context:g}=x,A=x.zip215===void 0?!!K.zip215:x.zip215,T=D.signature;h=M(h,T,"signature"),y=M(y,void 0,"message"),E=M(E,D.publicKey,"publicKey"),A!==void 0&&vt(A,"zip215"),s&&(y=s(y));let I=T/2,R=h.subarray(0,I),C=Ut(h.subarray(I,T)),H,V,N;try{H=e.fromBytes(E,A),V=e.fromBytes(R,A),N=i.multiplyUnsafe(C)}catch{return!1}if(!A&&H.isSmallOrder())return!1;let J=w(g,R,E,y);return V.add(H.multiplyUnsafe(J)).subtract(N).clearCofactor().is0()}let F=a.BYTES,D={secretKey:F,publicKey:F,signature:2*F,seed:F};function _(h){return h=h===void 0?l(D.seed):h,M(h,D.seed,"seed")}function O(h){return le(h)&&h.length===D.secretKey}function k(h,y){try{return!!e.fromBytes(h,y===void 0?K.zip215:y)}catch{return!1}}let U={getExtendedPublicKey:m,randomSecretKey:_,isValidSecretKey:O,isValidPublicKey:k,toMontgomery(h){let{y}=e.fromBytes(h),E=D.publicKey,x=E===32;if(!x&&E!==57)throw new Error("only defined for 25519 and 448");let g=x?a.div(nt+y,nt-y):a.div(y-nt,y+nt);return a.toBytes(g)},toMontgomerySecret(h){let y=D.secretKey;M(h,y);let E=n(h.subarray(0,y));return b(E).subarray(0,y)}};return Object.freeze(D),Object.freeze(U),Object.freeze({keygen:Yr(_,d),getPublicKey:d,sign:v,verify:L,utils:U,Point:e,lengths:D})}function pr(e,t){if(_t(e),_t(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(e<0||e>2**(8*t)-1)throw new Error("invalid I2OSP input: "+e);let r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function gf(e,t){let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}function xf(e){if(!le(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?jr(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function mo(e,t,r,n){M(e),_t(r),t=xf(t),t.length>255&&(t=n(Q(jr("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=Q(t,pr(t.length,1)),f=new Uint8Array(s),c=pr(r,2),u=new Array(i),l=n(Q(f,e,c,pr(0,1),a));u[0]=n(Q(l,pr(1,1),a));for(let p=1;p<i;p++){let S=[gf(l,u[p-1]),pr(p+1,1),a];u[p]=n(Q(...S))}return Q(...u).slice(0,r)}var Ai="HashToScalar-";var wf=BigInt(0),qt=BigInt(1),Bi=BigInt(2);var Ef=BigInt(5),Sf=BigInt(8),He=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),xo={p:He,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Sf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Af(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=He,a=e*e%s*e%s,f=Z(a,Bi,s)*a%s,c=Z(f,qt,s)*e%s,u=Z(c,Ef,s)*c%s,l=Z(u,t,s)*u%s,b=Z(l,r,s)*l%s,p=Z(b,n,s)*b%s,S=Z(p,o,s)*p%s,B=Z(S,o,s)*p%s,m=Z(B,t,s)*u%s;return{pow_p_5_8:Z(m,Bi,s)*e%s,b2:a}}function Bf(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var yo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function wo(e,t){let r=He,n=W(t*t*t,r),o=W(n*n*t,r),s=Af(e*o).pow_p_5_8,i=W(e*n*s,r),a=W(t*i*i,r),f=i,c=W(i*yo,r),u=a===e,l=a===W(-e,r),b=a===W(-e*yo,r);return u&&(i=f),(l||b)&&(i=c),Mt(i,r)&&(i=W(-i,r)),{isValid:u||l,value:i}}var Wt=Ei(xo,{uvRatio:wo}),Xt=Wt.Fp,Ii=Wt.Fn;function vf(e){return Si(Wt,Ke,Object.assign({adjustScalarBytes:Bf,zip215:!0},e))}var Me=vf({});var bo=yo,_f=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),If=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Tf=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Lf=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),vi=e=>wo(qt,e),Rf=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),go=e=>Xt.create(Ut(e)&Rf);function _i(e){let{d:t}=xo,r=He,n=d=>Xt.create(d),o=n(bo*e*e),s=n((o+qt)*Tf),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:f,value:c}=wo(s,a),u=n(c*e);Mt(u,r)||(u=n(-u)),f||(c=u),f||(i=o);let l=n(i*(o-qt)*Lf-a),b=c*c,p=n((c+c)*a),S=n(l*_f),B=n(qt-b),m=n(qt+b);return new Wt(n(p*m),n(B*S),n(S*m),n(p*B))}var Jt=class e extends $r{static BASE=new e(Wt.BASE);static ZERO=new e(Wt.ZERO);static Fp=Xt;static Fn=Ii;constructor(t){super(t)}static fromAffine(t){return new e(Wt.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static fromBytes(t){pt(t,32);let{a:r,d:n}=xo,o=He,s=K=>Xt.create(K),i=go(t);if(!ri(Xt.toBytes(i),t)||Mt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),f=s(qt+r*a),c=s(qt-r*a),u=s(f*f),l=s(c*c),b=s(r*n*u-l),{isValid:p,value:S}=vi(s(b*l)),B=s(S*c),m=s(S*B*b),d=s((i+i)*B);Mt(d,o)&&(d=s(-d));let w=s(f*m),v=s(d*w);if(!p||Mt(v,o)||w===wf)throw new Error("invalid ristretto255 encoding 2");return new e(new Wt(d,w,qt,v))}static fromHex(t){return e.fromBytes(or(t))}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=He,i=m=>Xt.create(m),a=i(i(n+r)*i(n-r)),f=i(t*r),c=i(f*f),{value:u}=vi(i(a*c)),l=i(u*a),b=i(u*f),p=i(l*b*o),S;if(Mt(o*p,s)){let m=i(r*bo),d=i(t*bo);t=m,r=d,S=i(l*If)}else S=b;Mt(t*p,s)&&(r=i(-r));let B=i((n-r)*S);return Mt(B,s)&&(B=i(-B)),Xt.toBytes(B)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=c=>Xt.create(c),a=i(r*s)===i(n*o),f=i(n*s)===i(r*o);return a||f}is0(){return this.equals(e.ZERO)}};Object.freeze(Jt.BASE);Object.freeze(Jt.ZERO);Object.freeze(Jt.prototype);Object.freeze(Jt);var Df=Object.freeze({Point:Jt,hashToCurve(e,t){let r=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=mo(e,r,64,Ke);return Df.deriveToCurve(n)},hashToScalar(e,t={DST:Ai}){let r=mo(e,t.DST,64,Ke);return Ii.create(Ut(r))},deriveToCurve(e){pt(e,64);let t=go(e.subarray(0,32)),r=_i(t),n=go(e.subarray(32,64)),o=_i(n);return new Jt(r.add(o))}});var Qt=32,gt=64,Gr=32;var qe,Ti=(async()=>{try{return await Y.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function Li(){let e=Me.utils.randomSecretKey(),t=Me.getPublicKey(e);return{privateKey:Ci(e,t),publicKey:t}}function Ri(e){if(e.length!==Gr)throw new TypeError('"seed" must be 32 bytes in length.');if(!(e instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let t=e,r=Me.getPublicKey(t);return{privateKey:Ci(t,r),publicKey:r}}async function Kf(e,t){let r;e.length===gt?r=e.subarray(0,32):r=e;let n={crv:"Ed25519",kty:"OKP",x:q(e.subarray(32),"base64url"),d:q(r,"base64url"),ext:!0,key_ops:["sign"]},o=await Y.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),s=await Y.get().subtle.sign({name:"Ed25519"},o,ot(t instanceof Uint8Array?t:t.subarray()));return new Uint8Array(s,0,s.byteLength)}function Cf(e,t){let r=e.subarray(0,Gr);return Me.sign(t instanceof Uint8Array?t:t.subarray(),r)}async function Di(e,t){return qe==null&&(qe=await Ti),qe?Kf(e,t):Cf(e,t)}async function Uf(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Y.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Y.get().subtle.verify({name:"Ed25519"},n,ot(t),ot(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Ff(e,t,r){return Me.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Ki(e,t,r){return qe==null&&(qe=await Ti),qe?Uf(e,t,r):Ff(e,t,r)}function Ci(e,t){let r=new Uint8Array(gt);for(let n=0;n<Gr;n++)r[n]=e[n],r[Gr+n]=t[n];return r}function Eo(e,t){let r=z(e,"base64urlpad");if(t!=null){if(r.length>t)throw new Error("byte array longer than desired length");r=Kt([new Uint8Array(t-r.length),r])}return r}function Ve(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var mr=class{type="Ed25519";raw;constructor(t){this.raw=je(t,Qt)}toMultihash(){return se.digest(ae(this))}toCID(){return Et.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Ki(this.raw,r,t);return Ve(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}},ye=class{type="Ed25519";raw;publicKey;constructor(t,r){this.raw=je(t,gt),this.publicKey=new mr(r)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}sign(t,r){r?.signal?.throwIfAborted();let n=Di(this.raw,t);return Ve(n)?n.then(o=>(r?.signal?.throwIfAborted(),o)):(r?.signal?.throwIfAborted(),n)}};function So(e){if(e.length>gt){e=je(e,gt+Qt);let n=e.subarray(0,gt),o=e.subarray(gt,e.length);return new ye(n,o)}e=je(e,gt);let t=e.subarray(0,gt),r=e.subarray(Qt);return new ye(t,r)}function Xr(e){return e=je(e,Qt),new mr(e)}async function Fi(){let{privateKey:e,publicKey:t}=Li();return new ye(e,t)}async function Oi(e){let{privateKey:t,publicKey:r}=Ri(e);return new ye(t,r)}function je(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new P(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Of=Math.pow(2,7),kf=Math.pow(2,14),Pf=Math.pow(2,21),ki=Math.pow(2,28),Pi=Math.pow(2,35),Ni=Math.pow(2,42),Hi=Math.pow(2,49),ht=128,te=127;function yr(e){if(e<Of)return 1;if(e<kf)return 2;if(e<Pf)return 3;if(e<ki)return 4;if(e<Pi)return 5;if(e<Ni)return 6;if(e<Hi)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Mi(e,t,r=0){switch(yr(e)){case 8:t[r++]=e&255|ht,e/=128;case 7:t[r++]=e&255|ht,e/=128;case 6:t[r++]=e&255|ht,e/=128;case 5:t[r++]=e&255|ht,e/=128;case 4:t[r++]=e&255|ht,e>>>=7;case 3:t[r++]=e&255|ht,e>>>=7;case 2:t[r++]=e&255|ht,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function qi(e,t){let r=e[t],n=0;if(n+=r&te,r<ht||(r=e[t+1],n+=(r&te)<<7,r<ht)||(r=e[t+2],n+=(r&te)<<14,r<ht)||(r=e[t+3],n+=(r&te)<<21,r<ht)||(r=e[t+4],n+=(r&te)*ki,r<ht)||(r=e[t+5],n+=(r&te)*Pi,r<ht)||(r=e[t+6],n+=(r&te)*Ni,r<ht)||(r=e[t+7],n+=(r&te)*Hi,r<ht))return n;throw new RangeError("Could not decode varint")}var Ao=new Float32Array([-0]),ee=new Uint8Array(Ao.buffer);function Vi(e,t,r){Ao[0]=e,t[r]=ee[0],t[r+1]=ee[1],t[r+2]=ee[2],t[r+3]=ee[3]}function ji(e,t){return ee[0]=e[t],ee[1]=e[t+1],ee[2]=e[t+2],ee[3]=e[t+3],Ao[0]}var Bo=new Float64Array([-0]),ft=new Uint8Array(Bo.buffer);function zi(e,t,r){Bo[0]=e,t[r]=ft[0],t[r+1]=ft[1],t[r+2]=ft[2],t[r+3]=ft[3],t[r+4]=ft[4],t[r+5]=ft[5],t[r+6]=ft[6],t[r+7]=ft[7]}function Zi(e,t){return ft[0]=e[t],ft[1]=e[t+1],ft[2]=e[t+2],ft[3]=e[t+3],ft[4]=e[t+4],ft[5]=e[t+5],ft[6]=e[t+6],ft[7]=e[t+7],Bo[0]}var Nf=BigInt(Number.MAX_SAFE_INTEGER),Hf=BigInt(Number.MIN_SAFE_INTEGER),xt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return be;if(t<Nf&&t>Hf)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>Yi&&(o=0n,++n>Yi&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return be;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):be}},be=new xt(0,0);be.toBigInt=function(){return 0n};be.zzEncode=be.zzDecode=function(){return this};be.length=function(){return 1};var Yi=4294967296n;function $i(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Gi(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 vo(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 Tt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Wr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var _o=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=ot(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,Tt(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 Tt(this,4);return Wr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tt(this,4);return Wr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tt(this,4);let t=ji(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Tt(this,4);let t=Zi(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 Tt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Gi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Tt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Tt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new xt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Tt(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 Tt(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 Tt(this,8);let t=Wr(this.buf,this.pos+=4),r=Wr(this.buf,this.pos+=4);return new xt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=qi(this.buf,this.pos);return this.pos+=yr(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 br(e){return new _o(e instanceof Uint8Array?e:e.subarray())}function Jr(e,t,r){let n=br(e);return t.decode(n,void 0,r)}function Io(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return yt(i);o+i>t&&(n=yt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ge=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function To(){}var Ro=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Mf=Io();function qf(e){return globalThis.Buffer!=null?yt(e):Mf(e)}var xr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ge(To,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ge(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Do((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,xt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=xt.fromBigInt(t);return this._push(Qr,r.length(),r)}uint64Number(t){return this._push(Mi,yr(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=xt.fromBigInt(t).zzEncode();return this._push(Qr,r.length(),r)}sint64Number(t){let r=xt.fromNumber(t).zzEncode();return this._push(Qr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Lo,1,t?1:0)}fixed32(t){return this._push(gr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=xt.fromBigInt(t);return this._push(gr,4,r.lo)._push(gr,4,r.hi)}fixed64Number(t){let r=xt.fromNumber(t);return this._push(gr,4,r.lo)._push(gr,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(Vi,4,t)}double(t){return this._push(zi,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Lo,1,0):this.uint32(r)._push(jf,r,t)}string(t){let r=$i(t);return r!==0?this.uint32(r)._push(vo,r,t):this._push(Lo,1,0)}fork(){return this.states=new Ro(this),this.head=this.tail=new ge(To,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 ge(To,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=qf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Lo(e,t,r){t[r]=e&255}function Vf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Do=class extends ge{next;constructor(t,r){super(Vf,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 gr(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 jf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(xr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(zf,t,e),this},xr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Zf,t,e),this});function zf(e,t,r){t.set(e,r)}function Zf(e,t,r){e.length<40?vo(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(z(e),r)}function Ko(){return new xr}function tn(e,t){let r=Ko();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*en(e,t,r){let n=br(e);yield*t.stream(n,void 0,"$",r)}var rn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function nn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function Co(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,a){let f=t(i);a.int32(f)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return nn("enum",rn.VARINT,r,n,o)}function on(e,t,r){return nn("message",rn.LENGTH_DELIMITED,e,t,r)}var j;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(j||(j={}));var Uo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Uo||(Uo={}));(function(e){e.codec=()=>Co(Uo)})(j||(j={}));var Ft;(function(e){let t;e.codec=()=>(t==null&&(t=on((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),j.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let f={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{f.Type=j.codec().decode(s);break}case 2:{f.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return f},function*(s,i,a,f={}){let c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:j.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return tn(s,e.codec())}e.encode=r;function n(s,i){return Jr(s,e.codec(),i)}e.decode=n;function o(s,i){return en(s,e.codec(),i)}e.stream=o})(Ft||(Ft={}));var wr;(function(e){let t;e.codec=()=>(t==null&&(t=on((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),j.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let f={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{f.Type=j.codec().decode(s);break}case 2:{f.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return f},function*(s,i,a,f={}){let c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:j.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return tn(s,e.codec())}e.encode=r;function n(s,i){return Jr(s,e.codec(),i)}e.decode=n;function o(s,i){return en(s,e.codec(),i)}e.stream=o})(wr||(wr={}));function Fo(e){if(isNaN(e)||e<=0)throw new P("random bytes length must be a Number bigger than 0");return crypto.getRandomValues(new Uint8Array(e))}var Sr={};at(Sr,{MAX_RSA_KEY_SIZE:()=>Oo,generateRSAKeyPair:()=>Vo,jwkToJWKKeyPair:()=>ta,jwkToPkcs1:()=>Xf,jwkToPkix:()=>Ho,jwkToRSAPrivateKey:()=>cn,pkcs1MessageToJwk:()=>Po,pkcs1MessageToRSAPrivateKey:()=>sn,pkcs1ToJwk:()=>Gf,pkcs1ToRSAPrivateKey:()=>Mo,pkixMessageToJwk:()=>No,pkixMessageToRSAPublicKey:()=>an,pkixToJwk:()=>Wf,pkixToRSAPublicKey:()=>qo});var ze=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Sr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return Et.createV1(114,this._multihash)}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){return Qi(this.jwk,r,t,n)}},Er=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Sr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}sign(t,r){return Ji(this.jwk,t,r)}};var Oo=8192,ko=18,Yf=1062,$f=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Gf(e){let t=bt(e);return Po(t)}function Po(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 Xf(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 P("JWK was missing components");return At([lt(Uint8Array.from([0])),lt(z(e.n,"base64url")),lt(z(e.e,"base64url")),lt(z(e.d,"base64url")),lt(z(e.p,"base64url")),lt(z(e.q,"base64url")),lt(z(e.dp,"base64url")),lt(z(e.dq,"base64url")),lt(z(e.qi,"base64url"))]).subarray()}function Wf(e){let t=bt(e,{offset:0});return No(t)}function No(e){let t=bt(e[1],{offset:0});return{kty:"RSA",n:q(t[0],"base64url"),e:q(t[1],"base64url")}}function Ho(e){if(e.n==null||e.e==null)throw new P("JWK was missing components");return At([$f,nr(At([lt(z(e.n,"base64url")),lt(z(e.e,"base64url"))]))]).subarray()}function Mo(e){let t=bt(e);return sn(t)}function sn(e){let t=Po(e);return cn(t)}function qo(e,t){if(e.byteLength>=Yf)throw new we("Key size is too large");let r=bt(e,{offset:0});return an(r,e,t)}function an(e,t,r){let n=No(e);if(r==null){let o=$t(Ft.encode({Type:j.RSA,Data:t}));r=Dt(ko,o)}return new ze(n,r)}function cn(e){if(ra(e)>Oo)throw new P("Key size is too large");let t=ta(e),r=$t(Ft.encode({Type:j.RSA,Data:Ho(t.publicKey)})),n=Dt(ko,r);return new Er(t.privateKey,new ze(t.publicKey,n))}async function Vo(e){if(e>Oo)throw new P("Key size is too large");let t=await ea(e),r=$t(Ft.encode({Type:j.RSA,Data:Ho(t.publicKey)})),n=Dt(ko,r);return new Er(t.privateKey,new ze(t.publicKey,n))}function ta(e){if(e==null)throw new P("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var na="1.2.840.113549.1.1.1";async function ea(e,t){let r=await Y.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 Jf(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Ji(e,t,r){let n=await Y.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Y.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,ot(t instanceof Uint8Array?t:t.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Qi(e,t,r,n){let o=await Y.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Y.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,ot(t),ot(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function Jf(e,t){if(e.privateKey==null||e.publicKey==null)throw new P("Private and public key are required");let r=await Promise.all([Y.get().subtle.exportKey("jwk",e.privateKey),Y.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function ra(e){if(e.kty!=="RSA")throw new P("invalid key type");if(e.n==null)throw new P("invalid key modulus");return z(e.n,"base64url").length*8}var fn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(Le(t),pt(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),mt(o)}update(t){return Re(this),this.iHash.update(t),this}digestInto(t){Re(this),Ur(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}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},un=(()=>{let e=((t,r,n)=>new fn(t,r).update(n).digest());return e.create=(t,r)=>new fn(t,r),e})();var oa=(e,t)=>(e+(e>=0?t:-t)/sa)/t;function Qf(e,t,r){Fe("scalar",e,Ot,r);let[[n,o],[s,i]]=t,a=oa(i*e,r),f=oa(-o*e,r),c=e-a*n-f*s,u=-a*o-f*i,l=c<Ot,b=u<Ot;l&&(c=-c),b&&(u=-u);let p=lr(Math.ceil(Oe(r)/2))+re;if(c<Ot||c>=p||u<Ot||u>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:c,k2neg:b,k2:u}}function zo(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function jo(e,t){It(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return vt(r.lowS,"lowS"),vt(r.prehash,"prehash"),r.format!==void 0&&zo(r.format),r}var Zo=class extends Error{constructor(t=""){super(t)}},Lt={Err:Zo,_tlv:{encode:(e,t)=>{let{Err:r}=Lt;if(_t(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=fr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?fr(o.length/2|128):"";return fr(e)+s+o+t},decode(e,t){let{Err:r}=Lt;t=M(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let f=o&127;if(!f)throw new r("tlv.decode(long): indefinite length not supported");if(f>4)throw new r("tlv.decode(long): byte length is too big");let c=t.subarray(n,n+f);if(c.length!==f)throw new r("tlv.decode: length bytes not complete");if(c[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of c)i=i<<8|u;if(n+=f,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}=Lt;if(qr(e),e<Ot)throw new t("integer: negative integers are not allowed");let r=fr(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}=Lt;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 he(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Lt,o=M(e,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:f}=n.decode(2,s),{v:c,l:u}=n.decode(2,f);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(c)}},hexFromSig(e){let{_tlv:t,_int:r}=Lt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}};Object.freeze(Lt._tlv);Object.freeze(Lt._int);Object.freeze(Lt);var Ot=BigInt(0),re=BigInt(1),sa=BigInt(2),ln=BigInt(3),tu=BigInt(4);function ia(e,t={}){let r=Zr("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;It(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:f,allowInfinityPoint:c}=t;if(f&&(!n.is0(s.a)||typeof f.beta!="bigint"||!Array.isArray(f.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=ca(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function b(U,h,y){if(c&&h.is0())return Uint8Array.of(0);let{x:E,y:x}=h.toAffine(),g=n.toBytes(E);if(vt(y,"isCompressed"),y){l();let A=!n.isOdd(x);return Q(aa(A),g)}else return Q(Uint8Array.of(4),g,n.toBytes(x))}function p(U){M(U,void 0,"Point");let{publicKey:h,publicKeyUncompressed:y}=u,E=U.length,x=U[0],g=U.subarray(1);if(c&&E===1&&x===0)return{x:n.ZERO,y:n.ZERO};if(E===h&&(x===2||x===3)){let A=n.fromBytes(g);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let T=m(A),I;try{I=n.sqrt(T)}catch(H){let V=H instanceof Error?": "+H.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}l();let R=n.isOdd(I);return(x&1)===1!==R&&(I=n.neg(I)),{x:A,y:I}}else if(E===y&&x===4){let A=n.BYTES,T=n.fromBytes(g.subarray(0,A)),I=n.fromBytes(g.subarray(A,A*2));if(!d(T,I))throw new Error("bad point: is not on curve");return{x:T,y:I}}else throw new Error(`bad point: got length ${E}, expected compressed=${h} or uncompressed=${y}`)}let S=t.toBytes===void 0?b:t.toBytes,B=t.fromBytes===void 0?p:t.fromBytes;function m(U){let h=n.sqr(U),y=n.mul(h,U);return n.add(n.add(y,n.mul(U,s.a)),s.b)}function d(U,h){let y=n.sqr(h),E=m(U);return n.eql(y,E)}if(!d(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let w=n.mul(n.pow(s.a,ln),tu),v=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(w,v)))throw new Error("bad curve params: a or b");function K(U,h,y=!1){if(!n.isValid(h)||y&&n.is0(h))throw new Error(`bad point coordinate ${U}`);return h}function L(U){if(!(U instanceof _))throw new Error("Weierstrass Point expected")}function F(U){if(!f||!f.basises)throw new Error("no endo");return Qf(U,f.basises,o.ORDER)}function D(U,h,y,E,x){return y=new _(n.mul(y.X,U),y.Y,y.Z),h=dr(E,h),y=dr(x,y),h.add(y)}class _{static BASE=new _(s.Gx,s.Gy,n.ONE);static ZERO=new _(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(h,y,E){this.X=K("x",h),this.Y=K("y",y,!0),this.Z=K("z",E),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){let{x:y,y:E}=h||{};if(!h||!n.isValid(y)||!n.isValid(E))throw new Error("invalid affine point");if(h instanceof _)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(E)?_.ZERO:new _(y,E,n.ONE)}static fromBytes(h){let y=_.fromAffine(B(M(h,void 0,"point")));return y.assertValidity(),y}static fromHex(h){return _.fromBytes(Ue(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,y=!0){return k.createCache(this,h),y||this.multiply(ln),this}assertValidity(){let h=this;if(h.is0()){if(t.allowInfinityPoint&&n.is0(h.X)&&n.eql(h.Y,n.ONE)&&n.is0(h.Z))return;throw new Error("bad point: ZERO")}let{x:y,y:E}=h.toAffine();if(!n.isValid(y)||!n.isValid(E))throw new Error("bad point: x or y not field elements");if(!d(y,E))throw new Error("bad point: equation left != right");if(!h.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){L(h);let{X:y,Y:E,Z:x}=this,{X:g,Y:A,Z:T}=h,I=n.eql(n.mul(y,T),n.mul(g,x)),R=n.eql(n.mul(E,T),n.mul(A,x));return I&&R}negate(){return new _(this.X,n.neg(this.Y),this.Z)}double(){let{a:h,b:y}=s,E=n.mul(y,ln),{X:x,Y:g,Z:A}=this,T=n.ZERO,I=n.ZERO,R=n.ZERO,C=n.mul(x,x),H=n.mul(g,g),V=n.mul(A,A),N=n.mul(x,g);return N=n.add(N,N),R=n.mul(x,A),R=n.add(R,R),T=n.mul(h,R),I=n.mul(E,V),I=n.add(T,I),T=n.sub(H,I),I=n.add(H,I),I=n.mul(T,I),T=n.mul(N,T),R=n.mul(E,R),V=n.mul(h,V),N=n.sub(C,V),N=n.mul(h,N),N=n.add(N,R),R=n.add(C,C),C=n.add(R,C),C=n.add(C,V),C=n.mul(C,N),I=n.add(I,C),V=n.mul(g,A),V=n.add(V,V),C=n.mul(V,N),T=n.sub(T,C),R=n.mul(V,H),R=n.add(R,R),R=n.add(R,R),new _(T,I,R)}add(h){L(h);let{X:y,Y:E,Z:x}=this,{X:g,Y:A,Z:T}=h,I=n.ZERO,R=n.ZERO,C=n.ZERO,H=s.a,V=n.mul(s.b,ln),N=n.mul(y,g),J=n.mul(E,A),tt=n.mul(x,T),et=n.add(y,E),X=n.add(g,A);et=n.mul(et,X),X=n.add(N,J),et=n.sub(et,X),X=n.add(y,x);let dt=n.add(g,T);return X=n.mul(X,dt),dt=n.add(N,tt),X=n.sub(X,dt),dt=n.add(E,x),I=n.add(A,T),dt=n.mul(dt,I),I=n.add(J,tt),dt=n.sub(dt,I),C=n.mul(H,X),I=n.mul(V,tt),C=n.add(I,C),I=n.sub(J,C),C=n.add(J,C),R=n.mul(I,C),J=n.add(N,N),J=n.add(J,N),tt=n.mul(H,tt),X=n.mul(V,X),J=n.add(J,tt),tt=n.sub(N,tt),tt=n.mul(H,tt),X=n.add(X,tt),N=n.mul(J,X),R=n.add(R,N),N=n.mul(dt,X),I=n.mul(et,I),I=n.sub(I,N),N=n.mul(et,J),C=n.mul(dt,C),C=n.add(C,N),new _(I,R,C)}subtract(h){return L(h),this.add(h.negate())}is0(){return this.equals(_.ZERO)}multiply(h){let{endo:y}=t;if(!o.isValidNot0(h))throw new RangeError("invalid scalar: out of range");let E,x,g=A=>k.cached(this,A,T=>me(_,T));if(y){let{k1neg:A,k1:T,k2neg:I,k2:R}=F(h),{p:C,f:H}=g(T),{p:V,f:N}=g(R);x=H.add(N),E=D(y.beta,C,V,A,I)}else{let{p:A,f:T}=g(h);E=A,x=T}return me(_,[E,x])[0]}multiplyUnsafe(h){let{endo:y}=t,E=this,x=h;if(!o.isValid(x))throw new RangeError("invalid scalar: out of range");if(x===Ot||E.is0())return _.ZERO;if(x===re)return E;if(k.hasCache(this))return this.multiply(x);if(y){let{k1neg:g,k1:A,k2neg:T,k2:I}=F(x),{p1:R,p2:C}=wi(_,E,A,I);return D(y.beta,R,C,g,T)}else return k.unsafe(E,x)}toAffine(h){let y=this,E=h,{X:x,Y:g,Z:A}=y;if(n.eql(A,n.ONE))return{x,y:g};let T=y.is0();E==null&&(E=T?n.ONE:n.inv(A));let I=n.mul(x,E),R=n.mul(g,E),C=n.mul(A,E);if(T)return{x:n.ZERO,y:n.ZERO};if(!n.eql(C,n.ONE))throw new Error("invZ was invalid");return{x:I,y:R}}isTorsionFree(){let{isTorsionFree:h}=t;return i===re?!0:h?h(_,this):k.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:h}=t;return i===re?this:h?h(_,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===re?this.is0():this.clearCofactor().is0()}toBytes(h=!0){return vt(h,"isCompressed"),this.assertValidity(),S(_,this,h)}toHex(h=!0){return Ce(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let O=o.BITS,k=new Ne(_,t.endo?Math.ceil(O/2):O);return O>=8&&_.BASE.precompute(8),Object.freeze(_.prototype),Object.freeze(_),_}function aa(e){return Uint8Array.of(e?2:3)}function ca(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function eu(e,t={}){let{Fn:r}=e,n=t.randomBytes===void 0?cr:t.randomBytes,o=Object.assign(ca(e.Fp,r),{seed:Math.max(co(r.ORDER),16)});function s(p){try{let S=r.fromBytes(p);return r.isValidNot0(S)}catch{return!1}}function i(p,S){let{publicKey:B,publicKeyUncompressed:m}=o;try{let d=p.length;return S===!0&&d!==B||S===!1&&d!==m?!1:!!e.fromBytes(p)}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,fo(M(p,o.seed,"seed"),r.ORDER)}function f(p,S=!0){return e.BASE.multiply(r.fromBytes(p)).toBytes(S)}function c(p){let{secretKey:S,publicKey:B,publicKeyUncompressed:m}=o,d=r._lengths;if(!le(p))return;let w=M(p,void 0,"key").length,v=w===B||w===m,K=w===S||!!d?.includes(w);if(!(v&&K))return v}function u(p,S,B=!0){if(c(p)===!0)throw new Error("first arg must be private key");if(c(S)===!1)throw new Error("second arg must be public key");let m=r.fromBytes(p);return e.fromBytes(S).multiply(m).toBytes(B)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},b=Yr(a,f);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:f,getSharedSecret:u,keygen:b,Point:e,utils:l,lengths:o})}function fa(e,t,r={}){let n=t;Le(n),It(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?cr:r.randomBytes,s=r.hmac===void 0?(x,g)=>un(n,x,g):r.hmac,{Fp:i,Fn:a}=e,{ORDER:f,BITS:c}=a,{keygen:u,getPublicKey:l,getSharedSecret:b,utils:p,lengths:S}=eu(e,r),B={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},m=f*sa+re<i.ORDER;function d(x){let g=f>>re;return x>g}function w(x,g){if(!a.isValidNot0(g))throw new Error(`invalid signature ${x}: out of range 1..Point.Fn.ORDER`);return g}function v(){if(m)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function K(x,g){zo(g);let A=S.signature,T=g==="compact"?A:g==="recovered"?A+1:void 0;return M(x,T)}class L{r;s;recovery;constructor(g,A,T){if(this.r=w("r",g),this.s=w("s",A),T!=null){if(v(),![0,1,2,3].includes(T))throw new Error("invalid recovery id");this.recovery=T}Object.freeze(this)}static fromBytes(g,A=B.format){K(g,A);let T;if(A==="der"){let{r:H,s:V}=Lt.toSig(M(g));return new L(H,V)}A==="recovered"&&(T=g[0],A="compact",g=g.subarray(1));let I=S.signature/2,R=g.subarray(0,I),C=g.subarray(I,I*2);return new L(a.fromBytes(R),a.fromBytes(C),T)}static fromHex(g,A){return this.fromBytes(Ue(g),A)}assertRecovery(){let{recovery:g}=this;if(g==null)throw new Error("invalid recovery id: must be present");return g}addRecoveryBit(g){return new L(this.r,this.s,g)}recoverPublicKey(g){let{r:A,s:T}=this,I=this.assertRecovery(),R=I===2||I===3?A+f:A;if(!i.isValid(R))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let C=i.toBytes(R),H=e.fromBytes(Q(aa((I&1)===0),C)),V=a.inv(R),N=D(M(g,void 0,"msgHash")),J=a.create(-N*V),tt=a.create(T*V),et=e.BASE.multiplyUnsafe(J).add(H.multiplyUnsafe(tt));if(et.is0())throw new Error("invalid recovery: point at infinify");return et.assertValidity(),et}hasHighS(){return d(this.s)}toBytes(g=B.format){if(zo(g),g==="der")return Ue(Lt.hexFromSig(this));let{r:A,s:T}=this,I=a.toBytes(A),R=a.toBytes(T);return g==="recovered"?(v(),Q(Uint8Array.of(this.assertRecovery()),I,R)):Q(I,R)}toHex(g){return Ce(this.toBytes(g))}}Object.freeze(L.prototype),Object.freeze(L);let F=r.bits2int===void 0?function(g){if(g.length>8192)throw new Error("input is too large");let A=he(g),T=g.length*8-c;return T>0?A>>BigInt(T):A}:r.bits2int,D=r.bits2int_modN===void 0?function(g){return a.create(F(g))}:r.bits2int_modN,_=lr(c);function O(x){return Fe("num < 2^"+c,x,Ot,_),a.toBytes(x)}function k(x,g){return M(x,void 0,"message"),g?M(n(x),void 0,"prehashed message"):x}function U(x,g,A){let{lowS:T,prehash:I,extraEntropy:R}=jo(A,B);x=k(x,I);let C=D(x),H=a.fromBytes(g);if(!a.isValidNot0(H))throw new Error("invalid private key");let V=[O(H),O(C)];if(R!=null&&R!==!1){let et=R===!0?o(S.secretKey):R;V.push(M(et,void 0,"extraEntropy"))}let N=Q(...V),J=C;function tt(et){let X=F(et);if(!a.isValidNot0(X))return;let dt=a.inv(X),xe=e.BASE.multiply(X).toAffine(),Ze=a.create(xe.x);if(Ze===Ot)return;let _r=a.create(dt*a.create(J+Ze*H));if(_r===Ot)return;let ts=(xe.x===Ze?0:2)|Number(xe.y&re),es=_r;return T&&d(_r)&&(es=a.neg(_r),ts^=1),new L(Ze,es,m?void 0:ts)}return{seed:N,k2sig:tt}}function h(x,g,A={}){let{seed:T,k2sig:I}=U(x,g,A);return ni(n.outputLen,a.BYTES,s)(T,I).toBytes(A.format)}function y(x,g,A,T={}){let{lowS:I,prehash:R,format:C}=jo(T,B);if(A=M(A,void 0,"publicKey"),g=k(g,R),!le(x)){let H=x instanceof L?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+H)}K(x,C);try{let H=L.fromBytes(x,C),V=e.fromBytes(A);if(I&&H.hasHighS())return!1;let{r:N,s:J}=H,tt=D(g),et=a.inv(J),X=a.create(tt*et),dt=a.create(N*et),xe=e.BASE.multiplyUnsafe(X).add(V.multiplyUnsafe(dt));return xe.is0()?!1:a.create(xe.x)===N}catch{return!1}}function E(x,g,A={}){let{prehash:T}=jo(A,B);return g=k(g,T),L.fromBytes(x,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:b,utils:p,lengths:S,Point:e,sign:h,verify:y,recoverPublicKey:E,Signature:L,hash:n})}var $o={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ru={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ua=BigInt(2);function nu(e){let t=$o.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),f=BigInt(88),c=e*e*e%t,u=c*c*e%t,l=Z(u,r,t)*u%t,b=Z(l,r,t)*u%t,p=Z(b,ua,t)*c%t,S=Z(p,o,t)*p%t,B=Z(S,s,t)*S%t,m=Z(B,a,t)*B%t,d=Z(m,f,t)*m%t,w=Z(d,a,t)*B%t,v=Z(w,r,t)*u%t,K=Z(v,i,t)*S%t,L=Z(K,n,t)*c%t,F=Z(L,ua,t);if(!Yo.eql(Yo.sqr(F),e))throw new Error("Cannot find square root");return F}var Yo=ke($o.p,{sqrt:nu}),ou=ia($o,{Fp:Yo,endo:ru}),Rt=fa(ou,$t);var la=33,ha=32;function da(e,t,r){let n=Dr.digest(t instanceof Uint8Array?t:t.subarray());if(Ve(n))return n.then(({digest:o})=>(r?.signal?.throwIfAborted(),Rt.sign(o,e,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Ye(String(o))});try{return Rt.sign(n.digest,e,{prehash:!1,format:"der"})}catch(o){throw new Ye(String(o))}}function pa(e,t,r,n){let o=Dr.digest(r instanceof Uint8Array?r:r.subarray());if(Ve(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Rt.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new $e(String(s))});try{return n?.signal?.throwIfAborted(),Rt.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new $e(String(s))}}var Ar=class{type="secp256k1";raw;_key;constructor(t){this._key=ba(t),this.raw=ma(this._key)}toMultihash(){return se.digest(ae(this))}toCID(){return Et.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){return pa(this._key,r,t,n)}},Br=class{type="secp256k1";raw;publicKey;constructor(t,r){this.raw=ya(t),this.publicKey=new Ar(r??ga(t))}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}sign(t,r){return da(this.raw,t,r)}};function Go(e){return new Br(e)}function hn(e){return new Ar(e)}async function xa(){let e=su();return new Br(e)}function ma(e){return Rt.Point.fromBytes(e).toBytes()}function ya(e){try{return Rt.getPublicKey(e,!0),e}catch(t){throw new Ge(String(t))}}function ba(e){try{return Rt.Point.fromBytes(e),e}catch(t){throw new we(String(t))}}function ga(e){try{return Rt.getPublicKey(e,!0)}catch(t){throw new Ge(String(t))}}function su(){return Rt.utils.randomSecretKey()}var dn={"P-256":32,"P-384":48,"P-521":66},iu=Object.keys(dn),Xo=iu.join(" / ");async function wa(e){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new P(`Unknown curve: ${e}. Must be ${Xo}`);let t=await Y.get().subtle.generateKey({name:"ECDH",namedCurve:e},!0,["deriveBits"]),r=async(s,i)=>{let a;i!=null?a=await Y.get().subtle.importKey("jwk",cu(e,i),{name:"ECDH",namedCurve:e},!1,["deriveBits"]):a=t.privateKey;let f=await Y.get().subtle.importKey("jwk",Ea(e,s),{name:"ECDH",namedCurve:e},!1,[]),c=await Y.get().subtle.deriveBits({name:"ECDH",public:f},a,dn[e]*8);return new Uint8Array(c,0,c.byteLength)},n=await Y.get().subtle.exportKey("jwk",t.publicKey);return{key:au(n),genSharedKey:r}}function au(e){if(e.crv==null||e.x==null||e.y==null)throw new P("JWK was missing components");if(e.crv!=="P-256"&&e.crv!=="P-384"&&e.crv!=="P-521")throw new P(`Unknown curve: ${e.crv}. Must be ${Xo}`);let t=dn[e.crv];return Kt([Uint8Array.from([4]),Eo(e.x,t),Eo(e.y,t)],1+t*2)}function Ea(e,t){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new P(`Unknown curve: ${e}. Must be ${Xo}`);let r=dn[e];if(!ct(t.subarray(0,1),Uint8Array.from([4])))throw new P("Cannot unmarshal public key - invalid key format");return{kty:"EC",crv:e,x:q(t.subarray(1,r+1),"base64url"),y:q(t.subarray(1+r),"base64url"),ext:!0}}var cu=(e,t)=>({...Ea(e,t.public),d:q(t.private,"base64url")});var fu={"AES-128":{ivSize:16,keySize:16},"AES-256":{ivSize:16,keySize:32},Blowfish:{ivSize:8,keySize:32}};async function Sa(e,t,r){if(e!=="AES-128"&&e!=="AES-256"&&e!=="Blowfish")throw new P("Cipher type was missing or unsupported");if(t!=="SHA1"&&t!=="SHA256"&&t!=="SHA512")throw new P("Hash type was missing or unsupported");if(r==null||!(r instanceof Uint8Array))throw new P("Secret was missing or an incorrect type");let n=fu[e],o=n.keySize,s=n.ivSize,i=20,a=z("key expansion"),f=2*(s+o+i),c=await mn(t,r),u=await c.digest(a),l=[],b=0;for(;b<f;){let w=await c.digest(Kt([u,a])),v=w.length;b+v>f&&(v=f-b),l.push(w),b+=v,u=await c.digest(u)}let p=f/2,S=Kt(l),B=S.subarray(0,p),m=S.subarray(p,f),d=w=>({iv:w.subarray(0,s),cipherKey:w.subarray(s,s+o),macKey:w.subarray(s+o)});return{k1:d(B),k2:d(m)}}async function uu(e,t){if(e==="Ed25519")return Fi();if(e==="secp256k1")return xa();if(e==="RSA")return Vo(gu(t));if(e==="ECDSA")return Ms(xu(t));throw new Vt}async function lu(e,t){if(e!=="Ed25519")throw new Vt("Seed key derivation only supported for Ed25519 keys");return Oi(t)}function hu(e,t){let{Type:r,Data:n}=Ft.decode(e),o=n??new Uint8Array;switch(r){case j.RSA:return qo(o,t);case j.Ed25519:return Xr(o);case j.secp256k1:return hn(o);case j.ECDSA:return jn(o);default:throw new Vt}}function du(e){if(e.byteLength===Qt)return Xr(e);if(e.byteLength===la)return hn(e);let t=bt(e),r=t[1]?.[0];if(r===_n||r===In||r===Tn)return zn(t);if(t[0]?.[0]===na)return an(t,e);throw new P("Could not extract public key from raw bytes")}function pu(e){let{Type:t,Data:r}=Ft.decode(e.digest),n=r??new Uint8Array;switch(t){case j.Ed25519:return Xr(n);case j.secp256k1:return hn(n);case j.ECDSA:return jn(n);default:throw new Vt}}function ae(e){return Ft.encode({Type:j[e.type],Data:e.raw})}function mu(e){let t=wr.decode(e),r=t.Data??new Uint8Array;switch(t.Type){case j.RSA:return Mo(r);case j.Ed25519:return So(r);case j.secp256k1:return Go(r);case j.ECDSA:return ks(r);default:throw new Vt}}function yu(e){if(e.byteLength===gt)return So(e);if(e.byteLength===ha)return Go(e);let t=bt(e),r=t[2]?.[0];if(r===_n||r===In||r===Tn)return Vn(t);if(t.length>8)return sn(t);throw new P("Could not extract private key from raw bytes")}function bu(e){return wr.encode({Type:j[e.type],Data:e.raw})}function gu(e){return e==null?2048:parseInt(e,10)}function xu(e){if(e==="P-256"||e==null)return"P-256";if(e==="P-384")return"P-384";if(e==="P-521")return"P-521";throw new P("Unsupported curve, should be P-256, P-384 or P-521")}async function wu(e){if(e.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(e.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"ECDSA",namedCurve:e.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"ECDSA",namedCurve:e.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new P("Only RSA and ECDSA keys are supported")}async function Eu(e){if(e.privateKey.algorithm.name==="RSASSA-PKCS1-v1_5"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return cn(t)}if(e.privateKey.algorithm.name==="ECDSA"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return new Pt(t)}throw new P("Only RSA and ECDSA keys are supported")}var vr=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),ne=new Uint32Array(80),Jo=class extends ce{A=vr[0]|0;B=vr[1]|0;C=vr[2]|0;D=vr[3]|0;E=vr[4]|0;constructor(){super(64,20,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s}=this;return[t,r,n,o,s]}set(t,r,n,o,s){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0}process(t,r){for(let f=0;f<16;f++,r+=4)ne[f]=t.getUint32(r,!1);for(let f=16;f<80;f++)ne[f]=Fr(ne[f-3]^ne[f-8]^ne[f-14]^ne[f-16],1);let{A:n,B:o,C:s,D:i,E:a}=this;for(let f=0;f<80;f++){let c,u;f<20?(c=kr(o,s,i),u=1518500249):f<40?(c=o^s^i,u=1859775393):f<60?(c=Pr(o,s,i),u=2400959708):(c=o^s^i,u=3395469782);let l=Fr(n,5)+c+a+u+ne[f]|0;a=i,i=s,s=Fr(o,30),o=n,n=l}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,this.set(n,o,s,i,a)}roundClean(){mt(ne)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0),mt(this.buffer)}},Aa=sr(()=>new Jo);function Su(e,t,r,n){Le(e);let o=js({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:a}=o;if(St(s,"c"),St(i,"dkLen"),St(a,"asyncTick"),s<1)throw new Error("iterations (c) must be >= 1");if(i<1)throw new Error('"dkLen" must be >= 1');if(i>(2**32-1)*e.outputLen)throw new Error("derived key too long");let f=Yn(t,"password"),c=Yn(r,"salt"),u=new Uint8Array(i),l=un.create(e,f),b=l._cloneInto().update(c);return{c:s,dkLen:i,asyncTick:a,DK:u,PRF:l,PRFSalt:b}}function Au(e,t,r,n,o){return e.destroy(),t.destroy(),n&&n.destroy(),mt(o),r}function Ba(e,t,r,n){let{c:o,dkLen:s,DK:i,PRF:a,PRFSalt:f}=Su(e,t,r,n),c,u=new Uint8Array(4),l=De(u),b=new Uint8Array(a.outputLen);for(let p=1,S=0;S<s;p++,S+=a.outputLen){let B=i.subarray(S,S+a.outputLen);l.setInt32(0,p,!1),(c=f._cloneInto(c)).update(u).digestInto(b),B.set(b.subarray(0,B.length));for(let m=1;m<o;m++){a._cloneInto(c).update(b).digestInto(b);for(let d=0;d<B.length;d++)B[d]^=b[d]}}return Au(a,f,i,c,b)}var va={sha1:Aa,"sha2-256":$t,"sha2-512":Ke};function Qo(e,t,r,n,o){if(o!=="sha1"&&o!=="sha2-256"&&o!=="sha2-512"){let a=Object.keys(va).join(" / ");throw new P(`Hash '${o}' is unknown or not supported. Must be ${a}`)}let s=va[o],i=Ba(s,e,t,{c:r,dkLen:n});return Cn.encode(i).substring(1)}return Ra(Bu);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/curves/utils.js: