@libp2p/plaintext 3.0.15-2151144c3 → 3.0.15-811a29f8a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -4
- package/dist/index.min.js.map +4 -4
- package/package.json +7 -7
package/dist/index.min.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPlaintext = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PPlaintext=(()=>{var Or=Object.defineProperty;var Gi=Object.getOwnPropertyDescriptor;var ji=Object.getOwnPropertyNames;var $i=Object.prototype.hasOwnProperty;var lt=(e,t)=>{for(var r in t)Or(e,r,{get:t[r],enumerable:!0})},Zi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ji(t))!$i.call(e,o)&&o!==r&&Or(e,o,{get:()=>t[o],enumerable:!(n=Gi(t,o))||n.enumerable});return e};var zi=e=>Zi(Or({},"__esModule",{value:!0}),e);var kf={};lt(kf,{plaintext:()=>Kf});var nr=class extends Error{static name="UnexpectedPeerError";constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError"}},Te=class extends Error{static name="InvalidCryptoExchangeError";constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError"}},Z=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},fe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var ue=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var Ce=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Pr=Symbol.for("@libp2p/peer-id");var Ro=Symbol.for("@libp2p/service-capabilities");var Fr={};lt(Fr,{base58btc:()=>X,base58flickr:()=>ec});var uu=new Uint8Array(0);function Uo(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 Lt(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 Ko(e){return new TextEncoder().encode(e)}function ko(e){return new TextDecoder().decode(e)}function Yi(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 c=e.length,a=e.charAt(0),u=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function l(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 v=0,A=0,y=0,B=d.length;y!==B&&d[y]===0;)y++,v++;for(var g=(B-y)*f+1>>>0,I=new Uint8Array(g);y!==B;){for(var U=d[y],O=0,P=g-1;(U!==0||O<A)&&P!==-1;P--,O++)U+=256*I[P]>>>0,I[P]=U%c>>>0,U=U/c>>>0;if(U!==0)throw new Error("Non-zero carry");A=O,y++}for(var E=g-A;E!==g&&I[E]===0;)E++;for(var w=a.repeat(v);E<g;++E)w+=e.charAt(I[E]);return w}function x(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var v=0;if(d[v]!==" "){for(var A=0,y=0;d[v]===a;)A++,v++;for(var B=(d.length-v)*u+1>>>0,g=new Uint8Array(B);d[v];){var I=r[d.charCodeAt(v)];if(I===255)return;for(var U=0,O=B-1;(I!==0||U<y)&&O!==-1;O--,U++)I+=c*g[O]>>>0,g[O]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");y=U,v++}if(d[v]!==" "){for(var P=B-y;P!==B&&g[P]===0;)P++;for(var E=new Uint8Array(A+(B-P)),w=A;P!==B;)E[w++]=g[P++];return E}}}function m(d){var v=x(d);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:x,decode:m}}var Xi=Yi,Wi=Xi,Oo=Wi;var Hr=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")}},Mr=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 Po(this,t)}},qr=class{decoders;constructor(t){this.decoders=t}or(t){return Po(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 Po(e,t){return new qr({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Vr=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 Hr(t,r,n),this.decoder=new Mr(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function le({name:e,prefix:t,encode:r,decode:n}){return new Vr(e,t,r,n)}function Pt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Oo(r,e);return le({prefix:t,name:e,encode:n,decode:s=>Lt(o(s))})}function Ji(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let u=0;u<o;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|f,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Qi(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function tc(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function z({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=tc(n);return le({prefix:t,name:e,encode(s){return Qi(s,n,r)},decode(s){return Ji(s,o,r,e)}})}var X=Pt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ec=Pt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Gr={};lt(Gr,{base32:()=>he,base32hex:()=>sc,base32hexpad:()=>cc,base32hexpadupper:()=>ac,base32hexupper:()=>ic,base32pad:()=>nc,base32padupper:()=>oc,base32upper:()=>rc,base32z:()=>fc});var he=z({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),rc=z({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),nc=z({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),oc=z({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),sc=z({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ic=z({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),cc=z({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ac=z({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),fc=z({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var jr={};lt(jr,{base36:()=>Re,base36upper:()=>uc});var Re=Pt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),uc=Pt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var lc=qo,Ho=128,hc=127,dc=~hc,pc=Math.pow(2,31);function qo(e,t,r){t=t||[],r=r||0;for(var n=r;e>=pc;)t[r++]=e&255|Ho,e/=128;for(;e&dc;)t[r++]=e&255|Ho,e>>>=7;return t[r]=e|0,qo.bytes=r-n+1,t}var bc=$r,mc=128,Mo=127;function $r(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw $r.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Mo)<<o:(i&Mo)*Math.pow(2,o),o+=7}while(i>=mc);return $r.bytes=s-n,r}var xc=Math.pow(2,7),yc=Math.pow(2,14),gc=Math.pow(2,21),wc=Math.pow(2,28),Ec=Math.pow(2,35),Sc=Math.pow(2,42),Ac=Math.pow(2,49),vc=Math.pow(2,56),Bc=Math.pow(2,63),Ic=function(e){return e<xc?1:e<yc?2:e<gc?3:e<wc?4:e<Ec?5:e<Sc?6:e<Ac?7:e<vc?8:e<Bc?9:10},Lc={encode:lc,decode:bc,encodingLength:Ic},_c=Lc,Ue=_c;function Ke(e,t=0){return[Ue.decode(e,t),Ue.decode.bytes]}function de(e,t,r=0){return Ue.encode(e,t,r),t}function pe(e){return Ue.encodingLength(e)}function St(e,t){let r=t.byteLength,n=pe(e),o=n+pe(r),s=new Uint8Array(o+r);return de(e,s,0),de(r,s,n),s.set(t,o),new be(e,r,t,s)}function Zr(e){let t=Lt(e),[r,n]=Ke(t),[o,s]=Ke(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new be(r,o,i,t)}function Vo(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Uo(e.bytes,r.bytes)}}var be=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Fo(e,t){let{bytes:r,version:n}=e;return n===0?Tc(r,zr(e),t??X.encoder):Cc(r,zr(e),t??he.encoder)}var Go=new WeakMap;function zr(e){let t=Go.get(e);if(t==null){let r=new Map;return Go.set(e,r),r}return t}var st=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=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!==ke)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Rc)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=St(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&&Vo(t.multihash,n.multihash)}toString(t){return Fo(this,t)}toJSON(){return{"/":Fo(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??jo(n,o,s.bytes))}else if(r[Uc]===!0){let{version:n,multihash:o,code:s}=r,i=Zr(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==ke)throw new Error(`Version 0 CID must use dag-pb (code: ${ke}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=jo(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,ke,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Lt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new be(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,x]=Ke(t.subarray(r));return r+=x,l},o=n(),s=ke;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),u=r+a,f=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:f,size:u}}static parse(t,r){let[n,o]=Dc(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 zr(s).set(n,t),s}};function Dc(e,t){switch(e[0]){case"Q":{let r=t??X;return[X.prefix,r.decode(`${X.prefix}${e}`)]}case X.prefix:{let r=t??X;return[X.prefix,r.decode(e)]}case he.prefix:{let r=t??he;return[he.prefix,r.decode(e)]}case Re.prefix:{let r=t??Re;return[Re.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 Tc(e,t,r){let{prefix:n}=r;if(n!==X.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 Cc(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var ke=112,Rc=18;function jo(e,t,r){let n=pe(e),o=n+pe(t),s=new Uint8Array(o+r.byteLength);return de(e,s,0),de(t,s,n),s.set(r,o),s}var Uc=Symbol.for("@ipld/js-cid/CID");var Yr={};lt(Yr,{identity:()=>At});var $o=0,Kc="identity",Zo=Lt;function kc(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 St($o,Zo(e))}var At={code:$o,name:Kc,encode:Zo,digest:kc};function it(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function xt(e=0){return new Uint8Array(e)}function ht(e=0){return new Uint8Array(e)}function sr(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ht(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Yo=Symbol.for("@achingbrain/uint8arraylist");function zo(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 ir(e){return!!e?.[Yo]}var Q=class e{bufs;length;[Yo]=!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(ir(n))r+=n.byteLength,this.bufs.push(...n.bufs);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(ir(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=zo(this.bufs,t);return r.buf[r.index]}set(t,r){let n=zo(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(ir(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 sr(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:sr(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],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let u=t>=c&&t<a,f=r>c&&r<=a;if(u&&f){if(t===c&&r===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(f){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!ir(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 c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=a;l+=f){f=0;for(let x=u;x>=0;x--){let m=this.get(l+x);if(n[x]!==m){f=Math.max(1,x-c[m]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ht(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=xt(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=xt(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=xt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=ht(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=xt(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=xt(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=xt(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=xt(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=xt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!it(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Xr={};lt(Xr,{base10:()=>Nc});var Nc=Pt({prefix:"9",name:"base10",alphabet:"0123456789"});var Wr={};lt(Wr,{base16:()=>Oc,base16upper:()=>Pc});var Oc=z({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Pc=z({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Jr={};lt(Jr,{base2:()=>Hc});var Hc=z({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Qr={};lt(Qr,{base256emoji:()=>Gc});var Xo=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}"),Mc=Xo.reduce((e,t,r)=>(e[r]=t,e),[]),qc=Xo.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Vc(e){return e.reduce((t,r)=>(t+=Mc[r],t),"")}function Fc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=qc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Gc=le({prefix:"\u{1F680}",name:"base256emoji",encode:Vc,decode:Fc});var tn={};lt(tn,{base64:()=>jc,base64pad:()=>$c,base64url:()=>Zc,base64urlpad:()=>zc});var jc=z({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),$c=z({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Zc=z({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),zc=z({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var en={};lt(en,{base8:()=>Yc});var Yc=z({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var rn={};lt(rn,{identity:()=>Xc});var Xc=le({prefix:"\0",name:"identity",encode:e=>ko(e),decode:e=>Ko(e)});var Zu=new TextEncoder,zu=new TextDecoder;var sn={};lt(sn,{sha256:()=>cr,sha512:()=>ta});var Qc=20;function on({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new nn(e,t,r,n,o)}var nn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Qc,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?Wo(n,this.code,r?.truncate):n.then(o=>Wo(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Wo(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 St(t,e)}function Qo(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var cr=on({name:"sha2-256",code:18,encode:Qo("SHA-256")}),ta=on({name:"sha2-512",code:19,encode:Qo("SHA-512")});var cn={...rn,...Jr,...en,...Xr,...Wr,...Gr,...jr,...Fr,...tn,...Qr},il={...sn,...Yr};function es(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ts=es("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),an=es("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=ht(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),ea={utf8:ts,"utf-8":ts,hex:cn.base16,latin1:an,ascii:an,binary:an,...cn},ar=ea;function W(e,t="utf8"){let r=ar[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function Y(e,t="utf8"){let r=ar[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var ra=parseInt("11111",2),fn=parseInt("10000000",2),na=parseInt("01111111",2),rs={0:Ne,1:Ne,2:oa,3:ca,4:aa,5:ia,6:sa,16:Ne,22:Ne,48:Ne};function vt(e,t={offset:0}){let r=e[t.offset]&ra;if(t.offset++,rs[r]!=null)return rs[r](e,t);throw new Error("No decoder for tag "+r)}function Oe(e,t){let r=0;if((e[t.offset]&fn)===fn){let n=e[t.offset]&na,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 Ne(e,t){Oe(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=vt(e,t);if(n===null)break;r.push(n)}return r}function oa(e,t){let r=Oe(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 sa(e,t){let r=Oe(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 c=`${s}.${i}`,a=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let f=0;for(let l=0;l<a.length;l++)f+=a[l]<<l*7;c+=`.${f}`,a=[]}}return c}function ia(e,t){return t.offset++,null}function ca(e,t){let r=Oe(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 aa(e,t){let r=Oe(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function fa(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new Q;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function un(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=fa(e.byteLength);return new Q(Uint8Array.from([t.byteLength|fn]),t)}function dt(e){let t=new Q,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new Q(Uint8Array.from([2]),un(t),t)}function fr(e){let t=Uint8Array.from([0]),r=new Q(t,e);return new Q(Uint8Array.from([3]),un(r),r)}function Ht(e,t=48){let r=new Q;for(let n of e)r.append(n);return new Q(Uint8Array.from([t]),un(r),r)}var ns="1.2.840.10045.3.1.7",os="1.3.132.0.34",ss="1.3.132.0.35";async function is(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,t,r.subarray());return n?.signal?.throwIfAborted(),s}var ua=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),la=Uint8Array.from([6,5,43,129,4,0,34]),ha=Uint8Array.from([6,5,43,129,4,0,35]),da={ext:!0,kty:"EC",crv:"P-256"},pa={ext:!0,kty:"EC",crv:"P-384"},ba={ext:!0,kty:"EC",crv:"P-521"},ln=32,hn=48,dn=66;function cs(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===ln*2+1)return n=Y(t.subarray(r,r+ln),"base64url"),o=Y(t.subarray(r+ln),"base64url"),new xe({...da,key_ops:["verify"],x:n,y:o});if(t.byteLength===hn*2+1)return n=Y(t.subarray(r,r+hn),"base64url"),o=Y(t.subarray(r+hn),"base64url"),new xe({...pa,key_ops:["verify"],x:n,y:o});if(t.byteLength===dn*2+1)return n=Y(t.subarray(r,r+dn),"base64url"),o=Y(t.subarray(r+dn),"base64url"),new xe({...ba,key_ops:["verify"],x:n,y:o});throw new Z(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function as(e){return Ht([dt(Uint8Array.from([1])),Ht([ma(e.crv)],160),Ht([fr(new Q(Uint8Array.from([4]),W(e.x??"","base64url"),W(e.y??"","base64url")))],161)]).subarray()}function ma(e){if(e==="P-256")return ua;if(e==="P-384")return la;if(e==="P-521")return ha;throw new Z(`Invalid curve ${e}`)}var xe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=as(this.jwk)),this._raw}toMultihash(){return At.digest(ye(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(this.raw,t.raw)}async verify(t,r,n){return is(this.jwk,r,t,n)}};function Yt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Bt(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function N(e,t,r=""){let n=Yt(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function ur(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Bt(e.outputLen),Bt(e.blockLen)}function ge(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 us(e,t){N(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Dt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function lr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function yt(e,t){return e<<32-t|e>>>t}var ls=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",xa=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Tt(e){if(N(e),ls)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=xa[e[r]];return t}var _t={_0:48,_9:57,A:65,F:70,a:97,f:102};function fs(e){if(e>=_t._0&&e<=_t._9)return e-_t._0;if(e>=_t.A&&e<=_t.F)return e-(_t.A-10);if(e>=_t.a&&e<=_t.f)return e-(_t.a-10)}function Ct(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ls)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("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=fs(e.charCodeAt(s)),c=fs(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function pt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];N(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 pn(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.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function we(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var bn=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function hs(e,t,r){return e&t^~e&r}function ds(e,t,r){return e&t^e&r^t&r}var Pe=class{blockLen;outputLen;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=lr(this.buffer)}update(t){ge(this),N(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=lr(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ge(this),us(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Dt(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 c=lr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=a/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Rt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var nt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var hr=BigInt(4294967295),ps=BigInt(32);function ya(e,t=!1){return t?{h:Number(e&hr),l:Number(e>>ps&hr)}:{h:Number(e>>ps&hr)|0,l:Number(e&hr)|0}}function bs(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:c}=ya(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var mn=(e,t,r)=>e>>>r,xn=(e,t,r)=>e<<32-r|t>>>r,Xt=(e,t,r)=>e>>>r|t<<32-r,Wt=(e,t,r)=>e<<32-r|t>>>r,He=(e,t,r)=>e<<64-r|t>>>r-32,Me=(e,t,r)=>e>>>r-32|t<<64-r;function It(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ms=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),xs=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ys=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),gs=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ws=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Es=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var wa=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Mt=new Uint32Array(64),yn=class extends Pe{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){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=c|0,this.H=a|0}process(t,r){for(let l=0;l<16;l++,r+=4)Mt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let x=Mt[l-15],m=Mt[l-2],d=yt(x,7)^yt(x,18)^x>>>3,v=yt(m,17)^yt(m,19)^m>>>10;Mt[l]=v+Mt[l-7]+d+Mt[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:f}=this;for(let l=0;l<64;l++){let x=yt(c,6)^yt(c,11)^yt(c,25),m=f+x+hs(c,a,u)+wa[l]+Mt[l]|0,v=(yt(n,2)^yt(n,13)^yt(n,22))+ds(n,o,s)|0;f=u,u=a,a=c,c=i+m|0,i=s,s=o,o=n,n=m+v|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,c,a,u,f)}roundClean(){Dt(Mt)}destroy(){this.set(0,0,0,0,0,0,0,0),Dt(this.buffer)}},gn=class extends yn{A=Rt[0]|0;B=Rt[1]|0;C=Rt[2]|0;D=Rt[3]|0;E=Rt[4]|0;F=Rt[5]|0;G=Rt[6]|0;H=Rt[7]|0;constructor(){super(32)}};var Ss=bs(["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))),Ea=Ss[0],Sa=Ss[1],qt=new Uint32Array(80),Vt=new Uint32Array(80),wn=class extends Pe{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:f,Fh:l,Fl:x,Gh:m,Gl:d,Hh:v,Hl:A}=this;return[t,r,n,o,s,i,c,a,u,f,l,x,m,d,v,A]}set(t,r,n,o,s,i,c,a,u,f,l,x,m,d,v,A){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=x|0,this.Gh=m|0,this.Gl=d|0,this.Hh=v|0,this.Hl=A|0}process(t,r){for(let g=0;g<16;g++,r+=4)qt[g]=t.getUint32(r),Vt[g]=t.getUint32(r+=4);for(let g=16;g<80;g++){let I=qt[g-15]|0,U=Vt[g-15]|0,O=Xt(I,U,1)^Xt(I,U,8)^mn(I,U,7),P=Wt(I,U,1)^Wt(I,U,8)^xn(I,U,7),E=qt[g-2]|0,w=Vt[g-2]|0,K=Xt(E,w,19)^He(E,w,61)^mn(E,w,6),H=Wt(E,w,19)^Me(E,w,61)^xn(E,w,6),T=ys(P,H,Vt[g-7],Vt[g-16]),p=gs(T,O,K,qt[g-7],qt[g-16]);qt[g]=p|0,Vt[g]=T|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:f,Eh:l,El:x,Fh:m,Fl:d,Gh:v,Gl:A,Hh:y,Hl:B}=this;for(let g=0;g<80;g++){let I=Xt(l,x,14)^Xt(l,x,18)^He(l,x,41),U=Wt(l,x,14)^Wt(l,x,18)^Me(l,x,41),O=l&m^~l&v,P=x&d^~x&A,E=ws(B,U,P,Sa[g],Vt[g]),w=Es(E,y,I,O,Ea[g],qt[g]),K=E|0,H=Xt(n,o,28)^He(n,o,34)^He(n,o,39),T=Wt(n,o,28)^Me(n,o,34)^Me(n,o,39),p=n&s^n&c^s&c,b=o&i^o&a^i&a;y=v|0,B=A|0,v=m|0,A=d|0,m=l|0,d=x|0,{h:l,l:x}=It(u|0,f|0,w|0,K|0),u=c|0,f=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let h=ms(K,T,b);n=xs(h,w,H,p),o=h|0}({h:n,l:o}=It(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=It(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=It(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:f}=It(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:x}=It(this.Eh|0,this.El|0,l|0,x|0),{h:m,l:d}=It(this.Fh|0,this.Fl|0,m|0,d|0),{h:v,l:A}=It(this.Gh|0,this.Gl|0,v|0,A|0),{h:y,l:B}=It(this.Hh|0,this.Hl|0,y|0,B|0),this.set(n,o,s,i,c,a,u,f,l,x,m,d,v,A,y,B)}roundClean(){Dt(qt,Vt)}destroy(){Dt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},En=class extends wn{Ah=nt[0]|0;Al=nt[1]|0;Bh=nt[2]|0;Bl=nt[3]|0;Ch=nt[4]|0;Cl=nt[5]|0;Dh=nt[6]|0;Dl=nt[7]|0;Eh=nt[8]|0;El=nt[9]|0;Fh=nt[10]|0;Fl=nt[11]|0;Gh=nt[12]|0;Gl=nt[13]|0;Hh=nt[14]|0;Hl=nt[15]|0;constructor(){super(64)}};var As=pn(()=>new gn,bn(1));var vs=pn(()=>new En,bn(3));var An=BigInt(0),Sn=BigInt(1);function Ut(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function Bs(e){if(typeof e=="bigint"){if(!dr(e))throw new Error("positive bigint expected, got "+e)}else Bt(e);return e}function qe(e){let t=Bs(e).toString(16);return t.length&1?"0"+t:t}function Is(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?An:BigInt("0x"+e)}function Ee(e){return Is(Tt(e))}function Jt(e){return Is(Tt(br(N(e)).reverse()))}function pr(e,t){Bt(t),e=Bs(e);let r=Ct(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function vn(e,t){return pr(e,t).reverse()}function br(e){return Uint8Array.from(e)}var dr=e=>typeof e=="bigint"&&An<=e;function Aa(e,t,r){return dr(e)&&dr(t)&&dr(r)&&t<=e&&e<r}function Ve(e,t,r,n){if(!Aa(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Bn(e){let t;for(t=0;e>An;e>>=Sn,t+=1);return t}var Fe=e=>(Sn<<BigInt(e))-Sn;function Ls(e,t,r){if(Bt(e,"hashLen"),Bt(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=A=>new Uint8Array(A),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),c=1e3,a=n(e),u=n(e),f=0,l=()=>{a.fill(1),u.fill(0),f=0},x=(...A)=>r(u,pt(a,...A)),m=(A=o)=>{u=x(s,A),a=x(),A.length!==0&&(u=x(i,A),a=x())},d=()=>{if(f++>=c)throw new Error("drbg: tried max amount of iterations");let A=0,y=[];for(;A<t;){a=x();let B=a.slice();y.push(B),A+=a.length}return pt(...y)};return(A,y)=>{l(),m(A);let B;for(;!(B=y(d()));)m();return l(),B}}function Ft(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(s,i,c){let a=e[s];if(c&&a===void 0)return;let u=typeof a;if(u!==i||a===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([c,a])=>n(c,a,i));o(t,!1),o(r,!0)}function Se(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var ut=BigInt(0),tt=BigInt(1),Qt=BigInt(2),Ts=BigInt(3),Cs=BigInt(4),Rs=BigInt(5),va=BigInt(7),Us=BigInt(8),Ba=BigInt(9),Ks=BigInt(16);function J(e,t){let r=e%t;return r>=ut?r:t+r}function F(e,t,r){let n=e;for(;t-- >ut;)n*=n,n%=r;return n}function _s(e,t){if(e===ut)throw new Error("invert: expected non-zero number");if(t<=ut)throw new Error("invert: expected positive modulus, got "+t);let r=J(e,t),n=t,o=ut,s=tt,i=tt,c=ut;for(;r!==ut;){let u=n/r,f=n%r,l=o-i*u,x=s-c*u;n=r,r=f,o=i,s=c,i=l,c=x}if(n!==tt)throw new Error("invert: does not exist");return J(o,t)}function Ln(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function ks(e,t){let r=(e.ORDER+tt)/Cs,n=e.pow(t,r);return Ln(e,n,t),n}function Ia(e,t){let r=(e.ORDER-Rs)/Us,n=e.mul(t,Qt),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,Qt),o),c=e.mul(s,e.sub(i,e.ONE));return Ln(e,c,t),c}function La(e){let t=Ae(e),r=Ns(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+va)/Ks;return(c,a)=>{let u=c.pow(a,i),f=c.mul(u,n),l=c.mul(u,o),x=c.mul(u,s),m=c.eql(c.sqr(f),a),d=c.eql(c.sqr(l),a);u=c.cmov(u,f,m),f=c.cmov(x,l,d);let v=c.eql(c.sqr(f),a),A=c.cmov(u,f,v);return Ln(c,A,a),A}}function Ns(e){if(e<Ts)throw new Error("sqrt is not defined for small field");let t=e-tt,r=0;for(;t%Qt===ut;)t/=Qt,r++;let n=Qt,o=Ae(e);for(;Ds(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ks;let s=o.pow(n,t),i=(t+tt)/Qt;return function(a,u){if(a.is0(u))return u;if(Ds(a,u)!==1)throw new Error("Cannot find square root");let f=r,l=a.mul(a.ONE,s),x=a.pow(u,t),m=a.pow(u,i);for(;!a.eql(x,a.ONE);){if(a.is0(x))return a.ZERO;let d=1,v=a.sqr(x);for(;!a.eql(v,a.ONE);)if(d++,v=a.sqr(v),d===f)throw new Error("Cannot find square root");let A=tt<<BigInt(f-d-1),y=a.pow(l,A);f=d,l=a.sqr(y),x=a.mul(x,l),m=a.mul(m,y)}return m}}function _a(e){return e%Cs===Ts?ks:e%Us===Rs?Ia:e%Ks===Ba?La(e):Ns(e)}var Os=(e,t)=>(J(e,t)&tt)===tt,Da=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function _n(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Da.reduce((n,o)=>(n[o]="function",n),t);return Ft(e,r),e}function Ta(e,t,r){if(r<ut)throw new Error("invalid exponent, negatives unsupported");if(r===ut)return e.ONE;if(r===tt)return t;let n=e.ONE,o=t;for(;r>ut;)r&tt&&(n=e.mul(n,o)),o=e.sqr(o),r>>=tt;return n}function Ge(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function Ds(e,t){let r=(e.ORDER-tt)/Qt,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Ca(e,t){t!==void 0&&Bt(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var In=class{ORDER;BITS;BYTES;isLE;ZERO=ut;ONE=tt;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=ut)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=Ca(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return J(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return ut<=t&&t<this.ORDER}is0(t){return t===ut}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&tt)===tt}neg(t){return J(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return J(t*t,this.ORDER)}add(t,r){return J(t+r,this.ORDER)}sub(t,r){return J(t-r,this.ORDER)}mul(t,r){return J(t*r,this.ORDER)}pow(t,r){return Ta(this,t,r)}div(t,r){return J(t*_s(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 _s(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=_a(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?vn(t,this.BYTES):pr(t,this.BYTES)}fromBytes(t,r=!1){N(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:c}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(o);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let a=s?Jt(t):Ee(t);if(c&&(a=J(a,i)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(t){return Ge(this,t)}cmov(t,r,n){return n?r:t}};function Ae(e,t={}){return new In(e,t)}function Ps(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Dn(e){let t=Ps(e);return t+Math.ceil(t/2)}function Tn(e,t,r=!1){N(e);let n=e.length,o=Ps(t),s=Dn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Jt(e):Ee(e),c=J(i,t-tt)+tt;return r?vn(c,o):pr(c,o)}var ve=BigInt(0),te=BigInt(1);function je(e,t){let r=t.negate();return e?r:t}function ee(e,t){let r=Ge(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Vs(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Cn(e,t){Vs(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Fe(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Hs(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=te);let u=t*n,f=u+Math.abs(c)-1,l=c===0,x=c<0,m=t%2!==0;return{nextN:a,offset:f,isZero:l,isNeg:x,isNegF:m,offsetF:u}}var Rn=new WeakMap,Fs=new WeakMap;function Un(e){return Fs.get(e)||1}function Ms(e){if(e!==ve)throw new Error("invalid wNAF")}var Be=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>ve;)r&te&&(n=n.add(o)),o=o.double(),r>>=te;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Cn(r,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let u=1;u<o;u++)c=c.add(i),s.push(c);i=c.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=Cn(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:u,isZero:f,isNeg:l,isNegF:x,offsetF:m}=Hs(n,c,i);n=a,f?s=s.add(je(x,r[m])):o=o.add(je(l,r[u]))}return Ms(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Cn(t,this.bits);for(let i=0;i<s.windows&&n!==ve;i++){let{nextN:c,offset:a,isZero:u,isNeg:f}=Hs(n,i,s);if(n=c,!u){let l=r[a];o=o.add(f?l.negate():l)}}return Ms(n),o}getPrecomputes(t,r,n){let o=Rn.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Rn.set(r,o))),o}cached(t,r,n){let o=Un(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Un(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Vs(r,this.bits),Fs.set(t,r),Rn.delete(t)}hasCache(t){return Un(t)!==1}};function Gs(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>ve||n>ve;)r&te&&(s=s.add(o)),n&te&&(i=i.add(o)),o=o.double(),r>>=te,n>>=te;return{p1:s,p2:i}}function qs(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return _n(t),t}else return Ae(e,{isLE:r})}function mr(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 a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>ve))throw new Error(`CURVE.${a} must be positive bigint`)}let o=qs(t.p,r.Fp,n),s=qs(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function xr(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Gt=BigInt(0),et=BigInt(1),Kn=BigInt(2),Ra=BigInt(8);function Ua(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function js(e,t={}){let r=mr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;Ft(t,{},{uvRatio:"function"});let c=Kn<<BigInt(o.BYTES*8)-et,a=A=>n.create(A),u=t.uvRatio||((A,y)=>{try{return{isValid:!0,value:n.sqrt(n.div(A,y))}}catch{return{isValid:!1,value:Gt}}});if(!Ua(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function f(A,y,B=!1){let g=B?et:Gt;return Ve("coordinate "+A,y,g,c),y}function l(A){if(!(A instanceof d))throw new Error("EdwardsPoint expected")}let x=Se((A,y)=>{let{X:B,Y:g,Z:I}=A,U=A.is0();y==null&&(y=U?Ra:n.inv(I));let O=a(B*y),P=a(g*y),E=n.mul(I,y);if(U)return{x:Gt,y:et};if(E!==et)throw new Error("invZ was invalid");return{x:O,y:P}}),m=Se(A=>{let{a:y,d:B}=s;if(A.is0())throw new Error("bad point: ZERO");let{X:g,Y:I,Z:U,T:O}=A,P=a(g*g),E=a(I*I),w=a(U*U),K=a(w*w),H=a(P*y),T=a(w*a(H+E)),p=a(K+a(B*a(P*E)));if(T!==p)throw new Error("bad point: equation left != right (1)");let b=a(g*I),h=a(U*O);if(b!==h)throw new Error("bad point: equation left != right (2)");return!0});class d{static BASE=new d(s.Gx,s.Gy,et,a(s.Gx*s.Gy));static ZERO=new d(Gt,et,et,Gt);static Fp=n;static Fn=o;X;Y;Z;T;constructor(y,B,g,I){this.X=f("x",y),this.Y=f("y",B),this.Z=f("z",g,!0),this.T=f("t",I),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){if(y instanceof d)throw new Error("extended point not allowed");let{x:B,y:g}=y||{};return f("x",B),f("y",g),new d(B,g,et,a(B*g))}static fromBytes(y,B=!1){let g=n.BYTES,{a:I,d:U}=s;y=br(N(y,g,"point")),Ut(B,"zip215");let O=br(y),P=y[g-1];O[g-1]=P&-129;let E=Jt(O),w=B?c:n.ORDER;Ve("point.y",E,Gt,w);let K=a(E*E),H=a(K-et),T=a(U*K-I),{isValid:p,value:b}=u(H,T);if(!p)throw new Error("bad point: invalid y coordinate");let h=(b&et)===et,S=(P&128)!==0;if(!B&&b===Gt&&S)throw new Error("bad point: x=0 and x_0=1");return S!==h&&(b=a(-b)),d.fromAffine({x:b,y:E})}static fromHex(y,B=!1){return d.fromBytes(Ct(y),B)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,B=!0){return v.createCache(this,y),B||this.multiply(Kn),this}assertValidity(){m(this)}equals(y){l(y);let{X:B,Y:g,Z:I}=this,{X:U,Y:O,Z:P}=y,E=a(B*P),w=a(U*I),K=a(g*P),H=a(O*I);return E===w&&K===H}is0(){return this.equals(d.ZERO)}negate(){return new d(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:y}=s,{X:B,Y:g,Z:I}=this,U=a(B*B),O=a(g*g),P=a(Kn*a(I*I)),E=a(y*U),w=B+g,K=a(a(w*w)-U-O),H=E+O,T=H-P,p=E-O,b=a(K*T),h=a(H*p),S=a(K*p),L=a(T*H);return new d(b,h,L,S)}add(y){l(y);let{a:B,d:g}=s,{X:I,Y:U,Z:O,T:P}=this,{X:E,Y:w,Z:K,T:H}=y,T=a(I*E),p=a(U*w),b=a(P*g*H),h=a(O*K),S=a((I+U)*(E+w)-T-p),L=h-b,D=h+b,C=a(p-B*T),_=a(S*L),R=a(D*C),k=a(S*C),G=a(L*D);return new d(_,R,G,k)}subtract(y){return this.add(y.negate())}multiply(y){if(!o.isValidNot0(y))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:B,f:g}=v.cached(this,y,I=>ee(d,I));return ee(d,[B,g])[0]}multiplyUnsafe(y,B=d.ZERO){if(!o.isValid(y))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return y===Gt?d.ZERO:this.is0()||y===et?this:v.unsafe(this,y,g=>ee(d,g),B)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return v.unsafe(this,s.n).is0()}toAffine(y){return x(this,y)}clearCofactor(){return i===et?this:this.multiplyUnsafe(i)}toBytes(){let{x:y,y:B}=this.toAffine(),g=n.toBytes(B);return g[g.length-1]|=y&et?128:0,g}toHex(){return Tt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let v=new Be(d,o.BITS);return d.BASE.precompute(8),d}function $s(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');Ft(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,c=r.randomBytes||we,a=r.adjustScalarBytes||(E=>E),u=r.domain||((E,w,K)=>{if(Ut(K,"phflag"),w.length||K)throw new Error("Contexts/pre-hash are not supported");return E});function f(E){return i.create(Jt(E))}function l(E){let w=g.secretKey;N(E,g.secretKey,"secretKey");let K=N(t(E),2*w,"hashedSecretKey"),H=a(K.slice(0,w)),T=K.slice(w,2*w),p=f(H);return{head:H,prefix:T,scalar:p}}function x(E){let{head:w,prefix:K,scalar:H}=l(E),T=o.multiply(H),p=T.toBytes();return{head:w,prefix:K,scalar:H,point:T,pointBytes:p}}function m(E){return x(E).pointBytes}function d(E=Uint8Array.of(),...w){let K=pt(...w);return f(t(u(K,N(E,void 0,"context"),!!n)))}function v(E,w,K={}){E=N(E,void 0,"message"),n&&(E=n(E));let{prefix:H,scalar:T,pointBytes:p}=x(w),b=d(K.context,H,E),h=o.multiply(b).toBytes(),S=d(K.context,h,p,E),L=i.create(b+S*T);if(!i.isValid(L))throw new Error("sign failed: invalid s");let D=pt(h,i.toBytes(L));return N(D,g.signature,"result")}let A={zip215:!0};function y(E,w,K,H=A){let{context:T,zip215:p}=H,b=g.signature;E=N(E,b,"signature"),w=N(w,void 0,"message"),K=N(K,g.publicKey,"publicKey"),p!==void 0&&Ut(p,"zip215"),n&&(w=n(w));let h=b/2,S=E.subarray(0,h),L=Jt(E.subarray(h,b)),D,C,_;try{D=e.fromBytes(K,p),C=e.fromBytes(S,p),_=o.multiplyUnsafe(L)}catch{return!1}if(!p&&D.isSmallOrder())return!1;let R=d(T,C.toBytes(),D.toBytes(),w);return C.add(D.multiplyUnsafe(R)).subtract(_).clearCofactor().is0()}let B=s.BYTES,g={secretKey:B,publicKey:B,signature:2*B,seed:B};function I(E=c(g.seed)){return N(E,g.seed,"seed")}function U(E){return Yt(E)&&E.length===i.BYTES}function O(E,w){try{return!!e.fromBytes(E,w)}catch{return!1}}let P={getExtendedPublicKey:x,randomSecretKey:I,isValidSecretKey:U,isValidPublicKey:O,toMontgomery(E){let{y:w}=e.fromBytes(E),K=g.publicKey,H=K===32;if(!H&&K!==57)throw new Error("only defined for 25519 and 448");let T=H?s.div(et+w,et-w):s.div(w-et,w+et);return s.toBytes(T)},toMontgomerySecret(E){let w=g.secretKey;N(E,w);let K=t(E.subarray(0,w));return a(K).subarray(0,w)}};return Object.freeze({keygen:xr(I,m),getPublicKey:m,sign:v,verify:y,utils:P,Point:e,lengths:g})}var Ka=BigInt(1),Zs=BigInt(2);var ka=BigInt(5),Na=BigInt(8),kn=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Oa={p:kn,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Na,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Pa(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=kn,c=e*e%s*e%s,a=F(c,Zs,s)*c%s,u=F(a,Ka,s)*e%s,f=F(u,ka,s)*u%s,l=F(f,t,s)*f%s,x=F(l,r,s)*l%s,m=F(x,n,s)*x%s,d=F(m,o,s)*m%s,v=F(d,o,s)*m%s,A=F(v,t,s)*f%s;return{pow_p_5_8:F(A,Zs,s)*e%s,b2:c}}function Ha(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var zs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Ma(e,t){let r=kn,n=J(t*t*t,r),o=J(n*n*t,r),s=Pa(e*o).pow_p_5_8,i=J(e*n*s,r),c=J(t*i*i,r),a=i,u=J(i*zs,r),f=c===e,l=c===J(-e,r),x=c===J(-e*zs,r);return f&&(i=a),(l||x)&&(i=u),Os(i,r)&&(i=J(-i,r)),{isValid:f||l,value:i}}var qa=js(Oa,{uvRatio:Ma});function Va(e){return $s(qa,vs,Object.assign({adjustScalarBytes:Ha},e))}var Ys=Va({});var $e=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},yr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Xs={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new yr("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 mt=Xs;var Ie=32;var Nn,Fa=(async()=>{try{return await mt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Ga(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await mt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await mt.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function ja(e,t,r){return Ys.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Ws(e,t,r){return Nn==null&&(Nn=await Fa),Nn?Ga(e,t,r):ja(e,t,r)}function gr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var wr=class{type="Ed25519";raw;constructor(t){this.raw=On(t,Ie)}toMultihash(){return At.digest(ye(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Ws(this.raw,r,t);return gr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ti(e){return e=On(e,Ie),new wr(e)}function On(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new Z(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var $a=Math.pow(2,7),Za=Math.pow(2,14),za=Math.pow(2,21),Pn=Math.pow(2,28),Hn=Math.pow(2,35),Mn=Math.pow(2,42),qn=Math.pow(2,49),q=128,ct=127;function Kt(e){if(e<$a)return 1;if(e<Za)return 2;if(e<za)return 3;if(e<Pn)return 4;if(e<Hn)return 5;if(e<Mn)return 6;if(e<qn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Vn(e,t,r=0){switch(Kt(e)){case 8:t[r++]=e&255|q,e/=128;case 7:t[r++]=e&255|q,e/=128;case 6:t[r++]=e&255|q,e/=128;case 5:t[r++]=e&255|q,e/=128;case 4:t[r++]=e&255|q,e>>>=7;case 3:t[r++]=e&255|q,e>>>=7;case 2:t[r++]=e&255|q,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Ya(e,t,r=0){switch(Kt(e)){case 8:t.set(r++,e&255|q),e/=128;case 7:t.set(r++,e&255|q),e/=128;case 6:t.set(r++,e&255|q),e/=128;case 5:t.set(r++,e&255|q),e/=128;case 4:t.set(r++,e&255|q),e>>>=7;case 3:t.set(r++,e&255|q),e>>>=7;case 2:t.set(r++,e&255|q),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Fn(e,t){let r=e[t],n=0;if(n+=r&ct,r<q||(r=e[t+1],n+=(r&ct)<<7,r<q)||(r=e[t+2],n+=(r&ct)<<14,r<q)||(r=e[t+3],n+=(r&ct)<<21,r<q)||(r=e[t+4],n+=(r&ct)*Pn,r<q)||(r=e[t+5],n+=(r&ct)*Hn,r<q)||(r=e[t+6],n+=(r&ct)*Mn,r<q)||(r=e[t+7],n+=(r&ct)*qn,r<q))return n;throw new RangeError("Could not decode varint")}function Xa(e,t){let r=e.get(t),n=0;if(n+=r&ct,r<q||(r=e.get(t+1),n+=(r&ct)<<7,r<q)||(r=e.get(t+2),n+=(r&ct)<<14,r<q)||(r=e.get(t+3),n+=(r&ct)<<21,r<q)||(r=e.get(t+4),n+=(r&ct)*Pn,r<q)||(r=e.get(t+5),n+=(r&ct)*Hn,r<q)||(r=e.get(t+6),n+=(r&ct)*Mn,r<q)||(r=e.get(t+7),n+=(r&ct)*qn,r<q))return n;throw new RangeError("Could not decode varint")}function ei(e,t,r=0){return t==null&&(t=ht(Kt(e))),t instanceof Uint8Array?Vn(e,t,r):Ya(e,t,r)}function ri(e,t=0){return e instanceof Uint8Array?Fn(e,t):Xa(e,t)}var Gn=new Float32Array([-0]),jt=new Uint8Array(Gn.buffer);function ni(e,t,r){Gn[0]=e,t[r]=jt[0],t[r+1]=jt[1],t[r+2]=jt[2],t[r+3]=jt[3]}function oi(e,t){return jt[0]=e[t],jt[1]=e[t+1],jt[2]=e[t+2],jt[3]=e[t+3],Gn[0]}var jn=new Float64Array([-0]),at=new Uint8Array(jn.buffer);function si(e,t,r){jn[0]=e,t[r]=at[0],t[r+1]=at[1],t[r+2]=at[2],t[r+3]=at[3],t[r+4]=at[4],t[r+5]=at[5],t[r+6]=at[6],t[r+7]=at[7]}function ii(e,t){return at[0]=e[t],at[1]=e[t+1],at[2]=e[t+2],at[3]=e[t+3],at[4]=e[t+4],at[5]=e[t+5],at[6]=e[t+6],at[7]=e[t+7],jn[0]}var Ja=BigInt(Number.MAX_SAFE_INTEGER),Qa=BigInt(Number.MIN_SAFE_INTEGER),bt=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 re;if(t<Ja&&t>Qa)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>ci&&(o=0n,++n>ci&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return re;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):re}},re=new bt(0,0);re.toBigInt=function(){return 0n};re.zzEncode=re.zzDecode=function(){return this};re.length=function(){return 1};var ci=4294967296n;function ai(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 fi(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&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 $n(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 gt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Er(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Zn=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=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,gt(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 gt(this,4);return Er(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw gt(this,4);return Er(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw gt(this,4);let t=oi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw gt(this,4);let t=ii(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 gt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return fi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw gt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw gt(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 bt(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 gt(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 gt(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 gt(this,8);let t=Er(this.buf,this.pos+=4),r=Er(this.buf,this.pos+=4);return new bt(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=Fn(this.buf,this.pos);return this.pos+=Kt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Ze(e){return new Zn(e instanceof Uint8Array?e:e.subarray())}function ne(e,t,r){let n=Ze(e);return t.decode(n,void 0,r)}function zn(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return ht(i);o+i>t&&(n=ht(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var oe=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Yn(){}var Wn=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},tf=zn();function ef(e){return globalThis.Buffer!=null?ht(e):tf(e)}var Ye=class{len;head;tail;states;constructor(){this.len=0,this.head=new oe(Yn,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new oe(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Jn((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Sr,10,bt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=bt.fromBigInt(t);return this._push(Sr,r.length(),r)}uint64Number(t){return this._push(Vn,Kt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=bt.fromBigInt(t).zzEncode();return this._push(Sr,r.length(),r)}sint64Number(t){let r=bt.fromNumber(t).zzEncode();return this._push(Sr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Xn,1,t?1:0)}fixed32(t){return this._push(ze,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=bt.fromBigInt(t);return this._push(ze,4,r.lo)._push(ze,4,r.hi)}fixed64Number(t){let r=bt.fromNumber(t);return this._push(ze,4,r.lo)._push(ze,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(ni,4,t)}double(t){return this._push(si,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Xn,1,0):this.uint32(r)._push(nf,r,t)}string(t){let r=ai(t);return r!==0?this.uint32(r)._push($n,r,t):this._push(Xn,1,0)}fork(){return this.states=new Wn(this),this.head=this.tail=new oe(Yn,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 oe(Yn,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=ef(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Xn(e,t,r){t[r]=e&255}function rf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Jn=class extends oe{next;constructor(t,r){super(rf,t,r),this.next=void 0}};function Sr(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 ze(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 nf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Ye.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(of,t,e),this},Ye.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(sf,t,e),this});function of(e,t,r){t.set(e,r)}function sf(e,t,r){e.length<40?$n(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(W(e),r)}function Qn(){return new Ye}function se(e,t){let r=Qn();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*ie(e,t,r){let n=Ze(e);yield*t.stream(n,void 0,"$",r)}var Ar={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function vr(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function Xe(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,c){let a=t(i);c.int32(a)},n=function(i){let c=i.int32();return t(c)},o=function*(i){let c=i.int32();yield t(c)};return vr("enum",Ar.VARINT,r,n,o)}function ce(e,t,r){return vr("message",Ar.LENGTH_DELIMITED,e,t,r)}var ft;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(ft||(ft={}));var to;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(to||(to={}));(function(e){e.codec=()=>Xe(to)})(ft||(ft={}));var $t;(function(e){let t;e.codec=()=>(t==null&&(t=ce((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ft.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.Type=ft.codec().decode(s);break}case 2:{a.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return a},function*(s,i,c,a={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${c}.Type`,value:ft.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return se(s,e.codec())}e.encode=r;function n(s,i){return ne(s,e.codec(),i)}e.decode=n;function o(s,i){return ie(s,e.codec(),i)}e.stream=o})($t||($t={}));var eo;(function(e){let t;e.codec=()=>(t==null&&(t=ce((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ft.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.Type=ft.codec().decode(s);break}case 2:{a.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return a},function*(s,i,c,a={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${c}.Type`,value:ft.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return se(s,e.codec())}e.encode=r;function n(s,i){return ne(s,e.codec(),i)}e.decode=n;function o(s,i){return ie(s,e.codec(),i)}e.stream=o})(eo||(eo={}));function cf(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function ro(e,t,r=""){let n=cf(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`,u=i+"expected Uint8Array"+c+", got "+a;throw n?new RangeError(u):new TypeError(u)}return e}function no(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 hi(e,t){ro(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 We(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Br(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function wt(e,t){return e<<32-t|e>>>t}function di(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)}var pi=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});var Qe={};lt(Qe,{MAX_RSA_KEY_SIZE:()=>io,generateRSAKeyPair:()=>Ei,jwkToJWKKeyPair:()=>Si,jwkToPkcs1:()=>hf,jwkToPkix:()=>uo,jwkToRSAPrivateKey:()=>ho,pkcs1MessageToJwk:()=>ao,pkcs1MessageToRSAPrivateKey:()=>lo,pkcs1ToJwk:()=>lf,pkcs1ToRSAPrivateKey:()=>gi,pkixMessageToJwk:()=>fo,pkixMessageToRSAPublicKey:()=>_r,pkixToJwk:()=>df,pkixToRSAPublicKey:()=>wi});function bi(e,t,r){return e&t^~e&r}function mi(e,t,r){return e&t^e&r^t&r}var Ir=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=Br(this.buffer)}update(t){no(this),ro(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Br(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){no(this),hi(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,We(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 c=Br(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=a/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},kt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var af=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),oo=class extends Ir{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){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=c|0,this.H=a|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 x=Zt[l-15],m=Zt[l-2],d=wt(x,7)^wt(x,18)^x>>>3,v=wt(m,17)^wt(m,19)^m>>>10;Zt[l]=v+Zt[l-7]+d+Zt[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:f}=this;for(let l=0;l<64;l++){let x=wt(c,6)^wt(c,11)^wt(c,25),m=f+x+bi(c,a,u)+af[l]+Zt[l]|0,v=(wt(n,2)^wt(n,13)^wt(n,22))+mi(n,o,s)|0;f=u,u=a,a=c,c=i+m|0,i=s,s=o,o=n,n=m+v|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,c,a,u,f)}roundClean(){We(Zt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),We(this.buffer)}},so=class extends oo{A=kt[0]|0;B=kt[1]|0;C=kt[2]|0;D=kt[3]|0;E=kt[4]|0;F=kt[5]|0;G=kt[6]|0;H=kt[7]|0;constructor(){super(32)}};var Lr=di(()=>new so,pi(1));var Le=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Qe.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return st.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(this.raw,t.raw)}verify(t,r,n){return yi(this.jwk,r,t,n)}},Je=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Qe.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(this.raw,t.raw)}sign(t,r){return xi(this.jwk,t,r)}};var io=8192,co=18,ff=1062,uf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function lf(e){let t=vt(e);return ao(t)}function ao(e){return{n:Y(e[1],"base64url"),e:Y(e[2],"base64url"),d:Y(e[3],"base64url"),p:Y(e[4],"base64url"),q:Y(e[5],"base64url"),dp:Y(e[6],"base64url"),dq:Y(e[7],"base64url"),qi:Y(e[8],"base64url"),kty:"RSA"}}function hf(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 Z("JWK was missing components");return Ht([dt(Uint8Array.from([0])),dt(W(e.n,"base64url")),dt(W(e.e,"base64url")),dt(W(e.d,"base64url")),dt(W(e.p,"base64url")),dt(W(e.q,"base64url")),dt(W(e.dp,"base64url")),dt(W(e.dq,"base64url")),dt(W(e.qi,"base64url"))]).subarray()}function df(e){let t=vt(e,{offset:0});return fo(t)}function fo(e){let t=vt(e[1],{offset:0});return{kty:"RSA",n:Y(t[0],"base64url"),e:Y(t[1],"base64url")}}function uo(e){if(e.n==null||e.e==null)throw new Z("JWK was missing components");return Ht([uf,fr(Ht([dt(W(e.n,"base64url")),dt(W(e.e,"base64url"))]))]).subarray()}function gi(e){let t=vt(e);return lo(t)}function lo(e){let t=ao(e);return ho(t)}function wi(e,t){if(e.byteLength>=ff)throw new fe("Key size is too large");let r=vt(e,{offset:0});return _r(r,e,t)}function _r(e,t,r){let n=fo(e);if(r==null){let o=Lr($t.encode({Type:ft.RSA,Data:t}));r=St(co,o)}return new Le(n,r)}function ho(e){if(vi(e)>io)throw new Z("Key size is too large");let t=Si(e),r=Lr($t.encode({Type:ft.RSA,Data:uo(t.publicKey)})),n=St(co,r);return new Je(t.privateKey,new Le(t.publicKey,n))}async function Ei(e){if(e>io)throw new Z("Key size is too large");let t=await Ai(e),r=Lr($t.encode({Type:ft.RSA,Data:uo(t.publicKey)})),n=St(co,r);return new Je(t.privateKey,new Le(t.publicKey,n))}function Si(e){if(e==null)throw new Z("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var Bi="1.2.840.113549.1.1.1";async function Ai(e,t){let r=await mt.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 pf(r,t);return{privateKey:n[0],publicKey:n[1]}}async function xi(e,t,r){let n=await mt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await mt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function yi(e,t,r,n){let o=await mt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await mt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function pf(e,t){if(e.privateKey==null||e.publicKey==null)throw new Z("Private and public key are required");let r=await Promise.all([mt.get().subtle.exportKey("jwk",e.privateKey),mt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function vi(e){if(e.kty!=="RSA")throw new Z("invalid key type");if(e.n==null)throw new Z("invalid key modulus");return W(e.n,"base64url").length*8}var Dr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(ur(t),N(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),Dt(o)}update(t){return ge(this),this.iHash.update(t),this}digestInto(t){ge(this),N(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),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:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},po=(e,t,r)=>new Dr(e,t).update(r).digest();po.create=(e,t)=>new Dr(e,t);var Ii=(e,t)=>(e+(e>=0?t:-t)/Li)/t;function bf(e,t,r){let[[n,o],[s,i]]=t,c=Ii(i*e,r),a=Ii(-o*e,r),u=e-c*n-a*s,f=-c*o-a*i,l=u<Nt,x=f<Nt;l&&(u=-u),x&&(f=-f);let m=Fe(Math.ceil(Bn(r)/2))+_e;if(u<Nt||u>=m||f<Nt||f>=m)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:u,k2neg:x,k2:f}}function mo(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function bo(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Ut(r.lowS,"lowS"),Ut(r.prehash,"prehash"),r.format!==void 0&&mo(r.format),r}var xo=class extends Error{constructor(t=""){super(t)}},zt={Err:xo,_tlv:{encode:(e,t)=>{let{Err:r}=zt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=qe(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?qe(o.length/2|128):"";return qe(e)+s+o+t},decode(e,t){let{Err:r}=zt,n=0;if(e<0||e>256)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 a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=zt;if(e<Nt)throw new t("integer: negative integers are not allowed");let r=qe(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}=zt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Ee(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=zt,o=N(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:c,l:a}=n.decode(2,s),{v:u,l:f}=n.decode(2,a);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=zt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Nt=BigInt(0),_e=BigInt(1),Li=BigInt(2),Tr=BigInt(3),mf=BigInt(4);function _i(e,t={}){let r=mr("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;Ft(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Ti(n,o);function f(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(T,p,b){let{x:h,y:S}=p.toAffine(),L=n.toBytes(h);if(Ut(b,"isCompressed"),b){f();let D=!n.isOdd(S);return pt(Di(D),L)}else return pt(Uint8Array.of(4),L,n.toBytes(S))}function x(T){N(T,void 0,"Point");let{publicKey:p,publicKeyUncompressed:b}=u,h=T.length,S=T[0],L=T.subarray(1);if(h===p&&(S===2||S===3)){let D=n.fromBytes(L);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let C=v(D),_;try{_=n.sqrt(C)}catch(G){let V=G instanceof Error?": "+G.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}f();let R=n.isOdd(_);return(S&1)===1!==R&&(_=n.neg(_)),{x:D,y:_}}else if(h===b&&S===4){let D=n.BYTES,C=n.fromBytes(L.subarray(0,D)),_=n.fromBytes(L.subarray(D,D*2));if(!A(C,_))throw new Error("bad point: is not on curve");return{x:C,y:_}}else throw new Error(`bad point: got length ${h}, expected compressed=${p} or uncompressed=${b}`)}let m=t.toBytes||l,d=t.fromBytes||x;function v(T){let p=n.sqr(T),b=n.mul(p,T);return n.add(n.add(b,n.mul(T,s.a)),s.b)}function A(T,p){let b=n.sqr(p),h=v(T);return n.eql(b,h)}if(!A(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let y=n.mul(n.pow(s.a,Tr),mf),B=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(y,B)))throw new Error("bad curve params: a or b");function g(T,p,b=!1){if(!n.isValid(p)||b&&n.is0(p))throw new Error(`bad point coordinate ${T}`);return p}function I(T){if(!(T instanceof w))throw new Error("Weierstrass Point expected")}function U(T){if(!a||!a.basises)throw new Error("no endo");return bf(T,a.basises,o.ORDER)}let O=Se((T,p)=>{let{X:b,Y:h,Z:S}=T;if(n.eql(S,n.ONE))return{x:b,y:h};let L=T.is0();p==null&&(p=L?n.ONE:n.inv(S));let D=n.mul(b,p),C=n.mul(h,p),_=n.mul(S,p);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(_,n.ONE))throw new Error("invZ was invalid");return{x:D,y:C}}),P=Se(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:p,y:b}=T.toAffine();if(!n.isValid(p)||!n.isValid(b))throw new Error("bad point: x or y not field elements");if(!A(p,b))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function E(T,p,b,h,S){return b=new w(n.mul(b.X,T),b.Y,b.Z),p=je(h,p),b=je(S,b),p.add(b)}class w{static BASE=new w(s.Gx,s.Gy,n.ONE);static ZERO=new w(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(p,b,h){this.X=g("x",p),this.Y=g("y",b,!0),this.Z=g("z",h),Object.freeze(this)}static CURVE(){return s}static fromAffine(p){let{x:b,y:h}=p||{};if(!p||!n.isValid(b)||!n.isValid(h))throw new Error("invalid affine point");if(p instanceof w)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(h)?w.ZERO:new w(b,h,n.ONE)}static fromBytes(p){let b=w.fromAffine(d(N(p,void 0,"point")));return b.assertValidity(),b}static fromHex(p){return w.fromBytes(Ct(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,b=!0){return H.createCache(this,p),b||this.multiply(Tr),this}assertValidity(){P(this)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){I(p);let{X:b,Y:h,Z:S}=this,{X:L,Y:D,Z:C}=p,_=n.eql(n.mul(b,C),n.mul(L,S)),R=n.eql(n.mul(h,C),n.mul(D,S));return _&&R}negate(){return new w(this.X,n.neg(this.Y),this.Z)}double(){let{a:p,b}=s,h=n.mul(b,Tr),{X:S,Y:L,Z:D}=this,C=n.ZERO,_=n.ZERO,R=n.ZERO,k=n.mul(S,S),G=n.mul(L,L),V=n.mul(D,D),M=n.mul(S,L);return M=n.add(M,M),R=n.mul(S,D),R=n.add(R,R),C=n.mul(p,R),_=n.mul(h,V),_=n.add(C,_),C=n.sub(G,_),_=n.add(G,_),_=n.mul(C,_),C=n.mul(M,C),R=n.mul(h,R),V=n.mul(p,V),M=n.sub(k,V),M=n.mul(p,M),M=n.add(M,R),R=n.add(k,k),k=n.add(R,k),k=n.add(k,V),k=n.mul(k,M),_=n.add(_,k),V=n.mul(L,D),V=n.add(V,V),k=n.mul(V,M),C=n.sub(C,k),R=n.mul(V,G),R=n.add(R,R),R=n.add(R,R),new w(C,_,R)}add(p){I(p);let{X:b,Y:h,Z:S}=this,{X:L,Y:D,Z:C}=p,_=n.ZERO,R=n.ZERO,k=n.ZERO,G=s.a,V=n.mul(s.b,Tr),M=n.mul(b,L),j=n.mul(h,D),rt=n.mul(S,C),Et=n.add(b,h),$=n.add(L,D);Et=n.mul(Et,$),$=n.add(M,j),Et=n.sub(Et,$),$=n.add(b,S);let ot=n.add(L,C);return $=n.mul($,ot),ot=n.add(M,rt),$=n.sub($,ot),ot=n.add(h,S),_=n.add(D,C),ot=n.mul(ot,_),_=n.add(j,rt),ot=n.sub(ot,_),k=n.mul(G,$),_=n.mul(V,rt),k=n.add(_,k),_=n.sub(j,k),k=n.add(j,k),R=n.mul(_,k),j=n.add(M,M),j=n.add(j,M),rt=n.mul(G,rt),$=n.mul(V,$),j=n.add(j,rt),rt=n.sub(M,rt),rt=n.mul(G,rt),$=n.add($,rt),M=n.mul(j,$),R=n.add(R,M),M=n.mul(ot,$),_=n.mul(Et,_),_=n.sub(_,M),M=n.mul(Et,j),k=n.mul(ot,k),k=n.add(k,M),new w(_,R,k)}subtract(p){return this.add(p.negate())}is0(){return this.equals(w.ZERO)}multiply(p){let{endo:b}=t;if(!o.isValidNot0(p))throw new Error("invalid scalar: out of range");let h,S,L=D=>H.cached(this,D,C=>ee(w,C));if(b){let{k1neg:D,k1:C,k2neg:_,k2:R}=U(p),{p:k,f:G}=L(C),{p:V,f:M}=L(R);S=G.add(M),h=E(b.beta,k,V,D,_)}else{let{p:D,f:C}=L(p);h=D,S=C}return ee(w,[h,S])[0]}multiplyUnsafe(p){let{endo:b}=t,h=this;if(!o.isValid(p))throw new Error("invalid scalar: out of range");if(p===Nt||h.is0())return w.ZERO;if(p===_e)return h;if(H.hasCache(this))return this.multiply(p);if(b){let{k1neg:S,k1:L,k2neg:D,k2:C}=U(p),{p1:_,p2:R}=Gs(w,h,L,C);return E(b.beta,_,R,S,D)}else return H.unsafe(h,p)}toAffine(p){return O(this,p)}isTorsionFree(){let{isTorsionFree:p}=t;return i===_e?!0:p?p(w,this):H.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:p}=t;return i===_e?this:p?p(w,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(p=!0){return Ut(p,"isCompressed"),this.assertValidity(),m(w,this,p)}toHex(p=!0){return Tt(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let K=o.BITS,H=new Be(w,t.endo?Math.ceil(K/2):K);return w.BASE.precompute(8),w}function Di(e){return Uint8Array.of(e?2:3)}function Ti(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function xf(e,t={}){let{Fn:r}=e,n=t.randomBytes||we,o=Object.assign(Ti(e.Fp,r),{seed:Dn(r.ORDER)});function s(m){try{let d=r.fromBytes(m);return r.isValidNot0(d)}catch{return!1}}function i(m,d){let{publicKey:v,publicKeyUncompressed:A}=o;try{let y=m.length;return d===!0&&y!==v||d===!1&&y!==A?!1:!!e.fromBytes(m)}catch{return!1}}function c(m=n(o.seed)){return Tn(N(m,o.seed,"seed"),r.ORDER)}function a(m,d=!0){return e.BASE.multiply(r.fromBytes(m)).toBytes(d)}function u(m){let{secretKey:d,publicKey:v,publicKeyUncompressed:A}=o;if(!Yt(m)||"_lengths"in r&&r._lengths||d===v)return;let y=N(m,void 0,"key").length;return y===v||y===A}function f(m,d,v=!0){if(u(m)===!0)throw new Error("first arg must be private key");if(u(d)===!1)throw new Error("second arg must be public key");let A=r.fromBytes(m);return e.fromBytes(d).multiply(A).toBytes(v)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c},x=xr(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:f,keygen:x,Point:e,utils:l,lengths:o})}function Ci(e,t,r={}){ur(t),Ft(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||we,o=r.hmac||((b,h)=>po(t,b,h)),{Fp:s,Fn:i}=e,{ORDER:c,BITS:a}=i,{keygen:u,getPublicKey:f,getSharedSecret:l,utils:x,lengths:m}=xf(e,r),d={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},v=c*Li<s.ORDER;function A(b){let h=c>>_e;return b>h}function y(b,h){if(!i.isValidNot0(h))throw new Error(`invalid signature ${b}: out of range 1..Point.Fn.ORDER`);return h}function B(){if(v)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function g(b,h){mo(h);let S=m.signature,L=h==="compact"?S:h==="recovered"?S+1:void 0;return N(b,L)}class I{r;s;recovery;constructor(h,S,L){if(this.r=y("r",h),this.s=y("s",S),L!=null){if(B(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(h,S=d.format){g(h,S);let L;if(S==="der"){let{r:R,s:k}=zt.toSig(N(h));return new I(R,k)}S==="recovered"&&(L=h[0],S="compact",h=h.subarray(1));let D=m.signature/2,C=h.subarray(0,D),_=h.subarray(D,D*2);return new I(i.fromBytes(C),i.fromBytes(_),L)}static fromHex(h,S){return this.fromBytes(Ct(h),S)}assertRecovery(){let{recovery:h}=this;if(h==null)throw new Error("invalid recovery id: must be present");return h}addRecoveryBit(h){return new I(this.r,this.s,h)}recoverPublicKey(h){let{r:S,s:L}=this,D=this.assertRecovery(),C=D===2||D===3?S+c:S;if(!s.isValid(C))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let _=s.toBytes(C),R=e.fromBytes(pt(Di((D&1)===0),_)),k=i.inv(C),G=O(N(h,void 0,"msgHash")),V=i.create(-G*k),M=i.create(L*k),j=e.BASE.multiplyUnsafe(V).add(R.multiplyUnsafe(M));if(j.is0())throw new Error("invalid recovery: point at infinify");return j.assertValidity(),j}hasHighS(){return A(this.s)}toBytes(h=d.format){if(mo(h),h==="der")return Ct(zt.hexFromSig(this));let{r:S,s:L}=this,D=i.toBytes(S),C=i.toBytes(L);return h==="recovered"?(B(),pt(Uint8Array.of(this.assertRecovery()),D,C)):pt(D,C)}toHex(h){return Tt(this.toBytes(h))}}let U=r.bits2int||function(h){if(h.length>8192)throw new Error("input is too large");let S=Ee(h),L=h.length*8-a;return L>0?S>>BigInt(L):S},O=r.bits2int_modN||function(h){return i.create(U(h))},P=Fe(a);function E(b){return Ve("num < 2^"+a,b,Nt,P),i.toBytes(b)}function w(b,h){return N(b,void 0,"message"),h?N(t(b),void 0,"prehashed message"):b}function K(b,h,S){let{lowS:L,prehash:D,extraEntropy:C}=bo(S,d);b=w(b,D);let _=O(b),R=i.fromBytes(h);if(!i.isValidNot0(R))throw new Error("invalid private key");let k=[E(R),E(_)];if(C!=null&&C!==!1){let j=C===!0?n(m.secretKey):C;k.push(N(j,void 0,"extraEntropy"))}let G=pt(...k),V=_;function M(j){let rt=U(j);if(!i.isValidNot0(rt))return;let Et=i.inv(rt),$=e.BASE.multiply(rt).toAffine(),ot=i.create($.x);if(ot===Nt)return;let rr=i.create(Et*i.create(V+ot*R));if(rr===Nt)return;let To=($.x===ot?0:2)|Number($.y&_e),Co=rr;return L&&A(rr)&&(Co=i.neg(rr),To^=1),new I(ot,Co,v?void 0:To)}return{seed:G,k2sig:M}}function H(b,h,S={}){let{seed:L,k2sig:D}=K(b,h,S);return Ls(t.outputLen,i.BYTES,o)(L,D).toBytes(S.format)}function T(b,h,S,L={}){let{lowS:D,prehash:C,format:_}=bo(L,d);if(S=N(S,void 0,"publicKey"),h=w(h,C),!Yt(b)){let R=b instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+R)}g(b,_);try{let R=I.fromBytes(b,_),k=e.fromBytes(S);if(D&&R.hasHighS())return!1;let{r:G,s:V}=R,M=O(h),j=i.inv(V),rt=i.create(M*j),Et=i.create(G*j),$=e.BASE.multiplyUnsafe(rt).add(k.multiplyUnsafe(Et));return $.is0()?!1:i.create($.x)===G}catch{return!1}}function p(b,h,S={}){let{prehash:L}=bo(S,d);return h=w(h,L),I.fromBytes(b,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:u,getPublicKey:f,getSharedSecret:l,utils:x,lengths:m,Point:e,sign:H,verify:T,recoverPublicKey:p,Signature:I,hash:t})}var go={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},yf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ri=BigInt(2);function gf(e){let t=go.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=F(f,r,t)*f%t,x=F(l,r,t)*f%t,m=F(x,Ri,t)*u%t,d=F(m,o,t)*m%t,v=F(d,s,t)*d%t,A=F(v,c,t)*v%t,y=F(A,a,t)*A%t,B=F(y,c,t)*v%t,g=F(B,r,t)*f%t,I=F(g,i,t)*d%t,U=F(I,n,t)*u%t,O=F(U,Ri,t);if(!yo.eql(yo.sqr(O),e))throw new Error("Cannot find square root");return O}var yo=Ae(go.p,{sqrt:gf}),wf=_i(go,{Fp:yo,endo:yf}),De=Ci(wf,As);var Ui=33;function Ki(e,t,r,n){let o=cr.digest(r instanceof Uint8Array?r:r.subarray());if(gr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),De.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new $e(String(s))});try{return n?.signal?.throwIfAborted(),De.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new $e(String(s))}}var Cr=class{type="secp256k1";raw;_key;constructor(t){this._key=Ni(t),this.raw=ki(this._key)}toMultihash(){return At.digest(ye(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(this.raw,t.raw)}verify(t,r,n){return Ki(this._key,r,t,n)}};function Oi(e){return new Cr(e)}function ki(e){return De.Point.fromBytes(e).toBytes()}function Ni(e){try{return De.Point.fromBytes(e),e}catch(t){throw new fe(String(t))}}function Pi(e){if(e.byteLength===Ie)return ti(e);if(e.byteLength===Ui)return Oi(e);let t=vt(e),r=t[1]?.[0];if(r===ns||r===os||r===ss)return cs(t);if(t[0]?.[0]===Bi)return _r(t,e);throw new Z("Could not extract public key from raw bytes")}function ye(e){return $t.encode({Type:ft[e.type],Data:e.raw})}var Hi=Symbol.for("nodejs.util.inspect.custom"),Ef=114,tr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Pr]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return st.createV1(Ef,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return it(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return it(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Hi](){return`PeerId(${this.toString()})`}},Rr=class extends tr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Ur=class extends tr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Kr=class extends tr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Sf=2336,wo=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=At.digest(W(this.url))}[Hi](){return`PeerId(${this.url})`}[Pr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return st.createV1(Sf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=Y(t)),t.toString()===this.toString())}};function Mi(e){if(e.type==="Ed25519")return new Ur({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Kr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Rr({multihash:e.toCID().multihash,publicKey:e});throw new Ce}var Eo=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},qi=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function So(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,c,a,f=new Promise((l,x)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){x(qi(i));return}if(i&&(a=()=>{x(qi(i))},i.addEventListener("abort",a,{once:!0})),e.then(l,x),r===Number.POSITIVE_INFINITY)return;let m=new Eo;c=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(d){x(d)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?l():o instanceof Error?x(o):(m.message=o??`Promise timed out after ${r} milliseconds`,x(m))},r)}).finally(()=>{f.clear(),a&&i&&i.removeEventListener("abort",a)});return f.clear=()=>{s.clearTimeout.call(void 0,c),c=void 0},f}var Af=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function vf(e,t,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let c=[t].flat(),a=[],{addListener:u,removeListener:f}=Af(e),l=async(...m)=>{let d=r.multiArgs?m:m[0];if(r.filter)try{if(!await r.filter(d))return}catch(v){n(),i(v);return}a.push(d),r.count===a.length&&(n(),s(a))},x=(...m)=>{n(),i(r.rejectionMultiArgs?m:m[0])};n=()=>{for(let m of c)f(m,l);for(let m of r.rejectionEvents)c.includes(m)||f(m,x)};for(let m of c)u(m,l);for(let m of r.rejectionEvents)c.includes(m)||u(m,x);r.signal&&r.signal.addEventListener("abort",()=>{x(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(a)});if(o.cancel=n,typeof r.timeout=="number"){let s=So(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Vi(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=vf(e,t,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var ae=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Bf(e){return e.reason}async function Ao(e,t,r){if(t==null)return e;let n=r?.translateError??Bf;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var Lf=4194304,kr=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Bo=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Io=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Lo=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function _f(e){return typeof e?.closeRead=="function"}function Df(e){return typeof e?.close=="function"}function vo(e){return _f(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:Df(e)?e.status!=="open":!1}function Tf(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function Cf(e,t){let r=t?.maxBufferSize??Lf,n=new Q,o,s=!1;if(!Tf(e))throw new Z("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>r){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${r}`))}o?.resolve()};e.addEventListener("message",i);let c=f=>{f.error!=null?o?.reject(f.error):o?.resolve()};e.addEventListener("close",c);let a=()=>{o?.resolve()};e.addEventListener("remoteCloseWrite",a);let u={readBuffer:n,async read(f){if(s===!0)throw new kr("Stream was unwrapped");if(vo(e)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new ae(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let l=f?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await Ao(o.promise,f?.signal),vo(e)){if(n.byteLength===0&&f?.bytes==null)return null;break}o=Promise.withResolvers()}let x=f?.bytes??n.byteLength;if(n.byteLength<x){if(vo(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,x),new ae(`Unexpected EOF - stream closed while reading ${n.byteLength}/${x} bytes`);return u.read(f)}let m=n.sublist(0,x);return n.consume(x),m},async write(f,l){if(s===!0)throw new kr("Stream was unwrapped");e.send(f)||await Vi(e,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",i),e.removeEventListener("close",c),e.removeEventListener("remoteCloseWrite",a),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e}};return u}function Rf(e,t={}){let r=Cf(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Kt(t.maxDataLength));let n=t?.lengthDecoder??ri,o=t?.lengthEncoder??ei;return{async read(i){let c=-1,a=new Q;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;a.append(f);try{c=n(a)}catch(l){if(l instanceof RangeError)continue;throw l}if(c<0)throw new Bo("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new Lo(`Message length length too long - ${a.byteLength} > ${t.maxLengthLength}`);if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new Io(`Message length too long - ${c} > ${t.maxDataLength}`);let u=await r.read({...i,bytes:c});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",c),new ae(`Unexpected EOF - tried to read ${c} bytes but the stream closed`);if(u.byteLength!==c)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,c),new ae(`Unexpected EOF - read ${u.byteLength}/${c} bytes before the stream closed`);return u},async write(i,c){await r.write(new Q(o(i.byteLength),i),c)},async writeV(i,c){let a=new Q(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(a,c)},unwrap(){return r.unwrap()}}}function Fi(e,t){let r=Rf(e,t),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(c=>s.encode(c)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var Nr;(function(e){let t;e.codec=()=>(t==null&&(t=ce((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.id!=null&&(i.uint32(10),i.bytes(s.id)),s.pubkey!=null&&(i.uint32(18),er.codec().encode(s.pubkey,i)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.id=s.bytes();break}case 2:{a.pubkey=er.codec().decode(s,s.uint32(),{limits:c.limits?.pubkey});break}default:{s.skipType(f&7);break}}}return a},function*(s,i,c,a={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${c}.id`,value:s.bytes()};break}case 2:{yield*er.codec().stream(s,s.uint32(),`${c}.pubkey`,{limits:a.limits?.pubkey});break}default:{s.skipType(f&7);break}}}})),t);function r(s){return se(s,e.codec())}e.encode=r;function n(s,i){return ne(s,e.codec(),i)}e.decode=n;function o(s,i){return ie(s,e.codec(),i)}e.stream=o})(Nr||(Nr={}));var Ot;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(Ot||(Ot={}));var _o;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(_o||(_o={}));(function(e){e.codec=()=>Xe(_o)})(Ot||(Ot={}));var er;(function(e){let t;e.codec=()=>(t==null&&(t=ce((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),Ot.codec().encode(s.Type,i)),s.Data!=null&&s.Data.byteLength>0&&(i.uint32(18),i.bytes(s.Data)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={Data:xt(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.Type=Ot.codec().decode(s);break}case 2:{a.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return a},function*(s,i,c,a={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${c}.Type`,value:Ot.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return se(s,e.codec())}e.encode=r;function n(s,i){return ne(s,e.codec(),i)}e.decode=n;function o(s,i){return ie(s,e.codec(),i)}e.stream=o})(er||(er={}));var Uf="/plaintext/2.0.0",Do=class{protocol=Uf;privateKey;log;constructor(t){this.privateKey=t.privateKey,this.log=t.logger.forComponent("libp2p:plaintext")}[Symbol.toStringTag]="@libp2p/plaintext";[Ro]=["@libp2p/connection-encryption"];async secureInbound(t,r){return this._encrypt(t,r)}async secureOutbound(t,r){return this._encrypt(t,r)}async _encrypt(t,r){let n=t.log?.newScope("plaintext")??this.log,o=Fi(t).pb(Nr);n("write pubkey exchange to peer %p",r?.remotePeer);let s=this.privateKey.publicKey;await o.write({id:s.toMultihash().bytes,pubkey:{Type:Ot[s.type],Data:s.raw}},r);let i=await o.read(r),c;try{if(i.pubkey==null)throw new ue("Public key missing");if(i.pubkey.Data.byteLength===0)throw new ue("Public key data too short");if(i.id==null)throw new ue("Remote id missing");let a=Pi(i.pubkey.Data);if(c=Mi(a),!it(c.toMultihash().bytes,i.id))throw new Te("Public key did not match id")}catch(a){throw n.error("invalid public key - %e",a),new Te(`Invalid public key - ${a.message}`)}if(r?.remotePeer!=null&&!c.equals(r?.remotePeer))throw new nr;return n("plaintext key exchange completed successfully with peer %p",c),{connection:o.unwrap().unwrap(),remotePeer:c}}};function Kf(){return e=>new Do(e)}return zi(kf);})();
|
|
2
|
+
"use strict";var Libp2PPlaintext=(()=>{var Xr=Object.defineProperty;var ea=Object.getOwnPropertyDescriptor;var ra=Object.getOwnPropertyNames;var na=Object.prototype.hasOwnProperty;var ht=(e,t)=>{for(var r in t)Xr(e,r,{get:t[r],enumerable:!0})},oa=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ra(t))!na.call(e,o)&&o!==r&&Xr(e,o,{get:()=>t[o],enumerable:!(n=ea(t,o))||n.enumerable});return e};var sa=e=>oa(Xr({},"__esModule",{value:!0}),e);var Gf={};ht(Gf,{plaintext:()=>$f});var hr=class extends Error{static name="UnexpectedPeerError";constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError"}},ke=class extends Error{static name="InvalidCryptoExchangeError";constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError"}},j=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},de=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var pe=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var Pe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Wr=Symbol.for("@libp2p/peer-id");var Zo=Symbol.for("@libp2p/service-capabilities");var rn={};ht(rn,{base58btc:()=>G,base58flickr:()=>ha});var Au=new Uint8Array(0);function Yo(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 Dt(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 $o(e){return new TextEncoder().encode(e)}function Go(e){return new TextDecoder().decode(e)}function ia(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 l(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var E=0,p=0,w=0,v=b.length;w!==v&&b[w]===0;)w++,E++;for(var B=(v-w)*u+1>>>0,D=new Uint8Array(B);w!==v;){for(var _=b[w],F=0,C=B-1;(_!==0||F<p)&&C!==-1;C--,F++)_+=256*D[C]>>>0,D[C]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");p=F,w++}for(var L=B-p;L!==B&&D[L]===0;)L++;for(var K=f.repeat(E);L<B;++L)K+=e.charAt(D[L]);return K}function m(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var E=0;if(b[E]!==" "){for(var p=0,w=0;b[E]===f;)p++,E++;for(var v=(b.length-E)*c+1>>>0,B=new Uint8Array(v);b[E];){var D=r[b.charCodeAt(E)];if(D===255)return;for(var _=0,F=v-1;(D!==0||_<w)&&F!==-1;F--,_++)D+=a*B[F]>>>0,B[F]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");w=_,E++}if(b[E]!==" "){for(var C=v-w;C!==v&&B[C]===0;)C++;for(var L=new Uint8Array(p+(v-C)),K=p;C!==v;)L[K++]=B[C++];return L}}}function d(b){var E=m(b);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:m,decode:d}}var aa=ia,ca=aa,Wo=ca;var Jr=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Qr=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Jo(this,t)}},tn=class{decoders;constructor(t){this.decoders=t}or(t){return Jo(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Jo(e,t){return new tn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var en=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Jr(t,r,n),this.decoder=new Qr(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function me({name:e,prefix:t,encode:r,decode:n}){return new en(e,t,r,n)}function Nt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Wo(r,e);return me({prefix:t,name:e,encode:n,decode:s=>Dt(o(s))})}function fa(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 ua(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 la(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function z({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=la(n);return me({prefix:t,name:e,encode(s){return ua(s,n,r)},decode(s){return fa(s,o,r,e)}})}var G=Nt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ha=Nt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var nn={};ht(nn,{base32:()=>ye,base32hex:()=>ya,base32hexpad:()=>ga,base32hexpadupper:()=>xa,base32hexupper:()=>ba,base32pad:()=>pa,base32padupper:()=>ma,base32upper:()=>da,base32z:()=>wa});var ye=z({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),da=z({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),pa=z({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ma=z({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ya=z({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ba=z({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ga=z({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),xa=z({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),wa=z({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var on={};ht(on,{base36:()=>Ne,base36upper:()=>Ea});var Ne=Nt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ea=Nt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Sa=es,Qo=128,va=127,Aa=~va,Ba=Math.pow(2,31);function es(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Ba;)t[r++]=e&255|Qo,e/=128;for(;e&Aa;)t[r++]=e&255|Qo,e>>>=7;return t[r]=e|0,es.bytes=r-n+1,t}var Ia=sn,La=128,ts=127;function sn(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw sn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&ts)<<o:(i&ts)*Math.pow(2,o),o+=7}while(i>=La);return sn.bytes=s-n,r}var Ta=Math.pow(2,7),_a=Math.pow(2,14),Ra=Math.pow(2,21),Da=Math.pow(2,28),Ca=Math.pow(2,35),Oa=Math.pow(2,42),Fa=Math.pow(2,49),Ka=Math.pow(2,56),Ua=Math.pow(2,63),ka=function(e){return e<Ta?1:e<_a?2:e<Ra?3:e<Da?4:e<Ca?5:e<Oa?6:e<Fa?7:e<Ka?8:e<Ua?9:10},Pa={encode:Sa,decode:Ia,encodingLength:ka},Na=Pa,Me=Na;function qe(e,t=0){return[Me.decode(e,t),Me.decode.bytes]}function be(e,t,r=0){return Me.encode(e,t,r),t}function ge(e){return Me.encodingLength(e)}function Bt(e,t){let r=t.byteLength,n=ge(e),o=n+ge(r),s=new Uint8Array(o+r);return be(e,s,0),be(r,s,n),s.set(t,o),new xe(e,r,t,s)}function an(e){let t=Dt(e),[r,n]=qe(t),[o,s]=qe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new xe(r,o,i,t)}function rs(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Yo(e.bytes,r.bytes)}}var xe=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function ns(e,t){let{bytes:r,version:n}=e;return n===0?qa(r,cn(e),t??G.encoder):Ha(r,cn(e),t??ye.encoder)}var os=new WeakMap;function cn(e){let t=os.get(e);if(t==null){let r=new Map;return os.set(e,r),r}return t}var it=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=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!==He)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Va)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=Bt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&rs(t.multihash,n.multihash)}toString(t){return ns(this,t)}toJSON(){return{"/":ns(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??ss(n,o,s.bytes))}else if(r[ja]===!0){let{version:n,multihash:o,code:s}=r,i=an(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!==He)throw new Error(`Version 0 CID must use dag-pb (code: ${He}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=ss(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,He,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=Dt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new xe(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,m]=qe(t.subarray(r));return r+=m,l},o=n(),s=He;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]=Ma(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 cn(s).set(n,t),s}};function Ma(e,t){switch(e[0]){case"Q":{let r=t??G;return[G.prefix,r.decode(`${G.prefix}${e}`)]}case G.prefix:{let r=t??G;return[G.prefix,r.decode(e)]}case ye.prefix:{let r=t??ye;return[ye.prefix,r.decode(e)]}case Ne.prefix:{let r=t??Ne;return[Ne.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function qa(e,t,r){let{prefix:n}=r;if(n!==G.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 Ha(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 He=112,Va=18;function ss(e,t,r){let n=ge(e),o=n+ge(t),s=new Uint8Array(o+r.byteLength);return be(e,s,0),be(t,s,n),s.set(r,o),s}var ja=Symbol.for("@ipld/js-cid/CID");var fn={};ht(fn,{identity:()=>It});var is=0,za="identity",as=Dt;function Za(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 Bt(is,as(e))}var It={code:is,name:za,encode:as,digest:Za};function at(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 gt(e=0){return new Uint8Array(e)}function dt(e=0){return new Uint8Array(e)}function pr(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=dt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var fs=Symbol.for("@achingbrain/uint8arraylist");function cs(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 mr(e){return!!e?.[fs]}var rt=class e{bufs;length;[fs]=!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(mr(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(mr(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=cs(this.bufs,t);return r.buf[r.index]}set(t,r){let n=cs(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(mr(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 pr(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:pr(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(!mr(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 m=c;m>=0;m--){let d=this.get(l+m);if(n[m]!==d){u=Math.max(1,m-a[d]);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=dt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=gt(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=gt(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=gt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=dt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=gt(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=gt(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=gt(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=gt(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=gt(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(!at(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 un={};ht(un,{base10:()=>Ya});var Ya=Nt({prefix:"9",name:"base10",alphabet:"0123456789"});var ln={};ht(ln,{base16:()=>$a,base16upper:()=>Ga});var $a=z({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ga=z({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var hn={};ht(hn,{base2:()=>Xa});var Xa=z({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var dn={};ht(dn,{base256emoji:()=>ec});var us=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Wa=us.reduce((e,t,r)=>(e[r]=t,e),[]),Ja=us.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Qa(e){return e.reduce((t,r)=>(t+=Wa[r],t),"")}function tc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ja[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var ec=me({prefix:"\u{1F680}",name:"base256emoji",encode:Qa,decode:tc});var pn={};ht(pn,{base64:()=>rc,base64pad:()=>nc,base64url:()=>oc,base64urlpad:()=>sc});var rc=z({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),nc=z({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),oc=z({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),sc=z({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var mn={};ht(mn,{base8:()=>ic});var ic=z({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var yn={};ht(yn,{identity:()=>ac});var ac=me({prefix:"\0",name:"identity",encode:e=>Go(e),decode:e=>$o(e)});var al=new TextEncoder,cl=new TextDecoder;var xn={};ht(xn,{sha256:()=>yr,sha512:()=>lc});var uc=20;function gn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new bn(e,t,r,n,o)}var bn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??uc,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?ls(n,this.code,r?.truncate):n.then(o=>ls(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ls(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 Bt(t,e)}function ds(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var yr=gn({name:"sha2-256",code:18,encode:ds("SHA-256")}),lc=gn({name:"sha2-512",code:19,encode:ds("SHA-512")});var wn={...yn,...hn,...mn,...un,...ln,...nn,...on,...rn,...pn,...dn},wl={...xn,...fn};function ms(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ps=ms("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),En=ms("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=dt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),hc={utf8:ps,"utf-8":ps,hex:wn.base16,latin1:En,ascii:En,binary:En,...wn},br=hc;function X(e,t="utf8"){let r=br[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function Z(e,t="utf8"){let r=br[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var dc=parseInt("11111",2),Sn=parseInt("10000000",2),pc=parseInt("01111111",2),ys={0:Ve,1:Ve,2:mc,3:gc,4:xc,5:bc,6:yc,16:Ve,22:Ve,48:Ve};function Lt(e,t={offset:0}){let r=e[t.offset]&dc;if(t.offset++,ys[r]!=null)return ys[r](e,t);throw new Error("No decoder for tag "+r)}function je(e,t){let r=0;if((e[t.offset]&Sn)===Sn){let n=e[t.offset]&pc,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 Ve(e,t){je(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Lt(e,t);if(n===null)break;r.push(n)}return r}function mc(e,t){let r=je(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function yc(e,t){let r=je(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,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 bc(e,t){return t.offset++,null}function gc(e,t){let r=je(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function xc(e,t){let r=je(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function wc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new rt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function vn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=wc(e.byteLength);return new rt(Uint8Array.from([t.byteLength|Sn]),t)}function pt(e){let t=new rt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new rt(Uint8Array.from([2]),vn(t),t)}function gr(e){let t=Uint8Array.from([0]),r=new rt(t,e);return new rt(Uint8Array.from([3]),vn(r),r)}function Mt(e,t=48){let r=new rt;for(let n of e)r.append(n);return new rt(Uint8Array.from([t]),vn(r),r)}var bs="1.2.840.10045.3.1.7",gs="1.3.132.0.34",xs="1.3.132.0.35";async function ws(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,t,r.subarray());return n?.signal?.throwIfAborted(),s}var Ec=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Sc=Uint8Array.from([6,5,43,129,4,0,34]),vc=Uint8Array.from([6,5,43,129,4,0,35]),Ac={ext:!0,kty:"EC",crv:"P-256"},Bc={ext:!0,kty:"EC",crv:"P-384"},Ic={ext:!0,kty:"EC",crv:"P-521"},An=32,Bn=48,In=66;function Es(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===An*2+1)return n=Z(t.subarray(r,r+An),"base64url"),o=Z(t.subarray(r+An),"base64url"),new Ee({...Ac,key_ops:["verify"],x:n,y:o});if(t.byteLength===Bn*2+1)return n=Z(t.subarray(r,r+Bn),"base64url"),o=Z(t.subarray(r+Bn),"base64url"),new Ee({...Bc,key_ops:["verify"],x:n,y:o});if(t.byteLength===In*2+1)return n=Z(t.subarray(r,r+In),"base64url"),o=Z(t.subarray(r+In),"base64url"),new Ee({...Ic,key_ops:["verify"],x:n,y:o});throw new j(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ss(e){return Mt([pt(Uint8Array.from([1])),Mt([Lc(e.crv)],160),Mt([gr(new rt(Uint8Array.from([4]),X(e.x??"","base64url"),X(e.y??"","base64url")))],161)]).subarray()}function Lc(e){if(e==="P-256")return Ec;if(e==="P-384")return Sc;if(e==="P-521")return vc;throw new j(`Invalid curve ${e}`)}var Ee=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ss(this.jwk)),this._raw}toMultihash(){return It.digest(Se(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}async verify(t,r,n){return ws(this.jwk,r,t,n)}};function Ln(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function qt(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=Ln(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 xr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(qt(e.outputLen),qt(e.blockLen),e.outputLen<1)throw new Error('"outputLen" must be >= 1');if(e.blockLen<1)throw new Error('"blockLen" must be >= 1')}function ve(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 Ot(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Er(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function xt(e,t){return e<<32-t|e>>>t}var As=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Tc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Sr(e){if(mt(e),As)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Tc[e[r]];return t}var Ct={_0:48,_9:57,A:65,F:70,a:97,f:102};function vs(e){if(e>=Ct._0&&e<=Ct._9)return e-Ct._0;if(e>=Ct.A&&e<=Ct.F)return e-(Ct.A-10);if(e>=Ct.a&&e<=Ct.f)return e-(Ct.a-10)}function ze(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(As)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=vs(e.charCodeAt(s)),a=vs(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 Tn(...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 _n(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 Bs(e=32){qt(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 Rn=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Is(e,t,r){return e&t^~e&r}function Ls(e,t,r){return e&t^e&r^t&r}var Ze=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=Er(this.buffer)}update(t){ve(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=Er(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){ve(this),wr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Ot(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=Er(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()}},Ft=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ot=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var vr=BigInt(4294967295),Ts=BigInt(32);function _c(e,t=!1){return t?{h:Number(e&vr),l:Number(e>>Ts&vr)}:{h:Number(e>>Ts&vr)|0,l:Number(e&vr)|0}}function _s(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}=_c(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Dn=(e,t,r)=>e>>>r,Cn=(e,t,r)=>e<<32-r|t>>>r,Jt=(e,t,r)=>e>>>r|t<<32-r,Qt=(e,t,r)=>e<<32-r|t>>>r,Ye=(e,t,r)=>e<<64-r|t>>>r-32,$e=(e,t,r)=>e>>>r-32|t<<64-r;function Tt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Rs=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Ds=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Cs=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Os=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Fs=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Ks=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Dc=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]),Ht=new Uint32Array(64),On=class extends Ze{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)Ht[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let m=Ht[l-15],d=Ht[l-2],b=xt(m,7)^xt(m,18)^m>>>3,E=xt(d,17)^xt(d,19)^d>>>10;Ht[l]=E+Ht[l-7]+b+Ht[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 m=xt(a,6)^xt(a,11)^xt(a,25),d=u+m+Is(a,f,c)+Dc[l]+Ht[l]|0,E=(xt(n,2)^xt(n,13)^xt(n,22))+Ls(n,o,s)|0;u=c,c=f,f=a,a=i+d|0,i=s,s=o,o=n,n=d+E|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(){Ot(Ht)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ot(this.buffer)}},Fn=class extends On{A=Ft[0]|0;B=Ft[1]|0;C=Ft[2]|0;D=Ft[3]|0;E=Ft[4]|0;F=Ft[5]|0;G=Ft[6]|0;H=Ft[7]|0;constructor(){super(32)}};var Us=_s(["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))),Cc=Us[0],Oc=Us[1],Vt=new Uint32Array(80),jt=new Uint32Array(80),Kn=class extends Ze{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:m,Gh:d,Gl:b,Hh:E,Hl:p}=this;return[t,r,n,o,s,i,a,f,c,u,l,m,d,b,E,p]}set(t,r,n,o,s,i,a,f,c,u,l,m,d,b,E,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=l|0,this.Fl=m|0,this.Gh=d|0,this.Gl=b|0,this.Hh=E|0,this.Hl=p|0}process(t,r){for(let B=0;B<16;B++,r+=4)Vt[B]=t.getUint32(r),jt[B]=t.getUint32(r+=4);for(let B=16;B<80;B++){let D=Vt[B-15]|0,_=jt[B-15]|0,F=Jt(D,_,1)^Jt(D,_,8)^Dn(D,_,7),C=Qt(D,_,1)^Qt(D,_,8)^Cn(D,_,7),L=Vt[B-2]|0,K=jt[B-2]|0,H=Jt(L,K,19)^Ye(L,K,61)^Dn(L,K,6),U=Qt(L,K,19)^$e(L,K,61)^Cn(L,K,6),h=Cs(C,U,jt[B-7],jt[B-16]),y=Os(h,F,H,Vt[B-7],Vt[B-16]);Vt[B]=y|0,jt[B]=h|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:f,Dh:c,Dl:u,Eh:l,El:m,Fh:d,Fl:b,Gh:E,Gl:p,Hh:w,Hl:v}=this;for(let B=0;B<80;B++){let D=Jt(l,m,14)^Jt(l,m,18)^Ye(l,m,41),_=Qt(l,m,14)^Qt(l,m,18)^$e(l,m,41),F=l&d^~l&E,C=m&b^~m&p,L=Fs(v,_,C,Oc[B],jt[B]),K=Ks(L,w,D,F,Cc[B],Vt[B]),H=L|0,U=Jt(n,o,28)^Ye(n,o,34)^Ye(n,o,39),h=Qt(n,o,28)^$e(n,o,34)^$e(n,o,39),y=n&s^n&a^s&a,S=o&i^o&f^i&f;w=E|0,v=p|0,E=d|0,p=b|0,d=l|0,b=m|0,{h:l,l:m}=Tt(c|0,u|0,K|0,H|0),c=a|0,u=f|0,a=s|0,f=i|0,s=n|0,i=o|0;let x=Rs(H,h,S);n=Ds(x,K,U,y),o=x|0}({h:n,l:o}=Tt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Tt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:f}=Tt(this.Ch|0,this.Cl|0,a|0,f|0),{h:c,l:u}=Tt(this.Dh|0,this.Dl|0,c|0,u|0),{h:l,l:m}=Tt(this.Eh|0,this.El|0,l|0,m|0),{h:d,l:b}=Tt(this.Fh|0,this.Fl|0,d|0,b|0),{h:E,l:p}=Tt(this.Gh|0,this.Gl|0,E|0,p|0),{h:w,l:v}=Tt(this.Hh|0,this.Hl|0,w|0,v|0),this.set(n,o,s,i,a,f,c,u,l,m,d,b,E,p,w,v)}roundClean(){Ot(Vt,jt)}destroy(){this.destroyed=!0,Ot(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Un=class extends Kn{Ah=ot[0]|0;Al=ot[1]|0;Bh=ot[2]|0;Bl=ot[3]|0;Ch=ot[4]|0;Cl=ot[5]|0;Dh=ot[6]|0;Dl=ot[7]|0;Eh=ot[8]|0;El=ot[9]|0;Fh=ot[10]|0;Fl=ot[11]|0;Gh=ot[12]|0;Gl=ot[13]|0;Hh=ot[14]|0;Hl=ot[15]|0;constructor(){super(64)}};var Ae=_n(()=>new Fn,Rn(1));var Ar=_n(()=>new Un,Rn(3));var N=(e,t,r)=>mt(e,t,r),Pn=qt,Be=Sr,Q=(...e)=>Tn(...e),Ie=e=>ze(e),te=Ln,Ge=e=>Bs(e),Ir=BigInt(0),kn=BigInt(1);function wt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function Lr(e){if(typeof e=="bigint"){if(!Br(e))throw new RangeError("positive bigint expected, got "+e)}else Pn(e);return e}function Et(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 Xe(e){let t=Lr(e).toString(16);return t.length&1?"0"+t:t}function ks(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?Ir:BigInt("0x"+e)}function ee(e){return ks(Sr(e))}function _t(e){return ks(Sr(We(mt(e)).reverse()))}function Tr(e,t){if(qt(t),t===0)throw new RangeError("zero length");e=Lr(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return ze(r.padStart(t*2,"0"))}function Nn(e,t){return Tr(e,t).reverse()}function Ps(e,t){if(e=N(e),t=N(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 We(e){return Uint8Array.from(N(e))}function _r(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 Br=e=>typeof e=="bigint"&&Ir<=e;function Fc(e,t,r){return Br(e)&&Br(t)&&Br(r)&&t<=e&&e<r}function Le(e,t,r,n){if(!Fc(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Te(e){if(e<Ir)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>Ir;e>>=kn,t+=1);return t}var Je=e=>(kn<<BigInt(e))-kn;function Ns(e,t,r){if(qt(e,"hashLen"),qt(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,l=()=>{f.fill(1),c.fill(0),u=0},m=(...p)=>r(c,Q(f,...p)),d=(p=o)=>{c=m(s,p),f=m(),p.length!==0&&(c=m(i,p),f=m())},b=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let p=0,w=[];for(;p<t;){f=m();let v=f.slice();w.push(v),p+=f.length}return Q(...w)};return(p,w)=>{l(),d(p);let v;for(;(v=w(b()))===void 0;)d();return l(),v}}function St(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 Mn=()=>{throw new Error("not implemented")};var st=BigInt(0),Y=BigInt(1),re=BigInt(2),Vs=BigInt(3),js=BigInt(4),zs=BigInt(5),Kc=BigInt(7),Zs=BigInt(8),Uc=BigInt(9),Ys=BigInt(16);function W(e,t){if(t<=st)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=st?r:t+r}function V(e,t,r){if(t<st)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >st;)n*=n,n%=r;return n}function Ms(e,t){if(e===st)throw new Error("invert: expected non-zero number");if(t<=st)throw new Error("invert: expected positive modulus, got "+t);let r=W(e,t),n=t,o=st,s=Y,i=Y,a=st;for(;r!==st;){let c=n/r,u=n-r*c,l=o-i*c,m=s-a*c;n=r,r=u,o=i,s=a,i=l,a=m}if(n!==Y)throw new Error("invert: does not exist");return W(o,t)}function qn(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function $s(e,t){let r=e,n=(r.ORDER+Y)/js,o=r.pow(t,n);return qn(r,o,t),o}function kc(e,t){let r=e,n=(r.ORDER-zs)/Zs,o=r.mul(t,re),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,re),s),f=r.mul(i,r.sub(a,r.ONE));return qn(r,f,t),f}function Pc(e){let t=_e(e),r=Gs(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Kc)/Ys;return((a,f)=>{let c=a,u=c.pow(f,i),l=c.mul(u,n),m=c.mul(u,o),d=c.mul(u,s),b=c.eql(c.sqr(l),f),E=c.eql(c.sqr(m),f);u=c.cmov(u,l,b),l=c.cmov(d,m,E);let p=c.eql(c.sqr(l),f),w=c.cmov(u,l,p);return qn(c,w,f),w})}function Gs(e){if(e<Vs)throw new Error("sqrt is not defined for small field");let t=e-Y,r=0;for(;t%re===st;)t/=re,r++;let n=re,o=_e(e);for(;qs(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return $s;let s=o.pow(n,t),i=(t+Y)/re;return function(f,c){let u=f;if(u.is0(c))return c;if(qs(u,c)!==1)throw new Error("Cannot find square root");let l=r,m=u.mul(u.ONE,s),d=u.pow(c,t),b=u.pow(c,i);for(;!u.eql(d,u.ONE);){if(u.is0(d))return u.ZERO;let E=1,p=u.sqr(d);for(;!u.eql(p,u.ONE);)if(E++,p=u.sqr(p),E===l)throw new Error("Cannot find square root");let w=Y<<BigInt(l-E-1),v=u.pow(m,w);l=E,m=u.sqr(v),d=u.mul(d,m),b=u.mul(b,v)}return b}}function Nc(e){return e%js===Vs?$s:e%Zs===zs?kc:e%Ys===Uc?Pc(e):Gs(e)}var Kt=(e,t)=>(W(e,t)&Y)===Y,Mc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Hn(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Mc.reduce((n,o)=>(n[o]="function",n),t);if(St(e,r),Et(e.BYTES,"BYTES"),Et(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=Y)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function qc(e,t,r){let n=e;if(r<st)throw new Error("invalid exponent, negatives unsupported");if(r===st)return n.ONE;if(r===Y)return t;let o=n.ONE,s=t;for(;r>st;)r&Y&&(o=n.mul(o,s)),s=n.sqr(s),r>>=Y;return o}function Qe(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 qs(e,t){let r=e,n=(r.ORDER-Y)/re,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 Hc(e,t){if(t!==void 0&&Pn(t),e<=st)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=Te(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 Hs=new WeakMap,Rr=class{ORDER;BITS;BYTES;isLE;ZERO=st;ONE=Y;_lengths;_mod;constructor(t,r={}){if(t<=Y)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}=Hc(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 st<=t&&t<this.ORDER}is0(t){return t===st}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&Y)===Y}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 qc(this,t,r)}div(t,r){return W(t*Ms(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 Ms(t,this.ORDER)}sqrt(t){let r=Hs.get(this);return r||Hs.set(this,r=Nc(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?Nn(t,this.BYTES):Tr(t,this.BYTES)}fromBytes(t,r=!1){N(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?_t(t):ee(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 Qe(this,t)}cmov(t,r,n){return wt(n,"condition"),n?r:t}};Object.freeze(Rr.prototype);function _e(e,t={}){return new Rr(e,t)}function Xs(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=Y)throw new Error("field order must be greater than 1");let t=Te(e-Y);return Math.ceil(t/8)}function Vn(e){let t=Xs(e);return t+Math.ceil(t/2)}function jn(e,t,r=!1){N(e);let n=e.length,o=Xs(t),s=Math.max(Vn(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?_t(e):ee(e),a=W(i,t-Y)+Y;return r?Nn(a,o):Tr(a,o)}var Re=BigInt(0),ne=BigInt(1);function tr(e,t){let r=t.negate();return e?r:t}function oe(e,t){let r=Qe(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function ti(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function zn(e,t){ti(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Je(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Ws(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+=ne);let c=t*n,u=c+Math.abs(a)-1,l=a===0,m=a<0,d=t%2!==0;return{nextN:f,offset:u,isZero:l,isNeg:m,isNegF:d,offsetF:c}}var Zn=new WeakMap,ei=new WeakMap;function Yn(e){return ei.get(e)||1}function Js(e){if(e!==Re)throw new Error("invalid wNAF")}var De=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>Re;)r&ne&&(n=n.add(o)),o=o.double(),r>>=ne;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=zn(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=zn(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:f,offset:c,isZero:u,isNeg:l,isNegF:m,offsetF:d}=Ws(n,a,i);n=f,u?s=s.add(tr(m,r[d])):o=o.add(tr(l,r[c]))}return Js(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=zn(t,this.bits);for(let i=0;i<s.windows&&n!==Re;i++){let{nextN:a,offset:f,isZero:c,isNeg:u}=Ws(n,i,s);if(n=a,!c){let l=r[f];o=o.add(u?l.negate():l)}}return Js(n),o}getPrecomputes(t,r,n){let o=Zn.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Zn.set(r,o))),o}cached(t,r,n){let o=Yn(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Yn(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){ti(r,this.bits),ei.set(t,r),Zn.delete(t)}hasCache(t){return Yn(t)!==1}};function ri(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Re||n>Re;)r&ne&&(s=s.add(o)),n&ne&&(i=i.add(o)),o=o.double(),r>>=ne,n>>=ne;return{p1:s,p2:i}}function Qs(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Hn(t),t}else return _e(e,{isLE:r})}function Dr(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>Re))throw new Error(`CURVE.${f} must be positive bigint`)}let o=Qs(t.p,r.Fp,n),s=Qs(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 Cr(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var zt=BigInt(0),nt=BigInt(1),$n=BigInt(2),Vc=BigInt(8);function jc(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 ni(e,t={}){let r=t,n=Dr("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;St(r,{},{uvRatio:"function"});let f=$n<<BigInt(s.BYTES*8)-nt,c=E=>o.create(E),u=r.uvRatio===void 0?(E,p)=>{try{return{isValid:!0,value:o.sqrt(o.div(E,p))}}catch{return{isValid:!1,value:zt}}}:r.uvRatio;if(!jc(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(E,p,w=!1){let v=w?nt:zt;return Le("coordinate "+E,p,v,f),p}function m(E){if(!(E instanceof d))throw new Error("EdwardsPoint expected")}class d{static BASE=new d(i.Gx,i.Gy,nt,c(i.Gx*i.Gy));static ZERO=new d(zt,nt,nt,zt);static Fp=o;static Fn=s;X;Y;Z;T;constructor(p,w,v,B){this.X=l("x",p),this.Y=l("y",w),this.Z=l("z",v,!0),this.T=l("t",B),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){if(p instanceof d)throw new Error("extended point not allowed");let{x:w,y:v}=p||{};return l("x",w),l("y",v),new d(w,v,nt,c(w*v))}static fromBytes(p,w=!1){let v=o.BYTES,{a:B,d:D}=i;p=We(N(p,v,"point")),wt(w,"zip215");let _=We(p),F=p[v-1];_[v-1]=F&-129;let C=_t(_),L=w?f:o.ORDER;Le("point.y",C,zt,L);let K=c(C*C),H=c(K-nt),U=c(D*K-B),{isValid:h,value:y}=u(H,U);if(!h)throw new Error("bad point: invalid y coordinate");let S=(y&nt)===nt,x=(F&128)!==0;if(!w&&y===zt&&x)throw new Error("bad point: x=0 and x_0=1");return x!==S&&(y=c(-y)),d.fromAffine({x:y,y:C})}static fromHex(p,w=!1){return d.fromBytes(Ie(p),w)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,w=!0){return b.createCache(this,p),w||this.multiply($n),this}assertValidity(){let p=this,{a:w,d:v}=i;if(p.is0())throw new Error("bad point: ZERO");let{X:B,Y:D,Z:_,T:F}=p,C=c(B*B),L=c(D*D),K=c(_*_),H=c(K*K),U=c(C*w),h=c(K*c(U+L)),y=c(H+c(v*c(C*L)));if(h!==y)throw new Error("bad point: equation left != right (1)");let S=c(B*D),x=c(_*F);if(S!==x)throw new Error("bad point: equation left != right (2)")}equals(p){m(p);let{X:w,Y:v,Z:B}=this,{X:D,Y:_,Z:F}=p,C=c(w*F),L=c(D*B),K=c(v*F),H=c(_*B);return C===L&&K===H}is0(){return this.equals(d.ZERO)}negate(){return new d(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:p}=i,{X:w,Y:v,Z:B}=this,D=c(w*w),_=c(v*v),F=c($n*c(B*B)),C=c(p*D),L=w+v,K=c(c(L*L)-D-_),H=C+_,U=H-F,h=C-_,y=c(K*U),S=c(H*h),x=c(K*h),g=c(U*H);return new d(y,S,g,x)}add(p){m(p);let{a:w,d:v}=i,{X:B,Y:D,Z:_,T:F}=this,{X:C,Y:L,Z:K,T:H}=p,U=c(B*C),h=c(D*L),y=c(F*v*H),S=c(_*K),x=c((B+D)*(C+L)-U-h),g=S-y,A=S+y,T=c(h-w*U),I=c(x*g),R=c(A*T),O=c(x*T),P=c(g*A);return new d(I,R,P,O)}subtract(p){return m(p),this.add(p.negate())}multiply(p){if(!s.isValidNot0(p))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:w,f:v}=b.cached(this,p,B=>oe(d,B));return oe(d,[w,v])[0]}multiplyUnsafe(p){if(!s.isValid(p))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return p===zt?d.ZERO:this.is0()||p===nt?this:b.unsafe(this,p,w=>oe(d,w))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return b.unsafe(this,i.n).is0()}toAffine(p){let w=this,v=p,{X:B,Y:D,Z:_}=w,F=w.is0();v==null&&(v=F?Vc:o.inv(_));let C=c(B*v),L=c(D*v),K=o.mul(_,v);if(F)return{x:zt,y:nt};if(K!==nt)throw new Error("invZ was invalid");return{x:C,y:L}}clearCofactor(){return a===nt?this:this.multiplyUnsafe(a)}toBytes(){let{x:p,y:w}=this.toAffine(),v=o.toBytes(w);return v[v.length-1]|=p&nt?128:0,v}toHex(){return Be(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let b=new De(d,s.BITS);return s.BITS>=8&&d.BASE.precompute(8),Object.freeze(d.prototype),Object.freeze(d),d}var Or=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){Mn()}static fromHex(t){Mn()}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 Be(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 oi(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;St(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&&(Et(c,"hash.outputLen"),c!==u))throw new Error(`hash.outputLen must be ${u}, got ${c}`);let l=o.randomBytes===void 0?Ge:o.randomBytes,m=o.adjustScalarBytes===void 0?h=>h:o.adjustScalarBytes,d=o.domain===void 0?(h,y,S)=>{if(wt(S,"phflag"),y.length||S)throw new Error("Contexts/pre-hash are not supported");return h}:o.domain;function b(h){return f.create(_t(h))}function E(h){let y=C.secretKey;N(h,C.secretKey,"secretKey");let S=N(n(h),2*y,"hashedSecretKey"),x=m(S.slice(0,y)),g=S.slice(y,2*y),A=b(x);return{head:x,prefix:g,scalar:A}}function p(h){let{head:y,prefix:S,scalar:x}=E(h),g=i.multiply(x),A=g.toBytes();return{head:y,prefix:S,scalar:x,point:g,pointBytes:A}}function w(h){return p(h).pointBytes}function v(h=Uint8Array.of(),...y){let S=Q(...y);return b(n(d(S,N(h,void 0,"context"),!!s)))}function B(h,y,S={}){h=N(h,void 0,"message"),s&&(h=s(h));let{prefix:x,scalar:g,pointBytes:A}=p(y),T=v(S.context,x,h),I=i.multiply(T).toBytes(),R=v(S.context,I,A,h),O=f.create(T+R*g);if(!f.isValid(O))throw new Error("sign failed: invalid s");let P=Q(I,f.toBytes(O));return N(P,C.signature,"result")}let D={zip215:o.zip215};function _(h,y,S,x=D){let{context:g}=x,A=x.zip215===void 0?!!D.zip215:x.zip215,T=C.signature;h=N(h,T,"signature"),y=N(y,void 0,"message"),S=N(S,C.publicKey,"publicKey"),A!==void 0&&wt(A,"zip215"),s&&(y=s(y));let I=T/2,R=h.subarray(0,I),O=_t(h.subarray(I,T)),P,M,k;try{P=e.fromBytes(S,A),M=e.fromBytes(R,A),k=i.multiplyUnsafe(O)}catch{return!1}if(!A&&P.isSmallOrder())return!1;let J=v(g,R,S,y);return M.add(P.multiplyUnsafe(J)).subtract(k).clearCofactor().is0()}let F=a.BYTES,C={secretKey:F,publicKey:F,signature:2*F,seed:F};function L(h){return h=h===void 0?l(C.seed):h,N(h,C.seed,"seed")}function K(h){return te(h)&&h.length===C.secretKey}function H(h,y){try{return!!e.fromBytes(h,y===void 0?D.zip215:y)}catch{return!1}}let U={getExtendedPublicKey:p,randomSecretKey:L,isValidSecretKey:K,isValidPublicKey:H,toMontgomery(h){let{y}=e.fromBytes(h),S=C.publicKey,x=S===32;if(!x&&S!==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=C.secretKey;N(h,y);let S=n(h.subarray(0,y));return m(S).subarray(0,y)}};return Object.freeze(C),Object.freeze(U),Object.freeze({keygen:Cr(L,w),getPublicKey:w,sign:B,verify:_,utils:U,Point:e,lengths:C})}function er(e,t){if(Et(e),Et(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 zc(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 Zc(e){if(!te(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?_r(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function Gn(e,t,r,n){N(e),Et(r),t=Zc(t),t.length>255&&(t=n(Q(_r("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,er(t.length,1)),f=new Uint8Array(s),c=er(r,2),u=new Array(i),l=n(Q(f,e,c,er(0,1),a));u[0]=n(Q(l,er(1,1),a));for(let d=1;d<i;d++){let b=[zc(l,u[d-1]),er(d+1,1),a];u[d]=n(Q(...b))}return Q(...u).slice(0,r)}var si="HashToScalar-";var Yc=BigInt(0),Ut=BigInt(1),ii=BigInt(2);var $c=BigInt(5),Gc=BigInt(8),Ce=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Qn={p:Ce,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Gc,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Xc(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ce,a=e*e%s*e%s,f=V(a,ii,s)*a%s,c=V(f,Ut,s)*e%s,u=V(c,$c,s)*c%s,l=V(u,t,s)*u%s,m=V(l,r,s)*l%s,d=V(m,n,s)*m%s,b=V(d,o,s)*d%s,E=V(b,o,s)*d%s,p=V(E,t,s)*u%s;return{pow_p_5_8:V(p,ii,s)*e%s,b2:a}}function Wc(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Xn=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function to(e,t){let r=Ce,n=W(t*t*t,r),o=W(n*n*t,r),s=Xc(e*o).pow_p_5_8,i=W(e*n*s,r),a=W(t*i*i,r),f=i,c=W(i*Xn,r),u=a===e,l=a===W(-e,r),m=a===W(-e*Xn,r);return u&&(i=f),(l||m)&&(i=c),Kt(i,r)&&(i=W(-i,r)),{isValid:u||l,value:i}}var Yt=ni(Qn,{uvRatio:to}),Zt=Yt.Fp,fi=Yt.Fn;function Jc(e){return oi(Yt,Ar,Object.assign({adjustScalarBytes:Wc,zip215:!0},e))}var ui=Jc({});var Wn=Xn,Qc=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),tf=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),ef=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),rf=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),ai=e=>to(Ut,e),nf=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Jn=e=>Zt.create(_t(e)&nf);function ci(e){let{d:t}=Qn,r=Ce,n=w=>Zt.create(w),o=n(Wn*e*e),s=n((o+Ut)*ef),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:f,value:c}=to(s,a),u=n(c*e);Kt(u,r)||(u=n(-u)),f||(c=u),f||(i=o);let l=n(i*(o-Ut)*rf-a),m=c*c,d=n((c+c)*a),b=n(l*Qc),E=n(Ut-m),p=n(Ut+m);return new Yt(n(d*p),n(E*b),n(b*p),n(d*E))}var $t=class e extends Or{static BASE=new e(Yt.BASE);static ZERO=new e(Yt.ZERO);static Fp=Zt;static Fn=fi;constructor(t){super(t)}static fromAffine(t){return new e(Yt.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}=Qn,o=Ce,s=D=>Zt.create(D),i=Jn(t);if(!Ps(Zt.toBytes(i),t)||Kt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),f=s(Ut+r*a),c=s(Ut-r*a),u=s(f*f),l=s(c*c),m=s(r*n*u-l),{isValid:d,value:b}=ai(s(m*l)),E=s(b*c),p=s(b*E*m),w=s((i+i)*E);Kt(w,o)&&(w=s(-w));let v=s(f*p),B=s(w*v);if(!d||Kt(B,o)||v===Yc)throw new Error("invalid ristretto255 encoding 2");return new e(new Yt(w,v,Ut,B))}static fromHex(t){return e.fromBytes(ze(t))}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Ce,i=p=>Zt.create(p),a=i(i(n+r)*i(n-r)),f=i(t*r),c=i(f*f),{value:u}=ai(i(a*c)),l=i(u*a),m=i(u*f),d=i(l*m*o),b;if(Kt(o*d,s)){let p=i(r*Wn),w=i(t*Wn);t=p,r=w,b=i(l*tf)}else b=m;Kt(t*d,s)&&(r=i(-r));let E=i((n-r)*b);return Kt(E,s)&&(E=i(-E)),Zt.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=c=>Zt.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($t.BASE);Object.freeze($t.ZERO);Object.freeze($t.prototype);Object.freeze($t);var of=Object.freeze({Point:$t,hashToCurve(e,t){let r=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=Gn(e,r,64,Ar);return of.deriveToCurve(n)},hashToScalar(e,t={DST:si}){let r=Gn(e,t.DST,64,Ar);return fi.create(_t(r))},deriveToCurve(e){mt(e,64);let t=Jn(e.subarray(0,32)),r=ci(t),n=Jn(e.subarray(32,64)),o=ci(n);return new $t(r.add(o))}});var rr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Fr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var li={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Fr("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 bt=li;var Oe=32;var eo,sf=(async()=>{try{return await bt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function af(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await bt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await bt.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function cf(e,t,r){return ui.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function hi(e,t,r){return eo==null&&(eo=await sf),eo?af(e,t,r):cf(e,t,r)}function Kr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Ur=class{type="Ed25519";raw;constructor(t){this.raw=ro(t,Oe)}toMultihash(){return It.digest(Se(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=hi(this.raw,r,t);return Kr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function mi(e){return e=ro(e,Oe),new Ur(e)}function ro(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new j(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var ff=Math.pow(2,7),uf=Math.pow(2,14),lf=Math.pow(2,21),no=Math.pow(2,28),oo=Math.pow(2,35),so=Math.pow(2,42),io=Math.pow(2,49),q=128,ct=127;function kt(e){if(e<ff)return 1;if(e<uf)return 2;if(e<lf)return 3;if(e<no)return 4;if(e<oo)return 5;if(e<so)return 6;if(e<io)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ao(e,t,r=0){switch(kt(e)){case 8:t[r++]=e&255|q,e/=128;case 7:t[r++]=e&255|q,e/=128;case 6:t[r++]=e&255|q,e/=128;case 5:t[r++]=e&255|q,e/=128;case 4:t[r++]=e&255|q,e>>>=7;case 3:t[r++]=e&255|q,e>>>=7;case 2:t[r++]=e&255|q,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function hf(e,t,r=0){switch(kt(e)){case 8:t.set(r++,e&255|q),e/=128;case 7:t.set(r++,e&255|q),e/=128;case 6:t.set(r++,e&255|q),e/=128;case 5:t.set(r++,e&255|q),e/=128;case 4:t.set(r++,e&255|q),e>>>=7;case 3:t.set(r++,e&255|q),e>>>=7;case 2:t.set(r++,e&255|q),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function co(e,t){let r=e[t],n=0;if(n+=r&ct,r<q||(r=e[t+1],n+=(r&ct)<<7,r<q)||(r=e[t+2],n+=(r&ct)<<14,r<q)||(r=e[t+3],n+=(r&ct)<<21,r<q)||(r=e[t+4],n+=(r&ct)*no,r<q)||(r=e[t+5],n+=(r&ct)*oo,r<q)||(r=e[t+6],n+=(r&ct)*so,r<q)||(r=e[t+7],n+=(r&ct)*io,r<q))return n;throw new RangeError("Could not decode varint")}function df(e,t){let r=e.get(t),n=0;if(n+=r&ct,r<q||(r=e.get(t+1),n+=(r&ct)<<7,r<q)||(r=e.get(t+2),n+=(r&ct)<<14,r<q)||(r=e.get(t+3),n+=(r&ct)<<21,r<q)||(r=e.get(t+4),n+=(r&ct)*no,r<q)||(r=e.get(t+5),n+=(r&ct)*oo,r<q)||(r=e.get(t+6),n+=(r&ct)*so,r<q)||(r=e.get(t+7),n+=(r&ct)*io,r<q))return n;throw new RangeError("Could not decode varint")}function yi(e,t,r=0){return t==null&&(t=dt(kt(e))),t instanceof Uint8Array?ao(e,t,r):hf(e,t,r)}function bi(e,t=0){return e instanceof Uint8Array?co(e,t):df(e,t)}var fo=new Float32Array([-0]),Gt=new Uint8Array(fo.buffer);function gi(e,t,r){fo[0]=e,t[r]=Gt[0],t[r+1]=Gt[1],t[r+2]=Gt[2],t[r+3]=Gt[3]}function xi(e,t){return Gt[0]=e[t],Gt[1]=e[t+1],Gt[2]=e[t+2],Gt[3]=e[t+3],fo[0]}var uo=new Float64Array([-0]),ft=new Uint8Array(uo.buffer);function wi(e,t,r){uo[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 Ei(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],uo[0]}var mf=BigInt(Number.MAX_SAFE_INTEGER),yf=BigInt(Number.MIN_SAFE_INTEGER),yt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return se;if(t<mf&&t>yf)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>Si&&(o=0n,++n>Si&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return se;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):se}},se=new yt(0,0);se.toBigInt=function(){return 0n};se.zzEncode=se.zzDecode=function(){return this};se.length=function(){return 1};var Si=4294967296n;function vi(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 Ai(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 lo(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 vt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function kr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var ho=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,vt(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 vt(this,4);return kr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw vt(this,4);return kr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw vt(this,4);let t=xi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw vt(this,4);let t=Ei(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 vt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Ai(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw vt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw vt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new yt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw vt(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 vt(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 vt(this,8);let t=kr(this.buf,this.pos+=4),r=kr(this.buf,this.pos+=4);return new yt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=co(this.buf,this.pos);return this.pos+=kt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function nr(e){return new ho(e instanceof Uint8Array?e:e.subarray())}function ie(e,t,r){let n=nr(e);return t.decode(n,void 0,r)}function po(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return dt(i);o+i>t&&(n=dt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ae=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function mo(){}var bo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},bf=po();function gf(e){return globalThis.Buffer!=null?dt(e):bf(e)}var sr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ae(mo,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ae(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new go((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(Pr,10,yt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=yt.fromBigInt(t);return this._push(Pr,r.length(),r)}uint64Number(t){return this._push(ao,kt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=yt.fromBigInt(t).zzEncode();return this._push(Pr,r.length(),r)}sint64Number(t){let r=yt.fromNumber(t).zzEncode();return this._push(Pr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(yo,1,t?1:0)}fixed32(t){return this._push(or,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=yt.fromBigInt(t);return this._push(or,4,r.lo)._push(or,4,r.hi)}fixed64Number(t){let r=yt.fromNumber(t);return this._push(or,4,r.lo)._push(or,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(gi,4,t)}double(t){return this._push(wi,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(yo,1,0):this.uint32(r)._push(wf,r,t)}string(t){let r=vi(t);return r!==0?this.uint32(r)._push(lo,r,t):this._push(yo,1,0)}fork(){return this.states=new bo(this),this.head=this.tail=new ae(mo,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 ae(mo,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=gf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function yo(e,t,r){t[r]=e&255}function xf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var go=class extends ae{next;constructor(t,r){super(xf,t,r),this.next=void 0}};function Pr(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 or(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 wf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(sr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Ef,t,e),this},sr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Sf,t,e),this});function Ef(e,t,r){t.set(e,r)}function Sf(e,t,r){e.length<40?lo(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(X(e),r)}function xo(){return new sr}function ce(e,t){let r=xo();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*fe(e,t,r){let n=nr(e);yield*t.stream(n,void 0,"$",r)}var Nr={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Mr(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function ir(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 Mr("enum",Nr.VARINT,r,n,o)}function ue(e,t,r){return Mr("message",Nr.LENGTH_DELIMITED,e,t,r)}var ut;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(ut||(ut={}));var wo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(wo||(wo={}));(function(e){e.codec=()=>ir(wo)})(ut||(ut={}));var Xt;(function(e){let t;e.codec=()=>(t==null&&(t=ue((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ut.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=ut.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:ut.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 ce(s,e.codec())}e.encode=r;function n(s,i){return ie(s,e.codec(),i)}e.decode=n;function o(s,i){return fe(s,e.codec(),i)}e.stream=o})(Xt||(Xt={}));var Eo;(function(e){let t;e.codec=()=>(t==null&&(t=ue((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ut.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=ut.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:ut.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 ce(s,e.codec())}e.encode=r;function n(s,i){return ie(s,e.codec(),i)}e.decode=n;function o(s,i){return fe(s,e.codec(),i)}e.stream=o})(Eo||(Eo={}));var cr={};ht(cr,{MAX_RSA_KEY_SIZE:()=>So,generateRSAKeyPair:()=>Di,jwkToJWKKeyPair:()=>Ci,jwkToPkcs1:()=>If,jwkToPkix:()=>Io,jwkToRSAPrivateKey:()=>To,pkcs1MessageToJwk:()=>Ao,pkcs1MessageToRSAPrivateKey:()=>Lo,pkcs1ToJwk:()=>Bf,pkcs1ToRSAPrivateKey:()=>_i,pkixMessageToJwk:()=>Bo,pkixMessageToRSAPublicKey:()=>qr,pkixToJwk:()=>Lf,pkixToRSAPublicKey:()=>Ri});var Fe=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=cr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return it.createV1(114,this._multihash)}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}verify(t,r,n){return Ti(this.jwk,r,t,n)}},ar=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=cr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}sign(t,r){return Li(this.jwk,t,r)}};var So=8192,vo=18,vf=1062,Af=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Bf(e){let t=Lt(e);return Ao(t)}function Ao(e){return{n:Z(e[1],"base64url"),e:Z(e[2],"base64url"),d:Z(e[3],"base64url"),p:Z(e[4],"base64url"),q:Z(e[5],"base64url"),dp:Z(e[6],"base64url"),dq:Z(e[7],"base64url"),qi:Z(e[8],"base64url"),kty:"RSA"}}function If(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 j("JWK was missing components");return Mt([pt(Uint8Array.from([0])),pt(X(e.n,"base64url")),pt(X(e.e,"base64url")),pt(X(e.d,"base64url")),pt(X(e.p,"base64url")),pt(X(e.q,"base64url")),pt(X(e.dp,"base64url")),pt(X(e.dq,"base64url")),pt(X(e.qi,"base64url"))]).subarray()}function Lf(e){let t=Lt(e,{offset:0});return Bo(t)}function Bo(e){let t=Lt(e[1],{offset:0});return{kty:"RSA",n:Z(t[0],"base64url"),e:Z(t[1],"base64url")}}function Io(e){if(e.n==null||e.e==null)throw new j("JWK was missing components");return Mt([Af,gr(Mt([pt(X(e.n,"base64url")),pt(X(e.e,"base64url"))]))]).subarray()}function _i(e){let t=Lt(e);return Lo(t)}function Lo(e){let t=Ao(e);return To(t)}function Ri(e,t){if(e.byteLength>=vf)throw new de("Key size is too large");let r=Lt(e,{offset:0});return qr(r,e,t)}function qr(e,t,r){let n=Bo(e);if(r==null){let o=Ae(Xt.encode({Type:ut.RSA,Data:t}));r=Bt(vo,o)}return new Fe(n,r)}function To(e){if(Fi(e)>So)throw new j("Key size is too large");let t=Ci(e),r=Ae(Xt.encode({Type:ut.RSA,Data:Io(t.publicKey)})),n=Bt(vo,r);return new ar(t.privateKey,new Fe(t.publicKey,n))}async function Di(e){if(e>So)throw new j("Key size is too large");let t=await Oi(e),r=Ae(Xt.encode({Type:ut.RSA,Data:Io(t.publicKey)})),n=Bt(vo,r);return new ar(t.privateKey,new Fe(t.publicKey,n))}function Ci(e){if(e==null)throw new j("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var Ki="1.2.840.113549.1.1.1";async function Oi(e,t){let r=await bt.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 Tf(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Li(e,t,r){let n=await bt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await bt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Ti(e,t,r,n){let o=await bt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await bt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Tf(e,t){if(e.privateKey==null||e.publicKey==null)throw new j("Private and public key are required");let r=await Promise.all([bt.get().subtle.exportKey("jwk",e.privateKey),bt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Fi(e){if(e.kty!=="RSA")throw new j("invalid key type");if(e.n==null)throw new j("invalid key modulus");return X(e.n,"base64url").length*8}var Hr=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(xr(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),Ot(o)}update(t){return ve(this),this.iHash.update(t),this}digestInto(t){ve(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()}},Ui=(()=>{let e=((t,r,n)=>new Hr(t,r).update(n).digest());return e.create=(t,r)=>new Hr(t,r),e})();var ki=(e,t)=>(e+(e>=0?t:-t)/Pi)/t;function _f(e,t,r){Le("scalar",e,Rt,r);let[[n,o],[s,i]]=t,a=ki(i*e,r),f=ki(-o*e,r),c=e-a*n-f*s,u=-a*o-f*i,l=c<Rt,m=u<Rt;l&&(c=-c),m&&(u=-u);let d=Je(Math.ceil(Te(r)/2))+Wt;if(c<Rt||c>=d||u<Rt||u>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:c,k2neg:m,k2:u}}function Ro(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function _o(e,t){St(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return wt(r.lowS,"lowS"),wt(r.prehash,"prehash"),r.format!==void 0&&Ro(r.format),r}var Do=class extends Error{constructor(t=""){super(t)}},At={Err:Do,_tlv:{encode:(e,t)=>{let{Err:r}=At;if(Et(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=Xe(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Xe(o.length/2|128):"";return Xe(e)+s+o+t},decode(e,t){let{Err:r}=At;t=N(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}=At;if(Lr(e),e<Rt)throw new t("integer: negative integers are not allowed");let r=Xe(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}=At;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 ee(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=At,o=N(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}=At,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(At._tlv);Object.freeze(At._int);Object.freeze(At);var Rt=BigInt(0),Wt=BigInt(1),Pi=BigInt(2),Vr=BigInt(3),Rf=BigInt(4);function Ni(e,t={}){let r=Dr("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;St(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=qi(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function m(U,h,y){if(c&&h.is0())return Uint8Array.of(0);let{x:S,y:x}=h.toAffine(),g=n.toBytes(S);if(wt(y,"isCompressed"),y){l();let A=!n.isOdd(x);return Q(Mi(A),g)}else return Q(Uint8Array.of(4),g,n.toBytes(x))}function d(U){N(U,void 0,"Point");let{publicKey:h,publicKeyUncompressed:y}=u,S=U.length,x=U[0],g=U.subarray(1);if(c&&S===1&&x===0)return{x:n.ZERO,y:n.ZERO};if(S===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=p(A),I;try{I=n.sqrt(T)}catch(P){let M=P instanceof Error?": "+P.message:"";throw new Error("bad point: is not on curve, sqrt error"+M)}l();let R=n.isOdd(I);return(x&1)===1!==R&&(I=n.neg(I)),{x:A,y:I}}else if(S===y&&x===4){let A=n.BYTES,T=n.fromBytes(g.subarray(0,A)),I=n.fromBytes(g.subarray(A,A*2));if(!w(T,I))throw new Error("bad point: is not on curve");return{x:T,y:I}}else throw new Error(`bad point: got length ${S}, expected compressed=${h} or uncompressed=${y}`)}let b=t.toBytes===void 0?m:t.toBytes,E=t.fromBytes===void 0?d:t.fromBytes;function p(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 w(U,h){let y=n.sqr(h),S=p(U);return n.eql(y,S)}if(!w(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(s.a,Vr),Rf),B=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(v,B)))throw new Error("bad curve params: a or b");function D(U,h,y=!1){if(!n.isValid(h)||y&&n.is0(h))throw new Error(`bad point coordinate ${U}`);return h}function _(U){if(!(U instanceof L))throw new Error("Weierstrass Point expected")}function F(U){if(!f||!f.basises)throw new Error("no endo");return _f(U,f.basises,o.ORDER)}function C(U,h,y,S,x){return y=new L(n.mul(y.X,U),y.Y,y.Z),h=tr(S,h),y=tr(x,y),h.add(y)}class L{static BASE=new L(s.Gx,s.Gy,n.ONE);static ZERO=new L(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(h,y,S){this.X=D("x",h),this.Y=D("y",y,!0),this.Z=D("z",S),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){let{x:y,y:S}=h||{};if(!h||!n.isValid(y)||!n.isValid(S))throw new Error("invalid affine point");if(h instanceof L)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(S)?L.ZERO:new L(y,S,n.ONE)}static fromBytes(h){let y=L.fromAffine(E(N(h,void 0,"point")));return y.assertValidity(),y}static fromHex(h){return L.fromBytes(Ie(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,y=!0){return H.createCache(this,h),y||this.multiply(Vr),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:S}=h.toAffine();if(!n.isValid(y)||!n.isValid(S))throw new Error("bad point: x or y not field elements");if(!w(y,S))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){_(h);let{X:y,Y:S,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(S,T),n.mul(A,x));return I&&R}negate(){return new L(this.X,n.neg(this.Y),this.Z)}double(){let{a:h,b:y}=s,S=n.mul(y,Vr),{X:x,Y:g,Z:A}=this,T=n.ZERO,I=n.ZERO,R=n.ZERO,O=n.mul(x,x),P=n.mul(g,g),M=n.mul(A,A),k=n.mul(x,g);return k=n.add(k,k),R=n.mul(x,A),R=n.add(R,R),T=n.mul(h,R),I=n.mul(S,M),I=n.add(T,I),T=n.sub(P,I),I=n.add(P,I),I=n.mul(T,I),T=n.mul(k,T),R=n.mul(S,R),M=n.mul(h,M),k=n.sub(O,M),k=n.mul(h,k),k=n.add(k,R),R=n.add(O,O),O=n.add(R,O),O=n.add(O,M),O=n.mul(O,k),I=n.add(I,O),M=n.mul(g,A),M=n.add(M,M),O=n.mul(M,k),T=n.sub(T,O),R=n.mul(M,P),R=n.add(R,R),R=n.add(R,R),new L(T,I,R)}add(h){_(h);let{X:y,Y:S,Z:x}=this,{X:g,Y:A,Z:T}=h,I=n.ZERO,R=n.ZERO,O=n.ZERO,P=s.a,M=n.mul(s.b,Vr),k=n.mul(y,g),J=n.mul(S,A),tt=n.mul(x,T),et=n.add(y,S),$=n.add(g,A);et=n.mul(et,$),$=n.add(k,J),et=n.sub(et,$),$=n.add(y,x);let lt=n.add(g,T);return $=n.mul($,lt),lt=n.add(k,tt),$=n.sub($,lt),lt=n.add(S,x),I=n.add(A,T),lt=n.mul(lt,I),I=n.add(J,tt),lt=n.sub(lt,I),O=n.mul(P,$),I=n.mul(M,tt),O=n.add(I,O),I=n.sub(J,O),O=n.add(J,O),R=n.mul(I,O),J=n.add(k,k),J=n.add(J,k),tt=n.mul(P,tt),$=n.mul(M,$),J=n.add(J,tt),tt=n.sub(k,tt),tt=n.mul(P,tt),$=n.add($,tt),k=n.mul(J,$),R=n.add(R,k),k=n.mul(lt,$),I=n.mul(et,I),I=n.sub(I,k),k=n.mul(et,J),O=n.mul(lt,O),O=n.add(O,k),new L(I,R,O)}subtract(h){return _(h),this.add(h.negate())}is0(){return this.equals(L.ZERO)}multiply(h){let{endo:y}=t;if(!o.isValidNot0(h))throw new RangeError("invalid scalar: out of range");let S,x,g=A=>H.cached(this,A,T=>oe(L,T));if(y){let{k1neg:A,k1:T,k2neg:I,k2:R}=F(h),{p:O,f:P}=g(T),{p:M,f:k}=g(R);x=P.add(k),S=C(y.beta,O,M,A,I)}else{let{p:A,f:T}=g(h);S=A,x=T}return oe(L,[S,x])[0]}multiplyUnsafe(h){let{endo:y}=t,S=this,x=h;if(!o.isValid(x))throw new RangeError("invalid scalar: out of range");if(x===Rt||S.is0())return L.ZERO;if(x===Wt)return S;if(H.hasCache(this))return this.multiply(x);if(y){let{k1neg:g,k1:A,k2neg:T,k2:I}=F(x),{p1:R,p2:O}=ri(L,S,A,I);return C(y.beta,R,O,g,T)}else return H.unsafe(S,x)}toAffine(h){let y=this,S=h,{X:x,Y:g,Z:A}=y;if(n.eql(A,n.ONE))return{x,y:g};let T=y.is0();S==null&&(S=T?n.ONE:n.inv(A));let I=n.mul(x,S),R=n.mul(g,S),O=n.mul(A,S);if(T)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:I,y:R}}isTorsionFree(){let{isTorsionFree:h}=t;return i===Wt?!0:h?h(L,this):H.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:h}=t;return i===Wt?this:h?h(L,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Wt?this.is0():this.clearCofactor().is0()}toBytes(h=!0){return wt(h,"isCompressed"),this.assertValidity(),b(L,this,h)}toHex(h=!0){return Be(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let K=o.BITS,H=new De(L,t.endo?Math.ceil(K/2):K);return K>=8&&L.BASE.precompute(8),Object.freeze(L.prototype),Object.freeze(L),L}function Mi(e){return Uint8Array.of(e?2:3)}function qi(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Df(e,t={}){let{Fn:r}=e,n=t.randomBytes===void 0?Ge:t.randomBytes,o=Object.assign(qi(e.Fp,r),{seed:Math.max(Vn(r.ORDER),16)});function s(d){try{let b=r.fromBytes(d);return r.isValidNot0(b)}catch{return!1}}function i(d,b){let{publicKey:E,publicKeyUncompressed:p}=o;try{let w=d.length;return b===!0&&w!==E||b===!1&&w!==p?!1:!!e.fromBytes(d)}catch{return!1}}function a(d){return d=d===void 0?n(o.seed):d,jn(N(d,o.seed,"seed"),r.ORDER)}function f(d,b=!0){return e.BASE.multiply(r.fromBytes(d)).toBytes(b)}function c(d){let{secretKey:b,publicKey:E,publicKeyUncompressed:p}=o,w=r._lengths;if(!te(d))return;let v=N(d,void 0,"key").length,B=v===E||v===p,D=v===b||!!w?.includes(v);if(!(B&&D))return B}function u(d,b,E=!0){if(c(d)===!0)throw new Error("first arg must be private key");if(c(b)===!1)throw new Error("second arg must be public key");let p=r.fromBytes(d);return e.fromBytes(b).multiply(p).toBytes(E)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},m=Cr(a,f);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:f,getSharedSecret:u,keygen:m,Point:e,utils:l,lengths:o})}function Hi(e,t,r={}){let n=t;xr(n),St(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?Ge:r.randomBytes,s=r.hmac===void 0?(x,g)=>Ui(n,x,g):r.hmac,{Fp:i,Fn:a}=e,{ORDER:f,BITS:c}=a,{keygen:u,getPublicKey:l,getSharedSecret:m,utils:d,lengths:b}=Df(e,r),E={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},p=f*Pi+Wt<i.ORDER;function w(x){let g=f>>Wt;return x>g}function v(x,g){if(!a.isValidNot0(g))throw new Error(`invalid signature ${x}: out of range 1..Point.Fn.ORDER`);return g}function B(){if(p)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function D(x,g){Ro(g);let A=b.signature,T=g==="compact"?A:g==="recovered"?A+1:void 0;return N(x,T)}class _{r;s;recovery;constructor(g,A,T){if(this.r=v("r",g),this.s=v("s",A),T!=null){if(B(),![0,1,2,3].includes(T))throw new Error("invalid recovery id");this.recovery=T}Object.freeze(this)}static fromBytes(g,A=E.format){D(g,A);let T;if(A==="der"){let{r:P,s:M}=At.toSig(N(g));return new _(P,M)}A==="recovered"&&(T=g[0],A="compact",g=g.subarray(1));let I=b.signature/2,R=g.subarray(0,I),O=g.subarray(I,I*2);return new _(a.fromBytes(R),a.fromBytes(O),T)}static fromHex(g,A){return this.fromBytes(Ie(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 _(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 O=i.toBytes(R),P=e.fromBytes(Q(Mi((I&1)===0),O)),M=a.inv(R),k=C(N(g,void 0,"msgHash")),J=a.create(-k*M),tt=a.create(T*M),et=e.BASE.multiplyUnsafe(J).add(P.multiplyUnsafe(tt));if(et.is0())throw new Error("invalid recovery: point at infinify");return et.assertValidity(),et}hasHighS(){return w(this.s)}toBytes(g=E.format){if(Ro(g),g==="der")return Ie(At.hexFromSig(this));let{r:A,s:T}=this,I=a.toBytes(A),R=a.toBytes(T);return g==="recovered"?(B(),Q(Uint8Array.of(this.assertRecovery()),I,R)):Q(I,R)}toHex(g){return Be(this.toBytes(g))}}Object.freeze(_.prototype),Object.freeze(_);let F=r.bits2int===void 0?function(g){if(g.length>8192)throw new Error("input is too large");let A=ee(g),T=g.length*8-c;return T>0?A>>BigInt(T):A}:r.bits2int,C=r.bits2int_modN===void 0?function(g){return a.create(F(g))}:r.bits2int_modN,L=Je(c);function K(x){return Le("num < 2^"+c,x,Rt,L),a.toBytes(x)}function H(x,g){return N(x,void 0,"message"),g?N(n(x),void 0,"prehashed message"):x}function U(x,g,A){let{lowS:T,prehash:I,extraEntropy:R}=_o(A,E);x=H(x,I);let O=C(x),P=a.fromBytes(g);if(!a.isValidNot0(P))throw new Error("invalid private key");let M=[K(P),K(O)];if(R!=null&&R!==!1){let et=R===!0?o(b.secretKey):R;M.push(N(et,void 0,"extraEntropy"))}let k=Q(...M),J=O;function tt(et){let $=F(et);if(!a.isValidNot0($))return;let lt=a.inv($),he=e.BASE.multiply($).toAffine(),Ue=a.create(he.x);if(Ue===Rt)return;let lr=a.create(lt*a.create(J+Ue*P));if(lr===Rt)return;let jo=(he.x===Ue?0:2)|Number(he.y&Wt),zo=lr;return T&&w(lr)&&(zo=a.neg(lr),jo^=1),new _(Ue,zo,p?void 0:jo)}return{seed:k,k2sig:tt}}function h(x,g,A={}){let{seed:T,k2sig:I}=U(x,g,A);return Ns(n.outputLen,a.BYTES,s)(T,I).toBytes(A.format)}function y(x,g,A,T={}){let{lowS:I,prehash:R,format:O}=_o(T,E);if(A=N(A,void 0,"publicKey"),g=H(g,R),!te(x)){let P=x instanceof _?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+P)}D(x,O);try{let P=_.fromBytes(x,O),M=e.fromBytes(A);if(I&&P.hasHighS())return!1;let{r:k,s:J}=P,tt=C(g),et=a.inv(J),$=a.create(tt*et),lt=a.create(k*et),he=e.BASE.multiplyUnsafe($).add(M.multiplyUnsafe(lt));return he.is0()?!1:a.create(he.x)===k}catch{return!1}}function S(x,g,A={}){let{prehash:T}=_o(A,E);return g=H(g,T),_.fromBytes(x,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:m,utils:d,lengths:b,Point:e,sign:h,verify:y,recoverPublicKey:S,Signature:_,hash:n})}var Oo={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Cf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Vi=BigInt(2);function Of(e){let t=Oo.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=V(u,r,t)*u%t,m=V(l,r,t)*u%t,d=V(m,Vi,t)*c%t,b=V(d,o,t)*d%t,E=V(b,s,t)*b%t,p=V(E,a,t)*E%t,w=V(p,f,t)*p%t,v=V(w,a,t)*E%t,B=V(v,r,t)*u%t,D=V(B,i,t)*b%t,_=V(D,n,t)*c%t,F=V(_,Vi,t);if(!Co.eql(Co.sqr(F),e))throw new Error("Cannot find square root");return F}var Co=_e(Oo.p,{sqrt:Of}),Ff=Ni(Oo,{Fp:Co,endo:Cf}),Ke=Hi(Ff,Ae);var ji=33;function zi(e,t,r,n){let o=yr.digest(r instanceof Uint8Array?r:r.subarray());if(Kr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ke.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new rr(String(s))});try{return n?.signal?.throwIfAborted(),Ke.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new rr(String(s))}}var jr=class{type="secp256k1";raw;_key;constructor(t){this._key=Yi(t),this.raw=Zi(this._key)}toMultihash(){return It.digest(Se(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}verify(t,r,n){return zi(this._key,r,t,n)}};function $i(e){return new jr(e)}function Zi(e){return Ke.Point.fromBytes(e).toBytes()}function Yi(e){try{return Ke.Point.fromBytes(e),e}catch(t){throw new de(String(t))}}function Gi(e){if(e.byteLength===Oe)return mi(e);if(e.byteLength===ji)return $i(e);let t=Lt(e),r=t[1]?.[0];if(r===bs||r===gs||r===xs)return Es(t);if(t[0]?.[0]===Ki)return qr(t,e);throw new j("Could not extract public key from raw bytes")}function Se(e){return Xt.encode({Type:ut[e.type],Data:e.raw})}var Xi=Symbol.for("nodejs.util.inspect.custom"),Kf=114,fr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Wr]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return it.createV1(Kf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return at(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return at(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Xi](){return`PeerId(${this.toString()})`}},zr=class extends fr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Zr=class extends fr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Yr=class extends fr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Uf=2336,Fo=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=It.digest(X(this.url))}[Xi](){return`PeerId(${this.url})`}[Wr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return it.createV1(Uf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=Z(t)),t.toString()===this.toString())}};function Wi(e){if(e.type==="Ed25519")return new Zr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Yr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new zr({multihash:e.toCID().multihash,publicKey:e});throw new Pe}var Ko=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},Ji=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function Uo(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,f,u=new Promise((l,m)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){m(Ji(i));return}if(i&&(f=()=>{m(Ji(i))},i.addEventListener("abort",f,{once:!0})),e.then(l,m),r===Number.POSITIVE_INFINITY)return;let d=new Ko;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(b){m(b)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?l():o instanceof Error?m(o):(d.message=o??`Promise timed out after ${r} milliseconds`,m(d))},r)}).finally(()=>{u.clear(),f&&i&&i.removeEventListener("abort",f)});return u.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},u}var kf=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function Pf(e,t,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[t].flat(),f=[],{addListener:c,removeListener:u}=kf(e),l=async(...d)=>{let b=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(b))return}catch(E){n(),i(E);return}f.push(b),r.count===f.length&&(n(),s(f))},m=(...d)=>{n(),i(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)u(d,l);for(let d of r.rejectionEvents)a.includes(d)||u(d,m)};for(let d of a)c(d,l);for(let d of r.rejectionEvents)a.includes(d)||c(d,m);r.signal&&r.signal.addEventListener("abort",()=>{m(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(f)});if(o.cancel=n,typeof r.timeout=="number"){let s=Uo(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Qi(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Pf(e,t,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var le=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Nf(e){return e.reason}async function ko(e,t,r){if(t==null)return e;let n=r?.translateError??Nf;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var qf=4194304,$r=class extends Error{static name="UnwrappedError";name="UnwrappedError"},No=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Mo=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},qo=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Hf(e){return typeof e?.closeRead=="function"}function Vf(e){return typeof e?.close=="function"}function Po(e){return Hf(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:Vf(e)?e.status!=="open":!1}function jf(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function zf(e,t){let r=t?.maxBufferSize??qf,n=new rt,o,s=!1;if(!jf(e))throw new j("Argument should be a Stream or a Multiaddr");let i=u=>{if(n.append(u.data),n.byteLength>r){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${r}`))}o?.resolve()};e.addEventListener("message",i);let a=u=>{u.error!=null?o?.reject(u.error):o?.resolve()};e.addEventListener("close",a);let f=()=>{o?.resolve()};e.addEventListener("remoteCloseWrite",f);let c={readBuffer:n,async read(u){if(s===!0)throw new $r("Stream was unwrapped");if(Po(e)){if(n.byteLength===0&&u?.bytes==null)return null;if(u?.bytes!=null&&n.byteLength<u.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,u.bytes),new le(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let l=u?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await ko(o.promise,u?.signal),Po(e)){if(n.byteLength===0&&u?.bytes==null)return null;break}o=Promise.withResolvers()}let m=u?.bytes??n.byteLength;if(n.byteLength<m){if(Po(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,m),new le(`Unexpected EOF - stream closed while reading ${n.byteLength}/${m} bytes`);return c.read(u)}let d=n.sublist(0,m);return n.consume(m),d},async write(u,l){if(s===!0)throw new $r("Stream was unwrapped");e.send(u)||await Qi(e,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",i),e.removeEventListener("close",a),e.removeEventListener("remoteCloseWrite",f),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e}};return c}function Zf(e,t={}){let r=zf(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=kt(t.maxDataLength));let n=t?.lengthDecoder??bi,o=t?.lengthEncoder??yi;return{async read(i){let a=-1,f=new rt;for(;;){let u=await r.read({...i,bytes:1});if(u==null)break;f.append(u);try{a=n(f)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new No("Invalid message length");if(t?.maxLengthLength!=null&&f.byteLength>t.maxLengthLength)throw new qo(`Message length length too long - ${f.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Mo(`Message length too long - ${a} > ${t.maxDataLength}`);let c=await r.read({...i,bytes:a});if(c==null)throw e.log.error("tried to read %d bytes but the stream closed",a),new le(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(c.byteLength!==a)throw e.log.error("read %d/%d bytes before the stream closed",c.byteLength,a),new le(`Unexpected EOF - read ${c.byteLength}/${a} bytes before the stream closed`);return c},async write(i,a){await r.write(new rt(o(i.byteLength),i),a)},async writeV(i,a){let f=new rt(...i.flatMap(c=>[o(c.byteLength),c]));await r.write(f,a)},unwrap(){return r.unwrap()}}}function ta(e,t){let r=Zf(e,t),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var Gr;(function(e){let t;e.codec=()=>(t==null&&(t=ue((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.id!=null&&(i.uint32(10),i.bytes(s.id)),s.pubkey!=null&&(i.uint32(18),ur.codec().encode(s.pubkey,i)),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.id=s.bytes();break}case 2:{f.pubkey=ur.codec().decode(s,s.uint32(),{limits:a.limits?.pubkey});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}.id`,value:s.bytes()};break}case 2:{yield*ur.codec().stream(s,s.uint32(),`${a}.pubkey`,{limits:f.limits?.pubkey});break}default:{s.skipType(u&7);break}}}})),t);function r(s){return ce(s,e.codec())}e.encode=r;function n(s,i){return ie(s,e.codec(),i)}e.decode=n;function o(s,i){return fe(s,e.codec(),i)}e.stream=o})(Gr||(Gr={}));var Pt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(Pt||(Pt={}));var Ho;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Ho||(Ho={}));(function(e){e.codec=()=>ir(Ho)})(Pt||(Pt={}));var ur;(function(e){let t;e.codec=()=>(t==null&&(t=ue((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),Pt.codec().encode(s.Type,i)),s.Data!=null&&s.Data.byteLength>0&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let f={Data:gt(0)},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{f.Type=Pt.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:Pt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return ce(s,e.codec())}e.encode=r;function n(s,i){return ie(s,e.codec(),i)}e.decode=n;function o(s,i){return fe(s,e.codec(),i)}e.stream=o})(ur||(ur={}));var Yf="/plaintext/2.0.0",Vo=class{protocol=Yf;privateKey;log;constructor(t){this.privateKey=t.privateKey,this.log=t.logger.forComponent("libp2p:plaintext")}[Symbol.toStringTag]="@libp2p/plaintext";[Zo]=["@libp2p/connection-encryption"];async secureInbound(t,r){return this._encrypt(t,r)}async secureOutbound(t,r){return this._encrypt(t,r)}async _encrypt(t,r){let n=t.log?.newScope("plaintext")??this.log,o=ta(t).pb(Gr);n("write pubkey exchange to peer %p",r?.remotePeer);let s=this.privateKey.publicKey;await o.write({id:s.toMultihash().bytes,pubkey:{Type:Pt[s.type],Data:s.raw}},r);let i=await o.read(r),a;try{if(i.pubkey==null)throw new pe("Public key missing");if(i.pubkey.Data.byteLength===0)throw new pe("Public key data too short");if(i.id==null)throw new pe("Remote id missing");let f=Gi(i.pubkey.Data);if(a=Wi(f),!at(a.toMultihash().bytes,i.id))throw new ke("Public key did not match id")}catch(f){throw n.error("invalid public key - %e",f),new ke(`Invalid public key - ${f.message}`)}if(r?.remotePeer!=null&&!a.equals(r?.remotePeer))throw new hr;return n("plaintext key exchange completed successfully with peer %p",a),{connection:o.unwrap().unwrap(),remotePeer:a}}};function $f(){return e=>new Vo(e)}return sa(Gf);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
|
-
@noble/hashes/utils.js:
|
|
6
|
-
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
7
|
-
|
|
8
5
|
@noble/curves/utils.js:
|
|
9
6
|
@noble/curves/abstract/modular.js:
|
|
10
7
|
@noble/curves/abstract/curve.js:
|