@snaha/swarm-id 0.0.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/README.md +431 -0
- package/dist/chunk/bmt.d.ts +17 -0
- package/dist/chunk/bmt.d.ts.map +1 -0
- package/dist/chunk/cac.d.ts +18 -0
- package/dist/chunk/cac.d.ts.map +1 -0
- package/dist/chunk/constants.d.ts +10 -0
- package/dist/chunk/constants.d.ts.map +1 -0
- package/dist/chunk/encrypted-cac.d.ts +48 -0
- package/dist/chunk/encrypted-cac.d.ts.map +1 -0
- package/dist/chunk/encryption.d.ts +86 -0
- package/dist/chunk/encryption.d.ts.map +1 -0
- package/dist/chunk/index.d.ts +6 -0
- package/dist/chunk/index.d.ts.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/proxy/act/act.d.ts +78 -0
- package/dist/proxy/act/act.d.ts.map +1 -0
- package/dist/proxy/act/crypto.d.ts +44 -0
- package/dist/proxy/act/crypto.d.ts.map +1 -0
- package/dist/proxy/act/grantee-list.d.ts +82 -0
- package/dist/proxy/act/grantee-list.d.ts.map +1 -0
- package/dist/proxy/act/history.d.ts +183 -0
- package/dist/proxy/act/history.d.ts.map +1 -0
- package/dist/proxy/act/index.d.ts +104 -0
- package/dist/proxy/act/index.d.ts.map +1 -0
- package/dist/proxy/chunking-encrypted.d.ts +14 -0
- package/dist/proxy/chunking-encrypted.d.ts.map +1 -0
- package/dist/proxy/chunking.d.ts +15 -0
- package/dist/proxy/chunking.d.ts.map +1 -0
- package/dist/proxy/download-data.d.ts +16 -0
- package/dist/proxy/download-data.d.ts.map +1 -0
- package/dist/proxy/feed-manifest.d.ts +62 -0
- package/dist/proxy/feed-manifest.d.ts.map +1 -0
- package/dist/proxy/feeds/epochs/async-finder.d.ts +77 -0
- package/dist/proxy/feeds/epochs/async-finder.d.ts.map +1 -0
- package/dist/proxy/feeds/epochs/epoch.d.ts +88 -0
- package/dist/proxy/feeds/epochs/epoch.d.ts.map +1 -0
- package/dist/proxy/feeds/epochs/finder.d.ts +67 -0
- package/dist/proxy/feeds/epochs/finder.d.ts.map +1 -0
- package/dist/proxy/feeds/epochs/index.d.ts +35 -0
- package/dist/proxy/feeds/epochs/index.d.ts.map +1 -0
- package/dist/proxy/feeds/epochs/test-utils.d.ts +93 -0
- package/dist/proxy/feeds/epochs/test-utils.d.ts.map +1 -0
- package/dist/proxy/feeds/epochs/types.d.ts +109 -0
- package/dist/proxy/feeds/epochs/types.d.ts.map +1 -0
- package/dist/proxy/feeds/epochs/updater.d.ts +68 -0
- package/dist/proxy/feeds/epochs/updater.d.ts.map +1 -0
- package/dist/proxy/feeds/epochs/utils.d.ts +22 -0
- package/dist/proxy/feeds/epochs/utils.d.ts.map +1 -0
- package/dist/proxy/feeds/index.d.ts +5 -0
- package/dist/proxy/feeds/index.d.ts.map +1 -0
- package/dist/proxy/feeds/sequence/async-finder.d.ts +14 -0
- package/dist/proxy/feeds/sequence/async-finder.d.ts.map +1 -0
- package/dist/proxy/feeds/sequence/finder.d.ts +17 -0
- package/dist/proxy/feeds/sequence/finder.d.ts.map +1 -0
- package/dist/proxy/feeds/sequence/index.d.ts +23 -0
- package/dist/proxy/feeds/sequence/index.d.ts.map +1 -0
- package/dist/proxy/feeds/sequence/types.d.ts +80 -0
- package/dist/proxy/feeds/sequence/types.d.ts.map +1 -0
- package/dist/proxy/feeds/sequence/updater.d.ts +26 -0
- package/dist/proxy/feeds/sequence/updater.d.ts.map +1 -0
- package/dist/proxy/index.d.ts +6 -0
- package/dist/proxy/index.d.ts.map +1 -0
- package/dist/proxy/manifest-builder.d.ts +183 -0
- package/dist/proxy/manifest-builder.d.ts.map +1 -0
- package/dist/proxy/mantaray-encrypted.d.ts +27 -0
- package/dist/proxy/mantaray-encrypted.d.ts.map +1 -0
- package/dist/proxy/mantaray.d.ts +26 -0
- package/dist/proxy/mantaray.d.ts.map +1 -0
- package/dist/proxy/types.d.ts +29 -0
- package/dist/proxy/types.d.ts.map +1 -0
- package/dist/proxy/upload-data.d.ts +17 -0
- package/dist/proxy/upload-data.d.ts.map +1 -0
- package/dist/proxy/upload-encrypted-data.d.ts +103 -0
- package/dist/proxy/upload-encrypted-data.d.ts.map +1 -0
- package/dist/schemas.d.ts +240 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/storage/debounced-uploader.d.ts +62 -0
- package/dist/storage/debounced-uploader.d.ts.map +1 -0
- package/dist/storage/utilization-store.d.ts +108 -0
- package/dist/storage/utilization-store.d.ts.map +1 -0
- package/dist/swarm-id-auth.d.ts +74 -0
- package/dist/swarm-id-auth.d.ts.map +1 -0
- package/dist/swarm-id-auth.js +2 -0
- package/dist/swarm-id-auth.js.map +1 -0
- package/dist/swarm-id-client.d.ts +878 -0
- package/dist/swarm-id-client.d.ts.map +1 -0
- package/dist/swarm-id-client.js +2 -0
- package/dist/swarm-id-client.js.map +1 -0
- package/dist/swarm-id-proxy.d.ts +236 -0
- package/dist/swarm-id-proxy.d.ts.map +1 -0
- package/dist/swarm-id-proxy.js +2 -0
- package/dist/swarm-id-proxy.js.map +1 -0
- package/dist/swarm-id.esm.js +2 -0
- package/dist/swarm-id.esm.js.map +1 -0
- package/dist/swarm-id.umd.js +2 -0
- package/dist/swarm-id.umd.js.map +1 -0
- package/dist/sync/index.d.ts +9 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/key-derivation.d.ts +25 -0
- package/dist/sync/key-derivation.d.ts.map +1 -0
- package/dist/sync/restore-account.d.ts +28 -0
- package/dist/sync/restore-account.d.ts.map +1 -0
- package/dist/sync/serialization.d.ts +16 -0
- package/dist/sync/serialization.d.ts.map +1 -0
- package/dist/sync/store-interfaces.d.ts +53 -0
- package/dist/sync/store-interfaces.d.ts.map +1 -0
- package/dist/sync/sync-account.d.ts +44 -0
- package/dist/sync/sync-account.d.ts.map +1 -0
- package/dist/sync/types.d.ts +13 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/test-fixtures.d.ts +17 -0
- package/dist/test-fixtures.d.ts.map +1 -0
- package/dist/types-BD_VkNn0.js +2 -0
- package/dist/types-BD_VkNn0.js.map +1 -0
- package/dist/types-lJCaT-50.js +2 -0
- package/dist/types-lJCaT-50.js.map +1 -0
- package/dist/types.d.ts +2157 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/account-payload.d.ts +94 -0
- package/dist/utils/account-payload.d.ts.map +1 -0
- package/dist/utils/account-state-snapshot.d.ts +38 -0
- package/dist/utils/account-state-snapshot.d.ts.map +1 -0
- package/dist/utils/backup-encryption.d.ts +127 -0
- package/dist/utils/backup-encryption.d.ts.map +1 -0
- package/dist/utils/batch-utilization.d.ts +432 -0
- package/dist/utils/batch-utilization.d.ts.map +1 -0
- package/dist/utils/constants.d.ts +11 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/hex.d.ts +17 -0
- package/dist/utils/hex.d.ts.map +1 -0
- package/dist/utils/key-derivation.d.ts +92 -0
- package/dist/utils/key-derivation.d.ts.map +1 -0
- package/dist/utils/storage-managers.d.ts +65 -0
- package/dist/utils/storage-managers.d.ts.map +1 -0
- package/dist/utils/swarm-id-export.d.ts +24 -0
- package/dist/utils/swarm-id-export.d.ts.map +1 -0
- package/dist/utils/ttl.d.ts +49 -0
- package/dist/utils/ttl.d.ts.map +1 -0
- package/dist/utils/url.d.ts +41 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/dist/utils/versioned-storage.d.ts +131 -0
- package/dist/utils/versioned-storage.d.ts.map +1 -0
- package/package.json +78 -0
- package/src/chunk/bmt.test.ts +217 -0
- package/src/chunk/bmt.ts +57 -0
- package/src/chunk/cac.test.ts +214 -0
- package/src/chunk/cac.ts +65 -0
- package/src/chunk/constants.ts +18 -0
- package/src/chunk/encrypted-cac.test.ts +385 -0
- package/src/chunk/encrypted-cac.ts +131 -0
- package/src/chunk/encryption.test.ts +352 -0
- package/src/chunk/encryption.ts +300 -0
- package/src/chunk/index.ts +47 -0
- package/src/index.ts +430 -0
- package/src/proxy/act/act.test.ts +278 -0
- package/src/proxy/act/act.ts +158 -0
- package/src/proxy/act/bee-compat.test.ts +948 -0
- package/src/proxy/act/crypto.test.ts +436 -0
- package/src/proxy/act/crypto.ts +376 -0
- package/src/proxy/act/grantee-list.test.ts +393 -0
- package/src/proxy/act/grantee-list.ts +239 -0
- package/src/proxy/act/history.test.ts +360 -0
- package/src/proxy/act/history.ts +413 -0
- package/src/proxy/act/index.test.ts +748 -0
- package/src/proxy/act/index.ts +853 -0
- package/src/proxy/chunking-encrypted.ts +95 -0
- package/src/proxy/chunking.ts +65 -0
- package/src/proxy/download-data.ts +448 -0
- package/src/proxy/feed-manifest.ts +174 -0
- package/src/proxy/feeds/epochs/async-finder.ts +372 -0
- package/src/proxy/feeds/epochs/epoch.test.ts +249 -0
- package/src/proxy/feeds/epochs/epoch.ts +181 -0
- package/src/proxy/feeds/epochs/finder.ts +282 -0
- package/src/proxy/feeds/epochs/index.ts +73 -0
- package/src/proxy/feeds/epochs/integration.test.ts +1336 -0
- package/src/proxy/feeds/epochs/test-utils.ts +274 -0
- package/src/proxy/feeds/epochs/types.ts +128 -0
- package/src/proxy/feeds/epochs/updater.ts +192 -0
- package/src/proxy/feeds/epochs/utils.ts +62 -0
- package/src/proxy/feeds/index.ts +5 -0
- package/src/proxy/feeds/sequence/async-finder.ts +31 -0
- package/src/proxy/feeds/sequence/finder.ts +73 -0
- package/src/proxy/feeds/sequence/index.ts +54 -0
- package/src/proxy/feeds/sequence/integration.test.ts +966 -0
- package/src/proxy/feeds/sequence/types.ts +103 -0
- package/src/proxy/feeds/sequence/updater.ts +71 -0
- package/src/proxy/index.ts +5 -0
- package/src/proxy/manifest-builder.test.ts +427 -0
- package/src/proxy/manifest-builder.ts +679 -0
- package/src/proxy/mantaray-encrypted.ts +78 -0
- package/src/proxy/mantaray.ts +104 -0
- package/src/proxy/types.ts +32 -0
- package/src/proxy/upload-data.ts +189 -0
- package/src/proxy/upload-encrypted-data.ts +658 -0
- package/src/schemas.ts +299 -0
- package/src/storage/debounced-uploader.ts +192 -0
- package/src/storage/utilization-store.ts +397 -0
- package/src/swarm-id-client.test.ts +99 -0
- package/src/swarm-id-client.ts +3095 -0
- package/src/swarm-id-proxy.ts +3891 -0
- package/src/sync/index.ts +28 -0
- package/src/sync/restore-account.ts +90 -0
- package/src/sync/serialization.ts +39 -0
- package/src/sync/store-interfaces.ts +62 -0
- package/src/sync/sync-account.test.ts +302 -0
- package/src/sync/sync-account.ts +396 -0
- package/src/sync/types.ts +11 -0
- package/src/test-fixtures.ts +109 -0
- package/src/types.ts +1651 -0
- package/src/utils/account-state-snapshot.test.ts +595 -0
- package/src/utils/account-state-snapshot.ts +94 -0
- package/src/utils/backup-encryption.test.ts +442 -0
- package/src/utils/backup-encryption.ts +352 -0
- package/src/utils/batch-utilization.ts +1309 -0
- package/src/utils/constants.ts +20 -0
- package/src/utils/hex.ts +27 -0
- package/src/utils/key-derivation.ts +197 -0
- package/src/utils/storage-managers.ts +365 -0
- package/src/utils/ttl.ts +129 -0
- package/src/utils/url.test.ts +136 -0
- package/src/utils/url.ts +71 -0
- package/src/utils/versioned-storage.ts +323 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).SwarmId={})}(this,function(e){"use strict";function t(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,"_zod",{value:{def:r,constr:a,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);const i=a.prototype,o=Object.keys(i);for(let e=0;e<o.length;e++){const t=o[e];t in n||(n[t]=i[t].bind(n))}}const i=n?.Parent??Object;class o extends i{}function a(e){var t;const i=n?.Parent?new o:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(const e of i._zod.deferred)e();return i}return Object.defineProperty(o,"name",{value:e}),Object.defineProperty(a,"init",{value:r}),Object.defineProperty(a,Symbol.hasInstance,{value:t=>!!(n?.Parent&&t instanceof n.Parent)||t?._zod?.traits?.has(e)}),Object.defineProperty(a,"name",{value:e}),a}class n extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class r extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const i={};function o(e){return i}function a(e,t){return"bigint"==typeof t?t.toString():t}function s(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function c(e){return null==e}function u(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}const l=Symbol("evaluating");function h(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==l)return void 0===r&&(r=l,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function f(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function d(...e){const t={};for(const n of e){const e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function p(e){return JSON.stringify(e)}const m="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function g(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}const y=s(()=>{if("undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function w(e){if(!1===g(e))return!1;const t=e.constructor;if(void 0===t)return!0;if("function"!=typeof t)return!0;const n=t.prototype;return!1!==g(n)&&!1!==Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")}function b(e){return w(e)?{...e}:Array.isArray(e)?[...e]:e}const v=new Set(["string","number","symbol"]);function E(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function x(e,t,n){const r=new e._zod.constr(t??e._zod.def);return t&&!n?.parent||(r._zod.parent=e),r}function B(e){const t=e;if(!t)return{};if("string"==typeof t)return{error:()=>t};if(void 0!==t?.message){if(void 0!==t?.error)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,"string"==typeof t.error?{...t,error:()=>t.error}:t}const T={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function A(e,t=0){if(!0===e.aborted)return!0;for(let n=t;n<e.issues.length;n++)if(!0!==e.issues[n]?.continue)return!0;return!1}function O(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function R(e){return"string"==typeof e?e:e?.message}function S(e,t,n){const r={...e,path:e.path??[]};if(!e.message){const i=R(e.inst?._zod.def?.error?.(e))??R(t?.error?.(e))??R(n.customError?.(e))??R(n.localeError?.(e))??"Invalid input";r.message=i}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function k(e){return Array.isArray(e)?"array":"string"==typeof e?"string":"unknown"}function $(...e){const[t,n,r]=e;return"string"==typeof t?{message:t,code:"custom",input:n,inst:r}:{...t}}const I=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,a,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},z=t("$ZodError",I),D=t("$ZodError",I,{Parent:Error});const C=e=>(t,r,i,a)=>{const s=i?Object.assign(i,{async:!1}):{async:!1},c=t._zod.run({value:r,issues:[]},s);if(c instanceof Promise)throw new n;if(c.issues.length){const t=new(a?.Err??e)(c.issues.map(e=>S(e,s,o())));throw m(t,a?.callee),t}return c.value},P=e=>async(t,n,r,i)=>{const a=r?Object.assign(r,{async:!0}):{async:!0};let s=t._zod.run({value:n,issues:[]},a);if(s instanceof Promise&&(s=await s),s.issues.length){const t=new(i?.Err??e)(s.issues.map(e=>S(e,a,o())));throw m(t,i?.callee),t}return s.value},N=e=>(t,r,i)=>{const a=i?{...i,async:!1}:{async:!1},s=t._zod.run({value:r,issues:[]},a);if(s instanceof Promise)throw new n;return s.issues.length?{success:!1,error:new(e??z)(s.issues.map(e=>S(e,a,o())))}:{success:!0,data:s.value}},U=N(D),_=e=>async(t,n,r)=>{const i=r?Object.assign(r,{async:!0}):{async:!0};let a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>S(e,i,o())))}:{success:!0,data:a.value}},V=_(D),F=e=>(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return C(e)(t,n,i)},M=e=>(t,n,r)=>C(e)(t,n,r),j=e=>async(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return P(e)(t,n,i)},L=e=>async(t,n,r)=>P(e)(t,n,r),q=e=>(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return N(e)(t,n,i)},G=e=>(t,n,r)=>N(e)(t,n,r),H=e=>async(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return _(e)(t,n,i)},Z=e=>async(t,n,r)=>_(e)(t,n,r),W=/^[cC][^\s-]{8,}$/,K=/^[0-9a-z]+$/,J=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,X=/^[0-9a-vA-V]{20}$/,Y=/^[A-Za-z0-9]{27}$/,Q=/^[a-zA-Z0-9_-]{21}$/,ee=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,te=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,ne=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,re=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;const ie=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,oe=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,ae=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,se=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,ce=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,ue=/^[A-Za-z0-9_-]*$/,le=/^\+(?:[0-9]){6,14}[0-9]$/,he="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",fe=new RegExp(`^${he}$`);function de(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof e.precision?-1===e.precision?`${t}`:0===e.precision?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}const pe=/^-?\d+$/,me=/^-?\d+(?:\.\d+)?/,ge=/^(?:true|false)$/i,ye=/^[^A-Z]*$/,we=/^[^a-z]*$/,be=t("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),ve={number:"number",bigint:"bigint",object:"date"},Ee=t("$ZodCheckLessThan",(e,t)=>{be.init(e,t);const n=ve[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),xe=t("$ZodCheckGreaterThan",(e,t)=>{be.init(e,t);const n=ve[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Be=t("$ZodCheckMultipleOf",(e,t)=>{be.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof n.value?n.value%t.value===BigInt(0):0===function(e,t){const n=(e.toString().split(".")[1]||"").length,r=t.toString();let i=(r.split(".")[1]||"").length;if(0===i&&/\d?e-\d?/.test(r)){const e=r.match(/\d?e-(\d?)/);e?.[1]&&(i=Number.parseInt(e[1]))}const o=n>i?n:i;return Number.parseInt(e.toFixed(o).replace(".",""))%Number.parseInt(t.toFixed(o).replace(".",""))/10**o}(n.value,t.value))||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Te=t("$ZodCheckNumberFormat",(e,t)=>{be.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[i,o]=T[t.format];e._zod.onattach.push(e=>{const r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=o,n&&(r.pattern=pe)}),e._zod.check=a=>{const s=a.value;if(n){if(!Number.isInteger(s))return void a.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:s,inst:e});if(!Number.isSafeInteger(s))return void(s>0?a.issues.push({input:s,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort}):a.issues.push({input:s,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort}))}s<i&&a.issues.push({origin:"number",input:s,code:"too_small",minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>o&&a.issues.push({origin:"number",input:s,code:"too_big",maximum:o,inst:e})}}),Ae=t("$ZodCheckMaxLength",(e,t)=>{var n;be.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!c(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{const r=n.value;if(r.length<=t.maximum)return;const i=k(r);n.issues.push({origin:i,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Oe=t("$ZodCheckMinLength",(e,t)=>{var n;be.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!c(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{const r=n.value;if(r.length>=t.minimum)return;const i=k(r);n.issues.push({origin:i,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Re=t("$ZodCheckLengthEquals",(e,t)=>{var n;be.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!c(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{const r=n.value,i=r.length;if(i===t.length)return;const o=k(r),a=i>t.length;n.issues.push({origin:o,...a?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),Se=t("$ZodCheckStringFormat",(e,t)=>{var n,r;be.init(e,t),e._zod.onattach.push(e=>{const n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??(n.patterns=new Set),n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,t.pattern.test(n.value)||n.issues.push({origin:"string",code:"invalid_format",format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),ke=t("$ZodCheckRegex",(e,t)=>{Se.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,t.pattern.test(n.value)||n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),$e=t("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=ye),Se.init(e,t)}),Ie=t("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=we),Se.init(e,t)}),ze=t("$ZodCheckIncludes",(e,t)=>{be.init(e,t);const n=E(t.includes),r=new RegExp("number"==typeof t.position?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),De=t("$ZodCheckStartsWith",(e,t)=>{be.init(e,t);const n=new RegExp(`^${E(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Ce=t("$ZodCheckEndsWith",(e,t)=>{be.init(e,t);const n=new RegExp(`.*${E(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),Pe=t("$ZodCheckOverwrite",(e,t)=>{be.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});class Ne{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if("function"==typeof e)return e(this,{execution:"sync"}),void e(this,{execution:"async"});const t=e.split("\n").filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>" ".repeat(2*this.indent)+e);for(const e of r)this.content.push(e)}compile(){const e=Function,t=this?.args;return new e(...t,[...(this?.content??[""]).map(e=>` ${e}`)].join("\n"))}}const Ue={major:4,minor:1,patch:13},_e=t("$ZodType",(e,t)=>{var r;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Ue;const i=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&i.unshift(e);for(const t of i)for(const n of t._zod.onattach)n(e);if(0===i.length)(r=e._zod).deferred??(r.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const t=(e,t,r)=>{let i,o=A(e);for(const a of t){if(a._zod.def.when){if(!a._zod.def.when(e))continue}else if(o)continue;const t=e.issues.length,s=a._zod.check(e);if(s instanceof Promise&&!1===r?.async)throw new n;if(i||s instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await s;e.issues.length!==t&&(o||(o=A(e,t)))});else{if(e.issues.length===t)continue;o||(o=A(e,t))}}return i?i.then(()=>e):e},r=(r,o,a)=>{if(A(r))return r.aborted=!0,r;const s=t(o,i,a);if(s instanceof Promise){if(!1===a.async)throw new n;return s.then(t=>e._zod.parse(t,a))}return e._zod.parse(s,a)};e._zod.run=(o,a)=>{if(a.skipChecks)return e._zod.parse(o,a);if("backward"===a.direction){const t=e._zod.parse({value:o.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>r(e,o,a)):r(t,o,a)}const s=e._zod.parse(o,a);if(s instanceof Promise){if(!1===a.async)throw new n;return s.then(e=>t(e,i,a))}return t(s,i,a)}}e["~standard"]={validate:t=>{try{const n=U(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch(n){return V(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:"zod",version:1}}),Ve=t("$ZodString",(e,t)=>{var n;_e.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??(n=e._zod.bag,new RegExp(`^${n?`[\\s\\S]{${n?.minimum??0},${n?.maximum??""}}`:"[\\s\\S]*"}$`)),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch(r){}return"string"==typeof n.value||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),Fe=t("$ZodStringFormat",(e,t)=>{Se.init(e,t),Ve.init(e,t)}),Me=t("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=te),Fe.init(e,t)}),je=t("$ZodUUID",(e,t)=>{if(t.version){const e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(void 0===e)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=ne(e))}else t.pattern??(t.pattern=ne());Fe.init(e,t)}),Le=t("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=re),Fe.init(e,t)}),qe=t("$ZodURL",(e,t)=>{Fe.init(e,t),e._zod.check=n=>{try{const r=n.value.trim(),i=new URL(r);return t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(":")?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),void(t.normalize?n.value=i.href:n.value=r)}catch(r){n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),Ge=t("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),Fe.init(e,t)}),He=t("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=Q),Fe.init(e,t)}),Ze=t("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=W),Fe.init(e,t)}),We=t("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=K),Fe.init(e,t)}),Ke=t("$ZodULID",(e,t)=>{t.pattern??(t.pattern=J),Fe.init(e,t)}),Je=t("$ZodXID",(e,t)=>{t.pattern??(t.pattern=X),Fe.init(e,t)}),Xe=t("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=Y),Fe.init(e,t)}),Ye=t("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=function(e){const t=de({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${t}(?:${n.join("|")})`;return new RegExp(`^${he}T(?:${r})$`)}(t)),Fe.init(e,t)}),Qe=t("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=fe),Fe.init(e,t)}),et=t("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=new RegExp(`^${de(t)}$`)),Fe.init(e,t)}),tt=t("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=ee),Fe.init(e,t)}),nt=t("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=ie),Fe.init(e,t),e._zod.bag.format="ipv4"}),rt=t("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=oe),Fe.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),it=t("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=ae),Fe.init(e,t)}),ot=t("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=se),Fe.init(e,t),e._zod.check=n=>{const r=n.value.split("/");try{if(2!==r.length)throw new Error;const[e,t]=r;if(!t)throw new Error;const n=Number(t);if(`${n}`!==t)throw new Error;if(n<0||n>128)throw new Error;new URL(`http://[${e}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function at(e){if(""===e)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const st=t("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=ce),Fe.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{at(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});const ct=t("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=ue),Fe.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{(function(e){if(!ue.test(e))return!1;const t=e.replace(/[-_]/g,e=>"-"===e?"+":"/");return at(t.padEnd(4*Math.ceil(t.length/4),"="))})(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),ut=t("$ZodE164",(e,t)=>{t.pattern??(t.pattern=le),Fe.init(e,t)});const lt=t("$ZodJWT",(e,t)=>{Fe.init(e,t),e._zod.check=n=>{(function(e,t=null){try{const n=e.split(".");if(3!==n.length)return!1;const[r]=n;if(!r)return!1;const i=JSON.parse(atob(r));return!("typ"in i&&"JWT"!==i?.typ||!i.alg||t&&(!("alg"in i)||i.alg!==t))}catch{return!1}})(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),ht=t("$ZodNumber",(e,t)=>{_e.init(e,t),e._zod.pattern=e._zod.bag.pattern??me,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch(e){}const i=n.value;if("number"==typeof i&&!Number.isNaN(i)&&Number.isFinite(i))return n;const o="number"==typeof i?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:i,inst:e,...o?{received:o}:{}}),n}}),ft=t("$ZodNumberFormat",(e,t)=>{Te.init(e,t),ht.init(e,t)}),dt=t("$ZodBoolean",(e,t)=>{_e.init(e,t),e._zod.pattern=ge,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Boolean(n.value)}catch(e){}const i=n.value;return"boolean"==typeof i||n.issues.push({expected:"boolean",code:"invalid_type",input:i,inst:e}),n}}),pt=t("$ZodUnknown",(e,t)=>{_e.init(e,t),e._zod.parse=e=>e}),mt=t("$ZodNever",(e,t)=>{_e.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:"never",code:"invalid_type",input:t.value,inst:e}),t)});function gt(e,t,n){e.issues.length&&t.issues.push(...O(n,e.issues)),t.value[n]=e.value}const yt=t("$ZodArray",(e,t)=>{_e.init(e,t),e._zod.parse=(n,r)=>{const i=n.value;if(!Array.isArray(i))return n.issues.push({expected:"array",code:"invalid_type",input:i,inst:e}),n;n.value=Array(i.length);const o=[];for(let e=0;e<i.length;e++){const a=i[e],s=t.element._zod.run({value:a,issues:[]},r);s instanceof Promise?o.push(s.then(t=>gt(t,n,e))):gt(s,n,e)}return o.length?Promise.all(o).then(()=>n):n}});function wt(e,t,n,r){e.issues.length&&t.issues.push(...O(n,e.issues)),void 0===e.value?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function bt(e){const t=Object.keys(e.shape);for(const n of t)if(!e.shape?.[n]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${n}": expected a Zod schema`);const n=(r=e.shape,Object.keys(r).filter(e=>"optional"===r[e]._zod.optin&&"optional"===r[e]._zod.optout));var r;return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function vt(e,t,n,r,i,o){const a=[],s=i.keySet,c=i.catchall._zod,u=c.def.type;for(const i in t){if(s.has(i))continue;if("never"===u){a.push(i);continue}const o=c.run({value:t[i],issues:[]},r);o instanceof Promise?e.push(o.then(e=>wt(e,n,i,t))):wt(o,n,i,t)}return a.length&&n.issues.push({code:"unrecognized_keys",keys:a,input:t,inst:o}),e.length?Promise.all(e).then(()=>n):n}const Et=t("$ZodObject",(e,t)=>{_e.init(e,t);const n=Object.getOwnPropertyDescriptor(t,"shape");if(!n?.get){const e=t.shape;Object.defineProperty(t,"shape",{get:()=>{const n={...e};return Object.defineProperty(t,"shape",{value:n}),n}})}const r=s(()=>bt(t));h(e._zod,"propValues",()=>{const e=t.shape,n={};for(const t in e){const r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(const e of r.values)n[t].add(e)}}return n});const i=g,o=t.catchall;let a;e._zod.parse=(t,n)=>{a??(a=r.value);const s=t.value;if(!i(s))return t.issues.push({expected:"object",code:"invalid_type",input:s,inst:e}),t;t.value={};const c=[],u=a.shape;for(const e of a.keys){const r=u[e]._zod.run({value:s[e],issues:[]},n);r instanceof Promise?c.push(r.then(n=>wt(n,t,e,s))):wt(r,t,e,s)}return o?vt(c,s,t,n,r.value,e):c.length?Promise.all(c).then(()=>t):t}}),xt=t("$ZodObjectJIT",(e,t)=>{Et.init(e,t);const n=e._zod.parse,r=s(()=>bt(t));let o;const a=g,c=!i.jitless,u=c&&y.value,l=t.catchall;let h;e._zod.parse=(i,s)=>{h??(h=r.value);const f=i.value;return a(f)?c&&u&&!1===s?.async&&!0!==s.jitless?(o||(o=(e=>{const t=new Ne(["shape","payload","ctx"]),n=r.value,i=e=>{const t=p(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write("const input = payload.value;");const o=Object.create(null);let a=0;for(const e of n.keys)o[e]="key_"+a++;t.write("const newResult = {};");for(const e of n.keys){const n=o[e],r=p(e);t.write(`const ${n} = ${i(e)};`),t.write(`\n if (${n}.issues.length) {\n payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${r}, ...iss.path] : [${r}]\n })));\n }\n \n \n if (${n}.value === undefined) {\n if (${r} in input) {\n newResult[${r}] = undefined;\n }\n } else {\n newResult[${r}] = ${n}.value;\n }\n \n `)}t.write("payload.value = newResult;"),t.write("return payload;");const s=t.compile();return(t,n)=>s(e,t,n)})(t.shape)),i=o(i,s),l?vt([],f,i,s,h,e):i):n(i,s):(i.issues.push({expected:"object",code:"invalid_type",input:f,inst:e}),i)}});function Bt(e,t,n,r){for(const n of e)if(0===n.issues.length)return t.value=n.value,t;const i=e.filter(e=>!A(e));return 1===i.length?(t.value=i[0].value,i[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>S(e,r,o())))}),t)}const Tt=t("$ZodUnion",(e,t)=>{_e.init(e,t),h(e._zod,"optin",()=>t.options.some(e=>"optional"===e._zod.optin)?"optional":void 0),h(e._zod,"optout",()=>t.options.some(e=>"optional"===e._zod.optout)?"optional":void 0),h(e._zod,"values",()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),h(e._zod,"pattern",()=>{if(t.options.every(e=>e._zod.pattern)){const e=t.options.map(e=>e._zod.pattern);return new RegExp(`^(${e.map(e=>u(e.source)).join("|")})$`)}});const n=1===t.options.length,r=t.options[0]._zod.run;e._zod.parse=(i,o)=>{if(n)return r(i,o);let a=!1;const s=[];for(const e of t.options){const t=e._zod.run({value:i.value,issues:[]},o);if(t instanceof Promise)s.push(t),a=!0;else{if(0===t.issues.length)return t;s.push(t)}}return a?Promise.all(s).then(t=>Bt(t,i,e,o)):Bt(s,i,e,o)}}),At=t("$ZodDiscriminatedUnion",(e,t)=>{Tt.init(e,t);const n=e._zod.parse;h(e._zod,"propValues",()=>{const e={};for(const n of t.options){const r=n._zod.propValues;if(!r||0===Object.keys(r).length)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(n)}"`);for(const[t,n]of Object.entries(r)){e[t]||(e[t]=new Set);for(const r of n)e[t].add(r)}}return e});const r=s(()=>{const e=t.options,n=new Map;for(const r of e){const e=r._zod.propValues?.[t.discriminator];if(!e||0===e.size)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(r)}"`);for(const t of e){if(n.has(t))throw new Error(`Duplicate discriminator value "${String(t)}"`);n.set(t,r)}}return n});e._zod.parse=(i,o)=>{const a=i.value;if(!g(a))return i.issues.push({code:"invalid_type",expected:"object",input:a,inst:e}),i;const s=r.value.get(a?.[t.discriminator]);return s?s._zod.run(i,o):t.unionFallback?n(i,o):(i.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:t.discriminator,input:a,path:[t.discriminator],inst:e}),i)}}),Ot=t("$ZodIntersection",(e,t)=>{_e.init(e,t),e._zod.parse=(e,n)=>{const r=e.value,i=t.left._zod.run({value:r,issues:[]},n),o=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||o instanceof Promise?Promise.all([i,o]).then(([t,n])=>St(e,t,n)):St(e,i,o)}});function Rt(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e===+t)return{valid:!0,data:e};if(w(e)&&w(t)){const n=Object.keys(t),r=Object.keys(e).filter(e=>-1!==n.indexOf(e)),i={...e,...t};for(const n of r){const r=Rt(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const i=Rt(e[r],t[r]);if(!i.valid)return{valid:!1,mergeErrorPath:[r,...i.mergeErrorPath]};n.push(i.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function St(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),A(e))return e;const r=Rt(t.value,n.value);if(!r.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const kt=t("$ZodEnum",(e,t)=>{_e.init(e,t);const n=function(e){const t=Object.values(e).filter(e=>"number"==typeof e);return Object.entries(e).filter(([e,n])=>-1===t.indexOf(+e)).map(([e,t])=>t)}(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(e=>v.has(typeof e)).map(e=>"string"==typeof e?E(e):e.toString()).join("|")})$`),e._zod.parse=(t,i)=>{const o=t.value;return r.has(o)||t.issues.push({code:"invalid_value",values:n,input:o,inst:e}),t}}),$t=t("$ZodLiteral",(e,t)=>{if(_e.init(e,t),0===t.values.length)throw new Error("Cannot create literal schema with no valid values");const n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map(e=>"string"==typeof e?E(e):e?E(e.toString()):String(e)).join("|")})$`),e._zod.parse=(r,i)=>{const o=r.value;return n.has(o)||r.issues.push({code:"invalid_value",values:t.values,input:o,inst:e}),r}}),It=t("$ZodTransform",(e,t)=>{_e.init(e,t),e._zod.parse=(i,o)=>{if("backward"===o.direction)throw new r(e.constructor.name);const a=t.transform(i.value,i);if(o.async){return(a instanceof Promise?a:Promise.resolve(a)).then(e=>(i.value=e,i))}if(a instanceof Promise)throw new n;return i.value=a,i}});function zt(e,t){return e.issues.length&&void 0===t?{issues:[],value:void 0}:e}const Dt=t("$ZodOptional",(e,t)=>{_e.init(e,t),e._zod.optin="optional",e._zod.optout="optional",h(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),h(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${u(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if("optional"===t.innerType._zod.optin){const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(t=>zt(t,e.value)):zt(r,e.value)}return void 0===e.value?e:t.innerType._zod.run(e,n)}}),Ct=t("$ZodNullable",(e,t)=>{_e.init(e,t),h(e._zod,"optin",()=>t.innerType._zod.optin),h(e._zod,"optout",()=>t.innerType._zod.optout),h(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${u(e.source)}|null)$`):void 0}),h(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>null===e.value?e:t.innerType._zod.run(e,n)}),Pt=t("$ZodDefault",(e,t)=>{_e.init(e,t),e._zod.optin="optional",h(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);if(void 0===e.value)return e.value=t.defaultValue,e;const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Nt(e,t)):Nt(r,t)}});function Nt(e,t){return void 0===e.value&&(e.value=t.defaultValue),e}const Ut=t("$ZodPrefault",(e,t)=>{_e.init(e,t),e._zod.optin="optional",h(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>("backward"===n.direction||void 0===e.value&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),_t=t("$ZodNonOptional",(e,t)=>{_e.init(e,t),h(e._zod,"values",()=>{const e=t.innerType._zod.values;return e?new Set([...e].filter(e=>void 0!==e)):void 0}),e._zod.parse=(n,r)=>{const i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Vt(t,e)):Vt(i,e)}});function Vt(e,t){return e.issues.length||void 0!==e.value||e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const Ft=t("$ZodCatch",(e,t)=>{_e.init(e,t),h(e._zod,"optin",()=>t.innerType._zod.optin),h(e._zod,"optout",()=>t.innerType._zod.optout),h(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>S(e,n,o()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>S(e,n,o()))},input:e.value}),e.issues=[]),e)}}),Mt=t("$ZodPipe",(e,t)=>{_e.init(e,t),h(e._zod,"values",()=>t.in._zod.values),h(e._zod,"optin",()=>t.in._zod.optin),h(e._zod,"optout",()=>t.out._zod.optout),h(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if("backward"===n.direction){const r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>jt(e,t.in,n)):jt(r,t.in,n)}const r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>jt(e,t.out,n)):jt(r,t.out,n)}});function jt(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const Lt=t("$ZodReadonly",(e,t)=>{_e.init(e,t),h(e._zod,"propValues",()=>t.innerType._zod.propValues),h(e._zod,"values",()=>t.innerType._zod.values),h(e._zod,"optin",()=>t.innerType?._zod?.optin),h(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(qt):qt(r)}});function qt(e){return e.value=Object.freeze(e.value),e}const Gt=t("$ZodCustom",(e,t)=>{be.init(e,t),_e.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{const r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>Ht(t,n,r,e));Ht(i,n,r,e)}});function Ht(e,t,n,r){if(!e){const e={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push($(e))}}var Zt;class Wt{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){const n=t[0];if(this._map.set(e,n),n&&"object"==typeof n&&"id"in n){if(this._idmap.has(n.id))throw new Error(`ID ${n.id} already exists in the registry`);this._idmap.set(n.id,e)}return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){const t=this._map.get(e);return t&&"object"==typeof t&&"id"in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){const t=e._zod.parent;if(t){const n={...this.get(t)??{}};delete n.id;const r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}(Zt=globalThis).__zod_globalRegistry??(Zt.__zod_globalRegistry=new Wt);const Kt=globalThis.__zod_globalRegistry;function Jt(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...B(t)})}function Xt(e,t){return new Ee({check:"less_than",...B(t),value:e,inclusive:!1})}function Yt(e,t){return new Ee({check:"less_than",...B(t),value:e,inclusive:!0})}function Qt(e,t){return new xe({check:"greater_than",...B(t),value:e,inclusive:!1})}function en(e,t){return new xe({check:"greater_than",...B(t),value:e,inclusive:!0})}function tn(e,t){return new Be({check:"multiple_of",...B(t),value:e})}function nn(e,t){return new Ae({check:"max_length",...B(t),maximum:e})}function rn(e,t){return new Oe({check:"min_length",...B(t),minimum:e})}function on(e,t){return new Re({check:"length_equals",...B(t),length:e})}function an(e){return new Pe({check:"overwrite",tx:e})}function sn(e){const t=function(e,t){const n=new be({check:"custom",...B(t)});return n._zod.check=e,n}(n=>(n.addIssue=e=>{if("string"==typeof e)n.issues.push($(e,n.value,t._zod.def));else{const r=e;r.fatal&&(r.continue=!1),r.code??(r.code="custom"),r.input??(r.input=n.value),r.inst??(r.inst=t),r.continue??(r.continue=!t._zod.def.abort),n.issues.push($(r))}},e(n.value,n)));return t}const cn=t("ZodISODateTime",(e,t)=>{Ye.init(e,t),Dn.init(e,t)});function un(e){return function(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...B(t)})}(cn,e)}const ln=t("ZodISODate",(e,t)=>{Qe.init(e,t),Dn.init(e,t)});function hn(e){return function(e,t){return new e({type:"string",format:"date",check:"string_format",...B(t)})}(ln,e)}const fn=t("ZodISOTime",(e,t)=>{et.init(e,t),Dn.init(e,t)});function dn(e){return function(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...B(t)})}(fn,e)}const pn=t("ZodISODuration",(e,t)=>{tt.init(e,t),Dn.init(e,t)});function mn(e){return function(e,t){return new e({type:"string",format:"duration",check:"string_format",...B(t)})}(pn,e)}const gn=t("ZodError",(e,t)=>{z.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:t=>function(e,t=e=>e.message){const n={_errors:[]},r=e=>{for(const i of e.issues)if("invalid_union"===i.code&&i.errors.length)i.errors.map(e=>r({issues:e}));else if("invalid_key"===i.code)r({issues:i.issues});else if("invalid_element"===i.code)r({issues:i.issues});else if(0===i.path.length)n._errors.push(t(i));else{let e=n,r=0;for(;r<i.path.length;){const n=i.path[r];r===i.path.length-1?(e[n]=e[n]||{_errors:[]},e[n]._errors.push(t(i))):e[n]=e[n]||{_errors:[]},e=e[n],r++}}};return r(e),n}(e,t)},flatten:{value:t=>function(e,t=e=>e.message){const n={},r=[];for(const i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,a,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,a,2)}},isEmpty:{get:()=>0===e.issues.length}})},{Parent:Error}),yn=C(gn),wn=P(gn),bn=N(gn),vn=_(gn),En=F(gn),xn=M(gn),Bn=j(gn),Tn=L(gn),An=q(gn),On=G(gn),Rn=H(gn),Sn=Z(gn),kn=t("ZodType",(e,t)=>(_e.init(e,t),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(d(t,{checks:[...t.checks??[],...n.map(e=>"function"==typeof e?{_zod:{check:e,def:{check:"custom"},onattach:[]}}:e)]})),e.clone=(t,n)=>x(e,t,n),e.brand=()=>e,e.register=(t,n)=>(t.add(e,n),e),e.parse=(t,n)=>yn(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>bn(e,t,n),e.parseAsync=async(t,n)=>wn(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>vn(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>En(e,t,n),e.decode=(t,n)=>xn(e,t,n),e.encodeAsync=async(t,n)=>Bn(e,t,n),e.decodeAsync=async(t,n)=>Tn(e,t,n),e.safeEncode=(t,n)=>An(e,t,n),e.safeDecode=(t,n)=>On(e,t,n),e.safeEncodeAsync=async(t,n)=>Rn(e,t,n),e.safeDecodeAsync=async(t,n)=>Sn(e,t,n),e.refine=(t,n)=>e.check(function(e,t={}){return function(e,t,n){return new e({type:"custom",check:"custom",fn:t,...B(n)})}(Dr,e,t)}(t,n)),e.superRefine=t=>e.check(sn(t)),e.overwrite=t=>e.check(an(t)),e.optional=()=>Br(e),e.nullable=()=>Ar(e),e.nullish=()=>Br(Ar(e)),e.nonoptional=t=>function(e,t){return new Sr({type:"nonoptional",innerType:e,...B(t)})}(e,t),e.array=()=>{return function(e,t,n){return new e({type:"array",element:t,...B(n)})}(ur,e,t);var t},e.or=t=>dr([e,t]),e.and=t=>new gr({type:"intersection",left:e,right:t}),e.transform=t=>Ir(e,new Er({type:"transform",transform:t})),e.default=t=>{return n=t,new Or({type:"default",innerType:e,get defaultValue(){return"function"==typeof n?n():b(n)}});var n},e.prefault=t=>{return n=t,new Rr({type:"prefault",innerType:e,get defaultValue(){return"function"==typeof n?n():b(n)}});var n},e.catch=t=>{return new kr({type:"catch",innerType:e,catchValue:"function"==typeof(n=t)?n:()=>n});var n},e.pipe=t=>Ir(e,t),e.readonly=()=>new zr({type:"readonly",innerType:e}),e.describe=t=>{const n=e.clone();return Kt.add(n,{description:t}),n},Object.defineProperty(e,"description",{get:()=>Kt.get(e)?.description,configurable:!0}),e.meta=(...t)=>{if(0===t.length)return Kt.get(e);const n=e.clone();return Kt.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),$n=t("_ZodString",(e,t)=>{Ve.init(e,t),kn.init(e,t);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(function(e,t){return new ke({check:"string_format",format:"regex",...B(t),pattern:e})}(...t)),e.includes=(...t)=>e.check(function(e,t){return new ze({check:"string_format",format:"includes",...B(t),includes:e})}(...t)),e.startsWith=(...t)=>e.check(function(e,t){return new De({check:"string_format",format:"starts_with",...B(t),prefix:e})}(...t)),e.endsWith=(...t)=>e.check(function(e,t){return new Ce({check:"string_format",format:"ends_with",...B(t),suffix:e})}(...t)),e.min=(...t)=>e.check(rn(...t)),e.max=(...t)=>e.check(nn(...t)),e.length=(...t)=>e.check(on(...t)),e.nonempty=(...t)=>e.check(rn(1,...t)),e.lowercase=t=>e.check(function(e){return new $e({check:"string_format",format:"lowercase",...B(e)})}(t)),e.uppercase=t=>e.check(function(e){return new Ie({check:"string_format",format:"uppercase",...B(e)})}(t)),e.trim=()=>e.check(an(e=>e.trim())),e.normalize=(...t)=>e.check(function(e){return an(t=>t.normalize(e))}(...t)),e.toLowerCase=()=>e.check(an(e=>e.toLowerCase())),e.toUpperCase=()=>e.check(an(e=>e.toUpperCase())),e.slugify=()=>e.check(an(e=>function(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}(e)))}),In=t("ZodString",(e,t)=>{Ve.init(e,t),$n.init(e,t),e.email=t=>e.check(function(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...B(t)})}(Cn,t)),e.url=t=>e.check(function(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...B(t)})}(Un,t)),e.jwt=t=>e.check(function(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...B(t)})}(Yn,t)),e.emoji=t=>e.check(function(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...B(t)})}(_n,t)),e.guid=t=>e.check(Jt(Pn,t)),e.uuid=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...B(t)})}(Nn,t)),e.uuidv4=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...B(t)})}(Nn,t)),e.uuidv6=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...B(t)})}(Nn,t)),e.uuidv7=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...B(t)})}(Nn,t)),e.nanoid=t=>e.check(function(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...B(t)})}(Vn,t)),e.guid=t=>e.check(Jt(Pn,t)),e.cuid=t=>e.check(function(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...B(t)})}(Fn,t)),e.cuid2=t=>e.check(function(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...B(t)})}(Mn,t)),e.ulid=t=>e.check(function(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...B(t)})}(jn,t)),e.base64=t=>e.check(function(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...B(t)})}(Kn,t)),e.base64url=t=>e.check(function(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...B(t)})}(Jn,t)),e.xid=t=>e.check(function(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...B(t)})}(Ln,t)),e.ksuid=t=>e.check(function(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...B(t)})}(qn,t)),e.ipv4=t=>e.check(function(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...B(t)})}(Gn,t)),e.ipv6=t=>e.check(function(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...B(t)})}(Hn,t)),e.cidrv4=t=>e.check(function(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...B(t)})}(Zn,t)),e.cidrv6=t=>e.check(function(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...B(t)})}(Wn,t)),e.e164=t=>e.check(function(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...B(t)})}(Xn,t)),e.datetime=t=>e.check(un(t)),e.date=t=>e.check(hn(t)),e.time=t=>e.check(dn(t)),e.duration=t=>e.check(mn(t))});function zn(e){return function(e,t){return new e({type:"string",...B(t)})}(In,e)}const Dn=t("ZodStringFormat",(e,t)=>{Fe.init(e,t),$n.init(e,t)}),Cn=t("ZodEmail",(e,t)=>{Le.init(e,t),Dn.init(e,t)}),Pn=t("ZodGUID",(e,t)=>{Me.init(e,t),Dn.init(e,t)}),Nn=t("ZodUUID",(e,t)=>{je.init(e,t),Dn.init(e,t)}),Un=t("ZodURL",(e,t)=>{qe.init(e,t),Dn.init(e,t)}),_n=t("ZodEmoji",(e,t)=>{Ge.init(e,t),Dn.init(e,t)}),Vn=t("ZodNanoID",(e,t)=>{He.init(e,t),Dn.init(e,t)}),Fn=t("ZodCUID",(e,t)=>{Ze.init(e,t),Dn.init(e,t)}),Mn=t("ZodCUID2",(e,t)=>{We.init(e,t),Dn.init(e,t)}),jn=t("ZodULID",(e,t)=>{Ke.init(e,t),Dn.init(e,t)}),Ln=t("ZodXID",(e,t)=>{Je.init(e,t),Dn.init(e,t)}),qn=t("ZodKSUID",(e,t)=>{Xe.init(e,t),Dn.init(e,t)}),Gn=t("ZodIPv4",(e,t)=>{nt.init(e,t),Dn.init(e,t)}),Hn=t("ZodIPv6",(e,t)=>{rt.init(e,t),Dn.init(e,t)}),Zn=t("ZodCIDRv4",(e,t)=>{it.init(e,t),Dn.init(e,t)}),Wn=t("ZodCIDRv6",(e,t)=>{ot.init(e,t),Dn.init(e,t)}),Kn=t("ZodBase64",(e,t)=>{st.init(e,t),Dn.init(e,t)}),Jn=t("ZodBase64URL",(e,t)=>{ct.init(e,t),Dn.init(e,t)}),Xn=t("ZodE164",(e,t)=>{ut.init(e,t),Dn.init(e,t)}),Yn=t("ZodJWT",(e,t)=>{lt.init(e,t),Dn.init(e,t)}),Qn=t("ZodNumber",(e,t)=>{ht.init(e,t),kn.init(e,t),e.gt=(t,n)=>e.check(Qt(t,n)),e.gte=(t,n)=>e.check(en(t,n)),e.min=(t,n)=>e.check(en(t,n)),e.lt=(t,n)=>e.check(Xt(t,n)),e.lte=(t,n)=>e.check(Yt(t,n)),e.max=(t,n)=>e.check(Yt(t,n)),e.int=t=>e.check(nr(t)),e.safe=t=>e.check(nr(t)),e.positive=t=>e.check(Qt(0,t)),e.nonnegative=t=>e.check(en(0,t)),e.negative=t=>e.check(Xt(0,t)),e.nonpositive=t=>e.check(Yt(0,t)),e.multipleOf=(t,n)=>e.check(tn(t,n)),e.step=(t,n)=>e.check(tn(t,n)),e.finite=()=>e;const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function er(e){return function(e,t){return new e({type:"number",checks:[],...B(t)})}(Qn,e)}const tr=t("ZodNumberFormat",(e,t)=>{ft.init(e,t),Qn.init(e,t)});function nr(e){return function(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...B(t)})}(tr,e)}const rr=t("ZodBoolean",(e,t)=>{dt.init(e,t),kn.init(e,t)});function ir(e){return function(e,t){return new e({type:"boolean",...B(t)})}(rr,e)}const or=t("ZodUnknown",(e,t)=>{pt.init(e,t),kn.init(e,t)});function ar(){return new or({type:"unknown"})}const sr=t("ZodNever",(e,t)=>{mt.init(e,t),kn.init(e,t)});function cr(e){return function(e,t){return new e({type:"never",...B(t)})}(sr,e)}const ur=t("ZodArray",(e,t)=>{yt.init(e,t),kn.init(e,t),e.element=t.element,e.min=(t,n)=>e.check(rn(t,n)),e.nonempty=t=>e.check(rn(1,t)),e.max=(t,n)=>e.check(nn(t,n)),e.length=(t,n)=>e.check(on(t,n)),e.unwrap=()=>e.element});const lr=t("ZodObject",(e,t)=>{xt.init(e,t),kn.init(e,t),h(e,"shape",()=>t.shape),e.keyof=()=>wr(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:ar()}),e.loose=()=>e.clone({...e._zod.def,catchall:ar()}),e.strict=()=>e.clone({...e._zod.def,catchall:cr()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>function(e,t){if(!w(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0)throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");const r=d(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t};return f(this,"shape",n),n},checks:[]});return x(e,r)}(e,t),e.safeExtend=t=>function(e,t){if(!w(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n={...e._zod.def,get shape(){const n={...e._zod.def.shape,...t};return f(this,"shape",n),n},checks:e._zod.def.checks};return x(e,n)}(e,t),e.merge=t=>function(e,t){const n=d(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t._zod.def.shape};return f(this,"shape",n),n},get catchall(){return t._zod.def.catchall},checks:[]});return x(e,n)}(e,t),e.pick=t=>function(e,t){const n=e._zod.def;return x(e,d(e._zod.def,{get shape(){const e={};for(const r in t){if(!(r in n.shape))throw new Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return f(this,"shape",e),e},checks:[]}))}(e,t),e.omit=t=>function(e,t){const n=e._zod.def,r=d(e._zod.def,{get shape(){const r={...e._zod.def.shape};for(const e in t){if(!(e in n.shape))throw new Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return f(this,"shape",r),r},checks:[]});return x(e,r)}(e,t),e.partial=(...t)=>function(e,t,n){const r=d(t._zod.def,{get shape(){const r=t._zod.def.shape,i={...r};if(n)for(const t in n){if(!(t in r))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:"optional",innerType:r[t]}):r[t])}else for(const t in r)i[t]=e?new e({type:"optional",innerType:r[t]}):r[t];return f(this,"shape",i),i},checks:[]});return x(t,r)}(xr,e,t[0]),e.required=(...t)=>function(e,t,n){const r=d(t._zod.def,{get shape(){const r=t._zod.def.shape,i={...r};if(n)for(const t in n){if(!(t in i))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:"nonoptional",innerType:r[t]}))}else for(const t in r)i[t]=new e({type:"nonoptional",innerType:r[t]});return f(this,"shape",i),i},checks:[]});return x(t,r)}(Sr,e,t[0])});function hr(e,t){const n={type:"object",shape:e??{},...B(t)};return new lr(n)}const fr=t("ZodUnion",(e,t)=>{Tt.init(e,t),kn.init(e,t),e.options=t.options});function dr(e,t){return new fr({type:"union",options:e,...B(t)})}const pr=t("ZodDiscriminatedUnion",(e,t)=>{fr.init(e,t),At.init(e,t)});function mr(e,t,n){return new pr({type:"union",options:t,discriminator:e,...B(n)})}const gr=t("ZodIntersection",(e,t)=>{Ot.init(e,t),kn.init(e,t)});const yr=t("ZodEnum",(e,t)=>{kt.init(e,t),kn.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{const i={};for(const r of e){if(!n.has(r))throw new Error(`Key ${r} not found in enum`);i[r]=t.entries[r]}return new yr({...t,checks:[],...B(r),entries:i})},e.exclude=(e,r)=>{const i={...t.entries};for(const t of e){if(!n.has(t))throw new Error(`Key ${t} not found in enum`);delete i[t]}return new yr({...t,checks:[],...B(r),entries:i})}});function wr(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new yr({type:"enum",entries:n,...B(t)})}const br=t("ZodLiteral",(e,t)=>{$t.init(e,t),kn.init(e,t),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function vr(e,t){return new br({type:"literal",values:Array.isArray(e)?e:[e],...B(t)})}const Er=t("ZodTransform",(e,t)=>{It.init(e,t),kn.init(e,t),e._zod.parse=(n,i)=>{if("backward"===i.direction)throw new r(e.constructor.name);n.addIssue=r=>{if("string"==typeof r)n.issues.push($(r,n.value,t));else{const t=r;t.fatal&&(t.continue=!1),t.code??(t.code="custom"),t.input??(t.input=n.value),t.inst??(t.inst=e),n.issues.push($(t))}};const o=t.transform(n.value,n);return o instanceof Promise?o.then(e=>(n.value=e,n)):(n.value=o,n)}});const xr=t("ZodOptional",(e,t)=>{Dt.init(e,t),kn.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Br(e){return new xr({type:"optional",innerType:e})}const Tr=t("ZodNullable",(e,t)=>{Ct.init(e,t),kn.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ar(e){return new Tr({type:"nullable",innerType:e})}const Or=t("ZodDefault",(e,t)=>{Pt.init(e,t),kn.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});const Rr=t("ZodPrefault",(e,t)=>{Ut.init(e,t),kn.init(e,t),e.unwrap=()=>e._zod.def.innerType});const Sr=t("ZodNonOptional",(e,t)=>{_t.init(e,t),kn.init(e,t),e.unwrap=()=>e._zod.def.innerType});const kr=t("ZodCatch",(e,t)=>{Ft.init(e,t),kn.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});const $r=t("ZodPipe",(e,t)=>{Mt.init(e,t),kn.init(e,t),e.in=t.in,e.out=t.out});function Ir(e,t){return new $r({type:"pipe",in:e,out:t})}const zr=t("ZodReadonly",(e,t)=>{Lt.init(e,t),kn.init(e,t),e.unwrap=()=>e._zod.def.innerType});const Dr=t("ZodCustom",(e,t)=>{Gt.init(e,t),kn.init(e,t)});function Cr(e,t={error:`Input not instance of ${e.name}`}){const n=new Dr({type:"custom",check:"custom",fn:t=>t instanceof e,abort:!0,...B(t)});return n._zod.bag.Class=e,n}const Pr=zn().refine(e=>64===e.length||128===e.length,{message:"Reference must be 64 chars (32 bytes) or 128 chars (64 bytes for encrypted)"}),Nr=zn().length(64),Ur=zn().length(40),_r=hr({pin:ir().optional(),encrypt:ir().optional(),tag:er().optional(),deferred:ir().optional(),redundancyLevel:er().min(0).max(4).optional()}).optional(),Vr=hr({redundancyStrategy:dr([vr(0),vr(1),vr(2),vr(3)]).optional(),fallback:ir().optional(),timeoutMs:er().optional(),actPublisher:dr([Cr(Uint8Array),zn()]),actHistoryAddress:dr([Cr(Uint8Array),zn()]),actTimestamp:dr([er(),zn()])}).optional(),Fr=hr({reference:Pr,tagUid:er().optional()}),Mr=hr({name:zn(),data:Cr(Uint8Array)}),jr=hr({batchID:Nr,utilization:er(),usable:ir(),label:zn(),depth:er(),amount:zn(),bucketDepth:er(),blockNumber:er(),immutableFlag:ir(),exists:ir(),batchTTL:er().optional()}),Lr=hr({authenticated:ir(),origin:zn().optional()}),qr=hr({backgroundColor:zn().optional(),color:zn().optional(),border:zn().optional(),borderRadius:zn().optional(),padding:zn().optional(),fontSize:zn().optional(),fontFamily:zn().optional(),fontWeight:zn().optional(),cursor:zn().optional(),width:zn().optional(),height:zn().optional()}).optional(),Gr=mr("type",[hr({type:vr("parentIdentify"),beeApiUrl:zn().url().optional(),popupMode:wr(["popup","window"]).optional()}),hr({type:vr("checkAuth"),requestId:zn()}),hr({type:vr("requestAuth"),styles:qr}),hr({type:vr("uploadData"),requestId:zn(),data:Cr(Uint8Array),options:_r,enableProgress:ir().optional()}),hr({type:vr("downloadData"),requestId:zn(),reference:Pr,options:Vr}),hr({type:vr("uploadFile"),requestId:zn(),data:Cr(Uint8Array),name:zn().optional(),options:_r}),hr({type:vr("downloadFile"),requestId:zn(),reference:Pr,path:zn().optional(),options:Vr}),hr({type:vr("uploadChunk"),requestId:zn(),data:Cr(Uint8Array),options:_r}),hr({type:vr("downloadChunk"),requestId:zn(),reference:Pr,options:Vr})]),Hr=mr("type",[hr({type:vr("proxyReady"),authenticated:ir(),parentOrigin:zn()}),hr({type:vr("initError"),error:zn()}),hr({type:vr("authStatusResponse"),requestId:zn(),authenticated:ir(),origin:zn().optional()}),hr({type:vr("authSuccess"),origin:zn()}),hr({type:vr("uploadDataResponse"),requestId:zn(),reference:Pr,tagUid:er().optional()}),hr({type:vr("downloadDataResponse"),requestId:zn(),data:Cr(Uint8Array)}),hr({type:vr("uploadFileResponse"),requestId:zn(),reference:Pr,tagUid:er().optional()}),hr({type:vr("downloadFileResponse"),requestId:zn(),name:zn(),data:Cr(Uint8Array)}),hr({type:vr("uploadChunkResponse"),requestId:zn(),reference:Pr}),hr({type:vr("downloadChunkResponse"),requestId:zn(),data:Cr(Uint8Array)}),hr({type:vr("uploadProgress"),requestId:zn(),total:er(),processed:er()}),hr({type:vr("error"),requestId:zn(),error:zn()})]),Zr=hr({secret:zn(),postageBatchId:Nr.optional(),signerKey:zn().length(64).optional()}).refine(e=>!!e.postageBatchId,{message:"postageBatchId is required. signerKey is optional for client-side signing."}),Wr=mr("type",[hr({type:vr("setSecret"),appOrigin:zn(),data:Zr})]);var Kr="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function Jr(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Xr,Yr={};var Qr=(Xr||(Xr=1,function(e){var t;async function n(e){return new Promise((t,n)=>e.then(n,t))}async function r(e){return new Promise(t=>setTimeout(()=>{t(!0)},e))}function i(e,t=Math.random){for(let n=e.length-1;n>0;n--){const r=Math.floor(t()*(n+1)),i=e[n];e[n]=e[r],e[r]=i}return e}function o(e,t,n=Math.random){return i(q(0,e.length-1),n).slice(0,t)}function a(e,t,n=Math.random){return Math.floor(n()*(t-e+1))+e}function s(e,t,n){return t>=e.x&&t<e.x+e.width&&n>=e.y&&n<e.y+e.height}function c(e,t=Math.random){return t()<e}function u(e,t=Math.random){return e[Math.floor(e.length*t())]}function l(e){if(!e.length)throw Error("Received empty array");return e[e.length-1]}function h(e,t,n){return n(t.reduce((e,t)=>t(e),e))}function f(e,t){if(null==e)return null;const n=t.split(".");let r=e;for(const e of n){if(null===r[e]||void 0===r[e])return null;r=r[e]}return r}function d(e,t,n){const r=t.split(/\.|\[/);let i=e;for(let e=0;e<r.length;e++){const t=r[e],o=e<r.length-1&&r[e+1].includes("]"),a=t.includes("]")?t.replace(/\[|\]/g,""):t;if(e===r.length-1)return i[a]=n,n;m(i[a])||(i[a]=o?[]:{}),i=i[a]}return n}function p(e,t){return Math.round(e/t)*t}function m(e,t=!0){return!(!e||t&&!w(e._readableState)||t&&e.constructor&&(e.constructor.isBuffer||"Uint8Array"==e.constructor.name||"ArrayBuffer"===e.constructor.name||"ReadableStream"===e.constructor.name))&&"object"==typeof e}function g(e){return m(e)&&!Array.isArray(e)}function y(e){return Array.isArray(e)&&0===e.length}function w(e){return void 0===e}function b(e){return"[object Function]"===Object.prototype.toString.call(e)||"[object AsyncFunction]"===Object.prototype.toString.call(e)}function v(e){return"[object String]"===Object.prototype.toString.call(e)}function E(e){return"number"==typeof e&&isFinite(e)}function x(e){return!0===e||!1===e}function B(e){return"[object Date]"===Object.prototype.toString.call(e)}function T(e){return!v(e)||0===e.trim().length}function A(e){return E(e)&&Number.isInteger(e)&&e>=1}function O(e){return v(e)&&null!==e.match(/^-?\d+$/)}function R(e){return v(e)&&null!==e.match(/^(0x)?[0-9a-f]+$/i)}Object.defineProperty(e,"__esModule",{value:!0}),e.Vector=e.Cache=e.Assertions=e.Strings=e.Types=e.Objects=e.Dates=e.Promises=e.Numbers=e.System=e.Arrays=e.Random=e.Elliptic=e.Binary=e.TrieRouter=e.AsyncQueue=e.PubSubChannel=e.FixedPointNumber=e.MerkleTree=e.Chunk=e.Uint8ArrayWriter=e.Uint8ArrayReader=e.AsyncLazy=e.Lazy=e.Optional=void 0;const S="!@#$%^&*()_+-=[]{}|;:<>?,./".split(""),k="abcdefghijklmnopqrstuvwxyz",$=k+"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",I=$+"!@#$%^&*()_+-=[]{}|;:<>?,./",z=["—","\\","東","京","都","𝖆","𝖇","𝖈","👾","🙇","💁","🙅","ᚠ","ᛇ","ᚻ","ᛦ"],D="0123456789abcdef";function C(e,t){if(T(e))throw new TypeError(`Expected string${t?.name?` for ${t.name}`:""}, got: `+e);if(t&&(void 0!==t.min&&e.length<t.min||void 0!==t.max&&e.length>t.max))throw RangeError(`Expected string${t?.name?` for ${t.name}`:""} length in range: ${t.min??"-inf"}..${t.max??"inf"}; got: ${e.length}`);return e}function P(e,t){if(void 0!==t.min&&e<t.min||void 0!==t.max&&e>t.max)throw RangeError(`Expected value${t?.name?` for ${t.name}`:""} in range: ${t.min??"-inf"}..${t.max??"inf"}; got: ${e}`)}function N(e,t){if(E(e))return t&&P(e,t),e;if(!v(e)||!e.match(/^-?\d+(\.\d+)?$/))throw new TypeError(`Expected number${t?.name?` for ${t.name}`:""}, got: `+e);const n=parseFloat(e);return t&&P(n,t),n}function U(e,t){return 0|N(e,t)}function _(e,t){if(!g(e))throw new TypeError(`Expected object${t?.name?` for ${t.name}`:""}, got: `+e);return e}function V(e){return v(e)&&null!==e.match(/^https?:\/\/.+/)}function F(e,t){for(const[n,r]of Object.entries(t))if(!r(e[n]))throw TypeError(`${n} in value does not exist or match shape`);for(const n of Object.keys(e))if(!t[n])throw TypeError(`${n} exists in value but not in shape`);return!0}function M(e,t){if(g(e)&&g(t))for(const n in t)g(t[n])?(e[n]||(e[n]={}),M(e[n],t[n])):Array.isArray(t[n])?e[n]=[...t[n]]:(null!==t[n]&&void 0!==t[n]||null===e[n]||void 0===e[n])&&(e[n]=t[n]);return e}function j(e,t){const n={};for(const r of e)for(const e of Object.keys(r))n[e]?n[e]=t(n[e],r[e]):n[e]=r[e];return n}function L(e,t){Array.prototype.push.apply(e,t)}function q(e,t){const n=[];for(let r=e;r<=t;r++)n.push(r);return n}function G(e,t=()=>!1){return e.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").split("").map(e=>/[a-z0-9]/.test(e)||t(e)?e:"-").join("").replace(/-+/g,"-").replace(/^-|-$/g,"")}function H(e,t){if(0===t.length)return 0;const n=e.toLowerCase(),r=t.toLowerCase();return e===t?1e4:n.startsWith(r)?1e4-e.length:n.includes(r)?5e3-e.length:new RegExp(".*"+r.split("").join(".*")+".*").test(n)?1e3-e.length:0}const Z={"&":"&",""":'"',"'":"'",">":">","<":"<"};function W(e,t){const n=e.indexOf(t);return-1===n?null:e.slice(0,n)}function K(e,t){const n=e.indexOf(t);return-1===n?null:e.slice(n+t.length)}function J(e,t){const n=e.lastIndexOf(t);return-1===n?null:e.slice(0,n)}function X(e,t){const n=e.lastIndexOf(t);return-1===n?null:e.slice(n+t.length)}function Y(e,t,n=!1){const r=n?e.lastIndexOf(t):e.indexOf(t);return-1===r?n?[null,e]:[e,null]:[e.slice(0,r),e.slice(r+t.length)]}function Q(e,t){let n=[e];for(const e of t)n=n.flatMap(t=>t.split(e));return n.filter(e=>e)}function ee(e){const t=l(e.split(/\\|\//g)),n=t.lastIndexOf(".",t.length-1);return n<=0?"":t.slice(n+1)}function te(e){const t=l(e.split(/\\|\//g)),n=t.lastIndexOf(".",t.length-1);return n<=0?t:t.slice(0,n)}function ne(e){return e.split("\n").map(e=>e.trim().replace(/\s+/g," ")).filter(e=>e.length>0).join("\n")}function re(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ie(e){return e.charAt(0).toLowerCase()+e.slice(1)}function oe(e){if(!e)return!1;const t=e.charCodeAt(0);return t>=65&&t<=90||t>=97&&t<=122}function ae(e){if(!e)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}function se(e){return oe(e)||ae(e)}const ce=" \n\t\r.,?!:;\"'`(){}[]~@#$%^&*-+=|<>/\\".split("");function ue(e){return ce.includes(e)}function le(e,t,n=0){const r=t.exec(e.slice(n));return r?{index:r.index,match:r[0]}:null}function he(e,t,n=!0){if(!n)return t.every(t=>t instanceof RegExp?t.test(e):-1!==e.indexOf(t,0));let r=0;for(const n of t)if(n instanceof RegExp){const t=le(e,n,r);if(!t)return!1;r=t.index+t.match.length}else{const t=e.indexOf(n,r);if(-1===t)return!1;r=t+n.length}return!0}function fe(e,t,n=0){const r=[];let i=e.indexOf(t,n);for(;-1!==i;)r.push(i),i=e.indexOf(t,i+t.length);return r}function de(e,t,n=0){let r=-1;for(const i of t){const t=e.indexOf(i,n);-1!==t&&(-1===r||t<r)&&(r=t)}return r}function pe(e,t=0){for(let n=t;n<e.length;n++)if(ue(e[n]))return n;return-1}function me(e,t=0){for(let n=t;n<e.length;n++)if("#"===e[n]&&se(e[n+1]))return n;return-1}function ge(e,t,n=0){return e.slice(0,n).lastIndexOf(t)}function ye(e,t=0,n="{",r="}"){let i=1;for(let o=t;o<e.length;o++)if(e.slice(o,o+r.length)===r){if(0===--i)return o}else e.slice(o,o+n.length)===n&&i++;return-1}function we(e,t){const n=t.wordBoundary?de(e,[`${t.opening} `,`${t.opening}\n`],t.start||0):e.indexOf(t.opening,t.start||0);if(-1===n)return null;const r=ye(e,n+t.opening.length,t.opening,t.closing);return-1===r?null:t.exclusive?e.slice(n+t.opening.length,r):e.slice(n,r+t.closing.length)}const be="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ve="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function Ee(e,t){const n=t.length;let r=0,i=0;const o=[];for(let a=0;a<e.length;a++){const s=e[a];if("="===s)break;const c=t.indexOf(s);if(-1===c)throw new Error(`Invalid character: ${s}`);i=i<<Math.log2(n)|c,r+=Math.log2(n),r>=8&&(r-=8,o.push(i>>r&255))}return new Uint8Array(o)}function xe(e,t){const n=t.length;let r=0,i=0,o="";for(let a=0;a<e.length;a++)for(i=i<<8|e[a],r+=8;r>=Math.log2(n);)r-=Math.log2(n),o+=t[i>>r&n-1];return r>0&&(o+=t[i<<Math.log2(n)-r&n-1]),o.length%4!=0&&(o+="=".repeat(4-o.length%4)),o}function Be(e,t,n){const r=[];for(const i of n)i!==t&&r.push(e.replace(t,i));return r}function Te(e){const t=e.lastIndexOf(" ");return-1===t?{line:e,rest:""}:{line:e.slice(0,t),rest:e.slice(t+1)}}function Ae(e){const t=e.reduce((e,t)=>e.length<t.length?e:t);let n="";for(let r=0;r<t.length;r++){const i=t[r];if(!e.every(e=>e[r]===i))break;n+=i}return n}function Oe(e,t){return new RegExp(`\\b${t}\\b`).test(e)}function Re(e,t,n=[]){let r="";for(;t<e.length&&(se(e[t])||n.includes(e[t]));)r+=e[t++];return r}function Se(e,t,n,r="$",i=":"){if(""===n)return e;let o=e.indexOf(`${r}${t}`);for(;-1!==o;){if(e[o+t.length+1]===i)if(e[o+t.length+2]===i)e=e.replace(`${r}${t}${i}${i}`,n);else{const a=Re(e,o+t.length+2,["_"]);e=e.replace(`${r}${t}${i}${a}`,n)}else e=e.replace(`${r}${t}`,n);o=e.indexOf(`${r}${t}`,o+n.length)}return e}function ke(e,t="$",n=":"){let r=e.indexOf(t);for(;-1!==r;){const i=Re(e,r+1);if(e[r+i.length+1]===n)if(e[r+i.length+2]===n)e=e.replace(`${t}${i}${n}${n}`,"");else{const o=Re(e,r+i.length+2);e=e.replace(`${t}${i}${n}${o}`,o)}r=e.indexOf(t,r+1)}return e}function $e(e,t=!0){const n=Object.entries(e).filter(([e,t])=>null!=t).map(([e,t])=>`${e}=${encodeURIComponent(t)}`).join("&");return n?(t?"?":"")+n:""}function Ie(e){return String(Math.floor(e)).padStart(2,"0")}function ze(e){const t=Math.floor(e/36e5);e%=36e5;const n=Math.floor(e/6e4);e%=6e4;const r=Math.floor(e/1e3);return t?`${Ie(t)}:${Ie(n)}:${Ie(r)}`:`${Ie(n)}:${Ie(r)}`}function De(e){return Math.floor((B(e)?e.getTime():e)/864e5)}const Ce={today:(e,t)=>Ie(e)+":"+Ie(t),yesterday:()=>"Yesterday",monday:()=>"Mon",tuesday:()=>"Tue",wednesday:()=>"Wed",thursday:()=>"Thu",friday:()=>"Fri",saturday:()=>"Sat",sunday:()=>"Sun",weeks:e=>`${e}w`},Pe={now:()=>"A few seconds",seconds:e=>`${e} seconds`,minutes:e=>`${e} minutes`,hours:e=>`${e} hours`,days:e=>`${e} days`,weeks:e=>`${e} weeks`};function Ne(t,n){const r=n?.now??Date.now(),i=n?.labels||Pe;let o=(r-(e.Types.isDate(t)?t.getTime():t))/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 Ue={},_e={s:1e3,m:6e4,h:36e5,d:864e5},Ve={0:"sunday",1:"monday",2:"tuesday",3:"wednesday",4:"thursday",5:"friday",6:"saturday"};function Fe(e){return{zeroBasedIndex:e,day:Ve[e]}}function Me(e){return Fe(e.getDay())}const je={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},Le={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},qe=new Map;function Ge(e,t=!1){e=e.filter(e=>e),t&&v(e[1])&&(e[1]="../"+e[1]);let n="";v(e[0])&&e[0].includes("://")&&(n=W(e[0],"://")??"",e[0]=K(e[0],"://")??"");const r=e.map(e=>String(e)).flatMap(e=>e.split("/")),i=[];for(let e=0;e<r.length;e++)"."!==r[e]&&(".."===r[e]?(!n||i.length>1)&&i.pop():i.push(r[e]));return(n?n+"://":"")+i.join("/").replaceAll(/\/{2,}/g,"/")}function He(e){const t=Object.keys(e).sort((e,t)=>e.localeCompare(t)),n={};for(const r of t)n[r]=We(e[r]);return n}function Ze(e){const t=[];return e.sort((e,t)=>JSON.stringify(We(e)).localeCompare(JSON.stringify(We(t)))).forEach(e=>t.push(We(e))),t}function We(e){return Array.isArray(e)?Ze(e):m(e)?He(e):e}function Ke(e,t){return JSON.stringify(We(e))===JSON.stringify(We(t))}function Je(e){const t=Object.keys(e);return t[Math.floor(Math.random()*t.length)]}const Xe=[1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24,1e27,1e30,1e9,1e16,1e18,1e18,1e18,1e33],Ye=["thousand","million","billion","trillion","quadrillion","quintillion","sextillion","septillion","octillion","nonillion","gwei","bzz","btc","eth","dai","decillion"],Qe=["K","M","B","T","Qa","Qi","Sx","Sp","O","N","gwei","bzz","eth","btc","dai","D"];function et(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeNumber got NaN for input");const n=e.replace(/^-?[0-9.]+/,"").trim(),r=Qe.findIndex(e=>e.toLowerCase()===n.toLowerCase());return-1===r?t:t*Xe[r]}function tt(e,t,n){return e<t?t:e>n?n:e}function nt(e,t,n){return e+(n?"["+t+"]":(e.length?".":"")+t)}function rt(e,t,n,r,i){if(!m(t))return t;for(const[o,a]of Object.entries(t)){const t=nt(n,o,r);Array.isArray(a)?i?rt(e,a,t,!0,i):e[t]=a.map(e=>rt(Array.isArray(e)?[]:{},e,"",!1,i)):m(a)?rt(e,a,t,!1,i):e[t]=a}return e}function it(e,t){const n={};for(const r of e)n[t(r)]=r;return n}function ot(e,t){const n=Math.ceil(e.length/t),r=[];for(let t=0;t<e.length;t+=n)r.push(e.slice(t,t+n));return r}function at(e,t){const n=[],r=Math.ceil(e.length/t);for(let i=0;i<r;i++)n.push(e.slice(i*t,i*t+t));return n}function st(e,t){return Object.fromEntries(Object.entries(e).sort(t))}function ct(e,t){const n=[];let r=[];return e.forEach((i,o)=>{(0===o||!t(i,e[o-1]))&&(r=[],n.push(r)),r.push(i)}),n}function ut(e,t,n,r=100){if(e.map.has(t)){const n=e.keys.indexOf(t);e.keys.splice(n,1)}if(e.map.set(t,n),e.keys.push(t),e.keys.length>r){const t=e.keys.shift();t&&e.map.delete(t)}}class lt{constructor(e){this.value=e}static of(e){return new lt(e)}static empty(){return new lt(null)}map(e){return new lt(null!==this.value&&void 0!==this.value?e(this.value):null)}mapAsync(e){return null!==this.value&&void 0!==this.value?e(this.value).then(e=>lt.of(e)):Promise.resolve(lt.empty())}ifPresent(e){return null!==this.value&&void 0!==this.value&&e(this.value),this}ifPresentAsync(e){return null!==this.value&&void 0!==this.value?e(this.value).then(()=>this):Promise.resolve(this)}ifAbsent(e){return(null===this.value||void 0===this.value)&&e(),this}ifAbsentAsync(e){return null===this.value||void 0===this.value?e().then(()=>this):Promise.resolve(this)}getOrFallback(e){return this.value??e()}getOrFallbackAsync(e){return null!==this.value&&void 0!==this.value?Promise.resolve(this.value):e()}getOrThrow(){if(null===this.value||void 0===this.value)throw Error("Optional.value is empty");return this.value}}e.Optional=lt,e.Lazy=class{constructor(e){this.supplier=e,this.value=null}get(){return this.value||(this.value=this.supplier()),this.value}},e.AsyncLazy=class{constructor(e){this.supplier=e,this.value=null}async get(){return this.value||(this.value=await this.supplier()),this.value}};class ht{constructor(e){this.value=e,this.children=[]}}function ft(e,t){if(Math.log2(e.length)%1!=0)throw new Error("Array length must be a power of 2");let n=[...e];for(;n.length>1;){const e=[];for(let r=0;r<n.length;r+=2){const i=n[r+1];e.push(t(n[r],i))}n=e}return n[0]}function dt(...e){const t=e.reduce((e,t)=>e+t.length,0),n=new Uint8Array(t);let r=0;return e.forEach(e=>{n.set(e,r),r+=e.length}),n}function pt(e){return 137===e[0]&&80===e[1]&&78===e[2]&&71===e[3]}function mt(e){return 255===e[0]&&216===e[1]}function gt(e){return 87===e[8]&&69===e[9]&&66===e[10]&&80===e[11]}function yt(e,t){const n=new ArrayBuffer(8);return new DataView(n).setBigUint64(0,BigInt(e),"LE"===t),new Uint8Array(n)}function wt(e,t){const n=new Uint8Array(32);let r=e;if("LE"===t){for(let e=0;e<32;e++)n[e]=Number(0xffn&r),r>>=8n;return n}for(let e=31;e>=0;e--)n[e]=Number(0xffn&r),r>>=8n;return n}function bt(e,t){let n=0n;if("LE"===t){for(let t=31;t>=0;t--)n=n<<8n|BigInt(e[t]);return n}for(let t=0;t<32;t++)n=n<<8n|BigInt(e[t]);return n}function vt(e,t){const n=[];for(let r=0;r<e.length;r+=t)n.push(e.subarray(r,r+t));return n}const Et=[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 xt(e){for(let t=0;t<24;t++){const n=e[0]^e[10]^e[20]^e[30]^e[40],r=e[1]^e[11]^e[21]^e[31]^e[41],i=e[2]^e[12]^e[22]^e[32]^e[42],o=e[3]^e[13]^e[23]^e[33]^e[43],a=e[4]^e[14]^e[24]^e[34]^e[44],s=e[5]^e[15]^e[25]^e[35]^e[45],c=e[6]^e[16]^e[26]^e[36]^e[46],u=e[7]^e[17]^e[27]^e[37]^e[47],l=e[8]^e[18]^e[28]^e[38]^e[48],h=e[9]^e[19]^e[29]^e[39]^e[49],f=l^(i<<1|o>>>31),d=h^(o<<1|i>>>31),p=n^(a<<1|s>>>31),m=r^(s<<1|a>>>31),g=i^(c<<1|u>>>31),y=o^(u<<1|c>>>31),w=a^(l<<1|h>>>31),b=s^(h<<1|l>>>31),v=c^(n<<1|r>>>31),E=u^(r<<1|n>>>31);e[0]^=f,e[1]^=d,e[2]^=p,e[3]^=m,e[4]^=g,e[5]^=y,e[6]^=w,e[7]^=b,e[8]^=v,e[9]^=E,e[10]^=f,e[11]^=d,e[12]^=p,e[13]^=m,e[14]^=g,e[15]^=y,e[16]^=w,e[17]^=b,e[18]^=v,e[19]^=E,e[20]^=f,e[21]^=d,e[22]^=p,e[23]^=m,e[24]^=g,e[25]^=y,e[26]^=w,e[27]^=b,e[28]^=v,e[29]^=E,e[30]^=f,e[31]^=d,e[32]^=p,e[33]^=m,e[34]^=g,e[35]^=y,e[36]^=w,e[37]^=b,e[38]^=v,e[39]^=E,e[40]^=f,e[41]^=d,e[42]^=p,e[43]^=m,e[44]^=g,e[45]^=y,e[46]^=w,e[47]^=b,e[48]^=v,e[49]^=E;const x=e[0],B=e[1],T=e[2]<<1|e[3]>>>31,A=e[3]<<1|e[2]>>>31,O=e[5]<<30|e[4]>>>2,R=e[4]<<30|e[5]>>>2,S=e[6]<<28|e[7]>>>4,k=e[7]<<28|e[6]>>>4,$=e[8]<<27|e[9]>>>5,I=e[9]<<27|e[8]>>>5,z=e[11]<<4|e[10]>>>28,D=e[10]<<4|e[11]>>>28,C=e[13]<<12|e[12]>>>20,P=e[12]<<12|e[13]>>>20,N=e[14]<<6|e[15]>>>26,U=e[15]<<6|e[14]>>>26,_=e[17]<<23|e[16]>>>9,V=e[16]<<23|e[17]>>>9,F=e[18]<<20|e[19]>>>12,M=e[19]<<20|e[18]>>>12,j=e[20]<<3|e[21]>>>29,L=e[21]<<3|e[20]>>>29,q=e[22]<<10|e[23]>>>22,G=e[23]<<10|e[22]>>>22,H=e[25]<<11|e[24]>>>21,Z=e[24]<<11|e[25]>>>21,W=e[26]<<25|e[27]>>>7,K=e[27]<<25|e[26]>>>7,J=e[29]<<7|e[28]>>>25,X=e[28]<<7|e[29]>>>25,Y=e[31]<<9|e[30]>>>23,Q=e[30]<<9|e[31]>>>23,ee=e[33]<<13|e[32]>>>19,te=e[32]<<13|e[33]>>>19,ne=e[34]<<15|e[35]>>>17,re=e[35]<<15|e[34]>>>17,ie=e[36]<<21|e[37]>>>11,oe=e[37]<<21|e[36]>>>11,ae=e[38]<<8|e[39]>>>24,se=e[39]<<8|e[38]>>>24,ce=e[40]<<18|e[41]>>>14,ue=e[41]<<18|e[40]>>>14,le=e[42]<<2|e[43]>>>30,he=e[43]<<2|e[42]>>>30,fe=e[45]<<29|e[44]>>>3,de=e[44]<<29|e[45]>>>3,pe=e[47]<<24|e[46]>>>8,me=e[46]<<24|e[47]>>>8,ge=e[48]<<14|e[49]>>>18,ye=e[49]<<14|e[48]>>>18;e[0]=x^~C&H,e[1]=B^~P&Z,e[2]=C^~H&ie,e[3]=P^~Z&oe,e[4]=H^~ie&ge,e[5]=Z^~oe&ye,e[6]=ie^~ge&x,e[7]=oe^~ye&B,e[8]=ge^~x&C,e[9]=ye^~B&P,e[10]=S^~F&j,e[11]=k^~M&L,e[12]=F^~j&ee,e[13]=M^~L&te,e[14]=j^~ee&fe,e[15]=L^~te&de,e[16]=ee^~fe&S,e[17]=te^~de&k,e[18]=fe^~S&F,e[19]=de^~k&M,e[20]=T^~N&W,e[21]=A^~U&K,e[22]=N^~W&ae,e[23]=U^~K&se,e[24]=W^~ae&ce,e[25]=K^~se&ue,e[26]=ae^~ce&T,e[27]=se^~ue&A,e[28]=ce^~T&N,e[29]=ue^~A&U,e[30]=$^~z&q,e[31]=I^~D&G,e[32]=z^~q&ne,e[33]=D^~G&re,e[34]=q^~ne&pe,e[35]=G^~re&me,e[36]=ne^~pe&$,e[37]=re^~me&I,e[38]=pe^~$&z,e[39]=me^~I&D,e[40]=O^~_&J,e[41]=R^~V&X,e[42]=_^~J&Y,e[43]=V^~X&Q,e[44]=J^~Y&le,e[45]=X^~Q&he,e[46]=Y^~le&O,e[47]=Q^~he&R,e[48]=le^~O&_,e[49]=he^~R&V,e[0]^=Et[2*t],e[1]^=Et[2*t+1]}}function Bt(e){const t=[];for(let n=0;n<e.length;n+=4)t.push(e[n]|e[n+1]<<8|e[n+2]<<16|e[n+3]<<24);return t}function Tt(e,t){if(!e.length){const e=new Uint8Array(136);return e[0]=t,e[135]=128,[Bt(e)]}const n=vt(e,136),r=n[n.length-1];if(r.length<136){const e=new Uint8Array(136);e.set(r),e[r.length]=t,e[135]|=128,n[n.length-1]=e}if(136===r.length){const e=new Uint8Array(136);e[0]=t,e[135]=128,n.push(e)}return n.map(Bt)}function At(e,t){for(const n of t){for(let t=0;t<34;t+=2)e[t]^=n[t+1],e[t+1]^=n[t];xt(e)}return e}function Ot(e){return new Uint8Array([e[1],e[1]>>-24,e[1]>>-16,e[1]>>-8,e[0],e[0]>>8,e[0]>>16,e[0]>>24,e[3],e[3]>>-24,e[3]>>-16,e[3]>>-8,e[2],e[2]>>8,e[2]>>16,e[2]>>24,e[5],e[5]>>-24,e[5]>>-16,e[5]>>-8,e[4],e[4]>>8,e[4]>>16,e[4]>>24,e[7],e[7]>>-24,e[7]>>-16,e[7]>>-8,e[6],e[6]>>8,e[6]>>16,e[6]>>24])}function Rt(e){return Ot(At(new Array(50).fill(0),Tt(e,1)))}function St(e,t,n=0){if(e.length>=t)return e;const r=new Uint8Array(t);return r.fill(n),r.set(e,t-e.length),r}function kt(e,t,n=0){if(e.length>=t)return e;const r=new Uint8Array(t);return r.fill(n),r.set(e,0),r}function $t(e,t){return(e%t+t)%t}function It(e,t){e=$t(e,t);let[n,r]=[0n,1n],[i,o]=[t,e];for(;0n!==o;){const e=i/o;[n,r]=[r,n-e*r],[i,o]=[o,i-e*o]}if(i>1n)throw new Error("a is not invertible");return n<0n&&(n+=t),n}function zt(e,t){return 0n===$t(e,t)?0n:t%4n==3n?function(e,t,n){let r=1n;for(e=$t(e,n);t>0;)t%2n==1n&&(r=$t(r*e,n)),e=$t(e*e,n),t/=2n;return r}(e,(t+1n)/4n,t):null}const Dt=0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,Ct=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,Pt=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,Nt=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n;function Ut(e,t,n){if(0n===t)return[0n,0n];const r=$t(3n*e*e*It(2n*t,n),n),i=$t(r*r-2n*e,n);return[i,$t(r*(e-i)-t,n)]}function _t(e,t,n,r,i){if(0n===e&&0n===t)return[n,r];if(0n===n&&0n===r)return[e,t];if(e===n&&t===$t(-r,i))return[0n,0n];if(e===n&&t===r)return Ut(e,t,i);const o=$t((r-t)*It(n-e,i),i),a=$t(o*o-e-n,i);return[a,$t(o*(e-a)-t,i)]}function Vt(e,t,n,r){let i=[0n,0n],o=[e,t];const a=n.toString(2);for(const e of a)"0"===e?(o=_t(i[0],i[1],o[0],o[1],r),i=Ut(i[0],i[1],r)):(i=_t(i[0],i[1],o[0],o[1],r),o=Ut(o[0],o[1],r));return i}function Ft(e,t,n){if(t<=0n||t>=Ct)throw new Error("Invalid private key");if(n||(n=$t(bt(Rt(dt(Rt(wt(t,"BE")),wt(e,"BE"))),"BE"),Ct)),n<=0n||n>=Ct)throw new Error("Invalid nonce");const r=$t(e,Ct),i=Vt(Pt,Nt,n,Dt),o=$t(i[0],Ct);let a=$t((r+$t(o,Ct)*t)*It(n,Ct),Ct);if(0n===o||0n===a)throw new Error("Invalid r or s value");let s=i[1]%2n==0n?27n:28n;return a>Ct/2n&&(a=Ct-a,s=27n===s?28n:27n),[o,a,s]}class Mt{constructor(e){this.cursor=0,this.buffer=e}read(e){const t=this.buffer.subarray(this.cursor,this.cursor+e);return this.cursor+=e,t}max(){return this.buffer.length-this.cursor}}e.Uint8ArrayReader=Mt;class jt{constructor(e){this.buffer=e,this.cursor=0}write(e){const t=Math.min(this.max(),e.max());return this.buffer.set(e.read(t),this.cursor),this.cursor+=t,t}max(){return this.buffer.length-this.cursor}}e.Uint8ArrayWriter=jt;class Lt{constructor(e,t=0n){this.span=t,this.writer=new jt(new Uint8Array(e))}build(){return dt(yt(this.span,"LE"),this.writer.buffer)}hash(){const e=ft(vt(this.writer.buffer,32),(e,t)=>Lt.hashFunction(dt(e,t)));return Lt.hashFunction(dt(yt(this.span,"LE"),e))}}e.Chunk=Lt,Lt.hashFunction=Rt;class qt{constructor(e,t=4096){this.counters=[1],this.capacity=t,this.chunks=[new Lt(t)],this.onChunk=e}static async root(e,n=4096){const r=new t(t.NOOP,n);return await r.append(e),r.finalize()}async append(e,t=0,n=0n){const r=new Mt(e);for(;r.max()>0;){0===this.chunks[t].writer.max()&&await this.elevate(t);const e=this.chunks[t].writer.write(r);n?this.chunks[t].span+=n:this.chunks[0].span+=BigInt(e)}}async elevate(e){this.counters[e]=++this.counters[e]%(this.capacity/32),this.chunks[e+1]||(this.chunks.push(new Lt(this.capacity)),this.counters.push(1)),await this.append(this.chunks[e].hash(),e+1,this.chunks[e].span),await this.onChunk(this.chunks[e]),this.chunks[e]=new Lt(this.capacity)}async finalize(e=0){return this.chunks[e+1]?1===this.counters[e]?(await this.elevate(e+1),this.chunks[e+1]=this.chunks[e],this.finalize(e+1)):(await this.elevate(e),this.finalize(e+1)):(await this.onChunk(this.chunks[e]),this.chunks[e])}}e.MerkleTree=qt,t=qt,qt.NOOP=async e=>{};class Gt{constructor(e,t){if(t<0)throw Error("Scale must be non-negative");this.value=BigInt(e),this.scale=t}static fromDecimalString(e,t){let[n,r]=e.split(".");return r=(r||"").padEnd(t,"0").slice(0,t),new Gt(BigInt(n+r),t)}add(e){return this.assertSameScale(e),new Gt(this.value+e.value,this.scale)}subtract(e){return this.assertSameScale(e),new Gt(this.value-e.value,this.scale)}multiply(e){return new Gt(this.value*e,this.scale)}divmod(e){if(0n===e)throw new Error("Division by zero is not allowed");const t=this.value/e,n=this.value%e;return[new Gt(t,this.scale),new Gt(n,this.scale)]}exchange(e,t,n){if("*"===e){const e=this.value*t.value/10n**BigInt(this.scale);return new Gt(e,n)}this.assertSameScale(t);const r=this.value*10n**BigInt(n)/t.value;return new Gt(r,n)}compare(e){return this.assertSameScale(e),this.value>e.value?1:this.value<e.value?-1:0}toDecimalString(){if(0===this.scale)return this.value.toString();const e=this.value.toString();return`${e.slice(0,-this.scale)||"0"}.${e.slice(-this.scale).padStart(this.scale,"0")}`}toString(){return this.value.toString()}toJSON(){return this.toString()}assertSameScale(e){if(this.scale!==e.scale)throw new Error(`Scale mismatch: expected ${this.scale}, but got ${e.scale}`)}}function Ht(e,t,n,r){const i=e.findIndex(e=>e===`--${t}`||e.startsWith(`--${t}=`)),o=e[i];if(!o)return(n||{})[r||t||""]||null;if(o.includes("="))return o.split("=")[1];const a=e[i+1];return a&&!a.startsWith("-")?a:(n||{})[r||t||""]||null}function Zt(e,t,n,r){const i=Ht(e,t,n,r);if(!i)throw new Error(`Missing argument ${t}`);return i}function Wt(e,t){const n=e[t];e.splice(t,1),e.unshift(n)}function Kt(e,t){return{x:e.x+t.x,y:e.y+t.y}}function Jt(e,t){return{x:e.x*t,y:e.y*t}}function Xt(e,t,n){return{x:e.x+Math.cos(t)*n,y:e.y+Math.sin(t)*n}}function Yt(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function Qt(e,t,n="row-first"){const r=[];if("column-first"===n)for(let n=0;n<e.length;n++)for(let i=0;i<e[0].length;i++)t(n,i)&&r.push({x:n,y:i});else for(let n=0;n<e[0].length;n++)for(let i=0;i<e.length;i++)t(i,n)&&r.push({x:i,y:n});return r}function en(e,t,n){return!e[t-1]?.[n]}function tn(e,t,n){return!e[t+1]?.[n]}function nn(e,t,n){return!e[t][n-1]}function rn(e,t,n){return!e[t][n+1]}function on(e,t,n){const r=[];return e[t][n]?function(e,t,n){return e[t+1]?.[n]&&e[t-1]?.[n]&&!e[t][n-1]&&!e[t][n+1]}(e,t,n)||function(e,t,n){return e[t][n+1]&&e[t][n-1]&&!e[t-1]?.[n]&&!e[t+1]?.[n]}(e,t,n)?[]:(!e[t-1]?.[n-1]&&en(e,t,n)&&nn(e,t,n)&&r.push({x:t,y:n}),!e[t+1]?.[n-1]&&tn(e,t,n)&&nn(e,t,n)&&r.push({x:t+1,y:n}),!e[t-1]?.[n+1]&&en(e,t,n)&&rn(e,t,n)&&r.push({x:t,y:n+1}),!e[t+1]?.[n+1]&&tn(e,t,n)&&rn(e,t,n)&&r.push({x:t+1,y:n+1}),r):(e[t-1]?.[n]&&e[t][n-1]&&r.push({x:t,y:n}),e[t+1]?.[n]&&e[t][n-1]&&r.push({x:t+1,y:n}),e[t-1]?.[n]&&e[t][n+1]&&r.push({x:t,y:n+1}),e[t+1]?.[n]&&e[t][n+1]&&r.push({x:t+1,y:n+1}),r)}function an(e,t){return t.map(t=>function(e,t){return Math.atan2(t.y-e.y,t.x-e.x)}(e,t)).sort((e,t)=>e-t)}function sn(e,t,n,r){const i=(r.y-n.y)*(t.x-e.x)-(r.x-n.x)*(t.y-e.y);if(0===i)return null;let o=e.y-n.y,a=e.x-n.x;const s=(r.x-n.x)*o-(r.y-n.y)*a,c=(t.x-e.x)*o-(t.y-e.y)*a;return o=s/i,a=c/i,o>0&&o<1&&a>0&&a<1?{x:e.x+o*(t.x-e.x),y:e.y+o*(t.y-e.y)}:null}function cn(e,t,n){const r=[],i=Xt(e,n,1e4);for(const n of t){const t=sn(e,i,n.start,n.end);t&&r.push(t)}return r.length?r.reduce((t,n)=>Yt(e,n)<Yt(e,t)?n:t):null}e.FixedPointNumber=Gt;class un{constructor(){this.subscribers=[]}subscribe(e){return this.subscribers.push(e),()=>{this.subscribers=this.subscribers.filter(t=>t!==e)}}publish(e){this.subscribers.forEach(t=>t(e))}clear(){this.subscribers=[]}getSubscriberCount(){return this.subscribers.length}}e.PubSubChannel=un,e.AsyncQueue=class{constructor(e,t){this.queue=[],this.running=0,this.onProcessed=new un,this.onDrained=new un,this.concurrency=e,this.capacity=t}process(){if(this.running>=this.concurrency)return;const e=this.queue.shift();e&&(this.running++,e().finally(()=>{this.running--,this.process(),this.onProcessed.publish(),0===this.running&&this.onDrained.publish()}))}enqueue(e){if(this.queue.length<this.capacity)return this.queue.push(e),this.process(),Promise.resolve();if(this.onProcessed.getSubscriberCount())throw Error("Queue capacity is full");return new Promise(t=>{this.onProcessed.subscribe(()=>{this.queue.length<this.capacity&&(this.queue.push(e),this.process(),this.onProcessed.clear(),t())})})}drain(){if(0===this.running)return Promise.resolve();if(this.onDrained.getSubscriberCount())throw Error("Already draining");return new Promise(e=>{this.onDrained.subscribe(()=>{this.onDrained.clear(),e()})})}};class ln{constructor(){this.forks=new Map}insert(e,t){if(0===e.length)return void(this.handler=t);const n=e[0];let r,i=n;if(n.startsWith(":")&&(i=":",r=n.slice(1)),!this.forks.has(i)){const e=new ln;r&&(e.variableName=r),this.forks.set(i,e)}this.forks.get(i).insert(e.slice(1),t)}async handle(e,t,n,r){if(0===e.length)return!!this.handler&&(await this.handler(t,n,r),!0);const i=e[0],o=this.forks.get(i);if(o)return o.handle(e.slice(1),t,n,r);const a=this.forks.get(":");if(a)return a.variableName&&r.set(a.variableName,decodeURIComponent(i)),a.handle(e.slice(1),t,n,r);const s=this.forks.get("*");return!!s&&(r.set("wildcard",e.join("/")),!!s.handler&&(await s.handler(t,n,r),!0))}}e.TrieRouter=ln,e.Binary={hexToUint8Array:function(e){(e.startsWith("0x")||e.startsWith("0X"))&&(e=e.slice(2));const t=e.length/2,n=new Uint8Array(t);for(let r=0;r<t;r++){const t=parseInt(e.slice(2*r,2*r+2),16);n[r]=t}return n},uint8ArrayToHex:function(e){return Array.from(e).map(e=>e.toString(16).padStart(2,"0")).join("")},binaryToUint8Array:function(e){const t=Math.ceil(e.length/8),n=new Uint8Array(t);for(let r=0;r<t;r++){const t=parseInt(e.slice(8*r,8*r+8),2);n[r]=t}return n},uint8ArrayToBinary:function(e){return Array.from(e).map(e=>e.toString(2).padStart(8,"0")).join("")},base64ToUint8Array:function(e){return Ee(e,be)},uint8ArrayToBase64:function(e){return xe(e,be)},base32ToUint8Array:function(e){return Ee(e,ve)},uint8ArrayToBase32:function(e){return xe(e,ve)},log2Reduce:ft,partition:vt,concatBytes:dt,numberToUint8:function(e){return new Uint8Array([e])},uint8ToNumber:function(e){return e[0]},numberToUint16:function(e,t){const n=new ArrayBuffer(2);return new DataView(n).setUint16(0,e,"LE"===t),new Uint8Array(n)},uint16ToNumber:function(e,t){return new DataView(e.buffer).getUint16(e.byteOffset,"LE"===t)},numberToUint32:function(e,t){const n=new ArrayBuffer(4);return new DataView(n).setUint32(0,e,"LE"===t),new Uint8Array(n)},uint32ToNumber:function(e,t){return new DataView(e.buffer).getUint32(e.byteOffset,"LE"===t)},numberToUint64:yt,uint64ToNumber:function(e,t){return new DataView(e.buffer).getBigUint64(e.byteOffset,"LE"===t)},numberToUint256:wt,uint256ToNumber:bt,sliceBytes:function(e,t){const n=[];let r=0;for(const i of t)n.push(e.subarray(r,r+i)),r+=i;return n},keccak256:Rt,sha3_256:function(e){return Ot(At(new Array(50).fill(0),Tt(e,6)))},proximity:function(e,t){const n=Math.min(e.length,t.length);for(let r=0;r<n;r++){const n=e[r]^t[r];for(let e=0;e<8;e++)if(n>>7-e&1)return 8*r+e}return 8*Math.min(e.length,t.length)},commonPrefix:function(e,t){const n=Math.min(e.length,t.length);for(let r=0;r<n;r++)if(e[r]!==t[r])return e.subarray(0,r);return e.subarray(0,n)},setBit:function(e,t,n,r){const i=Math.floor(t/8),o=t%8;1===n?e[i]|=1<<("BE"===r?7-o:o):e[i]&=~(1<<("BE"===r?7-o:o))},getBit:function(e,t,n){const r=t%8;return e[Math.floor(t/8)]>>("BE"===n?7-r:r)&1},indexOf:function(e,t,n=0){for(let r=n;r<e.length;r++)for(let n=0;n<t.length&&e[r+n]===t[n];n++)if(n===t.length-1)return r;return-1},equals:function(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0},padStart:St,padStartToMultiple:function(e,t,n=0){const r=e.length%t;return 0===r?e:St(e,e.length+t-r,n)},padEnd:kt,padEndToMultiple:function(e,t,n=0){const r=e.length%t;return 0===r?e:kt(e,e.length+t-r,n)},xorCypher:function(e,t){const n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e[r]^t[r%t.length];return n},isUtf8:function(e){for(let t=0;t<e.length;t++){const n=e[t];if(!(n<128))if(192==(224&n)){if(t+1>=e.length||128!=(192&e[t+1]))return!1;t+=1}else if(224==(240&n)){if(t+2>=e.length||128!=(192&e[t+1])||128!=(192&e[t+2]))return!1;t+=2}else{if(240!=(248&n))return!1;if(t+3>=e.length||128!=(192&e[t+1])||128!=(192&e[t+2])||128!=(192&e[t+3]))return!1;t+=3}}return!0}},e.Elliptic={privateKeyToPublicKey:function(e){if(e<=0n||e>=Ct)throw new Error("Invalid private key");return Vt(Pt,Nt,e,Dt)},compressPublicKey:function(e){const t=e[1]%2n==0n?2:3;return new Uint8Array([t,...wt(e[0],"BE")])},publicKeyFromCompressed:function(e){if(33!==e.length||2!==e[0]&&3!==e[0])throw new Error("Invalid compressed public key");const t=bt(e.slice(1),"BE"),n=zt($t(t**3n+7n,Dt),Dt);if(!n)throw Error("Invalid x: does not correspond to a valid curve point");const r=$t(-n,Dt),i=n%2n==0n;return[t,2===e[0]?i?n:r:i?r:n]},publicKeyToAddress:function(e){const t=new Uint8Array(20),n=Rt(dt(wt(e[0],"BE"),wt(e[1],"BE")));return t.set(n.subarray(12)),t},signMessage:function(e,t,n){return Ft(bt(Rt(e),"BE"),t,n)},signHash:Ft,verifySignature:function(e,t,n,r){const i=$t(bt(Rt(e),"BE"),Ct),o=It(r,Ct),a=$t(i*o,Ct),s=$t(n*o,Ct),c=Vt(Pt,Nt,a,Dt),u=Vt(t[0],t[1],s,Dt);return n===$t(_t(c[0],c[1],u[0],u[1],Dt)[0],Ct)},recoverPublicKey:function(e,t,n,r){const i=zt($t(t**3n+7n,Dt),Dt);if(!i)throw new Error("Invalid r: does not correspond to a valid curve point");const o=i%2n==(27n===r?0n:1n)?i:Dt-i,a=$t(bt(Rt(e),"BE"),Ct),s=Vt(t,o,n,Dt),c=Vt(Pt,Nt,a,Dt),u=_t(s[0],s[1],c[0],$t(-c[1],Dt),Dt);return Vt(u[0],u[1],It(t,Ct),Dt)},checksumEncode:function(t){const n=e.Binary.uint8ArrayToHex(t),r=e.Binary.uint8ArrayToHex(e.Binary.keccak256(new Uint8Array([...n].map(e=>e.charCodeAt(0)))));let i="0x";for(let e=0;e<n.length;e++)parseInt(r[e],16)>7?i+=n[e].toUpperCase():i+=n[e];return i}},e.Random={intBetween:a,floatBetween:function(e,t,n=Math.random){return n()*(t-e)+e},chance:c,signed:function(){return 2*Math.random()-1},makeSeededRng:function(e){let t=e,n=3405648695,r=3735928559;return function(){return t+=n,n^=t<<7,t*=r,r^=t<<13,t^=n^r,(t>>>0)/4294967296}},point:function(e,t,n,r=Math.random){let i,o;do{i=a(0,e-1,r),o=a(0,t-1,r)}while(n&&s(n,i,o));return[i,o]},procs:function(e,t=Math.random){const n=Math.floor(e);return c(e-n,t)?n+1:n}},e.Arrays={countUnique:function(e,t,n,r,i){const o=t?e.map(t):e,a={};for(const e of o)a[e]=(a[e]||0)+1;const s=r?st(a,i?(e,t)=>e[1]-t[1]:(e,t)=>t[1]-e[1]):a;return n?Object.keys(s):s},makeUnique:function(e,t){return Object.values(it(e,t))},splitBySize:function(e,t){const n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n},splitByCount:ot,index:it,indexCollection:function(e,t){const n={};for(const r of e){const e=t(r);n[e]||(n[e]=[]),n[e].push(r)}return n},onlyOrThrow:function(e){if(1===e.length)return e[0];throw Error(`Expected exactly one element, actual: ${e.length}`)},onlyOrNull:function(e){return 1===e.length?e[0]:null},firstOrThrow:function(e){if(!e.length)throw Error("Received empty array");return e[0]},firstOrNull:function(e){return e.length>0?e[0]:null},shuffle:i,initialize:function(e,t){const n=[];for(let r=0;r<e;r++)n.push(t(r));return n},initialize2D:function(e,t,n){const r=[];for(let i=0;i<e;i++){r.push([]);for(let e=0;e<t;e++)r[i].push(n)}return r},rotate2D:function(e){const t=[];for(let n=0;n<e[0].length;n++){t.push([]);for(let r=0;r<e.length;r++)t[n].push(e[r][n])}return t},containsShape:function(e,t,n,r){if(n<0||r<0||r+t[0].length>e[0].length||n+t.length>e.length)return!1;for(let i=0;i<t.length;i++)for(let o=0;o<t[i].length;o++)if(void 0!==t[i][o]&&e[n+i][r+o]!==t[i][o])return!1;return!0},glue:function(e,t){const n=[];for(let r=0;r<e.length;r++)n.push(e[r]),r<e.length-1&&(b(t)?n.push(t()):n.push(t));return n},pluck:function(e,t){return e.map(e=>e[t])},pick:u,pickMany:function(e,t,n=Math.random){if(t>e.length)throw new Error(`Count (${t}) is greater than array length (${e.length})`);return o(e,t,n).map(t=>e[t])},pickManyUnique:function(e,t,n,r=Math.random){if(t>e.length)throw new Error(`Count (${t}) is greater than array length (${e.length})`);const i=[];for(;i.length<t;){const t=u(e,r);i.some(e=>n(e,t))||i.push(t)}return i},pickWeighted:function(e,t,n){if(void 0===n&&(n=Math.random()),e.length!==t.length)throw new Error("Array length mismatch");let r=t.reduce((e,t)=>e+t,0);const i=n*r;for(let n=0;n<e.length-1;n++)if(r-=t[n],i>=r)return e[n];return l(e)},pickRandomIndices:o,pickGuaranteed:function(t,n,r,o,a,s=Math.random){const c=t.filter(e=>e!==n&&e!==r),u=[];for(null!==n&&u.push(n);c.length&&u.length<o;){const t=e.Random.intBetween(0,c.length-1,s);a(c[t],u)&&u.push(c[t]),c.splice(t,1)}return i(u,s),{values:u,indexOfGuaranteed:null!==n?u.indexOf(n):-1}},last:l,pipe:h,makePipe:function(e,t){return n=>h(n,e,t)},sortWeighted:function(e,t,n=Math.random){const r=t.map(e=>n()*e),i=[];for(let t=0;t<e.length;t++)i.push([e[t],r[t]]);return i.sort((e,t)=>t[1]-e[1]).map(e=>e[0])},pushAll:L,unshiftAll:function(e,t){Array.prototype.unshift.apply(e,t)},filterAndRemove:function(e,t){const n=[];for(let r=e.length-1;r>=0;r--)t(e[r])&&n.push(e.splice(r,1)[0]);return n},merge:function(e,t){const n=Object.keys(t);for(const r of n)Array.isArray(t[r])&&Array.isArray(e[r])&&L(e[r],t[r])},empty:function(e){return e.splice(0,e.length),e},pushToBucket:function(e,t,n){e[t]||(e[t]=[]),e[t].push(n)},unshiftAndLimit:function(e,t,n){for(e.unshift(t);e.length>n;)e.pop()},atRolling:function(e,t){let n=t%e.length;return n<0&&(n+=e.length),e[n]},group:ct,createOscillator:function(e){let t=0;return{next:()=>e[t++%e.length]}},organiseWithLimits:function(e,t,n,r,i){const o={};for(const e of Object.keys(t))o[e]=[];o[r]=[],i&&(e=e.sort(i));for(const i of e){const e=i[n],a=t[e]?e:r;o[a].length>=t[a]?o[r].push(i):o[a].push(i)}return o},tickPlaybook:function(e){if(0===e.length)return null;const t=e[0];return t.ttlMax?--t.ttl<=0&&e.shift():t.ttlMax=t.ttl,{progress:(t.ttlMax-t.ttl)/t.ttlMax,data:t.data}},getArgument:Ht,getBooleanArgument:function(e,t,n,r){const i=e.some(e=>e.endsWith("-"+t)),o=Ht(e,t,n,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 ${t}: ${o}`)},getNumberArgument:function(e,t,n,r){const i=Ht(e,t,n,r);if(!i)return null;try{return et(i)}catch{throw new Error(`Invalid number argument ${t}: ${i}`)}},requireStringArgument:Zt,requireNumberArgument:function(e,t,n,r){const i=Zt(e,t,n,r);try{return et(i)}catch{throw new Error(`Invalid argument ${t}: ${i}`)}},bringToFront:function(e,t){const n=[...e];return Wt(n,t),n},bringToFrontInPlace:Wt,findInstance:function(e,t){const n=e.find(e=>e instanceof t);return lt.of(n)},filterInstances:function(e,t){return e.filter(e=>e instanceof t)},interleave:function(e,t){const n=[],r=Math.max(e.length,t.length);for(let i=0;i<r;i++)e[i]&&n.push(e[i]),t[i]&&n.push(t[i]);return n},toggle:function(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]},createHierarchy:function(e,t,n,r,i=!1){const o=new Map,a=[];e.forEach(e=>{const n=new ht(e);o.set(e[t],n)}),e.forEach(e=>{const r=o.get(e[t]);if(!r)return;const i=e[n];if(i){const e=o.get(i);e&&e.children.push(r)}else a.push(r)});const s=e=>{e.children.sort((e,t)=>{const n=e.value[r],o=t.value[r];return i?o-n:n-o}),e.children.forEach(s)};return a.forEach(s),a},multicall:function(e){return()=>e.forEach(e=>e())},maxBy:function(e,t){return e.reduce((e,n)=>t(e)>t(n)?e:n)}},e.System={sleepMillis:r,forever:async function(e,t,n){for(;;){try{await e()}catch(e){n&&n("Error in forever",e)}await r(t)}},scheduleMany:function(e,t){for(let n=0;n<e.length;n++){const r=e[n],i=t[n],o=Math.max(0,i.getTime()-Date.now());setTimeout(r,o)}},waitFor:async function(e,t){let n=t.requiredConsecutivePasses||1,i=0;for(let o=0;o<t.attempts;o++){try{if(await e()){if(i++,i>=n)return}else i=0}catch{i=0}o<t.attempts-1&&await r(t.waitMillis)}throw Error("Timed out waiting for predicate")},expandError:function(e,t){if(v(e))return e;const n=Object.keys(e);e.message&&!n.includes("message")&&n.push("message");const r=n.map(t=>`${t}: ${e[t]}`).join("; ");return t&&e.stack?r+"\n"+e.stack:r},runAndSetInterval:function(e,t){e();const n=setInterval(()=>{e()},t);return()=>clearInterval(n)},whereAmI:function(){const e=globalThis.process;return e?!0===e.browser?"browser":"node":"browser"}},e.Numbers={make:et,sum:function(e){return e.reduce((e,t)=>e+t,0)},average:function(e){return e.reduce((e,t)=>e+t,0)/e.length},median:function(e){const t=[...e].sort((e,t)=>e-t),n=Math.floor(t.length/2);return t.length%2==0?(t[n]+t[n-1])/2:t[n]},getDistanceFromMidpoint:function(e,t){return e-(t-1)/2},clamp:tt,range:q,interpolate:function(e,t,n){return e+(t-e)*n},createSequence:function(){let e=0;return{next:()=>e++}},increment:function(e,t,n){const r=e+t;return r>n?n:r},decrement:function(e,t,n){const r=e-t;return r<n?n:r},format:function(e,t){const n=t?.longForm??!1,r=t?.unit?` ${t.unit}`:"",i=n?Ye:Qe,o=t?.precision??1;if(e<Xe[0])return`${e}${r}`;for(let t=0;t<Xe.length-1;t++)if(e<Xe[t+1])return`${(e/Xe[t]).toFixed(o)}${n?" ":""}${i[t]}${r}`;return`${(e/Xe[Xe.length-1]).toFixed(o)}${n?" ":""}${i[Xe.length-1]}${r}`},fromDecimals:function(e,t,n){let r=e.length-t;if(r<=0)return"0."+"0".repeat(-r)+e+(n?" "+n:"");let i=e.substring(0,r);return""===i&&(i="0"),i+"."+e.substring(r)+(n?" "+n:"")},makeStorage:function(e,t=1024){const n=parseFloat(e);if(isNaN(n))throw Error("makeStorage got NaN for input");const r=e.replace(/^-?[0-9.]+/,"").trim().toLowerCase(),i=""===r?0:Le[r];if(null==i)throw Error(`Unknown unit: "${r}"`);return Math.ceil(n*t**i)},asMegabytes:function(e){return e/1024/1024},convertBytes:function(e,t=1024){return e>=t*t*t*t?(e/t/t/t/t).toFixed(3)+" TB":e>=t*t*t?(e/t/t/t).toFixed(3)+" GB":e>=t*t?(e/t/t).toFixed(3)+" MB":e>=t?(e/t).toFixed(3)+" KB":e+" B"},hexToRgb:function(e){const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e.toLowerCase());if(!t)throw new Error("Invalid hex color: "+e);return[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]},rgbToHex:function(e){return"#"+e.map(e=>e.toString(16).padStart(2,"0")).join("")},haversineDistanceToMeters:function(e,t,n,r){const i=e*Math.PI/180,o=n*Math.PI/180,a=(n-e)*Math.PI/180,s=(r-t)*Math.PI/180,c=Math.sin(a/2)*Math.sin(a/2)+Math.cos(i)*Math.cos(o)*Math.sin(s/2)*Math.sin(s/2);return 2*Math.atan2(Math.sqrt(c),Math.sqrt(1-c))*6371e3},roundToNearest:p,formatDistance:function(e){return e>1e3?(e/1e3).toFixed(0)+" km":e>=500?p(e,100)+" m":e>=100?p(e,50)+" m":p(e,10)+" m"},triangularNumber:function(e){return e*(e+1)/2},searchFloat:function(e){const t=e.match(/-?\d+(\.\d+)?/);if(!t)throw Error("No float found in "+e);return parseFloat(t[0])},binomialSample:function(e,t,n=Math.random){const r=e*t,i=Math.sqrt(e*t*(1-t)),o=(n()+n()+n()+n()+n()+n()-3)*Math.SQRT2,a=Math.round(r+i*o);return Math.max(0,Math.min(e,a))}},e.Promises={raceFulfilled:async function(e){return n(Promise.all(e.map(n)))},invert:n,runInParallelBatches:async function(e,t=1){const n=ot(e,t),r=[],i=n.map(async e=>{for(const t of e)r.push(await t())});return await Promise.all(i),r}},e.Dates={getTimestamp:function(e,t){const n=new Date(t?.now||Date.now()),r=t?.labels||Ce,i=B(e)?e:new Date(e);if(De(n)===De(i))return r.today(i.getUTCHours(),i.getUTCMinutes(),i.getUTCHours()>12);if(De(n)-De(i)===1)return r.yesterday();const o=Me(i);return De(n)-De(i)<7?r[o.day]():r.weeks(Math.round((n.getTime()-i.getTime())/6048e5))},getTimeDelta:Ne,secondsToHumanTime:function(e,t=Pe){return Ne(0,{now:1e3*e,labels:t})},countCycles:function(e,t,n){const r=(n?.now??Date.now())-e;return{cycles:Math.floor(r/t),remaining:t/(n?.precision??1)-Math.ceil(r%t/(n?.precision??1))}},isoDate:function(e){return(e||new Date).toISOString().slice(0,10)},throttle:function(e,t){return(!Ue[e]||Date.now()>Ue[e])&&(Ue[e]=Date.now()+t,!0)},timeSince:function(e,t,n){return t=B(t)?t.getTime():t,((n=n?B(n)?n.getTime():n:Date.now())-t)/_e[e]},dateTimeSlug:function(e){return(e||new Date).toISOString().slice(0,19).replace(/T|:/g,"-")},unixTimestamp:function(e){return Math.ceil((e||Date.now())/1e3)},fromUtcString:function(e){const t=new Date(e);return new Date(t.getTime()-6e4*t.getTimezoneOffset())},fromMillis:function(e){return new Date(e)},getProgress:function(e,t,n,r){r||(r=Date.now());const i=r-e,o=i/t,a=o*n;return{deltaMs:i,progress:t/n,baseTimeMs:o,totalTimeMs:a,remainingTimeMs:a-i}},humanizeTime:ze,humanizeProgress:function(e){return`[${Math.floor(100*e.progress)}%] ${ze(e.deltaMs)} out of ${ze(e.totalTimeMs)} (${ze(e.remainingTimeMs)} left) [${Math.round(e.baseTimeMs)} ms each]`},createTimeDigits:Ie,mapDayNumber:Fe,getDayInfoFromDate:Me,getDayInfoFromDateTimeString:function(e){return Me(new Date(e))},seconds:function(e){return 1e3*e},minutes:function(e){return 6e4*e},hours:function(e){return 36e5*e},days:function(e){return 864e5*e},make:function(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeDate got NaN for input");const n=e.replace(/^-?[0-9.]+/,"").trim().toLowerCase(),r=""===n?1:je[n];if(!r)throw Error(`Unknown unit: "${n}"`);return Math.ceil(t*r)},normalizeTime:function(e){let[t,n]=e.split(":");E(parseInt(t,10))||(t="0"),E(parseInt(n,10))||(n="0");let r=tt(U(t),0,23),i=tt(U(n),0,59);return`${Ie(r)}:${Ie(i)}`},absoluteDays:De},e.Objects={safeParse:function(e){try{return JSON.parse(e)}catch{return null}},deleteDeep:function(e,t){const n=J(t,"."),r=X(t,".");if(!n||!r)return;const i=f(e,n);i&&delete i[r]},getDeep:f,setDeep:d,incrementDeep:function(e,t,n=1){const r=f(e,t)||0;return d(e,t,r+n),r},ensureDeep:function(e,t,n){return f(e,t)||d(e,t,n)},replaceDeep:function(e,t,n){const r=f(e,t);if(!r)throw new Error("Key '"+t+"' does not exist.");return d(e,t,n),r},getFirstDeep:function(e,t,n){for(const n of t){const t=f(e,n);if(t)return t}if(n){const t=Object.values(e);if(t.length)return t[0]}return null},deepMergeInPlace:M,deepMerge2:function(e,t){const n={};return M(n,e),M(n,t),n},deepMerge3:function(e,t,n){const r={};return M(r,e),M(r,t),M(r,n),r},mapAllAsync:async function(e,t){const n=[];for(const r of e)n.push(await t(r));return n},cloneWithJson:function(e){return JSON.parse(JSON.stringify(e))},sortObject:He,sortArray:Ze,sortAny:We,deepEquals:Ke,deepEqualsEvery:function(...e){for(let t=1;t<e.length;t++)if(!Ke(e[t-1],e[t]))return!1;return!0},runOn:function(e,t){return t(e),e},ifPresent:function(e,t){e&&t(e)},zip:j,zipSum:function(e){return j(e,(e,t)=>e+t)},removeEmptyArrays:function(e){for(const t of Object.keys(e))(y(e[t])||Array.isArray(e[t])&&e[t].every(e=>null==e))&&delete e[t];return e},removeEmptyValues:function(e){for(const t of Object.entries(e))(null===t[1]||void 0===t[1]||v(t[1])&&T(t[1]))&&delete e[t[0]];return e},flatten:function(e,t=!1,n){return rt({},e,n||"",!1,t)},unflatten:function e(t){if(!m(t))return t;const n=Array.isArray(t)?[]:{};for(const[r,i]of Object.entries(t))Array.isArray(i)?d(n,r,i.map(t=>e(t))):d(n,r,i);return n},match:function(e,t,n){return t[e]?t[e]:n},sort:st,map:function(e,t){const n={};for(const r of Object.entries(e))n[r[0]]=t(r[1]);return n},mapIterable:function(e,t){const n=[];let r=0;for(const i of e)n.push(t(i,r++));return n},filterKeys:function(e,t){const n={};for(const[r,i]of Object.entries(e))t(r)&&(n[r]=i);return n},filterValues:function(e,t){const n={};for(const[r,i]of Object.entries(e))t(i)&&(n[r]=i);return n},rethrow:async function(e,t){try{return await e()}catch{throw t}},setSomeOnObject:function(e,t,n){null!=n&&(e[t]=n)},setSomeDeep:function(e,t,n,r){const i=f(n,r);null!=i&&d(e,t,i)},flip:function(e){const t={};for(const[n,r]of Object.entries(e))t[r]=n;return t},getAllPermutations:function(e){const t=Object.keys(e),n=t.map(t=>e[t].length),r=n.reduce((e,t)=>e*t);let i=1;const o=[1];for(let e=0;e<n.length-1;e++)i*=n[e],o.push(i);const a=[];for(let n=0;n<r;n++){const r={};for(let i=0;i<t.length;i++){const a=e[t[i]],s=Math.floor(n/o[i])%a.length;r[t[i]]=a[s]}a.push(r)}return a},countTruthyValues:function(e){return Object.values(e).filter(e=>e).length},transformToArray:function(e){const t=[],n=Object.keys(e),r=e[n[0]].length;for(let i=0;i<r;i++){const r={};for(const t of n)r[t]=e[t][i];t.push(r)}return t},setMulti:function(e,t,n){for(const r of e)r[t]=n},incrementMulti:function(e,t,n=1){for(const r of e)r[t]+=n},createBidirectionalMap:function(){return{map:new Map,keys:[]}},createTemporalBidirectionalMap:function(){return{map:new Map,keys:[]}},pushToBidirectionalMap:ut,unshiftToBidirectionalMap:function(e,t,n,r=100){if(e.map.has(t)){const n=e.keys.indexOf(t);e.keys.splice(n,1)}if(e.map.set(t,n),e.keys.unshift(t),e.keys.length>r){const t=e.keys.shift();t&&e.map.delete(t)}},addToTemporalBidirectionalMap:function(e,t,n,r,i=100){ut(e,t,{validUntil:Date.now()+r,data:n},i)},getFromTemporalBidirectionalMap:function(e,t){const n=e.map.get(t);return n&&n.validUntil>Date.now()?n.data:null},createStatefulToggle:function(e){let t;return n=>{const r=n===e&&t!==e;return t=n,r}},diffKeys:function(e,t){const n=Object.keys(e),r=Object.keys(t);return{uniqueToA:n.filter(e=>!r.includes(e)),uniqueToB:r.filter(e=>!n.includes(e))}},pickRandomKey:Je,mapRandomKey:function(e,t){const n=Je(e);return e[n]=t(e[n]),n},fromObjectString:function(e){return e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=e.replace(/\r\n/g,"\n")).replace(/(\w+)\((.+)\)/g,(e,t,n)=>`${t}(${n.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,(e,t,n)=>`: (${t.trim()} && ${n.trim()}) ||`)).replace(/([a-zA-Z0-9]+)( ?: ?{)/g,'"$1"$2')).replace(/([a-zA-Z0-9]+) ?: ?(.+?)(,|\n|})/g,(e,t,n,r)=>`"${t}":"${n.trim()}"${r}`)).replace(/("'|'")/g,'"')).replaceAll(",",","),JSON.parse(e)},toQueryString:$e,parseQueryString:function(e){const t={},n=e.split("&");for(const e of n){const[n,r]=e.split("=");n&&r&&(t[n]=decodeURIComponent(r))}return t},hasKey:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},selectMax:function(e,t){let n=null,r=-1/0;for(const[i,o]of Object.entries(e)){const e=t(o);e>r&&(r=e,n=i)}return n?[n,e[n]]:null},reposition:function(e,t,n,r){const i=e.find(e=>e[t]===n),o=e.find(e=>e[t]===n+r);i&&o?(i[t]=n+r,o[t]=n):i&&(i[t]=n+r),e.sort((e,n)=>N(e[t])-N(n[t])),e.forEach((e,n)=>e[t]=n+1)},unwrapSingleKey:function(e){const t=Object.keys(e);if(1===t.length)return e[t[0]];throw new Error("Expected object to have a single key")},parseKeyValues:function(e,t=":"){return Object.fromEntries(e.map(e=>Y(e,t)).map(e=>e[0]&&e[1]?[ne(e[0]),ne(e[1])]:null).filter(e=>e))}},e.Types={isFunction:b,isObject:m,isStrictlyObject:g,isEmptyArray:y,isEmptyObject:function(e){return g(e)&&0===Object.keys(e).length},isUndefined:w,isString:v,isNumber:E,isBoolean:x,isDate:B,isBlank:T,isId:A,isIntegerString:O,isHexString:R,isUrl:V,isNullable:function(e,t){return null==t||e(t)},asString:C,asHexString:function(e,t){if(!R(e))throw new TypeError(`Expected hex string${t?.name?` for ${t.name}`:""}, got: `+e);const n=e.replace(/^0x/,"");if(n.length%2!=0)throw RangeError(`Expected even number of hex digits${t?.name?` for ${t.name}`:""}; got: `+e);if(t&&t.byteLength&&n.length!==2*t.byteLength)throw RangeError(`Expected hex string${t?.name?` for ${t.name}`:""} of byte length ${t.byteLength}; got: `+n);return n},asSafeString:function(e,t){if(!C(e,t).split("").every(e=>"_"===e||se(e)))throw new TypeError(`Expected safe string${t?.name?` for ${t.name}`:""}, got: `+e);return e},asIntegerString:function(e,t){if(!O(e))throw new TypeError(`Expected integer string${t?.name?` for ${t.name}`:""}, got: `+e);const n=BigInt(e);if(t&&(t.min&&n<t.min||t.max&&n>t.max))throw RangeError(`Expected integer string${t?.name?` for ${t.name}`:""} in range: ${t.min??"-inf"}..${t.max??"inf"}; got: `+n);return e},asNumber:N,asFunction:function(e,t){if(!b(e))throw new TypeError(`Expected function${t?.name?` for ${t.name}`:""}, got: `+e);return e},asInteger:U,asBoolean:function(e,t){if("true"===e)return!0;if("false"===e)return!1;if(!x(e))throw new TypeError(`Expected boolean${t?.name?` for ${t.name}`:""}, got: `+e);return e},asDate:function(e,t){if(!B(e))throw new TypeError(`Expected date${t?.name?` for ${t.name}`:""}, got: `+e);return e},asNullableString:function(e){return T(e)?null:e},asEmptiableString:function(e,t){if(!v(e))throw new TypeError(`Expected string${t?.name?` for ${t.name}`:""}, got: `+e);return e},asId:function(e,t){if(A(e))return e;const n=parseInt(e,10);if(!A(n))throw new TypeError(`Expected id${t?.name?` for ${t.name}`:""}, got: `+e);return n},asTime:function(e,t){if(!v(e))throw new TypeError(`Expected time${t?.name?` for ${t.name}`:""}, got: `+e);const n=e.split(":");if(2!==n.length)throw new TypeError(`Expected time${t?.name?` for ${t.name}`:""}, got: `+e);const r=parseInt(n[0],10),i=parseInt(n[1],10);if(!E(r)||!E(i)||r<0||r>23||i<0||i>59)throw new TypeError(`Expected time, got${t?.name?` for ${t.name}`:""}: `+e);return`${String(r).padStart(2,"0")}:${String(i).padStart(2,"0")}`},asArray:function(e,t){if(!Array.isArray(e))throw new TypeError(`Expected array${t?.name?` for ${t.name}`:""}, got: `+e);return e},asObject:_,asNullableObject:function(e,t){return null===e?null:_(e,t)},asStringMap:function(e,t){const n=_(e,t);for(const r of Object.keys(n))if(!v(n[r]))throw new TypeError(`Expected string map${t?.name?` for ${t.name}`:""}, got: `+e);return n},asNumericDictionary:function(e,t){const n=_(e),r=Object.keys(n),i=Object.values(n);if(!r.every(v)||!i.every(E))throw new TypeError(`Expected numeric dictionary${t?.name?` for ${t.name}`:""}, got: `+e);return n},asUrl:function(e,t){if(!V(e))throw new TypeError(`Expected url${t?.name?` for ${t.name}`:""}, got: `+e);return e},asEmptiable:function(e,t){return""===t?void 0:e(t)},asNullable:function(e,t){return null==t?null:e(t)},asOptional:function(e,t){return null==t?void 0:e(t)},enforceObjectShape:F,enforceArrayShape:function(e,t){return e.every(e=>F(e,t))},isPng:pt,isJpg:mt,isWebp:gt,isImage:function(e){return pt(e)||mt(e)||gt(e)}},e.Strings={tokenizeByCount:function(e,t){return at(e,Math.ceil(e.length/t))},tokenizeByLength:at,searchHex:function(e,t){const n=new RegExp(`[0-9a-f]{${t}}`,"i"),r=e.match(n);return r?r[0]:null},searchSubstring:function(e,t,n=S){const r=Q(e,n);for(const e of r)if(t(e))return e;return null},randomHex:function(e,t=Math.random){let n="";for(let r=0;r<e;r++)n+=D[Math.floor(16*t())];return n},randomLetter:function(e,t=Math.random){let n="";for(let r=0;r<e;r++)n+=k[Math.floor(26*t())];return n},randomAlphanumeric:function(e,t=Math.random){let n="";for(let r=0;r<e;r++)n+=$[Math.floor(62*t())];return n},randomRichAscii:function(e,t=Math.random){let n="";for(let r=0;r<e;r++)n+=I[Math.floor(89*t())];return n},randomUnicode:function(e,t=Math.random){let n="";for(let r=0;r<e;r++)n+=z[Math.floor(t()*z.length)];return n},includesAny:function(e,t){return t.some(t=>e.includes(t))},slugify:G,normalForm:function(e){return G(e).replaceAll("-","")},enumify:function(e){return G(e).replace(/-/g,"_").toUpperCase()},escapeHtml:function(e){return e.replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")},decodeHtmlEntities:function(e){let t=e.replace(/&#(\d+);/g,(e,t)=>String.fromCharCode(t)).replace(/&#x(\d+);/g,(e,t)=>String.fromCharCode(parseInt(t,16)));for(const[e,n]of Object.entries(Z))t=t.replaceAll(e,n);return t},after:K,afterLast:X,before:W,beforeLast:J,betweenWide:function(e,t,n){const r=J(e,n);return r?K(r,t):null},betweenNarrow:function(e,t,n){const r=K(e,t);return r?W(r,n):null},getPreLine:function(e){return e.replace(/ +/g," ").replace(/^ /gm,"")},containsWord:Oe,containsWords:function(e,t,n){return"any"===n?t.some(t=>Oe(e,t)):t.every(t=>Oe(e,t))},joinUrl:Ge,getFuzzyMatchScore:H,sortByFuzzyScore:function(e,t){return e.filter(e=>H(e,t)).sort((e,n)=>H(n,t)-H(e,t))},splitOnce:Y,splitAll:Q,randomize:function(e,t=Math.random){return e.replace(/\{(.+?)\}/g,(e,n)=>u(n.split("|"),t))},expand:function e(t){const n=t.match(/\{(.+?)\}/);if(!n||!n.index)return[t];const r=n[1].split(","),i=t.slice(0,n.index),o=t.slice(n.index+n[0].length);let a=[];for(const t of r){const n=e(i+t+o);a=a.concat(n)}return a},shrinkTrim:ne,capitalize:re,decapitalize:ie,csvEscape:function(e){return e.match(/"|,/)?`"${e.replace(/"/g,'""')}"`:e},parseCsv:function(e,t=",",n='"'){const r=[];let i="",o=!1;const a=e.split("");for(const e of a)e!==t||o?e!==n||(i||o)&&!o?i+=e:o=!o:(r.push(i),i="");return r.push(i),r},surroundInOut:function(e,t){return t+e.split("").join(t)+t},getExtension:ee,getBasename:te,normalizeEmail:function(e){let[t,n]=e.split("@");t=ne(t.replaceAll(".","").toLowerCase()).replaceAll(" ","");const[r]=t.split("+");if(!r||!n||-1===n.indexOf(".")||n.indexOf(".")===n.length-1)throw new Error("Invalid email");return n=ne(n.toLowerCase()).replaceAll(" ",""),`${r}@${n}`},normalizeFilename:function(e){const t=te(e),n=ee(e);return n?`${t}.${n}`:t},parseFilename:function(e){const t=te(e),n=ee(e);return{basename:t,extension:n,filename:n?`${t}.${n}`:t}},camelToTitle:function(e){return re(e.replace(/([A-Z])/g," $1"))},slugToTitle:function(e){return e.split("-").map(re).join(" ")},slugToCamel:function(e){return ie(e.split("-").map(re).join(""))},joinHumanly:function(e,t=", ",n=" and "){return e&&e.length?1===e.length?e[0]:2===e.length?`${e[0]}${n}${e[1]}`:`${e.slice(0,e.length-1).join(t)}${n}${e[e.length-1]}`:""},findWeightedPair:ye,extractBlock:we,extractAllBlocks:function(e,t){const n=[];let r=t.wordBoundary?de(e,[`${t.opening} `,`${t.opening}\n`],t.start||0):e.indexOf(t.opening,t.start||0);for(;;){if(-1===r)return n;const i=we(e,{...t,start:r});if(!i)return n;n.push(i),r=t.wordBoundary?de(e,[`${t.opening} `,`${t.opening}\n`],r+i.length):e.indexOf(t.opening,r+i.length)}},replaceBlocks:function(t,n,r){let i=0;for(;;){const o=e.Strings.extractBlock(t,{...r,start:i});if(!o)return t;const a=n(o);i=t.indexOf(o,i)+a.length,t=t.replace(o,a)}},indexOfEarliest:de,lastIndexOfBefore:ge,parseHtmlAttributes:function(e){const t={},n=e.match(/([a-z\-]+)="([^"]+)"/g);if(n)for(const e of n){const[n,r]=Y(e,"=");t[n]=r.slice(1,r.length-1)}return t},readNextWord:Re,readWordsAfterAll:function(e,t,n=[]){const r=fe(e,t),i=[];for(const o of r)i.push(Re(e,o+t.length,n));return i},resolveVariables:function(e,t,n="$",r=":"){for(const i in t)e=Se(e,i,t[i],n,r);return e=ke(e)},resolveVariableWithDefaultSyntax:Se,resolveRemainingVariablesWithDefaults:ke,isLetter:oe,isDigit:ae,isLetterOrDigit:se,isValidObjectPathCharacter:function(e){return se(e)||"."===e||"["===e||"]"===e||"_"===e},insert:function(e,t,n,r,i){return e.slice(0,t)+r+e.slice(t,t+n)+i+e.slice(t+n)},indexOfRegex:le,allIndexOf:fe,lineMatches:he,linesMatchInOrder:function(e,t,n=!0){let r=0;for(const i of t){let t=!1;for(;!t&&r<e.length;)he(e[r],i,n)&&(t=!0),r++;if(!t)return!1}return!0},represent:function e(t,n="json",r=0){if(t&&b(t.represent)){const e=t.represent();if(v(e))return"json"===n&&0===r?JSON.stringify(e):e}if(m(t,!1)){if(r>1)return"[object Object]";if("json"===n){if(Array.isArray(t)){const n=t.map(t=>e(t,"json",r+1));return 0===r?JSON.stringify(n):n}const n={};t.message&&(n.message=e(t.message,"json",r+1));for(const[i,o]of Object.entries(t))n[i]=e(o,"json",r+1);return 0===r?JSON.stringify(n):n}if("key-value"===n){const n=Object.keys(t);return t.message&&!n.includes("message")&&n.unshift("message"),n.map(n=>`${n}=${JSON.stringify(e(t[n],"json",r+1))}`).join(" ")}}return w(t)&&(t="undefined"),0===r?JSON.stringify(t):t},resolveMarkdownLinks:function(e,t){let n=e.indexOf("](");for(;-1!==n;){const r=ge(e,"[",n),i=e.indexOf(")",n);if(-1!==r&&-1!==i){const[n,o]=e.slice(r+1,i).split("]("),a=t(n,o);e=e.slice(0,r)+a+e.slice(i+1)}n=e.indexOf("](",n+1)}return e},buildUrl:function(e,t,n){return Ge([e,t])+$e(n||{})},isChinese:function(e){return/^[\u4E00-\u9FA5]+$/.test(e)},replaceBetweenStrings:function(e,t,n,r,i=!0){const o=e.indexOf(t),a=e.indexOf(n,o+t.length);if(-1===o||-1===a)throw Error("Start or end not found");return i?e.substring(0,o+t.length)+r+e.substring(a):e.substring(0,o)+r+e.substring(a+n.length)},describeMarkdown:function(e){let t="p";return e.startsWith("#")?(t="h1",e=e.slice(1).trim()):e.startsWith("-")&&(t="li",e=e.slice(1).trim()),{type:t,isCapitalized:e[0]===e[0].toUpperCase(),hasPunctuation:/[.?!]$/.test(e),endsWithColon:/:$/.test(e)}},isBalanced:function(e,t="(",n=")"){let r=0,i=0;for(;i<e.length;)if(e.startsWith(t,i)?(r++,i+=t.length):e.startsWith(n,i)?(r--,i+=n.length):i++,r<0)return!1;return t===n?r%2==0:0===r},textToFormat:function(e){let t=(e=e.normalize("NFD").replace(/[\u0300-\u036f]/g,"")).length;for(;(e=e.replace(/(\w+)[\s,']+\w+/g,"$1")).length!==t;)t=e.length;return e=(e=(e=e.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(e,t){const n=[];let r=0;for(;r<e.length;){const i=e.indexOf(t,r);if(-1===i){n.push({string:e.slice(r),symbol:null});break}const o=e.indexOf(t,i+t.length);if(i>r&&-1!==o&&n.push({string:e.slice(r,i),symbol:null}),-1===o){n.push({string:e.slice(r),symbol:null});break}n.push({string:e.slice(i+t.length,o),symbol:t}),r=o+t.length}return n},splitHashtags:function(e){const t=[];let n=0;for(;n<e.length;){const r=me(e,n);if(-1===r){t.push({string:e.slice(n),symbol:null});break}const i=pe(e,r+1);if(-1===i){t.push({string:e.slice(n,r),symbol:null}),t.push({string:e.slice(r+1),symbol:"#"});break}r>n&&t.push({string:e.slice(n,r),symbol:null}),t.push({string:e.slice(r+1,i),symbol:"#"}),n=i}return t},splitUrls:function(e){const t=[];let n=0;for(;n<e.length;){const r=de(e,["http://","https://"],n);if(-1===r){t.push({string:e.slice(n),symbol:null});break}const i=de(e,[" ","\n"],r);if(-1===i){r>n&&t.push({string:e.slice(n,r),symbol:null}),t.push({string:e.slice(r),symbol:"http"});break}r>n&&t.push({string:e.slice(n,r),symbol:null}),t.push({string:e.slice(r,i),symbol:"http"}),n=i}return t},route:function(e,t){const n=e.split("/").filter(e=>e),r=t.split("/").filter(e=>e);if(n.length!==r.length)return null;const i={};for(let e=0;e<n.length;e++){const t=n[e];if(t.startsWith(":"))i[t.slice(1)]=r[e];else if(t!==r[e])return null}return i},explodeReplace:Be,generateVariants:function(t,n,r,i=Math.random){const o=e.Arrays.shuffle(n.map(t=>({variants:e.Arrays.shuffle(t.variants.map(e=>e),i),avoid:t.avoid})),i),a=[];for(const e of o){const n=e.variants.filter(t=>t!==e.avoid),i=n.find(e=>t.includes(e));if(i&&(L(a,Be(t,i,n)),a.length>=r))break}if(a.length<r)for(const e of o){const n=e.variants.find(e=>t.includes(e));if(n&&(L(a,Be(t,n,e.variants)),a.length>=r))break}return a.slice(0,r)},replaceWord:function(e,t,n,r=!1){const i=new RegExp(r?`(?<=\\s|^)${t}(?=\\s|$)`:`\\b${t}\\b`,"g");return e.replace(i,n)},replacePascalCaseWords:function(e,t){return e.replace(/\b[A-Z][a-zA-Z0-9]*\b/g,e=>e.toUpperCase()===e?e:t(e))},stripHtml:function(e){return e.replace(/<[^>]*>/g,"")},breakLine:Te,measureTextWidth:function(e,t={}){return[...e].reduce((e,n)=>e+(t[n]||1),0)},toLines:function(e,t,n={}){const r=[];let i="",o=0;for(let a=0;a<e.length;a++){const s=e[a];if(i+=s,o+=n[s]||1,o>t){const{line:e,rest:t}=Te(i);r.push(e),i=t,o=t.split("").map(e=>n[e]||1).reduce((e,t)=>e+t,0)}}return i&&r.push(i),r},levenshteinDistance:function(e,t){const n=[];for(let t=0;t<=e.length;t++)n[t]=[t];for(let e=0;e<=t.length;e++)n[0][e]=e;for(let r=1;r<=e.length;r++)for(let i=1;i<=t.length;i++){const o=e[r-1]===t[i-1]?0:1;n[r][i]=Math.min(n[r-1][i]+1,n[r][i-1]+1,n[r-1][i-1]+o)}return n[e.length][t.length]},findCommonPrefix:Ae,findCommonDirectory:function(e){const t=Ae(e),n=t.lastIndexOf("/");return-1===n?"":t.slice(0,n+1)}},e.Assertions={asEqual:function(e,t){if(e!==t)throw Error(`Expected [${e}] to equal [${t}]`);return[e,t]},asTrue:function(e){if(!0!==e)throw Error(`Expected [true], got: [${e}]`);return e},asTruthy:function(e){if(!e)throw Error(`Expected truthy value, got: [${e}]`);return e},asFalse:function(e){if(!1!==e)throw Error(`Expected [false], got: [${e}]`);return e},asFalsy:function(e){if(e)throw Error(`Expected falsy value, got: [${e}]`);return e},asEither:function(e,t){if(!t.includes(e))throw Error(`Expected any of [${t.join(", ")}], got: [${e}]`);return e}},e.Cache={get:async function(e,t,n){const r=Date.now(),i=qe.get(e);if(i&&i.validUntil>r)return i.value;const o=await n(),a=r+t;return qe.set(e,{value:o,validUntil:a}),o},delete:function(e){qe.delete(e)},deleteExpired:function(){const e=Date.now();for(const[t,n]of qe.entries())n.validUntil<=e&&qe.delete(t)},size:function(){return qe.size}},e.Vector={addPoint:Kt,subtractPoint:function(e,t){return{x:e.x-t.x,y:e.y-t.y}},multiplyPoint:Jt,normalizePoint:function(e){const t=Math.sqrt(e.x*e.x+e.y*e.y);return{x:e.x/t,y:e.y/t}},pushPoint:Xt,filterCoordinates:Qt,findCorners:function(e,t,n,r){const i=[{x:0,y:0},{x:n,y:0},{x:0,y:r},{x:n,y:r}];for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const r=on(e,t,n);for(const e of r)i.some(t=>t.x===e.x&&t.y===e.y)||i.push(e)}return i.map(e=>({x:e.x*t,y:e.y*t}))},findLines:function(e,t){const n=Qt(e,(t,n)=>0===e[t][n]&&0!==e[t][n+1],"row-first").map(e=>({...e,dx:1,dy:0})),r=Qt(e,(t,n)=>0===e[t][n]&&0!==e[t][n-1],"row-first").map(e=>({...e,dx:1,dy:0})),i=Qt(e,(t,n)=>0===e[t][n]&&0!==e[t-1]?.[n],"column-first").map(e=>({...e,dx:0,dy:1})),o=Qt(e,(t,n)=>0===e[t][n]&&0!==e[t+1]?.[n],"column-first").map(e=>({...e,dx:0,dy:1}));return n.forEach(e=>e.y++),o.forEach(e=>e.x++),[...ct([...i,...o],(e,t)=>e.x===t.x&&e.y-1===t.y),...ct([...r,...n],(e,t)=>e.y===t.y&&e.x-1===t.x)].map(e=>({start:e[0],end:l(e)})).map(e=>({start:Jt(e.start,t),end:Jt(Kt(e.end,{x:e.start.dx,y:e.start.dy}),t)}))},raycast:cn,raycastCircle:function(e,t,n){const r=an(e,n),i=[];for(const n of r){const r=cn(e,t,n-.001),o=cn(e,t,n+.001);r&&i.push(r),o&&i.push(o)}return i},getLineIntersectionPoint:sn}}(Yr)),Yr),ei=Jr(Qr);ei.Arrays,ei.Assertions;const ti=ei.Binary;ei.Cache;const ni=ei.Dates,ri=ei.Elliptic,ii=ei.Numbers,oi=ei.Objects;ei.Pagination,ei.Promises,ei.Random;const ai=ei.Strings,si=ei.System,ci=ei.Types,ui=ei.Optional;ei.Vector,ei.PubSubChannel,ei.Chunk;const li=ei.MerkleTree,hi=ei.FixedPointNumber;ei.Lazy,ei.AsyncLazy;const fi=ei.AsyncQueue,di=ei.Uint8ArrayReader;ei.Uint8ArrayWriter,ei.TrieRouter;var pi,mi,gi,yi,wi,bi={exports:{}};function vi(){if(mi)return pi;mi=1;var e=1e3,t=60*e,n=60*t,r=24*n,i=7*r,o=365.25*r;function a(e,t,n,r){var i=t>=1.5*n;return Math.round(e/n)+" "+r+(i?"s":"")}return pi=function(s,c){c=c||{};var u=typeof s;if("string"===u&&s.length>0)return function(a){if((a=String(a)).length>100)return;var s=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(a);if(!s)return;var c=parseFloat(s[1]);switch((s[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return c*o;case"weeks":case"week":case"w":return c*i;case"days":case"day":case"d":return c*r;case"hours":case"hour":case"hrs":case"hr":case"h":return c*n;case"minutes":case"minute":case"mins":case"min":case"m":return c*t;case"seconds":case"second":case"secs":case"sec":case"s":return c*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return c;default:return}}(s);if("number"===u&&isFinite(s))return c.long?function(i){var o=Math.abs(i);if(o>=r)return a(i,o,r,"day");if(o>=n)return a(i,o,n,"hour");if(o>=t)return a(i,o,t,"minute");if(o>=e)return a(i,o,e,"second");return i+" ms"}(s):function(i){var o=Math.abs(i);if(o>=r)return Math.round(i/r)+"d";if(o>=n)return Math.round(i/n)+"h";if(o>=t)return Math.round(i/t)+"m";if(o>=e)return Math.round(i/e)+"s";return i+"ms"}(s);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(s))}}var Ei=(wi||(wi=1,function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,i=0;t[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(i=r))}),t.splice(i,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let e;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=(yi||(yi=1,gi=function(e){function t(e){let r,i,o,a=null;function s(...e){if(!s.enabled)return;const n=s,i=Number(new Date),o=i-(r||i);n.diff=o,n.prev=r,n.curr=i,r=i,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let a=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(r,i)=>{if("%%"===r)return"%";a++;const o=t.formatters[i];if("function"==typeof o){const t=e[a];r=o.call(n,t),e.splice(a,1),a--}return r}),t.formatArgs.call(n,e),(n.log||t.log).apply(n,e)}return s.namespace=e,s.useColors=t.useColors(),s.color=t.selectColor(e),s.extend=n,s.destroy=t.destroy,Object.defineProperty(s,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==a?a:(i!==t.namespaces&&(i=t.namespaces,o=t.enabled(e)),o),set:e=>{a=e}}),"function"==typeof t.init&&t.init(s),s}function n(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function r(e,t){let n=0,r=0,i=-1,o=0;for(;n<e.length;)if(r<t.length&&(t[r]===e[n]||"*"===t[r]))"*"===t[r]?(i=r,o=n,r++):(n++,r++);else{if(-1===i)return!1;r=i+1,o++,n=o}for(;r<t.length&&"*"===t[r];)r++;return r===t.length}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names,...t.skips.map(e=>"-"+e)].join(",");return t.enable(""),e},t.enable=function(e){t.save(e),t.namespaces=e,t.names=[],t.skips=[];const n=("string"==typeof e?e:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const e of n)"-"===e[0]?t.skips.push(e.slice(1)):t.names.push(e)},t.enabled=function(e){for(const n of t.skips)if(r(e,n))return!1;for(const n of t.names)if(r(e,n))return!0;return!1},t.humanize=vi(),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach(n=>{t[n]=e[n]}),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t}),gi)(t);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(bi,bi.exports)),bi.exports),xi=Jr(Ei);const Bi=xi("bee-js:bytes"),Ti=new TextDecoder,Ai=new TextEncoder;class Oi{constructor(e,t){if(!e)throw Error(`Bytes#constructor: constructor parameter is falsy: ${e}`);if(e instanceof Oi)this.bytes=e.bytes;else if("string"==typeof e)this.bytes=ti.hexToUint8Array(ci.asHexString(e,{name:"Bytes#constructor(bytes)"}));else if(e instanceof ArrayBuffer)this.bytes=new Uint8Array(e);else if(e instanceof Uint8Array)this.bytes=e;else{const t=e,n=oi.getDeep(t,"toHex");if(!ci.isFunction(n))throw Bi("bytes",e),new Error("Bytes#constructor: unsupported type: "+typeof e);{const e=n.call(t);this.bytes=ti.hexToUint8Array(ci.asHexString(e,{name:"Bytes#constructor(bytes)"}))}}if(this.length=this.bytes.length,t)if(Array.isArray(t)){if(!t.includes(this.length))throw new Error(`Bytes#checkByteLength: bytes length is ${this.length} but expected ${t.join(" or ")}`)}else if(this.length!==t)throw new Error(`Bytes#checkByteLength: bytes length is ${this.length} but expected ${t}`)}static keccak256(e){return new Oi(ti.keccak256(new Oi(e).toUint8Array()))}static fromUtf8(e){return new Oi(Ai.encode(e))}static fromSlice(e,t,n){return new Oi(void 0===n?e.slice(t):e.slice(t,t+n))}offset(e){return new Uint8Array(this.bytes.slice(e))}toUint8Array(){return new Uint8Array(this.bytes)}toHex(){return ti.uint8ArrayToHex(this.bytes)}toBase64(){return ti.uint8ArrayToBase64(this.bytes)}toBase32(){return ti.uint8ArrayToBase32(this.bytes)}toString(){return this.toHex()}toUtf8(){return Ti.decode(this.bytes)}toJSON(){return JSON.parse(this.toUtf8())}equals(e){return this.toHex()===new Oi(e).toHex()}represent(){return this.toHex()}}function Ri(e){const t=e.match(/^([\d.]+)\s*(B|kB|MB|GB|TB|PB)$/);if(!t)throw new Error(`Invalid size format: ${e}`);const n=parseFloat(t[1]),r=t[2];return Math.ceil(n*{B:1,kB:1e3,MB:1e6,GB:1e3**3,TB:1e3**4,PB:1e3**5}[r])}const Si=250,ki=251,$i={[Si]:"manifest",[ki]:"feed"};const Ii=new TextEncoder;class zi extends Oi{constructor(e){super(e,32)}publicKey(){const[e,t]=ri.privateKeyToPublicKey(ti.uint256ToNumber(this.bytes,"BE"));return new Di(ti.concatBytes(ti.numberToUint256(e,"BE"),ti.numberToUint256(t,"BE")))}sign(e){const t=ti.concatBytes(Ii.encode("Ethereum Signed Message:\n32"),ti.keccak256(e instanceof Uint8Array?e:Ii.encode(e))),[n,r,i]=ri.signMessage(t,ti.uint256ToNumber(this.bytes,"BE"));return new Mi(ti.concatBytes(ti.numberToUint256(n,"BE"),ti.numberToUint256(r,"BE"),new Uint8Array([Number(i)])))}}zi.LENGTH=32;class Di extends Oi{constructor(e){const t=new Oi(e);if(33===t.length){const[e,n]=ri.publicKeyFromCompressed(t.toUint8Array());super(ti.concatBytes(ti.numberToUint256(e,"BE"),ti.numberToUint256(n,"BE")),64)}else super(e,64)}address(){const e=ti.uint256ToNumber(this.bytes.slice(0,32),"BE"),t=ti.uint256ToNumber(this.bytes.slice(32,64),"BE");return new Ci(ri.publicKeyToAddress([e,t]))}toCompressedUint8Array(){const e=ti.uint256ToNumber(this.bytes.slice(0,32),"BE"),t=ti.uint256ToNumber(this.bytes.slice(32,64),"BE");return ri.compressPublicKey([e,t])}toCompressedHex(){return ti.uint8ArrayToHex(this.toCompressedUint8Array())}}Di.LENGTH=64;class Ci extends Oi{constructor(e){super(e,20)}toChecksum(){return ri.checksumEncode(this.bytes)}}Ci.LENGTH=20;class Pi extends Oi{constructor(e){super(e,32)}static fromString(e){return new Pi(ti.keccak256(Ii.encode(e)))}}Pi.LENGTH=32;class Ni extends Oi{constructor(e){if("string"==typeof e&&e.startsWith("bah5")){const t=function(e){const t=ti.base32ToUint8Array(e.toUpperCase().slice(1)),n=t[1];if(!$i[n])throw new Error("Unknown codec");const r=new Ni(t.slice(-32));return{type:$i[n],reference:r}}(e);super(t.reference.bytes,32)}else super(e,[32,64])}toCid(e){return function(e,t){e=new Ni(e);const n=new Uint8Array([1]),r=new Uint8Array(["feed"===t?251:250]),i=new Uint8Array([1]),o=new Uint8Array([27]),a=new Uint8Array([32]);return`b${ti.uint8ArrayToBase32(ti.concatBytes(n,r,i,o,a)).replace(/\=+$/,"")}${e.toBase32().replace(/\=+$/,"")}`.toLowerCase()}(this.bytes,e)}static isValid(e){try{return new Ni(e),!0}catch{return!1}}}Ni.LENGTH=32;class Ui extends Oi{constructor(e){super(e,32)}}Ui.LENGTH=32;class _i extends Oi{constructor(e){super(e,8)}static fromBigInt(e){return new _i(ti.numberToUint64(e,"LE"))}toBigInt(){return ti.uint64ToNumber(this.bytes,"LE")}static fromSlice(e,t){return new _i(e.slice(t,t+_i.LENGTH))}}_i.LENGTH=8;class Vi extends Oi{constructor(e){super(e,32)}}Vi.LENGTH=32;class Fi extends Oi{constructor(e){super(e,32)}}Fi.LENGTH=32;class Mi extends Oi{constructor(e){super(e,65)}static fromSlice(e,t){return new Mi(e.slice(t,t+Mi.LENGTH))}recoverPublicKey(e){const t=ti.uint256ToNumber(this.bytes.slice(0,32),"BE"),n=ti.uint256ToNumber(this.bytes.slice(32,64),"BE"),r=BigInt(this.bytes[64]),[i,o]=ri.recoverPublicKey(ti.concatBytes(Ii.encode("Ethereum Signed Message:\n32"),ti.keccak256(e instanceof Uint8Array?e:Ii.encode(e))),t,n,r);return new Di(ti.concatBytes(ti.numberToUint256(i,"BE"),ti.numberToUint256(o,"BE")))}isValid(e,t){return this.recoverPublicKey(e).address().equals(t)}}Mi.LENGTH=65;class ji extends Oi{constructor(e){super(e,32)}static fromString(e){return new ji(ti.keccak256(Ii.encode(e)))}}ji.LENGTH=32;const Li=new Uint8Array(8).fill(255,0,8);class qi extends Oi{constructor(e){super(e,8)}static fromBigInt(e){return new qi(ti.numberToUint64(e,"BE"))}toBigInt(){return ti.uint64ToNumber(this.bytes,"BE")}next(){return ti.equals(this.bytes,Li)?qi.fromBigInt(0n):qi.fromBigInt(this.toBigInt()+1n)}}qi.LENGTH=8,qi.MINUS_ONE=new qi(Li);class Gi extends Error{constructor(e){super(e)}}class Hi extends Gi{constructor(e,t){super(e),this.value=t}}class Zi extends Gi{constructor(e,t,n,r,i,o){super(n),this.method=e,this.url=t,this.responseBody=r,this.status=i,this.statusText=o}}const Wi=4096;function Ki(e){const t=e.slice(0,_i.LENGTH),n=function(e){if(e.length>Wi)throw new Hi(`payload size ${e.length} exceeds maximum chunk payload size 4096`,e);const t=new Uint8Array(Wi);t.set(e);let n=ti.partition(t,32);for(;n.length>1;){const e=[];for(let t=0;t<n.length;t+=2){const r=n[t],i=n[t+1],o=ti.concatBytes(r,i),a=ti.keccak256(o);e.push(a)}n=e}return n[0]}(e.slice(_i.LENGTH)),r=ti.keccak256(ti.concatBytes(t,n));return new Ni(r)}const Ji=4096,Xi=new TextEncoder;function Yi(e){if(e instanceof Uint8Array||(e=Xi.encode(e)),e.length<1||e.length>Ji)throw new RangeError(`payload size ${e.length} exceeds limits [1, 4096]`);const t=_i.fromBigInt(BigInt(e.length)),n=ti.concatBytes(t.toUint8Array(),e);return{data:n,span:t,payload:Oi.fromSlice(n,_i.LENGTH),address:Ki(n)}}function Qi(e){if(e.length<1+_i.LENGTH||e.length>Ji+_i.LENGTH)throw new RangeError(`chunk size ${e.length} exceeds limits [${1+_i.LENGTH}, ${_i.LENGTH}]`);const t=_i.fromSlice(e,0),n=ti.concatBytes(t.toUint8Array(),e.slice(_i.LENGTH));return{data:n,span:t,payload:Oi.fromSlice(n,_i.LENGTH),address:Ki(n)}}var eo;function to(e){switch(e){case"full":return eo.FULL;case"light":return eo.LIGHT;case"ultra-light":return eo.ULTRA_LIGHT;case"dev":return eo.DEV;default:throw new Error(`Unknown Bee mode: ${e}`)}}!function(e){e.FULL="full",e.LIGHT="light",e.ULTRA_LIGHT="ultra-light",e.DEV="dev"}(eo||(eo={}));var no,ro;!function(e){e[e.OFF=0]="OFF",e[e.MEDIUM=1]="MEDIUM",e[e.STRONG=2]="STRONG",e[e.INSANE=3]="INSANE",e[e.PARANOID=4]="PARANOID"}(no||(no={})),function(e){e[e.NONE=0]="NONE",e[e.DATA=1]="DATA",e[e.PROX=2]="PROX",e[e.RACE=3]="RACE"}(ro||(ro={}));const io={ENCRYPTION_OFF:{[no.OFF]:[{theoreticalVolume:"536.87 MB",effectiveVolume:"44.70 kB",batchDepth:17,utilizationRate:"0.01%"},{theoreticalVolume:"1.07 GB",effectiveVolume:"6.66 MB",batchDepth:18,utilizationRate:"0.61%"},{theoreticalVolume:"2.15 GB",effectiveVolume:"112.06 MB",batchDepth:19,utilizationRate:"5.09%"},{theoreticalVolume:"4.29 GB",effectiveVolume:"687.62 MB",batchDepth:20,utilizationRate:"15.65%"},{theoreticalVolume:"8.59 GB",effectiveVolume:"2.60 GB",batchDepth:21,utilizationRate:"30.27%"},{theoreticalVolume:"17.18 GB",effectiveVolume:"7.73 GB",batchDepth:22,utilizationRate:"44.99%"},{theoreticalVolume:"34.36 GB",effectiveVolume:"19.94 GB",batchDepth:23,utilizationRate:"58.03%"},{theoreticalVolume:"68.72 GB",effectiveVolume:"47.06 GB",batchDepth:24,utilizationRate:"68.48%"},{theoreticalVolume:"137.44 GB",effectiveVolume:"105.51 GB",batchDepth:25,utilizationRate:"76.77%"},{theoreticalVolume:"274.88 GB",effectiveVolume:"227.98 GB",batchDepth:26,utilizationRate:"82.94%"},{theoreticalVolume:"549.76 GB",effectiveVolume:"476.68 GB",batchDepth:27,utilizationRate:"86.71%"},{theoreticalVolume:"1.10 TB",effectiveVolume:"993.65 GB",batchDepth:28,utilizationRate:"88.37%"},{theoreticalVolume:"2.20 TB",effectiveVolume:"2.04 TB",batchDepth:29,utilizationRate:"92.88%"},{theoreticalVolume:"4.40 TB",effectiveVolume:"4.17 TB",batchDepth:30,utilizationRate:"94.81%"},{theoreticalVolume:"8.80 TB",effectiveVolume:"8.45 TB",batchDepth:31,utilizationRate:"96.06%"},{theoreticalVolume:"17.59 TB",effectiveVolume:"17.07 TB",batchDepth:32,utilizationRate:"97.01%"},{theoreticalVolume:"35.18 TB",effectiveVolume:"34.36 TB",batchDepth:33,utilizationRate:"97.65%"},{theoreticalVolume:"70.37 TB",effectiveVolume:"69.04 TB",batchDepth:34,utilizationRate:"98.11%"},{theoreticalVolume:"140.74 TB",effectiveVolume:"138.54 TB",batchDepth:35,utilizationRate:"98.44%"},{theoreticalVolume:"281.47 TB",effectiveVolume:"277.72 TB",batchDepth:36,utilizationRate:"98.67%"},{theoreticalVolume:"562.95 TB",effectiveVolume:"556.35 TB",batchDepth:37,utilizationRate:"98.83%"},{theoreticalVolume:"1.13 PB",effectiveVolume:"1.11 PB",batchDepth:38,utilizationRate:"98.91%"},{theoreticalVolume:"2.25 PB",effectiveVolume:"2.23 PB",batchDepth:39,utilizationRate:"98.96%"},{theoreticalVolume:"4.50 PB",effectiveVolume:"4.46 PB",batchDepth:40,utilizationRate:"98.98%"},{theoreticalVolume:"9.01 PB",effectiveVolume:"8.93 PB",batchDepth:41,utilizationRate:"99.11%"}],[no.MEDIUM]:[{theoreticalVolume:"536.87 MB",effectiveVolume:"41.56 kB",batchDepth:17,utilizationRate:"0.01%"},{theoreticalVolume:"1.07 GB",effectiveVolume:"6.19 MB",batchDepth:18,utilizationRate:"0.57%"},{theoreticalVolume:"2.15 GB",effectiveVolume:"104.18 MB",batchDepth:19,utilizationRate:"4.73%"},{theoreticalVolume:"4.29 GB",effectiveVolume:"639.27 MB",batchDepth:20,utilizationRate:"14.54%"},{theoreticalVolume:"8.59 GB",effectiveVolume:"2.41 GB",batchDepth:21,utilizationRate:"28.11%"},{theoreticalVolume:"17.18 GB",effectiveVolume:"7.18 GB",batchDepth:22,utilizationRate:"41.79%"},{theoreticalVolume:"34.36 GB",effectiveVolume:"18.54 GB",batchDepth:23,utilizationRate:"53.95%"},{theoreticalVolume:"68.72 GB",effectiveVolume:"43.75 GB",batchDepth:24,utilizationRate:"63.66%"},{theoreticalVolume:"137.44 GB",effectiveVolume:"98.09 GB",batchDepth:25,utilizationRate:"71.37%"},{theoreticalVolume:"274.88 GB",effectiveVolume:"211.95 GB",batchDepth:26,utilizationRate:"77.11%"},{theoreticalVolume:"549.76 GB",effectiveVolume:"443.16 GB",batchDepth:27,utilizationRate:"80.61%"},{theoreticalVolume:"1.10 TB",effectiveVolume:"923.78 GB",batchDepth:28,utilizationRate:"82.16%"},{theoreticalVolume:"2.20 TB",effectiveVolume:"1.90 TB",batchDepth:29,utilizationRate:"86.30%"},{theoreticalVolume:"4.40 TB",effectiveVolume:"3.88 TB",batchDepth:30,utilizationRate:"88.14%"},{theoreticalVolume:"8.80 TB",effectiveVolume:"7.86 TB",batchDepth:31,utilizationRate:"89.26%"},{theoreticalVolume:"17.59 TB",effectiveVolume:"15.87 TB",batchDepth:32,utilizationRate:"90.21%"},{theoreticalVolume:"35.18 TB",effectiveVolume:"31.94 TB",batchDepth:33,utilizationRate:"90.77%"},{theoreticalVolume:"70.37 TB",effectiveVolume:"64.19 TB",batchDepth:34,utilizationRate:"91.22%"},{theoreticalVolume:"140.74 TB",effectiveVolume:"128.80 TB",batchDepth:35,utilizationRate:"91.52%"},{theoreticalVolume:"281.47 TB",effectiveVolume:"258.19 TB",batchDepth:36,utilizationRate:"91.73%"},{theoreticalVolume:"562.95 TB",effectiveVolume:"517.23 TB",batchDepth:37,utilizationRate:"91.88%"},{theoreticalVolume:"1.13 PB",effectiveVolume:"1.04 PB",batchDepth:38,utilizationRate:"91.95%"},{theoreticalVolume:"2.25 PB",effectiveVolume:"2.07 PB",batchDepth:39,utilizationRate:"92.00%"},{theoreticalVolume:"4.50 PB",effectiveVolume:"4.15 PB",batchDepth:40,utilizationRate:"92.15%"},{theoreticalVolume:"9.01 PB",effectiveVolume:"8.30 PB",batchDepth:41,utilizationRate:"92.14%"}],[no.STRONG]:[{theoreticalVolume:"536.87 MB",effectiveVolume:"37.37 kB",batchDepth:17,utilizationRate:"0.01%"},{theoreticalVolume:"1.07 GB",effectiveVolume:"5.57 MB",batchDepth:18,utilizationRate:"0.51%"},{theoreticalVolume:"2.15 GB",effectiveVolume:"93.68 MB",batchDepth:19,utilizationRate:"4.25%"},{theoreticalVolume:"4.29 GB",effectiveVolume:"574.81 MB",batchDepth:20,utilizationRate:"13.07%"},{theoreticalVolume:"8.59 GB",effectiveVolume:"2.17 GB",batchDepth:21,utilizationRate:"25.26%"},{theoreticalVolume:"17.18 GB",effectiveVolume:"6.46 GB",batchDepth:22,utilizationRate:"37.58%"},{theoreticalVolume:"34.36 GB",effectiveVolume:"16.67 GB",batchDepth:23,utilizationRate:"48.50%"},{theoreticalVolume:"68.72 GB",effectiveVolume:"39.34 GB",batchDepth:24,utilizationRate:"57.24%"},{theoreticalVolume:"137.44 GB",effectiveVolume:"88.20 GB",batchDepth:25,utilizationRate:"64.17%"},{theoreticalVolume:"274.88 GB",effectiveVolume:"190.58 GB",batchDepth:26,utilizationRate:"69.33%"},{theoreticalVolume:"549.76 GB",effectiveVolume:"398.47 GB",batchDepth:27,utilizationRate:"72.48%"},{theoreticalVolume:"1.10 TB",effectiveVolume:"830.63 GB",batchDepth:28,utilizationRate:"73.85%"},{theoreticalVolume:"2.20 TB",effectiveVolume:"1.71 TB",batchDepth:29,utilizationRate:"77.59%"},{theoreticalVolume:"4.40 TB",effectiveVolume:"3.49 TB",batchDepth:30,utilizationRate:"79.27%"},{theoreticalVolume:"8.80 TB",effectiveVolume:"7.07 TB",batchDepth:31,utilizationRate:"80.34%"},{theoreticalVolume:"17.59 TB",effectiveVolume:"14.27 TB",batchDepth:32,utilizationRate:"81.12%"},{theoreticalVolume:"35.18 TB",effectiveVolume:"28.72 TB",batchDepth:33,utilizationRate:"81.63%"},{theoreticalVolume:"70.37 TB",effectiveVolume:"57.71 TB",batchDepth:34,utilizationRate:"82.01%"},{theoreticalVolume:"140.74 TB",effectiveVolume:"115.81 TB",batchDepth:35,utilizationRate:"82.29%"},{theoreticalVolume:"281.47 TB",effectiveVolume:"232.16 TB",batchDepth:36,utilizationRate:"82.48%"},{theoreticalVolume:"562.95 TB",effectiveVolume:"465.07 TB",batchDepth:37,utilizationRate:"82.61%"},{theoreticalVolume:"1.13 PB",effectiveVolume:"931.23 TB",batchDepth:38,utilizationRate:"82.67%"},{theoreticalVolume:"2.25 PB",effectiveVolume:"1.86 PB",batchDepth:39,utilizationRate:"82.71%"},{theoreticalVolume:"4.50 PB",effectiveVolume:"3.73 PB",batchDepth:40,utilizationRate:"82.78%"},{theoreticalVolume:"9.01 PB",effectiveVolume:"7.46 PB",batchDepth:41,utilizationRate:"82.79%"}],[no.INSANE]:[{theoreticalVolume:"536.87 MB",effectiveVolume:"33.88 kB",batchDepth:17,utilizationRate:"0.01%"},{theoreticalVolume:"1.07 GB",effectiveVolume:"5.05 MB",batchDepth:18,utilizationRate:"0.46%"},{theoreticalVolume:"2.15 GB",effectiveVolume:"84.92 MB",batchDepth:19,utilizationRate:"3.86%"},{theoreticalVolume:"4.29 GB",effectiveVolume:"521.09 MB",batchDepth:20,utilizationRate:"11.85%"},{theoreticalVolume:"8.59 GB",effectiveVolume:"1.97 GB",batchDepth:21,utilizationRate:"22.90%"},{theoreticalVolume:"17.18 GB",effectiveVolume:"5.86 GB",batchDepth:22,utilizationRate:"34.09%"},{theoreticalVolume:"34.36 GB",effectiveVolume:"15.11 GB",batchDepth:23,utilizationRate:"43.97%"},{theoreticalVolume:"68.72 GB",effectiveVolume:"35.66 GB",batchDepth:24,utilizationRate:"51.90%"},{theoreticalVolume:"137.44 GB",effectiveVolume:"79.96 GB",batchDepth:25,utilizationRate:"58.18%"},{theoreticalVolume:"274.88 GB",effectiveVolume:"172.77 GB",batchDepth:26,utilizationRate:"62.85%"},{theoreticalVolume:"549.76 GB",effectiveVolume:"361.23 GB",batchDepth:27,utilizationRate:"65.70%"},{theoreticalVolume:"1.10 TB",effectiveVolume:"753.00 GB",batchDepth:28,utilizationRate:"66.95%"},{theoreticalVolume:"2.20 TB",effectiveVolume:"1.55 TB",batchDepth:29,utilizationRate:"70.38%"},{theoreticalVolume:"4.40 TB",effectiveVolume:"3.16 TB",batchDepth:30,utilizationRate:"71.92%"},{theoreticalVolume:"8.80 TB",effectiveVolume:"6.41 TB",batchDepth:31,utilizationRate:"72.85%"},{theoreticalVolume:"17.59 TB",effectiveVolume:"12.93 TB",batchDepth:32,utilizationRate:"73.53%"},{theoreticalVolume:"35.18 TB",effectiveVolume:"26.04 TB",batchDepth:33,utilizationRate:"74.01%"},{theoreticalVolume:"70.37 TB",effectiveVolume:"52.32 TB",batchDepth:34,utilizationRate:"74.35%"},{theoreticalVolume:"140.74 TB",effectiveVolume:"104.99 TB",batchDepth:35,utilizationRate:"74.60%"},{theoreticalVolume:"281.47 TB",effectiveVolume:"210.46 TB",batchDepth:36,utilizationRate:"74.77%"},{theoreticalVolume:"562.95 TB",effectiveVolume:"421.61 TB",batchDepth:37,utilizationRate:"74.89%"},{theoreticalVolume:"1.13 PB",effectiveVolume:"844.20 TB",batchDepth:38,utilizationRate:"74.94%"},{theoreticalVolume:"2.25 PB",effectiveVolume:"1.69 PB",batchDepth:39,utilizationRate:"74.98%"},{theoreticalVolume:"4.50 PB",effectiveVolume:"3.38 PB",batchDepth:40,utilizationRate:"75.03%"},{theoreticalVolume:"9.01 PB",effectiveVolume:"6.77 PB",batchDepth:41,utilizationRate:"75.10%"}],[no.PARANOID]:[{theoreticalVolume:"536.87 MB",effectiveVolume:"13.27 kB",batchDepth:17,utilizationRate:"0.00%"},{theoreticalVolume:"1.07 GB",effectiveVolume:"1.98 MB",batchDepth:18,utilizationRate:"0.18%"},{theoreticalVolume:"2.15 GB",effectiveVolume:"33.27 MB",batchDepth:19,utilizationRate:"1.51%"},{theoreticalVolume:"4.29 GB",effectiveVolume:"204.14 MB",batchDepth:20,utilizationRate:"4.64%"},{theoreticalVolume:"8.59 GB",effectiveVolume:"771.13 MB",batchDepth:21,utilizationRate:"8.75%"},{theoreticalVolume:"17.18 GB",effectiveVolume:"2.29 GB",batchDepth:22,utilizationRate:"13.34%"},{theoreticalVolume:"34.36 GB",effectiveVolume:"5.92 GB",batchDepth:23,utilizationRate:"17.22%"},{theoreticalVolume:"68.72 GB",effectiveVolume:"13.97 GB",batchDepth:24,utilizationRate:"20.33%"},{theoreticalVolume:"137.44 GB",effectiveVolume:"31.32 GB",batchDepth:25,utilizationRate:"22.79%"},{theoreticalVolume:"274.88 GB",effectiveVolume:"67.68 GB",batchDepth:26,utilizationRate:"24.62%"},{theoreticalVolume:"549.76 GB",effectiveVolume:"141.51 GB",batchDepth:27,utilizationRate:"25.74%"},{theoreticalVolume:"1.10 TB",effectiveVolume:"294.99 GB",batchDepth:28,utilizationRate:"26.23%"},{theoreticalVolume:"2.20 TB",effectiveVolume:"606.90 GB",batchDepth:29,utilizationRate:"27.56%"},{theoreticalVolume:"4.40 TB",effectiveVolume:"1.24 TB",batchDepth:30,utilizationRate:"28.15%"},{theoreticalVolume:"8.80 TB",effectiveVolume:"2.51 TB",batchDepth:31,utilizationRate:"28.54%"},{theoreticalVolume:"17.59 TB",effectiveVolume:"5.07 TB",batchDepth:32,utilizationRate:"28.82%"},{theoreticalVolume:"35.18 TB",effectiveVolume:"10.20 TB",batchDepth:33,utilizationRate:"28.99%"},{theoreticalVolume:"70.37 TB",effectiveVolume:"20.50 TB",batchDepth:34,utilizationRate:"29.13%"},{theoreticalVolume:"140.74 TB",effectiveVolume:"41.13 TB",batchDepth:35,utilizationRate:"29.22%"},{theoreticalVolume:"281.47 TB",effectiveVolume:"82.45 TB",batchDepth:36,utilizationRate:"29.29%"},{theoreticalVolume:"562.95 TB",effectiveVolume:"165.17 TB",batchDepth:37,utilizationRate:"29.34%"},{theoreticalVolume:"1.13 PB",effectiveVolume:"330.72 TB",batchDepth:38,utilizationRate:"29.37%"},{theoreticalVolume:"2.25 PB",effectiveVolume:"661.97 TB",batchDepth:39,utilizationRate:"29.39%"},{theoreticalVolume:"4.50 PB",effectiveVolume:"1.32 PB",batchDepth:40,utilizationRate:"29.41%"},{theoreticalVolume:"9.01 PB",effectiveVolume:"2.65 PB",batchDepth:41,utilizationRate:"29.43%"}]},ENCRYPTION_ON:{[no.OFF]:[{theoreticalVolume:"536.87 MB",effectiveVolume:"44.35 kB",batchDepth:17,utilizationRate:"0.01%"},{theoreticalVolume:"1.07 GB",effectiveVolume:"6.61 MB",batchDepth:18,utilizationRate:"0.60%"},{theoreticalVolume:"2.15 GB",effectiveVolume:"111.18 MB",batchDepth:19,utilizationRate:"5.05%"},{theoreticalVolume:"4.29 GB",effectiveVolume:"682.21 MB",batchDepth:20,utilizationRate:"15.52%"},{theoreticalVolume:"8.59 GB",effectiveVolume:"2.58 GB",batchDepth:21,utilizationRate:"30.04%"},{theoreticalVolume:"17.18 GB",effectiveVolume:"7.67 GB",batchDepth:22,utilizationRate:"44.62%"},{theoreticalVolume:"34.36 GB",effectiveVolume:"19.78 GB",batchDepth:23,utilizationRate:"57.56%"},{theoreticalVolume:"68.72 GB",effectiveVolume:"46.69 GB",batchDepth:24,utilizationRate:"67.93%"},{theoreticalVolume:"137.44 GB",effectiveVolume:"104.68 GB",batchDepth:25,utilizationRate:"76.16%"},{theoreticalVolume:"274.88 GB",effectiveVolume:"226.19 GB",batchDepth:26,utilizationRate:"82.29%"},{theoreticalVolume:"549.76 GB",effectiveVolume:"472.93 GB",batchDepth:27,utilizationRate:"86.02%"},{theoreticalVolume:"1.10 TB",effectiveVolume:"985.83 GB",batchDepth:28,utilizationRate:"87.66%"},{theoreticalVolume:"2.20 TB",effectiveVolume:"2.03 TB",batchDepth:29,utilizationRate:"92.25%"},{theoreticalVolume:"4.40 TB",effectiveVolume:"4.14 TB",batchDepth:30,utilizationRate:"94.21%"},{theoreticalVolume:"8.80 TB",effectiveVolume:"8.39 TB",batchDepth:31,utilizationRate:"95.37%"},{theoreticalVolume:"17.59 TB",effectiveVolume:"16.93 TB",batchDepth:32,utilizationRate:"96.22%"},{theoreticalVolume:"35.18 TB",effectiveVolume:"34.09 TB",batchDepth:33,utilizationRate:"96.88%"},{theoreticalVolume:"70.37 TB",effectiveVolume:"68.50 TB",batchDepth:34,utilizationRate:"97.34%"},{theoreticalVolume:"140.74 TB",effectiveVolume:"137.45 TB",batchDepth:35,utilizationRate:"97.67%"},{theoreticalVolume:"281.47 TB",effectiveVolume:"275.53 TB",batchDepth:36,utilizationRate:"97.89%"},{theoreticalVolume:"562.95 TB",effectiveVolume:"551.97 TB",batchDepth:37,utilizationRate:"98.05%"},{theoreticalVolume:"1.13 PB",effectiveVolume:"1.11 PB",batchDepth:38,utilizationRate:"98.13%"},{theoreticalVolume:"2.25 PB",effectiveVolume:"2.21 PB",batchDepth:39,utilizationRate:"98.18%"},{theoreticalVolume:"4.50 PB",effectiveVolume:"4.43 PB",batchDepth:40,utilizationRate:"98.36%"},{theoreticalVolume:"9.01 PB",effectiveVolume:"8.86 PB",batchDepth:41,utilizationRate:"98.37%"}],[no.MEDIUM]:[{theoreticalVolume:"536.87 MB",effectiveVolume:"40.89 kB",batchDepth:17,utilizationRate:"0.01%"},{theoreticalVolume:"1.07 GB",effectiveVolume:"6.09 MB",batchDepth:18,utilizationRate:"0.56%"},{theoreticalVolume:"2.15 GB",effectiveVolume:"102.49 MB",batchDepth:19,utilizationRate:"4.65%"},{theoreticalVolume:"4.29 GB",effectiveVolume:"628.91 MB",batchDepth:20,utilizationRate:"14.30%"},{theoreticalVolume:"8.59 GB",effectiveVolume:"2.38 GB",batchDepth:21,utilizationRate:"27.68%"},{theoreticalVolume:"17.18 GB",effectiveVolume:"7.07 GB",batchDepth:22,utilizationRate:"41.15%"},{theoreticalVolume:"34.36 GB",effectiveVolume:"18.24 GB",batchDepth:23,utilizationRate:"53.09%"},{theoreticalVolume:"68.72 GB",effectiveVolume:"43.04 GB",batchDepth:24,utilizationRate:"62.63%"},{theoreticalVolume:"137.44 GB",effectiveVolume:"96.50 GB",batchDepth:25,utilizationRate:"70.21%"},{theoreticalVolume:"274.88 GB",effectiveVolume:"208.52 GB",batchDepth:26,utilizationRate:"75.86%"},{theoreticalVolume:"549.76 GB",effectiveVolume:"435.98 GB",batchDepth:27,utilizationRate:"79.30%"},{theoreticalVolume:"1.10 TB",effectiveVolume:"908.81 GB",batchDepth:28,utilizationRate:"80.82%"},{theoreticalVolume:"2.20 TB",effectiveVolume:"1.87 TB",batchDepth:29,utilizationRate:"84.98%"},{theoreticalVolume:"4.40 TB",effectiveVolume:"3.81 TB",batchDepth:30,utilizationRate:"86.67%"},{theoreticalVolume:"8.80 TB",effectiveVolume:"7.73 TB",batchDepth:31,utilizationRate:"87.84%"},{theoreticalVolume:"17.59 TB",effectiveVolume:"15.61 TB",batchDepth:32,utilizationRate:"88.74%"},{theoreticalVolume:"35.18 TB",effectiveVolume:"31.43 TB",batchDepth:33,utilizationRate:"89.34%"},{theoreticalVolume:"70.37 TB",effectiveVolume:"63.15 TB",batchDepth:34,utilizationRate:"89.74%"},{theoreticalVolume:"140.74 TB",effectiveVolume:"126.71 TB",batchDepth:35,utilizationRate:"90.03%"},{theoreticalVolume:"281.47 TB",effectiveVolume:"254.01 TB",batchDepth:36,utilizationRate:"90.24%"},{theoreticalVolume:"562.95 TB",effectiveVolume:"508.85 TB",batchDepth:37,utilizationRate:"90.39%"},{theoreticalVolume:"1.13 PB",effectiveVolume:"1.02 PB",batchDepth:38,utilizationRate:"90.47%"},{theoreticalVolume:"2.25 PB",effectiveVolume:"2.04 PB",batchDepth:39,utilizationRate:"90.51%"},{theoreticalVolume:"4.50 PB",effectiveVolume:"4.08 PB",batchDepth:40,utilizationRate:"90.64%"},{theoreticalVolume:"9.01 PB",effectiveVolume:"8.17 PB",batchDepth:41,utilizationRate:"90.65%"}],[no.STRONG]:[{theoreticalVolume:"536.87 MB",effectiveVolume:"36.73 kB",batchDepth:17,utilizationRate:"0.01%"},{theoreticalVolume:"1.07 GB",effectiveVolume:"5.47 MB",batchDepth:18,utilizationRate:"0.50%"},{theoreticalVolume:"2.15 GB",effectiveVolume:"92.07 MB",batchDepth:19,utilizationRate:"4.18%"},{theoreticalVolume:"4.29 GB",effectiveVolume:"564.95 MB",batchDepth:20,utilizationRate:"12.85%"},{theoreticalVolume:"8.59 GB",effectiveVolume:"2.13 GB",batchDepth:21,utilizationRate:"24.86%"},{theoreticalVolume:"17.18 GB",effectiveVolume:"6.35 GB",batchDepth:22,utilizationRate:"36.97%"},{theoreticalVolume:"34.36 GB",effectiveVolume:"16.38 GB",batchDepth:23,utilizationRate:"47.67%"},{theoreticalVolume:"68.72 GB",effectiveVolume:"38.66 GB",batchDepth:24,utilizationRate:"56.26%"},{theoreticalVolume:"137.44 GB",effectiveVolume:"86.69 GB",batchDepth:25,utilizationRate:"63.07%"},{theoreticalVolume:"274.88 GB",effectiveVolume:"187.31 GB",batchDepth:26,utilizationRate:"68.14%"},{theoreticalVolume:"549.76 GB",effectiveVolume:"391.64 GB",batchDepth:27,utilizationRate:"71.24%"},{theoreticalVolume:"1.10 TB",effectiveVolume:"816.39 GB",batchDepth:28,utilizationRate:"72.59%"},{theoreticalVolume:"2.20 TB",effectiveVolume:"1.68 TB",batchDepth:29,utilizationRate:"76.34%"},{theoreticalVolume:"4.40 TB",effectiveVolume:"3.43 TB",batchDepth:30,utilizationRate:"77.89%"},{theoreticalVolume:"8.80 TB",effectiveVolume:"6.94 TB",batchDepth:31,utilizationRate:"78.86%"},{theoreticalVolume:"17.59 TB",effectiveVolume:"14.02 TB",batchDepth:32,utilizationRate:"79.71%"},{theoreticalVolume:"35.18 TB",effectiveVolume:"28.23 TB",batchDepth:33,utilizationRate:"80.23%"},{theoreticalVolume:"70.37 TB",effectiveVolume:"56.72 TB",batchDepth:34,utilizationRate:"80.60%"},{theoreticalVolume:"140.74 TB",effectiveVolume:"113.82 TB",batchDepth:35,utilizationRate:"80.88%"},{theoreticalVolume:"281.47 TB",effectiveVolume:"228.18 TB",batchDepth:36,utilizationRate:"81.06%"},{theoreticalVolume:"562.95 TB",effectiveVolume:"457.10 TB",batchDepth:37,utilizationRate:"81.20%"},{theoreticalVolume:"1.13 PB",effectiveVolume:"915.26 TB",batchDepth:38,utilizationRate:"81.26%"},{theoreticalVolume:"2.25 PB",effectiveVolume:"1.83 PB",batchDepth:39,utilizationRate:"81.30%"},{theoreticalVolume:"4.50 PB",effectiveVolume:"3.67 PB",batchDepth:40,utilizationRate:"81.43%"},{theoreticalVolume:"9.01 PB",effectiveVolume:"7.34 PB",batchDepth:41,utilizationRate:"81.45%"}],[no.INSANE]:[{theoreticalVolume:"536.87 MB",effectiveVolume:"33.26 kB",batchDepth:17,utilizationRate:"0.01%"},{theoreticalVolume:"1.07 GB",effectiveVolume:"4.96 MB",batchDepth:18,utilizationRate:"0.45%"},{theoreticalVolume:"2.15 GB",effectiveVolume:"83.38 MB",batchDepth:19,utilizationRate:"3.79%"},{theoreticalVolume:"4.29 GB",effectiveVolume:"511.65 MB",batchDepth:20,utilizationRate:"11.64%"},{theoreticalVolume:"8.59 GB",effectiveVolume:"1.93 GB",batchDepth:21,utilizationRate:"22.52%"},{theoreticalVolume:"17.18 GB",effectiveVolume:"5.75 GB",batchDepth:22,utilizationRate:"33.50%"},{theoreticalVolume:"34.36 GB",effectiveVolume:"14.84 GB",batchDepth:23,utilizationRate:"43.19%"},{theoreticalVolume:"68.72 GB",effectiveVolume:"35.02 GB",batchDepth:24,utilizationRate:"50.96%"},{theoreticalVolume:"137.44 GB",effectiveVolume:"78.51 GB",batchDepth:25,utilizationRate:"57.12%"},{theoreticalVolume:"274.88 GB",effectiveVolume:"169.64 GB",batchDepth:26,utilizationRate:"61.71%"},{theoreticalVolume:"549.76 GB",effectiveVolume:"354.69 GB",batchDepth:27,utilizationRate:"64.52%"},{theoreticalVolume:"1.10 TB",effectiveVolume:"739.37 GB",batchDepth:28,utilizationRate:"65.74%"},{theoreticalVolume:"2.20 TB",effectiveVolume:"1.52 TB",batchDepth:29,utilizationRate:"69.15%"},{theoreticalVolume:"4.40 TB",effectiveVolume:"3.10 TB",batchDepth:30,utilizationRate:"70.56%"},{theoreticalVolume:"8.80 TB",effectiveVolume:"6.29 TB",batchDepth:31,utilizationRate:"71.48%"},{theoreticalVolume:"17.59 TB",effectiveVolume:"12.70 TB",batchDepth:32,utilizationRate:"72.18%"},{theoreticalVolume:"35.18 TB",effectiveVolume:"25.57 TB",batchDepth:33,utilizationRate:"72.67%"},{theoreticalVolume:"70.37 TB",effectiveVolume:"51.37 TB",batchDepth:34,utilizationRate:"73.00%"},{theoreticalVolume:"140.74 TB",effectiveVolume:"103.08 TB",batchDepth:35,utilizationRate:"73.24%"},{theoreticalVolume:"281.47 TB",effectiveVolume:"206.65 TB",batchDepth:36,utilizationRate:"73.42%"},{theoreticalVolume:"562.95 TB",effectiveVolume:"413.98 TB",batchDepth:37,utilizationRate:"73.54%"},{theoreticalVolume:"1.13 PB",effectiveVolume:"828.91 TB",batchDepth:38,utilizationRate:"73.59%"},{theoreticalVolume:"2.25 PB",effectiveVolume:"1.66 PB",batchDepth:39,utilizationRate:"73.62%"},{theoreticalVolume:"4.50 PB",effectiveVolume:"3.32 PB",batchDepth:40,utilizationRate:"73.72%"},{theoreticalVolume:"9.01 PB",effectiveVolume:"6.64 PB",batchDepth:41,utilizationRate:"73.74%"}],[no.PARANOID]:[{theoreticalVolume:"536.87 MB",effectiveVolume:"13.17 kB",batchDepth:17,utilizationRate:"0.00%"},{theoreticalVolume:"1.07 GB",effectiveVolume:"1.96 MB",batchDepth:18,utilizationRate:"0.18%"},{theoreticalVolume:"2.15 GB",effectiveVolume:"33.01 MB",batchDepth:19,utilizationRate:"1.50%"},{theoreticalVolume:"4.29 GB",effectiveVolume:"202.53 MB",batchDepth:20,utilizationRate:"4.61%"},{theoreticalVolume:"8.59 GB",effectiveVolume:"765.05 MB",batchDepth:21,utilizationRate:"8.68%"},{theoreticalVolume:"17.18 GB",effectiveVolume:"2.28 GB",batchDepth:22,utilizationRate:"13.27%"},{theoreticalVolume:"34.36 GB",effectiveVolume:"5.87 GB",batchDepth:23,utilizationRate:"17.08%"},{theoreticalVolume:"68.72 GB",effectiveVolume:"13.86 GB",batchDepth:24,utilizationRate:"20.17%"},{theoreticalVolume:"137.44 GB",effectiveVolume:"31.08 GB",batchDepth:25,utilizationRate:"22.61%"},{theoreticalVolume:"274.88 GB",effectiveVolume:"67.15 GB",batchDepth:26,utilizationRate:"24.43%"},{theoreticalVolume:"549.76 GB",effectiveVolume:"140.40 GB",batchDepth:27,utilizationRate:"25.54%"},{theoreticalVolume:"1.10 TB",effectiveVolume:"292.67 GB",batchDepth:28,utilizationRate:"26.03%"},{theoreticalVolume:"2.20 TB",effectiveVolume:"602.12 GB",batchDepth:29,utilizationRate:"27.35%"},{theoreticalVolume:"4.40 TB",effectiveVolume:"1.23 TB",batchDepth:30,utilizationRate:"27.94%"},{theoreticalVolume:"8.80 TB",effectiveVolume:"2.49 TB",batchDepth:31,utilizationRate:"28.32%"},{theoreticalVolume:"17.59 TB",effectiveVolume:"5.03 TB",batchDepth:32,utilizationRate:"28.60%"},{theoreticalVolume:"35.18 TB",effectiveVolume:"10.12 TB",batchDepth:33,utilizationRate:"28.77%"},{theoreticalVolume:"70.37 TB",effectiveVolume:"20.34 TB",batchDepth:34,utilizationRate:"28.91%"},{theoreticalVolume:"140.74 TB",effectiveVolume:"40.80 TB",batchDepth:35,utilizationRate:"29.00%"},{theoreticalVolume:"281.47 TB",effectiveVolume:"81.80 TB",batchDepth:36,utilizationRate:"29.06%"},{theoreticalVolume:"562.95 TB",effectiveVolume:"163.87 TB",batchDepth:37,utilizationRate:"29.11%"},{theoreticalVolume:"1.13 PB",effectiveVolume:"328.11 TB",batchDepth:38,utilizationRate:"29.14%"},{theoreticalVolume:"2.25 PB",effectiveVolume:"656.76 TB",batchDepth:39,utilizationRate:"29.16%"},{theoreticalVolume:"4.50 PB",effectiveVolume:"1.31 PB",batchDepth:40,utilizationRate:"29.18%"},{theoreticalVolume:"9.01 PB",effectiveVolume:"2.63 PB",batchDepth:41,utilizationRate:"29.19%"}]}};class oo{constructor(e){this.seconds=Math.ceil(e),e<0&&(this.seconds=0)}static fromMilliseconds(e){return new oo(e/1e3)}static fromSeconds(e){return new oo(e)}static fromHours(e){return new oo(60*e*60)}static fromDays(e){return new oo(24*e*60*60)}static fromWeeks(e){return new oo(7*e*24*60*60)}static fromYears(e){return new oo(365*e*24*60*60)}static fromEndDate(e,t){return new oo((e.getTime()-(t??new Date).getTime())/1e3)}static parseFromString(e){return oo.fromSeconds(ni.make(e)/1e3)}toSeconds(){return this.seconds}toHours(){return this.seconds/60/60}toDays(){return this.seconds/24/60/60}toWeeks(){return this.seconds/7/24/60/60}toYears(){return this.seconds/365/24/60/60}toEndDate(e){return new Date((e??new Date).getTime()+1e3*this.seconds)}represent(){return ni.secondsToHumanTime(this.seconds)}isZero(){return 0===this.seconds}}oo.ZERO=new oo(0);class ao{constructor(e){this.state=e}static fromDecimalString(e){return new ao(hi.fromDecimalString(e,ao.DIGITS))}static fromPLUR(e){return new ao(new hi(e,ao.DIGITS))}toPLURString(){return this.state.toString()}toPLURBigInt(){return this.state.value}toDecimalString(){return this.state.toDecimalString()}toSignificantDigits(e){return this.toDecimalString().slice(0,this.toDecimalString().indexOf(".")+e+1)}plus(e){return new ao(this.state.add(e instanceof ao?e.state:new hi(e,ao.DIGITS)))}minus(e){return new ao(this.state.subtract(e instanceof ao?e.state:new hi(e,ao.DIGITS)))}divide(e){return new ao(this.state.divmod(e)[0])}gt(e){return 1===this.state.compare(e.state)}gte(e){return-1!==this.state.compare(e.state)}lt(e){return-1===this.state.compare(e.state)}lte(e){return 1!==this.state.compare(e.state)}eq(e){return 0===this.state.compare(e.state)}exchangeToDAI(e){return so.fromWei(this.state.exchange("*",new hi(e.toWeiBigInt(),so.DIGITS),so.DIGITS).value)}}ao.DIGITS=16;class so{constructor(e){this.state=e}static fromDecimalString(e){return new so(hi.fromDecimalString(e,so.DIGITS))}static fromWei(e){return new so(new hi(e,so.DIGITS))}toWeiString(){return this.state.toString()}toWeiBigInt(){return this.state.value}toDecimalString(){return this.state.toDecimalString()}toSignificantDigits(e){return this.toDecimalString().slice(0,this.toDecimalString().indexOf(".")+e+1)}plus(e){return new so(this.state.add(e instanceof so?e.state:new hi(e,so.DIGITS)))}minus(e){return new so(this.state.subtract(e instanceof so?e.state:new hi(e,so.DIGITS)))}divide(e){return new so(this.state.divmod(e)[0])}gt(e){return 1===this.state.compare(e.state)}gte(e){return-1!==this.state.compare(e.state)}lt(e){return-1===this.state.compare(e.state)}lte(e){return 1!==this.state.compare(e.state)}eq(e){return 0===this.state.compare(e.state)}exchangeToBZZ(e){return ao.fromPLUR(this.state.exchange("/",new hi(e.toWeiBigInt(),so.DIGITS),ao.DIGITS).value)}}function co(e){if("function"==typeof File&&e instanceof File)return!0;const t=e;return"object"==typeof t&&"string"==typeof t.name&&("function"==typeof t.stream||"function"==typeof t.arrayBuffer)}async function uo(e){return e.arrayBuffer?e.arrayBuffer():new Promise(t=>{const n=new FileReader;n.onload=()=>t(n.result),n.readAsArrayBuffer(e)})}function lo(e,t){return"bigint"==typeof e&&(e=e.toString()),ci.asIntegerString(e,t)}function ho(e){const t=ci.asObject(e,{name:"DownloadOptions"});return{redundancyStrategy:ci.asOptional(e=>ci.asInteger(e,{name:"redundancyStrategy"}),t.redundancyStrategy),fallback:ci.asOptional(e=>ci.asBoolean(e,{name:"fallback"}),t.fallback),timeoutMs:ci.asOptional(e=>ci.asInteger(e,{name:"timeoutMs",min:0}),t.timeoutMs),actPublisher:ci.asOptional(e=>new Di(e),t.actPublisher),actHistoryAddress:ci.asOptional(e=>new Ni(e),t.actHistoryAddress),actTimestamp:ci.asOptional(e=>ci.asNumber(e,{name:"actTimestamp"}),t.actTimestamp)}}function fo(e,t="UploadOptions"){const n=ci.asObject(e,{name:t});return{act:ci.asOptional(e=>ci.asBoolean(e,{name:"act"}),n.act),actHistoryAddress:ci.asOptional(e=>new Ni(e),n.actHistoryAddress),deferred:ci.asOptional(e=>ci.asBoolean(e,{name:"deferred"}),n.deferred),encrypt:ci.asOptional(e=>ci.asBoolean(e,{name:"encrypt"}),n.encrypt),pin:ci.asOptional(e=>ci.asBoolean(e,{name:"pin"}),n.pin),tag:ci.asOptional(e=>ci.asInteger(e,{name:"tag",min:0}),n.tag)}}function po(e){const t=fo(e,"CollectionUploadOptions"),n=ci.asObject(e,{name:"CollectionUploadOptions"});return{...t,errorDocument:ci.asOptional(e=>ci.asString(e,{name:"errorDocument"}),n.errorDocument),indexDocument:ci.asOptional(e=>ci.asString(e,{name:"indexDocument"}),n.indexDocument),redundancyLevel:ci.asOptional(e=>ci.asInteger(e,{name:"redundancyLevel",min:0}),n.redundancyLevel)}}function mo(e){const t=ci.asObject(e,{name:"PostageBatchOptions"});return{gasPrice:ci.asOptional(e=>lo(e,{name:"gasPrice"}),t.gasPrice),immutableFlag:ci.asOptional(e=>ci.asBoolean(e,{name:"immutableFlag"}),t.immutableFlag),label:ci.asOptional(e=>ci.asString(e,{name:"label"}),t.label),waitForUsable:ci.asOptional(e=>ci.asBoolean(e,{name:"waitForUsable"}),t.waitForUsable),waitForUsableTimeout:ci.asOptional(e=>ci.asInteger(e,{name:"waitForUsableTimeout",min:0}),t.waitForUsableTimeout)}}function go(e,t="TransactionOptions"){const n=ci.asObject(e,{name:t});return{gasLimit:ci.asOptional(e=>lo(e,{name:"gasLimit",min:0n}),n.gasLimit),gasPrice:ci.asOptional(e=>lo(e,{name:"gasPrice",min:0n}),n.gasPrice)}}function yo(e){if("string"!=typeof e&&!(e instanceof Uint8Array))throw new TypeError("Data must be either string or Uint8Array!")}function wo(e){if(null==e)throw new TypeError(`Expected number | Tag | string from tagUid, got: ${e}`);if(function(e){try{const t=ci.asObject(e,{name:"Tag"});return ci.asInteger(t.uid,{name:"Tag.uid"}),!0}catch{return!1}}(e))return e.uid;if("number"==typeof e||"string"==typeof e)return ci.asNumber(e,{name:"tagUid",min:0});throw new TypeError(`Expected number | Tag | string from tagUid, got: ${e}`)}so.DIGITS=18;function bo(e,t,n){return e/Math.pow(2,t-n)}function vo(e){return 4096*2**e}const Eo=[[17,4089e-8],[18,.00609],[19,.10249],[20,.62891],[21,2.38],[22,7.07],[23,18.24],[24,43.04],[25,96.5],[26,208.52],[27,435.98],[28,908.81],[29,1870],[30,3810],[31,7730],[32,15610],[33,31430],[34,63150]];function xo(e,t,n){if(e<17)return 0;if(void 0!==t&&void 0!==n){const r=io[t?"ENCRYPTION_ON":"ENCRYPTION_OFF"][n].find(t=>t.batchDepth===e);if(r?.effectiveVolume)return Ri(r.effectiveVolume)}else{const t=Eo.find(([t,n])=>{if(e===t)return n});if(t)return 1e3*t[1]*1e3*1e3}return Math.ceil(.9*vo(e))}function Bo(e,t){return ao.fromPLUR(2n**BigInt(e)*BigInt(t))}function To(e,t,n){return BigInt(e.toSeconds())/BigInt(n)*BigInt(t)+1n}function Ao(e,t,n){if(void 0!==t&&void 0!==n){const r=io[t?"ENCRYPTION_ON":"ENCRYPTION_OFF"][n].find(t=>e.toBytes()<=Ri(t.effectiveVolume));if(r?.effectiveVolume)return r.batchDepth}else for(const[t,n]of Eo)if(e.toBytes()<=1e3*n*1e3*1e3)return t;return 35}function Oo(e){return function(e,t,n,r){if(65!==e.length)throw Error("invalid signature length");if(32!==t.length)throw Error("invalid batch ID length");if(8!==n.length)throw Error("invalid timestamp length");if(8!==r.length)throw Error("invalid index length");return new Oi(ti.concatBytes(t,r,n,e))}(e.signature,e.batchId.toUint8Array(),e.timestamp,e.index)}function Ro(e){return{name:function(e){if(!e)throw new Gi("missing content-disposition header");const t=e.match(/filename\*?=['"]?(?:UTF-\d['"]*)?([^;\r\n"']*)['"]?;?/i);if(t&&t.length>0)return t[1];throw new Gi("invalid content-disposition header")}(e["content-disposition"]),tagUid:function(e){if(!e)return;return parseInt(e,10)}(e["swarm-tag-uid"]),contentType:e["content-type"]||void 0}}function So(e,t){const n={};if(!function(e){if(!ci.isObject(e))return!1;const t=e;return void 0!==t.issuer&&void 0!==t.index&&void 0!==t.signature&&void 0!==t.timestamp&&void 0!==t.batchId}(e)?e&&(e=new Fi(e),n["swarm-postage-batch-id"]=e.toHex()):n["swarm-postage-stamp"]=Oo(e).toHex(),!t)return n;const r=ci.asObject(t);return r.size&&(n["content-length"]=String(r.size)),r.contentType&&(n["content-type"]=String(r.contentType)),r.redundancyLevel&&(n["swarm-redundancy-level"]=String(r.redundancyLevel)),ci.isBoolean(r.act)&&(n["swarm-act"]=String(r.act)),ci.isBoolean(r.pin)&&(n["swarm-pin"]=String(r.pin)),ci.isBoolean(r.encrypt)&&(n["swarm-encrypt"]=r.encrypt.toString()),r.tag&&(n["swarm-tag"]=String(r.tag)),ci.isBoolean(r.deferred)&&(n["swarm-deferred-upload"]=r.deferred.toString()),r.redundancyStrategy&&(n["swarm-redundancy-strategy"]=String(r.redundancyStrategy)),ci.isBoolean(r.fallback)&&(n["swarm-redundancy-fallback-mode"]=r.fallback.toString()),r.timeoutMs&&(n["swarm-chunk-retrieval-timeout"]=String(r.timeoutMs)),r.indexDocument&&(n["swarm-index-document"]=String(r.indexDocument)),r.errorDocument&&(n["swarm-error-document"]=String(r.errorDocument)),r.actPublisher&&(n["swarm-act-publisher"]=new Di(r.actPublisher).toCompressedHex()),r.actHistoryAddress&&(n["swarm-act-history-address"]=new Ni(r.actHistoryAddress).toHex()),r.actTimestamp&&(n["swarm-act-timestamp"]=String(r.actTimestamp)),(r.actPublisher||r.actHistoryAddress||r.actTimestamp)&&(n["swarm-act"]="true"),r.gasPrice&&(n["gas-price"]=String(r.gasPrice)),r.gasLimit&&(n["gas-limit"]=String(r.gasLimit)),n}var ko,$o,Io,zo,Do,Co,Po,No,Uo,_o,Vo,Fo,Mo,jo,Lo,qo,Go,Ho,Zo,Wo,Ko,Jo,Xo,Yo,Qo,ea,ta,na,ra,ia,oa,aa,sa,ca,ua,la,ha,fa,da,pa,ma,ga,ya,wa,ba,va,Ea,xa,Ba,Ta,Aa,Oa,Ra,Sa,ka,$a,Ia,za,Da,Ca,Pa,Na,Ua,_a,Va,Fa,Ma,ja,La,qa,Ga,Ha,Za,Wa,Ka,Ja,Xa,Ya,Qa,es={exports:{}};function ts(){return $o||($o=1,ko=function(e,t){return function(){return e.apply(t,arguments)}}),ko}function ns(){if(zo)return Io;zo=1;var e,t=ts(),n=Object.prototype.toString,r=(e=Object.create(null),function(t){var r=n.call(t);return e[r]||(e[r]=r.slice(8,-1).toLowerCase())});function i(e){return e=e.toLowerCase(),function(t){return r(t)===e}}function o(e){return Array.isArray(e)}function a(e){return void 0===e}var s=i("ArrayBuffer");function c(e){return"number"==typeof e}function u(e){return null!==e&&"object"==typeof e}function l(e){if("object"!==r(e))return!1;var t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}var h=i("Date"),f=i("File"),d=i("Blob"),p=i("FileList");function m(e){return"[object Function]"===n.call(e)}var g=i("URLSearchParams");function y(e,t){if(null!=e)if("object"!=typeof e&&(e=[e]),o(e))for(var n=0,r=e.length;n<r;n++)t.call(null,e[n],n,e);else for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.call(null,e[i],i,e)}var w,b=(w="undefined"!=typeof Uint8Array&&Object.getPrototypeOf(Uint8Array),function(e){return w&&e instanceof w});var v,E=i("HTMLFormElement"),x=(v=Object.prototype.hasOwnProperty,function(e,t){return v.call(e,t)});return Io={isArray:o,isArrayBuffer:s,isBuffer:function(e){return null!==e&&!a(e)&&null!==e.constructor&&!a(e.constructor)&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)},isFormData:function(e){var t="[object FormData]";return e&&("function"==typeof FormData&&e instanceof FormData||n.call(e)===t||m(e.toString)&&e.toString()===t)},isArrayBufferView:function(e){return"undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&s(e.buffer)},isString:function(e){return"string"==typeof e},isNumber:c,isObject:u,isPlainObject:l,isEmptyObject:function(e){return e&&0===Object.keys(e).length&&Object.getPrototypeOf(e)===Object.prototype},isUndefined:a,isDate:h,isFile:f,isBlob:d,isFunction:m,isStream:function(e){return u(e)&&m(e.pipe)},isURLSearchParams:g,isStandardBrowserEnv:function(){var e;return("undefined"==typeof navigator||"ReactNative"!==(e=navigator.product)&&"NativeScript"!==e&&"NS"!==e)&&("undefined"!=typeof window&&"undefined"!=typeof document)},forEach:y,merge:function e(){var t={};function n(n,r){l(t[r])&&l(n)?t[r]=e(t[r],n):l(n)?t[r]=e({},n):o(n)?t[r]=n.slice():t[r]=n}for(var r=0,i=arguments.length;r<i;r++)y(arguments[r],n);return t},extend:function(e,n,r){return y(n,function(n,i){e[i]=r&&"function"==typeof n?t(n,r):n}),e},trim:function(e){return e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")},stripBOM:function(e){return 65279===e.charCodeAt(0)&&(e=e.slice(1)),e},inherits:function(e,t,n,r){e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,n&&Object.assign(e.prototype,n)},toFlatObject:function(e,t,n,r){var i,o,a,s={};if(t=t||{},null==e)return t;do{for(o=(i=Object.getOwnPropertyNames(e)).length;o-- >0;)a=i[o],r&&!r(a,e,t)||s[a]||(t[a]=e[a],s[a]=!0);e=!1!==n&&Object.getPrototypeOf(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},kindOf:r,kindOfTest:i,endsWith:function(e,t,n){e=String(e),(void 0===n||n>e.length)&&(n=e.length),n-=t.length;var r=e.indexOf(t,n);return-1!==r&&r===n},toArray:function(e){if(!e)return null;if(o(e))return e;var t=e.length;if(!c(t))return null;for(var n=new Array(t);t-- >0;)n[t]=e[t];return n},isTypedArray:b,isFileList:p,forEachEntry:function(e,t){for(var n,r=(e&&e[Symbol.iterator]).call(e);(n=r.next())&&!n.done;){var i=n.value;t.call(e,i[0],i[1])}},matchAll:function(e,t){for(var n,r=[];null!==(n=e.exec(t));)r.push(n);return r},isHTMLForm:E,hasOwnProperty:x},Io}function rs(){if(Co)return Do;Co=1;var e=ns();function t(e,t,n,r,i){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),i&&(this.response=i)}e.inherits(t,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code,status:this.response&&this.response.status?this.response.status:null}}});var n=t.prototype,r={};return["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(function(e){r[e]={value:e}}),Object.defineProperties(t,r),Object.defineProperty(n,"isAxiosError",{value:!0}),t.from=function(r,i,o,a,s,c){var u=Object.create(n);return e.toFlatObject(r,u,function(e){return e!==Error.prototype}),t.call(u,r.message,i,o,a,s),u.cause=r,u.name=r.name,c&&Object.assign(u,c),u},Do=t}function is(){return _o?Uo:(_o=1,Uo=No?Po:(No=1,Po="object"==typeof self?self.FormData:window.FormData))}function os(){if(Fo)return Vo;Fo=1;var e=ns(),t=rs(),n=is();function r(t){return e.isPlainObject(t)||e.isArray(t)}function i(t){return e.endsWith(t,"[]")?t.slice(0,-2):t}function o(e,t,n){return e?e.concat(t).map(function(e,t){return e=i(e),!n&&t?"["+e+"]":e}).join(n?".":""):t}var a=e.toFlatObject(e,{},null,function(e){return/^is[A-Z]/.test(e)});return Vo=function(s,c,u){if(!e.isObject(s))throw new TypeError("target must be an object");c=c||new(n||FormData);var l,h=(u=e.toFlatObject(u,{metaTokens:!0,dots:!1,indexes:!1},!1,function(t,n){return!e.isUndefined(n[t])})).metaTokens,f=u.visitor||y,d=u.dots,p=u.indexes,m=(u.Blob||"undefined"!=typeof Blob&&Blob)&&((l=c)&&e.isFunction(l.append)&&"FormData"===l[Symbol.toStringTag]&&l[Symbol.iterator]);if(!e.isFunction(f))throw new TypeError("visitor must be a function");function g(n){if(null===n)return"";if(e.isDate(n))return n.toISOString();if(!m&&e.isBlob(n))throw new t("Blob is not supported. Use a Buffer instead.");return e.isArrayBuffer(n)||e.isTypedArray(n)?m&&"function"==typeof Blob?new Blob([n]):Buffer.from(n):n}function y(t,n,a){var s=t;if(t&&!a&&"object"==typeof t)if(e.endsWith(n,"{}"))n=h?n:n.slice(0,-2),t=JSON.stringify(t);else if(e.isArray(t)&&function(t){return e.isArray(t)&&!t.some(r)}(t)||e.isFileList(t)||e.endsWith(n,"[]")&&(s=e.toArray(t)))return n=i(n),s.forEach(function(t,r){!e.isUndefined(t)&&null!==t&&c.append(!0===p?o([n],r,d):null===p?n:n+"[]",g(t))}),!1;return!!r(t)||(c.append(o(a,n,d),g(t)),!1)}var w=[],b=Object.assign(a,{defaultVisitor:y,convertValue:g,isVisitable:r});if(!e.isObject(s))throw new TypeError("data must be an object");return function t(n,r){if(!e.isUndefined(n)){if(-1!==w.indexOf(n))throw Error("Circular reference detected in "+r.join("."));w.push(n),e.forEach(n,function(n,i){!0===(!(e.isUndefined(n)||null===n)&&f.call(c,n,e.isString(i)?i.trim():i,r,b))&&t(n,r?r.concat(i):[i])}),w.pop()}}(s),c}}function as(){if(jo)return Mo;jo=1;var e=os();function t(e){var t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'\(\)~]|%20|%00/g,function(e){return t[e]})}function n(t,n){this._pairs=[],t&&e(t,this,n)}var r=n.prototype;return r.append=function(e,t){this._pairs.push([e,t])},r.toString=function(e){var n=e?function(n){return e.call(this,n,t)}:t;return this._pairs.map(function(e){return n(e[0])+"="+n(e[1])},"").join("&")},Mo=n}function ss(){if(qo)return Lo;qo=1;var e=ns(),t=as();function n(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}return Lo=function(r,i,o){if(!i)return r;var a=r.indexOf("#");-1!==a&&(r=r.slice(0,a));var s,c=o&&o.encode||n,u=o&&o.serialize;return(s=u?u(i,o):e.isURLSearchParams(i)?i.toString():new t(i,o).toString(c))&&(r+=(-1===r.indexOf("?")?"?":"&")+s),r},Lo}function cs(){if(Wo)return Zo;Wo=1;var e=ns();return Zo=function(t,n){e.forEach(t,function(e,r){r!==n&&r.toUpperCase()===n.toUpperCase()&&(t[n]=e,delete t[r])})}}function us(){return Jo?Ko:(Jo=1,Ko={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1})}function ls(){if(Yo)return Xo;Yo=1;var e=as();return Xo="undefined"!=typeof URLSearchParams?URLSearchParams:e}function hs(){return ia?ra:(ia=1,ra=na?ta:(na=1,ta={isBrowser:!0,classes:{URLSearchParams:ls(),FormData:ea?Qo:(ea=1,Qo=FormData),Blob:Blob},protocols:["http","https","file","blob","url","data"]}))}function fs(){if(aa)return oa;aa=1;var e=ns(),t=os(),n=hs();return oa=function(r,i){return t(r,new n.classes.URLSearchParams,Object.assign({visitor:function(t,r,i,o){return n.isNode&&e.isBuffer(t)?(this.append(r,t.toString("base64")),!1):o.defaultVisitor.apply(this,arguments)}},i))},oa}function ds(){if(ca)return sa;ca=1;var e=ns();return sa=function(t){function n(t,r,i,o){var a=t[o++];if("__proto__"===a)return!0;var s=Number.isFinite(+a),c=o>=t.length;return a=!a&&e.isArray(i)?i.length:a,c?(e.hasOwnProperty(i,a)?i[a]=[i[a],r]:i[a]=r,!s):(i[a]&&e.isObject(i[a])||(i[a]=[]),n(t,r,i[a],o)&&e.isArray(i[a])&&(i[a]=function(e){var t,n,r={},i=Object.keys(e),o=i.length;for(t=0;t<o;t++)r[n=i[t]]=e[n];return r}(i[a])),!s)}if(e.isFormData(t)&&e.isFunction(t.entries)){var r={};return e.forEachEntry(t,function(t,i){n(function(t){return e.matchAll(/\w+|\[(\w*)]/g,t).map(function(e){return"[]"===e[0]?"":e[1]||e[0]})}(t),i,r,0)}),r}return null}}function ps(){if(la)return ua;la=1;var e=rs();return ua=function(t,n,r){var i=r.config.validateStatus;r.status&&i&&!i(r.status)?n(new e("Request failed with status code "+r.status,[e.ERR_BAD_REQUEST,e.ERR_BAD_RESPONSE][Math.floor(r.status/100)-4],r.config,r.request,r)):t(r)}}function ms(){if(fa)return ha;fa=1;var e=ns();return ha=e.isStandardBrowserEnv()?{write:function(t,n,r,i,o,a){var s=[];s.push(t+"="+encodeURIComponent(n)),e.isNumber(r)&&s.push("expires="+new Date(r).toGMTString()),e.isString(i)&&s.push("path="+i),e.isString(o)&&s.push("domain="+o),!0===a&&s.push("secure"),document.cookie=s.join("; ")},read:function(e){var t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}}}function gs(){return pa?da:(pa=1,da=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)})}function ys(){return ga?ma:(ga=1,ma=function(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e})}function ws(){if(wa)return ya;wa=1;var e=gs(),t=ys();return ya=function(n,r,i){var o=!e(r);return n&&(o||!1===i)?t(n,r):r}}function bs(){if(va)return ba;va=1;var e=ns(),t=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"];return ba=function(n){var r,i,o,a={};return n?(e.forEach(n.split("\n"),function(n){if(o=n.indexOf(":"),r=e.trim(n.slice(0,o)).toLowerCase(),i=e.trim(n.slice(o+1)),r){if(a[r]&&t.indexOf(r)>=0)return;a[r]="set-cookie"===r?(a[r]?a[r]:[]).concat([i]):a[r]?a[r]+", "+i:i}}),a):a}}function vs(){if(xa)return Ea;xa=1;var e=ns();return Ea=e.isStandardBrowserEnv()?function(){var t,n=/(msie|trident)/i.test(navigator.userAgent),r=document.createElement("a");function i(e){var t=e;return n&&(r.setAttribute("href",t),t=r.href),r.setAttribute("href",t),{href:r.href,protocol:r.protocol?r.protocol.replace(/:$/,""):"",host:r.host,search:r.search?r.search.replace(/^\?/,""):"",hash:r.hash?r.hash.replace(/^#/,""):"",hostname:r.hostname,port:r.port,pathname:"/"===r.pathname.charAt(0)?r.pathname:"/"+r.pathname}}return t=i(window.location.href),function(n){var r=e.isString(n)?i(n):n;return r.protocol===t.protocol&&r.host===t.host}}():function(){return!0}}function Es(){if(Ta)return Ba;Ta=1;var e=rs();function t(t,n,r){e.call(this,null==t?"canceled":t,e.ERR_CANCELED,n,r),this.name="CanceledError"}return ns().inherits(t,e,{__CANCEL__:!0}),Ba=t}function xs(){return Oa?Aa:(Oa=1,Aa=function(e){var t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""})}function Bs(){if(Sa)return Ra;Sa=1;var e=ns(),t=ps(),n=ms(),r=ss(),i=ws(),o=bs(),a=vs(),s=us(),c=rs(),u=Es(),l=xs(),h=hs();return Ra=function(f){return new Promise(function(d,p){var m,g=f.data,y=f.headers,w=f.responseType,b=f.withXSRFToken;function v(){f.cancelToken&&f.cancelToken.unsubscribe(m),f.signal&&f.signal.removeEventListener("abort",m)}e.isFormData(g)&&e.isStandardBrowserEnv()&&delete y["Content-Type"];var E=new XMLHttpRequest;if(f.auth){var x=f.auth.username||"",B=f.auth.password?unescape(encodeURIComponent(f.auth.password)):"";y.Authorization="Basic "+btoa(x+":"+B)}var T=i(f.baseURL,f.url,f.allowAbsoluteUrls);function A(){if(E){var e="getAllResponseHeaders"in E?o(E.getAllResponseHeaders()):null,n={data:w&&"text"!==w&&"json"!==w?E.response:E.responseText,status:E.status,statusText:E.statusText,headers:e,config:f,request:E};t(function(e){d(e),v()},function(e){p(e),v()},n),E=null}}if(E.open(f.method.toUpperCase(),r(T,f.params,f.paramsSerializer),!0),E.timeout=f.timeout,"onloadend"in E?E.onloadend=A:E.onreadystatechange=function(){E&&4===E.readyState&&(0!==E.status||E.responseURL&&0===E.responseURL.indexOf("file:"))&&setTimeout(A)},E.onabort=function(){E&&(p(new c("Request aborted",c.ECONNABORTED,f,E)),E=null)},E.onerror=function(){p(new c("Network Error",c.ERR_NETWORK,f,E)),E=null},E.ontimeout=function(){var e=f.timeout?"timeout of "+f.timeout+"ms exceeded":"timeout exceeded",t=f.transitional||s;f.timeoutErrorMessage&&(e=f.timeoutErrorMessage),p(new c(e,t.clarifyTimeoutError?c.ETIMEDOUT:c.ECONNABORTED,f,E)),E=null},e.isStandardBrowserEnv()&&(b&&e.isFunction(b)&&(b=b(f)),b||!1!==b&&a(T))){var O=f.xsrfHeaderName&&f.xsrfCookieName&&n.read(f.xsrfCookieName);O&&(y[f.xsrfHeaderName]=O)}"setRequestHeader"in E&&e.forEach(y,function(e,t){void 0===g&&"content-type"===t.toLowerCase()?delete y[t]:E.setRequestHeader(t,e)}),e.isUndefined(f.withCredentials)||(E.withCredentials=!!f.withCredentials),w&&"json"!==w&&(E.responseType=f.responseType),"function"==typeof f.onDownloadProgress&&E.addEventListener("progress",f.onDownloadProgress),"function"==typeof f.onUploadProgress&&E.upload&&E.upload.addEventListener("progress",f.onUploadProgress),(f.cancelToken||f.signal)&&(m=function(e){E&&(p(!e||e.type?new u(null,f,E):e),E.abort(),E=null)},f.cancelToken&&f.cancelToken.subscribe(m),f.signal&&(f.signal.aborted?m():f.signal.addEventListener("abort",m))),g||!1===g||0===g||""===g||(g=null);var R=l(T);R&&-1===h.protocols.indexOf(R)?p(new c("Unsupported protocol "+R+":",c.ERR_BAD_REQUEST,f)):E.send(g)})},Ra}function Ts(){if($a)return ka;$a=1;var e=ns(),t=cs(),n=rs(),r=us(),i=os(),o=fs(),a=hs(),s=ds(),c={"Content-Type":"application/x-www-form-urlencoded"};function u(t,n){!e.isUndefined(t)&&e.isUndefined(t["Content-Type"])&&(t["Content-Type"]=n)}var l,h={transitional:r,adapter:(("undefined"!=typeof XMLHttpRequest||"undefined"!=typeof process&&"[object process]"===Object.prototype.toString.call(process))&&(l=Bs()),l),transformRequest:[function(n,r){t(r,"Accept"),t(r,"Content-Type");var a,c=r&&r["Content-Type"]||"",l=c.indexOf("application/json")>-1,h=e.isObject(n);if(h&&e.isHTMLForm(n)&&(n=new FormData(n)),e.isFormData(n))return l?JSON.stringify(s(n)):n;if(e.isArrayBuffer(n)||e.isBuffer(n)||e.isStream(n)||e.isFile(n)||e.isBlob(n))return n;if(e.isArrayBufferView(n))return n.buffer;if(e.isURLSearchParams(n))return u(r,"application/x-www-form-urlencoded;charset=utf-8"),n.toString();if(h){if(-1!==c.indexOf("application/x-www-form-urlencoded"))return o(n,this.formSerializer).toString();if((a=e.isFileList(n))||c.indexOf("multipart/form-data")>-1){var f=this.env&&this.env.FormData;return i(a?{"files[]":n}:n,f&&new f,this.formSerializer)}}return h||l?(u(r,"application/json"),function(t,n,r){if(e.isString(t))try{return(n||JSON.parse)(t),e.trim(t)}catch(e){if("SyntaxError"!==e.name)throw e}return(r||JSON.stringify)(t)}(n)):n}],transformResponse:[function(t){var r=this.transitional||h.transitional,i=r&&r.forcedJSONParsing,o="json"===this.responseType;if(t&&e.isString(t)&&(i&&!this.responseType||o)){var a=!(r&&r.silentJSONParsing)&&o;try{return JSON.parse(t)}catch(e){if(a){if("SyntaxError"===e.name)throw n.from(e,n.ERR_BAD_RESPONSE,this,null,this.response);throw e}}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:a.classes.FormData,Blob:a.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};return e.forEach(["delete","get","head"],function(e){h.headers[e]={}}),e.forEach(["post","put","patch"],function(t){h.headers[t]=e.merge(c)}),ka=h}function As(){if(za)return Ia;za=1;var e=ns(),t=Ts();return Ia=function(n,r,i,o){var a=this||t;return e.forEach(o,function(e){n=e.call(a,n,r,i)}),n},Ia}function Os(){return Ca?Da:(Ca=1,Da=function(e){return!(!e||!e.__CANCEL__)})}function Rs(){if(Na)return Pa;Na=1;var e=ns(),t=As(),n=Os(),r=Ts(),i=Es(),o=cs();function a(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new i}return Pa=function(i){return a(i),i.headers=i.headers||{},i.data=t.call(i,i.data,i.headers,null,i.transformRequest),o(i.headers,"Accept"),o(i.headers,"Content-Type"),i.headers=e.merge(i.headers.common||{},i.headers[i.method]||{},i.headers),e.forEach(["delete","get","head","post","put","patch","common"],function(e){delete i.headers[e]}),(i.adapter||r.adapter)(i).then(function(e){return a(i),e.data=t.call(i,e.data,e.headers,e.status,i.transformResponse),e},function(e){return n(e)||(a(i),e&&e.response&&(e.response.data=t.call(i,e.response.data,e.response.headers,e.response.status,i.transformResponse))),Promise.reject(e)})},Pa}function Ss(){if(_a)return Ua;_a=1;var e=ns();return Ua=function(t,n){n=n||{};var r={};function i(t,n){return e.isPlainObject(t)&&e.isPlainObject(n)?e.merge(t,n):e.isEmptyObject(n)?e.merge({},t):e.isPlainObject(n)?e.merge({},n):e.isArray(n)?n.slice():n}function o(r){return e.isUndefined(n[r])?e.isUndefined(t[r])?void 0:i(void 0,t[r]):i(t[r],n[r])}function a(t){if(!e.isUndefined(n[t]))return i(void 0,n[t])}function s(r){return e.isUndefined(n[r])?e.isUndefined(t[r])?void 0:i(void 0,t[r]):i(void 0,n[r])}function c(e){return e in n?i(t[e],n[e]):e in t?i(void 0,t[e]):void 0}var u={url:a,method:a,data:a,baseURL:s,transformRequest:s,transformResponse:s,paramsSerializer:s,timeout:s,timeoutMessage:s,withCredentials:s,withXSRFToken:s,adapter:s,responseType:s,xsrfCookieName:s,xsrfHeaderName:s,onUploadProgress:s,onDownloadProgress:s,decompress:s,maxContentLength:s,maxBodyLength:s,beforeRedirect:s,transport:s,httpAgent:s,httpsAgent:s,cancelToken:s,socketPath:s,responseEncoding:s,validateStatus:c};return e.forEach(Object.keys(t).concat(Object.keys(n)),function(t){var n=u[t]||o,i=n(t);e.isUndefined(i)&&n!==c||(r[t]=i)}),r},Ua}function ks(){return Fa?Va:(Fa=1,Va={version:"0.30.2"})}function $s(){if(ja)return Ma;ja=1;var e=ks().version,t=rs(),n={};["object","boolean","number","function","string","symbol"].forEach(function(e,t){n[e]=function(n){return typeof n===e||"a"+(t<1?"n ":" ")+e}});var r={};return n.transitional=function(n,i,o){function a(t,n){return"[Axios v"+e+"] Transitional option '"+t+"'"+n+(o?". "+o:"")}return function(e,o,s){if(!1===n)throw new t(a(o," has been removed"+(i?" in "+i:"")),t.ERR_DEPRECATED);return i&&!r[o]&&(r[o]=!0,console.warn(a(o," has been deprecated since v"+i+" and will be removed in the near future"))),!n||n(e,o,s)}},Ma={assertOptions:function(e,n,r){if("object"!=typeof e)throw new t("options must be an object",t.ERR_BAD_OPTION_VALUE);for(var i=Object.keys(e),o=i.length;o-- >0;){var a=i[o],s=n[a];if(s){var c=e[a],u=void 0===c||s(c,a,e);if(!0!==u)throw new t("option "+a+" must be "+u,t.ERR_BAD_OPTION_VALUE)}else if(!0!==r)throw new t("Unknown option "+a,t.ERR_BAD_OPTION)}},validators:n}}function Is(){if(qa)return La;qa=1;var e=ns(),t=ss(),n=function(){if(Ho)return Go;Ho=1;var e=ns();function t(){this.handlers=[]}return t.prototype.use=function(e,t,n){return this.handlers.push({fulfilled:e,rejected:t,synchronous:!!n&&n.synchronous,runWhen:n?n.runWhen:null}),this.handlers.length-1},t.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},t.prototype.clear=function(){this.handlers&&(this.handlers=[])},t.prototype.forEach=function(t){e.forEach(this.handlers,function(e){null!==e&&t(e)})},Go=t}(),r=Rs(),i=Ss(),o=ws(),a=$s(),s=a.validators;function c(e){this.defaults=e,this.interceptors={request:new n,response:new n}}return c.prototype.request=function(t,n){"string"==typeof t?(n=n||{}).url=t:n=t||{},(n=i(this.defaults,n)).method?n.method=n.method.toLowerCase():this.defaults.method?n.method=this.defaults.method.toLowerCase():n.method="get";var o=n.transitional;void 0!==o&&a.assertOptions(o,{silentJSONParsing:s.transitional(s.boolean),forcedJSONParsing:s.transitional(s.boolean),clarifyTimeoutError:s.transitional(s.boolean)},!1);var c=n.paramsSerializer;null!=c&&(e.isFunction(c)?n.paramsSerializer={serialize:c}:a.assertOptions(c,{encode:s.function,serialize:s.function},!0));var u=[],l=!0;this.interceptors.request.forEach(function(e){"function"==typeof e.runWhen&&!1===e.runWhen(n)||(l=l&&e.synchronous,u.unshift(e.fulfilled,e.rejected))});var h,f=[];if(this.interceptors.response.forEach(function(e){f.push(e.fulfilled,e.rejected)}),!l){var d=[r,void 0];for(Array.prototype.unshift.apply(d,u),d=d.concat(f),h=Promise.resolve(n);d.length;)h=h.then(d.shift(),d.shift());return h}for(var p=n;u.length;){var m=u.shift(),g=u.shift();try{p=m(p)}catch(e){g(e);break}}try{h=r(p)}catch(e){return Promise.reject(e)}for(;f.length;)h=h.then(f.shift(),f.shift());return h},c.prototype.getUri=function(e){e=i(this.defaults,e);var n=o(e.baseURL,e.url,e.allowAbsoluteUrls);return t(n,e.params,e.paramsSerializer)},e.forEach(["delete","get","head","options"],function(e){c.prototype[e]=function(t,n){return this.request(i(n||{},{method:e,url:t,data:(n||{}).data}))}}),e.forEach(["post","put","patch"],function(e){function t(t){return function(n,r,o){return this.request(i(o||{},{method:e,headers:t?{"Content-Type":"multipart/form-data"}:{},url:n,data:r}))}}c.prototype[e]=t(),c.prototype[e+"Form"]=t(!0)}),La=c}function zs(){if(Xa)return es.exports;Xa=1;var e=ns(),t=ts(),n=Is(),r=Ss(),i=Ts(),o=ds();var a=function i(o){var a=new n(o),s=t(n.prototype.request,a);return e.extend(s,n.prototype,a),e.extend(s,a),s.create=function(e){return i(r(o,e))},s}(i);return a.Axios=n,a.CanceledError=Es(),a.CancelToken=function(){if(Ha)return Ga;Ha=1;var e=Es();function t(t){if("function"!=typeof t)throw new TypeError("executor must be a function.");var n;this.promise=new Promise(function(e){n=e});var r=this;this.promise.then(function(e){if(r._listeners){for(var t=r._listeners.length;t-- >0;)r._listeners[t](e);r._listeners=null}}),this.promise.then=function(e){var t,n=new Promise(function(e){r.subscribe(e),t=e}).then(e);return n.cancel=function(){r.unsubscribe(t)},n},t(function(t,i,o){r.reason||(r.reason=new e(t,i,o),n(r.reason))})}return t.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},t.prototype.subscribe=function(e){this.reason?e(this.reason):this._listeners?this._listeners.push(e):this._listeners=[e]},t.prototype.unsubscribe=function(e){if(this._listeners){var t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1)}},t.source=function(){var e;return{token:new t(function(t){e=t}),cancel:e}},Ga=t}(),a.isCancel=Os(),a.VERSION=ks().version,a.toFormData=os(),a.AxiosError=rs(),a.Cancel=a.CanceledError,a.all=function(e){return Promise.all(e)},a.spread=Wa?Za:(Wa=1,Za=function(e){return function(t){return e.apply(null,t)}}),a.isAxiosError=function(){if(Ja)return Ka;Ja=1;var e=ns();return Ka=function(t){return e.isObject(t)&&!0===t.isAxiosError}}(),a.formToJSON=function(t){return o(e.isHTMLForm(t)?new FormData(t):t)},es.exports=a,es.exports.default=a,es.exports}var Ds=Jr(Qa?Ya:(Qa=1,Ya=zs()));const Cs=xi("bee-js:http"),{AxiosError:Ps}=Ds,Ns=ni.minutes(1)/200,Us={headers:{accept:"application/json, text/plain, */*"},maxBodyLength:1/0,maxContentLength:1/0};async function _s(e,t){const n=oi.deepMerge3(Us,t,e);if(n.data&&"undefined"!=typeof Buffer&&Buffer.isBuffer(n.data)&&(n.data=n.data.buffer.slice(n.data.byteOffset,n.data.byteOffset+n.data.byteLength)),n.params){const e=Object.keys(n.params);for(const t of e){void 0===n.params[t]&&delete n.params[t]}}let r=0;for(;r<1e5;)try{Cs(`${n.method||"get"} ${ai.joinUrl([n.baseURL,n.url])}`,{headers:{...n.headers},params:n.params}),Vs(e,n);return await Ds(n)}catch(n){if(!(n instanceof Ps))throw n;if("ECONNABORTED"!==n.code||!e.endlesslyRetry)throw new Zi(t.method||"get",t.url||"<unknown>",n.message,n.response?.data,n.response?.status,n.code);r++,await si.sleepMillis(r<Ns?200:1e3)}throw Error("Max number of failed attempts reached")}function Vs(e,t){e.onRequest&&e.onRequest({method:t.method||"GET",url:ai.joinUrl([t.baseURL,t.url]),headers:{...t.headers},params:t.params})}const Fs="chunks";async function Ms(e,t,n){t=new Ni(t);const r=await _s(e,{responseType:"arraybuffer",url:`${Fs}/${t}`,headers:So(null,n)});return new Uint8Array(r.data)}const js=Pi.LENGTH,Ls=js+Mi.LENGTH,qs=Ls+_i.LENGTH;function Gs(e,t){e=e instanceof Oi?e.toUint8Array():e,t=new Ni(t);const n=function(e){const t=Ki(e.slice(Ls)),n=Mi.fromSlice(e,js),r=Oi.fromSlice(e,0,Pi.LENGTH),i=ti.concatBytes(r.toUint8Array(),t.toUint8Array());return n.recoverPublicKey(i).address()}(e),r=Oi.fromSlice(e,0,Pi.LENGTH),i=new Ni(ti.keccak256(ti.concatBytes(r.toUint8Array(),n.toUint8Array())));if(!ti.equals(t.toUint8Array(),i.toUint8Array()))throw new Gi("SOC Data does not match given address!");return{data:e,identifier:r,signature:Mi.fromSlice(e,js),span:_i.fromSlice(e,Ls),payload:Oi.fromSlice(e,qs),address:i,owner:n}}function Hs(e,t){return new Ni(ti.keccak256(ti.concatBytes(e.toUint8Array(),t.toUint8Array())))}function Zs(e,t,n){const r=Hs(t=new Pi(t),(n=new zi(n)).publicKey().address()),i=n.sign(ti.concatBytes(t.toUint8Array(),e.address.toUint8Array()));return{data:ti.concatBytes(t.toUint8Array(),i.toUint8Array(),e.data),identifier:t,signature:i,span:_i.fromSlice(e.data,0),payload:Oi.fromSlice(e.data,_i.LENGTH),address:r,owner:n.publicKey().address()}}async function Ws(e,t,n,r){const i=ti.concatBytes(t.span.toUint8Array(),t.payload.toUint8Array());return async function(e,t,n,r,i,o,a){const s=await _s(e,{method:"post",url:`soc/${t}/${n}`,data:i,headers:{"content-type":"application/octet-stream",...So(o,a)},responseType:"json",params:{sig:r.toHex()}}),c=ci.asObject(s.data,{name:"response.data"});return{reference:new Ni(ci.asHexString(c.reference)),tagUid:s.headers["swarm-tag"]?wo(s.headers["swarm-tag"]):void 0,historyAddress:s.headers["swarm-act-history-address"]?ui.of(new Ni(s.headers["swarm-act-history-address"])):ui.empty()}}(e,t.owner,t.identifier,t.signature,i,n,r)}async function Ks(e,t,n,r,i,o){t=new zi(t),r=new Pi(r);return Ws(e,Zs(Yi(i),r,t),n,o)}async function Js(e,t,n){const r=Hs(n=new Pi(n),t=new Ci(t));return Gs(await Ms(e,r.toHex()),r)}const Xs="bytes";async function Ys(e,t,n,r){const i=await _s(e,{url:Xs,method:"post",responseType:"json",data:t,headers:{"content-type":"application/octet-stream",...So(n,r)}}),o=ci.asObject(i.data,{name:"response.data"});return{reference:new Ni(ci.asHexString(o.reference)),tagUid:i.headers["swarm-tag"]?wo(i.headers["swarm-tag"]):void 0,historyAddress:i.headers["swarm-act-history-address"]?ui.of(new Ni(i.headers["swarm-act-history-address"])):ui.empty()}}async function Qs(e,t,n){n&&(n=ho(n));const r=await _s(e,{responseType:"arraybuffer",url:`${Xs}/${t}`,headers:So(null,n)});return new Oi(r.data)}const ec="feeds";function tc(e){const t=e["swarm-feed-index"],n=e["swarm-feed-index-next"];if(!t)throw new Gi("Response did not contain expected swarm-feed-index!");if(!n)throw new Gi("Response did not contain expected swarm-feed-index-next!");return{feedIndex:new qi(t),feedIndexNext:new qi(n)}}async function nc(e,t,n,r){const i=await _s(e,{responseType:"arraybuffer",url:`${ec}/${t}/${n}`,params:r});return{payload:new Oi(i.data),...tc(i.headers)}}class rc{constructor(e){this.raw=e}toString(){return ci.isString(this.raw)&&this.raw.includes(".eth")?this.raw:new Ni(this.raw).toHex()}}function ic(e,t){return t="number"==typeof t?qi.fromBigInt(BigInt(t)):t,new Pi(ti.keccak256(ti.concatBytes(e.toUint8Array(),t.toUint8Array())))}async function oc(e,t,n){try{const r=await nc(e,t,n);if(!r.feedIndexNext)throw Error("Feed index next is not defined. This should happen when fetching an exact index.");return r.feedIndexNext}catch(e){if(e instanceof Zi)return qi.fromBigInt(0n);throw e}}async function ac(e,t,n,r,i,o){const a=ic(n,o?.index??await oc(e,t.publicKey().address(),n));if(r.length>4096){const n=await Ys(e,r,i,o);return async function(e,t,n,r,i,o){return t=new zi(t),r=new Pi(r),Ws(e,Zs(Qi(i),r,t),n,o)}(e,t,i,a,await Ms(e,n.reference),o)}return Ks(e,t,i,a,ci.isString(r)?Oi.fromUtf8(r).toUint8Array():r,o)}function sc(e,t,n){const r=ic(t,n);return new Ni(ti.keccak256(ti.concatBytes(r.toUint8Array(),e.toUint8Array())))}async function cc(e,t,n,r,i=!1){const o=sc(t,n,r="number"==typeof r?qi.fromBigInt(BigInt(r)):r),a=Gs(await Ms(e,o.toHex()),o);let s=ui.empty();if(i){const e=Oi.fromSlice(a.payload.toUint8Array(),0,8);s=ui.of(Number(ti.uint64ToNumber(e.toUint8Array(),"BE")))}return{timestamp:s,payload:new Oi(a.payload.offset(i?8:0))}}async function uc(e,t,n,r){const i=sc(t,n,r="number"==typeof r?qi.fromBigInt(BigInt(r)):r);return Qi((await Ms(e,i)).slice(Pi.LENGTH+Mi.LENGTH))}function lc(e,t,n){const r=async r=>{if(void 0===r?.index)return nc(e,n,t);const i=await cc(e,n,t,r.index,r.hasTimestamp??!0),o="number"==typeof r.index?qi.fromBigInt(BigInt(r.index)):r.index;return{payload:i.payload,feedIndex:o,feedIndexNext:o.next()}};return{download:r,downloadPayload:async r=>{if(void 0===r?.index)return nc(e,n,t);const i=await uc(e,n,t,r.index),o=i.span.toBigInt()<=4096n?i.payload:await Qs(e,new rc(i.address)),a="number"==typeof r.index?qi.fromBigInt(BigInt(r.index)):r.index;return{payload:o,feedIndex:a,feedIndexNext:a.next()}},downloadReference:async i=>{let o=i?.index;void 0===o&&(o=(await async function(e,t,n){return tc((await _s(e,{responseType:"arraybuffer",url:`${ec}/${t}/${n}`,params:{"Swarm-Only-Root-Chunk":!0}})).headers)}(e,n,t)).feedIndex);const a=await r({...i,index:o});return{reference:new Ni(a.payload.toUint8Array()),feedIndex:a.feedIndex,feedIndexNext:a.feedIndexNext??a.feedIndex.next()}},owner:n,topic:t}}function hc(e,t,n){const r=async(r,i,o)=>async function(e,t,n,r,i,o){r=new Ni(r);const a=ic(n,o?.index??await oc(e,t.publicKey().address(),n)),s=o?.at??Date.now()/1e3,c=ti.numberToUint64(BigInt(Math.floor(s)),"BE");return Ks(e,t,i,a,ti.concatBytes(c,r.toUint8Array()),o)}(e,n,t,i,r,o);return{...lc(e,t,n.publicKey().address()),upload:r,uploadReference:r,uploadPayload:async(r,i,o)=>ac(e,n,t,i,r,o)}}async function fc(e,t,n,r,i,o){const a=function(e,t,n){const r=n.toBigInt(),i=[];for(let n=0n;n<=r;n++)i.push(sc(e,t,qi.fromBigInt(n)));return i}(t,n,r).map(async t=>async function(e,t,n,r){try{return await e.downloadChunk(t,n,r),!0}catch(e){const t=oi.getDeep(e,"status");if(404===t||500===t)return!1;throw e}}(e,t,i,o));return(await Promise.all(a)).every(e=>e)}function dc(e){if(!function(e){return!!Array.isArray(e)&&e.every(e=>"object"==typeof e&&e.path&&void 0!==e.size)}(e))throw new Hi("invalid collection",e)}function pc(e){if(e.webkitRelativePath&&""!==e.webkitRelativePath)return e.webkitRelativePath.replace(/.*?\//i,"");if(e.name)return e.name;throw new TypeError("file is not valid File object")}class mc{constructor(){this.pieces=[],this.currentFileSize=0}get output(){return this.pieces.reduce((e,t)=>{const n=new Uint8Array(e.length+t.length);return n.set(e),n.set(t,e.length),n})}beginFile(e,t){if(e.length>100)throw new Error(`File name too long: ${e}`);const n=function(e,t){const n=new TextEncoder;function r(e,t,r){const o=n.encode(e);i.set(o.slice(0,r),t)}const i=new Uint8Array(512);i.fill(0,0,512),r(e.slice(0,100).padEnd(100,"\0"),0,100),r("0000777\0",100,8),r("0001750\0",108,8),r("0001750\0",116,8),r(t.toString(8).padStart(11,"0")+"\0",124,12);r(Math.floor((new Date).getTime()/1e3).toString(8).padStart(11,"0")+"\0",136,12),r(" ",148,8),r("0",156,1),r("ustar\0\0",257,8);let o=0;for(let e=0;e<512;e++)o+=i[e];return r(o.toString(8).padStart(6,"0")+"\0 ",148,8),i}(e,t);this.pieces.push(n),this.currentFileSize=0}async appendFile(e){this.pieces.push(e),this.currentFileSize+=e.length}async endFile(){const e=this.currentFileSize%512==0?0:512-this.currentFileSize%512;e>0&&this.pieces.push(new Uint8Array(e))}async end(){this.pieces.push(new Uint8Array(1024))}}async function gc(e,t,n,r){const i=new mc;await async function(e,t){for(const n of e){if(!n.file)throw new Error("Invalid collection item");t.beginFile(n.path,n.file.size),await t.appendFile(new Uint8Array(await uo(n.file))),await t.endFile()}}(t,i),await i.end();return await _s(e,{method:"post",url:"bzz",data:i.output,responseType:"json",headers:{"content-type":"application/x-tar","swarm-collection":"true",...So(n,r)}})}const yc="bzz";async function wc(e,t,n,r,i){const o=await _s(e,{method:"post",url:yc,data:t,headers:So(n,i),params:{name:r},responseType:"json"}),a=ci.asObject(o.data,{name:"response.data"});return{reference:new Ni(ci.asHexString(a.reference)),tagUid:o.headers["swarm-tag"]?wo(o.headers["swarm-tag"]):void 0,historyAddress:o.headers["swarm-act-history-address"]?ui.of(new Ni(o.headers["swarm-act-history-address"])):ui.empty()}}async function bc(e,t,n,r){dc(t);const i=await gc(e,t,n,r),o=ci.asObject(i.data,{name:"response.data"});return{reference:new Ni(ci.asHexString(o.reference)),tagUid:i.headers["swarm-tag"]?wo(i.headers["swarm-tag"]):void 0,historyAddress:i.headers["swarm-act-history-address"]?ui.of(new Ni(i.headers["swarm-act-history-address"])):ui.empty()}}const vc=xi("bee-js:manifest"),Ec=new TextEncoder,xc=new TextDecoder,Bc=new Uint8Array([47]),Tc=ti.hexToUint8Array("5768b3b6a7db56d21d1abff40d41cebfc83448fed8d7e9b06ec0d3b073f28f7b");class Ac{constructor(e,t){this.prefix=e,this.node=t}static split(e,t){const n=ti.commonPrefix(e.prefix,t.prefix);if(n.length===e.prefix.length){const r=t.prefix.slice(n.length);return t.node.path=t.prefix.slice(n.length),t.prefix=t.prefix.slice(n.length),t.node.parent=e.node,e.node.forks.set(r[0],t),e}if(n.length===t.prefix.length){const r=e.prefix.slice(n.length);return e.node.path=e.prefix.slice(n.length),e.prefix=e.prefix.slice(n.length),e.node.parent=t.node,t.node.forks.set(r[0],e),t}const r=new Oc({path:n}),i=new Ac(e.prefix.slice(n.length),e.node),o=new Ac(t.prefix.slice(n.length),t.node);return e.node.path=e.prefix.slice(n.length),t.node.path=t.prefix.slice(n.length),e.prefix=e.prefix.slice(n.length),t.prefix=t.prefix.slice(n.length),r.forks.set(i.prefix[0],i),r.forks.set(o.prefix[0],o),i.node.parent=r,o.node.parent=r,new Ac(n,r)}marshal(){if(!this.node.selfAddress)throw Error("Fork#marshal node.selfAddress is not set");const e=[];if(e.push(new Uint8Array([this.node.determineType()])),e.push(ti.numberToUint8(this.prefix.length)),e.push(this.prefix),this.prefix.length<30&&e.push(new Uint8Array(30-this.prefix.length)),e.push(this.node.selfAddress),vc("marshalling fork",{prefixLength:this.prefix.length,prefix:xc.decode(this.prefix),address:ti.uint8ArrayToHex(this.node.selfAddress)}),this.node.metadata){const t=ti.padEndToMultiple(new Uint8Array([0,0,...Ec.encode(JSON.stringify(this.node.metadata))]),32,10),n=ti.numberToUint16(t.length-2,"BE");t.set(n,0),e.push(t)}return ti.concatBytes(...e)}static unmarshal(e,t){const n=ti.uint8ToNumber(e.read(1)),r=ti.uint8ToNumber(e.read(1)),i=e.read(r);r<30&&e.read(30-r);const o=e.read(t);let a;if(vc("unmarshalling fork",{type:n,prefixLength:r,prefix:xc.decode(i),addressLength:t,address:ti.uint8ArrayToHex(o)}),function(e,t){return(e&t)===t}(n,16)){const t=ti.uint16ToNumber(e.read(2),"BE");a=JSON.parse(xc.decode(e.read(t)))}return new Ac(i,new Oc({selfAddress:o,metadata:a,path:i}))}}class Oc{constructor(e){this.obfuscationKey=new Uint8Array(32),this.selfAddress=null,this.targetAddress=new Uint8Array(32),this.metadata=null,this.path=new Uint8Array(0),this.forks=new Map,this.parent=null,e?.targetAddress&&(this.targetAddress=e.targetAddress),e?.selfAddress&&(this.selfAddress=e.selfAddress),e?.metadata&&(this.metadata=e.metadata),e?.obfuscationKey&&(this.obfuscationKey=e.obfuscationKey),e?.path&&(this.path=e.path),e?.parent&&(this.parent=e.parent)}get fullPath(){return ti.concatBytes(this.parent?.fullPath??new Uint8Array(0),this.path)}get fullPathString(){return xc.decode(this.fullPath)}getRootMetadata(){const e=this.find("/");return e&&e.metadata?ui.of(e.metadata):ui.empty()}getDocsMetadata(){const e=this.find("/");return e&&e.metadata?{indexDocument:e.metadata["website-index-document"]??null,errorDocument:e.metadata["website-error-document"]??null}:{indexDocument:null,errorDocument:null}}async resolveFeed(e,t){const n=this.find("/");if(!n||!n.metadata)return ui.empty();const r=n.metadata["swarm-feed-owner"],i=n.metadata["swarm-feed-topic"];return r&&i?ui.of(await e.fetchLatestFeedUpdate(i,r,t)):ui.empty()}async marshal(){for(const e of this.forks.values())e.node.selfAddress||(e.node.selfAddress=(await e.node.calculateSelfAddress()).toUint8Array());const e=new Uint8Array(32);e.set(Tc,0),e.set(ti.equals(this.targetAddress,Uc)&&ti.equals(this.path,new Uint8Array([47]))?ti.numberToUint8(0):ti.numberToUint8(this.targetAddress.length),31);const t=new Uint8Array(32);for(const e of this.forks.keys())ti.setBit(t,e,1,"LE");const n=[];for(let e=0;e<256;e++)ti.getBit(t,e,"LE")&&n.push(this.forks.get(e).marshal());const r=ti.xorCypher(ti.concatBytes(e,ti.equals(this.targetAddress,Uc)&&ti.equals(this.path,new Uint8Array([47]))?new Uint8Array(0):this.targetAddress,t,...n),this.obfuscationKey);return ti.concatBytes(this.obfuscationKey,r)}static async unmarshal(e,t,n,r){t=new Ni(t);const i=(await e.downloadData(t,n,r)).toUint8Array();return this.unmarshalFromData(i,t.toUint8Array())}static unmarshalFromData(e,t){const n=e.subarray(0,32),r=ti.xorCypher(e.subarray(32),n),i=new di(r),o=i.read(31);if(!ti.equals(o,Tc.slice(0,31)))throw new Error("MantarayNode#unmarshal invalid version hash");const a=ti.uint8ToNumber(i.read(1)),s=a?i.read(a):Uc,c=new Oc({selfAddress:t,targetAddress:s,obfuscationKey:n}),u=i.read(32);for(let e=0;e<256;e++)if(ti.getBit(u,e,"LE")){const n=Ac.unmarshal(i,t.length);c.forks.set(e,n),n.node.parent=c}return c}addFork(e,t,n){this.selfAddress=null,e=e instanceof Uint8Array?e:Ec.encode(e),vc("adding fork",{path:xc.decode(e),reference:new Ni(t).represent()});let r=this;for(;e.length;){const i=e.slice(0,30),o=0===(e=e.slice(30)).length,[a,s]=r.findClosest(i),c=i.slice(s.length);if(s.length&&(r=a),!c.length)continue;const u=new Ac(c,new Oc({targetAddress:o?new Ni(t).toUint8Array():void 0,metadata:o?n:void 0,path:c})),l=a.forks.get(c[0]);if(l){const e=Ac.split(u,l);r.forks.set(c[0],e),e.node.parent=r,r.selfAddress=null,r=u.node}else r.forks.set(c[0],u),u.node.parent=r,r.selfAddress=null,r=u.node}}removeFork(e){if(this.selfAddress=null,0===(e=e instanceof Uint8Array?e:Ec.encode(e)).length)throw Error("MantarayNode#removeFork [path] parameter cannot be empty");const t=this.find(e);if(!t)throw Error("MantarayNode#removeFork fork not found");const[n,r]=this.findClosest(e.slice(0,e.length-1));n.forks.delete(e.slice(r.length)[0]);for(const e of t.forks.values())n.addFork(ti.concatBytes(t.path,e.prefix),e.node.targetAddress,e.node.metadata)}async calculateSelfAddress(){return this.selfAddress?new Ni(this.selfAddress):new Ni((await li.root(await this.marshal())).hash())}async saveRecursively(e,t,n,r){for(const i of this.forks.values())await i.node.saveRecursively(e,t,n,r);const i=await e.uploadData(t,await this.marshal(),n,r);return this.selfAddress=i.reference.toUint8Array(),i}async loadRecursively(e,t,n){for(const r of this.forks.values()){if(!r.node.selfAddress)throw Error("MantarayNode#loadRecursively fork.node.selfAddress is not set");const i=await Oc.unmarshal(e,r.node.selfAddress,t,n);r.node.targetAddress=i.targetAddress,r.node.forks=i.forks,r.node.path=r.prefix,r.node.parent=this,await r.node.loadRecursively(e,t,n)}}find(e){const[t,n]=this.findClosest(e);return n.length===e.length?t:null}findClosest(e,t=new Uint8Array){if(0===(e=e instanceof Uint8Array?e:Ec.encode(e)).length)return[this,t];const n=this.forks.get(e[0]);return n&&ti.commonPrefix(n.prefix,e).length===n.prefix.length?n.node.findClosest(e.slice(n.prefix.length),ti.concatBytes(t,n.prefix)):[this,t]}collect(e=[]){for(const t of this.forks.values())ti.equals(t.node.targetAddress,Uc)||e.push(t.node),t.node.collect(e);return e}collectAndMap(){const e=this.collect(),t={};for(const n of e)t[n.fullPathString]=new Ni(n.targetAddress).toHex();return t}determineType(){let e=0;return ti.equals(this.targetAddress,Uc)&&!ti.equals(this.path,Bc)||(e|=2),this.forks.size>0&&(e|=4),-1===ti.indexOf(this.path,Bc)||ti.equals(this.path,Bc)||(e|=8),this.metadata&&(e|=16),e}}class Rc{constructor(e,t,n){this.encryptionKey=e,this.keyLen=e.length,this.padding=t,this.initCtr=n,this.index=0}key(){return this.encryptionKey}encrypt(e){const t=e.length;let n=t;if(this.padding>0){if(t>this.padding)throw new Error(`data length ${t} longer than padding ${this.padding}`);n=this.padding}const r=new Uint8Array(n);return this.transform(e,r),r}decrypt(e){const t=e.length;if(this.padding>0&&t!==this.padding)throw new Error(`data length ${t} different than padding ${this.padding}`);const n=new Uint8Array(t);return this.transform(e,n),n}reset(){this.index=0}transform(e,t){const n=e.length;for(let r=0;r<n;r+=this.keyLen){const i=Math.min(this.keyLen,n-r);this.transcrypt(this.index,e.subarray(r,r+i),t.subarray(r,r+i)),this.index++}t.length>n&&Sc(t.subarray(n),this.encryptionKey,n)}transcrypt(e,t,n){const r=new Uint8Array(4);new DataView(r.buffer).setUint32(0,e+this.initCtr,!0);const i=new Uint8Array(this.encryptionKey.length+4);i.set(this.encryptionKey),i.set(r,this.encryptionKey.length);const o=ti.keccak256(i),a=ti.keccak256(o),s=t.length;for(let e=0;e<s;e++)n[e]=t[e]^a[e];n.length>s&&Sc(n.subarray(s),this.encryptionKey,e*this.keyLen+s)}}function Sc(e,t,n){if(0===e.length)return;let r=0,i=n;for(;r<e.length;){const n=new Uint8Array(4);new DataView(n.buffer).setUint32(0,i,!0);const o=new Uint8Array(t.length+n.length);o.set(t),o.set(n,t.length);const a=ti.keccak256(o),s=Math.min(a.length,e.length-r);e.set(a.subarray(0,s),r),r+=s,i++}}function kc(e=32){const t=new Uint8Array(e);var n;return 0!==(n=t).length&&crypto.getRandomValues(n),t}function $c(e){return new Rc(e,0,Math.floor(128))}function Ic(e){return new Rc(e,4096,0)}class zc{encryptChunk(e,t){const n=t||kc(32);return{key:n,encryptedSpan:$c(n).encrypt(e.subarray(0,8)),encryptedData:Ic(n).encrypt(e.subarray(8))}}}function Dc(){return new zc}const Cc=new TextEncoder;function Pc(e,t){if(e instanceof Uint8Array||(e=Cc.encode(e)),e.length<1||e.length>Ji)throw new RangeError(`payload size ${e.length} exceeds limits [1, 4096]`);const n=_i.fromBigInt(BigInt(e.length)),r=ti.concatBytes(n.toUint8Array(),e),i=Dc(),{key:o,encryptedSpan:a,encryptedData:s}=i.encryptChunk(r,t),c=ti.concatBytes(a,s),u=Ki(c),l=new Ni(ti.concatBytes(u.toUint8Array(),o));return{data:c,encryptionKey:o,span:n,payload:new Oi(c.slice(_i.LENGTH)),address:u,reference:l}}function Nc(e,t){return function(e,t){const n=$c(e).decrypt(t.subarray(0,8)),r=Ic(e).decrypt(t.subarray(8)),i=new Uint8Array(8+r.length);return i.set(n),i.set(r,8),i}(t,e)}new Fi("0000000000000000000000000000000000000000000000000000000000000000"),new ji("0000000000000000000000000000000000000000000000000000000000000000");const Uc=new Uint8Array(32);class _c{constructor(e,t,n={}){this.totalChunks=0,this.processedChunks=0,this.bee=e,this.rootReference=new Ni(t),this.options=n,this.isEncrypted=64===this.rootReference.length,this.isEncrypted&&(this.rootEncryptionKey=function(e){const t=e.toUint8Array();if(64!==t.length)throw new Error(`Invalid encrypted reference length: ${t.length}, expected 64`);return t.slice(32,64)}(this.rootReference),this.rootReference=function(e){const t=e.toUint8Array();if(64!==t.length)throw new Error(`Invalid encrypted reference length: ${t.length}, expected 64`);return new Ni(t.slice(0,32))}(this.rootReference))}async getSize(){return void 0!==this.fileSize||await this.fetchAndParseRoot(),this.fileSize}async fetchAndParseRoot(){if(void 0!==this.fileSize)return;const e=await this.downloadChunk(this.rootReference,this.rootEncryptionKey),t=_i.fromSlice(e,0);this.fileSize=t.toBigInt();const n=Math.ceil(Number(this.fileSize)/Ji);this.totalChunks=n,this.updateProgress()}async downloadChunk(e,t){try{const n=await this.bee.downloadChunk(e,this.options.downloadOptions,this.options.requestOptions);return t?Nc(n,t):n}catch(t){if(t&&"object"==typeof t&&"status"in t){const n=t.status;if(404===n||500===n)throw new Error(`Failed to download chunk ${e.toHex()}: Chunk not found. Make sure the data exists on the Bee node.`)}throw t}}updateProgress(){this.options.onDownloadProgress&&this.options.onDownloadProgress({total:this.totalChunks,processed:this.processedChunks})}async readChunkRecursively(e,t){const n=await this.downloadChunk(e,t),r=_i.fromSlice(n,0).toBigInt(),i=n.slice(_i.LENGTH);if(r<=BigInt(Ji))return this.processedChunks++,this.updateProgress(),i.slice(0,Number(r));const o=this.isEncrypted?64:32,a=[];for(let e=0;e<i.length;e+=o){const t=i.slice(e,e+o);if(t.length<o)break;const n=t.slice(0,32);ti.equals(n,Uc)||(this.isEncrypted?a.push({ref:new Ni(n),key:t.slice(32,64)}):a.push({ref:new Ni(n)}))}const s=this.options.concurrency??64,c=new Array(a.length);for(let e=0;e<a.length;e+=s){const t=a.slice(e,Math.min(e+s,a.length)).map(async({ref:t,key:n},r)=>{const i=e+r,o=await this.readChunkRecursively(t,n);c[i]=o});await Promise.all(t)}return ti.concatBytes(...c)}async createReadableStream(){await this.fetchAndParseRoot();const e=this;let t=!1;return new ReadableStream({async start(n){try{t=!0;const r=await e.readChunkRecursively(e.rootReference,e.rootEncryptionKey);n.enqueue(r),n.close()}catch(e){n.error(e)}},cancel(){}})}async readAll(){return await this.fetchAndParseRoot(),this.readChunkRecursively(this.rootReference,this.rootEncryptionKey)}}const Vc="balances",Fc="consumed";const Mc="chequebook";async function jc(e,t){const n=await _s(e,{url:Mc+`/cashout/${t}`,responseType:"json"}),r=ci.asObject(n.data,{name:"response.data"});return{peer:ci.asString(r.peer,{name:"peer"}),uncashedAmount:ao.fromPLUR(lo(r.uncashedAmount,{name:"uncashedAmount"})),transactionHash:ci.asNullableString(r.transactionHash),lastCashedCheque:ci.asNullable(e=>Lc(e),r.lastCashedCheque),result:ci.asNullable(e=>function(e){const t=ci.asObject(e,{name:"cashout result"});return{recipient:ci.asString(t.recipient,{name:"recipient"}),lastPayout:ao.fromPLUR(lo(t.lastPayout,{name:"lastPayout"})),bounced:ci.asBoolean(t.bounced,{name:"bounced"})}}(e),r.result)}}function Lc(e){const t=ci.asObject(e,{name:"cheque"});return{beneficiary:new Ci(ci.asString(t.beneficiary,{name:"beneficiary"})),chequebook:new Ci(ci.asString(t.chequebook,{name:"chequebook"})),payout:ao.fromPLUR(lo(t.payout,{name:"payout"}))}}function qc(e,t){const n=ci.asObject(e,{name:t});return n.disconnectedPeers||(n.disconnectedPeers=[]),n.connectedPeers||(n.connectedPeers=[]),{population:ci.asNumber(n.population,{name:"population"}),connected:ci.asNumber(n.connected,{name:"connected"}),connectedPeers:ci.asArray(n.connectedPeers,{name:"connectedPeers"}).map(e=>({address:ci.asString(ci.asObject(e,{name:"connectedPeer"}).address,{name:"address"})})),disconnectedPeers:ci.asArray(n.disconnectedPeers,{name:"disconnectedPeers"}).map(e=>({address:ci.asString(ci.asObject(e,{name:"disconnectedPeer"}).address,{name:"address"})}))}}const Gc="settlements";const Hc="stake";class Zc{constructor(e){if(this.bytes=Math.ceil(e),e<0)throw Error("Size must be at least 0")}static fromBytes(e){return new Zc(e)}static fromKilobytes(e){return new Zc(1e3*e)}static fromMegabytes(e){return new Zc(1e3*e*1e3)}static fromGigabytes(e){return new Zc(1e3*e*1e3*1e3)}static parseFromString(e){return Zc.fromBytes(ii.makeStorage(e,1e3))}toBytes(){return this.bytes}toGigabytes(){return this.bytes/1e3/1e3/1e3}toFormattedString(){return ii.convertBytes(this.bytes,1e3)}represent(){return this.toFormattedString()}}function Wc(e){return Number.isInteger(e)?e<1?1:e>315569260?315569260:e:1}const Kc="stamps";async function Jc(e){const t=await _s(e,{method:"get",url:"batches",responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"});return ci.asArray(n.batches,{name:"batches"}).map(e=>ci.asObject(e,{name:"batch"})).map(e=>({batchID:new Fi(ci.asString(e.batchID,{name:"batchID"})),batchTTL:ci.asNumber(e.batchTTL,{name:"batchTTL"}),bucketDepth:ci.asNumber(e.bucketDepth,{name:"bucketDepth"}),depth:ci.asNumber(e.depth,{name:"depth"}),immutable:ci.asBoolean(e.immutable,{name:"immutable"}),owner:new Ci(ci.asString(e.owner,{name:"owner"})),start:ci.asNumber(e.start,{name:"start"}),value:lo(e.value,{name:"value"})}))}async function Xc(e){const t=await _s(e,{method:"get",url:`${Kc}`,responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"});return ci.asArray(n.stamps,{name:"stamps"}).map(e=>ci.asObject(e,{name:"stamp"})).map(e=>{const t=ci.asNumber(e.utilization,{name:"utilization"}),n=ci.asNumber(e.depth,{name:"depth"}),r=ci.asNumber(e.bucketDepth,{name:"bucketDepth"}),i=bo(t,n,r),o=Wc(ci.asNumber(e.batchTTL,{name:"batchTTL"})),a=oo.fromSeconds(o),s=xo(n);return{batchID:new Fi(ci.asString(e.batchID,{name:"batchID"})),utilization:t,usable:ci.asBoolean(e.usable,{name:"usable"}),label:ci.asEmptiableString(e.label,{name:"label"}),depth:n,amount:lo(e.amount,{name:"amount"}),bucketDepth:r,blockNumber:ci.asNumber(e.blockNumber,{name:"blockNumber"}),immutableFlag:ci.asBoolean(e.immutableFlag,{name:"immutableFlag"}),usage:i,usageText:`${Math.round(100*i)}%`,size:Zc.fromBytes(s),remainingSize:Zc.fromBytes(Math.ceil(s*(1-i))),theoreticalSize:Zc.fromBytes(vo(n)),duration:a,calculateSize(e,t){const n=xo(this.depth,e,t);return Zc.fromBytes(n)},calculateRemainingSize(e,t){const n=xo(this.depth,e,t);return Zc.fromBytes(Math.ceil(n*(1-this.usage)))}}})}const Yc="wallet";var Qc,eu,tu,nu;function ru(){if(eu)return Qc;eu=1;const e="object"==typeof process&&process.env&&process.env.NODE_DEBUG&&/\bsemver\b/i.test(process.env.NODE_DEBUG)?(...e)=>console.error("SEMVER",...e):()=>{};return Qc=e}function iu(){if(nu)return tu;nu=1;const e=Number.MAX_SAFE_INTEGER||9007199254740991;return tu={MAX_LENGTH:256,MAX_SAFE_COMPONENT_LENGTH:16,MAX_SAFE_BUILD_LENGTH:250,MAX_SAFE_INTEGER:e,RELEASE_TYPES:["major","premajor","minor","preminor","patch","prepatch","prerelease"],SEMVER_SPEC_VERSION:"2.0.0",FLAG_INCLUDE_PRERELEASE:1,FLAG_LOOSE:2}}var ou,au,su,cu,uu,lu,hu,fu,du,pu={exports:{}};function mu(){return ou||(ou=1,function(e,t){const{MAX_SAFE_COMPONENT_LENGTH:n,MAX_SAFE_BUILD_LENGTH:r,MAX_LENGTH:i}=iu(),o=ru(),a=(t=e.exports={}).re=[],s=t.safeRe=[],c=t.src=[],u=t.safeSrc=[],l=t.t={};let h=0;const f="[a-zA-Z0-9-]",d=[["\\s",1],["\\d",i],[f,r]],p=(e,t,n)=>{const r=(e=>{for(const[t,n]of d)e=e.split(`${t}*`).join(`${t}{0,${n}}`).split(`${t}+`).join(`${t}{1,${n}}`);return e})(t),i=h++;o(e,i,t),l[e]=i,c[i]=t,u[i]=r,a[i]=new RegExp(t,n?"g":void 0),s[i]=new RegExp(r,n?"g":void 0)};p("NUMERICIDENTIFIER","0|[1-9]\\d*"),p("NUMERICIDENTIFIERLOOSE","\\d+"),p("NONNUMERICIDENTIFIER",`\\d*[a-zA-Z-]${f}*`),p("MAINVERSION",`(${c[l.NUMERICIDENTIFIER]})\\.(${c[l.NUMERICIDENTIFIER]})\\.(${c[l.NUMERICIDENTIFIER]})`),p("MAINVERSIONLOOSE",`(${c[l.NUMERICIDENTIFIERLOOSE]})\\.(${c[l.NUMERICIDENTIFIERLOOSE]})\\.(${c[l.NUMERICIDENTIFIERLOOSE]})`),p("PRERELEASEIDENTIFIER",`(?:${c[l.NONNUMERICIDENTIFIER]}|${c[l.NUMERICIDENTIFIER]})`),p("PRERELEASEIDENTIFIERLOOSE",`(?:${c[l.NONNUMERICIDENTIFIER]}|${c[l.NUMERICIDENTIFIERLOOSE]})`),p("PRERELEASE",`(?:-(${c[l.PRERELEASEIDENTIFIER]}(?:\\.${c[l.PRERELEASEIDENTIFIER]})*))`),p("PRERELEASELOOSE",`(?:-?(${c[l.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${c[l.PRERELEASEIDENTIFIERLOOSE]})*))`),p("BUILDIDENTIFIER",`${f}+`),p("BUILD",`(?:\\+(${c[l.BUILDIDENTIFIER]}(?:\\.${c[l.BUILDIDENTIFIER]})*))`),p("FULLPLAIN",`v?${c[l.MAINVERSION]}${c[l.PRERELEASE]}?${c[l.BUILD]}?`),p("FULL",`^${c[l.FULLPLAIN]}$`),p("LOOSEPLAIN",`[v=\\s]*${c[l.MAINVERSIONLOOSE]}${c[l.PRERELEASELOOSE]}?${c[l.BUILD]}?`),p("LOOSE",`^${c[l.LOOSEPLAIN]}$`),p("GTLT","((?:<|>)?=?)"),p("XRANGEIDENTIFIERLOOSE",`${c[l.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`),p("XRANGEIDENTIFIER",`${c[l.NUMERICIDENTIFIER]}|x|X|\\*`),p("XRANGEPLAIN",`[v=\\s]*(${c[l.XRANGEIDENTIFIER]})(?:\\.(${c[l.XRANGEIDENTIFIER]})(?:\\.(${c[l.XRANGEIDENTIFIER]})(?:${c[l.PRERELEASE]})?${c[l.BUILD]}?)?)?`),p("XRANGEPLAINLOOSE",`[v=\\s]*(${c[l.XRANGEIDENTIFIERLOOSE]})(?:\\.(${c[l.XRANGEIDENTIFIERLOOSE]})(?:\\.(${c[l.XRANGEIDENTIFIERLOOSE]})(?:${c[l.PRERELEASELOOSE]})?${c[l.BUILD]}?)?)?`),p("XRANGE",`^${c[l.GTLT]}\\s*${c[l.XRANGEPLAIN]}$`),p("XRANGELOOSE",`^${c[l.GTLT]}\\s*${c[l.XRANGEPLAINLOOSE]}$`),p("COERCEPLAIN",`(^|[^\\d])(\\d{1,${n}})(?:\\.(\\d{1,${n}}))?(?:\\.(\\d{1,${n}}))?`),p("COERCE",`${c[l.COERCEPLAIN]}(?:$|[^\\d])`),p("COERCEFULL",c[l.COERCEPLAIN]+`(?:${c[l.PRERELEASE]})?`+`(?:${c[l.BUILD]})?(?:$|[^\\d])`),p("COERCERTL",c[l.COERCE],!0),p("COERCERTLFULL",c[l.COERCEFULL],!0),p("LONETILDE","(?:~>?)"),p("TILDETRIM",`(\\s*)${c[l.LONETILDE]}\\s+`,!0),t.tildeTrimReplace="$1~",p("TILDE",`^${c[l.LONETILDE]}${c[l.XRANGEPLAIN]}$`),p("TILDELOOSE",`^${c[l.LONETILDE]}${c[l.XRANGEPLAINLOOSE]}$`),p("LONECARET","(?:\\^)"),p("CARETTRIM",`(\\s*)${c[l.LONECARET]}\\s+`,!0),t.caretTrimReplace="$1^",p("CARET",`^${c[l.LONECARET]}${c[l.XRANGEPLAIN]}$`),p("CARETLOOSE",`^${c[l.LONECARET]}${c[l.XRANGEPLAINLOOSE]}$`),p("COMPARATORLOOSE",`^${c[l.GTLT]}\\s*(${c[l.LOOSEPLAIN]})$|^$`),p("COMPARATOR",`^${c[l.GTLT]}\\s*(${c[l.FULLPLAIN]})$|^$`),p("COMPARATORTRIM",`(\\s*)${c[l.GTLT]}\\s*(${c[l.LOOSEPLAIN]}|${c[l.XRANGEPLAIN]})`,!0),t.comparatorTrimReplace="$1$2$3",p("HYPHENRANGE",`^\\s*(${c[l.XRANGEPLAIN]})\\s+-\\s+(${c[l.XRANGEPLAIN]})\\s*$`),p("HYPHENRANGELOOSE",`^\\s*(${c[l.XRANGEPLAINLOOSE]})\\s+-\\s+(${c[l.XRANGEPLAINLOOSE]})\\s*$`),p("STAR","(<|>)?=?\\s*\\*"),p("GTE0","^\\s*>=\\s*0\\.0\\.0\\s*$"),p("GTE0PRE","^\\s*>=\\s*0\\.0\\.0-0\\s*$")}(pu,pu.exports)),pu.exports}function gu(){if(hu)return lu;hu=1;const e=ru(),{MAX_LENGTH:t,MAX_SAFE_INTEGER:n}=iu(),{safeRe:r,t:i}=mu(),o=function(){if(su)return au;su=1;const e=Object.freeze({loose:!0}),t=Object.freeze({});return au=n=>n?"object"!=typeof n?e:n:t}(),{compareIdentifiers:a}=function(){if(uu)return cu;uu=1;const e=/^[0-9]+$/,t=(t,n)=>{if("number"==typeof t&&"number"==typeof n)return t===n?0:t<n?-1:1;const r=e.test(t),i=e.test(n);return r&&i&&(t=+t,n=+n),t===n?0:r&&!i?-1:i&&!r?1:t<n?-1:1};return cu={compareIdentifiers:t,rcompareIdentifiers:(e,n)=>t(n,e)}}();class s{constructor(a,c){if(c=o(c),a instanceof s){if(a.loose===!!c.loose&&a.includePrerelease===!!c.includePrerelease)return a;a=a.version}else if("string"!=typeof a)throw new TypeError(`Invalid version. Must be a string. Got type "${typeof a}".`);if(a.length>t)throw new TypeError(`version is longer than ${t} characters`);e("SemVer",a,c),this.options=c,this.loose=!!c.loose,this.includePrerelease=!!c.includePrerelease;const u=a.trim().match(c.loose?r[i.LOOSE]:r[i.FULL]);if(!u)throw new TypeError(`Invalid Version: ${a}`);if(this.raw=a,this.major=+u[1],this.minor=+u[2],this.patch=+u[3],this.major>n||this.major<0)throw new TypeError("Invalid major version");if(this.minor>n||this.minor<0)throw new TypeError("Invalid minor version");if(this.patch>n||this.patch<0)throw new TypeError("Invalid patch version");u[4]?this.prerelease=u[4].split(".").map(e=>{if(/^[0-9]+$/.test(e)){const t=+e;if(t>=0&&t<n)return t}return e}):this.prerelease=[],this.build=u[5]?u[5].split("."):[],this.format()}format(){return this.version=`${this.major}.${this.minor}.${this.patch}`,this.prerelease.length&&(this.version+=`-${this.prerelease.join(".")}`),this.version}toString(){return this.version}compare(t){if(e("SemVer.compare",this.version,this.options,t),!(t instanceof s)){if("string"==typeof t&&t===this.version)return 0;t=new s(t,this.options)}return t.version===this.version?0:this.compareMain(t)||this.comparePre(t)}compareMain(e){return e instanceof s||(e=new s(e,this.options)),this.major<e.major?-1:this.major>e.major?1:this.minor<e.minor?-1:this.minor>e.minor?1:this.patch<e.patch?-1:this.patch>e.patch?1:0}comparePre(t){if(t instanceof s||(t=new s(t,this.options)),this.prerelease.length&&!t.prerelease.length)return-1;if(!this.prerelease.length&&t.prerelease.length)return 1;if(!this.prerelease.length&&!t.prerelease.length)return 0;let n=0;do{const r=this.prerelease[n],i=t.prerelease[n];if(e("prerelease compare",n,r,i),void 0===r&&void 0===i)return 0;if(void 0===i)return 1;if(void 0===r)return-1;if(r!==i)return a(r,i)}while(++n)}compareBuild(t){t instanceof s||(t=new s(t,this.options));let n=0;do{const r=this.build[n],i=t.build[n];if(e("build compare",n,r,i),void 0===r&&void 0===i)return 0;if(void 0===i)return 1;if(void 0===r)return-1;if(r!==i)return a(r,i)}while(++n)}inc(e,t,n){if(e.startsWith("pre")){if(!t&&!1===n)throw new Error("invalid increment argument: identifier is empty");if(t){const e=`-${t}`.match(this.options.loose?r[i.PRERELEASELOOSE]:r[i.PRERELEASE]);if(!e||e[1]!==t)throw new Error(`invalid identifier: ${t}`)}}switch(e){case"premajor":this.prerelease.length=0,this.patch=0,this.minor=0,this.major++,this.inc("pre",t,n);break;case"preminor":this.prerelease.length=0,this.patch=0,this.minor++,this.inc("pre",t,n);break;case"prepatch":this.prerelease.length=0,this.inc("patch",t,n),this.inc("pre",t,n);break;case"prerelease":0===this.prerelease.length&&this.inc("patch",t,n),this.inc("pre",t,n);break;case"release":if(0===this.prerelease.length)throw new Error(`version ${this.raw} is not a prerelease`);this.prerelease.length=0;break;case"major":0===this.minor&&0===this.patch&&0!==this.prerelease.length||this.major++,this.minor=0,this.patch=0,this.prerelease=[];break;case"minor":0===this.patch&&0!==this.prerelease.length||this.minor++,this.patch=0,this.prerelease=[];break;case"patch":0===this.prerelease.length&&this.patch++,this.prerelease=[];break;case"pre":{const e=Number(n)?1:0;if(0===this.prerelease.length)this.prerelease=[e];else{let r=this.prerelease.length;for(;--r>=0;)"number"==typeof this.prerelease[r]&&(this.prerelease[r]++,r=-2);if(-1===r){if(t===this.prerelease.join(".")&&!1===n)throw new Error("invalid increment argument: identifier already exists");this.prerelease.push(e)}}if(t){let r=[t,e];!1===n&&(r=[t]),0===a(this.prerelease[0],t)?isNaN(this.prerelease[1])&&(this.prerelease=r):this.prerelease=r}break}default:throw new Error(`invalid increment argument: ${e}`)}return this.raw=this.format(),this.build.length&&(this.raw+=`+${this.build.join(".")}`),this}}return lu=s}var yu=Jr(function(){if(du)return fu;du=1;const e=gu();return fu=(t,n)=>new e(t,n).major}());const wu="2.6.0-d0aa8b93";wu.split("-")[0];const bu="7.3.0";async function vu(e){const t=await _s(e,{method:"get",url:"health",responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"});return{apiVersion:ci.asString(n.apiVersion,{name:"apiVersion"}),version:ci.asString(n.version,{name:"version"}),status:ci.asString(n.status,{name:"status"})}}const Eu="transactions";function xu(e){const t=ci.asObject(e,{name:"transaction"});return{transactionHash:new Ui(ci.asString(t.transactionHash,{name:"transactionHash"})),to:ci.asString(t.to,{name:"to"}),nonce:ci.asNumber(t.nonce,{name:"nonce"}),gasPrice:lo(t.gasPrice,{name:"gasPrice"}),gasLimit:ci.asNumber(t.gasLimit,{name:"gasLimit"}),data:ci.asString(t.data,{name:"data"}),created:ci.asString(t.created,{name:"created"}),description:ci.asString(t.description,{name:"description"}),value:lo(t.value,{name:"value"})}}const Bu="grantee";var Tu,Au;var Ou=Jr(function(){if(Au)return Tu;Au=1;var e=null;return"undefined"!=typeof WebSocket?e=WebSocket:"undefined"!=typeof MozWebSocket?e=MozWebSocket:void 0!==Kr?e=Kr.WebSocket||Kr.MozWebSocket:"undefined"!=typeof window?e=window.WebSocket||window.MozWebSocket:"undefined"!=typeof self&&(e=self.WebSocket||self.MozWebSocket),Tu=e}());const Ru="gsoc";const Su="pins";const ku="pss";async function $u(e,t,n,r,i,o){await _s(e,{method:"post",url:`${ku}/send/${t}/${n}`,data:r,responseType:"json",params:{recipient:o},headers:So(i)})}async function Iu(e){await _s(e,{url:""})}const zu="stewardship";const Du="tags";function Cu(e){return function e(t){return t<=1?t:t+e(Math.ceil(t/128))}(Math.ceil(e/4096))}const Pu={aac:"audio/aac",abw:"application/x-abiword",ai:"application/postscript",arc:"application/octet-stream",avi:"video/x-msvideo",azw:"application/vnd.amazon.ebook",bin:"application/octet-stream",bz:"application/x-bzip",bz2:"application/x-bzip2",csh:"application/x-csh",css:"text/css",csv:"text/csv",doc:"application/msword",dll:"application/octet-stream",dmg:"application/x-apple-diskimage",eot:"application/vnd.ms-fontobject",epub:"application/epub+zip",gif:"image/gif",htm:"text/html",html:"text/html",ico:"image/x-icon",ics:"text/calendar",jar:"application/java-archive",jpeg:"image/jpeg",jpg:"image/jpeg",js:"application/javascript",json:"application/json",mid:"audio/midi",midi:"audio/midi",mp2:"audio/mpeg",mp3:"audio/mpeg",mp4:"video/mp4",mpa:"video/mpeg",mpe:"video/mpeg",mpeg:"video/mpeg",mpkg:"application/vnd.apple.installer+xml",odp:"application/vnd.oasis.opendocument.presentation",ods:"application/vnd.oasis.opendocument.spreadsheet",odt:"application/vnd.oasis.opendocument.text",oga:"audio/ogg",ogv:"video/ogg",ogx:"application/ogg",otf:"font/otf",png:"image/png",pdf:"application/pdf",ppt:"application/vnd.ms-powerpoint",rar:"application/x-rar-compressed",rtf:"application/rtf",sh:"application/x-sh",svg:"image/svg+xml",swf:"application/x-shockwave-flash",tar:"application/x-tar",tif:"image/tiff",tiff:"image/tiff",ts:"application/typescript",ttf:"font/ttf",txt:"text/plain",vsd:"application/vnd.visio",wav:"audio/x-wav",weba:"audio/webm",webm:"video/webm",webp:"image/webp",woff:"font/woff",woff2:"font/woff2",xhtml:"application/xhtml+xml",xls:"application/vnd.ms-excel",xlsx:"application/vnd.ms-excel",xml:"application/xml",xul:"application/vnd.mozilla.xul+xml",zip:"application/zip","3gp":"video/3gpp","3gp2":"video/3gpp2","7z":"application/x-7z-compressed"};function Nu(e){return["text/html","text/css"].includes(e)?`${e}; charset=utf-8`:e}async function Uu(e){if("string"==typeof e)return(new TextEncoder).encode(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Blob)return new Uint8Array(await new Response(e).arrayBuffer());throw new TypeError("unknown websocket data type")}function _u(e){if(!function(e){try{if("string"!=typeof e)return!1;const t=new URL(e);return"http:"===t.protocol||"https:"===t.protocol}catch(e){return!1}}(e))throw new Hi("URL is not valid!",e)}class Vu{constructor(e,t){_u(e),this.url=function(e){return e.endsWith("/")?e.slice(0,-1):e}(e),t?.signer&&(this.signer=new zi(t.signer)),this.network=t?.network??"gnosis",this.requestOptions={baseURL:this.url,timeout:t?.timeout??0,headers:t?.headers,onRequest:t?.onRequest,httpAgent:t?.httpAgent,httpsAgent:t?.httpsAgent}}async uploadData(e,t,n,r){return e=new Fi(e),yo(t),n&&(n=function(e,t="UploadOptions"){const n=fo(e,t),r=ci.asObject(e,{name:t});return{...n,redundancyLevel:ci.asOptional(e=>ci.asInteger(e,{name:"redundancyLevel",min:0}),r.redundancyLevel)}}(n)),Ys(this.getRequestOptionsForCall(r),t,e,n)}async probeData(e,t){return e=new Ni(e),async function(e,t){t=new Ni(t);const n=await _s(e,{url:`${Xs}/${t}`,method:"head",responseType:"json"});return{contentLength:parseInt(n.headers["content-length"])}}(this.getRequestOptionsForCall(t),e)}async downloadData(e,t,n){return t&&(t=ho(t)),Qs(this.getRequestOptionsForCall(n),new rc(e),t)}async downloadReadableData(e,t,n){return t&&(t=ho(t)),async function(e,t,n){return n&&(n=ho(n)),(await _s(e,{responseType:"stream",url:`${Xs}/${t}`,headers:So(null,n)})).data}(this.getRequestOptionsForCall(n),new rc(e),t)}async downloadDataStreaming(e,t,n){return t&&(t={...ho(t),...t}),async function(e,t,n,r){const i=new Ni(t);return new _c(e,i,{onDownloadProgress:n?.onDownloadProgress,downloadOptions:n,requestOptions:r,concurrency:n?.concurrency}).createReadableStream()}(this,e,t,this.getRequestOptionsForCall(n))}async uploadChunk(e,t,n,r){if(t=t instanceof Uint8Array?t:t.data,n&&(n=fo(n)),t.length<_i.LENGTH)throw new Hi(`Chunk has to have size of at least ${_i.LENGTH}.`,t);if(t.length>4096+_i.LENGTH)throw new Hi(`Chunk has to have size of at most ${4096+_i.LENGTH}.`,t);return async function(e,t,n,r){const i=await _s(e,{method:"post",url:`${Fs}`,data:t,headers:{"content-type":"application/octet-stream",...So(n,r)},responseType:"json"}),o=ci.asObject(i.data,{name:"response.data"});return{reference:new Ni(ci.asString(o.reference,{name:"reference"})),tagUid:i.headers["swarm-tag"]?wo(i.headers["swarm-tag"]):void 0,historyAddress:i.headers["swarm-act-history-address"]?ui.of(new Ni(i.headers["swarm-act-history-address"])):ui.empty()}}(this.getRequestOptionsForCall(r),t,e,n)}async downloadChunk(e,t,n){return e=new Ni(e),t&&(t=ho(t)),Ms(this.getRequestOptionsForCall(n),e,t)}async createGrantees(e,t,n){return e=new Fi(e),t=t.map(e=>new Di(e)),async function(e,t,n){const r=await _s(e,{method:"post",url:Bu,data:{grantees:n.map(e=>e.toCompressedHex())},headers:So(t),responseType:"json"}),i=ci.asObject(r.data,{name:"response.data"});return{status:r.status,statusText:r.statusText,ref:new Ni(ci.asString(i.ref,{name:"ref"})),historyref:new Ni(ci.asString(i.historyref,{name:"historyref"}))}}(this.getRequestOptionsForCall(n),e,t)}async getGrantees(e,t){return async function(e,t){const n=await _s(t,{method:"get",url:`${Bu}/${e}`,responseType:"json"}),r=ci.asArray(n.data,{name:"response.data"}).map(e=>new Di(ci.asString(e,{name:"grantee"})));return{status:n.status,statusText:n.statusText,grantees:r}}(e=new Ni(e),this.getRequestOptionsForCall(t))}async patchGrantees(e,t,n,r,i){return async function(e,t,n,r,i){const o=await _s(i,{method:"patch",url:`${Bu}/${t}`,data:{add:r.add?.map(e=>e.toCompressedHex()),revoke:r.revoke?.map(e=>e.toCompressedHex())},headers:{...So(e),"swarm-act-history-address":n.toHex()},responseType:"json"}),a=ci.asObject(o.data,{name:"response.data"});return{status:o.status,statusText:o.statusText,ref:new Ni(ci.asString(a.ref,{name:"ref"})),historyref:new Ni(ci.asString(a.historyref,{name:"historyref"}))}}(e=new Fi(e),t=new Ni(t),n=new Ni(n),{add:r.add?.map(e=>new Di(e))??[],revoke:r.revoke?.map(e=>new Di(e))??[]},this.getRequestOptionsForCall(i))}async uploadFile(e,t,n,r,i){if(e=new Fi(e),function(e){if(!("string"==typeof e||e instanceof Uint8Array||co(e)))throw new TypeError("Data must be either string, Readable, Uint8Array or File!")}(t),r&&(r=function(e){const t=fo(e,"FileUploadOptions"),n=ci.asObject(e,{name:"FileUploadOptions"});return{...t,size:ci.asOptional(e=>ci.asInteger(e,{name:"size",min:0}),n.size),contentType:ci.asOptional(e=>ci.asString(e,{name:"contentType"}),n.contentType),redundancyLevel:ci.asOptional(e=>ci.asInteger(e,{name:"redundancyLevel",min:0}),n.redundancyLevel)}}(r)),n&&"string"!=typeof n)throw new TypeError("name has to be string or undefined!");if(co(t)){const o=await uo(t),a=n??t.name,s={contentType:t.type,...r};return wc(this.getRequestOptionsForCall(i),o,e,a,s)}return wc(this.getRequestOptionsForCall(i),t,e,n,r)}async downloadFile(e,t="",n,r){return n&&(n=ho(n)),async function(e,t,n="",r){const i=await _s(e,{method:"GET",responseType:"arraybuffer",url:`${yc}/${t}/${n}`,headers:So(null,r)});return{...Ro(i.headers),data:new Oi(i.data)}}(this.getRequestOptionsForCall(r),new rc(e),t,n)}async downloadReadableFile(e,t="",n,r){return e=new Ni(e),n&&(n=ho(n)),async function(e,t,n="",r){t=new Ni(t);const i=await _s(e,{method:"GET",responseType:"stream",url:`${yc}/${t}/${n}`,headers:So(null,r)});return{...Ro(i.headers),data:i.data}}(this.getRequestOptionsForCall(r),e,t,n)}async downloadFileStreaming(e,t="",n,r){return n&&(n={...ho(n),...n}),async function(e,t,n="",r,i){const o=new Ni(t),a=await Oc.unmarshal(e,o,r,i);await a.loadRecursively(e,r,i);const s=n?a.find(n):a.find("/");if(!s)throw new Error(`Path not found in manifest: ${n}`);if(!s.targetAddress)throw new Error(`No file at path: ${n}`);const c=s.metadata||{},u=new Ni(s.targetAddress),l=new _c(e,u,{onDownloadProgress:r?.onDownloadProgress,downloadOptions:r,requestOptions:i,concurrency:r?.concurrency}),h=await l.createReadableStream(),f={name:c.Filename||n.split("/").pop()||"",data:h};return c["Content-Type"]&&(f.contentType=c["Content-Type"]),f}(this,e,t,n,this.getRequestOptionsForCall(r))}async uploadFiles(e,t,n,r){e=new Fi(e),n&&(n=po(n));const i=function(e){return Array.from(e).map(e=>({path:pc(e),size:e.size,file:e}))}(t);return bc(this.getRequestOptionsForCall(r),i,e,n)}async hashDirectory(e){return async function(){throw new Error("Hashing directories is not supported in browsers!")}()}async streamDirectory(e,t,n,r,i){return e=new Fi(e),async function(){throw new Error("Streaming directories is not supported in browsers!")}(0,0,0,0,0,this.getRequestOptionsForCall(i))}async streamFiles(e,t,n,r,i){return async function(e,t,n,r,i,o){const a=new fi(64,64);let s=0,c=0;for(const e of t)s+=Cu(e.size);async function u(t){await a.enqueue(async()=>{await e.uploadChunk(n,t.build(),i,o),r?.({total:s,processed:++c})})}n=new Fi(n);const l=new Oc;for(const e of t){const t=await new Promise((t,n)=>{const r=new li(u);let i=0;const o=new FileReader;o.onerror=()=>{n(o.error)};const a=async()=>{if(i>=e.size){const e=await r.finalize();return void t(e)}const n=e.slice(i,i+4096);o.readAsArrayBuffer(n)};o.onload=async e=>{if(!e.target)return void n("No event target");const t=e.target.result;t&&(await r.append(new Uint8Array(t)),i+=4096),a()},a()});await a.drain();const{filename:n,extension:r}=ai.parseFilename(e.name);l.addFork(pc(e),t.hash(),{"Content-Type":Nu(Pu[r.toLowerCase()]||"application/octet-stream"),Filename:n}),"index.html"===e.name&&l.addFork("/",Uc,{"website-index-document":"index.html"})}return l.saveRecursively(e,n,i,o)}(this,t,e=new Fi(e),n,r,this.getRequestOptionsForCall(i))}async uploadCollection(e,t,n,r){return e=new Fi(e),dc(t),n&&(n=po(n)),bc(this.getRequestOptionsForCall(r),t,e,n)}async uploadFilesFromDirectory(e,t,n,r){e=new Fi(e),n&&(n=po(n));const i=await async function(){throw new Error("Creating Collection from File System is not supported in browsers!")}();return bc(this.getRequestOptionsForCall(r),i,e,n)}async createTag(e){return async function(e){const t=await _s(e,{method:"post",url:Du,responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"});return{address:ci.asEmptiableString(n.address,{name:"address"}),seen:ci.asNumber(n.seen,{name:"seen"}),sent:ci.asNumber(n.sent,{name:"sent"}),split:ci.asNumber(n.split,{name:"split"}),startedAt:ci.asString(n.startedAt,{name:"startedAt"}),stored:ci.asNumber(n.stored,{name:"stored"}),synced:ci.asNumber(n.synced,{name:"synced"}),uid:ci.asNumber(n.uid,{name:"uid"})}}(this.getRequestOptionsForCall(e))}async getAllTags(e,t){return e&&(e=function(e){const t=ci.asObject(e,{name:"AllTagsOptions"});return{limit:ci.asOptional(e=>ci.asInteger(e,{name:"limit",min:1,max:1e3}),t.limit),offset:ci.asOptional(e=>ci.asInteger(e,{name:"offset",min:0}),t.offset)}}(e)),async function(e,t,n){const r=await _s(e,{url:Du,params:{offset:t,limit:n},responseType:"json"}),i=ci.asObject(r.data,{name:"response.data"});return ci.asArray(i.tags,{name:"tags"}).map(e=>ci.asObject(e,{name:"tag"})).map(e=>({address:ci.asEmptiableString(e.address,{name:"address"}),seen:ci.asNumber(e.seen,{name:"seen"}),sent:ci.asNumber(e.sent,{name:"sent"}),split:ci.asNumber(e.split,{name:"split"}),startedAt:ci.asString(e.startedAt,{name:"startedAt"}),stored:ci.asNumber(e.stored,{name:"stored"}),synced:ci.asNumber(e.synced,{name:"synced"}),uid:ci.asNumber(e.uid,{name:"uid"})}))}(this.getRequestOptionsForCall(t),e?.offset,e?.limit)}async retrieveTag(e,t){return e=wo(e),async function(e,t){const n=await _s(e,{url:`${Du}/${t}`,responseType:"json"}),r=ci.asObject(n.data,{name:"response.data"});return{address:ci.asEmptiableString(r.address,{name:"address"}),seen:ci.asNumber(r.seen,{name:"seen"}),sent:ci.asNumber(r.sent,{name:"sent"}),split:ci.asNumber(r.split,{name:"split"}),startedAt:ci.asString(r.startedAt,{name:"startedAt"}),stored:ci.asNumber(r.stored,{name:"stored"}),synced:ci.asNumber(r.synced,{name:"synced"}),uid:ci.asNumber(r.uid,{name:"uid"})}}(this.getRequestOptionsForCall(t),e)}async deleteTag(e,t){return e=wo(e),async function(e,t){await _s(e,{method:"delete",url:`${Du}/${t}`})}(this.getRequestOptionsForCall(t),e)}async updateTag(e,t,n){return t=new Ni(t),e=wo(e),async function(e,t,n){await _s(e,{method:"patch",url:`${Du}/${t}`,data:{reference:n}})}(this.getRequestOptionsForCall(n),e,t)}async pin(e,t){return e=new Ni(e),async function(e,t){await _s(e,{method:"post",responseType:"json",url:`${Su}/${t}`})}(this.getRequestOptionsForCall(t),e)}async unpin(e,t){return e=new Ni(e),async function(e,t){await _s(e,{method:"delete",responseType:"json",url:`${Su}/${t}`})}(this.getRequestOptionsForCall(t),e)}async getAllPins(e){return async function(e){const t=await _s(e,{method:"get",responseType:"json",url:`${Su}`}),n=ci.asObject(t.data,{name:"response.data"});return null===n.references?[]:ci.asArray(n.references,{name:"references"}).map(e=>ci.asString(e,{name:"reference"})).map(e=>new Ni(e))}(this.getRequestOptionsForCall(e))}async getPin(e,t){return e=new Ni(e),async function(e,t){const n=await _s(e,{method:"get",responseType:"json",url:`${Su}/${t}`}),r=ci.asObject(n.data,{name:"response.data"});return{reference:new Ni(ci.asString(r.reference,{name:"reference"}))}}(this.getRequestOptionsForCall(t),e)}async reuploadPinnedData(e,t,n){e=new Fi(e),t=new Ni(t),await async function(e,t,n){await _s(e,{method:"put",url:`${zu}/${n}`,headers:{"swarm-postage-batch-id":t.toHex()}})}(this.getRequestOptionsForCall(n),e,t)}async isReferenceRetrievable(e,t){return e=new Ni(e),async function(e,t){t=new Ni(t);const n=await _s(e,{method:"get",responseType:"json",url:`${zu}/${t}`}),r=ci.asObject(n.data,{name:"response.data"});return ci.asBoolean(r.isRetrievable,{name:"isRetrievable"})}(this.getRequestOptionsForCall(t),e)}async isFeedRetrievable(e,t,n,r,i){if(e=new Ci(e),t=new ji(t),r&&(r=ho(r)),!n)try{return await this.makeFeedReader(t,e,i).download(),!0}catch(e){const t=oi.getDeep(e,"status");if(404===t||500===t)return!1;throw e}return fc(this,e,t,n,r,this.getRequestOptionsForCall(i))}async pssSend(e,t,n,r,i,o){return e=new Fi(e),yo(r),i?(i=new Di(i),$u(this.getRequestOptionsForCall(o),t,n,r,e,i)):$u(this.getRequestOptionsForCall(o),t,n,r,e)}pssSubscribe(e,t){t=function(e){const t=ci.asObject(e,{name:"PssMessageHandler"});return{onMessage:ci.asFunction(t.onMessage,{name:"onMessage"}),onError:ci.asFunction(t.onError,{name:"onError"}),onClose:ci.asFunction(t.onClose,{name:"onClose"})}}(t);const n=function(e,t,n){const r=e.replace(/^http/i,"ws");return"browser"===si.whereAmI()?new Ou(`${r}/${ku}/subscribe/${t.toHex()}`):new Ou(`${r}/${ku}/subscribe/${t.toHex()}`,{headers:n})}(this.url,e,this.requestOptions.headers);let r=!1;const i={topic:e,cancel:()=>{r||(r=!0,n.terminate?n.terminate():n.close())}};return n.onmessage=async e=>{const n=await Uu(e.data);n.length&&t.onMessage(new Oi(n),i)},n.onerror=e=>{r||t.onError(new Gi(e.message),i)},n.onclose=()=>{t.onClose(i)},i}async pssReceive(e,t=0){if("number"!=typeof t)throw new TypeError("timeoutMsc parameter has to be a number!");return new Promise((n,r)=>{let i;const o=this.pssSubscribe(e,{onError:e=>{clearTimeout(i),o.cancel(),r(e.message)},onMessage:e=>{clearTimeout(i),o.cancel(),n(e)},onClose:()=>{clearTimeout(i),o.cancel()}});t>0&&(i=setTimeout(()=>{o.cancel(),r(new Gi("pssReceive timeout"))},t))})}gsocMine(e,t,n=12){e=new Vi(e),t=new Pi(t);for(let r=0n;r<0xffffn;r++){const i=new zi(ti.numberToUint256(2867n+r,"BE")),o=Hs(t,i.publicKey().address());if(256-ti.proximity(o.toUint8Array(),e.toUint8Array())<=256-n)return i}throw Error("Could not mine a valid signer")}async gsocSend(e,t,n,r,i,o){e=new Fi(e),t=new zi(t),n=new Pi(n);const a=Zs(Yi(r),n,t);return async function(e,t,n,r){return Ws(e,t,n,r)}(this.getRequestOptionsForCall(o),a,e,i)}gsocSubscribe(e,t,n){e=new Ci(e),t=new Pi(t),n=function(e){const t=ci.asObject(e,{name:"GsocMessageHandler"});return{onMessage:ci.asFunction(t.onMessage,{name:"onMessage"}),onError:ci.asFunction(t.onError,{name:"onError"}),onClose:ci.asFunction(t.onClose,{name:"onClose"})}}(n);const r=Hs(t,e),i=function(e,t,n){const r=e.replace(/^http/i,"ws");return"browser"===si.whereAmI()?new Ou(`${r}/${Ru}/subscribe/${t.toHex()}`):new Ou(`${r}/${Ru}/subscribe/${t.toHex()}`,{headers:n})}(this.url,r,this.requestOptions.headers);let o=!1;const a={address:e,cancel:()=>{o||(o=!0,i.terminate?i.terminate():i.close())}};return i.onmessage=async e=>{const t=await Uu(e.data);t.length&&n.onMessage(new Oi(t),a)},i.onerror=e=>{o||n.onError(new Gi(e.message),a)},i.onclose=()=>{n.onClose(a)},a}async createFeedManifest(e,t,n,r,i){return e=new Fi(e),t=new ji(t),n=new Ci(n),r&&(r=fo(r)),async function(e,t,n,r,i){const o=await _s(e,{method:"post",responseType:"json",url:`${ec}/${t}/${n}`,headers:So(r,i)}),a=ci.asObject(o.data,{name:"response.data"});return new Ni(ci.asHexString(a.reference))}(this.getRequestOptionsForCall(i),n,t,e,r)}makeFeedReader(e,t,n){return e=new ji(e),t=new Ci(t),lc(this.getRequestOptionsForCall(n),e,t)}makeFeedWriter(e,t,n){if(e=new ji(e),!(t=t?new zi(t):this.signer))throw Error("No signer provided");return hc(this.getRequestOptionsForCall(n),e,t)}async fetchLatestFeedUpdate(e,t,n){return e=new ji(e),t=new Ci(t),nc(this.getRequestOptionsForCall(n),t,e)}makeSOCReader(e,t){return{owner:e=new Ci(e),download:Js.bind(null,this.getRequestOptionsForCall(t),e)}}makeSOCWriter(e,t){if(!(e=e?new zi(e):this.signer))throw Error("No signer provided");return{...this.makeSOCReader(e.publicKey().address(),t),upload:Ks.bind(null,this.getRequestOptionsForCall(t),e)}}async createEnvelope(e,t,n){return e=new Fi(e),t=new Ni(t),async function(e,t,n){const r=await _s(e,{method:"post",responseType:"json",url:`envelope/${n}`,headers:{"swarm-postage-batch-id":t.toHex()}}),i=ci.asObject(r.data,{name:"response.data"});return{issuer:ti.hexToUint8Array(ci.asHexString(i.issuer,{name:"issuer",byteLength:20})),index:ti.hexToUint8Array(ci.asHexString(i.index,{name:"index",byteLength:8})),timestamp:ti.hexToUint8Array(ci.asHexString(i.timestamp,{name:"timestamp",byteLength:8})),signature:ti.hexToUint8Array(ci.asHexString(i.signature,{name:"signature",byteLength:65})),batchId:t}}(this.getRequestOptionsForCall(n),e,t)}async rchash(e,t,n,r){return async function(e,t,n,r){const i=await _s(e,{responseType:"json",url:`rchash/${t}/${n}/${r}`}),o=ci.asObject(i.data,{name:"response.data"});return ci.asNumber(o.durationSeconds,{name:"durationSeconds"})}(this.getRequestOptionsForCall(r),e,t,n)}async checkConnection(e){return Iu(this.getRequestOptionsForCall(e))}async isConnected(e){try{await Iu(this.getRequestOptionsForCall(e))}catch(e){return!1}return!0}async isGateway(e){return async function(e){try{const t=await _s(e,{url:"/gateway"}),n=ci.asObject(t.data);return ci.asBoolean(n.gateway)}catch(e){return!1}}(this.getRequestOptionsForCall(e))}async getNodeAddresses(e){return async function(e){const t=await _s(e,{url:"addresses",responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"});return{overlay:new Vi(ci.asString(n.overlay,{name:"overlay"})),underlay:ci.asArray(n.underlay,{name:"underlay"}).map(e=>ci.asString(e,{name:"underlay"})),ethereum:new Ci(ci.asString(n.ethereum,{name:"ethereum"})),publicKey:new Di(ci.asString(n.publicKey,{name:"publicKey"})),pssPublicKey:new Di(ci.asString(n.pssPublicKey,{name:"pssPublicKey"}))}}(this.getRequestOptionsForCall(e))}async getBlocklist(e){return async function(e){return(await _s(e,{url:"blocklist",responseType:"json"})).data.peers}(this.getRequestOptionsForCall(e))}async getPeers(e){return async function(e){const t=await _s(e,{url:"peers",responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"});return ci.asArray(n.peers,{name:"peers"}).map(e=>({address:ci.asString(ci.asObject(e,{name:"peer"}).address,{name:"address"}),fullNode:ci.asBoolean(ci.asObject(e,{name:"peer"}).fullNode,{name:"fullNode"})}))}(this.getRequestOptionsForCall(e))}async removePeer(e,t){return e=new Vi(e),async function(e,t){return(await _s(e,{url:`peers/${t}`,responseType:"json",method:"DELETE"})).data}(this.getRequestOptionsForCall(t),e)}async getTopology(e){return async function(e){const t=await _s(e,{url:"topology",responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"}),r=ci.asObject(n.bins,{name:"bins"});return{baseAddr:ci.asString(n.baseAddr,{name:"baseAddr"}),population:ci.asNumber(n.population,{name:"population"}),connected:ci.asNumber(n.connected,{name:"connected"}),timestamp:ci.asString(n.timestamp,{name:"timestamp"}),nnLowWatermark:ci.asNumber(n.nnLowWatermark,{name:"nnLowWatermark"}),depth:ci.asNumber(n.depth,{name:"depth"}),reachability:ci.asString(n.reachability,{name:"reachability"}),networkAvailability:ci.asString(n.networkAvailability,{name:"networkAvailability"}),bins:{bin_0:qc(r.bin_0,"bin_0"),bin_1:qc(r.bin_1,"bin_1"),bin_2:qc(r.bin_2,"bin_2"),bin_3:qc(r.bin_3,"bin_3"),bin_4:qc(r.bin_4,"bin_4"),bin_5:qc(r.bin_5,"bin_5"),bin_6:qc(r.bin_6,"bin_6"),bin_7:qc(r.bin_7,"bin_7"),bin_8:qc(r.bin_8,"bin_8"),bin_9:qc(r.bin_9,"bin_9"),bin_10:qc(r.bin_10,"bin_10"),bin_11:qc(r.bin_11,"bin_11"),bin_12:qc(r.bin_12,"bin_12"),bin_13:qc(r.bin_13,"bin_13"),bin_14:qc(r.bin_14,"bin_14"),bin_15:qc(r.bin_15,"bin_15"),bin_16:qc(r.bin_16,"bin_16"),bin_17:qc(r.bin_17,"bin_17"),bin_18:qc(r.bin_18,"bin_18"),bin_19:qc(r.bin_19,"bin_19"),bin_20:qc(r.bin_20,"bin_20"),bin_21:qc(r.bin_21,"bin_21"),bin_22:qc(r.bin_22,"bin_22"),bin_23:qc(r.bin_23,"bin_23"),bin_24:qc(r.bin_24,"bin_24"),bin_25:qc(r.bin_25,"bin_25"),bin_26:qc(r.bin_26,"bin_26"),bin_27:qc(r.bin_27,"bin_27"),bin_28:qc(r.bin_28,"bin_28"),bin_29:qc(r.bin_29,"bin_29"),bin_30:qc(r.bin_30,"bin_30"),bin_31:qc(r.bin_31,"bin_31")}}}(this.getRequestOptionsForCall(e))}async pingPeer(e,t){return e=new Vi(e),async function(e,t){return(await _s(e,{url:`pingpong/${t}`,responseType:"json",method:"POST"})).data}(this.getRequestOptionsForCall(t),e)}async getAllBalances(e){return async function(e){const t=await _s(e,{url:Vc,responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"});return{balances:ci.asArray(n.balances,{name:"balances"}).map(e=>ci.asObject(e,{name:"balance"})).map(e=>({peer:ci.asString(e.peer,{name:"peer"}),balance:ao.fromPLUR(lo(e.balance,{name:"balance"}))}))}}(this.getRequestOptionsForCall(e))}async getPeerBalance(e,t){return e=new Vi(e),async function(e,t){const n=await _s(e,{url:`${Vc}/${t}`,responseType:"json"}),r=ci.asObject(n.data,{name:"response.data"});return{peer:ci.asString(r.peer,{name:"peer"}),balance:ao.fromPLUR(lo(r.balance,{name:"balance"}))}}(this.getRequestOptionsForCall(t),e)}async getPastDueConsumptionBalances(e){return async function(e){const t=await _s(e,{url:Fc,responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"});return{balances:ci.asArray(n.balances,{name:"balances"}).map(e=>ci.asObject(e,{name:"balance"})).map(e=>({peer:ci.asString(e.peer,{name:"peer"}),balance:ao.fromPLUR(lo(e.balance,{name:"balance"}))}))}}(this.getRequestOptionsForCall(e))}async getPastDueConsumptionPeerBalance(e,t){return e=new Vi(e),async function(e,t){const n=await _s(e,{url:`${Fc}/${t}`,responseType:"json"}),r=ci.asObject(n.data,{name:"response.data"});return{peer:ci.asString(r.peer,{name:"peer"}),balance:ao.fromPLUR(lo(r.balance,{name:"balance"}))}}(this.getRequestOptionsForCall(t),e)}async getChequebookAddress(e){return async function(e){const t=await _s(e,{url:Mc+"/address",responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"});return{chequebookAddress:new Ci(ci.asString(n.chequebookAddress,{name:"chequebookAddress"}))}}(this.getRequestOptionsForCall(e))}async getChequebookBalance(e){return async function(e){const t=await _s(e,{url:Mc+"/balance",responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"});return{availableBalance:ao.fromPLUR(lo(n.availableBalance,{name:"availableBalance"})),totalBalance:ao.fromPLUR(lo(n.totalBalance,{name:"totalBalance"}))}}(this.getRequestOptionsForCall(e))}async getLastCheques(e){return async function(e){const t=await _s(e,{url:Mc+"/cheque",responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"});return{lastcheques:ci.asArray(n.lastcheques,{name:"lastcheques"}).map(e=>ci.asObject(e,{name:"lastcheque"})).map(e=>({peer:ci.asString(e.peer,{name:"peer"}),lastreceived:ci.asNullable(e=>Lc(e),e.lastreceived),lastsent:ci.asNullable(e=>Lc(e),e.lastsent)}))}}(this.getRequestOptionsForCall(e))}async getLastChequesForPeer(e,t){return e=new Vi(e),async function(e,t){const n=await _s(e,{url:Mc+`/cheque/${t}`,responseType:"json"}),r=ci.asObject(n.data,{name:"response.data"});return{peer:ci.asString(r.peer,{name:"peer"}),lastreceived:ci.asNullable(e=>Lc(e),r.lastreceived),lastsent:ci.asNullable(e=>Lc(e),r.lastsent)}}(this.getRequestOptionsForCall(t),e)}async getLastCashoutAction(e,t){return e=new Vi(e),jc(this.getRequestOptionsForCall(t),e)}async cashoutLastCheque(e,t,n){return e=new Vi(e),t&&go(t),async function(e,t,n){const r=await _s(e,{method:"post",url:Mc+`/cashout/${t}`,responseType:"json",headers:So(null,n)}),i=ci.asObject(r.data,{name:"response.data"});return new Ui(ci.asString(i.transactionHash,{name:"transactionHash"}))}(this.getRequestOptionsForCall(n),e,t)}async depositTokens(e,t,n){return this.depositBZZToChequebook(e,t,n)}async depositBZZToChequebook(e,t,n){const r=e instanceof ao?e.toPLURString():lo(e,{min:1n,name:"amount"});let i;return t&&(i=lo(e,{min:0n,name:"gasPrice"})),async function(e,t,n){const r={};n&&(r["gas-price"]=n.toString());const i=await _s(e,{method:"post",url:Mc+"/deposit",responseType:"json",params:{amount:t.toString(10)},headers:r}),o=ci.asObject(i.data,{name:"response.data"});return new Ui(ci.asString(o.transactionHash,{name:"transactionHash"}))}(this.getRequestOptionsForCall(n),r,i)}async withdrawTokens(e,t,n){return this.withdrawBZZFromChequebook(e,t,n)}async withdrawBZZFromChequebook(e,t,n){const r=e instanceof ao?e.toPLURString():lo(e,{min:1n,name:"amount"});let i;return t&&(i=lo(e,{min:0n,name:"gasPrice"})),async function(e,t,n){const r={};n&&(r["gas-price"]=n.toString());const i=await _s(e,{method:"post",url:Mc+"/withdraw",responseType:"json",params:{amount:t.toString(10)},headers:r}),o=ci.asObject(i.data,{name:"response.data"});return new Ui(ci.asString(o.transactionHash,{name:"transactionHash"}))}(this.getRequestOptionsForCall(n),r,i)}async withdrawBZZToExternalWallet(e,t,n){return e=e instanceof ao?e:ao.fromPLUR(e),t=new Ci(t),async function(e,t,n){const r=await _s(e,{method:"post",url:`${Yc}/withdraw/bzz`,responseType:"json",params:{amount:t.toPLURString(),address:n.toHex()}}),i=ci.asObject(r.data,{name:"response.data"});return new Ui(ci.asString(i.transactionHash,{name:"transactionHash"}))}(this.getRequestOptionsForCall(n),e,t)}async withdrawDAIToExternalWallet(e,t,n){return e=e instanceof so?e:so.fromWei(e),t=new Ci(t),async function(e,t,n){const r=await _s(e,{method:"post",url:`${Yc}/withdraw/nativetoken`,responseType:"json",params:{amount:t.toWeiString(),address:n.toHex()}}),i=ci.asObject(r.data,{name:"response.data"});return new Ui(ci.asString(i.transactionHash,{name:"transactionHash"}))}(this.getRequestOptionsForCall(n),e,t)}async getSettlements(e,t){return e=new Vi(e),async function(e,t){const n=await _s(e,{url:`${Gc}/${t}`,responseType:"json"}),r=ci.asObject(n.data,{name:"response.data"});return{peer:ci.asString(r.peer,{name:"peer"}),sent:ao.fromPLUR(lo(r.sent,{name:"sent"})),received:ao.fromPLUR(lo(r.received,{name:"received"}))}}(this.getRequestOptionsForCall(t),e)}async getAllSettlements(e){return async function(e){const t=await _s(e,{url:Gc,responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"});return{totalSent:ao.fromPLUR(lo(n.totalSent,{name:"totalSent"})),totalReceived:ao.fromPLUR(lo(n.totalReceived,{name:"totalReceived"})),settlements:ci.asArray(n.settlements,{name:"settlements"}).map(e=>ci.asObject(e,{name:"settlement"})).map(e=>({peer:ci.asString(e.peer,{name:"peer"}),sent:ao.fromPLUR(lo(e.sent,{name:"sent"})),received:ao.fromPLUR(lo(e.received,{name:"received"}))}))}}(this.getRequestOptionsForCall(e))}async getStatus(e){return async function(e){const t=await _s(e,{method:"get",url:"status",responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"});return{overlay:ci.asString(n.overlay,{name:"overlay"}),proximity:ci.asNumber(n.proximity,{name:"proximity"}),beeMode:to(ci.asString(n.beeMode,{name:"beeMode"})),reserveSize:ci.asNumber(n.reserveSize,{name:"reserveSize"}),reserveSizeWithinRadius:ci.asNumber(n.reserveSizeWithinRadius,{name:"reserveSizeWithinRadius"}),pullsyncRate:ci.asNumber(n.pullsyncRate,{name:"pullsyncRate"}),storageRadius:ci.asNumber(n.storageRadius,{name:"storageRadius"}),connectedPeers:ci.asNumber(n.connectedPeers,{name:"connectedPeers"}),neighborhoodSize:ci.asNumber(n.neighborhoodSize,{name:"neighborhoodSize"}),batchCommitment:ci.asNumber(n.batchCommitment,{name:"batchCommitment"}),isReachable:ci.asBoolean(n.isReachable,{name:"isReachable"}),lastSyncedBlock:ci.asNumber(n.lastSyncedBlock,{name:"lastSyncedBlock"}),committedDepth:ci.asNumber(n.committedDepth,{name:"committedDepth"}),isWarmingUp:ci.asBoolean(n.isWarmingUp,{name:"isWarmingUp"})}}(this.getRequestOptionsForCall(e))}async getHealth(e){return vu(this.getRequestOptionsForCall(e))}async getReadiness(e){return async function(e){const t=await _s(e,{method:"get",url:"readiness"}),n=ci.asObject(t.data,{name:"response.data"});return{apiVersion:ci.asString(n.apiVersion,{name:"apiVersion"}),version:ci.asString(n.version,{name:"version"}),status:ci.asString(n.status,{name:"status"})}}(this.getRequestOptionsForCall(e))}async getNodeInfo(e){return async function(e){const t=await _s(e,{method:"get",url:"node",responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"});return{beeMode:to(ci.asString(n.beeMode,{name:"beeMode"})),chequebookEnabled:ci.asBoolean(n.chequebookEnabled,{name:"chequebookEnabled"}),swapEnabled:ci.asBoolean(n.swapEnabled,{name:"swapEnabled"})}}(this.getRequestOptionsForCall(e))}async isSupportedExactVersion(e){return async function(e){const{version:t}=await vu(e);return t===wu}(this.getRequestOptionsForCall(e))}async isSupportedApiVersion(e){return async function(e){const{apiVersion:t}=await vu(e);return yu(t)===yu(bu)}(this.getRequestOptionsForCall(e))}async getVersions(e){return async function(e){const{version:t,apiVersion:n}=await vu(e);return{supportedBeeVersion:wu,supportedBeeApiVersion:bu,beeVersion:t,beeApiVersion:n}}(this.getRequestOptionsForCall(e))}async getReserveState(e){return async function(e){const t=await _s(e,{method:"get",url:"reservestate",responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"});return{commitment:ci.asNumber(n.commitment,{name:"commitment"}),radius:ci.asNumber(n.radius,{name:"radius"}),storageRadius:ci.asNumber(n.storageRadius,{name:"storageRadius"})}}(this.getRequestOptionsForCall(e))}async getChainState(e){return async function(e){const t=await _s(e,{method:"get",url:"chainstate",responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"});return{block:ci.asNumber(n.block,{name:"block"}),chainTip:ci.asNumber(n.chainTip,{name:"chainTip"}),totalAmount:lo(n.totalAmount,{name:"totalAmount"}),currentPrice:(r=ci.asNumber(n.currentPrice,{name:"currentPrice"}),Number.isInteger(r)?r<24e3?24e3:r:24e3)};var r}(this.getRequestOptionsForCall(e))}async getWalletBalance(e){return async function(e){const t=await _s(e,{method:"get",url:`${Yc}`,responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"});return{bzzBalance:ao.fromPLUR(lo(n.bzzBalance,{name:"bzzBalance"})),nativeTokenBalance:so.fromWei(lo(n.nativeTokenBalance,{name:"nativeTokenBalance"})),chainID:ci.asNumber(n.chainID,{name:"chainID"}),chequebookContractAddress:ci.asString(n.chequebookContractAddress,{name:"chequebookContractAddress"}),walletAddress:ci.asString(n.walletAddress,{name:"walletAddress"})}}(this.getRequestOptionsForCall(e))}async createPostageBatch(e,t,n,r){const i=lo(e,{min:0n,name:"amount"});if(n&&(n=mo(n)),t<17||t>255)throw new Hi("Depth has to be between 17..255",t);const o=await this.getChainState(),a=17280n*BigInt(o.currentPrice)+1n;if(BigInt(i)<a)throw new Hi(`Amount has to be at least ${a} (1 day at current price ${o.currentPrice})`,i);const s=await async function(e,t,n,r){const i={};r?.gasPrice&&(i["gas-price"]=r.gasPrice.toString()),void 0!==r?.immutableFlag&&(i.immutable=String(r.immutableFlag));const o=await _s(e,{method:"post",url:`${Kc}/${t}/${n}`,responseType:"json",params:{label:r?.label},headers:i}),a=ci.asObject(o.data,{name:"response.data"});return new Fi(ci.asString(a.batchID,{name:"batchID"}))}(this.getRequestOptionsForCall(r),i,t,n);return!1!==n?.waitForUsable&&await this.waitForUsablePostageStamp(s,n?.waitForUsableTimeout),s}async buyStorage(e,t,n,r,i,o){const a=To(t,(await this.getChainState(r)).currentPrice,"gnosis"===this.network?5:15),s=Ao(e,i,o);return n&&(n=mo(n)),this.createPostageBatch(a,s,n,r)}async getStorageCost(e,t,n,r,i){const o=To(t,(await this.getChainState(n)).currentPrice,"gnosis"===this.network?5:15);return Bo(Ao(e,r,i),o)}async extendStorage(e,t,n,r,i,o){const a=await this.getPostageBatch(e,r),s=Ao(t,i,o),c=await this.getChainState(r),u=s-a.depth,l=u<=0?1n:2n**BigInt(u),h="gnosis"===this.network?5:15,f=To(n,c.currentPrice,h),d=To(a.duration,c.currentPrice,h),p=(n.isZero()?d*l:d+f*l)-d,m=await this.topUpBatch(a.batchID,p,r);return u>0?this.diluteBatch(a.batchID,s,r):m}async extendStorageSize(e,t,n,r,i){const o=await this.getChainState(n),a=await this.getPostageBatch(e,n),s=Ao(t,r,i),c=s-a.depth;if(c<=0)throw new Hi("New depth has to be greater than the original depth",s);const u=To(a.duration,o.currentPrice,"gnosis"===this.network?5:15);return await this.topUpBatch(a.batchID,u*(2n**BigInt(c)-1n)+1n,n),this.diluteBatch(a.batchID,s,n)}async extendStorageDuration(e,t,n){const r=await this.getPostageBatch(e,n),i=To(t,(await this.getChainState(n)).currentPrice,"gnosis"===this.network?5:15);return this.topUpBatch(r.batchID,i,n)}async getExtensionCost(e,t,n,r,i,o){const a=await this.getPostageBatch(e,r),s=await this.getChainState(r),c="gnosis"===this.network?5:15,u=n.isZero()?0n:To(n,s.currentPrice,c),l=Ao(t,i,o),h=To(a.duration,s.currentPrice,c),f=Bo(a.depth,h);return Bo(l,h+u).minus(f)}async getSizeExtensionCost(e,t,n,r,i){const o=await this.getPostageBatch(e,n),a=await this.getChainState(n),s=Ao(t,r,i);if(s-o.depth<=0)throw new Hi("New depth has to be greater than the original depth",s);const c=To(o.duration,a.currentPrice,"gnosis"===this.network?5:15),u=Bo(o.depth,c);return Bo(s,c).minus(u)}async getDurationExtensionCost(e,t,n){const r=await this.getPostageBatch(e,n),i=To(t,(await this.getChainState(n)).currentPrice,"gnosis"===this.network?5:15);return Bo(r.depth,i)}async topUpBatch(e,t,n){e=new Fi(e);const r=lo(t,{min:1n,name:"amount"});return async function(e,t,n){const r=await _s(e,{method:"patch",url:`${Kc}/topup/${t}/${n}`,responseType:"json"}),i=ci.asObject(r.data,{name:"response.data"});return new Fi(ci.asString(i.batchID,{name:"batchID"}))}(this.getRequestOptionsForCall(n),e,r)}async diluteBatch(e,t,n){return e=new Fi(e),t=ci.asNumber(t,{name:"depth",min:18,max:255}),async function(e,t,n){const r=await _s(e,{method:"patch",url:`${Kc}/dilute/${t}/${n}`,responseType:"json"}),i=ci.asObject(r.data,{name:"response.data"});return new Fi(ci.asString(i.batchID,{name:"batchID"}))}(this.getRequestOptionsForCall(n),e,t)}async getPostageBatch(e,t,n,r){return e=new Fi(e),async function(e,t,n,r){const i=await _s(e,{method:"get",url:`${Kc}/${t}`,responseType:"json"}),o=ci.asObject(i.data,{name:"response.data"}),a=ci.asNumber(o.utilization,{name:"utilization"}),s=ci.asNumber(o.depth,{name:"depth"}),c=ci.asNumber(o.bucketDepth,{name:"bucketDepth"}),u=bo(a,s,c),l=Wc(ci.asNumber(o.batchTTL,{name:"batchTTL"})),h=oo.fromSeconds(l),f=xo(s,n,r);return{batchID:new Fi(ci.asString(o.batchID,{name:"batchID"})),utilization:a,usable:ci.asBoolean(o.usable,{name:"usable"}),label:ci.asEmptiableString(o.label,{name:"label"}),depth:s,amount:lo(o.amount,{name:"amount"}),bucketDepth:c,blockNumber:ci.asNumber(o.blockNumber,{name:"blockNumber"}),immutableFlag:ci.asBoolean(o.immutableFlag,{name:"immutableFlag"}),usage:u,usageText:`${Math.round(100*u)}%`,size:Zc.fromBytes(f),remainingSize:Zc.fromBytes(Math.ceil(f*(1-u))),theoreticalSize:Zc.fromBytes(vo(s)),duration:h,calculateSize(e,t){const n=xo(s,e,t);return Zc.fromBytes(n)},calculateRemainingSize(e,t){const n=xo(s,e,t);return Zc.fromBytes(Math.ceil(n*(1-u)))}}}(this.getRequestOptionsForCall(t),e,n,r)}async getPostageBatchBuckets(e,t){return e=new Fi(e),async function(e,t){const n=await _s(e,{method:"get",url:`${Kc}/${t}/buckets`,responseType:"json"}),r=ci.asObject(n.data,{name:"response.data"});return{depth:ci.asNumber(r.depth,{name:"depth"}),bucketDepth:ci.asNumber(r.bucketDepth,{name:"bucketDepth"}),bucketUpperBound:ci.asNumber(r.bucketUpperBound,{name:"bucketUpperBound"}),buckets:ci.asArray(r.buckets,{name:"buckets"}).map(e=>ci.asObject(e,{name:"bucket"})).map(e=>({bucketID:ci.asNumber(e.bucketID,{name:"bucketID"}),collisions:ci.asNumber(e.collisions,{name:"collisions"})}))}}(this.getRequestOptionsForCall(t),e)}async getAllPostageBatch(e){return Xc(this.getRequestOptionsForCall(e))}async getAllGlobalPostageBatch(e){return Jc(this.getRequestOptionsForCall(e))}async getPostageBatches(e){return Xc(this.getRequestOptionsForCall(e))}async getGlobalPostageBatches(e){return Jc(this.getRequestOptionsForCall(e))}async getAllPendingTransactions(e){return async function(e){const t=await _s(e,{url:Eu,responseType:"json"}),n=ci.asObject(t.data,{name:"response.data"});return ci.asArray(n.pendingTransactions,{name:"pendingTransactions"}).map(xu)}(this.getRequestOptionsForCall(e))}async getPendingTransaction(e,t){return e=new Ui(e),async function(e,t){const n=await _s(e,{url:`${Eu}/${t}`,responseType:"json"});return xu(ci.asObject(n.data,{name:"response.data"}))}(this.getRequestOptionsForCall(t),e)}async rebroadcastPendingTransaction(e,t){return e=new Ui(e),async function(e,t){const n=await _s(e,{method:"post",url:`${Eu}/${t}`,responseType:"json"}),r=ci.asObject(n.data,{name:"response.data"});return new Ui(ci.asString(r.transactionHash,{name:"transactionHash"}))}(this.getRequestOptionsForCall(t),e)}async cancelPendingTransaction(e,t,n){let r;return e=new Ui(e),t&&(r=lo(t,{min:0n,name:"gasPrice"})),async function(e,t,n){const r={};n&&(r["gas-price"]=n.toString());const i=await _s(e,{method:"delete",headers:r,url:`${Eu}/${t}`,responseType:"json"}),o=ci.asObject(i.data,{name:"response.data"});return new Ui(ci.asString(o.transactionHash,{name:"transactionHash"}))}(this.getRequestOptionsForCall(n),e,r)}async getStake(e){return async function(e){const t=await _s(e,{method:"get",responseType:"json",url:`${Hc}`}),n=ci.asObject(t.data,{name:"response.data"});return ao.fromPLUR(lo(n.stakedAmount,{name:"stakedAmount"}))}(this.getRequestOptionsForCall(e))}async getWithdrawableStake(e){return async function(e){const t=await _s(e,{method:"get",responseType:"json",url:`${Hc}/withdrawable`}),n=ci.asObject(t.data,{name:"response.data"});return ao.fromPLUR(lo(n.withdrawableAmount,{name:"withdrawableAmount"}))}(this.getRequestOptionsForCall(e))}async withdrawSurplusStake(e){return async function(e){const t=await _s(e,{method:"delete",responseType:"json",url:`${Hc}/withdrawable`}),n=ci.asObject(t.data,{name:"response.data"});return new Ui(ci.asHexString(n.txHash,{name:"txHash"}))}(this.getRequestOptionsForCall(e))}async migrateStake(e){return async function(e){const t=await _s(e,{method:"delete",responseType:"json",url:Hc}),n=ci.asObject(t.data,{name:"response.data"});return new Ui(ci.asHexString(n.txHash,{name:"txHash"}))}(this.getRequestOptionsForCall(e))}async depositStake(e,t,n){const r=e instanceof ao?e.toPLURString():lo(e,{min:1n,name:"amount"});return t&&(t=go(t)),async function(e,t,n){const r=await _s(e,{method:"post",responseType:"json",url:`${Hc}/${t}`,headers:So(null,n)}),i=ci.asObject(r.data,{name:"response.data"});return new Ui(ci.asHexString(i.txHash,{name:"txHash"}))}(this.getRequestOptionsForCall(n),r,t)}async getRedistributionState(e){return async function(e){const t=await _s(e,{method:"get",responseType:"json",url:"redistributionstate"}),n=ci.asObject(t.data,{name:"response.data"});return{minimumGasFunds:so.fromWei(lo(n.minimumGasFunds,{name:"minimumGasFunds"})),hasSufficientFunds:ci.asBoolean(n.hasSufficientFunds,{name:"hasSufficientFunds"}),isFrozen:ci.asBoolean(n.isFrozen,{name:"isFrozen"}),isFullySynced:ci.asBoolean(n.isFullySynced,{name:"isFullySynced"}),phase:ci.asString(n.phase,{name:"phase"}),round:ci.asNumber(n.round,{name:"round"}),lastWonRound:ci.asNumber(n.lastWonRound,{name:"lastWonRound"}),lastPlayedRound:ci.asNumber(n.lastPlayedRound,{name:"lastPlayedRound"}),lastFrozenRound:ci.asNumber(n.lastFrozenRound,{name:"lastFrozenRound"}),lastSelectedRound:ci.asNumber(n.lastSelectedRound,{name:"lastSelectedRound"}),lastSampleDurationSeconds:ci.asNumber(n.lastSampleDurationSeconds,{name:"lastSampleDurationSeconds"}),block:ci.asNumber(n.block,{name:"block"}),reward:ao.fromPLUR(lo(n.reward,{name:"reward"})),fees:so.fromWei(lo(n.fees,{name:"fees"})),isHealthy:ci.asBoolean(n.isHealthy,{name:"isHealthy"})}}(this.getRequestOptionsForCall(e))}async waitForUsablePostageStamp(e,t=24e4){for(let n=0;n<t;n+=3e3){try{if((await this.getPostageBatch(e)).usable)return}catch(e){}await si.sleepMillis(3e3)}throw new Gi("Timeout on waiting for postage stamp to become usable")}getRequestOptionsForCall(e){return e&&(e=function(e){const t=ci.asObject(e,{name:"BeeRequestOptions"});return{baseURL:ci.asOptional(e=>ci.asString(e,{name:"baseURL"}),t.baseURL),timeout:ci.asOptional(e=>ci.asInteger(e,{name:"timeout",min:0}),t.timeout),headers:ci.asOptional(e=>ci.asStringMap(e,{name:"headers"}),t.headers),onRequest:ci.asOptional(e=>ci.asFunction(e,{name:"onRequest"}),t.onRequest),httpAgent:t.httpAgent,httpsAgent:t.httpsAgent,endlesslyRetry:ci.asOptional(e=>ci.asBoolean(e,{name:"endlesslyRetry"}),t.endlesslyRetry)}}(e)),e?oi.deepMerge2(this.requestOptions,e):this.requestOptions}}class Fu{constructor(e,t,n,r){this.signer=new zi(e),this.batchId=new Fi(t),this.buckets=n,this.depth=r,this.maxSlot=2**(this.depth-16)}static fromBlank(e,t,n){return new Fu(e,t,new Uint32Array(65536),n)}static fromState(e,t,n,r){return new Fu(e,t,n,r)}stamp(e){const t=e.hash(),n=ti.uint16ToNumber(t,"BE"),r=this.buckets[n];if(r>=this.maxSlot)throw Error("Bucket is full");this.buckets[n]++;const i=ti.concatBytes(ti.numberToUint32(n,"BE"),ti.numberToUint32(r,"BE")),o=ti.numberToUint64(BigInt(Date.now()),"BE"),a=this.signer.sign(ti.concatBytes(t,this.batchId.toUint8Array(),i,o));return{batchId:this.batchId,index:i,issuer:this.signer.publicKey().address().toUint8Array(),signature:a.toUint8Array(),timestamp:o}}getState(){return this.buckets}}no.MEDIUM,no.STRONG,no.INSANE,no.PARANOID;function Mu(e){const t=[];for(let n=0;n<e.length;n+=4096)t.push(e.slice(n,Math.min(n+4096,e.length)));return t}async function ju(e,t){if(1===e.length)return new Ni(e[0].address);const n=[];for(let r=0;r<e.length;r+=64){const i=e.slice(r,Math.min(r+64,e.length)),o=new Uint8Array(32*i.length);i.forEach((e,t)=>{o.set(e.address,32*t)});const a=Yi(o);n.push({address:a.address.toUint8Array()}),await t(a)}return n.length>1?ju(n,t):new Ni(n[0].address)}let Lu=class{constructor(e){this.cursor=0,this.buffer=e}write(e){throw new Error("SimpleUint8ArrayWriter.write() not implemented")}max(){return this.buffer.length}};class qu{constructor(e){this.chunk=e,this.span=e.span.toBigInt(),this.writer=new Lu(e.data)}hash(){return this.chunk.address.toUint8Array()}build(){return this.chunk.data}}async function Gu(e,t,n,r){const{bee:i,stamper:o,postageBatchId:a}=e;if(!o&&!a)throw new Error("No authentication method available");let s=n?.tag;if(!s){s=(await i.createTag()).uid}const c=Mu(t);let u=c.length,l=0;console.log(`[UploadData] Splitting ${t.length} bytes into ${u} chunks`);const h=()=>{r&&r({total:u,processed:l})},f=[],d={...n,tag:s};for(const e of c){const t=Yi(e);f.push({address:t.address.toUint8Array()}),await Hu(i,o,a,t,d),l++,h()}let p;return 1===f.length?(p=new Ni(f[0].address),console.log("[UploadData] Single chunk upload, reference:",p.toHex())):(console.log("[UploadData] Building merkle tree for",f.length,"chunks"),p=await ju(f,async e=>{await Hu(i,o,a,e,d),u++,l++,h()}),console.log("[UploadData] Merkle tree complete, root reference:",p.toHex())),{reference:p.toHex(),tagUid:s}}async function Hu(e,t,n,r,i){const o={...i,deferred:!0,pin:!1};if(console.log("[UploadData] uploadChunk options:",o),t){const n=new qu(r),i=t.stamp(n);await e.uploadChunk(i,r.data,o)}else{if(!n)throw new Error("No stamper or batch ID available");await e.uploadChunk(n,r.data,o)}}var Zu,Wu={};var Ku=(Zu||(Zu=1,function(e){var t;async function n(e){return new Promise((t,n)=>e.then(n,t))}async function r(e){return new Promise(t=>setTimeout(()=>{t(!0)},e))}function i(e,t=Math.random){for(let n=e.length-1;n>0;n--){const r=Math.floor(t()*(n+1)),i=e[n];e[n]=e[r],e[r]=i}return e}function o(e,t,n=Math.random){return i(q(0,e.length-1),n).slice(0,t)}function a(e,t,n=Math.random){return Math.floor(n()*(t-e+1))+e}function s(e,t,n){return t>=e.x&&t<e.x+e.width&&n>=e.y&&n<e.y+e.height}function c(e,t=Math.random){return t()<e}function u(e,t=Math.random){return e[Math.floor(e.length*t())]}function l(e){if(!e.length)throw Error("Received empty array");return e[e.length-1]}function h(e,t,n){return n(t.reduce((e,t)=>t(e),e))}function f(e,t){if(null==e)return null;const n=t.split(".");let r=e;for(const e of n){if(null===r[e]||void 0===r[e])return null;r=r[e]}return r}function d(e,t,n){const r=t.split(/\.|\[/);let i=e;for(let e=0;e<r.length;e++){const t=r[e],o=e<r.length-1&&r[e+1].includes("]"),a=t.includes("]")?t.replace(/\[|\]/g,""):t;if(e===r.length-1)return i[a]=n,n;m(i[a])||(i[a]=o?[]:{}),i=i[a]}return n}function p(e,t){return Math.round(e/t)*t}function m(e,t=!0){return!(!e||t&&!w(e._readableState)||t&&e.constructor&&(e.constructor.isBuffer||"Uint8Array"==e.constructor.name||"ArrayBuffer"===e.constructor.name||"ReadableStream"===e.constructor.name))&&"object"==typeof e}function g(e){return m(e)&&!Array.isArray(e)}function y(e){return Array.isArray(e)&&0===e.length}function w(e){return void 0===e}function b(e){return"[object Function]"===Object.prototype.toString.call(e)||"[object AsyncFunction]"===Object.prototype.toString.call(e)}function v(e){return"[object String]"===Object.prototype.toString.call(e)}function E(e){return"number"==typeof e&&isFinite(e)}function x(e){return!0===e||!1===e}function B(e){return"[object Date]"===Object.prototype.toString.call(e)}function T(e){return!v(e)||0===e.trim().length}function A(e){return E(e)&&Number.isInteger(e)&&e>=1}function O(e){return v(e)&&null!==e.match(/^-?\d+$/)}function R(e){return v(e)&&null!==e.match(/^(0x)?[0-9a-f]+$/i)}Object.defineProperty(e,"__esModule",{value:!0}),e.Vector=e.Cache=e.Assertions=e.Strings=e.Types=e.Objects=e.Dates=e.Promises=e.Numbers=e.System=e.Arrays=e.Random=e.Elliptic=e.Binary=e.RollingValueProvider=e.TrieRouter=e.AsyncQueue=e.PubSubChannel=e.FixedPointNumber=e.MerkleTree=e.Chunk=e.Uint8ArrayWriter=e.Uint8ArrayReader=e.AsyncLazy=e.Lazy=e.Optional=void 0;const S="!@#$%^&*()_+-=[]{}|;:<>?,./".split(""),k="abcdefghijklmnopqrstuvwxyz",$=k+"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",I=$+"!@#$%^&*()_+-=[]{}|;:<>?,./",z=["—","\\","東","京","都","𝖆","𝖇","𝖈","👾","🙇","💁","🙅","ᚠ","ᛇ","ᚻ","ᛦ"],D="0123456789abcdef";function C(e,t){if(T(e))throw new TypeError(`Expected string${t?.name?` for ${t.name}`:""}, got: `+e);if(t&&(void 0!==t.min&&e.length<t.min||void 0!==t.max&&e.length>t.max))throw RangeError(`Expected string${t?.name?` for ${t.name}`:""} length in range: ${t.min??"-inf"}..${t.max??"inf"}; got: ${e.length}`);return e}function P(e,t){if(void 0!==t.min&&e<t.min||void 0!==t.max&&e>t.max)throw RangeError(`Expected value${t?.name?` for ${t.name}`:""} in range: ${t.min??"-inf"}..${t.max??"inf"}; got: ${e}`)}function N(e,t){if(E(e))return t&&P(e,t),e;if(!v(e)||!e.match(/^-?\d+(\.\d+)?$/))throw new TypeError(`Expected number${t?.name?` for ${t.name}`:""}, got: `+e);const n=parseFloat(e);return t&&P(n,t),n}function U(e,t){return Math.trunc(N(e,t))}function _(e,t){if(!g(e))throw new TypeError(`Expected object${t?.name?` for ${t.name}`:""}, got: `+e);return e}function V(e){return v(e)&&null!==e.match(/^https?:\/\/.+/)}function F(e,t){for(const[n,r]of Object.entries(t))if(!r(e[n]))throw TypeError(`${n} in value does not exist or match shape`);for(const n of Object.keys(e))if(!t[n])throw TypeError(`${n} exists in value but not in shape`);return!0}function M(e,t){if(g(e)&&g(t))for(const n in t)g(t[n])?(e[n]||(e[n]={}),M(e[n],t[n])):Array.isArray(t[n])?e[n]=[...t[n]]:(null!==t[n]&&void 0!==t[n]||null===e[n]||void 0===e[n])&&(e[n]=t[n]);return e}function j(e,t){const n={};for(const r of e)for(const e of Object.keys(r))n[e]?n[e]=t(n[e],r[e]):n[e]=r[e];return n}function L(e,t){Array.prototype.push.apply(e,t)}function q(e,t){const n=[];for(let r=e;r<=t;r++)n.push(r);return n}function G(e,t=()=>!1){return e.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").split("").map(e=>/[a-z0-9]/.test(e)||t(e)?e:"-").join("").replace(/-+/g,"-").replace(/^-|-$/g,"")}function H(e,t){if(0===t.length)return 0;const n=e.toLowerCase(),r=t.toLowerCase();return e===t?1e4:n.startsWith(r)?1e4-e.length:n.includes(r)?5e3-e.length:new RegExp(".*"+r.split("").join(".*")+".*").test(n)?1e3-e.length:0}const Z={"&":"&",""":'"',"'":"'",">":">","<":"<"};function W(e,t){const n=e.indexOf(t);return-1===n?null:e.slice(0,n)}function K(e,t){const n=e.indexOf(t);return-1===n?null:e.slice(n+t.length)}function J(e,t){const n=e.lastIndexOf(t);return-1===n?null:e.slice(0,n)}function X(e,t){const n=e.lastIndexOf(t);return-1===n?null:e.slice(n+t.length)}function Y(e,t,n=!1){const r=n?e.lastIndexOf(t):e.indexOf(t);return-1===r?n?[null,e]:[e,null]:[e.slice(0,r),e.slice(r+t.length)]}function Q(e,t){let n=[e];for(const e of t)n=n.flatMap(t=>t.split(e));return n.filter(e=>e)}function ee(e){const t=l(e.split(/\\|\//g)),n=t.lastIndexOf(".",t.length-1);return n<=0?"":t.slice(n+1)}function te(e){const t=l(e.split(/\\|\//g)),n=t.lastIndexOf(".",t.length-1);return n<=0?t:t.slice(0,n)}function ne(e){return e.split("\n").map(e=>e.trim().replace(/\s+/g," ")).filter(e=>e.length>0).join("\n")}function re(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ie(e){return e.charAt(0).toLowerCase()+e.slice(1)}function oe(e){if(!e)return!1;const t=e.charCodeAt(0);return t>=65&&t<=90||t>=97&&t<=122}function ae(e){if(!e)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}function se(e){return oe(e)||ae(e)}const ce=" \n\t\r.,?!:;\"'`(){}[]~@#$%^&*-+=|<>/\\".split("");function ue(e){return ce.includes(e)}function le(e,t,n=0){const r=t.exec(e.slice(n));return r?{index:r.index,match:r[0]}:null}function he(e,t,n=!0){if(!n)return t.every(t=>t instanceof RegExp?t.test(e):-1!==e.indexOf(t,0));let r=0;for(const n of t)if(n instanceof RegExp){const t=le(e,n,r);if(!t)return!1;r=t.index+t.match.length}else{const t=e.indexOf(n,r);if(-1===t)return!1;r=t+n.length}return!0}function fe(e,t,n=0){const r=[];let i=e.indexOf(t,n);for(;-1!==i;)r.push(i),i=e.indexOf(t,i+t.length);return r}function de(e,t,n=0){let r=-1;for(const i of t){const t=e.indexOf(i,n);-1!==t&&(-1===r||t<r)&&(r=t)}return r}function pe(e,t=0){for(let n=t;n<e.length;n++)if(ue(e[n]))return n;return-1}function me(e,t=0){for(let n=t;n<e.length;n++)if("#"===e[n]&&se(e[n+1]))return n;return-1}function ge(e,t,n=0){return e.slice(0,n).lastIndexOf(t)}function ye(e,t=0,n="{",r="}"){let i=1;for(let o=t;o<e.length;o++)if(e.slice(o,o+r.length)===r){if(0===--i)return o}else e.slice(o,o+n.length)===n&&i++;return-1}function we(e,t){const n=t.wordBoundary?de(e,[`${t.opening} `,`${t.opening}\n`],t.start||0):e.indexOf(t.opening,t.start||0);if(-1===n)return null;const r=ye(e,n+t.opening.length,t.opening,t.closing);return-1===r?null:t.exclusive?e.slice(n+t.opening.length,r):e.slice(n,r+t.closing.length)}const be="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ve="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function Ee(e,t){const n=t.length;let r=0,i=0;const o=[];for(let a=0;a<e.length;a++){const s=e[a];if("="===s)break;const c=t.indexOf(s);if(-1===c)throw new Error(`Invalid character: ${s}`);i=i<<Math.log2(n)|c,r+=Math.log2(n),r>=8&&(r-=8,o.push(i>>r&255))}return new Uint8Array(o)}function xe(e,t){const n=t.length;let r=0,i=0,o="";for(let a=0;a<e.length;a++)for(i=i<<8|e[a],r+=8;r>=Math.log2(n);)r-=Math.log2(n),o+=t[i>>r&n-1];return r>0&&(o+=t[i<<Math.log2(n)-r&n-1]),o.length%4!=0&&(o+="=".repeat(4-o.length%4)),o}function Be(e,t,n){const r=[];for(const i of n)i!==t&&r.push(e.replace(t,i));return r}function Te(e){const t=e.lastIndexOf(" ");return-1===t?{line:e,rest:""}:{line:e.slice(0,t),rest:e.slice(t+1)}}function Ae(e){const t=e.reduce((e,t)=>e.length<t.length?e:t);let n="";for(let r=0;r<t.length;r++){const i=t[r];if(!e.every(e=>e[r]===i))break;n+=i}return n}function Oe(e,t){return new RegExp(`\\b${t}\\b`).test(e)}function Re(e,t,n=[]){let r="";for(;t<e.length&&(se(e[t])||n.includes(e[t]));)r+=e[t++];return r}function Se(e,t,n,r="$",i=":"){if(""===n)return e;let o=e.indexOf(`${r}${t}`);for(;-1!==o;){if(e[o+t.length+1]===i)if(e[o+t.length+2]===i)e=e.replace(`${r}${t}${i}${i}`,n);else{const a=Re(e,o+t.length+2,["_"]);e=e.replace(`${r}${t}${i}${a}`,n)}else e=e.replace(`${r}${t}`,n);o=e.indexOf(`${r}${t}`,o+n.length)}return e}function ke(e,t="$",n=":"){let r=e.indexOf(t);for(;-1!==r;){const i=Re(e,r+1);if(e[r+i.length+1]===n)if(e[r+i.length+2]===n)e=e.replace(`${t}${i}${n}${n}`,"");else{const o=Re(e,r+i.length+2);e=e.replace(`${t}${i}${n}${o}`,o)}r=e.indexOf(t,r+1)}return e}function $e(e,t=!0){const n=Object.entries(e).filter(([e,t])=>null!=t).map(([e,t])=>`${e}=${encodeURIComponent(t)}`).join("&");return n?(t?"?":"")+n:""}function Ie(e){return String(Math.floor(e)).padStart(2,"0")}function ze(e){const t=Math.floor(e/36e5);e%=36e5;const n=Math.floor(e/6e4);e%=6e4;const r=Math.floor(e/1e3);return t?`${Ie(t)}:${Ie(n)}:${Ie(r)}`:`${Ie(n)}:${Ie(r)}`}function De(e){return Math.floor((B(e)?e.getTime():e)/864e5)}const Ce={today:(e,t)=>Ie(e)+":"+Ie(t),yesterday:()=>"Yesterday",monday:()=>"Mon",tuesday:()=>"Tue",wednesday:()=>"Wed",thursday:()=>"Thu",friday:()=>"Fri",saturday:()=>"Sat",sunday:()=>"Sun",weeks:e=>`${e}w`},Pe={now:()=>"A few seconds",seconds:e=>`${e} seconds`,minutes:e=>`${e} minutes`,hours:e=>`${e} hours`,days:e=>`${e} days`,weeks:e=>`${e} weeks`};function Ne(t,n){const r=n?.now??Date.now(),i=n?.labels||Pe;let o=(r-(e.Types.isDate(t)?t.getTime():t))/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 Ue={},_e={s:1e3,m:6e4,h:36e5,d:864e5},Ve={0:"sunday",1:"monday",2:"tuesday",3:"wednesday",4:"thursday",5:"friday",6:"saturday"};function Fe(e){return{zeroBasedIndex:e,day:Ve[e]}}function Me(e){return Fe(e.getDay())}const je={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},Le={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},qe=new Map;function Ge(e,t=!1){e=e.filter(e=>e),t&&v(e[1])&&(e[1]="../"+e[1]);let n="";v(e[0])&&e[0].includes("://")&&(n=W(e[0],"://")??"",e[0]=K(e[0],"://")??"");const r=e.map(e=>String(e)).flatMap(e=>e.split("/")),i=[];for(let e=0;e<r.length;e++)"."!==r[e]&&(".."===r[e]?(!n||i.length>1)&&i.pop():i.push(r[e]));return(n?n+"://":"")+i.join("/").replaceAll(/\/{2,}/g,"/")}function He(e){const t=Object.keys(e).sort((e,t)=>e.localeCompare(t)),n={};for(const r of t)n[r]=We(e[r]);return n}function Ze(e){const t=[];return e.sort((e,t)=>JSON.stringify(We(e)).localeCompare(JSON.stringify(We(t)))).forEach(e=>t.push(We(e))),t}function We(e){return Array.isArray(e)?Ze(e):m(e)?He(e):e}function Ke(e,t){return JSON.stringify(We(e))===JSON.stringify(We(t))}function Je(e){const t=Object.keys(e);return t[Math.floor(Math.random()*t.length)]}const Xe=[1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24,1e27,1e30,1e9,1e16,1e18,1e18,1e18,1e33],Ye=["thousand","million","billion","trillion","quadrillion","quintillion","sextillion","septillion","octillion","nonillion","gwei","bzz","btc","eth","dai","decillion"],Qe=["K","M","B","T","Qa","Qi","Sx","Sp","O","N","gwei","bzz","eth","btc","dai","D"];function et(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeNumber got NaN for input");const n=e.replace(/^-?[0-9.]+/,"").trim(),r=Qe.findIndex(e=>e.toLowerCase()===n.toLowerCase());return-1===r?t:t*Xe[r]}function tt(e,t,n){return e<t?t:e>n?n:e}function nt(e,t,n){return e+(n?"["+t+"]":(e.length?".":"")+t)}function rt(e,t,n,r,i){if(!m(t))return t;for(const[o,a]of Object.entries(t)){const t=nt(n,o,r);Array.isArray(a)?i?rt(e,a,t,!0,i):e[t]=a.map(e=>rt(Array.isArray(e)?[]:{},e,"",!1,i)):m(a)?rt(e,a,t,!1,i):e[t]=a}return e}function it(e,t){const n={};for(const r of e)n[t(r)]=r;return n}function ot(e,t){const n=Math.ceil(e.length/t),r=[];for(let t=0;t<e.length;t+=n)r.push(e.slice(t,t+n));return r}function at(e,t){const n=[],r=Math.ceil(e.length/t);for(let i=0;i<r;i++)n.push(e.slice(i*t,i*t+t));return n}function st(e,t){return Object.fromEntries(Object.entries(e).sort(t))}function ct(e,t){const n=[];let r=[];return e.forEach((i,o)=>{(0===o||!t(i,e[o-1]))&&(r=[],n.push(r)),r.push(i)}),n}function ut(e,t,n,r=100){if(e.map.has(t)){const n=e.keys.indexOf(t);e.keys.splice(n,1)}if(e.map.set(t,n),e.keys.push(t),e.keys.length>r){const t=e.keys.shift();t&&e.map.delete(t)}}class lt{constructor(e){this.value=e}static of(e){return new lt(e)}static empty(){return new lt(null)}map(e){return new lt(null!==this.value&&void 0!==this.value?e(this.value):null)}mapAsync(e){return null!==this.value&&void 0!==this.value?e(this.value).then(e=>lt.of(e)):Promise.resolve(lt.empty())}ifPresent(e){return null!==this.value&&void 0!==this.value&&e(this.value),this}ifPresentAsync(e){return null!==this.value&&void 0!==this.value?e(this.value).then(()=>this):Promise.resolve(this)}ifAbsent(e){return(null===this.value||void 0===this.value)&&e(),this}ifAbsentAsync(e){return null===this.value||void 0===this.value?e().then(()=>this):Promise.resolve(this)}getOrFallback(e){return this.value??e()}getOrFallbackAsync(e){return null!==this.value&&void 0!==this.value?Promise.resolve(this.value):e()}getOrThrow(){if(null===this.value||void 0===this.value)throw Error("Optional.value is empty");return this.value}}e.Optional=lt,e.Lazy=class{constructor(e){this.supplier=e,this.value=null}get(){return this.value||(this.value=this.supplier()),this.value}},e.AsyncLazy=class{constructor(e){this.supplier=e,this.value=null}async get(){return this.value||(this.value=await this.supplier()),this.value}};class ht{constructor(e){this.value=e,this.children=[]}}function ft(e,t){if(Math.log2(e.length)%1!=0)throw new Error("Array length must be a power of 2");let n=[...e];for(;n.length>1;){const e=[];for(let r=0;r<n.length;r+=2){const i=n[r+1];e.push(t(n[r],i))}n=e}return n[0]}function dt(...e){const t=e.reduce((e,t)=>e+t.length,0),n=new Uint8Array(t);let r=0;return e.forEach(e=>{n.set(e,r),r+=e.length}),n}function pt(e){return 137===e[0]&&80===e[1]&&78===e[2]&&71===e[3]}function mt(e){return 255===e[0]&&216===e[1]}function gt(e){return 87===e[8]&&69===e[9]&&66===e[10]&&80===e[11]}function yt(e,t){const n=new ArrayBuffer(8);return new DataView(n).setBigUint64(0,BigInt(e),"LE"===t),new Uint8Array(n)}function wt(e,t){const n=new Uint8Array(32);let r=e;if("LE"===t){for(let e=0;e<32;e++)n[e]=Number(0xffn&r),r>>=8n;return n}for(let e=31;e>=0;e--)n[e]=Number(0xffn&r),r>>=8n;return n}function bt(e,t){let n=0n;if("LE"===t){for(let t=31;t>=0;t--)n=n<<8n|BigInt(e[t]);return n}for(let t=0;t<32;t++)n=n<<8n|BigInt(e[t]);return n}function vt(e,t){const n=[];for(let r=0;r<e.length;r+=t)n.push(e.subarray(r,r+t));return n}const Et=[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 xt(e){for(let t=0;t<24;t++){const n=e[0]^e[10]^e[20]^e[30]^e[40],r=e[1]^e[11]^e[21]^e[31]^e[41],i=e[2]^e[12]^e[22]^e[32]^e[42],o=e[3]^e[13]^e[23]^e[33]^e[43],a=e[4]^e[14]^e[24]^e[34]^e[44],s=e[5]^e[15]^e[25]^e[35]^e[45],c=e[6]^e[16]^e[26]^e[36]^e[46],u=e[7]^e[17]^e[27]^e[37]^e[47],l=e[8]^e[18]^e[28]^e[38]^e[48],h=e[9]^e[19]^e[29]^e[39]^e[49],f=l^(i<<1|o>>>31),d=h^(o<<1|i>>>31),p=n^(a<<1|s>>>31),m=r^(s<<1|a>>>31),g=i^(c<<1|u>>>31),y=o^(u<<1|c>>>31),w=a^(l<<1|h>>>31),b=s^(h<<1|l>>>31),v=c^(n<<1|r>>>31),E=u^(r<<1|n>>>31);e[0]^=f,e[1]^=d,e[2]^=p,e[3]^=m,e[4]^=g,e[5]^=y,e[6]^=w,e[7]^=b,e[8]^=v,e[9]^=E,e[10]^=f,e[11]^=d,e[12]^=p,e[13]^=m,e[14]^=g,e[15]^=y,e[16]^=w,e[17]^=b,e[18]^=v,e[19]^=E,e[20]^=f,e[21]^=d,e[22]^=p,e[23]^=m,e[24]^=g,e[25]^=y,e[26]^=w,e[27]^=b,e[28]^=v,e[29]^=E,e[30]^=f,e[31]^=d,e[32]^=p,e[33]^=m,e[34]^=g,e[35]^=y,e[36]^=w,e[37]^=b,e[38]^=v,e[39]^=E,e[40]^=f,e[41]^=d,e[42]^=p,e[43]^=m,e[44]^=g,e[45]^=y,e[46]^=w,e[47]^=b,e[48]^=v,e[49]^=E;const x=e[0],B=e[1],T=e[2]<<1|e[3]>>>31,A=e[3]<<1|e[2]>>>31,O=e[5]<<30|e[4]>>>2,R=e[4]<<30|e[5]>>>2,S=e[6]<<28|e[7]>>>4,k=e[7]<<28|e[6]>>>4,$=e[8]<<27|e[9]>>>5,I=e[9]<<27|e[8]>>>5,z=e[11]<<4|e[10]>>>28,D=e[10]<<4|e[11]>>>28,C=e[13]<<12|e[12]>>>20,P=e[12]<<12|e[13]>>>20,N=e[14]<<6|e[15]>>>26,U=e[15]<<6|e[14]>>>26,_=e[17]<<23|e[16]>>>9,V=e[16]<<23|e[17]>>>9,F=e[18]<<20|e[19]>>>12,M=e[19]<<20|e[18]>>>12,j=e[20]<<3|e[21]>>>29,L=e[21]<<3|e[20]>>>29,q=e[22]<<10|e[23]>>>22,G=e[23]<<10|e[22]>>>22,H=e[25]<<11|e[24]>>>21,Z=e[24]<<11|e[25]>>>21,W=e[26]<<25|e[27]>>>7,K=e[27]<<25|e[26]>>>7,J=e[29]<<7|e[28]>>>25,X=e[28]<<7|e[29]>>>25,Y=e[31]<<9|e[30]>>>23,Q=e[30]<<9|e[31]>>>23,ee=e[33]<<13|e[32]>>>19,te=e[32]<<13|e[33]>>>19,ne=e[34]<<15|e[35]>>>17,re=e[35]<<15|e[34]>>>17,ie=e[36]<<21|e[37]>>>11,oe=e[37]<<21|e[36]>>>11,ae=e[38]<<8|e[39]>>>24,se=e[39]<<8|e[38]>>>24,ce=e[40]<<18|e[41]>>>14,ue=e[41]<<18|e[40]>>>14,le=e[42]<<2|e[43]>>>30,he=e[43]<<2|e[42]>>>30,fe=e[45]<<29|e[44]>>>3,de=e[44]<<29|e[45]>>>3,pe=e[47]<<24|e[46]>>>8,me=e[46]<<24|e[47]>>>8,ge=e[48]<<14|e[49]>>>18,ye=e[49]<<14|e[48]>>>18;e[0]=x^~C&H,e[1]=B^~P&Z,e[2]=C^~H&ie,e[3]=P^~Z&oe,e[4]=H^~ie&ge,e[5]=Z^~oe&ye,e[6]=ie^~ge&x,e[7]=oe^~ye&B,e[8]=ge^~x&C,e[9]=ye^~B&P,e[10]=S^~F&j,e[11]=k^~M&L,e[12]=F^~j&ee,e[13]=M^~L&te,e[14]=j^~ee&fe,e[15]=L^~te&de,e[16]=ee^~fe&S,e[17]=te^~de&k,e[18]=fe^~S&F,e[19]=de^~k&M,e[20]=T^~N&W,e[21]=A^~U&K,e[22]=N^~W&ae,e[23]=U^~K&se,e[24]=W^~ae&ce,e[25]=K^~se&ue,e[26]=ae^~ce&T,e[27]=se^~ue&A,e[28]=ce^~T&N,e[29]=ue^~A&U,e[30]=$^~z&q,e[31]=I^~D&G,e[32]=z^~q&ne,e[33]=D^~G&re,e[34]=q^~ne&pe,e[35]=G^~re&me,e[36]=ne^~pe&$,e[37]=re^~me&I,e[38]=pe^~$&z,e[39]=me^~I&D,e[40]=O^~_&J,e[41]=R^~V&X,e[42]=_^~J&Y,e[43]=V^~X&Q,e[44]=J^~Y&le,e[45]=X^~Q&he,e[46]=Y^~le&O,e[47]=Q^~he&R,e[48]=le^~O&_,e[49]=he^~R&V,e[0]^=Et[2*t],e[1]^=Et[2*t+1]}}function Bt(e){const t=[];for(let n=0;n<e.length;n+=4)t.push(e[n]|e[n+1]<<8|e[n+2]<<16|e[n+3]<<24);return t}function Tt(e,t){if(!e.length){const e=new Uint8Array(136);return e[0]=t,e[135]=128,[Bt(e)]}const n=vt(e,136),r=n[n.length-1];if(r.length<136){const e=new Uint8Array(136);e.set(r),e[r.length]=t,e[135]|=128,n[n.length-1]=e}if(136===r.length){const e=new Uint8Array(136);e[0]=t,e[135]=128,n.push(e)}return n.map(Bt)}function At(e,t){for(const n of t){for(let t=0;t<34;t+=2)e[t]^=n[t+1],e[t+1]^=n[t];xt(e)}return e}function Ot(e){return new Uint8Array([e[1],e[1]>>-24,e[1]>>-16,e[1]>>-8,e[0],e[0]>>8,e[0]>>16,e[0]>>24,e[3],e[3]>>-24,e[3]>>-16,e[3]>>-8,e[2],e[2]>>8,e[2]>>16,e[2]>>24,e[5],e[5]>>-24,e[5]>>-16,e[5]>>-8,e[4],e[4]>>8,e[4]>>16,e[4]>>24,e[7],e[7]>>-24,e[7]>>-16,e[7]>>-8,e[6],e[6]>>8,e[6]>>16,e[6]>>24])}function Rt(e){return Ot(At(new Array(50).fill(0),Tt(e,1)))}function St(e,t,n=0){if(e.length>=t)return e;const r=new Uint8Array(t);return r.fill(n),r.set(e,t-e.length),r}function kt(e,t,n=0){if(e.length>=t)return e;const r=new Uint8Array(t);return r.fill(n),r.set(e,0),r}function $t(e,t){return(e%t+t)%t}function It(e,t){e=$t(e,t);let[n,r]=[0n,1n],[i,o]=[t,e];for(;0n!==o;){const e=i/o;[n,r]=[r,n-e*r],[i,o]=[o,i-e*o]}if(i>1n)throw new Error("a is not invertible");return n<0n&&(n+=t),n}function zt(e,t){return 0n===$t(e,t)?0n:t%4n==3n?function(e,t,n){let r=1n;for(e=$t(e,n);t>0;)t%2n==1n&&(r=$t(r*e,n)),e=$t(e*e,n),t/=2n;return r}(e,(t+1n)/4n,t):null}const Dt=0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,Ct=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,Pt=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,Nt=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n;function Ut(e,t,n){if(0n===t)return[0n,0n];const r=$t(3n*e*e*It(2n*t,n),n),i=$t(r*r-2n*e,n);return[i,$t(r*(e-i)-t,n)]}function _t(e,t,n,r,i){if(0n===e&&0n===t)return[n,r];if(0n===n&&0n===r)return[e,t];if(e===n&&t===$t(-r,i))return[0n,0n];if(e===n&&t===r)return Ut(e,t,i);const o=$t((r-t)*It(n-e,i),i),a=$t(o*o-e-n,i);return[a,$t(o*(e-a)-t,i)]}function Vt(e,t,n,r){let i=[0n,0n],o=[e,t];const a=n.toString(2);for(const e of a)"0"===e?(o=_t(i[0],i[1],o[0],o[1],r),i=Ut(i[0],i[1],r)):(i=_t(i[0],i[1],o[0],o[1],r),o=Ut(o[0],o[1],r));return i}function Ft(e,t,n){if(t<=0n||t>=Ct)throw new Error("Invalid private key");if(n||(n=$t(bt(Rt(dt(Rt(wt(t,"BE")),wt(e,"BE"))),"BE"),Ct)),n<=0n||n>=Ct)throw new Error("Invalid nonce");const r=$t(e,Ct),i=Vt(Pt,Nt,n,Dt),o=$t(i[0],Ct);let a=$t((r+$t(o,Ct)*t)*It(n,Ct),Ct);if(0n===o||0n===a)throw new Error("Invalid r or s value");let s=i[1]%2n==0n?27n:28n;return a>Ct/2n&&(a=Ct-a,s=27n===s?28n:27n),[o,a,s]}class Mt{constructor(e){this.cursor=0,this.buffer=e}read(e){const t=this.buffer.subarray(this.cursor,this.cursor+e);return this.cursor+=e,t}max(){return this.buffer.length-this.cursor}}e.Uint8ArrayReader=Mt;class jt{constructor(e){this.buffer=e,this.cursor=0}write(e){const t=Math.min(this.max(),e.max());return this.buffer.set(e.read(t),this.cursor),this.cursor+=t,t}max(){return this.buffer.length-this.cursor}}e.Uint8ArrayWriter=jt;class Lt{constructor(e,t=0n){this.span=t,this.writer=new jt(new Uint8Array(e))}build(){return dt(yt(this.span,"LE"),this.writer.buffer)}hash(){const e=ft(vt(this.writer.buffer,32),(e,t)=>Lt.hashFunction(dt(e,t)));return Lt.hashFunction(dt(yt(this.span,"LE"),e))}}e.Chunk=Lt,Lt.hashFunction=Rt;class qt{constructor(e,t=4096){this.counters=[1],this.capacity=t,this.chunks=[new Lt(t)],this.onChunk=e}static async root(e,n=4096){const r=new t(t.NOOP,n);return await r.append(e),r.finalize()}async append(e,t=0,n=0n){const r=new Mt(e);for(;r.max()>0;){0===this.chunks[t].writer.max()&&await this.elevate(t);const e=this.chunks[t].writer.write(r);n?this.chunks[t].span+=n:this.chunks[0].span+=BigInt(e)}}async elevate(e){this.counters[e]=++this.counters[e]%(this.capacity/32),this.chunks[e+1]||(this.chunks.push(new Lt(this.capacity)),this.counters.push(1)),await this.append(this.chunks[e].hash(),e+1,this.chunks[e].span),await this.onChunk(this.chunks[e]),this.chunks[e]=new Lt(this.capacity)}async finalize(e=0){return this.chunks[e+1]?1===this.counters[e]?(await this.elevate(e+1),this.chunks[e+1]=this.chunks[e],this.finalize(e+1)):(await this.elevate(e),this.finalize(e+1)):(await this.onChunk(this.chunks[e]),this.chunks[e])}}e.MerkleTree=qt,t=qt,qt.NOOP=async e=>{};class Gt{constructor(e,t){if(t<0)throw Error("Scale must be non-negative");this.value=BigInt(e),this.scale=t}static fromDecimalString(e,t){let[n,r]=e.split(".");return r=(r||"").padEnd(t,"0").slice(0,t),new Gt(BigInt(n+r),t)}add(e){return this.assertSameScale(e),new Gt(this.value+e.value,this.scale)}subtract(e){return this.assertSameScale(e),new Gt(this.value-e.value,this.scale)}multiply(e){return new Gt(this.value*e,this.scale)}divmod(e){if(0n===e)throw new Error("Division by zero is not allowed");const t=this.value/e,n=this.value%e;return[new Gt(t,this.scale),new Gt(n,this.scale)]}exchange(e,t,n){if("*"===e){const e=this.value*t.value/10n**BigInt(this.scale);return new Gt(e,n)}this.assertSameScale(t);const r=this.value*10n**BigInt(n)/t.value;return new Gt(r,n)}compare(e){return this.assertSameScale(e),this.value>e.value?1:this.value<e.value?-1:0}toDecimalString(){if(0===this.scale)return this.value.toString();const e=this.value.toString();return`${e.slice(0,-this.scale)||"0"}.${e.slice(-this.scale).padStart(this.scale,"0")}`}toString(){return this.value.toString()}toJSON(){return this.toString()}assertSameScale(e){if(this.scale!==e.scale)throw new Error(`Scale mismatch: expected ${this.scale}, but got ${e.scale}`)}}function Ht(e,t,n,r){const i=e.findIndex(e=>e===`--${t}`||e.startsWith(`--${t}=`)),o=e[i];if(!o)return(n||{})[r||t||""]||null;if(o.includes("="))return o.split("=")[1];const a=e[i+1];return a&&!a.startsWith("-")?a:(n||{})[r||t||""]||null}function Zt(e,t,n,r){const i=Ht(e,t,n,r);if(!i)throw new Error(`Missing argument ${t}`);return i}function Wt(e,t){const n=e[t];e.splice(t,1),e.unshift(n)}function Kt(e,t){return{x:e.x+t.x,y:e.y+t.y}}function Jt(e,t){return{x:e.x*t,y:e.y*t}}function Xt(e,t,n){return{x:e.x+Math.cos(t)*n,y:e.y+Math.sin(t)*n}}function Yt(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function Qt(e,t,n="row-first"){const r=[];if("column-first"===n)for(let n=0;n<e.length;n++)for(let i=0;i<e[0].length;i++)t(n,i)&&r.push({x:n,y:i});else for(let n=0;n<e[0].length;n++)for(let i=0;i<e.length;i++)t(i,n)&&r.push({x:i,y:n});return r}function en(e,t,n){return!e[t-1]?.[n]}function tn(e,t,n){return!e[t+1]?.[n]}function nn(e,t,n){return!e[t][n-1]}function rn(e,t,n){return!e[t][n+1]}function on(e,t,n){const r=[];return e[t][n]?function(e,t,n){return e[t+1]?.[n]&&e[t-1]?.[n]&&!e[t][n-1]&&!e[t][n+1]}(e,t,n)||function(e,t,n){return e[t][n+1]&&e[t][n-1]&&!e[t-1]?.[n]&&!e[t+1]?.[n]}(e,t,n)?[]:(!e[t-1]?.[n-1]&&en(e,t,n)&&nn(e,t,n)&&r.push({x:t,y:n}),!e[t+1]?.[n-1]&&tn(e,t,n)&&nn(e,t,n)&&r.push({x:t+1,y:n}),!e[t-1]?.[n+1]&&en(e,t,n)&&rn(e,t,n)&&r.push({x:t,y:n+1}),!e[t+1]?.[n+1]&&tn(e,t,n)&&rn(e,t,n)&&r.push({x:t+1,y:n+1}),r):(e[t-1]?.[n]&&e[t][n-1]&&r.push({x:t,y:n}),e[t+1]?.[n]&&e[t][n-1]&&r.push({x:t+1,y:n}),e[t-1]?.[n]&&e[t][n+1]&&r.push({x:t,y:n+1}),e[t+1]?.[n]&&e[t][n+1]&&r.push({x:t+1,y:n+1}),r)}function an(e,t){return t.map(t=>function(e,t){return Math.atan2(t.y-e.y,t.x-e.x)}(e,t)).sort((e,t)=>e-t)}function sn(e,t,n,r){const i=(r.y-n.y)*(t.x-e.x)-(r.x-n.x)*(t.y-e.y);if(0===i)return null;let o=e.y-n.y,a=e.x-n.x;const s=(r.x-n.x)*o-(r.y-n.y)*a,c=(t.x-e.x)*o-(t.y-e.y)*a;return o=s/i,a=c/i,o>0&&o<1&&a>0&&a<1?{x:e.x+o*(t.x-e.x),y:e.y+o*(t.y-e.y)}:null}function cn(e,t,n){const r=[],i=Xt(e,n,1e4);for(const n of t){const t=sn(e,i,n.start,n.end);t&&r.push(t)}return r.length?r.reduce((t,n)=>Yt(e,n)<Yt(e,t)?n:t):null}e.FixedPointNumber=Gt;class un{constructor(){this.subscribers=[]}subscribe(e){return this.subscribers.push(e),()=>{this.subscribers=this.subscribers.filter(t=>t!==e)}}publish(e){this.subscribers.forEach(t=>t(e))}clear(){this.subscribers=[]}getSubscriberCount(){return this.subscribers.length}}e.PubSubChannel=un,e.AsyncQueue=class{constructor(e,t){this.queue=[],this.running=0,this.onProcessed=new un,this.onDrained=new un,this.concurrency=e,this.capacity=t}process(){if(this.running>=this.concurrency)return;const e=this.queue.shift();e&&(this.running++,e().finally(()=>{this.running--,this.process(),this.onProcessed.publish(),0===this.running&&this.onDrained.publish()}))}enqueue(e){if(this.queue.length<this.capacity)return this.queue.push(e),this.process(),Promise.resolve();if(this.onProcessed.getSubscriberCount())throw Error("Queue capacity is full");return new Promise(t=>{this.onProcessed.subscribe(()=>{this.queue.length<this.capacity&&(this.queue.push(e),this.process(),this.onProcessed.clear(),t())})})}drain(){if(0===this.running)return Promise.resolve();if(this.onDrained.getSubscriberCount())throw Error("Already draining");return new Promise(e=>{this.onDrained.subscribe(()=>{this.onDrained.clear(),e()})})}};class ln{constructor(){this.forks=new Map}insert(e,t){if(0===e.length)return void(this.handler=t);const n=e[0];let r,i=n;if(n.startsWith(":")&&(i=":",r=n.slice(1)),!this.forks.has(i)){const e=new ln;r&&(e.variableName=r),this.forks.set(i,e)}this.forks.get(i).insert(e.slice(1),t)}async handle(e,t,n,r){if(0===e.length)return!!this.handler&&(await this.handler(t,n,r),!0);const i=e[0],o=this.forks.get(i);if(o)return o.handle(e.slice(1),t,n,r);const a=this.forks.get(":");if(a)return a.variableName&&r.set(a.variableName,decodeURIComponent(i)),a.handle(e.slice(1),t,n,r);const s=this.forks.get("*");return!!s&&(r.set("wildcard",e.join("/")),!!s.handler&&(await s.handler(t,n,r),!0))}}e.TrieRouter=ln,e.RollingValueProvider=class{constructor(e){this.index=0,this.values=e}current(){return this.values[this.index]}next(){return this.index=(this.index+1)%this.values.length,this.values[this.index]}},e.Binary={hexToUint8Array:function(e){(e.startsWith("0x")||e.startsWith("0X"))&&(e=e.slice(2));const t=e.length/2,n=new Uint8Array(t);for(let r=0;r<t;r++){const t=parseInt(e.slice(2*r,2*r+2),16);n[r]=t}return n},uint8ArrayToHex:function(e){return Array.from(e).map(e=>e.toString(16).padStart(2,"0")).join("")},binaryToUint8Array:function(e){const t=Math.ceil(e.length/8),n=new Uint8Array(t);for(let r=0;r<t;r++){const t=parseInt(e.slice(8*r,8*r+8),2);n[r]=t}return n},uint8ArrayToBinary:function(e){return Array.from(e).map(e=>e.toString(2).padStart(8,"0")).join("")},base64ToUint8Array:function(e){return Ee(e,be)},uint8ArrayToBase64:function(e){return xe(e,be)},base32ToUint8Array:function(e){return Ee(e,ve)},uint8ArrayToBase32:function(e){return xe(e,ve)},log2Reduce:ft,partition:vt,concatBytes:dt,numberToUint8:function(e){return new Uint8Array([e])},uint8ToNumber:function(e){return e[0]},numberToUint16:function(e,t){const n=new ArrayBuffer(2);return new DataView(n).setUint16(0,e,"LE"===t),new Uint8Array(n)},uint16ToNumber:function(e,t){return new DataView(e.buffer).getUint16(e.byteOffset,"LE"===t)},numberToUint32:function(e,t){const n=new ArrayBuffer(4);return new DataView(n).setUint32(0,e,"LE"===t),new Uint8Array(n)},uint32ToNumber:function(e,t){return new DataView(e.buffer).getUint32(e.byteOffset,"LE"===t)},numberToUint64:yt,uint64ToNumber:function(e,t){return new DataView(e.buffer).getBigUint64(e.byteOffset,"LE"===t)},numberToUint256:wt,uint256ToNumber:bt,sliceBytes:function(e,t){const n=[];let r=0;for(const i of t)n.push(e.subarray(r,r+i)),r+=i;return n},keccak256:Rt,sha3_256:function(e){return Ot(At(new Array(50).fill(0),Tt(e,6)))},proximity:function(e,t){const n=Math.min(e.length,t.length);for(let r=0;r<n;r++){const n=e[r]^t[r];for(let e=0;e<8;e++)if(n>>7-e&1)return 8*r+e}return 8*Math.min(e.length,t.length)},commonPrefix:function(e,t){const n=Math.min(e.length,t.length);for(let r=0;r<n;r++)if(e[r]!==t[r])return e.subarray(0,r);return e.subarray(0,n)},setBit:function(e,t,n,r){const i=Math.floor(t/8),o=t%8;1===n?e[i]|=1<<("BE"===r?7-o:o):e[i]&=~(1<<("BE"===r?7-o:o))},getBit:function(e,t,n){const r=t%8;return e[Math.floor(t/8)]>>("BE"===n?7-r:r)&1},indexOf:function(e,t,n=0){for(let r=n;r<e.length;r++)for(let n=0;n<t.length&&e[r+n]===t[n];n++)if(n===t.length-1)return r;return-1},equals:function(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0},padStart:St,padStartToMultiple:function(e,t,n=0){const r=e.length%t;return 0===r?e:St(e,e.length+t-r,n)},padEnd:kt,padEndToMultiple:function(e,t,n=0){const r=e.length%t;return 0===r?e:kt(e,e.length+t-r,n)},xorCypher:function(e,t){const n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e[r]^t[r%t.length];return n},isUtf8:function(e){for(let t=0;t<e.length;t++){const n=e[t];if(!(n<128))if(192==(224&n)){if(t+1>=e.length||128!=(192&e[t+1]))return!1;t+=1}else if(224==(240&n)){if(t+2>=e.length||128!=(192&e[t+1])||128!=(192&e[t+2]))return!1;t+=2}else{if(240!=(248&n))return!1;if(t+3>=e.length||128!=(192&e[t+1])||128!=(192&e[t+2])||128!=(192&e[t+3]))return!1;t+=3}}return!0}},e.Elliptic={privateKeyToPublicKey:function(e){if(e<=0n||e>=Ct)throw new Error("Invalid private key");return Vt(Pt,Nt,e,Dt)},compressPublicKey:function(e){const t=e[1]%2n==0n?2:3;return new Uint8Array([t,...wt(e[0],"BE")])},publicKeyFromCompressed:function(e){if(33!==e.length||2!==e[0]&&3!==e[0])throw new Error("Invalid compressed public key");const t=bt(e.slice(1),"BE"),n=zt($t(t**3n+7n,Dt),Dt);if(!n)throw Error("Invalid x: does not correspond to a valid curve point");const r=$t(-n,Dt),i=n%2n==0n;return[t,2===e[0]?i?n:r:i?r:n]},publicKeyToAddress:function(e){const t=new Uint8Array(20),n=Rt(dt(wt(e[0],"BE"),wt(e[1],"BE")));return t.set(n.subarray(12)),t},signMessage:function(e,t,n){return Ft(bt(Rt(e),"BE"),t,n)},signHash:Ft,verifySignature:function(e,t,n,r){const i=$t(bt(Rt(e),"BE"),Ct),o=It(r,Ct),a=$t(i*o,Ct),s=$t(n*o,Ct),c=Vt(Pt,Nt,a,Dt),u=Vt(t[0],t[1],s,Dt);return n===$t(_t(c[0],c[1],u[0],u[1],Dt)[0],Ct)},recoverPublicKey:function(e,t,n,r){const i=zt($t(t**3n+7n,Dt),Dt);if(!i)throw new Error("Invalid r: does not correspond to a valid curve point");const o=i%2n==(27n===r?0n:1n)?i:Dt-i,a=$t(bt(Rt(e),"BE"),Ct),s=Vt(t,o,n,Dt),c=Vt(Pt,Nt,a,Dt),u=_t(s[0],s[1],c[0],$t(-c[1],Dt),Dt);return Vt(u[0],u[1],It(t,Ct),Dt)},checksumEncode:function(t){const n=e.Binary.uint8ArrayToHex(t),r=e.Binary.uint8ArrayToHex(e.Binary.keccak256(new Uint8Array([...n].map(e=>e.charCodeAt(0)))));let i="0x";for(let e=0;e<n.length;e++)parseInt(r[e],16)>7?i+=n[e].toUpperCase():i+=n[e];return i}},e.Random={intBetween:a,floatBetween:function(e,t,n=Math.random){return n()*(t-e)+e},chance:c,signed:function(){return 2*Math.random()-1},makeSeededRng:function(e){let t=e,n=3405648695,r=3735928559;return function(){return t+=n,n^=t<<7,t*=r,r^=t<<13,t^=n^r,(t>>>0)/4294967296}},point:function(e,t,n,r=Math.random){let i,o;do{i=a(0,e-1,r),o=a(0,t-1,r)}while(n&&s(n,i,o));return[i,o]},procs:function(e,t=Math.random){const n=Math.floor(e);return c(e-n,t)?n+1:n}},e.Arrays={countUnique:function(e,t,n,r,i){const o=t?e.map(t):e,a={};for(const e of o)a[e]=(a[e]||0)+1;const s=r?st(a,i?(e,t)=>e[1]-t[1]:(e,t)=>t[1]-e[1]):a;return n?Object.keys(s):s},makeUnique:function(e,t){return Object.values(it(e,t))},splitBySize:function(e,t){const n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n},splitByCount:ot,index:it,indexCollection:function(e,t){const n={};for(const r of e){const e=t(r);n[e]||(n[e]=[]),n[e].push(r)}return n},onlyOrThrow:function(e){if(1===e.length)return e[0];throw Error(`Expected exactly one element, actual: ${e.length}`)},onlyOrNull:function(e){return 1===e.length?e[0]:null},firstOrThrow:function(e){if(!e.length)throw Error("Received empty array");return e[0]},firstOrNull:function(e){return e.length>0?e[0]:null},shuffle:i,initialize:function(e,t){const n=[];for(let r=0;r<e;r++)n.push(t(r));return n},initialize2D:function(e,t,n){const r=[];for(let i=0;i<e;i++){r.push([]);for(let e=0;e<t;e++)r[i].push(n)}return r},rotate2D:function(e){const t=[];for(let n=0;n<e[0].length;n++){t.push([]);for(let r=0;r<e.length;r++)t[n].push(e[r][n])}return t},containsShape:function(e,t,n,r){if(n<0||r<0||r+t[0].length>e[0].length||n+t.length>e.length)return!1;for(let i=0;i<t.length;i++)for(let o=0;o<t[i].length;o++)if(void 0!==t[i][o]&&e[n+i][r+o]!==t[i][o])return!1;return!0},glue:function(e,t){const n=[];for(let r=0;r<e.length;r++)n.push(e[r]),r<e.length-1&&(b(t)?n.push(t()):n.push(t));return n},pluck:function(e,t){return e.map(e=>e[t])},pick:u,pickMany:function(e,t,n=Math.random){if(t>e.length)throw new Error(`Count (${t}) is greater than array length (${e.length})`);return o(e,t,n).map(t=>e[t])},pickManyUnique:function(e,t,n,r=Math.random){if(t>e.length)throw new Error(`Count (${t}) is greater than array length (${e.length})`);const i=[];for(;i.length<t;){const t=u(e,r);i.some(e=>n(e,t))||i.push(t)}return i},pickWeighted:function(e,t,n){if(void 0===n&&(n=Math.random()),e.length!==t.length)throw new Error("Array length mismatch");let r=t.reduce((e,t)=>e+t,0);const i=n*r;for(let n=0;n<e.length-1;n++)if(r-=t[n],i>=r)return e[n];return l(e)},pickRandomIndices:o,pickGuaranteed:function(t,n,r,o,a,s=Math.random){const c=t.filter(e=>e!==n&&e!==r),u=[];for(null!==n&&u.push(n);c.length&&u.length<o;){const t=e.Random.intBetween(0,c.length-1,s);a(c[t],u)&&u.push(c[t]),c.splice(t,1)}return i(u,s),{values:u,indexOfGuaranteed:null!==n?u.indexOf(n):-1}},last:l,pipe:h,makePipe:function(e,t){return n=>h(n,e,t)},sortWeighted:function(e,t,n=Math.random){const r=t.map(e=>n()*e),i=[];for(let t=0;t<e.length;t++)i.push([e[t],r[t]]);return i.sort((e,t)=>t[1]-e[1]).map(e=>e[0])},pushAll:L,unshiftAll:function(e,t){Array.prototype.unshift.apply(e,t)},filterAndRemove:function(e,t){const n=[];for(let r=e.length-1;r>=0;r--)t(e[r])&&n.push(e.splice(r,1)[0]);return n},merge:function(e,t){const n=Object.keys(t);for(const r of n)Array.isArray(t[r])&&Array.isArray(e[r])&&L(e[r],t[r])},empty:function(e){return e.splice(0,e.length),e},pushToBucket:function(e,t,n){e[t]||(e[t]=[]),e[t].push(n)},unshiftAndLimit:function(e,t,n){for(e.unshift(t);e.length>n;)e.pop()},atRolling:function(e,t){let n=t%e.length;return n<0&&(n+=e.length),e[n]},group:ct,createOscillator:function(e){let t=0;return{next:()=>e[t++%e.length]}},organiseWithLimits:function(e,t,n,r,i){const o={};for(const e of Object.keys(t))o[e]=[];o[r]=[],i&&(e=e.sort(i));for(const i of e){const e=i[n],a=t[e]?e:r;o[a].length>=t[a]?o[r].push(i):o[a].push(i)}return o},tickPlaybook:function(e){if(0===e.length)return null;const t=e[0];return t.ttlMax?--t.ttl<=0&&e.shift():t.ttlMax=t.ttl,{progress:(t.ttlMax-t.ttl)/t.ttlMax,data:t.data}},getArgument:Ht,getBooleanArgument:function(e,t,n,r){const i=e.some(e=>e.endsWith("-"+t)),o=Ht(e,t,n,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 ${t}: ${o}`)},getNumberArgument:function(e,t,n,r){const i=Ht(e,t,n,r);if(!i)return null;try{return et(i)}catch{throw new Error(`Invalid number argument ${t}: ${i}`)}},requireStringArgument:Zt,requireNumberArgument:function(e,t,n,r){const i=Zt(e,t,n,r);try{return et(i)}catch{throw new Error(`Invalid argument ${t}: ${i}`)}},bringToFront:function(e,t){const n=[...e];return Wt(n,t),n},bringToFrontInPlace:Wt,findInstance:function(e,t){const n=e.find(e=>e instanceof t);return lt.of(n)},filterInstances:function(e,t){return e.filter(e=>e instanceof t)},interleave:function(e,t){const n=[],r=Math.max(e.length,t.length);for(let i=0;i<r;i++)e[i]&&n.push(e[i]),t[i]&&n.push(t[i]);return n},toggle:function(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]},createHierarchy:function(e,t,n,r,i=!1){const o=new Map,a=[];e.forEach(e=>{const n=new ht(e);o.set(e[t],n)}),e.forEach(e=>{const r=o.get(e[t]);if(!r)return;const i=e[n];if(i){const e=o.get(i);e&&e.children.push(r)}else a.push(r)});const s=e=>{e.children.sort((e,t)=>{const n=e.value[r],o=t.value[r];return i?o-n:n-o}),e.children.forEach(s)};return a.forEach(s),a},multicall:function(e){return()=>e.forEach(e=>e())},maxBy:function(e,t){return e.reduce((e,n)=>t(e)>t(n)?e:n)}},e.System={sleepMillis:r,forever:async function(e,t,n){for(;;){try{await e()}catch(e){n&&n("Error in forever",e)}await r(t)}},scheduleMany:function(e,t){for(let n=0;n<e.length;n++){const r=e[n],i=t[n],o=Math.max(0,i.getTime()-Date.now());setTimeout(r,o)}},waitFor:async function(e,t){let n=t.requiredConsecutivePasses||1,i=0;for(let o=0;o<t.attempts;o++){try{if(await e()){if(i++,i>=n)return}else i=0}catch{i=0}o<t.attempts-1&&await r(t.waitMillis)}throw Error("Timed out waiting for predicate")},expandError:function(e,t){if(v(e))return e;const n=Object.keys(e);e.message&&!n.includes("message")&&n.push("message");const r=n.map(t=>`${t}: ${e[t]}`).join("; ");return t&&e.stack?r+"\n"+e.stack:r},runAndSetInterval:function(e,t){e();const n=setInterval(()=>{e()},t);return()=>clearInterval(n)},whereAmI:function(){const e=globalThis.process;return e?!0===e.browser?"browser":"node":"browser"},withRetries:async function(e,t,n,i,o,a){let s=null;for(let c=0;c<=t;c++)try{return await e()}catch(e){if(s=e,c===t)break;const u=n+c/(t-1)*(i-n);o&&o("Error in withRetries, retrying",{attempt:c+1,allowedFailures:t,delayMillis:u,error:e}),a&&a(),await r(u)}throw s}},e.Numbers={make:et,sum:function(e){return e.reduce((e,t)=>e+t,0)},average:function(e){return e.reduce((e,t)=>e+t,0)/e.length},median:function(e){const t=[...e].sort((e,t)=>e-t),n=Math.floor(t.length/2);return t.length%2==0?(t[n]+t[n-1])/2:t[n]},getDistanceFromMidpoint:function(e,t){return e-(t-1)/2},clamp:tt,range:q,interpolate:function(e,t,n){return e+(t-e)*n},createSequence:function(){let e=0;return{next:()=>e++}},increment:function(e,t,n){const r=e+t;return r>n?n:r},decrement:function(e,t,n){const r=e-t;return r<n?n:r},format:function(e,t){const n=t?.longForm??!1,r=t?.unit?` ${t.unit}`:"",i=n?Ye:Qe,o=t?.precision??1;if(e<Xe[0])return`${e}${r}`;for(let t=0;t<Xe.length-1;t++)if(e<Xe[t+1])return`${(e/Xe[t]).toFixed(o)}${n?" ":""}${i[t]}${r}`;return`${(e/Xe[Xe.length-1]).toFixed(o)}${n?" ":""}${i[Xe.length-1]}${r}`},fromDecimals:function(e,t,n){let r=e.length-t;if(r<=0)return"0."+"0".repeat(-r)+e+(n?" "+n:"");let i=e.substring(0,r);return""===i&&(i="0"),i+"."+e.substring(r)+(n?" "+n:"")},makeStorage:function(e,t=1024){const n=parseFloat(e);if(isNaN(n))throw Error("makeStorage got NaN for input");const r=e.replace(/^-?[0-9.]+/,"").trim().toLowerCase(),i=""===r?0:Le[r];if(null==i)throw Error(`Unknown unit: "${r}"`);return Math.ceil(n*t**i)},asMegabytes:function(e){return e/1024/1024},convertBytes:function(e,t=1024){return e>=t*t*t*t?(e/t/t/t/t).toFixed(3)+" TB":e>=t*t*t?(e/t/t/t).toFixed(3)+" GB":e>=t*t?(e/t/t).toFixed(3)+" MB":e>=t?(e/t).toFixed(3)+" KB":e+" B"},hexToRgb:function(e){const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e.toLowerCase());if(!t)throw new Error("Invalid hex color: "+e);return[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]},rgbToHex:function(e){return"#"+e.map(e=>e.toString(16).padStart(2,"0")).join("")},haversineDistanceToMeters:function(e,t,n,r){const i=e*Math.PI/180,o=n*Math.PI/180,a=(n-e)*Math.PI/180,s=(r-t)*Math.PI/180,c=Math.sin(a/2)*Math.sin(a/2)+Math.cos(i)*Math.cos(o)*Math.sin(s/2)*Math.sin(s/2);return 2*Math.atan2(Math.sqrt(c),Math.sqrt(1-c))*6371e3},roundToNearest:p,formatDistance:function(e){return e>1e3?(e/1e3).toFixed(0)+" km":e>=500?p(e,100)+" m":e>=100?p(e,50)+" m":p(e,10)+" m"},triangularNumber:function(e){return e*(e+1)/2},searchFloat:function(e){const t=e.match(/-?\d+(\.\d+)?/);if(!t)throw Error("No float found in "+e);return parseFloat(t[0])},binomialSample:function(e,t,n=Math.random){const r=e*t,i=Math.sqrt(e*t*(1-t)),o=(n()+n()+n()+n()+n()+n()-3)*Math.SQRT2,a=Math.round(r+i*o);return Math.max(0,Math.min(e,a))},toSignificantDigits:function(e,t){if(!e.includes("."))return e;if(0===parseFloat(e))return"0";const[n,r]=e.split("."),i=n.replace("-",""),o=i.length;if(o>=t)return n;if("0"!==i){const e=t-o,i=r.slice(0,e);return/[1-9]/.test(i)?`${n}.${i.replace(/0+$/,"")}`:n}const a=t+(r.match(/^0*/)?.[0].length??0);return`${n}.${r.slice(0,a)}`}},e.Promises={raceFulfilled:async function(e){return n(Promise.all(e.map(n)))},invert:n,runInParallelBatches:async function(e,t=1){const n=ot(e,t),r=[],i=n.map(async e=>{for(const t of e)r.push(await t())});return await Promise.all(i),r}},e.Dates={getTimestamp:function(e,t){const n=new Date(t?.now||Date.now()),r=t?.labels||Ce,i=B(e)?e:new Date(e);if(De(n)===De(i))return r.today(i.getUTCHours(),i.getUTCMinutes(),i.getUTCHours()>12);if(De(n)-De(i)===1)return r.yesterday();const o=Me(i);return De(n)-De(i)<7?r[o.day]():r.weeks(Math.round((n.getTime()-i.getTime())/6048e5))},getTimeDelta:Ne,secondsToHumanTime:function(e,t=Pe){return Ne(0,{now:1e3*e,labels:t})},countCycles:function(e,t,n){const r=(n?.now??Date.now())-e;return{cycles:Math.floor(r/t),remaining:t/(n?.precision??1)-Math.ceil(r%t/(n?.precision??1))}},isoDate:function(e){return(e||new Date).toISOString().slice(0,10)},throttle:function(e,t){return(!Ue[e]||Date.now()>Ue[e])&&(Ue[e]=Date.now()+t,!0)},timeSince:function(e,t,n){return t=B(t)?t.getTime():t,((n=n?B(n)?n.getTime():n:Date.now())-t)/_e[e]},dateTimeSlug:function(e){return(e||new Date).toISOString().slice(0,19).replace(/T|:/g,"-")},unixTimestamp:function(e){return Math.ceil((e||Date.now())/1e3)},fromUtcString:function(e){const t=new Date(e);return new Date(t.getTime()-6e4*t.getTimezoneOffset())},fromMillis:function(e){return new Date(e)},getProgress:function(e,t,n,r){r||(r=Date.now());const i=r-e,o=i/t,a=o*n;return{deltaMs:i,progress:t/n,baseTimeMs:o,totalTimeMs:a,remainingTimeMs:a-i}},humanizeTime:ze,humanizeProgress:function(e){return`[${Math.floor(100*e.progress)}%] ${ze(e.deltaMs)} out of ${ze(e.totalTimeMs)} (${ze(e.remainingTimeMs)} left) [${Math.round(e.baseTimeMs)} ms each]`},createTimeDigits:Ie,mapDayNumber:Fe,getDayInfoFromDate:Me,getDayInfoFromDateTimeString:function(e){return Me(new Date(e))},seconds:function(e){return 1e3*e},minutes:function(e){return 6e4*e},hours:function(e){return 36e5*e},days:function(e){return 864e5*e},make:function(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeDate got NaN for input");const n=e.replace(/^-?[0-9.]+/,"").trim().toLowerCase(),r=""===n?1:je[n];if(!r)throw Error(`Unknown unit: "${n}"`);return Math.ceil(t*r)},normalizeTime:function(e){let[t,n]=e.split(":");E(parseInt(t,10))||(t="0"),E(parseInt(n,10))||(n="0");let r=tt(U(t),0,23),i=tt(U(n),0,59);return`${Ie(r)}:${Ie(i)}`},absoluteDays:De},e.Objects={safeParse:function(e){try{return JSON.parse(e)}catch{return null}},deleteDeep:function(e,t){const n=J(t,"."),r=X(t,".");if(!n||!r)return;const i=f(e,n);i&&delete i[r]},getDeep:f,setDeep:d,incrementDeep:function(e,t,n=1){const r=f(e,t)||0;return d(e,t,r+n),r},ensureDeep:function(e,t,n){return f(e,t)||d(e,t,n)},replaceDeep:function(e,t,n){const r=f(e,t);if(!r)throw new Error("Key '"+t+"' does not exist.");return d(e,t,n),r},getFirstDeep:function(e,t,n){for(const n of t){const t=f(e,n);if(t)return t}if(n){const t=Object.values(e);if(t.length)return t[0]}return null},deepMergeInPlace:M,deepMerge2:function(e,t){const n={};return M(n,e),M(n,t),n},deepMerge3:function(e,t,n){const r={};return M(r,e),M(r,t),M(r,n),r},mapAllAsync:async function(e,t){const n=[];for(const r of e)n.push(await t(r));return n},cloneWithJson:function(e){return JSON.parse(JSON.stringify(e))},sortObject:He,sortArray:Ze,sortAny:We,deepEquals:Ke,deepEqualsEvery:function(...e){for(let t=1;t<e.length;t++)if(!Ke(e[t-1],e[t]))return!1;return!0},runOn:function(e,t){return t(e),e},ifPresent:function(e,t){e&&t(e)},zip:j,zipSum:function(e){return j(e,(e,t)=>e+t)},removeEmptyArrays:function(e){for(const t of Object.keys(e))(y(e[t])||Array.isArray(e[t])&&e[t].every(e=>null==e))&&delete e[t];return e},removeEmptyValues:function(e){for(const t of Object.entries(e))(null===t[1]||void 0===t[1]||v(t[1])&&T(t[1]))&&delete e[t[0]];return e},flatten:function(e,t=!1,n){return rt({},e,n||"",!1,t)},unflatten:function e(t){if(!m(t))return t;const n=Array.isArray(t)?[]:{};for(const[r,i]of Object.entries(t))Array.isArray(i)?d(n,r,i.map(t=>e(t))):d(n,r,i);return n},match:function(e,t,n){return t[e]?t[e]:n},sort:st,map:function(e,t){const n={};for(const r of Object.entries(e))n[r[0]]=t(r[1]);return n},mapIterable:function(e,t){const n=[];let r=0;for(const i of e)n.push(t(i,r++));return n},filterKeys:function(e,t){const n={};for(const[r,i]of Object.entries(e))t(r)&&(n[r]=i);return n},filterValues:function(e,t){const n={};for(const[r,i]of Object.entries(e))t(i)&&(n[r]=i);return n},rethrow:async function(e,t){try{return await e()}catch{throw t}},setSomeOnObject:function(e,t,n){null!=n&&(e[t]=n)},setSomeDeep:function(e,t,n,r){const i=f(n,r);null!=i&&d(e,t,i)},flip:function(e){const t={};for(const[n,r]of Object.entries(e))t[r]=n;return t},getAllPermutations:function(e){const t=Object.keys(e),n=t.map(t=>e[t].length),r=n.reduce((e,t)=>e*t);let i=1;const o=[1];for(let e=0;e<n.length-1;e++)i*=n[e],o.push(i);const a=[];for(let n=0;n<r;n++){const r={};for(let i=0;i<t.length;i++){const a=e[t[i]],s=Math.floor(n/o[i])%a.length;r[t[i]]=a[s]}a.push(r)}return a},countTruthyValues:function(e){return Object.values(e).filter(e=>e).length},transformToArray:function(e){const t=[],n=Object.keys(e),r=e[n[0]].length;for(let i=0;i<r;i++){const r={};for(const t of n)r[t]=e[t][i];t.push(r)}return t},setMulti:function(e,t,n){for(const r of e)r[t]=n},incrementMulti:function(e,t,n=1){for(const r of e)r[t]+=n},createBidirectionalMap:function(){return{map:new Map,keys:[]}},createTemporalBidirectionalMap:function(){return{map:new Map,keys:[]}},pushToBidirectionalMap:ut,unshiftToBidirectionalMap:function(e,t,n,r=100){if(e.map.has(t)){const n=e.keys.indexOf(t);e.keys.splice(n,1)}if(e.map.set(t,n),e.keys.unshift(t),e.keys.length>r){const t=e.keys.shift();t&&e.map.delete(t)}},addToTemporalBidirectionalMap:function(e,t,n,r,i=100){ut(e,t,{validUntil:Date.now()+r,data:n},i)},getFromTemporalBidirectionalMap:function(e,t){const n=e.map.get(t);return n&&n.validUntil>Date.now()?n.data:null},createStatefulToggle:function(e){let t;return n=>{const r=n===e&&t!==e;return t=n,r}},diffKeys:function(e,t){const n=Object.keys(e),r=Object.keys(t);return{uniqueToA:n.filter(e=>!r.includes(e)),uniqueToB:r.filter(e=>!n.includes(e))}},pickRandomKey:Je,mapRandomKey:function(e,t){const n=Je(e);return e[n]=t(e[n]),n},fromObjectString:function(e){return e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=e.replace(/\r\n/g,"\n")).replace(/(\w+)\((.+)\)/g,(e,t,n)=>`${t}(${n.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,(e,t,n)=>`: (${t.trim()} && ${n.trim()}) ||`)).replace(/([a-zA-Z0-9]+)( ?: ?{)/g,'"$1"$2')).replace(/([a-zA-Z0-9]+) ?: ?(.+?)(,|\n|})/g,(e,t,n,r)=>`"${t}":"${n.trim()}"${r}`)).replace(/("'|'")/g,'"')).replaceAll(",",","),JSON.parse(e)},toQueryString:$e,parseQueryString:function(e){const t={},n=e.split("&");for(const e of n){const[n,r]=e.split("=");n&&r&&(t[n]=decodeURIComponent(r))}return t},hasKey:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},selectMax:function(e,t){let n=null,r=-1/0;for(const[i,o]of Object.entries(e)){const e=t(o);e>r&&(r=e,n=i)}return n?[n,e[n]]:null},reposition:function(e,t,n,r){const i=e.find(e=>e[t]===n),o=e.find(e=>e[t]===n+r);i&&o?(i[t]=n+r,o[t]=n):i&&(i[t]=n+r),e.sort((e,n)=>N(e[t])-N(n[t])),e.forEach((e,n)=>e[t]=n+1)},unwrapSingleKey:function(e){const t=Object.keys(e);if(1===t.length)return e[t[0]];throw new Error("Expected object to have a single key")},parseKeyValues:function(e,t=":"){return Object.fromEntries(e.map(e=>Y(e,t)).map(e=>e[0]&&e[1]?[ne(e[0]),ne(e[1])]:null).filter(e=>e))},errorMatches:function(e,t){if(!e)return!1;const n=e.message;return"string"==typeof n&&n.includes(t)}},e.Types={isFunction:b,isObject:m,isStrictlyObject:g,isEmptyArray:y,isEmptyObject:function(e){return g(e)&&0===Object.keys(e).length},isUndefined:w,isString:v,isNumber:E,isBoolean:x,isDate:B,isBlank:T,isId:A,isIntegerString:O,isHexString:R,isUrl:V,isNullable:function(e,t){return null==t||e(t)},asString:C,asHexString:function(e,t){if(!R(e))throw new TypeError(`Expected hex string${t?.name?` for ${t.name}`:""}, got: `+e);if(t?.strictPrefix&&!e.startsWith("0x"))throw new TypeError(`Expected hex string with 0x prefix${t?.name?` for ${t.name}`:""}, got: `+e);const n=e.replace(/^0x/,"");if(n.length%2!=0&&!t?.uneven)throw RangeError(`Expected even number of hex digits${t?.name?` for ${t.name}`:""}; got: `+e);if(t&&t.byteLength&&n.length!==2*t.byteLength)throw RangeError(`Expected hex string${t?.name?` for ${t.name}`:""} of byte length ${t.byteLength}; got: `+n);return`0x${n}`},asSafeString:function(e,t){if(!C(e,t).split("").every(e=>"_"===e||se(e)))throw new TypeError(`Expected safe string${t?.name?` for ${t.name}`:""}, got: `+e);return e},asIntegerString:function(e,t){if(!O(e))throw new TypeError(`Expected integer string${t?.name?` for ${t.name}`:""}, got: `+e);const n=BigInt(e);if(t&&(t.min&&n<t.min||t.max&&n>t.max))throw RangeError(`Expected integer string${t?.name?` for ${t.name}`:""} in range: ${t.min??"-inf"}..${t.max??"inf"}; got: `+n);return e},asNumber:N,asFunction:function(e,t){if(!b(e))throw new TypeError(`Expected function${t?.name?` for ${t.name}`:""}, got: `+e);return e},asInteger:U,asBoolean:function(e,t){if("true"===e)return!0;if("false"===e)return!1;if(!x(e))throw new TypeError(`Expected boolean${t?.name?` for ${t.name}`:""}, got: `+e);return e},asDate:function(e,t){if(!B(e))throw new TypeError(`Expected date${t?.name?` for ${t.name}`:""}, got: `+e);return e},asNullableString:function(e){return T(e)?null:e},asEmptiableString:function(e,t){if(!v(e))throw new TypeError(`Expected string${t?.name?` for ${t.name}`:""}, got: `+e);return e},asId:function(e,t){if(A(e))return e;const n=parseInt(e,10);if(!A(n))throw new TypeError(`Expected id${t?.name?` for ${t.name}`:""}, got: `+e);return n},asTime:function(e,t){if(!v(e))throw new TypeError(`Expected time${t?.name?` for ${t.name}`:""}, got: `+e);const n=e.split(":");if(2!==n.length)throw new TypeError(`Expected time${t?.name?` for ${t.name}`:""}, got: `+e);const r=parseInt(n[0],10),i=parseInt(n[1],10);if(!E(r)||!E(i)||r<0||r>23||i<0||i>59)throw new TypeError(`Expected time, got${t?.name?` for ${t.name}`:""}: `+e);return`${String(r).padStart(2,"0")}:${String(i).padStart(2,"0")}`},asArray:function(e,t){if(!Array.isArray(e))throw new TypeError(`Expected array${t?.name?` for ${t.name}`:""}, got: `+e);return e},asObject:_,asNullableObject:function(e,t){return null===e?null:_(e,t)},asStringMap:function(e,t){const n=_(e,t);for(const r of Object.keys(n))if(!v(n[r]))throw new TypeError(`Expected string map${t?.name?` for ${t.name}`:""}, got: `+e);return n},asNumericDictionary:function(e,t){const n=_(e),r=Object.keys(n),i=Object.values(n);if(!r.every(v)||!i.every(E))throw new TypeError(`Expected numeric dictionary${t?.name?` for ${t.name}`:""}, got: `+e);return n},asUrl:function(e,t){if(!V(e))throw new TypeError(`Expected url${t?.name?` for ${t.name}`:""}, got: `+e);return e},asEmptiable:function(e,t){return""===t?void 0:e(t)},asNullable:function(e,t){return null==t?null:e(t)},asOptional:function(e,t){return null==t?void 0:e(t)},enforceObjectShape:F,enforceArrayShape:function(e,t){return e.every(e=>F(e,t))},isPng:pt,isJpg:mt,isWebp:gt,isImage:function(e){return pt(e)||mt(e)||gt(e)}},e.Strings={tokenizeByCount:function(e,t){return at(e,Math.ceil(e.length/t))},tokenizeByLength:at,searchHex:function(e,t){const n=new RegExp(`[0-9a-f]{${t}}`,"i"),r=e.match(n);return r?r[0]:null},searchSubstring:function(e,t,n=S){const r=Q(e,n);for(const e of r)if(t(e))return e;return null},randomHex:function(e,t=Math.random){let n="";for(let r=0;r<e;r++)n+=D[Math.floor(16*t())];return n},randomLetter:function(e,t=Math.random){let n="";for(let r=0;r<e;r++)n+=k[Math.floor(26*t())];return n},randomAlphanumeric:function(e,t=Math.random){let n="";for(let r=0;r<e;r++)n+=$[Math.floor(62*t())];return n},randomRichAscii:function(e,t=Math.random){let n="";for(let r=0;r<e;r++)n+=I[Math.floor(89*t())];return n},randomUnicode:function(e,t=Math.random){let n="";for(let r=0;r<e;r++)n+=z[Math.floor(t()*z.length)];return n},includesAny:function(e,t){return t.some(t=>e.includes(t))},slugify:G,normalForm:function(e){return G(e).replaceAll("-","")},enumify:function(e){return G(e).replace(/-/g,"_").toUpperCase()},escapeHtml:function(e){return e.replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")},decodeHtmlEntities:function(e){let t=e.replace(/&#(\d+);/g,(e,t)=>String.fromCharCode(t)).replace(/&#x(\d+);/g,(e,t)=>String.fromCharCode(parseInt(t,16)));for(const[e,n]of Object.entries(Z))t=t.replaceAll(e,n);return t},after:K,afterLast:X,before:W,beforeLast:J,betweenWide:function(e,t,n){const r=J(e,n);return r?K(r,t):null},betweenNarrow:function(e,t,n){const r=K(e,t);return r?W(r,n):null},getPreLine:function(e){return e.replace(/ +/g," ").replace(/^ /gm,"")},containsWord:Oe,containsWords:function(e,t,n){return"any"===n?t.some(t=>Oe(e,t)):t.every(t=>Oe(e,t))},joinUrl:Ge,getFuzzyMatchScore:H,sortByFuzzyScore:function(e,t){return e.filter(e=>H(e,t)).sort((e,n)=>H(n,t)-H(e,t))},splitOnce:Y,splitAll:Q,randomize:function(e,t=Math.random){return e.replace(/\{(.+?)\}/g,(e,n)=>u(n.split("|"),t))},expand:function e(t){const n=t.match(/\{(.+?)\}/);if(!n||!n.index)return[t];const r=n[1].split(","),i=t.slice(0,n.index),o=t.slice(n.index+n[0].length);let a=[];for(const t of r){const n=e(i+t+o);a=a.concat(n)}return a},shrinkTrim:ne,capitalize:re,decapitalize:ie,csvEscape:function(e){return e.match(/"|,/)?`"${e.replace(/"/g,'""')}"`:e},parseCsv:function(e,t=",",n='"'){const r=[];let i="",o=!1;const a=e.split("");for(const e of a)e!==t||o?e!==n||(i||o)&&!o?i+=e:o=!o:(r.push(i),i="");return r.push(i),r},surroundInOut:function(e,t){return t+e.split("").join(t)+t},getExtension:ee,getBasename:te,normalizeEmail:function(e){let[t,n]=e.split("@");t=ne(t.replaceAll(".","").toLowerCase()).replaceAll(" ","");const[r]=t.split("+");if(!r||!n||-1===n.indexOf(".")||n.indexOf(".")===n.length-1)throw new Error("Invalid email");return n=ne(n.toLowerCase()).replaceAll(" ",""),`${r}@${n}`},normalizeFilename:function(e){const t=te(e),n=ee(e);return n?`${t}.${n}`:t},parseFilename:function(e){const t=te(e),n=ee(e);return{basename:t,extension:n,filename:n?`${t}.${n}`:t}},camelToTitle:function(e){return re(e.replace(/([A-Z])/g," $1"))},slugToTitle:function(e){return e.split("-").map(re).join(" ")},slugToCamel:function(e){return ie(e.split("-").map(re).join(""))},joinHumanly:function(e,t=", ",n=" and "){return e&&e.length?1===e.length?e[0]:2===e.length?`${e[0]}${n}${e[1]}`:`${e.slice(0,e.length-1).join(t)}${n}${e[e.length-1]}`:""},findWeightedPair:ye,extractBlock:we,extractAllBlocks:function(e,t){const n=[];let r=t.wordBoundary?de(e,[`${t.opening} `,`${t.opening}\n`],t.start||0):e.indexOf(t.opening,t.start||0);for(;;){if(-1===r)return n;const i=we(e,{...t,start:r});if(!i)return n;n.push(i),r=t.wordBoundary?de(e,[`${t.opening} `,`${t.opening}\n`],r+i.length):e.indexOf(t.opening,r+i.length)}},replaceBlocks:function(t,n,r){let i=0;for(;;){const o=e.Strings.extractBlock(t,{...r,start:i});if(!o)return t;const a=n(o);i=t.indexOf(o,i)+a.length,t=t.replace(o,a)}},indexOfEarliest:de,lastIndexOfBefore:ge,parseHtmlAttributes:function(e){const t={},n=e.match(/([a-z\-]+)="([^"]+)"/g);if(n)for(const e of n){const[n,r]=Y(e,"=");t[n]=r.slice(1,r.length-1)}return t},readNextWord:Re,readWordsAfterAll:function(e,t,n=[]){const r=fe(e,t),i=[];for(const o of r)i.push(Re(e,o+t.length,n));return i},resolveVariables:function(e,t,n="$",r=":"){for(const i in t)e=Se(e,i,t[i],n,r);return e=ke(e)},resolveVariableWithDefaultSyntax:Se,resolveRemainingVariablesWithDefaults:ke,isLetter:oe,isDigit:ae,isLetterOrDigit:se,isValidObjectPathCharacter:function(e){return se(e)||"."===e||"["===e||"]"===e||"_"===e},insert:function(e,t,n,r,i){return e.slice(0,t)+r+e.slice(t,t+n)+i+e.slice(t+n)},indexOfRegex:le,allIndexOf:fe,lineMatches:he,linesMatchInOrder:function(e,t,n=!0){let r=0;for(const i of t){let t=!1;for(;!t&&r<e.length;)he(e[r],i,n)&&(t=!0),r++;if(!t)return!1}return!0},represent:function e(t,n="json",r=0){if(t&&b(t.represent)){const e=t.represent();if(v(e))return"json"===n&&0===r?JSON.stringify(e):e}if(m(t,!1)){if(r>1)return"[object Object]";if("json"===n){if(Array.isArray(t)){const n=t.map(t=>e(t,"json",r+1));return 0===r?JSON.stringify(n):n}const n={};t.message&&(n.message=e(t.message,"json",r+1));for(const[i,o]of Object.entries(t))n[i]=e(o,"json",r+1);return 0===r?JSON.stringify(n):n}if("key-value"===n){const n=Object.keys(t);return t.message&&!n.includes("message")&&n.unshift("message"),n.map(n=>`${n}=${JSON.stringify(e(t[n],"json",r+1))}`).join(" ")}}return w(t)&&(t="undefined"),0===r?JSON.stringify(t):t},resolveMarkdownLinks:function(e,t){let n=e.indexOf("](");for(;-1!==n;){const r=ge(e,"[",n),i=e.indexOf(")",n);if(-1!==r&&-1!==i){const[n,o]=e.slice(r+1,i).split("]("),a=t(n,o);e=e.slice(0,r)+a+e.slice(i+1)}n=e.indexOf("](",n+1)}return e},buildUrl:function(e,t,n){return Ge([e,t])+$e(n||{})},isChinese:function(e){return/^[\u4E00-\u9FA5]+$/.test(e)},replaceBetweenStrings:function(e,t,n,r,i=!0){const o=e.indexOf(t),a=e.indexOf(n,o+t.length);if(-1===o||-1===a)throw Error("Start or end not found");return i?e.substring(0,o+t.length)+r+e.substring(a):e.substring(0,o)+r+e.substring(a+n.length)},describeMarkdown:function(e){let t="p";return e.startsWith("#")?(t="h1",e=e.slice(1).trim()):e.startsWith("-")&&(t="li",e=e.slice(1).trim()),{type:t,isCapitalized:e[0]===e[0].toUpperCase(),hasPunctuation:/[.?!]$/.test(e),endsWithColon:/:$/.test(e)}},isBalanced:function(e,t="(",n=")"){let r=0,i=0;for(;i<e.length;)if(e.startsWith(t,i)?(r++,i+=t.length):e.startsWith(n,i)?(r--,i+=n.length):i++,r<0)return!1;return t===n?r%2==0:0===r},textToFormat:function(e){let t=(e=e.normalize("NFD").replace(/[\u0300-\u036f]/g,"")).length;for(;(e=e.replace(/(\w+)[\s,']+\w+/g,"$1")).length!==t;)t=e.length;return e=(e=(e=e.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(e,t){const n=[];let r=0;for(;r<e.length;){const i=e.indexOf(t,r);if(-1===i){n.push({string:e.slice(r),symbol:null});break}const o=e.indexOf(t,i+t.length);if(i>r&&-1!==o&&n.push({string:e.slice(r,i),symbol:null}),-1===o){n.push({string:e.slice(r),symbol:null});break}n.push({string:e.slice(i+t.length,o),symbol:t}),r=o+t.length}return n},splitHashtags:function(e){const t=[];let n=0;for(;n<e.length;){const r=me(e,n);if(-1===r){t.push({string:e.slice(n),symbol:null});break}const i=pe(e,r+1);if(-1===i){t.push({string:e.slice(n,r),symbol:null}),t.push({string:e.slice(r+1),symbol:"#"});break}r>n&&t.push({string:e.slice(n,r),symbol:null}),t.push({string:e.slice(r+1,i),symbol:"#"}),n=i}return t},splitUrls:function(e){const t=[];let n=0;for(;n<e.length;){const r=de(e,["http://","https://"],n);if(-1===r){t.push({string:e.slice(n),symbol:null});break}const i=de(e,[" ","\n"],r);if(-1===i){r>n&&t.push({string:e.slice(n,r),symbol:null}),t.push({string:e.slice(r),symbol:"http"});break}r>n&&t.push({string:e.slice(n,r),symbol:null}),t.push({string:e.slice(r,i),symbol:"http"}),n=i}return t},route:function(e,t){const n=e.split("/").filter(e=>e),r=t.split("/").filter(e=>e);if(n.length!==r.length)return null;const i={};for(let e=0;e<n.length;e++){const t=n[e];if(t.startsWith(":"))i[t.slice(1)]=r[e];else if(t!==r[e])return null}return i},explodeReplace:Be,generateVariants:function(t,n,r,i=Math.random){const o=e.Arrays.shuffle(n.map(t=>({variants:e.Arrays.shuffle(t.variants.map(e=>e),i),avoid:t.avoid})),i),a=[];for(const e of o){const n=e.variants.filter(t=>t!==e.avoid),i=n.find(e=>t.includes(e));if(i&&(L(a,Be(t,i,n)),a.length>=r))break}if(a.length<r)for(const e of o){const n=e.variants.find(e=>t.includes(e));if(n&&(L(a,Be(t,n,e.variants)),a.length>=r))break}return a.slice(0,r)},replaceWord:function(e,t,n,r=!1){const i=new RegExp(r?`(?<=\\s|^)${t}(?=\\s|$)`:`\\b${t}\\b`,"g");return e.replace(i,n)},replacePascalCaseWords:function(e,t){return e.replace(/\b[A-Z][a-zA-Z0-9]*\b/g,e=>e.toUpperCase()===e?e:t(e))},stripHtml:function(e){return e.replace(/<[^>]*>/g,"")},breakLine:Te,measureTextWidth:function(e,t={}){return[...e].reduce((e,n)=>e+(t[n]||1),0)},toLines:function(e,t,n={}){const r=[];let i="",o=0;for(let a=0;a<e.length;a++){const s=e[a];if(i+=s,o+=n[s]||1,o>t){const{line:e,rest:t}=Te(i);r.push(e),i=t,o=t.split("").map(e=>n[e]||1).reduce((e,t)=>e+t,0)}}return i&&r.push(i),r},levenshteinDistance:function(e,t){const n=[];for(let t=0;t<=e.length;t++)n[t]=[t];for(let e=0;e<=t.length;e++)n[0][e]=e;for(let r=1;r<=e.length;r++)for(let i=1;i<=t.length;i++){const o=e[r-1]===t[i-1]?0:1;n[r][i]=Math.min(n[r-1][i]+1,n[r][i-1]+1,n[r-1][i-1]+o)}return n[e.length][t.length]},findCommonPrefix:Ae,findCommonDirectory:function(e){const t=Ae(e),n=t.lastIndexOf("/");return-1===n?"":t.slice(0,n+1)}},e.Assertions={asEqual:function(e,t){if(e!==t)throw Error(`Expected [${e}] to equal [${t}]`);return[e,t]},asTrue:function(e){if(!0!==e)throw Error(`Expected [true], got: [${e}]`);return e},asTruthy:function(e){if(!e)throw Error(`Expected truthy value, got: [${e}]`);return e},asFalse:function(e){if(!1!==e)throw Error(`Expected [false], got: [${e}]`);return e},asFalsy:function(e){if(e)throw Error(`Expected falsy value, got: [${e}]`);return e},asEither:function(e,t){if(!t.includes(e))throw Error(`Expected any of [${t.join(", ")}], got: [${e}]`);return e}},e.Cache={get:async function(e,t,n){const r=Date.now(),i=qe.get(e);if(i&&i.validUntil>r)return i.value;const o=await n(),a=r+t;return qe.set(e,{value:o,validUntil:a}),o},delete:function(e){qe.delete(e)},deleteExpired:function(){const e=Date.now();for(const[t,n]of qe.entries())n.validUntil<=e&&qe.delete(t)},size:function(){return qe.size}},e.Vector={addPoint:Kt,subtractPoint:function(e,t){return{x:e.x-t.x,y:e.y-t.y}},multiplyPoint:Jt,normalizePoint:function(e){const t=Math.sqrt(e.x*e.x+e.y*e.y);return{x:e.x/t,y:e.y/t}},pushPoint:Xt,filterCoordinates:Qt,findCorners:function(e,t,n,r){const i=[{x:0,y:0},{x:n,y:0},{x:0,y:r},{x:n,y:r}];for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const r=on(e,t,n);for(const e of r)i.some(t=>t.x===e.x&&t.y===e.y)||i.push(e)}return i.map(e=>({x:e.x*t,y:e.y*t}))},findLines:function(e,t){const n=Qt(e,(t,n)=>0===e[t][n]&&0!==e[t][n+1],"row-first").map(e=>({...e,dx:1,dy:0})),r=Qt(e,(t,n)=>0===e[t][n]&&0!==e[t][n-1],"row-first").map(e=>({...e,dx:1,dy:0})),i=Qt(e,(t,n)=>0===e[t][n]&&0!==e[t-1]?.[n],"column-first").map(e=>({...e,dx:0,dy:1})),o=Qt(e,(t,n)=>0===e[t][n]&&0!==e[t+1]?.[n],"column-first").map(e=>({...e,dx:0,dy:1}));return n.forEach(e=>e.y++),o.forEach(e=>e.x++),[...ct([...i,...o],(e,t)=>e.x===t.x&&e.y-1===t.y),...ct([...r,...n],(e,t)=>e.y===t.y&&e.x-1===t.x)].map(e=>({start:e[0],end:l(e)})).map(e=>({start:Jt(e.start,t),end:Jt(Kt(e.end,{x:e.start.dx,y:e.start.dy}),t)}))},raycast:cn,raycastCircle:function(e,t,n){const r=an(e,n),i=[];for(const n of r){const r=cn(e,t,n-.001),o=cn(e,t,n+.001);r&&i.push(r),o&&i.push(o)}return i},getLineIntersectionPoint:sn}}(Wu)),Wu),Ju=Jr(Ku);Ju.Arrays,Ju.Assertions;const Xu=Ju.Binary;Ju.Cache,Ju.Dates,Ju.Elliptic,Ju.Numbers,Ju.Objects,Ju.Pagination,Ju.Promises,Ju.Random,Ju.Strings,Ju.System,Ju.Types,Ju.Optional,Ju.Vector,Ju.PubSubChannel,Ju.Chunk,Ju.MerkleTree,Ju.FixedPointNumber,Ju.Lazy,Ju.AsyncLazy,Ju.AsyncQueue,Ju.Uint8ArrayReader,Ju.Uint8ArrayWriter,Ju.TrieRouter,Ju.RollingValueProvider;async function Yu(e,t){if(1===e.length){const t=new Uint8Array(64);return t.set(e[0].address,0),t.set(e[0].key,32),new Ni(t)}const n=[];for(let r=0;r<e.length;r+=64){const i=e.slice(r,Math.min(r+64,e.length)),o=i.reduce((e,t)=>e+t.span,0n);console.log(`[BuildEncryptedTree] Creating intermediate chunk for ${i.length} refs, totalSpan=${o}`);const a=new Uint8Array(4096);i.forEach((e,t)=>{a.set(e.address,64*t),a.set(e.key,64*t+32)}),console.log(`[BuildEncryptedTree] Payload size: ${a.length} bytes (${i.length} * 64 refs + zero padding)`);const s=_i.fromBigInt(o).toUint8Array(),c=Xu.concatBytes(s,a);console.log(`[BuildEncryptedTree] Chunk data size (before encryption): ${c.length} bytes (span=8 + payload=${a.length})`);const u=Dc(),{key:l,encryptedSpan:h,encryptedData:f}=u.encryptChunk(c),d=Xu.concatBytes(h,f);console.log(`[BuildEncryptedTree] Encrypted chunk data size: ${d.length} bytes (encryptedSpan=${h.length} + encryptedData=${f.length})`);const p=await Ki(d);console.log(`[BuildEncryptedTree] Intermediate chunk address: ${p.toHex()}, key: ${Array.from(l).map(e=>e.toString(16).padStart(2,"0")).join("")}`),await t(d),n.push({address:p.toUint8Array(),key:l,span:o})}if(n.length>1)return Yu(n,t);const r=new Uint8Array(64);return r.set(n[0].address,0),r.set(n[0].key,32),new Ni(r)}class Qu{constructor(e){this.cursor=0,this.buffer=e}write(e){throw new Error("SimpleUint8ArrayWriter.write() not implemented")}max(){return this.buffer.length}}class el{constructor(e){this.encryptedChunk=e,this.span=e.span.toBigInt(),this.writer=new Qu(e.data)}hash(){return this.encryptedChunk.address.toUint8Array()}build(){return this.encryptedChunk.data}}async function tl(e,t,n,r){const{bee:i,stamper:o,postageBatchId:a}=e;if(!o&&!a)throw new Error("No authentication method available");let s=n?.tag;if(!s){s=(await i.createTag()).uid}const c=Mu(t);let u=c.length,l=0;console.log(`[UploadEncryptedData] Splitting ${t.length} bytes into ${u} chunks`);const h=()=>{r&&r({total:u,processed:l})},f=[],d={...n,tag:s};for(const e of c){const t=Pc(e);console.log(`[UploadEncryptedData] Leaf chunk ${f.length}: address=${t.address.toHex()}, span=${e.length}, data size=${t.data.length}`),f.push({address:t.address.toUint8Array(),key:t.encryptionKey,span:BigInt(e.length)}),await nl(i,o,a,t,d),l++,h()}let p;if(1===f.length){const e=new Uint8Array(64);e.set(f[0].address,0),e.set(f[0].key,32),p=new Ni(e),console.log("[UploadEncryptedData] Single chunk upload, reference:",p.toHex())}else console.log("[UploadEncryptedData] Building encrypted merkle tree for",f.length,"chunks"),p=await Yu(f,async e=>{if(console.log(`[UploadCallback] Received encrypted chunk data, size: ${e.length} bytes`),o){const t=await Ki(e);console.log(`[UploadCallback] Calculated address for upload: ${t.toHex()}`);const n=o.stamp({hash:()=>t.toUint8Array(),build:()=>e,span:0n,writer:void 0});console.log("[UploadCallback] Uploading intermediate chunk with client-side signing..."),await i.uploadChunk(n,e,d),console.log(`[UploadCallback] Upload complete for address: ${t.toHex()}`)}else console.log("[UploadCallback] Uploading intermediate chunk with node-side stamping..."),await i.uploadChunk(a,e,d),console.log("[UploadCallback] Upload complete");u++,l++,h()}),console.log("[UploadEncryptedData] Encrypted merkle tree complete, root reference:",p.toHex());return{reference:p.toHex(),tagUid:s}}async function nl(e,t,n,r,i){const o={...i,deferred:!0,pin:!1};if(t){const n=new el(r),i=t.stamp(n);await e.uploadChunk(i,r.data,o)}else{if(!n)throw new Error("No stamper or batch ID available");await e.uploadChunk(n,r.data,o)}}class rl{constructor(e){this.parentIdentified=!1,this.authenticated=!1,this.stamperDepth=23,this.popupMode="window",this.defaultBeeApiUrl=e.beeApiUrl,this.beeApiUrl=e.beeApiUrl,this.allowedOrigins=e.allowedOrigins||[],this.bee=new Vu(this.beeApiUrl),this.setupMessageListener(),console.log("[Proxy] Proxy initialized with default Bee API:",this.defaultBeeApiUrl),this.announceReady()}announceReady(){window.parent&&window.parent!==window&&(console.log("[Proxy] Announcing readiness to parent window"),window.parent.postMessage({type:"proxyInitialized"},"*"))}getPostageBatchId(){return this.postageBatchId}getSignerKey(){return this.signerKey}initializeStamper(){if(this.signerKey&&this.postageBatchId)try{const e=this.loadStamperState();e?(this.stamper=Fu.fromState(this.signerKey,this.postageBatchId,e,this.stamperDepth),console.log("[Proxy] Stamper restored from saved state")):(this.stamper=Fu.fromBlank(this.signerKey,this.postageBatchId,this.stamperDepth),console.log("[Proxy] Stamper initialized fresh with depth:",this.stamperDepth))}catch(e){console.error("[Proxy] Failed to initialize stamper:",e),this.stamper=void 0}else console.warn("[Proxy] Cannot initialize stamper: missing signer key or batch ID")}saveStamperState(){if(this.stamper&&this.parentOrigin&&this.postageBatchId)try{const e=this.stamper.getState(),t=`swarm-stamper-${this.parentOrigin}-${this.postageBatchId}`,n=[];for(let t=0;t<e.length;t++)0!==e[t]&&n.push([t,e[t]]);localStorage.setItem(t,JSON.stringify(n))}catch(e){console.error("[Proxy] Failed to save stamper state:",e)}}loadStamperState(){if(this.parentOrigin&&this.postageBatchId)try{const e=`swarm-stamper-${this.parentOrigin}-${this.postageBatchId}`,t=localStorage.getItem(e);if(t){const e=JSON.parse(t),n=new Uint32Array(65536);for(const[t,r]of e)n[t]=r;return n}}catch(e){console.error("[Proxy] Failed to load stamper state:",e)}}setupMessageListener(){window.addEventListener("message",async e=>{console.log("[Proxy] Message received:",e.data.type,"from:",e.origin);const{type:t}=e.data;if("parentIdentify"===t)return void this.handleParentIdentify(e);if(!this.parentIdentified)return void console.warn("[Proxy] Ignoring message - parent not identified yet");const n=e.origin===window.location.origin,r=e.origin===this.parentOrigin;if("setButtonStyles"===t&&r)return this.currentStyles=e.data.styles,console.log("[Proxy] Button styles updated"),void(!this.authenticated&&this.authButtonContainer&&this.showAuthButton());if(n||r)try{if(r)try{const t=Gr.parse(e.data);return void await this.handleParentMessage(t,e)}catch(e){console.warn("[Proxy] Invalid parent message:",e)}if(n)try{const t=Wr.parse(e.data);return void await this.handlePopupMessage(t,e)}catch(e){console.warn("[Proxy] Invalid popup message:",e)}console.warn("[Proxy] Unknown message type:",t),this.sendErrorToParent(e,e.data.requestId,`Unknown message type: ${t}`)}catch(t){console.error("[Proxy] Error handling message:",t),this.sendErrorToParent(e,e.data.requestId,t instanceof Error?t.message:"Unknown error")}else console.warn("[Proxy] Rejected message from unauthorized origin:",e.origin)})}handleParentIdentify(e){if(this.parentIdentified)return void console.error("[Proxy] Parent already identified! Ignoring duplicate.");const t=e.data,n=t.beeApiUrl,r=t.popupMode;if(this.parentOrigin=e.origin,this.parentIdentified=!0,console.log("[Proxy] Parent identified via postMessage:",this.parentOrigin),console.log("[Proxy] Parent locked in - cannot be changed"),this.allowedOrigins.length>0&&!this.isAllowedOrigin(this.parentOrigin)){const t=`Origin validation failed! Expected one of: ${this.allowedOrigins.join(", ")}, but received: ${this.parentOrigin}`;return console.error("[Proxy]",t),void(e.source&&e.source.postMessage({type:"initError",error:t},{targetOrigin:e.origin}))}n?(this.beeApiUrl=n,this.bee=new Vu(this.beeApiUrl),console.log("[Proxy] Using Bee API URL from parent:",this.beeApiUrl)):console.log("[Proxy] Using default Bee API URL:",this.beeApiUrl),r&&(this.popupMode=r,console.log("[Proxy] Using popup mode from parent:",this.popupMode)),this.loadAuthData(),e.source&&e.source.postMessage({type:"proxyReady",authenticated:this.authenticated,parentOrigin:this.parentOrigin},{targetOrigin:e.origin})}async handleParentMessage(e,t){switch(e.type){case"parentIdentify":break;case"checkAuth":this.handleCheckAuth(e,t);break;case"requestAuth":this.handleRequestAuth(e,t);break;case"uploadData":await this.handleUploadData(e,t);break;case"downloadData":await this.handleDownloadData(e,t);break;case"uploadFile":await this.handleUploadFile(e,t);break;case"downloadFile":await this.handleDownloadFile(e,t);break;case"uploadChunk":await this.handleUploadChunk(e,t);break;case"downloadChunk":await this.handleDownloadChunk(e,t);break;default:const n=e;console.warn("[Proxy] Unhandled message type:",n)}}async handlePopupMessage(e,t){if("setSecret"===e.type)await this.handleSetSecret(e,t)}isAllowedOrigin(e){return 0===this.allowedOrigins.length||this.allowedOrigins.includes(e)}loadAuthData(){if(!this.parentOrigin)return void console.log("[Proxy] No parent origin, cannot load auth data");const e=`swarm-secret-${this.parentOrigin}`,t=localStorage.getItem(e);if(t)try{const e=JSON.parse(t);console.log("[Proxy] Auth data loaded from localStorage for:",this.parentOrigin),this.appSecret=e.secret,this.postageBatchId=e.postageBatchId,this.signerKey=e.signerKey,this.authenticated=!0,this.hideAuthButton(),this.signerKey&&this.postageBatchId&&this.initializeStamper()}catch(e){console.error("[Proxy] Failed to parse auth data:",e),this.showAuthButton()}else console.log("[Proxy] No auth data found for:",this.parentOrigin),this.showAuthButton()}updateAuthStatus(e){this.authenticated=e,e?this.hideAuthButton():this.showAuthButton()}saveAuthData(e,t){const n=`swarm-secret-${e}`;localStorage.setItem(n,JSON.stringify(t)),console.log("[Proxy] Auth data saved to localStorage for:",e)}sendErrorToParent(e,t,n){e.source&&t&&e.source.postMessage({type:"error",requestId:t,error:n},{targetOrigin:e.origin})}sendToParent(e){this.parentOrigin&&window.parent&&window.parent!==window.self?window.parent.postMessage(e,this.parentOrigin):console.warn("[Proxy] Cannot send message to parent - no parent window")}handleCheckAuth(e,t){console.log("[Proxy] Checking authentication status..."),t.source&&t.source.postMessage({type:"authStatusResponse",requestId:e.requestId,authenticated:this.authenticated,origin:this.authenticated?this.parentOrigin:void 0},{targetOrigin:t.origin}),console.log("[Proxy] Authentication status:",this.authenticated)}handleRequestAuth(e,t){console.log("[Proxy] Request to show auth button for parent:",this.parentOrigin),this.currentStyles=e.styles,this.authButtonContainer&&this.showAuthButton()}showAuthButton(){if(!this.authButtonContainer)return void console.log("[Proxy] No auth button container set yet");this.authButtonContainer.innerHTML="";const e=document.createElement("button");e.textContent="🔐 Login with Swarm ID";const t=this.currentStyles||{};e.style.backgroundColor=t.backgroundColor||"#dd7200",e.style.color=t.color||"white",e.style.border=t.border||"none",e.style.borderRadius=t.borderRadius||"6px",e.style.padding=t.padding||"12px 24px",e.style.fontSize=t.fontSize||"14px",e.style.fontWeight=t.fontWeight||"600",e.style.cursor=t.cursor||"pointer",e.style.transition="all 0.2s",e.style.boxShadow="0 2px 8px rgba(221, 114, 0, 0.3)",e.addEventListener("mouseenter",()=>{e.style.transform="translateY(-1px)",e.style.boxShadow="0 4px 12px rgba(221, 114, 0, 0.5)"}),e.addEventListener("mouseleave",()=>{e.style.transform="translateY(0)",e.style.boxShadow="0 2px 8px rgba(221, 114, 0, 0.3)"}),e.addEventListener("click",()=>{if(!this.parentOrigin)return void console.error("[Proxy] Cannot open auth window - parent origin not set");if(console.log("[Proxy] Opening authentication window for parent:",this.parentOrigin),e.disabled=!0,e.innerHTML='<span style="display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.3); border-radius: 50%; border-top-color: white; animation: spin 1s linear infinite;"></span>',!document.getElementById("swarm-id-spinner-style")){const e=document.createElement("style");e.id="swarm-id-spinner-style",e.textContent="@keyframes spin { to { transform: rotate(360deg); } }",document.head.appendChild(e)}const t=`${window.location.origin}/connect?origin=${encodeURIComponent(this.parentOrigin)}`;"popup"===this.popupMode?window.open(t,"_blank","width=500,height=600"):window.open(t,"_blank")}),this.authButtonContainer.appendChild(e),console.log("[Proxy] Auth button shown")}hideAuthButton(){this.authButtonContainer&&(this.authButtonContainer.innerHTML="",console.log("[Proxy] Auth button hidden"))}setAuthButtonContainer(e){this.authButtonContainer=e,console.log("[Proxy] Auth button container set")}async handleSetSecret(e,t){const{appOrigin:n,data:r}=e;console.log("[Proxy] Received auth data for app:",n),n!==this.parentOrigin&&console.warn("[Proxy] App origin mismatch:",n,"vs",this.parentOrigin),this.saveAuthData(n,r),this.appSecret=r.secret,this.postageBatchId=r.postageBatchId,this.signerKey=r.signerKey,this.updateAuthStatus(!0),this.signerKey&&this.postageBatchId&&this.initializeStamper(),this.sendToParent({type:"authSuccess",origin:n}),console.log("[Proxy] Notified parent of successful authentication"),t.source&&!t.source.closed&&t.source.postMessage({type:"secretReceived",success:!0},{targetOrigin:t.origin})}async handleUploadData(e,t){const{requestId:n,data:r,options:i,enableProgress:o}=e;if(console.log("[Proxy] Upload data request, size:",r?r.length:0),!this.authenticated||!this.appSecret)throw new Error("Not authenticated. Please login first.");try{const e={bee:this.bee,stamper:this.stamper,postageBatchId:this.postageBatchId,signerKey:this.signerKey},a=o?e=>{t.source&&t.source.postMessage({type:"uploadProgress",requestId:n,total:e.total,processed:e.processed},{targetOrigin:t.origin})}:void 0;let s;if(this.signerKey)i?.encrypt?(console.log("[Proxy] Using client-side signing with encryption for uploadData"),s=await tl(e,r,i,a)):(console.log("[Proxy] Using client-side signing for uploadData"),s=await Gu(e,r,i,a));else{if(!this.postageBatchId)throw new Error("No authentication method available");if(i?.encrypt){console.log("[Proxy] Using node-side stamping with encryption for uploadData");const e=await this.bee.uploadData(this.postageBatchId,r,i);s={reference:e.reference.toHex(),tagUid:e.tagUid}}else{console.log("[Proxy] Using node-side stamping for uploadData");const e=await this.bee.uploadData(this.postageBatchId,r,i);s={reference:e.reference.toHex(),tagUid:e.tagUid}}}this.signerKey&&this.stamper&&this.saveStamperState(),t.source&&t.source.postMessage({type:"uploadDataResponse",requestId:n,reference:s.reference,tagUid:s.tagUid},{targetOrigin:t.origin}),console.log("[Proxy] Data uploaded:",s.reference)}catch(e){this.sendErrorToParent(t,n,e instanceof Error?e.message:"Upload failed")}}async handleDownloadData(e,t){const{requestId:n,reference:r,options:i}=e;if(console.log("[Proxy] Download data request, reference:",r),!this.authenticated||!this.appSecret)throw new Error("Not authenticated. Please login first.");try{console.log("[Proxy] Downloading from Bee at:",this.beeApiUrl);const e=await async function(e,t,n){console.log(`[DownloadData] Downloading from reference: ${t} (${t.length} chars)`);const r=new Ni(t),i=new _c(e,r,{downloadOptions:n,onDownloadProgress:void 0,concurrency:64}),o=await i.readAll();return console.log(`[DownloadData] Download complete, ${o.length} bytes`),o}(this.bee,r,i);console.log("[Proxy] Download successful, data size:",e.length),t.source&&t.source.postMessage({type:"downloadDataResponse",requestId:n,data:e},{targetOrigin:t.origin}),console.log("[Proxy] Data downloaded:",r)}catch(e){this.sendErrorToParent(t,n,e instanceof Error?e.message:"Download failed")}}async handleUploadFile(e,t){const{requestId:n,data:r,name:i,options:o}=e;if(console.log("[Proxy] Upload file request, name:",i,"size:",r?r.length:0),!this.authenticated||!this.appSecret)throw new Error("Not authenticated. Please login first.");if(!this.signerKey||this.postageBatchId){if(!this.postageBatchId)throw new Error("No postage batch ID available. Please authenticate with a valid batch ID.");try{console.log("[Proxy] Uploading file to Bee at:",this.beeApiUrl,"with batch:",this.postageBatchId);const e=await this.bee.uploadFile(this.postageBatchId,r,i,o);console.log("[Proxy] File upload successful, reference:",e.reference.toHex()),t.source&&t.source.postMessage({type:"uploadFileResponse",requestId:n,reference:e.reference.toHex(),tagUid:e.tagUid},{targetOrigin:t.origin}),console.log("[Proxy] File uploaded:",e.reference.toHex())}catch(e){this.sendErrorToParent(t,n,e instanceof Error?e.message:"Upload failed")}}else this.sendErrorToParent(t,n,"Signed uploads for files not yet implemented. Please use uploadChunk for signed uploads, or provide a postage batch ID for automatic chunking.")}async handleDownloadFile(e,t){const{requestId:n,reference:r,path:i,options:o}=e;if(console.log("[Proxy] Download file request, reference:",r,"path:",i),!this.authenticated||!this.appSecret)throw new Error("Not authenticated. Please login first.");try{console.log("[Proxy] Downloading file from Bee at:",this.beeApiUrl);const e=await this.bee.downloadFile(r,i,o);console.log("[Proxy] File download successful, data size:",e.data.toUint8Array().length);const a=e.data.toUint8Array();t.source&&t.source.postMessage({type:"downloadFileResponse",requestId:n,name:e.name||"file",data:a},{targetOrigin:t.origin}),console.log("[Proxy] File downloaded:",r)}catch(e){this.sendErrorToParent(t,n,e instanceof Error?e.message:"Download failed")}}async handleUploadChunk(e,t){const{requestId:n,data:r,options:i}=e;if(console.log("[Proxy] Upload chunk request, size:",r?r.length:0),!this.authenticated||!this.appSecret)throw new Error("Not authenticated. Please login first.");if(!this.signerKey&&!this.postageBatchId)throw new Error("No postage batch ID or signer key available. Please authenticate.");try{if(r.length<1||r.length>4096)throw new Error(`Invalid chunk size: ${r.length} bytes. Chunks must be between 1 and 4096 bytes.`);let e;if(this.signerKey){if(this.stamper||this.initializeStamper(),!this.stamper)throw new Error("Failed to initialize stamper for signing");console.log("[Proxy] Signing and uploading chunk with signer key");const t=Yi(r),n=this.stamper.stamp(t),o={...i,deferred:!0,pin:!1};e=await this.bee.uploadChunk(n,t.data,o)}else{if(!this.postageBatchId)throw new Error("No authentication method available");{console.log("[Proxy] Uploading chunk to Bee at:",this.beeApiUrl,"with batch:",this.postageBatchId);const t={...i,deferred:!0,pin:!1};e=await this.bee.uploadChunk(this.postageBatchId,r,t)}}console.log("[Proxy] Chunk upload successful, reference:",e.reference.toHex()),this.signerKey&&this.stamper&&this.saveStamperState(),t.source&&t.source.postMessage({type:"uploadChunkResponse",requestId:n,reference:e.reference.toHex()},{targetOrigin:t.origin}),console.log("[Proxy] Chunk uploaded:",e.reference.toHex())}catch(e){this.sendErrorToParent(t,n,e instanceof Error?e.message:"Upload failed")}}async handleDownloadChunk(e,t){const{requestId:n,reference:r,options:i}=e;if(console.log("[Proxy] Download chunk request, reference:",r),!this.authenticated||!this.appSecret)throw new Error("Not authenticated. Please login first.");try{console.log("[Proxy] Downloading chunk from Bee at:",this.beeApiUrl);const e=await this.bee.downloadChunk(r,i);console.log("[Proxy] Chunk download successful, data size:",e.length),t.source&&t.source.postMessage({type:"downloadChunkResponse",requestId:n,data:e},{targetOrigin:t.origin}),console.log("[Proxy] Chunk downloaded:",r)}catch(e){this.sendErrorToParent(t,n,e instanceof Error?e.message:"Download failed")}}}async function il(e,t){console.log("[KeyDerivation] Deriving secret for app:",t);const n=new TextEncoder,r=al(e),i=n.encode(t),o=await crypto.subtle.importKey("raw",r,{name:"HMAC",hash:"SHA-256"},!1,["sign"]),a=await crypto.subtle.sign("HMAC",o,i),s=sl(new Uint8Array(a));return console.log("[KeyDerivation] Secret derived:",s.substring(0,16)+"..."),s}async function ol(){console.log("[KeyDerivation] Generating random master key...");const e=new Uint8Array(32);crypto.getRandomValues(e);const t=sl(e);return console.log("[KeyDerivation] Master key generated:",t.substring(0,16)+"..."),t}function al(e){const t=e.replace(/\s/g,"");if(t.length%2!=0)throw new Error("Invalid hex string: length must be even");const n=new Uint8Array(t.length/2);for(let e=0;e<t.length;e+=2)n[e/2]=parseInt(t.substring(e,e+2),16);return n}function sl(e){return Array.from(e).map(e=>e.toString(16).padStart(2,"0")).join("")}const cl={hexToUint8Array:al,uint8ArrayToHex:sl};class ul{constructor(e={}){this.masterKeyStorageKey=e.masterKeyStorageKey||"swarm-master-key"}async initialize(){if(!window.opener)throw new Error("No opener window found. This page must be opened by Swarm ID iframe.");try{const e=window.opener.location.origin;if(e!==window.location.origin)throw new Error(`Opener origin (${e}) does not match expected origin`);console.log("[Auth] Security: Opener origin validated ✓")}catch{throw new Error("Cannot verify opener origin - cross-origin access denied")}const e=new URLSearchParams(window.location.search);if(this.appOrigin=e.get("origin")??void 0,!this.appOrigin)throw new Error("No origin parameter found in URL");console.log("[Auth] Got app origin from URL parameter:",this.appOrigin),this.masterKey=localStorage.getItem(this.masterKeyStorageKey)??void 0,this.masterKey?console.log("[Auth] Master key loaded from localStorage"):console.log("[Auth] No master key found")}getAppOrigin(){return this.appOrigin}getMasterKey(){return this.masterKey}hasMasterKey(){return void 0!==this.masterKey}setPostageBatchId(e){this.postageBatchId=e}getPostageBatchId(){return this.postageBatchId}setSignerKey(e){this.signerKey=e}getSignerKey(){return this.signerKey}setAuthData({postageBatchId:e,signerKey:t}){this.postageBatchId=e,this.signerKey=t}async setupNewIdentity(){console.log("[Auth] Setting up new identity...");const e=await ol();return localStorage.setItem(this.masterKeyStorageKey,e),this.masterKey=e,console.log("[Auth] New master key generated and stored"),e}async authenticate(){if(!this.masterKey)throw new Error("No master key available. Please set up an identity first.");if(!this.appOrigin)throw new Error("Unknown app origin. Cannot authenticate.");if(!this.postageBatchId&&!this.signerKey)throw new Error("No postage batch ID or signer key provided. Cannot authenticate.");console.log("[Auth] Starting authentication for app:",this.appOrigin);const e=await il(this.masterKey,this.appOrigin);if(console.log("[Auth] App secret derived:",e.substring(0,16)+"..."),!window.opener||window.opener.closed)throw new Error("Opener window not available");console.log("[Auth] Sending auth data to iframe..."),window.opener.postMessage({type:"setSecret",appOrigin:this.appOrigin,data:{secret:e,postageBatchId:this.postageBatchId,signerKey:this.signerKey}},window.location.origin),console.log("[Auth] Auth data sent to iframe")}close(e=1500){setTimeout(()=>{window.close()},e)}}e.AddressSchema=Ur,e.AuthStatusSchema=Lr,e.BatchIdSchema=Nr,e.ButtonStylesSchema=qr,e.DownloadOptionsSchema=Vr,e.FileDataSchema=Mr,e.IframeToParentMessageSchema=Hr,e.ParentToIframeMessageSchema=Gr,e.PopupToIframeMessageSchema=Wr,e.PostageBatchSchema=jr,e.ReferenceSchema=Pr,e.SwarmIdAuth=ul,e.SwarmIdClient=class{constructor(e){this.ready=!1,this.pendingRequests=new Map,this.requestIdCounter=0,this.iframeOrigin=e.iframeOrigin,this.iframePath=e.iframePath||"/demo/proxy.html",this.beeApiUrl=e.beeApiUrl||"http://localhost:1633",this.timeout=e.timeout||3e4,this.onAuthChange=e.onAuthChange,this.popupMode=e.popupMode||"window",this.readyPromise=new Promise((e,t)=>{this.readyResolve=e,this.readyReject=t,setTimeout(()=>{t(new Error("Proxy initialization timeout - proxy did not respond within 10 seconds"))},1e4)}),this.setupMessageListener()}async initialize(){if(this.iframe)throw new Error("SwarmIdClient already initialized");this.iframe=document.createElement("iframe"),this.iframe.src=`${this.iframeOrigin}${this.iframePath}`,console.log("[SwarmIdClient] Creating iframe with src:",this.iframe.src),console.log("[SwarmIdClient] iframeOrigin:",this.iframeOrigin),console.log("[SwarmIdClient] iframePath:",this.iframePath),this.iframe.style.display="none",this.iframe.style.position="fixed",this.iframe.style.bottom="20px",this.iframe.style.right="20px",this.iframe.style.width="300px",this.iframe.style.height="80px",this.iframe.style.border="1px solid #ddd",this.iframe.style.borderRadius="8px",this.iframe.style.boxShadow="0 4px 12px rgba(0,0,0,0.15)",this.iframe.style.zIndex="999999",this.iframe.style.backgroundColor="white",await new Promise((e,t)=>{this.iframe.onload=()=>e(),this.iframe.onerror=()=>t(new Error("Failed to load Swarm ID iframe")),document.body.appendChild(this.iframe)}),console.log("[SwarmIdClient] Iframe loaded, waiting for proxy initialization..."),await this.waitForProxyInitialized(),console.log("[SwarmIdClient] Proxy initialized and ready"),console.log("[SwarmIdClient] Sending parentIdentify to iframe at origin:",this.iframeOrigin),this.sendMessage({type:"parentIdentify",beeApiUrl:this.beeApiUrl,popupMode:this.popupMode}),console.log("[SwarmIdClient] parentIdentify sent"),await this.readyPromise}waitForProxyInitialized(){return new Promise((e,t)=>{const n=setTimeout(()=>{i(),t(new Error("Proxy initialization timeout - proxy did not signal readiness"))},1e4),r=t=>{"proxyInitialized"===t.data?.type&&(console.log("[SwarmIdClient] Received proxyInitialized from:",t.origin),i(),e())},i=()=>{clearTimeout(n),window.removeEventListener("message",r)};window.addEventListener("message",r)})}setupMessageListener(){this.messageListener=e=>{if(e.origin!==this.iframeOrigin)return void console.warn("[SwarmIdClient] Rejected message from unauthorized origin:",e.origin);let t;try{t=Hr.parse(e.data)}catch(t){return void console.warn("[SwarmIdClient] Invalid message format:",e.data,t)}this.handleIframeMessage(t)},window.addEventListener("message",this.messageListener)}handleIframeMessage(e){switch(e.type){case"proxyReady":this.ready=!0,this.readyResolve&&this.readyResolve(),this.iframe&&(this.iframe.style.display=e.authenticated?"none":"block"),this.onAuthChange&&this.onAuthChange(e.authenticated);break;case"authStatusResponse":if(this.iframe&&(this.iframe.style.display=e.authenticated?"none":"block"),this.onAuthChange&&this.onAuthChange(e.authenticated),"requestId"in e){const t=this.pendingRequests.get(e.requestId);t&&(clearTimeout(t.timeoutId),this.pendingRequests.delete(e.requestId),t.resolve(e))}break;case"authSuccess":this.iframe&&(this.iframe.style.display="none"),this.onAuthChange&&this.onAuthChange(!0);break;case"initError":console.error("[SwarmIdClient] Proxy initialization error:",e.error),this.readyReject&&this.readyReject(new Error(e.error));break;case"error":{const t=this.pendingRequests.get(e.requestId);t&&(clearTimeout(t.timeoutId),this.pendingRequests.delete(e.requestId),t.reject(new Error(e.error)));break}default:if("requestId"in e){const t=this.pendingRequests.get(e.requestId);t&&(clearTimeout(t.timeoutId),this.pendingRequests.delete(e.requestId),t.resolve(e))}}}sendMessage(e){if(!this.iframe||!this.iframe.contentWindow)throw new Error("Iframe not initialized");try{Gr.parse(e)}catch(e){throw new Error(`Invalid message format: ${e}`)}this.iframe.contentWindow.postMessage(e,this.iframeOrigin)}async sendRequest(e){return new Promise((t,n)=>{const r=setTimeout(()=>{this.pendingRequests.delete(e.requestId),n(new Error(`Request timeout after ${this.timeout}ms`))},this.timeout);this.pendingRequests.set(e.requestId,{resolve:t,reject:n,timeoutId:r}),this.sendMessage(e)})}generateRequestId(){return`req-${++this.requestIdCounter}-${Date.now()}`}ensureReady(){if(!this.ready)throw new Error("SwarmIdClient not initialized. Call initialize() first.")}createAuthButton(e,t){if(this.ensureReady(),!this.iframe)throw new Error("Iframe not initialized");return this.iframe}async checkAuthStatus(){this.ensureReady();const e=this.generateRequestId(),t=await this.sendRequest({type:"checkAuth",requestId:e});return{authenticated:t.authenticated,origin:t.origin}}async isAuthenticated(){return(await this.checkAuthStatus()).authenticated}async uploadData(e,t,n){this.ensureReady();const r=this.generateRequestId();let i;n&&(i=e=>{if(e.origin===this.iframeOrigin)try{const t=Hr.parse(e.data);"uploadProgress"===t.type&&t.requestId===r&&n({total:t.total,processed:t.processed})}catch{}},window.addEventListener("message",i));try{const i=await this.sendRequest({type:"uploadData",requestId:r,data:new Uint8Array(e),options:t,enableProgress:!!n});return{reference:i.reference,tagUid:i.tagUid}}finally{i&&window.removeEventListener("message",i)}}async downloadData(e,t){this.ensureReady();const n=this.generateRequestId();return(await this.sendRequest({type:"downloadData",requestId:n,reference:e,options:t})).data}async uploadFile(e,t,n){this.ensureReady();const r=this.generateRequestId();let i,o=t;if(e instanceof File){const t=await e.arrayBuffer();i=new Uint8Array(t),o=o||e.name}else i=new Uint8Array(e.buffer.slice(0),e.byteOffset,e.byteLength);const a=await this.sendRequest({type:"uploadFile",requestId:r,data:i,name:o,options:n});return{reference:a.reference,tagUid:a.tagUid}}async downloadFile(e,t,n){this.ensureReady();const r=this.generateRequestId(),i=await this.sendRequest({type:"downloadFile",requestId:r,reference:e,path:t,options:n});return{name:i.name,data:new Uint8Array(i.data)}}async uploadChunk(e,t){this.ensureReady();const n=this.generateRequestId();return{reference:(await this.sendRequest({type:"uploadChunk",requestId:n,data:e,options:t})).reference}}async downloadChunk(e,t){this.ensureReady();const n=this.generateRequestId(),r=await this.sendRequest({type:"downloadChunk",requestId:n,reference:e,options:t});return new Uint8Array(r.data)}destroy(){this.pendingRequests.forEach(e=>{clearTimeout(e.timeoutId),e.reject(new Error("Client destroyed"))}),this.pendingRequests.clear(),this.messageListener&&(window.removeEventListener("message",this.messageListener),this.messageListener=void 0),this.iframe&&this.iframe.parentNode&&(this.iframe.parentNode.removeChild(this.iframe),this.iframe=void 0),this.ready=!1}},e.SwarmIdProxy=rl,e.UploadOptionsSchema=_r,e.UploadResultSchema=Fr,e.deriveSecret=il,e.generateMasterKey=ol,e.hexToUint8Array=al,e.initAuth=async function(e){const t=new ul(e);return await t.initialize(),t},e.initProxy=function(e){return new rl(e)},e.uint8ArrayToHex=sl,e.utils=cl,e.verifySecret=async function(e,t,n){return await il(e,t)===n}});
|
|
2
|
+
//# sourceMappingURL=swarm-id.umd.js.map
|