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