UNPKG

@chainsafe/libp2p-noise

Version:
2 lines 136 kB
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.ChainsafeLibp2PNoise = factory()}(typeof self !== 'undefined' ? self : this, function () { "use strict";var ChainsafeLibp2PNoise=(()=>{var pn=Object.defineProperty;var qa=Object.getOwnPropertyDescriptor;var Va=Object.getOwnPropertyNames;var Fa=Object.prototype.hasOwnProperty;var Et=(r,t)=>{for(var e in t)pn(r,e,{get:t[e],enumerable:!0})},za=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Va(t))!Fa.call(r,o)&&o!==e&&pn(r,o,{get:()=>t[o],enumerable:!(n=qa(t,o))||n.enumerable});return r};var Ga=r=>za(pn({},"__esModule",{value:!0}),r);var lh={};Et(lh,{noise:()=>hh,pureJsCrypto:()=>un});var mn=Symbol.for("@libp2p/peer-id");var br=class extends Error{static name="UnexpectedPeerError";constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError"}},wr=class extends Error{static name="InvalidCryptoExchangeError";constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError"}},ot=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},we=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Ee=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ws=Symbol.for("@libp2p/service-capabilities"),yh=Symbol.for("@libp2p/service-dependencies");var wn={};Et(wn,{base58btc:()=>nt,base58flickr:()=>$a});var Oh=new Uint8Array(0);function Es(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function kt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Ss(r){return new TextEncoder().encode(r)}function As(r){return new TextDecoder().decode(r)}function ja(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var m=0,h=0,g=0,b=w.length;g!==b&&w[g]===0;)g++,m++;for(var d=(b-g)*f+1>>>0,v=new Uint8Array(d);g!==b;){for(var R=w[g],K=0,I=d-1;(R!==0||K<h)&&I!==-1;I--,K++)R+=256*v[I]>>>0,v[I]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");h=K,g++}for(var T=d-h;T!==d&&v[T]===0;)T++;for(var B=c.repeat(m);T<d;++T)B+=r.charAt(v[T]);return B}function p(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var m=0;if(w[m]!==" "){for(var h=0,g=0;w[m]===c;)h++,m++;for(var b=(w.length-m)*u+1>>>0,d=new Uint8Array(b);w[m];){var v=e[w.charCodeAt(m)];if(v===255)return;for(var R=0,K=b-1;(v!==0||R<g)&&K!==-1;K--,R++)v+=a*d[K]>>>0,d[K]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");g=R,m++}if(w[m]!==" "){for(var I=b-g;I!==b&&d[I]===0;)I++;for(var T=new Uint8Array(h+(b-I)),B=h;I!==b;)T[B++]=d[I++];return T}}}function S(w){var m=p(w);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:p,decode:S}}var Za=ja,Ya=Za,Bs=Ya;var yn=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},xn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.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 Ls(this,t)}},gn=class{decoders;constructor(t){this.decoders=t}or(t){return Ls(this,t)}decode(t){let e=t[0],n=this.decoders[e];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 Ls(r,t){return new gn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var bn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new yn(t,e,n),this.decoder=new xn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Se({name:r,prefix:t,encode:e,decode:n}){return new bn(r,t,e,n)}function jt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Bs(e,r);return Se({prefix:t,name:r,encode:n,decode:s=>kt(o(s))})}function Wa(r,t,e,n){let o={};for(let f=0;f<t.length;++f)o[t[f]]=f;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),a=0,c=0,u=0;for(let f=0;f<s;++f){let l=o[r[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|l,a+=e,a>=8&&(a-=8,i[u++]=255&c>>a)}if(a>=e||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return i}function Xa(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function rt({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Se({prefix:t,name:r,encode(o){return Xa(o,n,e)},decode(o){return Wa(o,n,e,r)}})}var nt=jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),$a=jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var En={};Et(En,{base32:()=>Ae,base32hex:()=>ec,base32hexpad:()=>nc,base32hexpadupper:()=>oc,base32hexupper:()=>rc,base32pad:()=>Qa,base32padupper:()=>tc,base32upper:()=>Ja,base32z:()=>sc});var Ae=rt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ja=rt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Qa=rt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),tc=rt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ec=rt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),rc=rt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),nc=rt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),oc=rt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),sc=rt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Sn={};Et(Sn,{base36:()=>Ge,base36upper:()=>ic});var Ge=jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ic=jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ac=Cs,_s=128,cc=127,fc=~cc,uc=Math.pow(2,31);function Cs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=uc;)t[e++]=r&255|_s,r/=128;for(;r&fc;)t[e++]=r&255|_s,r>>>=7;return t[e]=r|0,Cs.bytes=e-n+1,t}var hc=An,lc=128,Is=127;function An(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw An.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Is)<<o:(i&Is)*Math.pow(2,o),o+=7}while(i>=lc);return An.bytes=s-n,e}var dc=Math.pow(2,7),pc=Math.pow(2,14),mc=Math.pow(2,21),yc=Math.pow(2,28),xc=Math.pow(2,35),gc=Math.pow(2,42),bc=Math.pow(2,49),wc=Math.pow(2,56),Ec=Math.pow(2,63),Sc=function(r){return r<dc?1:r<pc?2:r<mc?3:r<yc?4:r<xc?5:r<gc?6:r<bc?7:r<wc?8:r<Ec?9:10},Ac={encode:ac,decode:hc,encodingLength:Sc},vc=Ac,je=vc;function Ze(r,t=0){return[je.decode(r,t),je.decode.bytes]}function ve(r,t,e=0){return je.encode(r,t,e),t}function Be(r){return je.encodingLength(r)}function _t(r,t){let e=t.byteLength,n=Be(r),o=n+Be(e),s=new Uint8Array(o+e);return ve(r,s,0),ve(e,s,n),s.set(t,o),new Le(r,e,t,s)}function vn(r){let t=kt(r),[e,n]=Ze(t),[o,s]=Ze(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Le(e,o,i,t)}function Ts(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Es(r.bytes,e.bytes)}}var Le=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Ks(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Lc(e,Bn(r),t??nt.encoder);default:return _c(e,Bn(r),t??Ae.encoder)}}var Us=new WeakMap;function Bn(r){let t=Us.get(r);if(t==null){let e=new Map;return Us.set(r,e),e}return t}var dt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,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:e}=this;if(t!==Ye)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ic)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:e}=this.multihash,n=_t(t,e);return r.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 r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Ts(t.multihash,n.multihash)}toString(t){return Ks(this,t)}toJSON(){return{"/":Ks(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 e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??Rs(n,o,s.bytes))}else if(e[Cc]===!0){let{version:n,multihash:o,code:s}=e,i=vn(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="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(e!==Ye)throw new Error(`Version 0 CID must use dag-pb (code: ${Ye}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Rs(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ye,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=kt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Le(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,p]=Ze(t.subarray(e));return e+=p,l},o=n(),s=Ye;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),u=e+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,e){let[n,o]=Bc(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Bn(s).set(n,t),s}};function Bc(r,t){switch(r[0]){case"Q":{let e=t??nt;return[nt.prefix,e.decode(`${nt.prefix}${r}`)]}case nt.prefix:{let e=t??nt;return[nt.prefix,e.decode(r)]}case Ae.prefix:{let e=t??Ae;return[Ae.prefix,e.decode(r)]}case Ge.prefix:{let e=t??Ge;return[Ge.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Lc(r,t,e){let{prefix:n}=e;if(n!==nt.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function _c(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Ye=112,Ic=18;function Rs(r,t,e){let n=Be(r),o=n+Be(t),s=new Uint8Array(o+e.byteLength);return ve(r,s,0),ve(t,s,n),s.set(e,o),s}var Cc=Symbol.for("@ipld/js-cid/CID");var Ln={};Et(Ln,{identity:()=>Rt});var Ps=0,Tc="identity",Ds=kt;function Kc(r){return _t(Ps,Ds(r))}var Rt={code:Ps,name:Tc,encode:Ds,digest:Kc};function gt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function st(r=0){return new Uint8Array(r)}function it(r=0){return new Uint8Array(r)}function ie(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=it(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ks=Symbol.for("@achingbrain/uint8arraylist");function Ns(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Sr(r){return!!r?.[ks]}var Z=class r{bufs;length;[ks]=!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 e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Sr(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Sr(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Ns(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ns(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Sr(t))for(let n=0;n<t.length;n++)this.set(e+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,e){let{bufs:n,length:o}=this._subList(t,e);return ie(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:ie(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,f=e>a&&e<=c;if(u&&f){if(t===a&&e===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Sr(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(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=e;l<=c;l+=f){f=0;for(let p=u;p>=0;p--){let S=this.get(l+p);if(n[p]!==S){f=Math.max(1,p-a[S]);break}}if(f===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=it(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=st(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=st(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=st(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=it(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=st(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=st(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=st(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=st(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=st(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!gt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var _n={};Et(_n,{base10:()=>Rc});var Rc=jt({prefix:"9",name:"base10",alphabet:"0123456789"});var In={};Et(In,{base16:()=>Pc,base16upper:()=>Dc});var Pc=rt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Dc=rt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Cn={};Et(Cn,{base2:()=>Nc});var Nc=rt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Tn={};Et(Tn,{base256emoji:()=>qc});var Ms=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}"),kc=Ms.reduce((r,t,e)=>(r[e]=t,r),[]),Mc=Ms.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Oc(r){return r.reduce((t,e)=>(t+=kc[e],t),"")}function Hc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Mc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var qc=Se({prefix:"\u{1F680}",name:"base256emoji",encode:Oc,decode:Hc});var Kn={};Et(Kn,{base64:()=>Vc,base64pad:()=>Fc,base64url:()=>zc,base64urlpad:()=>Gc});var Vc=rt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Fc=rt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),zc=rt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Gc=rt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Un={};Et(Un,{base8:()=>jc});var jc=rt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Rn={};Et(Rn,{identity:()=>Zc});var Zc=Se({prefix:"\0",name:"identity",encode:r=>As(r),decode:r=>Ss(r)});var El=new TextEncoder,Sl=new TextDecoder;var Nn={};Et(Nn,{sha256:()=>Ar,sha512:()=>Xc});function Dn({name:r,code:t,encode:e}){return new Pn(r,t,e)}var Pn=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?_t(this.code,e):e.then(n=>_t(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Hs(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Ar=Dn({name:"sha2-256",code:18,encode:Hs("SHA-256")}),Xc=Dn({name:"sha2-512",code:19,encode:Hs("SHA-512")});var kn={...Rn,...Cn,...Un,..._n,...In,...En,...Sn,...wn,...Kn,...Tn},Pl={...Nn,...Ln};function Vs(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var qs=Vs("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Mn=Vs("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=it(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),$c={utf8:qs,"utf-8":qs,hex:kn.base16,latin1:Mn,ascii:Mn,binary:Mn,...kn},vr=$c;function $(r,t="utf8"){let e=vr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function G(r,t="utf8"){let e=vr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Jc=parseInt("11111",2),On=parseInt("10000000",2),Qc=parseInt("01111111",2),Fs={0:We,1:We,2:tf,3:nf,4:of,5:rf,6:ef,16:We,22:We,48:We};function Mt(r,t={offset:0}){let e=r[t.offset]&Jc;if(t.offset++,Fs[e]!=null)return Fs[e](r,t);throw new Error("No decoder for tag "+e)}function Xe(r,t){let e=0;if((r[t.offset]&On)===On){let n=r[t.offset]&Qc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function We(r,t){Xe(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Mt(r,t);if(n===null)break;e.push(n)}return e}function tf(r,t){let e=Xe(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function ef(r,t){let e=Xe(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function rf(r,t){return t.offset++,null}function nf(r,t){let e=Xe(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function of(r,t){let e=Xe(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function sf(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new Z;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Hn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=sf(r.byteLength);return new Z(Uint8Array.from([t.byteLength|On]),t)}function St(r){let t=new Z,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new Z(Uint8Array.from([2]),Hn(t),t)}function Br(r){let t=Uint8Array.from([0]),e=new Z(t,r);return new Z(Uint8Array.from([3]),Hn(e),e)}function Zt(r,t=48){let e=new Z;for(let n of r)e.append(n);return new Z(Uint8Array.from([t]),Hn(e),e)}async function zs(r,t,e){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,e.subarray())}var af=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),cf=Uint8Array.from([6,5,43,129,4,0,34]),ff=Uint8Array.from([6,5,43,129,4,0,35]),uf={ext:!0,kty:"EC",crv:"P-256"},hf={ext:!0,kty:"EC",crv:"P-384"},lf={ext:!0,kty:"EC",crv:"P-521"},qn=32,Vn=48,Fn=66;function Gs(r){let t=Mt(r);return js(t)}function js(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===qn*2+1)return n=G(t.subarray(e,e+qn),"base64url"),o=G(t.subarray(e+qn),"base64url"),new Ie({...uf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Vn*2+1)return n=G(t.subarray(e,e+Vn),"base64url"),o=G(t.subarray(e+Vn),"base64url"),new Ie({...hf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Fn*2+1)return n=G(t.subarray(e,e+Fn),"base64url"),o=G(t.subarray(e+Fn),"base64url"),new Ie({...lf,key_ops:["verify"],x:n,y:o});throw new ot(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Zs(r){return Zt([St(Uint8Array.from([1])),Zt([df(r.crv)],160),Zt([Br(new Z(Uint8Array.from([4]),$(r.x??"","base64url"),$(r.y??"","base64url")))],161)]).subarray()}function df(r){if(r==="P-256")return af;if(r==="P-384")return cf;if(r==="P-521")return ff;throw new ot(`Invalid curve ${r}`)}var Ie=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Zs(this.jwk)),this._raw}toMultihash(){return Rt.digest(Yt(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return nt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}async verify(t,e){return zs(this.jwk,e,t)}};function Lr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function pf(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ce(r,...t){if(!pf(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function $e(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Lr(r.outputLen),Lr(r.blockLen)}function Te(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Ys(r,t){Ce(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var ae=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function _r(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function It(r,t){return r<<32-t|r>>>t}var md=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function";function Ws(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function Wt(r){return typeof r=="string"&&(r=Ws(r)),Ce(r),r}function zn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Ce(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var Ke=class{clone(){return this._cloneInto()}};function Ir(r){let t=n=>r().update(Wt(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Je(r=32){if(ae&&typeof ae.getRandomValues=="function")return ae.getRandomValues(new Uint8Array(r));if(ae&&typeof ae.randomBytes=="function")return Uint8Array.from(ae.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function mf(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,u=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+u,a,n)}function Xs(r,t,e){return r&t^~r&e}function $s(r,t,e){return r&t^r&e^t&e}var Ue=class extends Ke{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=_r(this.buffer)}update(t){Te(this);let{view:e,buffer:n,blockLen:o}=this;t=Wt(t);let s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=_r(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(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Te(this),Ys(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;mf(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=_r(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.length=o,t.pos=a,t.finished=s,t.destroyed=i,o%e&&t.buffer.set(n),t}};var yf=new Uint32Array([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]),Xt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),$t=new Uint32Array(64),Gn=class extends Ue{constructor(t=32){super(64,t,8,!1),this.A=Xt[0]|0,this.B=Xt[1]|0,this.C=Xt[2]|0,this.D=Xt[3]|0,this.E=Xt[4]|0,this.F=Xt[5]|0,this.G=Xt[6]|0,this.H=Xt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|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,e){for(let l=0;l<16;l++,e+=4)$t[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let p=$t[l-15],S=$t[l-2],w=It(p,7)^It(p,18)^p>>>3,m=It(S,17)^It(S,19)^S>>>10;$t[l]=m+$t[l-7]+w+$t[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let p=It(a,6)^It(a,11)^It(a,25),S=f+p+Xs(a,c,u)+yf[l]+$t[l]|0,m=(It(n,2)^It(n,13)^It(n,22))+$s(n,o,s)|0;f=u,u=c,c=a,a=i+S|0,i=s,s=o,o=n,n=S+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){$t.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Ct=Ir(()=>new Gn);var Cr=BigInt(4294967295),jn=BigInt(32);function Js(r,t=!1){return t?{h:Number(r&Cr),l:Number(r>>jn&Cr)}:{h:Number(r>>jn&Cr)|0,l:Number(r&Cr)|0}}function xf(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=Js(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var gf=(r,t)=>BigInt(r>>>0)<<jn|BigInt(t>>>0),bf=(r,t,e)=>r>>>e,wf=(r,t,e)=>r<<32-e|t>>>e,Ef=(r,t,e)=>r>>>e|t<<32-e,Sf=(r,t,e)=>r<<32-e|t>>>e,Af=(r,t,e)=>r<<64-e|t>>>e-32,vf=(r,t,e)=>r>>>e-32|t<<64-e,Bf=(r,t)=>t,Lf=(r,t)=>r,_f=(r,t,e)=>r<<e|t>>>32-e,If=(r,t,e)=>t<<e|r>>>32-e,Cf=(r,t,e)=>t<<e-32|r>>>64-e,Tf=(r,t,e)=>r<<e-32|t>>>64-e;function Kf(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Uf=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Rf=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Pf=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Df=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Nf=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),kf=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Mf={fromBig:Js,split:xf,toBig:gf,shrSH:bf,shrSL:wf,rotrSH:Ef,rotrSL:Sf,rotrBH:Af,rotrBL:vf,rotr32H:Bf,rotr32L:Lf,rotlSH:_f,rotlSL:If,rotlBH:Cf,rotlBL:Tf,add:Kf,add3L:Uf,add3H:Rf,add4L:Pf,add4H:Df,add5H:kf,add5L:Nf},F=Mf;var[Of,Hf]=F.split(["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(r=>BigInt(r))),Jt=new Uint32Array(80),Qt=new Uint32Array(80),Zn=class extends Ue{constructor(t=64){super(128,t,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:p,Gh:S,Gl:w,Hh:m,Hl:h}=this;return[t,e,n,o,s,i,a,c,u,f,l,p,S,w,m,h]}set(t,e,n,o,s,i,a,c,u,f,l,p,S,w,m,h){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=p|0,this.Gh=S|0,this.Gl=w|0,this.Hh=m|0,this.Hl=h|0}process(t,e){for(let d=0;d<16;d++,e+=4)Jt[d]=t.getUint32(e),Qt[d]=t.getUint32(e+=4);for(let d=16;d<80;d++){let v=Jt[d-15]|0,R=Qt[d-15]|0,K=F.rotrSH(v,R,1)^F.rotrSH(v,R,8)^F.shrSH(v,R,7),I=F.rotrSL(v,R,1)^F.rotrSL(v,R,8)^F.shrSL(v,R,7),T=Jt[d-2]|0,B=Qt[d-2]|0,M=F.rotrSH(T,B,19)^F.rotrBH(T,B,61)^F.shrSH(T,B,6),P=F.rotrSL(T,B,19)^F.rotrBL(T,B,61)^F.shrSL(T,B,6),k=F.add4L(I,P,Qt[d-7],Qt[d-16]),O=F.add4H(k,K,M,Jt[d-7],Jt[d-16]);Jt[d]=O|0,Qt[d]=k|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:p,Fh:S,Fl:w,Gh:m,Gl:h,Hh:g,Hl:b}=this;for(let d=0;d<80;d++){let v=F.rotrSH(l,p,14)^F.rotrSH(l,p,18)^F.rotrBH(l,p,41),R=F.rotrSL(l,p,14)^F.rotrSL(l,p,18)^F.rotrBL(l,p,41),K=l&S^~l&m,I=p&w^~p&h,T=F.add5L(b,R,I,Hf[d],Qt[d]),B=F.add5H(T,g,v,K,Of[d],Jt[d]),M=T|0,P=F.rotrSH(n,o,28)^F.rotrBH(n,o,34)^F.rotrBH(n,o,39),k=F.rotrSL(n,o,28)^F.rotrBL(n,o,34)^F.rotrBL(n,o,39),O=n&s^n&a^s&a,A=o&i^o&c^i&c;g=m|0,b=h|0,m=S|0,h=w|0,S=l|0,w=p|0,{h:l,l:p}=F.add(u|0,f|0,B|0,M|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let L=F.add3L(M,k,A);n=F.add3H(L,B,P,O),o=L|0}({h:n,l:o}=F.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=F.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=F.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=F.add(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:p}=F.add(this.Eh|0,this.El|0,l|0,p|0),{h:S,l:w}=F.add(this.Fh|0,this.Fl|0,S|0,w|0),{h:m,l:h}=F.add(this.Gh|0,this.Gl|0,m|0,h|0),{h:g,l:b}=F.add(this.Hh|0,this.Hl|0,g|0,b|0),this.set(n,o,s,i,a,c,u,f,l,p,S,w,m,h,g,b)}roundClean(){Jt.fill(0),Qt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Yn=Ir(()=>new Zn);var Jn=BigInt(0),$n=BigInt(1);function ce(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Qn(r){if(!ce(r))throw new Error("Uint8Array expected")}function Pt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function Qe(r){let t=r.toString(16);return t.length&1?"0"+t:t}function ei(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Jn:BigInt("0x"+r)}var ri=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",qf=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function te(r){if(Qn(r),ri)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=qf[r[e]];return t}var Ot={_0:48,_9:57,A:65,F:70,a:97,f:102};function Qs(r){if(r>=Ot._0&&r<=Ot._9)return r-Ot._0;if(r>=Ot.A&&r<=Ot.F)return r-(Ot.A-10);if(r>=Ot.a&&r<=Ot.f)return r-(Ot.a-10)}function tr(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(ri)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Qs(r.charCodeAt(s)),a=Qs(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Ht(r){return ei(te(r))}function Dt(r){return Qn(r),ei(te(Uint8Array.from(r).reverse()))}function fe(r,t){return tr(r.toString(16).padStart(t*2,"0"))}function ee(r,t){return fe(r,t).reverse()}function J(r,t,e){let n;if(typeof t=="string")try{n=tr(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(ce(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function re(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Qn(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var Wn=r=>typeof r=="bigint"&&Jn<=r;function Tr(r,t,e){return Wn(r)&&Wn(t)&&Wn(e)&&t<=r&&r<e}function pt(r,t,e,n){if(!Tr(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function ni(r){let t;for(t=0;r>Jn;r>>=$n,t+=1);return t}var ue=r=>($n<<BigInt(r))-$n,Xn=r=>new Uint8Array(r),ti=r=>Uint8Array.from(r);function oi(r,t,e){if(typeof r!="number"||r<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 e!="function")throw new Error("hmacFn must be a function");let n=Xn(r),o=Xn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...l)=>e(o,n,...l),c=(l=Xn(0))=>{o=a(ti([0]),l),n=a(),l.length!==0&&(o=a(ti([1]),l),n=a())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,p=[];for(;l<t;){n=a();let S=n.slice();p.push(S),l+=n.length}return re(...p)};return(l,p)=>{i(),c(l);let S;for(;!(S=p(u()));)c();return i(),S}}var Vf={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||ce(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Tt(r,t,e={}){let n=(o,s,i)=>{let a=Vf[s];if(typeof a!="function")throw new Error("invalid validator function");let c=r[o];if(!(i&&c===void 0)&&!a(c,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+c)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}function Re(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var at=BigInt(0),et=BigInt(1),he=BigInt(2),Ff=BigInt(3),to=BigInt(4),si=BigInt(5),ii=BigInt(8),zf=BigInt(9),Gf=BigInt(16);function j(r,t){let e=r%t;return e>=at?e:t+e}function eo(r,t,e){if(t<at)throw new Error("invalid exponent, negatives unsupported");if(e<=at)throw new Error("invalid modulus");if(e===et)return at;let n=et;for(;t>at;)t&et&&(n=n*r%e),r=r*r%e,t>>=et;return n}function Q(r,t,e){let n=r;for(;t-- >at;)n*=n,n%=e;return n}function Kr(r,t){if(r===at)throw new Error("invert: expected non-zero number");if(t<=at)throw new Error("invert: expected positive modulus, got "+t);let e=j(r,t),n=t,o=at,s=et,i=et,a=at;for(;e!==at;){let u=n/e,f=n%e,l=o-i*u,p=s-a*u;n=e,e=f,o=i,s=a,i=l,a=p}if(n!==et)throw new Error("invert: does not exist");return j(o,t)}function jf(r){let t=(r-et)/he,e,n,o;for(e=r-et,n=0;e%he===at;e/=he,n++);for(o=he;o<r&&eo(o,t,r)!==r-et;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+et)/to;return function(c,u){let f=c.pow(u,i);if(!c.eql(c.sqr(f),u))throw new Error("Cannot find square root");return f}}let s=(e+et)/he;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,f=a.pow(a.mul(a.ONE,o),e),l=a.pow(c,s),p=a.pow(c,e);for(;!a.eql(p,a.ONE);){if(a.eql(p,a.ZERO))return a.ZERO;let S=1;for(let m=a.sqr(p);S<u&&!a.eql(m,a.ONE);S++)m=a.sqr(m);let w=a.pow(f,et<<BigInt(u-S-1));f=a.sqr(w),l=a.mul(l,w),p=a.mul(p,f),u=S}return l}}function Zf(r){if(r%to===Ff){let t=(r+et)/to;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%ii===si){let t=(r-si)/ii;return function(n,o){let s=n.mul(o,he),i=n.pow(s,t),a=n.mul(o,i),c=n.mul(n.mul(a,he),i),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),o))throw new Error("Cannot find square root");return u}}return r%Gf,jf(r)}var ai=(r,t)=>(j(r,t)&et)===et,Yf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ro(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Yf.reduce((n,o)=>(n[o]="function",n),t);return Tt(r,e)}function Wf(r,t,e){if(e<at)throw new Error("invalid exponent, negatives unsupported");if(e===at)return r.ONE;if(e===et)return t;let n=r.ONE,o=t;for(;e>at;)e&et&&(n=r.mul(n,o)),o=r.sqr(o),e>>=et;return n}function Xf(r,t){let e=new Array(t.length),n=t.reduce((s,i,a)=>r.is0(i)?s:(e[a]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return t.reduceRight((s,i,a)=>r.is0(i)?s:(e[a]=r.mul(s,e[a]),r.mul(s,i)),o),e}function no(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function ne(r,t,e=!1,n={}){if(r<=at)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=no(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,a=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:ue(o),ZERO:at,ONE:et,create:c=>j(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return at<=c&&c<r},is0:c=>c===at,isOdd:c=>(c&et)===et,neg:c=>j(-c,r),eql:(c,u)=>c===u,sqr:c=>j(c*c,r),add:(c,u)=>j(c+u,r),sub:(c,u)=>j(c-u,r),mul:(c,u)=>j(c*u,r),pow:(c,u)=>Wf(a,c,u),div:(c,u)=>j(c*Kr(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Kr(c,r),sqrt:n.sqrt||(c=>(i||(i=Zf(r)),i(a,c))),invertBatch:c=>Xf(a,c),cmov:(c,u,f)=>f?u:c,toBytes:c=>e?ee(c,s):fe(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return e?Dt(c):Ht(c)}});return Object.freeze(a)}function ci(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function oo(r){let t=ci(r);return t+Math.ceil(t/2)}function fi(r,t,e=!1){let n=r.length,o=ci(t),s=oo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Dt(r):Ht(r),a=j(i,t-et)+et;return e?ee(a,o):fe(a,o)}var ui=BigInt(0),fo=BigInt(1);function so(r,t){let e=t.negate();return r?e:t}function li(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function io(r,t){li(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ue(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function hi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=fo);let u=t*n,f=u+Math.abs(a)-1,l=a===0,p=a<0,S=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:p,isNegF:S,offsetF:u}}function $f(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function Jf(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var ao=new WeakMap,di=new WeakMap;function co(r){return di.get(r)||1}function Ur(r,t){return{constTimeNegate:so,hasPrecomputes(e){return co(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>ui;)n&fo&&(o=o.add(s)),s=s.double(),n>>=fo;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=io(n,t),i=[],a=e,c=a;for(let u=0;u<o;u++){c=a,i.push(c);for(let f=1;f<s;f++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,a=io(e,t);for(let c=0;c<a.windows;c++){let{nextN:u,offset:f,isZero:l,isNeg:p,isNegF:S,offsetF:w}=hi(o,c,a);o=u,l?i=i.add(so(S,n[w])):s=s.add(so(p,n[f]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=io(e,t);for(let a=0;a<i.windows&&o!==ui;a++){let{nextN:c,offset:u,isZero:f,isNeg:l}=hi(o,a,i);if(o=c,!f){let p=n[u];s=s.add(l?p.negate():p)}}return s},getPrecomputes(e,n,o){let s=ao.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&ao.set(n,o(s))),s},wNAFCached(e,n,o){let s=co(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=co(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){li(n,t),di.set(e,n),ao.delete(e)}}}function Rr(r,t,e,n){if($f(e,r),Jf(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=ni(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,a=ue(i),c=new Array(Number(a)+1).fill(o),u=Math.floor((t.BITS-1)/i)*i,f=o;for(let l=u;l>=0;l-=i){c.fill(o);for(let S=0;S<n.length;S++){let w=n[S],m=Number(w>>BigInt(l)&a);c[m]=c[m].add(e[S])}let p=o;for(let S=c.length-1,w=o;S>0;S--)w=w.add(c[S]),p=p.add(w);if(f=f.add(p),l!==0)for(let S=0;S<i;S++)f=f.double()}return f}function er(r){return ro(r.Fp),Tt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...no(r.n,r.nBitLe