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