UNPKG

libp2p

Version:

JavaScript implementation of libp2p, a modular peer to peer network stack

2 lines • 282 kB
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2P = factory()}(typeof self !== 'undefined' ? self : this, function () { "use strict";var Libp2P=(()=>{var Fh=Object.create;var ho=Object.defineProperty;var Uh=Object.getOwnPropertyDescriptor;var Kh=Object.getOwnPropertyNames;var qh=Object.getPrototypeOf,zh=Object.prototype.hasOwnProperty;var Se=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),Pt=(r,t)=>{for(var e in t)ho(r,e,{get:t[e],enumerable:!0})},Yl=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Kh(t))!zh.call(r,o)&&o!==e&&ho(r,o,{get:()=>t[o],enumerable:!(n=Uh(t,o))||n.enumerable});return r};var ln=(r,t,e)=>(e=r!=null?Fh(qh(r)):{},Yl(t||!r||!r.__esModule?ho(e,"default",{value:r,enumerable:!0}):e,r)),Vh=r=>Yl(ho({},"__esModule",{value:!0}),r);var Of=Se((vv,hc)=>{"use strict";var Bg=Object.prototype.hasOwnProperty,Mt="~";function Un(){}Object.create&&(Un.prototype=Object.create(null),new Un().__proto__||(Mt=!1));function Og(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function Bf(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new Og(e,n||r,o),i=Mt?Mt+t:t;return r._events[i]?r._events[i].fn?r._events[i]=[r._events[i],s]:r._events[i].push(s):(r._events[i]=s,r._eventsCount++),r}function jo(r,t){--r._eventsCount===0?r._events=new Un:delete r._events[t]}function It(){this._events=new Un,this._eventsCount=0}It.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)Bg.call(e,n)&&t.push(Mt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};It.prototype.listeners=function(t){var e=Mt?Mt+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i};It.prototype.listenerCount=function(t){var e=Mt?Mt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};It.prototype.emit=function(t,e,n,o,s,i){var a=Mt?Mt+t:t;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,l,f;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,o),!0;case 5:return c.fn.call(c.context,e,n,o,s),!0;case 6:return c.fn.call(c.context,e,n,o,s,i),!0}for(f=1,l=new Array(u-1);f<u;f++)l[f-1]=arguments[f];c.fn.apply(c.context,l)}else{var d=c.length,m;for(f=0;f<d;f++)switch(c[f].once&&this.removeListener(t,c[f].fn,void 0,!0),u){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,e);break;case 3:c[f].fn.call(c[f].context,e,n);break;case 4:c[f].fn.call(c[f].context,e,n,o);break;default:if(!l)for(m=1,l=new Array(u-1);m<u;m++)l[m-1]=arguments[m];c[f].fn.apply(c[f].context,l)}}return!0};It.prototype.on=function(t,e,n){return Bf(this,t,e,n,!1)};It.prototype.once=function(t,e,n){return Bf(this,t,e,n,!0)};It.prototype.removeListener=function(t,e,n,o){var s=Mt?Mt+t:t;if(!this._events[s])return this;if(!e)return jo(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&jo(this,s);else{for(var a=0,c=[],u=i.length;a<u;a++)(i[a].fn!==e||o&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[s]=c.length===1?c[0]:c:jo(this,s)}return this};It.prototype.removeAllListeners=function(t){var e;return t?(e=Mt?Mt+t:t,this._events[e]&&jo(this,e)):(this._events=new Un,this._eventsCount=0),this};It.prototype.off=It.prototype.removeListener;It.prototype.addListener=It.prototype.on;It.prefixed=Mt;It.EventEmitter=It;typeof hc<"u"&&(hc.exports=It)});var zf=Se(($v,qf)=>{qf.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var t=0,e=Object.create(null),n=Object.create(null);function o(s,i){e[s]=i,t++,t>=r&&(t=0,n=e,e=Object.create(null))}return{has:function(s){return e[s]!==void 0||n[s]!==void 0},remove:function(s){e[s]!==void 0&&(e[s]=void 0),n[s]!==void 0&&(n[s]=void 0)},get:function(s){var i=e[s];if(i!==void 0)return i;if((i=n[s])!==void 0)return o(s,i),i},set:function(s,i){e[s]!==void 0?e[s]=i:o(s,i)},clear:function(){e=Object.create(null),n=Object.create(null)}}}});var id=Se((yS,sd)=>{"use strict";sd.exports=r=>{if(Object.prototype.toString.call(r)!=="[object Object]")return!1;let t=Object.getPrototypeOf(r);return t===null||t===Object.prototype}});var dd=Se((ud,fd)=>{"use strict";var as=id(),{hasOwnProperty:cd}=Object.prototype,{propertyIsEnumerable:c0}=Object,Zr=(r,t,e)=>Object.defineProperty(r,t,{value:e,writable:!0,enumerable:!0,configurable:!0}),l0=ud,ad={concatArrays:!1,ignoreUndefined:!1},cs=r=>{let t=[];for(let e in r)cd.call(r,e)&&t.push(e);if(Object.getOwnPropertySymbols){let e=Object.getOwnPropertySymbols(r);for(let n of e)c0.call(r,n)&&t.push(n)}return t};function jr(r){return Array.isArray(r)?u0(r):as(r)?f0(r):r}function u0(r){let t=r.slice(0,0);return cs(r).forEach(e=>{Zr(t,e,jr(r[e]))}),t}function f0(r){let t=Object.getPrototypeOf(r)===null?Object.create(null):{};return cs(r).forEach(e=>{Zr(t,e,jr(r[e]))}),t}var ld=(r,t,e,n)=>(e.forEach(o=>{typeof t[o]>"u"&&n.ignoreUndefined||(o in r&&r[o]!==Object.getPrototypeOf(r)?Zr(r,o,Oc(r[o],t[o],n)):Zr(r,o,jr(t[o])))}),r),d0=(r,t,e)=>{let n=r.slice(0,0),o=0;return[r,t].forEach(s=>{let i=[];for(let a=0;a<s.length;a++)cd.call(s,a)&&(i.push(String(a)),s===r?Zr(n,o++,s[a]):Zr(n,o++,jr(s[a])));n=ld(n,s,cs(s).filter(a=>!i.includes(a)),e)}),n};function Oc(r,t,e){return e.concatArrays&&Array.isArray(r)&&Array.isArray(t)?d0(r,t,e):!as(t)||!as(r)?jr(t):ld(r,t,cs(t),e)}fd.exports=function(...r){let t=Oc(jr(ad),this!==l0&&this||{},ad),e={_:{}};for(let n of r)if(n!==void 0){if(!as(n))throw new TypeError("`"+n+"` is not an Option Object");e=Oc(e,{_:n},t)}return e._}});var qd=Se(Yn=>{(function(){var r,t,e,n,o,s,i,a;a=function(c){var u,l,f,d;return u=(c&255<<24)>>>24,l=(c&255<<16)>>>16,f=(c&65280)>>>8,d=c&255,[u,l,f,d].join(".")},i=function(c){var u,l,f,d,m,p;for(u=[],f=d=0;d<=3&&c.length!==0;f=++d){if(f>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}p=t(c),m=p[0],l=p[1],c=c.substring(l),u.push(m)}if(c.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},e=function(c){return c.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(c){var u,l,f,d,m;for(d=0,u=10,l="9",f=0,c.length>1&&c[f]==="0"&&(c[f+1]==="x"||c[f+1]==="X"?(f+=2,u=16):"0"<=c[f+1]&&c[f+1]<="9"&&(f++,u=8,l="7")),m=f;f<c.length;){if("0"<=c[f]&&c[f]<=l)d=d*u+(e(c[f])-n)>>>0;else if(u===16)if("a"<=c[f]&&c[f]<="f")d=d*u+(10+e(c[f])-s)>>>0;else if("A"<=c[f]&&c[f]<="F")d=d*u+(10+e(c[f])-o)>>>0;else break;else break;if(d>4294967295)throw new Error("too large");f++}if(f===m)throw new Error("empty octet");return[d,f]},r=function(){function c(u,l){var f,d,m,p;if(typeof u!="string")throw new Error("Missing `net' parameter");if(l||(p=u.split("/",2),u=p[0],l=p[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(g){throw f=g,new Error("Invalid mask: "+l)}for(d=m=32;m>=0;d=--m)if(this.maskLong===4294967295<<32-d>>>0){this.bitmask=d;break}}else if(l||l===0)this.bitmask=parseInt(l,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(u)&this.maskLong)>>>0}catch(g){throw f=g,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new c(u)),u instanceof c?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(u){return u==null&&(u=1),new c(a(this.netLong+this.size*u),this.mask)},c.prototype.forEach=function(u){var l,f,d;for(d=i(this.first),f=i(this.last),l=0;d<=f;)u(a(d),d,l),l++,d++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),Yn.ip2long=i,Yn.long2ip=a,Yn.Netmask=r}).call(Yn)});var hh=Se((NI,dh)=>{function Ht(r,t){typeof t=="boolean"&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(r)),this._timeouts=r,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}dh.exports=Ht;Ht.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)};Ht.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null};Ht.prototype.retry=function(r){if(this._timeout&&clearTimeout(this._timeout),!r)return!1;var t=new Date().getTime();if(r&&t-this._operationStart>=this._maxRetryTime)return this._errors.push(r),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(r);var e=this._timeouts.shift();if(e===void 0)if(this._cachedTimeouts)this._errors.splice(0,this._errors.length-1),e=this._cachedTimeouts.slice(-1);else return!1;var n=this;return this._timer=setTimeout(function(){n._attempts++,n._operationTimeoutCb&&(n._timeout=setTimeout(function(){n._operationTimeoutCb(n._attempts)},n._operationTimeout),n._options.unref&&n._timeout.unref()),n._fn(n._attempts)},e),this._options.unref&&this._timer.unref(),!0};Ht.prototype.attempt=function(r,t){this._fn=r,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var e=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){e._operationTimeoutCb()},e._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)};Ht.prototype.try=function(r){console.log("Using RetryOperation.try() is deprecated"),this.attempt(r)};Ht.prototype.start=function(r){console.log("Using RetryOperation.start() is deprecated"),this.attempt(r)};Ht.prototype.start=Ht.prototype.try;Ht.prototype.errors=function(){return this._errors};Ht.prototype.attempts=function(){return this._attempts};Ht.prototype.mainError=function(){if(this._errors.length===0)return null;for(var r={},t=null,e=0,n=0;n<this._errors.length;n++){var o=this._errors[n],s=o.message,i=(r[s]||0)+1;r[s]=i,i>=e&&(t=o,e=i)}return t}});var ph=Se(wr=>{var jy=hh();wr.operation=function(r){var t=wr.timeouts(r);return new jy(t,{forever:r&&(r.forever||r.retries===1/0),unref:r&&r.unref,maxRetryTime:r&&r.maxRetryTime})};wr.timeouts=function(r){if(r instanceof Array)return[].concat(r);var t={retries:10,factor:2,minTimeout:1*1e3,maxTimeout:1/0,randomize:!1};for(var e in r)t[e]=r[e];if(t.minTimeout>t.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var n=[],o=0;o<t.retries;o++)n.push(this.createTimeout(o,t));return r&&r.forever&&!n.length&&n.push(this.createTimeout(o,t)),n.sort(function(s,i){return s-i}),n};wr.createTimeout=function(r,t){var e=t.randomize?Math.random()+1:1,n=Math.round(e*Math.max(t.minTimeout,1)*Math.pow(t.factor,r));return n=Math.min(n,t.maxTimeout),n};wr.wrap=function(r,t,e){if(t instanceof Array&&(e=t,t=null),!e){e=[];for(var n in r)typeof r[n]=="function"&&e.push(n)}for(var o=0;o<e.length;o++){var s=e[o],i=r[s];r[s]=function(c){var u=wr.operation(t),l=Array.prototype.slice.call(arguments,1),f=l.pop();l.push(function(d){u.retry(d)||(d&&(arguments[0]=u.mainError()),f.apply(this,arguments))}),u.attempt(function(){c.apply(r,l)})}.bind(r,i),r[s].options=t}}});var gh=Se((OI,mh)=>{mh.exports=ph()});var _b={};Pt(_b,{createLibp2p:()=>Ab});var Ql=Symbol.for("@libp2p/connection");var Fi=Symbol.for("@libp2p/content-routing");var Ui=Symbol.for("@libp2p/peer-discovery");var po=Symbol.for("@libp2p/peer-id");function mo(r){return!!r?.[po]}var Ki=Symbol.for("@libp2p/peer-routing");var qi="keep-alive";var Rb=Symbol.for("@libp2p/transport");var $e;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})($e||($e={}));var Gt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var R=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Er=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},un=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var go=class extends Error{static name="ConnectionClosingError";constructor(t="The connection is closing"){super(t),this.name="ConnectionClosingError"}},Sr=class extends Error{static name="ConnectionClosedError";constructor(t="The connection is closed"){super(t),this.name="ConnectionClosedError"}};var He=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}},Ar=class extends Error{static name="InvalidPeerIdError";constructor(t="Invalid PeerID"){super(t),this.name="InvalidPeerIdError"}},Ae=class extends Error{static name="InvalidMultiaddrError";constructor(t="Invalid multiaddr"){super(t),this.name="InvalidMultiaddrError"}},yo=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},bo=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}},fn=class extends Error{static name="UnsupportedProtocolError";constructor(t="Unsupported protocol error"){super(t),this.name="UnsupportedProtocolError"}},wo=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var xo=class extends Error{static name="TimeoutError";constructor(t="Timed out"){super(t),this.name="TimeoutError"}},ce=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var _r=class extends Error{static name="DialError";constructor(t="Dial error"){super(t),this.name="DialError"}};var Ir=class extends Error{static name="LimitedConnectionError";constructor(t="Limited connection"){super(t),this.name="LimitedConnectionError"}},vo=class extends Error{static name="TooManyInboundProtocolStreamsError";constructor(t="Too many inbound protocol streams"){super(t),this.name="TooManyInboundProtocolStreamsError"}},Eo=class extends Error{static name="TooManyOutboundProtocolStreamsError";constructor(t="Too many outbound protocol streams"){super(t),this.name="TooManyOutboundProtocolStreamsError"}},_e=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var le=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};function So(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function Jl(...r){let t=[];for(let e of r)So(e)&&t.push(e);await Promise.all(t.map(async e=>{e.beforeStart!=null&&await e.beforeStart()})),await Promise.all(t.map(async e=>{await e.start()})),await Promise.all(t.map(async e=>{e.afterStart!=null&&await e.afterStart()}))}async function tu(...r){let t=[];for(let e of r)So(e)&&t.push(e);await Promise.all(t.map(async e=>{e.beforeStop!=null&&await e.beforeStop()})),await Promise.all(t.map(async e=>{await e.stop()})),await Promise.all(t.map(async e=>{e.afterStop!=null&&await e.afterStop()}))}var dn=Symbol.for("@libp2p/service-capabilities"),zi=Symbol.for("@libp2p/service-dependencies");var Wi={};Pt(Wi,{base58btc:()=>G,base58flickr:()=>Zh});var iw=new Uint8Array(0);function eu(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 ue(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 ru(r){return new TextEncoder().encode(r)}function nu(r){return new TextDecoder().decode(r)}function $h(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),l=Math.log(256)/Math.log(a);function f(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var g=0,h=0,b=0,x=p.length;b!==x&&p[b]===0;)b++,g++;for(var y=(x-b)*l+1>>>0,E=new Uint8Array(y);b!==x;){for(var _=p[b],L=0,I=y-1;(_!==0||L<h)&&I!==-1;I--,L++)_+=256*E[I]>>>0,E[I]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");h=L,b++}for(var P=y-h;P!==y&&E[P]===0;)P++;for(var T=c.repeat(g);P<y;++P)T+=r.charAt(E[P]);return T}function d(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var g=0;if(p[g]!==" "){for(var h=0,b=0;p[g]===c;)h++,g++;for(var x=(p.length-g)*u+1>>>0,y=new Uint8Array(x);p[g];){var E=e[p.charCodeAt(g)];if(E===255)return;for(var _=0,L=x-1;(E!==0||_<b)&&L!==-1;L--,_++)E+=a*y[L]>>>0,y[L]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");b=_,g++}if(p[g]!==" "){for(var I=x-b;I!==x&&y[I]===0;)I++;for(var P=new Uint8Array(h+(x-I)),T=h;I!==x;)P[T++]=y[I++];return P}}}function m(p){var g=d(p);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:d,decode:m}}var Hh=$h,Gh=Hh,su=Gh;var Vi=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")}},$i=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 iu(this,t)}},Hi=class{decoders;constructor(t){this.decoders=t}or(t){return iu(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 iu(r,t){return new Hi({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Gi=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 Vi(t,e,n),this.decoder=new $i(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Cr({name:r,prefix:t,encode:e,decode:n}){return new Gi(r,t,e,n)}function Ie({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=su(e,r);return Cr({prefix:t,name:r,encode:n,decode:s=>ue(o(s))})}function Wh(r,t,e,n){let o={};for(let l=0;l<t.length;++l)o[t[l]]=l;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 l=0;l<s;++l){let f=o[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|f,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 Xh(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 at({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Cr({prefix:t,name:r,encode(o){return Xh(o,n,e)},decode(o){return Wh(o,n,e,r)}})}var G=Ie({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Zh=Ie({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Xi={};Pt(Xi,{base32:()=>Ut,base32hex:()=>Jh,base32hexpad:()=>ep,base32hexpadupper:()=>rp,base32hexupper:()=>tp,base32pad:()=>Yh,base32padupper:()=>Qh,base32upper:()=>jh,base32z:()=>np});var Ut=at({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),jh=at({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Yh=at({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Qh=at({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Jh=at({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),tp=at({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ep=at({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),rp=at({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),np=at({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Zi={};Pt(Zi,{base36:()=>hn,base36upper:()=>op});var hn=Ie({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),op=Ie({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var sp=lu,au=128,ip=127,ap=~ip,cp=Math.pow(2,31);function lu(r,t,e){t=t||[],e=e||0;for(var n=e;r>=cp;)t[e++]=r&255|au,r/=128;for(;r&ap;)t[e++]=r&255|au,r>>>=7;return t[e]=r|0,lu.bytes=e-n+1,t}var lp=ji,up=128,cu=127;function ji(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw ji.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&cu)<<o:(i&cu)*Math.pow(2,o),o+=7}while(i>=up);return ji.bytes=s-n,e}var fp=Math.pow(2,7),dp=Math.pow(2,14),hp=Math.pow(2,21),pp=Math.pow(2,28),mp=Math.pow(2,35),gp=Math.pow(2,42),yp=Math.pow(2,49),bp=Math.pow(2,56),wp=Math.pow(2,63),xp=function(r){return r<fp?1:r<dp?2:r<hp?3:r<pp?4:r<mp?5:r<gp?6:r<yp?7:r<bp?8:r<wp?9:10},vp={encode:sp,decode:lp,encodingLength:xp},Ep=vp,pn=Ep;function mn(r,t=0){return[pn.decode(r,t),pn.decode.bytes]}function Tr(r,t,e=0){return pn.encode(r,t,e),t}function Pr(r){return pn.encodingLength(r)}function Wt(r,t){let e=t.byteLength,n=Pr(r),o=n+Pr(e),s=new Uint8Array(o+e);return Tr(r,s,0),Tr(e,s,n),s.set(t,o),new Lr(r,e,t,s)}function Kt(r){let t=ue(r),[e,n]=mn(t),[o,s]=mn(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Lr(e,o,i,t)}function uu(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&eu(r.bytes,e.bytes)}}var Lr=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function fu(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Ap(e,Yi(r),t??G.encoder);default:return _p(e,Yi(r),t??Ut.encoder)}}var du=new WeakMap;function Yi(r){let t=du.get(r);if(t==null){let e=new Map;return du.set(r,e),e}return t}var ut=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!==gn)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ip)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=Wt(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&&uu(t.multihash,n.multihash)}toString(t){return fu(this,t)}toJSON(){return{"/":fu(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??hu(n,o,s.bytes))}else if(e[Cp]===!0){let{version:n,multihash:o,code:s}=e,i=Kt(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!==gn)throw new Error(`Version 0 CID must use dag-pb (code: ${gn}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=hu(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,gn,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=ue(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 Lr(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[f,d]=mn(t.subarray(e));return e+=d,f},o=n(),s=gn;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,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(t,e){let[n,o]=Sp(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 Yi(s).set(n,t),s}};function Sp(r,t){switch(r[0]){case"Q":{let e=t??G;return[G.prefix,e.decode(`${G.prefix}${r}`)]}case G.prefix:{let e=t??G;return[G.prefix,e.decode(r)]}case Ut.prefix:{let e=t??Ut;return[Ut.prefix,e.decode(r)]}case hn.prefix:{let e=t??hn;return[hn.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 Ap(r,t,e){let{prefix:n}=e;if(n!==G.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 _p(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 gn=112,Ip=18;function hu(r,t,e){let n=Pr(r),o=n+Pr(t),s=new Uint8Array(o+e.byteLength);return Tr(r,s,0),Tr(t,s,n),s.set(e,o),s}var Cp=Symbol.for("@ipld/js-cid/CID");var Qi={};Pt(Qi,{identity:()=>fe});var pu=0,Tp="identity",mu=ue;function Pp(r){return Wt(pu,mu(r))}var fe={code:pu,name:Tp,encode:mu,digest:Pp};function et(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 gu(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Lp(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Dr(r,...t){if(!Lp(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 yu(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");gu(r.outputLen),gu(r.blockLen)}function kr(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 bu(r,t){Dr(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var Ge=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function _o(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Xt(r,t){return r<<32-t|r>>>t}function wu(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function yn(r){return typeof r=="string"&&(r=wu(r)),Dr(r),r}function Ji(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Dr(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 Rr=class{clone(){return this._cloneInto()}};function Io(r){let t=n=>r().update(yn(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Mr(r=32){if(Ge&&typeof Ge.getRandomValues=="function")return Ge.getRandomValues(new Uint8Array(r));if(Ge&&typeof Ge.randomBytes=="function")return Ge.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function Dp(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 xu(r,t,e){return r&t^~r&e}function vu(r,t,e){return r&t^r&e^t&e}var Nr=class extends Rr{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=_o(this.buffer)}update(t){kr(this);let{view:e,buffer:n,blockLen:o}=this;t=yn(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=_o(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){kr(this),bu(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 f=i;f<o;f++)e[f]=0;Dp(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=_o(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],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 Co=BigInt(4294967295),ta=BigInt(32);function Eu(r,t=!1){return t?{h:Number(r&Co),l:Number(r>>ta&Co)}:{h:Number(r>>ta&Co)|0,l:Number(r&Co)|0}}function kp(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}=Eu(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var Rp=(r,t)=>BigInt(r>>>0)<<ta|BigInt(t>>>0),Mp=(r,t,e)=>r>>>e,Np=(r,t,e)=>r<<32-e|t>>>e,Bp=(r,t,e)=>r>>>e|t<<32-e,Op=(r,t,e)=>r<<32-e|t>>>e,Fp=(r,t,e)=>r<<64-e|t>>>e-32,Up=(r,t,e)=>r>>>e-32|t<<64-e,Kp=(r,t)=>t,qp=(r,t)=>r,zp=(r,t,e)=>r<<e|t>>>32-e,Vp=(r,t,e)=>t<<e|r>>>32-e,$p=(r,t,e)=>t<<e-32|r>>>64-e,Hp=(r,t,e)=>r<<e-32|t>>>64-e;function Gp(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Wp=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Xp=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Zp=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),jp=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Yp=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Qp=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Jp={fromBig:Eu,split:kp,toBig:Rp,shrSH:Mp,shrSL:Np,rotrSH:Bp,rotrSL:Op,rotrBH:Fp,rotrBL:Up,rotr32H:Kp,rotr32L:qp,rotlSH:zp,rotlSL:Vp,rotlBH:$p,rotlBL:Hp,add:Gp,add3L:Wp,add3H:Xp,add4L:Zp,add4H:jp,add5H:Qp,add5L:Yp},F=Jp;var[tm,em]=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))),Ce=new Uint32Array(80),Te=new Uint32Array(80),ea=class extends Nr{constructor(){super(128,64,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:l,Fh:f,Fl:d,Gh:m,Gl:p,Hh:g,Hl:h}=this;return[t,e,n,o,s,i,a,c,u,l,f,d,m,p,g,h]}set(t,e,n,o,s,i,a,c,u,l,f,d,m,p,g,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=l|0,this.Fh=f|0,this.Fl=d|0,this.Gh=m|0,this.Gl=p|0,this.Hh=g|0,this.Hl=h|0}process(t,e){for(let y=0;y<16;y++,e+=4)Ce[y]=t.getUint32(e),Te[y]=t.getUint32(e+=4);for(let y=16;y<80;y++){let E=Ce[y-15]|0,_=Te[y-15]|0,L=F.rotrSH(E,_,1)^F.rotrSH(E,_,8)^F.shrSH(E,_,7),I=F.rotrSL(E,_,1)^F.rotrSL(E,_,8)^F.shrSL(E,_,7),P=Ce[y-2]|0,T=Te[y-2]|0,rt=F.rotrSH(P,T,19)^F.rotrBH(P,T,61)^F.shrSH(P,T,6),H=F.rotrSL(P,T,19)^F.rotrBL(P,T,61)^F.shrSL(P,T,6),K=F.add4L(I,H,Te[y-7],Te[y-16]),ht=F.add4H(K,L,rt,Ce[y-7],Ce[y-16]);Ce[y]=ht|0,Te[y]=K|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:d,Fh:m,Fl:p,Gh:g,Gl:h,Hh:b,Hl:x}=this;for(let y=0;y<80;y++){let E=F.rotrSH(f,d,14)^F.rotrSH(f,d,18)^F.rotrBH(f,d,41),_=F.rotrSL(f,d,14)^F.rotrSL(f,d,18)^F.rotrBL(f,d,41),L=f&m^~f&g,I=d&p^~d&h,P=F.add5L(x,_,I,em[y],Te[y]),T=F.add5H(P,b,E,L,tm[y],Ce[y]),rt=P|0,H=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),ht=n&s^n&a^s&a,A=o&i^o&c^i&c;b=g|0,x=h|0,g=m|0,h=p|0,m=f|0,p=d|0,{h:f,l:d}=F.add(u|0,l|0,T|0,rt|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let D=F.add3L(rt,K,A);n=F.add3H(D,T,H,ht),o=D|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.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:d}=F.add(this.Eh|0,this.El|0,f|0,d|0),{h:m,l:p}=F.add(this.Fh|0,this.Fl|0,m|0,p|0),{h:g,l:h}=F.add(this.Gh|0,this.Gl|0,g|0,h|0),{h:b,l:x}=F.add(this.Hh|0,this.Hl|0,b|0,x|0),this.set(n,o,s,i,a,c,u,l,f,d,m,p,g,h,b,x)}roundClean(){Ce.fill(0),Te.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 Su=Io(()=>new ea);var Lo={};Pt(Lo,{aInRange:()=>Bt,abool:()=>Zt,abytes:()=>Br,bitGet:()=>am,bitLen:()=>sa,bitMask:()=>wn,bitSet:()=>cm,bytesToHex:()=>he,bytesToNumberBE:()=>pe,bytesToNumberLE:()=>Le,concatBytes:()=>me,createHmacDrbg:()=>ia,ensureBytes:()=>st,equalBytes:()=>sm,hexToBytes:()=>Xe,hexToNumber:()=>oa,inRange:()=>bn,isBytes:()=>Pe,memoized:()=>je,notImplemented:()=>um,numberToBytesBE:()=>De,numberToBytesLE:()=>Ze,numberToHexUnpadded:()=>We,numberToVarBytesBE:()=>om,utf8ToBytes:()=>im,validateObject:()=>ne});var To=BigInt(0),Po=BigInt(1),rm=BigInt(2);function Pe(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Br(r){if(!Pe(r))throw new Error("Uint8Array expected")}function Zt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var nm=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function he(r){Br(r);let t="";for(let e=0;e<r.length;e++)t+=nm[r[e]];return t}function We(r){let t=r.toString(16);return t.length&1?"0"+t:t}function oa(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?To:BigInt("0x"+r)}var de={_0:48,_9:57,A:65,F:70,a:97,f:102};function Au(r){if(r>=de._0&&r<=de._9)return r-de._0;if(r>=de.A&&r<=de.F)return r-(de.A-10);if(r>=de.a&&r<=de.f)return r-(de.a-10)}function Xe(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof 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=Au(r.charCodeAt(s)),a=Au(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 pe(r){return oa(he(r))}function Le(r){return Br(r),oa(he(Uint8Array.from(r).reverse()))}function De(r,t){return Xe(r.toString(16).padStart(t*2,"0"))}function Ze(r,t){return De(r,t).reverse()}function om(r){return Xe(We(r))}function st(r,t,e){let n;if(typeof t=="string")try{n=Xe(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Pe(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 me(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Br(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}function sm(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function im(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var ra=r=>typeof r=="bigint"&&To<=r;function bn(r,t,e){return ra(r)&&ra(t)&&ra(e)&&t<=r&&r<e}function Bt(r,t,e,n){if(!bn(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function sa(r){let t;for(t=0;r>To;r>>=Po,t+=1);return t}function am(r,t){return r>>BigInt(t)&Po}function cm(r,t,e){return r|(e?Po:To)<<BigInt(t)}var wn=r=>(rm<<BigInt(r-1))-Po,na=r=>new Uint8Array(r),_u=r=>Uint8Array.from(r);function ia(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=na(r),o=na(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...f)=>e(o,n,...f),c=(f=na())=>{o=a(_u([0]),f),n=a(),f.length!==0&&(o=a(_u([1]),f),n=a())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,d=[];for(;f<t;){n=a();let m=n.slice();d.push(m),f+=n.length}return me(...d)};return(f,d)=>{i(),c(f);let m;for(;!(m=d(u()));)c();return i(),m}}var lm={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"||Pe(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 ne(r,t,e={}){let n=(o,s,i)=>{let a=lm[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}var um=()=>{throw new Error("not implemented")};function je(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 pt=BigInt(0),nt=BigInt(1),Ye=BigInt(2),fm=BigInt(3),aa=BigInt(4),Iu=BigInt(5),Cu=BigInt(8),dm=BigInt(9),hm=BigInt(16);function Y(r,t){let e=r%t;return e>=pt?e:t+e}function pm(r,t,e){if(t<pt)throw new Error("invalid exponent, negatives unsupported");if(e<=pt)throw new Error("invalid modulus");if(e===nt)return pt;let n=nt;for(;t>pt;)t&nt&&(n=n*r%e),r=r*r%e,t>>=nt;return n}function ot(r,t,e){let n=r;for(;t-- >pt;)n*=n,n%=e;return n}function Do(r,t){if(r===pt)throw new Error("invert: expected non-zero number");if(t<=pt)throw new Error("invert: expected positive modulus, got "+t);let e=Y(r,t),n=t,o=pt,s=nt,i=nt,a=pt;for(;e!==pt;){let u=n/e,l=n%e,f=o-i*u,d=s-a*u;n=e,e=l,o=i,s=a,i=f,a=d}if(n!==nt)throw new Error("invert: does not exist");return Y(o,t)}function mm(r){let t=(r-nt)/Ye,e,n,o;for(e=r-nt,n=0;e%Ye===pt;e/=Ye,n++);for(o=Ye;o<r&&pm(o,t,r)!==r-nt;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+nt)/aa;return function(c,u){let l=c.pow(u,i);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}let s=(e+nt)/Ye;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,l=a.pow(a.mul(a.ONE,o),e),f=a.pow(c,s),d=a.pow(c,e);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let m=1;for(let g=a.sqr(d);m<u&&!a.eql(g,a.ONE);m++)g=a.sqr(g);let p=a.pow(l,nt<<BigInt(u-m-1));l=a.sqr(p),f=a.mul(f,p),d=a.mul(d,l),u=m}return f}}function gm(r){if(r%aa===fm){let t=(r+nt)/aa;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%Cu===Iu){let t=(r-Iu)/Cu;return function(n,o){let s=n.mul(o,Ye),i=n.pow(s,t),a=n.mul(o,i),c=n.mul(n.mul(a,Ye),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%hm,mm(r)}var Tu=(r,t)=>(Y(r,t)&nt)===nt,ym=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ca(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=ym.reduce((n,o)=>(n[o]="function",n),t);return ne(r,e)}function bm(r,t,e){if(e<pt)throw new Error("invalid exponent, negatives unsupported");if(e===pt)return r.ONE;if(e===nt)return t;let n=r.ONE,o=t;for(;e>pt;)e&nt&&(n=r.mul(n,o)),o=r.sqr(o),e>>=nt;return n}function wm(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 la(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function ke(r,t,e=!1,n={}){if(r<=pt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=la(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:wn(o),ZERO:pt,ONE:nt,create:c=>Y(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return pt<=c&&c<r},is0:c=>c===pt,isOdd:c=>(c&nt)===nt,neg:c=>Y(-c,r),eql:(c,u)=>c===u,sqr:c=>Y(c*c,r),add:(c,u)=>Y(c+u,r),sub:(c,u)=>Y(c-u,r),mul:(c,u)=>Y(c*u,r),pow:(c,u)=>bm(a,c,u),div:(c,u)=>Y(c*Do(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Do(c,r),sqrt:n.sqrt||(c=>(i||(i=gm(r)),i(a,c))),invertBatch:c=>wm(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>e?Ze(c,s):De(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return e?Le(c):pe(c)}});return Object.freeze(a)}function Pu(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 ua(r){let t=Pu(r);return t+Math.ceil(t/2)}function Lu(r,t,e=!1){let n=r.length,o=Pu(t),s=ua(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Le(r):pe(r),a=Y(i,t-nt)+nt;return e?Ze(a,o):De(a,o)}var Du=BigInt(0),ko=BigInt(1);function fa(r,t){let e=t.negate();return r?e:t}function ku(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function da(r,t){ku(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function xm(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 vm(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 ha=new WeakMap,Ru=new WeakMap;function pa(r){return Ru.get(r)||1}function Ro(r,t){return{constTimeNegate:fa,hasPrecomputes(e){return pa(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Du;)n&ko&&(o=o.add(s)),s=s.double(),n>>=ko;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=da(n,t),i=[],a=e,c=a;for(let u=0;u<o;u++){c=a,i.push(c);for(let l=1;l<s;l++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,o){let{windows:s,windowSize:i}=da(e,t),a=r.ZERO,c=r.BASE,u=BigInt(2**e-1),l=2**e,f=BigInt(e);for(let d=0;d<s;d++){let m=d*i,p=Number(o&u);o>>=f,p>i&&(p-=l,o+=ko);let g=m,h=m+Math.abs(p)-1,b=d%2!==0,x=p<0;p===0?c=c.add(fa(b,n[g])):a=a.add(fa(x,n[h]))}return{p:a,f:c}},wNAFUnsafe(e,n,o,s=r.ZERO){let{windows:i,windowSize:a}=da(e,t),c=BigInt(2**e-1),u=2**e,l=BigInt(e);for(let f=0;f<i;f++){let d=f*a;if(o===Du)break;let m=Number(o&c);if(o>>=l,m>a&&(m-=u,o+=ko),m===0)continue;let p=n[d+Math.abs(m)-1];m<0&&(p=p.negate()),s=s.add(p)}return s},getPrecomputes(e,n,o){let s=ha.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&ha.set(n,o(s))),s},wNAFCached(e,n,o){let s=pa(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=pa(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){ku(n,t),Ru.set(e,n),ha.delete(e)}}}function Mo(r,t,e,n){if(xm(e,r),vm(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=sa(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,a=(1<<i)-1,c=new Array(a+1).fill(o),u=Math.floor((t.BITS-1)/i)*i,l=o;for(let f=u;f>=0;f-=i){c.fill(o);for(let m=0;m<n.length;m++){let p=n[m],g=Number(p>>BigInt(f)&BigInt(a));c[g]=c[g].add(e[m])}let d=o;for(let m=c.length-1,p=o;m>0;m--)p=p.add(c[m]),d=d.add(p);if(l=l.add(d),f!==0)for(let m=0;m<i;m++)l=l.double()}return l}function xn(r){return ca(r.Fp),ne(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...la(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var jt=BigInt(0),Ot=BigInt(1),No=BigInt(2),Em=BigInt(8),Sm={zip215:!0};function Am(r){let t=xn(r);return ne(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Mu(r){let t=Am(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,u=No<<BigInt(a*8)-Ot,l=e.create,f=ke(t.n,t.nBitLength),d=t.uvRatio||((v,w)=>{try{return{isValid:!0,value:e.sqrt(v*e.inv(w))}}catch{return{isValid:!1,value:jt}}}),m=t.adjustScalarBytes||(v=>v),p=t.domain||((v,w,S)=>{if(Zt("phflag",S),w.length||S)throw new Error("Contexts/pre-hash are not supported");return v});function g(v,w){Bt("coordinate "+v,w,jt,u)}function h(v){if(!(v instanceof y))throw new Error("ExtendedPoint expected")}let b=je((v,w)=>{let{ex:S,ey:C,ez:M}=v,N=v.is0();w==null&&(w=N?Em:e.inv(M));let U=l(S*w),q=l(C*w),O=l(M*w);if(N)return{x:jt,y:Ot};if(O!==Ot)throw new Error("invZ was invalid");return{x:U,y:q}}),x=je(v=>{let{a:w,d:S}=t;if(v.is0())throw new Error("bad point: ZERO");let{ex:C,ey:M,ez:N,et:U}=v,q=l(C*C),O=l(M*M),j=l(N*N),tt=l(j*j),gt=l(q*w),yt=l(j*l(gt+O