@solarpunkltd/swarm-id 0.0.0-stage → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +89 -2
- package/dist/bus/account-bus.d.ts +104 -0
- package/dist/bus/account-delta.d.ts +52 -0
- package/dist/bus/bus-context.d.ts +7 -0
- package/dist/bus/envelope.d.ts +9 -0
- package/dist/bus/messages.d.ts +241 -0
- package/dist/bus/presence.d.ts +62 -0
- package/dist/bus/signaling-transport.d.ts +79 -0
- package/dist/chunk/bmt.d.ts +16 -0
- package/dist/chunk/cac.d.ts +17 -0
- package/dist/chunk/constants.d.ts +10 -0
- package/dist/chunk/encrypted-cac.d.ts +47 -0
- package/dist/chunk/encryption.d.ts +85 -0
- package/dist/chunk/index.d.ts +5 -0
- package/dist/chunks/chat-binding-DO5aGhPl.js +23 -0
- package/dist/chunks/chat-binding-DO5aGhPl.js.map +1 -0
- package/dist/errors.d.ts +35 -0
- package/dist/index.d.ts +27 -0
- package/dist/internal.d.ts +49 -0
- package/dist/internal.esm.js +2 -0
- package/dist/internal.esm.js.map +1 -0
- package/dist/proxy/act/act.d.ts +58 -0
- package/dist/proxy/act/crypto.d.ts +46 -0
- package/dist/proxy/act/grantee-list.d.ts +81 -0
- package/dist/proxy/act/history.d.ts +182 -0
- package/dist/proxy/act/index.d.ts +114 -0
- package/dist/proxy/app-stamp-limits.d.ts +62 -0
- package/dist/proxy/chunk-upload-stream.d.ts +37 -0
- package/dist/proxy/chunking.d.ts +15 -0
- package/dist/proxy/collection.d.ts +38 -0
- package/dist/proxy/download-data.d.ts +27 -0
- package/dist/proxy/errors.d.ts +8 -0
- package/dist/proxy/feed-manifest.d.ts +60 -0
- package/dist/proxy/feeds/epochs/async-finder.d.ts +70 -0
- package/dist/proxy/feeds/epochs/epoch.d.ts +79 -0
- package/dist/proxy/feeds/epochs/finder.d.ts +60 -0
- package/dist/proxy/feeds/epochs/index.d.ts +30 -0
- package/dist/proxy/feeds/epochs/types.d.ts +110 -0
- package/dist/proxy/feeds/epochs/updater.d.ts +76 -0
- package/dist/proxy/feeds/epochs/utils.d.ts +21 -0
- package/dist/proxy/feeds/index.d.ts +4 -0
- package/dist/proxy/feeds/sequence/async-finder.d.ts +14 -0
- package/dist/proxy/feeds/sequence/finder.d.ts +11 -0
- package/dist/proxy/feeds/sequence/index.d.ts +22 -0
- package/dist/proxy/feeds/sequence/types.d.ts +82 -0
- package/dist/proxy/feeds/sequence/updater.d.ts +20 -0
- package/dist/proxy/index.d.ts +5 -0
- package/dist/proxy/manifest-builder.d.ts +164 -0
- package/dist/proxy/mantaray.d.ts +76 -0
- package/dist/proxy/soc-restamp-slots.d.ts +48 -0
- package/dist/proxy/stamp-chunk.d.ts +45 -0
- package/dist/proxy/stamp-worker-handler.d.ts +32 -0
- package/dist/proxy/stamp-worker-pool.d.ts +52 -0
- package/dist/proxy/stamp-worker.d.ts +1 -0
- package/dist/proxy/types.d.ts +38 -0
- package/dist/proxy/upload.d.ts +207 -0
- package/dist/schemas.d.ts +671 -0
- package/dist/stamp-worker.iife.js +1 -0
- package/dist/storage/debounced-uploader.d.ts +61 -0
- package/dist/storage/utilization-store.d.ts +113 -0
- package/dist/swarm-id-client.d.ts +1143 -0
- package/dist/swarm-id-proxy.d.ts +1079 -0
- package/dist/swarm-id.esm.js +2 -0
- package/dist/swarm-id.esm.js.map +1 -0
- package/dist/sync/batch-write-coordinator.d.ts +348 -0
- package/dist/sync/device-roster.d.ts +59 -0
- package/dist/sync/device-state.d.ts +199 -0
- package/dist/sync/fold-account-from-swarm.d.ts +53 -0
- package/dist/sync/index.d.ts +11 -0
- package/dist/sync/merge-snapshot.d.ts +57 -0
- package/dist/sync/partition-intent.d.ts +218 -0
- package/dist/sync/partition-lease.d.ts +531 -0
- package/dist/sync/partition-lock.d.ts +218 -0
- package/dist/sync/partition-state.d.ts +287 -0
- package/dist/sync/session-check.d.ts +29 -0
- package/dist/sync/store-interfaces.d.ts +48 -0
- package/dist/sync/sync-account.d.ts +45 -0
- package/dist/sync/timing-constants.d.ts +32 -0
- package/dist/sync/types.d.ts +18 -0
- package/dist/types.d.ts +3042 -0
- package/dist/utils/account-state-snapshot.d.ts +43 -0
- package/dist/utils/active-devices.d.ts +45 -0
- package/dist/utils/avatar.d.ts +30 -0
- package/dist/utils/batch-utilization.d.ts +840 -0
- package/dist/utils/batch-write-lock.d.ts +12 -0
- package/dist/utils/bee-error.d.ts +11 -0
- package/dist/utils/chat-binding.d.ts +113 -0
- package/dist/utils/coalesced-task.d.ts +28 -0
- package/dist/utils/collection.d.ts +6 -0
- package/dist/utils/connection-info.d.ts +11 -0
- package/dist/utils/constants.d.ts +28 -0
- package/dist/utils/device-id.d.ts +109 -0
- package/dist/utils/hex.d.ts +31 -0
- package/dist/utils/json-rpc.d.ts +34 -0
- package/dist/utils/key-derivation.d.ts +124 -0
- package/dist/utils/lock-soc.d.ts +35 -0
- package/dist/utils/postage-contract.d.ts +143 -0
- package/dist/utils/postage-stamp-association.d.ts +39 -0
- package/dist/utils/promise.d.ts +37 -0
- package/dist/utils/sealed-values.d.ts +23 -0
- package/dist/utils/seed-encryption.d.ts +17 -0
- package/dist/utils/site-allow-list.d.ts +54 -0
- package/dist/utils/stamp-lifespan.d.ts +37 -0
- package/dist/utils/storage-managers.d.ts +62 -0
- package/dist/utils/storage-probe.d.ts +40 -0
- package/dist/utils/tag.d.ts +11 -0
- package/dist/utils/ttl.d.ts +120 -0
- package/dist/utils/url.d.ts +55 -0
- package/dist/utils/versioned-storage.d.ts +183 -0
- package/package.json +91 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(){"use strict";var t,n={};var e=(t||(t=1,function(t){var n;async function e(t){return new Promise((n,e)=>t.then(e,n))}async function r(t){return new Promise(n=>setTimeout(()=>{n(!0)},t))}function i(t,n=Math.random){for(let e=t.length-1;e>0;e--){const r=Math.floor(n()*(e+1)),i=t[e];t[e]=t[r],t[r]=i}return t}function o(t,n,e=Math.random){return i(V(0,t.length-1),e).slice(0,n)}function s(t,n,e=Math.random){return Math.floor(e()*(n-t+1))+t}function u(t,n,e){return n>=t.x&&n<t.x+t.width&&e>=t.y&&e<t.y+t.height}function a(t,n=Math.random){return n()<t}function c(t,n=Math.random){return t[Math.floor(t.length*n())]}function l(t){if(!t.length)throw Error("Received empty array");return t[t.length-1]}function f(t,n,e){return e(n.reduce((t,n)=>n(t),t))}function h(t,n){if(null==t)return null;const e=n.split(".");let r=t;for(const t of e){if(null===r[t]||void 0===r[t])return null;r=r[t]}return r}function g(t,n,e){const r=n.split(/\.|\[/);let i=t;for(let t=0;t<r.length;t++){const n=r[t],o=t<r.length-1&&r[t+1].includes("]"),s=n.includes("]")?n.replace(/\[|\]/g,""):n;if(t===r.length-1)return i[s]=e,e;d(i[s])||(i[s]=o?[]:{}),i=i[s]}return e}function p(t,n){return Math.round(t/n)*n}function d(t,n=!0){return!(!t||n&&!w(t._readableState)||n&&t.constructor&&(t.constructor.isBuffer||"AbortController"==t.constructor.name||"AbortSignal"==t.constructor.name||"Uint8Array"==t.constructor.name||"ArrayBuffer"===t.constructor.name||"ReadableStream"===t.constructor.name))&&"object"==typeof t}function m(t){return d(t)&&!Array.isArray(t)}function y(t){return Array.isArray(t)&&0===t.length}function w(t){return void 0===t}function b(t){return"[object Function]"===Object.prototype.toString.call(t)||"[object AsyncFunction]"===Object.prototype.toString.call(t)}function x(t){return"[object String]"===Object.prototype.toString.call(t)}function $(t){return"number"==typeof t&&isFinite(t)}function v(t){return!0===t||!1===t}function E(t){return"[object Date]"===Object.prototype.toString.call(t)}function M(t){return!x(t)||0===t.trim().length}function A(t){return $(t)&&Number.isInteger(t)&&t>=1}function S(t){return x(t)&&null!==t.match(/^-?\d+$/)}function k(t){return x(t)&&null!==t.match(/^(0x)?[0-9a-f]+$/i)}Object.defineProperty(t,"__esModule",{value:!0}),t.Vector=t.Cache=t.Assertions=t.Strings=t.Types=t.Objects=t.Dates=t.Promises=t.Numbers=t.System=t.Arrays=t.Random=t.Elliptic=t.Binary=t.Lock=t.Solver=t.RollingValueProvider=t.TrieRouter=t.AsyncQueue=t.PubSubChannel=t.FixedPointNumber=t.MerkleTree=t.Chunk=t.Uint8ArrayWriter=t.Uint8ArrayReader=t.AsyncLazy=t.Lazy=t.Optional=void 0;const O="!@#$%^&*()_+-=[]{}|;:<>?,./".split(""),T="abcdefghijklmnopqrstuvwxyz",B=T+"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",j=B+"!@#$%^&*()_+-=[]{}|;:<>?,./",C=["—","\\","東","京","都","𝖆","𝖇","𝖈","👾","🙇","💁","🙅","ᚠ","ᛇ","ᚻ","ᛦ"],D="0123456789abcdef";function I(t,n){if(M(t))throw new TypeError(`Expected string${n?.name?` for ${n.name}`:""}, got: `+t);if(n&&(void 0!==n.min&&t.length<n.min||void 0!==n.max&&t.length>n.max))throw RangeError(`Expected string${n?.name?` for ${n.name}`:""} length in range: ${n.min??"-inf"}..${n.max??"inf"}; got: ${t.length}`);return t}function U(t,n){if(void 0!==n.min&&t<n.min||void 0!==n.max&&t>n.max)throw RangeError(`Expected value${n?.name?` for ${n.name}`:""} in range: ${n.min??"-inf"}..${n.max??"inf"}; got: ${t}`)}function F(t,n){if($(t))return n&&U(t,n),t;if(!x(t)||!t.match(/^-?\d+(\.\d+)?$/))throw new TypeError(`Expected number${n?.name?` for ${n.name}`:""}, got: `+t);const e=parseFloat(t);return n&&U(e,n),e}function N(t,n){return Math.trunc(F(t,n))}function P(t,n){if(!m(t))throw new TypeError(`Expected object${n?.name?` for ${n.name}`:""}, got: `+t);return t}function z(t){return x(t)&&null!==t.match(/^https?:\/\/.+/)}function L(t){return"bigint"==typeof t}function R(t,n){if(!L(t))throw new TypeError(`Expected bigint${n?.name?` for ${n.name}`:""}, got: `+t);if(void 0!==n?.min&&t<n?.min||void 0!==n?.max&&t>n?.max)throw RangeError(`Expected value${n?.name?` for ${n.name}`:""} in range: ${n.min??"-inf"}..${n.max??"inf"}; got: ${t}`);return t}function W(t,n){for(const[e,r]of Object.entries(n))if(!r(t[e]))throw TypeError(`${e} in value does not exist or match shape`);for(const e of Object.keys(t))if(!n[e])throw TypeError(`${e} exists in value but not in shape`);return!0}function q(t,n){if(m(t)&&m(n))for(const e in n)m(n[e])?(t[e]||(t[e]={}),q(t[e],n[e])):Array.isArray(n[e])?t[e]=[...n[e]]:(null!==n[e]&&void 0!==n[e]||null===t[e]||void 0===t[e])&&(t[e]=n[e]);return t}function H(t,n){const e={};for(const r of t)for(const t of Object.keys(r))e[t]?e[t]=n(e[t],r[t]):e[t]=r[t];return e}function K(t,n){Array.prototype.push.apply(t,n)}function V(t,n){const e=[];for(let r=t;r<=n;r++)e.push(r);return e}function J(t,n=()=>!1){return t.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").split("").map(t=>/[a-z0-9]/.test(t)||n(t)?t:"-").join("").replace(/-+/g,"-").replace(/^-|-$/g,"")}function Z(t,n){if(0===n.length)return 0;const e=t.toLowerCase(),r=n.toLowerCase();return t===n?1e4:e.startsWith(r)?1e4-t.length:e.includes(r)?5e3-t.length:new RegExp(".*"+r.split("").join(".*")+".*").test(e)?1e3-t.length:0}const Q={"&":"&",""":'"',"'":"'",">":">","<":"<"};function _(t,n){const e=t.indexOf(n);return-1===e?null:t.slice(0,e)}function G(t,n){const e=t.indexOf(n);return-1===e?null:t.slice(e+n.length)}function X(t,n){const e=t.lastIndexOf(n);return-1===e?null:t.slice(0,e)}function Y(t,n){const e=t.lastIndexOf(n);return-1===e?null:t.slice(e+n.length)}function tt(t,n,e=!1){const r=e?t.lastIndexOf(n):t.indexOf(n);return-1===r?e?[null,t]:[t,null]:[t.slice(0,r),t.slice(r+n.length)]}function nt(t,n){let e=[t];for(const t of n)e=e.flatMap(n=>n.split(t));return e.filter(t=>t)}function et(t){const n=l(t.split(/\\|\//g)),e=n.lastIndexOf(".",n.length-1);return e<=0?"":n.slice(e+1)}function rt(t){const n=l(t.split(/\\|\//g)),e=n.lastIndexOf(".",n.length-1);return e<=0?n:n.slice(0,e)}function it(t){return t.split("\n").map(t=>t.trim().replace(/\s+/g," ")).filter(t=>t.length>0).join("\n")}function ot(t){return t.charAt(0).toUpperCase()+t.slice(1)}function st(t){return t.charAt(0).toLowerCase()+t.slice(1)}function ut(t){if(!t)return!1;const n=t.charCodeAt(0);return n>=65&&n<=90||n>=97&&n<=122}function at(t){if(!t)return!1;const n=t.charCodeAt(0);return n>=48&&n<=57}function ct(t){return ut(t)||at(t)}const lt=" \n\t\r.,?!:;\"'`(){}[]~@#$%^&*-+=|<>/\\".split("");function ft(t){return lt.includes(t)}function ht(t,n,e=0){const r=n.exec(t.slice(e));return r?{index:r.index,match:r[0]}:null}function gt(t,n,e=!0){if(!e)return n.every(n=>n instanceof RegExp?n.test(t):-1!==t.indexOf(n,0));let r=0;for(const e of n)if(e instanceof RegExp){const n=ht(t,e,r);if(!n)return!1;r=n.index+n.match.length}else{const n=t.indexOf(e,r);if(-1===n)return!1;r=n+e.length}return!0}function pt(t,n,e=0){const r=[];let i=t.indexOf(n,e);for(;-1!==i;)r.push(i),i=t.indexOf(n,i+n.length);return r}function dt(t,n,e=0){let r=-1;for(const i of n){const n=t.indexOf(i,e);-1!==n&&(-1===r||n<r)&&(r=n)}return r}function mt(t,n=0){for(let e=n;e<t.length;e++)if(ft(t[e]))return e;return-1}function yt(t,n=0){for(let e=n;e<t.length;e++)if("#"===t[e]&&ct(t[e+1]))return e;return-1}function wt(t,n,e=0){return t.slice(0,e).lastIndexOf(n)}function bt(t,n=0,e="{",r="}"){let i=1;for(let o=n;o<t.length;o++)if(t.slice(o,o+r.length)===r){if(0===--i)return o}else t.slice(o,o+e.length)===e&&i++;return-1}function xt(t,n){const e=n.wordBoundary?dt(t,[`${n.opening} `,`${n.opening}\n`],n.start||0):t.indexOf(n.opening,n.start||0);if(-1===e)return null;const r=bt(t,e+n.opening.length,n.opening,n.closing);return-1===r?null:n.exclusive?t.slice(e+n.opening.length,r):t.slice(e,r+n.closing.length)}const $t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",vt="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function Et(t,n){const e=n.length;let r=0,i=0;const o=[];for(let s=0;s<t.length;s++){const u=t[s];if("="===u)break;const a=n.indexOf(u);if(-1===a)throw new Error(`Invalid character: ${u}`);i=i<<Math.log2(e)|a,r+=Math.log2(e),r>=8&&(r-=8,o.push(i>>r&255))}return new Uint8Array(o)}function Mt(t,n){const e=n.length;let r=0,i=0,o="";for(let s=0;s<t.length;s++)for(i=i<<8|t[s],r+=8;r>=Math.log2(e);)r-=Math.log2(e),o+=n[i>>r&e-1];return r>0&&(o+=n[i<<Math.log2(e)-r&e-1]),o.length%4!=0&&(o+="=".repeat(4-o.length%4)),o}function At(t,n,e){const r=[];for(const i of e)i!==n&&r.push(t.replace(n,i));return r}function St(t){const n=t.lastIndexOf(" ");return-1===n?{line:t,rest:""}:{line:t.slice(0,n),rest:t.slice(n+1)}}function kt(t){const n=t.reduce((t,n)=>t.length<n.length?t:n);let e="";for(let r=0;r<n.length;r++){const i=n[r];if(!t.every(t=>t[r]===i))break;e+=i}return e}function Ot(t,n){return new RegExp(`\\b${n}\\b`).test(t)}function Tt(t,n,e=[]){let r="";for(;n<t.length&&(ct(t[n])||e.includes(t[n]));)r+=t[n++];return r}function Bt(t,n,e,r="$",i=":"){if(""===e)return t;let o=t.indexOf(`${r}${n}`);for(;-1!==o;){if(t[o+n.length+1]===i)if(t[o+n.length+2]===i)t=t.replace(`${r}${n}${i}${i}`,e);else{const s=Tt(t,o+n.length+2,["_"]);t=t.replace(`${r}${n}${i}${s}`,e)}else t=t.replace(`${r}${n}`,e);o=t.indexOf(`${r}${n}`,o+e.length)}return t}function jt(t,n="$",e=":"){let r=t.indexOf(n);for(;-1!==r;){const i=Tt(t,r+1);if(t[r+i.length+1]===e)if(t[r+i.length+2]===e)t=t.replace(`${n}${i}${e}${e}`,"");else{const o=Tt(t,r+i.length+2);t=t.replace(`${n}${i}${e}${o}`,o)}r=t.indexOf(n,r+1)}return t}function Ct(t,n=!0){const e=Object.entries(t).filter(([t,n])=>null!=n).map(([t,n])=>`${t}=${encodeURIComponent(n)}`).join("&");return e?(n?"?":"")+e:""}function Dt(t){return String(Math.floor(t)).padStart(2,"0")}function It(t){const n=Math.floor(t/36e5);t%=36e5;const e=Math.floor(t/6e4);t%=6e4;const r=Math.floor(t/1e3);return n?`${Dt(n)}:${Dt(e)}:${Dt(r)}`:`${Dt(e)}:${Dt(r)}`}function Ut(t){return Math.floor((E(t)?t.getTime():t)/864e5)}const Ft={today:(t,n)=>Dt(t)+":"+Dt(n),yesterday:()=>"Yesterday",monday:()=>"Mon",tuesday:()=>"Tue",wednesday:()=>"Wed",thursday:()=>"Thu",friday:()=>"Fri",saturday:()=>"Sat",sunday:()=>"Sun",weeks:t=>`${t}w`},Nt={now:()=>"A few seconds",seconds:t=>`${t} seconds`,minutes:t=>`${t} minutes`,hours:t=>`${t} hours`,days:t=>`${t} days`,weeks:t=>`${t} weeks`};function Pt(n,e){const r=e?.now??Date.now(),i=e?.labels||Nt;let o=(r-(t.Types.isDate(n)?n.getTime():n))/1e3;return o<10?i.now():o<120?i.seconds(Math.floor(o)):(o/=60,o<120?i.minutes(Math.floor(o)):(o/=60,o<48?i.hours(Math.floor(o)):(o/=24,o<14?i.days(Math.floor(o)):(o/=7,i.weeks(Math.floor(o))))))}const zt={},Lt={s:1e3,m:6e4,h:36e5,d:864e5},Rt={0:"sunday",1:"monday",2:"tuesday",3:"wednesday",4:"thursday",5:"friday",6:"saturday"};function Wt(t){return{zeroBasedIndex:t,day:Rt[t]}}function qt(t){return Wt(t.getDay())}const Ht={ms:1,milli:1,millis:1,millisecond:1,milliseconds:1,s:1e3,sec:1e3,second:1e3,seconds:1e3,m:6e4,min:6e4,minute:6e4,minutes:6e4,h:36e5,hour:36e5,hours:36e5,d:864e5,day:864e5,days:864e5,w:6048e5,week:6048e5,weeks:6048e5,month:2592e6,months:2592e6,y:31536e6,year:31536e6,years:31536e6},Kt={b:0,byte:0,bytes:0,kb:1,kilobyte:1,kilobytes:1,mb:2,megabyte:2,megabytes:2,gb:3,gigabyte:3,gigabytes:3,tb:4,terabyte:4,terabytes:4},Vt=new Map;function Jt(t,n=!1){t=t.filter(t=>t),n&&x(t[1])&&(t[1]="../"+t[1]);let e="";x(t[0])&&t[0].includes("://")&&(e=_(t[0],"://")??"",t[0]=G(t[0],"://")??"");const r=t.map(t=>String(t)).flatMap(t=>t.split("/")),i=[];for(let t=0;t<r.length;t++)"."!==r[t]&&(".."===r[t]?(!e||i.length>1)&&i.pop():i.push(r[t]));return(e?e+"://":"")+i.join("/").replaceAll(/\/{2,}/g,"/")}function Zt(t){const n=Object.keys(t).sort((t,n)=>t.localeCompare(n)),e={};for(const r of n)e[r]=_t(t[r]);return e}function Qt(t){const n=[];return t.sort((t,n)=>JSON.stringify(_t(t)).localeCompare(JSON.stringify(_t(n)))).forEach(t=>n.push(_t(t))),n}function _t(t){return Array.isArray(t)?Qt(t):d(t)?Zt(t):t}function Gt(t,n){return JSON.stringify(_t(t))===JSON.stringify(_t(n))}function Xt(t){const n=Object.keys(t);return n[Math.floor(Math.random()*n.length)]}const Yt=[1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24,1e27,1e30,1e9,1e16,1e18,1e18,1e18,1e33],tn=["thousand","million","billion","trillion","quadrillion","quintillion","sextillion","septillion","octillion","nonillion","gwei","bzz","btc","eth","dai","decillion"],nn=["K","M","B","T","Qa","Qi","Sx","Sp","O","N","gwei","bzz","eth","btc","dai","D"];function en(t){const n=parseFloat(t);if(isNaN(n))throw Error("makeNumber got NaN for input");const e=t.replace(/^-?[0-9.]+/,"").trim(),r=nn.findIndex(t=>t.toLowerCase()===e.toLowerCase());return-1===r?n:n*Yt[r]}function rn(t,n,e){return t<n?n:t>e?e:t}function on(t,n,e){return t+(e?"["+n+"]":(t.length?".":"")+n)}function sn(t,n,e,r,i){if(!d(n))return n;for(const[o,s]of Object.entries(n)){const n=on(e,o,r);Array.isArray(s)?i?sn(t,s,n,!0,i):t[n]=s.map(t=>sn(Array.isArray(t)?[]:{},t,"",!1,i)):d(s)?sn(t,s,n,!1,i):t[n]=s}return t}function un(t,n){const e={};for(const r of t)e[n(r)]=r;return e}function an(t,n){const e=Math.ceil(t.length/n),r=[];for(let n=0;n<t.length;n+=e)r.push(t.slice(n,n+e));return r}function cn(t,n){const e=[],r=Math.ceil(t.length/n);for(let i=0;i<r;i++)e.push(t.slice(i*n,i*n+n));return e}function ln(t,n){return Object.fromEntries(Object.entries(t).sort(n))}function fn(t,n){const e=[];let r=[];return t.forEach((i,o)=>{(0===o||!n(i,t[o-1]))&&(r=[],e.push(r)),r.push(i)}),e}function hn(t,n,e,r=100){if(t.map.has(n)){const e=t.keys.indexOf(n);t.keys.splice(e,1)}if(t.map.set(n,e),t.keys.push(n),t.keys.length>r){const n=t.keys.shift();n&&t.map.delete(n)}}class gn{constructor(t){this.value=t}static of(t){return new gn(t)}static empty(){return new gn(null)}map(t){return new gn(null!==this.value&&void 0!==this.value?t(this.value):null)}mapAsync(t){return null!==this.value&&void 0!==this.value?t(this.value).then(t=>gn.of(t)):Promise.resolve(gn.empty())}ifPresent(t){return null!==this.value&&void 0!==this.value&&t(this.value),this}ifPresentAsync(t){return null!==this.value&&void 0!==this.value?t(this.value).then(()=>this):Promise.resolve(this)}ifAbsent(t){return(null===this.value||void 0===this.value)&&t(),this}ifAbsentAsync(t){return null===this.value||void 0===this.value?t().then(()=>this):Promise.resolve(this)}getOrFallback(t){return this.value??t()}getOrFallbackAsync(t){return null!==this.value&&void 0!==this.value?Promise.resolve(this.value):t()}getOrThrow(){if(null===this.value||void 0===this.value)throw Error("Optional.value is empty");return this.value}}t.Optional=gn,t.Lazy=class{constructor(t){this.supplier=t,this.value=null}get(){return this.value||(this.value=this.supplier()),this.value}},t.AsyncLazy=class{constructor(t){this.supplier=t,this.value=null}async get(){return this.value||(this.value=await this.supplier()),this.value}};class pn{constructor(t){this.value=t,this.children=[]}}function dn(t,n){if(Math.log2(t.length)%1!=0)throw new Error("Array length must be a power of 2");let e=[...t];for(;e.length>1;){const t=[];for(let r=0;r<e.length;r+=2){const i=e[r+1];t.push(n(e[r],i))}e=t}return e[0]}function mn(...t){const n=t.reduce((t,n)=>t+n.length,0),e=new Uint8Array(n);let r=0;return t.forEach(t=>{e.set(t,r),r+=t.length}),e}function yn(t){return 137===t[0]&&80===t[1]&&78===t[2]&&71===t[3]}function wn(t){return 255===t[0]&&216===t[1]}function bn(t){return 87===t[8]&&69===t[9]&&66===t[10]&&80===t[11]}function xn(t,n){const e=new ArrayBuffer(8);return new DataView(e).setBigUint64(0,BigInt(t),"LE"===n),new Uint8Array(e)}function $n(t,n){const e=new Uint8Array(32);let r=t;if("LE"===n){for(let t=0;t<32;t++)e[t]=Number(0xffn&r),r>>=8n;return e}for(let t=31;t>=0;t--)e[t]=Number(0xffn&r),r>>=8n;return e}function vn(t,n){let e=0n;if("LE"===n){for(let n=31;n>=0;n--)e=e<<8n|BigInt(t[n]);return e}for(let n=0;n<32;n++)e=e<<8n|BigInt(t[n]);return e}function En(t,n){const e=[];for(let r=0;r<t.length;r+=n)e.push(t.subarray(r,r+n));return e}const Mn=[0,1,0,32898,2147483648,32906,2147483648,2147516416,0,32907,0,2147483649,2147483648,2147516545,2147483648,32777,0,138,0,136,0,2147516425,0,2147483658,0,2147516555,2147483648,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,0,32778,2147483648,2147483658,2147483648,2147516545,2147483648,32896,0,2147483649,2147483648,2147516424];function An(t){for(let n=0;n<24;n++){const e=t[0]^t[10]^t[20]^t[30]^t[40],r=t[1]^t[11]^t[21]^t[31]^t[41],i=t[2]^t[12]^t[22]^t[32]^t[42],o=t[3]^t[13]^t[23]^t[33]^t[43],s=t[4]^t[14]^t[24]^t[34]^t[44],u=t[5]^t[15]^t[25]^t[35]^t[45],a=t[6]^t[16]^t[26]^t[36]^t[46],c=t[7]^t[17]^t[27]^t[37]^t[47],l=t[8]^t[18]^t[28]^t[38]^t[48],f=t[9]^t[19]^t[29]^t[39]^t[49],h=l^(i<<1|o>>>31),g=f^(o<<1|i>>>31),p=e^(s<<1|u>>>31),d=r^(u<<1|s>>>31),m=i^(a<<1|c>>>31),y=o^(c<<1|a>>>31),w=s^(l<<1|f>>>31),b=u^(f<<1|l>>>31),x=a^(e<<1|r>>>31),$=c^(r<<1|e>>>31);t[0]^=h,t[1]^=g,t[2]^=p,t[3]^=d,t[4]^=m,t[5]^=y,t[6]^=w,t[7]^=b,t[8]^=x,t[9]^=$,t[10]^=h,t[11]^=g,t[12]^=p,t[13]^=d,t[14]^=m,t[15]^=y,t[16]^=w,t[17]^=b,t[18]^=x,t[19]^=$,t[20]^=h,t[21]^=g,t[22]^=p,t[23]^=d,t[24]^=m,t[25]^=y,t[26]^=w,t[27]^=b,t[28]^=x,t[29]^=$,t[30]^=h,t[31]^=g,t[32]^=p,t[33]^=d,t[34]^=m,t[35]^=y,t[36]^=w,t[37]^=b,t[38]^=x,t[39]^=$,t[40]^=h,t[41]^=g,t[42]^=p,t[43]^=d,t[44]^=m,t[45]^=y,t[46]^=w,t[47]^=b,t[48]^=x,t[49]^=$;const v=t[0],E=t[1],M=t[2]<<1|t[3]>>>31,A=t[3]<<1|t[2]>>>31,S=t[5]<<30|t[4]>>>2,k=t[4]<<30|t[5]>>>2,O=t[6]<<28|t[7]>>>4,T=t[7]<<28|t[6]>>>4,B=t[8]<<27|t[9]>>>5,j=t[9]<<27|t[8]>>>5,C=t[11]<<4|t[10]>>>28,D=t[10]<<4|t[11]>>>28,I=t[13]<<12|t[12]>>>20,U=t[12]<<12|t[13]>>>20,F=t[14]<<6|t[15]>>>26,N=t[15]<<6|t[14]>>>26,P=t[17]<<23|t[16]>>>9,z=t[16]<<23|t[17]>>>9,L=t[18]<<20|t[19]>>>12,R=t[19]<<20|t[18]>>>12,W=t[20]<<3|t[21]>>>29,q=t[21]<<3|t[20]>>>29,H=t[22]<<10|t[23]>>>22,K=t[23]<<10|t[22]>>>22,V=t[25]<<11|t[24]>>>21,J=t[24]<<11|t[25]>>>21,Z=t[26]<<25|t[27]>>>7,Q=t[27]<<25|t[26]>>>7,_=t[29]<<7|t[28]>>>25,G=t[28]<<7|t[29]>>>25,X=t[31]<<9|t[30]>>>23,Y=t[30]<<9|t[31]>>>23,tt=t[33]<<13|t[32]>>>19,nt=t[32]<<13|t[33]>>>19,et=t[34]<<15|t[35]>>>17,rt=t[35]<<15|t[34]>>>17,it=t[36]<<21|t[37]>>>11,ot=t[37]<<21|t[36]>>>11,st=t[38]<<8|t[39]>>>24,ut=t[39]<<8|t[38]>>>24,at=t[40]<<18|t[41]>>>14,ct=t[41]<<18|t[40]>>>14,lt=t[42]<<2|t[43]>>>30,ft=t[43]<<2|t[42]>>>30,ht=t[45]<<29|t[44]>>>3,gt=t[44]<<29|t[45]>>>3,pt=t[47]<<24|t[46]>>>8,dt=t[46]<<24|t[47]>>>8,mt=t[48]<<14|t[49]>>>18,yt=t[49]<<14|t[48]>>>18;t[0]=v^~I&V,t[1]=E^~U&J,t[2]=I^~V&it,t[3]=U^~J&ot,t[4]=V^~it&mt,t[5]=J^~ot&yt,t[6]=it^~mt&v,t[7]=ot^~yt&E,t[8]=mt^~v&I,t[9]=yt^~E&U,t[10]=O^~L&W,t[11]=T^~R&q,t[12]=L^~W&tt,t[13]=R^~q&nt,t[14]=W^~tt&ht,t[15]=q^~nt>,t[16]=tt^~ht&O,t[17]=nt^~gt&T,t[18]=ht^~O&L,t[19]=gt^~T&R,t[20]=M^~F&Z,t[21]=A^~N&Q,t[22]=F^~Z&st,t[23]=N^~Q&ut,t[24]=Z^~st&at,t[25]=Q^~ut&ct,t[26]=st^~at&M,t[27]=ut^~ct&A,t[28]=at^~M&F,t[29]=ct^~A&N,t[30]=B^~C&H,t[31]=j^~D&K,t[32]=C^~H&et,t[33]=D^~K&rt,t[34]=H^~et&pt,t[35]=K^~rt&dt,t[36]=et^~pt&B,t[37]=rt^~dt&j,t[38]=pt^~B&C,t[39]=dt^~j&D,t[40]=S^~P&_,t[41]=k^~z&G,t[42]=P^~_&X,t[43]=z^~G&Y,t[44]=_^~X<,t[45]=G^~Y&ft,t[46]=X^~lt&S,t[47]=Y^~ft&k,t[48]=lt^~S&P,t[49]=ft^~k&z,t[0]^=Mn[2*n],t[1]^=Mn[2*n+1]}}function Sn(t){const n=[];for(let e=0;e<t.length;e+=4)n.push(t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24);return n}function kn(t,n){if(!t.length){const t=new Uint8Array(136);return t[0]=n,t[135]=128,[Sn(t)]}const e=En(t,136),r=e[e.length-1];if(r.length<136){const t=new Uint8Array(136);t.set(r),t[r.length]=n,t[135]|=128,e[e.length-1]=t}if(136===r.length){const t=new Uint8Array(136);t[0]=n,t[135]=128,e.push(t)}return e.map(Sn)}function On(t,n){for(const e of n){for(let n=0;n<34;n+=2)t[n]^=e[n+1],t[n+1]^=e[n];An(t)}return t}function Tn(t){return new Uint8Array([t[1],t[1]>>-24,t[1]>>-16,t[1]>>-8,t[0],t[0]>>8,t[0]>>16,t[0]>>24,t[3],t[3]>>-24,t[3]>>-16,t[3]>>-8,t[2],t[2]>>8,t[2]>>16,t[2]>>24,t[5],t[5]>>-24,t[5]>>-16,t[5]>>-8,t[4],t[4]>>8,t[4]>>16,t[4]>>24,t[7],t[7]>>-24,t[7]>>-16,t[7]>>-8,t[6],t[6]>>8,t[6]>>16,t[6]>>24])}function Bn(t){return Tn(On(new Array(50).fill(0),kn(t,1)))}function jn(t,n,e=0){if(t.length>=n)return t;const r=new Uint8Array(n);return r.fill(e),r.set(t,n-t.length),r}function Cn(t,n,e=0){if(t.length>=n)return t;const r=new Uint8Array(n);return r.fill(e),r.set(t,0),r}function Dn(t,n){return(t%n+n)%n}function In(t,n){t=Dn(t,n);let[e,r]=[0n,1n],[i,o]=[n,t];for(;0n!==o;){const t=i/o;[e,r]=[r,e-t*r],[i,o]=[o,i-t*o]}if(i>1n)throw new Error("a is not invertible");return e<0n&&(e+=n),e}function Un(t,n){return 0n===Dn(t,n)?0n:n%4n==3n?function(t,n,e){let r=1n;for(t=Dn(t,e);n>0;)n%2n==1n&&(r=Dn(r*t,e)),t=Dn(t*t,e),n/=2n;return r}(t,(n+1n)/4n,n):null}const Fn=0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,Nn=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,Pn=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,zn=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n;function Ln(t,n,e){if(0n===n)return[0n,0n];const r=Dn(3n*t*t*In(2n*n,e),e),i=Dn(r*r-2n*t,e);return[i,Dn(r*(t-i)-n,e)]}function Rn(t,n,e,r,i){if(0n===t&&0n===n)return[e,r];if(0n===e&&0n===r)return[t,n];if(t===e&&n===Dn(-r,i))return[0n,0n];if(t===e&&n===r)return Ln(t,n,i);const o=Dn((r-n)*In(e-t,i),i),s=Dn(o*o-t-e,i);return[s,Dn(o*(t-s)-n,i)]}function Wn(t,n,e,r){let i=[0n,0n],o=[t,n];const s=e.toString(2);for(const t of s)"0"===t?(o=Rn(i[0],i[1],o[0],o[1],r),i=Ln(i[0],i[1],r)):(i=Rn(i[0],i[1],o[0],o[1],r),o=Ln(o[0],o[1],r));return i}function qn(t,n,e){if(n<=0n||n>=Nn)throw new Error("Invalid private key");if(e||(e=Dn(vn(Bn(mn(Bn($n(n,"BE")),$n(t,"BE"))),"BE"),Nn)),e<=0n||e>=Nn)throw new Error("Invalid nonce");const r=Dn(t,Nn),i=Wn(Pn,zn,e,Fn),o=Dn(i[0],Nn);let s=Dn((r+Dn(o,Nn)*n)*In(e,Nn),Nn);if(0n===o||0n===s)throw new Error("Invalid r or s value");let u=i[1]%2n==0n?27n:28n;return s>Nn/2n&&(s=Nn-s,u=27n===u?28n:27n),[o,s,u]}class Hn{constructor(t){this.cursor=0,this.buffer=t}read(t){const n=this.buffer.subarray(this.cursor,this.cursor+t);return this.cursor+=t,n}max(){return this.buffer.length-this.cursor}}t.Uint8ArrayReader=Hn;class Kn{constructor(t){this.buffer=t,this.cursor=0}write(t){const n=Math.min(this.max(),t.max());return this.buffer.set(t.read(n),this.cursor),this.cursor+=n,n}max(){return this.buffer.length-this.cursor}}t.Uint8ArrayWriter=Kn;class Vn{constructor(t,n=0n){this.span=n,this.writer=new Kn(new Uint8Array(t))}build(){return mn(xn(this.span,"LE"),this.writer.buffer)}hash(){const t=dn(En(this.writer.buffer,32),(t,n)=>Vn.hashFunction(mn(t,n)));return Vn.hashFunction(mn(xn(this.span,"LE"),t))}}t.Chunk=Vn,Vn.hashFunction=Bn;class Jn{constructor(t,n=4096){this.counters=[1],this.capacity=n,this.chunks=[new Vn(n)],this.onChunk=t}static async root(t,e=4096){const r=new n(n.NOOP,e);return await r.append(t),r.finalize()}async append(t,n=0,e=0n){const r=new Hn(t);for(;r.max()>0;){0===this.chunks[n].writer.max()&&await this.elevate(n);const t=this.chunks[n].writer.write(r);e?this.chunks[n].span+=e:this.chunks[0].span+=BigInt(t)}}async elevate(t){this.counters[t]=++this.counters[t]%(this.capacity/32),this.chunks[t+1]||(this.chunks.push(new Vn(this.capacity)),this.counters.push(1)),await this.append(this.chunks[t].hash(),t+1,this.chunks[t].span),await this.onChunk(this.chunks[t]),this.chunks[t]=new Vn(this.capacity)}async finalize(t=0){return this.chunks[t+1]?1===this.counters[t]?(await this.elevate(t+1),this.chunks[t+1]=this.chunks[t],this.finalize(t+1)):(await this.elevate(t),this.finalize(t+1)):(await this.onChunk(this.chunks[t]),this.chunks[t])}}t.MerkleTree=Jn,n=Jn,Jn.NOOP=async t=>{};class Zn{constructor(t,n){if(n<0)throw Error("Scale must be non-negative");this.value=BigInt(t),this.scale=n}static cast(t){if(!t)throw Error("Cannot cast falsy value to FixedPointNumber");if(t instanceof Zn)return t;const n=R(t.value),e=F(t.scale);return new Zn(n,e)}static fromDecimalString(t,n){/e\-\d+$/i.test(t)&&(t=parseFloat(t).toFixed(n));let[e,r]=t.split(".");return r=(r||"").padEnd(n,"0").slice(0,n),new Zn(BigInt(e+r),n)}static fromFloat(t,n){return Zn.fromDecimalString(t.toString(),n)}add(t){return this.assertSameScale(t),new Zn(this.value+t.value,this.scale)}subtract(t){return this.assertSameScale(t),new Zn(this.value-t.value,this.scale)}multiply(t){return new Zn(this.value*t,this.scale)}divmod(t){if(0n===t)throw new Error("Division by zero is not allowed");const n=this.value/t,e=this.value%t;return[new Zn(n,this.scale),new Zn(e,this.scale)]}exchange(t,n,e){if("*"===t){const t=this.value*n.value/10n**BigInt(this.scale);return new Zn(t,e)}this.assertSameScale(n);const r=this.value*10n**BigInt(e)/n.value;return new Zn(r,e)}compare(t){return this.assertSameScale(t),this.value>t.value?1:this.value<t.value?-1:0}toDecimalString(){if(0===this.scale)return this.value.toString();const t=this.value.toString();return`${t.slice(0,-this.scale)||"0"}.${t.slice(-this.scale).padStart(this.scale,"0")}`}toString(){return this.value.toString()}toJSON(){return this.toString()}toFloat(){return parseFloat(this.toDecimalString())}assertSameScale(t){if(this.scale!==t.scale)throw new Error(`Scale mismatch: expected ${this.scale}, but got ${t.scale}`)}}function Qn(t,n,e,r){const i=t.findIndex(t=>t===`--${n}`||t.startsWith(`--${n}=`)),o=t[i];if(!o)return(e||{})[r||n||""]||null;if(o.includes("="))return o.split("=")[1];const s=t[i+1];return s&&!s.startsWith("-")?s:(e||{})[r||n||""]||null}function _n(t,n,e,r){const i=Qn(t,n,e,r);if(!i)throw new Error(`Missing argument ${n}`);return i}function Gn(t,n){const e=t[n];t.splice(n,1),t.unshift(e)}function Xn(t,n){return{x:t.x+n.x,y:t.y+n.y}}function Yn(t,n){return{x:t.x*n,y:t.y*n}}function te(t,n,e){return{x:t.x+Math.cos(n)*e,y:t.y+Math.sin(n)*e}}function ne(t,n){return Math.sqrt((t.x-n.x)**2+(t.y-n.y)**2)}function ee(t,n,e="row-first"){const r=[];if("column-first"===e)for(let e=0;e<t.length;e++)for(let i=0;i<t[0].length;i++)n(e,i)&&r.push({x:e,y:i});else for(let e=0;e<t[0].length;e++)for(let i=0;i<t.length;i++)n(i,e)&&r.push({x:i,y:e});return r}function re(t,n,e){return!t[n-1]?.[e]}function ie(t,n,e){return!t[n+1]?.[e]}function oe(t,n,e){return!t[n][e-1]}function se(t,n,e){return!t[n][e+1]}function ue(t,n,e){const r=[];return t[n][e]?function(t,n,e){return t[n+1]?.[e]&&t[n-1]?.[e]&&!t[n][e-1]&&!t[n][e+1]}(t,n,e)||function(t,n,e){return t[n][e+1]&&t[n][e-1]&&!t[n-1]?.[e]&&!t[n+1]?.[e]}(t,n,e)?[]:(!t[n-1]?.[e-1]&&re(t,n,e)&&oe(t,n,e)&&r.push({x:n,y:e}),!t[n+1]?.[e-1]&&ie(t,n,e)&&oe(t,n,e)&&r.push({x:n+1,y:e}),!t[n-1]?.[e+1]&&re(t,n,e)&&se(t,n,e)&&r.push({x:n,y:e+1}),!t[n+1]?.[e+1]&&ie(t,n,e)&&se(t,n,e)&&r.push({x:n+1,y:e+1}),r):(t[n-1]?.[e]&&t[n][e-1]&&r.push({x:n,y:e}),t[n+1]?.[e]&&t[n][e-1]&&r.push({x:n+1,y:e}),t[n-1]?.[e]&&t[n][e+1]&&r.push({x:n,y:e+1}),t[n+1]?.[e]&&t[n][e+1]&&r.push({x:n+1,y:e+1}),r)}function ae(t,n){return n.map(n=>function(t,n){return Math.atan2(n.y-t.y,n.x-t.x)}(t,n)).sort((t,n)=>t-n)}function ce(t,n,e,r){const i=(r.y-e.y)*(n.x-t.x)-(r.x-e.x)*(n.y-t.y);if(0===i)return null;let o=t.y-e.y,s=t.x-e.x;const u=(r.x-e.x)*o-(r.y-e.y)*s,a=(n.x-t.x)*o-(n.y-t.y)*s;return o=u/i,s=a/i,o>0&&o<1&&s>0&&s<1?{x:t.x+o*(n.x-t.x),y:t.y+o*(n.y-t.y)}:null}function le(t,n,e){const r=[],i=te(t,e,1e4);for(const e of n){const n=ce(t,i,e.start,e.end);n&&r.push(n)}return r.length?r.reduce((n,e)=>ne(t,e)<ne(t,n)?e:n):null}t.FixedPointNumber=Zn;class fe{constructor(){this.subscribers=[]}subscribe(t){return this.subscribers.push(t),()=>{this.subscribers=this.subscribers.filter(n=>n!==t)}}publish(t){this.subscribers.forEach(n=>n(t))}clear(){this.subscribers=[]}getSubscriberCount(){return this.subscribers.length}}t.PubSubChannel=fe,t.AsyncQueue=class{constructor(t,n){this.queue=[],this.running=0,this.onProcessed=new fe,this.onDrained=new fe,this.concurrency=t,this.capacity=n}process(){if(this.running>=this.concurrency)return;const t=this.queue.shift();t&&(this.running++,t().finally(()=>{this.running--,this.process(),this.onProcessed.publish(),0===this.running&&this.onDrained.publish()}))}enqueue(t){if(this.queue.length<this.capacity)return this.queue.push(t),this.process(),Promise.resolve();if(this.onProcessed.getSubscriberCount())throw Error("Queue capacity is full");return new Promise(n=>{this.onProcessed.subscribe(()=>{this.queue.length<this.capacity&&(this.queue.push(t),this.process(),this.onProcessed.clear(),n())})})}drain(){if(0===this.running)return Promise.resolve();if(this.onDrained.getSubscriberCount())throw Error("Already draining");return new Promise(t=>{this.onDrained.subscribe(()=>{this.onDrained.clear(),t()})})}};class he{constructor(){this.forks=new Map}insert(t,n){if(0===t.length)return void(this.handler=n);const e=t[0];let r,i=e;if(e.startsWith(":")&&(i=":",r=e.slice(1)),!this.forks.has(i)){const t=new he;r&&(t.variableName=r),this.forks.set(i,t)}this.forks.get(i).insert(t.slice(1),n)}async handle(t,n,e,r){if(0===t.length)return!!this.handler&&(await this.handler(n,e,r),!0);const i=t[0],o=this.forks.get(i);if(o)return o.handle(t.slice(1),n,e,r);const s=this.forks.get(":");if(s)return s.variableName&&r.set(s.variableName,decodeURIComponent(i)),s.handle(t.slice(1),n,e,r);const u=this.forks.get("*");return!!u&&(r.set("wildcard",t.join("/")),!!u.handler&&(await u.handler(n,e,r),!0))}}t.TrieRouter=he,t.RollingValueProvider=class{constructor(t){this.index=0,this.values=t}current(){return this.values[this.index]}next(){return this.index=(this.index+1)%this.values.length,this.values[this.index]}},t.Solver=class{constructor(){this.status="pending",this.steps=[],this.onStatusChange=async()=>{},this.onStepChange=async()=>{},this.onFinish=async()=>{},this.onError=async()=>{},this.context=new Map}getStatus(){return this.status}createInitialState(){return Object.fromEntries(this.steps.map(t=>[t.name,"pending"]))}setHooks(t){t.onStatusChange&&(this.onStatusChange=t.onStatusChange),t.onStepChange&&(this.onStepChange=t.onStepChange),t.onFinish&&(this.onFinish=t.onFinish),t.onError&&(this.onError=t.onError)}addStep(t){if(this.steps.find(n=>n.name===t.name))throw Error(`Step with name ${t.name} already exists`);this.steps.push(t)}async execute(){if("pending"!==this.status)throw Error(`Cannot execute solver in status ${this.status}`);this.status="in-progress",await this.onStatusChange(this.status);let t=this.createInitialState();for(const n of this.steps)try{if(n.transientSkipStepName){const e=t[n.transientSkipStepName];if("skipped"===e||"failed"===e){t={...t,[n.name]:"skipped"},await this.onStepChange(t);continue}}if(n.precondition&&!await n.precondition(this.context)){t={...t,[n.name]:"skipped"},await this.onStepChange(t);continue}t={...t,[n.name]:"in-progress"},await this.onStepChange(t);for(let t=0;"retry"===await n.action(this.context,t);t++);t={...t,[n.name]:"completed"},await this.onStepChange(t)}catch(e){throw t={...t,[n.name]:"failed"},this.status="failed",await this.onStatusChange(this.status),await this.onStepChange(t),await this.onError(e),e}return this.status="completed",await this.onStatusChange(this.status),await this.onFinish(),this.context}},t.Lock=class{constructor(t){this.queryFunction=t.queryFunction,this.lockFunction=t.lockFunction,this.unlockFunction=t.unlockFunction,this.timeoutMillis=t.timeoutMillis}async couldLock(){const t=await this.queryFunction();try{const n=N(t);if(Date.now()<n+this.timeoutMillis)return new Date(n+this.timeoutMillis)}catch{}return await this.lockFunction(Date.now().toString()),!0}async unlock(){await this.unlockFunction()}},t.Binary={hexToUint8Array:function(t){(t.startsWith("0x")||t.startsWith("0X"))&&(t=t.slice(2));const n=t.length/2,e=new Uint8Array(n);for(let r=0;r<n;r++){const n=parseInt(t.slice(2*r,2*r+2),16);e[r]=n}return e},uint8ArrayToHex:function(t){return Array.from(t).map(t=>t.toString(16).padStart(2,"0")).join("")},binaryToUint8Array:function(t){const n=Math.ceil(t.length/8),e=new Uint8Array(n);for(let r=0;r<n;r++){const n=parseInt(t.slice(8*r,8*r+8),2);e[r]=n}return e},uint8ArrayToBinary:function(t){return Array.from(t).map(t=>t.toString(2).padStart(8,"0")).join("")},base64ToUint8Array:function(t){return Et(t,$t)},uint8ArrayToBase64:function(t){return Mt(t,$t)},base32ToUint8Array:function(t){return Et(t,vt)},uint8ArrayToBase32:function(t){return Mt(t,vt)},log2Reduce:dn,partition:En,concatBytes:mn,numberToUint8:function(t){return new Uint8Array([t])},uint8ToNumber:function(t){return t[0]},numberToUint16:function(t,n){const e=new ArrayBuffer(2);return new DataView(e).setUint16(0,t,"LE"===n),new Uint8Array(e)},uint16ToNumber:function(t,n){return new DataView(t.buffer).getUint16(t.byteOffset,"LE"===n)},numberToUint32:function(t,n){const e=new ArrayBuffer(4);return new DataView(e).setUint32(0,t,"LE"===n),new Uint8Array(e)},uint32ToNumber:function(t,n){return new DataView(t.buffer).getUint32(t.byteOffset,"LE"===n)},numberToUint64:xn,uint64ToNumber:function(t,n){return new DataView(t.buffer).getBigUint64(t.byteOffset,"LE"===n)},numberToUint256:$n,uint256ToNumber:vn,sliceBytes:function(t,n){const e=[];let r=0;for(const i of n)e.push(t.subarray(r,r+i)),r+=i;return e},keccak256:Bn,sha3_256:function(t){return Tn(On(new Array(50).fill(0),kn(t,6)))},proximity:function(t,n){const e=Math.min(t.length,n.length);for(let r=0;r<e;r++){const e=t[r]^n[r];for(let t=0;t<8;t++)if(e>>7-t&1)return 8*r+t}return 8*Math.min(t.length,n.length)},commonPrefix:function(t,n){const e=Math.min(t.length,n.length);for(let r=0;r<e;r++)if(t[r]!==n[r])return t.subarray(0,r);return t.subarray(0,e)},setBit:function(t,n,e,r){const i=Math.floor(n/8),o=n%8;1===e?t[i]|=1<<("BE"===r?7-o:o):t[i]&=~(1<<("BE"===r?7-o:o))},getBit:function(t,n,e){const r=n%8;return t[Math.floor(n/8)]>>("BE"===e?7-r:r)&1},indexOf:function(t,n,e=0){for(let r=e;r<t.length;r++)for(let e=0;e<n.length&&t[r+e]===n[e];e++)if(e===n.length-1)return r;return-1},equals:function(t,n){if(t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1;return!0},padStart:jn,padStartToMultiple:function(t,n,e=0){const r=t.length%n;return 0===r?t:jn(t,t.length+n-r,e)},padEnd:Cn,padEndToMultiple:function(t,n,e=0){const r=t.length%n;return 0===r?t:Cn(t,t.length+n-r,e)},xorCypher:function(t,n){const e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t[r]^n[r%n.length];return e},isUtf8:function(t){for(let n=0;n<t.length;n++){const e=t[n];if(!(e<128))if(192==(224&e)){if(n+1>=t.length||128!=(192&t[n+1]))return!1;n+=1}else if(224==(240&e)){if(n+2>=t.length||128!=(192&t[n+1])||128!=(192&t[n+2]))return!1;n+=2}else{if(240!=(248&e))return!1;if(n+3>=t.length||128!=(192&t[n+1])||128!=(192&t[n+2])||128!=(192&t[n+3]))return!1;n+=3}}return!0}},t.Elliptic={privateKeyToPublicKey:function(t){if(t<=0n||t>=Nn)throw new Error("Invalid private key");return Wn(Pn,zn,t,Fn)},compressPublicKey:function(t){const n=t[1]%2n==0n?2:3;return new Uint8Array([n,...$n(t[0],"BE")])},publicKeyFromCompressed:function(t){if(33!==t.length||2!==t[0]&&3!==t[0])throw new Error("Invalid compressed public key");const n=vn(t.slice(1),"BE"),e=Un(Dn(n**3n+7n,Fn),Fn);if(!e)throw Error("Invalid x: does not correspond to a valid curve point");const r=Dn(-e,Fn),i=e%2n==0n;return[n,2===t[0]?i?e:r:i?r:e]},publicKeyToAddress:function(t){const n=new Uint8Array(20),e=Bn(mn($n(t[0],"BE"),$n(t[1],"BE")));return n.set(e.subarray(12)),n},signMessage:function(t,n,e){return qn(vn(Bn(t),"BE"),n,e)},signHash:qn,verifySignature:function(t,n,e,r){const i=Dn(vn(Bn(t),"BE"),Nn),o=In(r,Nn),s=Dn(i*o,Nn),u=Dn(e*o,Nn),a=Wn(Pn,zn,s,Fn),c=Wn(n[0],n[1],u,Fn);return e===Dn(Rn(a[0],a[1],c[0],c[1],Fn)[0],Nn)},recoverPublicKey:function(t,n,e,r){const i=Un(Dn(n**3n+7n,Fn),Fn);if(!i)throw new Error("Invalid r: does not correspond to a valid curve point");const o=i%2n==(27n===r?0n:1n)?i:Fn-i,s=Dn(vn(Bn(t),"BE"),Nn),u=Wn(n,o,e,Fn),a=Wn(Pn,zn,s,Fn),c=Rn(u[0],u[1],a[0],Dn(-a[1],Fn),Fn);return Wn(c[0],c[1],In(n,Nn),Fn)},checksumEncode:function(n){const e=t.Binary.uint8ArrayToHex(n),r=t.Binary.uint8ArrayToHex(t.Binary.keccak256(new Uint8Array([...e].map(t=>t.charCodeAt(0)))));let i="0x";for(let t=0;t<e.length;t++)parseInt(r[t],16)>7?i+=e[t].toUpperCase():i+=e[t];return i}},t.Random={intBetween:s,floatBetween:function(t,n,e=Math.random){return e()*(n-t)+t},chance:a,signed:function(){return 2*Math.random()-1},makeSeededRng:function(t){let n=t,e=3405648695,r=3735928559;return function(){return n+=e,e^=n<<7,n*=r,r^=n<<13,n^=e^r,(n>>>0)/4294967296}},point:function(t,n,e,r=Math.random){let i,o;do{i=s(0,t-1,r),o=s(0,n-1,r)}while(e&&u(e,i,o));return[i,o]},procs:function(t,n=Math.random){const e=Math.floor(t);return a(t-e,n)?e+1:e}},t.Arrays={countUnique:function(t,n,e,r,i){const o=n?t.map(n):t,s={};for(const t of o)s[t]=(s[t]||0)+1;const u=r?ln(s,i?(t,n)=>t[1]-n[1]:(t,n)=>n[1]-t[1]):s;return e?Object.keys(u):u},makeUnique:function(t,n){return Object.values(un(t,n))},splitBySize:function(t,n){const e=[];for(let r=0;r<t.length;r+=n)e.push(t.slice(r,r+n));return e},splitByCount:an,index:un,indexCollection:function(t,n){const e={};for(const r of t){const t=n(r);e[t]||(e[t]=[]),e[t].push(r)}return e},onlyOrThrow:function(t){if(1===t.length)return t[0];throw Error(`Expected exactly one element, actual: ${t.length}`)},onlyOrNull:function(t){return 1===t.length?t[0]:null},firstOrThrow:function(t){if(!t.length)throw Error("Received empty array");return t[0]},firstOrNull:function(t){return t.length>0?t[0]:null},shuffle:i,initialize:function(t,n){const e=[];for(let r=0;r<t;r++)e.push(n(r));return e},initialize2D:function(t,n,e){const r=[];for(let i=0;i<t;i++){r.push([]);for(let t=0;t<n;t++)r[i].push(e)}return r},rotate2D:function(t){const n=[];for(let e=0;e<t[0].length;e++){n.push([]);for(let r=0;r<t.length;r++)n[e].push(t[r][e])}return n},containsShape:function(t,n,e,r){if(e<0||r<0||r+n[0].length>t[0].length||e+n.length>t.length)return!1;for(let i=0;i<n.length;i++)for(let o=0;o<n[i].length;o++)if(void 0!==n[i][o]&&t[e+i][r+o]!==n[i][o])return!1;return!0},glue:function(t,n){const e=[];for(let r=0;r<t.length;r++)e.push(t[r]),r<t.length-1&&(b(n)?e.push(n()):e.push(n));return e},pluck:function(t,n){return t.map(t=>t[n])},pick:c,pickMany:function(t,n,e=Math.random){if(n>t.length)throw new Error(`Count (${n}) is greater than array length (${t.length})`);return o(t,n,e).map(n=>t[n])},pickManyUnique:function(t,n,e,r=Math.random){if(n>t.length)throw new Error(`Count (${n}) is greater than array length (${t.length})`);const i=[];for(;i.length<n;){const n=c(t,r);i.some(t=>e(t,n))||i.push(n)}return i},pickWeighted:function(t,n,e){if(void 0===e&&(e=Math.random()),t.length!==n.length)throw new Error("Array length mismatch");let r=n.reduce((t,n)=>t+n,0);const i=e*r;for(let e=0;e<t.length-1;e++)if(r-=n[e],i>=r)return t[e];return l(t)},pickRandomIndices:o,pickGuaranteed:function(n,e,r,o,s,u=Math.random){const a=n.filter(t=>t!==e&&t!==r),c=[];for(null!==e&&c.push(e);a.length&&c.length<o;){const n=t.Random.intBetween(0,a.length-1,u);s(a[n],c)&&c.push(a[n]),a.splice(n,1)}return i(c,u),{values:c,indexOfGuaranteed:null!==e?c.indexOf(e):-1}},last:l,pipe:f,makePipe:function(t,n){return e=>f(e,t,n)},sortWeighted:function(t,n,e=Math.random){const r=n.map(t=>e()*t),i=[];for(let n=0;n<t.length;n++)i.push([t[n],r[n]]);return i.sort((t,n)=>n[1]-t[1]).map(t=>t[0])},pushAll:K,unshiftAll:function(t,n){Array.prototype.unshift.apply(t,n)},filterAndRemove:function(t,n){const e=[];for(let r=t.length-1;r>=0;r--)n(t[r])&&e.push(t.splice(r,1)[0]);return e},merge:function(t,n){const e=Object.keys(n);for(const r of e)Array.isArray(n[r])&&Array.isArray(t[r])&&K(t[r],n[r])},empty:function(t){return t.splice(0,t.length),t},pushToBucket:function(t,n,e){t[n]||(t[n]=[]),t[n].push(e)},unshiftAndLimit:function(t,n,e){for(t.unshift(n);t.length>e;)t.pop()},atRolling:function(t,n){let e=n%t.length;return e<0&&(e+=t.length),t[e]},group:fn,createOscillator:function(t){let n=0;return{next:()=>t[n++%t.length]}},organiseWithLimits:function(t,n,e,r,i){const o={};for(const t of Object.keys(n))o[t]=[];o[r]=[],i&&(t=t.sort(i));for(const i of t){const t=i[e],s=n[t]?t:r;o[s].length>=n[s]?o[r].push(i):o[s].push(i)}return o},tickPlaybook:function(t){if(0===t.length)return null;const n=t[0];return n.ttlMax?--n.ttl<=0&&t.shift():n.ttlMax=n.ttl,{progress:(n.ttlMax-n.ttl)/n.ttlMax,data:n.data}},getArgument:Qn,getBooleanArgument:function(t,n,e,r){const i=t.some(t=>t.endsWith("-"+n)),o=Qn(t,n,e,r);if(!o&&i)return!0;if(!o&&!i)return null;if(["true","1","yes","y","on"].includes(o.toLowerCase()))return!0;if(["false","0","no","n","off"].includes(o.toLowerCase()))return!1;throw Error(`Invalid boolean argument ${n}: ${o}`)},getNumberArgument:function(t,n,e,r){const i=Qn(t,n,e,r);if(!i)return null;try{return en(i)}catch{throw new Error(`Invalid number argument ${n}: ${i}`)}},requireStringArgument:_n,requireNumberArgument:function(t,n,e,r){const i=_n(t,n,e,r);try{return en(i)}catch{throw new Error(`Invalid argument ${n}: ${i}`)}},bringToFront:function(t,n){const e=[...t];return Gn(e,n),e},bringToFrontInPlace:Gn,findInstance:function(t,n){const e=t.find(t=>t instanceof n);return gn.of(e)},filterInstances:function(t,n){return t.filter(t=>t instanceof n)},interleave:function(t,n){const e=[],r=Math.max(t.length,n.length);for(let i=0;i<r;i++)t[i]&&e.push(t[i]),n[i]&&e.push(n[i]);return e},toggle:function(t,n){return t.includes(n)?t.filter(t=>t!==n):[...t,n]},createHierarchy:function(t,n,e,r,i=!1){const o=new Map,s=[];t.forEach(t=>{const e=new pn(t);o.set(t[n],e)}),t.forEach(t=>{const r=o.get(t[n]);if(!r)return;const i=t[e];if(i){const t=o.get(i);t&&t.children.push(r)}else s.push(r)});const u=t=>{t.children.sort((t,n)=>{const e=t.value[r],o=n.value[r];return i?o-e:e-o}),t.children.forEach(u)};return s.forEach(u),s},multicall:function(t){return()=>t.forEach(t=>t())},maxBy:function(t,n){return t.reduce((t,e)=>n(t)>n(e)?t:e)},minBy:function(t,n){return t.reduce((t,e)=>n(t)<n(e)?t:e)},allIndexOf:function(t,n){const e=[];return t.forEach((t,r)=>{n(t)&&e.push(r)}),e}},t.System={sleepMillis:r,forever:async function(t,n,e){for(;;){try{await t()}catch(t){e&&e("Error in forever",t)}await r(n)}},scheduleMany:function(t,n){for(let e=0;e<t.length;e++){const r=t[e],i=n[e],o=Math.max(0,i.getTime()-Date.now());setTimeout(r,o)}},waitFor:async function(t,n){let e=n.requiredConsecutivePasses||1,i=0;for(let o=0;o<n.attempts;o++){try{if(await t()){if(i++,i>=e)return}else i=0}catch{i=0}o<n.attempts-1&&await r(n.waitMillis)}throw Error("Timed out waiting for predicate")},expandError:function(t,n){if(x(t))return t;const e=Object.keys(t);t.message&&!e.includes("message")&&e.push("message");const r=e.map(n=>`${n}: ${t[n]}`).join("; ");return n&&t.stack?r+"\n"+t.stack:r},runAndSetInterval:function(t,n){t();const e=setInterval(()=>{t()},n);return()=>clearInterval(e)},whereAmI:function(){const t=globalThis.process;return t?!0===t.browser?"browser":"node":"browser"},withRetries:async function(t,n,e,i,o,s){let u=null;for(let a=0;a<=n;a++)try{return await t()}catch(t){if(u=t,a===n)break;const c=e+a/(n-1)*(i-e);o&&o("Error in withRetries, retrying",{attempt:a+1,allowedFailures:n,delayMillis:c,error:t}),s&&s(),await r(c)}throw u}},t.Numbers={make:en,sum:function(t){return t.reduce((t,n)=>t+n,0)},average:function(t){return t.reduce((t,n)=>t+n,0)/t.length},median:function(t){const n=[...t].sort((t,n)=>t-n),e=Math.floor(n.length/2);return n.length%2==0?(n[e]+n[e-1])/2:n[e]},getDistanceFromMidpoint:function(t,n){return t-(n-1)/2},clamp:rn,range:V,interpolate:function(t,n,e){return t+(n-t)*e},createSequence:function(){let t=0;return{next:()=>t++}},increment:function(t,n,e){const r=t+n;return r>e?e:r},decrement:function(t,n,e){const r=t-n;return r<e?e:r},format:function(t,n){const e=n?.longForm??!1,r=n?.unit?` ${n.unit}`:"",i=e?tn:nn,o=n?.precision??1;if(t<Yt[0])return`${t}${r}`;for(let n=0;n<Yt.length-1;n++)if(t<Yt[n+1])return`${(t/Yt[n]).toFixed(o)}${e?" ":""}${i[n]}${r}`;return`${(t/Yt[Yt.length-1]).toFixed(o)}${e?" ":""}${i[Yt.length-1]}${r}`},fromDecimals:function(t,n,e){let r=t.length-n;if(r<=0)return"0."+"0".repeat(-r)+t+(e?" "+e:"");let i=t.substring(0,r);return""===i&&(i="0"),i+"."+t.substring(r)+(e?" "+e:"")},makeStorage:function(t,n=1024){const e=parseFloat(t);if(isNaN(e))throw Error("makeStorage got NaN for input");const r=t.replace(/^-?[0-9.]+/,"").trim().toLowerCase(),i=""===r?0:Kt[r];if(null==i)throw Error(`Unknown unit: "${r}"`);return Math.ceil(e*n**i)},asMegabytes:function(t){return t/1024/1024},convertBytes:function(t,n=1024){return t>=n*n*n*n?(t/n/n/n/n).toFixed(3)+" TB":t>=n*n*n?(t/n/n/n).toFixed(3)+" GB":t>=n*n?(t/n/n).toFixed(3)+" MB":t>=n?(t/n).toFixed(3)+" KB":t+" B"},hexToRgb:function(t){const n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t.toLowerCase());if(!n)throw new Error("Invalid hex color: "+t);return[parseInt(n[1],16),parseInt(n[2],16),parseInt(n[3],16)]},rgbToHex:function(t){return"#"+t.map(t=>t.toString(16).padStart(2,"0")).join("")},haversineDistanceToMeters:function(t,n,e,r){const i=t*Math.PI/180,o=e*Math.PI/180,s=(e-t)*Math.PI/180,u=(r-n)*Math.PI/180,a=Math.sin(s/2)*Math.sin(s/2)+Math.cos(i)*Math.cos(o)*Math.sin(u/2)*Math.sin(u/2);return 2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a))*6371e3},roundToNearest:p,formatDistance:function(t){return t>1e3?(t/1e3).toFixed(0)+" km":t>=500?p(t,100)+" m":t>=100?p(t,50)+" m":p(t,10)+" m"},triangularNumber:function(t){return t*(t+1)/2},searchFloat:function(t){const n=t.match(/-?\d+(\.\d+)?/);if(!n)throw Error("No float found in "+t);return parseFloat(n[0])},binomialSample:function(t,n,e=Math.random){const r=t*n,i=Math.sqrt(t*n*(1-n)),o=(e()+e()+e()+e()+e()+e()-3)*Math.SQRT2,s=Math.round(r+i*o);return Math.max(0,Math.min(t,s))},toSignificantDigits:function(t,n){if(!t.includes("."))return t;if(0===parseFloat(t))return"0";const[e,r]=t.split("."),i=e.replace("-",""),o=i.length;if(o>=n)return e;if("0"!==i){const t=n-o,i=r.slice(0,t);return/[1-9]/.test(i)?`${e}.${i.replace(/0+$/,"")}`:e}const s=n+(r.match(/^0*/)?.[0].length??0);return`${e}.${r.slice(0,s)}`}},t.Promises={raceFulfilled:async function(t){return e(Promise.all(t.map(e)))},invert:e,runInParallelBatches:async function(t,n=1){const e=an(t,n),r=[],i=e.map(async t=>{for(const n of t)r.push(await n())});return await Promise.all(i),r}},t.Dates={getTimestamp:function(t,n){const e=new Date(n?.now||Date.now()),r=n?.labels||Ft,i=E(t)?t:new Date(t);if(Ut(e)===Ut(i))return r.today(i.getUTCHours(),i.getUTCMinutes(),i.getUTCHours()>12);if(Ut(e)-Ut(i)===1)return r.yesterday();const o=qt(i);return Ut(e)-Ut(i)<7?r[o.day]():r.weeks(Math.round((e.getTime()-i.getTime())/6048e5))},getTimeDelta:Pt,secondsToHumanTime:function(t,n=Nt){return Pt(0,{now:1e3*t,labels:n})},countCycles:function(t,n,e){const r=(e?.now??Date.now())-t;return{cycles:Math.floor(r/n),remaining:n/(e?.precision??1)-Math.ceil(r%n/(e?.precision??1))}},isoDate:function(t){return(t||new Date).toISOString().slice(0,10)},throttle:function(t,n){return(!zt[t]||Date.now()>zt[t])&&(zt[t]=Date.now()+n,!0)},timeSince:function(t,n,e){return n=E(n)?n.getTime():n,((e=e?E(e)?e.getTime():e:Date.now())-n)/Lt[t]},dateTimeSlug:function(t){return(t||new Date).toISOString().slice(0,19).replace(/T|:/g,"-")},unixTimestamp:function(t){return Math.ceil((t||Date.now())/1e3)},fromUtcString:function(t){const n=new Date(t);return new Date(n.getTime()-6e4*n.getTimezoneOffset())},fromMillis:function(t){return new Date(t)},getProgress:function(t,n,e,r){r||(r=Date.now());const i=r-t,o=i/n,s=o*e;return{deltaMs:i,progress:n/e,baseTimeMs:o,totalTimeMs:s,remainingTimeMs:s-i}},humanizeTime:It,humanizeProgress:function(t){return`[${Math.floor(100*t.progress)}%] ${It(t.deltaMs)} out of ${It(t.totalTimeMs)} (${It(t.remainingTimeMs)} left) [${Math.round(t.baseTimeMs)} ms each]`},createTimeDigits:Dt,mapDayNumber:Wt,getDayInfoFromDate:qt,getDayInfoFromDateTimeString:function(t){return qt(new Date(t))},seconds:function(t){return 1e3*t},minutes:function(t){return 6e4*t},hours:function(t){return 36e5*t},days:function(t){return 864e5*t},make:function(t){const n=parseFloat(t);if(isNaN(n))throw Error("makeDate got NaN for input");const e=t.replace(/^-?[0-9.]+/,"").trim().toLowerCase(),r=""===e?1:Ht[e];if(!r)throw Error(`Unknown unit: "${e}"`);return Math.ceil(n*r)},normalizeTime:function(t){let[n,e]=t.split(":");$(parseInt(n,10))||(n="0"),$(parseInt(e,10))||(e="0");let r=rn(N(n),0,23),i=rn(N(e),0,59);return`${Dt(r)}:${Dt(i)}`},absoluteDays:Ut},t.Objects={safeParse:function(t){try{return JSON.parse(t)}catch{return null}},deleteDeep:function(t,n){const e=X(n,"."),r=Y(n,".");if(!e||!r)return;const i=h(t,e);i&&delete i[r]},getDeep:h,setDeep:g,incrementDeep:function(t,n,e=1){const r=h(t,n)||0;return g(t,n,r+e),r},ensureDeep:function(t,n,e){return h(t,n)||g(t,n,e)},replaceDeep:function(t,n,e){const r=h(t,n);if(!r)throw new Error("Key '"+n+"' does not exist.");return g(t,n,e),r},getFirstDeep:function(t,n,e){for(const e of n){const n=h(t,e);if(n)return n}if(e){const n=Object.values(t);if(n.length)return n[0]}return null},deepMergeInPlace:q,deepMerge2:function(t,n){const e={};return q(e,t),q(e,n),e},deepMerge3:function(t,n,e){const r={};return q(r,t),q(r,n),q(r,e),r},mapAllAsync:async function(t,n){const e=[];for(const r of t)e.push(await n(r));return e},cloneWithJson:function(t){return JSON.parse(JSON.stringify(t))},sortObject:Zt,sortArray:Qt,sortAny:_t,deepEquals:Gt,deepEqualsEvery:function(...t){for(let n=1;n<t.length;n++)if(!Gt(t[n-1],t[n]))return!1;return!0},runOn:function(t,n){return n(t),t},ifPresent:function(t,n){t&&n(t)},zip:H,zipSum:function(t){return H(t,(t,n)=>t+n)},removeEmptyArrays:function(t){for(const n of Object.keys(t))(y(t[n])||Array.isArray(t[n])&&t[n].every(t=>null==t))&&delete t[n];return t},removeEmptyValues:function(t){for(const n of Object.entries(t))(null===n[1]||void 0===n[1]||x(n[1])&&M(n[1]))&&delete t[n[0]];return t},flatten:function(t,n=!1,e){return sn({},t,e||"",!1,n)},unflatten:function t(n){if(!d(n))return n;const e=Array.isArray(n)?[]:{};for(const[r,i]of Object.entries(n))Array.isArray(i)?g(e,r,i.map(n=>t(n))):g(e,r,i);return e},match:function(t,n,e){return n[t]?n[t]:e},sort:ln,map:function(t,n){const e={};for(const r of Object.entries(t))e[r[0]]=n(r[1]);return e},mapIterable:function(t,n){const e=[];let r=0;for(const i of t)e.push(n(i,r++));return e},filterKeys:function(t,n){const e={};for(const[r,i]of Object.entries(t))n(r)&&(e[r]=i);return e},filterValues:function(t,n){const e={};for(const[r,i]of Object.entries(t))n(i)&&(e[r]=i);return e},rethrow:async function(t,n){try{return await t()}catch{throw n}},setSomeOnObject:function(t,n,e){null!=e&&(t[n]=e)},setSomeDeep:function(t,n,e,r){const i=h(e,r);null!=i&&g(t,n,i)},flip:function(t){const n={};for(const[e,r]of Object.entries(t))n[r]=e;return n},getAllPermutations:function(t){const n=Object.keys(t),e=n.map(n=>t[n].length),r=e.reduce((t,n)=>t*n);let i=1;const o=[1];for(let t=0;t<e.length-1;t++)i*=e[t],o.push(i);const s=[];for(let e=0;e<r;e++){const r={};for(let i=0;i<n.length;i++){const s=t[n[i]],u=Math.floor(e/o[i])%s.length;r[n[i]]=s[u]}s.push(r)}return s},countTruthyValues:function(t){return Object.values(t).filter(t=>t).length},transformToArray:function(t){const n=[],e=Object.keys(t),r=t[e[0]].length;for(let i=0;i<r;i++){const r={};for(const n of e)r[n]=t[n][i];n.push(r)}return n},setMulti:function(t,n,e){for(const r of t)r[n]=e},incrementMulti:function(t,n,e=1){for(const r of t)r[n]+=e},createBidirectionalMap:function(){return{map:new Map,keys:[]}},createTemporalBidirectionalMap:function(){return{map:new Map,keys:[]}},pushToBidirectionalMap:hn,unshiftToBidirectionalMap:function(t,n,e,r=100){if(t.map.has(n)){const e=t.keys.indexOf(n);t.keys.splice(e,1)}if(t.map.set(n,e),t.keys.unshift(n),t.keys.length>r){const n=t.keys.shift();n&&t.map.delete(n)}},addToTemporalBidirectionalMap:function(t,n,e,r,i=100){hn(t,n,{validUntil:Date.now()+r,data:e},i)},getFromTemporalBidirectionalMap:function(t,n){const e=t.map.get(n);return e&&e.validUntil>Date.now()?e.data:null},createStatefulToggle:function(t){let n;return e=>{const r=e===t&&n!==t;return n=e,r}},diffKeys:function(t,n){const e=Object.keys(t),r=Object.keys(n);return{uniqueToA:e.filter(t=>!r.includes(t)),uniqueToB:r.filter(t=>!e.includes(t))}},pickRandomKey:Xt,mapRandomKey:function(t,n){const e=Xt(t);return t[e]=n(t[e]),e},fromObjectString:function(t){return t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=t.replace(/\r\n/g,"\n")).replace(/(\w+)\((.+)\)/g,(t,n,e)=>`${n}(${e.replaceAll(",",",")})`)).replace(/(,)(\s+})/g,"$2")).replace(/\.\.\..+?,/g,"")).replace(/({\s+)([a-zA-Z]\w+),/g,"$1$2: '$2',")).replace(/(,\s+)([a-zA-Z]\w+),/g,"$1$2: '$2',")).replace(/:(.+)\?(.+):/g,(t,n,e)=>`: (${n.trim()} && ${e.trim()}) ||`)).replace(/([a-zA-Z0-9]+)( ?: ?{)/g,'"$1"$2')).replace(/([a-zA-Z0-9]+) ?: ?(.+?)(,|\n|})/g,(t,n,e,r)=>`"${n}":"${e.trim()}"${r}`)).replace(/("'|'")/g,'"')).replaceAll(",",","),JSON.parse(t)},toQueryString:Ct,parseQueryString:function(t){const n={},e=t.split("&");for(const t of e){const[e,r]=t.split("=");e&&r&&(n[e]=decodeURIComponent(r))}return n},hasKey:function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},selectMax:function(t,n){let e=null,r=-1/0;for(const[i,o]of Object.entries(t)){const t=n(o);t>r&&(r=t,e=i)}return e?[e,t[e]]:null},reposition:function(t,n,e,r){const i=t.find(t=>t[n]===e),o=t.find(t=>t[n]===e+r);i&&o?(i[n]=e+r,o[n]=e):i&&(i[n]=e+r),t.sort((t,e)=>F(t[n])-F(e[n])),t.forEach((t,e)=>t[n]=e+1)},unwrapSingleKey:function(t){const n=Object.keys(t);if(1===n.length)return t[n[0]];throw new Error("Expected object to have a single key")},parseKeyValues:function(t,n=":"){return Object.fromEntries(t.map(t=>tt(t,n)).map(t=>t[0]&&t[1]?[it(t[0]),it(t[1])]:null).filter(t=>t))},errorMatches:function(t,n){if(!t)return!1;const e=t.message;return"string"==typeof e&&e.includes(n)}},t.Types={isFunction:b,isObject:d,isStrictlyObject:m,isEmptyArray:y,isEmptyObject:function(t){return m(t)&&0===Object.keys(t).length},isUndefined:w,isString:x,isNumber:$,isBoolean:v,isDate:E,isBlank:M,isId:A,isIntegerString:S,isHexString:k,isUrl:z,isBigint:L,isNullable:function(t,n){return null==n||t(n)},asString:I,asHexString:function(t,n){if(!k(t))throw new TypeError(`Expected hex string${n?.name?` for ${n.name}`:""}, got: `+t);if(n?.strictPrefix&&!t.startsWith("0x")&&!t.startsWith("0X"))throw new TypeError(`Expected hex string with 0x prefix${n?.name?` for ${n.name}`:""}, got: `+t);const e=t.replace(/^0x/i,"");if(e.length%2!=0&&!n?.uneven)throw RangeError(`Expected even number of hex digits${n?.name?` for ${n.name}`:""}; got: `+t);if(n&&n.byteLength&&e.length!==2*n.byteLength)throw RangeError(`Expected hex string${n?.name?` for ${n.name}`:""} of byte length ${n.byteLength}; got: `+e);return`0x${e}`},asSafeString:function(t,n){if(!I(t,n).split("").every(t=>"_"===t||ct(t)))throw new TypeError(`Expected safe string${n?.name?` for ${n.name}`:""}, got: `+t);return t},asIntegerString:function(t,n){if(!S(t))throw new TypeError(`Expected integer string${n?.name?` for ${n.name}`:""}, got: `+t);const e=BigInt(t);if(n&&(n.min&&e<n.min||n.max&&e>n.max))throw RangeError(`Expected integer string${n?.name?` for ${n.name}`:""} in range: ${n.min??"-inf"}..${n.max??"inf"}; got: `+e);return t},asNumber:F,asFunction:function(t,n){if(!b(t))throw new TypeError(`Expected function${n?.name?` for ${n.name}`:""}, got: `+t);return t},asInteger:N,asBoolean:function(t,n){if("true"===t)return!0;if("false"===t)return!1;if(!v(t))throw new TypeError(`Expected boolean${n?.name?` for ${n.name}`:""}, got: `+t);return t},asDate:function(t,n){if(!E(t))throw new TypeError(`Expected date${n?.name?` for ${n.name}`:""}, got: `+t);return t},asNullableString:function(t){return M(t)?null:t},asEmptiableString:function(t,n){if(!x(t))throw new TypeError(`Expected string${n?.name?` for ${n.name}`:""}, got: `+t);return t},asId:function(t,n){if(A(t))return t;const e=parseInt(t,10);if(!A(e))throw new TypeError(`Expected id${n?.name?` for ${n.name}`:""}, got: `+t);return e},asTime:function(t,n){if(!x(t))throw new TypeError(`Expected time${n?.name?` for ${n.name}`:""}, got: `+t);const e=t.split(":");if(2!==e.length)throw new TypeError(`Expected time${n?.name?` for ${n.name}`:""}, got: `+t);const r=parseInt(e[0],10),i=parseInt(e[1],10);if(!$(r)||!$(i)||r<0||r>23||i<0||i>59)throw new TypeError(`Expected time, got${n?.name?` for ${n.name}`:""}: `+t);return`${String(r).padStart(2,"0")}:${String(i).padStart(2,"0")}`},asArray:function(t,n){if(!Array.isArray(t))throw new TypeError(`Expected array${n?.name?` for ${n.name}`:""}, got: `+t);return t},asObject:P,asNullableObject:function(t,n){return null===t?null:P(t,n)},asStringMap:function(t,n){const e=P(t,n);for(const r of Object.keys(e))if(!x(e[r]))throw new TypeError(`Expected string map${n?.name?` for ${n.name}`:""}, got: `+t);return e},asNumericDictionary:function(t,n){const e=P(t),r=Object.keys(e),i=Object.values(e);if(!r.every(x)||!i.every($))throw new TypeError(`Expected numeric dictionary${n?.name?` for ${n.name}`:""}, got: `+t);return e},asUrl:function(t,n){if(!z(t))throw new TypeError(`Expected url${n?.name?` for ${n.name}`:""}, got: `+t);return t},asBigint:R,asEmptiable:function(t,n){return""===n?void 0:t(n)},asNullable:function(t,n){return null==n?null:t(n)},asOptional:function(t,n){return null==n?void 0:t(n)},enforceObjectShape:W,enforceArrayShape:function(t,n){return t.every(t=>W(t,n))},isPng:yn,isJpg:wn,isWebp:bn,isImage:function(t){return yn(t)||wn(t)||bn(t)}},t.Strings={tokenizeByCount:function(t,n){return cn(t,Math.ceil(t.length/n))},tokenizeByLength:cn,searchHex:function(t,n){const e=new RegExp(`[0-9a-f]{${n}}`,"i"),r=t.match(e);return r?r[0]:null},searchSubstring:function(t,n,e=O){const r=nt(t,e);for(const t of r)if(n(t))return t;return null},randomHex:function(t,n=Math.random){let e="";for(let r=0;r<t;r++)e+=D[Math.floor(16*n())];return e},randomLetter:function(t,n=Math.random){let e="";for(let r=0;r<t;r++)e+=T[Math.floor(26*n())];return e},randomAlphanumeric:function(t,n=Math.random){let e="";for(let r=0;r<t;r++)e+=B[Math.floor(62*n())];return e},randomRichAscii:function(t,n=Math.random){let e="";for(let r=0;r<t;r++)e+=j[Math.floor(89*n())];return e},randomUnicode:function(t,n=Math.random){let e="";for(let r=0;r<t;r++)e+=C[Math.floor(n()*C.length)];return e},includesAny:function(t,n){return n.some(n=>t.includes(n))},slugify:J,normalForm:function(t){return J(t).replaceAll("-","")},enumify:function(t){return J(t).replace(/-/g,"_").toUpperCase()},escapeHtml:function(t){return t.replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")},decodeHtmlEntities:function(t){let n=t.replace(/&#(\d+);/g,(t,n)=>String.fromCharCode(n)).replace(/&#x(\d+);/g,(t,n)=>String.fromCharCode(parseInt(n,16)));for(const[t,e]of Object.entries(Q))n=n.replaceAll(t,e);return n},after:G,afterLast:Y,before:_,beforeLast:X,betweenWide:function(t,n,e){const r=X(t,e);return r?G(r,n):null},betweenNarrow:function(t,n,e){const r=G(t,n);return r?_(r,e):null},getPreLine:function(t){return t.replace(/ +/g," ").replace(/^ /gm,"")},containsWord:Ot,containsWords:function(t,n,e){return"any"===e?n.some(n=>Ot(t,n)):n.every(n=>Ot(t,n))},joinUrl:Jt,getFuzzyMatchScore:Z,sortByFuzzyScore:function(t,n){return t.filter(t=>Z(t,n)).sort((t,e)=>Z(e,n)-Z(t,n))},splitOnce:tt,splitAll:nt,randomize:function(t,n=Math.random){return t.replace(/\{(.+?)\}/g,(t,e)=>c(e.split("|"),n))},expand:function t(n){const e=n.match(/\{(.+?)\}/);if(!e||!e.index)return[n];const r=e[1].split(","),i=n.slice(0,e.index),o=n.slice(e.index+e[0].length);let s=[];for(const n of r){const e=t(i+n+o);s=s.concat(e)}return s},shrinkTrim:it,capitalize:ot,decapitalize:st,csvEscape:function(t){return t.match(/"|,/)?`"${t.replace(/"/g,'""')}"`:t},parseCsv:function(t,n=",",e='"'){const r=[];let i="",o=!1;const s=t.split("");for(const t of s)t!==n||o?t!==e||(i||o)&&!o?i+=t:o=!o:(r.push(i),i="");return r.push(i),r},surroundInOut:function(t,n){return n+t.split("").join(n)+n},getExtension:et,getBasename:rt,normalizeEmail:function(t){let[n,e]=t.split("@");n=it(n.replaceAll(".","").toLowerCase()).replaceAll(" ","");const[r]=n.split("+");if(!r||!e||-1===e.indexOf(".")||e.indexOf(".")===e.length-1)throw new Error("Invalid email");return e=it(e.toLowerCase()).replaceAll(" ",""),`${r}@${e}`},normalizeFilename:function(t){const n=rt(t),e=et(t);return e?`${n}.${e}`:n},parseFilename:function(t){const n=rt(t),e=et(t);return{basename:n,extension:e,filename:e?`${n}.${e}`:n}},camelToTitle:function(t){return ot(t.replace(/([A-Z])/g," $1"))},slugToTitle:function(t){return t.split("-").map(ot).join(" ")},slugToCamel:function(t){return st(t.split("-").map(ot).join(""))},joinHumanly:function(t,n=", ",e=" and "){return t&&t.length?1===t.length?t[0]:2===t.length?`${t[0]}${e}${t[1]}`:`${t.slice(0,t.length-1).join(n)}${e}${t[t.length-1]}`:""},findWeightedPair:bt,extractBlock:xt,extractAllBlocks:function(t,n){const e=[];let r=n.wordBoundary?dt(t,[`${n.opening} `,`${n.opening}\n`],n.start||0):t.indexOf(n.opening,n.start||0);for(;;){if(-1===r)return e;const i=xt(t,{...n,start:r});if(!i)return e;e.push(i),r=n.wordBoundary?dt(t,[`${n.opening} `,`${n.opening}\n`],r+i.length):t.indexOf(n.opening,r+i.length)}},replaceBlocks:function(n,e,r){let i=0;for(;;){const o=t.Strings.extractBlock(n,{...r,start:i});if(!o)return n;const s=e(o);i=n.indexOf(o,i)+s.length,n=n.replace(o,s)}},indexOfEarliest:dt,lastIndexOfBefore:wt,parseHtmlAttributes:function(t){const n={},e=t.match(/([a-z\-]+)="([^"]+)"/g);if(e)for(const t of e){const[e,r]=tt(t,"=");n[e]=r.slice(1,r.length-1)}return n},readNextWord:Tt,readWordsAfterAll:function(t,n,e=[]){const r=pt(t,n),i=[];for(const o of r)i.push(Tt(t,o+n.length,e));return i},resolveVariables:function(t,n,e="$",r=":"){for(const i in n)t=Bt(t,i,n[i],e,r);return t=jt(t)},resolveVariableWithDefaultSyntax:Bt,resolveRemainingVariablesWithDefaults:jt,isLetter:ut,isDigit:at,isLetterOrDigit:ct,isValidObjectPathCharacter:function(t){return ct(t)||"."===t||"["===t||"]"===t||"_"===t},insert:function(t,n,e,r,i){return t.slice(0,n)+r+t.slice(n,n+e)+i+t.slice(n+e)},indexOfRegex:ht,allIndexOf:pt,lineMatches:gt,linesMatchInOrder:function(t,n,e=!0){let r=0;for(const i of n){let n=!1;for(;!n&&r<t.length;)gt(t[r],i,e)&&(n=!0),r++;if(!n)return!1}return!0},represent:function t(n,e="json",r=0){if(n&&b(n.represent)){const t=n.represent();if(x(t))return"json"===e&&0===r?JSON.stringify(t):t}if(d(n,!1)){if(r>1)return"[object Object]";if("json"===e){if(Array.isArray(n)){const e=n.map(n=>t(n,"json",r+1));return 0===r?JSON.stringify(e):e}const e={};n.message&&(e.message=t(n.message,"json",r+1));for(const[i,o]of Object.entries(n))e[i]=t(o,"json",r+1);return 0===r?JSON.stringify(e):e}if("key-value"===e){const e=Object.keys(n);return n.message&&!e.includes("message")&&e.unshift("message"),e.map(e=>`${e}=${JSON.stringify(t(n[e],"json",r+1))}`).join(" ")}}return w(n)&&(n="undefined"),0===r?JSON.stringify(n):n},resolveMarkdownLinks:function(t,n){let e=t.indexOf("](");for(;-1!==e;){const r=wt(t,"[",e),i=t.indexOf(")",e);if(-1!==r&&-1!==i){const[e,o]=t.slice(r+1,i).split("]("),s=n(e,o);t=t.slice(0,r)+s+t.slice(i+1)}e=t.indexOf("](",e+1)}return t},buildUrl:function(t,n,e){return Jt([t,n])+Ct(e||{})},isChinese:function(t){return/^[\u4E00-\u9FA5]+$/.test(t)},replaceBetweenStrings:function(t,n,e,r,i=!0){const o=t.indexOf(n),s=t.indexOf(e,o+n.length);if(-1===o||-1===s)throw Error("Start or end not found");return i?t.substring(0,o+n.length)+r+t.substring(s):t.substring(0,o)+r+t.substring(s+e.length)},describeMarkdown:function(t){let n="p";return t.startsWith("#")?(n="h1",t=t.slice(1).trim()):t.startsWith("-")&&(n="li",t=t.slice(1).trim()),{type:n,isCapitalized:t[0]===t[0].toUpperCase(),hasPunctuation:/[.?!]$/.test(t),endsWithColon:/:$/.test(t)}},isBalanced:function(t,n="(",e=")"){let r=0,i=0;for(;i<t.length;)if(t.startsWith(n,i)?(r++,i+=n.length):t.startsWith(e,i)?(r--,i+=e.length):i++,r<0)return!1;return n===e?r%2==0:0===r},textToFormat:function(t){let n=(t=t.normalize("NFD").replace(/[\u0300-\u036f]/g,"")).length;for(;(t=t.replace(/(\w+)[\s,']+\w+/g,"$1")).length!==n;)n=t.length;return t=(t=(t=t.replaceAll(/[A-Z][a-zA-Z0-9]*/g,"A")).replaceAll(/[a-z][a-zA-Z0-9]*/g,"a")).replaceAll(/[\u4E00-\u9FA5]+/g,"Z")},splitFormatting:function(t,n){const e=[];let r=0;for(;r<t.length;){const i=t.indexOf(n,r);if(-1===i){e.push({string:t.slice(r),symbol:null});break}const o=t.indexOf(n,i+n.length);if(i>r&&-1!==o&&e.push({string:t.slice(r,i),symbol:null}),-1===o){e.push({string:t.slice(r),symbol:null});break}e.push({string:t.slice(i+n.length,o),symbol:n}),r=o+n.length}return e},splitHashtags:function(t){const n=[];let e=0;for(;e<t.length;){const r=yt(t,e);if(-1===r){n.push({string:t.slice(e),symbol:null});break}const i=mt(t,r+1);if(-1===i){n.push({string:t.slice(e,r),symbol:null}),n.push({string:t.slice(r+1),symbol:"#"});break}r>e&&n.push({string:t.slice(e,r),symbol:null}),n.push({string:t.slice(r+1,i),symbol:"#"}),e=i}return n},splitUrls:function(t){const n=[];let e=0;for(;e<t.length;){const r=dt(t,["http://","https://"],e);if(-1===r){n.push({string:t.slice(e),symbol:null});break}const i=dt(t,[" ","\n"],r);if(-1===i){r>e&&n.push({string:t.slice(e,r),symbol:null}),n.push({string:t.slice(r),symbol:"http"});break}r>e&&n.push({string:t.slice(e,r),symbol:null}),n.push({string:t.slice(r,i),symbol:"http"}),e=i}return n},route:function(t,n){const e=t.split("/").filter(t=>t),r=n.split("/").filter(t=>t);if(e.length!==r.length)return null;const i={};for(let t=0;t<e.length;t++){const n=e[t];if(n.startsWith(":"))i[n.slice(1)]=r[t];else if(n!==r[t])return null}return i},explodeReplace:At,generateVariants:function(n,e,r,i=Math.random){const o=t.Arrays.shuffle(e.map(n=>({variants:t.Arrays.shuffle(n.variants.map(t=>t),i),avoid:n.avoid})),i),s=[];for(const t of o){const e=t.variants.filter(n=>n!==t.avoid),i=e.find(t=>n.includes(t));if(i&&(K(s,At(n,i,e)),s.length>=r))break}if(s.length<r)for(const t of o){const e=t.variants.find(t=>n.includes(t));if(e&&(K(s,At(n,e,t.variants)),s.length>=r))break}return s.slice(0,r)},replaceWord:function(t,n,e,r=!1){const i=new RegExp(r?`(?<=\\s|^)${n}(?=\\s|$)`:`\\b${n}\\b`,"g");return t.replace(i,e)},replacePascalCaseWords:function(t,n){return t.replace(/\b[A-Z][a-zA-Z0-9]*\b/g,t=>t.toUpperCase()===t?t:n(t))},stripHtml:function(t){return t.replace(/<[^>]*>/g,"")},breakLine:St,measureTextWidth:function(t,n={}){return[...t].reduce((t,e)=>t+(n[e]||1),0)},toLines:function(t,n,e={}){const r=[];let i="",o=0;for(let s=0;s<t.length;s++){const u=t[s];if(i+=u,o+=e[u]||1,o>n){const{line:t,rest:n}=St(i);r.push(t),i=n,o=n.split("").map(t=>e[t]||1).reduce((t,n)=>t+n,0)}}return i&&r.push(i),r},levenshteinDistance:function(t,n){const e=[];for(let n=0;n<=t.length;n++)e[n]=[n];for(let t=0;t<=n.length;t++)e[0][t]=t;for(let r=1;r<=t.length;r++)for(let i=1;i<=n.length;i++){const o=t[r-1]===n[i-1]?0:1;e[r][i]=Math.min(e[r-1][i]+1,e[r][i-1]+1,e[r-1][i-1]+o)}return e[t.length][n.length]},findCommonPrefix:kt,findCommonDirectory:function(t){const n=kt(t),e=n.lastIndexOf("/");return-1===e?"":n.slice(0,e+1)}},t.Assertions={asEqual:function(t,n){if(t!==n)throw Error(`Expected [${t}] to equal [${n}]`);return[t,n]},asTrue:function(t){if(!0!==t)throw Error(`Expected [true], got: [${t}]`);return t},asTruthy:function(t){if(!t)throw Error(`Expected truthy value, got: [${t}]`);return t},asFalse:function(t){if(!1!==t)throw Error(`Expected [false], got: [${t}]`);return t},asFalsy:function(t){if(t)throw Error(`Expected falsy value, got: [${t}]`);return t},asEither:function(t,n){if(!n.includes(t))throw Error(`Expected any of [${n.join(", ")}], got: [${t}]`);return t}},t.Cache={get:async function(t,n,e,r){const i=Date.now(),o=Vt.get(t);if(o&&o.validUntil>i)return o.value;r?.onMiss?.();try{const r=await e();return Vt.set(t,{value:r,validUntil:i+n}),r}catch(t){throw r?.onFailure?.(t),t}},getDeferred:function(t,n,e,r){const i=Date.now(),o=Vt.get(t);if(o&&o.validUntil>i)return o.value;r?.onMiss?.();const s=e();return Vt.set(t,{value:s,validUntil:i+n}),s.catch(n=>{Vt.delete(t),r?.onFailure?.(n)}),s},delete:function(t){Vt.delete(t)},deleteExpired:function(){const t=Date.now();for(const[n,e]of Vt.entries())e.validUntil<=t&&Vt.delete(n)},size:function(){return Vt.size},clear:function(){Vt.clear()}},t.Vector={addPoint:Xn,subtractPoint:function(t,n){return{x:t.x-n.x,y:t.y-n.y}},multiplyPoint:Yn,normalizePoint:function(t){const n=Math.sqrt(t.x*t.x+t.y*t.y);return{x:t.x/n,y:t.y/n}},pushPoint:te,filterCoordinates:ee,findCorners:function(t,n,e,r){const i=[{x:0,y:0},{x:e,y:0},{x:0,y:r},{x:e,y:r}];for(let n=0;n<t.length;n++)for(let e=0;e<t[0].length;e++){const r=ue(t,n,e);for(const t of r)i.some(n=>n.x===t.x&&n.y===t.y)||i.push(t)}return i.map(t=>({x:t.x*n,y:t.y*n}))},findLines:function(t,n){const e=ee(t,(n,e)=>0===t[n][e]&&0!==t[n][e+1],"row-first").map(t=>({...t,dx:1,dy:0})),r=ee(t,(n,e)=>0===t[n][e]&&0!==t[n][e-1],"row-first").map(t=>({...t,dx:1,dy:0})),i=ee(t,(n,e)=>0===t[n][e]&&0!==t[n-1]?.[e],"column-first").map(t=>({...t,dx:0,dy:1})),o=ee(t,(n,e)=>0===t[n][e]&&0!==t[n+1]?.[e],"column-first").map(t=>({...t,dx:0,dy:1}));return e.forEach(t=>t.y++),o.forEach(t=>t.x++),[...fn([...i,...o],(t,n)=>t.x===n.x&&t.y-1===n.y),...fn([...r,...e],(t,n)=>t.y===n.y&&t.x-1===n.x)].map(t=>({start:t[0],end:l(t)})).map(t=>({start:Yn(t.start,n),end:Yn(Xn(t.end,{x:t.start.dx,y:t.start.dy}),n)}))},raycast:le,raycastCircle:function(t,n,e){const r=ae(t,e),i=[];for(const e of r){const r=le(t,n,e-.001),o=le(t,n,e+.001);r&&i.push(r),o&&i.push(o)}return i},getLineIntersectionPoint:ce}}(n)),n);const r=(new TextEncoder).encode("Ethereum Signed Message:\n32");let i,o;const s=self;s.onmessage=t=>{s.postMessage(function(t){if("init"===t.type){const n=e.Binary.hexToUint8Array(t.signerKeyHex);i=e.Binary.uint256ToNumber(n,"BE");const[r,s]=e.Elliptic.privateKeyToPublicKey(i),u=e.Binary.concatBytes(e.Binary.numberToUint256(r,"BE"),e.Binary.numberToUint256(s,"BE")),[a,c]=[e.Binary.uint256ToNumber(u.slice(0,32),"BE"),e.Binary.uint256ToNumber(u.slice(32,64),"BE")];return o=e.Elliptic.publicKeyToAddress([a,c]),{type:"ready",issuerHex:e.Binary.uint8ArrayToHex(o)}}const n=e.Binary.concatBytes(r,e.Binary.keccak256(t.message)),[s,u,a]=e.Elliptic.signMessage(n,i),c=e.Binary.concatBytes(e.Binary.numberToUint256(s,"BE"),e.Binary.numberToUint256(u,"BE"),new Uint8Array([Number(a)]));return{type:"signed",id:t.id,signatureHex:e.Binary.uint8ArrayToHex(c)}}(t.data))}}();
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debounced Utilization Uploader
|
|
3
|
+
*
|
|
4
|
+
* Batches multiple utilization updates together to minimize upload frequency.
|
|
5
|
+
* Uses a per-batch debounce mechanism with configurable delay.
|
|
6
|
+
*/
|
|
7
|
+
import type { DirtyChunkTracker } from "../utils/batch-utilization";
|
|
8
|
+
/**
|
|
9
|
+
* Debounced uploader for batch utilization data
|
|
10
|
+
*
|
|
11
|
+
* Batches multiple updates within a time window and uploads only once.
|
|
12
|
+
* Each batch has its own independent debounce timer.
|
|
13
|
+
*/
|
|
14
|
+
export declare class DebouncedUtilizationUploader {
|
|
15
|
+
private pendingUploads;
|
|
16
|
+
private defaultDelay;
|
|
17
|
+
/**
|
|
18
|
+
* Create a new debounced uploader
|
|
19
|
+
* @param delay - Debounce delay in milliseconds (default: 1000ms = 1s)
|
|
20
|
+
*/
|
|
21
|
+
constructor(delay?: number);
|
|
22
|
+
/**
|
|
23
|
+
* Schedule an upload for a batch (debounced)
|
|
24
|
+
*
|
|
25
|
+
* If multiple updates occur within the debounce window, they are merged
|
|
26
|
+
* and only one upload is performed.
|
|
27
|
+
*
|
|
28
|
+
* @param batchId - Batch ID (hex string)
|
|
29
|
+
* @param tracker - Dirty chunk tracker with current changes
|
|
30
|
+
* @param uploadFn - Function to execute upload
|
|
31
|
+
* @param delay - Optional custom delay for this upload
|
|
32
|
+
* @returns Promise that resolves when upload completes
|
|
33
|
+
*/
|
|
34
|
+
scheduleUpload(batchId: string, tracker: DirtyChunkTracker, uploadFn: () => Promise<void>, delay?: number): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Flush pending upload for a batch immediately (cancel debounce)
|
|
37
|
+
* @param batchId - Batch ID to flush
|
|
38
|
+
*/
|
|
39
|
+
flush(batchId: string): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Flush all pending uploads immediately
|
|
42
|
+
*/
|
|
43
|
+
flushAll(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Cancel pending upload for a batch (discard changes)
|
|
46
|
+
* @param batchId - Batch ID to cancel
|
|
47
|
+
*/
|
|
48
|
+
cancel(batchId: string): void;
|
|
49
|
+
/**
|
|
50
|
+
* Cancel all pending uploads (discard all changes)
|
|
51
|
+
*/
|
|
52
|
+
cancelAll(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Get count of pending uploads
|
|
55
|
+
*/
|
|
56
|
+
getPendingCount(): number;
|
|
57
|
+
/**
|
|
58
|
+
* Check if a batch has a pending upload
|
|
59
|
+
*/
|
|
60
|
+
hasPending(batchId: string): boolean;
|
|
61
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IndexedDB Cache for Batch Utilization Chunks
|
|
3
|
+
*
|
|
4
|
+
* Provides fast local caching of 4KB utilization chunks to avoid
|
|
5
|
+
* repeated Swarm downloads. Each chunk is 4096 bytes containing either
|
|
6
|
+
* 2048 uint16 or 1024 uint32 bucket counters, depending on batch depth.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Cache entry for a single utilization chunk
|
|
10
|
+
*/
|
|
11
|
+
export interface ChunkCacheEntry {
|
|
12
|
+
/** Batch ID (hex string) */
|
|
13
|
+
batchId: string;
|
|
14
|
+
/** Chunk index within the depth-dependent layout */
|
|
15
|
+
chunkIndex: number;
|
|
16
|
+
/** Serialized chunk data (4KB) */
|
|
17
|
+
data: Uint8Array;
|
|
18
|
+
/** Content hash for change detection */
|
|
19
|
+
contentHash: string;
|
|
20
|
+
/** SOC reference if uploaded to Swarm */
|
|
21
|
+
socReference?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Per-chunk-index encryption nonce that was used to derive this chunk's
|
|
24
|
+
* encryption key. Lets a re-save start its bucket-collision search from
|
|
25
|
+
* the previously-chosen value, so unchanged plaintexts keep the same
|
|
26
|
+
* derived key (and therefore the same `contentHash`) across saves.
|
|
27
|
+
*
|
|
28
|
+
* Required: every row is written by a bundle that sets it, and an upgrade
|
|
29
|
+
* drops the stores rather than carrying rows forward (#662).
|
|
30
|
+
*/
|
|
31
|
+
nonce: number;
|
|
32
|
+
/** Last access timestamp (for eviction) */
|
|
33
|
+
lastAccess: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Metadata for a batch's utilization state
|
|
37
|
+
*/
|
|
38
|
+
export interface BatchMetadata {
|
|
39
|
+
batchId: string;
|
|
40
|
+
lastSync: number;
|
|
41
|
+
chunkCount: number;
|
|
42
|
+
/**
|
|
43
|
+
* Per-partition "synced reference": the partition-state feed reference
|
|
44
|
+
* (hex) this device's local counter was last in sync with. On a cold
|
|
45
|
+
* acquire, if the feed still points here the counter-chunk download is
|
|
46
|
+
* skipped and the local counter reused. Keyed by partition index.
|
|
47
|
+
*/
|
|
48
|
+
syncedReferences?: Record<number, string>;
|
|
49
|
+
/**
|
|
50
|
+
* Per-partition buckets occupied by the LATEST published partition-state
|
|
51
|
+
* chunks (counter chunks + reference chunk). Those chunks overstamp the
|
|
52
|
+
* partition's reserved slot in their buckets, so utilization saves must
|
|
53
|
+
* avoid placing chunks there — a collision would evict the published
|
|
54
|
+
* state from the reserve (Bee replaces the older chunk at a colliding
|
|
55
|
+
* stamp index), and a later takeover would fail to read its resume point.
|
|
56
|
+
* Keyed by partition index; replaced wholesale on every publish/read.
|
|
57
|
+
*/
|
|
58
|
+
stateChunkBuckets?: Record<number, number[]>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Manages IndexedDB cache for batch utilization chunks
|
|
62
|
+
*/
|
|
63
|
+
export declare class UtilizationStoreDB {
|
|
64
|
+
private db;
|
|
65
|
+
/**
|
|
66
|
+
* Open the IndexedDB database
|
|
67
|
+
*/
|
|
68
|
+
open(): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Get a chunk from cache
|
|
71
|
+
* @param batchId - Batch ID (hex string)
|
|
72
|
+
* @param chunkIndex - Chunk index
|
|
73
|
+
* @returns Cache entry or undefined if not found
|
|
74
|
+
*/
|
|
75
|
+
getChunk(batchId: string, chunkIndex: number): Promise<ChunkCacheEntry | undefined>;
|
|
76
|
+
/**
|
|
77
|
+
* Store a chunk in cache
|
|
78
|
+
* @param entry - Cache entry to store
|
|
79
|
+
*/
|
|
80
|
+
putChunk(entry: ChunkCacheEntry): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Get all chunks for a batch
|
|
83
|
+
* @param batchId - Batch ID (hex string)
|
|
84
|
+
* @returns Array of cache entries (sorted by chunkIndex)
|
|
85
|
+
*/
|
|
86
|
+
getAllChunks(batchId: string): Promise<ChunkCacheEntry[]>;
|
|
87
|
+
/**
|
|
88
|
+
* Clear all chunks for a batch
|
|
89
|
+
* @param batchId - Batch ID (hex string)
|
|
90
|
+
*/
|
|
91
|
+
clearBatch(batchId: string): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Update lastAccess timestamp for a chunk
|
|
94
|
+
* @param batchId - Batch ID (hex string)
|
|
95
|
+
* @param chunkIndex - Chunk index
|
|
96
|
+
*/
|
|
97
|
+
private touchChunk;
|
|
98
|
+
/**
|
|
99
|
+
* Get batch metadata
|
|
100
|
+
* @param batchId - Batch ID (hex string)
|
|
101
|
+
* @returns Metadata or undefined if not found
|
|
102
|
+
*/
|
|
103
|
+
getMetadata(batchId: string): Promise<BatchMetadata | undefined>;
|
|
104
|
+
/**
|
|
105
|
+
* Update batch metadata
|
|
106
|
+
* @param metadata - Metadata to store
|
|
107
|
+
*/
|
|
108
|
+
putMetadata(metadata: BatchMetadata): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Close the database connection
|
|
111
|
+
*/
|
|
112
|
+
close(): void;
|
|
113
|
+
}
|