@libp2p/plaintext 2.0.27 → 2.0.28-4420fad68
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/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -3
- package/dist/src/index.js.map +1 -1
- package/package.json +6 -7
- package/src/index.ts +8 -9
- package/dist/typedoc-urls.json +0 -6
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 Mr=Object.defineProperty;var wi=Object.getOwnPropertyDescriptor;var gi=Object.getOwnPropertyNames;var Ei=Object.prototype.hasOwnProperty;var ct=(e,t)=>{for(var r in t)Mr(e,r,{get:t[r],enumerable:!0})},Si=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of gi(t))!Ei.call(e,o)&&o!==r&&Mr(e,o,{get:()=>t[o],enumerable:!(n=wi(t,o))||n.enumerable});return e};var Ai=e=>Si(Mr({},"__esModule",{value:!0}),e);var of={};ct(of,{plaintext:()=>nf});var qr=Symbol.for("@libp2p/peer-id");var tr=class extends Error{static name="UnexpectedPeerError";constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError"}},Le=class extends Error{static name="InvalidCryptoExchangeError";constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError"}},W=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ne=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var oe=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var De=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ho=Symbol.for("@libp2p/service-capabilities"),ff=Symbol.for("@libp2p/service-dependencies");var Gr={};ct(Gr,{base58btc:()=>j,base58flickr:()=>Ti});var Kf=new Uint8Array(0);function po(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Bt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return 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 mo(e){return new TextEncoder().encode(e)}function yo(e){return new TextDecoder().decode(e)}function vi(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),h=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(S){if(S instanceof Uint8Array||(ArrayBuffer.isView(S)?S=new Uint8Array(S.buffer,S.byteOffset,S.byteLength):Array.isArray(S)&&(S=Uint8Array.from(S))),!(S instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(S.length===0)return"";for(var E=0,m=0,A=0,D=S.length;A!==D&&S[A]===0;)A++,E++;for(var B=(D-A)*f+1>>>0,C=new Uint8Array(B);A!==D;){for(var p=S[A],K=0,T=B-1;(p!==0||K<m)&&T!==-1;T--,K++)p+=256*C[T]>>>0,C[T]=p%a>>>0,p=p/a>>>0;if(p!==0)throw new Error("Non-zero carry");m=K,A++}for(var I=B-m;I!==B&&C[I]===0;)I++;for(var u=c.repeat(E);I<B;++I)u+=e.charAt(C[I]);return u}function x(S){if(typeof S!="string")throw new TypeError("Expected String");if(S.length===0)return new Uint8Array;var E=0;if(S[E]!==" "){for(var m=0,A=0;S[E]===c;)m++,E++;for(var D=(S.length-E)*h+1>>>0,B=new Uint8Array(D);S[E];){var C=r[S.charCodeAt(E)];if(C===255)return;for(var p=0,K=D-1;(C!==0||p<A)&&K!==-1;K--,p++)C+=a*B[K]>>>0,B[K]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");A=p,E++}if(S[E]!==" "){for(var T=D-A;T!==D&&B[T]===0;)T++;for(var I=new Uint8Array(m+(D-T)),u=m;T!==D;)I[u++]=B[T++];return I}}}function b(S){var E=x(S);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:x,decode:b}}var Bi=vi,Ii=Bi,xo=Ii;var Vr=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")}},zr=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 wo(this,t)}},Fr=class{decoders;constructor(t){this.decoders=t}or(t){return wo(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 wo(e,t){return new Fr({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var jr=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 Vr(t,r,n),this.decoder=new zr(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function se({name:e,prefix:t,encode:r,decode:n}){return new jr(e,t,r,n)}function Ct({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=xo(r,e);return se({prefix:t,name:e,encode:n,decode:s=>Bt(o(s))})}function _i(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 h=0;h<o;++h){let f=t[e[h]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Li(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 Di(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function V({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Di(n);return se({prefix:t,name:e,encode(s){return Li(s,n,r)},decode(s){return _i(s,o,r,e)}})}var j=Ct({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ti=Ct({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Zr={};ct(Zr,{base32:()=>ie,base32hex:()=>Ui,base32hexpad:()=>Ni,base32hexpadupper:()=>ki,base32hexupper:()=>Pi,base32pad:()=>Ci,base32padupper:()=>Ri,base32upper:()=>Ki,base32z:()=>Oi});var ie=V({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ki=V({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ci=V({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ri=V({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ui=V({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Pi=V({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ni=V({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ki=V({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Oi=V({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Wr={};ct(Wr,{base36:()=>Te,base36upper:()=>Hi});var Te=Ct({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Hi=Ct({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Mi=So,go=128,qi=127,Vi=~qi,zi=Math.pow(2,31);function So(e,t,r){t=t||[],r=r||0;for(var n=r;e>=zi;)t[r++]=e&255|go,e/=128;for(;e&Vi;)t[r++]=e&255|go,e>>>=7;return t[r]=e|0,So.bytes=r-n+1,t}var Fi=Yr,ji=128,Eo=127;function Yr(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw Yr.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Eo)<<o:(i&Eo)*Math.pow(2,o),o+=7}while(i>=ji);return Yr.bytes=s-n,r}var Gi=Math.pow(2,7),Zi=Math.pow(2,14),Wi=Math.pow(2,21),Yi=Math.pow(2,28),$i=Math.pow(2,35),Xi=Math.pow(2,42),Ji=Math.pow(2,49),Qi=Math.pow(2,56),ta=Math.pow(2,63),ea=function(e){return e<Gi?1:e<Zi?2:e<Wi?3:e<Yi?4:e<$i?5:e<Xi?6:e<Ji?7:e<Qi?8:e<ta?9:10},ra={encode:Mi,decode:Fi,encodingLength:ea},na=ra,Ke=na;function Ce(e,t=0){return[Ke.decode(e,t),Ke.decode.bytes]}function ae(e,t,r=0){return Ke.encode(e,t,r),t}function ce(e){return Ke.encodingLength(e)}function mt(e,t){let r=t.byteLength,n=ce(e),o=n+ce(r),s=new Uint8Array(o+r);return ae(e,s,0),ae(r,s,n),s.set(t,o),new fe(e,r,t,s)}function $r(e){let t=Bt(e),[r,n]=Ce(t),[o,s]=Ce(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new fe(r,o,i,t)}function Ao(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&po(e.bytes,r.bytes)}}var fe=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function vo(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return sa(r,Xr(e),t??j.encoder);default:return ia(r,Xr(e),t??ie.encoder)}}var Bo=new WeakMap;function Xr(e){let t=Bo.get(e);if(t==null){let r=new Map;return Bo.set(e,r),r}return t}var tt=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!==Re)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==aa)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=mt(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&&Ao(t.multihash,n.multihash)}toString(t){return vo(this,t)}toJSON(){return{"/":vo(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??Io(n,o,s.bytes))}else if(r[ca]===!0){let{version:n,multihash:o,code:s}=r,i=$r(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!==Re)throw new Error(`Version 0 CID must use dag-pb (code: ${Re}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Io(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Re,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Bt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new fe(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,x]=Ce(t.subarray(r));return r+=x,l},o=n(),s=Re;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(),h=r+c,f=h-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:h}}static parse(t,r){let[n,o]=oa(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 Xr(s).set(n,t),s}};function oa(e,t){switch(e[0]){case"Q":{let r=t??j;return[j.prefix,r.decode(`${j.prefix}${e}`)]}case j.prefix:{let r=t??j;return[j.prefix,r.decode(e)]}case ie.prefix:{let r=t??ie;return[ie.prefix,r.decode(e)]}case Te.prefix:{let r=t??Te;return[Te.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 sa(e,t,r){let{prefix:n}=r;if(n!==j.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 ia(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 Re=112,aa=18;function Io(e,t,r){let n=ce(e),o=n+ce(t),s=new Uint8Array(o+r.byteLength);return ae(e,s,0),ae(t,s,n),s.set(r,o),s}var ca=Symbol.for("@ipld/js-cid/CID");var Jr={};ct(Jr,{identity:()=>gt});var _o=0,fa="identity",Lo=Bt;function ua(e){return mt(_o,Lo(e))}var gt={code:_o,name:fa,encode:Lo,digest:ua};function et(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 yt(e=0){return new Uint8Array(e)}function ft(e=0){return new Uint8Array(e)}function rr(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ft(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var To=Symbol.for("@achingbrain/uint8arraylist");function Do(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 nr(e){return!!e?.[To]}var Y=class e{bufs;length;[To]=!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(nr(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(nr(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=Do(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Do(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(nr(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 rr(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:rr(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 h=t>=a&&t<c,f=r>a&&r<=c;if(h&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(h){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!nr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,h=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let x=h;x>=0;x--){let b=this.get(l+x);if(n[x]!==b){f=Math.max(1,x-a[b]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ft(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=yt(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=yt(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=yt(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=ft(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=yt(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=yt(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=yt(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=yt(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=yt(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(!et(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 Qr={};ct(Qr,{base10:()=>la});var la=Ct({prefix:"9",name:"base10",alphabet:"0123456789"});var tn={};ct(tn,{base16:()=>ha,base16upper:()=>da});var ha=V({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),da=V({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var en={};ct(en,{base2:()=>pa});var pa=V({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var rn={};ct(rn,{base256emoji:()=>wa});var Ko=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}"),ma=Ko.reduce((e,t,r)=>(e[r]=t,e),[]),ya=Ko.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function ba(e){return e.reduce((t,r)=>(t+=ma[r],t),"")}function xa(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=ya[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var wa=se({prefix:"\u{1F680}",name:"base256emoji",encode:ba,decode:xa});var nn={};ct(nn,{base64:()=>ga,base64pad:()=>Ea,base64url:()=>Sa,base64urlpad:()=>Aa});var ga=V({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ea=V({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Sa=V({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Aa=V({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var on={};ct(on,{base8:()=>va});var va=V({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var sn={};ct(sn,{identity:()=>Ba});var Ba=se({prefix:"\0",name:"identity",encode:e=>yo(e),decode:e=>mo(e)});var pu=new TextEncoder,mu=new TextDecoder;var fn={};ct(fn,{sha256:()=>or,sha512:()=>La});function cn({name:e,code:t,encode:r}){return new an(e,t,r)}var an=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?mt(this.code,r):r.then(n=>mt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ro(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var or=cn({name:"sha2-256",code:18,encode:Ro("SHA-256")}),La=cn({name:"sha2-512",code:19,encode:Ro("SHA-512")});var un={...sn,...en,...on,...Qr,...tn,...Zr,...Wr,...Gr,...nn,...rn},_u={...fn,...Jr};function Po(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Uo=Po("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),ln=Po("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=ft(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Da={utf8:Uo,"utf-8":Uo,hex:un.base16,latin1:ln,ascii:ln,binary:ln,...un},sr=Da;function G(e,t="utf8"){let r=sr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function z(e,t="utf8"){let r=sr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Ta=parseInt("11111",2),hn=parseInt("10000000",2),Ka=parseInt("01111111",2),No={0:Ue,1:Ue,2:Ca,3:Pa,4:Na,5:Ua,6:Ra,16:Ue,22:Ue,48:Ue};function Et(e,t={offset:0}){let r=e[t.offset]&Ta;if(t.offset++,No[r]!=null)return No[r](e,t);throw new Error("No decoder for tag "+r)}function Pe(e,t){let r=0;if((e[t.offset]&hn)===hn){let n=e[t.offset]&Ka,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 Ue(e,t){Pe(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Et(e,t);if(n===null)break;r.push(n)}return r}function Ca(e,t){let r=Pe(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 Ra(e,t){let r=Pe(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 h=e[t.offset];if(t.offset++,c.push(h&127),h<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Ua(e,t){return t.offset++,null}function Pa(e,t){let r=Pe(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 Na(e,t){let r=Pe(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function ka(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new Y;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function dn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=ka(e.byteLength);return new Y(Uint8Array.from([t.byteLength|hn]),t)}function ut(e){let t=new Y,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new Y(Uint8Array.from([2]),dn(t),t)}function ir(e){let t=Uint8Array.from([0]),r=new Y(t,e);return new Y(Uint8Array.from([3]),dn(r),r)}function Rt(e,t=48){let r=new Y;for(let n of e)r.append(n);return new Y(Uint8Array.from([t]),dn(r),r)}var ko="1.2.840.10045.3.1.7",Oo="1.3.132.0.34",Ho="1.3.132.0.35";async function Mo(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 Oa=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Ha=Uint8Array.from([6,5,43,129,4,0,34]),Ma=Uint8Array.from([6,5,43,129,4,0,35]),qa={ext:!0,kty:"EC",crv:"P-256"},Va={ext:!0,kty:"EC",crv:"P-384"},za={ext:!0,kty:"EC",crv:"P-521"},pn=32,mn=48,yn=66;function qo(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===pn*2+1)return n=z(t.subarray(r,r+pn),"base64url"),o=z(t.subarray(r+pn),"base64url"),new le({...qa,key_ops:["verify"],x:n,y:o});if(t.byteLength===mn*2+1)return n=z(t.subarray(r,r+mn),"base64url"),o=z(t.subarray(r+mn),"base64url"),new le({...Va,key_ops:["verify"],x:n,y:o});if(t.byteLength===yn*2+1)return n=z(t.subarray(r,r+yn),"base64url"),o=z(t.subarray(r+yn),"base64url"),new le({...za,key_ops:["verify"],x:n,y:o});throw new W(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Vo(e){return Rt([ut(Uint8Array.from([1])),Rt([Fa(e.crv)],160),Rt([ir(new Y(Uint8Array.from([4]),G(e.x??"","base64url"),G(e.y??"","base64url")))],161)]).subarray()}function Fa(e){if(e==="P-256")return Oa;if(e==="P-384")return Ha;if(e==="P-521")return Ma;throw new W(`Invalid curve ${e}`)}var le=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Vo(this.jwk)),this._raw}toMultihash(){return gt.digest(he(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:et(this.raw,t.raw)}async verify(t,r,n){return Mo(this.jwk,r,t,n)}};var zt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function pe(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ne(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function rt(e,...t){if(!pe(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 Fo(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Ne(e.outputLen),Ne(e.blockLen)}function me(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 jo(e,t){rt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function _t(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function ar(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function bt(e,t){return e<<32-t|e>>>t}var Go=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ja=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function St(e){if(rt(e),Go)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=ja[e[r]];return t}var It={_0:48,_9:57,A:65,F:70,a:97,f:102};function zo(e){if(e>=It._0&&e<=It._9)return e-It._0;if(e>=It.A&&e<=It.F)return e-(It.A-10);if(e>=It.a&&e<=It.f)return e-(It.a-10)}function ye(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Go)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=zo(e.charCodeAt(s)),a=zo(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 Zo(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function ke(e){return typeof e=="string"&&(e=Zo(e)),rt(e),e}function ht(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];rt(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 de=class{};function bn(e){let t=n=>e().update(ke(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Oe(e=32){if(zt&&typeof zt.getRandomValues=="function")return zt.getRandomValues(new Uint8Array(e));if(zt&&typeof zt.randomBytes=="function")return Uint8Array.from(zt.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Ga(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,h=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+h,a,n)}function Wo(e,t,r){return e&t^~e&r}function Yo(e,t,r){return e&t^e&r^t&r}var He=class extends de{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=ar(this.buffer)}update(t){me(this),t=ke(t),rt(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=ar(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){me(this),jo(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,_t(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;Ga(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=ar(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let h=c/4,f=this.get();if(h>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<h;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_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()}},Lt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var J=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var cr=BigInt(4294967295),$o=BigInt(32);function Za(e,t=!1){return t?{h:Number(e&cr),l:Number(e>>$o&cr)}:{h:Number(e>>$o&cr)|0,l:Number(e&cr)|0}}function Xo(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}=Za(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var xn=(e,t,r)=>e>>>r,wn=(e,t,r)=>e<<32-r|t>>>r,Ft=(e,t,r)=>e>>>r|t<<32-r,jt=(e,t,r)=>e<<32-r|t>>>r,Me=(e,t,r)=>e<<64-r|t>>>r-32,qe=(e,t,r)=>e>>>r-32|t<<64-r;function At(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Jo=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Qo=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ts=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),es=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,rs=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ns=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Ya=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]),Ut=new Uint32Array(64),fr=class extends He{constructor(t=32){super(64,t,8,!1),this.A=Lt[0]|0,this.B=Lt[1]|0,this.C=Lt[2]|0,this.D=Lt[3]|0,this.E=Lt[4]|0,this.F=Lt[5]|0,this.G=Lt[6]|0,this.H=Lt[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 l=0;l<16;l++,r+=4)Ut[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let x=Ut[l-15],b=Ut[l-2],S=bt(x,7)^bt(x,18)^x>>>3,E=bt(b,17)^bt(b,19)^b>>>10;Ut[l]=E+Ut[l-7]+S+Ut[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:h,H:f}=this;for(let l=0;l<64;l++){let x=bt(a,6)^bt(a,11)^bt(a,25),b=f+x+Wo(a,c,h)+Ya[l]+Ut[l]|0,E=(bt(n,2)^bt(n,13)^bt(n,22))+Yo(n,o,s)|0;f=h,h=c,c=a,a=i+b|0,i=s,s=o,o=n,n=b+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,h=h+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,h,f)}roundClean(){_t(Ut)}destroy(){this.set(0,0,0,0,0,0,0,0),_t(this.buffer)}};var os=Xo(["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))),$a=os[0],Xa=os[1],Pt=new Uint32Array(80),Nt=new Uint32Array(80),gn=class extends He{constructor(t=64){super(128,t,16,!1),this.Ah=J[0]|0,this.Al=J[1]|0,this.Bh=J[2]|0,this.Bl=J[3]|0,this.Ch=J[4]|0,this.Cl=J[5]|0,this.Dh=J[6]|0,this.Dl=J[7]|0,this.Eh=J[8]|0,this.El=J[9]|0,this.Fh=J[10]|0,this.Fl=J[11]|0,this.Gh=J[12]|0,this.Gl=J[13]|0,this.Hh=J[14]|0,this.Hl=J[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:h,El:f,Fh:l,Fl:x,Gh:b,Gl:S,Hh:E,Hl:m}=this;return[t,r,n,o,s,i,a,c,h,f,l,x,b,S,E,m]}set(t,r,n,o,s,i,a,c,h,f,l,x,b,S,E,m){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=h|0,this.El=f|0,this.Fh=l|0,this.Fl=x|0,this.Gh=b|0,this.Gl=S|0,this.Hh=E|0,this.Hl=m|0}process(t,r){for(let B=0;B<16;B++,r+=4)Pt[B]=t.getUint32(r),Nt[B]=t.getUint32(r+=4);for(let B=16;B<80;B++){let C=Pt[B-15]|0,p=Nt[B-15]|0,K=Ft(C,p,1)^Ft(C,p,8)^xn(C,p,7),T=jt(C,p,1)^jt(C,p,8)^wn(C,p,7),I=Pt[B-2]|0,u=Nt[B-2]|0,w=Ft(I,u,19)^Me(I,u,61)^xn(I,u,6),d=jt(I,u,19)^qe(I,u,61)^wn(I,u,6),y=ts(T,d,Nt[B-7],Nt[B-16]),g=es(y,K,w,Pt[B-7],Pt[B-16]);Pt[B]=g|0,Nt[B]=y|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:h,Dl:f,Eh:l,El:x,Fh:b,Fl:S,Gh:E,Gl:m,Hh:A,Hl:D}=this;for(let B=0;B<80;B++){let C=Ft(l,x,14)^Ft(l,x,18)^Me(l,x,41),p=jt(l,x,14)^jt(l,x,18)^qe(l,x,41),K=l&b^~l&E,T=x&S^~x&m,I=rs(D,p,T,Xa[B],Nt[B]),u=ns(I,A,C,K,$a[B],Pt[B]),w=I|0,d=Ft(n,o,28)^Me(n,o,34)^Me(n,o,39),y=jt(n,o,28)^qe(n,o,34)^qe(n,o,39),g=n&s^n&a^s&a,_=o&i^o&c^i&c;A=E|0,D=m|0,E=b|0,m=S|0,b=l|0,S=x|0,{h:l,l:x}=At(h|0,f|0,u|0,w|0),h=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let v=Jo(w,y,_);n=Qo(v,u,d,g),o=v|0}({h:n,l:o}=At(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=At(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=At(this.Ch|0,this.Cl|0,a|0,c|0),{h,l:f}=At(this.Dh|0,this.Dl|0,h|0,f|0),{h:l,l:x}=At(this.Eh|0,this.El|0,l|0,x|0),{h:b,l:S}=At(this.Fh|0,this.Fl|0,b|0,S|0),{h:E,l:m}=At(this.Gh|0,this.Gl|0,E|0,m|0),{h:A,l:D}=At(this.Hh|0,this.Hl|0,A|0,D|0),this.set(n,o,s,i,a,c,h,f,l,x,b,S,E,m,A,D)}roundClean(){_t(Pt,Nt)}destroy(){_t(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ur=bn(()=>new fr);var ss=bn(()=>new gn);var An=BigInt(0),Sn=BigInt(1);function Dt(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}function Ve(e){let t=e.toString(16);return t.length&1?"0"+t:t}function is(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?An:BigInt("0x"+e)}function be(e){return is(St(e))}function Gt(e){return rt(e),is(St(Uint8Array.from(e).reverse()))}function lr(e,t){return ye(e.toString(16).padStart(t*2,"0"))}function xe(e,t){return lr(e,t).reverse()}function H(e,t,r){let n;if(typeof t=="string")try{n=ye(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(pe(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}var En=e=>typeof e=="bigint"&&An<=e;function as(e,t,r){return En(e)&&En(t)&&En(r)&&t<=e&&e<r}function kt(e,t,r,n){if(!as(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function cs(e){let t;for(t=0;e>An;e>>=Sn,t+=1);return t}var Zt=e=>(Sn<<BigInt(e))-Sn;function fs(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=b=>new Uint8Array(b),o=b=>Uint8Array.of(b),s=n(e),i=n(e),a=0,c=()=>{s.fill(1),i.fill(0),a=0},h=(...b)=>r(i,s,...b),f=(b=n(0))=>{i=h(o(0),b),s=h(),b.length!==0&&(i=h(o(1),b),s=h())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let b=0,S=[];for(;b<t;){s=h();let E=s.slice();S.push(E),b+=s.length}return ht(...S)};return(b,S)=>{c(),f(b);let E;for(;!(E=S(l()));)f();return c(),E}}function Ot(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))}function we(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 it=BigInt(0),X=BigInt(1),Wt=BigInt(2),Ja=BigInt(3),hs=BigInt(4),ds=BigInt(5),ps=BigInt(8);function q(e,t){let r=e%t;return r>=it?r:t+r}function M(e,t,r){let n=e;for(;t-- >it;)n*=n,n%=r;return n}function us(e,t){if(e===it)throw new Error("invert: expected non-zero number");if(t<=it)throw new Error("invert: expected positive modulus, got "+t);let r=q(e,t),n=t,o=it,s=X,i=X,a=it;for(;r!==it;){let h=n/r,f=n%r,l=o-i*h,x=s-a*h;n=r,r=f,o=i,s=a,i=l,a=x}if(n!==X)throw new Error("invert: does not exist");return q(o,t)}function ms(e,t){let r=(e.ORDER+X)/hs,n=e.pow(t,r);if(!e.eql(e.sqr(n),t))throw new Error("Cannot find square root");return n}function Qa(e,t){let r=(e.ORDER-ds)/ps,n=e.mul(t,Wt),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,Wt),o),a=e.mul(s,e.sub(i,e.ONE));if(!e.eql(e.sqr(a),t))throw new Error("Cannot find square root");return a}function tc(e){if(e<BigInt(3))throw new Error("sqrt is not defined for small field");let t=e-X,r=0;for(;t%Wt===it;)t/=Wt,r++;let n=Wt,o=xt(e);for(;ls(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ms;let s=o.pow(n,t),i=(t+X)/Wt;return function(c,h){if(c.is0(h))return h;if(ls(c,h)!==1)throw new Error("Cannot find square root");let f=r,l=c.mul(c.ONE,s),x=c.pow(h,t),b=c.pow(h,i);for(;!c.eql(x,c.ONE);){if(c.is0(x))return c.ZERO;let S=1,E=c.sqr(x);for(;!c.eql(E,c.ONE);)if(S++,E=c.sqr(E),S===f)throw new Error("Cannot find square root");let m=X<<BigInt(f-S-1),A=c.pow(l,m);f=S,l=c.sqr(A),x=c.mul(x,l),b=c.mul(b,A)}return b}}function ec(e){return e%hs===Ja?ms:e%ps===ds?Qa:tc(e)}var ys=(e,t)=>(q(e,t)&X)===X,rc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function vn(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=rc.reduce((n,o)=>(n[o]="function",n),t);return Ot(e,r),e}function nc(e,t,r){if(r<it)throw new Error("invalid exponent, negatives unsupported");if(r===it)return e.ONE;if(r===X)return t;let n=e.ONE,o=t;for(;r>it;)r&X&&(n=e.mul(n,o)),o=e.sqr(o),r>>=X;return n}function ze(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 ls(e,t){let r=(e.ORDER-X)/Wt,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 bs(e,t){t!==void 0&&Ne(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<=it)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=bs(e,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c,h=Object.freeze({ORDER:e,isLE:r,BITS:i,BYTES:a,MASK:Zt(i),ZERO:it,ONE:X,create:f=>q(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return it<=f&&f<e},is0:f=>f===it,isValidNot0:f=>!h.is0(f)&&h.isValid(f),isOdd:f=>(f&X)===X,neg:f=>q(-f,e),eql:(f,l)=>f===l,sqr:f=>q(f*f,e),add:(f,l)=>q(f+l,e),sub:(f,l)=>q(f-l,e),mul:(f,l)=>q(f*l,e),pow:(f,l)=>nc(h,f,l),div:(f,l)=>q(f*us(l,e),e),sqrN:f=>f*f,addN:(f,l)=>f+l,subN:(f,l)=>f-l,mulN:(f,l)=>f*l,inv:f=>us(f,e),sqrt:s||(f=>(c||(c=ec(e)),c(h,f))),toBytes:f=>r?xe(f,a):lr(f,a),fromBytes:f=>{if(f.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);return r?Gt(f):be(f)},invertBatch:f=>ze(h,f),cmov:(f,l,x)=>x?l:f});return Object.freeze(h)}function xs(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 Bn(e){let t=xs(e);return t+Math.ceil(t/2)}function ws(e,t,r=!1){let n=e.length,o=xs(t),s=Bn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Gt(e):be(e),a=q(i,t-X)+X;return r?xe(a,o):lr(a,o)}var Ee=BigInt(0),Yt=BigInt(1);function ge(e,t){let r=t.negate();return e?r:t}function hr(e,t,r){let n=t==="pz"?i=>i.pz:i=>i.ez,o=ze(e.Fp,r.map(n));return r.map((i,a)=>i.toAffine(o[a])).map(e.fromAffine)}function As(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function In(e,t){As(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Zt(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function gs(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+=Yt);let h=t*n,f=h+Math.abs(a)-1,l=a===0,x=a<0,b=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:x,isNegF:b,offsetF:h}}function oc(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 sc(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 _n=new WeakMap,vs=new WeakMap;function Ln(e){return vs.get(e)||1}function Es(e){if(e!==Ee)throw new Error("invalid wNAF")}function dr(e,t){return{constTimeNegate:ge,hasPrecomputes(r){return Ln(r)!==1},unsafeLadder(r,n,o=e.ZERO){let s=r;for(;n>Ee;)n&Yt&&(o=o.add(s)),s=s.double(),n>>=Yt;return o},precomputeWindow(r,n){let{windows:o,windowSize:s}=In(n,t),i=[],a=r,c=a;for(let h=0;h<o;h++){c=a,i.push(c);for(let f=1;f<s;f++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(r,n,o){let s=e.ZERO,i=e.BASE,a=In(r,t);for(let c=0;c<a.windows;c++){let{nextN:h,offset:f,isZero:l,isNeg:x,isNegF:b,offsetF:S}=gs(o,c,a);o=h,l?i=i.add(ge(b,n[S])):s=s.add(ge(x,n[f]))}return Es(o),{p:s,f:i}},wNAFUnsafe(r,n,o,s=e.ZERO){let i=In(r,t);for(let a=0;a<i.windows&&o!==Ee;a++){let{nextN:c,offset:h,isZero:f,isNeg:l}=gs(o,a,i);if(o=c,!f){let x=n[h];s=s.add(l?x.negate():x)}}return Es(o),s},getPrecomputes(r,n,o){let s=_n.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&(typeof o=="function"&&(s=o(s)),_n.set(n,s))),s},wNAFCached(r,n,o){let s=Ln(r);return this.wNAF(s,this.getPrecomputes(s,r,o),n)},wNAFCachedUnsafe(r,n,o,s){let i=Ln(r);return i===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,r,o),n,s)},setWindowSize(r,n){As(n,t),vs.set(r,n),_n.delete(r)}}}function Bs(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Ee||n>Ee;)r&Yt&&(s=s.add(o)),n&Yt&&(i=i.add(o)),o=o.double(),r>>=Yt,n>>=Yt;return{p1:s,p2:i}}function pr(e,t,r,n){oc(r,e),sc(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=cs(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let h=Zt(c),f=new Array(Number(h)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c,x=i;for(let b=l;b>=0;b-=c){f.fill(i);for(let E=0;E<s;E++){let m=n[E],A=Number(m>>BigInt(b)&h);f[A]=f[A].add(r[E])}let S=i;for(let E=f.length-1,m=i;E>0;E--)m=m.add(f[E]),S=S.add(m);if(x=x.add(S),b!==0)for(let E=0;E<c;E++)x=x.double()}return x}function Ss(e,t){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return vn(t),t}else return xt(e)}function mr(e,t,r={}){if(!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>Ee))throw new Error(`CURVE.${a} must be positive bigint`)}let n=Ss(t.p,r.Fp),o=Ss(t.n,r.Fn),i=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var vt=BigInt(0),at=BigInt(1),Dn=BigInt(2),ic=BigInt(8),ac={zip215:!0};function cc(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 fc(e,t={}){let{Fp:r,Fn:n}=mr("edwards",e,t),{h:o,n:s}=e;Ot(t,{},{uvRatio:"function"});let i=Dn<<BigInt(n.BYTES*8)-at,a=E=>r.create(E),c=t.uvRatio||((E,m)=>{try{return{isValid:!0,value:r.sqrt(r.div(E,m))}}catch{return{isValid:!1,value:vt}}});if(!cc(r,e,e.Gx,e.Gy))throw new Error("bad curve params: generator point");function h(E,m,A=!1){let D=A?at:vt;return kt("coordinate "+E,m,D,i),m}function f(E){if(!(E instanceof b))throw new Error("ExtendedPoint expected")}let l=we((E,m)=>{let{ex:A,ey:D,ez:B}=E,C=E.is0();m==null&&(m=C?ic:r.inv(B));let p=a(A*m),K=a(D*m),T=a(B*m);if(C)return{x:vt,y:at};if(T!==at)throw new Error("invZ was invalid");return{x:p,y:K}}),x=we(E=>{let{a:m,d:A}=e;if(E.is0())throw new Error("bad point: ZERO");let{ex:D,ey:B,ez:C,et:p}=E,K=a(D*D),T=a(B*B),I=a(C*C),u=a(I*I),w=a(K*m),d=a(I*a(w+T)),y=a(u+a(A*a(K*T)));if(d!==y)throw new Error("bad point: equation left != right (1)");let g=a(D*B),_=a(C*p);if(g!==_)throw new Error("bad point: equation left != right (2)");return!0});class b{constructor(m,A,D,B){this.ex=h("x",m),this.ey=h("y",A),this.ez=h("z",D,!0),this.et=h("t",B),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(m){if(m instanceof b)throw new Error("extended point not allowed");let{x:A,y:D}=m||{};return h("x",A),h("y",D),new b(A,D,at,a(A*D))}static normalizeZ(m){return hr(b,"ez",m)}static msm(m,A){return pr(b,n,m,A)}_setWindowSize(m){this.precompute(m)}precompute(m=8,A=!0){return S.setWindowSize(this,m),A||this.multiply(Dn),this}assertValidity(){x(this)}equals(m){f(m);let{ex:A,ey:D,ez:B}=this,{ex:C,ey:p,ez:K}=m,T=a(A*K),I=a(C*B),u=a(D*K),w=a(p*B);return T===I&&u===w}is0(){return this.equals(b.ZERO)}negate(){return new b(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:m}=e,{ex:A,ey:D,ez:B}=this,C=a(A*A),p=a(D*D),K=a(Dn*a(B*B)),T=a(m*C),I=A+D,u=a(a(I*I)-C-p),w=T+p,d=w-K,y=T-p,g=a(u*d),_=a(w*y),v=a(u*y),L=a(d*w);return new b(g,_,L,v)}add(m){f(m);let{a:A,d:D}=e,{ex:B,ey:C,ez:p,et:K}=this,{ex:T,ey:I,ez:u,et:w}=m,d=a(B*T),y=a(C*I),g=a(K*D*w),_=a(p*u),v=a((B+C)*(T+I)-d-y),L=_-g,U=_+g,R=a(y-A*d),F=a(v*L),k=a(U*R),P=a(v*R),Z=a(L*U);return new b(F,k,Z,P)}subtract(m){return this.add(m.negate())}multiply(m){let A=m;kt("scalar",A,at,s);let{p:D,f:B}=S.wNAFCached(this,A,b.normalizeZ);return b.normalizeZ([D,B])[0]}multiplyUnsafe(m,A=b.ZERO){let D=m;return kt("scalar",D,vt,s),D===vt?b.ZERO:this.is0()||D===at?this:S.wNAFCachedUnsafe(this,D,b.normalizeZ,A)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return S.wNAFCachedUnsafe(this,s).is0()}toAffine(m){return l(this,m)}clearCofactor(){return o===at?this:this.multiplyUnsafe(o)}static fromBytes(m,A=!1){return rt(m),this.fromHex(m,A)}static fromHex(m,A=!1){let{d:D,a:B}=e,C=r.BYTES;m=H("pointHex",m,C),Dt("zip215",A);let p=m.slice(),K=m[C-1];p[C-1]=K&-129;let T=Gt(p),I=A?i:r.ORDER;kt("pointHex.y",T,vt,I);let u=a(T*T),w=a(u-at),d=a(D*u-B),{isValid:y,value:g}=c(w,d);if(!y)throw new Error("Point.fromHex: invalid y coordinate");let _=(g&at)===at,v=(K&128)!==0;if(!A&&g===vt&&v)throw new Error("Point.fromHex: x=0 and x_0=1");return v!==_&&(g=a(-g)),b.fromAffine({x:g,y:T})}static fromPrivateScalar(m){return b.BASE.multiply(m)}toBytes(){let{x:m,y:A}=this.toAffine(),D=xe(A,r.BYTES);return D[D.length-1]|=m&at?128:0,D}toRawBytes(){return this.toBytes()}toHex(){return St(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}b.BASE=new b(e.Gx,e.Gy,at,a(e.Gx*e.Gy)),b.ZERO=new b(vt,at,at,vt),b.Fp=r,b.Fn=n;let S=dr(b,n.BYTES*8);return b}function uc(e,t){Ot(t,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:r,hash:n}=t,{BASE:o,Fp:s,Fn:i}=e,a=i.ORDER,c=t.randomBytes||Oe,h=t.adjustScalarBytes||(p=>p),f=t.domain||((p,K,T)=>{if(Dt("phflag",T),K.length||T)throw new Error("Contexts/pre-hash are not supported");return p});function l(p){return i.create(p)}function x(p){return l(Gt(p))}function b(p){let K=s.BYTES;p=H("private key",p,K);let T=H("hashed private key",n(p),2*K),I=h(T.slice(0,K)),u=T.slice(K,2*K),w=x(I);return{head:I,prefix:u,scalar:w}}function S(p){let{head:K,prefix:T,scalar:I}=b(p),u=o.multiply(I),w=u.toBytes();return{head:K,prefix:T,scalar:I,point:u,pointBytes:w}}function E(p){return S(p).pointBytes}function m(p=Uint8Array.of(),...K){let T=ht(...K);return x(n(f(T,H("context",p),!!r)))}function A(p,K,T={}){p=H("message",p),r&&(p=r(p));let{prefix:I,scalar:u,pointBytes:w}=S(K),d=m(T.context,I,p),y=o.multiply(d).toBytes(),g=m(T.context,y,w,p),_=l(d+g*u);kt("signature.s",_,vt,a);let v=s.BYTES,L=ht(y,xe(_,v));return H("result",L,v*2)}let D=ac;function B(p,K,T,I=D){let{context:u,zip215:w}=I,d=s.BYTES;p=H("signature",p,2*d),K=H("message",K),T=H("publicKey",T,d),w!==void 0&&Dt("zip215",w),r&&(K=r(K));let y=Gt(p.slice(d,2*d)),g,_,v;try{g=e.fromHex(T,w),_=e.fromHex(p.slice(0,d),w),v=o.multiplyUnsafe(y)}catch{return!1}if(!w&&g.isSmallOrder())return!1;let L=m(u,_.toBytes(),g.toBytes(),K);return _.add(g.multiplyUnsafe(L)).subtract(v).clearCofactor().is0()}return o.precompute(8),{getPublicKey:E,sign:A,verify:B,utils:{getExtendedPublicKey:S,randomPrivateKey:()=>c(s.BYTES),precompute(p=8,K=e.BASE){return K.precompute(p,!1)}},Point:e}}function lc(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={hash:e.hash,randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,eddsaOpts:s}}function hc(e,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:e})}function Is(e){let{CURVE:t,curveOpts:r,eddsaOpts:n}=lc(e),o=fc(t,r),s=uc(o,n);return hc(e,s)}var Cl=BigInt(0),dc=BigInt(1),_s=BigInt(2),Rl=BigInt(3),pc=BigInt(5),mc=BigInt(8),yr={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:mc,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function yc(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=yr.p,a=e*e%s*e%s,c=M(a,_s,s)*a%s,h=M(c,dc,s)*e%s,f=M(h,pc,s)*h%s,l=M(f,t,s)*f%s,x=M(l,r,s)*l%s,b=M(x,n,s)*x%s,S=M(b,o,s)*b%s,E=M(S,o,s)*b%s,m=M(E,t,s)*f%s;return{pow_p_5_8:M(m,_s,s)*e%s,b2:a}}function bc(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ls=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function xc(e,t){let r=yr.p,n=q(t*t*t,r),o=q(n*n*t,r),s=yc(e*o).pow_p_5_8,i=q(e*n*s,r),a=q(t*i*i,r),c=i,h=q(i*Ls,r),f=a===e,l=a===q(-e,r),x=a===q(-e*Ls,r);return f&&(i=c),(l||x)&&(i=h),ys(i,r)&&(i=q(-i,r)),{isValid:f||l,value:i}}var wc=xt(yr.p,void 0,!0),gc={...yr,Fp:wc,hash:ss,adjustScalarBytes:bc,uvRatio:xc},Ds=Is(gc);var Fe=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},br=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Ts={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new br("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 pt=Ts;var Se=32;var Tn,Ec=(async()=>{try{return await pt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Sc(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await pt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await pt.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 Ac(e,t,r){return Ds.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Ks(e,t,r){return Tn==null&&(Tn=await Ec),Tn?Sc(e,t,r):Ac(e,t,r)}function xr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var wr=class{type="Ed25519";raw;constructor(t){this.raw=Kn(t,Se)}toMultihash(){return gt.digest(he(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:et(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Ks(this.raw,r,t);return xr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Us(e){return e=Kn(e,Se),new wr(e)}function Kn(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new W(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var vc=Math.pow(2,7),Bc=Math.pow(2,14),Ic=Math.pow(2,21),Cn=Math.pow(2,28),Rn=Math.pow(2,35),Un=Math.pow(2,42),Pn=Math.pow(2,49),N=128,nt=127;function Tt(e){if(e<vc)return 1;if(e<Bc)return 2;if(e<Ic)return 3;if(e<Cn)return 4;if(e<Rn)return 5;if(e<Un)return 6;if(e<Pn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Nn(e,t,r=0){switch(Tt(e)){case 8:t[r++]=e&255|N,e/=128;case 7:t[r++]=e&255|N,e/=128;case 6:t[r++]=e&255|N,e/=128;case 5:t[r++]=e&255|N,e/=128;case 4:t[r++]=e&255|N,e>>>=7;case 3:t[r++]=e&255|N,e>>>=7;case 2:t[r++]=e&255|N,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function _c(e,t,r=0){switch(Tt(e)){case 8:t.set(r++,e&255|N),e/=128;case 7:t.set(r++,e&255|N),e/=128;case 6:t.set(r++,e&255|N),e/=128;case 5:t.set(r++,e&255|N),e/=128;case 4:t.set(r++,e&255|N),e>>>=7;case 3:t.set(r++,e&255|N),e>>>=7;case 2:t.set(r++,e&255|N),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function kn(e,t){let r=e[t],n=0;if(n+=r&nt,r<N||(r=e[t+1],n+=(r&nt)<<7,r<N)||(r=e[t+2],n+=(r&nt)<<14,r<N)||(r=e[t+3],n+=(r&nt)<<21,r<N)||(r=e[t+4],n+=(r&nt)*Cn,r<N)||(r=e[t+5],n+=(r&nt)*Rn,r<N)||(r=e[t+6],n+=(r&nt)*Un,r<N)||(r=e[t+7],n+=(r&nt)*Pn,r<N))return n;throw new RangeError("Could not decode varint")}function Lc(e,t){let r=e.get(t),n=0;if(n+=r&nt,r<N||(r=e.get(t+1),n+=(r&nt)<<7,r<N)||(r=e.get(t+2),n+=(r&nt)<<14,r<N)||(r=e.get(t+3),n+=(r&nt)<<21,r<N)||(r=e.get(t+4),n+=(r&nt)*Cn,r<N)||(r=e.get(t+5),n+=(r&nt)*Rn,r<N)||(r=e.get(t+6),n+=(r&nt)*Un,r<N)||(r=e.get(t+7),n+=(r&nt)*Pn,r<N))return n;throw new RangeError("Could not decode varint")}function Ps(e,t,r=0){return t==null&&(t=ft(Tt(e))),t instanceof Uint8Array?Nn(e,t,r):_c(e,t,r)}function Ns(e,t=0){return e instanceof Uint8Array?kn(e,t):Lc(e,t)}var On=new Float32Array([-0]),Ht=new Uint8Array(On.buffer);function ks(e,t,r){On[0]=e,t[r]=Ht[0],t[r+1]=Ht[1],t[r+2]=Ht[2],t[r+3]=Ht[3]}function Os(e,t){return Ht[0]=e[t],Ht[1]=e[t+1],Ht[2]=e[t+2],Ht[3]=e[t+3],On[0]}var Hn=new Float64Array([-0]),ot=new Uint8Array(Hn.buffer);function Hs(e,t,r){Hn[0]=e,t[r]=ot[0],t[r+1]=ot[1],t[r+2]=ot[2],t[r+3]=ot[3],t[r+4]=ot[4],t[r+5]=ot[5],t[r+6]=ot[6],t[r+7]=ot[7]}function Ms(e,t){return ot[0]=e[t],ot[1]=e[t+1],ot[2]=e[t+2],ot[3]=e[t+3],ot[4]=e[t+4],ot[5]=e[t+5],ot[6]=e[t+6],ot[7]=e[t+7],Hn[0]}var Tc=BigInt(Number.MAX_SAFE_INTEGER),Kc=BigInt(Number.MIN_SAFE_INTEGER),dt=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 $t;if(t<Tc&&t>Kc)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>qs&&(o=0n,++n>qs&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return $t;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):$t}},$t=new dt(0,0);$t.toBigInt=function(){return 0n};$t.zzEncode=$t.zzDecode=function(){return this};$t.length=function(){return 1};var qs=4294967296n;function Vs(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 zs(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 Mn(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 wt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function gr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var qn=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,wt(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 wt(this,4);return gr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw wt(this,4);return gr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw wt(this,4);let t=Os(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw wt(this,4);let t=Ms(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 wt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return zs(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw wt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw wt(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 dt(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 wt(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 wt(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 wt(this,8);let t=gr(this.buf,this.pos+=4),r=gr(this.buf,this.pos+=4);return new dt(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=kn(this.buf,this.pos);return this.pos+=Tt(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 Vn(e){return new qn(e instanceof Uint8Array?e:e.subarray())}function Xt(e,t,r){let n=Vn(e);return t.decode(n,void 0,r)}function zn(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return ft(i);o+i>t&&(n=ft(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Jt=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Fn(){}var Gn=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Cc=zn();function Rc(e){return globalThis.Buffer!=null?ft(e):Cc(e)}var Ge=class{len;head;tail;states;constructor(){this.len=0,this.head=new Jt(Fn,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Jt(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Zn((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(Er,10,dt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=dt.fromBigInt(t);return this._push(Er,r.length(),r)}uint64Number(t){return this._push(Nn,Tt(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=dt.fromBigInt(t).zzEncode();return this._push(Er,r.length(),r)}sint64Number(t){let r=dt.fromNumber(t).zzEncode();return this._push(Er,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(jn,1,t?1:0)}fixed32(t){return this._push(je,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=dt.fromBigInt(t);return this._push(je,4,r.lo)._push(je,4,r.hi)}fixed64Number(t){let r=dt.fromNumber(t);return this._push(je,4,r.lo)._push(je,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(ks,4,t)}double(t){return this._push(Hs,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(jn,1,0):this.uint32(r)._push(Pc,r,t)}string(t){let r=Vs(t);return r!==0?this.uint32(r)._push(Mn,r,t):this._push(jn,1,0)}fork(){return this.states=new Gn(this),this.head=this.tail=new Jt(Fn,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 Jt(Fn,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=Rc(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function jn(e,t,r){t[r]=e&255}function Uc(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Zn=class extends Jt{next;constructor(t,r){super(Uc,t,r),this.next=void 0}};function Er(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 je(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 Pc(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Ge.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Nc,t,e),this},Ge.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(kc,t,e),this});function Nc(e,t,r){t.set(e,r)}function kc(e,t,r){e.length<40?Mn(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(G(e),r)}function Wn(){return new Ge}function Qt(e,t){let r=Wn();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Ae;(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"})(Ae||(Ae={}));function Sr(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Ze(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 Sr("enum",Ae.VARINT,r,n)}function te(e,t){return Sr("message",Ae.LENGTH_DELIMITED,e,t)}var lt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(lt||(lt={}));var Yn;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Yn||(Yn={}));(function(e){e.codec=()=>Ze(Yn)})(lt||(lt={}));var Mt;(function(e){let t;e.codec=()=>(t==null&&(t=te((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),lt.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=lt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Qt(r,e.codec()),e.decode=(r,n)=>Xt(r,e.codec(),n)})(Mt||(Mt={}));var $n;(function(e){let t;e.codec=()=>(t==null&&(t=te((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),lt.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=lt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Qt(r,e.codec()),e.decode=(r,n)=>Xt(r,e.codec(),n)})($n||($n={}));var Ye={};ct(Ye,{MAX_RSA_KEY_SIZE:()=>Xn,generateRSAKeyPair:()=>$s,jwkToJWKKeyPair:()=>Xs,jwkToPkcs1:()=>qc,jwkToPkix:()=>eo,jwkToRSAPrivateKey:()=>no,pkcs1MessageToJwk:()=>Qn,pkcs1MessageToRSAPrivateKey:()=>ro,pkcs1ToJwk:()=>Mc,pkcs1ToRSAPrivateKey:()=>Ws,pkixMessageToJwk:()=>to,pkixMessageToRSAPublicKey:()=>vr,pkixToJwk:()=>Vc,pkixToRSAPublicKey:()=>Ys});var Ar=ur;var ve=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Ye.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return tt.createV1(114,this._multihash)}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:et(this.raw,t.raw)}verify(t,r,n){return Zs(this.jwk,r,t,n)}},We=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Ye.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:et(this.raw,t.raw)}sign(t,r){return Gs(this.jwk,t,r)}};var Xn=8192,Jn=18,Oc=1062,Hc=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Mc(e){let t=Et(e);return Qn(t)}function Qn(e){return{n:z(e[1],"base64url"),e:z(e[2],"base64url"),d:z(e[3],"base64url"),p:z(e[4],"base64url"),q:z(e[5],"base64url"),dp:z(e[6],"base64url"),dq:z(e[7],"base64url"),qi:z(e[8],"base64url"),kty:"RSA"}}function qc(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 W("JWK was missing components");return Rt([ut(Uint8Array.from([0])),ut(G(e.n,"base64url")),ut(G(e.e,"base64url")),ut(G(e.d,"base64url")),ut(G(e.p,"base64url")),ut(G(e.q,"base64url")),ut(G(e.dp,"base64url")),ut(G(e.dq,"base64url")),ut(G(e.qi,"base64url"))]).subarray()}function Vc(e){let t=Et(e,{offset:0});return to(t)}function to(e){let t=Et(e[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function eo(e){if(e.n==null||e.e==null)throw new W("JWK was missing components");return Rt([Hc,ir(Rt([ut(G(e.n,"base64url")),ut(G(e.e,"base64url"))]))]).subarray()}function Ws(e){let t=Et(e);return ro(t)}function ro(e){let t=Qn(e);return no(t)}function Ys(e,t){if(e.byteLength>=Oc)throw new ne("Key size is too large");let r=Et(e,{offset:0});return vr(r,e,t)}function vr(e,t,r){let n=to(e);if(r==null){let o=Ar(Mt.encode({Type:lt.RSA,Data:t}));r=mt(Jn,o)}return new ve(n,r)}function no(e){if(Qs(e)>Xn)throw new W("Key size is too large");let t=Xs(e),r=Ar(Mt.encode({Type:lt.RSA,Data:eo(t.publicKey)})),n=mt(Jn,r);return new We(t.privateKey,new ve(t.publicKey,n))}async function $s(e){if(e>Xn)throw new W("Key size is too large");let t=await Js(e),r=Ar(Mt.encode({Type:lt.RSA,Data:eo(t.publicKey)})),n=mt(Jn,r);return new We(t.privateKey,new ve(t.publicKey,n))}function Xs(e){if(e==null)throw new W("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var ti="1.2.840.113549.1.1.1";async function Js(e,t){let r=await pt.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 zc(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Gs(e,t,r){let n=await pt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await pt.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 Zs(e,t,r,n){let o=await pt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await pt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function zc(e,t){if(e.privateKey==null||e.publicKey==null)throw new W("Private and public key are required");let r=await Promise.all([pt.get().subtle.exportKey("jwk",e.privateKey),pt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Qs(e){if(e.kty!=="RSA")throw new W("invalid key type");if(e.n==null)throw new W("invalid key modulus");return G(e.n,"base64url").length*8}var Br=class extends de{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Fo(t);let n=ke(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),_t(s)}update(t){return me(this),this.iHash.update(t),this}digestInto(t){me(this),rt(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()}},oo=(e,t,r)=>new Br(e,t).update(r).digest();oo.create=(e,t)=>new Br(e,t);function ei(e){e.lowS!==void 0&&Dt("lowS",e.lowS),e.prehash!==void 0&&Dt("prehash",e.prehash)}var so=class extends Error{constructor(t=""){super(t)}},Kt={Err:so,_tlv:{encode:(e,t)=>{let{Err:r}=Kt;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=Ve(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Ve(o.length/2|128):"";return Ve(e)+s+o+t},decode(e,t){let{Err:r}=Kt,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 h=t.subarray(n,n+c);if(h.length!==c)throw new r("tlv.decode: length bytes not complete");if(h[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of h)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Kt;if(e<$e)throw new t("integer: negative integers are not allowed");let r=Ve(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}=Kt;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 be(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Kt,o=H("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:h,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(h)}},hexFromSig(e){let{_tlv:t,_int:r}=Kt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},$e=BigInt(0),Xe=BigInt(1),Fc=BigInt(2),Ir=BigInt(3),jc=BigInt(4);function Gc(e,t,r){function n(o){let s=e.sqr(o),i=e.mul(s,o);return e.add(e.add(i,e.mul(o,t)),r)}return n}function ri(e,t,r){let{BYTES:n}=e;function o(s){let i;if(typeof s=="bigint")i=s;else{let a=H("private key",s);if(t){if(!t.includes(a.length*2))throw new Error("invalid private key");let c=new Uint8Array(n);c.set(a,c.length-a.length),a=c}try{i=e.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof s}`)}}if(r&&(i=e.create(i)),!e.isValidNot0(i))throw new Error("invalid private key: out of range [1..N-1]");return i}return o}function Zc(e,t={}){let{Fp:r,Fn:n}=mr("weierstrass",e,t),{h:o,n:s}=e;Ot(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!r.is0(e.a)||typeof i.beta!="bigint"||typeof i.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(I,u,w){let{x:d,y}=u.toAffine(),g=r.toBytes(d);if(Dt("isCompressed",w),w){a();let _=!r.isOdd(y);return ht(ni(_),g)}else return ht(Uint8Array.of(4),g,r.toBytes(y))}function h(I){rt(I);let u=r.BYTES,w=u+1,d=2*u+1,y=I.length,g=I[0],_=I.subarray(1);if(y===w&&(g===2||g===3)){let v=r.fromBytes(_);if(!r.isValid(v))throw new Error("bad point: is not on curve, wrong x");let L=x(v),U;try{U=r.sqrt(L)}catch(k){let P=k instanceof Error?": "+k.message:"";throw new Error("bad point: is not on curve, sqrt error"+P)}a();let R=r.isOdd(U);return(g&1)===1!==R&&(U=r.neg(U)),{x:v,y:U}}else if(y===d&&g===4){let v=r.fromBytes(_.subarray(u*0,u*1)),L=r.fromBytes(_.subarray(u*1,u*2));if(!b(v,L))throw new Error("bad point: is not on curve");return{x:v,y:L}}else throw new Error(`bad point: got length ${y}, expected compressed=${w} or uncompressed=${d}`)}let f=t.toBytes||c,l=t.fromBytes||h,x=Gc(r,e.a,e.b);function b(I,u){let w=r.sqr(u),d=x(I);return r.eql(w,d)}if(!b(e.Gx,e.Gy))throw new Error("bad curve params: generator point");let S=r.mul(r.pow(e.a,Ir),jc),E=r.mul(r.sqr(e.b),BigInt(27));if(r.is0(r.add(S,E)))throw new Error("bad curve params: a or b");function m(I,u,w=!1){if(!r.isValid(u)||w&&r.is0(u))throw new Error(`bad point coordinate ${I}`);return u}function A(I){if(!(I instanceof p))throw new Error("ProjectivePoint expected")}let D=we((I,u)=>{let{px:w,py:d,pz:y}=I;if(r.eql(y,r.ONE))return{x:w,y:d};let g=I.is0();u==null&&(u=g?r.ONE:r.inv(y));let _=r.mul(w,u),v=r.mul(d,u),L=r.mul(y,u);if(g)return{x:r.ZERO,y:r.ZERO};if(!r.eql(L,r.ONE))throw new Error("invZ was invalid");return{x:_,y:v}}),B=we(I=>{if(I.is0()){if(t.allowInfinityPoint&&!r.is0(I.py))return;throw new Error("bad point: ZERO")}let{x:u,y:w}=I.toAffine();if(!r.isValid(u)||!r.isValid(w))throw new Error("bad point: x or y not field elements");if(!b(u,w))throw new Error("bad point: equation left != right");if(!I.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function C(I,u,w,d,y){return w=new p(r.mul(w.px,I),w.py,w.pz),u=ge(d,u),w=ge(y,w),u.add(w)}class p{constructor(u,w,d){this.px=m("x",u),this.py=m("y",w,!0),this.pz=m("z",d),Object.freeze(this)}static fromAffine(u){let{x:w,y:d}=u||{};if(!u||!r.isValid(w)||!r.isValid(d))throw new Error("invalid affine point");if(u instanceof p)throw new Error("projective point not allowed");return r.is0(w)&&r.is0(d)?p.ZERO:new p(w,d,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(u){return hr(p,"pz",u)}static fromBytes(u){return rt(u),p.fromHex(u)}static fromHex(u){let w=p.fromAffine(l(H("pointHex",u)));return w.assertValidity(),w}static fromPrivateKey(u){let w=ri(n,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return p.BASE.multiply(w(u))}static msm(u,w){return pr(p,n,u,w)}precompute(u=8,w=!0){return T.setWindowSize(this,u),w||this.multiply(Ir),this}_setWindowSize(u){this.precompute(u)}assertValidity(){B(this)}hasEvenY(){let{y:u}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(u)}equals(u){A(u);let{px:w,py:d,pz:y}=this,{px:g,py:_,pz:v}=u,L=r.eql(r.mul(w,v),r.mul(g,y)),U=r.eql(r.mul(d,v),r.mul(_,y));return L&&U}negate(){return new p(this.px,r.neg(this.py),this.pz)}double(){let{a:u,b:w}=e,d=r.mul(w,Ir),{px:y,py:g,pz:_}=this,v=r.ZERO,L=r.ZERO,U=r.ZERO,R=r.mul(y,y),F=r.mul(g,g),k=r.mul(_,_),P=r.mul(y,g);return P=r.add(P,P),U=r.mul(y,_),U=r.add(U,U),v=r.mul(u,U),L=r.mul(d,k),L=r.add(v,L),v=r.sub(F,L),L=r.add(F,L),L=r.mul(v,L),v=r.mul(P,v),U=r.mul(d,U),k=r.mul(u,k),P=r.sub(R,k),P=r.mul(u,P),P=r.add(P,U),U=r.add(R,R),R=r.add(U,R),R=r.add(R,k),R=r.mul(R,P),L=r.add(L,R),k=r.mul(g,_),k=r.add(k,k),R=r.mul(k,P),v=r.sub(v,R),U=r.mul(k,F),U=r.add(U,U),U=r.add(U,U),new p(v,L,U)}add(u){A(u);let{px:w,py:d,pz:y}=this,{px:g,py:_,pz:v}=u,L=r.ZERO,U=r.ZERO,R=r.ZERO,F=e.a,k=r.mul(e.b,Ir),P=r.mul(w,g),Z=r.mul(d,_),$=r.mul(y,v),Q=r.add(w,d),O=r.add(g,_);Q=r.mul(Q,O),O=r.add(P,Z),Q=r.sub(Q,O),O=r.add(w,y);let st=r.add(g,v);return O=r.mul(O,st),st=r.add(P,$),O=r.sub(O,st),st=r.add(d,y),L=r.add(_,v),st=r.mul(st,L),L=r.add(Z,$),st=r.sub(st,L),R=r.mul(F,O),L=r.mul(k,$),R=r.add(L,R),L=r.sub(Z,R),R=r.add(Z,R),U=r.mul(L,R),Z=r.add(P,P),Z=r.add(Z,P),$=r.mul(F,$),O=r.mul(k,O),Z=r.add(Z,$),$=r.sub(P,$),$=r.mul(F,$),O=r.add(O,$),P=r.mul(Z,O),U=r.add(U,P),P=r.mul(st,O),L=r.mul(Q,L),L=r.sub(L,P),P=r.mul(Q,Z),R=r.mul(st,R),R=r.add(R,P),new p(L,U,R)}subtract(u){return this.add(u.negate())}is0(){return this.equals(p.ZERO)}multiply(u){let{endo:w}=t;if(!n.isValidNot0(u))throw new Error("invalid scalar: out of range");let d,y,g=_=>T.wNAFCached(this,_,p.normalizeZ);if(w){let{k1neg:_,k1:v,k2neg:L,k2:U}=w.splitScalar(u),{p:R,f:F}=g(v),{p:k,f:P}=g(U);y=F.add(P),d=C(w.beta,R,k,_,L)}else{let{p:_,f:v}=g(u);d=_,y=v}return p.normalizeZ([d,y])[0]}multiplyUnsafe(u){let{endo:w}=t,d=this;if(!n.isValid(u))throw new Error("invalid scalar: out of range");if(u===$e||d.is0())return p.ZERO;if(u===Xe)return d;if(T.hasPrecomputes(this))return this.multiply(u);if(w){let{k1neg:y,k1:g,k2neg:_,k2:v}=w.splitScalar(u),{p1:L,p2:U}=Bs(p,d,g,v);return C(w.beta,L,U,y,_)}else return T.wNAFCachedUnsafe(d,u)}multiplyAndAddUnsafe(u,w,d){let y=this.multiplyUnsafe(w).add(u.multiplyUnsafe(d));return y.is0()?void 0:y}toAffine(u){return D(this,u)}isTorsionFree(){let{isTorsionFree:u}=t;return o===Xe?!0:u?u(p,this):T.wNAFCachedUnsafe(this,s).is0()}clearCofactor(){let{clearCofactor:u}=t;return o===Xe?this:u?u(p,this):this.multiplyUnsafe(o)}toBytes(u=!0){return Dt("isCompressed",u),this.assertValidity(),f(p,this,u)}toRawBytes(u=!0){return this.toBytes(u)}toHex(u=!0){return St(this.toBytes(u))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}p.BASE=new p(e.Gx,e.Gy,r.ONE),p.ZERO=new p(r.ZERO,r.ONE,r.ZERO),p.Fp=r,p.Fn=n;let K=n.BITS,T=dr(p,t.endo?Math.ceil(K/2):K);return p}function ni(e){return Uint8Array.of(e?2:3)}function Wc(e,t,r={}){Ot(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||Oe,o=t.hmac||((d,...y)=>oo(t.hash,d,ht(...y))),{Fp:s,Fn:i}=e,{ORDER:a,BITS:c}=i;function h(d){let y=a>>Xe;return d>y}function f(d){return h(d)?i.neg(d):d}function l(d,y){if(!i.isValidNot0(y))throw new Error(`invalid signature ${d}: out of range 1..CURVE.n`)}class x{constructor(y,g,_){l("r",y),l("s",g),this.r=y,this.s=g,_!=null&&(this.recovery=_),Object.freeze(this)}static fromCompact(y){let g=i.BYTES,_=H("compactSignature",y,g*2);return new x(i.fromBytes(_.subarray(0,g)),i.fromBytes(_.subarray(g,g*2)))}static fromDER(y){let{r:g,s:_}=Kt.toSig(H("DER",y));return new x(g,_)}assertValidity(){}addRecoveryBit(y){return new x(this.r,this.s,y)}recoverPublicKey(y){let g=s.ORDER,{r:_,s:v,recovery:L}=this;if(L==null||![0,1,2,3].includes(L))throw new Error("recovery id invalid");if(a*Fc<g&&L>1)throw new Error("recovery id is ambiguous for h>1 curve");let R=L===2||L===3?_+a:_;if(!s.isValid(R))throw new Error("recovery id 2 or 3 invalid");let F=s.toBytes(R),k=e.fromHex(ht(ni((L&1)===0),F)),P=i.inv(R),Z=B(H("msgHash",y)),$=i.create(-Z*P),Q=i.create(v*P),O=e.BASE.multiplyUnsafe($).add(k.multiplyUnsafe(Q));if(O.is0())throw new Error("point at infinify");return O.assertValidity(),O}hasHighS(){return h(this.s)}normalizeS(){return this.hasHighS()?new x(this.r,i.neg(this.s),this.recovery):this}toBytes(y){if(y==="compact")return ht(i.toBytes(this.r),i.toBytes(this.s));if(y==="der")return ye(Kt.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return St(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return St(this.toBytes("compact"))}}let b=ri(i,r.allowedPrivateKeyLengths,r.wrapPrivateKey),S={isValidPrivateKey(d){try{return b(d),!0}catch{return!1}},normPrivateKeyToScalar:b,randomPrivateKey:()=>{let d=a;return ws(n(Bn(d)),d)},precompute(d=8,y=e.BASE){return y.precompute(d,!1)}};function E(d,y=!0){return e.fromPrivateKey(d).toBytes(y)}function m(d){if(typeof d=="bigint")return!1;if(d instanceof e)return!0;let g=H("key",d).length,_=s.BYTES,v=_+1,L=2*_+1;if(!(r.allowedPrivateKeyLengths||i.BYTES===v))return g===v||g===L}function A(d,y,g=!0){if(m(d)===!0)throw new Error("first arg must be private key");if(m(y)===!1)throw new Error("second arg must be public key");return e.fromHex(y).multiply(b(d)).toBytes(g)}let D=t.bits2int||function(d){if(d.length>8192)throw new Error("input is too large");let y=be(d),g=d.length*8-c;return g>0?y>>BigInt(g):y},B=t.bits2int_modN||function(d){return i.create(D(d))},C=Zt(c);function p(d){return kt("num < 2^"+c,d,$e,C),i.toBytes(d)}function K(d,y,g=T){if(["recovered","canonical"].some(Q=>Q in g))throw new Error("sign() legacy options not supported");let{hash:_}=t,{lowS:v,prehash:L,extraEntropy:U}=g;v==null&&(v=!0),d=H("msgHash",d),ei(g),L&&(d=H("prehashed msgHash",_(d)));let R=B(d),F=b(y),k=[p(F),p(R)];if(U!=null&&U!==!1){let Q=U===!0?n(s.BYTES):U;k.push(H("extraEntropy",Q))}let P=ht(...k),Z=R;function $(Q){let O=D(Q);if(!i.isValidNot0(O))return;let st=i.inv(O),_e=e.BASE.multiply(O).toAffine(),ee=i.create(_e.x);if(ee===$e)return;let Vt=i.create(st*i.create(Z+ee*F));if(Vt===$e)return;let Hr=(_e.x===ee?0:2)|Number(_e.y&Xe),re=Vt;return v&&h(Vt)&&(re=f(Vt),Hr^=1),new x(ee,re,Hr)}return{seed:P,k2sig:$}}let T={lowS:t.lowS,prehash:!1},I={lowS:t.lowS,prehash:!1};function u(d,y,g=T){let{seed:_,k2sig:v}=K(d,y,g);return fs(t.hash.outputLen,i.BYTES,o)(_,v)}e.BASE.precompute(8);function w(d,y,g,_=I){let v=d;y=H("msgHash",y),g=H("publicKey",g),ei(_);let{lowS:L,prehash:U,format:R}=_;if("strict"in _)throw new Error("options.strict was renamed to lowS");if(R!==void 0&&!["compact","der","js"].includes(R))throw new Error('format must be "compact", "der" or "js"');let F=typeof v=="string"||pe(v),k=!F&&!R&&typeof v=="object"&&v!==null&&typeof v.r=="bigint"&&typeof v.s=="bigint";if(!F&&!k)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let P,Z;try{if(k)if(R===void 0||R==="js")P=new x(v.r,v.s);else throw new Error("invalid format");if(F){try{R!=="compact"&&(P=x.fromDER(v))}catch(re){if(!(re instanceof Kt.Err))throw re}!P&&R!=="der"&&(P=x.fromCompact(v))}Z=e.fromHex(g)}catch{return!1}if(!P||L&&P.hasHighS())return!1;U&&(y=t.hash(y));let{r:$,s:Q}=P,O=B(y),st=i.inv(Q),_e=i.create(O*st),ee=i.create($*st),Vt=e.BASE.multiplyUnsafe(_e).add(Z.multiplyUnsafe(ee));return Vt.is0()?!1:i.create(Vt.x)===$}return Object.freeze({getPublicKey:E,getSharedSecret:A,sign:u,verify:w,utils:S,Point:e,Signature:x})}function Yc(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=xt(t.n,e.nBitLength),o={Fp:r,Fn:n,allowedPrivateKeyLengths:e.allowedPrivateKeyLengths,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,wrapPrivateKey:e.wrapPrivateKey,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:o}}function $c(e){let{CURVE:t,curveOpts:r}=Yc(e),n={hash:e.hash,hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,ecdsaOpts:n}}function Xc(e,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:e})}function oi(e){let{CURVE:t,curveOpts:r,ecdsaOpts:n}=$c(e),o=Zc(t,r),s=Wc(o,n,r);return Xc(e,s)}function si(e,t){let r=n=>oi({...e,hash:n});return{...r(t),create:r}}var _r={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},wd=BigInt(0),Jc=BigInt(1),io=BigInt(2),ii=(e,t)=>(e+t/io)/t;function Qc(e){let t=_r.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),h=e*e*e%t,f=h*h*e%t,l=M(f,r,t)*f%t,x=M(l,r,t)*f%t,b=M(x,io,t)*h%t,S=M(b,o,t)*b%t,E=M(S,s,t)*S%t,m=M(E,a,t)*E%t,A=M(m,c,t)*m%t,D=M(A,a,t)*E%t,B=M(D,r,t)*f%t,C=M(B,i,t)*S%t,p=M(C,n,t)*h%t,K=M(p,io,t);if(!ao.eql(ao.sqr(K),e))throw new Error("Cannot find square root");return K}var ao=xt(_r.p,void 0,void 0,{sqrt:Qc}),Be=si({..._r,Fp:ao,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{let t=_r.n,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Jc*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,i=BigInt("0x100000000000000000000000000000000"),a=ii(s*e,t),c=ii(-n*e,t),h=q(e-a*r-c*o,t),f=q(-a*n-c*s,t),l=h>i,x=f>i;if(l&&(h=t-h),x&&(f=t-f),h>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:l,k1:h,k2neg:x,k2:f}}}},ur);var ai=33;function ci(e,t,r,n){let o=or.digest(r instanceof Uint8Array?r:r.subarray());if(xr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Be.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new Fe(String(s))});try{return n?.signal?.throwIfAborted(),Be.verify(t,o.digest,e)}catch(s){throw new Fe(String(s))}}var Lr=class{type="secp256k1";raw;_key;constructor(t){this._key=ui(t),this.raw=fi(this._key)}toMultihash(){return gt.digest(he(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:et(this.raw,t.raw)}verify(t,r,n){return ci(this._key,r,t,n)}};function li(e){return new Lr(e)}function fi(e){return Be.ProjectivePoint.fromHex(e).toRawBytes(!0)}function ui(e){try{return Be.ProjectivePoint.fromHex(e),e}catch(t){throw new ne(String(t))}}function hi(e){if(e.byteLength===Se)return Us(e);if(e.byteLength===ai)return li(e);let t=Et(e),r=t[1]?.[0];if(r===ko||r===Oo||r===Ho)return qo(t);if(t[0]?.[0]===ti)return vr(t,e);throw new W("Could not extract public key from raw bytes")}function he(e){return Mt.encode({Type:lt[e.type],Data:e.raw})}var di=Symbol.for("nodejs.util.inspect.custom"),tf=114,Je=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()})`}[qr]=!0;toString(){return this.string==null&&(this.string=j.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return tt.createV1(tf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return et(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return et(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[di](){return`PeerId(${this.toString()})`}},Dr=class extends Je{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Tr=class extends Je{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Kr=class extends Je{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},ef=2336,co=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=gt.digest(G(this.url))}[di](){return`PeerId(${this.url})`}[qr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return tt.createV1(ef,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};function pi(e){if(e.type==="Ed25519")return new Tr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Kr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Dr({multihash:e.toCID().multihash,publicKey:e});throw new De}function Ie(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Cr=class extends Error{type;code;constructor(t,r,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=r??"ABORT_ERR"}};async function Qe(e,t,r){if(t==null)return e;if(t.aborted)return e.catch(()=>{}),Promise.reject(new Cr(r?.errorMessage,r?.errorCode,r?.errorName));let n,o=new Cr(r?.errorMessage,r?.errorCode,r?.errorName);try{return await Promise.race([e,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var fo=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Ie(),this.haveNext=Ie()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Ie(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,r){await this._push(t,r)}async end(t,r){t!=null?await this.throw(t):await this._push(void 0,r)}async _push(t,r){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Ie(),await Qe(this.readNext.promise,r?.signal,r)}};function mi(){return new fo}var Rr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function yi(e,t){let r=mi();e.sink(r).catch(async i=>{await r.end(i)}),e.sink=async i=>{for await(let a of i)await r.push(a);await r.end()};let n=e.source;e.source[Symbol.iterator]!=null?n=e.source[Symbol.iterator]():e.source[Symbol.asyncIterator]!=null&&(n=e.source[Symbol.asyncIterator]());let o=new Y;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:c,value:h}=await Qe(n.next(),i?.signal);return c===!0?null:h}for(;o.byteLength<i.bytes;){let{value:c,done:h}=await Qe(n.next(),i?.signal);if(h===!0)throw new Rr("unexpected end of input");o.append(c)}let a=o.sublist(0,i.bytes);return o.consume(i.bytes),a},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await r.push(i,a):await r.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=e.source;e.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return e}}}var Ur=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Pr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Nr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function bi(e,t={}){let r=yi(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Tt(t.maxDataLength));let n=t?.lengthDecoder??Ns,o=t?.lengthEncoder??Ps;return{read:async i=>{let a=-1,c=new Y;for(;;){c.append(await r.read({...i,bytes:1}));try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new Ur("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Nr("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Pr("message length too long");return r.read({...i,bytes:a})},write:async(i,a)=>{await r.write(new Y(o(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new Y(...i.flatMap(h=>[o(h.byteLength),h]));await r.write(c,a)},unwrap:()=>r.unwrap()}}function xi(e,t){let r=bi(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 kr;(function(e){let t;e.codec=()=>(t==null&&(t=te((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.id!=null&&(n.uint32(10),n.bytes(r.id)),r.pubkey!=null&&(n.uint32(18),Or.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=Or.codec().decode(r,r.uint32(),{limits:o.limits?.pubkey});break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Qt(r,e.codec()),e.decode=(r,n)=>Xt(r,e.codec(),n)})(kr||(kr={}));var qt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(qt||(qt={}));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=()=>Ze(uo)})(qt||(qt={}));var Or;(function(e){let t;e.codec=()=>(t==null&&(t=te((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),qt.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:yt(0)},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=qt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Qt(r,e.codec()),e.decode=(r,n)=>Xt(r,e.codec(),n)})(Or||(Or={}));var rf="/plaintext/2.0.0",lo=class{protocol=rf;privateKey;log;constructor(t){this.privateKey=t.privateKey,this.log=t.logger.forComponent("libp2p:plaintext")}[Symbol.toStringTag]="@libp2p/plaintext";[ho]=["@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=xi(t).pb(kr);this.log("write pubkey exchange to peer %p",r?.remotePeer);let o=this.privateKey.publicKey,[,s]=await Promise.all([n.write({id:o.toMultihash().bytes,pubkey:{Type:qt[o.type],Data:o.raw}},r),n.read(r)]),i;try{if(s.pubkey==null)throw new oe("Public key missing");if(s.pubkey.Data.byteLength===0)throw new oe("Public key data too short");if(s.id==null)throw new oe("Remote id missing");let a=hi(s.pubkey.Data);if(i=pi(a),!et(i.toMultihash().bytes,s.id))throw new Le("Public key did not match id")}catch(a){throw this.log.error(a),new Le("Invalid public key - "+a.message)}if(r?.remotePeer!=null&&!i.equals(r?.remotePeer))throw new tr;return this.log("plaintext key exchange completed successfully with peer %p",i),{conn:n.unwrap().unwrap(),remotePeer:i}}};function nf(){return e=>new lo(e)}return Ai(of);})();
|
|
2
|
+
"use strict";var Libp2PPlaintext=(()=>{var Mr=Object.defineProperty;var wi=Object.getOwnPropertyDescriptor;var gi=Object.getOwnPropertyNames;var Ei=Object.prototype.hasOwnProperty;var ct=(e,t)=>{for(var r in t)Mr(e,r,{get:t[r],enumerable:!0})},Si=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of gi(t))!Ei.call(e,o)&&o!==r&&Mr(e,o,{get:()=>t[o],enumerable:!(n=wi(t,o))||n.enumerable});return e};var Ai=e=>Si(Mr({},"__esModule",{value:!0}),e);var of={};ct(of,{plaintext:()=>nf});var qr=Symbol.for("@libp2p/peer-id");var tr=class extends Error{static name="UnexpectedPeerError";constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError"}},Le=class extends Error{static name="InvalidCryptoExchangeError";constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError"}},W=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ne=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var oe=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}};var De=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ho=Symbol.for("@libp2p/service-capabilities"),ff=Symbol.for("@libp2p/service-dependencies");var Gr={};ct(Gr,{base58btc:()=>j,base58flickr:()=>Ti});var Kf=new Uint8Array(0);function po(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Bt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return 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 mo(e){return new TextEncoder().encode(e)}function yo(e){return new TextDecoder().decode(e)}function vi(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),h=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(S){if(S instanceof Uint8Array||(ArrayBuffer.isView(S)?S=new Uint8Array(S.buffer,S.byteOffset,S.byteLength):Array.isArray(S)&&(S=Uint8Array.from(S))),!(S instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(S.length===0)return"";for(var E=0,m=0,A=0,D=S.length;A!==D&&S[A]===0;)A++,E++;for(var B=(D-A)*f+1>>>0,C=new Uint8Array(B);A!==D;){for(var p=S[A],K=0,T=B-1;(p!==0||K<m)&&T!==-1;T--,K++)p+=256*C[T]>>>0,C[T]=p%a>>>0,p=p/a>>>0;if(p!==0)throw new Error("Non-zero carry");m=K,A++}for(var I=B-m;I!==B&&C[I]===0;)I++;for(var u=c.repeat(E);I<B;++I)u+=e.charAt(C[I]);return u}function x(S){if(typeof S!="string")throw new TypeError("Expected String");if(S.length===0)return new Uint8Array;var E=0;if(S[E]!==" "){for(var m=0,A=0;S[E]===c;)m++,E++;for(var D=(S.length-E)*h+1>>>0,B=new Uint8Array(D);S[E];){var C=r[S.charCodeAt(E)];if(C===255)return;for(var p=0,K=D-1;(C!==0||p<A)&&K!==-1;K--,p++)C+=a*B[K]>>>0,B[K]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");A=p,E++}if(S[E]!==" "){for(var T=D-A;T!==D&&B[T]===0;)T++;for(var I=new Uint8Array(m+(D-T)),u=m;T!==D;)I[u++]=B[T++];return I}}}function b(S){var E=x(S);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:x,decode:b}}var Bi=vi,Ii=Bi,xo=Ii;var Vr=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")}},zr=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 wo(this,t)}},Fr=class{decoders;constructor(t){this.decoders=t}or(t){return wo(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 wo(e,t){return new Fr({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var jr=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 Vr(t,r,n),this.decoder=new zr(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function se({name:e,prefix:t,encode:r,decode:n}){return new jr(e,t,r,n)}function Ct({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=xo(r,e);return se({prefix:t,name:e,encode:n,decode:s=>Bt(o(s))})}function _i(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 h=0;h<o;++h){let f=t[e[h]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Li(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 Di(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function V({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Di(n);return se({prefix:t,name:e,encode(s){return Li(s,n,r)},decode(s){return _i(s,o,r,e)}})}var j=Ct({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ti=Ct({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Zr={};ct(Zr,{base32:()=>ie,base32hex:()=>Ui,base32hexpad:()=>Ni,base32hexpadupper:()=>ki,base32hexupper:()=>Pi,base32pad:()=>Ci,base32padupper:()=>Ri,base32upper:()=>Ki,base32z:()=>Oi});var ie=V({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ki=V({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ci=V({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ri=V({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ui=V({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Pi=V({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ni=V({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ki=V({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Oi=V({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Wr={};ct(Wr,{base36:()=>Te,base36upper:()=>Hi});var Te=Ct({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Hi=Ct({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Mi=So,go=128,qi=127,Vi=~qi,zi=Math.pow(2,31);function So(e,t,r){t=t||[],r=r||0;for(var n=r;e>=zi;)t[r++]=e&255|go,e/=128;for(;e&Vi;)t[r++]=e&255|go,e>>>=7;return t[r]=e|0,So.bytes=r-n+1,t}var Fi=Yr,ji=128,Eo=127;function Yr(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw Yr.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Eo)<<o:(i&Eo)*Math.pow(2,o),o+=7}while(i>=ji);return Yr.bytes=s-n,r}var Gi=Math.pow(2,7),Zi=Math.pow(2,14),Wi=Math.pow(2,21),Yi=Math.pow(2,28),$i=Math.pow(2,35),Xi=Math.pow(2,42),Ji=Math.pow(2,49),Qi=Math.pow(2,56),ta=Math.pow(2,63),ea=function(e){return e<Gi?1:e<Zi?2:e<Wi?3:e<Yi?4:e<$i?5:e<Xi?6:e<Ji?7:e<Qi?8:e<ta?9:10},ra={encode:Mi,decode:Fi,encodingLength:ea},na=ra,Ke=na;function Ce(e,t=0){return[Ke.decode(e,t),Ke.decode.bytes]}function ae(e,t,r=0){return Ke.encode(e,t,r),t}function ce(e){return Ke.encodingLength(e)}function mt(e,t){let r=t.byteLength,n=ce(e),o=n+ce(r),s=new Uint8Array(o+r);return ae(e,s,0),ae(r,s,n),s.set(t,o),new fe(e,r,t,s)}function $r(e){let t=Bt(e),[r,n]=Ce(t),[o,s]=Ce(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new fe(r,o,i,t)}function Ao(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&po(e.bytes,r.bytes)}}var fe=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function vo(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return sa(r,Xr(e),t??j.encoder);default:return ia(r,Xr(e),t??ie.encoder)}}var Bo=new WeakMap;function Xr(e){let t=Bo.get(e);if(t==null){let r=new Map;return Bo.set(e,r),r}return t}var tt=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!==Re)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==aa)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=mt(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&&Ao(t.multihash,n.multihash)}toString(t){return vo(this,t)}toJSON(){return{"/":vo(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??Io(n,o,s.bytes))}else if(r[ca]===!0){let{version:n,multihash:o,code:s}=r,i=$r(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!==Re)throw new Error(`Version 0 CID must use dag-pb (code: ${Re}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Io(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Re,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Bt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new fe(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,x]=Ce(t.subarray(r));return r+=x,l},o=n(),s=Re;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(),h=r+c,f=h-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:h}}static parse(t,r){let[n,o]=oa(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 Xr(s).set(n,t),s}};function oa(e,t){switch(e[0]){case"Q":{let r=t??j;return[j.prefix,r.decode(`${j.prefix}${e}`)]}case j.prefix:{let r=t??j;return[j.prefix,r.decode(e)]}case ie.prefix:{let r=t??ie;return[ie.prefix,r.decode(e)]}case Te.prefix:{let r=t??Te;return[Te.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 sa(e,t,r){let{prefix:n}=r;if(n!==j.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 ia(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 Re=112,aa=18;function Io(e,t,r){let n=ce(e),o=n+ce(t),s=new Uint8Array(o+r.byteLength);return ae(e,s,0),ae(t,s,n),s.set(r,o),s}var ca=Symbol.for("@ipld/js-cid/CID");var Jr={};ct(Jr,{identity:()=>gt});var _o=0,fa="identity",Lo=Bt;function ua(e){return mt(_o,Lo(e))}var gt={code:_o,name:fa,encode:Lo,digest:ua};function et(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 yt(e=0){return new Uint8Array(e)}function ft(e=0){return new Uint8Array(e)}function rr(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ft(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var To=Symbol.for("@achingbrain/uint8arraylist");function Do(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 nr(e){return!!e?.[To]}var Y=class e{bufs;length;[To]=!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(nr(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(nr(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=Do(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Do(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(nr(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 rr(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:rr(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 h=t>=a&&t<c,f=r>a&&r<=c;if(h&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(h){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!nr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,h=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let x=h;x>=0;x--){let b=this.get(l+x);if(n[x]!==b){f=Math.max(1,x-a[b]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ft(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=yt(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=yt(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=yt(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=ft(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=yt(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=yt(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=yt(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=yt(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=yt(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(!et(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 Qr={};ct(Qr,{base10:()=>la});var la=Ct({prefix:"9",name:"base10",alphabet:"0123456789"});var tn={};ct(tn,{base16:()=>ha,base16upper:()=>da});var ha=V({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),da=V({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var en={};ct(en,{base2:()=>pa});var pa=V({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var rn={};ct(rn,{base256emoji:()=>wa});var Ko=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}"),ma=Ko.reduce((e,t,r)=>(e[r]=t,e),[]),ya=Ko.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function ba(e){return e.reduce((t,r)=>(t+=ma[r],t),"")}function xa(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=ya[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var wa=se({prefix:"\u{1F680}",name:"base256emoji",encode:ba,decode:xa});var nn={};ct(nn,{base64:()=>ga,base64pad:()=>Ea,base64url:()=>Sa,base64urlpad:()=>Aa});var ga=V({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ea=V({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Sa=V({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Aa=V({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var on={};ct(on,{base8:()=>va});var va=V({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var sn={};ct(sn,{identity:()=>Ba});var Ba=se({prefix:"\0",name:"identity",encode:e=>yo(e),decode:e=>mo(e)});var pu=new TextEncoder,mu=new TextDecoder;var fn={};ct(fn,{sha256:()=>or,sha512:()=>La});function cn({name:e,code:t,encode:r}){return new an(e,t,r)}var an=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?mt(this.code,r):r.then(n=>mt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ro(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var or=cn({name:"sha2-256",code:18,encode:Ro("SHA-256")}),La=cn({name:"sha2-512",code:19,encode:Ro("SHA-512")});var un={...sn,...en,...on,...Qr,...tn,...Zr,...Wr,...Gr,...nn,...rn},_u={...fn,...Jr};function Po(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Uo=Po("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),ln=Po("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=ft(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Da={utf8:Uo,"utf-8":Uo,hex:un.base16,latin1:ln,ascii:ln,binary:ln,...un},sr=Da;function G(e,t="utf8"){let r=sr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function z(e,t="utf8"){let r=sr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Ta=parseInt("11111",2),hn=parseInt("10000000",2),Ka=parseInt("01111111",2),No={0:Ue,1:Ue,2:Ca,3:Pa,4:Na,5:Ua,6:Ra,16:Ue,22:Ue,48:Ue};function Et(e,t={offset:0}){let r=e[t.offset]&Ta;if(t.offset++,No[r]!=null)return No[r](e,t);throw new Error("No decoder for tag "+r)}function Pe(e,t){let r=0;if((e[t.offset]&hn)===hn){let n=e[t.offset]&Ka,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 Ue(e,t){Pe(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Et(e,t);if(n===null)break;r.push(n)}return r}function Ca(e,t){let r=Pe(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 Ra(e,t){let r=Pe(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 h=e[t.offset];if(t.offset++,c.push(h&127),h<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Ua(e,t){return t.offset++,null}function Pa(e,t){let r=Pe(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 Na(e,t){let r=Pe(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function ka(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new Y;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function dn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=ka(e.byteLength);return new Y(Uint8Array.from([t.byteLength|hn]),t)}function ut(e){let t=new Y,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new Y(Uint8Array.from([2]),dn(t),t)}function ir(e){let t=Uint8Array.from([0]),r=new Y(t,e);return new Y(Uint8Array.from([3]),dn(r),r)}function Rt(e,t=48){let r=new Y;for(let n of e)r.append(n);return new Y(Uint8Array.from([t]),dn(r),r)}var ko="1.2.840.10045.3.1.7",Oo="1.3.132.0.34",Ho="1.3.132.0.35";async function Mo(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 Oa=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Ha=Uint8Array.from([6,5,43,129,4,0,34]),Ma=Uint8Array.from([6,5,43,129,4,0,35]),qa={ext:!0,kty:"EC",crv:"P-256"},Va={ext:!0,kty:"EC",crv:"P-384"},za={ext:!0,kty:"EC",crv:"P-521"},pn=32,mn=48,yn=66;function qo(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===pn*2+1)return n=z(t.subarray(r,r+pn),"base64url"),o=z(t.subarray(r+pn),"base64url"),new le({...qa,key_ops:["verify"],x:n,y:o});if(t.byteLength===mn*2+1)return n=z(t.subarray(r,r+mn),"base64url"),o=z(t.subarray(r+mn),"base64url"),new le({...Va,key_ops:["verify"],x:n,y:o});if(t.byteLength===yn*2+1)return n=z(t.subarray(r,r+yn),"base64url"),o=z(t.subarray(r+yn),"base64url"),new le({...za,key_ops:["verify"],x:n,y:o});throw new W(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Vo(e){return Rt([ut(Uint8Array.from([1])),Rt([Fa(e.crv)],160),Rt([ir(new Y(Uint8Array.from([4]),G(e.x??"","base64url"),G(e.y??"","base64url")))],161)]).subarray()}function Fa(e){if(e==="P-256")return Oa;if(e==="P-384")return Ha;if(e==="P-521")return Ma;throw new W(`Invalid curve ${e}`)}var le=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Vo(this.jwk)),this._raw}toMultihash(){return gt.digest(he(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:et(this.raw,t.raw)}async verify(t,r,n){return Mo(this.jwk,r,t,n)}};var zt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function pe(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ne(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function rt(e,...t){if(!pe(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 Fo(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Ne(e.outputLen),Ne(e.blockLen)}function me(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 jo(e,t){rt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function _t(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function ar(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function bt(e,t){return e<<32-t|e>>>t}var Go=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ja=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function St(e){if(rt(e),Go)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=ja[e[r]];return t}var It={_0:48,_9:57,A:65,F:70,a:97,f:102};function zo(e){if(e>=It._0&&e<=It._9)return e-It._0;if(e>=It.A&&e<=It.F)return e-(It.A-10);if(e>=It.a&&e<=It.f)return e-(It.a-10)}function ye(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Go)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=zo(e.charCodeAt(s)),a=zo(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 Zo(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function ke(e){return typeof e=="string"&&(e=Zo(e)),rt(e),e}function ht(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];rt(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 de=class{};function bn(e){let t=n=>e().update(ke(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Oe(e=32){if(zt&&typeof zt.getRandomValues=="function")return zt.getRandomValues(new Uint8Array(e));if(zt&&typeof zt.randomBytes=="function")return Uint8Array.from(zt.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Ga(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,h=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+h,a,n)}function Wo(e,t,r){return e&t^~e&r}function Yo(e,t,r){return e&t^e&r^t&r}var He=class extends de{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=ar(this.buffer)}update(t){me(this),t=ke(t),rt(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=ar(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){me(this),jo(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,_t(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;Ga(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=ar(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let h=c/4,f=this.get();if(h>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<h;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_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()}},Lt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var J=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var cr=BigInt(4294967295),$o=BigInt(32);function Za(e,t=!1){return t?{h:Number(e&cr),l:Number(e>>$o&cr)}:{h:Number(e>>$o&cr)|0,l:Number(e&cr)|0}}function Xo(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}=Za(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var xn=(e,t,r)=>e>>>r,wn=(e,t,r)=>e<<32-r|t>>>r,Ft=(e,t,r)=>e>>>r|t<<32-r,jt=(e,t,r)=>e<<32-r|t>>>r,Me=(e,t,r)=>e<<64-r|t>>>r-32,qe=(e,t,r)=>e>>>r-32|t<<64-r;function At(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Jo=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Qo=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ts=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),es=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,rs=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ns=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Ya=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]),Ut=new Uint32Array(64),fr=class extends He{constructor(t=32){super(64,t,8,!1),this.A=Lt[0]|0,this.B=Lt[1]|0,this.C=Lt[2]|0,this.D=Lt[3]|0,this.E=Lt[4]|0,this.F=Lt[5]|0,this.G=Lt[6]|0,this.H=Lt[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 l=0;l<16;l++,r+=4)Ut[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let x=Ut[l-15],b=Ut[l-2],S=bt(x,7)^bt(x,18)^x>>>3,E=bt(b,17)^bt(b,19)^b>>>10;Ut[l]=E+Ut[l-7]+S+Ut[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:h,H:f}=this;for(let l=0;l<64;l++){let x=bt(a,6)^bt(a,11)^bt(a,25),b=f+x+Wo(a,c,h)+Ya[l]+Ut[l]|0,E=(bt(n,2)^bt(n,13)^bt(n,22))+Yo(n,o,s)|0;f=h,h=c,c=a,a=i+b|0,i=s,s=o,o=n,n=b+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,h=h+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,h,f)}roundClean(){_t(Ut)}destroy(){this.set(0,0,0,0,0,0,0,0),_t(this.buffer)}};var os=Xo(["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))),$a=os[0],Xa=os[1],Pt=new Uint32Array(80),Nt=new Uint32Array(80),gn=class extends He{constructor(t=64){super(128,t,16,!1),this.Ah=J[0]|0,this.Al=J[1]|0,this.Bh=J[2]|0,this.Bl=J[3]|0,this.Ch=J[4]|0,this.Cl=J[5]|0,this.Dh=J[6]|0,this.Dl=J[7]|0,this.Eh=J[8]|0,this.El=J[9]|0,this.Fh=J[10]|0,this.Fl=J[11]|0,this.Gh=J[12]|0,this.Gl=J[13]|0,this.Hh=J[14]|0,this.Hl=J[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:h,El:f,Fh:l,Fl:x,Gh:b,Gl:S,Hh:E,Hl:m}=this;return[t,r,n,o,s,i,a,c,h,f,l,x,b,S,E,m]}set(t,r,n,o,s,i,a,c,h,f,l,x,b,S,E,m){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=h|0,this.El=f|0,this.Fh=l|0,this.Fl=x|0,this.Gh=b|0,this.Gl=S|0,this.Hh=E|0,this.Hl=m|0}process(t,r){for(let B=0;B<16;B++,r+=4)Pt[B]=t.getUint32(r),Nt[B]=t.getUint32(r+=4);for(let B=16;B<80;B++){let C=Pt[B-15]|0,p=Nt[B-15]|0,K=Ft(C,p,1)^Ft(C,p,8)^xn(C,p,7),T=jt(C,p,1)^jt(C,p,8)^wn(C,p,7),I=Pt[B-2]|0,u=Nt[B-2]|0,w=Ft(I,u,19)^Me(I,u,61)^xn(I,u,6),d=jt(I,u,19)^qe(I,u,61)^wn(I,u,6),y=ts(T,d,Nt[B-7],Nt[B-16]),g=es(y,K,w,Pt[B-7],Pt[B-16]);Pt[B]=g|0,Nt[B]=y|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:h,Dl:f,Eh:l,El:x,Fh:b,Fl:S,Gh:E,Gl:m,Hh:A,Hl:D}=this;for(let B=0;B<80;B++){let C=Ft(l,x,14)^Ft(l,x,18)^Me(l,x,41),p=jt(l,x,14)^jt(l,x,18)^qe(l,x,41),K=l&b^~l&E,T=x&S^~x&m,I=rs(D,p,T,Xa[B],Nt[B]),u=ns(I,A,C,K,$a[B],Pt[B]),w=I|0,d=Ft(n,o,28)^Me(n,o,34)^Me(n,o,39),y=jt(n,o,28)^qe(n,o,34)^qe(n,o,39),g=n&s^n&a^s&a,_=o&i^o&c^i&c;A=E|0,D=m|0,E=b|0,m=S|0,b=l|0,S=x|0,{h:l,l:x}=At(h|0,f|0,u|0,w|0),h=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let v=Jo(w,y,_);n=Qo(v,u,d,g),o=v|0}({h:n,l:o}=At(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=At(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=At(this.Ch|0,this.Cl|0,a|0,c|0),{h,l:f}=At(this.Dh|0,this.Dl|0,h|0,f|0),{h:l,l:x}=At(this.Eh|0,this.El|0,l|0,x|0),{h:b,l:S}=At(this.Fh|0,this.Fl|0,b|0,S|0),{h:E,l:m}=At(this.Gh|0,this.Gl|0,E|0,m|0),{h:A,l:D}=At(this.Hh|0,this.Hl|0,A|0,D|0),this.set(n,o,s,i,a,c,h,f,l,x,b,S,E,m,A,D)}roundClean(){_t(Pt,Nt)}destroy(){_t(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ur=bn(()=>new fr);var ss=bn(()=>new gn);var An=BigInt(0),Sn=BigInt(1);function Dt(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}function Ve(e){let t=e.toString(16);return t.length&1?"0"+t:t}function is(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?An:BigInt("0x"+e)}function be(e){return is(St(e))}function Gt(e){return rt(e),is(St(Uint8Array.from(e).reverse()))}function lr(e,t){return ye(e.toString(16).padStart(t*2,"0"))}function xe(e,t){return lr(e,t).reverse()}function H(e,t,r){let n;if(typeof t=="string")try{n=ye(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(pe(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}var En=e=>typeof e=="bigint"&&An<=e;function as(e,t,r){return En(e)&&En(t)&&En(r)&&t<=e&&e<r}function kt(e,t,r,n){if(!as(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function cs(e){let t;for(t=0;e>An;e>>=Sn,t+=1);return t}var Zt=e=>(Sn<<BigInt(e))-Sn;function fs(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=b=>new Uint8Array(b),o=b=>Uint8Array.of(b),s=n(e),i=n(e),a=0,c=()=>{s.fill(1),i.fill(0),a=0},h=(...b)=>r(i,s,...b),f=(b=n(0))=>{i=h(o(0),b),s=h(),b.length!==0&&(i=h(o(1),b),s=h())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let b=0,S=[];for(;b<t;){s=h();let E=s.slice();S.push(E),b+=s.length}return ht(...S)};return(b,S)=>{c(),f(b);let E;for(;!(E=S(l()));)f();return c(),E}}function Ot(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))}function we(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 it=BigInt(0),X=BigInt(1),Wt=BigInt(2),Ja=BigInt(3),hs=BigInt(4),ds=BigInt(5),ps=BigInt(8);function q(e,t){let r=e%t;return r>=it?r:t+r}function M(e,t,r){let n=e;for(;t-- >it;)n*=n,n%=r;return n}function us(e,t){if(e===it)throw new Error("invert: expected non-zero number");if(t<=it)throw new Error("invert: expected positive modulus, got "+t);let r=q(e,t),n=t,o=it,s=X,i=X,a=it;for(;r!==it;){let h=n/r,f=n%r,l=o-i*h,x=s-a*h;n=r,r=f,o=i,s=a,i=l,a=x}if(n!==X)throw new Error("invert: does not exist");return q(o,t)}function ms(e,t){let r=(e.ORDER+X)/hs,n=e.pow(t,r);if(!e.eql(e.sqr(n),t))throw new Error("Cannot find square root");return n}function Qa(e,t){let r=(e.ORDER-ds)/ps,n=e.mul(t,Wt),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,Wt),o),a=e.mul(s,e.sub(i,e.ONE));if(!e.eql(e.sqr(a),t))throw new Error("Cannot find square root");return a}function tc(e){if(e<BigInt(3))throw new Error("sqrt is not defined for small field");let t=e-X,r=0;for(;t%Wt===it;)t/=Wt,r++;let n=Wt,o=xt(e);for(;ls(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ms;let s=o.pow(n,t),i=(t+X)/Wt;return function(c,h){if(c.is0(h))return h;if(ls(c,h)!==1)throw new Error("Cannot find square root");let f=r,l=c.mul(c.ONE,s),x=c.pow(h,t),b=c.pow(h,i);for(;!c.eql(x,c.ONE);){if(c.is0(x))return c.ZERO;let S=1,E=c.sqr(x);for(;!c.eql(E,c.ONE);)if(S++,E=c.sqr(E),S===f)throw new Error("Cannot find square root");let m=X<<BigInt(f-S-1),A=c.pow(l,m);f=S,l=c.sqr(A),x=c.mul(x,l),b=c.mul(b,A)}return b}}function ec(e){return e%hs===Ja?ms:e%ps===ds?Qa:tc(e)}var ys=(e,t)=>(q(e,t)&X)===X,rc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function vn(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=rc.reduce((n,o)=>(n[o]="function",n),t);return Ot(e,r),e}function nc(e,t,r){if(r<it)throw new Error("invalid exponent, negatives unsupported");if(r===it)return e.ONE;if(r===X)return t;let n=e.ONE,o=t;for(;r>it;)r&X&&(n=e.mul(n,o)),o=e.sqr(o),r>>=X;return n}function ze(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 ls(e,t){let r=(e.ORDER-X)/Wt,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 bs(e,t){t!==void 0&&Ne(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<=it)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=bs(e,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c,h=Object.freeze({ORDER:e,isLE:r,BITS:i,BYTES:a,MASK:Zt(i),ZERO:it,ONE:X,create:f=>q(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return it<=f&&f<e},is0:f=>f===it,isValidNot0:f=>!h.is0(f)&&h.isValid(f),isOdd:f=>(f&X)===X,neg:f=>q(-f,e),eql:(f,l)=>f===l,sqr:f=>q(f*f,e),add:(f,l)=>q(f+l,e),sub:(f,l)=>q(f-l,e),mul:(f,l)=>q(f*l,e),pow:(f,l)=>nc(h,f,l),div:(f,l)=>q(f*us(l,e),e),sqrN:f=>f*f,addN:(f,l)=>f+l,subN:(f,l)=>f-l,mulN:(f,l)=>f*l,inv:f=>us(f,e),sqrt:s||(f=>(c||(c=ec(e)),c(h,f))),toBytes:f=>r?xe(f,a):lr(f,a),fromBytes:f=>{if(f.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);return r?Gt(f):be(f)},invertBatch:f=>ze(h,f),cmov:(f,l,x)=>x?l:f});return Object.freeze(h)}function xs(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 Bn(e){let t=xs(e);return t+Math.ceil(t/2)}function ws(e,t,r=!1){let n=e.length,o=xs(t),s=Bn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Gt(e):be(e),a=q(i,t-X)+X;return r?xe(a,o):lr(a,o)}var Ee=BigInt(0),Yt=BigInt(1);function ge(e,t){let r=t.negate();return e?r:t}function hr(e,t,r){let n=t==="pz"?i=>i.pz:i=>i.ez,o=ze(e.Fp,r.map(n));return r.map((i,a)=>i.toAffine(o[a])).map(e.fromAffine)}function As(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function In(e,t){As(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Zt(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function gs(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+=Yt);let h=t*n,f=h+Math.abs(a)-1,l=a===0,x=a<0,b=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:x,isNegF:b,offsetF:h}}function oc(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 sc(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 _n=new WeakMap,vs=new WeakMap;function Ln(e){return vs.get(e)||1}function Es(e){if(e!==Ee)throw new Error("invalid wNAF")}function dr(e,t){return{constTimeNegate:ge,hasPrecomputes(r){return Ln(r)!==1},unsafeLadder(r,n,o=e.ZERO){let s=r;for(;n>Ee;)n&Yt&&(o=o.add(s)),s=s.double(),n>>=Yt;return o},precomputeWindow(r,n){let{windows:o,windowSize:s}=In(n,t),i=[],a=r,c=a;for(let h=0;h<o;h++){c=a,i.push(c);for(let f=1;f<s;f++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(r,n,o){let s=e.ZERO,i=e.BASE,a=In(r,t);for(let c=0;c<a.windows;c++){let{nextN:h,offset:f,isZero:l,isNeg:x,isNegF:b,offsetF:S}=gs(o,c,a);o=h,l?i=i.add(ge(b,n[S])):s=s.add(ge(x,n[f]))}return Es(o),{p:s,f:i}},wNAFUnsafe(r,n,o,s=e.ZERO){let i=In(r,t);for(let a=0;a<i.windows&&o!==Ee;a++){let{nextN:c,offset:h,isZero:f,isNeg:l}=gs(o,a,i);if(o=c,!f){let x=n[h];s=s.add(l?x.negate():x)}}return Es(o),s},getPrecomputes(r,n,o){let s=_n.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&(typeof o=="function"&&(s=o(s)),_n.set(n,s))),s},wNAFCached(r,n,o){let s=Ln(r);return this.wNAF(s,this.getPrecomputes(s,r,o),n)},wNAFCachedUnsafe(r,n,o,s){let i=Ln(r);return i===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,r,o),n,s)},setWindowSize(r,n){As(n,t),vs.set(r,n),_n.delete(r)}}}function Bs(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Ee||n>Ee;)r&Yt&&(s=s.add(o)),n&Yt&&(i=i.add(o)),o=o.double(),r>>=Yt,n>>=Yt;return{p1:s,p2:i}}function pr(e,t,r,n){oc(r,e),sc(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=cs(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let h=Zt(c),f=new Array(Number(h)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c,x=i;for(let b=l;b>=0;b-=c){f.fill(i);for(let E=0;E<s;E++){let m=n[E],A=Number(m>>BigInt(b)&h);f[A]=f[A].add(r[E])}let S=i;for(let E=f.length-1,m=i;E>0;E--)m=m.add(f[E]),S=S.add(m);if(x=x.add(S),b!==0)for(let E=0;E<c;E++)x=x.double()}return x}function Ss(e,t){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return vn(t),t}else return xt(e)}function mr(e,t,r={}){if(!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>Ee))throw new Error(`CURVE.${a} must be positive bigint`)}let n=Ss(t.p,r.Fp),o=Ss(t.n,r.Fn),i=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var vt=BigInt(0),at=BigInt(1),Dn=BigInt(2),ic=BigInt(8),ac={zip215:!0};function cc(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 fc(e,t={}){let{Fp:r,Fn:n}=mr("edwards",e,t),{h:o,n:s}=e;Ot(t,{},{uvRatio:"function"});let i=Dn<<BigInt(n.BYTES*8)-at,a=E=>r.create(E),c=t.uvRatio||((E,m)=>{try{return{isValid:!0,value:r.sqrt(r.div(E,m))}}catch{return{isValid:!1,value:vt}}});if(!cc(r,e,e.Gx,e.Gy))throw new Error("bad curve params: generator point");function h(E,m,A=!1){let D=A?at:vt;return kt("coordinate "+E,m,D,i),m}function f(E){if(!(E instanceof b))throw new Error("ExtendedPoint expected")}let l=we((E,m)=>{let{ex:A,ey:D,ez:B}=E,C=E.is0();m==null&&(m=C?ic:r.inv(B));let p=a(A*m),K=a(D*m),T=a(B*m);if(C)return{x:vt,y:at};if(T!==at)throw new Error("invZ was invalid");return{x:p,y:K}}),x=we(E=>{let{a:m,d:A}=e;if(E.is0())throw new Error("bad point: ZERO");let{ex:D,ey:B,ez:C,et:p}=E,K=a(D*D),T=a(B*B),I=a(C*C),u=a(I*I),w=a(K*m),d=a(I*a(w+T)),y=a(u+a(A*a(K*T)));if(d!==y)throw new Error("bad point: equation left != right (1)");let g=a(D*B),_=a(C*p);if(g!==_)throw new Error("bad point: equation left != right (2)");return!0});class b{constructor(m,A,D,B){this.ex=h("x",m),this.ey=h("y",A),this.ez=h("z",D,!0),this.et=h("t",B),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(m){if(m instanceof b)throw new Error("extended point not allowed");let{x:A,y:D}=m||{};return h("x",A),h("y",D),new b(A,D,at,a(A*D))}static normalizeZ(m){return hr(b,"ez",m)}static msm(m,A){return pr(b,n,m,A)}_setWindowSize(m){this.precompute(m)}precompute(m=8,A=!0){return S.setWindowSize(this,m),A||this.multiply(Dn),this}assertValidity(){x(this)}equals(m){f(m);let{ex:A,ey:D,ez:B}=this,{ex:C,ey:p,ez:K}=m,T=a(A*K),I=a(C*B),u=a(D*K),w=a(p*B);return T===I&&u===w}is0(){return this.equals(b.ZERO)}negate(){return new b(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:m}=e,{ex:A,ey:D,ez:B}=this,C=a(A*A),p=a(D*D),K=a(Dn*a(B*B)),T=a(m*C),I=A+D,u=a(a(I*I)-C-p),w=T+p,d=w-K,y=T-p,g=a(u*d),_=a(w*y),v=a(u*y),L=a(d*w);return new b(g,_,L,v)}add(m){f(m);let{a:A,d:D}=e,{ex:B,ey:C,ez:p,et:K}=this,{ex:T,ey:I,ez:u,et:w}=m,d=a(B*T),y=a(C*I),g=a(K*D*w),_=a(p*u),v=a((B+C)*(T+I)-d-y),L=_-g,U=_+g,R=a(y-A*d),F=a(v*L),k=a(U*R),P=a(v*R),Z=a(L*U);return new b(F,k,Z,P)}subtract(m){return this.add(m.negate())}multiply(m){let A=m;kt("scalar",A,at,s);let{p:D,f:B}=S.wNAFCached(this,A,b.normalizeZ);return b.normalizeZ([D,B])[0]}multiplyUnsafe(m,A=b.ZERO){let D=m;return kt("scalar",D,vt,s),D===vt?b.ZERO:this.is0()||D===at?this:S.wNAFCachedUnsafe(this,D,b.normalizeZ,A)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return S.wNAFCachedUnsafe(this,s).is0()}toAffine(m){return l(this,m)}clearCofactor(){return o===at?this:this.multiplyUnsafe(o)}static fromBytes(m,A=!1){return rt(m),this.fromHex(m,A)}static fromHex(m,A=!1){let{d:D,a:B}=e,C=r.BYTES;m=H("pointHex",m,C),Dt("zip215",A);let p=m.slice(),K=m[C-1];p[C-1]=K&-129;let T=Gt(p),I=A?i:r.ORDER;kt("pointHex.y",T,vt,I);let u=a(T*T),w=a(u-at),d=a(D*u-B),{isValid:y,value:g}=c(w,d);if(!y)throw new Error("Point.fromHex: invalid y coordinate");let _=(g&at)===at,v=(K&128)!==0;if(!A&&g===vt&&v)throw new Error("Point.fromHex: x=0 and x_0=1");return v!==_&&(g=a(-g)),b.fromAffine({x:g,y:T})}static fromPrivateScalar(m){return b.BASE.multiply(m)}toBytes(){let{x:m,y:A}=this.toAffine(),D=xe(A,r.BYTES);return D[D.length-1]|=m&at?128:0,D}toRawBytes(){return this.toBytes()}toHex(){return St(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}b.BASE=new b(e.Gx,e.Gy,at,a(e.Gx*e.Gy)),b.ZERO=new b(vt,at,at,vt),b.Fp=r,b.Fn=n;let S=dr(b,n.BYTES*8);return b}function uc(e,t){Ot(t,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:r,hash:n}=t,{BASE:o,Fp:s,Fn:i}=e,a=i.ORDER,c=t.randomBytes||Oe,h=t.adjustScalarBytes||(p=>p),f=t.domain||((p,K,T)=>{if(Dt("phflag",T),K.length||T)throw new Error("Contexts/pre-hash are not supported");return p});function l(p){return i.create(p)}function x(p){return l(Gt(p))}function b(p){let K=s.BYTES;p=H("private key",p,K);let T=H("hashed private key",n(p),2*K),I=h(T.slice(0,K)),u=T.slice(K,2*K),w=x(I);return{head:I,prefix:u,scalar:w}}function S(p){let{head:K,prefix:T,scalar:I}=b(p),u=o.multiply(I),w=u.toBytes();return{head:K,prefix:T,scalar:I,point:u,pointBytes:w}}function E(p){return S(p).pointBytes}function m(p=Uint8Array.of(),...K){let T=ht(...K);return x(n(f(T,H("context",p),!!r)))}function A(p,K,T={}){p=H("message",p),r&&(p=r(p));let{prefix:I,scalar:u,pointBytes:w}=S(K),d=m(T.context,I,p),y=o.multiply(d).toBytes(),g=m(T.context,y,w,p),_=l(d+g*u);kt("signature.s",_,vt,a);let v=s.BYTES,L=ht(y,xe(_,v));return H("result",L,v*2)}let D=ac;function B(p,K,T,I=D){let{context:u,zip215:w}=I,d=s.BYTES;p=H("signature",p,2*d),K=H("message",K),T=H("publicKey",T,d),w!==void 0&&Dt("zip215",w),r&&(K=r(K));let y=Gt(p.slice(d,2*d)),g,_,v;try{g=e.fromHex(T,w),_=e.fromHex(p.slice(0,d),w),v=o.multiplyUnsafe(y)}catch{return!1}if(!w&&g.isSmallOrder())return!1;let L=m(u,_.toBytes(),g.toBytes(),K);return _.add(g.multiplyUnsafe(L)).subtract(v).clearCofactor().is0()}return o.precompute(8),{getPublicKey:E,sign:A,verify:B,utils:{getExtendedPublicKey:S,randomPrivateKey:()=>c(s.BYTES),precompute(p=8,K=e.BASE){return K.precompute(p,!1)}},Point:e}}function lc(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={hash:e.hash,randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,eddsaOpts:s}}function hc(e,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:e})}function Is(e){let{CURVE:t,curveOpts:r,eddsaOpts:n}=lc(e),o=fc(t,r),s=uc(o,n);return hc(e,s)}var Cl=BigInt(0),dc=BigInt(1),_s=BigInt(2),Rl=BigInt(3),pc=BigInt(5),mc=BigInt(8),yr={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:mc,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function yc(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=yr.p,a=e*e%s*e%s,c=M(a,_s,s)*a%s,h=M(c,dc,s)*e%s,f=M(h,pc,s)*h%s,l=M(f,t,s)*f%s,x=M(l,r,s)*l%s,b=M(x,n,s)*x%s,S=M(b,o,s)*b%s,E=M(S,o,s)*b%s,m=M(E,t,s)*f%s;return{pow_p_5_8:M(m,_s,s)*e%s,b2:a}}function bc(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ls=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function xc(e,t){let r=yr.p,n=q(t*t*t,r),o=q(n*n*t,r),s=yc(e*o).pow_p_5_8,i=q(e*n*s,r),a=q(t*i*i,r),c=i,h=q(i*Ls,r),f=a===e,l=a===q(-e,r),x=a===q(-e*Ls,r);return f&&(i=c),(l||x)&&(i=h),ys(i,r)&&(i=q(-i,r)),{isValid:f||l,value:i}}var wc=xt(yr.p,void 0,!0),gc={...yr,Fp:wc,hash:ss,adjustScalarBytes:bc,uvRatio:xc},Ds=Is(gc);var Fe=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},br=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Ts={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new br("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 pt=Ts;var Se=32;var Tn,Ec=(async()=>{try{return await pt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Sc(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await pt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await pt.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 Ac(e,t,r){return Ds.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Ks(e,t,r){return Tn==null&&(Tn=await Ec),Tn?Sc(e,t,r):Ac(e,t,r)}function xr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var wr=class{type="Ed25519";raw;constructor(t){this.raw=Kn(t,Se)}toMultihash(){return gt.digest(he(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:et(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Ks(this.raw,r,t);return xr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Us(e){return e=Kn(e,Se),new wr(e)}function Kn(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new W(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var vc=Math.pow(2,7),Bc=Math.pow(2,14),Ic=Math.pow(2,21),Cn=Math.pow(2,28),Rn=Math.pow(2,35),Un=Math.pow(2,42),Pn=Math.pow(2,49),N=128,nt=127;function Tt(e){if(e<vc)return 1;if(e<Bc)return 2;if(e<Ic)return 3;if(e<Cn)return 4;if(e<Rn)return 5;if(e<Un)return 6;if(e<Pn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Nn(e,t,r=0){switch(Tt(e)){case 8:t[r++]=e&255|N,e/=128;case 7:t[r++]=e&255|N,e/=128;case 6:t[r++]=e&255|N,e/=128;case 5:t[r++]=e&255|N,e/=128;case 4:t[r++]=e&255|N,e>>>=7;case 3:t[r++]=e&255|N,e>>>=7;case 2:t[r++]=e&255|N,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function _c(e,t,r=0){switch(Tt(e)){case 8:t.set(r++,e&255|N),e/=128;case 7:t.set(r++,e&255|N),e/=128;case 6:t.set(r++,e&255|N),e/=128;case 5:t.set(r++,e&255|N),e/=128;case 4:t.set(r++,e&255|N),e>>>=7;case 3:t.set(r++,e&255|N),e>>>=7;case 2:t.set(r++,e&255|N),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function kn(e,t){let r=e[t],n=0;if(n+=r&nt,r<N||(r=e[t+1],n+=(r&nt)<<7,r<N)||(r=e[t+2],n+=(r&nt)<<14,r<N)||(r=e[t+3],n+=(r&nt)<<21,r<N)||(r=e[t+4],n+=(r&nt)*Cn,r<N)||(r=e[t+5],n+=(r&nt)*Rn,r<N)||(r=e[t+6],n+=(r&nt)*Un,r<N)||(r=e[t+7],n+=(r&nt)*Pn,r<N))return n;throw new RangeError("Could not decode varint")}function Lc(e,t){let r=e.get(t),n=0;if(n+=r&nt,r<N||(r=e.get(t+1),n+=(r&nt)<<7,r<N)||(r=e.get(t+2),n+=(r&nt)<<14,r<N)||(r=e.get(t+3),n+=(r&nt)<<21,r<N)||(r=e.get(t+4),n+=(r&nt)*Cn,r<N)||(r=e.get(t+5),n+=(r&nt)*Rn,r<N)||(r=e.get(t+6),n+=(r&nt)*Un,r<N)||(r=e.get(t+7),n+=(r&nt)*Pn,r<N))return n;throw new RangeError("Could not decode varint")}function Ps(e,t,r=0){return t==null&&(t=ft(Tt(e))),t instanceof Uint8Array?Nn(e,t,r):_c(e,t,r)}function Ns(e,t=0){return e instanceof Uint8Array?kn(e,t):Lc(e,t)}var On=new Float32Array([-0]),Ht=new Uint8Array(On.buffer);function ks(e,t,r){On[0]=e,t[r]=Ht[0],t[r+1]=Ht[1],t[r+2]=Ht[2],t[r+3]=Ht[3]}function Os(e,t){return Ht[0]=e[t],Ht[1]=e[t+1],Ht[2]=e[t+2],Ht[3]=e[t+3],On[0]}var Hn=new Float64Array([-0]),ot=new Uint8Array(Hn.buffer);function Hs(e,t,r){Hn[0]=e,t[r]=ot[0],t[r+1]=ot[1],t[r+2]=ot[2],t[r+3]=ot[3],t[r+4]=ot[4],t[r+5]=ot[5],t[r+6]=ot[6],t[r+7]=ot[7]}function Ms(e,t){return ot[0]=e[t],ot[1]=e[t+1],ot[2]=e[t+2],ot[3]=e[t+3],ot[4]=e[t+4],ot[5]=e[t+5],ot[6]=e[t+6],ot[7]=e[t+7],Hn[0]}var Tc=BigInt(Number.MAX_SAFE_INTEGER),Kc=BigInt(Number.MIN_SAFE_INTEGER),dt=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 $t;if(t<Tc&&t>Kc)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>qs&&(o=0n,++n>qs&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return $t;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):$t}},$t=new dt(0,0);$t.toBigInt=function(){return 0n};$t.zzEncode=$t.zzDecode=function(){return this};$t.length=function(){return 1};var qs=4294967296n;function Vs(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 zs(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 Mn(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 wt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function gr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var qn=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,wt(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 wt(this,4);return gr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw wt(this,4);return gr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw wt(this,4);let t=Os(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw wt(this,4);let t=Ms(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 wt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return zs(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw wt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw wt(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 dt(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 wt(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 wt(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 wt(this,8);let t=gr(this.buf,this.pos+=4),r=gr(this.buf,this.pos+=4);return new dt(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=kn(this.buf,this.pos);return this.pos+=Tt(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 Vn(e){return new qn(e instanceof Uint8Array?e:e.subarray())}function Xt(e,t,r){let n=Vn(e);return t.decode(n,void 0,r)}function zn(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return ft(i);o+i>t&&(n=ft(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Jt=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Fn(){}var Gn=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Cc=zn();function Rc(e){return globalThis.Buffer!=null?ft(e):Cc(e)}var Ge=class{len;head;tail;states;constructor(){this.len=0,this.head=new Jt(Fn,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Jt(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Zn((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(Er,10,dt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=dt.fromBigInt(t);return this._push(Er,r.length(),r)}uint64Number(t){return this._push(Nn,Tt(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=dt.fromBigInt(t).zzEncode();return this._push(Er,r.length(),r)}sint64Number(t){let r=dt.fromNumber(t).zzEncode();return this._push(Er,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(jn,1,t?1:0)}fixed32(t){return this._push(je,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=dt.fromBigInt(t);return this._push(je,4,r.lo)._push(je,4,r.hi)}fixed64Number(t){let r=dt.fromNumber(t);return this._push(je,4,r.lo)._push(je,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(ks,4,t)}double(t){return this._push(Hs,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(jn,1,0):this.uint32(r)._push(Pc,r,t)}string(t){let r=Vs(t);return r!==0?this.uint32(r)._push(Mn,r,t):this._push(jn,1,0)}fork(){return this.states=new Gn(this),this.head=this.tail=new Jt(Fn,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 Jt(Fn,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=Rc(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function jn(e,t,r){t[r]=e&255}function Uc(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Zn=class extends Jt{next;constructor(t,r){super(Uc,t,r),this.next=void 0}};function Er(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 je(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 Pc(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Ge.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Nc,t,e),this},Ge.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(kc,t,e),this});function Nc(e,t,r){t.set(e,r)}function kc(e,t,r){e.length<40?Mn(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(G(e),r)}function Wn(){return new Ge}function Qt(e,t){let r=Wn();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Ae;(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"})(Ae||(Ae={}));function Sr(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Ze(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 Sr("enum",Ae.VARINT,r,n)}function te(e,t){return Sr("message",Ae.LENGTH_DELIMITED,e,t)}var lt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(lt||(lt={}));var Yn;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Yn||(Yn={}));(function(e){e.codec=()=>Ze(Yn)})(lt||(lt={}));var Mt;(function(e){let t;e.codec=()=>(t==null&&(t=te((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),lt.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=lt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Qt(r,e.codec()),e.decode=(r,n)=>Xt(r,e.codec(),n)})(Mt||(Mt={}));var $n;(function(e){let t;e.codec=()=>(t==null&&(t=te((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),lt.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=lt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Qt(r,e.codec()),e.decode=(r,n)=>Xt(r,e.codec(),n)})($n||($n={}));var Ye={};ct(Ye,{MAX_RSA_KEY_SIZE:()=>Xn,generateRSAKeyPair:()=>$s,jwkToJWKKeyPair:()=>Xs,jwkToPkcs1:()=>qc,jwkToPkix:()=>eo,jwkToRSAPrivateKey:()=>no,pkcs1MessageToJwk:()=>Qn,pkcs1MessageToRSAPrivateKey:()=>ro,pkcs1ToJwk:()=>Mc,pkcs1ToRSAPrivateKey:()=>Ws,pkixMessageToJwk:()=>to,pkixMessageToRSAPublicKey:()=>vr,pkixToJwk:()=>Vc,pkixToRSAPublicKey:()=>Ys});var Ar=ur;var ve=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Ye.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return tt.createV1(114,this._multihash)}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:et(this.raw,t.raw)}verify(t,r,n){return Zs(this.jwk,r,t,n)}},We=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Ye.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:et(this.raw,t.raw)}sign(t,r){return Gs(this.jwk,t,r)}};var Xn=8192,Jn=18,Oc=1062,Hc=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Mc(e){let t=Et(e);return Qn(t)}function Qn(e){return{n:z(e[1],"base64url"),e:z(e[2],"base64url"),d:z(e[3],"base64url"),p:z(e[4],"base64url"),q:z(e[5],"base64url"),dp:z(e[6],"base64url"),dq:z(e[7],"base64url"),qi:z(e[8],"base64url"),kty:"RSA"}}function qc(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 W("JWK was missing components");return Rt([ut(Uint8Array.from([0])),ut(G(e.n,"base64url")),ut(G(e.e,"base64url")),ut(G(e.d,"base64url")),ut(G(e.p,"base64url")),ut(G(e.q,"base64url")),ut(G(e.dp,"base64url")),ut(G(e.dq,"base64url")),ut(G(e.qi,"base64url"))]).subarray()}function Vc(e){let t=Et(e,{offset:0});return to(t)}function to(e){let t=Et(e[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function eo(e){if(e.n==null||e.e==null)throw new W("JWK was missing components");return Rt([Hc,ir(Rt([ut(G(e.n,"base64url")),ut(G(e.e,"base64url"))]))]).subarray()}function Ws(e){let t=Et(e);return ro(t)}function ro(e){let t=Qn(e);return no(t)}function Ys(e,t){if(e.byteLength>=Oc)throw new ne("Key size is too large");let r=Et(e,{offset:0});return vr(r,e,t)}function vr(e,t,r){let n=to(e);if(r==null){let o=Ar(Mt.encode({Type:lt.RSA,Data:t}));r=mt(Jn,o)}return new ve(n,r)}function no(e){if(Qs(e)>Xn)throw new W("Key size is too large");let t=Xs(e),r=Ar(Mt.encode({Type:lt.RSA,Data:eo(t.publicKey)})),n=mt(Jn,r);return new We(t.privateKey,new ve(t.publicKey,n))}async function $s(e){if(e>Xn)throw new W("Key size is too large");let t=await Js(e),r=Ar(Mt.encode({Type:lt.RSA,Data:eo(t.publicKey)})),n=mt(Jn,r);return new We(t.privateKey,new ve(t.publicKey,n))}function Xs(e){if(e==null)throw new W("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var ti="1.2.840.113549.1.1.1";async function Js(e,t){let r=await pt.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 zc(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Gs(e,t,r){let n=await pt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await pt.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 Zs(e,t,r,n){let o=await pt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await pt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function zc(e,t){if(e.privateKey==null||e.publicKey==null)throw new W("Private and public key are required");let r=await Promise.all([pt.get().subtle.exportKey("jwk",e.privateKey),pt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Qs(e){if(e.kty!=="RSA")throw new W("invalid key type");if(e.n==null)throw new W("invalid key modulus");return G(e.n,"base64url").length*8}var Br=class extends de{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Fo(t);let n=ke(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),_t(s)}update(t){return me(this),this.iHash.update(t),this}digestInto(t){me(this),rt(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()}},oo=(e,t,r)=>new Br(e,t).update(r).digest();oo.create=(e,t)=>new Br(e,t);function ei(e){e.lowS!==void 0&&Dt("lowS",e.lowS),e.prehash!==void 0&&Dt("prehash",e.prehash)}var so=class extends Error{constructor(t=""){super(t)}},Kt={Err:so,_tlv:{encode:(e,t)=>{let{Err:r}=Kt;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=Ve(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Ve(o.length/2|128):"";return Ve(e)+s+o+t},decode(e,t){let{Err:r}=Kt,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 h=t.subarray(n,n+c);if(h.length!==c)throw new r("tlv.decode: length bytes not complete");if(h[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of h)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Kt;if(e<$e)throw new t("integer: negative integers are not allowed");let r=Ve(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}=Kt;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 be(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Kt,o=H("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:h,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(h)}},hexFromSig(e){let{_tlv:t,_int:r}=Kt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},$e=BigInt(0),Xe=BigInt(1),Fc=BigInt(2),Ir=BigInt(3),jc=BigInt(4);function Gc(e,t,r){function n(o){let s=e.sqr(o),i=e.mul(s,o);return e.add(e.add(i,e.mul(o,t)),r)}return n}function ri(e,t,r){let{BYTES:n}=e;function o(s){let i;if(typeof s=="bigint")i=s;else{let a=H("private key",s);if(t){if(!t.includes(a.length*2))throw new Error("invalid private key");let c=new Uint8Array(n);c.set(a,c.length-a.length),a=c}try{i=e.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof s}`)}}if(r&&(i=e.create(i)),!e.isValidNot0(i))throw new Error("invalid private key: out of range [1..N-1]");return i}return o}function Zc(e,t={}){let{Fp:r,Fn:n}=mr("weierstrass",e,t),{h:o,n:s}=e;Ot(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!r.is0(e.a)||typeof i.beta!="bigint"||typeof i.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(I,u,w){let{x:d,y}=u.toAffine(),g=r.toBytes(d);if(Dt("isCompressed",w),w){a();let _=!r.isOdd(y);return ht(ni(_),g)}else return ht(Uint8Array.of(4),g,r.toBytes(y))}function h(I){rt(I);let u=r.BYTES,w=u+1,d=2*u+1,y=I.length,g=I[0],_=I.subarray(1);if(y===w&&(g===2||g===3)){let v=r.fromBytes(_);if(!r.isValid(v))throw new Error("bad point: is not on curve, wrong x");let L=x(v),U;try{U=r.sqrt(L)}catch(k){let P=k instanceof Error?": "+k.message:"";throw new Error("bad point: is not on curve, sqrt error"+P)}a();let R=r.isOdd(U);return(g&1)===1!==R&&(U=r.neg(U)),{x:v,y:U}}else if(y===d&&g===4){let v=r.fromBytes(_.subarray(u*0,u*1)),L=r.fromBytes(_.subarray(u*1,u*2));if(!b(v,L))throw new Error("bad point: is not on curve");return{x:v,y:L}}else throw new Error(`bad point: got length ${y}, expected compressed=${w} or uncompressed=${d}`)}let f=t.toBytes||c,l=t.fromBytes||h,x=Gc(r,e.a,e.b);function b(I,u){let w=r.sqr(u),d=x(I);return r.eql(w,d)}if(!b(e.Gx,e.Gy))throw new Error("bad curve params: generator point");let S=r.mul(r.pow(e.a,Ir),jc),E=r.mul(r.sqr(e.b),BigInt(27));if(r.is0(r.add(S,E)))throw new Error("bad curve params: a or b");function m(I,u,w=!1){if(!r.isValid(u)||w&&r.is0(u))throw new Error(`bad point coordinate ${I}`);return u}function A(I){if(!(I instanceof p))throw new Error("ProjectivePoint expected")}let D=we((I,u)=>{let{px:w,py:d,pz:y}=I;if(r.eql(y,r.ONE))return{x:w,y:d};let g=I.is0();u==null&&(u=g?r.ONE:r.inv(y));let _=r.mul(w,u),v=r.mul(d,u),L=r.mul(y,u);if(g)return{x:r.ZERO,y:r.ZERO};if(!r.eql(L,r.ONE))throw new Error("invZ was invalid");return{x:_,y:v}}),B=we(I=>{if(I.is0()){if(t.allowInfinityPoint&&!r.is0(I.py))return;throw new Error("bad point: ZERO")}let{x:u,y:w}=I.toAffine();if(!r.isValid(u)||!r.isValid(w))throw new Error("bad point: x or y not field elements");if(!b(u,w))throw new Error("bad point: equation left != right");if(!I.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function C(I,u,w,d,y){return w=new p(r.mul(w.px,I),w.py,w.pz),u=ge(d,u),w=ge(y,w),u.add(w)}class p{constructor(u,w,d){this.px=m("x",u),this.py=m("y",w,!0),this.pz=m("z",d),Object.freeze(this)}static fromAffine(u){let{x:w,y:d}=u||{};if(!u||!r.isValid(w)||!r.isValid(d))throw new Error("invalid affine point");if(u instanceof p)throw new Error("projective point not allowed");return r.is0(w)&&r.is0(d)?p.ZERO:new p(w,d,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(u){return hr(p,"pz",u)}static fromBytes(u){return rt(u),p.fromHex(u)}static fromHex(u){let w=p.fromAffine(l(H("pointHex",u)));return w.assertValidity(),w}static fromPrivateKey(u){let w=ri(n,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return p.BASE.multiply(w(u))}static msm(u,w){return pr(p,n,u,w)}precompute(u=8,w=!0){return T.setWindowSize(this,u),w||this.multiply(Ir),this}_setWindowSize(u){this.precompute(u)}assertValidity(){B(this)}hasEvenY(){let{y:u}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(u)}equals(u){A(u);let{px:w,py:d,pz:y}=this,{px:g,py:_,pz:v}=u,L=r.eql(r.mul(w,v),r.mul(g,y)),U=r.eql(r.mul(d,v),r.mul(_,y));return L&&U}negate(){return new p(this.px,r.neg(this.py),this.pz)}double(){let{a:u,b:w}=e,d=r.mul(w,Ir),{px:y,py:g,pz:_}=this,v=r.ZERO,L=r.ZERO,U=r.ZERO,R=r.mul(y,y),F=r.mul(g,g),k=r.mul(_,_),P=r.mul(y,g);return P=r.add(P,P),U=r.mul(y,_),U=r.add(U,U),v=r.mul(u,U),L=r.mul(d,k),L=r.add(v,L),v=r.sub(F,L),L=r.add(F,L),L=r.mul(v,L),v=r.mul(P,v),U=r.mul(d,U),k=r.mul(u,k),P=r.sub(R,k),P=r.mul(u,P),P=r.add(P,U),U=r.add(R,R),R=r.add(U,R),R=r.add(R,k),R=r.mul(R,P),L=r.add(L,R),k=r.mul(g,_),k=r.add(k,k),R=r.mul(k,P),v=r.sub(v,R),U=r.mul(k,F),U=r.add(U,U),U=r.add(U,U),new p(v,L,U)}add(u){A(u);let{px:w,py:d,pz:y}=this,{px:g,py:_,pz:v}=u,L=r.ZERO,U=r.ZERO,R=r.ZERO,F=e.a,k=r.mul(e.b,Ir),P=r.mul(w,g),Z=r.mul(d,_),$=r.mul(y,v),Q=r.add(w,d),O=r.add(g,_);Q=r.mul(Q,O),O=r.add(P,Z),Q=r.sub(Q,O),O=r.add(w,y);let st=r.add(g,v);return O=r.mul(O,st),st=r.add(P,$),O=r.sub(O,st),st=r.add(d,y),L=r.add(_,v),st=r.mul(st,L),L=r.add(Z,$),st=r.sub(st,L),R=r.mul(F,O),L=r.mul(k,$),R=r.add(L,R),L=r.sub(Z,R),R=r.add(Z,R),U=r.mul(L,R),Z=r.add(P,P),Z=r.add(Z,P),$=r.mul(F,$),O=r.mul(k,O),Z=r.add(Z,$),$=r.sub(P,$),$=r.mul(F,$),O=r.add(O,$),P=r.mul(Z,O),U=r.add(U,P),P=r.mul(st,O),L=r.mul(Q,L),L=r.sub(L,P),P=r.mul(Q,Z),R=r.mul(st,R),R=r.add(R,P),new p(L,U,R)}subtract(u){return this.add(u.negate())}is0(){return this.equals(p.ZERO)}multiply(u){let{endo:w}=t;if(!n.isValidNot0(u))throw new Error("invalid scalar: out of range");let d,y,g=_=>T.wNAFCached(this,_,p.normalizeZ);if(w){let{k1neg:_,k1:v,k2neg:L,k2:U}=w.splitScalar(u),{p:R,f:F}=g(v),{p:k,f:P}=g(U);y=F.add(P),d=C(w.beta,R,k,_,L)}else{let{p:_,f:v}=g(u);d=_,y=v}return p.normalizeZ([d,y])[0]}multiplyUnsafe(u){let{endo:w}=t,d=this;if(!n.isValid(u))throw new Error("invalid scalar: out of range");if(u===$e||d.is0())return p.ZERO;if(u===Xe)return d;if(T.hasPrecomputes(this))return this.multiply(u);if(w){let{k1neg:y,k1:g,k2neg:_,k2:v}=w.splitScalar(u),{p1:L,p2:U}=Bs(p,d,g,v);return C(w.beta,L,U,y,_)}else return T.wNAFCachedUnsafe(d,u)}multiplyAndAddUnsafe(u,w,d){let y=this.multiplyUnsafe(w).add(u.multiplyUnsafe(d));return y.is0()?void 0:y}toAffine(u){return D(this,u)}isTorsionFree(){let{isTorsionFree:u}=t;return o===Xe?!0:u?u(p,this):T.wNAFCachedUnsafe(this,s).is0()}clearCofactor(){let{clearCofactor:u}=t;return o===Xe?this:u?u(p,this):this.multiplyUnsafe(o)}toBytes(u=!0){return Dt("isCompressed",u),this.assertValidity(),f(p,this,u)}toRawBytes(u=!0){return this.toBytes(u)}toHex(u=!0){return St(this.toBytes(u))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}p.BASE=new p(e.Gx,e.Gy,r.ONE),p.ZERO=new p(r.ZERO,r.ONE,r.ZERO),p.Fp=r,p.Fn=n;let K=n.BITS,T=dr(p,t.endo?Math.ceil(K/2):K);return p}function ni(e){return Uint8Array.of(e?2:3)}function Wc(e,t,r={}){Ot(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||Oe,o=t.hmac||((d,...y)=>oo(t.hash,d,ht(...y))),{Fp:s,Fn:i}=e,{ORDER:a,BITS:c}=i;function h(d){let y=a>>Xe;return d>y}function f(d){return h(d)?i.neg(d):d}function l(d,y){if(!i.isValidNot0(y))throw new Error(`invalid signature ${d}: out of range 1..CURVE.n`)}class x{constructor(y,g,_){l("r",y),l("s",g),this.r=y,this.s=g,_!=null&&(this.recovery=_),Object.freeze(this)}static fromCompact(y){let g=i.BYTES,_=H("compactSignature",y,g*2);return new x(i.fromBytes(_.subarray(0,g)),i.fromBytes(_.subarray(g,g*2)))}static fromDER(y){let{r:g,s:_}=Kt.toSig(H("DER",y));return new x(g,_)}assertValidity(){}addRecoveryBit(y){return new x(this.r,this.s,y)}recoverPublicKey(y){let g=s.ORDER,{r:_,s:v,recovery:L}=this;if(L==null||![0,1,2,3].includes(L))throw new Error("recovery id invalid");if(a*Fc<g&&L>1)throw new Error("recovery id is ambiguous for h>1 curve");let R=L===2||L===3?_+a:_;if(!s.isValid(R))throw new Error("recovery id 2 or 3 invalid");let F=s.toBytes(R),k=e.fromHex(ht(ni((L&1)===0),F)),P=i.inv(R),Z=B(H("msgHash",y)),$=i.create(-Z*P),Q=i.create(v*P),O=e.BASE.multiplyUnsafe($).add(k.multiplyUnsafe(Q));if(O.is0())throw new Error("point at infinify");return O.assertValidity(),O}hasHighS(){return h(this.s)}normalizeS(){return this.hasHighS()?new x(this.r,i.neg(this.s),this.recovery):this}toBytes(y){if(y==="compact")return ht(i.toBytes(this.r),i.toBytes(this.s));if(y==="der")return ye(Kt.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return St(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return St(this.toBytes("compact"))}}let b=ri(i,r.allowedPrivateKeyLengths,r.wrapPrivateKey),S={isValidPrivateKey(d){try{return b(d),!0}catch{return!1}},normPrivateKeyToScalar:b,randomPrivateKey:()=>{let d=a;return ws(n(Bn(d)),d)},precompute(d=8,y=e.BASE){return y.precompute(d,!1)}};function E(d,y=!0){return e.fromPrivateKey(d).toBytes(y)}function m(d){if(typeof d=="bigint")return!1;if(d instanceof e)return!0;let g=H("key",d).length,_=s.BYTES,v=_+1,L=2*_+1;if(!(r.allowedPrivateKeyLengths||i.BYTES===v))return g===v||g===L}function A(d,y,g=!0){if(m(d)===!0)throw new Error("first arg must be private key");if(m(y)===!1)throw new Error("second arg must be public key");return e.fromHex(y).multiply(b(d)).toBytes(g)}let D=t.bits2int||function(d){if(d.length>8192)throw new Error("input is too large");let y=be(d),g=d.length*8-c;return g>0?y>>BigInt(g):y},B=t.bits2int_modN||function(d){return i.create(D(d))},C=Zt(c);function p(d){return kt("num < 2^"+c,d,$e,C),i.toBytes(d)}function K(d,y,g=T){if(["recovered","canonical"].some(Q=>Q in g))throw new Error("sign() legacy options not supported");let{hash:_}=t,{lowS:v,prehash:L,extraEntropy:U}=g;v==null&&(v=!0),d=H("msgHash",d),ei(g),L&&(d=H("prehashed msgHash",_(d)));let R=B(d),F=b(y),k=[p(F),p(R)];if(U!=null&&U!==!1){let Q=U===!0?n(s.BYTES):U;k.push(H("extraEntropy",Q))}let P=ht(...k),Z=R;function $(Q){let O=D(Q);if(!i.isValidNot0(O))return;let st=i.inv(O),_e=e.BASE.multiply(O).toAffine(),ee=i.create(_e.x);if(ee===$e)return;let Vt=i.create(st*i.create(Z+ee*F));if(Vt===$e)return;let Hr=(_e.x===ee?0:2)|Number(_e.y&Xe),re=Vt;return v&&h(Vt)&&(re=f(Vt),Hr^=1),new x(ee,re,Hr)}return{seed:P,k2sig:$}}let T={lowS:t.lowS,prehash:!1},I={lowS:t.lowS,prehash:!1};function u(d,y,g=T){let{seed:_,k2sig:v}=K(d,y,g);return fs(t.hash.outputLen,i.BYTES,o)(_,v)}e.BASE.precompute(8);function w(d,y,g,_=I){let v=d;y=H("msgHash",y),g=H("publicKey",g),ei(_);let{lowS:L,prehash:U,format:R}=_;if("strict"in _)throw new Error("options.strict was renamed to lowS");if(R!==void 0&&!["compact","der","js"].includes(R))throw new Error('format must be "compact", "der" or "js"');let F=typeof v=="string"||pe(v),k=!F&&!R&&typeof v=="object"&&v!==null&&typeof v.r=="bigint"&&typeof v.s=="bigint";if(!F&&!k)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let P,Z;try{if(k)if(R===void 0||R==="js")P=new x(v.r,v.s);else throw new Error("invalid format");if(F){try{R!=="compact"&&(P=x.fromDER(v))}catch(re){if(!(re instanceof Kt.Err))throw re}!P&&R!=="der"&&(P=x.fromCompact(v))}Z=e.fromHex(g)}catch{return!1}if(!P||L&&P.hasHighS())return!1;U&&(y=t.hash(y));let{r:$,s:Q}=P,O=B(y),st=i.inv(Q),_e=i.create(O*st),ee=i.create($*st),Vt=e.BASE.multiplyUnsafe(_e).add(Z.multiplyUnsafe(ee));return Vt.is0()?!1:i.create(Vt.x)===$}return Object.freeze({getPublicKey:E,getSharedSecret:A,sign:u,verify:w,utils:S,Point:e,Signature:x})}function Yc(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=xt(t.n,e.nBitLength),o={Fp:r,Fn:n,allowedPrivateKeyLengths:e.allowedPrivateKeyLengths,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,wrapPrivateKey:e.wrapPrivateKey,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:o}}function $c(e){let{CURVE:t,curveOpts:r}=Yc(e),n={hash:e.hash,hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,ecdsaOpts:n}}function Xc(e,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:e})}function oi(e){let{CURVE:t,curveOpts:r,ecdsaOpts:n}=$c(e),o=Zc(t,r),s=Wc(o,n,r);return Xc(e,s)}function si(e,t){let r=n=>oi({...e,hash:n});return{...r(t),create:r}}var _r={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},wd=BigInt(0),Jc=BigInt(1),io=BigInt(2),ii=(e,t)=>(e+t/io)/t;function Qc(e){let t=_r.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),h=e*e*e%t,f=h*h*e%t,l=M(f,r,t)*f%t,x=M(l,r,t)*f%t,b=M(x,io,t)*h%t,S=M(b,o,t)*b%t,E=M(S,s,t)*S%t,m=M(E,a,t)*E%t,A=M(m,c,t)*m%t,D=M(A,a,t)*E%t,B=M(D,r,t)*f%t,C=M(B,i,t)*S%t,p=M(C,n,t)*h%t,K=M(p,io,t);if(!ao.eql(ao.sqr(K),e))throw new Error("Cannot find square root");return K}var ao=xt(_r.p,void 0,void 0,{sqrt:Qc}),Be=si({..._r,Fp:ao,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{let t=_r.n,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Jc*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,i=BigInt("0x100000000000000000000000000000000"),a=ii(s*e,t),c=ii(-n*e,t),h=q(e-a*r-c*o,t),f=q(-a*n-c*s,t),l=h>i,x=f>i;if(l&&(h=t-h),x&&(f=t-f),h>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:l,k1:h,k2neg:x,k2:f}}}},ur);var ai=33;function ci(e,t,r,n){let o=or.digest(r instanceof Uint8Array?r:r.subarray());if(xr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Be.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new Fe(String(s))});try{return n?.signal?.throwIfAborted(),Be.verify(t,o.digest,e)}catch(s){throw new Fe(String(s))}}var Lr=class{type="secp256k1";raw;_key;constructor(t){this._key=ui(t),this.raw=fi(this._key)}toMultihash(){return gt.digest(he(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:et(this.raw,t.raw)}verify(t,r,n){return ci(this._key,r,t,n)}};function li(e){return new Lr(e)}function fi(e){return Be.ProjectivePoint.fromHex(e).toRawBytes(!0)}function ui(e){try{return Be.ProjectivePoint.fromHex(e),e}catch(t){throw new ne(String(t))}}function hi(e){if(e.byteLength===Se)return Us(e);if(e.byteLength===ai)return li(e);let t=Et(e),r=t[1]?.[0];if(r===ko||r===Oo||r===Ho)return qo(t);if(t[0]?.[0]===ti)return vr(t,e);throw new W("Could not extract public key from raw bytes")}function he(e){return Mt.encode({Type:lt[e.type],Data:e.raw})}var di=Symbol.for("nodejs.util.inspect.custom"),tf=114,Je=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()})`}[qr]=!0;toString(){return this.string==null&&(this.string=j.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return tt.createV1(tf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return et(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return et(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[di](){return`PeerId(${this.toString()})`}},Dr=class extends Je{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Tr=class extends Je{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Kr=class extends Je{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},ef=2336,co=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=gt.digest(G(this.url))}[di](){return`PeerId(${this.url})`}[qr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return tt.createV1(ef,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};function pi(e){if(e.type==="Ed25519")return new Tr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Kr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Dr({multihash:e.toCID().multihash,publicKey:e});throw new De}function Ie(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Cr=class extends Error{type;code;constructor(t,r,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=r??"ABORT_ERR"}};async function Qe(e,t,r){if(t==null)return e;if(t.aborted)return e.catch(()=>{}),Promise.reject(new Cr(r?.errorMessage,r?.errorCode,r?.errorName));let n,o=new Cr(r?.errorMessage,r?.errorCode,r?.errorName);try{return await Promise.race([e,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var fo=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Ie(),this.haveNext=Ie()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Ie(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,r){await this._push(t,r)}async end(t,r){t!=null?await this.throw(t):await this._push(void 0,r)}async _push(t,r){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Ie(),await Qe(this.readNext.promise,r?.signal,r)}};function mi(){return new fo}var Rr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function yi(e,t){let r=mi();e.sink(r).catch(async i=>{await r.end(i)}),e.sink=async i=>{for await(let a of i)await r.push(a);await r.end()};let n=e.source;e.source[Symbol.iterator]!=null?n=e.source[Symbol.iterator]():e.source[Symbol.asyncIterator]!=null&&(n=e.source[Symbol.asyncIterator]());let o=new Y;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:c,value:h}=await Qe(n.next(),i?.signal);return c===!0?null:h}for(;o.byteLength<i.bytes;){let{value:c,done:h}=await Qe(n.next(),i?.signal);if(h===!0)throw new Rr("unexpected end of input");o.append(c)}let a=o.sublist(0,i.bytes);return o.consume(i.bytes),a},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await r.push(i,a):await r.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=e.source;e.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return e}}}var Ur=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Pr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Nr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function bi(e,t={}){let r=yi(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Tt(t.maxDataLength));let n=t?.lengthDecoder??Ns,o=t?.lengthEncoder??Ps;return{read:async i=>{let a=-1,c=new Y;for(;;){c.append(await r.read({...i,bytes:1}));try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new Ur("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Nr("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Pr("message length too long");return r.read({...i,bytes:a})},write:async(i,a)=>{await r.write(new Y(o(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new Y(...i.flatMap(h=>[o(h.byteLength),h]));await r.write(c,a)},unwrap:()=>r.unwrap()}}function xi(e,t){let r=bi(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 kr;(function(e){let t;e.codec=()=>(t==null&&(t=te((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.id!=null&&(n.uint32(10),n.bytes(r.id)),r.pubkey!=null&&(n.uint32(18),Or.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=Or.codec().decode(r,r.uint32(),{limits:o.limits?.pubkey});break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Qt(r,e.codec()),e.decode=(r,n)=>Xt(r,e.codec(),n)})(kr||(kr={}));var qt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(qt||(qt={}));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=()=>Ze(uo)})(qt||(qt={}));var Or;(function(e){let t;e.codec=()=>(t==null&&(t=te((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),qt.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:yt(0)},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=qt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Qt(r,e.codec()),e.decode=(r,n)=>Xt(r,e.codec(),n)})(Or||(Or={}));var rf="/plaintext/2.0.0",lo=class{protocol=rf;privateKey;log;constructor(t){this.privateKey=t.privateKey,this.log=t.logger.forComponent("libp2p:plaintext")}[Symbol.toStringTag]="@libp2p/plaintext";[ho]=["@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=xi(t).pb(kr);n("write pubkey exchange to peer %p",r?.remotePeer);let s=this.privateKey.publicKey,[,i]=await Promise.all([o.write({id:s.toMultihash().bytes,pubkey:{Type:qt[s.type],Data:s.raw}},r),o.read(r)]),a;try{if(i.pubkey==null)throw new oe("Public key missing");if(i.pubkey.Data.byteLength===0)throw new oe("Public key data too short");if(i.id==null)throw new oe("Remote id missing");let c=hi(i.pubkey.Data);if(a=pi(c),!et(a.toMultihash().bytes,i.id))throw new Le("Public key did not match id")}catch(c){throw n.error(c),new Le("Invalid public key - "+c.message)}if(r?.remotePeer!=null&&!a.equals(r?.remotePeer))throw new tr;return n("plaintext key exchange completed successfully with peer %p",a),{conn:o.unwrap().unwrap(),remotePeer:a}}};function nf(){return e=>new lo(e)}return Ai(of);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/esm/utils.js:
|