OSM2IPFS/earth/helia@2.0.1.js

130 lines
1.1 MiB
JavaScript
Raw Normal View History

2023-09-03 19:14:06 +02:00
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Helia = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var Helia=(()=>{var DN=Object.create;var Oh=Object.defineProperty;var CN=Object.getOwnPropertyDescriptor;var PN=Object.getOwnPropertyNames;var kN=Object.getPrototypeOf,NN=Object.prototype.hasOwnProperty;var b6=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var et=(r,e)=>()=>(r&&(e=r(r=0)),e);var B=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),be=(r,e)=>{for(var t in e)Oh(r,t,{get:e[t],enumerable:!0})},w6=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of PN(e))!NN.call(r,i)&&i!==t&&Oh(r,i,{get:()=>e[i],enumerable:!(n=CN(e,i))||n.enumerable});return r};var j=(r,e,t)=>(t=r!=null?DN(kN(r)):{},w6(e||!r||!r.__esModule?Oh(t,"default",{value:r,enumerable:!0}):t,r)),Bh=r=>w6(Oh({},"__esModule",{value:!0}),r);var P2=B((UZ,E6)=>{var nc=1e3,ic=nc*60,sc=ic*60,ea=sc*24,ON=ea*7,BN=ea*365.25;E6.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return LN(r);if(t==="number"&&isFinite(r))return e.long?UN(r):MN(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function LN(r){if(r=String(r),!(r.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(e){var t=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return t*BN;case"weeks":case"week":case"w":return t*ON;case"days":case"day":case"d":return t*ea;case"hours":case"hour":case"hrs":case"hr":case"h":return t*sc;case"minutes":case"minute":case"mins":case"min":case"m":return t*ic;case"seconds":case"second":case"secs":case"sec":case"s":return t*nc;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function MN(r){var e=Math.abs(r);return e>=ea?Math.round(r/ea)+"d":e>=sc?Math.round(r/sc)+"h":e>=ic?Math.round(r/ic)+"m":e>=nc?Math.round(r/nc)+"s":r+"ms"}function UN(r){var e=Math.abs(r);return e>=ea?Lh(r,e,ea,"day"):e>=sc?Lh(r,e,sc,"hour"):e>=ic?Lh(r,e,ic,"minute"):e>=nc?Lh(r,e,nc,"second"):r+" ms"}function Lh(r,e,t,n){var i=e>=t*1.5;return Math.round(r/t)+" "+n+(i?"s":"")}});var v6=B((FZ,x6)=>{function FN(r){t.debug=t,t.default=t,t.coerce=c,t.disable=s,t.enable=i,t.enabled=o,t.humanize=P2(),t.destroy=u,Object.keys(r).forEach(l=>{t[l]=r[l]}),t.names=[],t.skips=[],t.formatters={};function e(l){let f=0;for(let h=0;h<l.length;h++)f=(f<<5)-f+l.charCodeAt(h),f|=0;return t.colors[Math.abs(f)%t.colors.length]}t.selectColor=e;function t(l){let f,h=null,d,p;function m(...g){if(!m.enabled)return;let y=m,b=Number(new Date),E=b-(f||b);y.diff=E,y.prev=f,y.curr=b,f=b,g[0]=t.coerce(g[0]),typeof g[0]!="string"&&g.unshift("%O");let _=0;g[0]=g[0].replace(/%([a-zA-Z%])/g,(v,R)=>{if(v==="%%")return"%";_++;let T=t.formatters[R];if(typeof T=="function"){let P=g[_];v=T.call(y,P),g.splice(_,1),_--}return v}),t.formatArgs.call(y,g),(y.log||t.log).apply(y,g)}return m.namespace=l,m.useColors=t.useColors(),m.color=t.selectColor(l),m.extend=n,m.destroy=t.destroy,Object.defineProperty(m,"enabled",{enumerable:!0,configurable:!1,get:()=>h!==null?h:(d!==t.namespaces&&(d=t.namespaces,p=t.enabled(l)),p),set:g=>{h=g}}),typeof t.init=="function"&&t.init(m),m}function n(l,f){let h=t(this.namespace+(typeof f>"u"?":":f)+l);return h.log=this.log,h}function i(l){t.save(l),t.namespaces=l,t.names=[],t.skips=[];let f,h=(typeof l=="string"?l:"").split(/[\s,]+/),d=h.length;for(f=0;f<d;f++)h[f]&&(l=h[f].replace(/\*/g,".*?"),l[0]==="-"?t.skips.push(new RegExp("^"+l.slice(1)+"$")):t.names.push(new RegExp("^"+l+"$")))}function s(){let l=[...t.names.map(a),...t.skips.map(a).map(f=>"-"+f)].join(",");return t.enable(""),l}function o(l){if(l[l.length-1]==="*")return!0;let f,h;for(f=0,h=t.skips.length;f<h;f++)if(t.skips[f].test(l))return!1;for(f=0,h=t.names.length;f<h;f++)if(t.names[f].test(l))return!0;return!1}function a(l){return l.toString().su
`)}return n};m3.decode=function(r,e){if(typeof r!="string")throw new TypeError('"input" must be a string.');if(typeof e!="string")throw new TypeError('"alphabet" must be a string.');var t=Mw[e];if(!t){t=Mw[e]=[];for(var n=0;n<e.length;++n)t[e.charCodeAt(n)]=n}r=r.replace(/\s/g,"");for(var i=e.length,s=e.charAt(0),o=[0],n=0;n<r.length;n++){var a=t[r.charCodeAt(n)];if(a===void 0)return;for(var c=0,u=a;c<o.length;++c)u+=o[c]*i,o[c]=u&255,u>>=8;for(;u>0;)o.push(u&255),u>>=8}for(var l=0;r[l]===s&&l<r.length-1;++l)o.push(0);return typeof Buffer<"u"?Buffer.from(o.reverse()):new Uint8Array(o.reverse())};function vM(r,e){var t=0,n=e.length,i=e.charAt(0),s=[0];for(t=0;t<r.length();++t){for(var o=0,a=r.at(t);o<s.length;++o)a+=s[o]<<8,s[o]=a%n,a=a/n|0;for(;a>0;)s.push(a%n),a=a/n|0}var c="";for(t=0;r.at(t)===0&&t<r.length()-1;++t)c+=i;for(t=s.length-1;t>=0;--t)c+=e[s[t]];return c}});var Nt=B(($oe,zw)=>{var Kw=Ve(),Vw=Fw(),S=zw.exports=Kw.util=Kw.util||{};(function(){if(typeof process<"u"&&process.nextTick&&!process.browser){S.nextTick=process.nextTick,typeof setImmediate=="function"?S.setImmediate=setImmediate:S.setImmediate=S.nextTick;return}if(typeof setImmediate=="function"){S.setImmediate=function(){return setImmediate.apply(void 0,arguments)},S.nextTick=function(a){return setImmediate(a)};return}if(S.setImmediate=function(a){setTimeout(a,0)},typeof window<"u"&&typeof window.postMessage=="function"){let a=function(c){if(c.source===window&&c.data===r){c.stopPropagation();var u=e.slice();e.length=0,u.forEach(function(l){l()})}};var o=a,r="forge.setImmediate",e=[];S.setImmediate=function(c){e.push(c),e.length===1&&window.postMessage(r,"*")},window.addEventListener("message",a,!0)}if(typeof MutationObserver<"u"){var t=Date.now(),n=!0,i=document.createElement("div"),e=[];new MutationObserver(function(){var c=e.slice();e.length=0,c.forEach(function(u){u()})}).observe(i,{attributes:!0});var s=S.setImmediate;S.setImmediate=function(c){Date.now()-t>15?(t=Date.now(),s(c)):(e.push(c),e.length===1&&i.setAttribute("a",n=!n))}}S.nextTick=S.setImmediate})();S.isNodejs=typeof process<"u"&&process.versions&&process.versions.node;S.globalScope=function(){return S.isNodejs?globalThis:typeof self>"u"?window:self}();S.isArray=Array.isArray||function(r){return Object.prototype.toString.call(r)==="[object Array]"};S.isArrayBuffer=function(r){return typeof ArrayBuffer<"u"&&r instanceof ArrayBuffer};S.isArrayBufferView=function(r){return r&&S.isArrayBuffer(r.buffer)&&r.byteLength!==void 0};function Vl(r){if(!(r===8||r===16||r===24||r===32))throw new Error("Only 8, 16, 24, or 32 bits supported: "+r)}S.ByteBuffer=g3;function g3(r){if(this.data="",this.read=0,typeof r=="string")this.data=r;else if(S.isArrayBuffer(r)||S.isArrayBufferView(r))if(typeof Buffer<"u"&&r instanceof Buffer)this.data=r.toString("binary");else{var e=new Uint8Array(r);try{this.data=String.fromCharCode.apply(null,e)}catch{for(var t=0;t<e.length;++t)this.putByte(e[t])}}else(r instanceof g3||typeof r=="object"&&typeof r.data=="string"&&typeof r.read=="number")&&(this.data=r.data,this.read=r.read);this._constructedStringLength=0}S.ByteStringBuffer=g3;var _M=4096;S.ByteStringBuffer.prototype._optimizeConstructedString=function(r){this._constructedStringLength+=r,this._constructedStringLength>_M&&(this.data.substr(0,1),this._constructedStringLength=0)};S.ByteStringBuffer.prototype.length=function(){return this.data.length-this.read};S.ByteStringBuffer.prototype.isEmpty=function(){return this.length()<=0};S.ByteStringBuffer.prototype.putByte=function(r){return this.putBytes(String.fromCharCode(r))};S.ByteStringBuffer.prototype.fillWithByte=function(r,e){r=String.fromCharCode(r);for(var t=this.data;e>0;)e&1&&(t+=r),e>>>=1,e>0&&(r+=r);return this.data=t,this._optimizeConstructedString(e),this};S.ByteStringBuffer.prototype.putBytes=function(r){return this.data+=r,this._optimizeConstructedString(r.length),this};S.ByteStringBuffer.prototype.putString=function(r){return this.putBytes(S.encodeUtf8(r))};S.ByteStringBuffer.prototype.putInt16=function(r){return this.putBytes(String.fromCharCode(r>>8&2
`,t=t.substr(e));return n+=t,n};S.decode64=function(r){r=r.replace(/[^A-Za-z0-9\+\/\=]/g,"");for(var e="",t,n,i,s,o=0;o<r.length;)t=oo[r.charCodeAt(o++)-43],n=oo[r.charCodeAt(o++)-43],i=oo[r.charCodeAt(o++)-43],s=oo[r.charCodeAt(o++)-43],e+=String.fromCharCode(t<<2|n>>4),i!==64&&(e+=String.fromCharCode((n&15)<<4|i>>2),s!==64&&(e+=String.fromCharCode((i&3)<<6|s)));return e};S.encodeUtf8=function(r){return unescape(encodeURIComponent(r))};S.decodeUtf8=function(r){return decodeURIComponent(escape(r))};S.binary={raw:{},hex:{},base64:{},base58:{},baseN:{encode:Vw.encode,decode:Vw.decode}};S.binary.raw.encode=function(r){return String.fromCharCode.apply(null,r)};S.binary.raw.decode=function(r,e,t){var n=e;n||(n=new Uint8Array(r.length)),t=t||0;for(var i=t,s=0;s<r.length;++s)n[i++]=r.charCodeAt(s);return e?i-t:n};S.binary.hex.encode=S.bytesToHex;S.binary.hex.decode=function(r,e,t){var n=e;n||(n=new Uint8Array(Math.ceil(r.length/2))),t=t||0;var i=0,s=t;for(r.length&1&&(i=1,n[s++]=parseInt(r[0],16));i<r.length;i+=2)n[s++]=parseInt(r.substr(i,2),16);return e?s-t:n};S.binary.base64.encode=function(r,e){for(var t="",n="",i,s,o,a=0;a<r.byteLength;)i=r[a++],s=r[a++],o=r[a++],t+=so.charAt(i>>2),t+=so.charAt((i&3)<<4|s>>4),isNaN(s)?t+="==":(t+=so.charAt((s&15)<<2|o>>6),t+=isNaN(o)?"=":so.charAt(o&63)),e&&t.length>e&&(n+=t.substr(0,e)+`\r
`,t=t.substr(e));return n+=t,n};S.binary.base64.decode=function(r,e,t){var n=e;n||(n=new Uint8Array(Math.ceil(r.length/4)*3)),r=r.replace(/[^A-Za-z0-9\+\/\=]/g,""),t=t||0;for(var i,s,o,a,c=0,u=t;c<r.length;)i=oo[r.charCodeAt(c++)-43],s=oo[r.charCodeAt(c++)-43],o=oo[r.charCodeAt(c++)-43],a=oo[r.charCodeAt(c++)-43],n[u++]=i<<2|s>>4,o!==64&&(n[u++]=(s&15)<<4|o>>2,a!==64&&(n[u++]=(o&3)<<6|a));return e?u-t:n.subarray(0,u)};S.binary.base58.encode=function(r,e){return S.binary.baseN.encode(r,qw,e)};S.binary.base58.decode=function(r,e){return S.binary.baseN.decode(r,qw,e)};S.text={utf8:{},utf16:{}};S.text.utf8.encode=function(r,e,t){r=S.encodeUtf8(r);var n=e;n||(n=new Uint8Array(r.length)),t=t||0;for(var i=t,s=0;s<r.length;++s)n[i++]=r.charCodeAt(s);return e?i-t:n};S.text.utf8.decode=function(r){return S.decodeUtf8(String.fromCharCode.apply(null,r))};S.text.utf16.encode=function(r,e,t){var n=e;n||(n=new Uint8Array(r.length*2));var i=new Uint16Array(n.buffer);t=t||0;for(var s=t,o=t,a=0;a<r.length;++a)i[o++]=r.charCodeAt(a),s+=2;return e?s-t:n};S.text.utf16.decode=function(r){return String.fromCharCode.apply(null,new Uint16Array(r.buffer))};S.deflate=function(r,e,t){if(e=S.decode64(r.deflate(S.encode64(e)).rval),t){var n=2,i=e.charCodeAt(1);i&32&&(n=6),e=e.substring(n,e.length-4)}return e};S.inflate=function(r,e,t){var n=r.inflate(S.encode64(e)).rval;return n===null?null:S.decode64(n)};var y3=function(r,e,t){if(!r)throw new Error("WebStorage not available.");var n;if(t===null?n=r.removeItem(e):(t=S.encode64(JSON.stringify(t)),n=r.setItem(e,t)),typeof n<"u"&&n.rval!==!0){var i=new Error(n.error.message);throw i.id=n.error.id,i.name=n.error.name,i}},b3=function(r,e){if(!r)throw new Error("WebStorage not available.");var t=r.getItem(e);if(r.init)if(t.rval===null){if(t.error){var n=new Error(t.error.message);throw n.id=t.error.id,n.name=t.error.name,n}t=null}else t=t.rval;return t!==null&&(t=JSON.parse(S.decode64(t))),t},RM=function(r,e,t,n){var i=b3(r,e);i===null&&(i={}),i[t]=n,y3(r,e,i)},IM=function(r,e,t){var n=b3(r,e);return n!==null&&(n=t in n?n[t]:null),n},AM=function(r,e,t){var n=b3(r,e);if(n!==null&&t in n){delete n[t];var i=!0;for(var s in n){i=!1;break}i&&(n=null),y3(r,e,n)}},TM=function(r,e){y3(r,e,null)},z0=function(r,e,t){var n=null;typeof t>"u"&&(t=["web","flash"]);var i,s=!1,o=null;for(var a in t){i=t[a];try{if(i==="flash"||i==="both"){if(e[0]===null)throw new Error("Flash local storage not available.");n=r.apply(this,e),s=i==="flash"}(i==="web"||i==="both")&&(e[0]=localStorage,n=r.apply(this,e),s=!0)}catch(c){o=c}if(s)break}if(!s)throw o;return n};S.setItem=function(r,e,t,n,i){z0(RM,arguments,i)};S.getItem=function(r,e,t,n){return z0(IM,arguments,n)};S.removeItem=function(r,e,t,n){z0(AM,arguments,n)};S.clearItems=function(r,e,t){z0(TM,arguments,t)};S.isEmpty=function(r){for(var e in r)if(r.hasOwnProperty(e))return!1;return!0};S.format=function(r){for(var e=/%./g,t,n,i=0,s=[],o=0;t=e.exec(r);){n=r.substring(o,e.lastIndex-2),n.length>0&&s.push(n),o=e.lastIndex;var a=t[0][1];switch(a){case"s":case"o":i<arguments.length?s.push(arguments[i+++1]):s.push("<?>");break;case"%":s.push("%");break;default:s.push("<%"+a+"?>")}}return s.push(r.substring(o)),s.join("")};S.formatNumber=function(r,e,t,n){var i=r,s=isNaN(e=Math.abs(e))?2:e,o=t===void 0?",":t,a=n===void 0?".":n,c=i<0?"-":"",u=parseInt(i=Math.abs(+i||0).toFixed(s),10)+"",l=u.length>3?u.length%3:0;return c+(l?u.substr(0,l)+a:"")+u.substr(l).replace(/(\d{3})(?=\d)/g,"$1"+a)+(s?o+Math.abs(i-u).toFixed(s).slice(2):"")};S.formatSize=function(r){return r>=1073741824?r=S.formatNumber(r/1073741824,2,".","")+" GiB":r>=1048576?r=S.formatNumber(r/1048576,2,".","")+" MiB":r>=1024?r=S.formatNumber(r/1024,0)+" KiB":r=S.formatNumber(r,0)+" bytes",r};S.bytesFromIP=function(r){return r.indexOf(".")!==-1?S.bytesFromIPv4(r):r.indexOf(":")!==-1?S.bytesFromIPv6(r):null};S.bytesFromIPv4=function(r){if(r=r.split("."),r.length!==4)return null;for(var e=S.createBuffer(),t=0;t<r.length;++t){var n=parseInt(r[t],10);if(isNaN(n))return null;e.putByte(n)}return e.getBytes()};S.bytesFromIPv6=function(
`);for(var i="",s=0;s<e*t;++s)i+=" ";switch(n+=i+"Tag: ",r.tagClass){case ee.Class.UNIVERSAL:n+="Universal:";break;case ee.Class.APPLICATION:n+="Application:";break;case ee.Class.CONTEXT_SPECIFIC:n+="Context-Specific:";break;case ee.Class.PRIVATE:n+="Private:";break}if(r.tagClass===ee.Class.UNIVERSAL)switch(n+=r.type,r.type){case ee.Type.NONE:n+=" (None)";break;case ee.Type.BOOLEAN:n+=" (Boolean)";break;case ee.Type.INTEGER:n+=" (Integer)";break;case ee.Type.BITSTRING:n+=" (Bit string)";break;case ee.Type.OCTETSTRING:n+=" (Octet string)";break;case ee.Type.NULL:n+=" (Null)";break;case ee.Type.OID:n+=" (Object Identifier)";break;case ee.Type.ODESC:n+=" (Object Descriptor)";break;case ee.Type.EXTERNAL:n+=" (External or Instance of)";break;case ee.Type.REAL:n+=" (Real)";break;case ee.Type.ENUMERATED:n+=" (Enumerated)";break;case ee.Type.EMBEDDED:n+=" (Embedded PDV)";break;case ee.Type.UTF8:n+=" (UTF8)";break;case ee.Type.ROID:n+=" (Relative Object Identifier)";break;case ee.Type.SEQUENCE:n+=" (Sequence)";break;case ee.Type.SET:n+=" (Set)";break;case ee.Type.PRINTABLESTRING:n+=" (Printable String)";break;case ee.Type.IA5String:n+=" (IA5String (ASCII))";break;case ee.Type.UTCTIME:n+=" (UTC time)";break;case ee.Type.GENERALIZEDTIME:n+=" (Generalized time)";break;case ee.Type.BMPSTRING:n+=" (BMP String)";break}else n+=r.type;if(n+=`
`,n+=i+"Constructed: "+r.constructed+`
`,r.composed){for(var o=0,a="",s=0;s<r.value.length;++s)r.value[s]!==void 0&&(o+=1,a+=ee.prettyPrint(r.value[s],e+1,t),s+1<r.value.length&&(a+=","));n+=i+"Sub values: "+o+a}else{if(n+=i+"Value: ",r.type===ee.Type.OID){var c=ee.derToOid(r.value);n+=c,mt.pki&&mt.pki.oids&&c in mt.pki.oids&&(n+=" ("+mt.pki.oids[c]+") ")}if(r.type===ee.Type.INTEGER)try{n+=ee.derToInteger(r.value)}catch{n+="0x"+mt.util.bytesToHex(r.value)}else if(r.type===ee.Type.BITSTRING){if(r.value.length>1?n+="0x"+mt.util.bytesToHex(r.value.slice(1)):n+="(none)",r.value.length>0){var u=r.value.charCodeAt(0);u==1?n+=" (1 unused bit shown)":u>1&&(n+=" ("+u+" unused bits shown)")}}else if(r.type===ee.Type.OCTETSTRING)Hw.test(r.value)||(n+="("+r.value+") "),n+="0x"+mt.util.bytesToHex(r.value);else if(r.type===ee.Type.UTF8)try{n+=mt.util.decodeUtf8(r.value)}catch(l){if(l.message==="URI malformed")n+="0x"+mt.util.bytesToHex(r.value)+" (malformed UTF8)";else throw l}else r.type===ee.Type.PRINTABLESTRING||r.type===ee.Type.IA5String?n+=r.value:Hw.test(r.value)?n+="0x"+mt.util.bytesToHex(r.value):r.value.length===0?n+="[null]":n+=r.value}return n}});var x3=B((Woe,Ww)=>{var ar=Ve();Nt();Ww.exports=ar.cipher=ar.cipher||{};ar.cipher.algorithms=ar.cipher.algorithms||{};ar.cipher.createCipher=function(r,e){var t=r;if(typeof t=="string"&&(t=ar.cipher.getAlgorithm(t),t&&(t=t())),!t)throw new Error("Unsupported algorithm: "+r);return new ar.cipher.BlockCipher({algorithm:t,key:e,decrypt:!1})};ar.cipher.createDecipher=function(r,e){var t=r;if(typeof t=="string"&&(t=ar.cipher.getAlgorithm(t),t&&(t=t())),!t)throw new Error("Unsupported algorithm: "+r);return new ar.cipher.BlockCipher({algorithm:t,key:e,decrypt:!0})};ar.cipher.registerAlgorithm=function(r,e){r=r.toUpperCase(),ar.cipher.algorithms[r]=e};ar.cipher.getAlgorithm=function(r){return r=r.toUpperCase(),r in ar.cipher.algorithms?ar.cipher.algorithms[r]:null};var E3=ar.cipher.BlockCipher=function(r){this.algorithm=r.algorithm,this.mode=this.algorithm.mode,this.blockSize=this.mode.blockSize,this._finish=!1,this._input=null,this.output=null,this._op=r.decrypt?this.mode.decrypt:this.mode.encrypt,this._decrypt=r.decrypt,this.algorithm.initialize(r)};E3.prototype.start=function(r){r=r||{};var e={};for(var t in r)e[t]=r[t];e.decrypt=this._decrypt,this._finish=!1,this._input=ar.util.createBuffer(),this.output=r.output||ar.util.createBuffer(),this.mode.start(e)};E3.prototype.update=function(r){for(r&&this._input.putBuffer(r);!this._op.call(this.mode,this._input,this.output,this._finish)&&!this._finish;);this._input.compact()};E3.prototype.finish=function(r){r&&(this.mode.name==="ECB"||this.mode.name==="CBC")&&(this.mode.pad=function(t){return r(this.blockSize,t,!1)},this.mode.unpad=function(t){return r(this.blockSize,t,!0)});var e={};return e.decrypt=this._decrypt,e.overflow=this._input.length()%this.blockSize,!(!this._decrypt&&this.mode.pad&&!this.mode.pad(this._input,e)||(this._finish=!0,this.update(),this._decrypt&&this.mode.unpad&&!this.mode.unpad(this.output,e))||this.mode.afterFinish&&!this.mode.afterFinish(this.output,e))}});var _3=B((Yoe,Yw)=>{var cr=Ve();Nt();cr.cipher=cr.cipher||{};var Ue=Yw.exports=cr.cipher.modes=cr.cipher.modes||{};Ue.ecb=function(r){r=r||{},this.name="ECB",this.cipher=r.cipher,this.blockSize=r.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints)};Ue.ecb.prototype.start=function(r){};Ue.ecb.prototype.encrypt=function(r,e,t){if(r.length()<this.blockSize&&!(t&&r.length()>0))return!0;for(var n=0;n<this._ints;++n)this._inBlock[n]=r.getInt32();this.cipher.encrypt(this._inBlock,this._outBlock);for(var n=0;n<this._ints;++n)e.putInt32(this._outBlock[n])};Ue.ecb.prototype.decrypt=function(r,e,t){if(r.length()<this.blockSize&&!(t&&r.length()>0))return!0;for(var n=0;n<this._ints;++n)this._inBlock[n]=r.getInt32();this.cipher.decrypt(this._inBlock,this._outBlock);for(var n=0;n<this._ints;++n)e.putInt32(this._outBlock[n])};Ue.ecb.prototype.pad=function(r,e){var t=r.length()===this.blockSize?this.blockSize:this.blockSize-r.length();return r.fillWithByt
`,n;if(r.procType&&(n={name:"Proc-Type",values:[String(r.procType.version),r.procType.type]},t+=Z0(n)),r.contentDomain&&(n={name:"Content-Domain",values:[r.contentDomain]},t+=Z0(n)),r.dekInfo&&(n={name:"DEK-Info",values:[r.dekInfo.algorithm]},r.dekInfo.parameters&&n.values.push(r.dekInfo.parameters),t+=Z0(n)),r.headers)for(var i=0;i<r.headers.length;++i)t+=Z0(r.headers[i]);return r.procType&&(t+=`\r
`),t+=J0.util.encode64(r.body,e.maxline||64)+`\r
`,t+="-----END "+r.type+`-----\r
`,t};oE.decode=function(r){for(var e=[],t=/\s*-----BEGIN ([A-Z0-9- ]+)-----\r?\n?([\x21-\x7e\s]+?(?:\r?\n\r?\n))?([:A-Za-z0-9+\/=\s]+?)-----END \1-----/g,n=/([\x21-\x7e]+):\s*([\x21-\x7e\s^:]+)/,i=/\r?\n/,s;s=t.exec(r),!!s;){var o=s[1];o==="NEW CERTIFICATE REQUEST"&&(o="CERTIFICATE REQUEST");var a={type:o,procType:null,contentDomain:null,dekInfo:null,headers:[],body:J0.util.decode64(s[3])};if(e.push(a),!!s[2]){for(var c=s[2].split(i),u=0;s&&u<c.length;){for(var l=c[u].replace(/\s+$/,""),f=u+1;f<c.length;++f){var h=c[f];if(!/\s/.test(h[0]))break;l+=h,u=f}if(s=l.match(n),s){for(var d={name:s[1],values:[]},p=s[2].split(","),m=0;m<p.length;++m)d.values.push(VM(p[m]));if(a.procType)if(!a.contentDomain&&d.name==="Content-Domain")a.contentDomain=p[0]||"";else if(!a.dekInfo&&d.name==="DEK-Info"){if(d.values.length===0)throw new Error('Invalid PEM formatted message. The "DEK-Info" header must have at least one subfield.');a.dekInfo={algorithm:p[0],parameters:p[1]||null}}else a.headers.push(d);else{if(d.name!=="Proc-Type")throw new Error('Invalid PEM formatted message. The first encapsulated header must be "Proc-Type".');if(d.values.length!==2)throw new Error('Invalid PEM formatted message. The "Proc-Type" header must have two subfields.');a.procType={version:p[0],type:p[1]}}}++u}if(a.procType==="ENCRYPTED"&&!a.dekInfo)throw new Error('Invalid PEM formatted message. The "DEK-Info" header must be present if "Proc-Type" is "ENCRYPTED".')}}if(e.length===0)throw new Error("Invalid PEM formatted message.");return e};function Z0(r){for(var e=r.name+": ",t=[],n=function(c,u){return" "+u},i=0;i<r.values.length;++i)t.push(r.values[i].replace(/^(\S+\r\n)/,n));e+=t.join(",")+`\r
`;for(var s=0,o=-1,i=0;i<e.length;++i,++s)if(s>65&&o!==-1){var a=e[o];a===","?(++o,e=e.substr(0,o)+`\r
`+e.substr(o)):e=e.substr(0,o)+`\r
`+a+e.substr(o+1),s=i-o-1,o=-1,++i}else(e[i]===" "||e[i]===" "||e[i]===",")&&(o=i);return e}function VM(r){return r.replace(/^\s+/,"")}});var pE=B((nae,dE)=>{var Hi=Ve();ya();Nt();var lE=dE.exports=Hi.sha256=Hi.sha256||{};Hi.md.sha256=Hi.md.algorithms.sha256=lE;lE.create=function(){fE||qM();var r=null,e=Hi.util.createBuffer(),t=new Array(64),n={algorithm:"sha256",blockLength:64,digestLength:32,messageLength:0,fullMessageLength:null,messageLengthSize:8};return n.start=function(){n.messageLength=0,n.fullMessageLength=n.messageLength64=[];for(var i=n.messageLengthSize/4,s=0;s<i;++s)n.fullMessageLength.push(0);return e=Hi.util.createBuffer(),r={h0:1779033703,h1:3144134277,h2:1013904242,h3:2773480762,h4:1359893119,h5:2600822924,h6:528734635,h7:1541459225},n},n.start(),n.update=function(i,s){s==="utf8"&&(i=Hi.util.encodeUtf8(i));var o=i.length;n.messageLength+=o,o=[o/4294967296>>>0,o>>>0];for(var a=n.fullMessageLength.length-1;a>=0;--a)n.fullMessageLength[a]+=o[1],o[1]=o[0]+(n.fullMessageLength[a]/4294967296>>>0),n.fullMessageLength[a]=n.fullMessageLength[a]>>>0,o[0]=o[1]/4294967296>>>0;return e.putBytes(i),uE(r,t,e),(e.read>2048||e.length()===0)&&e.compact(),n},n.digest=function(){var i=Hi.util.createBuffer();i.putBytes(e.bytes());var s=n.fullMessageLength[n.fullMessageLength.length-1]+n.messageLengthSize,o=s&n.blockLength-1;i.putBytes(T3.substr(0,n.blockLength-o));for(var a,c,u=n.fullMessageLength[0]*8,l=0;l<n.fullMessageLength.length-1;++l)a=n.fullMessageLength[l+1]*8,c=a/4294967296>>>0,u+=c,i.putInt32(u>>>0),u=a>>>0;i.putInt32(u);var f={h0:r.h0,h1:r.h1,h2:r.h2,h3:r.h3,h4:r.h4,h5:r.h5,h6:r.h6,h7:r.h7};uE(f,t,i);var h=Hi.util.createBuffer();return h.putInt32(f.h0),h.putInt32(f.h1),h.putInt32(f.h2),h.putInt32(f.h3),h.putInt32(f.h4),h.putInt32(f.h5),h.putInt32(f.h6),h.putInt32(f.h7),h},n};var T3=null,fE=!1,hE=null;function qM(){T3=String.fromCharCode(128),T3+=Hi.util.fillString(String.fromCharCode(0),64),hE=[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],fE=!0}function uE(r,e,t){for(var n,i,s,o,a,c,u,l,f,h,d,p,m,g,y,b=t.length();b>=64;){for(u=0;u<16;++u)e[u]=t.getInt32();for(;u<64;++u)n=e[u-2],n=(n>>>17|n<<15)^(n>>>19|n<<13)^n>>>10,i=e[u-15],i=(i>>>7|i<<25)^(i>>>18|i<<14)^i>>>3,e[u]=n+e[u-7]+i+e[u-16]|0;for(l=r.h0,f=r.h1,h=r.h2,d=r.h3,p=r.h4,m=r.h5,g=r.h6,y=r.h7,u=0;u<64;++u)o=(p>>>6|p<<26)^(p>>>11|p<<21)^(p>>>25|p<<7),a=g^p&(m^g),s=(l>>>2|l<<30)^(l>>>13|l<<19)^(l>>>22|l<<10),c=l&f|h&(l^f),n=y+o+a+hE[u]+e[u],i=s+c,y=g,g=m,m=p,p=d+n>>>0,d=h,h=f,f=l,l=n+i>>>0;r.h0=r.h0+l|0,r.h1=r.h1+f|0,r.h2=r.h2+h|0,r.h3=r.h3+d|0,r.h4=r.h4+p|0,r.h5=r.h5+m|0,r.h6=r.h6+g|0,r.h7=r.h7+y|0,b-=64}}});var gE=B((iae,mE)=>{var Gi=Ve();Nt();var ed=null;Gi.util.isNodejs&&!Gi.options.usePureJavaScript&&!process.versions["node-webkit"]&&(ed=ba());var zM=mE.exports=Gi.prng=Gi.prng||{};zM.create=function(r){for(var e={plugin:r,key:null,seed:null,time:null,reseeds:0,generated:0,keyBytes:""},t=r.md,n=new Array(32),i=0;i<32;++i)n[i]=t.create();e.pools=n,e.pool=0,e.generate=function(u,l){if(!l)return e.generateSync(u);var f=e.plugin.cipher,h=e.plugin.increment,d=e.plugin.formatKey,p=e.plugin.formatSeed,m=Gi.util.createBuffer();e.key=null,g();function g(y){if(y)return l(y);if(m.length()>=u)return l(null,m.getBytes(u));if(e.generated>1048575&&(e.key=null),e.key===null)return Gi.util.nextTick(function(){s(g)});var b=f(e.key,e.seed);e.generated+=b.length,m.putBytes(b),e.key=d(f(e.key,h(e.seed))),e.seed=p(f(e.key,e.seed)),Gi.util.setImme
ON DUPLICATE KEY UPDATE
points = ?,
expire = ?;`,h=[this.dbName,this.tableName,t,n,l,n,l]):(f=`INSERT INTO ??.?? VALUES (?, ?, ?)
ON DUPLICATE KEY UPDATE
points = IF(expire <= ?, ?, points + (?)),
expire = IF(expire <= ?, ?, expire);`,h=[this.dbName,this.tableName,t,n,l,u,n,n,u,l]),e.query(f,h,d=>{if(d)return e.rollback(),a(d);e.query("SELECT points, expire FROM ??.?? WHERE `key` = ?;",[this.dbName,this.tableName,t],(p,m)=>{if(p)return e.rollback(),a(p);e.query("COMMIT",g=>{if(g)return e.rollback(),a(g);o(m)})})})})})}_upsert(e,t,n,i=!1){return this.tableCreated?new Promise((s,o)=>{this._getConnection().then(a=>{this._upsertTransaction(a,e,t,n,i).then(c=>{s(c),this._releaseConnection(a)}).catch(c=>{o(c),this._releaseConnection(a)})}).catch(a=>{o(a)})}):Promise.reject(Error("Table is not created yet"))}_get(e){return this.tableCreated?new Promise((t,n)=>{this._getConnection().then(i=>{i.query("SELECT points, expire FROM ??.?? WHERE `key` = ? AND (`expire` > ? OR `expire` IS NULL)",[this.dbName,this.tableName,e,Date.now()],(s,o)=>{s?n(s):o.length===0?t(null):t(o),this._releaseConnection(i)})}).catch(i=>{n(i)})}):Promise.reject(Error("Table is not created yet"))}_delete(e){return this.tableCreated?new Promise((t,n)=>{this._getConnection().then(i=>{i.query("DELETE FROM ??.?? WHERE `key` = ?",[this.dbName,this.tableName,e],(s,o)=>{s?n(s):t(o.affectedRows>0),this._releaseConnection(i)})}).catch(i=>{n(i)})}):Promise.reject(Error("Table is not created yet"))}};F_.exports=Z4});var q_=B((r1e,V_)=>{var oz=Zc(),az=bn(),J4=class extends oz{constructor(e,t=null){super(e),this.client=e.storeClient,this.clientType=e.storeType,this.tableName=e.tableName,this.clearExpiredByTimeout=e.clearExpiredByTimeout,this.tableCreated=e.tableCreated,this.tableCreated?typeof t=="function"&&t():this._createTable().then(()=>{this.tableCreated=!0,this.clearExpiredByTimeout&&this._clearExpiredHourAgo(),typeof t=="function"&&t()}).catch(n=>{if(typeof t=="function")t(n);else throw n})}clearExpired(e){return new Promise(t=>{let n={name:"rlflx-clear-expired",text:`DELETE FROM ${this.tableName} WHERE expire < $1`,values:[e]};this._query(n).then(()=>{t()}).catch(()=>{t()})})}_clearExpiredHourAgo(){this._clearExpiredTimeoutId&&clearTimeout(this._clearExpiredTimeoutId),this._clearExpiredTimeoutId=setTimeout(()=>{this.clearExpired(Date.now()-36e5).then(()=>{this._clearExpiredHourAgo()})},3e5),this._clearExpiredTimeoutId.unref()}_getConnection(){switch(this.clientType){case"pool":return Promise.resolve(this.client);case"sequelize":return this.client.connectionManager.getConnection();case"knex":return this.client.client.acquireConnection();case"typeorm":return Promise.resolve(this.client.driver.master);default:return Promise.resolve(this.client)}}_releaseConnection(e){switch(this.clientType){case"pool":return!0;case"sequelize":return this.client.connectionManager.releaseConnection(e);case"knex":return this.client.client.releaseConnection(e);case"typeorm":return!0;default:return!0}}_createTable(){return new Promise((e,t)=>{this._query({text:this._getCreateTableStmt()}).then(()=>{e()}).catch(n=>{n.code==="23505"?e():t(n)})})}_getCreateTableStmt(){return`CREATE TABLE IF NOT EXISTS ${this.tableName} (
key varchar(255) PRIMARY KEY,
points integer NOT NULL DEFAULT 0,
expire bigint
);`}get clientType(){return this._clientType}set clientType(e){let t=this.client.constructor.name;if(typeof e>"u")if(t==="Client")e="client";else if(t==="Pool"||t==="BoundPool")e="pool";else if(t==="Sequelize")e="sequelize";else throw new Error("storeType is not defined");this._clientType=e.toLowerCase()}get tableName(){return this._tableName}set tableName(e){this._tableName=typeof e>"u"?this.keyPrefix:e}get tableCreated(){return this._tableCreated}set tableCreated(e){this._tableCreated=typeof e>"u"?!1:!!e}get clearExpiredByTimeout(){return this._clearExpiredByTimeout}set clearExpiredByTimeout(e){this._clearExpiredByTimeout=typeof e>"u"?!0:!!e}_getRateLimiterRes(e,t,n){let i=new az,s=n.rows[0];return i.isFirstInDuration=t===s.points,i.consumedPoints=i.isFirstInDuration?t:s.points,i.remainingPoints=Math.max(this.points-i.consumedPoints,0),i.msBeforeNext=s.expire?Math.max(s.expire-Date.now(),0):-1,i}_query(e){let n={name:`${this.tableName.toLowerCase()}:${e.name}`,text:e.text,values:e.values};return new Promise((i,s)=>{this._getConnection().then(o=>{o.query(n).then(a=>{i(a),this._releaseConnection(o)}).catch(a=>{s(a),this._releaseConnection(o)})}).catch(o=>{s(o)})})}_upsert(e,t,n,i=!1){if(!this.tableCreated)return Promise.reject(Error("Table is not created yet"));let s=n>0?Date.now()+n:null,o=i?" $3 ":` CASE
WHEN ${this.tableName}.expire <= $4 THEN $3
ELSE ${this.tableName}.expire
END `;return this._query({name:i?"rlflx-upsert-force":"rlflx-upsert",text:`
INSERT INTO ${this.tableName} VALUES ($1, $2, $3)
ON CONFLICT(key) DO UPDATE SET
points = CASE
WHEN (${this.tableName}.expire <= $4 OR 1=${i?1:0}) THEN $2
ELSE ${this.tableName}.points + ($2)
END,
expire = ${o}
RETURNING points, expire;`,values:[e,t,s,Date.now()]})}_get(e){return this.tableCreated?new Promise((t,n)=>{this._query({name:"rlflx-get",text:`
SELECT points, expire FROM ${this.tableName} WHERE key = $1 AND (expire > $2 OR expire IS NULL);`,values:[e,Date.now()]}).then(i=>{i.rowCount===0&&(i=null),t(i)}).catch(i=>{n(i)})}):Promise.reject(Error("Table is not created yet"))}_delete(e){return this.tableCreated?this._query({name:"rlflx-delete",text:`DELETE FROM ${this.tableName} WHERE key = $1`,values:[e]}).then(t=>t.rowCount>0):Promise.reject(Error("Table is not created yet"))}};V_.exports=J4});var z_=B(()=>{});var H_=B((o1e,$_)=>{$_.exports=class{constructor(e,t,n=null){this.value=e,this.expiresAt=t,this.timeoutId=n}get value(){return this._value}set value(e){this._value=parseInt(e)}get expiresAt(){return this._expiresAt}set expiresAt(e){!(e instanceof Date)&&Number.isInteger(e)&&(e=new Date(e)),this._expiresAt=e}get timeoutId(){return this._timeoutId}set timeoutId(e){this._timeoutId=e}}});var W_=B((c1e,G_)=>{var cz=H_(),eg=bn();G_.exports=class{constructor(){this._storage={}}incrby(e,t,n){if(this._storage[e]){let i=this._storage[e].expiresAt?this._storage[e].expiresAt.getTime()-new Date().getTime():-1;return i!==0?(this._storage[e].value=this._storage[e].value+t,new eg(0,i,this._storage[e].value,!1)):this.set(e,t,n)}return this.set(e,t,n)}set(e,t,n){let i=n*1e3;return this._storage[e]&&this._storage[e].timeoutId&&clearTimeout(this._storage[e].timeoutId),this._storage[e]=new cz(t,i>0?new Date(Date.now()+i):null),i>0&&(this._storage[e].timeoutId=setTimeout(()=>{delete this._storage[e]},i),this._storage[e].timeoutId.unref&&this._storage[e].timeoutId.unref()),new eg(0,i===0?-1:i,this._storage[e].value,!0)}get(e){if(this._storage[e]){let t=this._storage[e].expiresAt?this._storage[e].expiresAt.getTime()-new Date().getTime():-1;return new eg(0,t,this._storage[e].value,!1)}return null}delete(e){return this._storage[e]?(this._storage[e].timeoutId&&clearTimeout(this._storage[e].timeoutId),delete this._storage[e],!0):!1}}});var rg=B((u1e,Q_)=>{var uz=bf(),lz=W_(),Y_=bn(),tg=class extends uz{constructor(e={}){super(e),this._memoryStorage=new lz}consume(e,t=1,n={}){return new Promise((i,s)=>{let o=this.getKey(e),a=this._getKeySecDuration(n),c=this._memoryStorage.incrby(o,t,a);if(c.remainingPoints=Math.max(this.points-c.consumedPoints,0),c.consumedPoints>this.points)this.blockDuration>0&&c.consumedPoints<=this.points+t&&(c=this._memoryStorage.set(o,c.consumedPoints,this.blockDuration)),s(c);else if(this.execEvenly&&c.msBeforeNext>0&&!c.isFirstInDuration){let u=Math.ceil(c.msBeforeNext/(c.remainingPoints+2));u<this.execEvenlyMinDelayMs&&(u=c.consumedPoints*this.execEvenlyMinDelayMs),setTimeout(i,u,c)}else i(c)})}penalty(e,t=1,n={}){let i=this.getKey(e);return new Promise(s=>{let o=this._getKeySecDuration(n),a=this._memoryStorage.incrby(i,t,o);a.remainingPoints=Math.max(this.points-a.consumedPoints,0),s(a)})}reward(e,t=1,n={}){let i=this.getKey(e);return new Promise(s=>{let o=this._getKeySecDuration(n),a=this._memoryStorage.incrby(i,-t,o);a.remainingPoints=Math.max(this.points-a.consumedPoints,0),s(a)})}block(e,t){let n=t*1e3,i=this.points+1;return this._memoryStorage.set(this.getKey(e),i,t),Promise.resolve(new Y_(0,n===0?-1:n,i))}set(e,t,n){let i=(n>=0?n:this.duration)*1e3;return this._memoryStorage.set(this.getKey(e),t,n),Promise.resolve(new Y_(0,i===0?-1:i,t))}get(e){let t=this._memoryStorage.get(this.getKey(e));return t!==null&&(t.remainingPoints=Math.max(this.points-t.consumedPoints,0)),Promise.resolve(t)}delete(e){return Promise.resolve(this._memoryStorage.delete(this.getKey(e)))}};Q_.exports=tg});var rS=B((l1e,tS)=>{var X_=z_(),fz=ba(),hz=bf(),Z_=rg(),dz=bn(),Wn="rate_limiter_flexible",tu=null,j_=function(r,e,t,n){let i;n===null||n===!0||n===!1?i=n:i={remainingPoints:n.remainingPoints,msBeforeNext:n.msBeforeNext,consumedPoints:n.consumedPoints,isFirstInDuration:n.isFirstInDuration},r.send({channel:Wn,keyPrefix:e.keyPrefix,promiseId:e.promiseId,type:t,data:i})},J_=function(r){setTimeout(()=>{this._initiated?process.send(r):typeof this._promises[r.promiseId]<"u"&&J_.call(this,r)},30)},Jc=function(r,e,t,n,i){let s={channel:Wn,keyPrefix:this.keyPrefix,func:r,pro
`}()});var SI=B((R8e,F1)=>{F1.exports=uy();F1.exports.parse=uy();F1.exports.stringify=_I()});var GI=B((a6e,HI)=>{HI.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function i(s,o){t[s]=o,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(s){return t[s]!==void 0||n[s]!==void 0},remove:function(s){t[s]!==void 0&&(t[s]=void 0),n[s]!==void 0&&(n[s]=void 0)},get:function(s){var o=t[s];if(o!==void 0)return o;if((o=n[s])!==void 0)return i(s,o),o},set:function(s,o){t[s]!==void 0?t[s]=o:i(s,o)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var FA=B((Ewe,UA)=>{"use strict";function $G(r){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),t=0;t<e.length;t++)e[t]=255;for(var n=0;n<r.length;n++){var i=r.charAt(n),s=i.charCodeAt(0);if(e[s]!==255)throw new TypeError(i+" is ambiguous");e[s]=n}var o=r.length,a=r.charAt(0),c=Math.log(o)/Math.log(256),u=Math.log(256)/Math.log(o);function l(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var p=0,m=0,g=0,y=d.length;g!==y&&d[g]===0;)g++,p++;for(var b=(y-g)*u+1>>>0,E=new Uint8Array(b);g!==y;){for(var _=d[g],x=0,v=b-1;(_!==0||x<m)&&v!==-1;v--,x++)_+=256*E[v]>>>0,E[v]=_%o>>>0,_=_/o>>>0;if(_!==0)throw new Error("Non-zero carry");m=x,g++}for(var R=b-m;R!==b&&E[R]===0;)R++;for(var T=a.repeat(p);R<b;++R)T+=r.charAt(E[R]);return T}function f(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var p=0;if(d[p]!==" "){for(var m=0,g=0;d[p]===a;)m++,p++;for(var y=(d.length-p)*c+1>>>0,b=new Uint8Array(y);d[p];){var E=e[d.charCodeAt(p)];if(E===255)return;for(var _=0,x=y-1;(E!==0||_<g)&&x!==-1;x--,_++)E+=o*b[x]>>>0,b[x]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");g=_,p++}if(d[p]!==" "){for(var v=y-g;v!==y&&b[v]===0;)v++;for(var R=new Uint8Array(m+(y-v)),T=m;v!==y;)R[T++]=b[v++];return R}}}function h(d){var p=f(d);if(p)return p;throw new Error("Non-base"+o+" character")}return{encode:l,decodeUnsafe:f,decode:h}}UA.exports=$G});var vp=B((xwe,KA)=>{"use strict";var HG=new TextDecoder,GG=r=>HG.decode(r),WG=new TextEncoder,YG=r=>WG.encode(r);function QG(r,e){let t=new Uint8Array(e),n=0;for(let i of r)t.set(i,n),n+=i.length;return t}KA.exports={decodeText:GG,encodeText:YG,concat:QG}});var qA=B((vwe,VA)=>{"use strict";var{encodeText:XG}=vp(),Gy=class{constructor(e,t,n,i){this.name=e,this.code=t,this.codeBuf=XG(this.code),this.alphabet=i,this.codec=n(i)}encode(e){return this.codec.encode(e)}decode(e){for(let t of e)if(this.alphabet&&this.alphabet.indexOf(t)<0)throw new Error(`invalid character '${t}' in '${e}'`);return this.codec.decode(e)}};VA.exports=Gy});var $A=B((_we,zA)=>{"use strict";var jG=(r,e,t)=>{let n={};for(let u=0;u<e.length;++u)n[e[u]]=u;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),o=0,a=0,c=0;for(let u=0;u<i;++u){let l=n[r[u]];if(l===void 0)throw new SyntaxError("Invalid character "+r[u]);a=a<<t|l,o+=t,o>=8&&(o-=8,s[c++]=255&a>>o)}if(o>=t||255&a<<8-o)throw new SyntaxError("Unexpected end of data");return s},ZG=(r,e,t)=>{let n=e[e.length-1]==="=",i=(1<<t)-1,s="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>t;)o-=t,s+=e[i&a>>o];if(o&&(s+=e[i&a<<t-o]),n)for(;s.length*t&7;)s+="=";return s},JG=r=>e=>({encode(t){return ZG(t,e,r)},decode(t){return jG(t,e,r)}});zA.exports={rfc4648:JG}});var YA=B((Swe,WA)=>{"use strict";var Qf=FA(),eW=qA(),{rfc4648:Sr}=$A(),{decodeText:tW,encodeText:rW}=vp(),nW=()=>({encode:tW,decode:rW}),HA=[["identity","\0",nW,""],["base2","0",Sr(1),"01"],["base8","7",Sr(3),"01234567"],["base10","9",Qf,"0123456789"],["base16","f",Sr(4),"0123456789abcdef"],["base16upper","F",Sr(4),"0123456789ABCDEF"],["base32hex","v",Sr(5),"0123456789abcdefghijklmnopqrstuv"],["base32hexupper","V",Sr(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV"
Following code pattern:
if (CID.isCID(value)) {
doSomethingWithCID(value)
}
Is replaced with:
const cid = CID.asCID(value)
if (cid) {
// Make sure to use cid instead of value
doSomethingWithCID(cid)
}
`});var $T=et(()=>{zT();Rp();No();d8();Jf()});var g8,aEe,HT=et(()=>{bT();wT();ET();xT();vT();i8();_T();a8();ST();IT();BT();UT();FT();KT();$T();g8={...Zy,...Jy,...e8,...t8,...r8,...n8,...s8,...o8,...c8,...u8},aEe={...p8,...m8}});function Ou(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}var Dp=et(()=>{});function Cp(r=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?Ou(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var y8=et(()=>{Dp()});function WT(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var GT,b8,MY,Pp,w8=et(()=>{HT();y8();GT=WT("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),b8=WT("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Cp(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),MY={utf8:GT,"utf-8":GT,hex:g8.base16,latin1:b8,ascii:b8,binary:b8,...g8},Pp=MY});var YT={};be(YT,{toString:()=>UY});function UY(r,e="utf8"){let t=Pp[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var QT=et(()=>{w8()});var XT={};be(XT,{fromString:()=>FY});function FY(r,e="utf8"){let t=Pp[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Ou(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var jT=et(()=>{w8();Dp()});var ZT={};be(ZT,{concat:()=>KY});function KY(r,e){e||(e=r.reduce((i,s)=>i+s.length,0));let t=Cp(e),n=0;for(let i of r)t.set(i,n),n+=i.length;return Ou(t)}var JT=et(()=>{y8();Dp()});var x8=B((EEe,sD)=>{"use strict";var eD=jA(),Bu=cT(),{names:th}=lT(),{toString:kp}=(QT(),Bh(YT)),{fromString:VY}=(jT(),Bh(XT)),{concat:qY}=(JT(),Bh(ZT)),Lu={};for(let r in th){let e=r;Lu[th[e]]=e}Object.freeze(Lu);function zY(r){if(!(r instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return kp(r,"base16")}function $Y(r){return VY(r,"base16")}function HY(r){if(!(r instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return kp(eD.encode("base58btc",r)).slice(1)}function GY(r){let e=r instanceof Uint8Array?kp(r):r;return eD.decode("z"+e)}function tD(r){if(!(r instanceof Uint8Array))throw new Error("multihash must be a Uint8Array");if(r.length<2)throw new Error("multihash too short. must be > 2 bytes.");let e=Bu.decode(r);if(!nD(e))throw new Error(`multihash unknown function code: 0x${e.toString(16)}`);r=r.slice(Bu.decode.bytes);let t=Bu.decode(r);if(t<0)throw new Error(`multihash invalid length: ${t}`);if(r=r.slice(Bu.decode.bytes),r.length!==t)throw new Error(`multihash length inconsistent: 0x${kp(r,"base16")}`);return{code:e,name:Lu[e],length:t,digest:r}}function WY(r,e,t){if(!r||e===void 0)throw new Error("multihash encode requires at least two args: digest, code");let n=rD(e);if(!(r instanceof Uint8Array))throw new Error("digest should be a Uint8Array");if(t==null&&(t=r.length),t&&r.length!==t)throw new Error("digest length should be equal to specified length.");let i=Bu.encode(n),s=Bu.encode(t);return qY([i,s,r],i.length+s.length+r.length)}function rD(r){let e=r;if(typeof r=="string"){if(th[r]===void 0)throw new Error(`Unrecognized hash function named: ${r}`);e=th[r]}if(typeof e!="number")throw new Error(`Hash function code should be a number. Got: ${e}`);if(Lu[e]===void 0&&!E8(e))throw new Error(`Unrecognized function code: ${e}`);return e}function E8(r){return r>0&&r<16}function nD(r){return!!(E8(r)||Lu[r])}function iD(r){tD(r)}function YY(r){return iD(r),r.subarray(0,2)}sD.exports={names:th,codes:Lu,toHexString:zY,fromHexString:$Y,toB58String:HY,fromB58String:GY,decode:tD,encode:WY,coerceCode:rD,isAppCode:E8,validate:iD,prefix:YY,isValidCode:nD}});var xD=B(Mp=>{"use strict";Object.defineProperty(Mp,"__esModule",{value:!0});var A8=class{constructor(){thi
(?:
(?:${Qt}:){7}(?:${Qt}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
(?:${Qt}:){6}(?:${Si}|:${Qt}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
(?:${Qt}:){5}(?::${Si}|(?::${Qt}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
(?:${Qt}:){4}(?:(?::${Qt}){0,1}:${Si}|(?::${Qt}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
(?:${Qt}:){3}(?:(?::${Qt}){0,2}:${Si}|(?::${Qt}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
(?:${Qt}:){2}(?:(?::${Qt}){0,3}:${Si}|(?::${Qt}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
(?:${Qt}:){1}(?:(?::${Qt}){0,4}:${Si}|(?::${Qt}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
(?::(?:(?::${Qt}){0,5}:${Si}|(?::${Qt}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
`.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),Uq=new RegExp(`(?:^${Si}$)|(?:^${$d}$)`),Fq=new RegExp(`^${Si}$`),Kq=new RegExp(`^${$d}$`),z4=r=>r&&r.exact?Uq:new RegExp(`(?:${wo(r)}${Si}${wo(r)})|(?:${wo(r)}${$d}${wo(r)})`,"g");z4.v4=r=>r&&r.exact?Fq:new RegExp(`${wo(r)}${Si}${wo(r)}`,"g");z4.v6=r=>r&&r.exact?Kq:new RegExp(`${wo(r)}${$d}${wo(r)}`,"g");var a_=z4;var h_=j(u_(),1),{isValid:Vq,parse:qq}=h_.default,zq=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],$q=zq.map(r=>new f_.Netmask(r));function Hq(r){for(let e of $q)if(e.contains(r))return!0;return!1}function l_(r){return/^::$/.test(r)||/^::1$/.test(r)||/^::f{4}:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^::f{4}:0.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}var d_=r=>{if(Vq(r)){let e=qq(r);if(e.kind()==="ipv4")return Hq(e.toNormalizedString());if(e.kind()==="ipv6")return l_(r)}else if(Hc(r)&&a_.v6().test(r))return l_(r)};var Jr=d_;function p_(r={}){return{denyDialPeer:async()=>!1,denyDialMultiaddr:async e=>{let t=e.stringTuples();return t[0][0]===4||t[0][0]===41?!!Jr(`${t[0][1]}`):!1},denyInboundConnection:async()=>!1,denyOutboundConnection:async()=>!1,denyInboundEncryptedConnection:async()=>!1,denyOutboundEncryptedConnection:async()=>!1,denyInboundUpgradedConnection:async()=>!1,denyOutboundUpgradedConnection:async()=>!1,filterMultiaddrForPeer:async()=>!0,...r}}var Ji=Symbol.for("@libp2p/transport");var Eo;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Eo||(Eo={}));function $4(r){try{let{address:e}=r.nodeAddress();return!!Jr(e)}catch{return!0}}function Xc(r,e){let t=$4(r.multiaddr),n=$4(e.multiaddr);return t&&!n?1:!t&&n||r.isCertified&&!e.isCertified?-1:!r.isCertified&&e.isCertified?1:0}var G4=j(Uh(),1),W4=j(y_(),1);var b_=globalThis.fetch,w_=globalThis.Headers,Rde=globalThis.Request,Ide=globalThis.Response;function Gd(r,e,t){return`${r}?name=${e}&type=${t}`}async function E_(r,e){return await(await b_(r,{headers:new w_({accept:"application/dns-json"}),signal:e})).json()}function La(r,e){return`${e}_${r}`}var H4=Object.assign((0,G4.default)("dns-over-http-resolver"),{error:(0,G4.default)("dns-over-http-resolver:error")}),Y4=class{constructor(e={}){this._cache=new W4.default({max:e?.maxCache??100}),this._TXTcache=new W4.default({max:e?.maxCache??100}),this._servers=["https://cloudflare-dns.com/dns-query","https://dns.google/resolve"],this._request=e.request??E_,this._abortControllers=[]}cancel(){this._abortControllers.forEach(e=>e.abort())}getServers(){return this._servers}_getShuffledServers(){let e=[...this._servers];for(let t=e.length-1;t>0;t--){let n=Math.floor(Math.random()*t),i=e[t];e[t]=e[n],e[n]=i}return e}setServers(e){this._servers=e}async resolve(e,t="A"){switch(t){case"A":return await this.resolve4(e);case"AAAA":return await this.resolve6(e);case"TXT":return await this.resolveTxt(e);defau
`);function vf(r){let e=new Te(r,SS);return Kt.single(e)}function Fa(r,e,t={}){let n=vf(e);t.writeBytes===!0?r.push(n.subarray()):r.push(n)}function RS(r,e,t={}){let n=new Te;for(let i of e)n.append(vf(i));t.writeBytes===!0?r.push(n.subarray()):r.push(n)}async function Qz(r,e){let t=1,n={[Symbol.asyncIterator]:()=>n,next:async()=>r.next(t)},i=n;e?.signal!=null&&(i=Er(n,e.signal));let s=a=>{t=a},o=await Me(i,a=>Yt(a,{onLength:s,maxDataLength:1024}),async a=>Ns(a));if(o==null||o.length===0)throw new w("no buffer returned","ERR_INVALID_MULTISTREAM_SELECT_MESSAGE");if(o.get(o.byteLength-1)!==SS[0])throw Yz.error("Invalid mss message - missing newline - %s",o.subarray()),new w("missing newline","ERR_INVALID_MULTISTREAM_SELECT_MESSAGE");return o.sublist(0,-1)}async function su(r,e){let t=await Qz(r,e);return U(t.subarray())}var _f=C("libp2p:mss:select");async function Sf(r,e,t={}){e=Array.isArray(e)?[...e]:[e];let{reader:n,writer:i,rest:s,stream:o}=u1(r),a=e.shift();if(a==null)throw new Error("At least one protocol must be specified");_f.trace('select: write ["%s", "%s"]',Os,a);let c=G(Os),u=G(a);RS(i,[c,u],t);let l=await su(n,t);if(_f.trace('select: read "%s"',l),l===Os&&(l=await su(n,t),_f.trace('select: read "%s"',l)),l===a)return s(),{stream:o,protocol:a};for(let f of e){_f.trace('select: write "%s"',f),Fa(i,G(f),t);let h=await su(n,t);if(_f.trace('select: read "%s" for "%s"',h,f),h===f)return s(),{stream:o,protocol:f}}throw s(),new w("protocol selection failed","ERR_UNSUPPORTED_PROTOCOL")}var Rf=C("libp2p:mss:handle");async function If(r,e,t){e=Array.isArray(e)?e:[e];let{writer:n,reader:i,rest:s,stream:o}=u1(r);for(;;){let a=await su(i,t);if(Rf.trace('read "%s"',a),a===Os){Rf.trace('respond with "%s" for "%s"',Os,a),Fa(n,G(Os),t);continue}if(e.includes(a))return Fa(n,G(a),t),Rf.trace('respond with "%s" for "%s"',a,a),s(),{stream:o,protocol:a};if(a==="ls"){Fa(n,new Te(...e.map(c=>vf(G(c)))),t),Rf.trace('respond with "%s" for %s',e,a);continue}Fa(n,G("na"),t),Rf('respond with "na" for "%s"',a)}}var TS=j(Xr(),1);var AS=Symbol.for("@libp2p/connection");var l1=C("libp2p:connection"),jz=500,vg=class{id;remoteAddr;remotePeer;direction;timeline;multiplexer;encryption;status;transient;tags;_newStream;_close;_abort;_getStreams;constructor(e){let{remoteAddr:t,remotePeer:n,newStream:i,close:s,abort:o,getStreams:a}=e;this.id=`${parseInt(String(Math.random()*1e9)).toString(36)}${Date.now()}`,this.remoteAddr=t,this.remotePeer=n,this.direction=e.direction,this.status="open",this.timeline=e.timeline,this.multiplexer=e.multiplexer,this.encryption=e.encryption,this.transient=e.transient??!1,this._newStream=i,this._close=s,this._abort=o,this._getStreams=a,this.tags=[]}[Symbol.toStringTag]="Connection";[AS]=!0;get streams(){return this._getStreams()}async newStream(e,t){if(this.status==="closing")throw new w("the connection is being closed","ERR_CONNECTION_BEING_CLOSED");if(this.status==="closed")throw new w("the connection is closed","ERR_CONNECTION_CLOSED");if(Array.isArray(e)||(e=[e]),this.transient&&t?.runOnTransientConnection!==!0)throw new w("Cannot open protocol stream on transient connection","ERR_TRANSIENT_CONNECTION");let n=await this._newStream(e,t);return n.direction="outbound",n}async close(e={}){if(!(this.status==="closed"||this.status==="closing")){l1("closing connection to %a",this.remoteAddr),this.status="closing",e.signal=e?.signal??AbortSignal.timeout(jz);try{(0,TS.setMaxListeners)?.(1/0,e.signal)}catch{}try{await Promise.all(this.streams.map(async t=>t.close(e))),await this._close(e),this.timeline.close=Date.now(),this.status="closed"}catch(t){l1.error("error encountered during graceful close of connection to %a",this.remoteAddr,t),this.abort(t)}}}abort(e){l1.error("aborting connection to %a due to error",this.remoteAddr,e),this.status="closing",this.streams.forEach(t=>{t.abort(e)}),l1.error("all streams aborted",this.streams.length),this._abort(e),this.timeline.close=Date.now(),this.status="closed"}};function DS(r){return new vg(r)}var St=C("libp2p:upgrader");function Jz(r,e){try{let{options:t}=e.getHandler(r);return t.m
`).filter(n=>n.startsWith("a=candidate")).pop(),t=e?.split(" ");return e==null||t==null||t.length<5?(ko("could not parse remote address from",e),"/webrtc"):`/dnsaddr/${t[4]}/${t[2].toLowerCase()}/${t[3]}/webrtc`}var Ep=class extends Ye{peerId;transportManager;constructor(e){super(),this.peerId=e.peerId,this.transportManager=e.transportManager}async listen(){this.safeDispatchEvent("listening",{})}getAddrs(){return this.transportManager.getListeners().filter(e=>e!==this).map(e=>e.getAddrs().filter(t=>Ai.matches(t)).map(t=>t.encapsulate(`/webrtc/p2p/${this.peerId}`))).flat()}async close(){this.safeDispatchEvent("close",{})}};var MA=C("libp2p:webrtc:peer"),KG="/webrtc",VG="/p2p-circuit",Hy="/webrtc-signaling/0.0.1",qG=le("webrtc").code,xp=class{components;init;_started=!1;constructor(e,t={}){this.components=e,this.init=t}isStarted(){return this._started}async start(){await this.components.registrar.handle(Hy,e=>{this._onProtocol(e).catch(t=>{MA.error("failed to handle incoming connect from %p",e.connection.remotePeer,t)})},{runOnTransientConnection:!0}),this._started=!0}async stop(){await this.components.registrar.unhandle(Hy),this._started=!1}createListener(e){return new Ep(this.components)}[Symbol.toStringTag]="@libp2p/webrtc";[Ji]=!0;filter(e){return e.filter(t=>t.protoCodes().includes(qG))}async dial(e,t){MA.trace("dialing address: ",e);let{baseAddr:n,peerId:i}=zG(e);if(t.signal==null){let a=new AbortController;t.signal=a.signal}let s=await this.components.transportManager.dial(n,t),o=await s.newStream(Hy,{...t,runOnTransientConnection:!0});try{let{pc:a,muxerFactory:c,remoteAddress:u}=await BA({stream:o,rtcConfiguration:this.init.rtcConfiguration,dataChannelOptions:this.init.dataChannel,signal:t.signal}),l=await t.upgrader.upgradeOutbound(new Ga({peerConnection:a,timeline:{open:Date.now()},remoteAddr:ge(u).encapsulate(`/p2p/${i.toString()}`)}),{skipProtection:!0,skipEncryption:!0,muxerFactory:c});return await o.close(),l}catch(a){throw o.abort(a),a}finally{await s.close()}}async _onProtocol({connection:e,stream:t}){try{let{pc:n,muxerFactory:i,remoteAddress:s}=await OA({rtcConfiguration:this.init.rtcConfiguration,connection:e,stream:t,dataChannelOptions:this.init.dataChannel});await this.components.upgrader.upgradeInbound(new Ga({peerConnection:n,timeline:{open:new Date().getTime()},remoteAddr:ge(s).encapsulate(`/p2p/${e.remotePeer.toString()}`)}),{skipEncryption:!0,skipProtection:!0,muxerFactory:i})}catch(n){throw t.abort(n),n}finally{await e.close()}}};function zG(r){let e=r.toString().split(KG+"/");if(e.length!==2)throw new w("webrtc protocol was not present in multiaddr",vn.ERR_INVALID_MULTIADDR);if(!e[0].includes(VG))throw new w("p2p-circuit protocol was not present in multiaddr",vn.ERR_INVALID_MULTIADDR);let t=ge(e[0]),i=ge("/"+e[1]).getPeerId();if(i==null)throw new w("destination peer id was missing",vn.ERR_INVALID_MULTIADDR);let s=t.protos().pop();if(s===void 0)throw new w("invalid multiaddr",vn.ERR_INVALID_MULTIADDR);return s.name!=="p2p"&&(t=t.encapsulate(`/p2p/${i}`)),{baseAddr:t,peerId:we(i)}}var hD=j(x8(),1);var oD=j(x8(),1);var v8=C("libp2p:webrtc:sdp"),_8=Object.values(Bn).map(r=>r.decoder).reduce((r,e)=>r.or(e));function aD(r){let e=r.getConfiguration().certificates?.at(0);if(e==null||e.getFingerprints==null){v8.trace("fetching fingerprint from local SDP");let n=r.localDescription;return n==null?void 0:XY(n.sdp)}if(v8.trace("fetching fingerprint from local certificate"),e.getFingerprints().length===0)return;let t=e.getFingerprints()[0].value;if(t==null)throw My("","no fingerprint on local certificate");return t}var QY=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function XY(r){return r.match(QY)?.groups?.fingerprint}function jY(r){for(let e of r.protoNames())if(e.startsWith("ip"))return e.toUpperCase();return v8("Warning: multiaddr does not appear to contain IP4 or IP6, defaulting to IP6",r),"IP6"}function Np(r){let t=r.stringTuples().filter(n=>n[0]===I8).map(n=>n[1])[0];if(t===void 0||t==="")throw gp(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}fu
o=- 0 0 IN ${i} ${t}
s=-
c=IN ${i} ${t}
t=0 0
a=ice-lite
m=application ${n} UDP/DTLS/SCTP webrtc-datachannel
a=mid:0
a=setup:passive
a=ice-ufrag:${e}
a=ice-pwd:${e}
a=fingerprint:${s}
a=sctp-port:5000
a=max-message-size:16384
a=candidate:1467250027 1 UDP 1467250027 ${t} ${n} typ host\r
`}function cD(r,e){return{type:"answer",sdp:JY(r,e)}}function uD(r,e){if(r.sdp===void 0)throw Gf("Can't munge a missing SDP");return r.sdp=r.sdp.replace(/\na=ice-ufrag:[^\n]*\n/,`
a=ice-ufrag:`+e+`
`).replace(/\na=ice-pwd:[^\n]*\n/,`
a=ice-pwd:`+e+`
`),r}var lD=Array.from("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),fD=r=>[...Array(r)].map(()=>lD.at(Math.floor(Math.random()*lD.length))).join("");var Op=C("libp2p:webrtc:transport"),tQ=1e4,rQ=le("webrtc-direct").code,I8=le("certhash").code,Bp=class{metrics;components;init;constructor(e,t={}){this.components=e,this.init=t,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_dialer_events_total",{label:"event",help:"Total count of WebRTC dial events by type"})})}async dial(e,t){let n=await this._connect(e,t);return Op(`dialing address - ${e.toString()}`),n}createListener(e){throw wA("WebRTCTransport.createListener")}filter(e){return e.filter(nQ)}[Symbol.toStringTag]="@libp2p/webrtc-direct";[Ji]=!0;async _connect(e,t){let n=new AbortController,i=n.signal,s=e.getPeerId();if(s===null)throw gp("we need to have the remote's PeerId");let o=we(s),a=S8(Np(e)),c=await Ru.generateCertificate({name:"ECDSA",namedCurve:"P-256",hash:R8(a.name)}),u=new Ru({certificates:[c]});try{let l=new Promise((T,P)=>{let q=u.createDataChannel("",{negotiated:!0,id:0}),$=setTimeout(()=>{let Q=`Data channel was never opened: state: ${q.readyState}`;Op.error(Q),this.metrics?.dialerEvents.increment({open_error:!0}),P(Ly("data",Q))},tQ);q.onopen=Q=>{clearTimeout($),T(q)},q.onerror=Q=>{clearTimeout($);let _e=`Error opening a data channel for handshaking: ${Q.target?.toString()??"not specified"}`;Op.error(_e),this.metrics?.dialerEvents.increment({unknown_error:!0}),P(Ly("data",_e))}}),f="libp2p+webrtc+v1/"+fD(32),h=await u.createOffer(),d=uD(h,f);await u.setLocalDescription(d);let p=cD(e,f);await u.setRemoteDescription(p);let m=await l,g=this.components.peerId,y=this.generateNoisePrologue(u,a.code,e),b=mu({prologueBytes:y})(),E=Au({channel:m,direction:"inbound",dataChannelOptions:this.init.dataChannel}),_={...E,sink:E.sink.bind(E),source:async function*(){for await(let T of E.source)for(let P of T)yield P}()},x=new Ga({peerConnection:u,remoteAddr:e,timeline:{open:Date.now()},metrics:this.metrics?.dialerEvents}),v=Wf?"iceconnectionstatechange":"connectionstatechange";u.addEventListener(v,()=>{switch(u.connectionState){case"failed":case"disconnected":case"closed":x.close().catch(T=>{Op.error("error closing connection",T)}).finally(()=>{n.abort()});break;default:break}},{signal:i}),this.metrics?.dialerEvents.increment({peer_connection:!0});let R=new Wa({peerConnection:u,metrics:this.metrics?.dialerEvents,dataChannelOptions:this.init.dataChannel});return await b.secureInbound(g,_,o),await t.upgrader.upgradeOutbound(x,{skipProtection:!0,skipEncryption:!0,muxerFactory:R})}catch(l){throw u.close(),l}}generateNoisePrologue(e,t,n){if(e.getConfiguration().certificates?.length===0)throw Gf("no local certificate");let i=aD(e);if(i==null)throw Gf("no local fingerprint found");let s=i.trim().toLowerCase().replaceAll(":",""),o=G(s,"hex"),a=hD.encode(o,t),c=_8.decode(Np(n)),u=G("libp2p-webrtc-noise:");return ve([u,a,c])}};function nQ(r){let e=r.protoCodes();return e.includes(rQ)&&e.includes(I8)&&r.getPeerId()!=null&&!e.includes(le("p2p-circuit").code)}function dD(r){return e=>new Bp(e,r)}function pD(r){return e=>new xp(e,r)}function mD(r){let e;try{e=le("sni").code}catch{return null}for(let[t,n]of r)if(t===e&&n!==void 0)return n;return null}function gD(r){return r.some(([e,t])=>e===le("tls").code)}function Sn(r,e,t){let n=yD[le(r).name];if(n===void 0)throw new Error(`Can't interpret protocol ${le(r).name}`);let i=n(e,t);return r===le("ip6").code?`[${i}]`:i}var yD={ip4:(r,e)=>r,ip6:(r,e)=>e.length===0?r:`[${r}]`,tcp:(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");return`tcp://${Sn(t[0],t[1]??"",e)}:${r}`},udp:(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");return`udp://${Sn(t[0],t[1]??"",e)}:${r}`},dnsaddr:(r,e)=>r,dns4:(r,e)=>r,dns6:(r,e)=>r,dns:(r,e)=>r,ipfs:(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");return`${Sn(t[0],t[1]??"",e)}/ipfs/${r}`},p2p:(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Une
/*! Bundled license information:
@noble/hashes/esm/utils.js:
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
@noble/curves/esm/abstract/utils.js:
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
@noble/curves/esm/abstract/modular.js:
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
@noble/curves/esm/abstract/curve.js:
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
@noble/curves/esm/abstract/edwards.js:
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
@noble/curves/esm/abstract/montgomery.js:
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
@noble/curves/esm/ed25519.js:
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
@noble/curves/esm/abstract/weierstrass.js:
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
@noble/curves/esm/_shortw_utils.js:
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
@noble/curves/esm/secp256k1.js:
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
@noble/ciphers/esm/utils.js:
(*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
@libp2p/webtransport/dist/src/index.js:
(*! TODO unclear how to add backpressure here? *)
@noble/ed25519/lib/esm/index.js:
(*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) *)
@noble/secp256k1/lib/esm/index.js:
(*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) *)
*/
return Helia}));