UNPKG

@libp2p/peer-id

Version:
2 lines • 94.2 kB
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPeerId = factory()}(typeof self !== 'undefined' ? self : this, function () { "use strict";var Libp2PPeerId=(()=>{var wr=Object.defineProperty;var Ts=Object.getOwnPropertyDescriptor;var Ds=Object.getOwnPropertyNames;var Cs=Object.prototype.hasOwnProperty;var rt=(e,t)=>{for(var r in t)wr(e,r,{get:t[r],enumerable:!0})},Us=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ds(t))!Cs.call(e,o)&&o!==r&&wr(e,o,{get:()=>t[o],enumerable:!(n=Ts(t,o))||n.enumerable});return e};var Ks=e=>Us(wr({},"__esModule",{value:!0}),e);var uc={};rt(uc,{peerIdFromCID:()=>Ls,peerIdFromMultihash:()=>Cn,peerIdFromPrivateKey:()=>ac,peerIdFromPublicKey:()=>_s,peerIdFromString:()=>ic});var Er=Symbol.for("@libp2p/peer-id");var pt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ve=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var ze=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Fe=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Zt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Ir={};rt(Ir,{base58btc:()=>F,base58flickr:()=>Ms});var pc=new Uint8Array(0);function Un(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function xt(e){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 Kn(e){return new TextEncoder().encode(e)}function Pn(e){return new TextDecoder().decode(e)}function Ps(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,f=e.charAt(0),l=Math.log(a)/Math.log(256),c=Math.log(256)/Math.log(a);function h(S){if(S instanceof Uint8Array||(ArrayBuffer.isView(S)?S=new Uint8Array(S.buffer,S.byteOffset,S.byteLength):Array.isArray(S)&&(S=Uint8Array.from(S))),!(S instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(S.length===0)return"";for(var E=0,m=0,A=0,T=S.length;A!==T&&S[A]===0;)A++,E++;for(var v=(T-A)*c+1>>>0,U=new Uint8Array(v);A!==T;){for(var p=S[A],C=0,D=v-1;(p!==0||C<m)&&D!==-1;D--,C++)p+=256*U[D]>>>0,U[D]=p%a>>>0,p=p/a>>>0;if(p!==0)throw new Error("Non-zero carry");m=C,A++}for(var I=v-m;I!==v&&U[I]===0;)I++;for(var u=f.repeat(E);I<v;++I)u+=e.charAt(U[I]);return u}function x(S){if(typeof S!="string")throw new TypeError("Expected String");if(S.length===0)return new Uint8Array;var E=0;if(S[E]!==" "){for(var m=0,A=0;S[E]===f;)m++,E++;for(var T=(S.length-E)*l+1>>>0,v=new Uint8Array(T);S[E];){var U=r[S.charCodeAt(E)];if(U===255)return;for(var p=0,C=T-1;(U!==0||p<A)&&C!==-1;C--,p++)U+=a*v[C]>>>0,v[C]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");A=p,E++}if(S[E]!==" "){for(var D=T-A;D!==T&&v[D]===0;)D++;for(var I=new Uint8Array(m+(T-D)),u=m;D!==T;)I[u++]=v[D++];return I}}}function b(S){var E=x(S);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:x,decode:b}}var Rs=Ps,Ns=Rs,Nn=Ns;var Sr=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")}},Ar=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 On(this,t)}},Br=class{decoders;constructor(t){this.decoders=t}or(t){return On(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 On(e,t){return new Br({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var vr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Sr(t,r,n),this.decoder=new Ar(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Yt({name:e,prefix:t,encode:r,decode:n}){return new vr(e,t,r,n)}function vt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Nn(r,e);return Yt({prefix:t,name:e,encode:n,decode:s=>xt(o(s))})}function Os(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,f=0;for(let l=0;l<o;++l){let c=t[e[l]];if(c===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|c,i+=r,i>=8&&(i-=8,s[f++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ks(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let f=0;f<e.length;++f)for(a=a<<8|e[f],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Hs(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function q({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Hs(n);return Yt({prefix:t,name:e,encode(s){return ks(s,n,r)},decode(s){return Os(s,o,r,e)}})}var F=vt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ms=vt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var _r={};rt(_r,{base32:()=>Wt,base32hex:()=>Fs,base32hexpad:()=>Gs,base32hexpadupper:()=>Zs,base32hexupper:()=>js,base32pad:()=>Vs,base32padupper:()=>zs,base32upper:()=>qs,base32z:()=>Ys});var Wt=q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),qs=q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Vs=q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),zs=q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Fs=q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),js=q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Gs=q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Zs=q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ys=q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Lr={};rt(Lr,{base36:()=>pe,base36upper:()=>Ws});var pe=vt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ws=vt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var $s=Mn,kn=128,Xs=127,Js=~Xs,Qs=Math.pow(2,31);function Mn(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Qs;)t[r++]=e&255|kn,e/=128;for(;e&Js;)t[r++]=e&255|kn,e>>>=7;return t[r]=e|0,Mn.bytes=r-n+1,t}var ti=Tr,ei=128,Hn=127;function Tr(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw Tr.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Hn)<<o:(i&Hn)*Math.pow(2,o),o+=7}while(i>=ei);return Tr.bytes=s-n,r}var ri=Math.pow(2,7),ni=Math.pow(2,14),oi=Math.pow(2,21),si=Math.pow(2,28),ii=Math.pow(2,35),ai=Math.pow(2,42),ci=Math.pow(2,49),fi=Math.pow(2,56),ui=Math.pow(2,63),hi=function(e){return e<ri?1:e<ni?2:e<oi?3:e<si?4:e<ii?5:e<ai?6:e<ci?7:e<fi?8:e<ui?9:10},li={encode:$s,decode:ti,encodingLength:hi},di=li,me=di;function ye(e,t=0){return[me.decode(e,t),me.decode.bytes]}function $t(e,t,r=0){return me.encode(e,t,r),t}function Xt(e){return me.encodingLength(e)}function Rt(e,t){let r=t.byteLength,n=Xt(e),o=n+Xt(r),s=new Uint8Array(o+r);return $t(e,s,0),$t(r,s,n),s.set(t,o),new Jt(e,r,t,s)}function be(e){let t=xt(e),[r,n]=ye(t),[o,s]=ye(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Jt(r,o,i,t)}function qn(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Un(e.bytes,r.bytes)}}var Jt=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Vn(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return mi(r,Dr(e),t??F.encoder);default:return yi(r,Dr(e),t??Wt.encoder)}}var zn=new WeakMap;function Dr(e){let t=zn.get(e);if(t==null){let r=new Map;return zn.set(e,r),r}return t}var J=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!==xe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==bi)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=Rt(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&&qn(t.multihash,n.multihash)}toString(t){return Vn(this,t)}toJSON(){return{"/":Vn(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??Fn(n,o,s.bytes))}else if(r[xi]===!0){let{version:n,multihash:o,code:s}=r,i=be(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!==xe)throw new Error(`Version 0 CID must use dag-pb (code: ${xe}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Fn(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,xe,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=xt(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 Jt(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[h,x]=ye(t.subarray(r));return r+=x,h},o=n(),s=xe;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),f=n(),l=r+f,c=l-i;return{version:o,codec:s,multihashCode:a,digestSize:f,multihashSize:c,size:l}}static parse(t,r){let[n,o]=pi(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 Dr(s).set(n,t),s}};function pi(e,t){switch(e[0]){case"Q":{let r=t??F;return[F.prefix,r.decode(`${F.prefix}${e}`)]}case F.prefix:{let r=t??F;return[F.prefix,r.decode(e)]}case Wt.prefix:{let r=t??Wt;return[Wt.prefix,r.decode(e)]}case pe.prefix:{let r=t??pe;return[pe.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 mi(e,t,r){let{prefix:n}=r;if(n!==F.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 yi(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 xe=112,bi=18;function Fn(e,t,r){let n=Xt(e),o=n+Xt(t),s=new Uint8Array(o+r.byteLength);return $t(e,s,0),$t(t,s,n),s.set(r,o),s}var xi=Symbol.for("@ipld/js-cid/CID");var Cr={};rt(Cr,{identity:()=>ft});var jn=0,gi="identity",Gn=xt;function wi(e){return Rt(jn,Gn(e))}var ft={code:jn,name:gi,encode:Gn,digest:wi};function ut(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function gt(e=0){return new Uint8Array(e)}function nt(e=0){return new Uint8Array(e)}function Ge(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=nt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Yn=Symbol.for("@achingbrain/uint8arraylist");function Zn(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 Ze(e){return!!e?.[Yn]}var ot=class e{bufs;length;[Yn]=!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(Ze(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(Ze(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=Zn(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Zn(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(Ze(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 Ge(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Ge(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,f=a+i.byteLength;if(o=f,t>=f)continue;let l=t>=a&&t<f,c=r>a&&r<=f;if(l&&c){if(t===a&&r===f){n.push(i);break}let h=t-a;n.push(i.subarray(h,h+(r-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(c){if(r===f){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Ze(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,f=this.byteLength-n.byteLength,l=n.byteLength-1,c;for(let h=r;h<=f;h+=c){c=0;for(let x=l;x>=0;x--){let b=this.get(h+x);if(n[x]!==b){c=Math.max(1,x-a[b]);break}}if(c===0)return h}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=nt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=gt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=gt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=gt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=nt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=gt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=gt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=gt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=gt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=gt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ut(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 Ur={};rt(Ur,{base10:()=>Ei});var Ei=vt({prefix:"9",name:"base10",alphabet:"0123456789"});var Kr={};rt(Kr,{base16:()=>Si,base16upper:()=>Ai});var Si=q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ai=q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Pr={};rt(Pr,{base2:()=>Bi});var Bi=q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Rr={};rt(Rr,{base256emoji:()=>Ti});var Wn=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}"),vi=Wn.reduce((e,t,r)=>(e[r]=t,e),[]),Ii=Wn.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function _i(e){return e.reduce((t,r)=>(t+=vi[r],t),"")}function Li(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ii[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Ti=Yt({prefix:"\u{1F680}",name:"base256emoji",encode:_i,decode:Li});var Nr={};rt(Nr,{base64:()=>Di,base64pad:()=>Ci,base64url:()=>Ui,base64urlpad:()=>Ki});var Di=q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ci=q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ui=q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ki=q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Or={};rt(Or,{base8:()=>Pi});var Pi=q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var kr={};rt(kr,{identity:()=>Ri});var Ri=Yt({prefix:"\0",name:"identity",encode:e=>Pn(e),decode:e=>Kn(e)});var Xc=new TextEncoder,Jc=new TextDecoder;var qr={};rt(qr,{sha256:()=>ge,sha512:()=>ki});function Mr({name:e,code:t,encode:r}){return new Hr(e,t,r)}var Hr=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?Rt(this.code,r):r.then(n=>Rt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Xn(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var ge=Mr({name:"sha2-256",code:18,encode:Xn("SHA-256")}),ki=Mr({name:"sha2-512",code:19,encode:Xn("SHA-512")});var Vr={...kr,...Pr,...Or,...Ur,...Kr,..._r,...Lr,...Ir,...Nr,...Rr},hf={...qr,...Cr};function Qn(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Jn=Qn("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),zr=Qn("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=nt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Hi={utf8:Jn,"utf-8":Jn,hex:Vr.base16,latin1:zr,ascii:zr,binary:zr,...Vr},Ye=Hi;function It(e,t="utf8"){let r=Ye[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function st(e,t="utf8"){let r=Ye[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Mi=parseInt("11111",2),Fr=parseInt("10000000",2),qi=parseInt("01111111",2),to={0:we,1:we,2:Vi,3:ji,4:Gi,5:Fi,6:zi,16:we,22:we,48:we};function jr(e,t={offset:0}){let r=e[t.offset]&Mi;if(t.offset++,to[r]!=null)return to[r](e,t);throw new Error("No decoder for tag "+r)}function Ee(e,t){let r=0;if((e[t.offset]&Fr)===Fr){let n=e[t.offset]&qi,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 we(e,t){Ee(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=jr(e,t);if(n===null)break;r.push(n)}return r}function Vi(e,t){let r=Ee(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 zi(e,t){let r=Ee(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,f=[];for(;t.offset<n;){let l=e[t.offset];if(t.offset++,f.push(l&127),l<128){f.reverse();let c=0;for(let h=0;h<f.length;h++)c+=f[h]<<h*7;a+=`.${c}`,f=[]}}return a}function Fi(e,t){return t.offset++,null}function ji(e,t){let r=Ee(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 Gi(e,t){let r=Ee(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Zi(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ot;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Gr(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Zi(e.byteLength);return new ot(Uint8Array.from([t.byteLength|Fr]),t)}function eo(e){let t=new ot,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ot(Uint8Array.from([2]),Gr(t),t)}function ro(e){let t=Uint8Array.from([0]),r=new ot(t,e);return new ot(Uint8Array.from([3]),Gr(r),r)}function We(e,t=48){let r=new ot;for(let n of e)r.append(n);return new ot(Uint8Array.from([t]),Gr(r),r)}async function no(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 Yi=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Wi=Uint8Array.from([6,5,43,129,4,0,34]),$i=Uint8Array.from([6,5,43,129,4,0,35]),Xi={ext:!0,kty:"EC",crv:"P-256"},Ji={ext:!0,kty:"EC",crv:"P-384"},Qi={ext:!0,kty:"EC",crv:"P-521"},Zr=32,Yr=48,Wr=66;function oo(e){let t=jr(e);return so(t)}function so(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Zr*2+1)return n=st(t.subarray(r,r+Zr),"base64url"),o=st(t.subarray(r+Zr),"base64url"),new te({...Xi,key_ops:["verify"],x:n,y:o});if(t.byteLength===Yr*2+1)return n=st(t.subarray(r,r+Yr),"base64url"),o=st(t.subarray(r+Yr),"base64url"),new te({...Ji,key_ops:["verify"],x:n,y:o});if(t.byteLength===Wr*2+1)return n=st(t.subarray(r,r+Wr),"base64url"),o=st(t.subarray(r+Wr),"base64url"),new te({...Qi,key_ops:["verify"],x:n,y:o});throw new pt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function io(e){return We([eo(Uint8Array.from([1])),We([ta(e.crv)],160),We([ro(new ot(Uint8Array.from([4]),It(e.x??"","base64url"),It(e.y??"","base64url")))],161)]).subarray()}function ta(e){if(e==="P-256")return Yi;if(e==="P-384")return Wi;if(e==="P-521")return $i;throw new pt(`Invalid curve ${e}`)}var te=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=io(this.jwk)),this._raw}toMultihash(){return ft.digest(ee(this))}toCID(){return J.createV1(114,this.toMultihash())}toString(){return F.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}async verify(t,r,n){return no(this.jwk,r,t,n)}};var Nt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function ne(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Se(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function W(e,...t){if(!ne(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function co(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Se(e.outputLen),Se(e.blockLen)}function oe(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 fo(e,t){W(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Et(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function $e(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function ht(e,t){return e<<32-t|e>>>t}var uo=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ea=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function mt(e){if(W(e),uo)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=ea[e[r]];return t}var wt={_0:48,_9:57,A:65,F:70,a:97,f:102};function ao(e){if(e>=wt._0&&e<=wt._9)return e-wt._0;if(e>=wt.A&&e<=wt.F)return e-(wt.A-10);if(e>=wt.a&&e<=wt.f)return e-(wt.a-10)}function se(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(uo)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=ao(e.charCodeAt(s)),a=ao(e.charCodeAt(s+1));if(i===void 0||a===void 0){let f=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+f+'" at index '+s)}n[o]=i*16+a}return n}function ho(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Ae(e){return typeof e=="string"&&(e=ho(e)),W(e),e}function it(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];W(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var re=class{};function $r(e){let t=n=>e().update(Ae(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Be(e=32){if(Nt&&typeof Nt.getRandomValues=="function")return Nt.getRandomValues(new Uint8Array(e));if(Nt&&typeof Nt.randomBytes=="function")return Uint8Array.from(Nt.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function ra(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),a=Number(r&s),f=n?4:0,l=n?0:4;e.setUint32(t+f,i,n),e.setUint32(t+l,a,n)}function lo(e,t,r){return e&t^~e&r}function po(e,t,r){return e&t^e&r^t&r}var ve=class extends re{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=$e(this.buffer)}update(t){oe(this),t=Ae(t),W(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let f=$e(t);for(;o<=s-i;i+=o)this.process(f,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){oe(this),fo(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Et(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let h=i;h<o;h++)r[h]=0;ra(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=$e(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=f/4,c=this.get();if(l>c.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<l;h++)a.setUint32(4*h,c[h],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},St=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Z=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Xe=BigInt(4294967295),mo=BigInt(32);function na(e,t=!1){return t?{h:Number(e&Xe),l:Number(e>>mo&Xe)}:{h:Number(e>>mo&Xe)|0,l:Number(e&Xe)|0}}function yo(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}=na(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Xr=(e,t,r)=>e>>>r,Jr=(e,t,r)=>e<<32-r|t>>>r,Ot=(e,t,r)=>e>>>r|t<<32-r,kt=(e,t,r)=>e<<32-r|t>>>r,Ie=(e,t,r)=>e<<64-r|t>>>r-32,_e=(e,t,r)=>e>>>r-32|t<<64-r;function yt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var bo=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),xo=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,go=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),wo=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Eo=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),So=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var sa=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]),_t=new Uint32Array(64),Qr=class extends ve{constructor(t=32){super(64,t,8,!1),this.A=St[0]|0,this.B=St[1]|0,this.C=St[2]|0,this.D=St[3]|0,this.E=St[4]|0,this.F=St[5]|0,this.G=St[6]|0,this.H=St[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:f}=this;return[t,r,n,o,s,i,a,f]}set(t,r,n,o,s,i,a,f){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=f|0}process(t,r){for(let h=0;h<16;h++,r+=4)_t[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){let x=_t[h-15],b=_t[h-2],S=ht(x,7)^ht(x,18)^x>>>3,E=ht(b,17)^ht(b,19)^b>>>10;_t[h]=E+_t[h-7]+S+_t[h-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:f,G:l,H:c}=this;for(let h=0;h<64;h++){let x=ht(a,6)^ht(a,11)^ht(a,25),b=c+x+lo(a,f,l)+sa[h]+_t[h]|0,E=(ht(n,2)^ht(n,13)^ht(n,22))+po(n,o,s)|0;c=l,l=f,f=a,a=i+b|0,i=s,s=o,o=n,n=b+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,f=f+this.F|0,l=l+this.G|0,c=c+this.H|0,this.set(n,o,s,i,a,f,l,c)}roundClean(){Et(_t)}destroy(){this.set(0,0,0,0,0,0,0,0),Et(this.buffer)}};var Ao=yo(["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))),ia=Ao[0],aa=Ao[1],Lt=new Uint32Array(80),Tt=new Uint32Array(80),tn=class extends ve{constructor(t=64){super(128,t,16,!1),this.Ah=Z[0]|0,this.Al=Z[1]|0,this.Bh=Z[2]|0,this.Bl=Z[3]|0,this.Ch=Z[4]|0,this.Cl=Z[5]|0,this.Dh=Z[6]|0,this.Dl=Z[7]|0,this.Eh=Z[8]|0,this.El=Z[9]|0,this.Fh=Z[10]|0,this.Fl=Z[11]|0,this.Gh=Z[12]|0,this.Gl=Z[13]|0,this.Hh=Z[14]|0,this.Hl=Z[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:f,Eh:l,El:c,Fh:h,Fl:x,Gh:b,Gl:S,Hh:E,Hl:m}=this;return[t,r,n,o,s,i,a,f,l,c,h,x,b,S,E,m]}set(t,r,n,o,s,i,a,f,l,c,h,x,b,S,E,m){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=f|0,this.Eh=l|0,this.El=c|0,this.Fh=h|0,this.Fl=x|0,this.Gh=b|0,this.Gl=S|0,this.Hh=E|0,this.Hl=m|0}process(t,r){for(let v=0;v<16;v++,r+=4)Lt[v]=t.getUint32(r),Tt[v]=t.getUint32(r+=4);for(let v=16;v<80;v++){let U=Lt[v-15]|0,p=Tt[v-15]|0,C=Ot(U,p,1)^Ot(U,p,8)^Xr(U,p,7),D=kt(U,p,1)^kt(U,p,8)^Jr(U,p,7),I=Lt[v-2]|0,u=Tt[v-2]|0,g=Ot(I,u,19)^Ie(I,u,61)^Xr(I,u,6),d=kt(I,u,19)^_e(I,u,61)^Jr(I,u,6),y=go(D,d,Tt[v-7],Tt[v-16]),w=wo(y,C,g,Lt[v-7],Lt[v-16]);Lt[v]=w|0,Tt[v]=y|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:f,Dh:l,Dl:c,Eh:h,El:x,Fh:b,Fl:S,Gh:E,Gl:m,Hh:A,Hl:T}=this;for(let v=0;v<80;v++){let U=Ot(h,x,14)^Ot(h,x,18)^Ie(h,x,41),p=kt(h,x,14)^kt(h,x,18)^_e(h,x,41),C=h&b^~h&E,D=x&S^~x&m,I=Eo(T,p,D,aa[v],Tt[v]),u=So(I,A,U,C,ia[v],Lt[v]),g=I|0,d=Ot(n,o,28)^Ie(n,o,34)^Ie(n,o,39),y=kt(n,o,28)^_e(n,o,34)^_e(n,o,39),w=n&s^n&a^s&a,_=o&i^o&f^i&f;A=E|0,T=m|0,E=b|0,m=S|0,b=h|0,S=x|0,{h,l:x}=yt(l|0,c|0,u|0,g|0),l=a|0,c=f|0,a=s|0,f=i|0,s=n|0,i=o|0;let B=bo(g,y,_);n=xo(B,u,d,w),o=B|0}({h:n,l:o}=yt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=yt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:f}=yt(this.Ch|0,this.Cl|0,a|0,f|0),{h:l,l:c}=yt(this.Dh|0,this.Dl|0,l|0,c|0),{h,l:x}=yt(this.Eh|0,this.El|0,h|0,x|0),{h:b,l:S}=yt(this.Fh|0,this.Fl|0,b|0,S|0),{h:E,l:m}=yt(this.Gh|0,this.Gl|0,E|0,m|0),{h:A,l:T}=yt(this.Hh|0,this.Hl|0,A|0,T|0),this.set(n,o,s,i,a,f,l,c,h,x,b,S,E,m,A,T)}roundClean(){Et(Lt,Tt)}destroy(){Et(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Bo=$r(()=>new Qr);var vo=$r(()=>new tn);var nn=BigInt(0),rn=BigInt(1);function At(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}function Le(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Io(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?nn:BigInt("0x"+e)}function ie(e){return Io(mt(e))}function Ht(e){return W(e),Io(mt(Uint8Array.from(e).reverse()))}function Je(e,t){return se(e.toString(16).padStart(t*2,"0"))}function ae(e,t){return Je(e,t).reverse()}function k(e,t,r){let n;if(typeof t=="string")try{n=se(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(ne(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}var en=e=>typeof e=="bigint"&&nn<=e;function _o(e,t,r){return en(e)&&en(t)&&en(r)&&t<=e&&e<r}function Dt(e,t,r,n){if(!_o(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Lo(e){let t;for(t=0;e>nn;e>>=rn,t+=1);return t}var Mt=e=>(rn<<BigInt(e))-rn;function To(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=b=>new Uint8Array(b),o=b=>Uint8Array.of(b),s=n(e),i=n(e),a=0,f=()=>{s.fill(1),i.fill(0),a=0},l=(...b)=>r(i,s,...b),c=(b=n(0))=>{i=l(o(0),b),s=l(),b.length!==0&&(i=l(o(1),b),s=l())},h=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let b=0,S=[];for(;b<t;){s=l();let E=s.slice();S.push(E),b+=s.length}return it(...S)};return(b,S)=>{f(),c(b);let E;for(;!(E=S(h()));)c();return f(),E}}function Ct(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let a=e[o];if(i&&a===void 0)return;let f=typeof a;if(f!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${f}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}function ce(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 Q=BigInt(0),G=BigInt(1),qt=BigInt(2),ca=BigInt(3),Uo=BigInt(4),Ko=BigInt(5),Po=BigInt(8);function M(e,t){let r=e%t;return r>=Q?r:t+r}function H(e,t,r){let n=e;for(;t-- >Q;)n*=n,n%=r;return n}function Do(e,t){if(e===Q)throw new Error("invert: expected non-zero number");if(t<=Q)throw new Error("invert: expected positive modulus, got "+t);let r=M(e,t),n=t,o=Q,s=G,i=G,a=Q;for(;r!==Q;){let l=n/r,c=n%r,h=o-i*l,x=s-a*l;n=r,r=c,o=i,s=a,i=h,a=x}if(n!==G)throw new Error("invert: does not exist");return M(o,t)}function Ro(e,t){let r=(e.ORDER+G)/Uo,n=e.pow(t,r);if(!e.eql(e.sqr(n),t))throw new Error("Cannot find square root");return n}function fa(e,t){let r=(e.ORDER-Ko)/Po,n=e.mul(t,qt),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,qt),o),a=e.mul(s,e.sub(i,e.ONE));if(!e.eql(e.sqr(a),t))throw new Error("Cannot find square root");return a}function ua(e){if(e<BigInt(3))throw new Error("sqrt is not defined for small field");let t=e-G,r=0;for(;t%qt===Q;)t/=qt,r++;let n=qt,o=lt(e);for(;Co(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ro;let s=o.pow(n,t),i=(t+G)/qt;return function(f,l){if(f.is0(l))return l;if(Co(f,l)!==1)throw new Error("Cannot find square root");let c=r,h=f.mul(f.ONE,s),x=f.pow(l,t),b=f.pow(l,i);for(;!f.eql(x,f.ONE);){if(f.is0(x))return f.ZERO;let S=1,E=f.sqr(x);for(;!f.eql(E,f.ONE);)if(S++,E=f.sqr(E),S===c)throw new Error("Cannot find square root");let m=G<<BigInt(c-S-1),A=f.pow(h,m);c=S,h=f.sqr(A),x=f.mul(x,h),b=f.mul(b,A)}return b}}function ha(e){return e%Uo===ca?Ro:e%Po===Ko?fa:ua(e)}var No=(e,t)=>(M(e,t)&G)===G,la=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function on(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=la.reduce((n,o)=>(n[o]="function",n),t);return Ct(e,r),e}function da(e,t,r){if(r<Q)throw new Error("invalid exponent, negatives unsupported");if(r===Q)return e.ONE;if(r===G)return t;let n=e.ONE,o=t;for(;r>Q;)r&G&&(n=e.mul(n,o)),o=e.sqr(o),r>>=G;return n}function Te(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,f)=>e.is0(a)?i:(n[f]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,f)=>e.is0(a)?i:(n[f]=e.mul(i,n[f]),e.mul(i,a)),s),n}function Co(e,t){let r=(e.ORDER-G)/qt,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Oo(e,t){t!==void 0&&Se(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function lt(e,t,r=!1,n={}){if(e<=Q)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let c=t;c.BITS&&(o=c.BITS),c.sqrt&&(s=c.sqrt),typeof c.isLE=="boolean"&&(r=c.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=Oo(e,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f,l=Object.freeze({ORDER:e,isLE:r,BITS:i,BYTES:a,MASK:Mt(i),ZERO:Q,ONE:G,create:c=>M(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return Q<=c&&c<e},is0:c=>c===Q,isValidNot0:c=>!l.is0(c)&&l.isValid(c),isOdd:c=>(c&G)===G,neg:c=>M(-c,e),eql:(c,h)=>c===h,sqr:c=>M(c*c,e),add:(c,h)=>M(c+h,e),sub:(c,h)=>M(c-h,e),mul:(c,h)=>M(c*h,e),pow:(c,h)=>da(l,c,h),div:(c,h)=>M(c*Do(h,e),e),sqrN:c=>c*c,addN:(c,h)=>c+h,subN:(c,h)=>c-h,mulN:(c,h)=>c*h,inv:c=>Do(c,e),sqrt:s||(c=>(f||(f=ha(e)),f(l,c))),toBytes:c=>r?ae(c,a):Je(c,a),fromBytes:c=>{if(c.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+c.length);return r?Ht(c):ie(c)},invertBatch:c=>Te(l,c),cmov:(c,h,x)=>x?h:c});return Object.freeze(l)}function ko(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 sn(e){let t=ko(e);return t+Math.ceil(t/2)}function Ho(e,t,r=!1){let n=e.length,o=ko(t),s=sn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Ht(e):ie(e),a=M(i,t-G)+G;return r?ae(a,o):Je(a,o)}var ue=BigInt(0),Vt=BigInt(1);function fe(e,t){let r=t.negate();return e?r:t}function Qe(e,t,r){let n=t==="pz"?i=>i.pz:i=>i.ez,o=Te(e.Fp,r.map(n));return r.map((i,a)=>i.toAffine(o[a])).map(e.fromAffine)}function zo(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function an(e,t){zo(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Mt(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Mo(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),f=e>>i;a>n&&(a-=s,f+=Vt);let l=t*n,c=l+Math.abs(a)-1,h=a===0,x=a<0,b=t%2!==0;return{nextN:f,offset:c,isZero:h,isNeg:x,isNegF:b,offsetF:l}}function pa(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function ma(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var cn=new WeakMap,Fo=new WeakMap;function fn(e){return Fo.get(e)||1}function qo(e){if(e!==ue)throw new Error("invalid wNAF")}function tr(e,t){return{constTimeNegate:fe,hasPrecomputes(r){return fn(r)!==1},unsafeLadder(r,n,o=e.ZERO){let s=r;for(;n>ue;)n&Vt&&(o=o.add(s)),s=s.double(),n>>=Vt;return o},precomputeWindow(r,n){let{windows:o,windowSize:s}=an(n,t),i=[],a=r,f=a;for(let l=0;l<o;l++){f=a,i.push(f);for(let c=1;c<s;c++)f=f.add(a),i.push(f);a=f.double()}return i},wNAF(r,n,o){let s=e.ZERO,i=e.BASE,a=an(r,t);for(let f=0;f<a.windows;f++){let{nextN:l,offset:c,isZero:h,isNeg:x,isNegF:b,offsetF:S}=Mo(o,f,a);o=l,h?i=i.add(fe(b,n[S])):s=s.add(fe(x,n[c]))}return qo(o),{p:s,f:i}},wNAFUnsafe(r,n,o,s=e.ZERO){let i=an(r,t);for(let a=0;a<i.windows&&o!==ue;a++){let{nextN:f,offset:l,isZero:c,isNeg:h}=Mo(o,a,i);if(o=f,!c){let x=n[l];s=s.add(h?x.negate():x)}}return qo(o),s},getPrecomputes(r,n,o){let s=cn.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&(typeof o=="function"&&(s=o(s)),cn.set(n,s))),s},wNAFCached(r,n,o){let s=fn(r);return this.wNAF(s,this.getPrecomputes(s,r,o),n)},wNAFCachedUnsafe(r,n,o,s){let i=fn(r);return i===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,r,o),n,s)},setWindowSize(r,n){zo(n,t),Fo.set(r,n),cn.delete(r)}}}function jo(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>ue||n>ue;)r&Vt&&(s=s.add(o)),n&Vt&&(i=i.add(o)),o=o.double(),r>>=Vt,n>>=Vt;return{p1:s,p2:i}}function er(e,t,r,n){pa(r,e),ma(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,a=Lo(BigInt(o)),f=1;a>12?f=a-3:a>4?f=a-2:a>0&&(f=2);let l=Mt(f),c=new Array(Number(l)+1).fill(i),h=Math.floor((t.BITS-1)/f)*f,x=i;for(let b=h;b>=0;b-=f){c.fill(i);for(let E=0;E<s;E++){let m=n[E],A=Number(m>>BigInt(b)&l);c[A]=c[A].add(r[E])}let S=i;for(let E=c.length-1,m=i;E>0;E--)m=m.add(c[E]),S=S.add(m);if(x=x.add(S),b!==0)for(let E=0;E<f;E++)x=x.double()}return x}function Vo(e,t){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return on(t),t}else return lt(e)}function rr(e,t,r={}){if(!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let f=t[a];if(!(typeof f=="bigint"&&f>ue))throw new Error(`CURVE.${a} must be positive bigint`)}let n=Vo(t.p,r.Fp),o=Vo(t.n,r.Fn),i=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var bt=BigInt(0),tt=BigInt(1),un=BigInt(2),ya=BigInt(8),ba={zip215:!0};function xa(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)}functi