@libp2p/plaintext 2.0.29-a02cb0461 → 2.0.29-e8398d97e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +3 -3
- package/package.json +8 -8
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPlaintext = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PPlaintext=(()=>{var jr=Object.defineProperty;var ji=Object.getOwnPropertyDescriptor;var Zi=Object.getOwnPropertyNames;var Gi=Object.prototype.hasOwnProperty;var ht=(e,t)=>{for(var r in t)jr(e,r,{get:t[r],enumerable:!0})},Yi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Zi(t))!Gi.call(e,o)&&o!==r&&jr(e,o,{get:()=>t[o],enumerable:!(n=ji(t,o))||n.enumerable});return e};var $i=e=>Yi(jr({},"__esModule",{value:!0}),e);var Zu={};ht(Zu,{plaintext:()=>ju});var lr=class extends Error{static name="UnexpectedPeerError";constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError"}},Me=class extends Error{static name="InvalidCryptoExchangeError";constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError"}},G=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},pe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var me=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var He=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Zr=Symbol.for("@libp2p/peer-id");var Oo=Symbol.for("@libp2p/service-capabilities"),Xu=Symbol.for("@libp2p/service-dependencies");var Wr={};ht(Wr,{base58btc:()=>W,base58flickr:()=>ra});var Af=new Uint8Array(0);function Mo(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 Tt(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 Ho(e){return new TextEncoder().encode(e)}function qo(e){return new TextDecoder().decode(e)}function Xi(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,c=e.charAt(0),f=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function h(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var E=0,v=0,x=0,A=p.length;x!==A&&p[x]===0;)x++,E++;for(var w=(A-x)*d+1>>>0,D=new Uint8Array(w);x!==A;){for(var R=p[x],O=0,k=w-1;(R!==0||O<v)&&k!==-1;k--,O++)R+=256*D[k]>>>0,D[k]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");v=O,x++}for(var U=w-v;U!==w&&D[U]===0;)U++;for(var g=c.repeat(E);U<w;++U)g+=e.charAt(D[U]);return g}function u(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var E=0;if(p[E]!==" "){for(var v=0,x=0;p[E]===c;)v++,E++;for(var A=(p.length-E)*f+1>>>0,w=new Uint8Array(A);p[E];){var D=r[p.charCodeAt(E)];if(D===255)return;for(var R=0,O=A-1;(D!==0||R<x)&&O!==-1;O--,R++)D+=a*w[O]>>>0,w[O]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");x=R,E++}if(p[E]!==" "){for(var k=A-x;k!==A&&w[k]===0;)k++;for(var U=new Uint8Array(v+(A-k)),g=v;k!==A;)U[g++]=w[k++];return U}}}function l(p){var E=u(p);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:u,decode:l}}var Wi=Xi,Ji=Wi,Fo=Ji;var Gr=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")}},Yr=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 zo(this,t)}},$r=class{decoders;constructor(t){this.decoders=t}or(t){return zo(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 zo(e,t){return new $r({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Xr=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 Gr(t,r,n),this.decoder=new Yr(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ye({name:e,prefix:t,encode:r,decode:n}){return new Xr(e,t,r,n)}function zt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Fo(r,e);return ye({prefix:t,name:e,encode:n,decode:s=>Tt(o(s))})}function Qi(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let d=t[e[f]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|d,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ta(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function ea(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function Y({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=ea(n);return ye({prefix:t,name:e,encode(s){return ta(s,n,r)},decode(s){return Qi(s,o,r,e)}})}var W=zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ra=zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Jr={};ht(Jr,{base32:()=>be,base32hex:()=>ia,base32hexpad:()=>ca,base32hexpadupper:()=>ua,base32hexupper:()=>aa,base32pad:()=>oa,base32padupper:()=>sa,base32upper:()=>na,base32z:()=>fa});var be=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),na=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),oa=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),sa=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ia=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),aa=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ca=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ua=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),fa=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Qr={};ht(Qr,{base36:()=>qe,base36upper:()=>la});var qe=zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),la=zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ha=Go,jo=128,da=127,pa=~da,ma=Math.pow(2,31);function Go(e,t,r){t=t||[],r=r||0;for(var n=r;e>=ma;)t[r++]=e&255|jo,e/=128;for(;e&pa;)t[r++]=e&255|jo,e>>>=7;return t[r]=e|0,Go.bytes=r-n+1,t}var ya=tn,ba=128,Zo=127;function tn(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw tn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Zo)<<o:(i&Zo)*Math.pow(2,o),o+=7}while(i>=ba);return tn.bytes=s-n,r}var xa=Math.pow(2,7),ga=Math.pow(2,14),wa=Math.pow(2,21),Ea=Math.pow(2,28),Sa=Math.pow(2,35),va=Math.pow(2,42),Aa=Math.pow(2,49),Ba=Math.pow(2,56),Ia=Math.pow(2,63),La=function(e){return e<xa?1:e<ga?2:e<wa?3:e<Ea?4:e<Sa?5:e<va?6:e<Aa?7:e<Ba?8:e<Ia?9:10},_a={encode:ha,decode:ya,encodingLength:La},Ta=_a,Ve=Ta;function Fe(e,t=0){return[Ve.decode(e,t),Ve.decode.bytes]}function xe(e,t,r=0){return Ve.encode(e,t,r),t}function ge(e){return Ve.encodingLength(e)}function Bt(e,t){let r=t.byteLength,n=ge(e),o=n+ge(r),s=new Uint8Array(o+r);return xe(e,s,0),xe(r,s,n),s.set(t,o),new we(e,r,t,s)}function en(e){let t=Tt(e),[r,n]=Fe(t),[o,s]=Fe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new we(r,o,i,t)}function Yo(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Mo(e.bytes,r.bytes)}}var we=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function $o(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Ca(r,rn(e),t??W.encoder);default:return Ka(r,rn(e),t??be.encoder)}}var Xo=new WeakMap;function rn(e){let t=Xo.get(e);if(t==null){let r=new Map;return Xo.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!==ze)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ra)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&&Yo(t.multihash,n.multihash)}toString(t){return $o(this,t)}toJSON(){return{"/":$o(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??Wo(n,o,s.bytes))}else if(r[Ua]===!0){let{version:n,multihash:o,code:s}=r,i=en(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!==ze)throw new Error(`Version 0 CID must use dag-pb (code: ${ze}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Wo(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,ze,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=Tt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new we(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[h,u]=Fe(t.subarray(r));return r+=u,h},o=n(),s=ze;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),f=r+c,d=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:f}}static parse(t,r){let[n,o]=Da(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 rn(s).set(n,t),s}};function Da(e,t){switch(e[0]){case"Q":{let r=t??W;return[W.prefix,r.decode(`${W.prefix}${e}`)]}case W.prefix:{let r=t??W;return[W.prefix,r.decode(e)]}case be.prefix:{let r=t??be;return[be.prefix,r.decode(e)]}case qe.prefix:{let r=t??qe;return[qe.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 Ca(e,t,r){let{prefix:n}=r;if(n!==W.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 Ka(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 ze=112,Ra=18;function Wo(e,t,r){let n=ge(e),o=n+ge(t),s=new Uint8Array(o+r.byteLength);return xe(e,s,0),xe(t,s,n),s.set(r,o),s}var Ua=Symbol.for("@ipld/js-cid/CID");var nn={};ht(nn,{identity:()=>It});var Jo=0,Pa="identity",Qo=Tt;function Na(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(Jo,Qo(e))}var It={code:Jo,name:Pa,encode:Qo,digest:Na};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 St(e=0){return new Uint8Array(e)}function dt(e=0){return new Uint8Array(e)}function dr(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 es=Symbol.for("@achingbrain/uint8arraylist");function ts(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 pr(e){return!!e?.[es]}var tt=class e{bufs;length;[es]=!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(pr(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(pr(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=ts(this.bufs,t);return r.buf[r.index]}set(t,r){let n=ts(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(pr(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 dr(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:dr(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,d=r>a&&r<=c;if(f&&d){if(t===a&&r===c){n.push(i);break}let h=t-a;n.push(i.subarray(h,h+(r-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(d){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!pr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,d;for(let h=r;h<=c;h+=d){d=0;for(let u=f;u>=0;u--){let l=this.get(h+u);if(n[u]!==l){d=Math.max(1,u-a[l]);break}}if(d===0)return h}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=dt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=St(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=St(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=St(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=dt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=St(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=St(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=St(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=St(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=St(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!it(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var on={};ht(on,{base10:()=>ka});var ka=zt({prefix:"9",name:"base10",alphabet:"0123456789"});var sn={};ht(sn,{base16:()=>Oa,base16upper:()=>Ma});var Oa=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ma=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var an={};ht(an,{base2:()=>Ha});var Ha=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var cn={};ht(cn,{base256emoji:()=>ja});var rs=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}"),qa=rs.reduce((e,t,r)=>(e[r]=t,e),[]),Va=rs.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Fa(e){return e.reduce((t,r)=>(t+=qa[r],t),"")}function za(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Va[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var ja=ye({prefix:"\u{1F680}",name:"base256emoji",encode:Fa,decode:za});var un={};ht(un,{base64:()=>Za,base64pad:()=>Ga,base64url:()=>Ya,base64urlpad:()=>$a});var Za=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ga=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ya=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),$a=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var fn={};ht(fn,{base8:()=>Xa});var Xa=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ln={};ht(ln,{identity:()=>Wa});var Wa=ye({prefix:"\0",name:"identity",encode:e=>qo(e),decode:e=>Ho(e)});var al=new TextEncoder,cl=new TextDecoder;var pn={};ht(pn,{sha256:()=>mr,sha512:()=>ec});var tc=20;function dn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new hn(e,t,r,n,o)}var hn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??tc,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?ns(n,this.code,r?.truncate):n.then(o=>ns(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ns(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 ss(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var mr=dn({name:"sha2-256",code:18,encode:ss("SHA-256")}),ec=dn({name:"sha2-512",code:19,encode:ss("SHA-512")});var mn={...ln,...an,...fn,...on,...sn,...Jr,...Qr,...Wr,...un,...cn},wl={...pn,...nn};function as(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var is=as("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),yn=as("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}),rc={utf8:is,"utf-8":is,hex:mn.base16,latin1:yn,ascii:yn,binary:yn,...mn},yr=rc;function J(e,t="utf8"){let r=yr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function $(e,t="utf8"){let r=yr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var nc=parseInt("11111",2),bn=parseInt("10000000",2),oc=parseInt("01111111",2),cs={0:je,1:je,2:sc,3:cc,4:uc,5:ac,6:ic,16:je,22:je,48:je};function Lt(e,t={offset:0}){let r=e[t.offset]&nc;if(t.offset++,cs[r]!=null)return cs[r](e,t);throw new Error("No decoder for tag "+r)}function Ze(e,t){let r=0;if((e[t.offset]&bn)===bn){let n=e[t.offset]&oc,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 je(e,t){Ze(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Lt(e,t);if(n===null)break;r.push(n)}return r}function sc(e,t){let r=Ze(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function ic(e,t){let r=Ze(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let f=e[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let d=0;for(let h=0;h<c.length;h++)d+=c[h]<<h*7;a+=`.${d}`,c=[]}}return a}function ac(e,t){return t.offset++,null}function cc(e,t){let r=Ze(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function uc(e,t){let r=Ze(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function fc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new tt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function xn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=fc(e.byteLength);return new tt(Uint8Array.from([t.byteLength|bn]),t)}function pt(e){let t=new tt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new tt(Uint8Array.from([2]),xn(t),t)}function br(e){let t=Uint8Array.from([0]),r=new tt(t,e);return new tt(Uint8Array.from([3]),xn(r),r)}function jt(e,t=48){let r=new tt;for(let n of e)r.append(n);return new tt(Uint8Array.from([t]),xn(r),r)}var us="1.2.840.10045.3.1.7",fs="1.3.132.0.34",ls="1.3.132.0.35";async function hs(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var lc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),hc=Uint8Array.from([6,5,43,129,4,0,34]),dc=Uint8Array.from([6,5,43,129,4,0,35]),pc={ext:!0,kty:"EC",crv:"P-256"},mc={ext:!0,kty:"EC",crv:"P-384"},yc={ext:!0,kty:"EC",crv:"P-521"},gn=32,wn=48,En=66;function ds(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===gn*2+1)return n=$(t.subarray(r,r+gn),"base64url"),o=$(t.subarray(r+gn),"base64url"),new Se({...pc,key_ops:["verify"],x:n,y:o});if(t.byteLength===wn*2+1)return n=$(t.subarray(r,r+wn),"base64url"),o=$(t.subarray(r+wn),"base64url"),new Se({...mc,key_ops:["verify"],x:n,y:o});if(t.byteLength===En*2+1)return n=$(t.subarray(r,r+En),"base64url"),o=$(t.subarray(r+En),"base64url"),new Se({...yc,key_ops:["verify"],x:n,y:o});throw new G(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ps(e){return jt([pt(Uint8Array.from([1])),jt([bc(e.crv)],160),jt([br(new tt(Uint8Array.from([4]),J(e.x??"","base64url"),J(e.y??"","base64url")))],161)]).subarray()}function bc(e){if(e==="P-256")return lc;if(e==="P-384")return hc;if(e==="P-521")return dc;throw new G(`Invalid curve ${e}`)}var Se=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ps(this.jwk)),this._raw}toMultihash(){return It.digest(ve(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return W.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 hs(this.jwk,r,t,n)}};var re=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ct(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ge(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function mt(e,...t){if(!Ct(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function xr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Ge(e.outputLen),Ge(e.blockLen)}function Be(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 ys(e,t){mt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Kt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function gr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function vt(e,t){return e<<32-t|e>>>t}var bs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",xc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function wt(e){if(mt(e),bs)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=xc[e[r]];return t}var Dt={_0:48,_9:57,A:65,F:70,a:97,f:102};function ms(e){if(e>=Dt._0&&e<=Dt._9)return e-Dt._0;if(e>=Dt.A&&e<=Dt.F)return e-(Dt.A-10);if(e>=Dt.a&&e<=Dt.f)return e-(Dt.a-10)}function ne(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(bs)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=ms(e.charCodeAt(s)),a=ms(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Sn(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Ye(e){return typeof e=="string"&&(e=Sn(e)),mt(e),e}function ut(...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}var Ae=class{};function vn(e){let t=n=>e().update(Ye(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Ie(e=32){if(re&&typeof re.getRandomValues=="function")return re.getRandomValues(new Uint8Array(e));if(re&&typeof re.randomBytes=="function")return Uint8Array.from(re.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function gc(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),a=Number(r&s),c=n?4:0,f=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+f,a,n)}function xs(e,t,r){return e&t^~e&r}function gs(e,t,r){return e&t^e&r^t&r}var $e=class extends Ae{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=gr(this.buffer)}update(t){Be(this),t=Ye(t),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 c=gr(t);for(;o<=s-i;i+=o)this.process(c,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){Be(this),ys(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Kt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let h=i;h<o;h++)r[h]=0;gc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=gr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,d=this.get();if(f>d.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,d[h],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(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()}},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 wr=BigInt(4294967295),ws=BigInt(32);function wc(e,t=!1){return t?{h:Number(e&wr),l:Number(e>>ws&wr)}:{h:Number(e>>ws&wr)|0,l:Number(e&wr)|0}}function Es(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}=wc(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var An=(e,t,r)=>e>>>r,Bn=(e,t,r)=>e<<32-r|t>>>r,oe=(e,t,r)=>e>>>r|t<<32-r,se=(e,t,r)=>e<<32-r|t>>>r,Xe=(e,t,r)=>e<<64-r|t>>>r-32,We=(e,t,r)=>e>>>r-32|t<<64-r;function _t(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Ss=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),vs=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,As=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Bs=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Is=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Ls=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Sc=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),Er=class extends $e{constructor(t=32){super(64,t,8,!1),this.A=Rt[0]|0,this.B=Rt[1]|0,this.C=Rt[2]|0,this.D=Rt[3]|0,this.E=Rt[4]|0,this.F=Rt[5]|0,this.G=Rt[6]|0,this.H=Rt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let h=0;h<16;h++,r+=4)Zt[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){let u=Zt[h-15],l=Zt[h-2],p=vt(u,7)^vt(u,18)^u>>>3,E=vt(l,17)^vt(l,19)^l>>>10;Zt[h]=E+Zt[h-7]+p+Zt[h-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:d}=this;for(let h=0;h<64;h++){let u=vt(a,6)^vt(a,11)^vt(a,25),l=d+u+xs(a,c,f)+Sc[h]+Zt[h]|0,E=(vt(n,2)^vt(n,13)^vt(n,22))+gs(n,o,s)|0;d=f,f=c,c=a,a=i+l|0,i=s,s=o,o=n,n=l+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,c=c+this.F|0,f=f+this.G|0,d=d+this.H|0,this.set(n,o,s,i,a,c,f,d)}roundClean(){Kt(Zt)}destroy(){this.set(0,0,0,0,0,0,0,0),Kt(this.buffer)}};var _s=Es(["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))),vc=_s[0],Ac=_s[1],Gt=new Uint32Array(80),Yt=new Uint32Array(80),In=class extends $e{constructor(t=64){super(128,t,16,!1),this.Ah=nt[0]|0,this.Al=nt[1]|0,this.Bh=nt[2]|0,this.Bl=nt[3]|0,this.Ch=nt[4]|0,this.Cl=nt[5]|0,this.Dh=nt[6]|0,this.Dl=nt[7]|0,this.Eh=nt[8]|0,this.El=nt[9]|0,this.Fh=nt[10]|0,this.Fl=nt[11]|0,this.Gh=nt[12]|0,this.Gl=nt[13]|0,this.Hh=nt[14]|0,this.Hl=nt[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:d,Fh:h,Fl:u,Gh:l,Gl:p,Hh:E,Hl:v}=this;return[t,r,n,o,s,i,a,c,f,d,h,u,l,p,E,v]}set(t,r,n,o,s,i,a,c,f,d,h,u,l,p,E,v){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=d|0,this.Fh=h|0,this.Fl=u|0,this.Gh=l|0,this.Gl=p|0,this.Hh=E|0,this.Hl=v|0}process(t,r){for(let w=0;w<16;w++,r+=4)Gt[w]=t.getUint32(r),Yt[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let D=Gt[w-15]|0,R=Yt[w-15]|0,O=oe(D,R,1)^oe(D,R,8)^An(D,R,7),k=se(D,R,1)^se(D,R,8)^Bn(D,R,7),U=Gt[w-2]|0,g=Yt[w-2]|0,_=oe(U,g,19)^Xe(U,g,61)^An(U,g,6),P=se(U,g,19)^We(U,g,61)^Bn(U,g,6),T=As(k,P,Yt[w-7],Yt[w-16]),b=Bs(T,O,_,Gt[w-7],Gt[w-16]);Gt[w]=b|0,Yt[w]=T|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:d,Eh:h,El:u,Fh:l,Fl:p,Gh:E,Gl:v,Hh:x,Hl:A}=this;for(let w=0;w<80;w++){let D=oe(h,u,14)^oe(h,u,18)^Xe(h,u,41),R=se(h,u,14)^se(h,u,18)^We(h,u,41),O=h&l^~h&E,k=u&p^~u&v,U=Is(A,R,k,Ac[w],Yt[w]),g=Ls(U,x,D,O,vc[w],Gt[w]),_=U|0,P=oe(n,o,28)^Xe(n,o,34)^Xe(n,o,39),T=se(n,o,28)^We(n,o,34)^We(n,o,39),b=n&s^n&a^s&a,m=o&i^o&c^i&c;x=E|0,A=v|0,E=l|0,v=p|0,l=h|0,p=u|0,{h,l:u}=_t(f|0,d|0,g|0,_|0),f=a|0,d=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let y=Ss(_,T,m);n=vs(y,g,P,b),o=y|0}({h:n,l:o}=_t(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=_t(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=_t(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:d}=_t(this.Dh|0,this.Dl|0,f|0,d|0),{h,l:u}=_t(this.Eh|0,this.El|0,h|0,u|0),{h:l,l:p}=_t(this.Fh|0,this.Fl|0,l|0,p|0),{h:E,l:v}=_t(this.Gh|0,this.Gl|0,E|0,v|0),{h:x,l:A}=_t(this.Hh|0,this.Hl|0,x|0,A|0),this.set(n,o,s,i,a,c,f,d,h,u,l,p,E,v,x,A)}roundClean(){Kt(Gt,Yt)}destroy(){Kt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Sr=vn(()=>new Er);var Ts=vn(()=>new In);var Tn=BigInt(0),_n=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 bt(e,t,r=""){let n=Ct(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function Je(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Ds(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Tn:BigInt("0x"+e)}function Le(e){return Ds(wt(e))}function Pt(e){return mt(e),Ds(wt(Uint8Array.from(e).reverse()))}function vr(e,t){return ne(e.toString(16).padStart(t*2,"0"))}function Dn(e,t){return vr(e,t).reverse()}function q(e,t,r){let n;if(typeof t=="string")try{n=ne(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Ct(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function Cs(e,t){if(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 Cn(e){return Uint8Array.from(e)}var Ln=e=>typeof e=="bigint"&&Tn<=e;function Ks(e,t,r){return Ln(e)&&Ln(t)&&Ln(r)&&t<=e&&e<r}function Qe(e,t,r,n){if(!Ks(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ar(e){let t;for(t=0;e>Tn;e>>=_n,t+=1);return t}var $t=e=>(_n<<BigInt(e))-_n;function Rs(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=l=>new Uint8Array(l),o=l=>Uint8Array.of(l),s=n(e),i=n(e),a=0,c=()=>{s.fill(1),i.fill(0),a=0},f=(...l)=>r(i,s,...l),d=(l=n(0))=>{i=f(o(0),l),s=f(),l.length!==0&&(i=f(o(1),l),s=f())},h=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,p=[];for(;l<t;){s=f();let E=s.slice();p.push(E),l+=s.length}return ut(...p)};return(l,p)=>{c(),d(l);let E;for(;!(E=p(h()));)d();return c(),E}}function Xt(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let a=e[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var Kn=()=>{throw new Error("not implemented")};function _e(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 ft=BigInt(0),et=BigInt(1),ie=BigInt(2),Ns=BigInt(3),ks=BigInt(4),Os=BigInt(5),Bc=BigInt(7),Ms=BigInt(8),Ic=BigInt(9),Hs=BigInt(16);function X(e,t){let r=e%t;return r>=ft?r:t+r}function F(e,t,r){let n=e;for(;t-- >ft;)n*=n,n%=r;return n}function Us(e,t){if(e===ft)throw new Error("invert: expected non-zero number");if(t<=ft)throw new Error("invert: expected positive modulus, got "+t);let r=X(e,t),n=t,o=ft,s=et,i=et,a=ft;for(;r!==ft;){let f=n/r,d=n%r,h=o-i*f,u=s-a*f;n=r,r=d,o=i,s=a,i=h,a=u}if(n!==et)throw new Error("invert: does not exist");return X(o,t)}function Rn(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function qs(e,t){let r=(e.ORDER+et)/ks,n=e.pow(t,r);return Rn(e,n,t),n}function Lc(e,t){let r=(e.ORDER-Os)/Ms,n=e.mul(t,ie),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,ie),o),a=e.mul(s,e.sub(i,e.ONE));return Rn(e,a,t),a}function _c(e){let t=xt(e),r=Vs(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Bc)/Hs;return(a,c)=>{let f=a.pow(c,i),d=a.mul(f,n),h=a.mul(f,o),u=a.mul(f,s),l=a.eql(a.sqr(d),c),p=a.eql(a.sqr(h),c);f=a.cmov(f,d,l),d=a.cmov(u,h,p);let E=a.eql(a.sqr(d),c),v=a.cmov(f,d,E);return Rn(a,v,c),v}}function Vs(e){if(e<Ns)throw new Error("sqrt is not defined for small field");let t=e-et,r=0;for(;t%ie===ft;)t/=ie,r++;let n=ie,o=xt(e);for(;Ps(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return qs;let s=o.pow(n,t),i=(t+et)/ie;return function(c,f){if(c.is0(f))return f;if(Ps(c,f)!==1)throw new Error("Cannot find square root");let d=r,h=c.mul(c.ONE,s),u=c.pow(f,t),l=c.pow(f,i);for(;!c.eql(u,c.ONE);){if(c.is0(u))return c.ZERO;let p=1,E=c.sqr(u);for(;!c.eql(E,c.ONE);)if(p++,E=c.sqr(E),p===d)throw new Error("Cannot find square root");let v=et<<BigInt(d-p-1),x=c.pow(h,v);d=p,h=c.sqr(x),u=c.mul(u,h),l=c.mul(l,x)}return l}}function Tc(e){return e%ks===Ns?qs:e%Ms===Os?Lc:e%Hs===Ic?_c(e):Vs(e)}var Nt=(e,t)=>(X(e,t)&et)===et,Dc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Un(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Dc.reduce((n,o)=>(n[o]="function",n),t);return Xt(e,r),e}function Cc(e,t,r){if(r<ft)throw new Error("invalid exponent, negatives unsupported");if(r===ft)return e.ONE;if(r===et)return t;let n=e.ONE,o=t;for(;r>ft;)r&et&&(n=e.mul(n,o)),o=e.sqr(o),r>>=et;return n}function tr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),s),n}function Ps(e,t){let r=(e.ORDER-et)/ie,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 Br(e,t){t!==void 0&&Ge(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function xt(e,t,r=!1,n={}){if(e<=ft)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let u=t;u.BITS&&(o=u.BITS),u.sqrt&&(s=u.sqrt),typeof u.isLE=="boolean"&&(r=u.isLE),typeof u.modFromBytes=="boolean"&&(i=u.modFromBytes),a=u.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:c,nByteLength:f}=Br(e,o);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let d,h=Object.freeze({ORDER:e,isLE:r,BITS:c,BYTES:f,MASK:$t(c),ZERO:ft,ONE:et,allowedLengths:a,create:u=>X(u,e),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return ft<=u&&u<e},is0:u=>u===ft,isValidNot0:u=>!h.is0(u)&&h.isValid(u),isOdd:u=>(u&et)===et,neg:u=>X(-u,e),eql:(u,l)=>u===l,sqr:u=>X(u*u,e),add:(u,l)=>X(u+l,e),sub:(u,l)=>X(u-l,e),mul:(u,l)=>X(u*l,e),pow:(u,l)=>Cc(h,u,l),div:(u,l)=>X(u*Us(l,e),e),sqrN:u=>u*u,addN:(u,l)=>u+l,subN:(u,l)=>u-l,mulN:(u,l)=>u*l,inv:u=>Us(u,e),sqrt:s||(u=>(d||(d=Tc(e)),d(h,u))),toBytes:u=>r?Dn(u,f):vr(u,f),fromBytes:(u,l=!0)=>{if(a){if(!a.includes(u.length)||u.length>f)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);let E=new Uint8Array(f);E.set(u,r?0:E.length-u.length),u=E}if(u.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+u.length);let p=r?Pt(u):Le(u);if(i&&(p=X(p,e)),!l&&!h.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:u=>tr(h,u),cmov:(u,l,p)=>p?l:u});return Object.freeze(h)}function Fs(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 Pn(e){let t=Fs(e);return t+Math.ceil(t/2)}function Nn(e,t,r=!1){let n=e.length,o=Fs(t),s=Pn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Pt(e):Le(e),a=X(i,t-et)+et;return r?Dn(a,o):vr(a,o)}var Te=BigInt(0),ae=BigInt(1);function er(e,t){let r=t.negate();return e?r:t}function kt(e,t){let r=tr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Gs(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function kn(e,t){Gs(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=$t(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function zs(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),c=e>>i;a>n&&(a-=s,c+=ae);let f=t*n,d=f+Math.abs(a)-1,h=a===0,u=a<0,l=t%2!==0;return{nextN:c,offset:d,isZero:h,isNeg:u,isNegF:l,offsetF:f}}function Kc(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Rc(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var On=new WeakMap,Ys=new WeakMap;function Mn(e){return Ys.get(e)||1}function js(e){if(e!==Te)throw new Error("invalid wNAF")}var De=class{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>Te;)r&ae&&(n=n.add(o)),o=o.double(),r>>=ae;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=kn(r,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let f=1;f<o;f++)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=kn(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:d,isNeg:h,isNegF:u,offsetF:l}=zs(n,a,i);n=c,d?s=s.add(er(u,r[l])):o=o.add(er(h,r[f]))}return js(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=kn(t,this.bits);for(let i=0;i<s.windows&&n!==Te;i++){let{nextN:a,offset:c,isZero:f,isNeg:d}=zs(n,i,s);if(n=a,!f){let h=r[c];o=o.add(d?h.negate():h)}}return js(n),o}getPrecomputes(t,r,n){let o=On.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),On.set(r,o))),o}cached(t,r,n){let o=Mn(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Mn(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Gs(r,this.bits),Ys.set(t,r),On.delete(t)}hasCache(t){return Mn(t)!==1}};function $s(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Te||n>Te;)r&ae&&(s=s.add(o)),n&ae&&(i=i.add(o)),o=o.double(),r>>=ae,n>>=ae;return{p1:s,p2:i}}function Ce(e,t,r,n){Kc(r,e),Rc(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,a=Ar(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let f=$t(c),d=new Array(Number(f)+1).fill(i),h=Math.floor((t.BITS-1)/c)*c,u=i;for(let l=h;l>=0;l-=c){d.fill(i);for(let E=0;E<s;E++){let v=n[E],x=Number(v>>BigInt(l)&f);d[x]=d[x].add(r[E])}let p=i;for(let E=d.length-1,v=i;E>0;E--)v=v.add(d[E]),p=p.add(v);if(u=u.add(p),l!==0)for(let E=0;E<c;E++)u=u.double()}return u}function Zs(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Un(t),t}else return xt(e,{isLE:r})}function Ir(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 c of["p","n","h"]){let f=t[c];if(!(typeof f=="bigint"&&f>Te))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Zs(t.p,r.Fp,n),s=Zs(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var Wt=BigInt(0),rt=BigInt(1),Hn=BigInt(2),Uc=BigInt(8);function Pc(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 Nc(e,t={}){let r=Ir("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;Xt(t,{},{uvRatio:"function"});let a=Hn<<BigInt(o.BYTES*8)-rt,c=v=>n.create(v),f=t.uvRatio||((v,x)=>{try{return{isValid:!0,value:n.sqrt(n.div(v,x))}}catch{return{isValid:!1,value:Wt}}});if(!Pc(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function d(v,x,A=!1){let w=A?rt:Wt;return Qe("coordinate "+v,x,w,a),x}function h(v){if(!(v instanceof p))throw new Error("ExtendedPoint expected")}let u=_e((v,x)=>{let{X:A,Y:w,Z:D}=v,R=v.is0();x==null&&(x=R?Uc:n.inv(D));let O=c(A*x),k=c(w*x),U=n.mul(D,x);if(R)return{x:Wt,y:rt};if(U!==rt)throw new Error("invZ was invalid");return{x:O,y:k}}),l=_e(v=>{let{a:x,d:A}=s;if(v.is0())throw new Error("bad point: ZERO");let{X:w,Y:D,Z:R,T:O}=v,k=c(w*w),U=c(D*D),g=c(R*R),_=c(g*g),P=c(k*x),T=c(g*c(P+U)),b=c(_+c(A*c(k*U)));if(T!==b)throw new Error("bad point: equation left != right (1)");let m=c(w*D),y=c(R*O);if(m!==y)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(x,A,w,D){this.X=d("x",x),this.Y=d("y",A),this.Z=d("z",w,!0),this.T=d("t",D),Object.freeze(this)}static CURVE(){return s}static fromAffine(x){if(x instanceof p)throw new Error("extended point not allowed");let{x:A,y:w}=x||{};return d("x",A),d("y",w),new p(A,w,rt,c(A*w))}static fromBytes(x,A=!1){let w=n.BYTES,{a:D,d:R}=s;x=Cn(bt(x,w,"point")),Ut(A,"zip215");let O=Cn(x),k=x[w-1];O[w-1]=k&-129;let U=Pt(O),g=A?a:n.ORDER;Qe("point.y",U,Wt,g);let _=c(U*U),P=c(_-rt),T=c(R*_-D),{isValid:b,value:m}=f(P,T);if(!b)throw new Error("bad point: invalid y coordinate");let y=(m&rt)===rt,S=(k&128)!==0;if(!A&&m===Wt&&S)throw new Error("bad point: x=0 and x_0=1");return S!==y&&(m=c(-m)),p.fromAffine({x:m,y:U})}static fromHex(x,A=!1){return p.fromBytes(q("point",x),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,A=!0){return E.createCache(this,x),A||this.multiply(Hn),this}assertValidity(){l(this)}equals(x){h(x);let{X:A,Y:w,Z:D}=this,{X:R,Y:O,Z:k}=x,U=c(A*k),g=c(R*D),_=c(w*k),P=c(O*D);return U===g&&_===P}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:x}=s,{X:A,Y:w,Z:D}=this,R=c(A*A),O=c(w*w),k=c(Hn*c(D*D)),U=c(x*R),g=A+w,_=c(c(g*g)-R-O),P=U+O,T=P-k,b=U-O,m=c(_*T),y=c(P*b),S=c(_*b),B=c(T*P);return new p(m,y,B,S)}add(x){h(x);let{a:A,d:w}=s,{X:D,Y:R,Z:O,T:k}=this,{X:U,Y:g,Z:_,T:P}=x,T=c(D*U),b=c(R*g),m=c(k*w*P),y=c(O*_),S=c((D+R)*(U+g)-T-b),B=y-m,C=y+m,I=c(b-A*T),L=c(S*B),K=c(C*I),N=c(S*I),z=c(B*C);return new p(L,K,z,N)}subtract(x){return this.add(x.negate())}multiply(x){if(!o.isValidNot0(x))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=E.cached(this,x,D=>kt(p,D));return kt(p,[A,w])[0]}multiplyUnsafe(x,A=p.ZERO){if(!o.isValid(x))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return x===Wt?p.ZERO:this.is0()||x===rt?this:E.unsafe(this,x,w=>kt(p,w),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(x){return u(this,x)}clearCofactor(){return i===rt?this:this.multiplyUnsafe(i)}toBytes(){let{x,y:A}=this.toAffine(),w=n.toBytes(A);return w[w.length-1]|=x&rt?128:0,w}toHex(){return wt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(x){return kt(p,x)}static msm(x,A){return Ce(p,o,x,A)}_setWindowSize(x){this.precompute(x)}toRawBytes(){return this.toBytes()}}p.BASE=new p(s.Gx,s.Gy,rt,c(s.Gx*s.Gy)),p.ZERO=new p(Wt,rt,rt,Wt),p.Fp=n,p.Fn=o;let E=new De(p,o.BITS);return p.BASE.precompute(8),p}var Lr=class{constructor(t){this.ep=t}static fromBytes(t){Kn()}static fromHex(t){Kn()}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 wt(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.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function kc(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');Xt(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,a=r.randomBytes||Ie,c=r.adjustScalarBytes||(g=>g),f=r.domain||((g,_,P)=>{if(Ut(P,"phflag"),_.length||P)throw new Error("Contexts/pre-hash are not supported");return g});function d(g){return i.create(Pt(g))}function h(g){let _=w.secretKey;g=q("private key",g,_);let P=q("hashed private key",t(g),2*_),T=c(P.slice(0,_)),b=P.slice(_,2*_),m=d(T);return{head:T,prefix:b,scalar:m}}function u(g){let{head:_,prefix:P,scalar:T}=h(g),b=o.multiply(T),m=b.toBytes();return{head:_,prefix:P,scalar:T,point:b,pointBytes:m}}function l(g){return u(g).pointBytes}function p(g=Uint8Array.of(),..._){let P=ut(..._);return d(t(f(P,q("context",g),!!n)))}function E(g,_,P={}){g=q("message",g),n&&(g=n(g));let{prefix:T,scalar:b,pointBytes:m}=u(_),y=p(P.context,T,g),S=o.multiply(y).toBytes(),B=p(P.context,S,m,g),C=i.create(y+B*b);if(!i.isValid(C))throw new Error("sign failed: invalid s");let I=ut(S,i.toBytes(C));return bt(I,w.signature,"result")}let v={zip215:!0};function x(g,_,P,T=v){let{context:b,zip215:m}=T,y=w.signature;g=q("signature",g,y),_=q("message",_),P=q("publicKey",P,w.publicKey),m!==void 0&&Ut(m,"zip215"),n&&(_=n(_));let S=y/2,B=g.subarray(0,S),C=Pt(g.subarray(S,y)),I,L,K;try{I=e.fromBytes(P,m),L=e.fromBytes(B,m),K=o.multiplyUnsafe(C)}catch{return!1}if(!m&&I.isSmallOrder())return!1;let N=p(b,L.toBytes(),I.toBytes(),_);return L.add(I.multiplyUnsafe(N)).subtract(K).clearCofactor().is0()}let A=s.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function D(g=a(w.seed)){return bt(g,w.seed,"seed")}function R(g){let _=U.randomSecretKey(g);return{secretKey:_,publicKey:l(_)}}function O(g){return Ct(g)&&g.length===i.BYTES}function k(g,_){try{return!!e.fromBytes(g,_)}catch{return!1}}let U={getExtendedPublicKey:u,randomSecretKey:D,isValidSecretKey:O,isValidPublicKey:k,toMontgomery(g){let{y:_}=e.fromBytes(g),P=w.publicKey,T=P===32;if(!T&&P!==57)throw new Error("only defined for 25519 and 448");let b=T?s.div(rt+_,rt-_):s.div(_-rt,_+rt);return s.toBytes(b)},toMontgomerySecret(g){let _=w.secretKey;bt(g,_);let P=t(g.subarray(0,_));return c(P).subarray(0,_)},randomPrivateKey:D,precompute(g=8,_=e.BASE){return _.precompute(g,!1)}};return Object.freeze({keygen:R,getPublicKey:l,sign:E,verify:x,utils:U,Point:e,lengths:w})}function Oc(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=xt(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function Mc(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function Xs(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=Oc(e),s=Nc(t,r),i=kc(s,n,o);return Mc(e,i)}var Hc=BigInt(0),Ot=BigInt(1),Ws=BigInt(2),_h=BigInt(3),qc=BigInt(5),Vc=BigInt(8),Ke=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),rr={p:Ke,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Vc,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Fc(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ke,a=e*e%s*e%s,c=F(a,Ws,s)*a%s,f=F(c,Ot,s)*e%s,d=F(f,qc,s)*f%s,h=F(d,t,s)*d%s,u=F(h,r,s)*h%s,l=F(u,n,s)*u%s,p=F(l,o,s)*l%s,E=F(p,o,s)*l%s,v=F(E,t,s)*d%s;return{pow_p_5_8:F(v,Ws,s)*e%s,b2:a}}function zc(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var qn=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function zn(e,t){let r=Ke,n=X(t*t*t,r),o=X(n*n*t,r),s=Fc(e*o).pow_p_5_8,i=X(e*n*s,r),a=X(t*i*i,r),c=i,f=X(i*qn,r),d=a===e,h=a===X(-e,r),u=a===X(-e*qn,r);return d&&(i=c),(h||u)&&(i=f),Nt(i,r)&&(i=X(-i,r)),{isValid:d||h,value:i}}var Jt=xt(rr.p,{isLE:!0}),jc=xt(rr.n,{isLE:!0}),Zc={...rr,Fp:Jt,hash:Ts,adjustScalarBytes:zc,uvRatio:zn},Mt=Xs(Zc);var Vn=qn,Gc=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Yc=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),$c=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Xc=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Js=e=>zn(Ot,e),Wc=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Fn=e=>Mt.Point.Fp.create(Pt(e)&Wc);function Qs(e){let{d:t}=rr,r=Ke,n=x=>Jt.create(x),o=n(Vn*e*e),s=n((o+Ot)*$c),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:f}=zn(s,a),d=n(f*e);Nt(d,r)||(d=n(-d)),c||(f=d),c||(i=o);let h=n(i*(o-Ot)*Xc-a),u=f*f,l=n((f+f)*a),p=n(h*Gc),E=n(Ot-u),v=n(Ot+u);return new Mt.Point(n(l*v),n(E*p),n(p*v),n(l*E))}function Jc(e){mt(e,64);let t=Fn(e.subarray(0,32)),r=Qs(t),n=Fn(e.subarray(32,64)),o=Qs(n);return new Ht(r.add(o))}var Ht=class e extends Lr{constructor(t){super(t)}static fromAffine(t){return new e(Mt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return Jc(q("ristrettoHash",t,64))}static fromBytes(t){mt(t,32);let{a:r,d:n}=rr,o=Ke,s=D=>Jt.create(D),i=Fn(t);if(!Cs(Jt.toBytes(i),t)||Nt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Ot+r*a),f=s(Ot-r*a),d=s(c*c),h=s(f*f),u=s(r*n*d-h),{isValid:l,value:p}=Js(s(u*h)),E=s(p*f),v=s(p*E*u),x=s((i+i)*E);Nt(x,o)&&(x=s(-x));let A=s(c*v),w=s(x*A);if(!l||Nt(w,o)||A===Hc)throw new Error("invalid ristretto255 encoding 2");return new e(new Mt.Point(x,A,Ot,w))}static fromHex(t){return e.fromBytes(q("ristrettoHex",t,32))}static msm(t,r){return Ce(e,Mt.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Ke,i=v=>Jt.create(v),a=i(i(n+r)*i(n-r)),c=i(t*r),f=i(c*c),{value:d}=Js(i(a*f)),h=i(d*a),u=i(d*c),l=i(h*u*o),p;if(Nt(o*l,s)){let v=i(r*Vn),x=i(t*Vn);t=v,r=x,p=i(h*Yc)}else p=u;Nt(t*l,s)&&(r=i(-r));let E=i((n-r)*p);return Nt(E,s)&&(E=i(-E)),Jt.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=f=>Jt.create(f),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(e.ZERO)}};Ht.BASE=new Ht(Mt.Point.BASE);Ht.ZERO=new Ht(Mt.Point.ZERO);Ht.Fp=Jt;Ht.Fn=jc;var nr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},_r=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ti={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new _r("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 Et=ti;var Re=32;var jn,Qc=(async()=>{try{return await Et.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function tu(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Et.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Et.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function eu(e,t,r){return Mt.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function ei(e,t,r){return jn==null&&(jn=await Qc),jn?tu(e,t,r):eu(e,t,r)}function Tr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Dr=class{type="Ed25519";raw;constructor(t){this.raw=Zn(t,Re)}toMultihash(){return It.digest(ve(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return W.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=ei(this.raw,r,t);return Tr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function oi(e){return e=Zn(e,Re),new Dr(e)}function Zn(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new G(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var ru=Math.pow(2,7),nu=Math.pow(2,14),ou=Math.pow(2,21),Gn=Math.pow(2,28),Yn=Math.pow(2,35),$n=Math.pow(2,42),Xn=Math.pow(2,49),H=128,at=127;function qt(e){if(e<ru)return 1;if(e<nu)return 2;if(e<ou)return 3;if(e<Gn)return 4;if(e<Yn)return 5;if(e<$n)return 6;if(e<Xn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Wn(e,t,r=0){switch(qt(e)){case 8:t[r++]=e&255|H,e/=128;case 7:t[r++]=e&255|H,e/=128;case 6:t[r++]=e&255|H,e/=128;case 5:t[r++]=e&255|H,e/=128;case 4:t[r++]=e&255|H,e>>>=7;case 3:t[r++]=e&255|H,e>>>=7;case 2:t[r++]=e&255|H,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function su(e,t,r=0){switch(qt(e)){case 8:t.set(r++,e&255|H),e/=128;case 7:t.set(r++,e&255|H),e/=128;case 6:t.set(r++,e&255|H),e/=128;case 5:t.set(r++,e&255|H),e/=128;case 4:t.set(r++,e&255|H),e>>>=7;case 3:t.set(r++,e&255|H),e>>>=7;case 2:t.set(r++,e&255|H),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Jn(e,t){let r=e[t],n=0;if(n+=r&at,r<H||(r=e[t+1],n+=(r&at)<<7,r<H)||(r=e[t+2],n+=(r&at)<<14,r<H)||(r=e[t+3],n+=(r&at)<<21,r<H)||(r=e[t+4],n+=(r&at)*Gn,r<H)||(r=e[t+5],n+=(r&at)*Yn,r<H)||(r=e[t+6],n+=(r&at)*$n,r<H)||(r=e[t+7],n+=(r&at)*Xn,r<H))return n;throw new RangeError("Could not decode varint")}function iu(e,t){let r=e.get(t),n=0;if(n+=r&at,r<H||(r=e.get(t+1),n+=(r&at)<<7,r<H)||(r=e.get(t+2),n+=(r&at)<<14,r<H)||(r=e.get(t+3),n+=(r&at)<<21,r<H)||(r=e.get(t+4),n+=(r&at)*Gn,r<H)||(r=e.get(t+5),n+=(r&at)*Yn,r<H)||(r=e.get(t+6),n+=(r&at)*$n,r<H)||(r=e.get(t+7),n+=(r&at)*Xn,r<H))return n;throw new RangeError("Could not decode varint")}function si(e,t,r=0){return t==null&&(t=dt(qt(e))),t instanceof Uint8Array?Wn(e,t,r):su(e,t,r)}function ii(e,t=0){return e instanceof Uint8Array?Jn(e,t):iu(e,t)}var Qn=new Float32Array([-0]),Qt=new Uint8Array(Qn.buffer);function ai(e,t,r){Qn[0]=e,t[r]=Qt[0],t[r+1]=Qt[1],t[r+2]=Qt[2],t[r+3]=Qt[3]}function ci(e,t){return Qt[0]=e[t],Qt[1]=e[t+1],Qt[2]=e[t+2],Qt[3]=e[t+3],Qn[0]}var to=new Float64Array([-0]),ct=new Uint8Array(to.buffer);function ui(e,t,r){to[0]=e,t[r]=ct[0],t[r+1]=ct[1],t[r+2]=ct[2],t[r+3]=ct[3],t[r+4]=ct[4],t[r+5]=ct[5],t[r+6]=ct[6],t[r+7]=ct[7]}function fi(e,t){return ct[0]=e[t],ct[1]=e[t+1],ct[2]=e[t+2],ct[3]=e[t+3],ct[4]=e[t+4],ct[5]=e[t+5],ct[6]=e[t+6],ct[7]=e[t+7],to[0]}var cu=BigInt(Number.MAX_SAFE_INTEGER),uu=BigInt(Number.MIN_SAFE_INTEGER),gt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ce;if(t<cu&&t>uu)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>li&&(o=0n,++n>li&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ce;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):ce}},ce=new gt(0,0);ce.toBigInt=function(){return 0n};ce.zzEncode=ce.zzDecode=function(){return this};ce.length=function(){return 1};var li=4294967296n;function hi(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function di(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function eo(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function At(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Cr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var ro=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,At(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw At(this,4);return Cr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw At(this,4);return Cr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw At(this,4);let t=ci(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw At(this,4);let t=fi(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw At(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return di(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw At(this,t);this.pos+=t}else do if(this.pos>=this.len)throw At(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new gt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw At(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw At(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw At(this,8);let t=Cr(this.buf,this.pos+=4),r=Cr(this.buf,this.pos+=4);return new gt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Jn(this.buf,this.pos);return this.pos+=qt(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 no(e){return new ro(e instanceof Uint8Array?e:e.subarray())}function ue(e,t,r){let n=no(e);return t.decode(n,void 0,r)}function oo(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 fe=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function so(){}var ao=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},fu=oo();function lu(e){return globalThis.Buffer!=null?dt(e):fu(e)}var sr=class{len;head;tail;states;constructor(){this.len=0,this.head=new fe(so,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new fe(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new co((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Kr,10,gt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=gt.fromBigInt(t);return this._push(Kr,r.length(),r)}uint64Number(t){return this._push(Wn,qt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=gt.fromBigInt(t).zzEncode();return this._push(Kr,r.length(),r)}sint64Number(t){let r=gt.fromNumber(t).zzEncode();return this._push(Kr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(io,1,t?1:0)}fixed32(t){return this._push(or,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=gt.fromBigInt(t);return this._push(or,4,r.lo)._push(or,4,r.hi)}fixed64Number(t){let r=gt.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(ai,4,t)}double(t){return this._push(ui,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(io,1,0):this.uint32(r)._push(du,r,t)}string(t){let r=hi(t);return r!==0?this.uint32(r)._push(eo,r,t):this._push(io,1,0)}fork(){return this.states=new ao(this),this.head=this.tail=new fe(so,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 fe(so,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=lu(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function io(e,t,r){t[r]=e&255}function hu(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var co=class extends fe{next;constructor(t,r){super(hu,t,r),this.next=void 0}};function Kr(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function 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 du(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(pu,t,e),this},sr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(mu,t,e),this});function pu(e,t,r){t.set(e,r)}function mu(e,t,r){e.length<40?eo(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(J(e),r)}function uo(){return new sr}function le(e,t){let r=uo();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Ue;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(Ue||(Ue={}));function Rr(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function ir(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Rr("enum",Ue.VARINT,r,n)}function he(e,t){return Rr("message",Ue.LENGTH_DELIMITED,e,t)}var yt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(yt||(yt={}));var fo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(fo||(fo={}));(function(e){e.codec=()=>ir(fo)})(yt||(yt={}));var te;(function(e){let t;e.codec=()=>(t==null&&(t=he((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),yt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=yt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>le(r,e.codec()),e.decode=(r,n)=>ue(r,e.codec(),n)})(te||(te={}));var lo;(function(e){let t;e.codec=()=>(t==null&&(t=he((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),yt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=yt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>le(r,e.codec()),e.decode=(r,n)=>ue(r,e.codec(),n)})(lo||(lo={}));var cr={};ht(cr,{MAX_RSA_KEY_SIZE:()=>ho,generateRSAKeyPair:()=>wi,jwkToJWKKeyPair:()=>Ei,jwkToPkcs1:()=>gu,jwkToPkix:()=>bo,jwkToRSAPrivateKey:()=>go,pkcs1MessageToJwk:()=>mo,pkcs1MessageToRSAPrivateKey:()=>xo,pkcs1ToJwk:()=>xu,pkcs1ToRSAPrivateKey:()=>xi,pkixMessageToJwk:()=>yo,pkixMessageToRSAPublicKey:()=>Pr,pkixToJwk:()=>wu,pkixToRSAPublicKey:()=>gi});var Ur=Sr;var Pe=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 st.createV1(114,this._multihash)}toString(){return W.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 bi(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:it(this.raw,t.raw)}sign(t,r){return yi(this.jwk,t,r)}};var ho=8192,po=18,yu=1062,bu=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function xu(e){let t=Lt(e);return mo(t)}function mo(e){return{n:$(e[1],"base64url"),e:$(e[2],"base64url"),d:$(e[3],"base64url"),p:$(e[4],"base64url"),q:$(e[5],"base64url"),dp:$(e[6],"base64url"),dq:$(e[7],"base64url"),qi:$(e[8],"base64url"),kty:"RSA"}}function gu(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 G("JWK was missing components");return jt([pt(Uint8Array.from([0])),pt(J(e.n,"base64url")),pt(J(e.e,"base64url")),pt(J(e.d,"base64url")),pt(J(e.p,"base64url")),pt(J(e.q,"base64url")),pt(J(e.dp,"base64url")),pt(J(e.dq,"base64url")),pt(J(e.qi,"base64url"))]).subarray()}function wu(e){let t=Lt(e,{offset:0});return yo(t)}function yo(e){let t=Lt(e[1],{offset:0});return{kty:"RSA",n:$(t[0],"base64url"),e:$(t[1],"base64url")}}function bo(e){if(e.n==null||e.e==null)throw new G("JWK was missing components");return jt([bu,br(jt([pt(J(e.n,"base64url")),pt(J(e.e,"base64url"))]))]).subarray()}function xi(e){let t=Lt(e);return xo(t)}function xo(e){let t=mo(e);return go(t)}function gi(e,t){if(e.byteLength>=yu)throw new pe("Key size is too large");let r=Lt(e,{offset:0});return Pr(r,e,t)}function Pr(e,t,r){let n=yo(e);if(r==null){let o=Ur(te.encode({Type:yt.RSA,Data:t}));r=Bt(po,o)}return new Pe(n,r)}function go(e){if(vi(e)>ho)throw new G("Key size is too large");let t=Ei(e),r=Ur(te.encode({Type:yt.RSA,Data:bo(t.publicKey)})),n=Bt(po,r);return new ar(t.privateKey,new Pe(t.publicKey,n))}async function wi(e){if(e>ho)throw new G("Key size is too large");let t=await Si(e),r=Ur(te.encode({Type:yt.RSA,Data:bo(t.publicKey)})),n=Bt(po,r);return new ar(t.privateKey,new Pe(t.publicKey,n))}function Ei(e){if(e==null)throw new G("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var Ai="1.2.840.113549.1.1.1";async function Si(e,t){let r=await Et.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Eu(r,t);return{privateKey:n[0],publicKey:n[1]}}async function yi(e,t,r){let n=await Et.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Et.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function bi(e,t,r,n){let o=await Et.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Et.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Eu(e,t){if(e.privateKey==null||e.publicKey==null)throw new G("Private and public key are required");let r=await Promise.all([Et.get().subtle.exportKey("jwk",e.privateKey),Et.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function vi(e){if(e.kty!=="RSA")throw new G("invalid key type");if(e.n==null)throw new G("invalid key modulus");return J(e.n,"base64url").length*8}var Nr=class extends Ae{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,xr(t);let n=Ye(r);if(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 o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),Kt(s)}update(t){return Be(this),this.iHash.update(t),this}digestInto(t){Be(this),mt(t,this.outputLen),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||(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()}},wo=(e,t,r)=>new Nr(e,t).update(r).digest();wo.create=(e,t)=>new Nr(e,t);var Bi=(e,t)=>(e+(e>=0?t:-t)/Ii)/t;function Su(e,t,r){let[[n,o],[s,i]]=t,a=Bi(i*e,r),c=Bi(-o*e,r),f=e-a*n-c*s,d=-a*o-c*i,h=f<Ft,u=d<Ft;h&&(f=-f),u&&(d=-d);let l=$t(Math.ceil(Ar(r)/2))+ke;if(f<Ft||f>=l||d<Ft||d>=l)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:h,k1:f,k2neg:u,k2:d}}function So(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Eo(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&&So(r.format),r}var vo=class extends Error{constructor(t=""){super(t)}},Vt={Err:vo,_tlv:{encode:(e,t)=>{let{Err:r}=Vt;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=Je(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Je(o.length/2|128):"";return Je(e)+s+o+t},decode(e,t){let{Err:r}=Vt,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 c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let d of f)i=i<<8|d;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Vt;if(e<Ft)throw new t("integer: negative integers are not allowed");let r=Je(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}=Vt;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 Le(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Vt,o=q("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:d}=n.decode(2,c);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=Vt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Ft=BigInt(0),ke=BigInt(1),Ii=BigInt(2),kr=BigInt(3),vu=BigInt(4);function Ne(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=q("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function Au(e,t={}){let r=Ir("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:a}=s;Xt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=_i(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(T,b,m){let{x:y,y:S}=b.toAffine(),B=n.toBytes(y);if(Ut(m,"isCompressed"),m){d();let C=!n.isOdd(S);return ut(Li(C),B)}else return ut(Uint8Array.of(4),B,n.toBytes(S))}function u(T){bt(T,void 0,"Point");let{publicKey:b,publicKeyUncompressed:m}=f,y=T.length,S=T[0],B=T.subarray(1);if(y===b&&(S===2||S===3)){let C=n.fromBytes(B);if(!n.isValid(C))throw new Error("bad point: is not on curve, wrong x");let I=E(C),L;try{L=n.sqrt(I)}catch(z){let V=z instanceof Error?": "+z.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}d();let K=n.isOdd(L);return(S&1)===1!==K&&(L=n.neg(L)),{x:C,y:L}}else if(y===m&&S===4){let C=n.BYTES,I=n.fromBytes(B.subarray(0,C)),L=n.fromBytes(B.subarray(C,C*2));if(!v(I,L))throw new Error("bad point: is not on curve");return{x:I,y:L}}else throw new Error(`bad point: got length ${y}, expected compressed=${b} or uncompressed=${m}`)}let l=t.toBytes||h,p=t.fromBytes||u;function E(T){let b=n.sqr(T),m=n.mul(b,T);return n.add(n.add(m,n.mul(T,s.a)),s.b)}function v(T,b){let m=n.sqr(b),y=E(T);return n.eql(m,y)}if(!v(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let x=n.mul(n.pow(s.a,kr),vu),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(x,A)))throw new Error("bad curve params: a or b");function w(T,b,m=!1){if(!n.isValid(b)||m&&n.is0(b))throw new Error(`bad point coordinate ${T}`);return b}function D(T){if(!(T instanceof g))throw new Error("ProjectivePoint expected")}function R(T){if(!c||!c.basises)throw new Error("no endo");return Su(T,c.basises,o.ORDER)}let O=_e((T,b)=>{let{X:m,Y:y,Z:S}=T;if(n.eql(S,n.ONE))return{x:m,y};let B=T.is0();b==null&&(b=B?n.ONE:n.inv(S));let C=n.mul(m,b),I=n.mul(y,b),L=n.mul(S,b);if(B)return{x:n.ZERO,y:n.ZERO};if(!n.eql(L,n.ONE))throw new Error("invZ was invalid");return{x:C,y:I}}),k=_e(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:b,y:m}=T.toAffine();if(!n.isValid(b)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!v(b,m))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function U(T,b,m,y,S){return m=new g(n.mul(m.X,T),m.Y,m.Z),b=er(y,b),m=er(S,m),b.add(m)}class g{constructor(b,m,y){this.X=w("x",b),this.Y=w("y",m,!0),this.Z=w("z",y),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){let{x:m,y}=b||{};if(!b||!n.isValid(m)||!n.isValid(y))throw new Error("invalid affine point");if(b instanceof g)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(y)?g.ZERO:new g(m,y,n.ONE)}static fromBytes(b){let m=g.fromAffine(p(bt(b,void 0,"point")));return m.assertValidity(),m}static fromHex(b){return g.fromBytes(q("pointHex",b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,m=!0){return P.createCache(this,b),m||this.multiply(kr),this}assertValidity(){k(this)}hasEvenY(){let{y:b}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(b)}equals(b){D(b);let{X:m,Y:y,Z:S}=this,{X:B,Y:C,Z:I}=b,L=n.eql(n.mul(m,I),n.mul(B,S)),K=n.eql(n.mul(y,I),n.mul(C,S));return L&&K}negate(){return new g(this.X,n.neg(this.Y),this.Z)}double(){let{a:b,b:m}=s,y=n.mul(m,kr),{X:S,Y:B,Z:C}=this,I=n.ZERO,L=n.ZERO,K=n.ZERO,N=n.mul(S,S),z=n.mul(B,B),V=n.mul(C,C),M=n.mul(S,B);return M=n.add(M,M),K=n.mul(S,C),K=n.add(K,K),I=n.mul(b,K),L=n.mul(y,V),L=n.add(I,L),I=n.sub(z,L),L=n.add(z,L),L=n.mul(I,L),I=n.mul(M,I),K=n.mul(y,K),V=n.mul(b,V),M=n.sub(N,V),M=n.mul(b,M),M=n.add(M,K),K=n.add(N,N),N=n.add(K,N),N=n.add(N,V),N=n.mul(N,M),L=n.add(L,N),V=n.mul(B,C),V=n.add(V,V),N=n.mul(V,M),I=n.sub(I,N),K=n.mul(V,z),K=n.add(K,K),K=n.add(K,K),new g(I,L,K)}add(b){D(b);let{X:m,Y:y,Z:S}=this,{X:B,Y:C,Z:I}=b,L=n.ZERO,K=n.ZERO,N=n.ZERO,z=s.a,V=n.mul(s.b,kr),M=n.mul(m,B),j=n.mul(y,C),Q=n.mul(S,I),lt=n.add(m,y),Z=n.add(B,C);lt=n.mul(lt,Z),Z=n.add(M,j),lt=n.sub(lt,Z),Z=n.add(m,S);let ot=n.add(B,I);return Z=n.mul(Z,ot),ot=n.add(M,Q),Z=n.sub(Z,ot),ot=n.add(y,S),L=n.add(C,I),ot=n.mul(ot,L),L=n.add(j,Q),ot=n.sub(ot,L),N=n.mul(z,Z),L=n.mul(V,Q),N=n.add(L,N),L=n.sub(j,N),N=n.add(j,N),K=n.mul(L,N),j=n.add(M,M),j=n.add(j,M),Q=n.mul(z,Q),Z=n.mul(V,Z),j=n.add(j,Q),Q=n.sub(M,Q),Q=n.mul(z,Q),Z=n.add(Z,Q),M=n.mul(j,Z),K=n.add(K,M),M=n.mul(ot,Z),L=n.mul(lt,L),L=n.sub(L,M),M=n.mul(lt,j),N=n.mul(ot,N),N=n.add(N,M),new g(L,K,N)}subtract(b){return this.add(b.negate())}is0(){return this.equals(g.ZERO)}multiply(b){let{endo:m}=t;if(!o.isValidNot0(b))throw new Error("invalid scalar: out of range");let y,S,B=C=>P.cached(this,C,I=>kt(g,I));if(m){let{k1neg:C,k1:I,k2neg:L,k2:K}=R(b),{p:N,f:z}=B(I),{p:V,f:M}=B(K);S=z.add(M),y=U(m.beta,N,V,C,L)}else{let{p:C,f:I}=B(b);y=C,S=I}return kt(g,[y,S])[0]}multiplyUnsafe(b){let{endo:m}=t,y=this;if(!o.isValid(b))throw new Error("invalid scalar: out of range");if(b===Ft||y.is0())return g.ZERO;if(b===ke)return y;if(P.hasCache(this))return this.multiply(b);if(m){let{k1neg:S,k1:B,k2neg:C,k2:I}=R(b),{p1:L,p2:K}=$s(g,y,B,I);return U(m.beta,L,K,S,C)}else return P.unsafe(y,b)}multiplyAndAddUnsafe(b,m,y){let S=this.multiplyUnsafe(m).add(b.multiplyUnsafe(y));return S.is0()?void 0:S}toAffine(b){return O(this,b)}isTorsionFree(){let{isTorsionFree:b}=t;return i===ke?!0:b?b(g,this):P.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:b}=t;return i===ke?this:b?b(g,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(b=!0){return Ut(b,"isCompressed"),this.assertValidity(),l(g,this,b)}toHex(b=!0){return wt(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(b=!0){return this.toBytes(b)}_setWindowSize(b){this.precompute(b)}static normalizeZ(b){return kt(g,b)}static msm(b,m){return Ce(g,o,b,m)}static fromPrivateKey(b){return g.BASE.multiply(Ne(o,b))}}g.BASE=new g(s.Gx,s.Gy,n.ONE),g.ZERO=new g(n.ZERO,n.ONE,n.ZERO),g.Fp=n,g.Fn=o;let _=o.BITS,P=new De(g,t.endo?Math.ceil(_/2):_);return g.BASE.precompute(8),g}function Li(e){return Uint8Array.of(e?2:3)}function _i(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Bu(e,t={}){let{Fn:r}=e,n=t.randomBytes||Ie,o=Object.assign(_i(e.Fp,r),{seed:Pn(r.ORDER)});function s(l){try{return!!Ne(r,l)}catch{return!1}}function i(l,p){let{publicKey:E,publicKeyUncompressed:v}=o;try{let x=l.length;return p===!0&&x!==E||p===!1&&x!==v?!1:!!e.fromBytes(l)}catch{return!1}}function a(l=n(o.seed)){return Nn(bt(l,o.seed,"seed"),r.ORDER)}function c(l,p=!0){return e.BASE.multiply(Ne(r,l)).toBytes(p)}function f(l){let p=a(l);return{secretKey:p,publicKey:c(p)}}function d(l){if(typeof l=="bigint")return!1;if(l instanceof e)return!0;let{secretKey:p,publicKey:E,publicKeyUncompressed:v}=o;if(r.allowedLengths||p===E)return;let x=q("key",l).length;return x===E||x===v}function h(l,p,E=!0){if(d(l)===!0)throw new Error("first arg must be private key");if(d(p)===!1)throw new Error("second arg must be public key");let v=Ne(r,l);return e.fromHex(p).multiply(v).toBytes(E)}return Object.freeze({getPublicKey:c,getSharedSecret:h,keygen:f,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a,isValidPrivateKey:s,randomPrivateKey:a,normPrivateKeyToScalar:l=>Ne(r,l),precompute(l=8,p=e.BASE){return p.precompute(l,!1)}},lengths:o})}function Iu(e,t,r={}){xr(t),Xt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||Ie,o=r.hmac||((m,...y)=>wo(t,m,ut(...y))),{Fp:s,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:f,getPublicKey:d,getSharedSecret:h,utils:u,lengths:l}=Bu(e,r),p={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},E="compact";function v(m){let y=a>>ke;return m>y}function x(m,y){if(!i.isValidNot0(y))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return y}function A(m,y){So(y);let S=l.signature,B=y==="compact"?S:y==="recovered"?S+1:void 0;return bt(m,B,`${y} signature`)}class w{constructor(y,S,B){this.r=x("r",y),this.s=x("s",S),B!=null&&(this.recovery=B),Object.freeze(this)}static fromBytes(y,S=E){A(y,S);let B;if(S==="der"){let{r:K,s:N}=Vt.toSig(bt(y));return new w(K,N)}S==="recovered"&&(B=y[0],S="compact",y=y.subarray(1));let C=i.BYTES,I=y.subarray(0,C),L=y.subarray(C,C*2);return new w(i.fromBytes(I),i.fromBytes(L),B)}static fromHex(y,S){return this.fromBytes(ne(y),S)}addRecoveryBit(y){return new w(this.r,this.s,y)}recoverPublicKey(y){let S=s.ORDER,{r:B,s:C,recovery:I}=this;if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");if(a*Ii<S&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");let K=I===2||I===3?B+a:B;if(!s.isValid(K))throw new Error("recovery id 2 or 3 invalid");let N=s.toBytes(K),z=e.fromBytes(ut(Li((I&1)===0),N)),V=i.inv(K),M=R(q("msgHash",y)),j=i.create(-M*V),Q=i.create(C*V),lt=e.BASE.multiplyUnsafe(j).add(z.multiplyUnsafe(Q));if(lt.is0())throw new Error("point at infinify");return lt.assertValidity(),lt}hasHighS(){return v(this.s)}toBytes(y=E){if(So(y),y==="der")return ne(Vt.hexFromSig(this));let S=i.toBytes(this.r),B=i.toBytes(this.s);if(y==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return ut(Uint8Array.of(this.recovery),S,B)}return ut(S,B)}toHex(y){return wt(this.toBytes(y))}assertValidity(){}static fromCompact(y){return w.fromBytes(q("sig",y),"compact")}static fromDER(y){return w.fromBytes(q("sig",y),"der")}normalizeS(){return this.hasHighS()?new w(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return wt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return wt(this.toBytes("compact"))}}let D=r.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let S=Le(y),B=y.length*8-c;return B>0?S>>BigInt(B):S},R=r.bits2int_modN||function(y){return i.create(D(y))},O=$t(c);function k(m){return Qe("num < 2^"+c,m,Ft,O),i.toBytes(m)}function U(m,y){return bt(m,void 0,"message"),y?bt(t(m),void 0,"prehashed message"):m}function g(m,y,S){if(["recovered","canonical"].some(j=>j in S))throw new Error("sign() legacy options not supported");let{lowS:B,prehash:C,extraEntropy:I}=Eo(S,p);m=U(m,C);let L=R(m),K=Ne(i,y),N=[k(K),k(L)];if(I!=null&&I!==!1){let j=I===!0?n(l.secretKey):I;N.push(q("extraEntropy",j))}let z=ut(...N),V=L;function M(j){let Q=D(j);if(!i.isValidNot0(Q))return;let lt=i.inv(Q),Z=e.BASE.multiply(Q).toAffine(),ot=i.create(Z.x);if(ot===Ft)return;let fr=i.create(lt*i.create(V+ot*K));if(fr===Ft)return;let No=(Z.x===ot?0:2)|Number(Z.y&ke),ko=fr;return B&&v(fr)&&(ko=i.neg(fr),No^=1),new w(ot,ko,No)}return{seed:z,k2sig:M}}function _(m,y,S={}){m=q("message",m);let{seed:B,k2sig:C}=g(m,y,S);return Rs(t.outputLen,i.BYTES,o)(B,C)}function P(m){let y,S=typeof m=="string"||Ct(m),B=!S&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!S&&!B)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(B)y=new w(m.r,m.s);else if(S){try{y=w.fromBytes(q("sig",m),"der")}catch(C){if(!(C instanceof Vt.Err))throw C}if(!y)try{y=w.fromBytes(q("sig",m),"compact")}catch{return!1}}return y||!1}function T(m,y,S,B={}){let{lowS:C,prehash:I,format:L}=Eo(B,p);if(S=q("publicKey",S),y=U(q("message",y),I),"strict"in B)throw new Error("options.strict was renamed to lowS");let K=L===void 0?P(m):w.fromBytes(q("sig",m),L);if(K===!1)return!1;try{let N=e.fromBytes(S);if(C&&K.hasHighS())return!1;let{r:z,s:V}=K,M=R(y),j=i.inv(V),Q=i.create(M*j),lt=i.create(z*j),Z=e.BASE.multiplyUnsafe(Q).add(N.multiplyUnsafe(lt));return Z.is0()?!1:i.create(Z.x)===z}catch{return!1}}function b(m,y,S={}){let{prehash:B}=Eo(S,p);return y=U(y,B),w.fromBytes(m,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:f,getPublicKey:d,getSharedSecret:h,utils:u,lengths:l,Point:e,sign:_,verify:T,recoverPublicKey:b,Signature:w,hash:t})}function Lu(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=xt(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function _u(e){let{CURVE:t,curveOpts:r}=Lu(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function Tu(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,Br(r.Fn.ORDER,r.Fn.BITS))})}function Ti(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=_u(e),s=Au(t,r),i=Iu(s,n,o);return Tu(e,i)}function Di(e,t){let r=n=>Ti({...e,hash:n});return{...r(t),create:r}}var Bo={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Du={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ci=BigInt(2);function Cu(e){let t=Bo.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=e*e*e%t,d=f*f*e%t,h=F(d,r,t)*d%t,u=F(h,r,t)*d%t,l=F(u,Ci,t)*f%t,p=F(l,o,t)*l%t,E=F(p,s,t)*p%t,v=F(E,a,t)*E%t,x=F(v,c,t)*v%t,A=F(x,a,t)*E%t,w=F(A,r,t)*d%t,D=F(w,i,t)*p%t,R=F(D,n,t)*f%t,O=F(R,Ci,t);if(!Ao.eql(Ao.sqr(O),e))throw new Error("Cannot find square root");return O}var Ao=xt(Bo.p,{sqrt:Cu}),Oe=Di({...Bo,Fp:Ao,lowS:!0,endo:Du},Sr);var Ki=33;function Ri(e,t,r,n){let o=mr.digest(r instanceof Uint8Array?r:r.subarray());if(Tr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Oe.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new nr(String(s))});try{return n?.signal?.throwIfAborted(),Oe.verify(t,o.digest,e)}catch(s){throw new nr(String(s))}}var Or=class{type="secp256k1";raw;_key;constructor(t){this._key=Pi(t),this.raw=Ui(this._key)}toMultihash(){return It.digest(ve(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return W.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 Ri(this._key,r,t,n)}};function Ni(e){return new Or(e)}function Ui(e){return Oe.ProjectivePoint.fromHex(e).toRawBytes(!0)}function Pi(e){try{return Oe.ProjectivePoint.fromHex(e),e}catch(t){throw new pe(String(t))}}function ki(e){if(e.byteLength===Re)return oi(e);if(e.byteLength===Ki)return Ni(e);let t=Lt(e),r=t[1]?.[0];if(r===us||r===fs||r===ls)return ds(t);if(t[0]?.[0]===Ai)return Pr(t,e);throw new G("Could not extract public key from raw bytes")}function ve(e){return te.encode({Type:yt[e.type],Data:e.raw})}var Oi=Symbol.for("nodejs.util.inspect.custom"),Ku=114,ur=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()})`}[Zr]=!0;toString(){return this.string==null&&(this.string=W.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return st.createV1(Ku,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")}[Oi](){return`PeerId(${this.toString()})`}},Mr=class extends ur{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Hr=class extends ur{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},qr=class extends ur{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ru=2336,Io=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=It.digest(J(this.url))}[Oi](){return`PeerId(${this.url})`}[Zr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return st.createV1(Ru,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=$(t)),t.toString()===this.toString())}};function Mi(e){if(e.type==="Ed25519")return new Hr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new qr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Mr({multihash:e.toCID().multihash,publicKey:e});throw new He}var Lo=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},_o=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},Hi=e=>globalThis.DOMException===void 0?new _o(e):new DOMException(e),qi=e=>{let t=e.reason===void 0?Hi("This operation was aborted."):e.reason;return t instanceof Error?t:Hi(t)};function To(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,f=new Promise((d,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:l}=t;l.aborted&&h(qi(l)),a=()=>{h(qi(l))},l.addEventListener("abort",a,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(d,h);return}let u=new Lo;i=s.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(l){h(l)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?d():o instanceof Error?h(o):(u.message=o??`Promise timed out after ${r} milliseconds`,h(u))},r),(async()=>{try{d(await e)}catch(l){h(l)}})()}).finally(()=>{f.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return f.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},f}var Uu=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 Pu(e,t,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:f,removeListener:d}=Uu(e),h=(...l)=>{let p=r.multiArgs?l:l[0];r.filter&&!r.filter(p)||(c.push(p),r.count===c.length&&(n(),s(c)))},u=l=>{n(),i(l)};n=()=>{for(let l of a)d(l,h);for(let l of r.rejectionEvents)d(l,u)};for(let l of a)f(l,h);for(let l of r.rejectionEvents)f(l,u);r.signal&&r.signal.addEventListener("abort",()=>{u(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(o.cancel=n,typeof r.timeout=="number"){let s=To(o,{milliseconds:r.timeout});return s.cancel=n,s}return o}function Vi(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Pu(e,t,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var de=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Nu(e){return e.reason}async function Fi(e,t,r){if(t==null)return e;let n=r?.translateError??Nu;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 Ou=4194304,Vr=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Co=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ko=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ro=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Mu(e){return typeof e?.closeRead=="function"}function Hu(e){return typeof e?.close=="function"}function Do(e){return Mu(e)?e.readStatus==="closing"||e.readStatus==="closed":Hu(e)?e.status!=="open":!1}function qu(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function Vu(e,t){let r=t?.maxBufferSize??Ou,n=new tt,o=Promise.withResolvers(),s=!1;if(!qu(e))throw new G("Argument should be a Stream or a Multiaddr");let i=d=>{if(t?.stopPropagation,n.append(d.data),n.byteLength>r){let h=n.byteLength;n.consume(n.byteLength),o.reject(new Error(`Read buffer overflow - ${h} > ${r}`))}o.resolve()};e.addEventListener("message",i);let a=d=>{d.error!=null?o.reject(d.error):o.resolve()};e.addEventListener("close",a);let c=()=>{o.resolve()};e.addEventListener("remoteCloseWrite",c);let f={readBuffer:n,async read(d){if(s===!0)throw new Vr("Stream was unwrapped");if(Do(e)){if(d?.bytes==null)return null;if(n.byteLength<d.bytes)throw new de(`Unexpected EOF - stream closed after reading ${n.byteLength}/${d.bytes} bytes`)}let h=d?.bytes??1;for(;;){if(n.byteLength>=h){o.resolve();break}if(await Fi(o.promise,d?.signal),Do(e)){if(n.byteLength===0&&d?.bytes==null)return null;break}o=Promise.withResolvers()}let u=d?.bytes??n.byteLength;if(n.byteLength<u){if(Do(e))throw new de(`Unexpected EOF - stream closed while reading ${n.byteLength}/${u} bytes`);return f.read(d)}let l=n.sublist(0,u);return n.consume(u),l},async write(d,h){if(s===!0)throw new Vr("Stream was unwrapped");e.send(d)||await Vi(e,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",i),e.removeEventListener("close",a),e.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e}};return f}function Fu(e,t={}){let r=Vu(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=qt(t.maxDataLength));let n=t?.lengthDecoder??ii,o=t?.lengthEncoder??si;return{async read(i){let a=-1,c=new tt;for(;;){let d=await r.read({...i,bytes:1});if(d==null)break;c.append(d);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new Co("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Ro(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Ko(`Message length too long - ${a} > ${t.maxDataLength}`);let f=await r.read({...i,bytes:a});if(f==null)throw new de(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(f.byteLength!==a)throw new de(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(i,a){await r.write(new tt(o(i.byteLength),i),a)},async writeV(i,a){let c=new tt(...i.flatMap(f=>[o(f.byteLength),f]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function zi(e,t){let r=Fu(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 Fr;(function(e){let t;e.codec=()=>(t==null&&(t=he((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.id!=null&&(n.uint32(10),n.bytes(r.id)),r.pubkey!=null&&(n.uint32(18),zr.codec().encode(r.pubkey,n)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.id=r.bytes();break}case 2:{s.pubkey=zr.codec().decode(r,r.uint32(),{limits:o.limits?.pubkey});break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>le(r,e.codec()),e.decode=(r,n)=>ue(r,e.codec(),n)})(Fr||(Fr={}));var ee;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(ee||(ee={}));var Uo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Uo||(Uo={}));(function(e){e.codec=()=>ir(Uo)})(ee||(ee={}));var zr;(function(e){let t;e.codec=()=>(t==null&&(t=he((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),ee.codec().encode(r.Type,n)),r.Data!=null&&r.Data.byteLength>0&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={Data:St(0)},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=ee.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>le(r,e.codec()),e.decode=(r,n)=>ue(r,e.codec(),n)})(zr||(zr={}));var zu="/plaintext/2.0.0",Po=class{protocol=zu;privateKey;log;constructor(t){this.privateKey=t.privateKey,this.log=t.logger.forComponent("libp2p:plaintext")}[Symbol.toStringTag]="@libp2p/plaintext";[Oo]=["@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=zi(t).pb(Fr);n("write pubkey exchange to peer %p",r?.remotePeer);let s=this.privateKey.publicKey;await o.write({id:s.toMultihash().bytes,pubkey:{Type:ee[s.type],Data:s.raw}},r);let i=await o.read(r),a;try{if(i.pubkey==null)throw new me("Public key missing");if(i.pubkey.Data.byteLength===0)throw new me("Public key data too short");if(i.id==null)throw new me("Remote id missing");let c=ki(i.pubkey.Data);if(a=Mi(c),!it(a.toMultihash().bytes,i.id))throw new Me("Public key did not match id")}catch(c){throw n.error(c),new Me("Invalid public key - "+c.message)}if(r?.remotePeer!=null&&!a.equals(r?.remotePeer))throw new lr;return n("plaintext key exchange completed successfully with peer %p",a),{connection:o.unwrap().unwrap(),remotePeer:a}}};function ju(){return e=>new Po(e)}return $i(Zu);})();
|
|
2
|
+
"use strict";var Libp2PPlaintext=(()=>{var jr=Object.defineProperty;var ji=Object.getOwnPropertyDescriptor;var Zi=Object.getOwnPropertyNames;var Gi=Object.prototype.hasOwnProperty;var ht=(e,t)=>{for(var r in t)jr(e,r,{get:t[r],enumerable:!0})},Yi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Zi(t))!Gi.call(e,o)&&o!==r&&jr(e,o,{get:()=>t[o],enumerable:!(n=ji(t,o))||n.enumerable});return e};var $i=e=>Yi(jr({},"__esModule",{value:!0}),e);var Zu={};ht(Zu,{plaintext:()=>ju});var lr=class extends Error{static name="UnexpectedPeerError";constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError"}},Me=class extends Error{static name="InvalidCryptoExchangeError";constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError"}},G=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},pe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var me=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var He=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Zr=Symbol.for("@libp2p/peer-id");var Oo=Symbol.for("@libp2p/service-capabilities"),Xu=Symbol.for("@libp2p/service-dependencies");var Wr={};ht(Wr,{base58btc:()=>W,base58flickr:()=>ra});var vf=new Uint8Array(0);function Mo(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 Tt(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 Ho(e){return new TextEncoder().encode(e)}function qo(e){return new TextDecoder().decode(e)}function Xi(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,c=e.charAt(0),f=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function h(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var E=0,v=0,g=0,A=p.length;g!==A&&p[g]===0;)g++,E++;for(var w=(A-g)*d+1>>>0,D=new Uint8Array(w);g!==A;){for(var R=p[g],O=0,k=w-1;(R!==0||O<v)&&k!==-1;k--,O++)R+=256*D[k]>>>0,D[k]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");v=O,g++}for(var U=w-v;U!==w&&D[U]===0;)U++;for(var x=c.repeat(E);U<w;++U)x+=e.charAt(D[U]);return x}function u(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var E=0;if(p[E]!==" "){for(var v=0,g=0;p[E]===c;)v++,E++;for(var A=(p.length-E)*f+1>>>0,w=new Uint8Array(A);p[E];){var D=r[p.charCodeAt(E)];if(D===255)return;for(var R=0,O=A-1;(D!==0||R<g)&&O!==-1;O--,R++)D+=a*w[O]>>>0,w[O]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");g=R,E++}if(p[E]!==" "){for(var k=A-g;k!==A&&w[k]===0;)k++;for(var U=new Uint8Array(v+(A-k)),x=v;k!==A;)U[x++]=w[k++];return U}}}function l(p){var E=u(p);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:u,decode:l}}var Wi=Xi,Ji=Wi,Fo=Ji;var Gr=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")}},Yr=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 zo(this,t)}},$r=class{decoders;constructor(t){this.decoders=t}or(t){return zo(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 zo(e,t){return new $r({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Xr=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 Gr(t,r,n),this.decoder=new Yr(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ye({name:e,prefix:t,encode:r,decode:n}){return new Xr(e,t,r,n)}function zt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Fo(r,e);return ye({prefix:t,name:e,encode:n,decode:s=>Tt(o(s))})}function Qi(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let d=t[e[f]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|d,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ta(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function ea(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function Y({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=ea(n);return ye({prefix:t,name:e,encode(s){return ta(s,n,r)},decode(s){return Qi(s,o,r,e)}})}var W=zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ra=zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Jr={};ht(Jr,{base32:()=>be,base32hex:()=>ia,base32hexpad:()=>ca,base32hexpadupper:()=>ua,base32hexupper:()=>aa,base32pad:()=>oa,base32padupper:()=>sa,base32upper:()=>na,base32z:()=>fa});var be=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),na=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),oa=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),sa=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ia=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),aa=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ca=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ua=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),fa=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Qr={};ht(Qr,{base36:()=>qe,base36upper:()=>la});var qe=zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),la=zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ha=Go,jo=128,da=127,pa=~da,ma=Math.pow(2,31);function Go(e,t,r){t=t||[],r=r||0;for(var n=r;e>=ma;)t[r++]=e&255|jo,e/=128;for(;e&pa;)t[r++]=e&255|jo,e>>>=7;return t[r]=e|0,Go.bytes=r-n+1,t}var ya=tn,ba=128,Zo=127;function tn(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw tn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Zo)<<o:(i&Zo)*Math.pow(2,o),o+=7}while(i>=ba);return tn.bytes=s-n,r}var ga=Math.pow(2,7),xa=Math.pow(2,14),wa=Math.pow(2,21),Ea=Math.pow(2,28),Sa=Math.pow(2,35),va=Math.pow(2,42),Aa=Math.pow(2,49),Ba=Math.pow(2,56),Ia=Math.pow(2,63),La=function(e){return e<ga?1:e<xa?2:e<wa?3:e<Ea?4:e<Sa?5:e<va?6:e<Aa?7:e<Ba?8:e<Ia?9:10},_a={encode:ha,decode:ya,encodingLength:La},Ta=_a,Ve=Ta;function Fe(e,t=0){return[Ve.decode(e,t),Ve.decode.bytes]}function ge(e,t,r=0){return Ve.encode(e,t,r),t}function xe(e){return Ve.encodingLength(e)}function Bt(e,t){let r=t.byteLength,n=xe(e),o=n+xe(r),s=new Uint8Array(o+r);return ge(e,s,0),ge(r,s,n),s.set(t,o),new we(e,r,t,s)}function en(e){let t=Tt(e),[r,n]=Fe(t),[o,s]=Fe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new we(r,o,i,t)}function Yo(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Mo(e.bytes,r.bytes)}}var we=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function $o(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Ca(r,rn(e),t??W.encoder);default:return Ka(r,rn(e),t??be.encoder)}}var Xo=new WeakMap;function rn(e){let t=Xo.get(e);if(t==null){let r=new Map;return Xo.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!==ze)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ra)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&&Yo(t.multihash,n.multihash)}toString(t){return $o(this,t)}toJSON(){return{"/":$o(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??Wo(n,o,s.bytes))}else if(r[Ua]===!0){let{version:n,multihash:o,code:s}=r,i=en(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!==ze)throw new Error(`Version 0 CID must use dag-pb (code: ${ze}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Wo(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,ze,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=Tt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new we(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[h,u]=Fe(t.subarray(r));return r+=u,h},o=n(),s=ze;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),f=r+c,d=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:f}}static parse(t,r){let[n,o]=Da(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 rn(s).set(n,t),s}};function Da(e,t){switch(e[0]){case"Q":{let r=t??W;return[W.prefix,r.decode(`${W.prefix}${e}`)]}case W.prefix:{let r=t??W;return[W.prefix,r.decode(e)]}case be.prefix:{let r=t??be;return[be.prefix,r.decode(e)]}case qe.prefix:{let r=t??qe;return[qe.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 Ca(e,t,r){let{prefix:n}=r;if(n!==W.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 Ka(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 ze=112,Ra=18;function Wo(e,t,r){let n=xe(e),o=n+xe(t),s=new Uint8Array(o+r.byteLength);return ge(e,s,0),ge(t,s,n),s.set(r,o),s}var Ua=Symbol.for("@ipld/js-cid/CID");var nn={};ht(nn,{identity:()=>It});var Jo=0,Pa="identity",Qo=Tt;function Na(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(Jo,Qo(e))}var It={code:Jo,name:Pa,encode:Qo,digest:Na};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 St(e=0){return new Uint8Array(e)}function dt(e=0){return new Uint8Array(e)}function dr(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 es=Symbol.for("@achingbrain/uint8arraylist");function ts(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 pr(e){return!!e?.[es]}var tt=class e{bufs;length;[es]=!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(pr(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(pr(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=ts(this.bufs,t);return r.buf[r.index]}set(t,r){let n=ts(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(pr(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 dr(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:dr(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,d=r>a&&r<=c;if(f&&d){if(t===a&&r===c){n.push(i);break}let h=t-a;n.push(i.subarray(h,h+(r-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(d){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!pr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,d;for(let h=r;h<=c;h+=d){d=0;for(let u=f;u>=0;u--){let l=this.get(h+u);if(n[u]!==l){d=Math.max(1,u-a[l]);break}}if(d===0)return h}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=dt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=St(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=St(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=St(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=dt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=St(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=St(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=St(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=St(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=St(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!it(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var on={};ht(on,{base10:()=>ka});var ka=zt({prefix:"9",name:"base10",alphabet:"0123456789"});var sn={};ht(sn,{base16:()=>Oa,base16upper:()=>Ma});var Oa=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ma=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var an={};ht(an,{base2:()=>Ha});var Ha=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var cn={};ht(cn,{base256emoji:()=>ja});var rs=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}"),qa=rs.reduce((e,t,r)=>(e[r]=t,e),[]),Va=rs.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Fa(e){return e.reduce((t,r)=>(t+=qa[r],t),"")}function za(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Va[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var ja=ye({prefix:"\u{1F680}",name:"base256emoji",encode:Fa,decode:za});var un={};ht(un,{base64:()=>Za,base64pad:()=>Ga,base64url:()=>Ya,base64urlpad:()=>$a});var Za=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ga=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ya=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),$a=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var fn={};ht(fn,{base8:()=>Xa});var Xa=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ln={};ht(ln,{identity:()=>Wa});var Wa=ye({prefix:"\0",name:"identity",encode:e=>qo(e),decode:e=>Ho(e)});var il=new TextEncoder,al=new TextDecoder;var pn={};ht(pn,{sha256:()=>mr,sha512:()=>ec});var tc=20;function dn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new hn(e,t,r,n,o)}var hn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??tc,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?ns(n,this.code,r?.truncate):n.then(o=>ns(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ns(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 ss(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var mr=dn({name:"sha2-256",code:18,encode:ss("SHA-256")}),ec=dn({name:"sha2-512",code:19,encode:ss("SHA-512")});var mn={...ln,...an,...fn,...on,...sn,...Jr,...Qr,...Wr,...un,...cn},xl={...pn,...nn};function as(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var is=as("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),yn=as("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}),rc={utf8:is,"utf-8":is,hex:mn.base16,latin1:yn,ascii:yn,binary:yn,...mn},yr=rc;function J(e,t="utf8"){let r=yr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function $(e,t="utf8"){let r=yr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var nc=parseInt("11111",2),bn=parseInt("10000000",2),oc=parseInt("01111111",2),cs={0:je,1:je,2:sc,3:cc,4:uc,5:ac,6:ic,16:je,22:je,48:je};function Lt(e,t={offset:0}){let r=e[t.offset]&nc;if(t.offset++,cs[r]!=null)return cs[r](e,t);throw new Error("No decoder for tag "+r)}function Ze(e,t){let r=0;if((e[t.offset]&bn)===bn){let n=e[t.offset]&oc,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 je(e,t){Ze(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Lt(e,t);if(n===null)break;r.push(n)}return r}function sc(e,t){let r=Ze(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function ic(e,t){let r=Ze(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let f=e[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let d=0;for(let h=0;h<c.length;h++)d+=c[h]<<h*7;a+=`.${d}`,c=[]}}return a}function ac(e,t){return t.offset++,null}function cc(e,t){let r=Ze(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function uc(e,t){let r=Ze(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function fc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new tt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function gn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=fc(e.byteLength);return new tt(Uint8Array.from([t.byteLength|bn]),t)}function pt(e){let t=new tt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new tt(Uint8Array.from([2]),gn(t),t)}function br(e){let t=Uint8Array.from([0]),r=new tt(t,e);return new tt(Uint8Array.from([3]),gn(r),r)}function jt(e,t=48){let r=new tt;for(let n of e)r.append(n);return new tt(Uint8Array.from([t]),gn(r),r)}var us="1.2.840.10045.3.1.7",fs="1.3.132.0.34",ls="1.3.132.0.35";async function hs(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var lc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),hc=Uint8Array.from([6,5,43,129,4,0,34]),dc=Uint8Array.from([6,5,43,129,4,0,35]),pc={ext:!0,kty:"EC",crv:"P-256"},mc={ext:!0,kty:"EC",crv:"P-384"},yc={ext:!0,kty:"EC",crv:"P-521"},xn=32,wn=48,En=66;function ds(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===xn*2+1)return n=$(t.subarray(r,r+xn),"base64url"),o=$(t.subarray(r+xn),"base64url"),new Se({...pc,key_ops:["verify"],x:n,y:o});if(t.byteLength===wn*2+1)return n=$(t.subarray(r,r+wn),"base64url"),o=$(t.subarray(r+wn),"base64url"),new Se({...mc,key_ops:["verify"],x:n,y:o});if(t.byteLength===En*2+1)return n=$(t.subarray(r,r+En),"base64url"),o=$(t.subarray(r+En),"base64url"),new Se({...yc,key_ops:["verify"],x:n,y:o});throw new G(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ps(e){return jt([pt(Uint8Array.from([1])),jt([bc(e.crv)],160),jt([br(new tt(Uint8Array.from([4]),J(e.x??"","base64url"),J(e.y??"","base64url")))],161)]).subarray()}function bc(e){if(e==="P-256")return lc;if(e==="P-384")return hc;if(e==="P-521")return dc;throw new G(`Invalid curve ${e}`)}var Se=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ps(this.jwk)),this._raw}toMultihash(){return It.digest(ve(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return W.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 hs(this.jwk,r,t,n)}};var re=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ct(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ge(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function mt(e,...t){if(!Ct(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function gr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Ge(e.outputLen),Ge(e.blockLen)}function Be(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 ys(e,t){mt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Kt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function xr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function vt(e,t){return e<<32-t|e>>>t}var bs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",gc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function wt(e){if(mt(e),bs)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=gc[e[r]];return t}var Dt={_0:48,_9:57,A:65,F:70,a:97,f:102};function ms(e){if(e>=Dt._0&&e<=Dt._9)return e-Dt._0;if(e>=Dt.A&&e<=Dt.F)return e-(Dt.A-10);if(e>=Dt.a&&e<=Dt.f)return e-(Dt.a-10)}function ne(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(bs)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=ms(e.charCodeAt(s)),a=ms(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Sn(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Ye(e){return typeof e=="string"&&(e=Sn(e)),mt(e),e}function ut(...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}var Ae=class{};function vn(e){let t=n=>e().update(Ye(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Ie(e=32){if(re&&typeof re.getRandomValues=="function")return re.getRandomValues(new Uint8Array(e));if(re&&typeof re.randomBytes=="function")return Uint8Array.from(re.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function xc(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),a=Number(r&s),c=n?4:0,f=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+f,a,n)}function gs(e,t,r){return e&t^~e&r}function xs(e,t,r){return e&t^e&r^t&r}var $e=class extends Ae{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=xr(this.buffer)}update(t){Be(this),t=Ye(t),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 c=xr(t);for(;o<=s-i;i+=o)this.process(c,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){Be(this),ys(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Kt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let h=i;h<o;h++)r[h]=0;xc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=xr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,d=this.get();if(f>d.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,d[h],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(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()}},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 wr=BigInt(4294967295),ws=BigInt(32);function wc(e,t=!1){return t?{h:Number(e&wr),l:Number(e>>ws&wr)}:{h:Number(e>>ws&wr)|0,l:Number(e&wr)|0}}function Es(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}=wc(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var An=(e,t,r)=>e>>>r,Bn=(e,t,r)=>e<<32-r|t>>>r,oe=(e,t,r)=>e>>>r|t<<32-r,se=(e,t,r)=>e<<32-r|t>>>r,Xe=(e,t,r)=>e<<64-r|t>>>r-32,We=(e,t,r)=>e>>>r-32|t<<64-r;function _t(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Ss=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),vs=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,As=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Bs=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Is=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Ls=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Sc=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),Er=class extends $e{constructor(t=32){super(64,t,8,!1),this.A=Rt[0]|0,this.B=Rt[1]|0,this.C=Rt[2]|0,this.D=Rt[3]|0,this.E=Rt[4]|0,this.F=Rt[5]|0,this.G=Rt[6]|0,this.H=Rt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let h=0;h<16;h++,r+=4)Zt[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){let u=Zt[h-15],l=Zt[h-2],p=vt(u,7)^vt(u,18)^u>>>3,E=vt(l,17)^vt(l,19)^l>>>10;Zt[h]=E+Zt[h-7]+p+Zt[h-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:d}=this;for(let h=0;h<64;h++){let u=vt(a,6)^vt(a,11)^vt(a,25),l=d+u+gs(a,c,f)+Sc[h]+Zt[h]|0,E=(vt(n,2)^vt(n,13)^vt(n,22))+xs(n,o,s)|0;d=f,f=c,c=a,a=i+l|0,i=s,s=o,o=n,n=l+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,c=c+this.F|0,f=f+this.G|0,d=d+this.H|0,this.set(n,o,s,i,a,c,f,d)}roundClean(){Kt(Zt)}destroy(){this.set(0,0,0,0,0,0,0,0),Kt(this.buffer)}};var _s=Es(["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))),vc=_s[0],Ac=_s[1],Gt=new Uint32Array(80),Yt=new Uint32Array(80),In=class extends $e{constructor(t=64){super(128,t,16,!1),this.Ah=nt[0]|0,this.Al=nt[1]|0,this.Bh=nt[2]|0,this.Bl=nt[3]|0,this.Ch=nt[4]|0,this.Cl=nt[5]|0,this.Dh=nt[6]|0,this.Dl=nt[7]|0,this.Eh=nt[8]|0,this.El=nt[9]|0,this.Fh=nt[10]|0,this.Fl=nt[11]|0,this.Gh=nt[12]|0,this.Gl=nt[13]|0,this.Hh=nt[14]|0,this.Hl=nt[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:d,Fh:h,Fl:u,Gh:l,Gl:p,Hh:E,Hl:v}=this;return[t,r,n,o,s,i,a,c,f,d,h,u,l,p,E,v]}set(t,r,n,o,s,i,a,c,f,d,h,u,l,p,E,v){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=d|0,this.Fh=h|0,this.Fl=u|0,this.Gh=l|0,this.Gl=p|0,this.Hh=E|0,this.Hl=v|0}process(t,r){for(let w=0;w<16;w++,r+=4)Gt[w]=t.getUint32(r),Yt[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let D=Gt[w-15]|0,R=Yt[w-15]|0,O=oe(D,R,1)^oe(D,R,8)^An(D,R,7),k=se(D,R,1)^se(D,R,8)^Bn(D,R,7),U=Gt[w-2]|0,x=Yt[w-2]|0,_=oe(U,x,19)^Xe(U,x,61)^An(U,x,6),P=se(U,x,19)^We(U,x,61)^Bn(U,x,6),T=As(k,P,Yt[w-7],Yt[w-16]),b=Bs(T,O,_,Gt[w-7],Gt[w-16]);Gt[w]=b|0,Yt[w]=T|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:d,Eh:h,El:u,Fh:l,Fl:p,Gh:E,Gl:v,Hh:g,Hl:A}=this;for(let w=0;w<80;w++){let D=oe(h,u,14)^oe(h,u,18)^Xe(h,u,41),R=se(h,u,14)^se(h,u,18)^We(h,u,41),O=h&l^~h&E,k=u&p^~u&v,U=Is(A,R,k,Ac[w],Yt[w]),x=Ls(U,g,D,O,vc[w],Gt[w]),_=U|0,P=oe(n,o,28)^Xe(n,o,34)^Xe(n,o,39),T=se(n,o,28)^We(n,o,34)^We(n,o,39),b=n&s^n&a^s&a,m=o&i^o&c^i&c;g=E|0,A=v|0,E=l|0,v=p|0,l=h|0,p=u|0,{h,l:u}=_t(f|0,d|0,x|0,_|0),f=a|0,d=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let y=Ss(_,T,m);n=vs(y,x,P,b),o=y|0}({h:n,l:o}=_t(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=_t(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=_t(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:d}=_t(this.Dh|0,this.Dl|0,f|0,d|0),{h,l:u}=_t(this.Eh|0,this.El|0,h|0,u|0),{h:l,l:p}=_t(this.Fh|0,this.Fl|0,l|0,p|0),{h:E,l:v}=_t(this.Gh|0,this.Gl|0,E|0,v|0),{h:g,l:A}=_t(this.Hh|0,this.Hl|0,g|0,A|0),this.set(n,o,s,i,a,c,f,d,h,u,l,p,E,v,g,A)}roundClean(){Kt(Gt,Yt)}destroy(){Kt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Sr=vn(()=>new Er);var Ts=vn(()=>new In);var Tn=BigInt(0),_n=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 bt(e,t,r=""){let n=Ct(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function Je(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Ds(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Tn:BigInt("0x"+e)}function Le(e){return Ds(wt(e))}function Pt(e){return mt(e),Ds(wt(Uint8Array.from(e).reverse()))}function vr(e,t){return ne(e.toString(16).padStart(t*2,"0"))}function Dn(e,t){return vr(e,t).reverse()}function q(e,t,r){let n;if(typeof t=="string")try{n=ne(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Ct(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function Cs(e,t){if(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 Cn(e){return Uint8Array.from(e)}var Ln=e=>typeof e=="bigint"&&Tn<=e;function Ks(e,t,r){return Ln(e)&&Ln(t)&&Ln(r)&&t<=e&&e<r}function Qe(e,t,r,n){if(!Ks(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ar(e){let t;for(t=0;e>Tn;e>>=_n,t+=1);return t}var $t=e=>(_n<<BigInt(e))-_n;function Rs(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=l=>new Uint8Array(l),o=l=>Uint8Array.of(l),s=n(e),i=n(e),a=0,c=()=>{s.fill(1),i.fill(0),a=0},f=(...l)=>r(i,s,...l),d=(l=n(0))=>{i=f(o(0),l),s=f(),l.length!==0&&(i=f(o(1),l),s=f())},h=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,p=[];for(;l<t;){s=f();let E=s.slice();p.push(E),l+=s.length}return ut(...p)};return(l,p)=>{c(),d(l);let E;for(;!(E=p(h()));)d();return c(),E}}function Xt(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let a=e[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var Kn=()=>{throw new Error("not implemented")};function _e(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 ft=BigInt(0),et=BigInt(1),ie=BigInt(2),Ns=BigInt(3),ks=BigInt(4),Os=BigInt(5),Bc=BigInt(7),Ms=BigInt(8),Ic=BigInt(9),Hs=BigInt(16);function X(e,t){let r=e%t;return r>=ft?r:t+r}function F(e,t,r){let n=e;for(;t-- >ft;)n*=n,n%=r;return n}function Us(e,t){if(e===ft)throw new Error("invert: expected non-zero number");if(t<=ft)throw new Error("invert: expected positive modulus, got "+t);let r=X(e,t),n=t,o=ft,s=et,i=et,a=ft;for(;r!==ft;){let f=n/r,d=n%r,h=o-i*f,u=s-a*f;n=r,r=d,o=i,s=a,i=h,a=u}if(n!==et)throw new Error("invert: does not exist");return X(o,t)}function Rn(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function qs(e,t){let r=(e.ORDER+et)/ks,n=e.pow(t,r);return Rn(e,n,t),n}function Lc(e,t){let r=(e.ORDER-Os)/Ms,n=e.mul(t,ie),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,ie),o),a=e.mul(s,e.sub(i,e.ONE));return Rn(e,a,t),a}function _c(e){let t=gt(e),r=Vs(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Bc)/Hs;return(a,c)=>{let f=a.pow(c,i),d=a.mul(f,n),h=a.mul(f,o),u=a.mul(f,s),l=a.eql(a.sqr(d),c),p=a.eql(a.sqr(h),c);f=a.cmov(f,d,l),d=a.cmov(u,h,p);let E=a.eql(a.sqr(d),c),v=a.cmov(f,d,E);return Rn(a,v,c),v}}function Vs(e){if(e<Ns)throw new Error("sqrt is not defined for small field");let t=e-et,r=0;for(;t%ie===ft;)t/=ie,r++;let n=ie,o=gt(e);for(;Ps(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return qs;let s=o.pow(n,t),i=(t+et)/ie;return function(c,f){if(c.is0(f))return f;if(Ps(c,f)!==1)throw new Error("Cannot find square root");let d=r,h=c.mul(c.ONE,s),u=c.pow(f,t),l=c.pow(f,i);for(;!c.eql(u,c.ONE);){if(c.is0(u))return c.ZERO;let p=1,E=c.sqr(u);for(;!c.eql(E,c.ONE);)if(p++,E=c.sqr(E),p===d)throw new Error("Cannot find square root");let v=et<<BigInt(d-p-1),g=c.pow(h,v);d=p,h=c.sqr(g),u=c.mul(u,h),l=c.mul(l,g)}return l}}function Tc(e){return e%ks===Ns?qs:e%Ms===Os?Lc:e%Hs===Ic?_c(e):Vs(e)}var Nt=(e,t)=>(X(e,t)&et)===et,Dc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Un(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Dc.reduce((n,o)=>(n[o]="function",n),t);return Xt(e,r),e}function Cc(e,t,r){if(r<ft)throw new Error("invalid exponent, negatives unsupported");if(r===ft)return e.ONE;if(r===et)return t;let n=e.ONE,o=t;for(;r>ft;)r&et&&(n=e.mul(n,o)),o=e.sqr(o),r>>=et;return n}function tr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),s),n}function Ps(e,t){let r=(e.ORDER-et)/ie,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 Br(e,t){t!==void 0&&Ge(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function gt(e,t,r=!1,n={}){if(e<=ft)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let u=t;u.BITS&&(o=u.BITS),u.sqrt&&(s=u.sqrt),typeof u.isLE=="boolean"&&(r=u.isLE),typeof u.modFromBytes=="boolean"&&(i=u.modFromBytes),a=u.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:c,nByteLength:f}=Br(e,o);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let d,h=Object.freeze({ORDER:e,isLE:r,BITS:c,BYTES:f,MASK:$t(c),ZERO:ft,ONE:et,allowedLengths:a,create:u=>X(u,e),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return ft<=u&&u<e},is0:u=>u===ft,isValidNot0:u=>!h.is0(u)&&h.isValid(u),isOdd:u=>(u&et)===et,neg:u=>X(-u,e),eql:(u,l)=>u===l,sqr:u=>X(u*u,e),add:(u,l)=>X(u+l,e),sub:(u,l)=>X(u-l,e),mul:(u,l)=>X(u*l,e),pow:(u,l)=>Cc(h,u,l),div:(u,l)=>X(u*Us(l,e),e),sqrN:u=>u*u,addN:(u,l)=>u+l,subN:(u,l)=>u-l,mulN:(u,l)=>u*l,inv:u=>Us(u,e),sqrt:s||(u=>(d||(d=Tc(e)),d(h,u))),toBytes:u=>r?Dn(u,f):vr(u,f),fromBytes:(u,l=!0)=>{if(a){if(!a.includes(u.length)||u.length>f)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);let E=new Uint8Array(f);E.set(u,r?0:E.length-u.length),u=E}if(u.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+u.length);let p=r?Pt(u):Le(u);if(i&&(p=X(p,e)),!l&&!h.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:u=>tr(h,u),cmov:(u,l,p)=>p?l:u});return Object.freeze(h)}function Fs(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 Pn(e){let t=Fs(e);return t+Math.ceil(t/2)}function Nn(e,t,r=!1){let n=e.length,o=Fs(t),s=Pn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Pt(e):Le(e),a=X(i,t-et)+et;return r?Dn(a,o):vr(a,o)}var Te=BigInt(0),ae=BigInt(1);function er(e,t){let r=t.negate();return e?r:t}function kt(e,t){let r=tr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Gs(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function kn(e,t){Gs(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=$t(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function zs(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),c=e>>i;a>n&&(a-=s,c+=ae);let f=t*n,d=f+Math.abs(a)-1,h=a===0,u=a<0,l=t%2!==0;return{nextN:c,offset:d,isZero:h,isNeg:u,isNegF:l,offsetF:f}}function Kc(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Rc(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var On=new WeakMap,Ys=new WeakMap;function Mn(e){return Ys.get(e)||1}function js(e){if(e!==Te)throw new Error("invalid wNAF")}var De=class{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>Te;)r&ae&&(n=n.add(o)),o=o.double(),r>>=ae;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=kn(r,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let f=1;f<o;f++)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=kn(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:d,isNeg:h,isNegF:u,offsetF:l}=zs(n,a,i);n=c,d?s=s.add(er(u,r[l])):o=o.add(er(h,r[f]))}return js(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=kn(t,this.bits);for(let i=0;i<s.windows&&n!==Te;i++){let{nextN:a,offset:c,isZero:f,isNeg:d}=zs(n,i,s);if(n=a,!f){let h=r[c];o=o.add(d?h.negate():h)}}return js(n),o}getPrecomputes(t,r,n){let o=On.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),On.set(r,o))),o}cached(t,r,n){let o=Mn(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Mn(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Gs(r,this.bits),Ys.set(t,r),On.delete(t)}hasCache(t){return Mn(t)!==1}};function $s(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Te||n>Te;)r&ae&&(s=s.add(o)),n&ae&&(i=i.add(o)),o=o.double(),r>>=ae,n>>=ae;return{p1:s,p2:i}}function Ce(e,t,r,n){Kc(r,e),Rc(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,a=Ar(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let f=$t(c),d=new Array(Number(f)+1).fill(i),h=Math.floor((t.BITS-1)/c)*c,u=i;for(let l=h;l>=0;l-=c){d.fill(i);for(let E=0;E<s;E++){let v=n[E],g=Number(v>>BigInt(l)&f);d[g]=d[g].add(r[E])}let p=i;for(let E=d.length-1,v=i;E>0;E--)v=v.add(d[E]),p=p.add(v);if(u=u.add(p),l!==0)for(let E=0;E<c;E++)u=u.double()}return u}function Zs(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Un(t),t}else return gt(e,{isLE:r})}function Ir(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 c of["p","n","h"]){let f=t[c];if(!(typeof f=="bigint"&&f>Te))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Zs(t.p,r.Fp,n),s=Zs(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var Wt=BigInt(0),rt=BigInt(1),Hn=BigInt(2),Uc=BigInt(8);function Pc(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 Nc(e,t={}){let r=Ir("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;Xt(t,{},{uvRatio:"function"});let a=Hn<<BigInt(o.BYTES*8)-rt,c=v=>n.create(v),f=t.uvRatio||((v,g)=>{try{return{isValid:!0,value:n.sqrt(n.div(v,g))}}catch{return{isValid:!1,value:Wt}}});if(!Pc(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function d(v,g,A=!1){let w=A?rt:Wt;return Qe("coordinate "+v,g,w,a),g}function h(v){if(!(v instanceof p))throw new Error("ExtendedPoint expected")}let u=_e((v,g)=>{let{X:A,Y:w,Z:D}=v,R=v.is0();g==null&&(g=R?Uc:n.inv(D));let O=c(A*g),k=c(w*g),U=n.mul(D,g);if(R)return{x:Wt,y:rt};if(U!==rt)throw new Error("invZ was invalid");return{x:O,y:k}}),l=_e(v=>{let{a:g,d:A}=s;if(v.is0())throw new Error("bad point: ZERO");let{X:w,Y:D,Z:R,T:O}=v,k=c(w*w),U=c(D*D),x=c(R*R),_=c(x*x),P=c(k*g),T=c(x*c(P+U)),b=c(_+c(A*c(k*U)));if(T!==b)throw new Error("bad point: equation left != right (1)");let m=c(w*D),y=c(R*O);if(m!==y)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(g,A,w,D){this.X=d("x",g),this.Y=d("y",A),this.Z=d("z",w,!0),this.T=d("t",D),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){if(g instanceof p)throw new Error("extended point not allowed");let{x:A,y:w}=g||{};return d("x",A),d("y",w),new p(A,w,rt,c(A*w))}static fromBytes(g,A=!1){let w=n.BYTES,{a:D,d:R}=s;g=Cn(bt(g,w,"point")),Ut(A,"zip215");let O=Cn(g),k=g[w-1];O[w-1]=k&-129;let U=Pt(O),x=A?a:n.ORDER;Qe("point.y",U,Wt,x);let _=c(U*U),P=c(_-rt),T=c(R*_-D),{isValid:b,value:m}=f(P,T);if(!b)throw new Error("bad point: invalid y coordinate");let y=(m&rt)===rt,S=(k&128)!==0;if(!A&&m===Wt&&S)throw new Error("bad point: x=0 and x_0=1");return S!==y&&(m=c(-m)),p.fromAffine({x:m,y:U})}static fromHex(g,A=!1){return p.fromBytes(q("point",g),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,A=!0){return E.createCache(this,g),A||this.multiply(Hn),this}assertValidity(){l(this)}equals(g){h(g);let{X:A,Y:w,Z:D}=this,{X:R,Y:O,Z:k}=g,U=c(A*k),x=c(R*D),_=c(w*k),P=c(O*D);return U===x&&_===P}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:g}=s,{X:A,Y:w,Z:D}=this,R=c(A*A),O=c(w*w),k=c(Hn*c(D*D)),U=c(g*R),x=A+w,_=c(c(x*x)-R-O),P=U+O,T=P-k,b=U-O,m=c(_*T),y=c(P*b),S=c(_*b),B=c(T*P);return new p(m,y,B,S)}add(g){h(g);let{a:A,d:w}=s,{X:D,Y:R,Z:O,T:k}=this,{X:U,Y:x,Z:_,T:P}=g,T=c(D*U),b=c(R*x),m=c(k*w*P),y=c(O*_),S=c((D+R)*(U+x)-T-b),B=y-m,C=y+m,I=c(b-A*T),L=c(S*B),K=c(C*I),N=c(S*I),z=c(B*C);return new p(L,K,z,N)}subtract(g){return this.add(g.negate())}multiply(g){if(!o.isValidNot0(g))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=E.cached(this,g,D=>kt(p,D));return kt(p,[A,w])[0]}multiplyUnsafe(g,A=p.ZERO){if(!o.isValid(g))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return g===Wt?p.ZERO:this.is0()||g===rt?this:E.unsafe(this,g,w=>kt(p,w),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(g){return u(this,g)}clearCofactor(){return i===rt?this:this.multiplyUnsafe(i)}toBytes(){let{x:g,y:A}=this.toAffine(),w=n.toBytes(A);return w[w.length-1]|=g&rt?128:0,w}toHex(){return wt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(g){return kt(p,g)}static msm(g,A){return Ce(p,o,g,A)}_setWindowSize(g){this.precompute(g)}toRawBytes(){return this.toBytes()}}p.BASE=new p(s.Gx,s.Gy,rt,c(s.Gx*s.Gy)),p.ZERO=new p(Wt,rt,rt,Wt),p.Fp=n,p.Fn=o;let E=new De(p,o.BITS);return p.BASE.precompute(8),p}var Lr=class{constructor(t){this.ep=t}static fromBytes(t){Kn()}static fromHex(t){Kn()}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 wt(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.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function kc(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');Xt(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,a=r.randomBytes||Ie,c=r.adjustScalarBytes||(x=>x),f=r.domain||((x,_,P)=>{if(Ut(P,"phflag"),_.length||P)throw new Error("Contexts/pre-hash are not supported");return x});function d(x){return i.create(Pt(x))}function h(x){let _=w.secretKey;x=q("private key",x,_);let P=q("hashed private key",t(x),2*_),T=c(P.slice(0,_)),b=P.slice(_,2*_),m=d(T);return{head:T,prefix:b,scalar:m}}function u(x){let{head:_,prefix:P,scalar:T}=h(x),b=o.multiply(T),m=b.toBytes();return{head:_,prefix:P,scalar:T,point:b,pointBytes:m}}function l(x){return u(x).pointBytes}function p(x=Uint8Array.of(),..._){let P=ut(..._);return d(t(f(P,q("context",x),!!n)))}function E(x,_,P={}){x=q("message",x),n&&(x=n(x));let{prefix:T,scalar:b,pointBytes:m}=u(_),y=p(P.context,T,x),S=o.multiply(y).toBytes(),B=p(P.context,S,m,x),C=i.create(y+B*b);if(!i.isValid(C))throw new Error("sign failed: invalid s");let I=ut(S,i.toBytes(C));return bt(I,w.signature,"result")}let v={zip215:!0};function g(x,_,P,T=v){let{context:b,zip215:m}=T,y=w.signature;x=q("signature",x,y),_=q("message",_),P=q("publicKey",P,w.publicKey),m!==void 0&&Ut(m,"zip215"),n&&(_=n(_));let S=y/2,B=x.subarray(0,S),C=Pt(x.subarray(S,y)),I,L,K;try{I=e.fromBytes(P,m),L=e.fromBytes(B,m),K=o.multiplyUnsafe(C)}catch{return!1}if(!m&&I.isSmallOrder())return!1;let N=p(b,L.toBytes(),I.toBytes(),_);return L.add(I.multiplyUnsafe(N)).subtract(K).clearCofactor().is0()}let A=s.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function D(x=a(w.seed)){return bt(x,w.seed,"seed")}function R(x){let _=U.randomSecretKey(x);return{secretKey:_,publicKey:l(_)}}function O(x){return Ct(x)&&x.length===i.BYTES}function k(x,_){try{return!!e.fromBytes(x,_)}catch{return!1}}let U={getExtendedPublicKey:u,randomSecretKey:D,isValidSecretKey:O,isValidPublicKey:k,toMontgomery(x){let{y:_}=e.fromBytes(x),P=w.publicKey,T=P===32;if(!T&&P!==57)throw new Error("only defined for 25519 and 448");let b=T?s.div(rt+_,rt-_):s.div(_-rt,_+rt);return s.toBytes(b)},toMontgomerySecret(x){let _=w.secretKey;bt(x,_);let P=t(x.subarray(0,_));return c(P).subarray(0,_)},randomPrivateKey:D,precompute(x=8,_=e.BASE){return _.precompute(x,!1)}};return Object.freeze({keygen:R,getPublicKey:l,sign:E,verify:g,utils:U,Point:e,lengths:w})}function Oc(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=gt(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function Mc(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function Xs(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=Oc(e),s=Nc(t,r),i=kc(s,n,o);return Mc(e,i)}var Hc=BigInt(0),Ot=BigInt(1),Ws=BigInt(2),Lh=BigInt(3),qc=BigInt(5),Vc=BigInt(8),Ke=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),rr={p:Ke,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Vc,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Fc(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ke,a=e*e%s*e%s,c=F(a,Ws,s)*a%s,f=F(c,Ot,s)*e%s,d=F(f,qc,s)*f%s,h=F(d,t,s)*d%s,u=F(h,r,s)*h%s,l=F(u,n,s)*u%s,p=F(l,o,s)*l%s,E=F(p,o,s)*l%s,v=F(E,t,s)*d%s;return{pow_p_5_8:F(v,Ws,s)*e%s,b2:a}}function zc(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var qn=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function zn(e,t){let r=Ke,n=X(t*t*t,r),o=X(n*n*t,r),s=Fc(e*o).pow_p_5_8,i=X(e*n*s,r),a=X(t*i*i,r),c=i,f=X(i*qn,r),d=a===e,h=a===X(-e,r),u=a===X(-e*qn,r);return d&&(i=c),(h||u)&&(i=f),Nt(i,r)&&(i=X(-i,r)),{isValid:d||h,value:i}}var Jt=gt(rr.p,{isLE:!0}),jc=gt(rr.n,{isLE:!0}),Zc={...rr,Fp:Jt,hash:Ts,adjustScalarBytes:zc,uvRatio:zn},Mt=Xs(Zc);var Vn=qn,Gc=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Yc=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),$c=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Xc=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Js=e=>zn(Ot,e),Wc=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Fn=e=>Mt.Point.Fp.create(Pt(e)&Wc);function Qs(e){let{d:t}=rr,r=Ke,n=g=>Jt.create(g),o=n(Vn*e*e),s=n((o+Ot)*$c),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:f}=zn(s,a),d=n(f*e);Nt(d,r)||(d=n(-d)),c||(f=d),c||(i=o);let h=n(i*(o-Ot)*Xc-a),u=f*f,l=n((f+f)*a),p=n(h*Gc),E=n(Ot-u),v=n(Ot+u);return new Mt.Point(n(l*v),n(E*p),n(p*v),n(l*E))}function Jc(e){mt(e,64);let t=Fn(e.subarray(0,32)),r=Qs(t),n=Fn(e.subarray(32,64)),o=Qs(n);return new Ht(r.add(o))}var Ht=class e extends Lr{constructor(t){super(t)}static fromAffine(t){return new e(Mt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return Jc(q("ristrettoHash",t,64))}static fromBytes(t){mt(t,32);let{a:r,d:n}=rr,o=Ke,s=D=>Jt.create(D),i=Fn(t);if(!Cs(Jt.toBytes(i),t)||Nt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Ot+r*a),f=s(Ot-r*a),d=s(c*c),h=s(f*f),u=s(r*n*d-h),{isValid:l,value:p}=Js(s(u*h)),E=s(p*f),v=s(p*E*u),g=s((i+i)*E);Nt(g,o)&&(g=s(-g));let A=s(c*v),w=s(g*A);if(!l||Nt(w,o)||A===Hc)throw new Error("invalid ristretto255 encoding 2");return new e(new Mt.Point(g,A,Ot,w))}static fromHex(t){return e.fromBytes(q("ristrettoHex",t,32))}static msm(t,r){return Ce(e,Mt.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Ke,i=v=>Jt.create(v),a=i(i(n+r)*i(n-r)),c=i(t*r),f=i(c*c),{value:d}=Js(i(a*f)),h=i(d*a),u=i(d*c),l=i(h*u*o),p;if(Nt(o*l,s)){let v=i(r*Vn),g=i(t*Vn);t=v,r=g,p=i(h*Yc)}else p=u;Nt(t*l,s)&&(r=i(-r));let E=i((n-r)*p);return Nt(E,s)&&(E=i(-E)),Jt.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=f=>Jt.create(f),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(e.ZERO)}};Ht.BASE=new Ht(Mt.Point.BASE);Ht.ZERO=new Ht(Mt.Point.ZERO);Ht.Fp=Jt;Ht.Fn=jc;var nr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},_r=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ti={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new _r("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 Et=ti;var Re=32;var jn,Qc=(async()=>{try{return await Et.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function tu(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Et.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Et.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function eu(e,t,r){return Mt.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function ei(e,t,r){return jn==null&&(jn=await Qc),jn?tu(e,t,r):eu(e,t,r)}function Tr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Dr=class{type="Ed25519";raw;constructor(t){this.raw=Zn(t,Re)}toMultihash(){return It.digest(ve(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return W.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=ei(this.raw,r,t);return Tr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function oi(e){return e=Zn(e,Re),new Dr(e)}function Zn(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new G(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var ru=Math.pow(2,7),nu=Math.pow(2,14),ou=Math.pow(2,21),Gn=Math.pow(2,28),Yn=Math.pow(2,35),$n=Math.pow(2,42),Xn=Math.pow(2,49),H=128,at=127;function qt(e){if(e<ru)return 1;if(e<nu)return 2;if(e<ou)return 3;if(e<Gn)return 4;if(e<Yn)return 5;if(e<$n)return 6;if(e<Xn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Wn(e,t,r=0){switch(qt(e)){case 8:t[r++]=e&255|H,e/=128;case 7:t[r++]=e&255|H,e/=128;case 6:t[r++]=e&255|H,e/=128;case 5:t[r++]=e&255|H,e/=128;case 4:t[r++]=e&255|H,e>>>=7;case 3:t[r++]=e&255|H,e>>>=7;case 2:t[r++]=e&255|H,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function su(e,t,r=0){switch(qt(e)){case 8:t.set(r++,e&255|H),e/=128;case 7:t.set(r++,e&255|H),e/=128;case 6:t.set(r++,e&255|H),e/=128;case 5:t.set(r++,e&255|H),e/=128;case 4:t.set(r++,e&255|H),e>>>=7;case 3:t.set(r++,e&255|H),e>>>=7;case 2:t.set(r++,e&255|H),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Jn(e,t){let r=e[t],n=0;if(n+=r&at,r<H||(r=e[t+1],n+=(r&at)<<7,r<H)||(r=e[t+2],n+=(r&at)<<14,r<H)||(r=e[t+3],n+=(r&at)<<21,r<H)||(r=e[t+4],n+=(r&at)*Gn,r<H)||(r=e[t+5],n+=(r&at)*Yn,r<H)||(r=e[t+6],n+=(r&at)*$n,r<H)||(r=e[t+7],n+=(r&at)*Xn,r<H))return n;throw new RangeError("Could not decode varint")}function iu(e,t){let r=e.get(t),n=0;if(n+=r&at,r<H||(r=e.get(t+1),n+=(r&at)<<7,r<H)||(r=e.get(t+2),n+=(r&at)<<14,r<H)||(r=e.get(t+3),n+=(r&at)<<21,r<H)||(r=e.get(t+4),n+=(r&at)*Gn,r<H)||(r=e.get(t+5),n+=(r&at)*Yn,r<H)||(r=e.get(t+6),n+=(r&at)*$n,r<H)||(r=e.get(t+7),n+=(r&at)*Xn,r<H))return n;throw new RangeError("Could not decode varint")}function si(e,t,r=0){return t==null&&(t=dt(qt(e))),t instanceof Uint8Array?Wn(e,t,r):su(e,t,r)}function ii(e,t=0){return e instanceof Uint8Array?Jn(e,t):iu(e,t)}var Qn=new Float32Array([-0]),Qt=new Uint8Array(Qn.buffer);function ai(e,t,r){Qn[0]=e,t[r]=Qt[0],t[r+1]=Qt[1],t[r+2]=Qt[2],t[r+3]=Qt[3]}function ci(e,t){return Qt[0]=e[t],Qt[1]=e[t+1],Qt[2]=e[t+2],Qt[3]=e[t+3],Qn[0]}var to=new Float64Array([-0]),ct=new Uint8Array(to.buffer);function ui(e,t,r){to[0]=e,t[r]=ct[0],t[r+1]=ct[1],t[r+2]=ct[2],t[r+3]=ct[3],t[r+4]=ct[4],t[r+5]=ct[5],t[r+6]=ct[6],t[r+7]=ct[7]}function fi(e,t){return ct[0]=e[t],ct[1]=e[t+1],ct[2]=e[t+2],ct[3]=e[t+3],ct[4]=e[t+4],ct[5]=e[t+5],ct[6]=e[t+6],ct[7]=e[t+7],to[0]}var cu=BigInt(Number.MAX_SAFE_INTEGER),uu=BigInt(Number.MIN_SAFE_INTEGER),xt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ce;if(t<cu&&t>uu)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>li&&(o=0n,++n>li&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ce;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):ce}},ce=new xt(0,0);ce.toBigInt=function(){return 0n};ce.zzEncode=ce.zzDecode=function(){return this};ce.length=function(){return 1};var li=4294967296n;function hi(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function di(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function eo(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function At(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Cr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var ro=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,At(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw At(this,4);return Cr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw At(this,4);return Cr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw At(this,4);let t=ci(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw At(this,4);let t=fi(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw At(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return di(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw At(this,t);this.pos+=t}else do if(this.pos>=this.len)throw At(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new xt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw At(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw At(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw At(this,8);let t=Cr(this.buf,this.pos+=4),r=Cr(this.buf,this.pos+=4);return new xt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Jn(this.buf,this.pos);return this.pos+=qt(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 no(e){return new ro(e instanceof Uint8Array?e:e.subarray())}function ue(e,t,r){let n=no(e);return t.decode(n,void 0,r)}function oo(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 fe=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function so(){}var ao=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},fu=oo();function lu(e){return globalThis.Buffer!=null?dt(e):fu(e)}var sr=class{len;head;tail;states;constructor(){this.len=0,this.head=new fe(so,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new fe(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new co((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Kr,10,xt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=xt.fromBigInt(t);return this._push(Kr,r.length(),r)}uint64Number(t){return this._push(Wn,qt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=xt.fromBigInt(t).zzEncode();return this._push(Kr,r.length(),r)}sint64Number(t){let r=xt.fromNumber(t).zzEncode();return this._push(Kr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(io,1,t?1:0)}fixed32(t){return this._push(or,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=xt.fromBigInt(t);return this._push(or,4,r.lo)._push(or,4,r.hi)}fixed64Number(t){let r=xt.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(ai,4,t)}double(t){return this._push(ui,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(io,1,0):this.uint32(r)._push(du,r,t)}string(t){let r=hi(t);return r!==0?this.uint32(r)._push(eo,r,t):this._push(io,1,0)}fork(){return this.states=new ao(this),this.head=this.tail=new fe(so,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 fe(so,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=lu(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function io(e,t,r){t[r]=e&255}function hu(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var co=class extends fe{next;constructor(t,r){super(hu,t,r),this.next=void 0}};function Kr(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function 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 du(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(pu,t,e),this},sr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(mu,t,e),this});function pu(e,t,r){t.set(e,r)}function mu(e,t,r){e.length<40?eo(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(J(e),r)}function uo(){return new sr}function le(e,t){let r=uo();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Ue;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(Ue||(Ue={}));function Rr(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function ir(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Rr("enum",Ue.VARINT,r,n)}function he(e,t){return Rr("message",Ue.LENGTH_DELIMITED,e,t)}var yt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(yt||(yt={}));var fo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(fo||(fo={}));(function(e){e.codec=()=>ir(fo)})(yt||(yt={}));var te;(function(e){let t;e.codec=()=>(t==null&&(t=he((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),yt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=yt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>le(r,e.codec()),e.decode=(r,n)=>ue(r,e.codec(),n)})(te||(te={}));var lo;(function(e){let t;e.codec=()=>(t==null&&(t=he((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),yt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=yt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>le(r,e.codec()),e.decode=(r,n)=>ue(r,e.codec(),n)})(lo||(lo={}));var cr={};ht(cr,{MAX_RSA_KEY_SIZE:()=>ho,generateRSAKeyPair:()=>wi,jwkToJWKKeyPair:()=>Ei,jwkToPkcs1:()=>xu,jwkToPkix:()=>bo,jwkToRSAPrivateKey:()=>xo,pkcs1MessageToJwk:()=>mo,pkcs1MessageToRSAPrivateKey:()=>go,pkcs1ToJwk:()=>gu,pkcs1ToRSAPrivateKey:()=>gi,pkixMessageToJwk:()=>yo,pkixMessageToRSAPublicKey:()=>Pr,pkixToJwk:()=>wu,pkixToRSAPublicKey:()=>xi});var Ur=Sr;var Pe=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 st.createV1(114,this._multihash)}toString(){return W.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 bi(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:it(this.raw,t.raw)}sign(t,r){return yi(this.jwk,t,r)}};var ho=8192,po=18,yu=1062,bu=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function gu(e){let t=Lt(e);return mo(t)}function mo(e){return{n:$(e[1],"base64url"),e:$(e[2],"base64url"),d:$(e[3],"base64url"),p:$(e[4],"base64url"),q:$(e[5],"base64url"),dp:$(e[6],"base64url"),dq:$(e[7],"base64url"),qi:$(e[8],"base64url"),kty:"RSA"}}function xu(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 G("JWK was missing components");return jt([pt(Uint8Array.from([0])),pt(J(e.n,"base64url")),pt(J(e.e,"base64url")),pt(J(e.d,"base64url")),pt(J(e.p,"base64url")),pt(J(e.q,"base64url")),pt(J(e.dp,"base64url")),pt(J(e.dq,"base64url")),pt(J(e.qi,"base64url"))]).subarray()}function wu(e){let t=Lt(e,{offset:0});return yo(t)}function yo(e){let t=Lt(e[1],{offset:0});return{kty:"RSA",n:$(t[0],"base64url"),e:$(t[1],"base64url")}}function bo(e){if(e.n==null||e.e==null)throw new G("JWK was missing components");return jt([bu,br(jt([pt(J(e.n,"base64url")),pt(J(e.e,"base64url"))]))]).subarray()}function gi(e){let t=Lt(e);return go(t)}function go(e){let t=mo(e);return xo(t)}function xi(e,t){if(e.byteLength>=yu)throw new pe("Key size is too large");let r=Lt(e,{offset:0});return Pr(r,e,t)}function Pr(e,t,r){let n=yo(e);if(r==null){let o=Ur(te.encode({Type:yt.RSA,Data:t}));r=Bt(po,o)}return new Pe(n,r)}function xo(e){if(vi(e)>ho)throw new G("Key size is too large");let t=Ei(e),r=Ur(te.encode({Type:yt.RSA,Data:bo(t.publicKey)})),n=Bt(po,r);return new ar(t.privateKey,new Pe(t.publicKey,n))}async function wi(e){if(e>ho)throw new G("Key size is too large");let t=await Si(e),r=Ur(te.encode({Type:yt.RSA,Data:bo(t.publicKey)})),n=Bt(po,r);return new ar(t.privateKey,new Pe(t.publicKey,n))}function Ei(e){if(e==null)throw new G("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var Ai="1.2.840.113549.1.1.1";async function Si(e,t){let r=await Et.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Eu(r,t);return{privateKey:n[0],publicKey:n[1]}}async function yi(e,t,r){let n=await Et.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Et.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function bi(e,t,r,n){let o=await Et.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Et.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Eu(e,t){if(e.privateKey==null||e.publicKey==null)throw new G("Private and public key are required");let r=await Promise.all([Et.get().subtle.exportKey("jwk",e.privateKey),Et.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function vi(e){if(e.kty!=="RSA")throw new G("invalid key type");if(e.n==null)throw new G("invalid key modulus");return J(e.n,"base64url").length*8}var Nr=class extends Ae{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,gr(t);let n=Ye(r);if(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 o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),Kt(s)}update(t){return Be(this),this.iHash.update(t),this}digestInto(t){Be(this),mt(t,this.outputLen),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||(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()}},wo=(e,t,r)=>new Nr(e,t).update(r).digest();wo.create=(e,t)=>new Nr(e,t);var Bi=(e,t)=>(e+(e>=0?t:-t)/Ii)/t;function Su(e,t,r){let[[n,o],[s,i]]=t,a=Bi(i*e,r),c=Bi(-o*e,r),f=e-a*n-c*s,d=-a*o-c*i,h=f<Ft,u=d<Ft;h&&(f=-f),u&&(d=-d);let l=$t(Math.ceil(Ar(r)/2))+ke;if(f<Ft||f>=l||d<Ft||d>=l)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:h,k1:f,k2neg:u,k2:d}}function So(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Eo(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&&So(r.format),r}var vo=class extends Error{constructor(t=""){super(t)}},Vt={Err:vo,_tlv:{encode:(e,t)=>{let{Err:r}=Vt;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=Je(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Je(o.length/2|128):"";return Je(e)+s+o+t},decode(e,t){let{Err:r}=Vt,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 c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let d of f)i=i<<8|d;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Vt;if(e<Ft)throw new t("integer: negative integers are not allowed");let r=Je(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}=Vt;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 Le(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Vt,o=q("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:d}=n.decode(2,c);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=Vt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Ft=BigInt(0),ke=BigInt(1),Ii=BigInt(2),kr=BigInt(3),vu=BigInt(4);function Ne(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=q("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function Au(e,t={}){let r=Ir("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:a}=s;Xt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=_i(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(T,b,m){let{x:y,y:S}=b.toAffine(),B=n.toBytes(y);if(Ut(m,"isCompressed"),m){d();let C=!n.isOdd(S);return ut(Li(C),B)}else return ut(Uint8Array.of(4),B,n.toBytes(S))}function u(T){bt(T,void 0,"Point");let{publicKey:b,publicKeyUncompressed:m}=f,y=T.length,S=T[0],B=T.subarray(1);if(y===b&&(S===2||S===3)){let C=n.fromBytes(B);if(!n.isValid(C))throw new Error("bad point: is not on curve, wrong x");let I=E(C),L;try{L=n.sqrt(I)}catch(z){let V=z instanceof Error?": "+z.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}d();let K=n.isOdd(L);return(S&1)===1!==K&&(L=n.neg(L)),{x:C,y:L}}else if(y===m&&S===4){let C=n.BYTES,I=n.fromBytes(B.subarray(0,C)),L=n.fromBytes(B.subarray(C,C*2));if(!v(I,L))throw new Error("bad point: is not on curve");return{x:I,y:L}}else throw new Error(`bad point: got length ${y}, expected compressed=${b} or uncompressed=${m}`)}let l=t.toBytes||h,p=t.fromBytes||u;function E(T){let b=n.sqr(T),m=n.mul(b,T);return n.add(n.add(m,n.mul(T,s.a)),s.b)}function v(T,b){let m=n.sqr(b),y=E(T);return n.eql(m,y)}if(!v(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let g=n.mul(n.pow(s.a,kr),vu),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(g,A)))throw new Error("bad curve params: a or b");function w(T,b,m=!1){if(!n.isValid(b)||m&&n.is0(b))throw new Error(`bad point coordinate ${T}`);return b}function D(T){if(!(T instanceof x))throw new Error("ProjectivePoint expected")}function R(T){if(!c||!c.basises)throw new Error("no endo");return Su(T,c.basises,o.ORDER)}let O=_e((T,b)=>{let{X:m,Y:y,Z:S}=T;if(n.eql(S,n.ONE))return{x:m,y};let B=T.is0();b==null&&(b=B?n.ONE:n.inv(S));let C=n.mul(m,b),I=n.mul(y,b),L=n.mul(S,b);if(B)return{x:n.ZERO,y:n.ZERO};if(!n.eql(L,n.ONE))throw new Error("invZ was invalid");return{x:C,y:I}}),k=_e(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:b,y:m}=T.toAffine();if(!n.isValid(b)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!v(b,m))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function U(T,b,m,y,S){return m=new x(n.mul(m.X,T),m.Y,m.Z),b=er(y,b),m=er(S,m),b.add(m)}class x{constructor(b,m,y){this.X=w("x",b),this.Y=w("y",m,!0),this.Z=w("z",y),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){let{x:m,y}=b||{};if(!b||!n.isValid(m)||!n.isValid(y))throw new Error("invalid affine point");if(b instanceof x)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(y)?x.ZERO:new x(m,y,n.ONE)}static fromBytes(b){let m=x.fromAffine(p(bt(b,void 0,"point")));return m.assertValidity(),m}static fromHex(b){return x.fromBytes(q("pointHex",b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,m=!0){return P.createCache(this,b),m||this.multiply(kr),this}assertValidity(){k(this)}hasEvenY(){let{y:b}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(b)}equals(b){D(b);let{X:m,Y:y,Z:S}=this,{X:B,Y:C,Z:I}=b,L=n.eql(n.mul(m,I),n.mul(B,S)),K=n.eql(n.mul(y,I),n.mul(C,S));return L&&K}negate(){return new x(this.X,n.neg(this.Y),this.Z)}double(){let{a:b,b:m}=s,y=n.mul(m,kr),{X:S,Y:B,Z:C}=this,I=n.ZERO,L=n.ZERO,K=n.ZERO,N=n.mul(S,S),z=n.mul(B,B),V=n.mul(C,C),M=n.mul(S,B);return M=n.add(M,M),K=n.mul(S,C),K=n.add(K,K),I=n.mul(b,K),L=n.mul(y,V),L=n.add(I,L),I=n.sub(z,L),L=n.add(z,L),L=n.mul(I,L),I=n.mul(M,I),K=n.mul(y,K),V=n.mul(b,V),M=n.sub(N,V),M=n.mul(b,M),M=n.add(M,K),K=n.add(N,N),N=n.add(K,N),N=n.add(N,V),N=n.mul(N,M),L=n.add(L,N),V=n.mul(B,C),V=n.add(V,V),N=n.mul(V,M),I=n.sub(I,N),K=n.mul(V,z),K=n.add(K,K),K=n.add(K,K),new x(I,L,K)}add(b){D(b);let{X:m,Y:y,Z:S}=this,{X:B,Y:C,Z:I}=b,L=n.ZERO,K=n.ZERO,N=n.ZERO,z=s.a,V=n.mul(s.b,kr),M=n.mul(m,B),j=n.mul(y,C),Q=n.mul(S,I),lt=n.add(m,y),Z=n.add(B,C);lt=n.mul(lt,Z),Z=n.add(M,j),lt=n.sub(lt,Z),Z=n.add(m,S);let ot=n.add(B,I);return Z=n.mul(Z,ot),ot=n.add(M,Q),Z=n.sub(Z,ot),ot=n.add(y,S),L=n.add(C,I),ot=n.mul(ot,L),L=n.add(j,Q),ot=n.sub(ot,L),N=n.mul(z,Z),L=n.mul(V,Q),N=n.add(L,N),L=n.sub(j,N),N=n.add(j,N),K=n.mul(L,N),j=n.add(M,M),j=n.add(j,M),Q=n.mul(z,Q),Z=n.mul(V,Z),j=n.add(j,Q),Q=n.sub(M,Q),Q=n.mul(z,Q),Z=n.add(Z,Q),M=n.mul(j,Z),K=n.add(K,M),M=n.mul(ot,Z),L=n.mul(lt,L),L=n.sub(L,M),M=n.mul(lt,j),N=n.mul(ot,N),N=n.add(N,M),new x(L,K,N)}subtract(b){return this.add(b.negate())}is0(){return this.equals(x.ZERO)}multiply(b){let{endo:m}=t;if(!o.isValidNot0(b))throw new Error("invalid scalar: out of range");let y,S,B=C=>P.cached(this,C,I=>kt(x,I));if(m){let{k1neg:C,k1:I,k2neg:L,k2:K}=R(b),{p:N,f:z}=B(I),{p:V,f:M}=B(K);S=z.add(M),y=U(m.beta,N,V,C,L)}else{let{p:C,f:I}=B(b);y=C,S=I}return kt(x,[y,S])[0]}multiplyUnsafe(b){let{endo:m}=t,y=this;if(!o.isValid(b))throw new Error("invalid scalar: out of range");if(b===Ft||y.is0())return x.ZERO;if(b===ke)return y;if(P.hasCache(this))return this.multiply(b);if(m){let{k1neg:S,k1:B,k2neg:C,k2:I}=R(b),{p1:L,p2:K}=$s(x,y,B,I);return U(m.beta,L,K,S,C)}else return P.unsafe(y,b)}multiplyAndAddUnsafe(b,m,y){let S=this.multiplyUnsafe(m).add(b.multiplyUnsafe(y));return S.is0()?void 0:S}toAffine(b){return O(this,b)}isTorsionFree(){let{isTorsionFree:b}=t;return i===ke?!0:b?b(x,this):P.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:b}=t;return i===ke?this:b?b(x,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(b=!0){return Ut(b,"isCompressed"),this.assertValidity(),l(x,this,b)}toHex(b=!0){return wt(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(b=!0){return this.toBytes(b)}_setWindowSize(b){this.precompute(b)}static normalizeZ(b){return kt(x,b)}static msm(b,m){return Ce(x,o,b,m)}static fromPrivateKey(b){return x.BASE.multiply(Ne(o,b))}}x.BASE=new x(s.Gx,s.Gy,n.ONE),x.ZERO=new x(n.ZERO,n.ONE,n.ZERO),x.Fp=n,x.Fn=o;let _=o.BITS,P=new De(x,t.endo?Math.ceil(_/2):_);return x.BASE.precompute(8),x}function Li(e){return Uint8Array.of(e?2:3)}function _i(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Bu(e,t={}){let{Fn:r}=e,n=t.randomBytes||Ie,o=Object.assign(_i(e.Fp,r),{seed:Pn(r.ORDER)});function s(l){try{return!!Ne(r,l)}catch{return!1}}function i(l,p){let{publicKey:E,publicKeyUncompressed:v}=o;try{let g=l.length;return p===!0&&g!==E||p===!1&&g!==v?!1:!!e.fromBytes(l)}catch{return!1}}function a(l=n(o.seed)){return Nn(bt(l,o.seed,"seed"),r.ORDER)}function c(l,p=!0){return e.BASE.multiply(Ne(r,l)).toBytes(p)}function f(l){let p=a(l);return{secretKey:p,publicKey:c(p)}}function d(l){if(typeof l=="bigint")return!1;if(l instanceof e)return!0;let{secretKey:p,publicKey:E,publicKeyUncompressed:v}=o;if(r.allowedLengths||p===E)return;let g=q("key",l).length;return g===E||g===v}function h(l,p,E=!0){if(d(l)===!0)throw new Error("first arg must be private key");if(d(p)===!1)throw new Error("second arg must be public key");let v=Ne(r,l);return e.fromHex(p).multiply(v).toBytes(E)}return Object.freeze({getPublicKey:c,getSharedSecret:h,keygen:f,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a,isValidPrivateKey:s,randomPrivateKey:a,normPrivateKeyToScalar:l=>Ne(r,l),precompute(l=8,p=e.BASE){return p.precompute(l,!1)}},lengths:o})}function Iu(e,t,r={}){gr(t),Xt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||Ie,o=r.hmac||((m,...y)=>wo(t,m,ut(...y))),{Fp:s,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:f,getPublicKey:d,getSharedSecret:h,utils:u,lengths:l}=Bu(e,r),p={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},E="compact";function v(m){let y=a>>ke;return m>y}function g(m,y){if(!i.isValidNot0(y))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return y}function A(m,y){So(y);let S=l.signature,B=y==="compact"?S:y==="recovered"?S+1:void 0;return bt(m,B,`${y} signature`)}class w{constructor(y,S,B){this.r=g("r",y),this.s=g("s",S),B!=null&&(this.recovery=B),Object.freeze(this)}static fromBytes(y,S=E){A(y,S);let B;if(S==="der"){let{r:K,s:N}=Vt.toSig(bt(y));return new w(K,N)}S==="recovered"&&(B=y[0],S="compact",y=y.subarray(1));let C=i.BYTES,I=y.subarray(0,C),L=y.subarray(C,C*2);return new w(i.fromBytes(I),i.fromBytes(L),B)}static fromHex(y,S){return this.fromBytes(ne(y),S)}addRecoveryBit(y){return new w(this.r,this.s,y)}recoverPublicKey(y){let S=s.ORDER,{r:B,s:C,recovery:I}=this;if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");if(a*Ii<S&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");let K=I===2||I===3?B+a:B;if(!s.isValid(K))throw new Error("recovery id 2 or 3 invalid");let N=s.toBytes(K),z=e.fromBytes(ut(Li((I&1)===0),N)),V=i.inv(K),M=R(q("msgHash",y)),j=i.create(-M*V),Q=i.create(C*V),lt=e.BASE.multiplyUnsafe(j).add(z.multiplyUnsafe(Q));if(lt.is0())throw new Error("point at infinify");return lt.assertValidity(),lt}hasHighS(){return v(this.s)}toBytes(y=E){if(So(y),y==="der")return ne(Vt.hexFromSig(this));let S=i.toBytes(this.r),B=i.toBytes(this.s);if(y==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return ut(Uint8Array.of(this.recovery),S,B)}return ut(S,B)}toHex(y){return wt(this.toBytes(y))}assertValidity(){}static fromCompact(y){return w.fromBytes(q("sig",y),"compact")}static fromDER(y){return w.fromBytes(q("sig",y),"der")}normalizeS(){return this.hasHighS()?new w(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return wt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return wt(this.toBytes("compact"))}}let D=r.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let S=Le(y),B=y.length*8-c;return B>0?S>>BigInt(B):S},R=r.bits2int_modN||function(y){return i.create(D(y))},O=$t(c);function k(m){return Qe("num < 2^"+c,m,Ft,O),i.toBytes(m)}function U(m,y){return bt(m,void 0,"message"),y?bt(t(m),void 0,"prehashed message"):m}function x(m,y,S){if(["recovered","canonical"].some(j=>j in S))throw new Error("sign() legacy options not supported");let{lowS:B,prehash:C,extraEntropy:I}=Eo(S,p);m=U(m,C);let L=R(m),K=Ne(i,y),N=[k(K),k(L)];if(I!=null&&I!==!1){let j=I===!0?n(l.secretKey):I;N.push(q("extraEntropy",j))}let z=ut(...N),V=L;function M(j){let Q=D(j);if(!i.isValidNot0(Q))return;let lt=i.inv(Q),Z=e.BASE.multiply(Q).toAffine(),ot=i.create(Z.x);if(ot===Ft)return;let fr=i.create(lt*i.create(V+ot*K));if(fr===Ft)return;let No=(Z.x===ot?0:2)|Number(Z.y&ke),ko=fr;return B&&v(fr)&&(ko=i.neg(fr),No^=1),new w(ot,ko,No)}return{seed:z,k2sig:M}}function _(m,y,S={}){m=q("message",m);let{seed:B,k2sig:C}=x(m,y,S);return Rs(t.outputLen,i.BYTES,o)(B,C)}function P(m){let y,S=typeof m=="string"||Ct(m),B=!S&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!S&&!B)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(B)y=new w(m.r,m.s);else if(S){try{y=w.fromBytes(q("sig",m),"der")}catch(C){if(!(C instanceof Vt.Err))throw C}if(!y)try{y=w.fromBytes(q("sig",m),"compact")}catch{return!1}}return y||!1}function T(m,y,S,B={}){let{lowS:C,prehash:I,format:L}=Eo(B,p);if(S=q("publicKey",S),y=U(q("message",y),I),"strict"in B)throw new Error("options.strict was renamed to lowS");let K=L===void 0?P(m):w.fromBytes(q("sig",m),L);if(K===!1)return!1;try{let N=e.fromBytes(S);if(C&&K.hasHighS())return!1;let{r:z,s:V}=K,M=R(y),j=i.inv(V),Q=i.create(M*j),lt=i.create(z*j),Z=e.BASE.multiplyUnsafe(Q).add(N.multiplyUnsafe(lt));return Z.is0()?!1:i.create(Z.x)===z}catch{return!1}}function b(m,y,S={}){let{prehash:B}=Eo(S,p);return y=U(y,B),w.fromBytes(m,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:f,getPublicKey:d,getSharedSecret:h,utils:u,lengths:l,Point:e,sign:_,verify:T,recoverPublicKey:b,Signature:w,hash:t})}function Lu(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=gt(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function _u(e){let{CURVE:t,curveOpts:r}=Lu(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function Tu(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,Br(r.Fn.ORDER,r.Fn.BITS))})}function Ti(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=_u(e),s=Au(t,r),i=Iu(s,n,o);return Tu(e,i)}function Di(e,t){let r=n=>Ti({...e,hash:n});return{...r(t),create:r}}var Bo={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Du={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ci=BigInt(2);function Cu(e){let t=Bo.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=e*e*e%t,d=f*f*e%t,h=F(d,r,t)*d%t,u=F(h,r,t)*d%t,l=F(u,Ci,t)*f%t,p=F(l,o,t)*l%t,E=F(p,s,t)*p%t,v=F(E,a,t)*E%t,g=F(v,c,t)*v%t,A=F(g,a,t)*E%t,w=F(A,r,t)*d%t,D=F(w,i,t)*p%t,R=F(D,n,t)*f%t,O=F(R,Ci,t);if(!Ao.eql(Ao.sqr(O),e))throw new Error("Cannot find square root");return O}var Ao=gt(Bo.p,{sqrt:Cu}),Oe=Di({...Bo,Fp:Ao,lowS:!0,endo:Du},Sr);var Ki=33;function Ri(e,t,r,n){let o=mr.digest(r instanceof Uint8Array?r:r.subarray());if(Tr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Oe.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new nr(String(s))});try{return n?.signal?.throwIfAborted(),Oe.verify(t,o.digest,e)}catch(s){throw new nr(String(s))}}var Or=class{type="secp256k1";raw;_key;constructor(t){this._key=Pi(t),this.raw=Ui(this._key)}toMultihash(){return It.digest(ve(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return W.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 Ri(this._key,r,t,n)}};function Ni(e){return new Or(e)}function Ui(e){return Oe.ProjectivePoint.fromHex(e).toRawBytes(!0)}function Pi(e){try{return Oe.ProjectivePoint.fromHex(e),e}catch(t){throw new pe(String(t))}}function ki(e){if(e.byteLength===Re)return oi(e);if(e.byteLength===Ki)return Ni(e);let t=Lt(e),r=t[1]?.[0];if(r===us||r===fs||r===ls)return ds(t);if(t[0]?.[0]===Ai)return Pr(t,e);throw new G("Could not extract public key from raw bytes")}function ve(e){return te.encode({Type:yt[e.type],Data:e.raw})}var Oi=Symbol.for("nodejs.util.inspect.custom"),Ku=114,ur=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()})`}[Zr]=!0;toString(){return this.string==null&&(this.string=W.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return st.createV1(Ku,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")}[Oi](){return`PeerId(${this.toString()})`}},Mr=class extends ur{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Hr=class extends ur{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},qr=class extends ur{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ru=2336,Io=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=It.digest(J(this.url))}[Oi](){return`PeerId(${this.url})`}[Zr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return st.createV1(Ru,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=$(t)),t.toString()===this.toString())}};function Mi(e){if(e.type==="Ed25519")return new Hr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new qr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Mr({multihash:e.toCID().multihash,publicKey:e});throw new He}var Lo=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},_o=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},Hi=e=>globalThis.DOMException===void 0?new _o(e):new DOMException(e),qi=e=>{let t=e.reason===void 0?Hi("This operation was aborted."):e.reason;return t instanceof Error?t:Hi(t)};function To(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,f=new Promise((d,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:l}=t;l.aborted&&h(qi(l)),a=()=>{h(qi(l))},l.addEventListener("abort",a,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(d,h);return}let u=new Lo;i=s.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(l){h(l)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?d():o instanceof Error?h(o):(u.message=o??`Promise timed out after ${r} milliseconds`,h(u))},r),(async()=>{try{d(await e)}catch(l){h(l)}})()}).finally(()=>{f.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return f.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},f}var Uu=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 Pu(e,t,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:f,removeListener:d}=Uu(e),h=(...l)=>{let p=r.multiArgs?l:l[0];r.filter&&!r.filter(p)||(c.push(p),r.count===c.length&&(n(),s(c)))},u=l=>{n(),i(l)};n=()=>{for(let l of a)d(l,h);for(let l of r.rejectionEvents)d(l,u)};for(let l of a)f(l,h);for(let l of r.rejectionEvents)f(l,u);r.signal&&r.signal.addEventListener("abort",()=>{u(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(o.cancel=n,typeof r.timeout=="number"){let s=To(o,{milliseconds:r.timeout});return s.cancel=n,s}return o}function Vi(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Pu(e,t,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var de=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Nu(e){return e.reason}async function Fi(e,t,r){if(t==null)return e;let n=r?.translateError??Nu;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 Ou=4194304,Vr=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Co=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ko=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ro=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Mu(e){return typeof e?.closeRead=="function"}function Hu(e){return typeof e?.close=="function"}function Do(e){return Mu(e)?e.readStatus==="closing"||e.readStatus==="closed":Hu(e)?e.status!=="open":!1}function qu(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function Vu(e,t){let r=t?.maxBufferSize??Ou,n=new tt,o=Promise.withResolvers(),s=!1;if(!qu(e))throw new G("Argument should be a Stream or a Multiaddr");let i=d=>{if(n.append(d.data),n.byteLength>r){let h=n.byteLength;n.consume(n.byteLength),o.reject(new Error(`Read buffer overflow - ${h} > ${r}`))}o.resolve()};e.addEventListener("message",i);let a=d=>{d.error!=null?o.reject(d.error):o.resolve()};e.addEventListener("close",a);let c=()=>{o.resolve()};e.addEventListener("remoteCloseWrite",c);let f={readBuffer:n,async read(d){if(s===!0)throw new Vr("Stream was unwrapped");if(Do(e)){if(d?.bytes==null)return null;if(n.byteLength<d.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,d.bytes),new de(`Unexpected EOF - stream closed after reading ${n.byteLength}/${d.bytes} bytes`)}let h=d?.bytes??1;for(;;){if(n.byteLength>=h){o.resolve();break}if(await Fi(o.promise,d?.signal),Do(e)){if(n.byteLength===0&&d?.bytes==null)return null;break}o=Promise.withResolvers()}let u=d?.bytes??n.byteLength;if(n.byteLength<u){if(Do(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,u),new de(`Unexpected EOF - stream closed while reading ${n.byteLength}/${u} bytes`);return f.read(d)}let l=n.sublist(0,u);return n.consume(u),l},async write(d,h){if(s===!0)throw new Vr("Stream was unwrapped");e.send(d)||await Vi(e,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",i),e.removeEventListener("close",a),e.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e}};return f}function Fu(e,t={}){let r=Vu(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=qt(t.maxDataLength));let n=t?.lengthDecoder??ii,o=t?.lengthEncoder??si;return{async read(i){let a=-1,c=new tt;for(;;){let d=await r.read({...i,bytes:1});if(d==null)break;c.append(d);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new Co("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Ro(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Ko(`Message length too long - ${a} > ${t.maxDataLength}`);let f=await r.read({...i,bytes:a});if(f==null)throw e.log.error("tried to read %d bytes but the stream closed",a),new de(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(f.byteLength!==a)throw e.log.error("read %d/%d bytes before the stream closed",f.byteLength,a),new de(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(i,a){await r.write(new tt(o(i.byteLength),i),a)},async writeV(i,a){let c=new tt(...i.flatMap(f=>[o(f.byteLength),f]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function zi(e,t){let r=Fu(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 Fr;(function(e){let t;e.codec=()=>(t==null&&(t=he((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.id!=null&&(n.uint32(10),n.bytes(r.id)),r.pubkey!=null&&(n.uint32(18),zr.codec().encode(r.pubkey,n)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.id=r.bytes();break}case 2:{s.pubkey=zr.codec().decode(r,r.uint32(),{limits:o.limits?.pubkey});break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>le(r,e.codec()),e.decode=(r,n)=>ue(r,e.codec(),n)})(Fr||(Fr={}));var ee;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(ee||(ee={}));var Uo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Uo||(Uo={}));(function(e){e.codec=()=>ir(Uo)})(ee||(ee={}));var zr;(function(e){let t;e.codec=()=>(t==null&&(t=he((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),ee.codec().encode(r.Type,n)),r.Data!=null&&r.Data.byteLength>0&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={Data:St(0)},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=ee.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>le(r,e.codec()),e.decode=(r,n)=>ue(r,e.codec(),n)})(zr||(zr={}));var zu="/plaintext/2.0.0",Po=class{protocol=zu;privateKey;log;constructor(t){this.privateKey=t.privateKey,this.log=t.logger.forComponent("libp2p:plaintext")}[Symbol.toStringTag]="@libp2p/plaintext";[Oo]=["@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=zi(t).pb(Fr);n("write pubkey exchange to peer %p",r?.remotePeer);let s=this.privateKey.publicKey;await o.write({id:s.toMultihash().bytes,pubkey:{Type:ee[s.type],Data:s.raw}},r);let i=await o.read(r),a;try{if(i.pubkey==null)throw new me("Public key missing");if(i.pubkey.Data.byteLength===0)throw new me("Public key data too short");if(i.id==null)throw new me("Remote id missing");let c=ki(i.pubkey.Data);if(a=Mi(c),!it(a.toMultihash().bytes,i.id))throw new Me("Public key did not match id")}catch(c){throw n.error(c),new Me("Invalid public key - "+c.message)}if(r?.remotePeer!=null&&!a.equals(r?.remotePeer))throw new lr;return n("plaintext key exchange completed successfully with peer %p",a),{connection:o.unwrap().unwrap(),remotePeer:a}}};function ju(){return e=>new Po(e)}return $i(Zu);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/esm/utils.js:
|