holosphere 2.0.0-alpha0 → 2.0.0-alpha10

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.
Files changed (418) hide show
  1. package/CHANGELOG.md +473 -0
  2. package/FEATURES.md +431 -0
  3. package/LICENSE +29 -42
  4. package/LICENSE-AGPL.md +180 -0
  5. package/README.md +97 -16
  6. package/dist/2019-D2OG2idw.js +6680 -0
  7. package/dist/2019-D2OG2idw.js.map +1 -0
  8. package/dist/2019-EION3wKo.cjs +8 -0
  9. package/dist/2019-EION3wKo.cjs.map +1 -0
  10. package/dist/_commonjsHelpers-C37NGDzP.cjs +2 -0
  11. package/dist/_commonjsHelpers-C37NGDzP.cjs.map +1 -0
  12. package/dist/_commonjsHelpers-CUmg6egw.js +7 -0
  13. package/dist/_commonjsHelpers-CUmg6egw.js.map +1 -0
  14. package/dist/browser-BSniCNqO.js +3058 -0
  15. package/dist/browser-BSniCNqO.js.map +1 -0
  16. package/dist/browser-Cq59Ij19.cjs +2 -0
  17. package/dist/browser-Cq59Ij19.cjs.map +1 -0
  18. package/dist/cdn/holosphere.min.js +55 -0
  19. package/dist/cdn/holosphere.min.js.map +1 -0
  20. package/dist/cjs/holosphere.cjs +2 -0
  21. package/dist/cjs/holosphere.cjs.map +1 -0
  22. package/dist/esm/holosphere.js +53 -0
  23. package/dist/esm/holosphere.js.map +1 -0
  24. package/dist/index-DDGt_V9o.cjs +12 -0
  25. package/dist/index-DDGt_V9o.cjs.map +1 -0
  26. package/dist/index-DJXftyvB.js +39841 -0
  27. package/dist/index-DJXftyvB.js.map +1 -0
  28. package/dist/index-DMbdcMtK.cjs +18 -0
  29. package/dist/index-DMbdcMtK.cjs.map +1 -0
  30. package/dist/index-DeZ1xz_s.js +15104 -0
  31. package/dist/index-DeZ1xz_s.js.map +1 -0
  32. package/dist/indexeddb-storage-BFt6hMeF.js +176 -0
  33. package/dist/indexeddb-storage-BFt6hMeF.js.map +1 -0
  34. package/dist/indexeddb-storage-BK5tv4Sh.cjs +2 -0
  35. package/dist/indexeddb-storage-BK5tv4Sh.cjs.map +1 -0
  36. package/dist/memory-storage-C9HuoL2E.js +91 -0
  37. package/dist/memory-storage-C9HuoL2E.js.map +1 -0
  38. package/dist/memory-storage-Dao7jfYG.cjs +2 -0
  39. package/dist/memory-storage-Dao7jfYG.cjs.map +1 -0
  40. package/dist/secp256k1-BbKzbLtD.cjs +12 -0
  41. package/dist/secp256k1-BbKzbLtD.cjs.map +1 -0
  42. package/dist/secp256k1-CreY7Pcl.js +1890 -0
  43. package/dist/secp256k1-CreY7Pcl.js.map +1 -0
  44. package/docs/CONTRACTS.md +797 -0
  45. package/docs/FOSDEM_PROPOSAL.md +388 -0
  46. package/docs/LOCALFIRST.md +266 -0
  47. package/docs/api/ai_aggregation.js.html +333 -0
  48. package/docs/api/ai_breakdown.js.html +524 -0
  49. package/docs/api/ai_classifier.js.html +231 -0
  50. package/docs/api/ai_council.js.html +246 -0
  51. package/docs/api/ai_embeddings.js.html +304 -0
  52. package/docs/api/ai_federation-ai.js.html +338 -0
  53. package/docs/api/ai_h3-ai.js.html +970 -0
  54. package/docs/api/ai_index.js.html +124 -0
  55. package/docs/api/ai_json-ops.js.html +241 -0
  56. package/docs/api/ai_llm-service.js.html +239 -0
  57. package/docs/api/ai_nl-query.js.html +236 -0
  58. package/docs/api/ai_relationships.js.html +367 -0
  59. package/docs/api/ai_schema-extractor.js.html +235 -0
  60. package/docs/api/ai_spatial.js.html +307 -0
  61. package/docs/api/ai_tts.js.html +214 -0
  62. package/docs/api/content_social-protocols.js.html +180 -0
  63. package/docs/api/core_holosphere.js.html +757 -0
  64. package/docs/api/crypto_nostr-utils.js.html +306 -0
  65. package/docs/api/crypto_secp256k1.js.html +267 -0
  66. package/docs/api/data/search.json +1 -0
  67. package/docs/api/federation_discovery.js.html +337 -0
  68. package/docs/api/federation_handshake.js.html +478 -0
  69. package/docs/api/federation_hologram.js.html +1053 -0
  70. package/docs/api/federation_registry.js.html +389 -0
  71. package/docs/api/fonts/Inconsolata-Regular.ttf +0 -0
  72. package/docs/api/fonts/OpenSans-Regular.ttf +0 -0
  73. package/docs/api/fonts/WorkSans-Bold.ttf +0 -0
  74. package/docs/api/global.html +3 -0
  75. package/docs/api/hierarchical_upcast.js.html +128 -0
  76. package/docs/api/index.html +265 -0
  77. package/docs/api/index.js.html +1868 -0
  78. package/docs/api/lib_ai-methods.js.html +660 -0
  79. package/docs/api/lib_contract-methods.js.html +445 -0
  80. package/docs/api/lib_errors.js.html +56 -0
  81. package/docs/api/lib_federation-methods.js.html +348 -0
  82. package/docs/api/lib_index.js.html +33 -0
  83. package/docs/api/module-ai.html +5 -0
  84. package/docs/api/module-ai_aggregation-SmartAggregation.html +6 -0
  85. package/docs/api/module-ai_aggregation.SmartAggregation.html +3 -0
  86. package/docs/api/module-ai_aggregation.html +3 -0
  87. package/docs/api/module-ai_breakdown-TaskBreakdown.html +5 -0
  88. package/docs/api/module-ai_breakdown.TaskBreakdown.html +3 -0
  89. package/docs/api/module-ai_breakdown.html +3 -0
  90. package/docs/api/module-ai_classifier-Classifier.html +6 -0
  91. package/docs/api/module-ai_classifier.Classifier.html +3 -0
  92. package/docs/api/module-ai_classifier.html +3 -0
  93. package/docs/api/module-ai_council-Council.html +6 -0
  94. package/docs/api/module-ai_council.Council.html +3 -0
  95. package/docs/api/module-ai_council.html +3 -0
  96. package/docs/api/module-ai_embeddings-Embeddings.html +5 -0
  97. package/docs/api/module-ai_embeddings.Embeddings.html +3 -0
  98. package/docs/api/module-ai_embeddings.html +3 -0
  99. package/docs/api/module-ai_federation-ai-FederationAdvisor.html +6 -0
  100. package/docs/api/module-ai_federation-ai.FederationAdvisor.html +3 -0
  101. package/docs/api/module-ai_federation-ai.html +3 -0
  102. package/docs/api/module-ai_h3-ai-H3AI.html +6 -0
  103. package/docs/api/module-ai_h3-ai.H3AI.html +3 -0
  104. package/docs/api/module-ai_h3-ai.html +3 -0
  105. package/docs/api/module-ai_json-ops-JSONOps.html +5 -0
  106. package/docs/api/module-ai_json-ops.JSONOps.html +3 -0
  107. package/docs/api/module-ai_json-ops.html +3 -0
  108. package/docs/api/module-ai_llm-service-LLMService.html +5 -0
  109. package/docs/api/module-ai_llm-service.LLMService.html +3 -0
  110. package/docs/api/module-ai_llm-service.html +3 -0
  111. package/docs/api/module-ai_nl-query-NLQuery.html +5 -0
  112. package/docs/api/module-ai_nl-query.NLQuery.html +3 -0
  113. package/docs/api/module-ai_nl-query.html +3 -0
  114. package/docs/api/module-ai_relationships-RelationshipDiscovery.html +6 -0
  115. package/docs/api/module-ai_relationships.RelationshipDiscovery.html +3 -0
  116. package/docs/api/module-ai_relationships.html +3 -0
  117. package/docs/api/module-ai_schema-extractor-SchemaExtractor.html +5 -0
  118. package/docs/api/module-ai_schema-extractor.SchemaExtractor.html +3 -0
  119. package/docs/api/module-ai_schema-extractor.html +3 -0
  120. package/docs/api/module-ai_spatial-SpatialAnalysis.html +6 -0
  121. package/docs/api/module-ai_spatial.SpatialAnalysis.html +3 -0
  122. package/docs/api/module-ai_spatial.html +3 -0
  123. package/docs/api/module-ai_tts-TTS.html +5 -0
  124. package/docs/api/module-ai_tts.TTS.html +3 -0
  125. package/docs/api/module-ai_tts.html +3 -0
  126. package/docs/api/module-content_social-protocols.html +3 -0
  127. package/docs/api/module-core_holosphere-HoloSphere.html +6 -0
  128. package/docs/api/module-core_holosphere.HoloSphere.html +3 -0
  129. package/docs/api/module-core_holosphere.html +3 -0
  130. package/docs/api/module-crypto_nostr-utils.html +3 -0
  131. package/docs/api/module-crypto_secp256k1.html +3 -0
  132. package/docs/api/module-federation_hologram.html +3 -0
  133. package/docs/api/module-hierarchical_upcast.html +3 -0
  134. package/docs/api/module-holosphere-HoloSphereBase.html +3 -0
  135. package/docs/api/module-holosphere.html +3 -0
  136. package/docs/api/module-lib_ai-methods.html +3 -0
  137. package/docs/api/module-lib_contract-methods.html +3 -0
  138. package/docs/api/module-lib_errors-AuthorizationError.html +3 -0
  139. package/docs/api/module-lib_errors-ValidationError.html +3 -0
  140. package/docs/api/module-lib_errors.AuthorizationError.html +3 -0
  141. package/docs/api/module-lib_errors.ValidationError.html +3 -0
  142. package/docs/api/module-lib_errors.html +3 -0
  143. package/docs/api/module-lib_federation-methods.html +3 -0
  144. package/docs/api/module-lib_index.html +3 -0
  145. package/docs/api/module-schema_validator-ValidationError.html +3 -0
  146. package/docs/api/module-schema_validator.ValidationError.html +3 -0
  147. package/docs/api/module-schema_validator.html +3 -0
  148. package/docs/api/module-spatial_h3-operations.html +4 -0
  149. package/docs/api/module-storage_backend-factory.BackendFactory.html +3 -0
  150. package/docs/api/module-storage_backend-factory.html +3 -0
  151. package/docs/api/module-storage_backend-interface-StorageBackend.html +3 -0
  152. package/docs/api/module-storage_backend-interface.StorageBackend.html +3 -0
  153. package/docs/api/module-storage_backend-interface.html +3 -0
  154. package/docs/api/module-storage_backends_activitypub-backend-ActivityPubBackend.html +7 -0
  155. package/docs/api/module-storage_backends_activitypub-backend.ActivityPubBackend.html +3 -0
  156. package/docs/api/module-storage_backends_activitypub-backend.html +3 -0
  157. package/docs/api/module-storage_backends_activitypub_server-ActivityPubServer.html +8 -0
  158. package/docs/api/module-storage_backends_activitypub_server.ActivityPubServer.html +3 -0
  159. package/docs/api/module-storage_backends_activitypub_server.html +3 -0
  160. package/docs/api/module-storage_backends_gundb-backend-GunDBBackend.html +7 -0
  161. package/docs/api/module-storage_backends_gundb-backend.GunDBBackend.html +3 -0
  162. package/docs/api/module-storage_backends_gundb-backend.html +3 -0
  163. package/docs/api/module-storage_backends_nostr-backend-NostrBackend.html +8 -0
  164. package/docs/api/module-storage_backends_nostr-backend.NostrBackend.html +3 -0
  165. package/docs/api/module-storage_backends_nostr-backend.html +3 -0
  166. package/docs/api/module-storage_filesystem-storage-FileSystemStorage.html +5 -0
  167. package/docs/api/module-storage_filesystem-storage-browser-FileSystemStorage.html +3 -0
  168. package/docs/api/module-storage_filesystem-storage-browser.FileSystemStorage.html +3 -0
  169. package/docs/api/module-storage_filesystem-storage-browser.html +3 -0
  170. package/docs/api/module-storage_filesystem-storage.FileSystemStorage.html +3 -0
  171. package/docs/api/module-storage_filesystem-storage.html +3 -0
  172. package/docs/api/module-storage_global-tables.html +3 -0
  173. package/docs/api/module-storage_gun-async.html +3 -0
  174. package/docs/api/module-storage_gun-auth-GunAuth.html +5 -0
  175. package/docs/api/module-storage_gun-auth.GunAuth.html +3 -0
  176. package/docs/api/module-storage_gun-auth.html +3 -0
  177. package/docs/api/module-storage_gun-federation.html +3 -0
  178. package/docs/api/module-storage_gun-references-GunReferenceHandler.html +5 -0
  179. package/docs/api/module-storage_gun-references.GunReferenceHandler.html +3 -0
  180. package/docs/api/module-storage_gun-references.html +3 -0
  181. package/docs/api/module-storage_gun-schema-GunSchemaValidator.html +5 -0
  182. package/docs/api/module-storage_gun-schema.GunSchemaValidator.html +3 -0
  183. package/docs/api/module-storage_gun-schema.html +3 -0
  184. package/docs/api/module-storage_gun-wrapper.html +11 -0
  185. package/docs/api/module-storage_indexeddb-storage-IndexedDBStorage.html +5 -0
  186. package/docs/api/module-storage_indexeddb-storage.IndexedDBStorage.html +3 -0
  187. package/docs/api/module-storage_indexeddb-storage.html +3 -0
  188. package/docs/api/module-storage_key-storage-simple.html +3 -0
  189. package/docs/api/module-storage_key-storage.html +4 -0
  190. package/docs/api/module-storage_memory-storage-MemoryStorage.html +5 -0
  191. package/docs/api/module-storage_memory-storage.MemoryStorage.html +3 -0
  192. package/docs/api/module-storage_memory-storage.html +3 -0
  193. package/docs/api/module-storage_migration-MigrationTool.html +6 -0
  194. package/docs/api/module-storage_migration.MigrationTool.html +3 -0
  195. package/docs/api/module-storage_migration.html +3 -0
  196. package/docs/api/module-storage_nostr-async.html +18 -0
  197. package/docs/api/module-storage_nostr-client-LRUCache.html +3 -0
  198. package/docs/api/module-storage_nostr-client-NostrClient.html +7 -0
  199. package/docs/api/module-storage_nostr-client.NostrClient.html +15 -0
  200. package/docs/api/module-storage_nostr-client.html +6 -0
  201. package/docs/api/module-storage_nostr-wrapper.html +3 -0
  202. package/docs/api/module-storage_outbox-queue-OutboxQueue.html +4 -0
  203. package/docs/api/module-storage_outbox-queue.OutboxQueue.html +3 -0
  204. package/docs/api/module-storage_outbox-queue.html +3 -0
  205. package/docs/api/module-storage_persistent-storage-PersistentStorage.html +3 -0
  206. package/docs/api/module-storage_persistent-storage.html +4 -0
  207. package/docs/api/module-storage_sync-service-SyncService.html +5 -0
  208. package/docs/api/module-storage_sync-service.SyncService.html +3 -0
  209. package/docs/api/module-storage_sync-service.html +3 -0
  210. package/docs/api/module-storage_unified-storage.html +3 -0
  211. package/docs/api/module-subscriptions_manager.SubscriptionRegistry.html +3 -0
  212. package/docs/api/module-subscriptions_manager.html +3 -0
  213. package/docs/api/schema_validator.js.html +113 -0
  214. package/docs/api/scripts/core.js +726 -0
  215. package/docs/api/scripts/core.min.js +23 -0
  216. package/docs/api/scripts/resize.js +90 -0
  217. package/docs/api/scripts/search.js +265 -0
  218. package/docs/api/scripts/search.min.js +6 -0
  219. package/docs/api/scripts/third-party/Apache-License-2.0.txt +202 -0
  220. package/docs/api/scripts/third-party/fuse.js +9 -0
  221. package/docs/api/scripts/third-party/hljs-line-num-original.js +369 -0
  222. package/docs/api/scripts/third-party/hljs-line-num.js +1 -0
  223. package/docs/api/scripts/third-party/hljs-original.js +5171 -0
  224. package/docs/api/scripts/third-party/hljs.js +1 -0
  225. package/docs/api/scripts/third-party/popper.js +5 -0
  226. package/docs/api/scripts/third-party/tippy.js +1 -0
  227. package/docs/api/scripts/third-party/tocbot.js +672 -0
  228. package/docs/api/scripts/third-party/tocbot.min.js +1 -0
  229. package/docs/api/spatial_h3-operations.js.html +129 -0
  230. package/docs/api/storage_backend-factory.js.html +133 -0
  231. package/docs/api/storage_backend-interface.js.html +164 -0
  232. package/docs/api/storage_backends_activitypub-backend.js.html +298 -0
  233. package/docs/api/storage_backends_activitypub_server.js.html +678 -0
  234. package/docs/api/storage_backends_gundb-backend.js.html +878 -0
  235. package/docs/api/storage_backends_nostr-backend.js.html +254 -0
  236. package/docs/api/storage_filesystem-storage-browser.js.html +83 -0
  237. package/docs/api/storage_filesystem-storage.js.html +207 -0
  238. package/docs/api/storage_global-tables.js.html +116 -0
  239. package/docs/api/storage_gun-async.js.html +344 -0
  240. package/docs/api/storage_gun-auth.js.html +376 -0
  241. package/docs/api/storage_gun-federation.js.html +788 -0
  242. package/docs/api/storage_gun-references.js.html +212 -0
  243. package/docs/api/storage_gun-schema.js.html +309 -0
  244. package/docs/api/storage_gun-wrapper.js.html +645 -0
  245. package/docs/api/storage_indexeddb-storage.js.html +224 -0
  246. package/docs/api/storage_key-storage-simple.js.html +102 -0
  247. package/docs/api/storage_key-storage.js.html +171 -0
  248. package/docs/api/storage_memory-storage.js.html +128 -0
  249. package/docs/api/storage_migration.js.html +354 -0
  250. package/docs/api/storage_nostr-async.js.html +1076 -0
  251. package/docs/api/storage_nostr-client.js.html +1598 -0
  252. package/docs/api/storage_nostr-wrapper.js.html +218 -0
  253. package/docs/api/storage_outbox-queue.js.html +248 -0
  254. package/docs/api/storage_persistent-storage.js.html +160 -0
  255. package/docs/api/storage_sync-service.js.html +201 -0
  256. package/docs/api/storage_unified-storage.js.html +157 -0
  257. package/docs/api/styles/clean-jsdoc-theme-base.css +1159 -0
  258. package/docs/api/styles/clean-jsdoc-theme-dark.css +412 -0
  259. package/docs/api/styles/clean-jsdoc-theme-light.css +482 -0
  260. package/docs/api/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  261. package/docs/api/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  262. package/docs/api/styles/clean-jsdoc-theme.min.css +1 -0
  263. package/docs/api/subscriptions_manager.js.html +162 -0
  264. package/docs/contracts/api-interface.md +793 -0
  265. package/docs/data-model.md +476 -0
  266. package/docs/gun-async-usage.md +338 -0
  267. package/docs/plan.md +349 -0
  268. package/docs/quickstart.md +674 -0
  269. package/docs/research.md +362 -0
  270. package/docs/spec.md +244 -0
  271. package/docs/storage-backends.md +326 -0
  272. package/docs/tasks.md +947 -0
  273. package/examples/demo.html +47 -0
  274. package/examples/holosphere-widget.js +1242 -0
  275. package/examples/widget-demo.html +274 -0
  276. package/examples/widget.html +703 -0
  277. package/jsdoc.json +26 -0
  278. package/package.json +25 -7
  279. package/src/ai/aggregation.js +13 -2
  280. package/src/ai/breakdown.js +12 -2
  281. package/src/ai/classifier.js +14 -3
  282. package/src/ai/council.js +22 -7
  283. package/src/ai/embeddings.js +37 -15
  284. package/src/ai/federation-ai.js +13 -2
  285. package/src/ai/h3-ai.js +14 -2
  286. package/src/ai/index.js +16 -7
  287. package/src/ai/json-ops.js +18 -5
  288. package/src/ai/llm-service.js +62 -31
  289. package/src/ai/nl-query.js +12 -2
  290. package/src/ai/relationships.js +13 -2
  291. package/src/ai/schema-extractor.js +24 -10
  292. package/src/ai/spatial.js +13 -2
  293. package/src/ai/tts.js +25 -8
  294. package/src/cdn-entry.js +22 -0
  295. package/src/content/social-protocols.js +34 -25
  296. package/src/contracts/abis/Appreciative.json +1280 -0
  297. package/src/contracts/abis/AppreciativeFactory.json +101 -0
  298. package/src/contracts/abis/Bundle.json +1438 -0
  299. package/src/contracts/abis/BundleFactory.json +106 -0
  300. package/src/contracts/abis/Holon.json +881 -0
  301. package/src/contracts/abis/Holons.json +330 -0
  302. package/src/contracts/abis/Managed.json +1262 -0
  303. package/src/contracts/abis/ManagedFactory.json +149 -0
  304. package/src/contracts/abis/Membrane.json +261 -0
  305. package/src/contracts/abis/Splitter.json +1624 -0
  306. package/src/contracts/abis/SplitterFactory.json +220 -0
  307. package/src/contracts/abis/TestToken.json +321 -0
  308. package/src/contracts/abis/Zoned.json +1461 -0
  309. package/src/contracts/abis/ZonedFactory.json +154 -0
  310. package/src/contracts/chain-manager.js +403 -0
  311. package/src/contracts/deployer.js +500 -0
  312. package/src/contracts/event-listener.js +539 -0
  313. package/src/contracts/holon-contracts.js +359 -0
  314. package/src/contracts/index.js +82 -0
  315. package/src/contracts/networks.js +229 -0
  316. package/src/contracts/operations.js +687 -0
  317. package/src/contracts/queries.js +638 -0
  318. package/src/core/holosphere.js +487 -6
  319. package/src/crypto/nostr-utils.js +303 -0
  320. package/src/crypto/secp256k1.js +7 -2
  321. package/src/federation/handshake.js +475 -0
  322. package/src/federation/hologram.js +117 -3
  323. package/src/hierarchical/upcast.js +40 -25
  324. package/src/index.js +1501 -1909
  325. package/src/lib/ai-methods.js +657 -0
  326. package/src/lib/contract-methods.js +442 -0
  327. package/src/lib/errors.js +53 -0
  328. package/src/lib/federation-methods.js +345 -0
  329. package/src/lib/index.js +30 -0
  330. package/src/schema/validator.js +22 -3
  331. package/src/spatial/h3-operations.js +19 -3
  332. package/src/storage/backend-factory.js +7 -2
  333. package/src/storage/backend-interface.js +21 -2
  334. package/src/storage/backends/activitypub/server.js +25 -3
  335. package/src/storage/backends/activitypub-backend.js +25 -2
  336. package/src/storage/backends/gundb-backend.js +692 -50
  337. package/src/storage/backends/nostr-backend.js +116 -1
  338. package/src/storage/filesystem-storage-browser.js +42 -2
  339. package/src/storage/filesystem-storage.js +72 -5
  340. package/src/storage/global-tables.js +35 -3
  341. package/src/storage/gun-async.js +75 -15
  342. package/src/storage/gun-auth.js +373 -0
  343. package/src/storage/gun-federation.js +785 -0
  344. package/src/storage/gun-references.js +209 -0
  345. package/src/storage/gun-schema.js +306 -0
  346. package/src/storage/gun-wrapper.js +475 -54
  347. package/src/storage/indexeddb-storage.js +112 -13
  348. package/src/storage/key-storage-simple.js +32 -9
  349. package/src/storage/key-storage.js +45 -13
  350. package/src/storage/memory-storage.js +68 -2
  351. package/src/storage/migration.js +20 -7
  352. package/src/storage/nostr-async.js +412 -122
  353. package/src/storage/nostr-client.js +749 -76
  354. package/src/storage/nostr-wrapper.js +6 -2
  355. package/src/storage/outbox-queue.js +55 -18
  356. package/src/storage/persistent-storage.js +62 -14
  357. package/src/storage/sync-service.js +51 -17
  358. package/src/storage/unified-storage.js +154 -0
  359. package/src/subscriptions/manager.js +34 -17
  360. package/types/index.d.ts +133 -0
  361. package/vite.config.cdn.js +60 -0
  362. package/tests/unit/ai/aggregation.test.js +0 -295
  363. package/tests/unit/ai/breakdown.test.js +0 -446
  364. package/tests/unit/ai/classifier.test.js +0 -294
  365. package/tests/unit/ai/council.test.js +0 -262
  366. package/tests/unit/ai/embeddings.test.js +0 -384
  367. package/tests/unit/ai/federation-ai.test.js +0 -344
  368. package/tests/unit/ai/h3-ai.test.js +0 -458
  369. package/tests/unit/ai/index.test.js +0 -304
  370. package/tests/unit/ai/json-ops.test.js +0 -307
  371. package/tests/unit/ai/llm-service.test.js +0 -390
  372. package/tests/unit/ai/nl-query.test.js +0 -383
  373. package/tests/unit/ai/relationships.test.js +0 -311
  374. package/tests/unit/ai/schema-extractor.test.js +0 -384
  375. package/tests/unit/ai/spatial.test.js +0 -279
  376. package/tests/unit/ai/tts.test.js +0 -279
  377. package/tests/unit/content.test.js +0 -332
  378. package/tests/unit/contract/core.test.js +0 -88
  379. package/tests/unit/contract/crypto.test.js +0 -198
  380. package/tests/unit/contract/data.test.js +0 -223
  381. package/tests/unit/contract/federation.test.js +0 -181
  382. package/tests/unit/contract/hierarchical.test.js +0 -113
  383. package/tests/unit/contract/schema.test.js +0 -114
  384. package/tests/unit/contract/social.test.js +0 -217
  385. package/tests/unit/contract/spatial.test.js +0 -110
  386. package/tests/unit/contract/subscriptions.test.js +0 -128
  387. package/tests/unit/contract/utils.test.js +0 -159
  388. package/tests/unit/core.test.js +0 -152
  389. package/tests/unit/crypto.test.js +0 -328
  390. package/tests/unit/federation.test.js +0 -234
  391. package/tests/unit/gun-async.test.js +0 -252
  392. package/tests/unit/hierarchical.test.js +0 -399
  393. package/tests/unit/integration/scenario-01-geographic-storage.test.js +0 -74
  394. package/tests/unit/integration/scenario-02-federation.test.js +0 -76
  395. package/tests/unit/integration/scenario-03-subscriptions.test.js +0 -102
  396. package/tests/unit/integration/scenario-04-validation.test.js +0 -129
  397. package/tests/unit/integration/scenario-05-hierarchy.test.js +0 -125
  398. package/tests/unit/integration/scenario-06-social.test.js +0 -135
  399. package/tests/unit/integration/scenario-07-persistence.test.js +0 -130
  400. package/tests/unit/integration/scenario-08-authorization.test.js +0 -161
  401. package/tests/unit/integration/scenario-09-cross-dimensional.test.js +0 -139
  402. package/tests/unit/integration/scenario-10-cross-holosphere-capabilities.test.js +0 -357
  403. package/tests/unit/integration/scenario-11-cross-holosphere-federation.test.js +0 -410
  404. package/tests/unit/integration/scenario-12-capability-federated-read.test.js +0 -719
  405. package/tests/unit/performance/benchmark.test.js +0 -85
  406. package/tests/unit/schema.test.js +0 -213
  407. package/tests/unit/spatial.test.js +0 -158
  408. package/tests/unit/storage.test.js +0 -195
  409. package/tests/unit/subscriptions.test.js +0 -328
  410. package/tests/unit/test-data-permanence-debug.js +0 -197
  411. package/tests/unit/test-data-permanence.js +0 -340
  412. package/tests/unit/test-key-persistence-fixed.js +0 -148
  413. package/tests/unit/test-key-persistence.js +0 -172
  414. package/tests/unit/test-relay-permanence.js +0 -376
  415. package/tests/unit/test-second-node.js +0 -95
  416. package/tests/unit/test-simple-write.js +0 -89
  417. /package/{cleanup-test-data.js → scripts/cleanup-test-data.js} +0 -0
  418. /package/{test-ai-real-api.js → scripts/test-ai-real-api.js} +0 -0
@@ -0,0 +1,55 @@
1
+ var __defProp=Object.defineProperty,__typeError=e=>{throw TypeError(e)},__defNormalProp=(e,t,n)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,__publicField=(e,t,n)=>__defNormalProp(e,"symbol"!=typeof t?t+"":t,n),__accessCheck=(e,t,n)=>t.has(e)||__typeError("Cannot "+n),__privateGet=(e,t,n)=>(__accessCheck(e,t,"read from private field"),n?n.call(e):t.get(e)),__privateAdd=(e,t,n)=>t.has(e)?__typeError("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),__privateSet=(e,t,n,r)=>(__accessCheck(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),__privateMethod=(e,t,n)=>(__accessCheck(e,t,"access private method"),n),__privateWrapper=(e,t,n,r)=>({set _(r){__privateSet(e,t,r,n)},get _(){return __privateGet(e,t,r)}});this.HoloSphere=function(){"use strict";var e,t,n,r,i,s,a,o,c,A,l,f,u,d,h,p,m,y,g,b,w,v,_,E,k,T,S,x,I,P,C,N,O,R,B,M,$,D,F,G,U,L,j,H,z,q,Q,V,J,K,W,Y,Z,X,ee,te,ne,re,ie,se,ae,oe,ce,Ae,le,fe,ue,de,he,pe,me,ye,ge,be,we,ve,_e,Ee,ke,Te,Se,xe,Ie,Pe,Ce,Ne,Oe,Re,Be,Me,$e,De,Fe,Ge,Ue,Le,je,He,ze,qe,Qe,Ve,Je,Ke,We,Ye,Ze,Xe,et,tt,nt,rt,it,st,at,ot,ct,At,lt,ft,ut,dt,ht,pt,mt,yt,gt,bt,wt,vt,_t,Et,kt,Tt,St,xt,It,Pt,Ct,Nt,Ot,Rt,Bt,Mt,$t,Dt,Ft,Gt,Ut,Lt,jt,Ht,zt,qt,Qt,Vt,Jt,Kt,Wt,Yt,Zt,Xt,en,tn,nn,rn,sn,an,on,cn,An,ln,fn,un,dn,hn,pn,mn,yn,gn,bn,wn,vn,_n,En,kn,Tn,Sn,xn,In,Pn,Cn,Nn,On,Rn,Bn,Mn,$n,Dn,Fn,Gn,Un,Ln,jn,Hn,zn,qn,Qn,Vn,Jn,Kn,Wn,Yn,Zn,Xn;function er(e,t){for(var n=0;n<t.length;n++){const r=t[n];if("string"!=typeof r&&!Array.isArray(r))for(const t in r)if("default"!==t&&!(t in e)){const n=Object.getOwnPropertyDescriptor(r,t);n&&Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>r[t]})}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}function tr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function nr(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function rr(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}const ir="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,sr=e=>e instanceof Uint8Array,ar=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),or=(e,t)=>e<<32-t|e>>>t;
2
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw new Error("Non little-endian hardware is not supported");function cr(e){if("string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),!sr(e))throw new Error("expected Uint8Array, got "+typeof e);return e}let Ar=class{clone(){return this._cloneInto()}};function lr(e){const t=t=>e().update(cr(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function fr(e=32){if(ir&&"function"==typeof ir.getRandomValues)return ir.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}let ur=class extends Ar{constructor(e,t,n,r){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=ar(this.buffer)}update(e){rr(this);const{view:t,buffer:n,blockLen:r}=this,i=(e=cr(e)).length;for(let s=0;s<i;){const a=Math.min(r-this.pos,i-s);if(a===r){const t=ar(e);for(;r<=i-s;s+=r)this.process(t,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){rr(this),function(e,t){nr(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:i}=this;let{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>r-s&&(this.process(n,0),s=0);for(let l=s;l<r;l++)t[l]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const i=BigInt(32),s=BigInt(4294967295),a=Number(n>>i&s),o=Number(n&s),c=r?4:0,A=r?0:4;e.setUint32(t+c,a,r),e.setUint32(t+A,o,r)}(n,r-8,BigInt(8*this.length),i),this.process(n,0);const a=ar(e),o=this.outputLen;if(o%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=o/4,A=this.get();if(c>A.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<c;l++)a.setUint32(4*l,A[l],i)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:i,destroyed:s,pos:a}=this;return e.length=r,e.pos=a,e.finished=i,e.destroyed=s,r%t&&e.buffer.set(n),e}};const dr=(e,t,n)=>e&t^~e&n,hr=(e,t,n)=>e&t^e&n^t&n,pr=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),mr=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),yr=new Uint32Array(64);let gr=class extends ur{constructor(){super(64,32,8,!1),this.A=0|mr[0],this.B=0|mr[1],this.C=0|mr[2],this.D=0|mr[3],this.E=0|mr[4],this.F=0|mr[5],this.G=0|mr[6],this.H=0|mr[7]}get(){const{A:e,B:t,C:n,D:r,E:i,F:s,G:a,H:o}=this;return[e,t,n,r,i,s,a,o]}set(e,t,n,r,i,s,a,o){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|s,this.G=0|a,this.H=0|o}process(e,t){for(let l=0;l<16;l++,t+=4)yr[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){const e=yr[l-15],t=yr[l-2],n=or(e,7)^or(e,18)^e>>>3,r=or(t,17)^or(t,19)^t>>>10;yr[l]=r+yr[l-7]+n+yr[l-16]|0}let{A:n,B:r,C:i,D:s,E:a,F:o,G:c,H:A}=this;for(let l=0;l<64;l++){const e=A+(or(a,6)^or(a,11)^or(a,25))+dr(a,o,c)+pr[l]+yr[l]|0,t=(or(n,2)^or(n,13)^or(n,22))+hr(n,r,i)|0;A=c,c=o,o=a,a=s+e|0,s=i,i=r,r=n,n=e+t|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,o=o+this.F|0,c=c+this.G|0,A=A+this.H|0,this.set(n,r,i,s,a,o,c,A)}roundClean(){yr.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const br=lr(()=>new gr),wr=BigInt(0),vr=BigInt(1),_r=BigInt(2),Er=e=>e instanceof Uint8Array,kr=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));
3
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Tr(e){if(!Er(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=kr[e[n]];return t}function Sr(e){const t=e.toString(16);return 1&t.length?`0${t}`:t}function xr(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return BigInt(""===e?"0":`0x${e}`)}function Ir(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let r=0;r<n.length;r++){const t=2*r,i=e.slice(t,t+2),s=Number.parseInt(i,16);if(Number.isNaN(s)||s<0)throw new Error("Invalid byte sequence");n[r]=s}return n}function Pr(e){return xr(Tr(e))}function Cr(e){if(!Er(e))throw new Error("Uint8Array expected");return xr(Tr(Uint8Array.from(e).reverse()))}function Nr(e,t){return Ir(e.toString(16).padStart(2*t,"0"))}function Or(e,t){return Nr(e,t).reverse()}function Rr(e,t,n){let r;if("string"==typeof t)try{r=Ir(t)}catch(s){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${s}`)}else{if(!Er(t))throw new Error(`${e} must be hex string or Uint8Array`);r=Uint8Array.from(t)}const i=r.length;if("number"==typeof n&&i!==n)throw new Error(`${e} expected ${n} bytes, got ${i}`);return r}function Br(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!Er(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}const Mr=e=>(_r<<BigInt(e-1))-vr,$r=e=>new Uint8Array(e),Dr=e=>Uint8Array.from(e);function Fr(e,t,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");let r=$r(e),i=$r(e),s=0;const a=()=>{r.fill(1),i.fill(0),s=0},o=(...e)=>n(i,r,...e),c=(e=$r())=>{i=o(Dr([0]),e),r=o(),0!==e.length&&(i=o(Dr([1]),e),r=o())},A=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){r=o();const t=r.slice();n.push(t),e+=r.length}return Br(...n)};return(e,t)=>{let n;for(a(),c(e);!(n=t(A()));)c();return a(),n}}const Gr={bigint:e=>"bigint"==typeof e,function:e=>"function"==typeof e,boolean:e=>"boolean"==typeof e,string:e=>"string"==typeof e,stringOrUint8Array:e=>"string"==typeof e||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>"function"==typeof e&&Number.isSafeInteger(e.outputLen)};function Ur(e,t,n={}){const r=(t,n,r)=>{const i=Gr[n];if("function"!=typeof i)throw new Error(`Invalid validator "${n}", expected function`);const s=e[t];if(!(r&&void 0===s||i(s,e)))throw new Error(`Invalid param ${String(t)}=${s} (${typeof s}), expected ${n}`)};for(const[i,s]of Object.entries(t))r(i,s,!1);for(const[i,s]of Object.entries(n))r(i,s,!0);return e}const Lr=Object.freeze(Object.defineProperty({__proto__:null,bitGet:function(e,t){return e>>BigInt(t)&vr},bitLen:function(e){let t;for(t=0;e>wr;e>>=vr,t+=1);return t},bitMask:Mr,bitSet:(e,t,n)=>e|(n?vr:wr)<<BigInt(t),bytesToHex:Tr,bytesToNumberBE:Pr,bytesToNumberLE:Cr,concatBytes:Br,createHmacDrbg:Fr,ensureBytes:Rr,equalBytes: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},hexToBytes:Ir,hexToNumber:xr,numberToBytesBE:Nr,numberToBytesLE:Or,numberToHexUnpadded:Sr,numberToVarBytesBE:function(e){return Ir(Sr(e))},utf8ToBytes:function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))},validateObject:Ur},Symbol.toStringTag,{value:"Module"})),jr=BigInt(0),Hr=BigInt(1),zr=BigInt(2),qr=BigInt(3),Qr=BigInt(4),Vr=BigInt(5),Jr=BigInt(8);
4
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Kr(e,t){const n=e%t;return n>=jr?n:t+n}function Wr(e,t,n){if(n<=jr||t<jr)throw new Error("Expected power/modulo > 0");if(n===Hr)return jr;let r=Hr;for(;t>jr;)t&Hr&&(r=r*e%n),e=e*e%n,t>>=Hr;return r}function Yr(e,t,n){let r=e;for(;t-- >jr;)r*=r,r%=n;return r}function Zr(e,t){if(e===jr||t<=jr)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=Kr(e,t),r=t,i=jr,s=Hr;for(;n!==jr;){const e=r%n,t=i-s*(r/n);r=n,n=e,i=s,s=t}if(r!==Hr)throw new Error("invert: does not exist");return Kr(i,t)}BigInt(9),BigInt(16);const Xr=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ei(e,t){const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function ti(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function ni(e){const t=ti(e);return t+Math.ceil(t/2)}
5
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
6
+ const ri=BigInt(0),ii=BigInt(1);function si(e){return Ur(e.Fp,Xr.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"})),Ur(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ei(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}
7
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const{bytesToNumberBE:ai,hexToBytes:oi}=Lr,ci={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(e){const{Err:t}=ci;if(e.length<2||2!==e[0])throw new t("Invalid signature integer tag");const n=e[1],r=e.subarray(2,n+2);if(!n||r.length!==n)throw new t("Invalid signature integer: wrong length");if(128&r[0])throw new t("Invalid signature integer: negative");if(0===r[0]&&!(128&r[1]))throw new t("Invalid signature integer: unnecessary leading zero");return{d:ai(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=ci,n="string"==typeof e?oi(e):e;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||48!=n[0])throw new t("Invalid signature tag");if(n[1]!==r-2)throw new t("Invalid signature: incorrect length");const{d:i,l:s}=ci._parseInt(n.subarray(2)),{d:a,l:o}=ci._parseInt(s);if(o.length)throw new t("Invalid signature: left bytes after parsing");return{r:i,s:a}},hexFromSig(e){const t=e=>8&Number.parseInt(e[0],16)?"00"+e:e,n=e=>{const t=e.toString(16);return 1&t.length?`0${t}`:t},r=t(n(e.s)),i=t(n(e.r)),s=r.length/2,a=i.length/2,o=n(s),c=n(a);return`30${n(a+s+4)}02${c}${i}02${o}${r}`}},Ai=BigInt(0),li=BigInt(1);BigInt(2);const fi=BigInt(3);function ui(e){const t=function(e){const t=si(e);return Ur(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}(e),{Fp:n,n:r}=t,i=n.BYTES+1,s=2*n.BYTES+1;function a(e){return Kr(e,r)}function o(e){return Zr(e,r)}const{ProjectivePoint:c,normPrivateKeyToScalar:A,weierstrassEquation:l,isWithinCurveOrder:f}=function(e){const t=function(e){const t=si(e);Ur(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:i}=t;if(n){if(!r.eql(i,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if("object"!=typeof n||"bigint"!=typeof n.beta||"function"!=typeof n.splitScalar)throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}(e),{Fp:n}=t,r=t.toBytes||((e,t,r)=>{const i=t.toAffine();return Br(Uint8Array.from([4]),n.toBytes(i.x),n.toBytes(i.y))}),i=t.fromBytes||(e=>{const t=e.subarray(1);return{x:n.fromBytes(t.subarray(0,n.BYTES)),y:n.fromBytes(t.subarray(n.BYTES,2*n.BYTES))}});function s(e){const{a:r,b:i}=t,s=n.sqr(e),a=n.mul(s,e);return n.add(n.add(a,n.mul(e,r)),i)}if(!n.eql(n.sqr(t.Gy),s(t.Gx)))throw new Error("bad generator point: equation left != right");function a(e){return"bigint"==typeof e&&Ai<e&&e<t.n}function o(e){if(!a(e))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(e){const{allowedPrivateKeyLengths:n,nByteLength:r,wrapPrivateKey:i,n:s}=t;if(n&&"bigint"!=typeof e){if(e instanceof Uint8Array&&(e=Tr(e)),"string"!=typeof e||!n.includes(e.length))throw new Error("Invalid key");e=e.padStart(2*r,"0")}let a;try{a="bigint"==typeof e?e:Pr(Rr("private key",e,r))}catch(c){throw new Error(`private key must be ${r} bytes, hex or bigint, not ${typeof e}`)}return i&&(a=Kr(a,s)),o(a),a}const A=new Map;function l(e){if(!(e instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(e,t,r){if(this.px=e,this.py=t,this.pz=r,null==e||!n.isValid(e))throw new Error("x required");if(null==t||!n.isValid(t))throw new Error("y required");if(null==r||!n.isValid(r))throw new Error("z required")}static fromAffine(e){const{x:t,y:r}=e||{};if(!e||!n.isValid(t)||!n.isValid(r))throw new Error("invalid affine point");if(e instanceof f)throw new Error("projective point not allowed");const i=e=>n.eql(e,n.ZERO);return i(t)&&i(r)?f.ZERO:new f(t,r,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(e){const t=n.invertBatch(e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(f.fromAffine)}static fromHex(e){const t=f.fromAffine(i(Rr("pointHex",e)));return t.assertValidity(),t}static fromPrivateKey(e){return f.BASE.multiply(c(e))}_setWindowSize(e){this._WINDOW_SIZE=e,A.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:e,y:r}=this.toAffine();if(!n.isValid(e)||!n.isValid(r))throw new Error("bad point: x or y not FE");const i=n.sqr(r),a=s(e);if(!n.eql(i,a))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:e}=this.toAffine();if(n.isOdd)return!n.isOdd(e);throw new Error("Field doesn't support isOdd")}equals(e){l(e);const{px:t,py:r,pz:i}=this,{px:s,py:a,pz:o}=e,c=n.eql(n.mul(t,o),n.mul(s,i)),A=n.eql(n.mul(r,o),n.mul(a,i));return c&&A}negate(){return new f(this.px,n.neg(this.py),this.pz)}double(){const{a:e,b:r}=t,i=n.mul(r,fi),{px:s,py:a,pz:o}=this;let c=n.ZERO,A=n.ZERO,l=n.ZERO,u=n.mul(s,s),d=n.mul(a,a),h=n.mul(o,o),p=n.mul(s,a);return p=n.add(p,p),l=n.mul(s,o),l=n.add(l,l),c=n.mul(e,l),A=n.mul(i,h),A=n.add(c,A),c=n.sub(d,A),A=n.add(d,A),A=n.mul(c,A),c=n.mul(p,c),l=n.mul(i,l),h=n.mul(e,h),p=n.sub(u,h),p=n.mul(e,p),p=n.add(p,l),l=n.add(u,u),u=n.add(l,u),u=n.add(u,h),u=n.mul(u,p),A=n.add(A,u),h=n.mul(a,o),h=n.add(h,h),u=n.mul(h,p),c=n.sub(c,u),l=n.mul(h,d),l=n.add(l,l),l=n.add(l,l),new f(c,A,l)}add(e){l(e);const{px:r,py:i,pz:s}=this,{px:a,py:o,pz:c}=e;let A=n.ZERO,u=n.ZERO,d=n.ZERO;const h=t.a,p=n.mul(t.b,fi);let m=n.mul(r,a),y=n.mul(i,o),g=n.mul(s,c),b=n.add(r,i),w=n.add(a,o);b=n.mul(b,w),w=n.add(m,y),b=n.sub(b,w),w=n.add(r,s);let v=n.add(a,c);return w=n.mul(w,v),v=n.add(m,g),w=n.sub(w,v),v=n.add(i,s),A=n.add(o,c),v=n.mul(v,A),A=n.add(y,g),v=n.sub(v,A),d=n.mul(h,w),A=n.mul(p,g),d=n.add(A,d),A=n.sub(y,d),d=n.add(y,d),u=n.mul(A,d),y=n.add(m,m),y=n.add(y,m),g=n.mul(h,g),w=n.mul(p,w),y=n.add(y,g),g=n.sub(m,g),g=n.mul(h,g),w=n.add(w,g),m=n.mul(y,w),u=n.add(u,m),m=n.mul(v,w),A=n.mul(b,A),A=n.sub(A,m),m=n.mul(b,y),d=n.mul(v,d),d=n.add(d,m),new f(A,u,d)}subtract(e){return this.add(e.negate())}is0(){return this.equals(f.ZERO)}wNAF(e){return d.wNAFCached(this,A,e,e=>{const t=n.invertBatch(e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(f.fromAffine)})}multiplyUnsafe(e){const r=f.ZERO;if(e===Ai)return r;if(o(e),e===li)return this;const{endo:i}=t;if(!i)return d.unsafeLadder(this,e);let{k1neg:s,k1:a,k2neg:c,k2:A}=i.splitScalar(e),l=r,u=r,h=this;for(;a>Ai||A>Ai;)a&li&&(l=l.add(h)),A&li&&(u=u.add(h)),h=h.double(),a>>=li,A>>=li;return s&&(l=l.negate()),c&&(u=u.negate()),u=new f(n.mul(u.px,i.beta),u.py,u.pz),l.add(u)}multiply(e){o(e);let r,i,s=e;const{endo:a}=t;if(a){const{k1neg:e,k1:t,k2neg:o,k2:c}=a.splitScalar(s);let{p:A,f:l}=this.wNAF(t),{p:u,f:h}=this.wNAF(c);A=d.constTimeNegate(e,A),u=d.constTimeNegate(o,u),u=new f(n.mul(u.px,a.beta),u.py,u.pz),r=A.add(u),i=l.add(h)}else{const{p:e,f:t}=this.wNAF(s);r=e,i=t}return f.normalizeZ([r,i])[0]}multiplyAndAddUnsafe(e,t,n){const r=f.BASE,i=(e,t)=>t!==Ai&&t!==li&&e.equals(r)?e.multiply(t):e.multiplyUnsafe(t),s=i(this,t).add(i(e,n));return s.is0()?void 0:s}toAffine(e){const{px:t,py:r,pz:i}=this,s=this.is0();null==e&&(e=s?n.ONE:n.inv(i));const a=n.mul(t,e),o=n.mul(r,e),c=n.mul(i,e);if(s)return{x:n.ZERO,y:n.ZERO};if(!n.eql(c,n.ONE))throw new Error("invZ was invalid");return{x:a,y:o}}isTorsionFree(){const{h:e,isTorsionFree:n}=t;if(e===li)return!0;if(n)return n(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:e,clearCofactor:n}=t;return e===li?this:n?n(f,this):this.multiplyUnsafe(t.h)}toRawBytes(e=!0){return this.assertValidity(),r(f,this,e)}toHex(e=!0){return Tr(this.toRawBytes(e))}}f.BASE=new f(t.Gx,t.Gy,n.ONE),f.ZERO=new f(n.ZERO,n.ONE,n.ZERO);const u=t.nBitLength,d=function(e,t){const n=(e,t)=>{const n=t.negate();return e?n:t},r=e=>({windows:Math.ceil(t/e)+1,windowSize:2**(e-1)});return{constTimeNegate:n,unsafeLadder(t,n){let r=e.ZERO,i=t;for(;n>ri;)n&ii&&(r=r.add(i)),i=i.double(),n>>=ii;return r},precomputeWindow(e,t){const{windows:n,windowSize:i}=r(t),s=[];let a=e,o=a;for(let r=0;r<n;r++){o=a,s.push(o);for(let e=1;e<i;e++)o=o.add(a),s.push(o);a=o.double()}return s},wNAF(t,i,s){const{windows:a,windowSize:o}=r(t);let c=e.ZERO,A=e.BASE;const l=BigInt(2**t-1),f=2**t,u=BigInt(t);for(let e=0;e<a;e++){const t=e*o;let r=Number(s&l);s>>=u,r>o&&(r-=f,s+=ii);const a=t,d=t+Math.abs(r)-1,h=e%2!=0,p=r<0;0===r?A=A.add(n(h,i[a])):c=c.add(n(p,i[d]))}return{p:c,f:A}},wNAFCached(e,t,n,r){const i=e._WINDOW_SIZE||1;let s=t.get(e);return s||(s=this.precomputeWindow(e,i),1!==i&&t.set(e,r(s))),this.wNAF(i,s,n)}}}(f,t.endo?Math.ceil(u/2):u);return{CURVE:t,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:s,isWithinCurveOrder:a}}({...t,toBytes(e,t,r){const i=t.toAffine(),s=n.toBytes(i.x),a=Br;return r?a(Uint8Array.from([t.hasEvenY()?2:3]),s):a(Uint8Array.from([4]),s,n.toBytes(i.y))},fromBytes(e){const t=e.length,r=e[0],a=e.subarray(1);if(t!==i||2!==r&&3!==r){if(t===s&&4===r)return{x:n.fromBytes(a.subarray(0,n.BYTES)),y:n.fromBytes(a.subarray(n.BYTES,2*n.BYTES))};throw new Error(`Point of length ${t} was invalid. Expected ${i} compressed bytes or ${s} uncompressed bytes`)}{const e=Pr(a);if(!(Ai<(o=e)&&o<n.ORDER))throw new Error("Point is not on curve");const t=l(e);let i=n.sqrt(t);return!(1&~r)!=((i&li)===li)&&(i=n.neg(i)),{x:e,y:i}}var o}}),u=e=>Tr(Nr(e,t.nByteLength));function d(e){return e>r>>li}const h=(e,t,n)=>Pr(e.slice(t,n));class p{constructor(e,t,n){this.r=e,this.s=t,this.recovery=n,this.assertValidity()}static fromCompact(e){const n=t.nByteLength;return e=Rr("compactSignature",e,2*n),new p(h(e,0,n),h(e,n,2*n))}static fromDER(e){const{r:t,s:n}=ci.toSig(Rr("DER",e));return new p(t,n)}assertValidity(){if(!f(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!f(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(e){return new p(this.r,this.s,e)}recoverPublicKey(e){const{r:r,s:i,recovery:s}=this,A=b(Rr("msgHash",e));if(null==s||![0,1,2,3].includes(s))throw new Error("recovery id invalid");const l=2===s||3===s?r+t.n:r;if(l>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const f=1&s?"03":"02",d=c.fromHex(f+u(l)),h=o(l),p=a(-A*h),m=a(i*h),y=c.BASE.multiplyAndAddUnsafe(d,p,m);if(!y)throw new Error("point at infinify");return y.assertValidity(),y}hasHighS(){return d(this.s)}normalizeS(){return this.hasHighS()?new p(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Ir(this.toDERHex())}toDERHex(){return ci.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ir(this.toCompactHex())}toCompactHex(){return u(this.r)+u(this.s)}}const m={isValidPrivateKey(e){try{return A(e),!0}catch(t){return!1}},normPrivateKeyToScalar:A,randomPrivateKey:()=>{const e=ni(t.n);return function(e,t,n=!1){const r=e.length,i=ti(t),s=ni(t);if(r<16||r<s||r>1024)throw new Error(`expected ${s}-1024 bytes of input, got ${r}`);const a=Kr(n?Pr(e):Cr(e),t-Hr)+Hr;return n?Or(a,i):Nr(a,i)}(t.randomBytes(e),t.n)},precompute:(e=8,t=c.BASE)=>(t._setWindowSize(e),t.multiply(BigInt(3)),t)};function y(e){const t=e instanceof Uint8Array,n="string"==typeof e,r=(t||n)&&e.length;return t?r===i||r===s:n?r===2*i||r===2*s:e instanceof c}const g=t.bits2int||function(e){const n=Pr(e),r=8*e.length-t.nBitLength;return r>0?n>>BigInt(r):n},b=t.bits2int_modN||function(e){return a(g(e))},w=Mr(t.nBitLength);function v(e){if("bigint"!=typeof e)throw new Error("bigint expected");if(!(Ai<=e&&e<w))throw new Error(`bigint expected < 2^${t.nBitLength}`);return Nr(e,t.nByteLength)}const _={lowS:t.lowS,prehash:!1},E={lowS:t.lowS,prehash:!1};return c.BASE._setWindowSize(8),{CURVE:t,getPublicKey:function(e,t=!0){return c.fromPrivateKey(e).toRawBytes(t)},getSharedSecret:function(e,t,n=!0){if(y(e))throw new Error("first arg must be private key");if(!y(t))throw new Error("second arg must be public key");return c.fromHex(t).multiply(A(e)).toRawBytes(n)},sign:function(e,r,i=_){const{seed:s,k2sig:l}=function(e,r,i=_){if(["recovered","canonical"].some(e=>e in i))throw new Error("sign() legacy options not supported");const{hash:s,randomBytes:l}=t;let{lowS:u,prehash:h,extraEntropy:m}=i;null==u&&(u=!0),e=Rr("msgHash",e),h&&(e=Rr("prehashed msgHash",s(e)));const y=b(e),w=A(r),E=[v(w),v(y)];if(null!=m){const e=!0===m?l(n.BYTES):m;E.push(Rr("extraEntropy",e))}const k=Br(...E),T=y;return{seed:k,k2sig:function(e){const t=g(e);if(!f(t))return;const n=o(t),r=c.BASE.multiply(t).toAffine(),i=a(r.x);if(i===Ai)return;const s=a(n*a(T+i*w));if(s===Ai)return;let A=(r.x===i?0:2)|Number(r.y&li),l=s;return u&&d(s)&&(l=function(e){return d(e)?a(-e):e}(s),A^=1),new p(i,l,A)}}}(e,r,i),u=t;return Fr(u.hash.outputLen,u.nByteLength,u.hmac)(s,l)},verify:function(e,n,r,i=E){const s=e;if(n=Rr("msgHash",n),r=Rr("publicKey",r),"strict"in i)throw new Error("options.strict was renamed to lowS");const{lowS:A,prehash:l}=i;let f,u;try{if("string"==typeof s||s instanceof Uint8Array)try{f=p.fromDER(s)}catch(_){if(!(_ instanceof ci.Err))throw _;f=p.fromCompact(s)}else{if("object"!=typeof s||"bigint"!=typeof s.r||"bigint"!=typeof s.s)throw new Error("PARSE");{const{r:e,s:t}=s;f=new p(e,t)}}u=c.fromHex(r)}catch(k){if("PARSE"===k.message)throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(A&&f.hasHighS())return!1;l&&(n=t.hash(n));const{r:d,s:h}=f,m=b(n),y=o(h),g=a(m*y),w=a(d*y),v=c.BASE.multiplyAndAddUnsafe(u,g,w)?.toAffine();return!!v&&a(v.x)===d},ProjectivePoint:c,Signature:p,utils:m}}BigInt(4);let di=class extends Ar{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");tr(e.outputLen),tr(e.blockLen)}(e);const n=cr(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,i=new Uint8Array(r);i.set(n.length>r?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(e){return rr(this),this.iHash.update(e),this}digestInto(e){rr(this),nr(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:s,outputLen:a}=this;return e.finished=r,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const hi=(e,t,n)=>new di(e,t).update(n).digest();
8
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
9
+ function pi(e){return{hash:e,hmac:(t,...n)=>hi(e,t,function(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!sr(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}(...n)),randomBytes:fr}}hi.create=(e,t)=>new di(e,t);
10
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
11
+ const mi=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),yi=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),gi=BigInt(1),bi=BigInt(2),wi=(e,t)=>(e+t/bi)/t;function vi(e){const t=mi,n=BigInt(3),r=BigInt(6),i=BigInt(11),s=BigInt(22),a=BigInt(23),o=BigInt(44),c=BigInt(88),A=e*e*e%t,l=A*A*e%t,f=Yr(l,n,t)*l%t,u=Yr(f,n,t)*l%t,d=Yr(u,bi,t)*A%t,h=Yr(d,i,t)*d%t,p=Yr(h,s,t)*h%t,m=Yr(p,o,t)*p%t,y=Yr(m,c,t)*m%t,g=Yr(y,o,t)*p%t,b=Yr(g,n,t)*l%t,w=Yr(b,a,t)*h%t,v=Yr(w,r,t)*A%t,_=Yr(v,bi,t);if(!_i.eql(_i.sqr(_),e))throw new Error("Cannot find square root");return _}const _i=function(e,t,n=!1,r={}){if(e<=jr)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:i,nByteLength:s}=ei(e,t);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");const a=function(e){if(e%Qr===qr){const t=(e+Hr)/Qr;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}if(e%Jr===Vr){const t=(e-Vr)/Jr;return function(e,n){const r=e.mul(n,zr),i=e.pow(r,t),s=e.mul(n,i),a=e.mul(e.mul(s,zr),i),o=e.mul(s,e.sub(a,e.ONE));if(!e.eql(e.sqr(o),n))throw new Error("Cannot find square root");return o}}return function(e){const t=(e-Hr)/zr;let n,r,i;for(n=e-Hr,r=0;n%zr===jr;n/=zr,r++);for(i=zr;i<e&&Wr(i,t,e)!==e-Hr;i++);if(1===r){const t=(e+Hr)/Qr;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}const s=(n+Hr)/zr;return function(e,a){if(e.pow(a,t)===e.neg(e.ONE))throw new Error("Cannot find square root");let o=r,c=e.pow(e.mul(e.ONE,i),n),A=e.pow(a,s),l=e.pow(a,n);for(;!e.eql(l,e.ONE);){if(e.eql(l,e.ZERO))return e.ZERO;let t=1;for(let r=e.sqr(l);t<o&&!e.eql(r,e.ONE);t++)r=e.sqr(r);const n=e.pow(c,Hr<<BigInt(o-t-1));c=e.sqr(n),A=e.mul(A,n),l=e.mul(l,c),o=t}return A}}(e)}(e),o=Object.freeze({ORDER:e,BITS:i,BYTES:s,MASK:Mr(i),ZERO:jr,ONE:Hr,create:t=>Kr(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("Invalid field element: expected bigint, got "+typeof t);return jr<=t&&t<e},is0:e=>e===jr,isOdd:e=>(e&Hr)===Hr,neg:t=>Kr(-t,e),eql:(e,t)=>e===t,sqr:t=>Kr(t*t,e),add:(t,n)=>Kr(t+n,e),sub:(t,n)=>Kr(t-n,e),mul:(t,n)=>Kr(t*n,e),pow:(e,t)=>function(e,t,n){if(n<jr)throw new Error("Expected power > 0");if(n===jr)return e.ONE;if(n===Hr)return t;let r=e.ONE,i=t;for(;n>jr;)n&Hr&&(r=e.mul(r,i)),i=e.sqr(i),n>>=Hr;return r}(o,e,t),div:(t,n)=>Kr(t*Zr(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>Zr(t,e),sqrt:r.sqrt||(e=>a(o,e)),invertBatch:e=>function(e,t){const n=new Array(t.length),r=t.reduce((t,r,i)=>e.is0(r)?t:(n[i]=t,e.mul(t,r)),e.ONE),i=e.inv(r);return t.reduceRight((t,r,i)=>e.is0(r)?t:(n[i]=e.mul(t,n[i]),e.mul(t,r)),i),n}(o,e),cmov:(e,t,n)=>n?t:e,toBytes:e=>n?Or(e,s):Nr(e,s),fromBytes:e=>{if(e.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${e.length}`);return n?Cr(e):Pr(e)}});return Object.freeze(o)}(mi,void 0,void 0,{sqrt:vi}),Ei=function(e,t){const n=t=>ui({...e,...pi(t)});return Object.freeze({...n(t),create:n})}({a:BigInt(0),b:BigInt(7),Fp:_i,n:yi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=yi,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-gi*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,a=BigInt("0x100000000000000000000000000000000"),o=wi(s*e,t),c=wi(-r*e,t);let A=Kr(e-o*n-c*i,t),l=Kr(-o*r-c*s,t);const f=A>a,u=l>a;if(f&&(A=t-A),u&&(l=t-l),A>a||l>a)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:f,k1:A,k2neg:u,k2:l}}}},br),ki=BigInt(0),Ti=e=>"bigint"==typeof e&&ki<e&&e<mi,Si={};function xi(e,...t){let n=Si[e];if(void 0===n){const t=br(Uint8Array.from(e,e=>e.charCodeAt(0)));n=Br(t,t),Si[e]=n}return br(Br(n,...t))}const Ii=e=>e.toRawBytes(!0).slice(1),Pi=e=>Nr(e,32),Ci=e=>Kr(e,mi),Ni=e=>Kr(e,yi),Oi=Ei.ProjectivePoint;function Ri(e){let t=Ei.utils.normPrivateKeyToScalar(e),n=Oi.fromPrivateKey(t);return{scalar:n.hasEvenY()?t:Ni(-t),bytes:Ii(n)}}function Bi(e){if(!Ti(e))throw new Error("bad x: need 0 < x < p");const t=Ci(e*e);let n=vi(Ci(t*e+BigInt(7)));n%bi!==ki&&(n=Ci(-n));const r=new Oi(e,n,gi);return r.assertValidity(),r}function Mi(...e){return Ni(Pr(xi("BIP0340/challenge",...e)))}function $i(e){return Ri(e).bytes}function Di(e,t,n=fr(32)){const r=Rr("message",e),{bytes:i,scalar:s}=Ri(t),a=Rr("auxRand",n,32),o=Pi(s^Pr(xi("BIP0340/aux",a))),c=xi("BIP0340/nonce",o,i,r),A=Ni(Pr(c));if(A===ki)throw new Error("sign failed: k is zero");const{bytes:l,scalar:f}=Ri(A),u=Mi(l,i,r),d=new Uint8Array(64);if(d.set(l,0),d.set(Pi(Ni(f+u*s)),32),!Fi(d,r,i))throw new Error("sign: Invalid signature produced");return d}function Fi(e,t,n){const r=Rr("signature",e,64),i=Rr("message",t),s=Rr("publicKey",n,32);try{const e=Bi(Pr(s)),t=Pr(r.subarray(0,32));if(!Ti(t))return!1;const n=Pr(r.subarray(32,64));if(!("bigint"==typeof(A=n)&&ki<A&&A<yi))return!1;const l=Mi(Pi(t),Ii(e),i),f=(a=e,o=n,c=Ni(-l),Oi.BASE.multiplyAndAddUnsafe(a,o,c));return!(!f||!f.hasEvenY()||f.toAffine().x!==t)}catch(l){return!1}var a,o,c,A}const Gi=(()=>({getPublicKey:$i,sign:Di,verify:Fi,utils:{randomPrivateKey:Ei.utils.randomPrivateKey,lift_x:Bi,pointToBytes:Ii,numberToBytesBE:Nr,bytesToNumberBE:Pr,taggedHash:xi,mod:Kr}}))(),Ui="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,Li=e=>e instanceof Uint8Array,ji=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Hi=(e,t)=>e<<32-t|e>>>t;if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw new Error("Non little-endian hardware is not supported");const zi=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function qi(e){if(!Li(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=zi[e[n]];return t}function Qi(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let r=0;r<n.length;r++){const t=2*r,i=e.slice(t,t+2),s=Number.parseInt(i,16);if(Number.isNaN(s)||s<0)throw new Error("Invalid byte sequence");n[r]=s}return n}function Vi(e){if("string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),!Li(e))throw new Error("expected Uint8Array, got "+typeof e);return e}function Ji(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!Li(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}let Ki=class{clone(){return this._cloneInto()}};function Wi(e){const t=t=>e().update(Vi(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Yi(e=32){if(Ui&&"function"==typeof Ui.getRandomValues)return Ui.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function Zi(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Xi(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}const es={number:Zi,bool:function(e){if("boolean"!=typeof e)throw new Error(`Expected boolean, not ${e}`)},bytes:Xi,hash:function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");Zi(e.outputLen),Zi(e.blockLen)},exists:function(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")},output:function(e,t){Xi(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}};let ts=class extends Ki{constructor(e,t,n,r){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=ji(this.buffer)}update(e){es.exists(this);const{view:t,buffer:n,blockLen:r}=this,i=(e=Vi(e)).length;for(let s=0;s<i;){const a=Math.min(r-this.pos,i-s);if(a===r){const t=ji(e);for(;r<=i-s;s+=r)this.process(t,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){es.exists(this),es.output(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:i}=this;let{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>r-s&&(this.process(n,0),s=0);for(let l=s;l<r;l++)t[l]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const i=BigInt(32),s=BigInt(4294967295),a=Number(n>>i&s),o=Number(n&s),c=r?4:0,A=r?0:4;e.setUint32(t+c,a,r),e.setUint32(t+A,o,r)}(n,r-8,BigInt(8*this.length),i),this.process(n,0);const a=ji(e),o=this.outputLen;if(o%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=o/4,A=this.get();if(c>A.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<c;l++)a.setUint32(4*l,A[l],i)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:i,destroyed:s,pos:a}=this;return e.length=r,e.pos=a,e.finished=i,e.destroyed=s,r%t&&e.buffer.set(n),e}};const ns=(e,t,n)=>e&t^~e&n,rs=(e,t,n)=>e&t^e&n^t&n,is=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ss=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),as=new Uint32Array(64);let os=class extends ts{constructor(){super(64,32,8,!1),this.A=0|ss[0],this.B=0|ss[1],this.C=0|ss[2],this.D=0|ss[3],this.E=0|ss[4],this.F=0|ss[5],this.G=0|ss[6],this.H=0|ss[7]}get(){const{A:e,B:t,C:n,D:r,E:i,F:s,G:a,H:o}=this;return[e,t,n,r,i,s,a,o]}set(e,t,n,r,i,s,a,o){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|s,this.G=0|a,this.H=0|o}process(e,t){for(let l=0;l<16;l++,t+=4)as[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){const e=as[l-15],t=as[l-2],n=Hi(e,7)^Hi(e,18)^e>>>3,r=Hi(t,17)^Hi(t,19)^t>>>10;as[l]=r+as[l-7]+n+as[l-16]|0}let{A:n,B:r,C:i,D:s,E:a,F:o,G:c,H:A}=this;for(let l=0;l<64;l++){const e=A+(Hi(a,6)^Hi(a,11)^Hi(a,25))+ns(a,o,c)+is[l]+as[l]|0,t=(Hi(n,2)^Hi(n,13)^Hi(n,22))+rs(n,r,i)|0;A=c,c=o,o=a,a=s+e|0,s=i,i=r,r=n,n=e+t|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,o=o+this.F|0,c=c+this.G|0,A=A+this.H|0,this.set(n,r,i,s,a,o,c,A)}roundClean(){as.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};class cs extends os{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}const As=Wi(()=>new os);
12
+ /*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
13
+ function ls(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function fs(...e){const t=(e,t)=>n=>e(t(n));return{encode:Array.from(e).reverse().reduce((e,n)=>e?t(e,n.encode):n.encode,void 0),decode:e.reduce((e,n)=>e?t(e,n.decode):n.decode,void 0)}}function us(e){return{encode:t=>{if(!Array.isArray(t)||t.length&&"number"!=typeof t[0])throw new Error("alphabet.encode input should be an array of numbers");return t.map(t=>{if(ls(t),t<0||t>=e.length)throw new Error(`Digit index outside alphabet: ${t} (alphabet: ${e.length})`);return e[t]})},decode:t=>{if(!Array.isArray(t)||t.length&&"string"!=typeof t[0])throw new Error("alphabet.decode input should be array of strings");return t.map(t=>{if("string"!=typeof t)throw new Error(`alphabet.decode: not string element=${t}`);const n=e.indexOf(t);if(-1===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n})}}}function ds(e=""){if("string"!=typeof e)throw new Error("join separator should be string");return{encode:t=>{if(!Array.isArray(t)||t.length&&"string"!=typeof t[0])throw new Error("join.encode input should be array of strings");for(let e of t)if("string"!=typeof e)throw new Error(`join.encode: non-string input=${e}`);return t.join(e)},decode:t=>{if("string"!=typeof t)throw new Error("join.decode input should be string");return t.split(e)}}}function hs(e,t="="){if(ls(e),"string"!=typeof t)throw new Error("padding chr should be string");return{encode(n){if(!Array.isArray(n)||n.length&&"string"!=typeof n[0])throw new Error("padding.encode input should be array of strings");for(let e of n)if("string"!=typeof e)throw new Error(`padding.encode: non-string input=${e}`);for(;n.length*e%8;)n.push(t);return n},decode(n){if(!Array.isArray(n)||n.length&&"string"!=typeof n[0])throw new Error("padding.encode input should be array of strings");for(let e of n)if("string"!=typeof e)throw new Error(`padding.decode: non-string input=${e}`);let r=n.length;if(r*e%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--)if(!((r-1)*e%8))throw new Error("Invalid padding: string has too much padding");return n.slice(0,r)}}}function ps(e){if("function"!=typeof e)throw new Error("normalize fn should be function");return{encode:e=>e,decode:t=>e(t)}}function ms(e,t,n){if(t<2)throw new Error(`convertRadix: wrong from=${t}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: wrong to=${n}, base cannot be less than 2`);if(!Array.isArray(e))throw new Error("convertRadix: data should be array");if(!e.length)return[];let r=0;const i=[],s=Array.from(e);for(s.forEach(e=>{if(ls(e),e<0||e>=t)throw new Error(`Wrong integer: ${e}`)});;){let e=0,a=!0;for(let i=r;i<s.length;i++){const o=s[i],c=t*e+o;if(!Number.isSafeInteger(c)||t*e/t!==e||c-o!==t*e)throw new Error("convertRadix: carry overflow");if(e=c%n,s[i]=Math.floor(c/n),!Number.isSafeInteger(s[i])||s[i]*n+e!==c)throw new Error("convertRadix: carry overflow");a&&(s[i]?a=!1:r=i)}if(i.push(e),a)break}for(let a=0;a<e.length-1&&0===e[a];a++)i.push(0);return i.reverse()}Wi(()=>new cs);const ys=(e,t)=>t?ys(t,e%t):e,gs=(e,t)=>e+(t-ys(e,t));function bs(e,t,n,r){if(!Array.isArray(e))throw new Error("convertRadix2: data should be array");if(t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(gs(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${gs(t,n)}`);let i=0,s=0;const a=2**n-1,o=[];for(const c of e){if(ls(c),c>=2**t)throw new Error(`convertRadix2: invalid data word=${c} from=${t}`);if(i=i<<t|c,s+t>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${t}`);for(s+=t;s>=n;s-=n)o.push((i>>s-n&a)>>>0);i&=2**s-1}if(i=i<<n-s&a,!r&&s>=t)throw new Error("Excess padding");if(!r&&i)throw new Error(`Non-zero padding: ${i}`);return r&&s>0&&o.push(i>>>0),o}function ws(e,t=!1){if(ls(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(gs(8,e)>32||gs(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!(n instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return bs(Array.from(n),8,e,!t)},decode:n=>{if(!Array.isArray(n)||n.length&&"number"!=typeof n[0])throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(bs(n,e,8,t))}}}function vs(e){if("function"!=typeof e)throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch(n){}}}const _s=fs(ws(4),us("0123456789ABCDEF"),ds("")),Es=fs(ws(5),us("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),hs(5),ds(""));fs(ws(5),us("0123456789ABCDEFGHIJKLMNOPQRSTUV"),hs(5),ds("")),fs(ws(5),us("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),ds(""),ps(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const ks=fs(ws(6),us("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),hs(6),ds("")),Ts=fs(ws(6),us("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),hs(6),ds("")),Ss=e=>fs((ls(58),{encode:e=>{if(!(e instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return ms(Array.from(e),256,58)},decode:e=>{if(!Array.isArray(e)||e.length&&"number"!=typeof e[0])throw new Error("radix.decode input should be array of strings");return Uint8Array.from(ms(e,58,256))}}),us(e),ds("")),xs=Ss("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");Ss("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),Ss("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const Is=[0,2,3,5,6,7,9,10,11],Ps={encode(e){let t="";for(let n=0;n<e.length;n+=8){const r=e.subarray(n,n+8);t+=xs.encode(r).padStart(Is[r.length],"1")}return t},decode(e){let t=[];for(let n=0;n<e.length;n+=11){const r=e.slice(n,n+11),i=Is.indexOf(r.length),s=xs.decode(r);for(let e=0;e<s.length-i;e++)if(0!==s[e])throw new Error("base58xmr: wrong padding");t=t.concat(Array.from(s.slice(s.length-i)))}return Uint8Array.from(t)}},Cs=fs(us("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),ds("")),Ns=[996825010,642813549,513874426,1027748829,705979059];function Os(e){const t=e>>25;let n=(33554431&e)<<5;for(let r=0;r<Ns.length;r++)1==(t>>r&1)&&(n^=Ns[r]);return n}function Rs(e,t,n=1){const r=e.length;let i=1;for(let s=0;s<r;s++){const t=e.charCodeAt(s);if(t<33||t>126)throw new Error(`Invalid prefix (${e})`);i=Os(i)^t>>5}i=Os(i);for(let s=0;s<r;s++)i=Os(i)^31&e.charCodeAt(s);for(let s of t)i=Os(i)^s;for(let s=0;s<6;s++)i=Os(i);return i^=n,Cs.encode(bs([i%2**30],30,5,!1))}function Bs(e){const t="bech32"===e?1:734539939,n=ws(5),r=n.decode,i=n.encode,s=vs(r);function a(e,n=90){if("string"!=typeof e)throw new Error("bech32.decode input should be string, not "+typeof e);if(e.length<8||!1!==n&&e.length>n)throw new TypeError(`Wrong string length: ${e.length} (${e}). Expected (8..${n})`);const r=e.toLowerCase();if(e!==r&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const i=(e=r).lastIndexOf("1");if(0===i||-1===i)throw new Error('Letter "1" must be present between prefix and data only');const s=e.slice(0,i),a=e.slice(i+1);if(a.length<6)throw new Error("Data must be at least 6 characters long");const o=Cs.decode(a).slice(0,-6),c=Rs(s,o,t);if(!a.endsWith(c))throw new Error(`Invalid checksum in ${e}: expected "${c}"`);return{prefix:s,words:o}}return{encode:function(e,n,r=90){if("string"!=typeof e)throw new Error("bech32.encode prefix should be string, not "+typeof e);if(!Array.isArray(n)||n.length&&"number"!=typeof n[0])throw new Error("bech32.encode words should be array of numbers, not "+typeof n);const i=e.length+7+n.length;if(!1!==r&&i>r)throw new TypeError(`Length ${i} exceeds limit ${r}`);return`${e=e.toLowerCase()}1${Cs.encode(n)}${Rs(e,n,t)}`},decode:a,decodeToBytes:function(e){const{prefix:t,words:n}=a(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:vs(a),fromWords:r,fromWordsUnsafe:s,toWords:i}}const Ms=Bs("bech32");Bs("bech32m");const $s={utf8:{encode:e=>(new TextDecoder).decode(e),decode:e=>(new TextEncoder).encode(e)},hex:fs(ws(4),us("0123456789abcdef"),ds(""),ps(e=>{if("string"!=typeof e||e.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()})),base16:_s,base32:Es,base64:ks,base64url:Ts,base58:xs,base58xmr:Ps};function Ds(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function Fs(e){if("boolean"!=typeof e)throw new Error(`boolean expected, not ${e}`)}function Gs(e,...t){if(!((n=e)instanceof Uint8Array||null!=n&&"object"==typeof n&&"Uint8Array"===n.constructor.name))throw new Error("Uint8Array expected");var n;if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}
14
+ /*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */Object.keys($s).join(", ");const Us=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4));if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw new Error("Non little-endian hardware is not supported");const Ls=(e,t)=>(Object.assign(t,e),t),js=16;function Hs(e){return e<<1^283&-(e>>7)}function zs(e,t){let n=0;for(;t>0;t>>=1)n^=e&-(1&t),e=Hs(e);return n}const qs=(()=>{let e=new Uint8Array(256);for(let n=0,r=1;n<256;n++,r^=Hs(r))e[n]=r;const t=new Uint8Array(256);t[0]=99;for(let n=0;n<255;n++){let r=e[255-n];r|=r<<8,t[e[n]]=255&(r^r>>4^r>>5^r>>6^r>>7^99)}return t})(),Qs=qs.map((e,t)=>qs.indexOf(t)),Vs=e=>e<<24|e>>>8,Js=e=>e<<8|e>>>24;function Ks(e,t){if(256!==e.length)throw new Error("Wrong sbox length");const n=new Uint32Array(256).map((n,r)=>t(e[r])),r=n.map(Js),i=r.map(Js),s=i.map(Js),a=new Uint32Array(65536),o=new Uint32Array(65536),c=new Uint16Array(65536);for(let A=0;A<256;A++)for(let t=0;t<256;t++){const l=256*A+t;a[l]=n[A]^r[t],o[l]=i[A]^s[t],c[l]=e[A]<<8|e[t]}return{sbox:e,sbox2:c,T0:n,T1:r,T2:i,T3:s,T01:a,T23:o}}const Ws=Ks(qs,e=>zs(e,3)<<24|e<<16|e<<8|zs(e,2)),Ys=Ks(Qs,e=>zs(e,11)<<24|zs(e,13)<<16|zs(e,9)<<8|zs(e,14)),Zs=(()=>{const e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=Hs(n))e[t]=n;return e})();function Xs(e){Gs(e);const t=e.length;if(![16,24,32].includes(t))throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${t}`);const{sbox2:n}=Ws,r=Us(e),i=r.length,s=e=>ta(n,e,e,e,e),a=new Uint32Array(t+28);a.set(r);for(let o=i;o<a.length;o++){let e=a[o-1];o%i===0?e=s(Vs(e))^Zs[o/i-1]:i>6&&o%i===4&&(e=s(e)),a[o]=a[o-i]^e}return a}function ea(e,t,n,r,i,s){return e[n<<8&65280|r>>>8&255]^t[i>>>8&65280|s>>>24&255]}function ta(e,t,n,r,i){return e[255&t|65280&n]|e[r>>>16&255|i>>>16&65280]<<16}function na(e,t,n,r,i){const{sbox2:s,T01:a,T23:o}=Ws;let c=0;t^=e[c++],n^=e[c++],r^=e[c++],i^=e[c++];const A=e.length/4-2;for(let l=0;l<A;l++){const s=e[c++]^ea(a,o,t,n,r,i),A=e[c++]^ea(a,o,n,r,i,t),l=e[c++]^ea(a,o,r,i,t,n),f=e[c++]^ea(a,o,i,t,n,r);t=s,n=A,r=l,i=f}return{s0:e[c++]^ta(s,t,n,r,i),s1:e[c++]^ta(s,n,r,i,t),s2:e[c++]^ta(s,r,i,t,n),s3:e[c++]^ta(s,i,t,n,r)}}function ra(e,t,n,r,i){const{sbox2:s,T01:a,T23:o}=Ys;let c=0;t^=e[c++],n^=e[c++],r^=e[c++],i^=e[c++];const A=e.length/4-2;for(let l=0;l<A;l++){const s=e[c++]^ea(a,o,t,i,r,n),A=e[c++]^ea(a,o,n,t,i,r),l=e[c++]^ea(a,o,r,n,t,i),f=e[c++]^ea(a,o,i,r,n,t);t=s,n=A,r=l,i=f}return{s0:e[c++]^ta(s,t,i,r,n),s1:e[c++]^ta(s,n,t,i,r),s2:e[c++]^ta(s,r,n,t,i),s3:e[c++]^ta(s,i,r,n,t)}}function ia(e,t){if(!t)return new Uint8Array(e);if(Gs(t),t.length<e)throw new Error(`aes: wrong destination length, expected at least ${e}, got: ${t.length}`);return t}const sa=Ls({blockSize:16,nonceLength:16},function(e,t,n={}){Gs(e),Gs(t,16);const r=!n.disablePadding;return{encrypt:(n,i)=>{const s=Xs(e),{b:a,o:o,out:c}=function(e,t,n){let r=e.length;const i=r%js;if(!t&&0!==i)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const s=Us(e);if(t){let e=js-i;e||(e=js),r+=e}const a=ia(r,n);return{b:s,o:Us(a),out:a}}(n,r,i),A=Us(t);let l=A[0],f=A[1],u=A[2],d=A[3],h=0;for(;h+4<=a.length;)l^=a[h+0],f^=a[h+1],u^=a[h+2],d^=a[h+3],({s0:l,s1:f,s2:u,s3:d}=na(s,l,f,u,d)),o[h++]=l,o[h++]=f,o[h++]=u,o[h++]=d;if(r){const e=function(e){const t=new Uint8Array(16),n=Us(t);t.set(e);const r=js-e.length;for(let i=js-r;i<js;i++)t[i]=r;return n}(n.subarray(4*h));l^=e[0],f^=e[1],u^=e[2],d^=e[3],({s0:l,s1:f,s2:u,s3:d}=na(s,l,f,u,d)),o[h++]=l,o[h++]=f,o[h++]=u,o[h++]=d}return s.fill(0),c},decrypt:(n,i)=>{!function(e){if(Gs(e),e.length%js!==0)throw new Error("aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size 16")}(n);const s=function(e){const t=Xs(e),n=t.slice(),r=t.length,{sbox2:i}=Ws,{T0:s,T1:a,T2:o,T3:c}=Ys;for(let A=0;A<r;A+=4)for(let e=0;e<4;e++)n[A+e]=t[r-A-4+e];t.fill(0);for(let A=4;A<r-4;A++){const e=n[A],t=ta(i,e,e,e,e);n[A]=s[255&t]^a[t>>>8&255]^o[t>>>16&255]^c[t>>>24]}return n}(e),a=Us(t),o=ia(n.length,i),c=Us(n),A=Us(o);let l=a[0],f=a[1],u=a[2],d=a[3];for(let e=0;e+4<=c.length;){const t=l,n=f,r=u,i=d;l=c[e+0],f=c[e+1],u=c[e+2],d=c[e+3];const{s0:a,s1:o,s2:h,s3:p}=ra(s,l,f,u,d);A[e++]=a^t,A[e++]=o^n,A[e++]=h^r,A[e++]=p^i}return s.fill(0),function(e,t){if(!t)return e;const n=e.length;if(!n)throw new Error("aes/pcks5: empty ciphertext not allowed");const r=e[n-1];if(r<=0||r>16)throw new Error(`aes/pcks5: wrong padding byte: ${r}`);const i=e.subarray(0,-r);for(let s=0;s<r;s++)if(e[n-s-1]!==r)throw new Error("aes/pcks5: wrong padding");return i}(o,r)}}}),aa=e=>Uint8Array.from(e.split("").map(e=>e.charCodeAt(0))),oa=aa("expand 16-byte k"),ca=aa("expand 32-byte k"),Aa=Us(oa),la=Us(ca);function fa(e,t){return e<<t|e>>>32-t}function ua(e){return e.byteOffset%4==0}la.slice();const da=2**32-1,ha=new Uint32Array;function pa(e,t){const{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:s,rounds:a}=function(e,t){if(null==t||"object"!=typeof t)throw new Error("options must be defined");return Object.assign({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t)}(0,t);if("function"!=typeof e)throw new Error("core must be a function");return Ds(i),Ds(a),Fs(s),Fs(n),(t,o,c,A,l=0)=>{Gs(t),Gs(o),Gs(c);const f=c.length;if(A||(A=new Uint8Array(f)),Gs(A),Ds(l),l<0||l>=da)throw new Error("arx: counter overflow");if(A.length<f)throw new Error(`arx: output (${A.length}) is shorter than data (${f})`);const u=[];let d,h,p=t.length;if(32===p)d=t.slice(),u.push(d),h=la;else{if(16!==p||!n)throw new Error(`arx: invalid 32-byte key, got length=${p}`);d=new Uint8Array(32),d.set(t),d.set(t,16),h=Aa,u.push(d)}ua(o)||(o=o.slice(),u.push(o));const m=Us(d);if(r){if(24!==o.length)throw new Error("arx: extended nonce must be 24 bytes");r(h,m,Us(o.subarray(0,16)),m),o=o.subarray(16)}const y=16-i;if(y!==o.length)throw new Error(`arx: nonce must be ${y} or 16 bytes`);if(12!==y){const e=new Uint8Array(12);e.set(o,s?0:12-o.length),o=e,u.push(o)}const g=Us(o);for(function(e,t,n,r,i,s,a,o){const c=i.length,A=new Uint8Array(64),l=Us(A),f=ua(i)&&ua(s),u=f?Us(i):ha,d=f?Us(s):ha;for(let h=0;h<c;a++){if(e(t,n,r,l,a,o),a>=da)throw new Error("arx: counter overflow");const p=Math.min(64,c-h);if(f&&64===p){const e=h/4;if(h%4!=0)throw new Error("arx: invalid block position");for(let t,n=0;n<16;n++)t=e+n,d[t]=u[t]^l[n];h+=64;continue}for(let e,t=0;t<p;t++)e=h+t,s[e]=i[e]^A[t];h+=p}}(e,h,m,g,c,A,l,a);u.length>0;)u.pop().fill(0);return A}}function ma(e,t,n,r,i,s=20){let a=e[0],o=e[1],c=e[2],A=e[3],l=t[0],f=t[1],u=t[2],d=t[3],h=t[4],p=t[5],m=t[6],y=t[7],g=i,b=n[0],w=n[1],v=n[2],_=a,E=o,k=c,T=A,S=l,x=f,I=u,P=d,C=h,N=p,O=m,R=y,B=g,M=b,$=w,D=v;for(let G=0;G<s;G+=2)_=_+S|0,B=fa(B^_,16),C=C+B|0,S=fa(S^C,12),_=_+S|0,B=fa(B^_,8),C=C+B|0,S=fa(S^C,7),E=E+x|0,M=fa(M^E,16),N=N+M|0,x=fa(x^N,12),E=E+x|0,M=fa(M^E,8),N=N+M|0,x=fa(x^N,7),k=k+I|0,$=fa($^k,16),O=O+$|0,I=fa(I^O,12),k=k+I|0,$=fa($^k,8),O=O+$|0,I=fa(I^O,7),T=T+P|0,D=fa(D^T,16),R=R+D|0,P=fa(P^R,12),T=T+P|0,D=fa(D^T,8),R=R+D|0,P=fa(P^R,7),_=_+x|0,D=fa(D^_,16),O=O+D|0,x=fa(x^O,12),_=_+x|0,D=fa(D^_,8),O=O+D|0,x=fa(x^O,7),E=E+I|0,B=fa(B^E,16),R=R+B|0,I=fa(I^R,12),E=E+I|0,B=fa(B^E,8),R=R+B|0,I=fa(I^R,7),k=k+P|0,M=fa(M^k,16),C=C+M|0,P=fa(P^C,12),k=k+P|0,M=fa(M^k,8),C=C+M|0,P=fa(P^C,7),T=T+S|0,$=fa($^T,16),N=N+$|0,S=fa(S^N,12),T=T+S|0,$=fa($^T,8),N=N+$|0,S=fa(S^N,7);let F=0;r[F++]=a+_|0,r[F++]=o+E|0,r[F++]=c+k|0,r[F++]=A+T|0,r[F++]=l+S|0,r[F++]=f+x|0,r[F++]=u+I|0,r[F++]=d+P|0,r[F++]=h+C|0,r[F++]=p+N|0,r[F++]=m+O|0,r[F++]=y+R|0,r[F++]=g+B|0,r[F++]=b+M|0,r[F++]=w+$|0,r[F++]=v+D|0}const ya=pa(ma,{counterRight:!1,counterLength:4,allowShortKeys:!1});let ga=class extends Ki{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,es.hash(e);const n=Vi(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,i=new Uint8Array(r);i.set(n.length>r?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(e){return es.exists(this),this.iHash.update(e),this}digestInto(e){es.exists(this),es.bytes(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:s,outputLen:a}=this;return e.finished=r,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const ba=(e,t,n)=>new ga(e,t).update(n).digest();ba.create=(e,t)=>new ga(e,t);const wa=new Uint8Array([0]),va=new Uint8Array;var _a=Object.defineProperty,Ea=(e,t)=>{for(var n in t)_a(e,n,{get:t[n],enumerable:!0})},ka=Symbol("verified");function Ta(e){if(!(e instanceof Object))return!1;if("number"!=typeof e.kind)return!1;if("string"!=typeof e.content)return!1;if("number"!=typeof e.created_at)return!1;if("string"!=typeof e.pubkey)return!1;if(!e.pubkey.match(/^[a-f0-9]{64}$/))return!1;if(!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let n=e.tags[t];if(!Array.isArray(n))return!1;for(let e=0;e<n.length;e++)if("string"!=typeof n[e])return!1}return!0}Ea({},{Queue:()=>Ra,QueueNode:()=>Oa,binarySearch:()=>Na,bytesToHex:()=>qi,hexToBytes:()=>Qi,insertEventIntoAscendingList:()=>Ca,insertEventIntoDescendingList:()=>Pa,normalizeURL:()=>Ia,utf8Decoder:()=>Sa,utf8Encoder:()=>xa});var Sa=new TextDecoder("utf-8"),xa=new TextEncoder;function Ia(e){try{-1===e.indexOf("://")&&(e="wss://"+e);let t=new URL(e);return t.pathname=t.pathname.replace(/\/+/g,"/"),t.pathname.endsWith("/")&&(t.pathname=t.pathname.slice(0,-1)),("80"===t.port&&"ws:"===t.protocol||"443"===t.port&&"wss:"===t.protocol)&&(t.port=""),t.searchParams.sort(),t.hash="",t.toString()}catch(t){throw new Error(`Invalid URL: ${e}`)}}function Pa(e,t){const[n,r]=Na(e,e=>t.id===e.id?0:t.created_at===e.created_at?-1:e.created_at-t.created_at);return r||e.splice(n,0,t),e}function Ca(e,t){const[n,r]=Na(e,e=>t.id===e.id?0:t.created_at===e.created_at?-1:t.created_at-e.created_at);return r||e.splice(n,0,t),e}function Na(e,t){let n=0,r=e.length-1;for(;n<=r;){const i=Math.floor((n+r)/2),s=t(e[i]);if(0===s)return[i,!0];s<0?r=i-1:n=i+1}return[n,!1]}var Oa=class{constructor(e){__publicField(this,"value"),__publicField(this,"next",null),__publicField(this,"prev",null),this.value=e}},Ra=class{constructor(){__publicField(this,"first"),__publicField(this,"last"),this.first=null,this.last=null}enqueue(e){const t=new Oa(e);return this.last?this.last===this.first?(this.last=t,this.last.prev=this.first,this.first.next=t):(t.prev=this.last,this.last.next=t,this.last=t):(this.first=t,this.last=t),!0}dequeue(){if(!this.first)return null;if(this.first===this.last){const e=this.first;return this.first=null,this.last=null,e.value}const e=this.first;return this.first=e.next,this.first&&(this.first.prev=null),e.value}};function Ba(e){return qi(As(xa.encode(function(e){if(!Ta(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}(e))))}var Ma=new class{generateSecretKey(){return Gi.utils.randomPrivateKey()}getPublicKey(e){return qi(Gi.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=qi(Gi.getPublicKey(t)),n.id=Ba(n),n.sig=qi(Gi.sign(Ba(n),t)),n[ka]=!0,n}verifyEvent(e){if("boolean"==typeof e[ka])return e[ka];const t=Ba(e);if(t!==e.id)return e[ka]=!1,!1;try{const n=Gi.verify(e.sig,t,e.pubkey);return e[ka]=n,n}catch(n){return e[ka]=!1,!1}}},$a=Ma.generateSecretKey,Da=Ma.getPublicKey,Fa=Ma.finalizeEvent,Ga=Ma.verifyEvent;function Ua(e){return 1e3<=e&&e<1e4||[1,2,4,5,6,7,8,16,40,41,42,43,44].includes(e)}function La(e){return[0,3].includes(e)||1e4<=e&&e<2e4}function ja(e){return 2e4<=e&&e<3e4}function Ha(e){return 3e4<=e&&e<4e4}function za(e){return Ua(e)?"regular":La(e)?"replaceable":ja(e)?"ephemeral":Ha(e)?"parameterized":"unknown"}function qa(e,t){const n=t instanceof Array?t:[t];return Ta(e)&&n.includes(e.kind)||!1}Ea({},{Application:()=>ic,BadgeAward:()=>eo,BadgeDefinition:()=>Yo,BlockedRelaysList:()=>Oo,BookmarkList:()=>Po,Bookmarksets:()=>Jo,Calendar:()=>fc,CalendarEventRSVP:()=>uc,ChannelCreation:()=>io,ChannelHideMessage:()=>oo,ChannelMessage:()=>ao,ChannelMetadata:()=>so,ChannelMuteUser:()=>co,ClassifiedListing:()=>oc,ClientAuth:()=>Uo,CommunitiesList:()=>Co,CommunityDefinition:()=>pc,CommunityPostApproval:()=>go,Contacts:()=>Ka,CreateOrUpdateProduct:()=>ec,CreateOrUpdateStall:()=>Xo,Curationsets:()=>Ko,Date:()=>Ac,DirectMessageRelaysList:()=>$o,DraftClassifiedListing:()=>cc,DraftLong:()=>nc,Emojisets:()=>rc,EncryptedDirectMessage:()=>Wa,EventDeletion:()=>Ya,FileMetadata:()=>fo,FileServerPreference:()=>Do,Followsets:()=>qo,GenericRepost:()=>ro,Genericlists:()=>Qo,GiftWrap:()=>lo,HTTPAuth:()=>zo,Handlerinformation:()=>hc,Handlerrecommendation:()=>dc,Highlights:()=>To,InterestsList:()=>Bo,Interestsets:()=>Zo,JobFeedback:()=>vo,JobRequest:()=>bo,JobResult:()=>wo,Label:()=>yo,LightningPubRPC:()=>Go,LiveChatMessage:()=>uo,LiveEvent:()=>sc,LongFormArticle:()=>tc,Metadata:()=>Qa,Mutelist:()=>So,NWCWalletInfo:()=>Fo,NWCWalletRequest:()=>Lo,NWCWalletResponse:()=>jo,NostrConnect:()=>Ho,OpenTimestamps:()=>Ao,Pinlist:()=>xo,PrivateDirectMessage:()=>no,ProblemTracker:()=>ho,ProfileBadges:()=>Wo,PublicChatsList:()=>No,Reaction:()=>Xa,RecommendRelay:()=>Ja,RelayList:()=>Io,Relaysets:()=>Vo,Report:()=>po,Reporting:()=>mo,Repost:()=>Za,Seal:()=>to,SearchRelaysList:()=>Ro,ShortTextNote:()=>Va,Time:()=>lc,UserEmojiList:()=>Mo,UserStatuses:()=>ac,Zap:()=>ko,ZapGoal:()=>_o,ZapRequest:()=>Eo,classifyKind:()=>za,isAddressableKind:()=>Ha,isEphemeralKind:()=>ja,isKind:()=>qa,isRegularKind:()=>Ua,isReplaceableKind:()=>La});var Qa=0,Va=1,Ja=2,Ka=3,Wa=4,Ya=5,Za=6,Xa=7,eo=8,to=13,no=14,ro=16,io=40,so=41,ao=42,oo=43,co=44,Ao=1040,lo=1059,fo=1063,uo=1311,ho=1971,po=1984,mo=1984,yo=1985,go=4550,bo=5999,wo=6999,vo=7e3,_o=9041,Eo=9734,ko=9735,To=9802,So=1e4,xo=10001,Io=10002,Po=10003,Co=10004,No=10005,Oo=10006,Ro=10007,Bo=10015,Mo=10030,$o=10050,Do=10096,Fo=13194,Go=21e3,Uo=22242,Lo=23194,jo=23195,Ho=24133,zo=27235,qo=3e4,Qo=30001,Vo=30002,Jo=30003,Ko=30004,Wo=30008,Yo=30009,Zo=30015,Xo=30017,ec=30018,tc=30023,nc=30024,rc=30030,ic=30078,sc=30311,ac=30315,oc=30402,cc=30403,Ac=31922,lc=31923,fc=31924,uc=31925,dc=31989,hc=31990,pc=34550;function mc(e,t){if(e.ids&&-1===e.ids.indexOf(t.id))return!1;if(e.kinds&&-1===e.kinds.indexOf(t.kind))return!1;if(e.authors&&-1===e.authors.indexOf(t.pubkey))return!1;for(let n in e)if("#"===n[0]){let r=e[`#${n.slice(1)}`];if(r&&!t.tags.find(([e,t])=>e===n.slice(1)&&-1!==r.indexOf(t)))return!1}return!(e.since&&t.created_at<e.since||e.until&&t.created_at>e.until)}function yc(e,t){let n=t.length+3,r=e.indexOf(`"${t}":`)+n,i=e.slice(r).indexOf('"')+r+1;return e.slice(i,i+64)}function gc(e,t){let n=t.length,r=e.indexOf(`"${t}":`)+n+3,i=e.slice(r),s=Math.min(i.indexOf(","),i.indexOf("}"));return parseInt(i.slice(0,s),10)}function bc(e){let t=e.slice(0,22).indexOf('"EVENT"');if(-1===t)return null;let n=e.slice(t+7+1).indexOf('"');if(-1===n)return null;let r=t+7+1+n,i=e.slice(r+1,80).indexOf('"');if(-1===i)return null;let s=r+1+i;return e.slice(r+1,s)}function wc(e,t){return t===yc(e,"id")}function vc(e,t){return t===yc(e,"pubkey")}function _c(e,t){return t===gc(e,"kind")}function Ec(e,t){return{kind:Uo,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}async function kc(){return new Promise(e=>{const t=new MessageChannel,n=()=>{t.port1.removeEventListener("message",n),e()};t.port1.addEventListener("message",n),t.port2.postMessage(0),t.port1.start()})}Ea({},{getHex64:()=>yc,getInt:()=>gc,getSubscriptionId:()=>bc,matchEventId:()=>wc,matchEventKind:()=>_c,matchEventPubkey:()=>vc}),Ea({},{makeAuthEvent:()=>Ec});var Tc=e=>(e[ka]=!0,!0),Sc=class extends Error{constructor(e,t){super(`Tried to send message '${e} on a closed connection to ${t}.`),this.name="SendingOnClosedConnection"}},xc=class{constructor(e,t){__publicField(this,"url"),__publicField(this,"_connected",!1),__publicField(this,"onclose",null),__publicField(this,"onnotice",e=>console.debug(`NOTICE from ${this.url}: ${e}`)),__publicField(this,"baseEoseTimeout",4400),__publicField(this,"connectionTimeout",4400),__publicField(this,"publishTimeout",4400),__publicField(this,"pingFrequency",2e4),__publicField(this,"pingTimeout",2e4),__publicField(this,"openSubs",new Map),__publicField(this,"enablePing"),__publicField(this,"connectionTimeoutHandle"),__publicField(this,"connectionPromise"),__publicField(this,"openCountRequests",new Map),__publicField(this,"openEventPublishes",new Map),__publicField(this,"ws"),__publicField(this,"incomingMessageQueue",new Ra),__publicField(this,"queueRunning",!1),__publicField(this,"challenge"),__publicField(this,"authPromise"),__publicField(this,"serial",0),__publicField(this,"verifyEvent"),__publicField(this,"_WebSocket"),this.url=Ia(e),this.verifyEvent=t.verifyEvent,this._WebSocket=t.websocketImplementation||WebSocket,this.enablePing=t.enablePing}static async connect(e,t){const n=new xc(e,t);return await n.connect(),n}closeAllSubscriptions(e){for(let[t,n]of this.openSubs)n.close(e);this.openSubs.clear();for(let[t,n]of this.openEventPublishes)n.reject(new Error(e));this.openEventPublishes.clear();for(let[t,n]of this.openCountRequests)n.reject(new Error(e));this.openCountRequests.clear()}get connected(){return this._connected}async connect(){return this.connectionPromise||(this.challenge=void 0,this.authPromise=void 0,this.connectionPromise=new Promise((e,t)=>{this.connectionTimeoutHandle=setTimeout(()=>{t("connection timed out"),this.connectionPromise=void 0,this.onclose?.(),this.closeAllSubscriptions("relay connection timed out")},this.connectionTimeout);try{this.ws=new this._WebSocket(this.url)}catch(n){return clearTimeout(this.connectionTimeoutHandle),void t(n)}this.ws.onopen=()=>{clearTimeout(this.connectionTimeoutHandle),this._connected=!0,this.enablePing&&this.pingpong(),e()},this.ws.onerror=e=>{clearTimeout(this.connectionTimeoutHandle),t(e.message||"websocket error"),this._connected=!1,this.connectionPromise=void 0,this.onclose?.(),this.closeAllSubscriptions("relay connection errored")},this.ws.onclose=e=>{clearTimeout(this.connectionTimeoutHandle),t(e.message||"websocket closed"),this._connected=!1,this.connectionPromise=void 0,this.onclose?.(),this.closeAllSubscriptions("relay connection closed")},this.ws.onmessage=this._onmessage.bind(this)})),this.connectionPromise}async waitForPingPong(){return new Promise((e,t)=>{this.ws&&this.ws.on&&this.ws.on("pong",()=>e(!0))||t("ws can't listen for pong"),this.ws&&this.ws.ping&&this.ws.ping()})}async waitForDummyReq(){return new Promise((e,t)=>{const n=this.subscribe([{ids:["a".repeat(64)]}],{oneose:()=>{n.close(),e(!0)},eoseTimeout:this.pingTimeout+1e3})})}async pingpong(){1===this.ws?.readyState&&(await Promise.any([this.ws&&this.ws.ping&&this.ws.on?this.waitForPingPong():this.waitForDummyReq(),new Promise(e=>setTimeout(()=>e(!1),this.pingTimeout))])?setTimeout(()=>this.pingpong(),this.pingFrequency):(this.closeAllSubscriptions("pingpong timed out"),this._connected=!1,this.onclose?.(),this.ws?.close()))}async runQueue(){for(this.queueRunning=!0;!1!==this.handleNext();)await kc();this.queueRunning=!1}handleNext(){const e=this.incomingMessageQueue.dequeue();if(!e)return!1;const t=bc(e);if(t){const n=this.openSubs.get(t);if(!n)return;const r=yc(e,"id"),i=n.alreadyHaveEvent?.(r);if(n.receivedEvent?.(this,r),i)return}try{let t=JSON.parse(e);switch(t[0]){case"EVENT":{const e=this.openSubs.get(t[1]),n=t[2];return void(this.verifyEvent(n)&&function(e,t){for(let n=0;n<e.length;n++)if(mc(e[n],t))return!0;return!1}(e.filters,n)&&e.onevent(n))}case"COUNT":{const e=t[1],n=t[2],r=this.openCountRequests.get(e);return void(r&&(r.resolve(n.count),this.openCountRequests.delete(e)))}case"EOSE":{const e=this.openSubs.get(t[1]);if(!e)return;return void e.receivedEose()}case"OK":{const e=t[1],n=t[2],r=t[3],i=this.openEventPublishes.get(e);return void(i&&(clearTimeout(i.timeout),n?i.resolve(r):i.reject(new Error(r)),this.openEventPublishes.delete(e)))}case"CLOSED":{const e=t[1],n=this.openSubs.get(e);if(!n)return;return n.closed=!0,void n.close(t[2])}case"NOTICE":return void this.onnotice(t[1]);case"AUTH":return void(this.challenge=t[1])}}catch(n){return}}async send(e){if(!this.connectionPromise)throw new Sc(e,this.url);this.connectionPromise.then(()=>{this.ws?.send(e)})}async auth(e){const t=this.challenge;if(!t)throw new Error("can't perform auth, no challenge was received");return this.authPromise||(this.authPromise=new Promise(async(n,r)=>{try{let i=await e(Ec(this.url,t)),s=setTimeout(()=>{let e=this.openEventPublishes.get(i.id);e&&(e.reject(new Error("auth timed out")),this.openEventPublishes.delete(i.id))},this.publishTimeout);this.openEventPublishes.set(i.id,{resolve:n,reject:r,timeout:s}),this.send('["AUTH",'+JSON.stringify(i)+"]")}catch(i){console.warn("subscribe auth function failed:",i)}})),this.authPromise}async publish(e){const t=new Promise((t,n)=>{const r=setTimeout(()=>{const t=this.openEventPublishes.get(e.id);t&&(t.reject(new Error("publish timed out")),this.openEventPublishes.delete(e.id))},this.publishTimeout);this.openEventPublishes.set(e.id,{resolve:t,reject:n,timeout:r})});return this.send('["EVENT",'+JSON.stringify(e)+"]"),t}async count(e,t){this.serial++;const n=t?.id||"count:"+this.serial,r=new Promise((e,t)=>{this.openCountRequests.set(n,{resolve:e,reject:t})});return this.send('["COUNT","'+n+'",'+JSON.stringify(e).substring(1)),r}subscribe(e,t){const n=this.prepareSubscription(e,t);return n.fire(),n}prepareSubscription(e,t){this.serial++;const n=t.id||(t.label?t.label+":":"sub:")+this.serial,r=new Ic(this,n,e,t);return this.openSubs.set(n,r),r}close(){this.closeAllSubscriptions("relay connection closed by us"),this._connected=!1,this.onclose?.(),this.ws?.close()}_onmessage(e){this.incomingMessageQueue.enqueue(e.data),this.queueRunning||this.runQueue()}},Ic=class{constructor(e,t,n,r){__publicField(this,"relay"),__publicField(this,"id"),__publicField(this,"closed",!1),__publicField(this,"eosed",!1),__publicField(this,"filters"),__publicField(this,"alreadyHaveEvent"),__publicField(this,"receivedEvent"),__publicField(this,"onevent"),__publicField(this,"oneose"),__publicField(this,"onclose"),__publicField(this,"eoseTimeout"),__publicField(this,"eoseTimeoutHandle"),this.relay=e,this.filters=n,this.id=t,this.alreadyHaveEvent=r.alreadyHaveEvent,this.receivedEvent=r.receivedEvent,this.eoseTimeout=r.eoseTimeout||e.baseEoseTimeout,this.oneose=r.oneose,this.onclose=r.onclose,this.onevent=r.onevent||(e=>{console.warn(`onevent() callback not defined for subscription '${this.id}' in relay ${this.relay.url}. event received:`,e)})}fire(){this.relay.send('["REQ","'+this.id+'",'+JSON.stringify(this.filters).substring(1)),this.eoseTimeoutHandle=setTimeout(this.receivedEose.bind(this),this.eoseTimeout)}receivedEose(){this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,this.oneose?.())}close(e="closed by caller"){if(!this.closed&&this.relay.connected){try{this.relay.send('["CLOSE",'+JSON.stringify(this.id)+"]")}catch(t){if(!(t instanceof Sc))throw t}this.closed=!0}this.relay.openSubs.delete(this.id),this.onclose?.(e)}};try{WebSocket}catch{}var Pc,Cc=class{constructor(e){__publicField(this,"relays",new Map),__publicField(this,"seenOn",new Map),__publicField(this,"trackRelays",!1),__publicField(this,"verifyEvent"),__publicField(this,"enablePing"),__publicField(this,"trustedRelayURLs",new Set),__publicField(this,"_WebSocket"),this.verifyEvent=e.verifyEvent,this._WebSocket=e.websocketImplementation,this.enablePing=e.enablePing}async ensureRelay(e,t){e=Ia(e);let n=this.relays.get(e);return n||(n=new xc(e,{verifyEvent:this.trustedRelayURLs.has(e)?Tc:this.verifyEvent,websocketImplementation:this._WebSocket,enablePing:this.enablePing}),n.onclose=()=>{this.relays.delete(e)},t?.connectionTimeout&&(n.connectionTimeout=t.connectionTimeout),this.relays.set(e,n)),await n.connect(),n}close(e){e.map(Ia).forEach(e=>{this.relays.get(e)?.close(),this.relays.delete(e)})}subscribe(e,t,n){n.onauth=n.onauth||n.doauth;const r=[];for(let i=0;i<e.length;i++){const n=Ia(e[i]);r.find(e=>e.url===n)||r.push({url:n,filter:t})}return this.subscribeMap(r,n)}subscribeMany(e,t,n){n.onauth=n.onauth||n.doauth;const r=[],i=[];for(let s=0;s<e.length;s++){const n=Ia(e[s]);-1===i.indexOf(n)&&(i.push(n),r.push({url:n,filter:t}))}return this.subscribeMap(r,n)}subscribeMap(e,t){t.onauth=t.onauth||t.doauth;const n=new Map;for(const u of e){const{url:e,filter:t}=u;n.has(e)||n.set(e,[]),n.get(e).push(t)}const r=Array.from(n.entries()).map(([e,t])=>({url:e,filters:t}));this.trackRelays&&(t.receivedEvent=(e,t)=>{let n=this.seenOn.get(t);n||(n=new Set,this.seenOn.set(t,n)),n.add(e)});const i=new Set,s=[],a=[];let o=n=>{a[n]||(a[n]=!0,a.filter(e=>e).length===e.length&&(t.oneose?.(),o=()=>{}))};const c=[];let A=(n,r)=>{c[n]||(o(n),c[n]=r,c.filter(e=>e).length===e.length&&(t.onclose?.(c),A=()=>{}))};const l=e=>{if(t.alreadyHaveEvent?.(e))return!0;const n=i.has(e);return i.add(e),n},f=Promise.all(r.map(async({url:e,filters:n},r)=>{let i;try{i=await this.ensureRelay(e,{connectionTimeout:t.maxWait?Math.max(.8*t.maxWait,t.maxWait-1e3):void 0})}catch(c){return void A(r,c?.message||String(c))}let a=i.subscribe(n,{...t,oneose:()=>o(r),onclose:e=>{e.startsWith("auth-required: ")&&t.onauth?i.auth(t.onauth).then(()=>{i.subscribe(n,{...t,oneose:()=>o(r),onclose:e=>{A(r,e)},alreadyHaveEvent:l,eoseTimeout:t.maxWait})}).catch(e=>{A(r,`auth was required and attempted, but failed with: ${e}`)}):A(r,e)},alreadyHaveEvent:l,eoseTimeout:t.maxWait});s.push(a)}));return{async close(e){await f,s.forEach(t=>{t.close(e)})}}}subscribeEose(e,t,n){n.onauth=n.onauth||n.doauth;const r=this.subscribe(e,t,{...n,oneose(){r.close("closed automatically on eose")}});return r}subscribeManyEose(e,t,n){n.onauth=n.onauth||n.doauth;const r=this.subscribeMany(e,t,{...n,oneose(){r.close("closed automatically on eose")}});return r}async querySync(e,t,n){return new Promise(async r=>{const i=[];this.subscribeEose(e,t,{...n,onevent(e){i.push(e)},onclose(e){r(i)}})})}async get(e,t,n){t.limit=1;const r=await this.querySync(e,t,n);return r.sort((e,t)=>t.created_at-e.created_at),r[0]||null}publish(e,t,n){return e.map(Ia).map(async(e,r,i)=>{if(i.indexOf(e)!==r)return Promise.reject("duplicate url");let s=await this.ensureRelay(e);return s.publish(t).catch(async e=>{if(e instanceof Error&&e.message.startsWith("auth-required: ")&&n?.onauth)return await s.auth(n.onauth),s.publish(t);throw e}).then(e=>{if(this.trackRelays){let e=this.seenOn.get(t.id);e||(e=new Set,this.seenOn.set(t.id,e)),e.add(s)}return e})})}listConnectionStatus(){const e=new Map;return this.relays.forEach((t,n)=>e.set(n,t.connected)),e}destroy(){this.relays.forEach(e=>e.close()),this.relays=new Map}};try{Pc=WebSocket}catch{}var Nc=class extends Cc{constructor(e){super({verifyEvent:Ga,websocketImplementation:Pc,...e})}};Ea({},{BECH32_REGEX:()=>Bc,Bech32MaxSize:()=>Rc,NostrTypeGuard:()=>Oc,decode:()=>$c,decodeNostrURI:()=>Mc,encodeBytes:()=>jc,naddrEncode:()=>qc,neventEncode:()=>zc,noteEncode:()=>Uc,nprofileEncode:()=>Hc,npubEncode:()=>Gc,nsecEncode:()=>Fc});var Oc={isNProfile:e=>/^nprofile1[a-z\d]+$/.test(e||""),isNEvent:e=>/^nevent1[a-z\d]+$/.test(e||""),isNAddr:e=>/^naddr1[a-z\d]+$/.test(e||""),isNSec:e=>/^nsec1[a-z\d]{58}$/.test(e||""),isNPub:e=>/^npub1[a-z\d]{58}$/.test(e||""),isNote:e=>/^note1[a-z\d]+$/.test(e||""),isNcryptsec:e=>/^ncryptsec1[a-z\d]+$/.test(e||"")},Rc=5e3,Bc=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function Mc(e){try{return e.startsWith("nostr:")&&(e=e.substring(6)),$c(e)}catch(t){return{type:"invalid",data:null}}}function $c(e){let{prefix:t,words:n}=Ms.decode(e,Rc),r=new Uint8Array(Ms.fromWords(n));switch(t){case"nprofile":{let e=Dc(r);if(!e[0]?.[0])throw new Error("missing TLV 0 for nprofile");if(32!==e[0][0].length)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:qi(e[0][0]),relays:e[1]?e[1].map(e=>Sa.decode(e)):[]}}}case"nevent":{let e=Dc(r);if(!e[0]?.[0])throw new Error("missing TLV 0 for nevent");if(32!==e[0][0].length)throw new Error("TLV 0 should be 32 bytes");if(e[2]&&32!==e[2][0].length)throw new Error("TLV 2 should be 32 bytes");if(e[3]&&4!==e[3][0].length)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:qi(e[0][0]),relays:e[1]?e[1].map(e=>Sa.decode(e)):[],author:e[2]?.[0]?qi(e[2][0]):void 0,kind:e[3]?.[0]?parseInt(qi(e[3][0]),16):void 0}}}case"naddr":{let e=Dc(r);if(!e[0]?.[0])throw new Error("missing TLV 0 for naddr");if(!e[2]?.[0])throw new Error("missing TLV 2 for naddr");if(32!==e[2][0].length)throw new Error("TLV 2 should be 32 bytes");if(!e[3]?.[0])throw new Error("missing TLV 3 for naddr");if(4!==e[3][0].length)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:Sa.decode(e[0][0]),pubkey:qi(e[2][0]),kind:parseInt(qi(e[3][0]),16),relays:e[1]?e[1].map(e=>Sa.decode(e)):[]}}}case"nsec":return{type:t,data:r};case"npub":case"note":return{type:t,data:qi(r)};default:throw new Error(`unknown prefix ${t}`)}}function Dc(e){let t={},n=e;for(;n.length>0;){let e=n[0],r=n[1],i=n.slice(2,2+r);if(n=n.slice(2+r),i.length<r)throw new Error(`not enough data to read on TLV ${e}`);t[e]=t[e]||[],t[e].push(i)}return t}function Fc(e){return jc("nsec",e)}function Gc(e){return jc("npub",Qi(e))}function Uc(e){return jc("note",Qi(e))}function Lc(e,t){let n=Ms.toWords(t);return Ms.encode(e,n,Rc)}function jc(e,t){return Lc(e,t)}function Hc(e){return Lc("nprofile",Qc({0:[Qi(e.pubkey)],1:(e.relays||[]).map(e=>xa.encode(e))}))}function zc(e){let t;return void 0!==e.kind&&(t=function(e){const t=new Uint8Array(4);return t[0]=e>>24&255,t[1]=e>>16&255,t[2]=e>>8&255,t[3]=255&e,t}(e.kind)),Lc("nevent",Qc({0:[Qi(e.id)],1:(e.relays||[]).map(e=>xa.encode(e)),2:e.author?[Qi(e.author)]:[],3:t?[new Uint8Array(t)]:[]}))}function qc(e){let t=new ArrayBuffer(4);return new DataView(t).setUint32(0,e.kind,!1),Lc("naddr",Qc({0:[xa.encode(e.identifier)],1:(e.relays||[]).map(e=>xa.encode(e)),2:[Qi(e.pubkey)],3:[new Uint8Array(t)]}))}function Qc(e){let t=[];return Object.entries(e).reverse().forEach(([e,n])=>{n.forEach(n=>{let r=new Uint8Array(n.length+2);r.set([parseInt(e)],0),r.set([n.length],1),r.set(n,2),t.push(r)})}),Ji(...t)}function Vc(e,t,n){const r=e instanceof Uint8Array?qi(e):e,i=Kc(Ei.getSharedSecret(r,"02"+t));let s=Uint8Array.from(Yi(16)),a=xa.encode(n),o=sa(i,s).encrypt(a);return`${ks.encode(new Uint8Array(o))}?iv=${ks.encode(new Uint8Array(s.buffer))}`}function Jc(e,t,n){const r=e instanceof Uint8Array?qi(e):e;let[i,s]=n.split("?iv="),a=Kc(Ei.getSharedSecret(r,"02"+t)),o=ks.decode(s),c=ks.decode(i),A=sa(a,o).decrypt(c);return Sa.decode(A)}function Kc(e){return e.slice(1,33)}Ea({},{decrypt:()=>Jc,encrypt:()=>Vc}),Ea({},{NIP05_REGEX:()=>Yc,isNip05:()=>Zc,isValid:()=>nA,queryProfile:()=>tA,searchDomain:()=>eA,useFetchImplementation:()=>Xc});var Wc,Yc=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,Zc=e=>Yc.test(e||"");try{Wc=fetch}catch(fH){}function Xc(e){Wc=e}async function eA(e,t=""){try{const n=`https://${e}/.well-known/nostr.json?name=${t}`,r=await Wc(n,{redirect:"manual"});if(200!==r.status)throw Error("Wrong response code");return(await r.json()).names}catch(fH){return{}}}async function tA(e){const t=e.match(Yc);if(!t)return null;const[,n="_",r]=t;try{const e=`https://${r}/.well-known/nostr.json?name=${n}`,t=await Wc(e,{redirect:"manual"});if(200!==t.status)throw Error("Wrong response code");const i=await t.json(),s=i.names[n];return s?{pubkey:s,relays:i.relays?.[s]}:null}catch(i){return null}}async function nA(e,t){const n=await tA(t);return!!n&&n.pubkey===e}function rA(e){const t={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]};let n,r;for(let i=e.tags.length-1;i>=0;i--){const s=e.tags[i];if("e"===s[0]&&s[1]){const[e,i,a,o,c]=s,A={id:i,relays:a?[a]:[],author:c};if("root"===o){t.root=A;continue}if("reply"===o){t.reply=A;continue}if("mention"===o){t.mentions.push(A);continue}n?r=A:n=A,t.mentions.push(A);continue}if("q"===s[0]&&s[1]){const[e,n,r]=s;t.quotes.push({id:n,relays:r?[r]:[]})}"p"===s[0]&&s[1]&&t.profiles.push({pubkey:s[1],relays:s[2]?[s[2]]:[]})}return t.root||(t.root=r||n||t.reply),t.reply||(t.reply=n||t.root),[t.reply,t.root].forEach(e=>{if(!e)return;let n=t.mentions.indexOf(e);if(-1!==n&&t.mentions.splice(n,1),e.author){let n=t.profiles.find(t=>t.pubkey===e.author);n&&n.relays&&(e.relays||(e.relays=[]),n.relays.forEach(t=>{-1===e.relays?.indexOf(t)&&e.relays.push(t)}),n.relays=e.relays)}}),t.mentions.forEach(e=>{if(e.author){let n=t.profiles.find(t=>t.pubkey===e.author);n&&n.relays&&(e.relays||(e.relays=[]),n.relays.forEach(t=>{-1===e.relays.indexOf(t)&&e.relays.push(t)}),n.relays=e.relays)}}),t}Ea({},{parse:()=>rA}),Ea({},{fetchRelayInformation:()=>sA,useFetchImplementation:()=>iA});try{fetch}catch{}function iA(e){}async function sA(e){return await(await fetch(e.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}function aA(e){let t=0;for(let n=0;n<64;n+=8){const r=parseInt(e.substring(n,n+8),16);if(0!==r){t+=Math.clz32(r);break}t+=32}return t}function oA(e,t){let n=0;const r=e,i=["nonce",n.toString(),t.toString()];for(r.tags.push(i);;){const e=Math.floor((new Date).getTime()/1e3);if(e!==r.created_at&&(n=0,r.created_at=e),i[1]=(++n).toString(),r.id=cA(r),aA(r.id)>=t)break}return r}function cA(e){return qi(As(xa.encode(JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]))))}Ea({},{fastEventHash:()=>cA,getPow:()=>aA,minePow:()=>oA}),Ea({},{unwrapEvent:()=>OA,unwrapManyEvents:()=>RA,wrapEvent:()=>CA,wrapManyEvents:()=>NA}),Ea({},{createRumor:()=>EA,createSeal:()=>kA,createWrap:()=>TA,unwrapEvent:()=>IA,unwrapManyEvents:()=>PA,wrapEvent:()=>SA,wrapManyEvents:()=>xA}),Ea({},{decrypt:()=>mA,encrypt:()=>pA,getConversationKey:()=>fA,v2:()=>yA});var AA=1,lA=65535;function fA(e,t){const n=Ei.getSharedSecret(e,"02"+t).subarray(1,33);return r=As,i=n,es.hash(r),ba(r,Vi("nip44-v2"),Vi(i));var r,i}function uA(e,t){const n=function(e,t,n,r=32){if(es.hash(e),es.number(r),r>255*e.outputLen)throw new Error("Length should be <= 255*HashLen");const i=Math.ceil(r/e.outputLen);void 0===n&&(n=va);const s=new Uint8Array(i*e.outputLen),a=ba.create(e,t),o=a._cloneInto(),c=new Uint8Array(a.outputLen);for(let A=0;A<i;A++)wa[0]=A+1,o.update(0===A?va:c).update(n).update(wa).digestInto(c),s.set(c,e.outputLen*A),a._cloneInto(o);return a.destroy(),o.destroy(),c.fill(0),wa.fill(0),s.slice(0,r)}(As,e,t,76);return{chacha_key:n.subarray(0,32),chacha_nonce:n.subarray(32,44),hmac_key:n.subarray(44,76)}}function dA(e){if(!Number.isSafeInteger(e)||e<1)throw new Error("expected positive integer");if(e<=32)return 32;const t=1<<Math.floor(Math.log2(e-1))+1,n=t<=256?32:t/8;return n*(Math.floor((e-1)/n)+1)}function hA(e,t,n){if(32!==n.length)throw new Error("AAD associated data must be 32 bytes");const r=Ji(n,t);return ba(As,e,r)}function pA(e,t,n=Yi(32)){const{chacha_key:r,chacha_nonce:i,hmac_key:s}=uA(t,n),a=function(e){const t=xa.encode(e),n=t.length;return Ji(function(e){if(!Number.isSafeInteger(e)||e<AA||e>lA)throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");const t=new Uint8Array(2);return new DataView(t.buffer).setUint16(0,e,!1),t}(n),t,new Uint8Array(dA(n)-n))}(e),o=ya(r,i,a),c=hA(s,o,n);return ks.encode(Ji(new Uint8Array([2]),n,o,c))}function mA(e,t){const{nonce:n,ciphertext:r,mac:i}=function(e){if("string"!=typeof e)throw new Error("payload must be a valid string");const t=e.length;if(t<132||t>87472)throw new Error("invalid payload length: "+t);if("#"===e[0])throw new Error("unknown encryption version");let n;try{n=ks.decode(e)}catch(s){throw new Error("invalid base64: "+s.message)}const r=n.length;if(r<99||r>65603)throw new Error("invalid data length: "+r);const i=n[0];if(2!==i)throw new Error("unknown encryption version "+i);return{nonce:n.subarray(1,33),ciphertext:n.subarray(33,-32),mac:n.subarray(-32)}}(e),{chacha_key:s,chacha_nonce:a,hmac_key:o}=uA(t,n);if(!function(e,t){if(e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return 0===n}(hA(o,r,n),i))throw new Error("invalid MAC");return function(e){const t=new DataView(e.buffer).getUint16(0),n=e.subarray(2,2+t);if(t<AA||t>lA||n.length!==t||e.length!==2+dA(t))throw new Error("invalid padding");return Sa.decode(n)}(ya(s,a,r))}var yA={utils:{getConversationKey:fA,calcPaddedLen:dA},encrypt:pA,decrypt:mA},gA=()=>Math.round(Date.now()/1e3),bA=()=>Math.round(gA()-172800*Math.random()),wA=(e,t)=>fA(e,t),vA=(e,t,n)=>pA(JSON.stringify(e),wA(t,n)),_A=(e,t)=>JSON.parse(mA(e.content,wA(t,e.pubkey)));function EA(e,t){const n={created_at:gA(),content:"",tags:[],...e,pubkey:Da(t)};return n.id=Ba(n),n}function kA(e,t,n){return Fa({kind:to,content:vA(e,t,n),created_at:bA(),tags:[]},t)}function TA(e,t){const n=$a();return Fa({kind:lo,content:vA(e,n,t),created_at:bA(),tags:[["p",t]]},n)}function SA(e,t,n){return TA(kA(EA(e,t),t,n),n)}function xA(e,t,n){if(!n||0===n.length)throw new Error("At least one recipient is required.");const r=Da(t),i=[SA(e,t,r)];return n.forEach(n=>{i.push(SA(e,t,n))}),i}function IA(e,t){const n=_A(e,t);return _A(n,t)}function PA(e,t){let n=[];return e.forEach(e=>{n.push(IA(e,t))}),n.sort((e,t)=>e.created_at-t.created_at),n}function CA(e,t,n,r,i){const s=function(e,t,n,r){const i={created_at:Math.ceil(Date.now()/1e3),kind:no,tags:[],content:t};return(Array.isArray(e)?e:[e]).forEach(({publicKey:e,relayUrl:t})=>{i.tags.push(t?["p",e,t]:["p",e])}),r&&i.tags.push(["e",r.eventId,r.relayUrl||"","reply"]),n&&i.tags.push(["subject",n]),i}(t,n,r,i);return SA(s,e,t.publicKey)}function NA(e,t,n,r,i){if(!t||0===t.length)throw new Error("At least one recipient is required.");return[{publicKey:Da(e)},...t].map(t=>CA(e,t,n,r,i))}var OA=IA,RA=PA;function BA(e,t,n,r){let i;const s=[...e.tags??[],["e",t.id,n],["p",t.pubkey]];return t.kind===Va?i=Za:(i=ro,s.push(["k",String(t.kind)])),Fa({kind:i,tags:s,content:""===e.content||t.tags?.find(e=>"-"===e[0])?"":JSON.stringify(t),created_at:e.created_at},r)}function MA(e){if(![Za,ro].includes(e.kind))return;let t,n;for(let r=e.tags.length-1;r>=0&&(void 0===t||void 0===n);r--){const i=e.tags[r];i.length>=2&&("e"===i[0]&&void 0===t?t=i:"p"===i[0]&&void 0===n&&(n=i))}return void 0!==t?{id:t[1],relays:[t[2],n?.[2]].filter(e=>"string"==typeof e),author:n?.[1]}:void 0}function $A(e,{skipVerification:t}={}){const n=MA(e);if(void 0===n||""===e.content)return;let r;try{r=JSON.parse(e.content)}catch(i){return}return r.id===n.id&&(t||Ga(r))?r:void 0}Ea({},{finishRepostEvent:()=>BA,getRepostedEvent:()=>$A,getRepostedEventPointer:()=>MA}),Ea({},{NOSTR_URI_REGEX:()=>DA,parse:()=>GA,test:()=>FA});var DA=new RegExp(`nostr:(${Bc.source})`);function FA(e){return"string"==typeof e&&new RegExp(`^${DA.source}$`).test(e)}function GA(e){const t=e.match(new RegExp(`^${DA.source}$`));if(!t)throw new Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:$c(t[1])}}function UA(e,t,n){const r=t.tags.filter(e=>e.length>=2&&("e"===e[0]||"p"===e[0]));return Fa({...e,kind:Xa,tags:[...e.tags??[],...r,["e",t.id],["p",t.pubkey]],content:e.content??"+"},n)}function LA(e){if(e.kind!==Xa)return;let t,n;for(let r=e.tags.length-1;r>=0&&(void 0===t||void 0===n);r--){const i=e.tags[r];i.length>=2&&("e"===i[0]&&void 0===t?t=i:"p"===i[0]&&void 0===n&&(n=i))}return void 0!==t&&void 0!==n?{id:t[1],relays:[t[2],n[2]].filter(e=>void 0!==e),author:n[1]}:void 0}Ea({},{finishReactionEvent:()=>UA,getReactedEventPointer:()=>LA}),Ea({},{parse:()=>zA});var jA=/\W/m,HA=/\W |\W$|$|,| /m;function*zA(e){const t=e.length;let n=0,r=0;for(;r<t;){let s=e.indexOf(":",r);if(-1===s)break;if("nostr"===e.substring(s-5,s)){const a=e.substring(s+60).match(jA),o=a?s+60+a.index:t;try{let t,{data:i,type:a}=$c(e.substring(s+1,o));switch(a){case"npub":t={pubkey:i};break;case"nsec":case"note":r=o+1;continue;default:t=i}n!==s-5&&(yield{type:"text",text:e.substring(n,s-5)}),yield{type:"reference",pointer:t},r=o,n=r;continue}catch(i){r=s+1;continue}}else if("https"===e.substring(s-5,s)||"http"===e.substring(s-4,s)){const a=e.substring(s+4).match(HA),o=a?s+4+a.index:t,c="s"===e[s-1]?5:4;try{let t=new URL(e.substring(s-c,o));if(-1===t.hostname.indexOf("."))throw new Error("invalid url");if(n!==s-c&&(yield{type:"text",text:e.substring(n,s-c)}),/\.(png|jpe?g|gif|webp)$/i.test(t.pathname)){yield{type:"image",url:t.toString()},r=o,n=r;continue}if(/\.(mp4|avi|webm|mkv)$/i.test(t.pathname)){yield{type:"video",url:t.toString()},r=o,n=r;continue}if(/\.(mp3|aac|ogg|opus)$/i.test(t.pathname)){yield{type:"audio",url:t.toString()},r=o,n=r;continue}yield{type:"url",url:t.toString()},r=o,n=r;continue}catch(i){r=o+1;continue}}else{if("wss"!==e.substring(s-3,s)&&"ws"!==e.substring(s-2,s)){r=s+1;continue}{const a=e.substring(s+4).match(HA),o=a?s+4+a.index:t,c="s"===e[s-1]?3:2;try{let t=new URL(e.substring(s-c,o));if(-1===t.hostname.indexOf("."))throw new Error("invalid ws url");n!==s-c&&(yield{type:"text",text:e.substring(n,s-c)}),yield{type:"relay",url:t.toString()},r=o,n=r;continue}catch(i){r=o+1;continue}}}}n!==t&&(yield{type:"text",text:e.substring(n)})}Ea({},{channelCreateEvent:()=>qA,channelHideMessageEvent:()=>JA,channelMessageEvent:()=>VA,channelMetadataEvent:()=>QA,channelMuteUserEvent:()=>KA});var qA=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return Fa({kind:io,tags:[...e.tags??[]],content:n,created_at:e.created_at},t)},QA=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return Fa({kind:so,tags:[["e",e.channel_create_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},VA=(e,t)=>{const n=[["e",e.channel_create_event_id,e.relay_url,"root"]];return e.reply_to_channel_message_event_id&&n.push(["e",e.reply_to_channel_message_event_id,e.relay_url,"reply"]),Fa({kind:ao,tags:[...n,...e.tags??[]],content:e.content,created_at:e.created_at},t)},JA=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return Fa({kind:oo,tags:[["e",e.channel_message_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},KA=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return Fa({kind:co,tags:[["p",e.pubkey_to_mute],...e.tags??[]],content:n,created_at:e.created_at},t)};Ea({},{EMOJI_SHORTCODE_REGEX:()=>ZA,matchAll:()=>el,regex:()=>XA,replaceAll:()=>tl});var WA,YA,ZA=/:(\w+):/,XA=()=>new RegExp(`\\B${ZA.source}\\B`,"g");function*el(e){const t=e.matchAll(XA());for(const r of t)try{const[e,t]=r;yield{shortcode:e,name:t,start:r.index,end:r.index+e.length}}catch(n){}}function tl(e,t){return e.replaceAll(XA(),(e,n)=>t({shortcode:e,name:n}))}Ea({},{useFetchImplementation:()=>nl,validateGithub:()=>rl});try{WA=fetch}catch{}function nl(e){WA=e}async function rl(e,t,n){try{return await(await WA(`https://gist.github.com/${t}/${n}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch(fH){return!1}}function il(e){const{host:t,pathname:n,searchParams:r}=new URL(e),i=n||t,s=r.get("relay"),a=r.get("secret");if(!i||!s||!a)throw new Error("invalid connection string");return{pubkey:i,relay:s,secret:a}}async function sl(e,t,n){const r={method:"pay_invoice",params:{invoice:n}},i=Vc(t,e,JSON.stringify(r)),s={kind:Lo,created_at:Math.round(Date.now()/1e3),content:i,tags:[["p",e]]};return Fa(s,t)}function al(e){return e=(e=e.trim().toLowerCase()).normalize("NFKC"),Array.from(e).map(e=>/\p{Letter}/u.test(e)||/\p{Number}/u.test(e)?e:"-").join("")}Ea({},{makeNwcRequestEvent:()=>sl,parseConnectionString:()=>il}),Ea({},{normalizeIdentifier:()=>al}),Ea({},{getSatoshisAmountFromBolt11:()=>ul,getZapEndpoint:()=>cl,makeZapReceipt:()=>fl,makeZapRequest:()=>Al,useFetchImplementation:()=>ol,validateZapRequest:()=>ll});try{YA=fetch}catch{}function ol(e){YA=e}async function cl(e){try{let t="",{lud06:n,lud16:r}=JSON.parse(e.content);if(n){let{words:e}=Ms.decode(n,1e3),r=Ms.fromWords(e);t=Sa.decode(r)}else{if(!r)return null;{let[e,n]=r.split("@");t=new URL(`/.well-known/lnurlp/${e}`,`https://${n}`).toString()}}let i=await YA(t),s=await i.json();if(s.allowsNostr&&s.nostrPubkey)return s.callback}catch(t){}return null}function Al(e){let t={kind:9734,created_at:Math.round(Date.now()/1e3),content:e.comment||"",tags:[["p","pubkey"in e?e.pubkey:e.event.pubkey],["amount",e.amount.toString()],["relays",...e.relays]]};if("event"in e){if(t.tags.push(["e",e.event.id]),La(e.event.kind)){const n=["a",`${e.event.kind}:${e.event.pubkey}:`];t.tags.push(n)}else if(Ha(e.event.kind)){let n=e.event.tags.find(([e,t])=>"d"===e&&t);if(!n)throw new Error("d tag not found or is empty");const r=["a",`${e.event.kind}:${e.event.pubkey}:${n[1]}`];t.tags.push(r)}t.tags.push(["k",e.event.kind.toString()])}return t}function ll(e){let t;try{t=JSON.parse(e)}catch(i){return"Invalid zap request JSON."}if(!Ta(t))return"Zap request is not a valid Nostr event.";if(!Ga(t))return"Invalid signature on zap request.";let n=t.tags.find(([e,t])=>"p"===e&&t);if(!n)return"Zap request doesn't have a 'p' tag.";if(!n[1].match(/^[a-f0-9]{64}$/))return"Zap request 'p' tag is not valid hex.";let r=t.tags.find(([e,t])=>"e"===e&&t);return r&&!r[1].match(/^[a-f0-9]{64}$/)?"Zap request 'e' tag is not valid hex.":t.tags.find(([e,t])=>"relays"===e&&t)?null:"Zap request doesn't have a 'relays' tag."}function fl({zapRequest:e,preimage:t,bolt11:n,paidAt:r}){let i=JSON.parse(e),s=i.tags.filter(([e])=>"e"===e||"p"===e||"a"===e),a={kind:9735,created_at:Math.round(r.getTime()/1e3),content:"",tags:[...s,["P",i.pubkey],["bolt11",n],["description",e]]};return t&&a.tags.push(["preimage",t]),a}function ul(e){if(e.length<50)return 0;const t=(e=e.substring(0,50)).lastIndexOf("1");if(-1===t)return 0;const n=e.substring(0,t);if(!n.startsWith("lnbc"))return 0;const r=n.substring(4);if(r.length<1)return 0;const i=r[r.length-1],s=i.charCodeAt(0)-"0".charCodeAt(0),a=s>=0&&s<=9;let o=r.length-1;if(a&&o++,o<1)return 0;const c=parseInt(r.substring(0,o));switch(i){case"m":return 1e5*c;case"u":return 100*c;case"n":return c/10;case"p":return c/1e4;default:return 1e8*c}}Ea({},{getToken:()=>hl,hashPayload:()=>vl,unpackEventFromToken:()=>ml,validateEvent:()=>El,validateEventKind:()=>gl,validateEventMethodTag:()=>wl,validateEventPayloadTag:()=>_l,validateEventTimestamp:()=>yl,validateEventUrlTag:()=>bl,validateToken:()=>pl});var dl="Nostr ";async function hl(e,t,n,r=!1,i){const s={kind:zo,tags:[["u",e],["method",t]],created_at:Math.round((new Date).getTime()/1e3),content:""};i&&s.tags.push(["payload",vl(i)]);const a=await n(s);return(r?dl:"")+ks.encode(xa.encode(JSON.stringify(a)))}async function pl(e,t,n){const r=await ml(e).catch(e=>{throw e});return await El(r,t,n).catch(e=>{throw e})}async function ml(e){if(!e)throw new Error("Missing token");e=e.replace(dl,"");const t=Sa.decode(ks.decode(e));if(!t||0===t.length||!t.startsWith("{"))throw new Error("Invalid token");return JSON.parse(t)}function yl(e){return!!e.created_at&&Math.round((new Date).getTime()/1e3)-e.created_at<60}function gl(e){return e.kind===zo}function bl(e,t){const n=e.tags.find(e=>"u"===e[0]);return!!n&&n.length>0&&n[1]===t}function wl(e,t){const n=e.tags.find(e=>"method"===e[0]);return!!n&&n.length>0&&n[1].toLowerCase()===t.toLowerCase()}function vl(e){return qi(As(xa.encode(JSON.stringify(e))))}function _l(e,t){const n=e.tags.find(e=>"payload"===e[0]);if(!n)return!1;const r=vl(t);return n.length>0&&n[1]===r}async function El(e,t,n,r){if(!Ga(e))throw new Error("Invalid nostr event, signature invalid");if(!gl(e))throw new Error("Invalid nostr event, kind invalid");if(!yl(e))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!bl(e,t))throw new Error("Invalid nostr event, url tag invalid");if(!wl(e,n))throw new Error("Invalid nostr event, method tag invalid");if(Boolean(r)&&"object"==typeof r&&Object.keys(r).length>0&&!_l(e,r))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}class kl{constructor(e,t={}){this.storage=e,this.queuePrefix="_outbox/",this.maxRetries=t.maxRetries||5,this.baseDelay=t.baseDelay||1e3,this.maxDelay=t.maxDelay||6e4,this.failedTTL=t.failedTTL||864e5}async enqueue(e,t){const n={id:e.id,event:e,relays:t,status:"pending",retries:0,createdAt:Date.now(),nextRetryAt:Date.now(),failedRelays:[]},r=`${this.queuePrefix}${e.id}`;return await this.storage.put(r,n),n}async markSent(e,t){const n=`${this.queuePrefix}${e}`,r=await this.storage.get(n);r&&(t.length>0?await this.storage.delete(n):await this._scheduleRetry(n,r))}async _scheduleRetry(e,t){if(t.retries++,t.retries>=this.maxRetries)t.status="failed",t.failedAt=Date.now();else{t.status="pending";const e=Math.min(this.baseDelay*Math.pow(2,t.retries)+1e3*Math.random(),this.maxDelay);t.nextRetryAt=Date.now()+e}await this.storage.put(e,t)}async getPendingEvents(){const e=await this.storage.getAll(this.queuePrefix),t=Date.now();return e.filter(e=>e&&"pending"===e.status&&e.nextRetryAt<=t).sort((e,t)=>e.createdAt-t.createdAt)}async getFailedEvents(){return(await this.storage.getAll(this.queuePrefix)).filter(e=>e&&"failed"===e.status)}async getStats(){const e=await this.storage.getAll(this.queuePrefix),t={total:e.length,pending:0,failed:0,oldestPending:null,oldestFailed:null};for(const n of e)n&&("pending"===n.status?(t.pending++,(!t.oldestPending||n.createdAt<t.oldestPending)&&(t.oldestPending=n.createdAt)):"failed"===n.status&&(t.failed++,(!t.oldestFailed||n.failedAt<t.oldestFailed)&&(t.oldestFailed=n.failedAt)));return t}async purgeOldFailed(e=this.failedTTL){const t=await this.storage.getAll(this.queuePrefix),n=Date.now();let r=0;for(const i of t)i&&"failed"===i.status&&n-i.failedAt>e&&(await this.storage.delete(`${this.queuePrefix}${i.id}`),r++);return r}async clear(){const e=await this.storage.getAll(this.queuePrefix);let t=0;for(const n of e)n&&n.id&&(await this.storage.delete(`${this.queuePrefix}${n.id}`),t++);return t}async retryFailed(e){const t=`${this.queuePrefix}${e}`,n=await this.storage.get(t);return n&&"failed"===n.status?(n.status="pending",n.retries=0,n.nextRetryAt=Date.now(),delete n.failedAt,await this.storage.put(t,n),n):null}}class Tl{constructor(e,t={}){this.client=e,this.interval=t.interval||1e4,this.running=!1,this.timer=null,this._processing=!1,t.autoStart&&this.start()}start(){this.running||(this.running=!0,this._scheduleNextRun())}stop(){this.running=!1,this.timer&&(clearTimeout(this.timer),this.timer=null)}isRunning(){return this.running}async syncNow(){return this._processOutbox()}_scheduleNextRun(){this.running&&(this.timer=setTimeout(()=>{this._runLoop()},this.interval))}async _runLoop(){if(this.running){try{await this._processOutbox()}catch(e){console.warn("[sync] Outbox processing failed:",e.message)}this._scheduleNextRun()}}async _processOutbox(){if(this._processing)return{skipped:!0,reason:"already processing"};this._processing=!0;const e={processed:0,succeeded:0,failed:0,purged:0};try{if(!this.client.outboxQueue)return{...e,skipped:!0,reason:"no outbox queue"};const n=await this.client.outboxQueue.getPendingEvents();e.processed=n.length;for(const r of n)try{(await this.client._attemptDelivery(r.event,r.relays)).successful.length>0?e.succeeded++:e.failed++}catch(t){console.warn(`[sync] Retry failed for ${r.id}:`,t.message),e.failed++}e.purged=await this.client.outboxQueue.purgeOldFailed()}finally{this._processing=!1}return e}async getStats(){const e={running:this.running,interval:this.interval,queue:null};return this.client.outboxQueue&&(e.queue=await this.client.outboxQueue.getStats()),e}}class Sl{async init(e){throw new Error("init() must be implemented by subclass")}async put(e,t){throw new Error("put() must be implemented by subclass")}async get(e){throw new Error("get() must be implemented by subclass")}async getAll(e){throw new Error("getAll() must be implemented by subclass")}async delete(e){throw new Error("delete() must be implemented by subclass")}async clear(){throw new Error("clear() must be implemented by subclass")}async close(){throw new Error("close() must be implemented by subclass")}}let xl=null,Il=new Set;const Pl=new Map,Cl=new Map,Nl=new Map,Ol=3e4,Rl=new Map,Bl=new Map;class Ml{constructor(e=500){this.maxSize=e,this.cache=new Map}get(e){if(!this.cache.has(e))return;const t=this.cache.get(e);return this.cache.delete(e),this.cache.set(e,t),t}set(e,t){for(this.cache.has(e)&&this.cache.delete(e),this.cache.set(e,t);this.cache.size>this.maxSize;){const e=this.cache.keys().next().value;this.cache.delete(e)}}has(e){return this.cache.has(e)}delete(e){return this.cache.delete(e)}clear(){this.cache.clear()}get size(){return this.cache.size}keys(){return this.cache.keys()}values(){return this.cache.values()}entries(){return this.cache.entries()}forEach(e){this.cache.forEach(e)}}let $l=null;class Dl{constructor(e={}){if(e.relays&&!Array.isArray(e.relays))throw new Error("Relays must be an array");this.relays=e.relays||[],this.privateKey=e.privateKey||this._generatePrivateKey(),this.publicKey=Da(this.privateKey),this.config=e,this._subscriptions=new Map,this._eventCache=new Ml(e.cacheSize||500),this._cacheIndex=new Map,this.persistentStorage=null,this._persistQueue=new Map,this._persistTimer=null,this._persistBatchMs=e.persistBatchMs||100,this._initReady=this._initialize()}async _initialize(){await(void 0!==globalThis.WebSocket?Promise.resolve():($l||($l=(async()=>{try{const{default:e}=await Promise.resolve().then(()=>PU);globalThis.WebSocket=e}catch(e){}})()),$l)),this.relays.length>0?(this.pool=function(e={}){return xl||(xl=new Nc({enableReconnect:!1!==e.enableReconnect,enablePing:!1!==e.enablePing})),xl}(this.config),this.relays.forEach(e=>Il.add(e))):this.pool={publish:(e,t)=>[Promise.resolve()],querySync:(e,t,n)=>Promise.resolve([]),subscribeMany:(e,t,n)=>({close:()=>{}}),close:e=>{}},await this._initPersistentStorage(),this.relays.length>0&&this._initLongLivedSubscription()}_initLongLivedSubscription(){const e=this.publicKey;if(Bl.has(e))return;const t={subscription:null,initialized:!1,initPromise:null,initResolve:null};t.initPromise=new Promise(e=>{t.initResolve=e}),Bl.set(e,t);const n={kinds:[3e4],authors:[this.publicKey]},r=this.pool.subscribeMany(this.relays,[n],{onevent:e=>{e.pubkey===this.publicKey&&this._cacheEvent(e)},oneose:()=>{t.initialized||(t.initialized=!0,t.initResolve())}});t.subscription=r,setTimeout(()=>{t.initialized||(t.initialized=!0,t.initResolve())},5e3)}async _waitForSubscriptionInit(){const e=Bl.get(this.publicKey);e&&e.initPromise&&await e.initPromise}async _initPersistentStorage(){if(!1!==this.config.persistence&&(this.config.radisk||this.config.appName))try{const e=this.config.appName||"holosphere_default";this.persistentStorage=await async function(e){const t="undefined"!=typeof window&&void 0!==window.indexedDB;if("undefined"!=typeof process&&process.versions,t){const{IndexedDBStorage:t}=await Promise.resolve().then(()=>TU),n=new t;return await n.init(e),n}{const{MemoryStorage:t}=await Promise.resolve().then(()=>xU),n=new t;return await n.init(e),n}}(e,this.config.dataDir),await this._loadFromPersistentStorage(),this.outboxQueue=new kl(this.persistentStorage,{maxRetries:this.config.maxRetries||5,baseDelay:this.config.retryBaseDelay||1e3,maxDelay:this.config.retryMaxDelay||6e4,failedTTL:this.config.failedTTL||864e5}),!1!==this.config.backgroundSync&&(this.syncService=new Tl(this,{interval:this.config.syncInterval||1e4,autoStart:!0}))}catch(e){console.warn("Failed to initialize persistent storage:",e)}}async _loadFromPersistentStorage(){if(this.persistentStorage)try{const e=await this.persistentStorage.getAll("");for(const t of e)t&&t.id&&!t.status&&this._cacheEventSync(t)}catch(e){console.warn("Failed to load from persistent storage:",e)}}async persistentGet(e){if(await this._initReady,!this.persistentStorage)return null;try{return await this.persistentStorage.get(e)||null}catch(t){return console.warn("[nostr] Persistent storage read failed:",t),null}}async persistentGetAll(e){if(await this._initReady,!this.persistentStorage)return[];try{return(await this.persistentStorage.getAll(e)).filter(e=>e&&e.id&&!e.status)}catch(t){return console.warn("[nostr] Persistent storage read failed:",t),[]}}_generatePrivateKey(){const e=new Uint8Array(32);if("undefined"!=typeof window&&window.crypto)window.crypto.getRandomValues(e);else try{const t=globalThis.crypto||globalThis.crypto;if(t&&t.getRandomValues)t.getRandomValues(e);else for(let n=0;n<32;n++)e[n]=Math.floor(256*Math.random())}catch(t){for(let n=0;n<32;n++)e[n]=Math.floor(256*Math.random())}return Array.from(e).map(e=>e.toString(16).padStart(2,"0")).join("")}async publish(e,t={}){await this._initReady;const n=t.waitForRelays||!1;if(e.kind>=3e4&&e.kind<4e4&&!1!==t.debounce&&!n){const n=e.tags?.find(e=>"d"===e[0]);if(n&&n[1])return this._debouncedPublish(e,n[1],t)}return this._doPublish(e,t)}_debouncedPublish(e,t,n){return new Promise((r,i)=>{const s=Rl.get(t);s&&(clearTimeout(s.timer),s.resolve({event:null,results:[],debounced:!0,supersededBy:e}));const a=setTimeout(async()=>{Rl.delete(t);try{const t=await this._doPublish(e,n);r(t)}catch(s){i(s)}},500);Rl.set(t,{event:e,timer:a,resolve:r,reject:i});const o=Fa(e,this.privateKey);this._cacheEvent(o)})}async _doPublish(e,t={}){const n=t.waitForRelays||!1,r=e.id&&e.sig?e:Fa(e,this.privateKey);return await this._cacheEvent(r),this.outboxQueue&&await this.outboxQueue.enqueue(r,this.relays),n?{event:r,results:(await this._attemptDelivery(r,this.relays)).results,queued:!!this.outboxQueue}:(this._attemptDelivery(r,this.relays).catch(()=>{}),{event:r,results:[],queued:!!this.outboxQueue})}async _attemptDelivery(e,t){const n=await Promise.allSettled(this.pool.publish(t,e)),r=[],i=[],s=[];if(n.forEach((e,n)=>{s.push({relay:t[n],status:e.status,value:e.value,reason:e.reason}),"fulfilled"===e.status?r.push(t[n]):i.push(t[n])}),this.outboxQueue&&await this.outboxQueue.markSent(e.id,r),i.length>0&&0===r.length){const t=n.filter(e=>"rejected"===e.status).map(e=>e.reason?.message||e.reason||"unknown").join(", ");t.includes("timed out")||console.warn(`[nostr] All relays failed for ${e.id.slice(0,8)}: ${t}`)}return{successful:r,failed:i,results:s}}async query(e,t={}){await this._initReady;const n=void 0!==t.timeout?t.timeout:3e4,r=!1!==t.localFirst,i=!0===t.forceRelay;if(0===this.relays.length)return this._getMatchingCachedEvents(e);const s=Bl.get(this.publicKey),a=e.authors&&1===e.authors.length&&e.authors[0]===this.publicKey;if(!i&&a&&s&&s.initialized)return this._getMatchingCachedEvents(e);if(a&&s&&!s.initialized&&(await Promise.race([s.initPromise,new Promise(e=>setTimeout(e,Math.min(n,5e3)))]),s.initialized))return this._getMatchingCachedEvents(e);if(e["#d"]&&1===e["#d"].length&&e.kinds&&1===e.kinds.length){const t=`d:${e.kinds[0]}:${e["#d"][0]}`,n=this._eventCache.get(t);if(n&&Date.now()-n.timestamp<5e3)return n.events}const o=JSON.stringify(e),c=this._eventCache.get(o);return c&&Date.now()-c.timestamp<5e3?c.events:r&&c?(this._refreshCacheInBackground(e,o,n),c.events):this._queryRelaysAndCache(e,o,n)}async _queryRelaysAndCache(e,t,n){const r=Pl.get(t);if(r&&Date.now()-r.timestamp<5e3)return r.promise;const i=(async()=>{try{let r=await this.pool.querySync(this.relays,e,{timeout:n});return e.authors&&e.authors.length>0&&(r=r.filter(t=>e.authors.includes(t.pubkey))),this._eventCache.set(t,{events:r,timestamp:Date.now()}),this._indexCacheEntry(t,e),r}finally{Pl.delete(t)}})();return Pl.set(t,{promise:i,timestamp:Date.now()}),i}_limitCacheSize(){}_indexCacheEntry(e,t){if(t.kinds)for(const n of t.kinds)this._cacheIndex.has(n)||this._cacheIndex.set(n,new Set),this._cacheIndex.get(n).add(e)}_unindexCacheEntry(e){if(e.startsWith("{"))try{const t=JSON.parse(e);if(t.kinds)for(const n of t.kinds){const t=this._cacheIndex.get(n);t&&(t.delete(e),0===t.size&&this._cacheIndex.delete(n))}}catch{}}_refreshCacheInBackground(e,t,n){this._queryRelaysAndCache(e,t,n).catch(e=>{console.debug("[nostr] Background cache refresh failed:",e.message)})}refreshPathInBackground(e,t=3e4,n={}){this._doBackgroundPathRefresh(e,t,n).catch(e=>{console.debug("[nostr] Background path refresh failed:",e.message)})}async _doBackgroundPathRefresh(e,t,n){if(0===this.relays.length)return;const r=Nl.get(e);if(r&&Date.now()-r<Ol)return;if(Nl.set(e,Date.now()),Nl.size>1e3){const e=Date.now()-Ol;for(const[t,n]of Nl)n<e&&Nl.delete(t)}const i={kinds:[t],authors:n.authors||[this.publicKey],"#d":[e],limit:1},s=JSON.stringify(i),a=n.timeout||3e4,o=(await this._queryRelaysAndCache(i,s,a)).filter(e=>(n.authors||[this.publicKey]).includes(e.pubkey));o.length>0&&await this._cacheEvent(o[0])}refreshPrefixInBackground(e,t=3e4,n={}){this._doBackgroundPrefixRefresh(e,t,n).catch(e=>{console.debug("[nostr] Background prefix refresh failed:",e.message)})}async _doBackgroundPrefixRefresh(e,t,n){if(0===this.relays.length)return;const r=`prefix:${e}`,i=Nl.get(r);if(i&&Date.now()-i<Ol)return;Nl.set(r,Date.now());const s={kinds:[t],authors:n.authors||[this.publicKey],limit:n.limit||1e3},a=JSON.stringify(s),o=n.timeout||3e4;let c=await this._queryRelaysAndCache(s,a,o);c=c.filter(e=>(n.authors||[this.publicKey]).includes(e.pubkey)),c=c.filter(t=>{const n=t.tags.find(e=>"d"===e[0]);return n&&n[1]&&n[1].startsWith(e)});for(const A of c)await this._cacheEvent(A)}async queryHybrid(e,t={}){await this._initReady;const n=void 0!==t.timeout?t.timeout:3e4,r=this._getMatchingCachedEvents(e);if(0===this.relays.length)return r;let i=[];try{i=await this.pool.querySync(this.relays,e,{timeout:n}),e.authors&&e.authors.length>0&&(i=i.filter(t=>e.authors.includes(t.pubkey)))}catch(c){console.warn("Relay query failed, using local cache only:",c.message)}const s=new Map;for(const A of r){const e=this._getEventKey(A);s.set(e,A)}for(const A of i){const e=this._getEventKey(A),t=s.get(e);A.kind>=3e4&&A.kind<4e4&&t?A.created_at>=t.created_at&&s.set(e,A):s.set(e,A)}const a=Array.from(s.values()),o=JSON.stringify(e);return this._eventCache.set(o,{events:a,timestamp:Date.now()}),a}_getEventKey(e){if(e.kind>=3e4&&e.kind<4e4){const t=e.tags.find(e=>"d"===e[0]);if(t&&t[1])return`${e.kind}:${t[1]}`}return e.id}async subscribe(e,t,n={}){await this._initReady;const r=`sub-${Date.now()}-${Math.random().toString(36).slice(2,11)}`,i=JSON.stringify(e);if(0===this.relays.length){const i=this._getMatchingCachedEvents(e),s={filter:e,onEvent:t,active:!0};return this._subscriptions.set(r,s),setTimeout(()=>{s.active&&(i.forEach(e=>t(e)),n.onEOSE&&n.onEOSE())},10),{id:r,unsubscribe:()=>{s.active=!1,this._subscriptions.delete(r),s.onEvent=()=>{}}}}const s=Cl.get(i);if(s)return s.callbacks.add(t),s.refCount++,{id:r,unsubscribe:()=>{s.callbacks.delete(t),s.refCount--,0===s.refCount&&(s.subscription&&s.subscription.close&&s.subscription.close(),Cl.delete(i)),this._subscriptions.delete(r)}};const a=new Set([t]),o={callbacks:a,refCount:1,subscription:null};Cl.set(i,o);const c=this.pool.subscribeMany(this.relays,[e],{onevent:t=>{if(e.authors&&e.authors.length>0&&!e.authors.includes(t.pubkey))return;this._cacheEvent(t);const n=Cl.get(i);if(n)for(const e of n.callbacks)try{e(t)}catch(r){console.warn("[nostr] Subscription callback error:",r.message)}},oneose:()=>{n.onEOSE&&n.onEOSE()}});return o.subscription=c,this._subscriptions.set(r,c),{id:r,unsubscribe:()=>{a.delete(t),o.refCount--,0===o.refCount&&(c.close&&c.close(),Cl.delete(i)),this._subscriptions.delete(r)}}}_cacheEventSync(e){const t=e.id;if(this._eventCache.set(t,{events:[e],timestamp:Date.now()}),e.kind>=3e4&&e.kind<4e4){const t=e.tags.find(e=>"d"===e[0]);if(t&&t[1]){const n=`d:${e.kind}:${t[1]}`,r=this._eventCache.get(n);(!r||!r.events[0]||e.created_at>r.events[0].created_at||e.created_at===r.events[0].created_at&&e.id!==r.events[0].id)&&(this._eventCache.set(n,{events:[e],timestamp:Date.now()}),r&&r.events[0]&&this._eventCache.delete(r.events[0].id),this._invalidateQueryCachesForEvent(e))}}}_invalidateQueryCachesForEvent(e){const t=this._cacheIndex.get(e.kind);if(!t||0===t.size)return;const n=[];for(const r of t)if(this._eventCache.get(r))try{const t=JSON.parse(r);this._eventMatchesFilter(e,t)&&n.push(r)}catch{t.delete(r)}else t.delete(r);for(const r of n)this._eventCache.delete(r),this._unindexCacheEntry(r)}async _cacheEvent(e){if(this._cacheEventSync(e),this.persistentStorage){let t=e.id;if(e.kind>=3e4&&e.kind<4e4){const n=e.tags.find(e=>"d"===e[0]);n&&n[1]&&(t=n[1])}this._persistQueue.set(t,e),this._persistTimer||(this._persistTimer=setTimeout(()=>this._flushPersistQueue(),this._persistBatchMs))}if(0===this.relays.length)for(const t of this._subscriptions.values())t.active&&this._eventMatchesFilter(e,t.filter)&&setTimeout(()=>{t.active&&t.onEvent(e)},10)}async _flushPersistQueue(){if(this._persistTimer=null,!this.persistentStorage||0===this._persistQueue.size)return;const e=Array.from(this._persistQueue.entries());this._persistQueue.clear();const t=e.map(async([e,t])=>{try{await this.persistentStorage.put(e,t)}catch(n){console.warn(`Failed to persist event ${e}:`,n.message)}});await Promise.all(t)}_getMatchingCachedEvents(e){const t=[],n=new Map;for(const r of this._eventCache.values())for(const i of r.events||[])if(this._eventMatchesFilter(i,e)){if(i.kind>=3e4&&i.kind<4e4){const e=i.tags.find(e=>"d"===e[0]);if(e&&e[1]){const r=`${i.kind}:${e[1]}`,s=n.get(r);if(!s||i.created_at>s.created_at||i.created_at===s.created_at&&JSON.parse(i.content)?._deleted&&!JSON.parse(s.content)?._deleted){if(s){const e=t.indexOf(s);e>-1&&t.splice(e,1)}n.set(r,i),t.push(i)}continue}}t.push(i)}return t}_eventMatchesFilter(e,t){if(t.kinds&&!t.kinds.includes(e.kind))return!1;if(t.ids&&!t.ids.includes(e.id))return!1;if(t.authors&&!t.authors.includes(e.pubkey))return!1;if(t["#d"]){const n=e.tags.find(e=>"d"===e[0]);if(!n||!t["#d"].includes(n[1]))return!1}return!(t.since&&e.created_at<t.since||t.until&&e.created_at>t.until)}async getEvent(e){const t=await this.query({ids:[e]});return t.length>0?t[0]:null}clearCache(e=null){if(e)for(const t of this._eventCache.keys())t.includes(e)&&this._eventCache.delete(t);else this._eventCache.clear()}async close(e={}){!1!==e.flush&&this._persistTimer&&(clearTimeout(this._persistTimer),await this._flushPersistQueue()),this.syncService&&this.syncService.stop();const t=Bl.get(this.publicKey);t&&t.subscription&&(t.subscription.close&&t.subscription.close(),Bl.delete(this.publicKey));for(const n of this._subscriptions.values())n.close?n.close():void 0!==n.active&&(n.active=!1);this._subscriptions.clear(),this.pool.close(this.relays),this._eventCache.clear(),this._cacheIndex.clear()}getRelayStatus(){return this.relays.map(e=>({url:e,connected:!0}))}}const Fl={nostr:"./backends/nostr-backend.js",gundb:"./backends/gundb-backend.js",activitypub:"./backends/activitypub-backend.js"},Gl=new Map;class Ul{static getAvailableBackends(){return Object.keys(Fl)}static isAvailable(e){return e in Fl}static async loadBackend(e){if(Gl.has(e))return Gl.get(e);const t=Fl[e];if(!t)throw new Error(`Unknown backend type: '${e}'. Available backends: ${Object.keys(Fl).join(", ")}`);try{const r=await import(t),i=r.default||r[`${n=e,n.charAt(0).toUpperCase()+n.slice(1)}Backend`];if(!i)throw new Error(`Backend module '${e}' does not export a valid backend class`);return Gl.set(e,i),i}catch(r){if("ERR_MODULE_NOT_FOUND"===r.code)throw new Error(`Backend '${e}' requires additional dependencies. Please install them: ${function(e){return{nostr:"npm install nostr-tools",gundb:"npm install gun",activitypub:"npm install express"}[e]||"Check the documentation for required dependencies"}(e)}`);throw r}var n}static async create(e,t){const n=new(await this.loadBackend(e))(t);return await n.init(),n}static register(e,t){"string"==typeof t?Fl[e]=t:(Gl.set(e,t),Fl[e]=null)}}function Ll(e,t=1e3){return new Promise((n,r)=>{let i=!1;const s=setTimeout(()=>{i||(i=!0,n(null))},t);e.once(e=>{i||(i=!0,clearTimeout(s),n(e||null))})})}function jl(e,t,n=1e3){return new Promise((r,i)=>{let s=!1;const a=setTimeout(()=>{s||(s=!0,r({ok:!0,timeout:!0}))},n);e.put(t,e=>{s||(s=!0,clearTimeout(a),e.err?i(new Error(e.err)):r(e))})})}async function Hl(e,t=5e3){return new Promise(n=>{const r={};let i=!1,s=0,a=0;e.once(t=>{if(i)return;if(!t)return i=!0,void n({});const o=Object.keys(t).filter(e=>"_"!==e);if(0===o.length)return i=!0,void n({});for(const e of o){const n=t[e];n&&("object"==typeof n&&n["#"]||(r[e]=n))}s=o.length,e.map().once((e,t)=>{i||!e||t.startsWith("_")||(r[t]=e,a++,i||s>0&&a>=s&&(i=!0,n(r)))})}),setTimeout(()=>{i||(i=!0,n(r))},t)})}function zl(e,t,n,r=null){const i=Ql(t),s=Ql(n);return r?`${e}/${i}/${s}/${Ql(r)}`:`${e}/${i}/${s}`}function ql(e,t,n=null){const r=Ql(t);return n?`${e}/${r}/${Ql(n)}`:`${e}/${r}`}function Ql(e){return encodeURIComponent(e).replace(/%2F/g,"/")}function Vl(e,t){const n=t.split("/").filter(e=>e.length>0);let r=e;for(const i of n)r=r.get(i);return r}function Jl(e){return JSON.stringify(e)}function Kl(e){if(!e)return null;try{if("string"==typeof e)try{return JSON.parse(e)}catch(t){return e}if(e._json&&"string"==typeof e._json)try{return JSON.parse(e._json)}catch(t){return console.warn("Failed to parse _json field:",t),null}if(e._&&e._["#"])return e;if(e._&&e._[">"]){const n=Object.entries(e).find(([e,t])=>"_"!==e&&"string"==typeof t);if(n)try{return JSON.parse(n[1])}catch(t){return n[1]}}if("object"==typeof e&&null!==e){const t={...e};return delete t._,0===Object.keys(t).length?null:t}return e}catch(n){return console.warn("Error deserializing Gun data:",n),e}}async function Wl(e,t,n){try{const r=Jl(n),i=t.split("/").filter(e=>e.length>0);console.log("[gun-wrapper] write:",{path:t,parts:i,dataId:n?.id});const s=Vl(e,t);console.log("[gun-wrapper] write ref soul:",s?._.get);const a=await jl(s,r,5e3);return console.log("[gun-wrapper] write ack:",{ok:a.ok,timeout:a.timeout}),a.timeout&&console.warn("[gun-wrapper] write timed out (data may not be persisted):",t),console.log("[gun-wrapper] write complete:",t),{ok:!0,timeout:a.timeout||!1}}catch(r){throw console.error("[gun-wrapper] write error:",r),r}}async function Yl(e,t){const n=t.split("/").filter(e=>e.length>0);console.log("[gun-wrapper] read:",{path:t,parts:n});const r=Vl(e,t);console.log("[gun-wrapper] read ref soul:",r?._.get);const i=await Ll(r,2e3);if(console.log("[gun-wrapper] read rawData:",i?"string"==typeof i?i.substring(0,100):"object":"null"),!i)return null;const s=Kl(i);return!s||s._deleted?null:s}async function Zl(e,t,n=5e3){const r=t.split("/").filter(e=>e.length>0);return console.log("[gun-wrapper] readAll:",{path:t,parts:r}),new Promise(r=>{const i=new Map;let s=!1,a=0,o=0;const c=Vl(e,t);console.log("[gun-wrapper] readAll ref soul:",c?._.get);const A=e=>Kl(e);c.once(e=>{if(s)return;if(console.log("[gun-wrapper] readAll parentData:",e),console.log("[gun-wrapper] readAll parentData keys:",e?Object.keys(e).filter(e=>"_"!==e):"null"),console.log("[gun-wrapper] readAll parentData type:",typeof e),!e)return s=!0,console.log("[gun-wrapper] readAll: no parent data, returning empty"),void r([]);const t=Object.keys(e).filter(e=>"_"!==e);if(console.log("[gun-wrapper] readAll keys:",t),0===t.length)return s=!0,console.log("[gun-wrapper] readAll: no keys, returning empty"),void r([]);for(const n of t){const t=e[n];if(!t)continue;if("object"==typeof t&&t["#"])continue;const r=A(t);r&&r.id&&!r._deleted&&i.set(r.id,r)}if(a=t.length,0===a)return s=!0,void r(Array.from(i.values()));c.map().once((e,t)=>{if(s||!e||"_"===t)return;const n=A(e);n&&n.id&&!n._deleted&&(i.has(n.id)||i.set(n.id,n)),o++,s||a>0&&o>=a&&(s=!0,console.log("[gun-wrapper] readAll resolved with",i.size,"items"),r(Array.from(i.values())))})}),setTimeout(()=>{s||(s=!0,r(Array.from(i.values())))},n)})}async function Xl(e,t,n){const r=await Ll(Vl(e,t));if(!r)return!1;const i=Kl(r);if(!i||!i.id||i._deleted)return!1;const s={...i,...n};try{const n=Jl(s);return await jl(Vl(e,t),n,2e3),await new Promise(e=>setTimeout(e,200)),!0}catch(a){throw a}}async function ef(e,t){try{const n=await Ll(Vl(e,t));if(!n)return!0;const r=Kl(n),i={id:r?.id,_deleted:!0,_deletedAt:Date.now()};return await jl(Vl(e,t),Jl(i),2e3),await new Promise(e=>setTimeout(e,200)),!0}catch(n){throw n}}async function tf(e,t){const n=await Zl(e,t);let r=0;for(const i of n)if(i&&i.id){const n=`${t}/${i.id}`;await ef(e,n),r++}return{success:!0,count:r}}function nf(e,t,n,r={}){const i=t.split("/");if(void 0!==r.prefix?r.prefix:i.length<=3){const r=Vl(e,t);return r.map().on((e,t)=>{if(e&&!t.startsWith("_")){const r=Kl(e);r&&!r._deleted&&n(r,t)}}),{unsubscribe:()=>{try{r.off()}catch(e){}}}}{const r=Vl(e,t).on((e,t)=>{if(e){const r=Kl(e);r&&!r._deleted&&n(r,t)}});return{unsubscribe:()=>{try{r.off()}catch(e){}}}}}async function rf(e,t,n,r){if(!r||!r.id)throw new Error("writeGlobal: data must have an id field");return Wl(e,ql(t,n,r.id),r)}async function sf(e,t,n,r){return Yl(e,ql(t,n,r))}async function af(e,t,n,r=2e3){return Zl(e,ql(t,n))}async function of(e,t,n,r){return ef(e,ql(t,n,r))}async function cf(e,t,n){return tf(e,ql(t,n))}function Af(e){return Kl(e)}const lf=Object.freeze(Object.defineProperty({__proto__:null,buildGlobalPath:ql,buildPath:zl,deleteAll:tf,deleteAllGlobal:cf,deleteData:ef,deleteGlobal:of,parse:Af,read:Yl,readAll:Zl,readAllGlobal:af,readGlobal:sf,serialize:function(e){return Jl(e)},subscribe:nf,update:Xl,write:Wl,writeGlobal:rf},Symbol.toStringTag,{value:"Module"}));async function ff(e,t){if(!t)throw new Error("getFederation: Missing space ID");return e.readGlobal("federation",t)}async function uf(e,t,n){const r=`${t}_${n}_fedmsgs`;return e.readGlobal("federation_messages",r)}class df{constructor(e){if(new.target===df)throw new Error("StorageBackend is abstract and cannot be instantiated directly");this.config=e,this.publicKey=null}async init(){throw new Error("init() must be implemented by subclass")}buildPath(e,t,n,r=null){throw new Error("buildPath() must be implemented by subclass")}async write(e,t,n={}){throw new Error("write() must be implemented by subclass")}async read(e,t={}){throw new Error("read() must be implemented by subclass")}async readAll(e,t={}){throw new Error("readAll() must be implemented by subclass")}async update(e,t){throw new Error("update() must be implemented by subclass")}async delete(e){throw new Error("delete() must be implemented by subclass")}async deleteAll(e){throw new Error("deleteAll() must be implemented by subclass")}async subscribe(e,t,n={}){throw new Error("subscribe() must be implemented by subclass")}async exportData(e=""){throw new Error("exportData() must be implemented by subclass")}async importData(e,t={}){throw new Error("importData() must be implemented by subclass")}close(){throw new Error("close() must be implemented by subclass")}getStatus(){throw new Error("getStatus() must be implemented by subclass")}}class hf{constructor(e){this.appname=e}createReference(e,t,n){if(!n||!n.id)throw new Error("createReference: data must have an id field");return{id:n.id,soul:`${this.appname}/${e}/${t}/${n.id}`}}isReference(e){return!!(e&&(e.soul&&e.id&&Object.keys(e).filter(e=>!e.startsWith("_")).length<=2||e._federation&&e._federation.isReference||e._&&e._["#"]))}parseSoulPath(e){if(!e||"string"!=typeof e)return null;const t=e.split("/");return t.length<4?null:{appname:t[0],holon:t[1],lens:t[2],key:t.slice(3).join("/")}}async resolveReference(e,t,n={}){const{followReferences:r=!0}=n;if(!t)return null;let i=null,s=null;if(t.soul)i=t.soul;else if(t._federation&&t._federation.isReference){const e=t._federation;e.origin&&e.lens&&t.id&&(i=`${this.appname}/${e.origin}/${e.lens}/${t.id}`,s=e)}else t._&&t._["#"]&&(i=t._["#"]);if(!i)return null;const a=this.parseSoulPath(i);if(!a)return null;try{const t=`${a.appname}/${a.holon}/${a.lens}/${a.key}`,n=await Yl(e,t);if(!n)return null;if(r&&this.isReference(n)){const t=await this.resolveReference(e,n,{followReferences:!0});if(t)return{...t,_federation:{resolved:!0,soul:i,origin:a.holon,lens:a.lens,timestamp:Date.now()}}}return{...n,_federation:{resolved:!0,soul:i,origin:s?.origin||a.holon,lens:s?.lens||a.lens,timestamp:Date.now()}}}catch(o){return console.warn("Error resolving reference:",o),null}}getSoul(e,t,n){return`${this.appname}/${e}/${t}/${n}`}}class pf{constructor(e,t){this.gun=e,this.appname=t,this.user=null,this.authenticated=!1,this.currentHolonId=null}userName(e){return`${this.appname}:${e}`}async authenticate(e,t){if(!e||!t)throw new Error("authenticate: holonId and password are required");const n=this.userName(e);return this.user=this.gun.user(),new Promise((r,i)=>{this.user.auth(n,t,t=>{t.err?(this.authenticated=!1,this.currentHolonId=null,i(new Error(t.err))):(this.authenticated=!0,this.currentHolonId=e,r(this.user))})})}async createUser(e,t){if(!e||!t)throw new Error("createUser: holonId and password are required");const n=this.userName(e);return this.user=this.gun.user(),new Promise((r,i)=>{this.user.create(n,t,s=>{s.err?i(new Error(s.err)):this.user.auth(n,t,t=>{t.err?i(new Error(t.err)):(this.authenticated=!0,this.currentHolonId=e,r(this.user))})})})}logout(){this.user&&this.user.leave(),this.authenticated=!1,this.currentHolonId=null,this.user=null}isAuthenticated(){return this.authenticated&&null!==this.user}getPrivatePath(e,t=null){if(!this.isAuthenticated())throw new Error("Not authenticated");const n=this.user.get("private").get(e);return t?n.get(t):n}async writePrivate(e,t,n){if(!this.isAuthenticated())throw new Error("Not authenticated");if(!n||!t)throw new Error("writePrivate: key and data are required");try{const r=JSON.stringify(n);return await jl(this.getPrivatePath(e,t),r,2e3),!0}catch(r){throw r}}async readPrivate(e,t){if(!this.isAuthenticated())throw new Error("Not authenticated");try{const r=await Ll(this.getPrivatePath(e,t),2e3);if(!r)return null;if("string"==typeof r)try{return JSON.parse(r)}catch(n){return r}if(r._json&&"string"==typeof r._json)try{return JSON.parse(r._json)}catch(n){return null}if("object"==typeof r){const e={...r};return delete e._,e}return null}catch(r){throw r}}async readAllPrivate(e,t=5e3){if(!this.isAuthenticated())throw new Error("Not authenticated");return new Promise(n=>{const r=[],i=new Set,s=this.getPrivatePath(e);let a=!1,o=0,c=0;const A=e=>{if(!e)return null;let t=null;if("string"==typeof e)try{t=JSON.parse(e)}catch(n){t=e}else if(e._json&&"string"==typeof e._json)try{t=JSON.parse(e._json)}catch(n){}else"object"==typeof e&&(t={...e},delete t._);return t};s.once(e=>{if(a)return;if(!e)return a=!0,void n([]);const t=Object.keys(e).filter(e=>"_"!==e);if(0===t.length)return a=!0,void n([]);for(const n of t){const t=e[n];if(!t)continue;if("object"==typeof t&&t["#"])continue;const s=A(t);!s||s._deleted||i.has(n)||(i.add(n),r.push(s))}o=t.length,s.map().once((e,t)=>{if(!a&&e&&!t.startsWith("_")){if(!i.has(t)){i.add(t);const n=A(e);n&&!n._deleted&&r.push(n)}c++,a||o>0&&c>=o&&(a=!0,n(r))}})}),setTimeout(()=>{a||(a=!0,n(r))},t)})}async deletePrivate(e,t){if(!this.isAuthenticated())throw new Error("Not authenticated");try{const n=await this.readPrivate(e,t),r={id:n?.id||t,_deleted:!0,_deletedAt:Date.now()};return await jl(this.getPrivatePath(e,t),JSON.stringify(r)),!0}catch(n){throw n}}}const mf={type:"object",required:["type"],properties:{$schema:{type:"string"},$id:{type:"string"},type:{type:"string"},properties:{type:"object"},required:{type:"array",items:{type:"string"}},additionalProperties:{type:"boolean"}}};class yf{constructor(e={}){this.strict=e.strict||!1,this.cacheMaxAge=e.cacheMaxAge||36e5,this.schemaCache=new Map,this.validator=null,this.Ajv=null}async init(){if(this.validator)return!0;try{const e=await Promise.resolve().then(()=>DL);return this.Ajv=e.default||e,this.validator=new this.Ajv({allErrors:!0,strict:!1,validateSchema:!0}),!0}catch(e){return console.warn("AJV not available, schema validation disabled:",e.message),!1}}async setSchema(e,t,n,r){if(!r||"object"!=typeof r)throw new Error("setSchema: schema must be an object");if(this.strict&&this.validator&&!this.validateSchema(mf,r))throw new Error("setSchema: Invalid schema definition");const i={id:n,lens:n,schema:r,timestamp:Date.now()};return await rf(e,t,"schemas",i),this.schemaCache.set(n,{schema:r,timestamp:Date.now()}),!0}async getSchema(e,t,n,r={}){const{useCache:i=!0}=r;if(i){const e=this.schemaCache.get(n);if(e&&Date.now()-e.timestamp<this.cacheMaxAge)return e.schema}const s=await sf(e,t,"schemas",n);return s&&s.schema?(this.schemaCache.set(n,{schema:s.schema,timestamp:Date.now()}),s.schema):null}async getAllSchemas(e,t){return af(e,t,"schemas")}async deleteSchema(e,t,n){return this.schemaCache.delete(n),of(e,t,"schemas",n)}validate(e,t){if(!this.validator)return{valid:!0,errors:[]};try{const n=this.validator.compile(e),r=n(t);return{valid:r,errors:r?[]:this.formatErrors(n.errors)}}catch(n){return{valid:!1,errors:[{message:n.message,path:""}]}}}async validateData(e,t,n,r){const i=await this.getSchema(e,t,n);return i?this.validate(i,r):{valid:!0,errors:[]}}validateSchema(e,t){if(!this.validator)return!0;try{return this.validator.compile(e)(t)}catch(n){return!1}}formatErrors(e){return e?e.map(e=>({message:e.message||"Validation error",path:e.instancePath||e.dataPath||"",keyword:e.keyword,params:e.params})):[]}clearCache(e=null){e?this.schemaCache.delete(e):this.schemaCache.clear()}isStrict(){return this.strict}setStrict(e){this.strict=e}}class gf extends df{constructor(e){super(e),this.gun=null,this.keyPair=null,this.appName=e.appName||"holosphere",this.references=null,this.auth=null,this.schemaValidator=null,this.subscriptions=new Map,this.subscriptionCounter=0,this.writeCache=new Map,this.writeCacheTTL=3e5,this.pendingWrites=new Map,this.maxWriteRetries=5,this.writeRetryInterval=1e4}async init(){let e;try{console.log("[gundb-backend] Importing Gun...");const t=await Promise.resolve().then(()=>LL);e=t.default||t,console.log("[gundb-backend] Gun imported:",typeof e)}catch(r){throw new Error('GunDB backend requires the "gun" package. Install it with: npm install gun')}const t=this.config.dataDir||"radata",n={peers:this.config.peers||[],radisk:!1!==this.config.radisk,localStorage:!1!==this.config.localStorage,file:t};console.log("[gundb-backend] Gun config:",JSON.stringify(n)),this.gun=e(n),console.log("[gundb-backend] Gun instance created:",!!this.gun);try{const e=`_test_${Date.now()}`;this.gun.get(e).put({test:!0},e=>{console.log("[gundb-backend] Gun test write ack:",e)}),console.log("[gundb-backend] Gun test write initiated")}catch(i){console.error("[gundb-backend] Gun test write failed:",i.message)}await new Promise(e=>setTimeout(e,500));try{const t=e.SEA;t?this.config.privateKey?(this.keyPair={priv:this.config.privateKey,pub:this.config.publicKey},this.publicKey=this.config.publicKey||this.config.privateKey.substring(0,32)):(this.keyPair=await t.pair(),this.publicKey=this.keyPair.pub):this.publicKey=this.appName}catch(r){this.publicKey=this.appName}this.references=new hf(this.appName),this.auth=new pf(this.gun,this.appName),this.schemaValidator=new yf({strict:this.config.strict||!1,cacheMaxAge:this.config.schemaCacheMaxAge||36e5}),await this.schemaValidator.init()}_addToWriteCache(e,t){if(!t||!t.id)return;const n=e.substring(0,e.lastIndexOf("/"));n&&(this.writeCache.has(n)||this.writeCache.set(n,new Map),this.writeCache.get(n).set(t.id.toString(),{data:t,timestamp:Date.now()}))}_removeFromWriteCache(e,t){const n=e.substring(0,e.lastIndexOf("/")),r=this.writeCache.get(n);r&&r.delete(t.toString())}_getWriteCacheEntries(e){const t=this.writeCache.get(e);if(!t)return[];const n=Date.now(),r=[];for(const[i,s]of t)n-s.timestamp<this.writeCacheTTL?r.push(s.data):t.delete(i);return r}_mergeWithWriteCache(e,t){const n=this._getWriteCacheEntries(e);if(0===n.length)return t;const r=new Map;for(const i of t)i&&i.id&&r.set(i.id.toString(),i);for(const i of n)i&&i.id&&!i._deleted?r.set(i.id.toString(),i):i&&i.id&&i._deleted&&r.delete(i.id.toString());return Array.from(r.values())}clearWriteCache(e=null){e?this.writeCache.delete(e):this.writeCache.clear()}buildPath(e,t,n,r=null){return zl(e,t,n,r)}buildGlobalPath(e,t=null){return ql(this.appName,e,t)}async write(e,t,n={}){if(this.schemaValidator&&this.schemaValidator.isStrict()){const n=e.split("/");if(n.length>=3){const e=n[2];if(!this.isReference(t)){const n=await this.schemaValidator.validateData(this.gun,this.appName,e,t);if(!n.valid)throw new Error(`Schema validation failed: ${JSON.stringify(n.errors)}`)}}}return this._addToWriteCache(e,t),await this._writeWithRetry(e,t)}async _writeWithRetry(e,t,n=0){const r=await Wl(this.gun,e,t);return r.timeout&&n<this.maxWriteRetries?(this.pendingWrites.set(e,{data:t,retries:n+1,lastAttempt:Date.now()}),this._scheduleRetry(e)):r.timeout||this.pendingWrites.delete(e),r}_scheduleRetry(e){setTimeout(async()=>{const t=this.pendingWrites.get(e);if(t){if(t.retries>=this.maxWriteRetries)return console.warn(`[gundb-backend] Max retries reached for: ${e}`),void this.pendingWrites.delete(e);console.log(`[gundb-backend] Retrying write (attempt ${t.retries+1}): ${e}`),await this._writeWithRetry(e,t.data,t.retries)}},this.writeRetryInterval)}async read(e,t={}){const n=await Yl(this.gun,e);return n&&t.resolveReferences&&this.isReference(n)?this.resolveReference(n):n}async readAll(e,t={}){const n=await Zl(this.gun,e),r=this._mergeWithWriteCache(e,n);if(t.resolveReferences){const e=[];for(const t of r)if(this.isReference(t)){const n=await this.resolveReference(t);n&&e.push(n)}else e.push(t);return e}return r}async update(e,t){return Xl(this.gun,e,t)}async delete(e){const t=await ef(this.gun,e),n=e.split("/"),r=n[n.length-1];if(r){const t=e.substring(0,e.lastIndexOf("/"));this.writeCache.has(t)||this.writeCache.set(t,new Map),this.writeCache.get(t).set(r.toString(),{data:{id:r,_deleted:!0},timestamp:Date.now()})}return t}async deleteAll(e){const t=await this.readAll(e);let n=0;for(const r of t)if(r&&r.id){const t=`${e}/${r.id}`;await ef(this.gun,t),n++}return{success:!0,count:n}}async writeGlobal(e,t){const n=this.buildGlobalPath(e,t.id);return this._addToWriteCache(n,t),await this._writeGlobalWithRetry(e,t)}async _writeGlobalWithRetry(e,t,n=0){const r=this.buildGlobalPath(e,t.id),i=await rf(this.gun,this.appName,e,t);return i.timeout&&n<this.maxWriteRetries?(this.pendingWrites.set(r,{data:{tableName:e,data:t},isGlobal:!0,retries:n+1,lastAttempt:Date.now()}),this._scheduleGlobalRetry(r,e)):i.timeout||this.pendingWrites.delete(r),i}_scheduleGlobalRetry(e,t){setTimeout(async()=>{const n=this.pendingWrites.get(e);if(n&&n.isGlobal){if(n.retries>=this.maxWriteRetries)return console.warn(`[gundb-backend] Max retries reached for global: ${e}`),void this.pendingWrites.delete(e);console.log(`[gundb-backend] Retrying global write (attempt ${n.retries+1}): ${e}`),await this._writeGlobalWithRetry(t,n.data.data,n.retries)}},this.writeRetryInterval)}async readGlobal(e,t){return sf(this.gun,this.appName,e,t)}async readAllGlobal(e,t=5e3){const n=await af(this.gun,this.appName,e,t),r=this.buildGlobalPath(e);return this._mergeWithWriteCache(r,n)}async deleteGlobal(e,t){const n=await of(this.gun,this.appName,e,t),r=this.buildGlobalPath(e);return this.writeCache.has(r)||this.writeCache.set(r,new Map),this.writeCache.get(r).set(t.toString(),{data:{id:t,_deleted:!0},timestamp:Date.now()}),n}async deleteAllGlobal(e){return cf(this.gun,this.appName,e)}createReference(e,t,n){return this.references.createReference(e,t,n)}isReference(e){return this.references.isReference(e)}async resolveReference(e,t={}){return this.references.resolveReference(this.gun,e,t)}parseSoulPath(e){return this.references.parseSoulPath(e)}getSoul(e,t,n){return this.references.getSoul(e,t,n)}async authenticate(e,t){return this.auth.authenticate(e,t)}async createUser(e,t){return this.auth.createUser(e,t)}logout(){this.auth.logout()}isAuthenticated(){return this.auth.isAuthenticated()}async writePrivate(e,t,n){return this.auth.writePrivate(e,t,n)}async readPrivate(e,t){return this.auth.readPrivate(e,t)}async readAllPrivate(e,t=2e3){return this.auth.readAllPrivate(e,t)}async deletePrivate(e,t){return this.auth.deletePrivate(e,t)}async setSchema(e,t){return this.schemaValidator.setSchema(this.gun,this.appName,e,t)}async getSchema(e,t={}){return this.schemaValidator.getSchema(this.gun,this.appName,e,t)}async getAllSchemas(){return this.schemaValidator.getAllSchemas(this.gun,this.appName)}async deleteSchema(e){return this.schemaValidator.deleteSchema(this.gun,this.appName,e)}validate(e,t){return this.schemaValidator.validate(e,t)}async validateData(e,t){return this.schemaValidator.validateData(this.gun,this.appName,e,t)}clearSchemaCache(e=null){this.schemaValidator.clearCache(e)}async subscribe(e,t,n={}){const r=++this.subscriptionCounter,i=e.split("/").length<=3,s={id:r,path:e,active:!0,gunRef:null};if(i){const i=this.gun.get(e);s.gunRef=i,i.map().on(async(e,i)=>{if(!this.subscriptions.get(r)?.active)return;if(!e||i.startsWith("_")||e._deleted)return;let s=Af(e);s&&(n.resolveReferences&&this.isReference(s)&&(s=await this.resolveReference(s)),s&&t(s,i))})}else{const i=this.gun.get(e);s.gunRef=i,i.on(async(e,i)=>{if(!this.subscriptions.get(r)?.active)return;if(!e)return;let s=Af(e);s&&!s._deleted&&(n.resolveReferences&&this.isReference(s)&&(s=await this.resolveReference(s)),s&&t(s,i))})}return this.subscriptions.set(r,s),{id:r,unsubscribe:()=>{const e=this.subscriptions.get(r);if(e){if(e.active=!1,e.gunRef)try{e.gunRef.off()}catch(t){}this.subscriptions.delete(r)}}}}async exportData(e=""){const t=[],n=e||this.appName;try{const e=await Hl(this.gun.get(n),2e3);for(const[r,i]of Object.entries(e))r.startsWith("_")||!i||"object"!=typeof i||i._deleted||await this._collectRecords(n,r,i,t)}catch(r){console.warn("Export data error:",r)}return t}async _collectRecords(e,t,n,r){const i=`${e}/${t}`;if(n.id)r.push({path:i,data:this._cleanGunData(n),timestamp:n._meta?.timestamp||Date.now()});else try{const e=await Hl(this.gun.get(i),500);for(const[t,n]of Object.entries(e))!t.startsWith("_")&&n&&await this._collectRecords(i,t,n,r)}catch(s){}}_cleanGunData(e){const t={...e};return delete t._,t}async importData(e,t={}){const n={success:0,failed:0,errors:[]};for(const i of e)try{await Wl(this.gun,i.path,i.data),n.success++}catch(r){n.failed++,n.errors.push({path:i.path,error:r.message})}return n}close(){for(const[n,r]of this.subscriptions)if(r.active&&(r.active=!1,r.gunRef))try{r.gunRef.off()}catch(e){}if(this.subscriptions.clear(),this.schemaValidator&&this.schemaValidator.clearCache(),this.writeCache.clear(),this.auth&&this.auth.logout(),this.gun)try{const e=this.gun.back("opt.mesh");e&&(e.way&&Object.values(e.way).forEach(e=>{e?.wire?.close&&e.wire.close()}),e.opt?.peers&&(e.opt.peers={}));const t=this.gun.back("opt.web");t?.close&&t.close(),this.gun.off()}catch(t){console.warn("Error during Gun cleanup:",t)}}getStatus(){return{type:"gundb",publicKey:this.publicKey,peers:this.config.peers||[],connected:!!this.gun,authenticated:this.isAuthenticated(),subscriptionCount:this.subscriptions.size,schemaValidationEnabled:this.schemaValidator?.isStrict()||!1}}}const bf="2.0.0-alpha8";function wf(e){if("undefined"!=typeof process&&process.env)return process.env[e]}function vf(){const e=wf("HOLOSPHERE_RELAYS");return e?e.split(",").map(e=>e.trim()).filter(e=>e):["wss://relay.holons.io"]}let _f=class{constructor(e={}){if("string"==typeof e&&(e={appName:e}),e&&"object"!=typeof e)throw new TypeError("Config must be an object");if(void 0!==e.appName&&"string"!=typeof e.appName)throw new TypeError("config.appName must be a string");if(void 0!==e.relays&&!Array.isArray(e.relays))throw new TypeError("config.relays must be an array");if(void 0!==e.logLevel&&!["ERROR","WARN","INFO","DEBUG"].includes(e.logLevel))throw new TypeError("config.logLevel must be one of: ERROR, WARN, INFO, DEBUG");if(void 0!==e.backend&&!Ul.isAvailable(e.backend))throw new TypeError(`config.backend must be one of: ${Ul.getAvailableBackends().join(", ")}`);this.config={appName:e.appName||wf("HOLOSPHERE_APP_NAME")||"holosphere",backend:e.backend||"nostr",relays:e.relays||vf(),privateKey:e.privateKey||wf("HOLOSPHERE_PRIVATE_KEY"),logLevel:e.logLevel||wf("HOLOSPHERE_LOG_LEVEL")||"INFO",hybridMode:!1!==e.hybridMode},this._rawConfig=e,this.logLevels={ERROR:0,WARN:1,INFO:2,DEBUG:3},this.currentLogLevel=this.logLevels[this.config.logLevel]||1,this._backend=null,"nostr"===this.config.backend?this._initNostrSync(e):"gundb"===this.config.backend?this._backendReady=this._initGunDBAsync(e):this._backendReady=this._initBackendAsync(e),this._metrics={writes:0,reads:0,subscriptions:0}}_initNostrSync(e){try{this.client=function(e){return new Dl(e)}({relays:this.config.relays,privateKey:this.config.privateKey,enableReconnect:!1!==e.enableReconnect,enablePing:!1!==e.enablePing,appName:this.config.appName,radisk:!1!==e.radisk,persistence:!1!==e.persistence,dataDir:e.dataDir}),this._logStartup({version:bf,appName:this.config.appName,backend:"nostr",relays:this.config.relays,publicKey:this.client.publicKey,logLevel:this.config.logLevel,persistence:!1!==e.persistence,reconnect:!1!==e.enableReconnect,dataDir:e.dataDir}),this._backendReady=Promise.resolve()}catch(t){throw this._log("ERROR","Nostr client initialization failed",{error:t.message}),new Error(`Nostr client initialization failed: ${t.message}`)}}async _initGunDBAsync(e){try{const t=e.gundb||{};this._backend=new gf({appName:this.config.appName,peers:t.peers||[],radisk:!1!==t.radisk,localStorage:!1!==t.localStorage,dataDir:e.dataDir,privateKey:this.config.privateKey,strict:t.strict||!1,schemaCacheMaxAge:t.schemaCacheMaxAge||36e5}),await this._backend.init(),this.publicKey=this._backend.publicKey,this._gun=this._backend.gun,this.client={publicKey:this.publicKey,gun:this._gun,write:(e,t)=>this._backend.write(e,t),read:(e,t)=>this._backend.read(e,t),readAll:(e,t)=>this._backend.readAll(e,t),update:(e,t)=>this._backend.update(e,t),delete:e=>this._backend.delete(e),subscribe:(e,t,n)=>this._backend.subscribe(e,t,n),buildPath:zl},this._gunWrapper=lf,this._logStartup({version:bf,appName:this.config.appName,backend:"gundb",peers:t.peers||[],publicKey:this.publicKey,logLevel:this.config.logLevel,persistence:!1!==t.radisk,dataDir:e.dataDir})}catch(t){throw this._log("ERROR","GunDB client initialization failed",{error:t.message}),new Error(`GunDB client initialization failed: ${t.message}`)}}async _initBackendAsync(e){const t=this.config.backend,n=e[t]||{};try{const r={appName:this.config.appName,privateKey:this.config.privateKey,persistence:!1!==e.persistence,dataDir:e.dataDir,...n};this._backend=await Ul.create(t,r),this.client=this._backend.client||this._backend,this._logStartup({version:bf,appName:this.config.appName,backend:t,publicKey:this._backend.publicKey,logLevel:this.config.logLevel,persistence:!1!==e.persistence,...this._backend.getStatus()})}catch(r){throw this._log("ERROR",`${t} backend initialization failed`,{error:r.message}),new Error(`${t} backend initialization failed: ${r.message}`)}}async ready(){this._backendReady&&await this._backendReady}get backend(){return this._backend}_log(e,t,n={}){if(this.logLevels[e]<=this.currentLogLevel){const r={timestamp:Date.now(),level:e,message:t,app:this.config.appName,...n};console.log(JSON.stringify(r))}}_logStartup(e){this.currentLogLevel>=this.logLevels.INFO&&(console.log("\n"+"=".repeat(60)),console.log(" HoloSphere - Holonic Geospatial Infrastructure"),console.log("=".repeat(60)),console.log(` Version: ${e.version}`),console.log(` App Name: ${e.appName}`),console.log(` Backend: ${e.backend||"nostr"}`),console.log(" Public Key: "+(e.publicKey?e.publicKey.substring(0,16)+"...":"N/A")),console.log(` Log Level: ${e.logLevel}`),console.log(` Persistence: ${e.persistence?"Enabled":"Disabled"}${e.dataDir?` (${e.dataDir})`:""}`),"nostr"!==e.backend&&e.backend?"gundb"===e.backend?(console.log("\n Gun Peers:"),e.peers&&0!==e.peers.length?e.peers.forEach((e,t)=>{console.log(` ${t+1}. ${e}`)}):console.log(" (none - running in local mode)")):"activitypub"===e.backend&&(console.log(` Server URL: ${e.serverUrl||"N/A"}`),console.log(` Actor ID: ${e.actorId||"N/A"}`)):(console.log(" Auto-reconnect: "+(e.reconnect?"Enabled":"Disabled")),console.log("\n Connected Relays:"),e.relays&&0!==e.relays.length?e.relays.forEach((e,t)=>{console.log(` ${t+1}. ${e}`)}):console.log(" (none - running in local mode)")),console.log("=".repeat(60)+"\n"))}metrics(){return{...this._metrics}}_requireGunDB(){if("gundb"!==this.config.backend)throw new Error("This method requires the GunDB backend");if(!this._backend)throw new Error("Backend not initialized. Call ready() first.")}async putGlobal(e,t){return await this.ready(),this._requireGunDB(),this._backend.writeGlobal(e,t)}async getGlobal(e,t){return await this.ready(),this._requireGunDB(),this._backend.readGlobal(e,t)}async getAllGlobal(e){return await this.ready(),this._requireGunDB(),this._backend.readAllGlobal(e)}async deleteGlobal(e,t){return await this.ready(),this._requireGunDB(),this._backend.deleteGlobal(e,t)}createReference(e,t,n){return this._requireGunDB(),this._backend.createReference(e,t,n)}isReference(e){return this._requireGunDB(),this._backend.isReference(e)}async resolveReference(e,t={}){return await this.ready(),this._requireGunDB(),this._backend.resolveReference(e,t)}async authenticate(e,t){return await this.ready(),this._requireGunDB(),this._backend.authenticate(e,t)}async createUser(e,t){return await this.ready(),this._requireGunDB(),this._backend.createUser(e,t)}logout(){this._requireGunDB(),this._backend.logout()}isAuthenticated(){return this._requireGunDB(),this._backend.isAuthenticated()}async writePrivate(e,t,n){return await this.ready(),this._requireGunDB(),this._backend.writePrivate(e,t,n)}async readPrivate(e,t){return await this.ready(),this._requireGunDB(),this._backend.readPrivate(e,t)}async setSchema(e,t){return await this.ready(),this._requireGunDB(),this._backend.setSchema(e,t)}async getSchema(e){return await this.ready(),this._requireGunDB(),this._backend.getSchema(e)}async validateData(e,t){return await this.ready(),this._requireGunDB(),this._backend.validateData(e,t)}async federate(e,t,n=!0){return await this.ready(),this._requireGunDB(),async function(e,t,n,r=!0){if(!t||!n)throw new Error("federate: Missing required space IDs");if(t===n)throw new Error("Cannot federate a space with itself");try{let i=await e.readGlobal("federation",t);i||(i={id:t,name:t,federation:[],notify:[],timestamp:Date.now()}),i.federation||(i.federation=[]),i.notify||(i.notify=[]),i.federation.includes(n)||i.federation.push(n),i.timestamp=Date.now(),await e.writeGlobal("federation",i);let s=await e.readGlobal("federation",n);s||(s={id:n,name:n,federation:[],notify:[],timestamp:Date.now()}),s.notify||(s.notify=[]),s.notify.includes(t)||s.notify.push(t),s.timestamp=Date.now(),await e.writeGlobal("federation",s);const a={id:`${t}_${n}`,space1:t,space2:n,created:Date.now(),status:"active",bidirectional:r};return await e.writeGlobal("federationMeta",a),!0}catch(i){throw console.error(`Federation creation failed: ${i.message}`),i}}(this._backend,e,t,n)}async unfederate(e,t){return await this.ready(),this._requireGunDB(),async function(e,t,n){if(!t||!n)throw new Error("unfederate: Missing required space IDs");try{let r=await e.readGlobal("federation",t);r&&r.federation&&(r.federation=r.federation.filter(e=>e!==n),r.timestamp=Date.now(),await e.writeGlobal("federation",r));let i=await e.readGlobal("federation",n);i&&i.notify&&(i.notify=i.notify.filter(e=>e!==t),i.timestamp=Date.now(),await e.writeGlobal("federation",i));const s=`${t}_${n}`,a=`${n}_${t}`;let o=await e.readGlobal("federationMeta",s);return o||(o=await e.readGlobal("federationMeta",a)),o&&(o.status="inactive",o.endedAt=Date.now(),await e.writeGlobal("federationMeta",o)),!0}catch(r){throw console.error(`Federation removal failed: ${r.message}`),r}}(this._backend,e,t)}async getFederation(e){return await this.ready(),this._requireGunDB(),ff(this._backend,e)}async resetFederation(e,t={}){return await this.ready(),this._requireGunDB(),async function(e,t,n={}){if(!t)throw new Error("resetFederation: Missing required space ID");const{notifyPartners:r=!0,spaceName:i=null}=n,s={success:!1,federatedCount:0,notifyCount:0,partnersNotified:0,errors:[]};try{const n=await ff(e,t);if(!n)return{...s,success:!0,message:"No federation configuration found for this space"};s.federatedCount=n.federation?.length||0,s.notifyCount=n.notify?.length||0;const o={id:t,name:i||t,federation:[],notify:[],timestamp:Date.now()};if(await e.writeGlobal("federation",o),r&&n.federation&&n.federation.length>0)for(const r of n.federation)try{const n=await ff(e,r);n&&(n.federation&&(n.federation=n.federation.filter(e=>e!==t.toString())),n.notify&&(n.notify=n.notify.filter(e=>e!==t.toString())),n.timestamp=Date.now(),await e.writeGlobal("federation",n),s.partnersNotified++)}catch(a){s.errors.push({partner:r,error:a.message})}if(n.federation&&n.federation.length>0)for(const r of n.federation)try{const n=`${t}_${r}`,i=`${r}_${t}`;let s=await e.readGlobal("federationMeta",n);s||(s=await e.readGlobal("federationMeta",i)),s&&(s.status="inactive",s.endedAt=Date.now(),await e.writeGlobal("federationMeta",s))}catch(a){}return s.success=!0,s}catch(a){return console.error(`Federation reset failed: ${a.message}`),{...s,success:!1,error:a.message}}}(this._backend,e,t)}async propagate(e,t,n,r={}){return await this.ready(),this._requireGunDB(),async function(e,t,n,r,i={}){if(!(e&&t&&n&&r))throw new Error("propagate: Missing required parameters");const{useReferences:s=!0,targetSpaces:a=null}=i,o={success:0,errors:0,errorDetails:[],propagated:!1,referencesUsed:s};try{const i=await ff(e,t);if(!i||!i.federation||0===i.federation.length)return{...o,message:`No federation found for ${t}`};if(!i.notify||0===i.notify.length)return{...o,message:`No notification targets found for ${t}`};let A=i.notify;if(a&&Array.isArray(a)&&a.length>0&&(A=A.filter(e=>a.includes(e))),0===A.length)return{...o,message:"No valid target spaces found after filtering"};const l=e.isReference(r);for(const a of A)try{if(s&&!l){const i=e.createReference(t,n,r);i._federation={origin:t,lens:n,timestamp:Date.now()};const s=e.buildPath(e.appName,a,n,i.id);await e.write(s,i),o.success++}else if(l){const i={...r,_federation:r._federation||{origin:t,lens:n,timestamp:Date.now()}},s=e.buildPath(e.appName,a,n,r.id);await e.write(s,i),o.success++}else{const i={...r,_federation:{origin:t,lens:n,timestamp:Date.now()}},s=e.buildPath(e.appName,a,n,r.id);await e.write(s,i),o.success++}}catch(c){o.errors++,o.errorDetails.push({space:a,error:c.message})}return o.propagated=o.success>0,o}catch(c){return console.error("Error in propagate:",c),{...o,error:c.message}}}(this._backend,e,t,n,r)}async getFederated(e,t,n={}){return await this.ready(),this._requireGunDB(),async function(e,t,n,r={}){const{aggregate:i=!1,idField:s="id",sumFields:a=[],concatArrays:o=[],removeDuplicates:c=!0,mergeStrategy:A=null,includeLocal:l=!0,includeFederated:f=!0,resolveReferences:u=!0,maxFederatedSpaces:d=-1,timeout:h=1e4}=r;if(!e||!t||!n)throw new Error("Missing required parameters: backend, holon, and lens are required");const p=await ff(e,t),m=[],y=new Set;if(f&&p&&p.federation&&p.federation.length>0){const t=-1===d?p.federation:p.federation.slice(0,d);for(const r of t)try{const t=e.buildPath(e.appName,r,n),i=await e.readAll(t);for(const e of i)e&&e[s]&&(m.push(e),y.add(e[s]))}catch(g){console.warn(`Error processing federated space ${r}: ${g.message}`)}}if(l){const r=e.buildPath(e.appName,t,n),i=await e.readAll(r);for(const e of i)e&&e[s]&&!y.has(e[s])&&(m.push(e),y.add(e[s]))}if(u)for(let b=0;b<m.length;b++){const t=m[b];if(t.soul&&t.id)try{const n=await e.resolveReference(t);n&&(m[b]=n)}catch(g){m[b]={id:t.id,_federation:{isReference:!0,resolved:!1,soul:t.soul,error:g.message,timestamp:Date.now()}}}else if(t._federation&&t._federation.isReference)try{const n=await e.resolveReference(t);n&&(m[b]=n)}catch(g){console.warn(`Error resolving legacy reference: ${g.message}`)}}if(i&&m.length>0){const e=m.reduce((e,t)=>{const n=t[s];return e[n]||(e[n]=[]),e[n].push(t),e},{});return Object.values(e).map(e=>{if(1===e.length)return e[0];if(A&&"function"==typeof A)return A(e);const t={...e[0]};for(const n of a)"number"==typeof t[n]&&(t[n]=e.reduce((e,t)=>e+(Number(t[n])||0),0));for(const n of o)if(Array.isArray(t[n])){const r=e.reduce((e,t)=>Array.isArray(t[n])?[...e,...t[n]]:e,[]);t[n]=c?Array.from(new Set(r)):r}return t._aggregated={count:e.length,timestamp:Date.now()},t})}return m}(this._backend,e,t,n)}async subscribeFederation(e,t,n={}){return await this.ready(),this._requireGunDB(),async function(e,t,n,r={}){if(!t||!n)throw new Error("subscribeFederation: Missing required parameters");const{lenses:i=["*"],throttle:s=0,resolveReferences:a=!0}=r,o=await ff(e,t);if(!o)throw new Error("No federation info found for space");const c=[];let A={};if(o.federation&&o.federation.length>0)for(const f of o.federation)for(const t of i)try{const r=e.buildPath(e.appName,f,t),i=await e.subscribe(r,async(r,i)=>{try{if(!r||!r.id)return;const i=Date.now(),o=`${f}_${t}_${r.id}`;if(s>0){if(A[o]&&i-A[o]<s)return;A[o]=i}let c=r;a&&e.isReference(r)&&(c=await e.resolveReference(r)),c._federation||(c._federation={origin:f,timestamp:i}),await n(c,f,t)}catch(o){console.warn("Federation notification error:",o)}},{resolveReferences:!1});i&&"function"==typeof i.unsubscribe&&c.push(i)}catch(l){console.warn(`Error creating subscription for ${f}/${t}:`,l)}return{unsubscribe:()=>{c.forEach(e=>{try{e&&"function"==typeof e.unsubscribe&&e.unsubscribe()}catch(l){console.warn("Error unsubscribing:",l)}}),c.length=0,A={}},getSubscriptionCount:()=>c.length}}(this._backend,e,t,n)}async federateMessage(e,t,n,r,i="generic"){return await this.ready(),this._requireGunDB(),async function(e,t,n,r,i,s="generic"){const a=`${t}_${n}_fedmsgs`;let o=await e.readGlobal("federation_messages",a);o||(o={id:a,originalChatId:t,originalMessageId:n,type:s,messages:[]});const c=o.messages.find(e=>e.chatId===r);c?(c.messageId=i,c.timestamp=Date.now()):o.messages.push({chatId:r,messageId:i,timestamp:Date.now()}),await e.writeGlobal("federation_messages",o)}(this._backend,e,t,n,r,i)}async getFederatedMessages(e,t){return await this.ready(),this._requireGunDB(),uf(this._backend,e,t)}async updateFederatedMessages(e,t,n){return await this.ready(),this._requireGunDB(),async function(e,t,n,r){const i=await uf(e,t,n);if(i?.messages)for(const a of i.messages)try{await r(a.chatId,a.messageId)}catch(s){console.warn(`Failed to update federated message in chat ${a.chatId}:`,s)}}(this._backend,e,t,n)}close(){this._backend&&this._backend.close(),this.client&&"function"==typeof this.client.close&&this.client.close()}};var Ef=function(e){var t,n=void 0!==(e=e||{})?e:{},r={};for(t in n)n.hasOwnProperty(t)&&(r[t]=n[t]);var i,s="";"undefined"!=typeof document&&document.currentScript&&(s=document.currentScript.src),s=0!==s.indexOf("blob:")?s.substr(0,s.lastIndexOf("/")+1):"",i=function(e,t,n){var r=new XMLHttpRequest;r.open("GET",e,!0),r.responseType="arraybuffer",r.onload=function(){if(200==r.status||0==r.status&&r.response)t(r.response);else{var i=H(e);i?t(i.buffer):n()}},r.onerror=n,r.send(null)};var a=n.print||console.log.bind(console),o=n.printErr||console.warn.bind(console);for(t in r)r.hasOwnProperty(t)&&(n[t]=r[t]);r=null,n.arguments&&n.arguments;var c=0,A=!1;function l(e){var t=n["_"+e];return t||ne("Assertion failed: "+("Cannot call unknown function "+e+", make sure it is exported")),t}var f,u,d,h,p,m,y,g="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function b(e,t){return e?function(e,t,n){for(var r=t+n,i=t;e[i]&&!(i>=r);)++i;if(i-t>16&&e.subarray&&g)return g.decode(e.subarray(t,i));for(var s="";t<i;){var a=e[t++];if(128&a){var o=63&e[t++];if(192!=(224&a)){var c=63&e[t++];if((a=224==(240&a)?(15&a)<<12|o<<6|c:(7&a)<<18|o<<12|c<<6|63&e[t++])<65536)s+=String.fromCharCode(a);else{var A=a-65536;s+=String.fromCharCode(55296|A>>10,56320|1023&A)}}else s+=String.fromCharCode((31&a)<<6|o)}else s+=String.fromCharCode(a)}return s}(d,e,t):""}function w(e,t){return e%t>0&&(e+=t-e%t),e}function v(e){f=e,n.HEAP8=u=new Int8Array(e),n.HEAP16=h=new Int16Array(e),n.HEAP32=p=new Int32Array(e),n.HEAPU8=d=new Uint8Array(e),n.HEAPU16=new Uint16Array(e),n.HEAPU32=new Uint32Array(e),n.HEAPF32=m=new Float32Array(e),n.HEAPF64=y=new Float64Array(e)}"undefined"!=typeof TextDecoder&&new TextDecoder("utf-16le");var _=n.TOTAL_MEMORY||33554432;function E(e){for(;e.length>0;){var t=e.shift();if("function"!=typeof t){var r=t.func;"number"==typeof r?void 0===t.arg?n.dynCall_v(r):n.dynCall_vi(r,t.arg):r(void 0===t.arg?null:t.arg)}else t()}}_=(f=n.buffer?n.buffer:new ArrayBuffer(_)).byteLength,v(f),p[7152]=5271520;var k=[],T=[],S=[],x=[];function I(e){k.unshift(e)}function P(e){x.unshift(e)}var C=Math.abs,N=Math.ceil,O=Math.floor,R=Math.min,B=0,M=null;n.preloadedImages={},n.preloadedAudios={};var $,D,F=null,G="data:application/octet-stream;base64,";function U(e){return String.prototype.startsWith?e.startsWith(G):0===e.indexOf(G)}function L(){return u.length}F="data:application/octet-stream;base64,AAAAAAAAAAAAAAAAAQAAAAIAAAADAAAABAAAAAUAAAAGAAAAAQAAAAQAAAADAAAABgAAAAUAAAACAAAAAAAAAAIAAAADAAAAAQAAAAQAAAAGAAAAAAAAAAUAAAADAAAABgAAAAQAAAAFAAAAAAAAAAEAAAACAAAABAAAAAUAAAAGAAAAAAAAAAIAAAADAAAAAQAAAAUAAAACAAAAAAAAAAEAAAADAAAABgAAAAQAAAAGAAAAAAAAAAUAAAACAAAAAQAAAAQAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAIAAAADAAAAAAAAAAAAAAACAAAAAAAAAAEAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAYAAAAAAAAABQAAAAAAAAAAAAAABAAAAAUAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAYAAAAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAgAAAAMAAAAEAAAABQAAAAYAAAABAAAAAgAAAAMAAAAEAAAABQAAAAYAAAAAAAAAAgAAAAMAAAAEAAAABQAAAAYAAAAAAAAAAQAAAAMAAAAEAAAABQAAAAYAAAAAAAAAAQAAAAIAAAAEAAAABQAAAAYAAAAAAAAAAQAAAAIAAAADAAAABQAAAAYAAAAAAAAAAQAAAAIAAAADAAAABAAAAAYAAAAAAAAAAQAAAAIAAAADAAAABAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAgAAAAIAAAAAAAAAAAAAAAYAAAAAAAAAAwAAAAIAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAFAAAABAAAAAAAAAABAAAAAAAAAAAAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAYAAAAAAAAABAAAAAAAAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAFAAAAAgAAAAQAAAADAAAACAAAAAEAAAAHAAAABgAAAAkAAAAAAAAAAwAAAAIAAAACAAAABgAAAAoAAAALAAAAAAAAAAEAAAAFAAAAAwAAAA0AAAABAAAABwAAAAQAAAAMAAAAAAAAAAQAAAB/AAAADwAAAAgAAAADAAAAAAAAAAwAAAAFAAAAAgAAABIAAAAKAAAACAAAAAAAAAAQAAAABgAAAA4AAAALAAAAEQAAAAEAAAAJAAAAAgAAAAcAAAAVAAAACQAAABMAAAADAAAADQAAAAEAAAAIAAAABQAAABYAAAAQAAAABAAAAAAAAAAPAAAACQAAABMAAAAOAAAAFAAAAAEAAAAHAAAABgAAAAoAAAALAAAAGAAAABcAAAAFAAAAAgAAABIAAAALAAAAEQAAABcAAAAZAAAAAgAAAAYAAAAKAAAADAAAABwAAAANAAAAGgAAAAQAAAAPAAAAAwAAAA0AAAAaAAAAFQAAAB0AAAADAAAADAAAAAcAAAAOAAAAfwAAABEAAAAbAAAACQAAABQAAAAGAAAADwAAABYAAAAcAAAAHwAAAAQAAAAIAAAADAAAABAAAAASAAAAIQAAAB4AAAAIAAAABQAAABYAAAARAAAACwAAAA4AAAAGAAAAIwAAABkAAAAbAAAAEgAAABgAAAAeAAAAIAAAAAUAAAAKAAAAEAAAABMAAAAiAAAAFAAAACQAAAAHAAAAFQAAAAkAAAAUAAAADgAAABMAAAAJAAAAKAAAABsAAAAkAAAAFQAAACYAAAATAAAAIgAAAA0AAAAdAAAABwAAABYAAAAQAAAAKQAAACEAAAAPAAAACAAAAB8AAAAXAAAAGAAAAAsAAAAKAAAAJwAAACUAAAAZAAAAGAAAAH8AAAAgAAAAJQAAAAoAAAAXAAAAEgAAABkAAAAXAAAAEQAAAAsAAAAtAAAAJwAAACMAAAAaAAAAKgAAAB0AAAArAAAADAAAABwAAAANAAAAGwAAACgAAAAjAAAALgAAAA4AAAAUAAAAEQAAABwAAAAfAAAAKgAAACwAAAAMAAAADwAAABoAAAAdAAAAKwAAACYAAAAvAAAADQAAABoAAAAVAAAAHgAAACAAAAAwAAAAMgAAABAAAAASAAAAIQAAAB8AAAApAAAALAAAADUAAAAPAAAAFgAAABwAAAAgAAAAHgAAABgAAAASAAAANAAAADIAAAAlAAAAIQAAAB4AAAAxAAAAMAAAABYAAAAQAAAAKQAAACIAAAATAAAAJgAAABUAAAA2AAAAJAAAADMAAAAjAAAALgAAAC0AAAA4AAAAEQAAABsAAAAZAAAAJAAAABQAAAAiAAAAEwAAADcAAAAoAAAANgAAACUAAAAnAAAANAAAADkAAAAYAAAAFwAAACAAAAAmAAAAfwAAACIAAAAzAAAAHQAAAC8AAAAVAAAAJwAAACUAAAAZAAAAFwAAADsAAAA5AAAALQAAACgAAAAbAAAAJAAAABQAAAA8AAAALgAAADcAAAApAAAAMQAAADUAAAA9AAAAFgAAACEAAAAfAAAAKgAAADoAAAArAAAAPgAAABwAAAAsAAAAGgAAACsAAAA+AAAALwAAAEAAAAAaAAAAKgAAAB0AAAAsAAAANQAAADoAAABBAAAAHAAAAB8AAAAqAAAALQAAACcAAAAjAAAAGQAAAD8AAAA7AAAAOAAAAC4AAAA8AAAAOAAAAEQAAAAbAAAAKAAAACMAAAAvAAAAJgAAACsAAAAdAAAARQAAADMAAABAAAAAMAAAADEAAAAeAAAAIQAAAEMAAABCAAAAMgAAADEAAAB/AAAAPQAAAEIAAAAhAAAAMAAAACkAAAAyAAAAMAAAACAAAAAeAAAARgAAAEMAAAA0AAAAMwAAAEUAAAA2AAAARwAAACYAAAAvAAAAIgAAADQAAAA5AAAARgAAAEoAAAAgAAAAJQAAADIAAAA1AAAAPQAAAEEAAABLAAAAHwAAACkAAAAsAAAANgAAAEcAAAA3AAAASQAAACIAAAAzAAAAJAAAADcAAAAoAAAANgAAACQAAABIAAAAPAAAAEkAAAA4AAAARAAAAD8AAABNAAAAIwAAAC4AAAAtAAAAOQAAADsAAABKAAAATgAAACUAAAAnAAAANAAAADoAAAB/AAAAPgAAAEwAAAAsAAAAQQAAACoAAAA7AAAAPwAAAE4AAABPAAAAJwAAAC0AAAA5AAAAPAAAAEgAAABEAAAAUAAAACgAAAA3AAAALgAAAD0AAAA1AAAAMQAAACkAAABRAAAASwAAAEIAAAA+AAAAKwAAADoAAAAqAAAAUgAAAEAAAABMAAAAPwAAAH8AAAA4AAAALQAAAE8AAAA7AAAATQAAAEAAAAAvAAAAPgAAACsAAABUAAAARQAAAFIAAABBAAAAOgAAADUAAAAsAAAAVgAAAEwAAABLAAAAQgAAAEMAAABRAAAAVQAAADEAAAAwAAAAPQAAAEMAAABCAAAAMgAAADAAAABXAAAAVQAAAEYAAABEAAAAOAAAADwAAAAuAAAAWgAAAE0AAABQAAAARQAAADMAAABAAAAALwAAAFkAAABHAAAAVAAAAEYAAABDAAAANAAAADIAAABTAAAAVwAAAEoAAABHAAAAWQAAAEkAAABbAAAAMwAAAEUAAAA2AAAASAAAAH8AAABJAAAANwAAAFAAAAA8AAAAWAAAAEkAAABbAAAASAAAAFgAAAA2AAAARwAAADcAAABKAAAATgAAAFMAAABcAAAANAAAADkAAABGAAAASwAAAEEAAAA9AAAANQAAAF4AAABWAAAAUQAAAEwAAABWAAAAUgAAAGAAAAA6AAAAQQAAAD4AAABNAAAAPwAAAEQAAAA4AAAAXQAAAE8AAABaAAAATgAAAEoAAAA7AAAAOQAAAF8AAABcAAAATwAAAE8AAABOAAAAPwAAADsAAABdAAAAXwAAAE0AAABQAAAARAAAAEgAAAA8AAAAYwAAAFoAAABYAAAAUQAAAFUAAABeAAAAZQAAAD0AAABCAAAASwAAAFIAAABgAAAAVAAAAGIAAAA+AAAATAAAAEAAAABTAAAAfwAAAEoAAABGAAAAZAAAAFcAAABcAAAAVAAAAEUAAABSAAAAQAAAAGEAAABZAAAAYgAAAFUAAABXAAAAZQAAAGYAAABCAAAAQwAAAFEAAABWAAAATAAAAEsAAABBAAAAaAAAAGAAAABeAAAAVwAAAFMAAABmAAAAZAAAAEMAAABGAAAAVQAAAFgAAABIAAAAWwAAAEkAAABjAAAAUAAAAGkAAABZAAAAYQAAAFsAAABnAAAARQAAAFQAAABHAAAAWgAAAE0AAABQAAAARAAAAGoAAABdAAAAYwAAAFsAAABJAAAAWQAAAEcAAABpAAAAWAAAAGcAAABcAAAAUwAAAE4AAABKAAAAbAAAAGQAAABfAAAAXQAAAE8AAABaAAAATQAAAG0AAABfAAAAagAAAF4AAABWAAAAUQAAAEsAAABrAAAAaAAAAGUAAABfAAAAXAAAAE8AAABOAAAAbQAAAGwAAABdAAAAYAAAAGgAAABiAAAAbgAAAEwAAABWAAAAUgAAAGEAAAB/AAAAYgAAAFQAAABnAAAAWQAAAG8AAABiAAAAbgAAAGEAAABvAAAAUgAAAGAAAABUAAAAYwAAAFAAAABpAAAAWAAAAGoAAABaAAAAcQAAAGQAAABmAAAAUwAAAFcAAABsAAAAcgAAAFwAAABlAAAAZgAAAGsAAABwAAAAUQAAAFUAAABeAAAAZgAAAGUAAABXAAAAVQAAAHIAAABwAAAAZAAAAGcAAABbAAAAYQAAAFkAAAB0AAAAaQAAAG8AAABoAAAAawAAAG4AAABzAAAAVgAAAF4AAABgAAAAaQAAAFgAAABnAAAAWwAAAHEAAABjAAAAdAAAAGoAAABdAAAAYwAAAFoAAAB1AAAAbQAAAHEAAABrAAAAfwAAAGUAAABeAAAAcwAAAGgAAABwAAAAbAAAAGQAAABfAAAAXAAAAHYAAAByAAAAbQAAAG0AAABsAAAAXQAAAF8AAAB1AAAAdgAAAGoAAABuAAAAYgAAAGgAAABgAAAAdwAAAG8AAABzAAAAbwAAAGEAAABuAAAAYgAAAHQAAABnAAAAdwAAAHAAAABrAAAAZgAAAGUAAAB4AAAAcwAAAHIAAABxAAAAYwAAAHQAAABpAAAAdQAAAGoAAAB5AAAAcgAAAHAAAABkAAAAZgAAAHYAAAB4AAAAbAAAAHMAAABuAAAAawAAAGgAAAB4AAAAdwAAAHAAAAB0AAAAZwAAAHcAAABvAAAAcQAAAGkAAAB5AAAAdQAAAH8AAABtAAAAdgAAAHEAAAB5AAAAagAAAHYAAAB4AAAAbAAAAHIAAAB1AAAAeQAAAG0AAAB3AAAAbwAAAHMAAABuAAAAeQAAAHQAAAB4AAAAeAAAAHMAAAByAAAAcAAAAHkAAAB3AAAAdgAAAHkAAAB0AAAAeAAAAHcAAAB1AAAAcQAAAHYAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAABAAAABQAAAAEAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAACAAAABQAAAAEAAAAAAAAA/////wEAAAAAAAAAAwAAAAQAAAACAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAMAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAFAAAAAQAAAAAAAAAAAAAAAQAAAAMAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAEAAAADAAAAAAAAAAAAAAABAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAADAAAABQAAAAEAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAP////8DAAAAAAAAAAUAAAACAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAEAAAABQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAAFAAAABQAAAAAAAAAAAAAAAwAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAMAAAADAAAAAwAAAAAAAAADAAAAAAAAAAAAAAD/////AwAAAAAAAAAFAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAAAAABAAAAAwAAAAAAAAAAAAAAAQAAAAAAAAADAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAQAAAAMAAAAAAAAAAAAAAAEAAAAAAAAAAwAAAAMAAAADAAAAAwAAAAAAAAADAAAAAAAAAAAAAAADAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAADAAAAAAAAAP////8DAAAAAAAAAAUAAAACAAAAAAAAAAAAAAADAAAAAAAAAAAAAAADAAAAAwAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAUAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAFAAAABQAAAAAAAAAAAAAAAwAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAwAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAAAAAADAAAAAAAAAAAAAAADAAAAAwAAAAMAAAAAAAAAAwAAAAAAAAAAAAAA/////wMAAAAAAAAABQAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAADAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAADAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAADAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAAAAAAA/////wMAAAAAAAAABQAAAAIAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAMAAAADAAAAAAAAAAAAAAADAAAAAwAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAwAAAAMAAAADAAAAAwAAAAAAAAADAAAAAAAAAAMAAAADAAAAAwAAAAMAAAAAAAAAAwAAAAAAAAD/////AwAAAAAAAAAFAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAADAAAAAAAAAAMAAAADAAAAAwAAAAAAAAADAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAADAAAAAAAAAAAAAAD/////AwAAAAAAAAAFAAAAAgAAAAAAAAAAAAAAAwAAAAMAAAADAAAAAAAAAAAAAAADAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAFAAAAAAAAAAAAAAADAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAADAAAAAQAAAAAAAAABAAAAAAAAAAAAAAABAAAAAwAAAAEAAAAAAAAAAQAAAAAAAAAAAAAAAwAAAAAAAAADAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAADAAAAAAAAAP////8DAAAAAAAAAAUAAAACAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAADAAAAAAAAAAAAAAADAAAAAwAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAUAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAwAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAFAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAAAAAAA/////wMAAAAAAAAABQAAAAIAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAwAAAAAAAAAFAAAAAAAAAAAAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAEAAAADAAAAAQAAAAAAAAABAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAwAAAAAAAAADAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAADAAAAAQAAAAAAAAABAAAAAAAAAAMAAAADAAAAAwAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAEAAAAAAAAAAwAAAAUAAAABAAAAAAAAAP////8DAAAAAAAAAAUAAAACAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAABAAAAAUAAAABAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAIAAAAFAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAEAAAADAAAAAQAAAAAAAAABAAAAAAAAAAUAAAAAAAAAAAAAAAUAAAAFAAAAAAAAAAAAAAD/////AQAAAAAAAAADAAAABAAAAAIAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAUAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAFAAAAAAAAAAAAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAUAAAABAAAAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAEAAAD//////////wEAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAADAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAsAAAACAAAAAAAAAAAAAAABAAAAAgAAAAYAAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAcAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAKAAAAAgAAAAAAAAAAAAAAAQAAAAEAAAAFAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAABwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAsAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAACAAAAAAAAAAAAAAABAAAAAwAAAAcAAAAGAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAABwAAAAEAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAADgAAAAIAAAAAAAAAAAAAAAEAAAAAAAAACQAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAMAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAABwAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAsAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADQAAAAIAAAAAAAAAAAAAAAEAAAAEAAAACAAAAAoAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAALAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAACQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAgAAAAAAAAAAAAAAAQAAAAsAAAAPAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAkAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAOAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAEAAAAAAAAAAQAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAIAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAABQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAAAAAgAAAAAAAAAAAAAAAQAAAAwAAAAQAAAADAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAoAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAPAAAAAAAAAAEAAAABAAAAAAAAAAAAAAAAAAAADwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAADQAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAACAAAAAAAAAAAAAAABAAAACgAAABMAAAAIAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAkAAAABAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAOAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAEQAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEQAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAAA8AAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAQAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAACQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAIAAAAAAAAAAAAAAAEAAAANAAAAEQAAAA0AAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAARAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAEwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAA4AAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAATAAAAAAAAAAEAAAABAAAAAAAAAAAAAAAAAAAAEQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAA0AAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAARAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAkAAAACAAAAAAAAAAAAAAABAAAADgAAABIAAAAPAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAADwAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABIAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAASAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAEwAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAABEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEgAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAABIAAAABAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAATAAAAAgAAAAAAAAAAAAAAAQAAAP//////////EwAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAEgAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAASAAAAAAAAABgAAAAAAAAAIQAAAAAAAAAeAAAAAAAAACAAAAADAAAAMQAAAAEAAAAwAAAAAwAAADIAAAADAAAACAAAAAAAAAAFAAAABQAAAAoAAAAFAAAAFgAAAAAAAAAQAAAAAAAAABIAAAAAAAAAKQAAAAEAAAAhAAAAAAAAAB4AAAAAAAAABAAAAAAAAAAAAAAABQAAAAIAAAAFAAAADwAAAAEAAAAIAAAAAAAAAAUAAAAFAAAAHwAAAAEAAAAWAAAAAAAAABAAAAAAAAAAAgAAAAAAAAAGAAAAAAAAAA4AAAAAAAAACgAAAAAAAAALAAAAAAAAABEAAAADAAAAGAAAAAEAAAAXAAAAAwAAABkAAAADAAAAAAAAAAAAAAABAAAABQAAAAkAAAAFAAAABQAAAAAAAAACAAAAAAAAAAYAAAAAAAAAEgAAAAEAAAAKAAAAAAAAAAsAAAAAAAAABAAAAAEAAAADAAAABQAAAAcAAAAFAAAACAAAAAEAAAAAAAAAAAAAAAEAAAAFAAAAEAAAAAEAAAAFAAAAAAAAAAIAAAAAAAAABwAAAAAAAAAVAAAAAAAAACYAAAAAAAAACQAAAAAAAAATAAAAAAAAACIAAAADAAAADgAAAAEAAAAUAAAAAwAAACQAAAADAAAAAwAAAAAAAAANAAAABQAAAB0AAAAFAAAAAQAAAAAAAAAHAAAAAAAAABUAAAAAAAAABgAAAAEAAAAJAAAAAAAAABMAAAAAAAAABAAAAAIAAAAMAAAABQAAABoAAAAFAAAAAAAAAAEAAAADAAAAAAAAAA0AAAAFAAAAAgAAAAEAAAABAAAAAAAAAAcAAAAAAAAAGgAAAAAAAAAqAAAAAAAAADoAAAAAAAAAHQAAAAAAAAArAAAAAAAAAD4AAAADAAAAJgAAAAEAAAAvAAAAAwAAAEAAAAADAAAADAAAAAAAAAAcAAAABQAAACwAAAAFAAAADQAAAAAAAAAaAAAAAAAAACoAAAAAAAAAFQAAAAEAAAAdAAAAAAAAACsAAAAAAAAABAAAAAMAAAAPAAAABQAAAB8AAAAFAAAAAwAAAAEAAAAMAAAAAAAAABwAAAAFAAAABwAAAAEAAAANAAAAAAAAABoAAAAAAAAAHwAAAAAAAAApAAAAAAAAADEAAAAAAAAALAAAAAAAAAA1AAAAAAAAAD0AAAADAAAAOgAAAAEAAABBAAAAAwAAAEsAAAADAAAADwAAAAAAAAAWAAAABQAAACEAAAAFAAAAHAAAAAAAAAAfAAAAAAAAACkAAAAAAAAAKgAAAAEAAAAsAAAAAAAAADUAAAAAAAAABAAAAAQAAAAIAAAABQAAABAAAAAFAAAADAAAAAEAAAAPAAAAAAAAABYAAAAFAAAAGgAAAAEAAAAcAAAAAAAAAB8AAAAAAAAAMgAAAAAAAAAwAAAAAAAAADEAAAADAAAAIAAAAAAAAAAeAAAAAwAAACEAAAADAAAAGAAAAAMAAAASAAAAAwAAABAAAAADAAAARgAAAAAAAABDAAAAAAAAAEIAAAADAAAANAAAAAMAAAAyAAAAAAAAADAAAAAAAAAAJQAAAAMAAAAgAAAAAAAAAB4AAAADAAAAUwAAAAAAAABXAAAAAwAAAFUAAAADAAAASgAAAAMAAABGAAAAAAAAAEMAAAAAAAAAOQAAAAEAAAA0AAAAAwAAADIAAAAAAAAAGQAAAAAAAAAXAAAAAAAAABgAAAADAAAAEQAAAAAAAAALAAAAAwAAAAoAAAADAAAADgAAAAMAAAAGAAAAAwAAAAIAAAADAAAALQAAAAAAAAAnAAAAAAAAACUAAAADAAAAIwAAAAMAAAAZAAAAAAAAABcAAAAAAAAAGwAAAAMAAAARAAAAAAAAAAsAAAADAAAAPwAAAAAAAAA7AAAAAwAAADkAAAADAAAAOAAAAAMAAAAtAAAAAAAAACcAAAAAAAAALgAAAAMAAAAjAAAAAwAAABkAAAAAAAAAJAAAAAAAAAAUAAAAAAAAAA4AAAADAAAAIgAAAAAAAAATAAAAAwAAAAkAAAADAAAAJgAAAAMAAAAVAAAAAwAAAAcAAAADAAAANwAAAAAAAAAoAAAAAAAAABsAAAADAAAANgAAAAMAAAAkAAAAAAAAABQAAAAAAAAAMwAAAAMAAAAiAAAAAAAAABMAAAADAAAASAAAAAAAAAA8AAAAAwAAAC4AAAADAAAASQAAAAMAAAA3AAAAAAAAACgAAAAAAAAARwAAAAMAAAA2AAAAAwAAACQAAAAAAAAAQAAAAAAAAAAvAAAAAAAAACYAAAADAAAAPgAAAAAAAAArAAAAAwAAAB0AAAADAAAAOgAAAAMAAAAqAAAAAwAAABoAAAADAAAAVAAAAAAAAABFAAAAAAAAADMAAAADAAAAUgAAAAMAAABAAAAAAAAAAC8AAAAAAAAATAAAAAMAAAA+AAAAAAAAACsAAAADAAAAYQAAAAAAAABZAAAAAwAAAEcAAAADAAAAYgAAAAMAAABUAAAAAAAAAEUAAAAAAAAAYAAAAAMAAABSAAAAAwAAAEAAAAAAAAAASwAAAAAAAABBAAAAAAAAADoAAAADAAAAPQAAAAAAAAA1AAAAAwAAACwAAAADAAAAMQAAAAMAAAApAAAAAwAAAB8AAAADAAAAXgAAAAAAAABWAAAAAAAAAEwAAAADAAAAUQAAAAMAAABLAAAAAAAAAEEAAAAAAAAAQgAAAAMAAAA9AAAAAAAAADUAAAADAAAAawAAAAAAAABoAAAAAwAAAGAAAAADAAAAZQAAAAMAAABeAAAAAAAAAFYAAAAAAAAAVQAAAAMAAABRAAAAAwAAAEsAAAAAAAAAOQAAAAAAAAA7AAAAAAAAAD8AAAADAAAASgAAAAAAAABOAAAAAwAAAE8AAAADAAAAUwAAAAMAAABcAAAAAwAAAF8AAAADAAAAJQAAAAAAAAAnAAAAAwAAAC0AAAADAAAANAAAAAAAAAA5AAAAAAAAADsAAAAAAAAARgAAAAMAAABKAAAAAAAAAE4AAAADAAAAGAAAAAAAAAAXAAAAAwAAABkAAAADAAAAIAAAAAMAAAAlAAAAAAAAACcAAAADAAAAMgAAAAMAAAA0AAAAAAAAADkAAAAAAAAALgAAAAAAAAA8AAAAAAAAAEgAAAADAAAAOAAAAAAAAABEAAAAAwAAAFAAAAADAAAAPwAAAAMAAABNAAAAAwAAAFoAAAADAAAAGwAAAAAAAAAoAAAAAwAAADcAAAADAAAAIwAAAAAAAAAuAAAAAAAAADwAAAAAAAAALQAAAAMAAAA4AAAAAAAAAEQAAAADAAAADgAAAAAAAAAUAAAAAwAAACQAAAADAAAAEQAAAAMAAAAbAAAAAAAAACgAAAADAAAAGQAAAAMAAAAjAAAAAAAAAC4AAAAAAAAARwAAAAAAAABZAAAAAAAAAGEAAAADAAAASQAAAAAAAABbAAAAAwAAAGcAAAADAAAASAAAAAMAAABYAAAAAwAAAGkAAAADAAAAMwAAAAAAAABFAAAAAwAAAFQAAAADAAAANgAAAAAAAABHAAAAAAAAAFkAAAAAAAAANwAAAAMAAABJAAAAAAAAAFsAAAADAAAAJgAAAAAAAAAvAAAAAwAAAEAAAAADAAAAIgAAAAMAAAAzAAAAAAAAAEUAAAADAAAAJAAAAAMAAAA2AAAAAAAAAEcAAAAAAAAAYAAAAAAAAABoAAAAAAAAAGsAAAADAAAAYgAAAAAAAABuAAAAAwAAAHMAAAADAAAAYQAAAAMAAABvAAAAAwAAAHcAAAADAAAATAAAAAAAAABWAAAAAwAAAF4AAAADAAAAUgAAAAAAAABgAAAAAAAAAGgAAAAAAAAAVAAAAAMAAABiAAAAAAAAAG4AAAADAAAAOgAAAAAAAABBAAAAAwAAAEsAAAADAAAAPgAAAAMAAABMAAAAAAAAAFYAAAADAAAAQAAAAAMAAABSAAAAAAAAAGAAAAAAAAAAVQAAAAAAAABXAAAAAAAAAFMAAAADAAAAZQAAAAAAAABmAAAAAwAAAGQAAAADAAAAawAAAAMAAABwAAAAAwAAAHIAAAADAAAAQgAAAAAAAABDAAAAAwAAAEYAAAADAAAAUQAAAAAAAABVAAAAAAAAAFcAAAAAAAAAXgAAAAMAAABlAAAAAAAAAGYAAAADAAAAMQAAAAAAAAAwAAAAAwAAADIAAAADAAAAPQAAAAMAAABCAAAAAAAAAEMAAAADAAAASwAAAAMAAABRAAAAAAAAAFUAAAAAAAAAXwAAAAAAAABcAAAAAAAAAFMAAAAAAAAATwAAAAAAAABOAAAAAAAAAEoAAAADAAAAPwAAAAEAAAA7AAAAAwAAADkAAAADAAAAbQAAAAAAAABsAAAAAAAAAGQAAAAFAAAAXQAAAAEAAABfAAAAAAAAAFwAAAAAAAAATQAAAAEAAABPAAAAAAAAAE4AAAAAAAAAdQAAAAQAAAB2AAAABQAAAHIAAAAFAAAAagAAAAEAAABtAAAAAAAAAGwAAAAAAAAAWgAAAAEAAABdAAAAAQAAAF8AAAAAAAAAWgAAAAAAAABNAAAAAAAAAD8AAAAAAAAAUAAAAAAAAABEAAAAAAAAADgAAAADAAAASAAAAAEAAAA8AAAAAwAAAC4AAAADAAAAagAAAAAAAABdAAAAAAAAAE8AAAAFAAAAYwAAAAEAAABaAAAAAAAAAE0AAAAAAAAAWAAAAAEAAABQAAAAAAAAAEQAAAAAAAAAdQAAAAMAAABtAAAABQAAAF8AAAAFAAAAcQAAAAEAAABqAAAAAAAAAF0AAAAAAAAAaQAAAAEAAABjAAAAAQAAAFoAAAAAAAAAaQAAAAAAAABYAAAAAAAAAEgAAAAAAAAAZwAAAAAAAABbAAAAAAAAAEkAAAADAAAAYQAAAAEAAABZAAAAAwAAAEcAAAADAAAAcQAAAAAAAABjAAAAAAAAAFAAAAAFAAAAdAAAAAEAAABpAAAAAAAAAFgAAAAAAAAAbwAAAAEAAABnAAAAAAAAAFsAAAAAAAAAdQAAAAIAAABqAAAABQAAAFoAAAAFAAAAeQAAAAEAAABxAAAAAAAAAGMAAAAAAAAAdwAAAAEAAAB0AAAAAQAAAGkAAAAAAAAAdwAAAAAAAABvAAAAAAAAAGEAAAAAAAAAcwAAAAAAAABuAAAAAAAAAGIAAAADAAAAawAAAAEAAABoAAAAAwAAAGAAAAADAAAAeQAAAAAAAAB0AAAAAAAAAGcAAAAFAAAAeAAAAAEAAAB3AAAAAAAAAG8AAAAAAAAAcAAAAAEAAABzAAAAAAAAAG4AAAAAAAAAdQAAAAEAAABxAAAABQAAAGkAAAAFAAAAdgAAAAEAAAB5AAAAAAAAAHQAAAAAAAAAcgAAAAEAAAB4AAAAAQAAAHcAAAAAAAAAcgAAAAAAAABwAAAAAAAAAGsAAAAAAAAAZAAAAAAAAABmAAAAAAAAAGUAAAADAAAAUwAAAAEAAABXAAAAAwAAAFUAAAADAAAAdgAAAAAAAAB4AAAAAAAAAHMAAAAFAAAAbAAAAAEAAAByAAAAAAAAAHAAAAAAAAAAXAAAAAEAAABkAAAAAAAAAGYAAAAAAAAAdQAAAAAAAAB5AAAABQAAAHcAAAAFAAAAbQAAAAEAAAB2AAAAAAAAAHgAAAAAAAAAXwAAAAEAAABsAAAAAQAAAHIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAAAAAAAAAAAEAAAABAAAAAQAAAAAAAAAAAAAAAQAAAAAAAAABAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAGAAAAAgAAAAUAAAABAAAABAAAAAAAAAAAAAAABQAAAAMAAAABAAAABgAAAAQAAAACAAAAAAAAAH6iBfbytuk/Gq6akm/58z/Xrm0Liez0P5doSdOpSwRAWs602ULg8D/dT7Rcbo/1v1N1RQHFNOM/g9Snx7HW3L8HWsP8Q3jfP6VwOLosutk/9rjk1YQcxj+gnmKMsNn6P/HDeuPFY+M/YHwDjqKhB0Ci19/fCVrbP4UxKkDWOP6/pvljWa09tL9wi7wrQXjnv/Z6yLImkM2/3yTlOzY14D+m+WNZrT20PzwKVQnrQwNA9nrIsiaQzT/g40rFrRQFwPa45NWEHMa/kbslHEZq97/xw3rjxWPjv4cLC2SMBci/otff3wla27+rKF5oIAv0P1N1RQHFNOO/iDJPGyWHBUAHWsP8Q3jfvwQf/by16gXAfqIF9vK26b8XrO0Vh0r+v9eubQuJ7PS/BxLrA0ZZ479azrTZQuDwv1MK1EuItPw/yscgV9Z6FkAwHBR2WjQMQJNRzXsQ5vY/GlUHVJYKF0DONuFv2lMNQNCGZ28QJfk/0WUwoIL36D8ggDOMQuATQNqMOeAy/wZAWFYOYM+M2z/LWC4uH3oSQDE+LyTsMgRAkJzhRGWFGEDd4soovCQQQKqk0DJMEP8/rGmNdwOLBUAW2X/9xCbjP4hu3dcqJhNAzuYItRvdB0CgzW3zJW/sPxotm/Y2TxRAQAk9XmdDDEC1Kx9MKgT3P1M+NctcghZAFVqcLlb0C0Bgzd3sB2b2P77mZDPUWhZAFROHJpUGCEDAfma5CxXtPz1DWq/zYxRAmhYY5824F0DOuQKWSbAOQNCMqrvu3fs/L6DR22K2wT9nAAxPBU8RQGiN6mW43AFAZhu25b633D8c1YgmzowSQNM25BRKWARArGS08/lNxD+LFssHwmMRQLC5aNcxBgJABL9HT0WRF0CjCmJmOGEOQHsuaVzMP/s/TWJCaGGwBUCeu1PAPLzjP9nqN9DZOBNAKE4JcydbCkCGtbd1qjPzP8dgm9U8jhVAtPeKTkVwDkCeCLss5l37P401XMPLmBdAFd29VMVQDUBg0yA55h75Pz6odcYLCRdApBM4rBrkAkDyAVWgQxbRP4XDMnK20hFAymLlF7EmzD8GUgo9XBHlP3lbK7T9COc/k+OhPthhy7+YGEpnrOvCPzBFhLs15u4/epbqB6H4uz9IuuLF5svev6lzLKY31es/CaQ0envF5z8ZY0xlUADXv7zaz7HYEuI/CfbK1sn16T8uAQfWwxLWPzKn/YuFN94/5KdbC1AFu793fyCSnlfvPzK2y4doAMY/NRg5t1/X6b/shq4QJaHDP5yNIAKPOeI/vpn7BSE30r/X4YQrO6nrv78Ziv/Thto/DqJ1Y6+y5z9l51NaxFrlv8QlA65HOLS/86dxiEc96z+Hj0+LFjneP6LzBZ8LTc2/DaJ1Y6+y579l51NaxFrlP8QlA65HOLQ/8qdxiEc967+Jj0+LFjnev6LzBZ8LTc0/1qdbC1AFuz93fyCSnlfvvzK2y4doAMa/NRg5t1/X6T/vhq4QJaHDv5yNIAKPOeK/wJn7BSE30j/W4YQrO6nrP78Ziv/Thtq/CaQ0envF578XY0xlUADXP7zaz7HYEuK/CvbK1sn16b8rAQfWwxLWvzKn/YuFN96/zWLlF7EmzL8GUgo9XBHlv3lbK7T9COe/kOOhPthhyz+cGEpnrOvCvzBFhLs15u6/c5bqB6H4u79IuuLF5sveP6lzLKY31eu/AQAAAP////8HAAAA/////zEAAAD/////VwEAAP////9hCQAA/////6dBAAD/////kcsBAP/////3kAwA/////8H2VwAAAAAAAAAAAAAAAAACAAAA/////w4AAAD/////YgAAAP////+uAgAA/////8ISAAD/////ToMAAP////8ilwMA/////+4hGQD/////gu2vAAAAAAAAAAAAAAAAAAAAAAACAAAA//////////8BAAAAAwAAAP//////////////////////////////////////////////////////////////////////////AQAAAAAAAAACAAAA////////////////AwAAAP//////////////////////////////////////////////////////////////////////////AQAAAAAAAAACAAAA////////////////AwAAAP//////////////////////////////////////////////////////////////////////////AQAAAAAAAAACAAAA////////////////AwAAAP//////////////////////////////////////////////////////////AgAAAP//////////AQAAAAAAAAD/////////////////////AwAAAP////////////////////////////////////////////////////8DAAAA/////////////////////wAAAAD/////////////////////AQAAAP///////////////wIAAAD///////////////////////////////8DAAAA/////////////////////wAAAAD///////////////8CAAAAAQAAAP////////////////////////////////////////////////////8DAAAA/////////////////////wAAAAD///////////////8CAAAAAQAAAP////////////////////////////////////////////////////8DAAAA/////////////////////wAAAAD///////////////8CAAAAAQAAAP////////////////////////////////////////////////////8DAAAA/////////////////////wAAAAD///////////////8CAAAAAQAAAP////////////////////////////////////////////////////8BAAAAAgAAAP///////////////wAAAAD/////////////////////AwAAAP////////////////////////////////////////////////////8BAAAAAgAAAP///////////////wAAAAD/////////////////////AwAAAP////////////////////////////////////////////////////8BAAAAAgAAAP///////////////wAAAAD/////////////////////AwAAAP////////////////////////////////////////////////////8BAAAAAgAAAP///////////////wAAAAD/////////////////////AwAAAP///////////////////////////////wIAAAD///////////////8BAAAA/////////////////////wAAAAD/////////////////////AwAAAP////////////////////////////////////////////////////8DAAAA/////////////////////wAAAAABAAAA//////////8CAAAA//////////////////////////////////////////////////////////8DAAAA////////////////AgAAAAAAAAABAAAA//////////////////////////////////////////////////////////////////////////8DAAAA////////////////AgAAAAAAAAABAAAA//////////////////////////////////////////////////////////////////////////8DAAAA////////////////AgAAAAAAAAABAAAA//////////////////////////////////////////////////////////////////////////8DAAAAAQAAAP//////////AgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAACAAAAAAAAAAIAAAABAAAAAQAAAAIAAAACAAAAAAAAAAUAAAAFAAAAAAAAAAIAAAACAAAAAwAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAgAAAAEAAAACAAAAAgAAAAIAAAAAAAAABQAAAAYAAAAAAAAAAgAAAAIAAAADAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAgAAAAAAAAACAAAAAQAAAAMAAAACAAAAAgAAAAAAAAAFAAAABwAAAAAAAAACAAAAAgAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAACAAAAAAAAAAIAAAABAAAABAAAAAIAAAACAAAAAAAAAAUAAAAIAAAAAAAAAAIAAAACAAAAAwAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAIAAAAAAAAAAgAAAAEAAAAAAAAAAgAAAAIAAAAAAAAABQAAAAkAAAAAAAAAAgAAAAIAAAADAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAKAAAAAgAAAAIAAAAAAAAAAwAAAA4AAAACAAAAAAAAAAIAAAADAAAAAAAAAAAAAAACAAAAAgAAAAMAAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAsAAAACAAAAAgAAAAAAAAADAAAACgAAAAIAAAAAAAAAAgAAAAMAAAABAAAAAAAAAAIAAAACAAAAAwAAAAcAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAIAAAACAAAAAAAAAAMAAAALAAAAAgAAAAAAAAACAAAAAwAAAAIAAAAAAAAAAgAAAAIAAAADAAAACAAAAAAAAAAAAAAAAAAAAAAAAAANAAAAAgAAAAIAAAAAAAAAAwAAAAwAAAACAAAAAAAAAAIAAAADAAAAAwAAAAAAAAACAAAAAgAAAAMAAAAJAAAAAAAAAAAAAAAAAAAAAAAAAA4AAAACAAAAAgAAAAAAAAADAAAADQAAAAIAAAAAAAAAAgAAAAMAAAAEAAAAAAAAAAIAAAACAAAAAwAAAAoAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAIAAAACAAAAAAAAAAMAAAAGAAAAAgAAAAAAAAACAAAAAwAAAA8AAAAAAAAAAgAAAAIAAAADAAAACwAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAgAAAAIAAAAAAAAAAwAAAAcAAAACAAAAAAAAAAIAAAADAAAAEAAAAAAAAAACAAAAAgAAAAMAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAcAAAACAAAAAgAAAAAAAAADAAAACAAAAAIAAAAAAAAAAgAAAAMAAAARAAAAAAAAAAIAAAACAAAAAwAAAA0AAAAAAAAAAAAAAAAAAAAAAAAACAAAAAIAAAACAAAAAAAAAAMAAAAJAAAAAgAAAAAAAAACAAAAAwAAABIAAAAAAAAAAgAAAAIAAAADAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAJAAAAAgAAAAIAAAAAAAAAAwAAAAUAAAACAAAAAAAAAAIAAAADAAAAEwAAAAAAAAACAAAAAgAAAAMAAAAPAAAAAAAAAAAAAAAAAAAAAAAAABAAAAACAAAAAAAAAAIAAAABAAAAEwAAAAIAAAACAAAAAAAAAAUAAAAKAAAAAAAAAAIAAAACAAAAAwAAABAAAAAAAAAAAAAAAAAAAAAAAAAAEQAAAAIAAAAAAAAAAgAAAAEAAAAPAAAAAgAAAAIAAAAAAAAABQAAAAsAAAAAAAAAAgAAAAIAAAADAAAAEQAAAAAAAAAAAAAAAAAAAAAAAAASAAAAAgAAAAAAAAACAAAAAQAAABAAAAACAAAAAgAAAAAAAAAFAAAADAAAAAAAAAACAAAAAgAAAAMAAAASAAAAAAAAAAAAAAAAAAAAAAAAABMAAAACAAAAAAAAAAIAAAABAAAAEQAAAAIAAAACAAAAAAAAAAUAAAANAAAAAAAAAAIAAAACAAAAAwAAABMAAAAAAAAAAAAAAAAAAAAAAAAADwAAAAIAAAAAAAAAAgAAAAEAAAASAAAAAgAAAAIAAAAAAAAABQAAAA4AAAAAAAAAAgAAAAIAAAADAAAAAgAAAAEAAAAAAAAAAQAAAAIAAAAAAAAAAAAAAAIAAAABAAAAAAAAAAEAAAACAAAAAQAAAAAAAAACAAAAAAAAAAUAAAAEAAAAAAAAAAEAAAAFAAAAAAAAAAAAAAAFAAAABAAAAAAAAAABAAAABQAAAAQAAAAAAAAABQAAAAAAAAACAAAAAQAAAAAAAAABAAAAAgAAAAAAAAAAAAAAAgAAAAEAAAAAAAAAAQAAAAIAAAABAAAAAAAAAAIAAAACAAAAAAAAAAEAAAAAAAAAAAAAAAUAAAAEAAAAAAAAAAEAAAAFAAAAAAAAAAAAAAAFAAAABAAAAAAAAAABAAAABQAAAAQAAAAAAAAABQAAAAUAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAABAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAEAAAAAAAAAAAEAAAAAAQAAAAAAAAAAAQAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAABAAAAAAAAAAAAAQAAAAAAAAAAAAA6B6FaUp9QQTPXMuL4myJBraiDfBwx9UBYJseitzTIQOL5if9jqZtAnXX+Z+ycb0C3pucbhRBCQG8wJBYqpRRAlWbDCzCY5z/eFWBUEve6P/+qo4Q50Y4/D9YM3iCcYT8fcA2QJSA0P4ADxu0qAAc/BNcGolVJ2j5d9FACqwquPh9z7MthtI9CSUSYJke/YUJQ/64OyjU0Qpi0+HCmFQdCm3GfIVdh2kHsJ11kAyauQYC3UDFJOoFBSJsFV1OwU0FK5fcxX4AmQWhy/zZIt/lACqaCPsBjzUDbdUNIScugQMYQlVJ4MXNANiuq8GTvRUDxTXnulxEZQFZ8QX5kpuw/qmG/JwYFlEAluh3Q6DB+QKn4vyNq0GZAKOXekas+UUB8xabXXhI6QG63C2pLtSNAdDBtyNfLDUDyOcu67ID2P0rCMvRXAeE/Ki2TSVyzyT9Dk+8Sz2uzP5J+w5ARWp0/NQAoOiMuhj9YnP+RyMJwPxgW7TvQVFk/KgsLYF0kQz9g5dAC6IwzQcgHPVvDex1B1XjppodHBkHJq3OMM9fwQNvcmJ7wddlAInGPpQs/w0BRobq5EBmtQJZ2ai7n+ZVAtv2G5E+bgECG+gIfKBlpQK5f8jdI91JAL39sL/WpPEB8rGxhDqklQK6yUf43XhBAxL9y/tK8+D86XyZpgrHiPwAAAAD/////AAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////AAAAAP////8AAAAAAAAAAAAAAAABAAAAAAAAAAAAAAD/////AAAAAAAAAAABAAAAAQAAAAAAAAAAAAAA/////wAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAP////8FAAAABQAAAAAAAAAAAAAAAAAAAAAAAAD/////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/////////////////////////////////////wAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP////////////////////////////////////8AAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAFAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////AAAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAQAAAAEAAAABAAAAAAAAAAEAAAAAAAAABQAAAAEAAAABAAAAAAAAAAAAAAABAAAAAQAAAAAAAAABAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAQAAAAAAAQABAAABAQAAAAAAAQAAAAEAAAABAAEAAAAAAAAAAAAAAAAAAAAAquJYWJZl+D9jaeZNtj/zPwwdI9KqaeO/qGefXwdHdz+q4lhYlmX4P+OrlPMN3PI/DB0j0qpp47+7SQLV4VIEQKriWFiWZfg/r2kma3tz8T82eQmLqNIGwMRIWXMqSvo/fcCszPux9j+jara6ozTwP6hnn18HR3c/MSoKLequ8r+SabgA2nj0P7jBLbDOHO8/1Ym/ICfH4T+6lxjvlFXHv73m373LRPU/0vXyDVxo7T+ToKRHJXMAQF/33578aPE/pAyy64tD9T8+U/hCvyruPwxv8Y7YYwLAuXYr8NAiCEB4+LDK0Sn0P1Qeuy4j+eo/OMx50n7K7L+TrGB/nyf8v5ehC2fbYPM/aXMKexiT6z8mFRIMjg/zP7yUVwGGBNw/E6opHERf8z/z0wR2g9DqPw4pBpcOhvu/NbA29uWAA8DMaTExyXzyP02biiQ+Ruk/S8jz2/FKBEB1pzZnpbb9P7pQU4wLfPI//7ZcQXeG6D9CqEQvAYoIwDB2VB6sSgRAVyv8H5We8T+EHWF8XNPmPzB2wT8Nrrg/SEi+cX+w4L8of+GtdSDxP1sjk5AdouU/6ZjOVru13r8K0obqI6bxvwVbdNXyhfA/w5GG024n5z+rwmtMzP8BwLw9pSX49QXABe/2uQxP8D+b6wCzCvXkP7uGT87fK+Q/pz/JWw4coj+qoBf2J0nwP/yE3PUo0+I/vFJeHcaC+D96luSIqvntP/bf8sHUYu8/gZNN41mL4z9bhOqVOF4FwO6lmAh1hQhAbCVxbdhk7z+1C8NdDcfiPwG36x/0OQBAx0WJ76c2+D9nlSHXANfuP2HlfZ3gqOE/EwnVlVPg9r96+oHzEH//v5bXzdT1Auw/DM3GwLsA4D9p/8uoKcr+v+U9x5DQVAPAehjSdghb7D9sc1IetODgP8MVwwB1pu6/azPk6OGe978W8t/TUc3rP+0QMvYfP+A/RsG/QpSE8D+l3uwScxzgPwQaifgujuw/k1Vti1I43z8MAwLnSh0GQH5nYnwwZgJAiGUzWC5s6j8WyyI/BbLgPw4iUapGeQJAB3W+imnp/j9BLWR4ssrpP2t+gG5Pstk/cpBsfm6DCMCOpU9dOZsFQEv8nFypHeo/ehJ6i+6S2D9jqlGEmarLv7STC5TRiOa/bC+x8WZD6D9H3yUkWpDZP8gZvmCMuQLAreY19/eRBsCoPOc8UzzpP6KI/QV+y9g/t/MoboyWzT+Hv5q3Zu3Mvy2xROCT4uY/9gQitMMg1T9abAqhWMDkv1oLTavoUfG/PMUJP9CD5j+fHRX3t6fSPz7W2gk6bvs/WRnuHwqN9D8YFturGCTmP1EZczv0b9I/5t4exabB5D/1ESLh5fTEP9X2z6SYweQ/6lv3I2zT0D9zkRGNUNMAQKoSvc4EIfs/Xggt8wQI5T+mJHHg/w/SP4lhT/9t8vQ/DrZ/DbwH7D+XlhbYZrjkP34LIpFt6c4/lwfp8fLX9L+j96CTTf76v3WdNhEv9uM/d8c3o4lV0D/vFdCHVcsFwAHeDq0F1QhApbYqcZiN5D9KoilqByXLPwX0/diA0vq/0fo0GxnxAMBbaTkvlCzjP/RrFrWXrMs/UYTrky7jA0DB9f4FiZYAQEGAk/3QzeE/r/TeqE8t0D/OqjlsnPbvvz8RKU8JOfW/smSEbK/O4T8MzuyPm3DDP/rFtctq9gZAfb1EVEaSA0Dts5dVInnhP18SFMc79MM/7y34cw6LAMDFrRJsZO0DwC2KLvLSYuA/hx5wcUHewz+49SnK/4ruPyeS0PX9a+E/ZxaaLvvZ3z8WPu5T2QS8Pygo4RIvMqa/BJ0Kqsd0279cKW4ay8jdP3b05bmZ364/10/qtdxk2r+Bcz6CDMvpv54qOw+Amdw/qLV71pW7sT/YKc80nIPUP8OfIaBJ77G/LyTuD1un2z+diYu8efWzP1wU7ACkfwjAZroyPL1yBkAmv3lKJJbbPysKSE4W+p0/dIgqY79TA8ATLTOQ3tsGwJ2zweD/Xdg/XO/jXeFUaL8VW2qLFKfov1cA9Aa6XfK/tIa7YGgI2T+f3hu/sxqPv2nXdPpf3Pc/jkw8Jbda8j+tT/z8tGPVP1yBHpJd35k/KYvYOy1s8j/yz+kCQjPrP9+agH7x59g/PZfJ9aBhpr/rDKzvYBb+PwtkiaGCt/c/vb1mVr+f1T/JIHwHc8Govw7aeF6+9vG/Xv7kD6fp979isYioQYHVP7AIQZuSFrG/3z1AdUTnAUDN3XY9O7f9P0AdQ9ljYNQ/dJANJPTOrb8kLECUiiPlP4yF7UgmStA/9xGmXxCG1T9qZzix4W2zv2SGJRJVrPe/Fh9a2M/B/b8IexzFCoPSP9y1QFD2bLe/Q86cWLJe/b+mOOfYm78BwOTjkPAGE9E/8aPCUKu/ub9pPZyLCiUGwBA7Mev/BQlALOmrlRi+0j+AMJ/dKULBv7iLtL6a6QRAEMDV/yajAUDa62dE3crJP1P70RgBUbq/38hVnR6esT/s1tG10Z/Ov/zLwalHPss/dTS9NKTXx78nMcRzCIEHQAabxDsAmQRA0tyLK3gSyT+Aui7nOhDGv5Gs58z3WgHATN3forJuBMCAui7nOhDGP9Lciyt4Esm/WAJyHQ4c7z8UP5HFIs3iP3U0vTSk18c//MvBqUc+y7+cvv8HLg/Kvy1I/mHsI+K/U/vRGAFRuj/a62dE3crJv8p+WV8KlQjAuQ/nOP43B0CAMJ/dKULBPyzpq5UYvtK/ZoU+VoLh4L9etLlRUfvtv/GjwlCrv7k/5OOQ8AYT0b9DfT9FhufXPwUX8hJp+4u/3LVAUPZstz8IexzFCoPSv9+L609E5fQ/q9Fz7X2J7T9qZzix4W2zP/cRpl8QhtW/vtNilqGX+j8MOy7QJoL0P3SQDST0zq0/QB1D2WNg1L8IIjSvGNkDwGB8Jou2GAfAsAhBm5IWsT9isYioQYHVvyS9D3zb6uy/gnwRa7uM9L/JIHwHc8GoP729Zla/n9W/CsAHJZwmAEDEW6OYT1r6Pz2XyfWgYaY/35qAfvHn2L83Tdy4lS30vxf2/gZ0jPq/XIEekl3fmb+tT/z8tGPVvybPr2zJ1/+/K7mJ0ypVAsCf3hu/sxqPPwCGu2BoCNm/5oITrpZn+r+UDUyDP+n/v1zv413hVGg/nbPB4P9d2L9MlmkxNvgCQMtZlKE85v8/KwpIThb6nb8mv3lKJJbbv8+SZsTvOOc/pQCIIOYw0j+diYu8efWzvy8k7g9bp9u/kxYDa+pKtD9XlYvA8HnVv6i1e9aVu7G/nio7D4CZ3L/WR6rNh5EGwCkgQweBkghAdvTluZnfrr9cKW4ay8jdvxbjhr1f1QVAR5C0MzivAkAWPu5T2QS8v2cWmi772d+/cKj4lzLJCEBx2QJfYrMFQIcecHFB3sO/LYou8tJi4L+jr7lhO38BwIcI0Nb7xgTAXxIUxzv0w7/ts5dVInnhv0T+l8DZLfE/MP3FoFvS5D8MzuyPm3DDv7JkhGyvzuG/tzhzRIRc0b9Ovv3/0z7mv6/03qhPLdC/m4CT/dDN4b9dwjU5VCQBQBBJX1ntCv0/9GsWtZesy79baTkvlCzjv1mjYgEz++S/oW6KnOQW8b9KoilqByXLv6W2KnGYjeS/SmaKz3Vx9z+BZB5yxGHwP3fHN6OJVdC/dZ02ES/2478PuaBjLrXaP4/JU81pPaO/fgsikW3pzr+XlhbYZrjkv4tSn7YDbP0/f2LnFKlF9z+mJHHg/w/Sv14ILfMECOW/mfg4qYhR/b+OP+RQDCACwOpb9yNs09C/1fbPpJjB5L9pN2WOVZ3wv3hHy9nxIve/URlzO/Rv0r8YFturGCTmv1d1/KKR8QPA8gsy9qzSB8CfHRX3t6fSvzzFCT/Qg+a/EYStnrzV9r/2QJqI7Lb9v/YEIrTDINW/LbFE4JPi5r/7kQEs5fEDQHunnf4GeQBAooj9BX7L2L+oPOc8Uzzpv+ydYY2SSAfAL4HK6CRTB0BH3yUkWpDZv2wvsfFmQ+i/Ik0Yzruh6T8fM3LoGoDUP3oSeovukti/S/ycXKkd6r9rEv+7UWcHQCRIQe/GfwNAa36Abk+y2b9BLWR4ssrpv9KT87qa0bM/FTyktw823L8WyyI/BbLgv4hlM1gubOq/DizMp9Ki6r8b5ckdjVrzv5NVbYtSON+/BBqJ+C6O7L/dUBFqgyXYv00Wh18r7+q/7RAy9h8/4L8W8t/TUc3rv4RM5DKx3wDAfvWIj94aBcBsc1IetODgv3oY0nYIW+y/oGcTFF54AUDkJqS/FKX6PwzNxsC7AOC/ltfN1PUC7L+5Wrz/zHnzP6688w2rNOc/YeV9neCo4b9nlSHXANfuvw9RsxKjY/s/1V8GteXE8j+1C8NdDcfiv2wlcW3YZO+/IOywaA7Q8b9bFP+4Tg36v4GTTeNZi+O/9t/ywdRi77+tRc3yFR7eP2bkcHXJkLO//ITc9SjT4r+qoBf2J0nwv2YHKoswwfm/iQcLspCjAcCb6wCzCvXkvwXv9rkMT/C/YkuwYAMXBMApCNUai9kIwMORhtNuJ+e/BVt01fKF8L+ZqWEfvIjsP6h693QZYNk/WyOTkB2i5b8of+GtdSDxvwpaaulDSwVADMQAX+lOAECEHWF8XNPmv1cr/B+VnvG/XyFG6opcCMD/mtR32/UEQP+2XEF3hui/ulBTjAt88r/imfCfRP+yP9zbvtc8XeO/TZuKJD5G6b/MaTExyXzyvxiTQeElXOO/rbJRQVGN9L/z0wR2g9DqvxOqKRxEX/O/FDGCEei99j9x8zV4VYTmP2lzCnsYk+u/l6ELZ9tg878pRXacaDT/v3k6GZRqoQXAVB67LiP56r94+LDK0Sn0vwO6pZ9b7wFAvK0nKVcc9j8+U/hCvyruv6QMsuuLQ/W/FPhKFYv46j8MyxaDTOW/v9L18g1caO2/vebfvctE9b/7GD8ZrF3xv3gx1AR9bQDAuMEtsM4c77+SabgA2nj0v5xKFIwxsATArKNSBaKsB0Cjara6ozTwv33ArMz7sfa/dF2U0FcWCcDxL357DJX/P69pJmt7c/G/quJYWJZl+L/YntVJlnrSP4sRLzXM+fe/46uU8w3c8r+q4lhYlmX4v85lu5+QRwRAsI0H/WU8479jaeZNtj/zv6riWFiWZfi/sI0H/WU847/OZbufkEcEQHAoPUBrnss/9exKzDtFtT88wM8kax+gP9OqeKeAYog/MW0ItiZvcj+ph+smvt5bP2lCaV5dEUU/StaUmQDaLz+kK9y22BMYP0O3whZuMwI/IIbgZGWE6z7UkjYaEM3UPuezxwa9cr8+LybxRMnFpz6E1N8DbPiRPsYjySMvK3s+//////8fAAj//////zMQCP////9/MiAI/////28yMAj/////YzJACP///z9iMlAI////N2IyYAj///8zYjJwCP//vzNiMoAI//+rM2IykAj/f6szYjKgCP8PqzNiMrAI/wOrM2IywAi/A6szYjLQCJ8DqzNiMuAImQOrM2Iy8Aj//////z8PCP//////Kx8I/////38pLwj/////Pyk/CP////85KU8I////PzgpXwj///8POClvCP///w44KX8I//8fDjgpjwj//w8OOCmfCP9/DQ44Ka8I/w8NDjgpvwj/DQ0OOCnPCP8MDQ44Kd8IxwwNDjgp7wjEDA0OOCn/CAcAAAAHAAAAAQAAAAIAAAAEAAAAAwAAAAAAAAAAAAAABwAAAAMAAAABAAAAAgAAAAUAAAAEAAAAAAAAAAAAAAAEAAAABAAAAAAAAAACAAAAAQAAAAMAAAAOAAAABgAAAAsAAAACAAAABwAAAAEAAAAYAAAABQAAAAoAAAABAAAABgAAAAAAAAAmAAAABwAAAAwAAAADAAAACAAAAAIAAAAxAAAACQAAAA4AAAAAAAAABQAAAAQAAAA6AAAACAAAAA0AAAAEAAAACQAAAAMAAAA/AAAACwAAAAYAAAAPAAAACgAAABAAAABIAAAADAAAAAcAAAAQAAAACwAAABEAAABTAAAACgAAAAUAAAATAAAADgAAAA8AAABhAAAADQAAAAgAAAARAAAADAAAABIAAABrAAAADgAAAAkAAAASAAAADQAAABMAAAB1AAAADwAAABMAAAARAAAAEgAAABAAAAAGAAAAAgAAAAMAAAAFAAAABAAAAAAAAAAAAAAAAAAAAAYAAAACAAAAAwAAAAEAAAAFAAAABAAAAAAAAAAAAAAABwAAAAUAAAADAAAABAAAAAEAAAAAAAAAAgAAAAAAAAACAAAAAwAAAAEAAAAFAAAABAAAAAYAAAAAAAAAAAAAABgtRFT7Ifk/GC1EVPsh+b8YLURU+yEJQBgtRFT7IQnAYWxnb3MuYwBoM05laWdoYm9yUm90YXRpb25zAGNvb3JkaWprLmMAX3VwQXA3Q2hlY2tlZABfdXBBcDdyQ2hlY2tlZABkaXJlY3RlZEVkZ2UuYwBkaXJlY3RlZEVkZ2VUb0JvdW5kYXJ5AGFkamFjZW50RmFjZURpclt0bXBGaWprLmZhY2VdW2ZpamsuZmFjZV0gPT0gS0kAZmFjZWlqay5jAF9mYWNlSWprUGVudFRvQ2VsbEJvdW5kYXJ5AGFkamFjZW50RmFjZURpcltjZW50ZXJJSksuZmFjZV1bZmFjZTJdID09IEtJAF9mYWNlSWprVG9DZWxsQm91bmRhcnkAaDNJbmRleC5jAGNvbXBhY3RDZWxscwBsYXRMbmdUb0NlbGwAY2VsbFRvQ2hpbGRQb3MAdmFsaWRhdGVDaGlsZFBvcwBsYXRMbmcuYwBjZWxsQXJlYVJhZHMyAHBvbHlnb24tPm5leHQgPT0gTlVMTABsaW5rZWRHZW8uYwBhZGROZXdMaW5rZWRQb2x5Z29uAG5leHQgIT0gTlVMTABsb29wICE9IE5VTEwAYWRkTmV3TGlua2VkTG9vcABwb2x5Z29uLT5maXJzdCA9PSBOVUxMAGFkZExpbmtlZExvb3AAY29vcmQgIT0gTlVMTABhZGRMaW5rZWRDb29yZABsb29wLT5maXJzdCA9PSBOVUxMAGlubmVyTG9vcHMgIT0gTlVMTABub3JtYWxpemVNdWx0aVBvbHlnb24AYmJveGVzICE9IE5VTEwAY2FuZGlkYXRlcyAhPSBOVUxMAGZpbmRQb2x5Z29uRm9ySG9sZQBjYW5kaWRhdGVCQm94ZXMgIT0gTlVMTAByZXZEaXIgIT0gSU5WQUxJRF9ESUdJVABsb2NhbGlqLmMAY2VsbFRvTG9jYWxJamsAYmFzZUNlbGwgIT0gb3JpZ2luQmFzZUNlbGwAIShvcmlnaW5PblBlbnQgJiYgaW5kZXhPblBlbnQpAGJhc2VDZWxsID09IG9yaWdpbkJhc2VDZWxsAGJhc2VDZWxsICE9IElOVkFMSURfQkFTRV9DRUxMAGxvY2FsSWprVG9DZWxsACFfaXNCYXNlQ2VsbFBlbnRhZ29uKGJhc2VDZWxsKQBiYXNlQ2VsbFJvdGF0aW9ucyA+PSAwAGdyaWRQYXRoQ2VsbHMAcG9seWZpbGwuYwBpdGVyU3RlcFBvbHlnb25Db21wYWN0ADAAdmVydGV4LmMAY2VsbFRvVmVydGV4AGdyYXBoLT5idWNrZXRzICE9IE5VTEwAdmVydGV4R3JhcGguYwBpbml0VmVydGV4R3JhcGgAbm9kZSAhPSBOVUxMAGFkZFZlcnRleE5vZGU=";var j="function"==typeof atob?atob:function(e){var t,n,r,i,s,a,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",c="",A=0;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");do{t=o.indexOf(e.charAt(A++))<<2|(i=o.indexOf(e.charAt(A++)))>>4,n=(15&i)<<4|(s=o.indexOf(e.charAt(A++)))>>2,r=(3&s)<<6|(a=o.indexOf(e.charAt(A++))),c+=String.fromCharCode(t),64!==s&&(c+=String.fromCharCode(n)),64!==a&&(c+=String.fromCharCode(r))}while(A<e.length);return c};function H(e){if(U(e))return function(e){try{for(var t=j(e),n=new Uint8Array(t.length),r=0;r<t.length;++r)n[r]=t.charCodeAt(r);return n}catch(fH){throw new Error("Converting base64 string to bytes failed.")}}(e.slice(G.length))}var z=function(e,t,n){var r=new e.Int8Array(n),i=new e.Int32Array(n);new e.Uint8Array(n),new e.Float32Array(n);var s=new e.Float64Array(n),a=0|t.o,o=0|t.p,c=e.Math.floor,A=e.Math.abs,l=e.Math.sqrt,f=e.Math.pow,u=e.Math.cos,d=e.Math.sin,h=e.Math.tan,p=e.Math.acos,m=e.Math.asin,y=e.Math.atan,g=e.Math.atan2,b=e.Math.ceil,w=e.Math.imul,v=e.Math.min,_=e.Math.max,E=e.Math.clz32,k=t.b,T=t.c,S=t.d,x=t.e,I=t.f,P=t.g,C=t.h,N=t.i,O=28640;function R(e,t,n,r){return 0|B(e|=0,t|=0,n|=0,r|=0,0)}function B(e,t,n,r,s){var a,o=0,c=0,A=0,l=0;if(a=O,O=O+16|0,c=a,!(0|M(e|=0,t|=0,n|=0,r|=0,s|=0)))return O=a,0;do{if((0|n)>=0){if((0|n)>13780509){if(0|(o=0|ct(15,c)))break;c=0|i[(A=c)>>2],A=0|i[A+4>>2]}else l=0|Wt(0|n,0|(o=((0|n)<0)<<31>>31),3,0),A=0|T(),o=0|qt(0|n,0|o,1,0),o=0|qt(0|(o=0|Wt(0|l,0|A,0|o,0|T())),0|T(),1,0),A=0|T(),i[c>>2]=o,i[c+4>>2]=A,c=o;if(cn(0|r,0,c<<3),0|s){cn(0|s,0,c<<2),o=0|$(e,t,n,r,s,c,A,0);break}(o=0|zt(c,4))?(l=0|$(e,t,n,r,o,c,A,0),Ht(o),o=l):o=13}else o=2}while(0);return O=a,0|o}function M(e,t,n,r,s){e|=0,t|=0,n|=0,r|=0,s|=0;var a,o,c=0,A=0,l=0,f=0,u=0,d=0,h=0,p=0,m=0;if(o=O,O=O+16|0,m=o+8|0,i[(p=a=o)>>2]=e,i[p+4>>2]=t,(0|n)<0)return O=o,2;if(i[(c=r)>>2]=e,i[c+4>>2]=t,(c=!!(0|s))&&(i[s>>2]=0),0|Ge(e,t))return O=o,9;i[m>>2]=0;e:do{if((0|n)>=1)if(c)for(d=1,u=0,h=0,p=1,c=e;;){if(!(u|h)){if(0|(c=0|D(c,t,4,m,a)))break e;if(0|Ge(c=0|i[(t=a)>>2],t=0|i[t+4>>2])){c=9;break e}}if(0|(c=0|D(c,t,0|i[26800+(h<<2)>>2],m,a)))break e;if(c=0|i[(t=a)>>2],t=0|i[t+4>>2],i[(e=r+(d<<3)|0)>>2]=c,i[e+4>>2]=t,i[s+(d<<2)>>2]=p,A=(0|(e=u+1|0))==(0|p),f=6==(0|(l=h+1|0)),0|Ge(c,t)){c=9;break e}if((0|(p=p+(f&A&1)|0))>(0|n)){c=0;break}d=d+1|0,u=A?0:e,h=A?f?0:l:h}else for(d=1,u=0,h=0,p=1,c=e;;){if(!(u|h)){if(0|(c=0|D(c,t,4,m,a)))break e;if(0|Ge(c=0|i[(t=a)>>2],t=0|i[t+4>>2])){c=9;break e}}if(0|(c=0|D(c,t,0|i[26800+(h<<2)>>2],m,a)))break e;if(c=0|i[(t=a)>>2],t=0|i[t+4>>2],i[(e=r+(d<<3)|0)>>2]=c,i[e+4>>2]=t,A=(0|(e=u+1|0))==(0|p),f=6==(0|(l=h+1|0)),0|Ge(c,t)){c=9;break e}if((0|(p=p+(f&A&1)|0))>(0|n)){c=0;break}d=d+1|0,u=A?0:e,h=A?f?0:l:h}else c=0}while(0);return O=o,0|c}function $(e,t,n,r,s,a,o,c){n|=0,r|=0,s|=0,c|=0;var A,l,f,u=0,d=0,h=0,p=0,m=0,y=0,g=0;if(f=O,O=O+16|0,A=f+8|0,l=f,u=0|Zt(0|(e|=0),0|(t|=0),0|(a|=0),0|(o|=0)),h=0|T(),!(!(0|(g=0|i[(y=p=r+(u<<3)|0)>>2]))&!(0|(y=0|i[y+4>>2]))|(d=(0|g)==(0|e)&(0|y)==(0|t))))do{u=0|Yt(0|(u=0|qt(0|u,0|h,1,0)),0|T(),0|a,0|o),h=0|T(),d=(0|(y=0|i[(g=p=r+(u<<3)|0)>>2]))==(0|e)&(0|(g=0|i[g+4>>2]))==(0|t)}while(!(!(0|y)&!(0|g)|d));if(u=s+(u<<2)|0,d&&(0|i[u>>2])<=(0|c))return O=f,0;if(i[(g=p)>>2]=e,i[g+4>>2]=t,i[u>>2]=c,(0|c)>=(0|n))return O=f,0;switch(d=c+1|0,i[A>>2]=0,0|(u=0|D(e,t,2,A,l))){case 9:m=9;break;case 0:(u=0|$(0|i[(u=l)>>2],0|i[u+4>>2],n,r,s,a,o,d))||(m=9)}e:do{if(9==(0|m)){switch(i[A>>2]=0,0|(u=0|D(e,t,3,A,l))){case 9:break;case 0:if(0|(u=0|$(0|i[(u=l)>>2],0|i[u+4>>2],n,r,s,a,o,d)))break e;break;default:break e}switch(i[A>>2]=0,0|(u=0|D(e,t,1,A,l))){case 9:break;case 0:if(0|(u=0|$(0|i[(u=l)>>2],0|i[u+4>>2],n,r,s,a,o,d)))break e;break;default:break e}switch(i[A>>2]=0,0|(u=0|D(e,t,5,A,l))){case 9:break;case 0:if(0|(u=0|$(0|i[(u=l)>>2],0|i[u+4>>2],n,r,s,a,o,d)))break e;break;default:break e}switch(i[A>>2]=0,0|(u=0|D(e,t,4,A,l))){case 9:break;case 0:if(0|(u=0|$(0|i[(u=l)>>2],0|i[u+4>>2],n,r,s,a,o,d)))break e;break;default:break e}switch(i[A>>2]=0,0|(u=0|D(e,t,6,A,l))){case 9:break;case 0:if(0|(u=0|$(0|i[(u=l)>>2],0|i[u+4>>2],n,r,s,a,o,d)))break e;break;default:break e}return O=f,0}}while(0);return O=f,0|u}function D(e,t,n,r,s){e|=0,t|=0,s|=0;var a,o,c=0,A=0,l=0,f=0,u=0,d=0,h=0;if((n|=0)>>>0>6)return 1;if(u=(0|i[(r|=0)>>2])%6|0,i[r>>2]=u,(0|u)>0){c=0;do{n=0|be(n),c=c+1|0}while((0|c)<(0|i[r>>2]))}if(u=0|en(0|e,0|t,45),T(),(o=127&u)>>>0>121)return 5;a=0|je(e,t),c=0|en(0|e,0|t,52),T(),c&=15;e:do{if(c){for(;;){if(l=0|en(0|e,0|t,0|(A=3*(15-c|0)|0)),T(),7==(0|(l&=7))){t=5;break}if(h=!(0|Ve(c)),c=c+-1|0,d=0|tn(7,0,0|A),t&=~T(),e=0|tn(0|i[(h?432:16)+(28*l|0)+(n<<2)>>2],0,0|A)|e&~d,t|=A=0|T(),!(n=0|i[(h?640:224)+(28*l|0)+(n<<2)>>2])){n=0;break e}if(!c){f=8;break e}}return 0|t}f=8}while(0);8==(0|f)&&(e|=0|tn(0|(h=0|i[848+(28*o|0)+(n<<2)>>2]),0,45),t=T()|-1040385&t,n=0|i[4272+(28*o|0)+(n<<2)>>2],127&~h||(h=0|tn(0|i[848+(28*o|0)+20>>2],0,45),t=T()|-1040385&t,n=0|i[4272+(28*o|0)+20>>2],e=0|ze(h|e,t),t=0|T(),i[r>>2]=1+(0|i[r>>2]))),l=0|en(0|e,0|t,45),T(),l&=127;e:do{if(0|L(l)){t:do{if(1==(0|je(e,t))){if((0|o)!=(0|l)){if(0|q(l,0|i[7696+(28*o|0)>>2])){e=0|Qe(e,t),A=1,t=0|T();break}S(27795,26864,533,26872)}switch(0|a){case 3:e=0|ze(e,t),t=0|T(),i[r>>2]=1+(0|i[r>>2]),A=0;break t;case 5:e=0|Qe(e,t),t=0|T(),i[r>>2]=5+(0|i[r>>2]),A=0;break t;case 0:return 9;default:return 1}}else A=0}while(0);if((0|n)>0){c=0;do{e=0|He(e,t),t=0|T(),c=c+1|0}while((0|c)!=(0|n))}if((0|o)!=(0|l)){if(!(0|j(l))){if(!!(0|A)|5!=(0|je(e,t)))break;i[r>>2]=1+(0|i[r>>2]);break}switch(127&u){case 8:case 118:break e}3!=(0|je(e,t))&&(i[r>>2]=1+(0|i[r>>2]))}}else if((0|n)>0){c=0;do{e=0|ze(e,t),t=0|T(),c=c+1|0}while((0|c)!=(0|n))}}while(0);return i[r>>2]=((0|i[r>>2])+n|0)%6|0,i[(h=s)>>2]=e,i[h+4>>2]=t,0}function F(e,t,n,r){e|=0,t|=0,n|=0,r|=0;var s,a,o=0,c=0,A=0,l=0,f=0,u=0,d=0,h=0,p=0;if(a=O,O=O+16|0,p=a+8|0,i[(h=s=a)>>2]=e,i[h+4>>2]=t,(0|n)<0)return O=a,2;if(!n)return i[(p=r)>>2]=e,i[p+4>>2]=t,O=a,0;i[p>>2]=0;e:do{if(0|Ge(e,t))e=9;else{o=0,h=e;do{if(0|(e=0|D(h,t,4,p,s)))break e;if(o=o+1|0,0|Ge(h=0|i[(t=s)>>2],t=0|i[t+4>>2])){e=9;break e}}while((0|o)<(0|n));i[(d=r)>>2]=h,i[d+4>>2]=t,d=n+-1|0,u=0,e=1;do{if(o=26800+(u<<2)|0,5==(0|u))for(A=0|i[o>>2],c=0,o=e;;){if(0|(e=0|D(0|i[(e=s)>>2],0|i[e+4>>2],A,p,s)))break e;if((0|c)!=(0|d)){if(l=0|i[(f=s)>>2],f=0|i[f+4>>2],i[(e=r+(o<<3)|0)>>2]=l,i[e+4>>2]=f,0|Ge(l,f)){e=9;break e}e=o+1|0}else e=o;if((0|(c=c+1|0))>=(0|n))break;o=e}else for(A=s,f=0|i[o>>2],l=0,o=e,c=0|i[A>>2],A=0|i[A+4>>2];;){if(0|(e=0|D(c,A,f,p,s)))break e;if(c=0|i[(A=s)>>2],A=0|i[A+4>>2],i[(e=r+(o<<3)|0)>>2]=c,i[e+4>>2]=A,e=o+1|0,0|Ge(c,A)){e=9;break e}if((0|(l=l+1|0))>=(0|n))break;o=e}u=u+1|0}while(u>>>0<6);e=(0|h)==(0|i[(e=s)>>2])&&(0|t)==(0|i[e+4>>2])?0:9}}while(0);return O=a,0|e}function G(e,t,n,r){n|=0,r|=0;var s,a,o,c=0,A=0;for(o=O,O=O+16|0,s=o,a=o+8|0,c=(c=!(0|Ge(e|=0,t|=0)))?1:2;;){if(i[a>>2]=0,!(0|D(e,t,c,a,s))&((0|i[(A=s)>>2])==(0|n)?(0|i[A+4>>2])==(0|r):0)){e=4;break}if((c=c+1|0)>>>0>=7){c=7,e=4;break}}return 4==(0|e)?(O=o,0|c):0}function U(e,t,n,r,a,o,c){t|=0,n|=0,r|=0,a|=0,o|=0,c|=0;var A,l,f,u,d,h,p,m,y,g,b=0,w=0,v=0,_=0,E=0,k=0,S=0,x=0,I=0,P=0,C=0,N=0,R=0,B=0,M=0,$=0,D=0,F=0,G=0;if(g=O,O=O+64|0,p=g+48|0,m=g+32|0,y=g+24|0,A=g+8|0,l=g,(0|(w=0|i[(e|=0)>>2]))<=0)return O=g,0;for(f=e+4|0,u=p+8|0,d=m+8|0,h=A+8|0,b=0,R=0;;){N=(v=0|i[f>>2])+(R<<4)|0,i[p>>2]=i[N>>2],i[p+4>>2]=i[N+4>>2],i[p+8>>2]=i[N+8>>2],i[p+12>>2]=i[N+12>>2],(0|R)==(w+-1|0)?(i[m>>2]=i[v>>2],i[m+4>>2]=i[v+4>>2],i[m+8>>2]=i[v+8>>2],i[m+12>>2]=i[v+12>>2]):(N=v+(R+1<<4)|0,i[m>>2]=i[N>>2],i[m+4>>2]=i[N+4>>2],i[m+8>>2]=i[N+8>>2],i[m+12>>2]=i[N+12>>2]),w=0|ne(p,m,r,y);e:do{if(w)v=0,b=w;else if(v=0|i[(w=y)>>2],(0|(w=0|i[w+4>>2]))>0|!(0|w)&v>>>0>0){C=0,N=0;t:for(;;){if(D=1/(+(v>>>0)+4294967296*+(0|w)),G=+s[p>>3],F=+((w=0|Qt(0|v,0|w,0|C,0|N))>>>0)+4294967296*+(0|T()),$=+(C>>>0)+4294967296*+(0|N),s[A>>3]=D*(G*F)+D*(+s[m>>3]*$),s[h>>3]=D*(+s[u>>3]*F)+D*(+s[d>>3]*$),0|(w=0|Je(A,r,l))){b=w;break}k=0|Zt(0|(I=0|i[(P=l)>>2]),0|(P=0|i[P+4>>2]),0|t,0|n),_=0|T(),v=0|i[(E=w=c+(k<<3)|0)>>2],E=0|i[E+4>>2];n:do{if(!(0|v)&!(0|E))B=w,M=16;else for(S=0,x=0;;){if((0|S)>(0|n)|(0|S)==(0|n)&x>>>0>t>>>0){b=1;break t}if((0|v)==(0|I)&(0|E)==(0|P))break n;if(k=0|Yt(0|(w=0|qt(0|k,0|_,1,0)),0|T(),0|t,0|n),_=0|T(),x=0|qt(0|x,0|S,1,0),S=0|T(),!(0|(v=0|i[(E=w=c+(k<<3)|0)>>2]))&!(0|(E=0|i[E+4>>2]))){B=w,M=16;break}}}while(0);if(16!=(0|M)||(M=0,!(0|I)&!(0|P))||(i[(x=B)>>2]=I,i[x+4>>2]=P,x=o+(i[a>>2]<<3)|0,i[x>>2]=I,i[x+4>>2]=P,x=0|qt(0|i[(x=a)>>2],0|i[x+4>>2],1,0),I=0|T(),i[(P=a)>>2]=x,i[P+4>>2]=I),C=0|qt(0|C,0|N,1,0),N=0|T(),v=0|i[(w=y)>>2],!((0|(w=0|i[w+4>>2]))>(0|N)|(0|w)==(0|N)&v>>>0>C>>>0)){v=1;break e}}v=0}else v=1}while(0);if(R=R+1|0,!v){M=21;break}if((0|R)>=(0|(w=0|i[e>>2]))){b=0,M=21;break}}return 21==(0|M)?(O=g,0|b):0}function L(e){return(e|=0)>>>0>121?0|(e=0):0|(e=0|i[7696+(28*e|0)+16>>2])}function j(e){return 4==(0|(e|=0))|117==(0|e)|0}function H(e){return 0|i[11120+(216*(0|i[(e|=0)>>2])|0)+(72*(0|i[e+4>>2])|0)+(24*(0|i[e+8>>2])|0)+(i[e+12>>2]<<3)>>2]}function z(e){return 0|i[11120+(216*(0|i[(e|=0)>>2])|0)+(72*(0|i[e+4>>2])|0)+(24*(0|i[e+8>>2])|0)+(i[e+12>>2]<<3)+4>>2]}function q(e,t){return t|=0,(0|i[7696+(28*(e|=0)|0)+20>>2])==(0|t)?0|(t=1):0|(t=(0|i[7696+(28*e|0)+24>>2])==(0|t))}function Q(e,t){return 0|i[848+(28*(e|=0)|0)+((t|=0)<<2)>>2]}function V(e,t){return t|=0,(0|i[848+(28*(e|=0)|0)>>2])==(0|t)?0|(t=0):(0|i[848+(28*e|0)+4>>2])==(0|t)?0|(t=1):(0|i[848+(28*e|0)+8>>2])==(0|t)?0|(t=2):(0|i[848+(28*e|0)+12>>2])==(0|t)?0|(t=3):(0|i[848+(28*e|0)+16>>2])==(0|t)?0|(t=4):(0|i[848+(28*e|0)+20>>2])==(0|t)?0|(t=5):0|((0|i[848+(28*e|0)+24>>2])==(0|t)?6:7)}function J(e){var t,n,r;return t=(r=+s[16+(e|=0)>>3])-(n=+s[e+24>>3]),+(r<n?t+6.283185307179586:t)}function K(e){return+s[16+(e|=0)>>3]<+s[e+24>>3]|0}function W(e){return+(+s[(e|=0)>>3]-+s[e+8>>3])}function Y(e,t){e|=0;var n,r,i=0;return(i=+s[(t|=0)>>3])>=+s[e+8>>3]&&i<=+s[e>>3]?(n=+s[e+16>>3],i=+s[e+24>>3],t=(r=+s[t+8>>3])>=i,e=r<=n&1,n<i?t&&(e=1):t||(e=0),0|(t=!!(0|e))):0|(t=0)}function Z(e,t){t|=0;var n,r,i,a,o,c=0,A=0,l=0,f=0;return+s[(e|=0)>>3]<+s[t+8>>3]||+s[e+8>>3]>+s[t>>3]?0|(c=0):(i=(A=+s[e+16>>3])<(f=+s[(n=e+24|0)>>3]),l=(o=+s[(c=t+16|0)>>3])<(a=+s[(r=t+24|0)>>3]),t=f-o<a-A,e=i?l|t?1:2:0,t=l?i?1:t?2:1:0,(A=+st(A,e))<+st(+s[r>>3],t)||(f=+st(+s[n>>3],e))>+st(+s[c>>3],t)?0|(l=0):0|(l=1))}function X(e,t){t|=0;var n,r,i,a,o,c=0,A=0,l=0,f=0;return+s[(e|=0)>>3]<+s[t>>3]||+s[e+8>>3]>+s[t+8>>3]?0|(c=0):(i=(a=+s[(c=e+16|0)>>3])<(A=+s[e+24>>3]),l=(f=+s[(n=t+16|0)>>3])<(o=+s[(r=t+24|0)>>3]),t=A-f<o-a,e=i?l|t?1:2:0,t=l?i?1:t?2:1:0,(A=+st(A,e))<=+st(+s[r>>3],t)?0|(l=(f=+st(+s[c>>3],e))>=+st(+s[n>>3],t)):0|(l=0))}function ee(e,t){e|=0,t|=0;var n,r,a,o,c,A=0;a=O,O=O+176|0,i[(r=a)>>2]=4,A=+s[t>>3],s[r+8>>3]=A,o=+s[t+16>>3],s[r+16>>3]=o,s[r+24>>3]=A,A=+s[t+24>>3],s[r+32>>3]=A,c=+s[t+8>>3],s[r+40>>3]=c,s[r+48>>3]=A,s[r+56>>3]=c,s[r+64>>3]=o,n=96+(t=r+72|0)|0;do{i[t>>2]=0,t=t+4|0}while((0|t)<(0|n));on(0|e,0|r,168),O=a}function te(e,t,n){e|=0,t|=0,n|=0;var r,o,l,f,u,d,h,p=0,m=0,y=0,g=0,w=0,_=0,E=0;d=O,O=O+288|0,u=d+264|0,g=d+96|0,m=(p=y=d)+96|0;do{i[p>>2]=0,p=p+4|0}while((0|p)<(0|m));return 0|(t=0|Xe(t,y))?(O=d,0|(_=t)):(Ye(y=0|i[(m=y)>>2],m=0|i[m+4>>2],u),Ze(y,m,g),f=+at(u,g+8|0),s[u>>3]=+s[e>>3],s[(m=u+8|0)>>3]=+s[e+16>>3],s[g>>3]=+s[e+8>>3],s[(y=g+8|0)>>3]=+s[e+24>>3],o=+at(u,g),E=+s[m>>3]-+s[y>>3],l=+A(+E),h=+s[u>>3]-+s[g>>3],r=+A(+h),!(0==E|0==h)&&(E=+rn(+l,+r),E=+b(+o*o/+sn(+E/+sn(+l,+r),3)/(f*(2.59807621135*f)*.8)),s[a>>3]=E,w=~~E>>>0,_=+A(E)>=1?E>0?~~+v(+c(E/4294967296),4294967295)>>>0:~~+b((E-+(~~E>>>0))/4294967296)>>>0:0,2146435072&~i[a+4>>2])?(g=!(0|w)&!(0|_),i[(t=n)>>2]=g?1:w,i[t+4>>2]=g?0:_,t=0):t=1,O=d,0|(_=t))}function ne(e,t,n,r){e|=0,t|=0,n|=0,r|=0;var o,l,f,u,d=0,h=0,p=0;u=O,O=O+288|0,l=u+264|0,f=u+96|0,o=(d=h=u)+96|0;do{i[d>>2]=0,d=d+4|0}while((0|d)<(0|o));return 0|(n=0|Xe(n,h))?(O=u,0|(r=n)):(Ye(d=0|i[(n=h)>>2],n=0|i[n+4>>2],l),Ze(d,n,f),p=+at(l,f+8|0),p=+b(+ +at(e,t)/(2*p)),s[a>>3]=p,n=~~p>>>0,d=+A(p)>=1?p>0?~~+v(+c(p/4294967296),4294967295)>>>0:~~+b((p-+(~~p>>>0))/4294967296)>>>0:0,2146435072&~i[a+4>>2]?(h=!(0|n)&!(0|d),i[r>>2]=h?1:n,i[r+4>>2]=h?0:d,O=u,0|(r=0)):(O=u,0|(r=1)))}function re(e,t,n,r){t|=0,n|=0,r|=0,i[(e|=0)>>2]=t,i[e+4>>2]=n,i[e+8>>2]=r}function ie(e){var t,n=0,r=0,s=0,a=0,o=0;n=0|i[(e|=0)>>2],r=0|i[(t=e+4|0)>>2],(0|n)<0&&(r=r-n|0,i[t>>2]=r,i[(o=e+8|0)>>2]=(0|i[o>>2])-n,i[e>>2]=0,n=0),(0|r)<0?(n=n-r|0,i[e>>2]=n,a=(0|i[(o=e+8|0)>>2])-r|0,i[o>>2]=a,i[t>>2]=0,r=0):(o=a=e+8|0,a=0|i[a>>2]),(0|a)<0&&(n=n-a|0,i[e>>2]=n,r=r-a|0,i[t>>2]=r,i[o>>2]=0,a=0),(0|(s=(0|a)<(0|(s=(0|r)<(0|n)?r:n))?a:s))<=0||(i[e>>2]=n-s,i[t>>2]=r-s,i[o>>2]=a-s)}function se(e,t){var n,r;t|=0,r=0|i[8+(e|=0)>>2],n=+((0|i[e+4>>2])-r|0),s[t>>3]=+((0|i[e>>2])-r|0)-.5*n,s[t+8>>3]=.8660254037844386*n}function ae(e,t,n){e|=0,t|=0,i[(n|=0)>>2]=(0|i[t>>2])+(0|i[e>>2]),i[n+4>>2]=(0|i[t+4>>2])+(0|i[e+4>>2]),i[n+8>>2]=(0|i[t+8>>2])+(0|i[e+8>>2])}function oe(e,t,n){e|=0,t|=0,i[(n|=0)>>2]=(0|i[e>>2])-(0|i[t>>2]),i[n+4>>2]=(0|i[e+4>>2])-(0|i[t+4>>2]),i[n+8>>2]=(0|i[e+8>>2])-(0|i[t+8>>2])}function ce(e,t){t|=0;var n,r=0;r=0|w(0|i[(e|=0)>>2],t),i[e>>2]=r,n=0|w(0|i[(r=e+4|0)>>2],t),i[r>>2]=n,t=0|w(0|i[(e=e+8|0)>>2],t),i[e>>2]=t}function Ae(e){var t,n,r=0,s=0,a=0,o=0,c=0;c=(0|(n=0|i[(e|=0)>>2]))<0,e=(e=(s=(0|(o=((t=(0|(a=(0|i[e+4>>2])-(c?n:0)|0))<0)?0-a|0:0)+((0|i[e+8>>2])-(c?n:0))|0))<0)?0:o)-((a=(0|(s=(0|e)<(0|(s=(0|(r=(t?0:a)-(s?o:0)|0))<(0|(o=(c?0:n)-(t?a:0)-(s?o:0)|0))?r:o))?e:s))>0)?s:0)|0,r=r-(a?s:0)|0;e:do{switch(o-(a?s:0)|0){case 0:switch(0|r){case 0:return 0|(0|e?1==(0|e)?1:7:0);case 1:return 0|(0|e?1==(0|e)?3:7:2);default:break e}case 1:switch(0|r){case 0:return 0|(0|e?1==(0|e)?5:7:4);case 1:if(e)break e;return 6;default:break e}}}while(0);return 7}function le(e){var t,n,r=0,s=0,a=0,o=0,c=0,A=0,l=0;if(A=0|i[(n=8+(e|=0)|0)>>2],(t=(0|i[e>>2])-A|0)>>>0>715827881|(A=(0|i[(l=e+4|0)>>2])-A|0)>>>0>715827881){if(o=2147483647-t|0,c=-2147483648-t|0,(a=(0|t)>0)?(0|o)<(0|t):(0|c)>(0|t))return 1;if(s=t<<1,a?(2147483647-s|0)<(0|t):(-2147483648-s|0)>(0|t))return 1;if((0|A)>0?(2147483647-A|0)<(0|A):(-2147483648-A|0)>(0|A))return 1;if(r=3*t|0,s=A<<1,(a?(0|o)<(0|s):(0|c)>(0|s))||((0|t)>-1?(-2147483648|r)>=(0|A):(-2147483648^r)<(0|A)))return 1}else s=A<<1,r=3*t|0;return a=0|Lt(.14285714285714285*+(r-A|0)),i[e>>2]=a,o=0|Lt(.14285714285714285*+(s+t|0)),i[l>>2]=o,i[n>>2]=0,r=(s=(0|o)<(0|a))?a:o,(0|(s=s?o:a))<0&&((-2147483648==(0|s)||((0|r)>0?(2147483647-r|0)<(0|s):(-2147483648-r|0)>(0|s)))&&S(27795,26892,354,26903),((0|r)>-1?(-2147483648|r)>=(0|s):(-2147483648^r)<(0|s))&&S(27795,26892,354,26903)),r=o-a|0,(0|a)<0?(s=0-a|0,i[l>>2]=r,i[n>>2]=s,i[e>>2]=0,a=0):(r=o,s=0),(0|r)<0&&(a=a-r|0,i[e>>2]=a,s=s-r|0,i[n>>2]=s,i[l>>2]=0,r=0),c=a-s|0,o=r-s|0,(0|s)<0?(i[e>>2]=c,i[l>>2]=o,i[n>>2]=0,r=o,o=c,s=0):o=a,(0|(a=(0|s)<(0|(a=(0|r)<(0|o)?r:o))?s:a))<=0||(i[e>>2]=o-a,i[l>>2]=r-a,i[n>>2]=s-a),0}function fe(e){var t,n=0,r=0,s=0,a=0,o=0,c=0,A=0;if(a=0|i[(t=8+(e|=0)|0)>>2],(o=(0|i[e>>2])-a|0)>>>0>715827881|(a=(0|i[(c=e+4|0)>>2])-a|0)>>>0>715827881){if((r=(0|o)>0)?(2147483647-o|0)<(0|o):(-2147483648-o|0)>(0|o))return 1;if(n=o<<1,(s=(0|a)>0)?(2147483647-a|0)<(0|a):(-2147483648-a|0)>(0|a))return 1;if(A=a<<1,s?(2147483647-A|0)<(0|a):(-2147483648-A|0)>(0|a))return 1;if(r?(2147483647-n|0)<(0|a):(-2147483648-n|0)>(0|a))return 1;if(r=3*a|0,(0|a)>-1?(-2147483648|r)>=(0|o):(-2147483648^r)<(0|o))return 1}else r=3*a|0,n=o<<1;return s=0|Lt(.14285714285714285*+(n+a|0)),i[e>>2]=s,a=0|Lt(.14285714285714285*+(r-o|0)),i[c>>2]=a,i[t>>2]=0,n=(r=(0|a)<(0|s))?s:a,(0|(r=r?a:s))<0&&((-2147483648==(0|r)||((0|n)>0?(2147483647-n|0)<(0|r):(-2147483648-n|0)>(0|r)))&&S(27795,26892,402,26917),((0|n)>-1?(-2147483648|n)>=(0|r):(-2147483648^n)<(0|r))&&S(27795,26892,402,26917)),n=a-s|0,(0|s)<0?(r=0-s|0,i[c>>2]=n,i[t>>2]=r,i[e>>2]=0,s=0):(n=a,r=0),(0|n)<0&&(s=s-n|0,i[e>>2]=s,r=r-n|0,i[t>>2]=r,i[c>>2]=0,n=0),o=s-r|0,a=n-r|0,(0|r)<0?(i[e>>2]=o,i[c>>2]=a,i[t>>2]=0,n=a,a=o,r=0):a=s,(0|(s=(0|r)<(0|(s=(0|n)<(0|a)?n:a))?r:s))<=0||(i[e>>2]=a-s,i[c>>2]=n-s,i[t>>2]=r-s),0}function ue(e){var t,n,r=0,s=0,a=0,o=0,c=0;s=0|i[(t=8+(e|=0)|0)>>2],a=0|Lt(.14285714285714285*+((3*(r=(0|i[e>>2])-s|0)|0)-(s=(0|i[(n=e+4|0)>>2])-s|0)|0)),i[e>>2]=a,r=0|Lt(.14285714285714285*+((s<<1)+r|0)),i[n>>2]=r,i[t>>2]=0,s=r-a|0,(0|a)<0?(c=0-a|0,i[n>>2]=s,i[t>>2]=c,i[e>>2]=0,r=s,a=0,s=c):s=0,(0|r)<0&&(a=a-r|0,i[e>>2]=a,s=s-r|0,i[t>>2]=s,i[n>>2]=0,r=0),c=a-s|0,o=r-s|0,(0|s)<0?(i[e>>2]=c,i[n>>2]=o,i[t>>2]=0,r=o,o=c,s=0):o=a,(0|(a=(0|s)<(0|(a=(0|r)<(0|o)?r:o))?s:a))<=0||(i[e>>2]=o-a,i[n>>2]=r-a,i[t>>2]=s-a)}function de(e){var t,n,r=0,s=0,a=0,o=0,c=0;s=0|i[(t=8+(e|=0)|0)>>2],a=0|Lt(.14285714285714285*+(((r=(0|i[e>>2])-s|0)<<1)+(s=(0|i[(n=e+4|0)>>2])-s|0)|0)),i[e>>2]=a,r=0|Lt(.14285714285714285*+((3*s|0)-r|0)),i[n>>2]=r,i[t>>2]=0,s=r-a|0,(0|a)<0?(c=0-a|0,i[n>>2]=s,i[t>>2]=c,i[e>>2]=0,r=s,a=0,s=c):s=0,(0|r)<0&&(a=a-r|0,i[e>>2]=a,s=s-r|0,i[t>>2]=s,i[n>>2]=0,r=0),c=a-s|0,o=r-s|0,(0|s)<0?(i[e>>2]=c,i[n>>2]=o,i[t>>2]=0,r=o,o=c,s=0):o=a,(0|(a=(0|s)<(0|(a=(0|r)<(0|o)?r:o))?s:a))<=0||(i[e>>2]=o-a,i[n>>2]=r-a,i[t>>2]=s-a)}function he(e){var t,n,r,s=0,a=0,o=0,c=0;s=0|i[(e|=0)>>2],a=0|i[(n=e+4|0)>>2],o=0|i[(r=e+8|0)>>2],c=a+(3*s|0)|0,i[e>>2]=c,a=o+(3*a|0)|0,i[n>>2]=a,s=(3*o|0)+s|0,i[r>>2]=s,o=a-c|0,(0|c)<0?(s=s-c|0,i[n>>2]=o,i[r>>2]=s,i[e>>2]=0,a=o,o=0):o=c,(0|a)<0&&(o=o-a|0,i[e>>2]=o,s=s-a|0,i[r>>2]=s,i[n>>2]=0,a=0),t=o-s|0,c=a-s|0,(0|s)<0?(i[e>>2]=t,i[n>>2]=c,i[r>>2]=0,o=t,s=0):c=a,(0|(a=(0|s)<(0|(a=(0|c)<(0|o)?c:o))?s:a))<=0||(i[e>>2]=o-a,i[n>>2]=c-a,i[r>>2]=s-a)}function pe(e){var t,n,r,s=0,a=0,o=0,c=0;c=0|i[(e|=0)>>2],o=(3*(s=0|i[(n=e+4|0)>>2])|0)+c|0,c=(a=0|i[(r=e+8|0)>>2])+(3*c|0)|0,i[e>>2]=c,i[n>>2]=o,s=(3*a|0)+s|0,i[r>>2]=s,a=o-c|0,(0|c)<0?(s=s-c|0,i[n>>2]=a,i[r>>2]=s,i[e>>2]=0,c=0):a=o,(0|a)<0&&(c=c-a|0,i[e>>2]=c,s=s-a|0,i[r>>2]=s,i[n>>2]=0,a=0),t=c-s|0,o=a-s|0,(0|s)<0?(i[e>>2]=t,i[n>>2]=o,i[r>>2]=0,c=t,s=0):o=a,(0|(a=(0|s)<(0|(a=(0|o)<(0|c)?o:c))?s:a))<=0||(i[e>>2]=c-a,i[n>>2]=o-a,i[r>>2]=s-a)}function me(e,t){e|=0;var n,r,s,a=0,o=0,c=0;((t|=0)-1|0)>>>0>=6||(c=(0|i[15440+(12*t|0)>>2])+(0|i[e>>2])|0,i[e>>2]=c,s=e+4|0,o=(0|i[15440+(12*t|0)+4>>2])+(0|i[s>>2])|0,i[s>>2]=o,r=e+8|0,t=(0|i[15440+(12*t|0)+8>>2])+(0|i[r>>2])|0,i[r>>2]=t,a=o-c|0,(0|c)<0?(t=t-c|0,i[s>>2]=a,i[r>>2]=t,i[e>>2]=0,o=0):(a=o,o=c),(0|a)<0&&(o=o-a|0,i[e>>2]=o,t=t-a|0,i[r>>2]=t,i[s>>2]=0,a=0),n=o-t|0,c=a-t|0,(0|t)<0?(i[e>>2]=n,i[s>>2]=c,i[r>>2]=0,o=n,t=0):c=a,(0|(a=(0|t)<(0|(a=(0|c)<(0|o)?c:o))?t:a))<=0||(i[e>>2]=o-a,i[s>>2]=c-a,i[r>>2]=t-a))}function ye(e){var t,n,r,s=0,a=0,o=0,c=0;c=0|i[(e|=0)>>2],o=(s=0|i[(n=e+4|0)>>2])+c|0,c=(a=0|i[(r=e+8|0)>>2])+c|0,i[e>>2]=c,i[n>>2]=o,s=a+s|0,i[r>>2]=s,a=o-c|0,(0|c)<0?(s=s-c|0,i[n>>2]=a,i[r>>2]=s,i[e>>2]=0,o=0):(a=o,o=c),(0|a)<0&&(o=o-a|0,i[e>>2]=o,s=s-a|0,i[r>>2]=s,i[n>>2]=0,a=0),t=o-s|0,c=a-s|0,(0|s)<0?(i[e>>2]=t,i[n>>2]=c,i[r>>2]=0,o=t,s=0):c=a,(0|(a=(0|s)<(0|(a=(0|c)<(0|o)?c:o))?s:a))<=0||(i[e>>2]=o-a,i[n>>2]=c-a,i[r>>2]=s-a)}function ge(e){var t,n,r,s=0,a=0,o=0,c=0;s=0|i[(e|=0)>>2],o=0|i[(n=e+4|0)>>2],a=0|i[(r=e+8|0)>>2],c=o+s|0,i[e>>2]=c,o=a+o|0,i[n>>2]=o,s=a+s|0,i[r>>2]=s,a=o-c|0,(0|c)<0?(s=s-c|0,i[n>>2]=a,i[r>>2]=s,i[e>>2]=0,o=0):(a=o,o=c),(0|a)<0&&(o=o-a|0,i[e>>2]=o,s=s-a|0,i[r>>2]=s,i[n>>2]=0,a=0),t=o-s|0,c=a-s|0,(0|s)<0?(i[e>>2]=t,i[n>>2]=c,i[r>>2]=0,o=t,s=0):c=a,(0|(a=(0|s)<(0|(a=(0|c)<(0|o)?c:o))?s:a))<=0||(i[e>>2]=o-a,i[n>>2]=c-a,i[r>>2]=s-a)}function be(e){switch(0|(e|=0)){case 1:e=5;break;case 5:e=4;break;case 4:e=6;break;case 6:e=2;break;case 2:e=3;break;case 3:e=1}return 0|e}function we(e){switch(0|(e|=0)){case 1:e=3;break;case 3:e=2;break;case 2:e=6;break;case 6:e=4;break;case 4:e=5;break;case 5:e=1}return 0|e}function ve(e){var t,n,r,s=0,a=0,o=0,c=0;s=0|i[(e|=0)>>2],a=0|i[(n=e+4|0)>>2],o=0|i[(r=e+8|0)>>2],c=a+(s<<1)|0,i[e>>2]=c,a=o+(a<<1)|0,i[n>>2]=a,s=(o<<1)+s|0,i[r>>2]=s,o=a-c|0,(0|c)<0?(s=s-c|0,i[n>>2]=o,i[r>>2]=s,i[e>>2]=0,a=o,o=0):o=c,(0|a)<0&&(o=o-a|0,i[e>>2]=o,s=s-a|0,i[r>>2]=s,i[n>>2]=0,a=0),t=o-s|0,c=a-s|0,(0|s)<0?(i[e>>2]=t,i[n>>2]=c,i[r>>2]=0,o=t,s=0):c=a,(0|(a=(0|s)<(0|(a=(0|c)<(0|o)?c:o))?s:a))<=0||(i[e>>2]=o-a,i[n>>2]=c-a,i[r>>2]=s-a)}function _e(e){var t,n,r,s=0,a=0,o=0,c=0;c=0|i[(e|=0)>>2],o=((s=0|i[(n=e+4|0)>>2])<<1)+c|0,c=(a=0|i[(r=e+8|0)>>2])+(c<<1)|0,i[e>>2]=c,i[n>>2]=o,s=(a<<1)+s|0,i[r>>2]=s,a=o-c|0,(0|c)<0?(s=s-c|0,i[n>>2]=a,i[r>>2]=s,i[e>>2]=0,c=0):a=o,(0|a)<0&&(c=c-a|0,i[e>>2]=c,s=s-a|0,i[r>>2]=s,i[n>>2]=0,a=0),t=c-s|0,o=a-s|0,(0|s)<0?(i[e>>2]=t,i[n>>2]=o,i[r>>2]=0,c=t,s=0):o=a,(0|(a=(0|s)<(0|(a=(0|o)<(0|c)?o:c))?s:a))<=0||(i[e>>2]=c-a,i[n>>2]=o-a,i[r>>2]=s-a)}function Ee(e,t){t|=0;var n,r,s,a=0,o=0,c=0;return s=(0|(r=(0|i[(e|=0)>>2])-(0|i[t>>2])|0))<0,n=(0|(o=(0|i[e+4>>2])-(0|i[t+4>>2])-(s?r:0)|0))<0,t=(t=(e=(0|(c=(s?0-r|0:0)+(0|i[e+8>>2])-(0|i[t+8>>2])+(n?0-o|0:0)|0))<0)?0:c)-((o=(0|(e=(0|t)<(0|(e=(0|(a=(n?0:o)-(e?c:0)|0))<(0|(c=(s?0:r)-(n?o:0)-(e?c:0)|0))?a:c))?t:e))>0)?e:0)|0,a=a-(o?e:0)|0,0|((0|(e=(0|(e=c-(o?e:0)|0))>-1?e:0-e|0))>(0|(t=(0|(a=(0|a)>-1?a:0-a|0))>(0|(t=(0|t)>-1?t:0-t|0))?a:t))?e:t)}function ke(e){var t,n,r,s;n=(s=0|i[(t=8+(e|=0)|0)>>2])-(0|i[e>>2])|0,i[e>>2]=n,e=(0|i[(r=e+4|0)>>2])-s|0,i[r>>2]=e,i[t>>2]=0-(e+n)}function Te(e){var t,n,r=0,s=0,a=0,o=0,c=0;r=0-(s=0|i[(e|=0)>>2])|0,i[e>>2]=r,i[(t=e+8|0)>>2]=0,o=(a=0|i[(n=e+4|0)>>2])+s|0,(0|s)>0?(i[n>>2]=o,i[t>>2]=s,i[e>>2]=0,r=0,a=o):s=0,(0|a)<0?(c=r-a|0,i[e>>2]=c,s=s-a|0,i[t>>2]=s,i[n>>2]=0,o=c-s|0,r=0-s|0,(0|s)<0?(i[e>>2]=o,i[n>>2]=r,i[t>>2]=0,a=r,s=0):(a=0,o=c)):o=r,(0|(r=(0|s)<(0|(r=(0|a)<(0|o)?a:o))?s:r))<=0||(i[e>>2]=o-r,i[n>>2]=a-r,i[t>>2]=s-r)}function Se(e,t,n){n|=0;var r,s,a=0,o=0;return s=O,O=O+16|0,r=s,o=-2130706433&(t|=0)|134217728,!0&268435456==(2013265920&t)?(a=0|en(0|(e|=0),0|t,56),T(),a=0|function(e,t,n){n|=0;var r,s=0,a=0;if(r=O,O=O+16|0,a=r,s=0|Ge(e|=0,t|=0),(n+-1|0)>>>0>5)return O=r,-1;if(1==(0|n)&(s=!!(0|s)))return O=r,-1;do{if(!(0|Ot(e,t,a))){if(s){s=(5+(0|i[26352+(n<<2)>>2])-(0|i[a>>2])|0)%5|0;break}s=(6+(0|i[26384+(n<<2)>>2])-(0|i[a>>2])|0)%6|0;break}s=-1}while(0);return O=r,0|(a=s)}(e,o,7&a),-1==(0|a)?(i[n>>2]=0,O=s,0|(o=6)):(0|We(e,o,r)&&S(27795,26932,282,26947),t=0|en(0|e,0|t,52),T(),t&=15,0|Ge(e,o)?Ie(r,t,a,2,n):Oe(r,t,a,2,n),O=s,0|(o=0))):(O=s,0|(o=6))}function xe(e,t,n,r,a){t|=0,n|=0,r|=0,a|=0;var o,c=0,f=0;if(c=+function(e){var t,n;return n=+s[(e|=0)>>3],t=+s[e+8>>3],+ +l(+(n*n+t*t))}(e|=0),c<1e-16)return t=15600+(t<<4)|0,i[a>>2]=i[t>>2],i[a+4>>2]=i[t+4>>2],i[a+8>>2]=i[t+8>>2],void(i[a+12>>2]=i[t+12>>2]);if(f=+g(+ +s[e+8>>3],+ +s[e>>3]),(0|n)>0){e=0;do{c*=.37796447300922725,e=e+1|0}while((0|e)!=(0|n))}o=.3333333333333333*c,r?(n=!(0|Ve(n)),c=+y(.381966011250105*(n?o:.37796447300922725*o))):(c=+y(.381966011250105*c),0|Ve(n)&&(f=+rt(f+.3334731722518321))),function(e,t,n,r){e|=0,t=+t,r|=0;var a=0,o=0,c=0,l=0;if((n=+n)<1e-16)return i[r>>2]=i[e>>2],i[r+4>>2]=i[e+4>>2],i[r+8>>2]=i[e+8>>2],void(i[r+12>>2]=i[e+12>>2]);o=t<0?t+6.283185307179586:t,o=t>=6.283185307179586?o+-6.283185307179586:o;do{if(!(o<1e-16)){if(a=+A(+(o+-3.141592653589793))<1e-16,t=+s[e>>3],a){t-=n,s[r>>3]=t,a=r;break}if(c=+u(+n),n=+d(+n),t=c*+d(+t)+ +u(+o)*(n*+u(+t)),t=+m(+((t=t>1?1:t)<-1?-1:t)),s[r>>3]=t,+A(+(t+-1.5707963267948966))<1e-16)return s[r>>3]=1.5707963267948966,void(s[r+8>>3]=0);if(+A(+(t+1.5707963267948966))<1e-16)return s[r>>3]=-1.5707963267948966,void(s[r+8>>3]=0);if(l=1/+u(+t),o=n*+d(+o)*l,n=+s[e>>3],t=l*((c-+d(+t)*+d(+n))/+u(+n)),c=o>1?1:o,t=t>1?1:t,(t=+s[e+8>>3]+ +g(+(c<-1?-1:c),+(t<-1?-1:t)))>3.141592653589793)do{t+=-6.283185307179586}while(t>3.141592653589793);if(t<-3.141592653589793)do{t+=6.283185307179586}while(t<-3.141592653589793);return void(s[r+8>>3]=t)}t=+s[e>>3]+n,s[r>>3]=t,a=r}while(0);if(+A(+(t+-1.5707963267948966))<1e-16)return s[a>>3]=1.5707963267948966,void(s[r+8>>3]=0);if(+A(+(t+1.5707963267948966))<1e-16)return s[a>>3]=-1.5707963267948966,void(s[r+8>>3]=0);if((t=+s[e+8>>3])>3.141592653589793)do{t+=-6.283185307179586}while(t>3.141592653589793);if(t<-3.141592653589793)do{t+=6.283185307179586}while(t<-3.141592653589793);s[r+8>>3]=t}(15600+(t<<4)|0,+rt(+s[15920+(24*t|0)>>3]-f),c,a)}function Ie(e,t,n,r,a){e|=0,t|=0,n|=0,r|=0,a|=0;var o,c,A,l,f,u,d,h,p,m,y,g,b,w,v,_,E,k,T,x,I,P,C=0,N=0,R=0,B=0,M=0,$=0;if(P=O,O=O+272|0,B=P+240|0,T=P,x=P+224|0,I=P+208|0,y=P+176|0,g=P+160|0,b=P+192|0,w=P+144|0,v=P+128|0,_=P+112|0,E=P+96|0,k=P+80|0,i[(C=P+256|0)>>2]=t,i[B>>2]=i[e>>2],i[B+4>>2]=i[e+4>>2],i[B+8>>2]=i[e+8>>2],i[B+12>>2]=i[e+12>>2],Pe(B,C,T),i[a>>2]=0,(0|(B=r+n+(5==(0|r)&1)|0))<=(0|n))O=P;else{c=x+4|0,A=y+4|0,l=n+5|0,f=16880+((o=0|i[C>>2])<<2)|0,u=16960+(o<<2)|0,d=v+8|0,h=_+8|0,p=E+8|0,m=I+4|0,R=n;e:for(;;){N=T+((0|R)%5<<4)|0,i[I>>2]=i[N>>2],i[I+4>>2]=i[N+4>>2],i[I+8>>2]=i[N+8>>2],i[I+12>>2]=i[N+12>>2];do{}while(2==(0|Ce(I,o,0,1)));if((0|R)>(0|n)&!!(0|Ve(t))){if(i[y>>2]=i[I>>2],i[y+4>>2]=i[I+4>>2],i[y+8>>2]=i[I+8>>2],i[y+12>>2]=i[I+12>>2],se(c,g),r=0|i[y>>2],C=0|i[17040+(80*r|0)+(i[x>>2]<<2)>>2],i[y>>2]=i[18640+(80*r|0)+(20*C|0)>>2],(0|(N=0|i[18640+(80*r|0)+(20*C|0)+16>>2]))>0){e=0;do{ye(A),e=e+1|0}while((0|e)<(0|N))}switch(N=18640+(80*r|0)+(20*C|0)+4|0,i[b>>2]=i[N>>2],i[b+4>>2]=i[N+4>>2],i[b+8>>2]=i[N+8>>2],ce(b,3*(0|i[f>>2])|0),ae(A,b,A),ie(A),se(A,w),M=+(0|i[u>>2]),s[v>>3]=3*M,s[d>>3]=0,$=-1.5*M,s[_>>3]=$,s[h>>3]=2.598076211353316*M,s[E>>3]=$,s[p>>3]=-2.598076211353316*M,0|i[17040+(80*(0|i[y>>2])|0)+(i[I>>2]<<2)>>2]){case 1:e=_,r=v;break;case 3:e=E,r=_;break;case 2:e=v,r=E;break;default:e=12;break e}Pt(g,w,r,e,k),xe(k,0|i[y>>2],o,1,a+8+(i[a>>2]<<4)|0),i[a>>2]=1+(0|i[a>>2])}if((0|R)<(0|l)&&(se(m,y),xe(y,0|i[I>>2],o,1,a+8+(i[a>>2]<<4)|0),i[a>>2]=1+(0|i[a>>2])),i[x>>2]=i[I>>2],i[x+4>>2]=i[I+4>>2],i[x+8>>2]=i[I+8>>2],i[x+12>>2]=i[I+12>>2],(0|(R=R+1|0))>=(0|B)){e=3;break}}3!=(0|e)?12==(0|e)&&S(26970,27017,572,27027):O=P}}function Pe(e,t,n){e|=0,t|=0,n|=0;var r,s=0,a=0,o=0,c=0,A=0;r=O,O=O+128|0,a=r,c=20240,A=60+(o=s=r+64|0)|0;do{i[o>>2]=i[c>>2],o=o+4|0,c=c+4|0}while((0|o)<(0|A));c=20304,A=(o=a)+60|0;do{i[o>>2]=i[c>>2],o=o+4|0,c=c+4|0}while((0|o)<(0|A));s=(A=!(0|Ve(0|i[t>>2])))?s:a,ve(a=e+4|0),_e(a),0|Ve(0|i[t>>2])&&(pe(a),i[t>>2]=1+(0|i[t>>2])),i[n>>2]=i[e>>2],ae(a,s,t=n+4|0),ie(t),i[n+16>>2]=i[e>>2],ae(a,s+12|0,t=n+20|0),ie(t),i[n+32>>2]=i[e>>2],ae(a,s+24|0,t=n+36|0),ie(t),i[n+48>>2]=i[e>>2],ae(a,s+36|0,t=n+52|0),ie(t),i[n+64>>2]=i[e>>2],ae(a,s+48|0,n=n+68|0),ie(n),O=r}function Ce(e,t,n,r){n|=0,r|=0;var s,a,o,c,A,l,f=0,u=0,d=0,h=0,p=0;if(l=O,O=O+32|0,A=l+12|0,a=l,p=4+(e|=0)|0,h=0|i[16960+((t|=0)<<2)>>2],h=(c=!!(0|r))?3*h|0:h,f=0|i[p>>2],s=0|i[(o=e+8|0)>>2],c){if((0|(f=s+f+(r=0|i[(u=e+12|0)>>2])|0))==(0|h))return O=l,1;d=u}else f=s+f+(r=0|i[(d=e+12|0)>>2])|0;if((0|f)<=(0|h))return O=l,0;do{if((0|r)>0){if(r=0|i[e>>2],(0|s)>0){u=18640+(80*r|0)+60|0,r=e;break}r=18640+(80*r|0)+40|0,n?(re(A,h,0,0),oe(p,A,a),ge(a),ae(a,A,p),u=r,r=e):(u=r,r=e)}else u=18640+(80*(0|i[e>>2])|0)+20|0,r=e}while(0);if(i[r>>2]=i[u>>2],(0|i[(f=u+16|0)>>2])>0){r=0;do{ye(p),r=r+1|0}while((0|r)<(0|i[f>>2]))}return e=u+4|0,i[A>>2]=i[e>>2],i[A+4>>2]=i[e+4>>2],i[A+8>>2]=i[e+8>>2],t=0|i[16880+(t<<2)>>2],ce(A,c?3*t|0:t),ae(p,A,p),ie(p),r=c&&((0|i[o>>2])+(0|i[p>>2])+(0|i[d>>2])|0)==(0|h)?1:2,O=l,0|r}function Ne(e,t){e|=0,t|=0;var n=0;do{n=0|Ce(e,t,0,1)}while(2==(0|n));return 0|n}function Oe(e,t,n,r,a){e|=0,t|=0,n|=0,r|=0,a|=0;var o,c,A,l,f,u,d,h,p,m,y,g,b,w,v,_,E,k,T=0,x=0,I=0,P=0,C=0;if(k=O,O=O+240|0,w=k+208|0,v=k,_=k+192|0,E=k+176|0,p=k+160|0,m=k+144|0,y=k+128|0,g=k+112|0,b=k+96|0,i[(T=k+224|0)>>2]=t,i[w>>2]=i[e>>2],i[w+4>>2]=i[e+4>>2],i[w+8>>2]=i[e+8>>2],i[w+12>>2]=i[e+12>>2],Re(w,T,v),i[a>>2]=0,(0|(h=r+n+(6==(0|r)&1)|0))<=(0|n))O=k;else{c=n+6|0,A=16960+((o=0|i[T>>2])<<2)|0,l=m+8|0,f=y+8|0,u=g+8|0,d=_+4|0,x=0,I=n,r=-1;e:for(;;){if(e=v+((T=(0|I)%6|0)<<4)|0,i[_>>2]=i[e>>2],i[_+4>>2]=i[e+4>>2],i[_+8>>2]=i[e+8>>2],i[_+12>>2]=i[e+12>>2],e=x,x=0|Ce(_,o,0,1),(0|I)>(0|n)&!!(0|Ve(t))&&1!=(0|e)&&(0|i[_>>2])!=(0|r)){switch(se(v+((T+5|0)%6<<4)+4|0,E),se(v+(T<<4)+4|0,p),P=+(0|i[A>>2]),s[m>>3]=3*P,s[l>>3]=0,C=-1.5*P,s[y>>3]=C,s[f>>3]=2.598076211353316*P,s[g>>3]=C,s[u>>3]=-2.598076211353316*P,T=0|i[w>>2],0|i[17040+(80*T|0)+(((0|r)==(0|T)?i[_>>2]:r)<<2)>>2]){case 1:e=y,r=m;break;case 3:e=g,r=y;break;case 2:e=m,r=g;break;default:e=8;break e}Pt(E,p,r,e,b),0|Ct(E,b)||0|Ct(p,b)||(xe(b,0|i[w>>2],o,1,a+8+(i[a>>2]<<4)|0),i[a>>2]=1+(0|i[a>>2]))}if((0|I)<(0|c)&&(se(d,E),xe(E,0|i[_>>2],o,1,a+8+(i[a>>2]<<4)|0),i[a>>2]=1+(0|i[a>>2])),(0|(I=I+1|0))>=(0|h)){e=3;break}r=0|i[_>>2]}3!=(0|e)?8==(0|e)&&S(27054,27017,737,27099):O=k}}function Re(e,t,n){e|=0,t|=0,n|=0;var r,s=0,a=0,o=0,c=0,A=0;r=O,O=O+160|0,a=r,c=20368,A=72+(o=s=r+80|0)|0;do{i[o>>2]=i[c>>2],o=o+4|0,c=c+4|0}while((0|o)<(0|A));c=20448,A=(o=a)+72|0;do{i[o>>2]=i[c>>2],o=o+4|0,c=c+4|0}while((0|o)<(0|A));s=(A=!(0|Ve(0|i[t>>2])))?s:a,ve(a=e+4|0),_e(a),0|Ve(0|i[t>>2])&&(pe(a),i[t>>2]=1+(0|i[t>>2])),i[n>>2]=i[e>>2],ae(a,s,t=n+4|0),ie(t),i[n+16>>2]=i[e>>2],ae(a,s+12|0,t=n+20|0),ie(t),i[n+32>>2]=i[e>>2],ae(a,s+24|0,t=n+36|0),ie(t),i[n+48>>2]=i[e>>2],ae(a,s+36|0,t=n+52|0),ie(t),i[n+64>>2]=i[e>>2],ae(a,s+48|0,t=n+68|0),ie(t),i[n+80>>2]=i[e>>2],ae(a,s+60|0,n=n+84|0),ie(n),O=r}function Be(e,t){return t=0|en(0|(e|=0),0|(t|=0),45),T(),127&t}function Me(e,t){e|=0;var n=0,i=0,s=0,a=0;return!0&134217728==(-16777216&(t|=0))?(i=0|en(0|e,0|t,52),T(),i&=15,n=0|en(0|e,0|t,45),T(),(n&=127)>>>0>121?0|(e=0):!(613566756&(a=0|tn(0|(s=0|en(0|e,0|t,0|(a=3*(15^i)|0))),0|T(),0|a))&Qt(-1227133514,-1171,0|a,0|(s=0|T())))&!(4681&s&T())&&15==(0|i)|!(0|(a=0|en(0|tn(0|~e,0|~t,0|(a=19+(3*i|0)|0)),0|T(),0|a)))&!(0|T())?0|r[20528+n|0]?!(0|e)&!(0|(t&=8191))?0|(a=1):(a=0|nn(0|e,0|t),T(),0|!!((63-a|0)%3|0)):0|(a=1):0|(a=0)):0|(e=0)}function $e(e,t,n,r){e|=0,n|=0,r|=0;var s=0,a=0,o=0,c=0;if(s=0|tn(0|(t|=0),0,52),a=0|T(),n=0|tn(0|n,0,45),n=0|a|T()|134225919,(0|t)<1)return a=-1,r=n,i[(t=e)>>2]=a,void(i[(e=e+4|0)>>2]=r);for(a=1,s=-1;c=0|tn(7,0,0|(o=3*(15-a|0)|0)),n&=~T(),s=s&~c|(o=0|tn(0|r,0,0|o)),n=0|n|T(),(0|a)!=(0|t);)a=a+1|0;i[(o=c=e)>>2]=s,i[(c=c+4|0)>>2]=n}function De(e,t,n,r){n|=0,r|=0;var s=0,a=0;if(a=0|en(0|(e|=0),0|(t|=0),52),T(),n>>>0>15)return 4;if((0|(a&=15))<(0|n))return 12;if((0|a)==(0|n))return i[r>>2]=e,i[r+4>>2]=t,0;if(s=0|tn(0|n,0,52),s|=e,e=T()|-15728641&t,(0|a)>(0|n))do{t=0|tn(7,0,3*(14-n|0)|0),n=n+1|0,s|=t,e=0|T()|e}while((0|n)<(0|a));return i[r>>2]=s,i[r+4>>2]=e,0}function Fe(e,t,n,r){n|=0,r|=0;var s=0,a=0,o=0;if(a=0|en(0|(e|=0),0|(t|=0),52),T(),!((0|n)<16&(0|(a&=15))<=(0|n)))return 4;s=n-a|0,n=0|en(0|e,0|t,45),T();e:do{if(0|L(127&n)){t:do{if(0|a){for(n=1;!((o=0|tn(7,0,3*(15-n|0)|0))&e)&!((0|T())&t);){if(!(n>>>0<a>>>0))break t;n=n+1|0}n=0|yt(7,0,s,((0|s)<0)<<31>>31),s=0|T();break e}}while(0);n=0|qt(0|(n=0|Wt(0|(n=0|yt(7,0,s,((0|s)<0)<<31>>31)),0|T(),5,0)),0|T(),-5,-1),n=0|qt(0|(n=0|Kt(0|n,0|T(),6,0)),0|T(),1,0),s=0|T()}else n=0|yt(7,0,s,((0|s)<0)<<31>>31),s=0|T()}while(0);return i[(o=r)>>2]=n,i[o+4>>2]=s,0}function Ge(e,t){var n=0,r=0,i=0;if(i=0|en(0|(e|=0),0|(t|=0),45),T(),!(0|L(127&i)))return 0;i=0|en(0|e,0|t,52),T(),i&=15;e:do{if(i)for(r=1;;){if(n=0|en(0|e,0|t,3*(15-r|0)|0),T(),0|(n&=7))break e;if(!(r>>>0<i>>>0)){n=0;break}r=r+1|0}else n=0}while(0);return 1&!(0|n)}function Ue(e,t,n,r){return e|=0,t|=0,(0|(r|=0))<(0|(n|=0))?(r=e,k(0|(n=t)),0|r):(n=0|tn(-1,-1,3+(3*(r-n|0)|0)|0),r=0|tn(0|~n,0|~T(),3*(15-r|0)|0),n=~T()&t,r=~r&e,k(0|n),0|r)}function Le(e,t,n,r){n|=0,r|=0;var s=0;return s=0|en(0|(e|=0),0|(t|=0),52),T(),(0|n)<16&(0|(s&=15))<=(0|n)?((0|s)<(0|n)&&(s=0|tn(-1,-1,3+(3*(n+-1-s|0)|0)|0),s=0|tn(0|~s,0|~T(),3*(15-n|0)|0),t=~T()&t,e&=~s),s=0|tn(0|n,0,52),n=-15728641&t|T(),i[r>>2]=e|s,i[r+4>>2]=n,0|(r=0)):0|(r=4)}function je(e,t){var n=0,r=0,i=0;if(i=0|en(0|(e|=0),0|(t|=0),52),T(),!(i&=15))return 0;for(r=1;;){if(n=0|en(0|e,0|t,3*(15-r|0)|0),T(),0|(n&=7)){r=5;break}if(!(r>>>0<i>>>0)){n=0,r=5;break}r=r+1|0}return 5==(0|r)?0|n:0}function He(e,t){var n=0,r=0,i=0,s=0,a=0,o=0,c=0;if(c=0|en(0|(e|=0),0|(t|=0),52),T(),!(c&=15))return c=e,k(0|(o=t)),0|c;for(o=1,n=0;;){r=0|tn(7,0,0|(s=3*(15-o|0)|0)),i=0|T(),a=0|en(0|e,0|t,0|s),T(),e=(s=0|tn(0|be(7&a),0,0|s))|e&~r,t=(a=0|T())|t&~i;e:do{if(!n)if(!(s&r|0)&!(a&i|0))n=0;else if(r=0|en(0|e,0|t,52),T(),r&=15){n=1;t:for(;;){switch(a=0|en(0|e,0|t,3*(15-n|0)|0),T(),7&a){case 1:break t;case 0:break;default:n=1;break e}if(!(n>>>0<r>>>0)){n=1;break e}n=n+1|0}for(n=1;;){if(i=0|en(0|e,0|t,0|(a=3*(15-n|0)|0)),T(),s=0|tn(7,0,0|a),t&=~T(),e=e&~s|(a=0|tn(0|be(7&i),0,0|a)),t=0|t|T(),!(n>>>0<r>>>0)){n=1;break}n=n+1|0}}else n=1}while(0);if(!(o>>>0<c>>>0))break;o=o+1|0}return k(0|t),0|e}function ze(e,t){var n=0,r=0,i=0,s=0,a=0;if(r=0|en(0|(e|=0),0|(t|=0),52),T(),!(r&=15))return r=e,k(0|(n=t)),0|r;for(n=1;a=0|en(0|e,0|t,0|(s=3*(15-n|0)|0)),T(),i=0|tn(7,0,0|s),t&=~T(),e=(s=0|tn(0|be(7&a),0,0|s))|e&~i,t=0|T()|t,n>>>0<r>>>0;)n=n+1|0;return k(0|t),0|e}function qe(e,t){var n=0,r=0,i=0,s=0,a=0,o=0,c=0;if(c=0|en(0|(e|=0),0|(t|=0),52),T(),!(c&=15))return c=e,k(0|(o=t)),0|c;for(o=1,n=0;;){r=0|tn(7,0,0|(s=3*(15-o|0)|0)),i=0|T(),a=0|en(0|e,0|t,0|s),T(),e=(s=0|tn(0|we(7&a),0,0|s))|e&~r,t=(a=0|T())|t&~i;e:do{if(!n)if(!(s&r|0)&!(a&i|0))n=0;else if(r=0|en(0|e,0|t,52),T(),r&=15){n=1;t:for(;;){switch(a=0|en(0|e,0|t,3*(15-n|0)|0),T(),7&a){case 1:break t;case 0:break;default:n=1;break e}if(!(n>>>0<r>>>0)){n=1;break e}n=n+1|0}for(n=1;;){if(s=0|tn(7,0,0|(i=3*(15-n|0)|0)),a=t&~T(),t=0|en(0|e,0|t,0|i),T(),e=e&~s|(t=0|tn(0|we(7&t),0,0|i)),t=0|a|T(),!(n>>>0<r>>>0)){n=1;break}n=n+1|0}}else n=1}while(0);if(!(o>>>0<c>>>0))break;o=o+1|0}return k(0|t),0|e}function Qe(e,t){var n=0,r=0,i=0,s=0,a=0;if(r=0|en(0|(e|=0),0|(t|=0),52),T(),!(r&=15))return r=e,k(0|(n=t)),0|r;for(n=1;s=0|tn(7,0,0|(a=3*(15-n|0)|0)),i=t&~T(),t=0|en(0|e,0|t,0|a),T(),e=(t=0|tn(0|we(7&t),0,0|a))|e&~s,t=0|T()|i,n>>>0<r>>>0;)n=n+1|0;return k(0|t),0|e}function Ve(e){return(0|(e|=0))%2|0}function Je(e,t,n){n|=0;var r,a=0;return r=O,O=O+16|0,a=r,(t|=0)>>>0>15?(O=r,0|(a=4)):2146435072&~i[4+(e|=0)>>2]&&2146435072&~i[e+8+4>>2]?(function(e,t,n){var r,a;r=O,O=O+16|0,function(e,t,n,r){t|=0,r|=0;var a,o=0,c=0,A=0,l=0;if(a=O,O=O+16|0,function(e,t,n){t|=0,n|=0;var r,a,o=0;a=O,O=O+32|0,function(e,t){t|=0;var n,r,i=0;i=+s[(e|=0)>>3],n=+u(+i),i=+d(+i),s[t+16>>3]=i,i=+s[e+8>>3],r=n*+u(+i),s[t>>3]=r,i=n*+d(+i),s[t+8>>3]=i}(e|=0,r=a),i[t>>2]=0,s[n>>3]=5,(o=+Nt(16400,r))<+s[n>>3]&&(i[t>>2]=0,s[n>>3]=o),(o=+Nt(16424,r))<+s[n>>3]&&(i[t>>2]=1,s[n>>3]=o),(o=+Nt(16448,r))<+s[n>>3]&&(i[t>>2]=2,s[n>>3]=o),(o=+Nt(16472,r))<+s[n>>3]&&(i[t>>2]=3,s[n>>3]=o),(o=+Nt(16496,r))<+s[n>>3]&&(i[t>>2]=4,s[n>>3]=o),(o=+Nt(16520,r))<+s[n>>3]&&(i[t>>2]=5,s[n>>3]=o),(o=+Nt(16544,r))<+s[n>>3]&&(i[t>>2]=6,s[n>>3]=o),(o=+Nt(16568,r))<+s[n>>3]&&(i[t>>2]=7,s[n>>3]=o),(o=+Nt(16592,r))<+s[n>>3]&&(i[t>>2]=8,s[n>>3]=o),(o=+Nt(16616,r))<+s[n>>3]&&(i[t>>2]=9,s[n>>3]=o),(o=+Nt(16640,r))<+s[n>>3]&&(i[t>>2]=10,s[n>>3]=o),(o=+Nt(16664,r))<+s[n>>3]&&(i[t>>2]=11,s[n>>3]=o),(o=+Nt(16688,r))<+s[n>>3]&&(i[t>>2]=12,s[n>>3]=o),(o=+Nt(16712,r))<+s[n>>3]&&(i[t>>2]=13,s[n>>3]=o),(o=+Nt(16736,r))<+s[n>>3]&&(i[t>>2]=14,s[n>>3]=o),(o=+Nt(16760,r))<+s[n>>3]&&(i[t>>2]=15,s[n>>3]=o),(o=+Nt(16784,r))<+s[n>>3]&&(i[t>>2]=16,s[n>>3]=o),(o=+Nt(16808,r))<+s[n>>3]&&(i[t>>2]=17,s[n>>3]=o),(o=+Nt(16832,r))<+s[n>>3]&&(i[t>>2]=18,s[n>>3]=o),(o=+Nt(16856,r))<+s[n>>3]?(i[t>>2]=19,s[n>>3]=o,O=a):O=a}(e|=0,n|=0,l=a),(c=+p(+(1-.5*+s[l>>3])))<1e-16)return i[r>>2]=0,i[r+4>>2]=0,i[r+8>>2]=0,i[r+12>>2]=0,void(O=a);if(l=0|i[n>>2],o=+rt((o=+s[15920+(24*l|0)>>3])-+rt(+function(e,t){var n,r,i,a,o;return e|=0,a=+s[(t|=0)>>3],r=+u(+a),i=+s[t+8>>3]-+s[e+8>>3],o=r*+d(+i),n=+s[e>>3],+ +g(+o,+(+d(+a)*+u(+n)-+u(+i)*(r*+d(+n))))}(15600+(l<<4)|0,e))),A=0|Ve(t)?+rt(o+-.3334731722518321):o,o=2.618033988749896*+h(+c),(0|t)>0){e=0;do{o*=2.6457513110645907,e=e+1|0}while((0|e)!=(0|t))}c=+u(+A)*o,s[r>>3]=c,A=+d(+A)*o,s[r+8>>3]=A,O=a}(e|=0,t|=0,n|=0,a=r),function(e,t){e|=0;var n,r,a,o,c=0,l=0,f=0,u=0,d=0,h=0,p=0;i[(o=8+(t|=0)|0)>>2]=0,r=+s[e>>3],u=+A(+r),a=+s[e+8>>3],u+=.5*(d=1.1547005383792515*+A(+a)),u-=+(0|(c=~~u)),d-=+(0|(e=~~d));do{if(u<.5){if(u<.3333333333333333){if(i[t>>2]=c,d<.5*(u+1)){i[t+4>>2]=e;break}e=e+1|0,i[t+4>>2]=e;break}if(e=(1&!(d<(p=1-u)))+e|0,i[t+4>>2]=e,p<=d&d<2*u){c=c+1|0,i[t>>2]=c;break}i[t>>2]=c;break}if(!(u<.6666666666666666)){if(c=c+1|0,i[t>>2]=c,d<.5*u){i[t+4>>2]=e;break}e=e+1|0,i[t+4>>2]=e;break}if(d<1-u){if(i[t+4>>2]=e,2*u-1<d){i[t>>2]=c;break}}else e=e+1|0,i[t+4>>2]=e;c=c+1|0,i[t>>2]=c}while(0);do{if(r<0){if(1&e){c=~~(+(0|c)-(2*(+((h=0|Qt(0|c,((0|c)<0)<<31>>31,0|(h=(e+1|0)/2|0),((0|h)<0)<<31>>31))>>>0)+4294967296*+(0|T()))+1)),i[t>>2]=c;break}c=~~(+(0|c)-2*(+((h=0|Qt(0|c,((0|c)<0)<<31>>31,0|(h=(0|e)/2|0),((0|h)<0)<<31>>31))>>>0)+4294967296*+(0|T()))),i[t>>2]=c;break}}while(0);h=t+4|0,a<0&&(c=c-((1|e<<1)/2|0)|0,i[t>>2]=c,e=0-e|0,i[h>>2]=e),l=e-c|0,(0|c)<0?(f=0-c|0,i[h>>2]=l,i[o>>2]=f,i[t>>2]=0,e=l,c=0):f=0,(0|e)<0&&(c=c-e|0,i[t>>2]=c,f=f-e|0,i[o>>2]=f,i[h>>2]=0,e=0),n=c-f|0,l=e-f|0,(0|f)<0&&(i[t>>2]=n,i[h>>2]=l,i[o>>2]=0,e=l,c=n,f=0),(0|(l=(0|f)<(0|(l=(0|e)<(0|c)?e:c))?f:l))<=0||(i[t>>2]=c-l,i[h>>2]=e-l,i[o>>2]=f-l)}(a,n+4|0),O=r}(e,t,a),t=0|function(e,t){e|=0;var n,r=0,s=0,a=0,o=0,c=0,A=0,l=0,f=0;if(n=O,O=O+64|0,A=n+40|0,s=n+24|0,a=n+12|0,o=n,tn(0|(t|=0),0,52),r=134225919|T(),!t)return(0|i[e+4>>2])>2||(0|i[e+8>>2])>2||(0|i[e+12>>2])>2?(A=0,k(0|(c=0)),O=n,0|A):(tn(0|H(e),0,45),c=0|T()|r,A=-1,k(0|c),O=n,0|A);if(i[A>>2]=i[e>>2],i[A+4>>2]=i[e+4>>2],i[A+8>>2]=i[e+8>>2],i[A+12>>2]=i[e+12>>2],c=A+4|0,(0|t)>0)for(e=-1;i[s>>2]=i[c>>2],i[s+4>>2]=i[c+4>>2],i[s+8>>2]=i[c+8>>2],1&t?(ue(c),i[a>>2]=i[c>>2],i[a+4>>2]=i[c+4>>2],i[a+8>>2]=i[c+8>>2],he(a)):(de(c),i[a>>2]=i[c>>2],i[a+4>>2]=i[c+4>>2],i[a+8>>2]=i[c+8>>2],pe(a)),oe(s,a,o),ie(o),l=0|tn(7,0,0|(f=3*(15-t|0)|0)),r&=~T(),e=(f=0|tn(0|Ae(o),0,0|f))|e&~l,r=0|T()|r,(0|t)>1;)t=t+-1|0;else e=-1;e:do{if((0|i[c>>2])<=2&&(0|i[A+8>>2])<=2&&(0|i[A+12>>2])<=2){if(t=0|tn(0|(s=0|H(A)),0,45),t|=e,e=T()|-1040385&r,o=0|z(A),!(0|L(s))){if((0|o)<=0)break;for(a=0;;){if(s=0|en(0|t,0|e,52),T(),s&=15)for(r=1;A=0|en(0|t,0|e,0|(f=3*(15-r|0)|0)),T(),l=0|tn(7,0,0|f),e&=~T(),t=t&~l|(f=0|tn(0|be(7&A),0,0|f)),e=0|e|T(),r>>>0<s>>>0;)r=r+1|0;if((0|(a=a+1|0))==(0|o))break e}}a=0|en(0|t,0|e,52),T(),a&=15;t:do{if(a){r=1;n:for(;;){switch(f=0|en(0|t,0|e,3*(15-r|0)|0),T(),7&f){case 1:break n;case 0:break;default:break t}if(!(r>>>0<a>>>0))break t;r=r+1|0}if(0|q(s,0|i[A>>2]))for(r=1;l=0|tn(7,0,0|(A=3*(15-r|0)|0)),f=e&~T(),e=0|en(0|t,0|e,0|A),T(),t=t&~l|(e=0|tn(0|we(7&e),0,0|A)),e=0|f|T(),r>>>0<a>>>0;)r=r+1|0;else for(r=1;A=0|en(0|t,0|e,0|(f=3*(15-r|0)|0)),T(),l=0|tn(7,0,0|f),e&=~T(),t=t&~l|(f=0|tn(0|be(7&A),0,0|f)),e=0|e|T(),r>>>0<a>>>0;)r=r+1|0}}while(0);if((0|o)>0){r=0;do{t=0|He(t,e),e=0|T(),r=r+1|0}while((0|r)!=(0|o))}}else t=0,e=0}while(0);return f=t,k(0|(l=e)),O=n,0|f}(a,t),a=0|T(),i[n>>2]=t,i[n+4>>2]=a,!(0|t)&!(0|a)&&S(27795,27122,959,27145),O=r,0|(a=0)):(O=r,0|(a=3))}function Ke(e,t,n){var r,s=0,a=0,o=0;if(r=4+(n|=0)|0,a=0|en(0|(e|=0),0|(t|=0),52),T(),a&=15,o=0|en(0|e,0|t,45),T(),s=!(0|a),0|L(127&o)){if(s)return 1;s=1}else{if(s)return 0;s=0|i[r>>2]||0|i[n+8>>2]?1:1&!!(0|i[n+12>>2])}for(n=1;1&n?he(r):pe(r),o=0|en(0|e,0|t,3*(15-n|0)|0),T(),me(r,7&o),n>>>0<a>>>0;)n=n+1|0;return 0|s}function We(e,t,n){n|=0;var r,s,a=0,o=0,c=0,A=0,l=0,f=0;if(s=O,O=O+16|0,r=s,f=0|en(0|(e|=0),0|(t|=0),45),T(),(f&=127)>>>0>121)return i[n>>2]=0,i[n+4>>2]=0,i[n+8>>2]=0,i[n+12>>2]=0,O=s,5;e:do{if(0|L(f)&&(c=0|en(0|e,0|t,52),T(),0|(c&=15))){a=1;t:for(;;){switch(l=0|en(0|e,0|t,3*(15-a|0)|0),T(),7&l){case 5:break t;case 0:break;default:a=t;break e}if(!(a>>>0<c>>>0)){a=t;break e}a=a+1|0}for(o=1,a=t;A=0|tn(7,0,0|(t=3*(15-o|0)|0)),l=a&~T(),a=0|en(0|e,0|a,0|t),T(),e=e&~A|(a=0|tn(0|we(7&a),0,0|t)),a=0|l|T(),o>>>0<c>>>0;)o=o+1|0}else a=t}while(0);if(l=7696+(28*f|0)|0,i[n>>2]=i[l>>2],i[n+4>>2]=i[l+4>>2],i[n+8>>2]=i[l+8>>2],i[n+12>>2]=i[l+12>>2],!(0|Ke(e,a,n)))return O=s,0;if(A=n+4|0,i[r>>2]=i[A>>2],i[r+4>>2]=i[A+4>>2],i[r+8>>2]=i[A+8>>2],c=0|en(0|e,0|a,52),T(),l=15&c,1&c?(pe(A),c=l+1|0):c=l,0|L(f)){e:do{if(l)for(t=1;;){if(o=0|en(0|e,0|a,3*(15-t|0)|0),T(),0|(o&=7)){a=o;break e}if(!(t>>>0<l>>>0)){a=0;break}t=t+1|0}else a=0}while(0);a=4==(0|a)&1}else a=0;if(0|Ce(n,c,a,0)){if(0|L(f))do{}while(0|Ce(n,c,0,0));(0|c)!=(0|l)&&de(A)}else(0|c)!=(0|l)&&(i[A>>2]=i[r>>2],i[A+4>>2]=i[r+4>>2],i[A+8>>2]=i[r+8>>2]);return O=s,0}function Ye(e,t,n){n|=0;var r,s,a=0;return s=O,O=O+16|0,0|(a=0|We(e|=0,t|=0,r=s))?(O=s,0|a):(a=0|en(0|e,0|t,52),T(),function(e,t,n){var r,s;t|=0,n|=0,r=O,O=O+16|0,se(4+(e|=0)|0,s=r),xe(s,0|i[e>>2],t,0,n),O=r}(r,15&a,n),O=s,0|(a=0))}function Ze(e,t,n){n|=0;var r,i=0,s=0,a=0;if(r=O,O=O+16|0,0|(i=0|We(e|=0,t|=0,a=r)))return O=r,0|i;i=0|en(0|e,0|t,45),T(),i=!(0|L(127&i)),s=0|en(0|e,0|t,52),T(),s&=15;e:do{if(!i){if(0|s)for(i=1;;){if(!(!((0|tn(7,0,3*(15-i|0)|0))&e)&!((0|T())&t)))break e;if(!(i>>>0<s>>>0))break;i=i+1|0}return Ie(a,s,0,5,n),O=r,0}}while(0);return Oe(a,s,0,6,n),O=r,0}function Xe(e,t){t|=0;var n=0,r=0,s=0,a=0,o=0,c=0,A=0;if((e|=0)>>>0>15)return 4;if(tn(0|e,0,52),c=134225919|T(),!e){n=0,r=0;do{0|L(r)&&(tn(0|r,0,45),o=0|c|T(),i[(e=t+(n<<3)|0)>>2]=-1,i[e+4>>2]=o,n=n+1|0),r=r+1|0}while(122!=(0|r));return 0}n=0,o=0;do{if(0|L(o)){for(tn(0|o,0,45),r=1,s=-1,a=0|c|T();s&=~(A=0|tn(7,0,3*(15-r|0)|0)),a&=~T(),(0|r)!=(0|e);)r=r+1|0;i[(A=t+(n<<3)|0)>>2]=s,i[A+4>>2]=a,n=n+1|0}o=o+1|0}while(122!=(0|o));return 0}function et(e,t,n,r){e|=0,r|=0;var s=0,a=0,o=0;s=0|en(0|(t|=0),0|(n|=0),52),T(),!(0|t)&!(0|n)|(0|r)>15|(0|(s&=15))>(0|r)?(a=-1,t=-1,n=0,s=0):(t=0|Ue(t,n,s+1|0,r),o=-15728641&T(),n=0|tn(0|r,0,52),a=s,t=(t=!(0|Ge(n|=t,o=0|o|T())))?-1:r,s=o),i[(o=e)>>2]=n,i[o+4>>2]=s,i[e+8>>2]=a,i[e+12>>2]=t}function tt(e,t,n,r){n|=0,r|=0;var s=0,a=0;return s=0|en(0|(e|=0),0|(t|=0),52),T(),s&=15,i[(a=r+8|0)>>2]=s,!(0|e)&!(0|t)|(0|n)>15|(0|s)>(0|n)?(i[(n=r)>>2]=0,i[n+4>>2]=0,i[a>>2]=-1,void(i[r+12>>2]=-1)):(e=0|Ue(e,t,s+1|0,n),a=-15728641&T(),s=0|tn(0|n,0,52),s|=e,a=0|a|T(),i[(e=r)>>2]=s,i[e+4>>2]=a,e=r+12|0,0|Ge(s,a)?void(i[e>>2]=n):void(i[e>>2]=-1))}function nt(e){var t,n=0,r=0,s=0,a=0,o=0,c=0,A=0,l=0;if(!(!(0|(n=0|i[(r=e|=0)>>2]))&!(0|(r=0|i[r+4>>2]))||(s=0|en(0|n,0|r,52),T(),n=0|qt(0|(A=0|tn(1,0,3*(15^(s&=15))|0)),0|T(),0|n,0|r),r=0|T(),i[(A=e)>>2]=n,i[A+4>>2]=r,(0|s)<(0|(c=0|i[(A=e+8|0)>>2]))))){for(t=e+12|0,o=s;;){if((0|o)==(0|c)){s=5;break}if(l=(0|o)==(0|i[t>>2]),s=0|en(0|n,0|r,0|(a=3*(15-o|0)|0)),T(),l&1==(0|(s&=7))&!0){s=7;break}if(!(7==(0|s)&!0)){s=10;break}if(n=0|qt(0|n,0|r,0|(l=0|tn(1,0,0|a)),0|T()),r=0|T(),i[(l=e)>>2]=n,i[l+4>>2]=r,!((0|o)>(0|c))){s=10;break}o=o+-1|0}if(5==(0|s))return i[(l=e)>>2]=0,i[l+4>>2]=0,i[A>>2]=-1,void(i[t>>2]=-1);if(7==(0|s))return c=0|qt(0|n,0|r,0|(c=0|tn(1,0,0|a)),0|T()),A=0|T(),i[(l=e)>>2]=c,i[l+4>>2]=A,void(i[t>>2]=o+-1)}}function rt(e){var t;return t=(e=+e)<0?e+6.283185307179586:e,+(e>=6.283185307179586?t+-6.283185307179586:t)}function it(e,t){return t|=0,+A(+(+s[(e|=0)>>3]-+s[t>>3]))<17453292519943298e-27?0|(t=+A(+(+s[e+8>>3]-+s[t+8>>3]))<17453292519943298e-27):0|(t=0)}function st(e,t){switch(e=+e,0|(t|=0)){case 1:e=e<0?e+6.283185307179586:e;break;case 2:e=e>0?e+-6.283185307179586:e}return+e}function at(e,t){e|=0;var n,r,i,a=0;return r=+s[(t|=0)>>3],n=+s[e>>3],a=(i=+d(.5*(r-n)))*i+(a=+d(.5*(+s[t+8>>3]-+s[e+8>>3])))*(+u(+r)*+u(+n)*a),2*+g(+ +l(+a),+ +l(+(1-a)))*6371.007180918475}function ot(e,t){return t|=0,(e|=0)>>>0>15?0|(t=4):(s[t>>3]=+s[20656+(e<<3)>>3],0|(t=0))}function ct(e,t){t|=0;var n=0;return(e|=0)>>>0>15?0|(t=4):(n=0|Wt(0|(n=0|yt(7,0,e,((0|e)<0)<<31>>31)),0|T(),120,0),e=0|T(),i[t>>2]=2|n,i[t+4>>2]=e,0|(t=0))}function At(e,t,n){e|=0,n|=0;var r,i,a,o,c=0,A=0,f=0,p=0,m=0,b=0;return b=+s[(t|=0)>>3],a=+s[e>>3],m=+d(.5*(b-a)),f=+s[t+8>>3],i=+s[e+8>>3],p=+d(.5*(f-i)),r=+u(+a),o=+u(+b),p=2*+g(+ +l(+(p=m*m+p*(o*r*p))),+ +l(+(1-p))),m=+s[n>>3],b=+d(.5*(m-b)),c=+s[n+8>>3],f=+d(.5*(c-f)),A=+u(+m),f=2*+g(+ +l(+(f=b*b+f*(o*A*f))),+ +l(+(1-f))),m=+d(.5*(a-m)),c=+d(.5*(i-c)),c=2*+g(+ +l(+(c=m*m+c*(r*A*c))),+ +l(+(1-c))),4*+y(+ +l(+ +h(.5*(A=.5*(p+f+c)))*+h(.5*(A-p))*+h(.5*(A-f))*+h(.5*(A-c))))}function lt(e,t,n){n|=0;var r,a,o,c=0,A=0;if(o=O,O=O+192|0,a=o,0|(A=0|Ye(e|=0,t|=0,r=o+168|0)))return O=o,0|A;if(0|Ze(e,t,a)&&S(27795,27190,415,27199),(0|(t=0|i[a>>2]))>0){if(c=+At(a+8|0,a+8+((1!=(0|t)&1)<<4)|0,r)+0,1!=(0|t)){e=1;do{c+=+At(a+8+((A=e)<<4)|0,a+8+((0|(e=e+1|0))%(0|t)<<4)|0,r)}while((0|e)<(0|t))}}else c=0;return s[n>>3]=c,O=o,0}function ft(e){e|=0;var t,n,r=0;return(t=0|zt(1,12))||S(27280,27235,49,27293),0|(r=0|i[(n=e+4|0)>>2])?(i[(r=r+8|0)>>2]=t,i[n>>2]=t,0|t):(0|i[e>>2]&&S(27310,27235,61,27333),i[(r=e)>>2]=t,i[n>>2]=t,0|t)}function ut(e,t){var n,r;return e|=0,t|=0,(r=0|jt(24))||S(27347,27235,78,27361),i[r>>2]=i[t>>2],i[r+4>>2]=i[t+4>>2],i[r+8>>2]=i[t+8>>2],i[r+12>>2]=i[t+12>>2],i[r+16>>2]=0,0|(n=0|i[(t=e+4|0)>>2])?(i[n+16>>2]=r,i[t>>2]=r,0|r):(0|i[e>>2]&&S(27376,27235,82,27361),i[e>>2]=r,i[t>>2]=r,0|r)}function dt(e){var t=0,n=0,r=0,s=0;if(e|=0)for(r=1;;){if(0|(t=0|i[e>>2]))do{if(0|(n=0|i[t>>2]))do{s=n,n=0|i[n+16>>2],Ht(s)}while(0|n);s=t,t=0|i[t+8>>2],Ht(s)}while(0|t);if(t=e,e=0|i[e+8>>2],r||Ht(t),!e)break;r=0}}function ht(e,t,n){e|=0;var r=0,a=0,o=0,c=0,A=0,l=0,f=0,u=0;if(!(0|Y(t|=0,n|=0)))return 0;if(t=0|K(t),r=+s[n>>3],a=t&(a=+s[n+8>>3])<0?a+6.283185307179586:a,!(e=0|i[e>>2]))return 0;if(t){t=0,f=a,n=e;e:for(;;){for(;c=+s[n>>3],a=+s[n+8>>3],u=0|i[(n=n+16|0)>>2],o=+s[(u=0|u?u:e)>>3],A=+s[u+8>>3],c>o?(l=c,c=A):(l=o,o=c,c=a,a=A),(r=r==o|r==l?r+2220446049250313e-31:r)<o|r>l;)if(!(n=0|i[n>>2])){n=22;break e}if(((l=(A=c<0?c+6.283185307179586:c)+(r-o)/(l-o)*((c=a<0?a+6.283185307179586:a)-A))<0?l+6.283185307179586:l)>(f=A==f|c==f?f+-2220446049250313e-31:f)&&(t^=1),!(n=0|i[n>>2])){n=22;break}}if(22==(0|n))return 0|t}else{t=0,f=a,n=e;e:for(;;){for(;c=+s[n>>3],a=+s[n+8>>3],u=0|i[(n=n+16|0)>>2],o=+s[(u=0|u?u:e)>>3],A=+s[u+8>>3],c>o?(l=c,c=A):(l=o,o=c,c=a,a=A),(r=r==o|r==l?r+2220446049250313e-31:r)<o|r>l;)if(!(n=0|i[n>>2])){n=22;break e}if(c+(r-o)/(l-o)*(a-c)>(f=c==f|a==f?f+-2220446049250313e-31:f)&&(t^=1),!(n=0|i[n>>2])){n=22;break}}if(22==(0|n))return 0|t}return 0}function pt(e,t,n,s,a){n|=0,s|=0,a|=0;var o,c,A,l,f=0,u=0,d=0,h=0,p=0,m=0,y=0,g=0,b=0,w=0;if(l=O,O=O+32|0,w=l+16|0,A=l,f=0|en(0|(e|=0),0|(t|=0),52),T(),f&=15,y=0|en(0|n,0|s,52),T(),(0|f)!=(15&y))return O=l,12;if(p=0|en(0|e,0|t,45),T(),p&=127,m=0|en(0|n,0|s,45),T(),p>>>0>121|(m&=127)>>>0>121)return O=l,5;if(y=(0|p)!=(0|m)){if(7==(0|(d=0|V(p,m))))return O=l,1;7==(0|(h=0|V(m,p)))?S(27514,27538,161,27548):(g=d,u=h)}else g=0,u=0;o=0|L(p),c=0|L(m),i[w>>2]=0,i[w+4>>2]=0,i[w+8>>2]=0,i[w+12>>2]=0;do{if(g){if(d=(0|(m=0|i[4272+(28*p|0)+(g<<2)>>2]))>0,c)if(d){p=0,h=n,d=s;do{h=0|qe(h,d),d=0|T(),1==(0|(u=0|we(u)))&&(u=0|we(1)),p=p+1|0}while((0|p)!=(0|m));m=u,p=h,h=d}else m=u,p=n,h=s;else if(d){p=0,h=n,d=s;do{h=0|Qe(h,d),d=0|T(),u=0|we(u),p=p+1|0}while((0|p)!=(0|m));m=u,p=h,h=d}else m=u,p=n,h=s;if(Ke(p,h,w),y||S(27563,27538,191,27548),(d=!!(0|o))&(u=!!(0|c))&&S(27590,27538,192,27548),d){if(7==(0|(u=0|je(e,t)))){f=5;break}if(0|r[22e3+(7*u|0)+g|0]){f=1;break}p=h=0|i[21168+(28*u|0)+(g<<2)>>2]}else if(u){if(7==(0|(u=0|je(p,h)))){f=5;break}if(0|r[22e3+(7*u|0)+m|0]){f=1;break}p=0,h=0|i[21168+(28*m|0)+(u<<2)>>2]}else p=0,h=0;if((p|h|0)<0)f=5;else{if((0|h)>0){d=w+4|0,u=0;do{ge(d),u=u+1|0}while((0|u)!=(0|h))}if(i[A>>2]=0,i[A+4>>2]=0,i[A+8>>2]=0,me(A,g),0|f)for(;0|Ve(f)?he(A):pe(A),(0|f)>1;)f=f+-1|0;if((0|p)>0){f=0;do{ge(A),f=f+1|0}while((0|f)!=(0|p))}ae(b=w+4|0,A,b),ie(b),b=51}}else if(Ke(n,s,w),!!(0|o)&!!(0|c))if((0|m)!=(0|p)&&S(27621,27538,261,27548),7==(0|(u=0|je(e,t)))|7==(0|(f=0|je(n,s))))f=5;else if(0|r[22e3+(7*u|0)+f|0])f=1;else if((0|(u=0|i[21168+(28*u|0)+(f<<2)>>2]))>0){d=w+4|0,f=0;do{ge(d),f=f+1|0}while((0|f)!=(0|u));b=51}else b=51;else b=51}while(0);return 51==(0|b)&&(f=w+4|0,i[a>>2]=i[f>>2],i[a+4>>2]=i[f+4>>2],i[a+8>>2]=i[f+8>>2],f=0),O=l,0|f}function mt(e,t,n,r){n|=0,r|=0;var s,a,o,c=0,A=0,l=0,f=0,u=0,d=0,h=0,p=0,m=0,y=0,g=0,b=0,w=0;if(o=O,O=O+48|0,s=o+36|0,l=o+24|0,f=o+12|0,u=o,c=0|en(0|(e|=0),0|(t|=0),52),T(),c&=15,h=0|en(0|e,0|t,45),T(),(h&=127)>>>0>121)return O=o,5;if(a=0|L(h),tn(0|c,0,52),y=134225919|T(),i[(A=r)>>2]=-1,i[A+4>>2]=y,!c)return 7==(0|(c=0|Ae(n)))||127==(0|(c=0|Q(h,c)))?(O=o,0|(y=1)):(p=0|tn(0|c,0,45),m=0|T(),m=-1040385&i[(h=r)+4>>2]|m,i[(y=r)>>2]=i[h>>2]|p,i[y+4>>2]=m,O=o,0|(y=0));for(i[s>>2]=i[n>>2],i[s+4>>2]=i[n+4>>2],i[s+8>>2]=i[n+8>>2],n=c;;){if(A=n,n=n+-1|0,i[l>>2]=i[s>>2],i[l+4>>2]=i[s+4>>2],i[l+8>>2]=i[s+8>>2],0|Ve(A)){if(0|(c=0|le(s))){n=13;break}i[f>>2]=i[s>>2],i[f+4>>2]=i[s+4>>2],i[f+8>>2]=i[s+8>>2],he(f)}else{if(0|(c=0|fe(s))){n=13;break}i[f>>2]=i[s>>2],i[f+4>>2]=i[s+4>>2],i[f+8>>2]=i[s+8>>2],pe(f)}if(oe(l,f,u),ie(u),b=0|i[(c=r)>>2],c=0|i[c+4>>2],g=0|tn(7,0,0|(w=3*(15-A|0)|0)),c&=~T(),w=0|tn(0|Ae(u),0,0|w),c=0|T()|c,i[(y=r)>>2]=w|b&~g,i[y+4>>2]=c,(0|A)<=1){n=14;break}}e:do{if(13!=(0|n)&&14==(0|n))if((0|i[s>>2])<=1&&(0|i[s+4>>2])<=1&&(0|i[s+8>>2])<=1){u=127==(0|(c=0|Q(h,n=0|Ae(s))))?0:0|L(c);t:do{if(n){if(a){if(7==(0|(c=0|je(e,t)))){c=5;break e}if((0|(A=0|i[21376+(28*c|0)+(n<<2)>>2]))>0){c=n,n=0;do{c=0|be(c),n=n+1|0}while((0|n)!=(0|A))}else c=n;if(1==(0|c)){c=9;break e}127==(0|(n=0|Q(h,c)))&&S(27648,27538,411,27678),0|L(n)?S(27693,27538,412,27678):(m=n,p=A,d=c)}else m=c,p=0,d=n;if((0|(f=0|i[4272+(28*h|0)+(d<<2)>>2]))<=-1&&S(27724,27538,419,27678),!u){if((0|p)<0){c=5;break e}if(0|p){c=0,n=0|i[(A=r)>>2],A=0|i[A+4>>2];do{n=0|ze(n,A),A=0|T(),i[(w=r)>>2]=n,i[w+4>>2]=A,c=c+1|0}while((0|c)<(0|p))}if((0|f)<=0){c=m,n=58;break}for(c=0,n=0|i[(A=r)>>2],A=0|i[A+4>>2];;)if(n=0|ze(n,A),A=0|T(),i[(w=r)>>2]=n,i[w+4>>2]=A,(0|(c=c+1|0))==(0|f)){c=m,n=58;break t}}if(7==(0|(l=0|V(m,h)))&&S(27514,27538,428,27678),n=0|i[(c=r)>>2],c=0|i[c+4>>2],(0|f)>0){A=0;do{n=0|ze(n,c),c=0|T(),i[(w=r)>>2]=n,i[w+4>>2]=c,A=A+1|0}while((0|A)!=(0|f))}if(7==(0|(c=0|je(n,c)))&&S(27795,27538,440,27678),n=0|j(m),(0|(n=0|i[(n?21792:21584)+(28*l|0)+(c<<2)>>2]))<0&&S(27795,27538,454,27678),n){c=0,A=0|i[(l=r)>>2],l=0|i[l+4>>2];do{A=0|He(A,l),l=0|T(),i[(w=r)>>2]=A,i[w+4>>2]=l,c=c+1|0}while((0|c)<(0|n));c=m,n=58}else c=m,n=58}else if(!!(0|a)&!!(0|u)){if(7==(0|(n=0|je(e,t)))|7==(0|(A=0|je(0|i[(A=r)>>2],0|i[A+4>>2])))){c=5;break e}if((0|(A=0|i[21376+(28*n|0)+(A<<2)>>2]))<0){c=5;break e}if(A){n=0,l=0|i[(f=r)>>2],f=0|i[f+4>>2];do{l=0|ze(l,f),f=0|T(),i[(w=r)>>2]=l,i[w+4>>2]=f,n=n+1|0}while((0|n)<(0|A));n=58}else n=59}else n=58}while(0);if(58==(0|n)&&u&&(n=59),59==(0|n)&&1==(0|je(0|i[(w=r)>>2],0|i[w+4>>2]))){c=9;break}g=0|i[(w=r)>>2],w=-1040385&i[w+4>>2],b=0|tn(0|c,0,45),w=0|w|T(),i[(c=r)>>2]=g|b,i[c+4>>2]=w,c=0}else c=1}while(0);return O=o,0|c}function yt(e,t,n,r){e|=0,t|=0;var i=0,s=0,a=0;if(!(0|(n|=0))&!(0|(r|=0)))return s=1,k(0|(i=0)),0|s;s=e,i=t,e=1,t=0;do{e=0|Wt(0|((a=!0&!(1&n))?1:s),0|(a?0:i),0|e,0|t),t=0|T(),n=0|Xt(0|n,0|r,1),r=0|T(),s=0|Wt(0|s,0|i,0|s,0|i),i=0|T()}while(!(!(0|n)&!(0|r)));return k(0|t),0|e}function gt(e,t,n,r){n|=0,r|=0;var a,o=0,c=0,A=0,l=0,f=0,d=0;a=O,O=O+16|0,c=a,A=0|en(0|(e|=0),0|(t|=0),52),T(),A&=15;do{if(A){if(!(o=0|Ye(e,t,c))){f=+s[c>>3],l=1/+u(+f),d=+s[25968+(A<<3)>>3],s[n>>3]=f+d,s[n+8>>3]=f-d,f=+s[c+8>>3],l*=d,s[n+16>>3]=l+f,s[n+24>>3]=f-l;break}return O=a,0|o}if(o=0|en(0|e,0|t,45),T(),(o&=127)>>>0>121)return O=a,5;c=22064+(o<<5)|0,i[n>>2]=i[c>>2],i[n+4>>2]=i[c+4>>2],i[n+8>>2]=i[c+8>>2],i[n+12>>2]=i[c+12>>2],i[n+16>>2]=i[c+16>>2],i[n+20>>2]=i[c+20>>2],i[n+24>>2]=i[c+24>>2],i[n+28>>2]=i[c+28>>2];break}while(0);return function(e,t){t=+t;var n,r,i,a,o,c,A,l=0,f=0;l=(a=+s[(i=16+(e|=0)|0)>>3])-(r=+s[(n=e+24|0)>>3]),l=a<r?l+6.283185307179586:l,f=+s[e>>3],l=.5*(l*t-l),f+=t=.5*((A=f-(c=+s[(o=e+8|0)>>3]))*t-A),s[e>>3]=f>1.5707963267948966?1.5707963267948966:f,t=c-t,s[o>>3]=t<-1.5707963267948966?-1.5707963267948966:t,t=(t=a+l)>3.141592653589793?t+-6.283185307179586:t,s[i>>3]=t<-3.141592653589793?t+6.283185307179586:t,t=(t=r-l)>3.141592653589793?t+-6.283185307179586:t,s[n>>3]=t<-3.141592653589793?t+6.283185307179586:t}(n,r?1.4:1.1),(0|i[(r=26096+(A<<3)|0)>>2])==(0|e)&&(0|i[r+4>>2])==(0|t)&&(s[n>>3]=1.5707963267948966),(0|i[(A=26224+(A<<3)|0)>>2])==(0|e)&&(0|i[A+4>>2])==(0|t)&&(s[n+8>>3]=-1.5707963267948966),1.5707963267948966!=+s[n>>3]&&-1.5707963267948966!=+s[n+8>>3]?(O=a,0|(A=0)):(s[n+16>>3]=3.141592653589793,s[n+24>>3]=-3.141592653589793,O=a,0|(A=0))}function bt(e){var t,n,s,a,o=0,c=0,A=0,l=0,f=0,u=0,d=0,h=0,p=0,m=0,y=0,g=0,b=0,w=0,v=0,_=0;if(a=O,O=O+336|0,t=a+168|0,n=a,!(0|(c=0|i[(A=e|=0)>>2]))&!(0|(A=0|i[A+4>>2])))O=a;else{if(0|r[0|(o=e+28|0)]?(c=0|wt(c,A),A=0|T()):r[0|o]=1,!(0|i[i[(s=e+20|0)>>2]>>2]))return 0|(c=0|i[(o=e+24|0)>>2])&&Ht(c),i[(_=e)>>2]=0,i[_+4>>2]=0,i[e+8>>2]=0,i[s>>2]=0,i[e+12>>2]=-1,i[e+16>>2]=0,i[o>>2]=0,void(O=a);l=15&(o=0|i[(_=e+16|0)>>2]);e:do{if(!(0|c)&!(0|A))v=e+24|0;else{b=e+12|0,y=3==(0|l),m=255&o,h=3==(1|l),g=e+24|0,p=(l+-1|0)>>>0<3,u=3==(2|l),d=n+8|0;t:for(;;){if(f=0|en(0|c,0|A,52),T(),(0|(f&=15))==(0|i[b>>2])){switch(15&m){case 0:case 2:case 3:if(0|(l=0|Ye(c,A,t))){w=15;break t}if(0|Tt(0|i[s>>2],0|i[g>>2],t)){w=19;break t}}if(h&&(l=0|i[4+(0|i[s>>2])>>2],i[t>>2]=i[l>>2],i[t+4>>2]=i[l+4>>2],i[t+8>>2]=i[l+8>>2],i[t+12>>2]=i[l+12>>2],0|Y(26832,t))){if(0|Je(0|i[4+(0|i[s>>2])>>2],f,n)){w=25;break}if((0|i[(l=n)>>2])==(0|c)&&(0|i[l+4>>2])==(0|A)){w=29;break}}if(p){if(0|(l=0|Ze(c,A,t))){w=32;break}if(0|gt(c,A,n,0)){w=36;break}if(u&&0|St(0|i[s>>2],0|i[g>>2],t,n)){w=42;break}if(h&&0|It(0|i[s>>2],0|i[g>>2],t,n)){w=42;break}}if(y){if(o=0|gt(c,A,t,1),l=0|i[g>>2],0|o){w=45;break}if(0|Z(l,t)){if(ee(n,t),0|X(t,0|i[g>>2])){w=53;break}if(0|Tt(0|i[s>>2],0|i[g>>2],d)){w=53;break}if(0|It(0|i[s>>2],0|i[g>>2],n,t)){w=53;break}}}}do{if((0|f)<(0|i[b>>2])){if(o=0|gt(c,A,t,1),l=0|i[g>>2],0|o){w=58;break t}if(!(0|Z(l,t))){w=73;break}if(0|X(0|i[g>>2],t)&&(ee(n,t),0|St(0|i[s>>2],0|i[g>>2],n,t))){w=65;break t}if(0|(c=0|Le(c,A,f+1|0,n))){w=67;break t}c=0|i[(A=n)>>2],A=0|i[A+4>>2]}else w=73}while(0);if(73==(0|w)&&(w=0,c=0|wt(c,A),A=0|T()),!(0|c)&!(0|A)){v=g;break e}}switch(0|w){case 15:0|(o=0|i[g>>2])&&Ht(o),i[(w=e)>>2]=0,i[w+4>>2]=0,i[s>>2]=0,i[b>>2]=-1,i[_>>2]=0,i[g>>2]=0,i[e+8>>2]=l,w=20;break;case 19:i[e>>2]=c,i[e+4>>2]=A,w=20;break;case 25:S(27795,27761,470,27772);break;case 29:case 42:return i[e>>2]=c,i[e+4>>2]=A,void(O=a);case 32:return 0|(o=0|i[g>>2])&&Ht(o),i[(v=e)>>2]=0,i[v+4>>2]=0,i[s>>2]=0,i[b>>2]=-1,i[_>>2]=0,i[g>>2]=0,i[e+8>>2]=l,void(O=a);case 36:S(27795,27761,493,27772);break;case 45:0|l&&Ht(l),i[(w=e)>>2]=0,i[w+4>>2]=0,i[s>>2]=0,i[b>>2]=-1,i[_>>2]=0,i[g>>2]=0,i[e+8>>2]=o,w=55;break;case 53:i[e>>2]=c,i[e+4>>2]=A,w=55;break;case 58:0|l&&Ht(l),i[(w=e)>>2]=0,i[w+4>>2]=0,i[s>>2]=0,i[b>>2]=-1,i[_>>2]=0,i[g>>2]=0,i[e+8>>2]=o,w=71;break;case 65:i[e>>2]=c,i[e+4>>2]=A,w=71;break;case 67:return 0|(o=0|i[g>>2])&&Ht(o),i[(v=e)>>2]=0,i[v+4>>2]=0,i[s>>2]=0,i[b>>2]=-1,i[_>>2]=0,i[g>>2]=0,i[e+8>>2]=c,void(O=a)}if(20==(0|w))return void(O=a);if(55==(0|w))return void(O=a);if(71==(0|w))return void(O=a)}}while(0);0|(o=0|i[v>>2])&&Ht(o),i[(w=e)>>2]=0,i[w+4>>2]=0,i[e+8>>2]=0,i[s>>2]=0,i[e+12>>2]=-1,i[_>>2]=0,i[v>>2]=0,O=a}}function wt(e,t){var n,r=0,s=0,a=0,o=0,c=0,A=0,l=0,f=0,u=0;n=O,O=O+16|0,u=n,s=0|en(0|(e|=0),0|(t|=0),52),T(),s&=15,r=0|en(0|e,0|t,45),T();do{if(s){for(;r=0|tn(s+4095|0,0,52),a=T()|-15728641&t,r=r|e|(c=0|tn(7,0,0|(o=3*(15-s|0)|0))),a|=A=0|T(),l=0|en(0|e,0|t,0|o),T(),s=s+-1|0,!((l&=7)>>>0<6);){if(!s){f=4;break}t=a,e=r}if(4==(0|f)){r=0|en(0|r,0|a,45),T();break}return u=0|tn(((u=!(0|l)&!!(0|Ge(r,a)))?2:1)+l|0,0,0|o),f=0|T()|t&~A,u|=e&~c,k(0|f),O=n,0|u}}while(0);return(r&=127)>>>0>120?(u=0,k(0|(f=0)),O=n,0|u):($e(u,0,r+1|0,0),f=0|i[u+4>>2],u=0|i[u>>2],k(0|f),O=n,0|u)}function vt(e,t,n){e|=0;var r,a=0,o=0,c=0,A=0,l=0,f=0,u=0,d=0,h=0;if(!(0|Y(t|=0,n|=0)))return 0;if(t=0|K(t),a=+s[n>>3],o=t&(o=+s[n+8>>3])<0?o+6.283185307179586:o,(0|(h=0|i[e>>2]))<=0)return 0;if(r=0|i[e+4>>2],t){t=0,d=o,n=-1,e=0;e:for(;;){for(u=e;A=+s[r+(u<<4)>>3],o=+s[r+(u<<4)+8>>3],c=+s[r+((e=(n+2|0)%(0|h)|0)<<4)>>3],l=+s[r+(e<<4)+8>>3],A>c?(f=A,A=l):(f=c,c=A,A=o,o=l),(a=a==c|a==f?a+2220446049250313e-31:a)<c|a>f;){if((0|(n=u+1|0))>=(0|h)){n=22;break e}e=u,u=n,n=e}if(((f=(l=A<0?A+6.283185307179586:A)+(a-c)/(f-c)*((A=o<0?o+6.283185307179586:o)-l))<0?f+6.283185307179586:f)>(d=l==d|A==d?d+-2220446049250313e-31:d)&&(t^=1),(0|(e=u+1|0))>=(0|h)){n=22;break}n=u}if(22==(0|n))return 0|t}else{t=0,d=o,n=-1,e=0;e:for(;;){for(u=e;A=+s[r+(u<<4)>>3],o=+s[r+(u<<4)+8>>3],c=+s[r+((e=(n+2|0)%(0|h)|0)<<4)>>3],l=+s[r+(e<<4)+8>>3],A>c?(f=A,A=l):(f=c,c=A,A=o,o=l),(a=a==c|a==f?a+2220446049250313e-31:a)<c|a>f;){if((0|(n=u+1|0))>=(0|h)){n=22;break e}e=u,u=n,n=e}if(A+(a-c)/(f-c)*(o-A)>(d=A==d|o==d?d+-2220446049250313e-31:d)&&(t^=1),(0|(e=u+1|0))>=(0|h)){n=22;break}n=u}if(22==(0|n))return 0|t}return 0}function _t(e,t){t|=0;var n,r,a,o,c,l=0,f=0,u=0,d=0,h=0,p=0,m=0,y=0,g=0,b=0,w=0,v=0;if(!(r=0|i[(e|=0)>>2]))return i[t>>2]=0,i[t+4>>2]=0,i[t+8>>2]=0,i[t+12>>2]=0,i[t+16>>2]=0,i[t+20>>2]=0,i[t+24>>2]=0,void(i[t+28>>2]=0);if(s[(a=t+8|0)>>3]=17976931348623157e292,s[(o=t+24|0)>>3]=17976931348623157e292,s[t>>3]=-17976931348623157e292,s[(c=t+16|0)>>3]=-17976931348623157e292,!((0|r)<=0)){for(n=0|i[e+4>>2],y=17976931348623157e292,g=-17976931348623157e292,b=0,e=-1,d=17976931348623157e292,h=17976931348623157e292,m=-17976931348623157e292,f=-17976931348623157e292,w=0;l=+s[n+(w<<4)>>3],p=+s[n+(w<<4)+8>>3],u=+s[n+(((0|(e=e+2|0))==(0|r)?0:e)<<4)+8>>3],l<d&&(s[a>>3]=l,d=l),p<h&&(s[o>>3]=p,h=p),l>m?s[t>>3]=l:l=m,p>f&&(s[c>>3]=p,f=p),y=p>0&p<y?p:y,g=p<0&p>g?p:g,b|=+A(+(p-u))>3.141592653589793,(0|(e=w+1|0))!=(0|r);)v=w,m=l,w=e,e=v;b&&(s[c>>3]=g,s[o>>3]=y)}}function Et(e){return 0|((e|=0)>>>0<4?0:15)}function kt(e,t){t|=0;var n,r=0,a=0,o=0,c=0,l=0,f=0,u=0,d=0,h=0,p=0,m=0,y=0,g=0,b=0,w=0,v=0,_=0,E=0,k=0,T=0,S=0;if(g=0|i[(e|=0)>>2]){if(s[(b=t+8|0)>>3]=17976931348623157e292,s[(w=t+24|0)>>3]=17976931348623157e292,s[t>>3]=-17976931348623157e292,s[(v=t+16|0)>>3]=-17976931348623157e292,(0|g)>0){for(o=0|i[e+4>>2],m=17976931348623157e292,y=-17976931348623157e292,a=0,r=-1,u=17976931348623157e292,d=17976931348623157e292,p=-17976931348623157e292,l=-17976931348623157e292,_=0;c=+s[o+(_<<4)>>3],h=+s[o+(_<<4)+8>>3],f=+s[o+(((0|(T=r+2|0))==(0|g)?0:T)<<4)+8>>3],c<u&&(s[b>>3]=c,u=c),h<d&&(s[w>>3]=h,d=h),c>p?s[t>>3]=c:c=p,h>l&&(s[v>>3]=h,l=h),m=h>0&h<m?h:m,y=h<0&h>y?h:y,a|=+A(+(h-f))>3.141592653589793,(0|(r=_+1|0))!=(0|g);)T=_,p=c,_=r,r=T;a&&(s[v>>3]=y,s[w>>3]=m)}}else i[t>>2]=0,i[t+4>>2]=0,i[t+8>>2]=0,i[t+12>>2]=0,i[t+16>>2]=0,i[t+20>>2]=0,i[t+24>>2]=0,i[t+28>>2]=0;if(!((0|(r=0|i[(T=e+8|0)>>2]))<=0)){n=e+12|0,k=0;do{if(o=0|i[n>>2],a=k,w=t+((k=k+1|0)<<5)|0,v=0|i[o+(a<<3)>>2]){if(s[(_=t+(k<<5)+8|0)>>3]=17976931348623157e292,s[(e=t+(k<<5)+24|0)>>3]=17976931348623157e292,s[w>>3]=-17976931348623157e292,s[(E=t+(k<<5)+16|0)>>3]=-17976931348623157e292,(0|v)>0){for(g=0|i[o+(a<<3)+4>>2],m=17976931348623157e292,y=-17976931348623157e292,o=0,a=-1,b=0,u=17976931348623157e292,d=17976931348623157e292,h=-17976931348623157e292,l=-17976931348623157e292;c=+s[g+(b<<4)>>3],p=+s[g+(b<<4)+8>>3],f=+s[g+(((0|(a=a+2|0))==(0|v)?0:a)<<4)+8>>3],c<u&&(s[_>>3]=c,u=c),p<d&&(s[e>>3]=p,d=p),c>h?s[w>>3]=c:c=h,p>l&&(s[E>>3]=p,l=p),m=p>0&p<m?p:m,y=p<0&p>y?p:y,o|=+A(+(p-f))>3.141592653589793,(0|(a=b+1|0))!=(0|v);)S=b,b=a,h=c,a=S;o&&(s[E>>3]=y,s[e>>3]=m)}}else i[w>>2]=0,i[w+4>>2]=0,i[w+8>>2]=0,i[w+12>>2]=0,i[w+16>>2]=0,i[w+20>>2]=0,i[w+24>>2]=0,i[w+28>>2]=0,r=0|i[T>>2]}while((0|k)<(0|r))}}function Tt(e,t,n){var r=0,s=0,a=0;if(!(0|vt(e|=0,t|=0,n|=0)))return 0;if((0|i[(s=e+8|0)>>2])<=0)return 1;for(r=e+12|0,e=0;;){if(a=e,e=e+1|0,0|vt((0|i[r>>2])+(a<<3)|0,t+(e<<5)|0,n)){e=0,r=6;break}if((0|e)>=(0|i[s>>2])){e=1,r=6;break}}return 6==(0|r)?0|e:0}function St(e,t,n,r){r|=0;var s,a,o=0,c=0,A=0,l=0,f=0;if(a=O,O=O+16|0,s=a,!(0|vt(e|=0,t|=0,A=8+(n|=0)|0)))return O=a,0;l=e+8|0;e:do{if((0|i[l>>2])>0){for(c=e+12|0,o=0;;){if(f=o,o=o+1|0,0|vt((0|i[c>>2])+(f<<3)|0,t+(o<<5)|0,A)){o=0;break}if((0|o)>=(0|i[l>>2]))break e}return O=a,0|o}}while(0);if(0|xt(e,t,n,r))return O=a,0;i[s>>2]=i[n>>2],i[s+4>>2]=A,o=0|i[l>>2];e:do{if((0|o)>0)for(e=e+12|0,A=0,c=o;;){if(o=0|i[e>>2],(0|i[o+(A<<3)>>2])>0){if(0|vt(s,r,0|i[o+(A<<3)+4>>2])){o=0;break e}if(o=A+1|0,0|xt((0|i[e>>2])+(A<<3)|0,t+(o<<5)|0,n,r)){o=0;break e}c=0|i[l>>2]}else o=A+1|0;if(!((0|o)<(0|c))){o=1;break}A=o}else o=1}while(0);return O=a,0|o}function xt(e,t,n,r){e|=0,n|=0;var a,o,c,A,l,f,u=0,d=0,h=0,p=0,m=0,y=0,g=0,b=0,w=0,v=0,_=0,E=0,k=0,T=0,S=0;if(f=O,O=O+176|0,A=f+172|0,u=f+168|0,l=f,!(0|Z(t|=0,r|=0)))return O=f,0;if(function(e,t,n,r){var a,o,c,A,l;t|=0,n|=0,r|=0,e=(o=+s[16+(e|=0)>>3])<(l=+s[e+24>>3]),a=(A=+s[t+16>>3])<(c=+s[t+24>>3]),t=l-A<c-o,i[n>>2]=e?a|t?1:2:0,i[r>>2]=a?e?1:t?2:1:0}(t,r,A,u),on(0|l,0|n,168),(0|i[n>>2])>0){t=0;do{_=+st(+s[(T=l+8+(t<<4)+8|0)>>3],0|i[u>>2]),s[T>>3]=_,t=t+1|0}while((0|t)<(0|i[n>>2]))}o=+s[r>>3],c=+s[r+8>>3],_=+st(+s[r+16>>3],0|i[u>>2]),a=+st(+s[r+24>>3],0|i[u>>2]);e:do{if((0|i[e>>2])>0){if(r=e+4|0,(0|(u=0|i[l>>2]))<=0)for(t=0;;)if((0|(t=t+1|0))>=(0|i[e>>2])){t=0;break e}for(n=0;;){if(t=0|i[r>>2],w=+s[t+(n<<4)>>3],v=+st(+s[t+(n<<4)+8>>3],0|i[A>>2]),t=0|i[r>>2],T=(0|(n=n+1|0))%(0|i[e>>2])|0,d=+s[t+(T<<4)>>3],h=+st(+s[t+(T<<4)+8>>3],0|i[A>>2]),!(w>=o)|!(d>=o)&&!(w<=c)|!(d<=c)&&!(v<=a)|!(h<=a)&&!(v>=_)|!(h>=_)){b=d-w,y=h-v,t=0;do{if(S=t,T=(0|(t=t+1|0))==(0|u)?0:t,d=+s[l+8+(S<<4)+8>>3],h=+s[l+8+(T<<4)+8>>3]-d,p=+s[l+8+(S<<4)>>3],!(0==(g=b*h-y*(m=+s[l+8+(T<<4)>>3]-p))||(E=v-d,k=w-p,m=(E*m-h*k)/g,m<0|m>1))&&(g=(b*E-y*k)/g)>=0&g<=1){t=1;break e}}while((0|t)<(0|u))}if((0|n)>=(0|i[e>>2])){t=0;break}}}else t=0}while(0);return O=f,0|t}function It(e,t,n,r){var s=0,a=0,o=0;if(0|xt(e|=0,t|=0,n|=0,r|=0))return 1;if((0|i[(a=e+8|0)>>2])<=0)return 0;for(s=e+12|0,e=0;;){if(o=e,e=e+1|0,0|xt((0|i[s>>2])+(o<<3)|0,t+(e<<5)|0,n,r)){e=1,s=6;break}if((0|e)>=(0|i[a>>2])){e=0,s=6;break}}return 6==(0|s)?0|e:0}function Pt(e,t,n,r,i){t|=0,n|=0,r|=0,i|=0;var a,o,c,A,l,f,u,d=0;A=+s[(e|=0)>>3],c=+s[t>>3]-A,o=+s[e+8>>3],a=+s[t+8>>3]-o,f=+s[n>>3],d=((d=+s[r>>3]-f)*(o-(u=+s[n+8>>3]))-(A-f)*(l=+s[r+8>>3]-u))/(c*l-a*d),s[i>>3]=A+c*d,s[i+8>>3]=o+a*d}function Ct(e,t){return t|=0,+A(+(+s[(e|=0)>>3]-+s[t>>3]))<1.1920928955078125e-7?0|(t=+A(+(+s[e+8>>3]-+s[t+8>>3]))<1.1920928955078125e-7):0|(t=0)}function Nt(e,t){var n,r,i;return t|=0,+((i=+s[(e|=0)>>3]-+s[t>>3])*i+(r=+s[e+8>>3]-+s[t+8>>3])*r+(n=+s[e+16>>3]-+s[t+16>>3])*n)}function Ot(e,t,n){n|=0;var r,s,a,o,c=0,A=0,l=0;if(o=O,O=O+32|0,l=o,0|(c=0|We(e|=0,t|=0,s=o+16|0)))return O=o,0|c;r=0|Be(e,t),a=0|je(e,t),function(e,t){e=7696+(28*(e|=0)|0)|0,i[(t|=0)>>2]=i[e>>2],i[t+4>>2]=i[e+4>>2],i[t+8>>2]=i[e+8>>2],i[t+12>>2]=i[e+12>>2]}(r,l),c=0|function(e,t){e|=0;var n=0,r=0;if((t|=0)>>>0>20)return-1;do{if((0|i[11120+(216*t|0)>>2])!=(0|e))if((0|i[11120+(216*t|0)+8>>2])!=(0|e))if((0|i[11120+(216*t|0)+16>>2])!=(0|e))if((0|i[11120+(216*t|0)+24>>2])!=(0|e))if((0|i[11120+(216*t|0)+32>>2])!=(0|e))if((0|i[11120+(216*t|0)+40>>2])!=(0|e))if((0|i[11120+(216*t|0)+48>>2])!=(0|e))if((0|i[11120+(216*t|0)+56>>2])!=(0|e))if((0|i[11120+(216*t|0)+64>>2])!=(0|e))if((0|i[11120+(216*t|0)+72>>2])!=(0|e))if((0|i[11120+(216*t|0)+80>>2])!=(0|e))if((0|i[11120+(216*t|0)+88>>2])!=(0|e))if((0|i[11120+(216*t|0)+96>>2])!=(0|e))if((0|i[11120+(216*t|0)+104>>2])!=(0|e))if((0|i[11120+(216*t|0)+112>>2])!=(0|e))if((0|i[11120+(216*t|0)+120>>2])!=(0|e))if((0|i[11120+(216*t|0)+128>>2])!=(0|e)){if((0|i[11120+(216*t|0)+136>>2])!=(0|e)){if((0|i[11120+(216*t|0)+144>>2])==(0|e)){e=0,n=2,r=0;break}if((0|i[11120+(216*t|0)+152>>2])==(0|e)){e=0,n=2,r=1;break}if((0|i[11120+(216*t|0)+160>>2])==(0|e)){e=0,n=2,r=2;break}if((0|i[11120+(216*t|0)+168>>2])==(0|e)){e=1,n=2,r=0;break}if((0|i[11120+(216*t|0)+176>>2])==(0|e)){e=1,n=2,r=1;break}if((0|i[11120+(216*t|0)+184>>2])==(0|e)){e=1,n=2,r=2;break}if((0|i[11120+(216*t|0)+192>>2])==(0|e)){e=2,n=2,r=0;break}if((0|i[11120+(216*t|0)+200>>2])==(0|e)){e=2,n=2,r=1;break}if((0|i[11120+(216*t|0)+208>>2])==(0|e)){e=2,n=2,r=2;break}return-1}e=2,n=1,r=2}else e=2,n=1,r=1;else e=2,n=1,r=0;else e=1,n=1,r=2;else e=1,n=1,r=1;else e=1,n=1,r=0;else e=0,n=1,r=2;else e=0,n=1,r=1;else e=0,n=1,r=0;else e=2,n=0,r=2;else e=2,n=0,r=1;else e=2,n=0,r=0;else e=1,n=0,r=2;else e=1,n=0,r=1;else e=1,n=0,r=0;else e=0,n=0,r=2;else e=0,n=0,r=1;else e=0,n=0,r=0}while(0);return 0|i[11120+(216*t|0)+(72*n|0)+(24*e|0)+(r<<3)+4>>2]}(r,0|i[s>>2]);e:do{if(0|L(r)){switch(0|r){case 4:e=0;break;case 14:e=1;break;case 24:e=2;break;case 38:e=3;break;case 49:e=4;break;case 58:e=5;break;case 63:e=6;break;case 72:e=7;break;case 83:e=8;break;case 97:e=9;break;case 107:e=10;break;case 117:e=11;break;default:c=1;break e}if(A=0|i[26416+(24*e|0)+8>>2],t=0|i[26416+(24*e|0)+16>>2],(0|(e=0|i[s>>2]))!=(0|i[l>>2])&&(l=0|j(r))|(0|(e=0|i[s>>2]))==(0|t)&&(c=(c+1|0)%6|0),3==(0|a)&(0|e)==(0|t)){c=(c+5|0)%6|0,A=22;break}5==(0|a)&(0|e)==(0|A)?(c=(c+1|0)%6|0,A=22):A=22}else A=22}while(0);return 22==(0|A)&&(i[n>>2]=c,c=0),O=o,0|c}function Rt(e,t,n,r){n|=0,r|=0;var s,a,o,c,A,l=0,f=0,u=0,d=0,h=0,p=0,m=0,y=0,g=0,b=0,w=0;if(A=O,O=O+32|0,w=A+24|0,c=A+20|0,o=A+8|0,a=A+16|0,s=A,h=(h=!(0|Ge(e|=0,t|=0)))?6:5,m=0|en(0|e,0|t,52),T(),h>>>0<=n>>>0)return O=A,2;!(y=!(0|(m&=15)))&&!((g=0|tn(7,0,3*(15^m)|0))&e)&!((0|T())&t)?l=n:f=4;e:do{if(4==(0|f)){if((0|((l=!!(0|Ge(e,t)))?4:5))<(0|n))return O=A,1;if(0|Ot(e,t,w))return O=A,1;if(f=(0|i[w>>2])+n|0,7==(0|(g=0|i[(l=l?26704+((0|f)%5<<2)|0:26736+((0|f)%6<<2)|0)>>2])))return O=A,1;i[c>>2]=0,l=0|D(e,t,g,c,o);do{if(!l){if(p=0|i[(d=o)>>2],f=(u=(d=0|i[d+4>>2])>>>0<t>>>0|(0|d)==(0|t)&p>>>0<e>>>0)?p:e,u=u?d:t,!y&&!(p&(y=0|tn(7,0,3*(15^m)|0)))&!(d&(0|T())))l=n;else{if(d=(n+-1+h|0)%(0|h)|0,l=0|Ge(e,t),(0|d)<0&&S(27795,27797,246,27806),(0|((h=!!(0|l))?4:5))<(0|d)&&S(27795,27797,246,27806),0|Ot(e,t,w)&&S(27795,27797,246,27806),l=(0|i[w>>2])+d|0,7==(0|(d=0|i[(l=h?26704+((0|l)%5<<2)|0:26736+((0|l)%6<<2)|0)>>2]))&&S(27795,27797,246,27806),i[a>>2]=0,0|(l=0|D(e,t,d,a,s)))break;h=0|i[(p=s)>>2],p=0|i[p+4>>2];do{if(p>>>0<u>>>0|(0|p)==(0|u)&h>>>0<f>>>0){if(f=0|Ge(h,p)?0|G(h,p,e,t):0|i[26800+(((0|i[a>>2])+(0|i[26768+(d<<2)>>2])|0)%6<<2)>>2],l=0|Ge(h,p),(f+-1|0)>>>0>5){l=-1,f=h,u=p;break}if(1==(0|f)&(l=!!(0|l))){l=-1,f=h,u=p;break}do{if(!(0|Ot(h,p,w))){if(l){l=(5+(0|i[26352+(f<<2)>>2])-(0|i[w>>2])|0)%5|0;break}l=(6+(0|i[26384+(f<<2)>>2])-(0|i[w>>2])|0)%6|0;break}l=-1}while(0);f=h,u=p}else l=n}while(0);p=0|i[(d=o)>>2],d=0|i[d+4>>2]}if((0|f)==(0|p)&(0|u)==(0|d)){if(e=(h=!!(0|Ge(p,d)))?0|G(p,d,e,t):0|i[26800+(((0|i[c>>2])+(0|i[26768+(g<<2)>>2])|0)%6<<2)>>2],l=0|Ge(p,d),(e+-1|0)>>>0<=5&&!(1==(0|e)&(b=!!(0|l))))do{if(!(0|Ot(p,d,w))){if(b){l=(5+(0|i[26352+(e<<2)>>2])-(0|i[w>>2])|0)%5|0;break}l=(6+(0|i[26384+(e<<2)>>2])-(0|i[w>>2])|0)%6|0;break}l=-1}while(0);else l=-1;l=6==(0|(l=l+1|0))|h&5==(0|l)?0:l}t=u,e=f;break e}}while(0);return O=A,0|l}}while(0);return b=0|tn(0|l,0,56),w=T()|-2130706433&t|536870912,i[r>>2]=b|e,i[r+4>>2]=w,O=A,0}function Bt(e,t,n){e|=0,n|=0;var r=0;(0|(t|=0))>0?(r=0|zt(t,4),i[e>>2]=r,r||S(27819,27842,40,27856)):i[e>>2]=0,i[e+4>>2]=t,i[e+8>>2]=0,i[e+12>>2]=n}function Mt(e){var t,n,r,a=0,o=0,c=0,l=0;t=4+(e|=0)|0,n=e+12|0,r=e+8|0;e:for(;;){for(o=0|i[t>>2],a=0;;){if((0|a)>=(0|o))break e;if(c=0|i[e>>2],l=0|i[c+(a<<2)>>2])break;a=a+1|0}a=c+(~~(+A(+ +f(10,+ +(15-(0|i[n>>2])|0))*(+s[l>>3]+ +s[l+8>>3]))%+(0|o))>>>0<<2)|0,o=0|i[a>>2];t:do{if(0|o){if(c=l+32|0,(0|o)==(0|l))i[a>>2]=i[c>>2];else{if(!(a=0|i[(o=o+32|0)>>2]))break;for(;(0|a)!=(0|l);)if(!(a=0|i[(o=a+32|0)>>2]))break t;i[o>>2]=i[c>>2]}Ht(l),i[r>>2]=(0|i[r>>2])-1}}while(0)}Ht(0|i[e>>2])}function $t(e){var t,n=0,r=0;for(t=0|i[4+(e|=0)>>2],r=0;;){if((0|r)>=(0|t)){n=0,r=4;break}if(n=0|i[(0|i[e>>2])+(r<<2)>>2]){r=4;break}r=r+1|0}return 4==(0|r)?0|n:0}function Dt(e,t){t|=0;var n=0,r=0,a=0,o=0;if(n=~~(+A(+ +f(10,+ +(15-(0|i[12+(e|=0)>>2])|0))*(+s[t>>3]+ +s[t+8>>3]))%+(0|i[e+4>>2]))>>>0,n=(0|i[e>>2])+(n<<2)|0,!(r=0|i[n>>2]))return 1;o=t+32|0;do{if((0|r)!=(0|t)){if(!(n=0|i[r+32>>2]))return 1;for(a=n;;){if((0|a)==(0|t)){a=8;break}if(!(n=0|i[a+32>>2])){n=1,a=10;break}r=a,a=n}if(8==(0|a)){i[r+32>>2]=i[o>>2];break}if(10==(0|a))return 0|n}else i[n>>2]=i[o>>2]}while(0);return Ht(t),i[(o=e+8|0)>>2]=(0|i[o>>2])-1,0}function Ft(e,t,n){e|=0,t|=0,n|=0;var r,a=0,o=0,c=0;(r=0|jt(40))||S(27872,27842,98,27885),i[r>>2]=i[t>>2],i[r+4>>2]=i[t+4>>2],i[r+8>>2]=i[t+8>>2],i[r+12>>2]=i[t+12>>2],i[(o=r+16|0)>>2]=i[n>>2],i[o+4>>2]=i[n+4>>2],i[o+8>>2]=i[n+8>>2],i[o+12>>2]=i[n+12>>2],i[r+32>>2]=0,o=~~(+A(+ +f(10,+ +(15-(0|i[e+12>>2])|0))*(+s[t>>3]+ +s[t+8>>3]))%+(0|i[e+4>>2]))>>>0,o=(0|i[e>>2])+(o<<2)|0,a=0|i[o>>2];do{if(a){for(;!(0|it(a,t)&&0|it(a+16|0,n));)if(o=0|i[a+32>>2],!(0|i[(a=0|o?o:a)+32>>2])){c=10;break}if(10==(0|c)){i[a+32>>2]=r;break}return Ht(r),0|a}i[o>>2]=r}while(0);return i[(c=e+8|0)>>2]=1+(0|i[c>>2]),0|r}function Gt(e,t,n){t|=0,n|=0;var r=0,a=0;if(a=~~(+A(+ +f(10,+ +(15-(0|i[12+(e|=0)>>2])|0))*(+s[t>>3]+ +s[t+8>>3]))%+(0|i[e+4>>2]))>>>0,!(a=0|i[(0|i[e>>2])+(a<<2)>>2]))return 0;if(!n){for(e=a;;){if(0|it(e,t)){r=10;break}if(!(e=0|i[e+32>>2])){e=0,r=10;break}}if(10==(0|r))return 0|e}for(e=a;;){if(0|it(e,t)&&0|it(e+16|0,n)){r=10;break}if(!(e=0|i[e+32>>2])){e=0,r=10;break}}return 10==(0|r)?0|e:0}function Ut(e,t){t|=0;var n=0;if(n=~~(+A(+ +f(10,+ +(15-(0|i[12+(e|=0)>>2])|0))*(+s[t>>3]+ +s[t+8>>3]))%+(0|i[e+4>>2]))>>>0,!(e=0|i[(0|i[e>>2])+(n<<2)>>2]))return 0;for(;;){if(0|it(e,t)){t=5;break}if(!(e=0|i[e+32>>2])){e=0,t=5;break}}return 5==(0|t)?0|e:0}function Lt(e){return 0|+An(+(e=+e))}function jt(e){e|=0;var t,n=0,r=0,s=0,a=0,o=0,c=0,A=0,l=0,f=0,u=0,d=0,h=0,p=0,m=0,y=0,g=0,b=0,w=0,v=0,_=0;t=O,O=O+16|0,h=t;do{if(e>>>0<245){if(e=(f=e>>>0<11?16:e+11&-8)>>>3,3&(r=(d=0|i[6977])>>>e))return s=0|i[(r=8+(e=27948+((n=(1&r^1)+e|0)<<1<<2)|0)|0)>>2],(0|(o=0|i[(a=s+8|0)>>2]))==(0|e)?i[6977]=d&~(1<<n):(i[o+12>>2]=e,i[r>>2]=o),_=n<<3,i[s+4>>2]=3|_,i[(_=s+_+4|0)>>2]=1|i[_>>2],O=t,0|a;if(f>>>0>(u=0|i[6979])>>>0){if(0|r)return n=((n=r<<e&((n=2<<e)|0-n))&0-n)-1|0,o=0|i[(e=8+(n=27948+((s=((r=(n>>>=A=n>>>12&16)>>>5&8)|A|(o=(n>>>=r)>>>2&4)|(e=(n>>>=o)>>>1&2)|(s=(n>>>=e)>>>1&1))+(n>>>s)|0)<<1<<2)|0)|0)>>2],(0|(r=0|i[(A=o+8|0)>>2]))==(0|n)?(e=d&~(1<<s),i[6977]=e):(i[r+12>>2]=n,i[e>>2]=r,e=d),c=(_=s<<3)-f|0,i[o+4>>2]=3|f,i[4+(a=o+f|0)>>2]=1|c,i[o+_>>2]=c,0|u&&(s=0|i[6982],r=27948+((n=u>>>3)<<1<<2)|0,e&(n=1<<n)?n=0|i[(e=r+8|0)>>2]:(i[6977]=e|n,n=r,e=r+8|0),i[e>>2]=s,i[n+12>>2]=s,i[s+8>>2]=n,i[s+12>>2]=r),i[6979]=c,i[6982]=a,O=t,0|A;if(o=0|i[6978]){for(r=(o&0-o)-1|0,r=l=0|i[28212+(((s=(r>>>=a=r>>>12&16)>>>5&8)|a|(c=(r>>>=s)>>>2&4)|(A=(r>>>=c)>>>1&2)|(l=(r>>>=A)>>>1&1))+(r>>>l)<<2)>>2],A=l,l=(-8&i[l+4>>2])-f|0;(e=0|i[r+16>>2])||(e=0|i[r+20>>2]);)r=e,A=(a=(c=(-8&i[e+4>>2])-f|0)>>>0<l>>>0)?e:A,l=a?c:l;if((c=A+f|0)>>>0>A>>>0){a=0|i[A+24>>2],n=0|i[A+12>>2];do{if((0|n)==(0|A)){if(!(n=0|i[(e=A+20|0)>>2])&&!(n=0|i[(e=A+16|0)>>2])){r=0;break}for(;;)if(r=0|i[(s=n+20|0)>>2])n=r,e=s;else{if(!(r=0|i[(s=n+16|0)>>2]))break;n=r,e=s}i[e>>2]=0,r=n}else r=0|i[A+8>>2],i[r+12>>2]=n,i[n+8>>2]=r,r=n}while(0);do{if(0|a){if(n=0|i[A+28>>2],(0|A)==(0|i[(e=28212+(n<<2)|0)>>2])){if(i[e>>2]=r,!r){i[6978]=o&~(1<<n);break}}else if(i[((0|i[(_=a+16|0)>>2])==(0|A)?_:a+20)>>2]=r,!r)break;i[r+24>>2]=a,0|(n=0|i[A+16>>2])&&(i[r+16>>2]=n,i[n+24>>2]=r),0|(n=0|i[A+20>>2])&&(i[r+20>>2]=n,i[n+24>>2]=r)}}while(0);return l>>>0<16?(_=l+f|0,i[A+4>>2]=3|_,i[(_=A+_+4|0)>>2]=1|i[_>>2]):(i[A+4>>2]=3|f,i[c+4>>2]=1|l,i[c+l>>2]=l,0|u&&(s=0|i[6982],r=27948+((n=u>>>3)<<1<<2)|0,(n=1<<n)&d?n=0|i[(e=r+8|0)>>2]:(i[6977]=n|d,n=r,e=r+8|0),i[e>>2]=s,i[n+12>>2]=s,i[s+8>>2]=n,i[s+12>>2]=r),i[6979]=l,i[6982]=c),O=t,0|A+8}d=f}else d=f}else d=f}else if(e>>>0<=4294967231)if(f=-8&(e=e+11|0),s=0|i[6978]){a=0-f|0,l=(e>>>=8)?f>>>0>16777215?31:f>>>(7+(l=14-((A=(520192+(y=e<<(d=(e+1048320|0)>>>16&8))|0)>>>16&4)|d|(l=(245760+(y<<=A)|0)>>>16&2))+(y<<l>>>15)|0)|0)&1|l<<1:0,r=0|i[28212+(l<<2)>>2];e:do{if(r)for(e=0,A=f<<(31==(0|l)?0:25-(l>>>1)|0),o=0;;){if((c=(-8&i[r+4>>2])-f|0)>>>0<a>>>0){if(!c){e=r,a=0,y=65;break e}e=r,a=c}if(o=!(0|(y=0|i[r+20>>2]))|(0|y)==(0|(r=0|i[r+16+(A>>>31<<2)>>2]))?o:y,!r){r=o,y=61;break}A<<=1}else r=0,e=0,y=61}while(0);if(61==(0|y)){if(!(0|r)&!(0|e)){if(!(e=((e=2<<l)|0-e)&s)){d=f;break}d=(e&0-e)-1|0,e=0,r=0|i[28212+(((o=(d>>>=c=d>>>12&16)>>>5&8)|c|(A=(d>>>=o)>>>2&4)|(l=(d>>>=A)>>>1&2)|(r=(d>>>=l)>>>1&1))+(d>>>r)<<2)>>2]}r?y=65:(A=e,c=a)}if(65==(0|y))for(o=r;;){if(a=(r=(d=(-8&i[o+4>>2])-f|0)>>>0<a>>>0)?d:a,e=r?o:e,(r=0|i[o+16>>2])||(r=0|i[o+20>>2]),!r){A=e,c=a;break}o=r}if(0|A&&c>>>0<((0|i[6979])-f|0)>>>0&&(u=A+f|0)>>>0>A>>>0){o=0|i[A+24>>2],n=0|i[A+12>>2];do{if((0|n)==(0|A)){if(!(n=0|i[(e=A+20|0)>>2])&&!(n=0|i[(e=A+16|0)>>2])){n=0;break}for(;;)if(r=0|i[(a=n+20|0)>>2])n=r,e=a;else{if(!(r=0|i[(a=n+16|0)>>2]))break;n=r,e=a}i[e>>2]=0}else _=0|i[A+8>>2],i[_+12>>2]=n,i[n+8>>2]=_}while(0);do{if(o){if(e=0|i[A+28>>2],(0|A)==(0|i[(r=28212+(e<<2)|0)>>2])){if(i[r>>2]=n,!n){s&=~(1<<e),i[6978]=s;break}}else if(i[((0|i[(_=o+16|0)>>2])==(0|A)?_:o+20)>>2]=n,!n)break;i[n+24>>2]=o,0|(e=0|i[A+16>>2])&&(i[n+16>>2]=e,i[e+24>>2]=n),(e=0|i[A+20>>2])&&(i[n+20>>2]=e,i[e+24>>2]=n)}}while(0);e:do{if(c>>>0<16)_=c+f|0,i[A+4>>2]=3|_,i[(_=A+_+4|0)>>2]=1|i[_>>2];else{if(i[A+4>>2]=3|f,i[u+4>>2]=1|c,i[u+c>>2]=c,n=c>>>3,c>>>0<256){r=27948+(n<<1<<2)|0,(e=0|i[6977])&(n=1<<n)?n=0|i[(e=r+8|0)>>2]:(i[6977]=e|n,n=r,e=r+8|0),i[e>>2]=u,i[n+12>>2]=u,i[u+8>>2]=n,i[u+12>>2]=r;break}if(n=28212+((r=(n=c>>>8)?c>>>0>16777215?31:c>>>(7+(r=14-((w=(520192+(_=n<<(v=(n+1048320|0)>>>16&8))|0)>>>16&4)|v|(r=(245760+(_<<=w)|0)>>>16&2))+(_<<r>>>15)|0)|0)&1|r<<1:0)<<2)|0,i[u+28>>2]=r,i[4+(e=u+16|0)>>2]=0,i[e>>2]=0,!(s&(e=1<<r))){i[6978]=s|e,i[n>>2]=u,i[u+24>>2]=n,i[u+12>>2]=u,i[u+8>>2]=u;break}n=0|i[n>>2];t:do{if((-8&i[n+4>>2])!=(0|c)){for(s=c<<(31==(0|r)?0:25-(r>>>1)|0);e=0|i[(r=n+16+(s>>>31<<2)|0)>>2];){if((-8&i[e+4>>2])==(0|c)){n=e;break t}s<<=1,n=e}i[r>>2]=u,i[u+24>>2]=n,i[u+12>>2]=u,i[u+8>>2]=u;break e}}while(0);_=0|i[(v=n+8|0)>>2],i[_+12>>2]=u,i[v>>2]=u,i[u+8>>2]=_,i[u+12>>2]=n,i[u+24>>2]=0}}while(0);return O=t,0|A+8}d=f}else d=f;else d=-1}while(0);if((r=0|i[6979])>>>0>=d>>>0)return n=r-d|0,e=0|i[6982],n>>>0>15?(_=e+d|0,i[6982]=_,i[6979]=n,i[_+4>>2]=1|n,i[e+r>>2]=n,i[e+4>>2]=3|d):(i[6979]=0,i[6982]=0,i[e+4>>2]=3|r,i[(_=e+r+4|0)>>2]=1|i[_>>2]),O=t,0|e+8;if((c=0|i[6980])>>>0>d>>>0)return w=c-d|0,i[6980]=w,v=(_=0|i[6983])+d|0,i[6983]=v,i[v+4>>2]=1|w,i[_+4>>2]=3|d,O=t,0|_+8;if(0|i[7095]?e=0|i[7097]:(i[7097]=4096,i[7096]=4096,i[7098]=-1,i[7099]=-1,i[7100]=0,i[7088]=0,i[7095]=-16&h^1431655768,e=4096),A=d+48|0,(f=(o=e+(l=d+47|0)|0)&(a=0-e|0))>>>0<=d>>>0)return O=t,0;if(0|(e=0|i[7087])&&(h=(u=0|i[7085])+f|0)>>>0<=u>>>0|h>>>0>e>>>0)return O=t,0;e:do{if(4&i[7088])n=0,y=143;else{r=0|i[6983];t:do{if(r){for(s=28356;!((h=0|i[s>>2])>>>0<=r>>>0&&(h+(0|i[s+4>>2])|0)>>>0>r>>>0);){if(!(e=0|i[s+8>>2])){y=128;break t}s=e}if((n=o-c&a)>>>0<2147483647)if((0|(e=0|ln(0|n)))==((0|i[s>>2])+(0|i[s+4>>2])|0)){if(-1!=(0|e)){c=n,o=e,y=145;break e}}else s=e,y=136;else n=0}else y=128}while(0);do{if(128==(0|y))if(-1!=(0|(r=0|ln(0)))&&(n=r,m=(n=((m=(p=0|i[7096])-1|0)&n?(m+n&0-p)-n|0:0)+f|0)+(p=0|i[7085])|0,n>>>0>d>>>0&n>>>0<2147483647)){if(0|(h=0|i[7087])&&m>>>0<=p>>>0|m>>>0>h>>>0){n=0;break}if((0|(e=0|ln(0|n)))==(0|r)){c=n,o=r,y=145;break e}s=e,y=136}else n=0}while(0);do{if(136==(0|y)){if(r=0-n|0,!(A>>>0>n>>>0&n>>>0<2147483647&-1!=(0|s))){if(-1==(0|s)){n=0;break}c=n,o=s,y=145;break e}if((e=l-n+(e=0|i[7097])&0-e)>>>0>=2147483647){c=n,o=s,y=145;break e}if(-1==(0|ln(0|e))){ln(0|r),n=0;break}c=e+n|0,o=s,y=145;break e}}while(0);i[7088]=4|i[7088],y=143}}while(0);if(143==(0|y)&&f>>>0<2147483647&&!(-1==(0|(w=0|ln(0|f)))|1^(b=(g=(m=0|ln(0))-w|0)>>>0>(d+40|0)>>>0)|w>>>0<m>>>0&-1!=(0|w)&-1!=(0|m)^1)&&(c=b?g:n,o=w,y=145),145==(0|y)){n=(0|i[7085])+c|0,i[7085]=n,n>>>0>(0|i[7086])>>>0&&(i[7086]=n),l=0|i[6983];e:do{if(l){for(n=28356;;){if((0|o)==((e=0|i[n>>2])+(r=0|i[n+4>>2])|0)){y=154;break}if(!(s=0|i[n+8>>2]))break;n=s}if(!(154!=(0|y)||(v=n+4|0,8&i[n+12>>2]))&&o>>>0>l>>>0&e>>>0<=l>>>0){i[v>>2]=r+c,v=l+(w=7&(w=l+8|0)?0-w&7:0)|0,w=(_=(0|i[6980])+c|0)-w|0,i[6983]=v,i[6980]=w,i[v+4>>2]=1|w,i[l+_+4>>2]=40,i[6984]=i[7099];break}for(o>>>0<(0|i[6981])>>>0&&(i[6981]=o),r=o+c|0,n=28356;;){if((0|i[n>>2])==(0|r)){y=162;break}if(!(e=0|i[n+8>>2]))break;n=e}if(162==(0|y)&&!(8&i[n+12>>2])){i[n>>2]=o,i[(u=n+4|0)>>2]=(0|i[u>>2])+c,f=(u=o+(7&(u=o+8|0)?0-u&7:0)|0)+d|0,A=(n=r+(7&(n=r+8|0)?0-n&7:0)|0)-u-d|0,i[u+4>>2]=3|d;t:do{if((0|l)==(0|n))_=(0|i[6980])+A|0,i[6980]=_,i[6983]=f,i[f+4>>2]=1|_;else{if((0|i[6982])==(0|n)){_=(0|i[6979])+A|0,i[6979]=_,i[6982]=f,i[f+4>>2]=1|_,i[f+_>>2]=_;break}if(1==(3&(e=0|i[n+4>>2]))){c=-8&e,s=e>>>3;n:do{if(e>>>0<256){if(e=0|i[n+8>>2],(0|(r=0|i[n+12>>2]))==(0|e)){i[6977]=i[6977]&~(1<<s);break}i[e+12>>2]=r,i[r+8>>2]=e;break}o=0|i[n+24>>2],e=0|i[n+12>>2];do{if((0|e)==(0|n)){if(e=0|i[(s=4+(r=n+16|0)|0)>>2])r=s;else if(!(e=0|i[r>>2])){e=0;break}for(;;)if(s=0|i[(a=e+20|0)>>2])e=s,r=a;else{if(!(s=0|i[(a=e+16|0)>>2]))break;e=s,r=a}i[r>>2]=0}else _=0|i[n+8>>2],i[_+12>>2]=e,i[e+8>>2]=_}while(0);if(!o)break;s=28212+((r=0|i[n+28>>2])<<2)|0;do{if((0|i[s>>2])==(0|n)){if(i[s>>2]=e,0|e)break;i[6978]=i[6978]&~(1<<r);break n}if(i[((0|i[(_=o+16|0)>>2])==(0|n)?_:o+20)>>2]=e,!e)break n}while(0);if(i[e+24>>2]=o,0|(s=0|i[(r=n+16|0)>>2])&&(i[e+16>>2]=s,i[s+24>>2]=e),!(r=0|i[r+4>>2]))break;i[e+20>>2]=r,i[r+24>>2]=e}while(0);n=n+c|0,a=c+A|0}else a=A;if(i[(n=n+4|0)>>2]=-2&i[n>>2],i[f+4>>2]=1|a,i[f+a>>2]=a,n=a>>>3,a>>>0<256){r=27948+(n<<1<<2)|0,(e=0|i[6977])&(n=1<<n)?n=0|i[(e=r+8|0)>>2]:(i[6977]=e|n,n=r,e=r+8|0),i[e>>2]=f,i[n+12>>2]=f,i[f+8>>2]=n,i[f+12>>2]=r;break}n=a>>>8;do{if(n){if(a>>>0>16777215){s=31;break}s=a>>>(7+(s=14-((w=(520192+(_=n<<(v=(n+1048320|0)>>>16&8))|0)>>>16&4)|v|(s=(245760+(_<<=w)|0)>>>16&2))+(_<<s>>>15)|0)|0)&1|s<<1}else s=0}while(0);if(n=28212+(s<<2)|0,i[f+28>>2]=s,i[4+(e=f+16|0)>>2]=0,i[e>>2]=0,!((e=0|i[6978])&(r=1<<s))){i[6978]=e|r,i[n>>2]=f,i[f+24>>2]=n,i[f+12>>2]=f,i[f+8>>2]=f;break}n=0|i[n>>2];n:do{if((-8&i[n+4>>2])!=(0|a)){for(s=a<<(31==(0|s)?0:25-(s>>>1)|0);e=0|i[(r=n+16+(s>>>31<<2)|0)>>2];){if((-8&i[e+4>>2])==(0|a)){n=e;break n}s<<=1,n=e}i[r>>2]=f,i[f+24>>2]=n,i[f+12>>2]=f,i[f+8>>2]=f;break t}}while(0);_=0|i[(v=n+8|0)>>2],i[_+12>>2]=f,i[v>>2]=f,i[f+8>>2]=_,i[f+12>>2]=n,i[f+24>>2]=0}}while(0);return O=t,0|u+8}for(n=28356;!((e=0|i[n>>2])>>>0<=l>>>0&&(_=e+(0|i[n+4>>2])|0)>>>0>l>>>0);)n=0|i[n+8>>2];n=(e=(e=(a=_+-47|0)+(7&(e=a+8|0)?0-e&7:0)|0)>>>0<(a=l+16|0)>>>0?l:e)+8|0,v=o+(w=7&(w=o+8|0)?0-w&7:0)|0,w=(r=c+-40|0)-w|0,i[6983]=v,i[6980]=w,i[v+4>>2]=1|w,i[o+r+4>>2]=40,i[6984]=i[7099],i[(r=e+4|0)>>2]=27,i[n>>2]=i[7089],i[n+4>>2]=i[7090],i[n+8>>2]=i[7091],i[n+12>>2]=i[7092],i[7089]=o,i[7090]=c,i[7092]=0,i[7091]=n,n=e+24|0;do{v=n,i[(n=n+4|0)>>2]=7}while((v+8|0)>>>0<_>>>0);if((0|e)!=(0|l)){if(o=e-l|0,i[r>>2]=-2&i[r>>2],i[l+4>>2]=1|o,i[e>>2]=o,n=o>>>3,o>>>0<256){r=27948+(n<<1<<2)|0,(e=0|i[6977])&(n=1<<n)?n=0|i[(e=r+8|0)>>2]:(i[6977]=e|n,n=r,e=r+8|0),i[e>>2]=l,i[n+12>>2]=l,i[l+8>>2]=n,i[l+12>>2]=r;break}if(r=28212+((s=(n=o>>>8)?o>>>0>16777215?31:o>>>(7+(s=14-((w=(520192+(_=n<<(v=(n+1048320|0)>>>16&8))|0)>>>16&4)|v|(s=(245760+(_<<=w)|0)>>>16&2))+(_<<s>>>15)|0)|0)&1|s<<1:0)<<2)|0,i[l+28>>2]=s,i[l+20>>2]=0,i[a>>2]=0,!((n=0|i[6978])&(e=1<<s))){i[6978]=n|e,i[r>>2]=l,i[l+24>>2]=r,i[l+12>>2]=l,i[l+8>>2]=l;break}n=0|i[r>>2];t:do{if((-8&i[n+4>>2])!=(0|o)){for(s=o<<(31==(0|s)?0:25-(s>>>1)|0);e=0|i[(r=n+16+(s>>>31<<2)|0)>>2];){if((-8&i[e+4>>2])==(0|o)){n=e;break t}s<<=1,n=e}i[r>>2]=l,i[l+24>>2]=n,i[l+12>>2]=l,i[l+8>>2]=l;break e}}while(0);_=0|i[(v=n+8|0)>>2],i[_+12>>2]=l,i[v>>2]=l,i[l+8>>2]=_,i[l+12>>2]=n,i[l+24>>2]=0}}else!(0|(_=0|i[6981]))|o>>>0<_>>>0&&(i[6981]=o),i[7089]=o,i[7090]=c,i[7092]=0,i[6986]=i[7095],i[6985]=-1,i[6990]=27948,i[6989]=27948,i[6992]=27956,i[6991]=27956,i[6994]=27964,i[6993]=27964,i[6996]=27972,i[6995]=27972,i[6998]=27980,i[6997]=27980,i[7e3]=27988,i[6999]=27988,i[7002]=27996,i[7001]=27996,i[7004]=28004,i[7003]=28004,i[7006]=28012,i[7005]=28012,i[7008]=28020,i[7007]=28020,i[7010]=28028,i[7009]=28028,i[7012]=28036,i[7011]=28036,i[7014]=28044,i[7013]=28044,i[7016]=28052,i[7015]=28052,i[7018]=28060,i[7017]=28060,i[7020]=28068,i[7019]=28068,i[7022]=28076,i[7021]=28076,i[7024]=28084,i[7023]=28084,i[7026]=28092,i[7025]=28092,i[7028]=28100,i[7027]=28100,i[7030]=28108,i[7029]=28108,i[7032]=28116,i[7031]=28116,i[7034]=28124,i[7033]=28124,i[7036]=28132,i[7035]=28132,i[7038]=28140,i[7037]=28140,i[7040]=28148,i[7039]=28148,i[7042]=28156,i[7041]=28156,i[7044]=28164,i[7043]=28164,i[7046]=28172,i[7045]=28172,i[7048]=28180,i[7047]=28180,i[7050]=28188,i[7049]=28188,i[7052]=28196,i[7051]=28196,v=o+(w=7&(w=o+8|0)?0-w&7:0)|0,w=(_=c+-40|0)-w|0,i[6983]=v,i[6980]=w,i[v+4>>2]=1|w,i[o+_+4>>2]=40,i[6984]=i[7099]}while(0);if((n=0|i[6980])>>>0>d>>>0)return w=n-d|0,i[6980]=w,v=(_=0|i[6983])+d|0,i[6983]=v,i[v+4>>2]=1|w,i[_+4>>2]=3|d,O=t,0|_+8}return i[(_=27904)>>2]=12,O=t,0}function Ht(e){var t=0,n=0,r=0,s=0,a=0,o=0,c=0,A=0;if(e|=0){n=e+-8|0,s=0|i[6981],A=n+(t=-8&(e=0|i[e+-4>>2]))|0;do{if(1&e)c=n,o=n;else{if(r=0|i[n>>2],!(3&e))return;if(a=r+t|0,(o=n+(0-r)|0)>>>0<s>>>0)return;if((0|i[6982])==(0|o)){if(3&~(t=0|i[(e=A+4|0)>>2])){c=o,t=a;break}return i[6979]=a,i[e>>2]=-2&t,i[o+4>>2]=1|a,void(i[o+a>>2]=a)}if(n=r>>>3,r>>>0<256){if(e=0|i[o+8>>2],(0|(t=0|i[o+12>>2]))==(0|e)){i[6977]=i[6977]&~(1<<n),c=o,t=a;break}i[e+12>>2]=t,i[t+8>>2]=e,c=o,t=a;break}s=0|i[o+24>>2],e=0|i[o+12>>2];do{if((0|e)==(0|o)){if(e=0|i[(n=4+(t=o+16|0)|0)>>2])t=n;else if(!(e=0|i[t>>2])){e=0;break}for(;;)if(n=0|i[(r=e+20|0)>>2])e=n,t=r;else{if(!(n=0|i[(r=e+16|0)>>2]))break;e=n,t=r}i[t>>2]=0}else c=0|i[o+8>>2],i[c+12>>2]=e,i[e+8>>2]=c}while(0);if(s){if(t=0|i[o+28>>2],(0|i[(n=28212+(t<<2)|0)>>2])==(0|o)){if(i[n>>2]=e,!e){i[6978]=i[6978]&~(1<<t),c=o,t=a;break}}else if(i[((0|i[(c=s+16|0)>>2])==(0|o)?c:s+20)>>2]=e,!e){c=o,t=a;break}i[e+24>>2]=s,0|(n=0|i[(t=o+16|0)>>2])&&(i[e+16>>2]=n,i[n+24>>2]=e),(t=0|i[t+4>>2])?(i[e+20>>2]=t,i[t+24>>2]=e,c=o,t=a):(c=o,t=a)}else c=o,t=a}}while(0);if(!(o>>>0>=A>>>0)&&1&(r=0|i[(e=A+4|0)>>2])){if(2&r)i[e>>2]=-2&r,i[c+4>>2]=1|t,i[o+t>>2]=t,s=t;else{if((0|i[6983])==(0|A)){if(A=(0|i[6980])+t|0,i[6980]=A,i[6983]=c,i[c+4>>2]=1|A,(0|c)!=(0|i[6982]))return;return i[6982]=0,void(i[6979]=0)}if((0|i[6982])==(0|A))return A=(0|i[6979])+t|0,i[6979]=A,i[6982]=o,i[c+4>>2]=1|A,void(i[o+A>>2]=A);s=(-8&r)+t|0,n=r>>>3;do{if(r>>>0<256){if(t=0|i[A+8>>2],(0|(e=0|i[A+12>>2]))==(0|t)){i[6977]=i[6977]&~(1<<n);break}i[t+12>>2]=e,i[e+8>>2]=t;break}a=0|i[A+24>>2],e=0|i[A+12>>2];do{if((0|e)==(0|A)){if(e=0|i[(n=4+(t=A+16|0)|0)>>2])t=n;else if(!(e=0|i[t>>2])){n=0;break}for(;;)if(n=0|i[(r=e+20|0)>>2])e=n,t=r;else{if(!(n=0|i[(r=e+16|0)>>2]))break;e=n,t=r}i[t>>2]=0,n=e}else n=0|i[A+8>>2],i[n+12>>2]=e,i[e+8>>2]=n,n=e}while(0);if(0|a){if(e=0|i[A+28>>2],(0|i[(t=28212+(e<<2)|0)>>2])==(0|A)){if(i[t>>2]=n,!n){i[6978]=i[6978]&~(1<<e);break}}else if(i[((0|i[(r=a+16|0)>>2])==(0|A)?r:a+20)>>2]=n,!n)break;i[n+24>>2]=a,0|(t=0|i[(e=A+16|0)>>2])&&(i[n+16>>2]=t,i[t+24>>2]=n),0|(e=0|i[e+4>>2])&&(i[n+20>>2]=e,i[e+24>>2]=n)}}while(0);if(i[c+4>>2]=1|s,i[o+s>>2]=s,(0|c)==(0|i[6982]))return void(i[6979]=s)}if(e=s>>>3,s>>>0<256)return n=27948+(e<<1<<2)|0,(t=0|i[6977])&(e=1<<e)?e=0|i[(t=n+8|0)>>2]:(i[6977]=t|e,e=n,t=n+8|0),i[t>>2]=c,i[e+12>>2]=c,i[c+8>>2]=e,void(i[c+12>>2]=n);e=28212+((r=(e=s>>>8)?s>>>0>16777215?31:s>>>(7+(r=14-((a=(520192+(A=e<<(o=(e+1048320|0)>>>16&8))|0)>>>16&4)|o|(r=(245760+(A<<=a)|0)>>>16&2))+(A<<r>>>15)|0)|0)&1|r<<1:0)<<2)|0,i[c+28>>2]=r,i[c+20>>2]=0,i[c+16>>2]=0,t=0|i[6978],n=1<<r;e:do{if(t&n){e=0|i[e>>2];t:do{if((-8&i[e+4>>2])!=(0|s)){for(r=s<<(31==(0|r)?0:25-(r>>>1)|0);t=0|i[(n=e+16+(r>>>31<<2)|0)>>2];){if((-8&i[t+4>>2])==(0|s)){e=t;break t}r<<=1,e=t}i[n>>2]=c,i[c+24>>2]=e,i[c+12>>2]=c,i[c+8>>2]=c;break e}}while(0);A=0|i[(o=e+8|0)>>2],i[A+12>>2]=c,i[o>>2]=c,i[c+8>>2]=A,i[c+12>>2]=e,i[c+24>>2]=0}else i[6978]=t|n,i[e>>2]=c,i[c+24>>2]=e,i[c+12>>2]=c,i[c+8>>2]=c}while(0);if(A=(0|i[6985])-1|0,i[6985]=A,!(0|A)){for(e=28364;e=0|i[e>>2];)e=e+8|0;i[6985]=-1}}}}function zt(e,t){t|=0;var n=0;return(e|=0)?(n=0|w(t,e),(t|e)>>>0>65535&&(n=((n>>>0)/(e>>>0)|0)==(0|t)?n:-1)):n=0,(e=0|jt(n))&&3&i[e+-4>>2]?(cn(0|e,0,0|n),0|e):0|e}function qt(e,t,n,r){return 0|(k((t|=0)+(r|=0)+((n=(e|=0)+(n|=0)>>>0)>>>0<e>>>0|0)>>>0|0),n)}function Qt(e,t,n,r){return 0|(k(0|(r=(t|=0)-(r|=0)-((n|=0)>>>0>(e|=0)>>>0|0)>>>0)),e-n>>>0)}function Vt(e){return 0|((e|=0)?31-(0|E(e^e-1)):32)}function Jt(e,t,n,r,s){s|=0;var a=0,o=0,c=0,A=0,l=0,f=0,u=0,d=0,h=0,p=0;if(f=e|=0,o=n|=0,c=d=r|=0,!(l=A=t|=0))return a=!!(0|s),c?a?(i[s>>2]=0|e,i[s+4>>2]=0&t,s=0,0|(k(0|(d=0)),s)):(s=0,0|(k(0|(d=0)),s)):(a&&(i[s>>2]=(f>>>0)%(o>>>0),i[s+4>>2]=0),s=(f>>>0)/(o>>>0)>>>0,0|(k(0|(d=0)),s));a=!(0|c);do{if(o){if(!a){if((a=(0|E(0|c))-(0|E(0|l))|0)>>>0<=31){o=u=a+1|0,e=f>>>(u>>>0)&(t=a-31>>31)|l<<(c=31-a|0),t&=l>>>(u>>>0),a=0,c=f<<c;break}return s?(i[s>>2]=0|e,i[s+4>>2]=A|0&t,s=0,0|(k(0|(d=0)),s)):(s=0,0|(k(0|(d=0)),s))}if((a=o-1|0)&o){o=c=33+(0|E(0|o))-(0|E(0|l))|0,e=(u=32-c|0)-1>>31&l>>>((h=c-32|0)>>>0)|(l<<u|f>>>(c>>>0))&(t=h>>31),t&=l>>>(c>>>0),a=f<<(p=64-c|0)&(A=u>>31),c=(l<<p|f>>>(h>>>0))&A|f<<u&c-33>>31;break}return 0|s&&(i[s>>2]=a&f,i[s+4>>2]=0),1==(0|o)?(p=0|e,0|(k(0|(h=A|0&t)),p)):(h=l>>>((p=0|Vt(0|o))>>>0)|0,p=l<<32-p|f>>>(p>>>0),0|(k(0|h),p))}if(a)return 0|s&&(i[s>>2]=(l>>>0)%(o>>>0),i[s+4>>2]=0),p=(l>>>0)/(o>>>0)>>>0,0|(k(0|(h=0)),p);if(!f)return 0|s&&(i[s>>2]=0,i[s+4>>2]=(l>>>0)%(c>>>0)),p=(l>>>0)/(c>>>0)>>>0,0|(k(0|(h=0)),p);if(!((a=c-1|0)&c))return 0|s&&(i[s>>2]=0|e,i[s+4>>2]=a&l|0&t),h=0,p=l>>>((0|Vt(0|c))>>>0),0|(k(0|h),p);if((a=(0|E(0|c))-(0|E(0|l))|0)>>>0<=30){o=t=a+1|0,e=l<<(c=31-a|0)|f>>>(t>>>0),t=l>>>(t>>>0),a=0,c=f<<c;break}return s?(i[s>>2]=0|e,i[s+4>>2]=A|0&t,p=0,0|(k(0|(h=0)),p)):(p=0,0|(k(0|(h=0)),p))}while(0);if(o){l=0|qt(0|(u=0|n),0|(f=d|0&r),-1,-1),n=0|T(),A=c,c=0;do{r=A,A=a>>>31|A<<1,a=c|a<<1,Qt(0|l,0|n,0|(r=e<<1|r>>>31),0|(d=e>>>31|t<<1)),c=1&(h=(p=0|T())>>31|((0|p)<0?-1:0)<<1),e=0|Qt(0|r,0|d,h&u|0,(((0|p)<0?-1:0)>>31|((0|p)<0?-1:0)<<1)&f),t=0|T(),o=o-1|0}while(0|o);l=A,A=0}else l=c,A=0,c=0;return o=0,0|s&&(i[s>>2]=e,i[s+4>>2]=t),p=a<<1&-2|c,0|(k(0|(h=(0|a)>>>31|(l|o)<<1|A)),p)}function Kt(e,t,n,r){var i,s,a,o,c;return n|=0,s=(r|=0)>>31|((0|r)<0?-1:0)<<1,i=((0|r)<0?-1:0)>>31|((0|r)<0?-1:0)<<1,a=0|Qt((c=(t|=0)>>31|((0|t)<0?-1:0)<<1)^(e|=0),(o=((0|t)<0?-1:0)>>31|((0|t)<0?-1:0)<<1)^t,0|c,0|o),e=s^c,t=i^o,0|Qt((0|Jt(a,0|T(),0|Qt(s^n|0,i^r|0,0|s,0|i),0|T(),0))^e,(0|T())^t,0|e,0|t)}function Wt(e,t,n,r){var i,s;return t|=0,r|=0,n=0|function(e,t){var n,r,i,s=0;return e=((n=0|w(s=65535&(t|=0),i=65535&(e|=0)))>>>16)+(0|w(s,r=e>>>16))|0,t=0|w(s=t>>>16,i),0|(k((e>>>16)+(0|w(s,r))+(((65535&e)+t|0)>>>16)|0),e+t<<16|65535&n)}(i=e|=0,s=n|=0),e=0|T(),0|(k((0|w(t,s))+(0|w(r,i))+e|0&e),n)}function Yt(e,t,n,r){var s,a,o,c,A,l;return n|=0,s=O,O=O+16|0,c=0|s,l=(r|=0)>>31|((0|r)<0?-1:0)<<1,A=((0|r)<0?-1:0)>>31|((0|r)<0?-1:0)<<1,Jt(e=0|Qt((o=(t|=0)>>31|((0|t)<0?-1:0)<<1)^(e|=0),(a=((0|t)<0?-1:0)>>31|((0|t)<0?-1:0)<<1)^t,0|o,0|a),t=0|T(),0|Qt(l^n|0,A^r|0,0|l,0|A),0|T(),c),r=0|Qt(i[c>>2]^o|0,i[c+4>>2]^a|0,0|o,0|a),n=0|T(),O=s,0|(k(0|n),r)}function Zt(e,t,n,r){var s,a;return a=O,O=O+16|0,Jt(e|=0,t|=0,n|=0,r|=0,s=0|a),O=a,0|(k(0|i[s+4>>2]),i[s>>2])}function Xt(e,t,n){return e|=0,t|=0,(0|(n|=0))<32?(k(t>>n|0),e>>>n|(t&(1<<n)-1)<<32-n):(k(0|((0|t)<0?-1:0)),t>>n-32)}function en(e,t,n){return e|=0,t|=0,(0|(n|=0))<32?(k(t>>>n|0),e>>>n|(t&(1<<n)-1)<<32-n):(k(0),t>>>n-32|0)}function tn(e,t,n){return e|=0,(0|(n|=0))<32?(k((t|=0)<<n|(e&(1<<n)-1<<32-n)>>>32-n),e<<n):(k(e<<n-32),0)}function nn(e,t,n){return e|=0,32==(0|(t=0|E(t|=0)))&&(t=t+(0|E(e))|0),k(0),0|t}function rn(e,t){return t=+t,(e=+e)!=e?+t:t!=t?+e:+_(+e,+t)}function sn(e,t){return t=+t,(e=+e)!=e?+t:t!=t?+e:+v(+e,+t)}function an(e){return(e=+e)>=0?+c(e+.5):+b(e-.5)}function on(e,t,n){e|=0,t|=0;var s,a,o=0;if((0|(n|=0))>=8192)return P(0|e,0|t,0|n),0|e;if(a=0|e,s=e+n|0,(3&e)==(3&t)){for(;3&e;){if(!n)return 0|a;r[0|e]=0|r[0|t],e=e+1|0,t=t+1|0,n=n-1|0}for(o=(n=-4&s)-64|0;(0|e)<=(0|o);)i[e>>2]=i[t>>2],i[e+4>>2]=i[t+4>>2],i[e+8>>2]=i[t+8>>2],i[e+12>>2]=i[t+12>>2],i[e+16>>2]=i[t+16>>2],i[e+20>>2]=i[t+20>>2],i[e+24>>2]=i[t+24>>2],i[e+28>>2]=i[t+28>>2],i[e+32>>2]=i[t+32>>2],i[e+36>>2]=i[t+36>>2],i[e+40>>2]=i[t+40>>2],i[e+44>>2]=i[t+44>>2],i[e+48>>2]=i[t+48>>2],i[e+52>>2]=i[t+52>>2],i[e+56>>2]=i[t+56>>2],i[e+60>>2]=i[t+60>>2],e=e+64|0,t=t+64|0;for(;(0|e)<(0|n);)i[e>>2]=i[t>>2],e=e+4|0,t=t+4|0}else for(n=s-4|0;(0|e)<(0|n);)r[0|e]=0|r[0|t],r[e+1|0]=0|r[t+1|0],r[e+2|0]=0|r[t+2|0],r[e+3|0]=0|r[t+3|0],e=e+4|0,t=t+4|0;for(;(0|e)<(0|s);)r[0|e]=0|r[0|t],e=e+1|0,t=t+1|0;return 0|a}function cn(e,t,n){t|=0;var s,a=0,o=0,c=0;if(s=(e|=0)+(n|=0)|0,t&=255,(0|n)>=67){for(;3&e;)r[0|e]=t,e=e+1|0;for(c=t|t<<8|t<<16|t<<24,o=(a=-4&s)-64|0;(0|e)<=(0|o);)i[e>>2]=c,i[e+4>>2]=c,i[e+8>>2]=c,i[e+12>>2]=c,i[e+16>>2]=c,i[e+20>>2]=c,i[e+24>>2]=c,i[e+28>>2]=c,i[e+32>>2]=c,i[e+36>>2]=c,i[e+40>>2]=c,i[e+44>>2]=c,i[e+48>>2]=c,i[e+52>>2]=c,i[e+56>>2]=c,i[e+60>>2]=c,e=e+64|0;for(;(0|e)<(0|a);)i[e>>2]=c,e=e+4|0}for(;(0|e)<(0|s);)r[0|e]=t,e=e+1|0;return s-n|0}function An(e){return(e=+e)>=0?+c(e+.5):+b(e-.5)}function ln(e){var t,n,r;return e|=0,r=0|I(),(0|e)>0&(0|(t=(n=0|i[o>>2])+e|0))<(0|n)|(0|t)<0?(N(0|t),x(12),-1):(0|t)>(0|r)&&!(0|C(0|t))?(x(12),-1):(i[o>>2]=t,0|n)}return{___divdi3:Kt,___muldi3:Wt,___remdi3:Yt,___uremdi3:Zt,_areNeighborCells:function(e,t,n,r,s){s|=0;var a,o,c,A=0,l=0,f=0,u=0;if(c=O,O=O+64|0,o=c,a=c+56|0,!(!0&134217728==(2013265920&(t|=0))&!0&134217728==(2013265920&(r|=0))))return O=c,5;if((0|(e|=0))==(0|(n|=0))&(0|t)==(0|r))return i[s>>2]=0,O=c,0;if(l=0|en(0|e,0|t,52),T(),l&=15,u=0|en(0|n,0|r,52),T(),(0|l)!=(15&u))return O=c,12;if(A=l+-1|0,l>>>0>1){De(e,t,A,o),De(n,r,A,a),f=0|i[(u=o)>>2],u=0|i[u+4>>2];e:do{if((0|f)==(0|i[a>>2])&&(0|u)==(0|i[a+4>>2])){A=0|en(0|e,0|t,0|(l=3*(15^l)|0)),T(),A&=7,l=0|en(0|n,0|r,0|l),T(),l&=7;do{if(!(0|A)|!(0|l))i[s>>2]=1,A=0;else if(7==(0|A))A=5;else{if(1==(0|A)|1==(0|l)&&0|Ge(f,u)){A=5;break}if((0|i[15536+(A<<2)>>2])!=(0|l)&&(0|i[15568+(A<<2)>>2])!=(0|l))break e;i[s>>2]=1,A=0}}while(0);return O=c,0|A}}while(0)}l=(A=o)+56|0;do{i[A>>2]=0,A=A+4|0}while((0|A)<(0|l));return R(e,t,1,o),A=(0|i[(t=o)>>2])==(0|n)&&(0|i[t+4>>2])==(0|r)||(0|i[(t=o+8|0)>>2])==(0|n)&&(0|i[t+4>>2])==(0|r)||(0|i[(t=o+16|0)>>2])==(0|n)&&(0|i[t+4>>2])==(0|r)||(0|i[(t=o+24|0)>>2])==(0|n)&&(0|i[t+4>>2])==(0|r)||(0|i[(t=o+32|0)>>2])==(0|n)&&(0|i[t+4>>2])==(0|r)||(0|i[(t=o+40|0)>>2])==(0|n)&&(0|i[t+4>>2])==(0|r)?1:1&((0|i[(A=o+48|0)>>2])==(0|n)?(0|i[A+4>>2])==(0|r):0),i[s>>2]=A,O=c,0},_bitshift64Ashr:Xt,_bitshift64Lshr:en,_bitshift64Shl:tn,_calloc:zt,_cellAreaKm2:function(e,t,n){return 0|(e=0|lt(e|=0,t|=0,n|=0))||(s[n>>3]=6371.007180918475*+s[n>>3]*6371.007180918475),0|e},_cellAreaM2:function(e,t,n){return 0|(e=0|lt(e|=0,t|=0,n|=0))||(s[n>>3]=6371.007180918475*+s[n>>3]*6371.007180918475*1e3*1e3),0|e},_cellAreaRads2:lt,_cellToBoundary:Ze,_cellToCenterChild:Le,_cellToChildPos:function(e,t,n,r){n|=0,r|=0;var s,a=0,o=0,c=0,A=0,l=0,f=0,u=0,d=0,h=0,p=0,m=0,y=0,g=0,b=0;if(s=O,O=O+16|0,g=s,b=0|en(0|(e|=0),0|(t|=0),52),T(),n>>>0>15)return O=s,4;if((0|(b&=15))<(0|n))return O=s,12;if((0|b)!=(0|n))if(o=0|tn(0|n,0,52),o|=e,A=T()|-15728641&t,(0|b)>(0|n)){l=n;do{y=0|tn(7,0,3*(14-l|0)|0),l=l+1|0,o|=y,A=0|T()|A}while((0|l)<(0|b));y=o}else y=o;else y=e,A=t;m=0|en(0|y,0|A,45),T();e:do{if(0|L(127&m)){if(l=0|en(0|y,0|A,52),T(),0|(l&=15))for(o=1;;){if(!(!((m=0|tn(7,0,3*(15-o|0)|0))&y)&!((0|T())&A))){f=33;break e}if(!(o>>>0<l>>>0))break;o=o+1|0}if(i[(m=r)>>2]=0,i[m+4>>2]=0,(0|b)>(0|n)){for(m=-15728641&t,p=b;;){if(h=p,(p=p+-1|0)>>>0>15|(0|b)<(0|p)){f=19;break}if((0|b)!=(0|p))if(o=0|tn(0|p,0,52),o|=e,l=0|T()|m,(0|b)<(0|h))d=o;else{f=p;do{d=0|tn(7,0,3*(14-f|0)|0),f=f+1|0,o|=d,l=0|T()|l}while((0|f)<(0|b));d=o}else d=e,l=t;if(u=0|en(0|d,0|l,45),T(),0|L(127&u)){u=0|en(0|d,0|l,52),T(),u&=15;t:do{if(u)for(f=1;;){if(o=0|en(0|d,0|l,3*(15-f|0)|0),T(),0|(o&=7))break t;if(!(f>>>0<u>>>0)){o=0;break}f=f+1|0}else o=0}while(0);o=1&!(0|o)}else o=0;if(l=0|en(0|e,0|t,3*(15-h|0)|0),T(),7==(0|(l&=7))){a=5,f=42;break}if(1==(0|l)&(o=!!(0|o))){a=5,f=42;break}if(0|(d=l+((!!(0|l)&o)<<31>>31)|0)&&(f=0|yt(7,0,f=b-h|0,((0|f)<0)<<31>>31),u=0|T(),o?(o=0|qt(0|(o=0|Wt(0|f,0|u,5,0)),0|T(),-5,-1),o=0|qt(0|(o=0|Kt(0|o,0|T(),6,0)),0|T(),1,0),l=0|T()):(o=f,l=u),h=0|qt(0|o,0|l,0|(h=0|Wt(0|f,0|u,0|(h=d+-1|0),((0|h)<0)<<31>>31)),0|T()),u=0|qt(0|h,0|(d=0|T()),0|i[(u=r)>>2],0|i[u+4>>2]),d=0|T(),i[(h=r)>>2]=u,i[h+4>>2]=d),(0|p)<=(0|n)){f=37;break}}if(19==(0|f))S(27795,27122,1276,27158);else{if(37==(0|f)){a=0|i[(c=r)+4>>2],c=0|i[c>>2];break}if(42==(0|f))return O=s,0|a}}else a=0,c=0}else f=33}while(0);e:do{if(33==(0|f)){if(i[(m=r)>>2]=0,i[m+4>>2]=0,(0|b)>(0|n)){for(o=b;;){if(a=0|en(0|e,0|t,3*(15-o|0)|0),T(),7==(0|(a&=7))){a=5;break}if(a=0|Wt(0|(c=0|yt(7,0,c=b-o|0,((0|c)<0)<<31>>31)),0|T(),0|a,0),c=0|T(),c=0|qt(0|i[(m=r)>>2],0|i[m+4>>2],0|a,0|c),a=0|T(),i[(m=r)>>2]=c,i[m+4>>2]=a,(0|(o=o+-1|0))<=(0|n))break e}return O=s,0|a}a=0,c=0}}while(0);return 0|Fe(y,A,b,g)&&S(27795,27122,1236,27173),((0|a)>-1|-1==(0|a)&c>>>0>4294967295)&((0|(g=0|i[(b=g)+4>>2]))>(0|a)|((0|g)==(0|a)?(0|i[b>>2])>>>0>c>>>0:0))?(O=s,0|(b=0)):(S(27795,27122,1316,27158),0)},_cellToChildren:function(e,t,n,r){r|=0;var s,a,o=0,c=0;if(a=O,O=O+16|0,et(s=a,e|=0,t|=0,n|=0),!(0|(e=0|i[(t=s)>>2]))&!(0|(t=0|i[t+4>>2])))return O=a,0;o=0,n=0;do{i[(c=r+(o<<3)|0)>>2]=e,i[c+4>>2]=t,o=0|qt(0|o,0|n,1,0),n=0|T(),nt(s),e=0|i[(c=s)>>2],t=0|i[c+4>>2]}while(!(!(0|e)&!(0|t)));return O=a,0},_cellToChildrenSize:Fe,_cellToLatLng:Ye,_cellToLocalIj:function(e,t,n,r,s,a){var o,c;return e|=0,a|=0,c=O,O=O+16|0,o=c,(s|=0)?e=15:(e=0|pt(e,t|=0,n|=0,r|=0,o))||(function(e,t){var n;t|=0,n=0|i[8+(e|=0)>>2],i[t>>2]=(0|i[e>>2])-n,i[t+4>>2]=(0|i[e+4>>2])-n}(o,a),e=0),O=c,0|e},_cellToParent:De,_cellToVertex:Rt,_cellToVertexes:function(e,t,n){n|=0;var r,s=0,a=0;return a=!(0|Ge(e|=0,t|=0)),r=!(0|(s=0|Rt(e,t,0,n))),a?r?0|(s=0|Rt(e,t,1,n+8|0))||0|(s=0|Rt(e,t,2,n+16|0))||0|(s=0|Rt(e,t,3,n+24|0))||(s=0|Rt(e,t,4,n+32|0))?0|(a=s):0|Rt(e,t,5,n+40|0):0|(a=s):r?0|(s=0|Rt(e,t,1,n+8|0))||0|(s=0|Rt(e,t,2,n+16|0))||0|(s=0|Rt(e,t,3,n+24|0))||0|(s=0|Rt(e,t,4,n+32|0))?0|(a=s):(i[(a=n+40|0)>>2]=0,i[a+4>>2]=0,0|(a=0)):0|(a=s)},_cellsToDirectedEdge:function(e,t,n,r,s){return s|=0,7==(0|(n=0|G(e|=0,t|=0,n|=0,r|=0)))?0|(s=11):(r=0|tn(0|n,0,56),t=-2130706433&t|T()|268435456,i[s>>2]=e|r,i[s+4>>2]=t,0|(s=0))},_cellsToLinkedMultiPolygon:function(e,t,n){n|=0;var r,a,o,c=0;if(o=O,O=O+32|0,r=o,0|(e=0|function(e,t,n){e|=0,n|=0;var r,s,a=0,o=0,c=0,A=0,l=0,f=0;if(s=O,O=O+176|0,r=s,(0|(t|=0))<1)return Bt(n,0,0),O=s,0;for(l=0|en(0|i[(l=e)>>2],0|i[l+4>>2],52),T(),Bt(n,(0|t)>6?t:6,15&l),l=0;!(0|(a=0|Ze(0|i[(a=e+(l<<3)|0)>>2],0|i[a+4>>2],r)));){if((0|(a=0|i[r>>2]))>0){A=0;do{c=r+8+(A<<4)|0,(o=0|Gt(n,a=r+8+((0|(A=A+1|0))%(0|a)<<4)|0,c))?Dt(n,o):Ft(n,c,a),a=0|i[r>>2]}while((0|A)<(0|a))}if((0|(l=l+1|0))>=(0|t)){a=0,f=13;break}}return 13==(0|f)?(O=s,0|a):(Mt(n),O=s,0|(f=a))}(e|=0,t|=0,a=o+16|0)))return O=o,0|e;if(i[n>>2]=0,i[n+4>>2]=0,i[n+8>>2]=0,0|(e=0|$t(a)))do{t=0|ft(n);do{ut(t,e),c=e+16|0,i[r>>2]=i[c>>2],i[r+4>>2]=i[c+4>>2],i[r+8>>2]=i[c+8>>2],i[r+12>>2]=i[c+12>>2],Dt(a,e),e=0|Ut(a,r)}while(0|e);e=0|$t(a)}while(0|e);return Mt(a),(e=0|function(e){var t,n,r=0,a=0,o=0,c=0,l=0,f=0,u=0,d=0,h=0,p=0,m=0,y=0,g=0,b=0,w=0,v=0,_=0,E=0,k=0,T=0,x=0,I=0,P=0,C=0,N=0,O=0,R=0,B=0,M=0,$=0;if(0|i[(c=(e|=0)+8|0)>>2])return 1;if(!(o=0|i[e>>2]))return 0;r=o,a=0;do{a=a+1|0,r=0|i[r+8>>2]}while(0|r);if(a>>>0<2)return 0;(n=0|jt(a<<2))||S(27396,27235,317,27415),(t=0|jt(a<<5))||S(27437,27235,321,27415),i[e>>2]=0,i[(I=e+4|0)>>2]=0,i[c>>2]=0,a=0,B=0,x=0,m=0;e:for(;;){if(p=0|i[o>>2]){l=0,f=p;do{if(d=+s[f+8>>3],r=f,f=0|i[f+16>>2],u=+s[(c=(h=!(0|f))?p:f)+8>>3],+A(+(d-u))>3.141592653589793){$=14;break}l+=(u-d)*(+s[r>>3]+ +s[c>>3])}while(!h);if(14==(0|$)){$=0,l=0,r=p;do{T=+s[r+8>>3],O=0|i[(R=r+16|0)>>2],k=+s[(O=0|O?O:p)+8>>3],l+=(+s[r>>3]+ +s[O>>3])*((k<0?k+6.283185307179586:k)-(T<0?T+6.283185307179586:T)),r=0|i[(0|r?R:o)>>2]}while(0|r)}l>0?(i[n+(B<<2)>>2]=o,B=B+1|0,c=x,r=m):$=19}else $=19;if(19==(0|$)){$=0;do{if(!a){if(m){c=I,f=m+8|0,r=o,a=e;break}if(0|i[e>>2]){$=27;break e}c=I,f=e,r=o,a=e;break}if(0|i[(r=a+8|0)>>2]){$=21;break e}if(!(a=0|zt(1,12))){$=23;break e}i[r>>2]=a,c=a+4|0,f=a,r=m}while(0);if(i[f>>2]=o,i[c>>2]=o,f=t+(x<<5)|0,h=0|i[o>>2]){for(s[(p=t+(x<<5)+8|0)>>3]=17976931348623157e292,s[(m=t+(x<<5)+24|0)>>3]=17976931348623157e292,s[f>>3]=-17976931348623157e292,s[(y=t+(x<<5)+16|0)>>3]=-17976931348623157e292,_=17976931348623157e292,E=-17976931348623157e292,c=0,g=h,d=17976931348623157e292,w=17976931348623157e292,v=-17976931348623157e292,u=-17976931348623157e292;l=+s[g>>3],T=+s[g+8>>3],g=0|i[g+16>>2],k=+s[((b=!(0|g))?h:g)+8>>3],l<d&&(s[p>>3]=l,d=l),T<w&&(s[m>>3]=T,w=T),l>v?s[f>>3]=l:l=v,T>u&&(s[y>>3]=T,u=T),_=T>0&T<_?T:_,E=T<0&T>E?T:E,c|=+A(+(T-k))>3.141592653589793,!b;)v=l;c&&(s[y>>3]=E,s[m>>3]=_)}else i[f>>2]=0,i[f+4>>2]=0,i[f+8>>2]=0,i[f+12>>2]=0,i[f+16>>2]=0,i[f+20>>2]=0,i[f+24>>2]=0,i[f+28>>2]=0;c=x+1|0}if(o=0|i[(R=o+8|0)>>2],i[R>>2]=0,!o){$=45;break}x=c,m=r}if(21==(0|$))S(27213,27235,35,27247);else if(23==(0|$))S(27267,27235,37,27247);else if(27==(0|$))S(27310,27235,61,27333);else if(45==(0|$)){e:do{if((0|B)>0){for(R=!(0|c),N=c<<2,O=!(0|e),C=0,r=0;;){if(P=0|i[n+(C<<2)>>2],R)$=73;else{if(!(x=0|jt(N))){$=50;break}if(!(I=0|jt(N))){$=52;break}t:do{if(O)a=0;else{for(c=0,a=0,f=e;o=t+(c<<5)|0,0|ht(0|i[f>>2],o,0|i[P>>2])?(i[x+(a<<2)>>2]=f,i[I+(a<<2)>>2]=o,b=a+1|0):b=a,f=0|i[f+8>>2];)c=c+1|0,a=b;if((0|b)>0)if(o=0|i[x>>2],1==(0|b))a=o;else for(y=0,g=-1,a=o,m=o;;){for(h=0|i[m>>2],o=0,f=0;p=(0|(c=0|i[i[x+(f<<2)>>2]>>2]))==(0|h)?o:o+(1&ht(c,0|i[I+(f<<2)>>2],0|i[h>>2]))|0,(0|(f=f+1|0))!=(0|b);)o=p;if(a=(c=(0|p)>(0|g))?m:a,(0|(o=y+1|0))==(0|b))break t;y=o,g=c?p:g,m=0|i[x+(o<<2)>>2]}else a=0}}while(0);if(Ht(x),Ht(I),a){if(o=0|i[(c=a+4|0)>>2])a=o+8|0;else if(0|i[a>>2]){$=70;break}i[a>>2]=P,i[c>>2]=P}else $=73}if(73==(0|$)){if($=0,0|(r=0|i[P>>2]))do{I=r,r=0|i[r+16>>2],Ht(I)}while(0|r);Ht(P),r=1}if((0|(C=C+1|0))>=(0|B)){M=r;break e}}50==(0|$)?S(27452,27235,249,27471):52==(0|$)?S(27490,27235,252,27471):70==(0|$)&&S(27310,27235,61,27333)}else M=0}while(0);return Ht(n),Ht(t),0|M}return 0}(n))?(dt(n),O=o,0|(c=e)):(O=o,0|(c=0))},_childPosToCell:function(e,t,n,r,s,a){e|=0,t|=0,a|=0;var o,c=0,A=0,l=0,f=0,u=0,d=0,h=0,p=0,m=0;if(o=O,O=O+16|0,c=o,(s|=0)>>>0>15)return O=o,4;if(A=0|en(0|(n|=0),0|(r|=0),52),T(),(0|(A&=15))>(0|s))return O=o,12;if(0|Fe(n,r,s,c)&&S(27795,27122,1236,27173),!(((0|t)>-1|-1==(0|t)&e>>>0>4294967295)&((0|(f=0|i[(u=c)+4>>2]))>(0|t)|((0|f)==(0|t)?(0|i[u>>2])>>>0>e>>>0:0))))return O=o,2;u=s-A|0,s=0|tn(0|s,0,52),l=T()|-15728641&r,i[(f=a)>>2]=s|n,i[f+4>>2]=l,f=0|en(0|n,0|r,45),T();e:do{if(0|L(127&f)){if(0|A)for(c=1;;){if(!(!((f=0|tn(7,0,3*(15-c|0)|0))&n)&!((0|T())&r)))break e;if(!(c>>>0<A>>>0))break;c=c+1|0}if((0|u)<1)return O=o,0;for(f=15^A,r=-1,l=1,c=1;;){A=0|yt(7,0,A=u-l|0,((0|A)<0)<<31>>31),n=0|T();do{if(c){if(c=0|Kt(0|(c=0|qt(0|(c=0|Wt(0|A,0|n,5,0)),0|T(),-5,-1)),0|T(),6,0),(0|t)>(0|(s=0|T()))|(0|t)==(0|s)&e>>>0>c>>>0){t=0|Qt(0|(t=0|qt(0|e,0|t,-1,-1)),0|T(),0|c,0|s),c=0|T(),p=0|i[(d=a)>>2],d=0|i[d+4>>2],h=0|tn(7,0,0|(m=3*(f+r|0)|0)),d&=~T(),m=0|tn(0|(s=0|qt(0|(r=0|Kt(0|t,0|c,0|A,0|n)),0|(e=0|T()),2,0)),0|T(),0|m),d=0|T()|d,i[(s=a)>>2]=m|p&~h,i[s+4>>2]=d,e=0|Qt(0|t,0|c,0|(e=0|Wt(0|r,0|e,0|A,0|n)),0|T()),c=0,t=0|T();break}h=0|i[(m=a)>>2],m=0|i[m+4>>2],p=0|tn(7,0,3*(f+r|0)|0),m&=~T(),i[(c=a)>>2]=h&~p,i[c+4>>2]=m,c=1;break}s=0|i[(h=a)>>2],h=0|i[h+4>>2],d=0|tn(7,0,0|(r=3*(f+r|0)|0)),h&=~T(),r=0|tn(0|(m=0|Kt(0|e,0|t,0|A,0|n)),0|(c=0|T()),0|r),h=0|T()|h,i[(p=a)>>2]=r|s&~d,i[p+4>>2]=h,e=0|Qt(0|e,0|t,0|(c=0|Wt(0|m,0|c,0|A,0|n)),0|T()),c=0,t=0|T()}while(0);if(!((0|u)>(0|l))){t=0;break}r=~l,l=l+1|0}return O=o,0|t}}while(0);if((0|u)<1)return O=o,0;for(s=15^A,c=1;;){if(p=0|yt(7,0,p=u-c|0,((0|p)<0)<<31>>31),m=0|T(),n=0|i[(l=a)>>2],l=0|i[l+4>>2],r=0|tn(7,0,0|(A=3*(s-c|0)|0)),l&=~T(),A=0|tn(0|(d=0|Kt(0|e,0|t,0|p,0|m)),0|(h=0|T()),0|A),l=0|T()|l,i[(f=a)>>2]=A|n&~r,i[f+4>>2]=l,e=0|Qt(0|e,0|t,0|(m=0|Wt(0|d,0|h,0|p,0|m)),0|T()),t=0|T(),(0|u)<=(0|c)){t=0;break}c=c+1|0}return O=o,0|t},_compactCells:function(e,t,n,r){t|=0;var s,a=0,o=0,c=0,A=0,l=0,f=0,u=0,d=0,h=0,p=0,m=0,y=0,g=0,b=0,w=0,v=0,_=0,E=0,k=0,x=0,I=0,P=0,C=0,N=0,O=0;if(!(0|(n|=0))&!(0|(r|=0)))return 0;if(o=0|i[(a=e|=0)>>2],!0&!(15728640&(a=0|i[a+4>>2]))){if(!((0|r)>0|!(0|r)&n>>>0>0))return 0;if(i[(O=t)>>2]=o,i[O+4>>2]=a,1==(0|n)&!(0|r))return 0;a=1,o=0;do{N=0|i[4+(C=e+(a<<3)|0)>>2],i[(O=t+(a<<3)|0)>>2]=i[C>>2],i[O+4>>2]=N,a=0|qt(0|a,0|o,1,0),o=0|T()}while((0|o)<(0|r)|(0|o)==(0|r)&a>>>0<n>>>0);return 0}if(!(N=0|jt(s=n<<3)))return 13;if(on(0|N,0|e,0|s),!(C=0|zt(n,8)))return Ht(N),13;e:for(;;){I=0|en(0|(f=0|i[(a=N)>>2]),0|(a=0|i[a+4>>2]),52),T(),P=(I&=15)-1|0,x=!!(0|I),k=(0|r)>0|!(0|r)&n>>>0>0;t:do{if(x&k){if(w=0|tn(0|P,0,52),v=0|T(),P>>>0>15){if(!(!(0|f)&!(0|a))){O=16;break e}for(o=0,e=0;;){if(o=0|qt(0|o,0|e,1,0),!((0|(e=0|T()))<(0|r)|(0|e)==(0|r)&o>>>0<n>>>0))break t;if(!(!(0|(E=0|i[(c=N+(o<<3)|0)>>2]))&!(0|(c=0|i[c+4>>2])))){a=c,O=16;break e}}}for(A=f,e=a,o=0,c=0;;){if(!(!(0|A)&!(0|e))){if(!(!0&!(117440512&e))){O=21;break e}if(u=0|en(0|A,0|e,52),T(),(0|(u&=15))<(0|P)){a=12,O=27;break e}if((0|u)!=(0|P)&&(A|=w,e=-15728641&e|v,u>>>0>=I>>>0)){l=P;do{E=0|tn(7,0,3*(14-l|0)|0),l=l+1|0,A|=E,e=0|T()|e}while(l>>>0<u>>>0)}if(h=0|Zt(0|A,0|e,0|n,0|r),p=0|T(),!(!(0|(d=0|i[(u=l=C+(h<<3)|0)>>2]))&!(0|(u=0|i[u+4>>2])))){g=0,b=0;do{if((0|g)>(0|r)|(0|g)==(0|r)&b>>>0>n>>>0){O=31;break e}if((0|d)==(0|A)&(-117440513&u)==(0|e)){m=0|en(0|d,0|u,56),T(),y=1+(m&=7)|0,E=0|en(0|d,0|u,45),T();n:do{if(0|L(127&E)){if(d=0|en(0|d,0|u,52),T(),!(d&=15)){u=6;break}for(u=1;;){if(!(!((E=0|tn(7,0,3*(15-u|0)|0))&A)&!((0|T())&e))){u=7;break n}if(!(u>>>0<d>>>0)){u=6;break}u=u+1|0}}else u=7}while(0);if((m+2|0)>>>0>u>>>0){O=41;break e}E=0|tn(0|y,0,56),e=T()|-117440513&e,i[(_=l)>>2]=0,i[_+4>>2]=0,A|=E}else h=0|Yt(0|(h=0|qt(0|h,0|p,1,0)),0|T(),0|n,0|r),p=0|T();b=0|qt(0|b,0|g,1,0),g=0|T(),d=0|i[(u=l=C+(h<<3)|0)>>2],u=0|i[u+4>>2]}while(!(!(0|d)&!(0|u)))}i[(E=l)>>2]=A,i[E+4>>2]=e}if(o=0|qt(0|o,0|c,1,0),!((0|(c=0|T()))<(0|r)|(0|c)==(0|r)&o>>>0<n>>>0))break t;A=0|i[(e=N+(o<<3)|0)>>2],e=0|i[e+4>>2]}}}while(0);if(E=0|qt(0|n,0|r,5,0),(_=0|T())>>>0<0|!(0|_)&E>>>0<11){O=85;break}if(E=0|Kt(0|n,0|r,6,0),T(),!(E=0|zt(E,8))){O=48;break}do{if(k){for(y=0,e=0,m=0,g=0;;){if(!(0|(o=0|i[(c=u=C+(y<<3)|0)>>2]))&!(0|(c=0|i[c+4>>2])))_=m;else{d=0|en(0|o,0|c,56),T(),A=1+(d&=7)|0,h=-117440513&c,_=0|en(0|o,0|c,45),T();t:do{if(0|L(127&_)){if(p=0|en(0|o,0|c,52),T(),0|(p&=15))for(l=1;;){if(!(!(o&(_=0|tn(7,0,3*(15-l|0)|0)))&!(h&(0|T()))))break t;if(!(l>>>0<p>>>0))break;l=l+1|0}o|=c=0|tn(0|A,0,56),c=0|T()|h,i[(A=u)>>2]=o,i[A+4>>2]=c,A=d+2|0}}while(0);7==(0|A)?(i[(_=E+(e<<3)|0)>>2]=o,i[_+4>>2]=-117440513&c,e=0|qt(0|e,0|m,1,0),_=0|T()):_=m}if(y=0|qt(0|y,0|g,1,0),!((0|(g=0|T()))<(0|r)|(0|g)==(0|r)&y>>>0<n>>>0))break;m=_}if(k){if(b=P>>>0>15,w=0|tn(0|P,0,52),v=0|T(),!x){for(o=0,l=0,A=0,c=0;!(0|f)&!(0|a)||(i[(P=t+(o<<3)|0)>>2]=f,i[P+4>>2]=a,o=0|qt(0|o,0|l,1,0),l=0|T()),A=0|qt(0|A,0|c,1,0),(0|(c=0|T()))<(0|r)|(0|c)==(0|r)&A>>>0<n>>>0;)f=0|i[(a=N+(A<<3)|0)>>2],a=0|i[a+4>>2];a=_;break}for(o=0,l=0,c=0,A=0;;){do{if(!(!(0|f)&!(0|a))){if(p=0|en(0|f,0|a,52),T(),b|(0|(p&=15))<(0|P)){O=80;break e}if((0|p)!=(0|P)){if(u=f|w,d=-15728641&a|v,p>>>0>=I>>>0){h=P;do{x=0|tn(7,0,3*(14-h|0)|0),h=h+1|0,u|=x,d=0|T()|d}while(h>>>0<p>>>0)}}else u=f,d=a;m=0|Zt(0|u,0|d,0|n,0|r),h=0,p=0,g=0|T();do{if((0|h)>(0|r)|(0|h)==(0|r)&p>>>0>n>>>0){O=81;break e}if((-117440513&(y=0|i[4+(x=C+(m<<3)|0)>>2]))==(0|d)&&(0|i[x>>2])==(0|u)){O=65;break}m=0|Yt(0|(x=0|qt(0|m,0|g,1,0)),0|T(),0|n,0|r),g=0|T(),p=0|qt(0|p,0|h,1,0),h=0|T(),x=C+(m<<3)|0}while((0|i[x>>2])!=(0|u)||(0|i[x+4>>2])!=(0|d));if(65==(0|O)&&(O=0,!0&100663296==(117440512&y)))break;i[(x=t+(o<<3)|0)>>2]=f,i[x+4>>2]=a,o=0|qt(0|o,0|l,1,0),l=0|T()}}while(0);if(c=0|qt(0|c,0|A,1,0),!((0|(A=0|T()))<(0|r)|(0|A)==(0|r)&c>>>0<n>>>0))break;f=0|i[(a=N+(c<<3)|0)>>2],a=0|i[a+4>>2]}a=_}else o=0,a=_}else o=0,e=0,a=0}while(0);if(cn(0|C,0,0|s),on(0|N,0|E,e<<3),Ht(E),!(0|e)&!(0|a)){O=89;break}t=t+(o<<3)|0,r=a,n=e}if(16==(0|O))!0&!(117440512&a)?(a=4,O=27):O=21;else if(31==(0|O))S(27795,27122,529,27132);else{if(41==(0|O))return Ht(N),Ht(C),10;if(48==(0|O))return Ht(N),Ht(C),13;80==(0|O)?S(27795,27122,620,27132):81==(0|O)?S(27795,27122,632,27132):85==(0|O)&&(on(0|t,0|N,n<<3),O=89)}return 21==(0|O)?(Ht(N),Ht(C),0|(O=5)):27==(0|O)?(Ht(N),Ht(C),0|(O=a)):89==(0|O)?(Ht(N),Ht(C),0|(O=0)):0},_destroyLinkedMultiPolygon:dt,_directedEdgeToBoundary:Se,_directedEdgeToCells:function(e,t,n){e|=0;var r,s,a,o=0;return r=O,O=O+16|0,o=r,!0&268435456==(2013265920&(t|=0))?(s=-2130706433&t|134217728,i[(a=n|=0)>>2]=e,i[a+4>>2]=s,i[o>>2]=0,t=0|en(0|e,0|t,56),T(),o=0|D(e,s,7&t,o,n+8|0),O=r,0|o):(O=r,0|(o=6))},_edgeLengthKm:function(e,t,n){n|=0;var r,a=0,o=0,c=0,A=0,f=0,h=0,p=0;if(r=O,O=O+176|0,0|(e=0|Se(e|=0,t|=0,A=r)))return A=e,c=+s[n>>3],c*=6371.007180918475,s[n>>3]=c,O=r,0|A;if(s[n>>3]=0,(0|(e=0|i[A>>2]))<=1)return A=0,c=0,c*=6371.007180918475,s[n>>3]=c,O=r,0|A;t=e+-1|0,e=0,a=+s[A+8>>3],o=+s[A+16>>3],c=0;do{h=a,a=+s[A+8+((e=e+1|0)<<4)>>3],p=+d(.5*(a-h)),f=o,o=+s[A+8+(e<<4)+8>>3],f=p*p+(f=+d(.5*(o-f)))*(+u(+h)*+u(+a)*f),c+=2*+g(+ +l(+f),+ +l(+(1-f)))}while((0|e)!=(0|t));return s[n>>3]=c,A=0,p=c,p*=6371.007180918475,s[n>>3]=p,O=r,0|A},_edgeLengthM:function(e,t,n){n|=0;var r,a=0,o=0,c=0,A=0,f=0,h=0,p=0;if(r=O,O=O+176|0,0|(e=0|Se(e|=0,t|=0,A=r)))return A=e,c=+s[n>>3],c*=6371.007180918475,c*=1e3,s[n>>3]=c,O=r,0|A;if(s[n>>3]=0,(0|(e=0|i[A>>2]))<=1)return A=0,c=0,c*=6371.007180918475,c*=1e3,s[n>>3]=c,O=r,0|A;t=e+-1|0,e=0,a=+s[A+8>>3],o=+s[A+16>>3],c=0;do{h=a,a=+s[A+8+((e=e+1|0)<<4)>>3],p=+d(.5*(a-h)),f=o,o=+s[A+8+(e<<4)+8>>3],f=p*p+(f=+d(.5*(o-f)))*(+u(+h)*+u(+a)*f),c+=2*+g(+ +l(+f),+ +l(+(1-f)))}while((0|e)!=(0|t));return s[n>>3]=c,A=0,p=c,p*=6371.007180918475,p*=1e3,s[n>>3]=p,O=r,0|A},_edgeLengthRads:function(e,t,n){n|=0;var r,a=0,o=0,c=0,A=0,f=0,h=0,p=0;if(r=O,O=O+176|0,0|(e=0|Se(e|=0,t|=0,A=r)))return O=r,0|e;if(s[n>>3]=0,(0|(e=0|i[A>>2]))<=1)return O=r,0;t=e+-1|0,e=0,a=+s[A+8>>3],o=+s[A+16>>3],c=0;do{h=a,a=+s[A+8+((e=e+1|0)<<4)>>3],p=+d(.5*(a-h)),f=o,o=+s[A+8+(e<<4)+8>>3],f=p*p+(f=+d(.5*(o-f)))*(+u(+a)*+u(+h)*f),c+=2*+g(+ +l(+f),+ +l(+(1-f)))}while((0|e)<(0|t));return s[n>>3]=c,O=r,0},_emscripten_replace_memory:function(e){return r=new Int8Array(e),i=new Int32Array(e),s=new Float64Array(e),n=e,!0},_free:Ht,_getBaseCellNumber:Be,_getDirectedEdgeDestination:function(e,t,n){e|=0,t|=0,n|=0;var r,s,a=0;return r=O,O=O+16|0,i[(a=r)>>2]=0,!0&268435456==(2013265920&t)?(s=0|en(0|e,0|t,56),T(),a=0|D(e,-2130706433&t|134217728,7&s,a,n),O=r,0|a):(O=r,0|(a=6))},_getDirectedEdgeOrigin:function(e,t,n){return e|=0,n|=0,!0&268435456==(2013265920&(t|=0))?(i[n>>2]=e,i[n+4>>2]=-2130706433&t|134217728,0|(n=0)):0|(n=6)},_getHexagonAreaAvgKm2:ot,_getHexagonAreaAvgM2:function(e,t){return t|=0,(e|=0)>>>0>15?0|(t=4):(s[t>>3]=+s[20784+(e<<3)>>3],0|(t=0))},_getHexagonEdgeLengthAvgKm:function(e,t){return t|=0,(e|=0)>>>0>15?0|(t=4):(s[t>>3]=+s[20912+(e<<3)>>3],0|(t=0))},_getHexagonEdgeLengthAvgM:function(e,t){return t|=0,(e|=0)>>>0>15?0|(t=4):(s[t>>3]=+s[21040+(e<<3)>>3],0|(t=0))},_getIcosahedronFaces:function e(t,n,r){r|=0;var s,a=0,o=0,c=0,A=0,l=0,f=0,u=0,d=0;s=O,O=O+128|0,u=s+112|0,c=s+96|0,d=s,o=0|en(0|(t|=0),0|(n|=0),52),T(),l=15&o,i[u>>2]=l,A=0|en(0|t,0|n,45),T(),A&=127;e:do{if(0|L(A)){if(0|l)for(a=1;;){if(!(!((f=0|tn(7,0,3*(15-a|0)|0))&t)&!((0|T())&n))){o=0;break e}if(!(a>>>0<l>>>0))break;a=a+1|0}if(!(1&o))return f=0|tn(l+1|0,0,52),d=T()|-15728641&n,d=0|e((f|t)&~(u=0|tn(7,0,3*(14-l|0)|0)),d&~T(),r),O=s,0|d;o=1}else o=0}while(0);if(!(a=0|We(t,n,c))){o?(Pe(c,u,d),f=5):(Re(c,u,d),f=6);e:do{if(0|L(A))if(l)for(a=1;;){if(!(!((A=0|tn(7,0,3*(15-a|0)|0))&t)&!((0|T())&n))){t=2;break e}if(!(a>>>0<l>>>0)){t=5;break}a=a+1|0}else t=5;else t=2}while(0);cn(0|r,-1,t<<2);e:do{if(o)for(c=0;;){if(Ne(A=d+(c<<4)|0,0|i[u>>2]),A=0|i[A>>2],-1==(0|(l=0|i[r>>2]))|(0|l)==(0|A))a=r;else{o=0;do{if((o=o+1|0)>>>0>=t>>>0){a=1;break e}l=0|i[(a=r+(o<<2)|0)>>2]}while(!(-1==(0|l)|(0|l)==(0|A)))}if(i[a>>2]=A,(c=c+1|0)>>>0>=f>>>0){a=0;break}}else for(c=0;;){if(Ce(A=d+(c<<4)|0,0|i[u>>2],0,1),A=0|i[A>>2],-1==(0|(l=0|i[r>>2]))|(0|l)==(0|A))a=r;else{o=0;do{if((o=o+1|0)>>>0>=t>>>0){a=1;break e}l=0|i[(a=r+(o<<2)|0)>>2]}while(!(-1==(0|l)|(0|l)==(0|A)))}if(i[a>>2]=A,(c=c+1|0)>>>0>=f>>>0){a=0;break}}}while(0)}return O=s,0|a},_getNumCells:ct,_getPentagons:Xe,_getRes0Cells:function(e){e|=0;var t=0,n=0,r=0;t=0;do{tn(0|t,0,45),r=134225919|T(),i[(n=e+(t<<3)|0)>>2]=-1,i[n+4>>2]=r,t=t+1|0}while(122!=(0|t));return 0},_getResolution:function(e,t){return t=0|en(0|(e|=0),0|(t|=0),52),T(),15&t},_greatCircleDistanceKm:at,_greatCircleDistanceM:function(e,t){e|=0;var n,r,i,a=0;return r=+s[(t|=0)>>3],n=+s[e>>3],a=(i=+d(.5*(r-n)))*i+(a=+d(.5*(+s[t+8>>3]-+s[e+8>>3])))*(+u(+r)*+u(+n)*a),2*+g(+ +l(+a),+ +l(+(1-a)))*6371.007180918475*1e3},_greatCircleDistanceRads:function(e,t){e|=0;var n,r,i,a=0;return r=+s[(t|=0)>>3],n=+s[e>>3],a=(i=+d(.5*(r-n)))*i+(a=+d(.5*(+s[t+8>>3]-+s[e+8>>3])))*(+u(+r)*+u(+n)*a),2*+g(+ +l(+a),+ +l(+(1-a)))},_gridDisk:R,_gridDiskDistances:B,_gridDistance:function(e,t,n,r,s){n|=0,r|=0,s|=0;var a,o,c=0,A=0;return o=O,O=O+32|0,A=o,0|(a=0|pt(e|=0,t|=0,e,t,c=o+12|0))?(O=o,0|(A=a)):0|(e=0|pt(e,t,n,r,A))?(O=o,0|(A=e)):(c=0|Ee(c,A),i[(A=s)>>2]=c,i[A+4>>2]=((0|c)<0)<<31>>31,O=o,0|(A=0))},_gridPathCells:function(e,t,n,r,s){n|=0,r|=0,s|=0;var a,o,c=0,l=0,f=0,u=0,d=0,h=0,p=0,m=0,y=0,g=0,b=0,w=0,v=0,_=0,E=0,k=0,x=0,I=0;if(o=O,O=O+48|0,l=o+12|0,x=o,!(c=0|pt(e|=0,t|=0,e,t,a=o+24|0))&&!(c=0|pt(e,t,n,r,l))){k=((0|(E=0|Ee(a,l)))<0)<<31>>31,i[a>>2]=0,i[a+4>>2]=0,i[a+8>>2]=0,i[l>>2]=0,i[l+4>>2]=0,i[l+8>>2]=0,0|pt(e,t,e,t,a)&&S(27795,27538,692,27747),0|pt(e,t,n,r,l)&&S(27795,27538,697,27747),ke(a),ke(l),h=0|E?1/+(0|E):0,n=0|i[a>>2],b=h*+((0|i[l>>2])-n|0),r=0|i[(w=a+4|0)>>2],v=h*+((0|i[l+4>>2])-r|0),c=0|i[(_=a+8|0)>>2],h*=+((0|i[l+8>>2])-c|0),i[x>>2]=n,i[(p=x+4|0)>>2]=r,i[(m=x+8|0)>>2]=c;e:do{if((0|E)<0)c=0;else for(y=0,g=0;;){I=b*(u=+(g>>>0)+4294967296*+(0|y))+ +(0|n),f=v*u+ +(0|r),u=h*u+ +(0|c),n=~~+an(+I),l=~~+an(+f),c=~~+an(+u),I=+A(+(+(0|n)-I)),f=+A(+(+(0|l)-f)),u=+A(+(+(0|c)-u));do{if(!(I>f&I>u)){if(d=0-n|0,f>u){r=d-c|0;break}r=l,c=d-l|0;break}n=0-(l+c)|0,r=l}while(0);if(i[x>>2]=n,i[p>>2]=r,i[m>>2]=c,Te(x),0|(c=0|mt(e,t,x,s+(g<<3)|0)))break e;if(!((0|y)<(0|k)|(0|y)==(0|k)&g>>>0<E>>>0)){c=0;break e}n=0|qt(0|g,0|y,1,0),y=r=0|T(),g=n,n=0|i[a>>2],r=0|i[w>>2],c=0|i[_>>2]}}while(0);return O=o,0|c}return O=o,0|c},_gridPathCellsSize:function(e,t,n,r,s){n|=0,r|=0,s|=0;var a,o=0,c=0,A=0;return a=O,O=O+32|0,A=a,(o=0|pt(e|=0,t|=0,e,t,c=a+12|0))||(o=0|pt(e,t,n,r,A))?(O=a,0|(A=o)):(r=0|qt(0|(r=0|Ee(c,A)),((0|r)<0)<<31>>31,1,0),c=0|T(),i[(A=s)>>2]=r,i[A+4>>2]=c,O=a,0|(A=0))},_gridRing:function(e,t,n,r){return 0|F(e|=0,t|=0,n|=0,r|=0)?(cn(0|r,0,48*n|0),0|(r=0|function(e,t,n,r){e|=0,t|=0,r|=0;var s,a=0,o=0,c=0,A=0,l=0,f=0,u=0,d=0;if(s=O,O=O+16|0,c=s,!(n|=0))return i[r>>2]=e,i[r+4>>2]=t,O=s,0;do{if((0|n)>=0){if((0|n)>13780509){if(0|(a=0|ct(15,c)))break;a=0|i[(o=c)>>2],o=0|i[o+4>>2]}else u=0|Wt(0|n,0|(a=((0|n)<0)<<31>>31),3,0),o=0|T(),a=0|qt(0|n,0|a,1,0),a=0|qt(0|(a=0|Wt(0|u,0|o,0|a,0|T())),0|T(),1,0),o=0|T(),i[(u=c)>>2]=a,i[u+4>>2]=o;if(f=0|zt(a,8)){if(!(u=0|zt(a,4))){Ht(f),a=13;break}if(0|(a=0|$(e,t,n,f,u,a,o,0))){Ht(f),Ht(u);break}if(t=0|i[c>>2],(0|(c=0|i[c+4>>2]))>0|!(0|c)&t>>>0>0){a=0,A=0,l=0;do{!(0|(o=0|i[(e=f+(A<<3)|0)>>2]))&!(0|(e=0|i[e+4>>2]))||(0|i[u+(A<<2)>>2])!=(0|n)||(i[(d=r+(a<<3)|0)>>2]=o,i[d+4>>2]=e,a=a+1|0),A=0|qt(0|A,0|l,1,0),l=0|T()}while((0|l)<(0|c)|(0|l)==(0|c)&A>>>0<t>>>0)}Ht(f),Ht(u),a=0}else a=13}else a=2}while(0);return O=s,0|a}(e,t,n,r))):0|(r=0)},_gridRingUnsafe:F,_i64Add:qt,_i64Subtract:Qt,_isPentagon:Ge,_isResClassIII:function(e,t){return t=0|en(0|(e|=0),0|(t|=0),52),T(),1&t},_isValidCell:Me,_isValidDirectedEdge:function(e,t){var n=0;switch(n=0|en(0|(e|=0),0|(t|=0),56),T(),7&n){case 0:case 7:return 0}return n=-2130706433&t|134217728,!0&268435456==(2013265920&t)?!0&16777216==(117440512&t)&!!(0|Ge(e,n))?0|(n=0):0|(n=0|Me(e,n)):0|(n=0)},_isValidVertex:function(e,t){e|=0;var n,r,s=0,a=0;return r=O,O=O+16|0,n=r,!0&536870912==(2013265920&(t|=0))&&0|Me(e,s=-2130706433&t|134217728)?(a=0|en(0|e,0|t,56),T(),s=(a=!(0|Rt(e,s,7&a,n)))&((0|i[(s=n)>>2])==(0|e)?(0|i[s+4>>2])==(0|t):0)&1,O=r,0|s):(O=r,0|(s=0))},_latLngToCell:Je,_llvm_ctlz_i64:nn,_llvm_maxnum_f64:rn,_llvm_minnum_f64:sn,_llvm_round_f64:an,_localIjToCell:function(e,t,n,r,s){var a,o;return e|=0,t|=0,n|=0,s|=0,o=O,O=O+16|0,a=o,(r|=0)?n=15:(n=0|function(e,t){t|=0;var n,r,s,a=0,o=0,c=0;if(o=0|i[(e|=0)>>2],i[t>>2]=o,c=0|i[e+4>>2],i[(r=t+4|0)>>2]=c,i[(s=t+8|0)>>2]=0,e=(a=(0|c)<(0|o))?o:c,(0|(a=a?c:o))<0){if(-2147483648==(0|a)||((0|e)>0?(2147483647-e|0)<(0|a):(-2147483648-e|0)>(0|a)))return 1;if((0|e)>-1?(-2147483648|e)>=(0|a):(-2147483648^e)<(0|a))return 1}return e=c-o|0,(0|o)<0?(a=0-o|0,i[r>>2]=e,i[s>>2]=a,i[t>>2]=0,o=0):(e=c,a=0),(0|e)<0&&(o=o-e|0,i[t>>2]=o,a=a-e|0,i[s>>2]=a,i[r>>2]=0,e=0),n=o-a|0,c=e-a|0,(0|a)<0?(i[t>>2]=n,i[r>>2]=c,i[s>>2]=0,e=c,c=n,a=0):c=o,(0|(o=(0|a)<(0|(o=(0|e)<(0|c)?e:c))?a:o))<=0||(i[t>>2]=c-o,i[r>>2]=e-o,i[s>>2]=a-o),0}(n,a))||(n=0|mt(e,t,a,s)),O=o,0|n},_malloc:jt,_maxFaceCount:function(e,t,n){n|=0;var r=0,s=0;if(s=0|en(0|(e|=0),0|(t|=0),45),T(),!(0|L(127&s)))return s=2,i[n>>2]=s,0;if(s=0|en(0|e,0|t,52),T(),!(s&=15))return s=5,i[n>>2]=s,0;for(r=1;;){if(!(!((0|tn(7,0,3*(15-r|0)|0))&e)&!((0|T())&t))){r=2,e=6;break}if(!(r>>>0<s>>>0)){r=5,e=6;break}r=r+1|0}return 6==(0|e)?(i[n>>2]=r,0):0},_maxGridDiskSize:function(e,t){t|=0;var n=0,r=0,s=0;return(0|(e|=0))<0?0|(t=2):(0|e)>13780509?0|(t=0|ct(15,t)):(s=0|Wt(0|e,0|(n=((0|e)<0)<<31>>31),3,0),r=0|T(),n=0|qt(0|e,0|n,1,0),n=0|qt(0|(n=0|Wt(0|s,0|r,0|n,0|T())),0|T(),1,0),e=0|T(),i[t>>2]=n,i[t+4>>2]=e,0|(t=0))},_maxPolygonToCellsSize:function(e,t,n,r){e|=0,t|=0,r|=0;var s,a=0,o=0,c=0,A=0,l=0;if(s=O,O=O+48|0,a=s+16|0,o=s+8|0,c=s,0|(n=0|Et(n|=0)))return O=s,0|n;if(A=0|i[(l=e)+4>>2],i[(n=o)>>2]=i[l>>2],i[n+4>>2]=A,_t(o,a),!(n=0|te(a,t,c))){if(t=0|i[o>>2],(0|(o=0|i[e+8>>2]))>0){a=0|i[e+12>>2],n=0;do{t=(0|i[a+(n<<3)>>2])+t|0,n=n+1|0}while((0|n)<(0|o))}a=0|i[(n=c)>>2],(0|(n=0|i[n+4>>2]))<(0|(o=((0|t)<0)<<31>>31))|(0|n)==(0|o)&a>>>0<t>>>0?(i[(n=c)>>2]=t,i[n+4>>2]=o,n=o):t=a,A=0|qt(0|t,0|n,12,0),l=0|T(),i[(n=c)>>2]=A,i[n+4>>2]=l,i[(n=r)>>2]=A,i[n+4>>2]=l,n=0}return O=s,0|n},_maxPolygonToCellsSizeExperimental:function(e,t,n,a){t|=0,n|=0,a|=0;var o,c,l=0,f=0,d=0,h=0,p=0,m=0,y=0,g=0;if(c=O,O=O+48|0,p=c+32|0,h=c+40|0,o=c,!(0|i[(e|=0)>>2]))return i[(m=a)>>2]=0,i[m+4>>2]=0,O=c,0;$e(p,0,0,0),l=0|i[(d=p)>>2],d=0|i[d+4>>2];do{if(t>>>0>15)i[(m=o)>>2]=0,i[m+4>>2]=0,i[o+8>>2]=4,i[o+12>>2]=-1,n=o+29|0,i[(m=o+16|0)>>2]=0,i[m+4>>2]=0,i[m+8>>2]=0,r[m+12|0]=0,r[0|n]=0|r[0|h],r[n+1|0]=0|r[h+1|0],r[n+2|0]=0|r[h+2|0],n=4,m=9;else{if(0|(n=0|Et(n))){i[(p=o)>>2]=0,i[p+4>>2]=0,i[o+8>>2]=n,i[o+12>>2]=-1,m=o+29|0,i[(p=o+16|0)>>2]=0,i[p+4>>2]=0,i[p+8>>2]=0,r[p+12|0]=0,r[0|m]=0|r[0|h],r[m+1|0]=0|r[h+1|0],r[m+2|0]=0|r[h+2|0],m=9;break}if(!(n=0|zt(1+(0|i[e+8>>2])|0,32))){i[(m=o)>>2]=0,i[m+4>>2]=0,i[o+8>>2]=13,i[o+12>>2]=-1,n=o+29|0,i[(m=o+16|0)>>2]=0,i[m+4>>2]=0,i[m+8>>2]=0,r[m+12|0]=0,r[0|n]=0|r[0|h],r[n+1|0]=0|r[h+1|0],r[n+2|0]=0|r[h+2|0],n=13,m=9;break}kt(e,n),i[(g=o)>>2]=l,i[g+4>>2]=d,i[(d=o+8|0)>>2]=0,i[o+12>>2]=t,i[o+20>>2]=e,i[o+24>>2]=n,r[o+28|0]=0,r[0|(l=o+29|0)]=0|r[0|h],r[l+1|0]=0|r[h+1|0],r[l+2|0]=0|r[h+2|0],i[o+16>>2]=3,y=+W(n),y*=+J(n),f=+A(+ +s[n>>3]),f=y/+u(+ +sn(+f,+ +A(+ +s[n+8>>3])))*6371.007180918475*6371.007180918475,n=0|i[(l=o+12|0)>>2];e:do{if((0|n)>0)do{if(ot(n+-1|0,p),!(f/+s[p>>3]>10))break e;n=(g=0|i[l>>2])-1|0,i[l>>2]=n}while((0|g)>1)}while(0);if(bt(o),i[(l=a)>>2]=0,i[l+4>>2]=0,!(!(0|(n=0|i[(l=o)>>2]))&!(0|(l=0|i[l+4>>2]))))do{Fe(n,l,t,p),h=p,h=0|qt(0|i[(e=a)>>2],0|i[e+4>>2],0|i[h>>2],0|i[h+4>>2]),e=0|T(),i[(g=a)>>2]=h,i[g+4>>2]=e,bt(o),n=0|i[(g=o)>>2],l=0|i[g+4>>2]}while(!(!(0|n)&!(0|l)));n=0|i[d>>2]}}while(0);return O=c,0|n},_memcpy:on,_memset:cn,_originToDirectedEdges:function(e,t,n){n|=0;var r,s=0;return r=!(0|Ge(e|=0,t|=0)),t&=-2130706433,i[(s=n)>>2]=r?e:0,i[s+4>>2]=r?285212672|t:0,i[(s=n+8|0)>>2]=e,i[s+4>>2]=301989888|t,i[(s=n+16|0)>>2]=e,i[s+4>>2]=318767104|t,i[(s=n+24|0)>>2]=e,i[s+4>>2]=335544320|t,i[(s=n+32|0)>>2]=e,i[s+4>>2]=352321536|t,i[(n=n+40|0)>>2]=e,i[n+4>>2]=369098752|t,0},_pentagonCount:function(){return 12},_polygonToCells:function(e,t,n,r){e|=0,t|=0,r|=0;var s,a,o,c,A=0,l=0,f=0,u=0,d=0,h=0,p=0,m=0,y=0,g=0,b=0,w=0,v=0,_=0,E=0,k=0,S=0,x=0,I=0,P=0,C=0,N=0,R=0,B=0,D=0,F=0,G=0;if(c=O,O=O+112|0,s=c+80|0,d=c+72|0,a=c,o=c+56|0,0|(A=0|Et(n|=0)))return O=c,0|A;if(!(G=0|jt(32+(i[(h=e+8|0)>>2]<<5)|0)))return O=c,13;if(kt(e,G),!(A=0|Et(n))){if(F=0|i[(D=e)+4>>2],i[(A=d)>>2]=i[D>>2],i[A+4>>2]=F,_t(d,s),A=0|te(s,t,a))D=0,F=0;else{if(A=0|i[d>>2],(0|(l=0|i[h>>2]))>0){f=0|i[e+12>>2],n=0;do{A=(0|i[f+(n<<3)>>2])+A|0,n=n+1|0}while((0|n)!=(0|l));n=A}else n=A;l=0|i[(A=a)>>2],(0|(A=0|i[A+4>>2]))<(0|(f=((0|n)<0)<<31>>31))|(0|A)==(0|f)&l>>>0<n>>>0?(i[(A=a)>>2]=n,i[A+4>>2]=f,A=f):n=l,D=0|qt(0|n,0|A,12,0),F=0|T(),i[(A=a)>>2]=D,i[A+4>>2]=F,A=0}if(!A){if(!(n=0|zt(D,8)))return Ht(G),O=c,13;if(!(u=0|zt(D,8)))return Ht(G),Ht(n),O=c,13;i[(R=s)>>2]=0,i[R+4>>2]=0,B=0|i[(R=e)+4>>2],i[(A=d)>>2]=i[R>>2],i[A+4>>2]=B,A=0|U(d,D,F,t,s,n,u);e:do{if(A)Ht(n),Ht(u),Ht(G);else{t:do{if((0|i[h>>2])>0){for(f=e+12|0,l=0;A=0|U((0|i[f>>2])+(l<<3)|0,D,F,t,s,n,u),l=l+1|0,!(0|A);)if((0|l)>=(0|i[h>>2]))break t;Ht(n),Ht(u),Ht(G);break e}}while(0);(0|F)>0|!(0|F)&D>>>0>0&&cn(0|u,0,D<<3),R=0|i[(B=s)+4>>2];t:do{if((0|R)>0|!(0|R)&(0|i[B>>2])>>>0>0){P=n,C=u,N=n,R=u,B=n,A=n,S=n,x=u,I=u,n=u;n:for(;;){for(v=0,_=0,E=0,k=0,l=0,f=0;;){d=(u=a)+56|0;do{i[u>>2]=0,u=u+4|0}while((0|u)<(0|d));if(0|M(h=0|i[(t=P+(v<<3)|0)>>2],t=0|i[t+4>>2],1,a,0)){d=(u=a)+56|0;do{i[u>>2]=0,u=u+4|0}while((0|u)<(0|d));0|(u=0|zt(7,4))&&($(h,t,1,a,u,7,0,0),Ht(u))}for(w=0;;){g=0|i[(b=a+(w<<3)|0)>>2],b=0|i[b+4>>2];r:do{if(!(0|g)&!(0|b))u=l,d=f;else{if(p=0|Zt(0|g,0|b,0|D,0|F),h=0|T(),!(!(0|(d=0|i[(t=u=r+(p<<3)|0)>>2]))&!(0|(t=0|i[t+4>>2])))){m=0,y=0;do{if((0|m)>(0|F)|(0|m)==(0|F)&y>>>0>D>>>0)break n;if((0|d)==(0|g)&(0|t)==(0|b)){u=l,d=f;break r}p=0|Yt(0|(u=0|qt(0|p,0|h,1,0)),0|T(),0|D,0|F),h=0|T(),y=0|qt(0|y,0|m,1,0),m=0|T(),d=0|i[(t=u=r+(p<<3)|0)>>2],t=0|i[t+4>>2]}while(!(!(0|d)&!(0|t)))}if(!(0|g)&!(0|b)){u=l,d=f;break}Ye(g,b,o),0|Tt(e,G,o)&&(y=0|qt(0|l,0|f,1,0),f=0|T(),i[(m=u)>>2]=g,i[m+4>>2]=b,i[(l=C+(l<<3)|0)>>2]=g,i[l+4>>2]=b,l=y),u=l,d=f}}while(0);if((w=w+1|0)>>>0>=7)break;l=u,f=d}if(v=0|qt(0|v,0|_,1,0),_=0|T(),E=0|qt(0|E,0|k,1,0),k=0|T(),l=0|i[(f=s)>>2],!((0|k)<(0|(f=0|i[f+4>>2]))|(0|k)==(0|f)&E>>>0<l>>>0))break;l=u,f=d}if((0|f)>0|!(0|f)&l>>>0>0){l=0,f=0;do{i[(k=P+(l<<3)|0)>>2]=0,i[k+4>>2]=0,l=0|qt(0|l,0|f,1,0),f=0|T(),E=0|i[(k=s)+4>>2]}while((0|f)<(0|E)|((0|f)==(0|E)?l>>>0<(0|i[k>>2])>>>0:0))}if(i[(k=s)>>2]=u,i[k+4>>2]=d,!((0|d)>0|!(0|d)&u>>>0>0))break t;w=n,v=I,_=B,E=x,k=C,n=S,I=A,x=N,S=w,A=v,B=R,R=_,N=E,C=P,P=k}Ht(N),Ht(R),Ht(G),A=1;break e}A=u}while(0);Ht(G),Ht(n),Ht(A),A=0}}while(0);return O=c,0|A}}return Ht(G),O=c,0|A},_polygonToCellsExperimental:function(e,t,n,s,a,o){s|=0,a|=0,o|=0;var c,A,l,f=0,u=0,d=0,h=0,p=0,m=0,y=0,g=0;l=O,O=O+160|0,u=l+64|0,p=l+112|0,g=l,function(e,t,n,s){e|=0,t|=0,n|=0,s|=0;var a,o,c,A=0,l=0,f=0,u=0;c=O,O=O+48|0,a=c+40|0,o=c,$e(l=c+32|0,0,0,0),f=0|i[l>>2],l=0|i[l+4>>2];do{if(n>>>0<=15){if(0|(A=0|Et(s))){i[(s=o)>>2]=0,i[s+4>>2]=0,i[o+8>>2]=A,i[o+12>>2]=-1,f=o+29|0,i[(s=o+16|0)>>2]=0,i[s+4>>2]=0,i[s+8>>2]=0,r[s+12|0]=0,r[0|f]=0|r[0|a],r[f+1|0]=0|r[a+1|0],r[f+2|0]=0|r[a+2|0];break}if(A=0|zt(1+(0|i[t+8>>2])|0,32)){kt(t,A),i[(u=o)>>2]=f,i[u+4>>2]=l,i[o+8>>2]=0,i[o+12>>2]=n,i[o+16>>2]=s,i[o+20>>2]=t,i[o+24>>2]=A,r[o+28|0]=0,r[0|(f=o+29|0)]=0|r[0|a],r[f+1|0]=0|r[a+1|0],r[f+2|0]=0|r[a+2|0];break}i[(s=o)>>2]=0,i[s+4>>2]=0,i[o+8>>2]=13,i[o+12>>2]=-1,f=o+29|0,i[(s=o+16|0)>>2]=0,i[s+4>>2]=0,i[s+8>>2]=0,r[s+12|0]=0,r[0|f]=0|r[0|a],r[f+1|0]=0|r[a+1|0],r[f+2|0]=0|r[a+2|0];break}i[(f=o)>>2]=0,i[f+4>>2]=0,i[o+8>>2]=4,i[o+12>>2]=-1,u=o+29|0,i[(f=o+16|0)>>2]=0,i[f+4>>2]=0,i[f+8>>2]=0,r[f+12|0]=0,r[0|u]=0|r[0|a],r[u+1|0]=0|r[a+1|0],r[u+2|0]=0|r[a+2|0]}while(0);bt(o),i[e>>2]=i[o>>2],i[e+4>>2]=i[o+4>>2],i[e+8>>2]=i[o+8>>2],i[e+12>>2]=i[o+12>>2],i[e+16>>2]=i[o+16>>2],i[e+20>>2]=i[o+20>>2],i[e+24>>2]=i[o+24>>2],i[e+28>>2]=i[o+28>>2],O=c}(h=l+80|0,e|=0,t|=0,n|=0),et(u,0|i[(d=h)>>2],0|i[d+4>>2],t),c=0|i[(d=u)>>2],d=0|i[d+4>>2],f=0|i[h+8>>2],i[(m=p+4|0)>>2]=i[h>>2],i[m+4>>2]=i[h+4>>2],i[m+8>>2]=i[h+8>>2],i[m+12>>2]=i[h+12>>2],i[m+16>>2]=i[h+16>>2],i[m+20>>2]=i[h+20>>2],i[m+24>>2]=i[h+24>>2],i[m+28>>2]=i[h+28>>2],i[(m=g)>>2]=c,i[m+4>>2]=d,i[(m=g+8|0)>>2]=f,t=p,n=36+(e=g+12|0)|0;do{i[e>>2]=i[t>>2],e=e+4|0,t=t+4|0}while((0|e)<(0|n));if(i[(p=g+48|0)>>2]=i[u>>2],i[p+4>>2]=i[u+4>>2],i[p+8>>2]=i[u+8>>2],i[p+12>>2]=i[u+12>>2],!(0|c)&!(0|d))return O=l,0|f;n=g+16|0,A=g+24|0,h=g+28|0,f=0,u=0,t=c,e=d;do{if(!((0|f)<(0|a)|(0|f)==(0|a)&u>>>0<s>>>0)){y=4;break}if(d=u,u=0|qt(0|u,0|f,1,0),f=0|T(),i[(d=o+(d<<3)|0)>>2]=t,i[d+4>>2]=e,nt(p),!(0|(t=0|i[(e=p)>>2]))&!(0|(e=0|i[e+4>>2]))){if(bt(n),!(0|(e=0|i[(t=n)>>2]))&!(0|(t=0|i[t+4>>2]))){y=10;break}tt(e,t,0|i[h>>2],p),t=0|i[(e=p)>>2],e=0|i[e+4>>2]}i[(d=g)>>2]=t,i[d+4>>2]=e}while(!(!(0|t)&!(0|e)));return 4==(0|y)?(0|(t=0|i[(e=g+40|0)>>2])&&Ht(t),i[(y=g+16|0)>>2]=0,i[y+4>>2]=0,i[A>>2]=0,i[g+36>>2]=0,i[h>>2]=-1,i[g+32>>2]=0,i[e>>2]=0,tt(0,0,0,p),i[g>>2]=0,i[g+4>>2]=0,i[m>>2]=0,O=l,0|(g=14)):(10==(0|y)&&(i[g>>2]=0,i[g+4>>2]=0,i[m>>2]=i[A>>2]),g=0|i[m>>2],O=l,0|g)},_readInt64AsDoubleFromPointer:function(e){return+(+((0|i[(e|=0)>>2])>>>0)+4294967296*+(0|i[e+4>>2]))},_res0CellCount:function(){return 122},_round:An,_sbrk:ln,_sizeOfCellBoundary:function(){return 168},_sizeOfCoordIJ:function(){return 8},_sizeOfGeoLoop:function(){return 8},_sizeOfGeoPolygon:function(){return 16},_sizeOfH3Index:function(){return 8},_sizeOfLatLng:function(){return 16},_sizeOfLinkedGeoPolygon:function(){return 12},_uncompactCells:function(e,t,n,r,s,a,o){e|=0,r|=0,s|=0,a|=0;var c,A=0,l=0,f=0,u=0,d=0,h=0,p=0,m=0;if(c=O,O=O+16|0,m=c,!((0|(n|=0))>0|!(0|n)&(t|=0)>>>0>0))return O=c,0;if((0|(o|=0))>=16)return O=c,12;h=0,p=0,d=0,A=0;e:for(;;){if(u=0|en(0|(l=0|i[(f=e+(h<<3)|0)>>2]),0|(f=0|i[f+4>>2]),52),T(),(15&u)>(0|o)){A=12,l=11;break}if(et(m,l,f,o),!(0|(f=0|i[(u=m)>>2]))&!(0|(u=0|i[u+4>>2])))l=d;else{l=d;do{if(!((0|A)<(0|a)|(0|A)==(0|a)&l>>>0<s>>>0)){l=10;break e}i[(d=r+(l<<3)|0)>>2]=f,i[d+4>>2]=u,l=0|qt(0|l,0|A,1,0),A=0|T(),nt(m),f=0|i[(d=m)>>2],u=0|i[d+4>>2]}while(!(!(0|f)&!(0|u)))}if(h=0|qt(0|h,0|p,1,0),!((0|(p=0|T()))<(0|n)|(0|p)==(0|n)&h>>>0<t>>>0)){A=0,l=11;break}d=l}return 10==(0|l)?(O=c,0|(m=14)):11==(0|l)?(O=c,0|A):0},_uncompactCellsSize:function(e,t,n,r,s){e|=0,t|=0,n|=0,r|=0,s|=0;var a,o,c=0,A=0,l=0,f=0,u=0,d=0;o=O,O=O+16|0,a=o;e:do{if((0|n)>0|!(0|n)&t>>>0>0){for(u=0,A=0,c=0,d=0;;){if(!(!(0|(l=0|i[(f=e+(u<<3)|0)>>2]))&!(0|(f=0|i[f+4>>2]))||(f=!(0|Fe(l,f,r,a)),A=0|qt(0|i[(l=a)>>2],0|i[l+4>>2],0|A,0|c),c=0|T(),f))){c=12;break}if(u=0|qt(0|u,0|d,1,0),!((0|(d=0|T()))<(0|n)|(0|d)==(0|n)&u>>>0<t>>>0))break e}return O=o,0|c}A=0,c=0}while(0);return i[s>>2]=A,i[s+4>>2]=c,O=o,0},_vertexToLatLng:function(e,t,n){n|=0;var r,s,a,o,c=0,A=0;return o=O,O=O+192|0,s=o,a=o+168|0,c=0|en(0|(e|=0),0|(t|=0),56),T(),c&=7,0|(r=0|We(e,A=-2130706433&t|134217728,a))?(O=o,0|(A=r)):(t=0|en(0|e,0|t,52),T(),t&=15,0|Ge(e,A)?Ie(a,t,c,1,s):Oe(a,t,c,1,s),A=s+8|0,i[n>>2]=i[A>>2],i[n+4>>2]=i[A+4>>2],i[n+8>>2]=i[A+8>>2],i[n+12>>2]=i[A+12>>2],O=o,0|(A=0))},establishStackSpace:function(e,t){O=e|=0},stackAlloc:function(e){var t;return t=O,O=15+(O=O+(e|=0)|0)&-16,0|t},stackRestore:function(e){O=e|=0},stackSave:function(){return 0|O}}}({Math:Math,Int8Array:Int8Array,Int32Array:Int32Array,Uint8Array:Uint8Array,Float32Array:Float32Array,Float64Array:Float64Array},{b:function(e){c=e},c:function(){return c},d:function(e,t,n,r){ne("Assertion failed: "+b(e)+", at: "+[t?b(t):"unknown filename",n,r?b(r):"unknown function"])},e:function(e){return n.___errno_location&&(p[n.___errno_location()>>2]=e),e},f:L,g:function(e,t,n){d.set(d.subarray(t,t+n),e)},h:function(e){var t=L(),n=16777216,r=2130706432;if(e>r)return!1;for(var i=Math.max(t,16777216);i<e;)i=i<=536870912?w(2*i,n):Math.min(w((3*i+2147483648)/4,n),r);return!!function(e){try{var t=new ArrayBuffer(e);if(t.byteLength!=e)return;return new Int8Array(t).set(u),q(t),v(t),1}catch(n){}}(i)},i:function(e){ne("OOM")},o:28624,p:28608},f);n.___divdi3=z.___divdi3,n.___muldi3=z.___muldi3,n.___remdi3=z.___remdi3,n.___uremdi3=z.___uremdi3,n._areNeighborCells=z._areNeighborCells,n._bitshift64Ashr=z._bitshift64Ashr,n._bitshift64Lshr=z._bitshift64Lshr,n._bitshift64Shl=z._bitshift64Shl,n._calloc=z._calloc,n._cellAreaKm2=z._cellAreaKm2,n._cellAreaM2=z._cellAreaM2,n._cellAreaRads2=z._cellAreaRads2,n._cellToBoundary=z._cellToBoundary,n._cellToCenterChild=z._cellToCenterChild,n._cellToChildPos=z._cellToChildPos,n._cellToChildren=z._cellToChildren,n._cellToChildrenSize=z._cellToChildrenSize,n._cellToLatLng=z._cellToLatLng,n._cellToLocalIj=z._cellToLocalIj,n._cellToParent=z._cellToParent,n._cellToVertex=z._cellToVertex,n._cellToVertexes=z._cellToVertexes,n._cellsToDirectedEdge=z._cellsToDirectedEdge,n._cellsToLinkedMultiPolygon=z._cellsToLinkedMultiPolygon,n._childPosToCell=z._childPosToCell,n._compactCells=z._compactCells,n._destroyLinkedMultiPolygon=z._destroyLinkedMultiPolygon,n._directedEdgeToBoundary=z._directedEdgeToBoundary,n._directedEdgeToCells=z._directedEdgeToCells,n._edgeLengthKm=z._edgeLengthKm,n._edgeLengthM=z._edgeLengthM,n._edgeLengthRads=z._edgeLengthRads;var q=n._emscripten_replace_memory=z._emscripten_replace_memory;n._free=z._free,n._getBaseCellNumber=z._getBaseCellNumber,n._getDirectedEdgeDestination=z._getDirectedEdgeDestination,n._getDirectedEdgeOrigin=z._getDirectedEdgeOrigin,n._getHexagonAreaAvgKm2=z._getHexagonAreaAvgKm2,n._getHexagonAreaAvgM2=z._getHexagonAreaAvgM2,n._getHexagonEdgeLengthAvgKm=z._getHexagonEdgeLengthAvgKm,n._getHexagonEdgeLengthAvgM=z._getHexagonEdgeLengthAvgM,n._getIcosahedronFaces=z._getIcosahedronFaces,n._getNumCells=z._getNumCells,n._getPentagons=z._getPentagons,n._getRes0Cells=z._getRes0Cells,n._getResolution=z._getResolution,n._greatCircleDistanceKm=z._greatCircleDistanceKm,n._greatCircleDistanceM=z._greatCircleDistanceM,n._greatCircleDistanceRads=z._greatCircleDistanceRads,n._gridDisk=z._gridDisk,n._gridDiskDistances=z._gridDiskDistances,n._gridDistance=z._gridDistance,n._gridPathCells=z._gridPathCells,n._gridPathCellsSize=z._gridPathCellsSize,n._gridRing=z._gridRing,n._gridRingUnsafe=z._gridRingUnsafe,n._i64Add=z._i64Add,n._i64Subtract=z._i64Subtract,n._isPentagon=z._isPentagon,n._isResClassIII=z._isResClassIII,n._isValidCell=z._isValidCell,n._isValidDirectedEdge=z._isValidDirectedEdge,n._isValidVertex=z._isValidVertex,n._latLngToCell=z._latLngToCell,n._llvm_ctlz_i64=z._llvm_ctlz_i64,n._llvm_maxnum_f64=z._llvm_maxnum_f64,n._llvm_minnum_f64=z._llvm_minnum_f64,n._llvm_round_f64=z._llvm_round_f64,n._localIjToCell=z._localIjToCell,n._malloc=z._malloc,n._maxFaceCount=z._maxFaceCount,n._maxGridDiskSize=z._maxGridDiskSize,n._maxPolygonToCellsSize=z._maxPolygonToCellsSize,n._maxPolygonToCellsSizeExperimental=z._maxPolygonToCellsSizeExperimental,n._memcpy=z._memcpy,n._memset=z._memset,n._originToDirectedEdges=z._originToDirectedEdges,n._pentagonCount=z._pentagonCount,n._polygonToCells=z._polygonToCells,n._polygonToCellsExperimental=z._polygonToCellsExperimental,n._readInt64AsDoubleFromPointer=z._readInt64AsDoubleFromPointer,n._res0CellCount=z._res0CellCount,n._round=z._round,n._sbrk=z._sbrk,n._sizeOfCellBoundary=z._sizeOfCellBoundary,n._sizeOfCoordIJ=z._sizeOfCoordIJ,n._sizeOfGeoLoop=z._sizeOfGeoLoop,n._sizeOfGeoPolygon=z._sizeOfGeoPolygon,n._sizeOfH3Index=z._sizeOfH3Index,n._sizeOfLatLng=z._sizeOfLatLng,n._sizeOfLinkedGeoPolygon=z._sizeOfLinkedGeoPolygon,n._uncompactCells=z._uncompactCells,n._uncompactCellsSize=z._uncompactCellsSize,n._vertexToLatLng=z._vertexToLatLng,n.establishStackSpace=z.establishStackSpace;var Q,V,J=n.stackAlloc=z.stackAlloc,K=n.stackRestore=z.stackRestore,W=n.stackSave=z.stackSave;if(n.asm=z,n.cwrap=function(e,t,n,r){var i=(n=n||[]).every(function(e){return"number"===e});return"string"!==t&&i&&!r?l(e):function(){return function(e,t,n,r){var i={string:function(e){var t=0;if(null!=e&&0!==e){var n=1+(e.length<<2);!function(e,t,n){!function(e,t,n,r){if(!(r>0))return 0;for(var i=n+r-1,s=0;s<e.length;++s){var a=e.charCodeAt(s);if(a>=55296&&a<=57343&&(a=65536+((1023&a)<<10)|1023&e.charCodeAt(++s)),a<=127){if(n>=i)break;t[n++]=a}else if(a<=2047){if(n+1>=i)break;t[n++]=192|a>>6,t[n++]=128|63&a}else if(a<=65535){if(n+2>=i)break;t[n++]=224|a>>12,t[n++]=128|a>>6&63,t[n++]=128|63&a}else{if(n+3>=i)break;t[n++]=240|a>>18,t[n++]=128|a>>12&63,t[n++]=128|a>>6&63,t[n++]=128|63&a}}t[n]=0}(e,d,t,n)}(e,t=J(n),n)}return t},array:function(e){var t,n,r=J(e.length);return t=e,n=r,u.set(t,n),r}},s=l(e),a=[],o=0;if(r)for(var c=0;c<r.length;c++){var A=i[n[c]];A?(0===o&&(o=W()),a[c]=A(r[c])):a[c]=r[c]}var f,h=s.apply(null,a);return f=h,h="string"===t?b(f):"boolean"===t?Boolean(f):f,0!==o&&K(o),h}(e,t,n,arguments)}},n.setValue=function(e,t,n,r){switch("*"===(n=n||"i8").charAt(n.length-1)&&(n="i32"),n){case"i1":case"i8":u[0|e]=t;break;case"i16":h[e>>1]=t;break;case"i32":p[e>>2]=t;break;case"i64":D=[t>>>0,($=t,+C($)>=1?$>0?(0|R(+O($/4294967296),4294967295))>>>0:~~+N(($-+(~~$>>>0))/4294967296)>>>0:0)],p[e>>2]=D[0],p[e+4>>2]=D[1];break;case"float":m[e>>2]=t;break;case"double":y[e>>3]=t;break;default:ne("invalid type for setValue: "+n)}},n.getValue=function(e,t,n){switch("*"===(t=t||"i8").charAt(t.length-1)&&(t="i32"),t){case"i1":case"i8":return u[0|e];case"i16":return h[e>>1];case"i32":case"i64":return p[e>>2];case"float":return m[e>>2];case"double":return y[e>>3];default:ne("invalid type for getValue: "+t)}return null},F){U(F)||(Q=F,F=n.locateFile?n.locateFile(Q,s):s+Q),B++,n.monitorRunDependencies&&n.monitorRunDependencies(B);var Y=function(e){e.byteLength&&(e=new Uint8Array(e)),d.set(e,8),n.memoryInitializerRequest&&delete n.memoryInitializerRequest.response,function(){if(B--,n.monitorRunDependencies&&n.monitorRunDependencies(B),0==B&&M){var e=M;M=null,e()}}()},Z=function(){i(F,Y,function(){throw"could not load memory initializer "+F})},X=H(F);if(X)Y(X.buffer);else if(n.memoryInitializerRequest){var ee=function(){var e=n.memoryInitializerRequest,t=e.response;if(200!==e.status&&0!==e.status){var r=H(n.memoryInitializerRequestURL);if(!r)return console.warn("a problem seems to have happened with Module.memoryInitializerRequest, status: "+e.status+", retrying "+F),void Z();t=r.buffer}Y(t)};n.memoryInitializerRequest.response?setTimeout(ee,0):n.memoryInitializerRequest.addEventListener("load",ee)}else Z()}function te(e){function t(){V||(V=!0,A||(E(T),E(S),n.onRuntimeInitialized&&n.onRuntimeInitialized(),function(){if(n.postRun)for("function"==typeof n.postRun&&(n.postRun=[n.postRun]);n.postRun.length;)P(n.postRun.shift());E(x)}()))}B>0||(function(){if(n.preRun)for("function"==typeof n.preRun&&(n.preRun=[n.preRun]);n.preRun.length;)I(n.preRun.shift());E(k)}(),B>0||(n.setStatus?(n.setStatus("Running..."),setTimeout(function(){setTimeout(function(){n.setStatus("")},1),t()},1)):t()))}function ne(e){throw n.onAbort&&n.onAbort(e),a(e+=""),o(e),A=!0,"abort("+e+"). Build with -s ASSERTIONS=1 for more info."}if(M=function e(){V||te(),V||(M=e)},n.run=te,n.abort=ne,n.preInit)for("function"==typeof n.preInit&&(n.preInit=[n.preInit]);n.preInit.length>0;)n.preInit.pop()();return te(),e}("object"==typeof Ef?Ef:{}),kf="number",Tf={0:"Success",1:"The operation failed but a more specific error is not available",2:"Argument was outside of acceptable range",3:"Latitude or longitude arguments were outside of acceptable range",4:"Resolution argument was outside of acceptable range",5:"Cell argument was not valid",6:"Directed edge argument was not valid",7:"Undirected edge argument was not valid",8:"Vertex argument was not valid",9:"Pentagon distortion was encountered",10:"Duplicate input",11:"Cell arguments were not neighbors",12:"Cell arguments had incompatible resolutions",13:"Memory allocation failed",14:"Bounds of provided memory were insufficient",15:"Mode or flags argument was not valid"},Sf=1e3,xf={1e3:"Unknown unit",1001:"Array length out of bounds",1002:"Got unexpected null value for H3 index"};function If(e,t,n){var r=n&&"value"in n,i=new Error((e[t]||"Unknown error")+" (code: "+t+(r?", value: "+n.value:"")+")");return i.code=t,i}function Pf(e,t){return If(Tf,e,2===arguments.length?{value:t}:{})}function Cf(e,t){return If(xf,e,2===arguments.length?{value:t}:{})}function Nf(e){if(0!==e)throw Pf(e)}var Of={};[["sizeOfH3Index",kf],["sizeOfLatLng",kf],["sizeOfCellBoundary",kf],["sizeOfGeoLoop",kf],["sizeOfGeoPolygon",kf],["sizeOfLinkedGeoPolygon",kf],["sizeOfCoordIJ",kf],["readInt64AsDoubleFromPointer",kf],["isValidCell",kf,[kf,kf]],["latLngToCell",kf,[kf,kf,kf,kf]],["cellToLatLng",kf,[kf,kf,kf]],["cellToBoundary",kf,[kf,kf,kf]],["maxGridDiskSize",kf,[kf,kf]],["gridDisk",kf,[kf,kf,kf,kf]],["gridDiskDistances",kf,[kf,kf,kf,kf,kf]],["gridRing",kf,[kf,kf,kf,kf]],["gridRingUnsafe",kf,[kf,kf,kf,kf]],["maxPolygonToCellsSize",kf,[kf,kf,kf,kf]],["polygonToCells",kf,[kf,kf,kf,kf]],["maxPolygonToCellsSizeExperimental",kf,[kf,kf,kf,kf]],["polygonToCellsExperimental",kf,[kf,kf,kf,kf,kf,kf]],["cellsToLinkedMultiPolygon",kf,[kf,kf,kf]],["destroyLinkedMultiPolygon",null,[kf]],["compactCells",kf,[kf,kf,kf,kf]],["uncompactCells",kf,[kf,kf,kf,kf,kf,kf]],["uncompactCellsSize",kf,[kf,kf,kf,kf,kf]],["isPentagon",kf,[kf,kf]],["isResClassIII",kf,[kf,kf]],["getBaseCellNumber",kf,[kf,kf]],["getResolution",kf,[kf,kf]],["maxFaceCount",kf,[kf,kf,kf]],["getIcosahedronFaces",kf,[kf,kf,kf]],["cellToParent",kf,[kf,kf,kf,kf]],["cellToChildren",kf,[kf,kf,kf,kf]],["cellToCenterChild",kf,[kf,kf,kf,kf]],["cellToChildrenSize",kf,[kf,kf,kf,kf]],["cellToChildPos",kf,[kf,kf,kf,kf]],["childPosToCell",kf,[kf,kf,kf,kf,kf,kf]],["areNeighborCells",kf,[kf,kf,kf,kf,kf]],["cellsToDirectedEdge",kf,[kf,kf,kf,kf,kf]],["getDirectedEdgeOrigin",kf,[kf,kf,kf]],["getDirectedEdgeDestination",kf,[kf,kf,kf]],["isValidDirectedEdge",kf,[kf,kf]],["directedEdgeToCells",kf,[kf,kf,kf]],["originToDirectedEdges",kf,[kf,kf,kf]],["directedEdgeToBoundary",kf,[kf,kf,kf]],["gridDistance",kf,[kf,kf,kf,kf,kf]],["gridPathCells",kf,[kf,kf,kf,kf,kf]],["gridPathCellsSize",kf,[kf,kf,kf,kf,kf]],["cellToLocalIj",kf,[kf,kf,kf,kf,kf,kf]],["localIjToCell",kf,[kf,kf,kf,kf,kf]],["getHexagonAreaAvgM2",kf,[kf,kf]],["getHexagonAreaAvgKm2",kf,[kf,kf]],["getHexagonEdgeLengthAvgM",kf,[kf,kf]],["getHexagonEdgeLengthAvgKm",kf,[kf,kf]],["greatCircleDistanceM",kf,[kf,kf]],["greatCircleDistanceKm",kf,[kf,kf]],["greatCircleDistanceRads",kf,[kf,kf]],["cellAreaM2",kf,[kf,kf,kf]],["cellAreaKm2",kf,[kf,kf,kf]],["cellAreaRads2",kf,[kf,kf,kf]],["edgeLengthM",kf,[kf,kf,kf]],["edgeLengthKm",kf,[kf,kf,kf]],["edgeLengthRads",kf,[kf,kf,kf]],["getNumCells",kf,[kf,kf]],["getRes0Cells",kf,[kf]],["res0CellCount",kf],["getPentagons",kf,[kf,kf]],["pentagonCount",kf],["cellToVertex",kf,[kf,kf,kf,kf]],["cellToVertexes",kf,[kf,kf,kf]],["vertexToLatLng",kf,[kf,kf,kf]],["isValidVertex",kf,[kf,kf]]].forEach(function(e){Of[e[0]]=Ef.cwrap.apply(Ef,e)});var Rf=16,Bf=Of.sizeOfH3Index(),Mf=Of.sizeOfLatLng(),$f=Of.sizeOfCellBoundary(),Df=Of.sizeOfGeoPolygon(),Ff=Of.sizeOfGeoLoop(),Gf=Of.sizeOfLinkedGeoPolygon(),Uf=Of.sizeOfCoordIJ(),Lf={m:"m",m2:"m2",km:"km",km2:"km2",rads:"rads",rads2:"rads2"},jf={containmentCenter:"containmentCenter",containmentFull:"containmentFull",containmentOverlapping:"containmentOverlapping",containmentOverlappingBbox:"containmentOverlappingBbox"};function Hf(e){if("number"!=typeof e||e<0||e>15||Math.floor(e)!==e)throw Pf(4,e);return e}function zf(e){if(!e)throw Cf(1002);return e}var qf=Math.pow(2,32)-1;function Qf(e){if(e>qf)throw Cf(1001,e);return e}var Vf=/[^0-9a-fA-F]/;function Jf(e){if(Array.isArray(e)&&2===e.length&&Number.isInteger(e[0])&&Number.isInteger(e[1]))return e;if("string"!=typeof e||Vf.test(e))return[0,0];var t=parseInt(e.substring(0,e.length-8),Rf);return[parseInt(e.substring(e.length-8),Rf),t]}function Kf(e){if(e>=0)return e.toString(Rf);var t=Yf(8,(e&=2147483647).toString(Rf));return(parseInt(t[0],Rf)+8).toString(Rf)+t.substring(1)}function Wf(e,t){return Kf(t)+Yf(8,Kf(e))}function Yf(e,t){for(var n=e-t.length,r="",i=0;i<n;i++)r+="0";return r+t}var Zf=Math.pow(2,32);function Xf(e,t,n){for(var r=e.length,i=Ef._calloc(r,Mf),s=n?1:0,a=n?0:1,o=0;o<2*r;o+=2)Ef.HEAPF64.set([e[o/2][s],e[o/2][a]].map(Eu),i/8+o);return Ef.HEAPU32.set([r,i],t/4),t}function eu(e,t){var n,r=e.length-1,i=Ef._calloc(Df),s=0+Ff,a=s+4;if(Xf(e[0],i+0,t),r>0){n=Ef._calloc(r,Ff);for(var o=0;o<r;o++)Xf(e[o+1],n+Ff*o,t)}return Ef.setValue(i+s,r,"i32"),Ef.setValue(i+a,n,"i32"),i}function tu(e){var t=0+Ff,n=t+4;Ef._free(Ef.getValue(e+0+4,"i8*"));var r=Ef.getValue(e+t,"i32");if(r>0){for(var i=Ef.getValue(e+n,"i32"),s=0;s<r;s++)Ef._free(Ef.getValue(i+Ff*s+4,"i8*"));Ef._free(i)}Ef._free(e)}function nu(e,t){void 0===t&&(t=0);var n=Ef.getValue(e+Bf*t,"i32"),r=Ef.getValue(e+Bf*t+4,"i32");return r?Wf(n,r):null}function ru(e,t){return void 0===t&&(t=0),Ef.getValue(e+8*t,"double")}function iu(e){return Of.readInt64AsDoubleFromPointer(e)}function su(e,t,n){Ef.HEAPU32.set(Jf(e),t/4+2*n)}function au(e,t){for(var n=[],r=0;r<t;r++){var i=nu(e,r);null!==i&&n.push(i)}return n}function ou(e,t){for(var n=t.length,r=0;r<n;r++)su(t[r],e,r)}function cu(e,t){var n=Ef._calloc(1,Mf);return Ef.HEAPF64.set([e,t].map(Eu),n/8),n}function Au(e){return ku(Ef.getValue(e,"double"))}function lu(e){return[Au(e),Au(e+8)]}function fu(e){return[Au(e+8),Au(e)]}function uu(e,t,n){for(var r=Ef.getValue(e,"i32"),i=e+8,s=[],a=t?fu:lu,o=0;o<2*r;o+=2)s.push(a(i+8*o));return n&&s.push(s[0]),s}function du(e){var t=Jf(e),n=t[0],r=t[1];return Boolean(Of.isValidCell(n,r))}function hu(e){var t=Jf(e),n=t[0],r=t[1];return Of.isValidCell(n,r)?Of.getResolution(n,r):-1}function pu(e,t,n){var r=Ef._malloc(Mf);Ef.HEAPF64.set([e,t].map(Eu),r/8);var i=Ef._malloc(Bf);try{return Nf(Of.latLngToCell(r,n,i)),zf(nu(i))}finally{Ef._free(i),Ef._free(r)}}function mu(e){var t=Ef._malloc(Mf),n=Jf(e),r=n[0],i=n[1];try{return Nf(Of.cellToLatLng(r,i,t)),lu(t)}finally{Ef._free(t)}}function yu(e,t){var n=Ef._malloc($f),r=Jf(e),i=r[0],s=r[1];try{return Nf(Of.cellToBoundary(i,s,n)),uu(n,t,t)}finally{Ef._free(n)}}function gu(e,t){var n=Jf(e),r=n[0],i=n[1],s=Ef._malloc(Bf);try{return Nf(Of.cellToParent(r,i,t,s)),zf(nu(s))}finally{Ef._free(s)}}function bu(e,t){if(!du(e))return[];var n=Jf(e),r=n[0],i=n[1],s=Qf(wu(e,t)),a=Ef._calloc(s,Bf);try{return Nf(Of.cellToChildren(r,i,t,a)),au(a,s)}finally{Ef._free(a)}}function wu(e,t){if(!du(e))throw Pf(5);var n=Jf(e),r=n[0],i=n[1],s=Ef._malloc(8);try{return Nf(Of.cellToChildrenSize(r,i,t,s)),iu(s)}finally{Ef._free(s)}}function vu(e,t){var n=Jf(e),r=n[0],i=n[1],s=Ef._malloc(8);try{Nf(Of.maxGridDiskSize(t,s));var a=Qf(iu(s)),o=Ef._calloc(a,Bf);try{return Nf(Of.gridDisk(r,i,t,o)),au(o,a)}finally{Ef._free(o)}}finally{Ef._free(s)}}function _u(e,t){var n=Jf(e),r=n[0],i=n[1],s=Ef._malloc(8);try{switch(t){case Lf.m2:Nf(Of.cellAreaM2(r,i,s));break;case Lf.km2:Nf(Of.cellAreaKm2(r,i,s));break;case Lf.rads2:Nf(Of.cellAreaRads2(r,i,s));break;default:throw Cf(Sf,t)}return ru(s)}finally{Ef._free(s)}}function Eu(e){return e*Math.PI/180}function ku(e){return 180*e/Math.PI}const Tu=Object.freeze(Object.defineProperty({__proto__:null,POLYGON_TO_CELLS_FLAGS:jf,UNITS:Lf,areNeighborCells:function(e,t){var n=Jf(e),r=n[0],i=n[1],s=Jf(t),a=s[0],o=s[1],c=Ef._malloc(4);try{return Nf(Of.areNeighborCells(r,i,a,o,c)),function(e,t){void 0===t&&(t=0);var n=Ef.getValue(e+4*t,"i32");return Boolean(n)}(c)}finally{Ef._free(c)}},cellArea:_u,cellToBoundary:yu,cellToCenterChild:function(e,t){var n=Jf(e),r=n[0],i=n[1],s=Ef._malloc(Bf);try{return Nf(Of.cellToCenterChild(r,i,t,s)),zf(nu(s))}finally{Ef._free(s)}},cellToChildPos:function(e,t){var n=Jf(e),r=n[0],i=n[1],s=Ef._malloc(8);try{return Nf(Of.cellToChildPos(r,i,t,s)),iu(s)}finally{Ef._free(s)}},cellToChildren:bu,cellToChildrenSize:wu,cellToLatLng:mu,cellToLocalIj:function(e,t){var n,r=Ef._malloc(Uf);try{return Nf(Of.cellToLocalIj.apply(Of,Jf(e).concat(Jf(t),[0],[r]))),n=r,{i:Ef.getValue(n,"i32"),j:Ef.getValue(n+4,"i32")}}finally{Ef._free(r)}},cellToParent:gu,cellToVertex:function(e,t){var n=Jf(e),r=n[0],i=n[1],s=Ef._malloc(Bf);try{return Nf(Of.cellToVertex(r,i,t,s)),zf(nu(s))}finally{Ef._free(s)}},cellToVertexes:function(e){var t=Jf(e),n=t[0],r=t[1],i=Ef._calloc(6,Bf);try{return Nf(Of.cellToVertexes(n,r,i)),au(i,6)}finally{Ef._free(i)}},cellsToDirectedEdge:function(e,t){var n=Jf(e),r=n[0],i=n[1],s=Jf(t),a=s[0],o=s[1],c=Ef._malloc(Bf);try{return Nf(Of.cellsToDirectedEdge(r,i,a,o,c)),zf(nu(c))}finally{Ef._free(c)}},cellsToMultiPolygon:function(e,t){if(!e||!e.length)return[];var n=e.length,r=Ef._calloc(n,Bf);ou(r,e);var i=Ef._calloc(Gf);try{return Nf(Of.cellsToLinkedMultiPolygon(r,n,i)),function(e,t){for(var n,r,i,s,a=[],o=t?fu:lu;e;){for(a.push(n=[]),r=Ef.getValue(e,"i8*");r;){for(n.push(i=[]),s=Ef.getValue(r,"i8*");s;)i.push(o(s)),s=Ef.getValue(s+16,"i8*");t&&i.push(i[0]),r=Ef.getValue(r+8,"i8*")}e=Ef.getValue(e+8,"i8*")}return a}(i,t)}finally{Of.destroyLinkedMultiPolygon(i),Ef._free(i),Ef._free(r)}},childPosToCell:function(e,t,n){var r,i="number"!=typeof(r=e)?[0,0]:[0|r,r/Zf|0],s=i[0],a=i[1],o=Jf(t),c=o[0],A=o[1],l=Ef._malloc(Bf);try{return Nf(Of.childPosToCell(s,a,c,A,n,l)),zf(nu(l))}finally{Ef._free(l)}},compactCells:function(e){if(!e||!e.length)return[];var t=e.length,n=Ef._calloc(t,Bf);ou(n,e);var r=Ef._calloc(t,Bf);try{return Nf(Of.compactCells(n,r,t,0)),au(r,t)}finally{Ef._free(n),Ef._free(r)}},degsToRads:Eu,directedEdgeToBoundary:function(e,t){var n=Ef._malloc($f),r=Jf(e),i=r[0],s=r[1];try{return Nf(Of.directedEdgeToBoundary(i,s,n)),uu(n,t)}finally{Ef._free(n)}},directedEdgeToCells:function(e){var t=Jf(e),n=t[0],r=t[1],i=Ef._calloc(2,Bf);try{return Nf(Of.directedEdgeToCells(n,r,i)),au(i,2)}finally{Ef._free(i)}},edgeLength:function(e,t){var n=Jf(e),r=n[0],i=n[1],s=Ef._malloc(8);try{switch(t){case Lf.m:Nf(Of.edgeLengthM(r,i,s));break;case Lf.km:Nf(Of.edgeLengthKm(r,i,s));break;case Lf.rads:Nf(Of.edgeLengthRads(r,i,s));break;default:throw Cf(Sf,t)}return ru(s)}finally{Ef._free(s)}},getBaseCellNumber:function(e){var t=Jf(e),n=t[0],r=t[1];return Of.getBaseCellNumber(n,r)},getDirectedEdgeDestination:function(e){var t=Jf(e),n=t[0],r=t[1],i=Ef._malloc(Bf);try{return Nf(Of.getDirectedEdgeDestination(n,r,i)),zf(nu(i))}finally{Ef._free(i)}},getDirectedEdgeOrigin:function(e){var t=Jf(e),n=t[0],r=t[1],i=Ef._malloc(Bf);try{return Nf(Of.getDirectedEdgeOrigin(n,r,i)),zf(nu(i))}finally{Ef._free(i)}},getHexagonAreaAvg:function(e,t){Hf(e);var n=Ef._malloc(8);try{switch(t){case Lf.m2:Nf(Of.getHexagonAreaAvgM2(e,n));break;case Lf.km2:Nf(Of.getHexagonAreaAvgKm2(e,n));break;default:throw Cf(Sf,t)}return ru(n)}finally{Ef._free(n)}},getHexagonEdgeLengthAvg:function(e,t){Hf(e);var n=Ef._malloc(8);try{switch(t){case Lf.m:Nf(Of.getHexagonEdgeLengthAvgM(e,n));break;case Lf.km:Nf(Of.getHexagonEdgeLengthAvgKm(e,n));break;default:throw Cf(Sf,t)}return ru(n)}finally{Ef._free(n)}},getIcosahedronFaces:function(e){var t=Jf(e),n=t[0],r=t[1],i=Ef._malloc(4);try{Nf(Of.maxFaceCount(n,r,i));var s=Ef.getValue(i,"i32"),a=Ef._malloc(4*s);try{return Nf(Of.getIcosahedronFaces(n,r,a)),function(e,t){for(var n=[],r=0;r<t;r++){var i=Ef.getValue(e+4*r,"i32");i>=0&&n.push(i)}return n}(a,s)}finally{Ef._free(a)}}finally{Ef._free(i)}},getNumCells:function(e){Hf(e);var t=Ef._malloc(8);try{return Nf(Of.getNumCells(e,t)),iu(t)}finally{Ef._free(t)}},getPentagons:function(e){Hf(e);var t=Of.pentagonCount(),n=Ef._malloc(Bf*t);try{return Nf(Of.getPentagons(e,n)),au(n,t)}finally{Ef._free(n)}},getRes0Cells:function(){var e=Of.res0CellCount(),t=Ef._malloc(Bf*e);try{return Nf(Of.getRes0Cells(t)),au(t,e)}finally{Ef._free(t)}},getResolution:hu,greatCircleDistance:function(e,t,n){var r,i=cu(e[0],e[1]),s=cu(t[0],t[1]);switch(n){case Lf.m:r=Of.greatCircleDistanceM(i,s);break;case Lf.km:r=Of.greatCircleDistanceKm(i,s);break;case Lf.rads:r=Of.greatCircleDistanceRads(i,s);break;default:r=null}if(Ef._free(i),Ef._free(s),null===r)throw Cf(Sf,n);return r},gridDisk:vu,gridDiskDistances:function(e,t){var n=Jf(e),r=n[0],i=n[1],s=Ef._malloc(8);try{Nf(Of.maxGridDiskSize(t,s));var a=Qf(iu(s)),o=Ef._calloc(a,Bf),c=Ef._calloc(a,4);try{Nf(Of.gridDiskDistances(r,i,t,o,c));for(var A=[],l=0;l<t+1;l++)A.push([]);for(var f=0;f<a;f++){var u=nu(o,f),d=Ef.getValue(c+4*f,"i32");null!==u&&A[d].push(u)}return A}finally{Ef._free(o),Ef._free(c)}}finally{Ef._free(s)}},gridDistance:function(e,t){var n=Jf(e),r=n[0],i=n[1],s=Jf(t),a=s[0],o=s[1],c=Ef._malloc(8);try{return Nf(Of.gridDistance(r,i,a,o,c)),iu(c)}finally{Ef._free(c)}},gridPathCells:function(e,t){var n=Jf(e),r=n[0],i=n[1],s=Jf(t),a=s[0],o=s[1],c=Ef._malloc(8);try{Nf(Of.gridPathCellsSize(r,i,a,o,c));var A=Qf(iu(c)),l=Ef._calloc(A,Bf);try{return Of.gridPathCells(r,i,a,o,l),au(l,A)}finally{Ef._free(l)}}finally{Ef._free(c)}},gridRing:function(e,t){var n=0===t?1:6*t,r=Ef._calloc(n,Bf);try{return Nf(Of.gridRing.apply(Of,Jf(e).concat([t],[r]))),au(r,n)}finally{Ef._free(r)}},gridRingUnsafe:function(e,t){var n=0===t?1:6*t,r=Ef._calloc(n,Bf);try{return Nf(Of.gridRingUnsafe.apply(Of,Jf(e).concat([t],[r]))),au(r,n)}finally{Ef._free(r)}},h3IndexToSplitLong:Jf,isPentagon:function(e){var t=Jf(e),n=t[0],r=t[1];return Boolean(Of.isPentagon(n,r))},isResClassIII:function(e){var t=Jf(e),n=t[0],r=t[1];return Boolean(Of.isResClassIII(n,r))},isValidCell:du,isValidDirectedEdge:function(e){var t=Jf(e),n=t[0],r=t[1];return Boolean(Of.isValidDirectedEdge(n,r))},isValidVertex:function(e){var t=Jf(e),n=t[0],r=t[1];return Boolean(Of.isValidVertex(n,r))},latLngToCell:pu,localIjToCell:function(e,t){if(!t||"number"!=typeof t.i||"number"!=typeof t.j)throw new Error("Coordinates must be provided as an {i, j} object");var n,r,i,s,a=Ef._malloc(Uf),o=Ef._malloc(Bf);n=a,i=(r=t).i,s=r.j,Ef.setValue(n,i,"i32"),Ef.setValue(n+4,s,"i32");try{return Nf(Of.localIjToCell.apply(Of,Jf(e).concat([a],[0],[o]))),zf(nu(o))}finally{Ef._free(a),Ef._free(o)}},originToDirectedEdges:function(e){var t=Jf(e),n=t[0],r=t[1],i=Ef._calloc(6,Bf);try{return Nf(Of.originToDirectedEdges(n,r,i)),au(i,6)}finally{Ef._free(i)}},polygonToCells:function(e,t,n){if(Hf(t),n=Boolean(n),0===e.length||0===e[0].length)return[];var r=eu("number"==typeof e[0][0]?[e]:e,n),i=Ef._malloc(8);try{Nf(Of.maxPolygonToCellsSize(r,t,0,i));var s=Qf(iu(i)),a=Ef._calloc(s,Bf);try{return Nf(Of.polygonToCells(r,t,0,a)),au(a,s)}finally{Ef._free(a)}}finally{Ef._free(i),tu(r)}},polygonToCellsExperimental:function(e,t,n,r){Hf(t),r=Boolean(r);var i=function(e){switch(e){case jf.containmentCenter:return 0;case jf.containmentFull:return 1;case jf.containmentOverlapping:return 2;case jf.containmentOverlappingBbox:return 3;default:throw Cf(15,e)}}(n);if(0===e.length||0===e[0].length)return[];var s=eu("number"==typeof e[0][0]?[e]:e,r),a=Ef._malloc(8);try{Nf(Of.maxPolygonToCellsSizeExperimental(s,t,i,a));var o=Qf(iu(a)),c=Ef._calloc(o,Bf);try{return Nf(Of.polygonToCellsExperimental(s,t,i,o,0,c)),au(c,o)}finally{Ef._free(c)}}finally{Ef._free(a),tu(s)}},radsToDegs:ku,splitLongToH3Index:Wf,uncompactCells:function(e,t){if(Hf(t),!e||!e.length)return[];var n=e.length,r=Ef._calloc(n,Bf);ou(r,e);var i=Ef._malloc(8);try{Nf(Of.uncompactCellsSize(r,n,0,t,i));var s=Qf(iu(i)),a=Ef._calloc(s,Bf);try{return Nf(Of.uncompactCells(r,n,0,a,s,0,t)),au(a,s)}finally{Ef._free(r),Ef._free(a)}}finally{Ef._free(i)}},vertexToLatLng:function(e){var t=Ef._malloc(Mf),n=Jf(e),r=n[0],i=n[1];try{return Nf(Of.vertexToLatLng(r,i,t)),lu(t)}finally{Ef._free(t)}}},Symbol.toStringTag,{value:"Module"}));function Su(e,t=0){if(!xu(e))throw new Error(`Invalid H3 holon ID: ${e}`);const n=[];let r=e;for(let s=hu(e)-1;s>=t;s--)try{r=gu(r,s),n.push(r)}catch(i){break}return n}function xu(e){return"string"==typeof e&&du(e)}const Iu=new Map,Pu=new Map,Cu=new Map,Nu=2e3;async function Ou(e,t,n,r=3e4){const i={kind:r,created_at:Math.floor(Date.now()/1e3),tags:[["d",t]],content:JSON.stringify(n)};return await e.publish(i)}async function Ru(e,t,n=3e4,r={}){const i=void 0!==r.timeout?r.timeout:3e4,s=r.authors||[e.publicKey];if(!r.skipPersistent&&e.persistentGet){const a=await e.persistentGet(t);if(a&&a.content&&s.includes(a.pubkey))try{const o=JSON.parse(a.content);return!o||o._deleted?null:(r.includeAuthor&&(o._author=a.pubkey),e.refreshPathInBackground&&e.refreshPathInBackground(t,n,{authors:s,timeout:i}),o)}catch(A){console.warn("[nostrGet] Failed to parse persisted event:",A)}}const a=`get:${e.publicKey}:${n}:${t}:${s.join(",")}`,o=Cu.get(a);if(o&&Date.now()-o.timestamp<Nu)return o.promise;const c=async function(e,t,n,r,i,s){const a={kinds:[n],authors:r,"#d":[t],limit:r.length},o=(await e.query(a,{timeout:i})).filter(e=>r.includes(e.pubkey));if(0===o.length)return null;const c=o.sort((e,t)=>t.created_at-e.created_at)[0];try{const e=JSON.parse(c.content);return!e||e._deleted?null:(s.includeAuthor&&(e._author=c.pubkey),e)}catch(A){return null}}(e,t,n,s,i,r);return Cu.set(a,{promise:c,timestamp:Date.now()}),c.finally(()=>{setTimeout(()=>{const e=Cu.get(a);e&&e.promise===c&&Cu.delete(a)},Nu)}),c}async function Bu(e,t,n=3e4,r={}){const i=void 0!==r.timeout?r.timeout:3e4,s=r.limit||1e3,a=r.authors||[e.publicKey];if(!r.skipPersistent&&e.persistentGetAll){const o=await e.persistentGetAll(t);if(o.length>0){const c=new Map;for(const e of o){if(!e||!e.tags)continue;if(!a.includes(e.pubkey))continue;const n=e.tags.find(e=>"d"===e[0]);if(!n||!n[1]||!n[1].startsWith(t))continue;const i=n[1],s=c.get(i);if(!s||e.created_at>s.created_at)try{const t=JSON.parse(e.content);if(!t||t._deleted){c.delete(i);continue}r.includeAuthor&&(t._author=e.pubkey),c.set(i,{data:t,created_at:e.created_at})}catch(l){}}return e.refreshPrefixInBackground&&e.refreshPrefixInBackground(t,n,{authors:a,timeout:i,limit:s}),Array.from(c.values()).map(e=>e.data)}}const o=`getAll:${e.publicKey}:${n}:${t}:${a.join(",")}`,c=Cu.get(o);if(c&&Date.now()-c.timestamp<Nu)return c.promise;const A=async function(e,t,n,r,i,s,a){const o={kinds:[n],authors:r,limit:s},c=(await e.query(o,{timeout:i})).filter(e=>{const n=e.tags.find(e=>"d"===e[0]),i=n&&n[1]&&n[1].startsWith(t),s=r.includes(e.pubkey);return i&&s}),A=new Map;for(const f of c){const e=f.tags.find(e=>"d"===e[0])[1],t=A.get(e);if(!t||f.created_at>t.created_at)try{const t=JSON.parse(f.content);if(!t||t._deleted){A.delete(e);continue}a.includeAuthor&&(t._author=f.pubkey),A.set(e,{data:t,created_at:f.created_at})}catch(l){}}return Array.from(A.values()).map(e=>e.data)}(e,t,n,a,i,s,r);return Cu.set(o,{promise:A,timestamp:Date.now()}),A.finally(()=>{setTimeout(()=>{const e=Cu.get(o);e&&e.promise===A&&Cu.delete(o)},Nu)}),A}async function Mu(e,t,n=3e4,r={}){const i=void 0!==r.timeout?r.timeout:3e4,s=r.limit||1e3,a=r.authors||[e.publicKey],o=e.queryHybrid||e.query,c={kinds:[n],authors:a,limit:s},A=(await o.call(e,c,{timeout:i})).filter(e=>{const n=e.tags.find(e=>"d"===e[0]),r=n&&n[1]&&n[1].startsWith(t),i=a.includes(e.pubkey);return r&&i}),l=new Map;for(const u of A){const e=u.tags.find(e=>"d"===e[0])[1],t=l.get(e);if(!t||u.created_at>t.created_at)try{const t=JSON.parse(u.content);if(null===t||"object"!=typeof t)continue;if(t._deleted){l.delete(e);continue}r.includeAuthor&&(t._author=u.pubkey),l.set(e,{data:t,created_at:u.created_at})}catch(f){}}return Array.from(l.values()).map(e=>e.data)}function $u(e){return encodeURIComponent(e).replace(/%2F/g,"/")}function Du(e,t,n,r=null){return function(e,t,n,r=null){const i=$u(t),s=$u(n);return r?`${e}/${i}/${s}/${$u(r)}`:`${e}/${i}/${s}`}(e,t,n,r)}async function Fu(e,t,n){return e.write&&e.gun?e.write(t,n):e.gun?Wl(e.gun,t,n):async function(e,t,n){try{const r=await Ou(e,t,n);return 0===r.results.length||r.results.some(e=>"fulfilled"===e.status)}catch(r){throw console.error("Nostr write error:",r),r}}(e,t,n)}async function Gu(e,t,n={}){return e.read&&e.gun?e.read(t,n):e.gun?Yl(e.gun,t):async function(e,t,n={}){const r=await Ru(e,t,3e4,n);return!r||r._deleted?null:r}(e,t,n)}async function Uu(e,t,n={}){return e.readAll&&e.gun?e.readAll(t,n):e.gun?Zl(e.gun,t):async function(e,t,n={}){const r=n.hybrid&&"function"==typeof e.queryHybrid?Mu:Bu;return(await r(e,t,3e4,n)).filter(e=>!(!e||"object"!=typeof e||e._deleted))}(e,t,n)}async function Lu(e,t,n){return e.update&&e.gun?e.update(t,n):e.gun?Xl(e.gun,t,n):async function(e,t,n){try{const r=await Ru(e,t);if(!r||!r.id||r._deleted)return!1;const i={...r,...n};i._meta||(i._meta={}),i._meta.timestamp=Date.now();const s=await Ou(e,t,i);return 0===s.results.length||s.results.some(e=>"fulfilled"===e.status)}catch(r){throw console.error("Nostr update error:",r),r}}(e,t,n)}async function ju(e,t){return e.delete&&e.gun?e.delete(t):e.gun?ef(e.gun,t):async function(e,t){try{const n=await async function(e,t,n=3e4){if(!(await Ru(e,t,n)))return{reason:"not_found",results:[]};const r={_deleted:!0,_deletedAt:Date.now()},i=await Ou(e,t,r,n);if(e.persistentStorage)try{await e.persistentStorage.delete(t)}catch(o){}e.clearCache&&e.clearCache(t);const s=`${n}:${e.publicKey}:${t}`,a={kind:5,created_at:Math.floor(Date.now()/1e3),tags:[["a",s]],content:""};try{await e.publish(a)}catch(c){}return i}(e,t);return"not_found"!==n.reason&&(0===n.results.length||n.results.some(e=>"fulfilled"===e.status))}catch(n){throw console.error("Nostr delete error:",n),n}}(e,t)}async function Hu(e,t){return e.gun?tf(e.gun,t):async function(e,t){try{const n=await async function(e,t,n=3e4){const r={kinds:[n],authors:[e.publicKey],limit:1e3},i=await e.query(r,{timeout:3e4});let s=[];if(e.persistentStorage)try{s=await e.persistentStorage.getAll(t)}catch(l){}const a=new Map;for(const u of i){const e=u.tags?.find(e=>"d"===e[0]);e&&e[1]&&e[1].startsWith(t)&&a.set(e[1],u)}for(const u of s){const e=u.tags?.find(e=>"d"===e[0]);if(e&&e[1]&&e[1].startsWith(t)){const t=a.get(e[1]);(!t||u.created_at>t.created_at)&&a.set(e[1],u)}}const o=Array.from(a.values());if(0===o.length)return{success:!0,count:0,results:[]};const c=[];for(const u of o){const t=u.tags.find(e=>"d"===e[0])[1];try{const r={_deleted:!0,_deletedAt:Date.now()},i=await Ou(e,t,r,n);if(c.push(i),e.persistentStorage)try{await e.persistentStorage.delete(t)}catch(l){}e.clearCache&&e.clearCache(t)}catch(f){console.error(`Failed to delete item ${t}:`,f)}}const A=o.map(t=>{const r=t.tags.find(e=>"d"===e[0])[1];return`${n}:${e.publicKey}:${r}`});try{const t={kind:5,created_at:Math.floor(Date.now()/1e3),tags:A.map(e=>["a",e]),content:""};await e.publish(t)}catch(f){}return{success:!0,count:o.length,results:c}}(e,t);return n}catch(n){throw console.error("Nostr deleteAll error:",n),n}}(e,t)}function zu(e,t,n,r={}){return e.subscribe&&e.gun?e.subscribe(t,n,r):e.gun?nf(e.gun,t,n,r):async function(e,t,n,r={}){return t.split("/").length<=3?await async function(e,t,n,r={}){const i=r.kind||3e4,s=`${e.publicKey}:${i}:${t}`,a=Iu.get(s);if(a)return a.callbacks.push(n),{unsubscribe:()=>{const e=a.callbacks.indexOf(n);e>-1&&a.callbacks.splice(e,1),0===a.callbacks.length&&(a.actualSubscription.unsubscribe(),Iu.delete(s))}};const o=new Set,c=[n];let A=0,l=0,f=Date.now();const u=n=>{if(o.has(n.id))return;if(o.add(n.id),n.pubkey!==e.publicKey){A++;const t=Date.now();return void(t-f>1e4&&(console.warn("[nostrSubscribeMany] ⚠️ Relay not respecting authors filter!",{rejectedCount:A,acceptedCount:l,expected:e.publicKey,message:"Consider using a different relay or implementing private relay"}),f=t))}const r=n.tags.find(e=>"d"===e[0]),i=r?.[1];if(i&&i.startsWith(t))try{const e=JSON.parse(n.content);if(!e||e._deleted)return;l++;for(const t of c)t(e,i,n)}catch(s){console.error("[nostrSubscribeMany] Failed to parse event:",s)}},d=Math.floor(Date.now()/1e3),h={kinds:[i],authors:[e.publicKey],since:d},p=await e.subscribe(h,u);let m="undefined"!=typeof document&&document.hidden,y=d;const g=async()=>{if("undefined"==typeof document)return;const t=m;if(m=document.hidden,t&&!m){const t=Math.floor(Date.now()/1e3);try{const n={...h,since:y,until:t},r=await e.query(n,{timeout:3e4});for(const e of r)u(e);y=t}catch(n){}}};"undefined"!=typeof document&&document.addEventListener("visibilitychange",g);const b={unsubscribe:()=>{p&&p.unsubscribe&&p.unsubscribe(),"undefined"!=typeof document&&document.removeEventListener("visibilitychange",g),Iu.delete(s)}},w={callbacks:c,actualSubscription:b};return Iu.set(s,w),b}(e,t+"/",(e,t)=>{const r=t.split("/").pop();n(e,r)},r):function(e,t,n,r={}){const i=r.kind||3e4,s=`single:${e.publicKey}:${i}:${t}`,a=Pu.get(s);if(a)return a.callbacks.push(n),{unsubscribe:()=>{const e=a.callbacks.indexOf(n);e>-1&&a.callbacks.splice(e,1),0===a.callbacks.length&&(a.subscription.unsubscribe(),Pu.delete(s))}};const o=[n],c={callbacks:o,subscription:null};Pu.set(s,c);const A={kinds:[i],authors:[e.publicKey],"#d":[t],limit:10},l=e.subscribe(A,t=>{if(t.pubkey===e.publicKey)try{const e=JSON.parse(t.content);if(!e||e._deleted)return;for(const r of o)try{r(e,t)}catch(n){console.error("Subscription callback error:",n)}}catch(r){console.error("Failed to parse event in subscription:",r)}},{onEOSE:()=>{}});return c.subscription=l,{unsubscribe:()=>{const e=o.indexOf(n);e>-1&&o.splice(e,1),0===o.length&&(l.unsubscribe(),Pu.delete(s))}}}(e,t,e=>{n(e,t.split("/").pop())},r)}(e,t,n,r)}async function qu(e,t,n,r){return r.id||(r.id=`${Date.now()}-${Math.random().toString(36).substr(2,9)}`),Fu(e,`${t}/${n}/${r.id}`,r)}async function Qu(e,t,n,r=null){return r?Gu(e,`${t}/${n}/${r}`):Uu(e,`${t}/${n}`)}function Vu(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Ju={exports:{}},Ku={},Wu={},Yu={},Zu={},Xu={},ed={};!function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.regexpCode=e.getEsmExportName=e.getProperty=e.safeStringify=e.stringify=e.strConcat=e.addCodeArg=e.str=e._=e.nil=e._Code=e.Name=e.IDENTIFIER=e._CodeOrName=void 0;class t{}e._CodeOrName=t,e.IDENTIFIER=/^[a-z$_][a-z$_0-9]*$/i;class n extends t{constructor(t){if(super(),!e.IDENTIFIER.test(t))throw new Error("CodeGen: name must be a valid identifier");this.str=t}toString(){return this.str}emptyStr(){return!1}get names(){return{[this.str]:1}}}e.Name=n;class r extends t{constructor(e){super(),this._items="string"==typeof e?[e]:e}toString(){return this.str}emptyStr(){if(this._items.length>1)return!1;const e=this._items[0];return""===e||'""'===e}get str(){var e;return null!==(e=this._str)&&void 0!==e?e:this._str=this._items.reduce((e,t)=>`${e}${t}`,"")}get names(){var e;return null!==(e=this._names)&&void 0!==e?e:this._names=this._items.reduce((e,t)=>(t instanceof n&&(e[t.str]=(e[t.str]||0)+1),e),{})}}function i(e,...t){const n=[e[0]];let i=0;for(;i<t.length;)o(n,t[i]),n.push(e[++i]);return new r(n)}e._Code=r,e.nil=new r(""),e._=i;const s=new r("+");function a(e,...t){const n=[A(e[0])];let i=0;for(;i<t.length;)n.push(s),o(n,t[i]),n.push(s,A(e[++i]));return function(e){let t=1;for(;t<e.length-1;){if(e[t]===s){const n=c(e[t-1],e[t+1]);if(void 0!==n){e.splice(t-1,3,n);continue}e[t++]="+"}t++}}(n),new r(n)}function o(e,t){var i;t instanceof r?e.push(...t._items):t instanceof n?e.push(t):e.push("number"==typeof(i=t)||"boolean"==typeof i||null===i?i:A(Array.isArray(i)?i.join(","):i))}function c(e,t){if('""'===t)return e;if('""'===e)return t;if("string"==typeof e){if(t instanceof n||'"'!==e[e.length-1])return;return"string"!=typeof t?`${e.slice(0,-1)}${t}"`:'"'===t[0]?e.slice(0,-1)+t.slice(1):void 0}return"string"!=typeof t||'"'!==t[0]||e instanceof n?void 0:`"${e}${t.slice(1)}`}function A(e){return JSON.stringify(e).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}e.str=a,e.addCodeArg=o,e.strConcat=function(e,t){return t.emptyStr()?e:e.emptyStr()?t:a`${e}${t}`},e.stringify=function(e){return new r(A(e))},e.safeStringify=A,e.getProperty=function(t){return"string"==typeof t&&e.IDENTIFIER.test(t)?new r(`.${t}`):i`[${t}]`},e.getEsmExportName=function(t){if("string"==typeof t&&e.IDENTIFIER.test(t))return new r(`${t}`);throw new Error(`CodeGen: invalid export name: ${t}, use explicit $id name mapping`)},e.regexpCode=function(e){return new r(e.toString())}}(ed);var td={};!function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.ValueScope=e.ValueScopeName=e.Scope=e.varKinds=e.UsedValueState=void 0;const t=ed;class n extends Error{constructor(e){super(`CodeGen: "code" for ${e} not defined`),this.value=e.value}}var r,i;(i=r||(e.UsedValueState=r={}))[i.Started=0]="Started",i[i.Completed=1]="Completed",e.varKinds={const:new t.Name("const"),let:new t.Name("let"),var:new t.Name("var")};class s{constructor({prefixes:e,parent:t}={}){this._names={},this._prefixes=e,this._parent=t}toName(e){return e instanceof t.Name?e:this.name(e)}name(e){return new t.Name(this._newName(e))}_newName(e){return`${e}${(this._names[e]||this._nameGroup(e)).index++}`}_nameGroup(e){var t,n;if((null===(n=null===(t=this._parent)||void 0===t?void 0:t._prefixes)||void 0===n?void 0:n.has(e))||this._prefixes&&!this._prefixes.has(e))throw new Error(`CodeGen: prefix "${e}" is not allowed in this scope`);return this._names[e]={prefix:e,index:0}}}e.Scope=s;class a extends t.Name{constructor(e,t){super(t),this.prefix=e}setValue(e,{property:n,itemIndex:r}){this.value=e,this.scopePath=t._`.${new t.Name(n)}[${r}]`}}e.ValueScopeName=a;const o=t._`\n`;e.ValueScope=class extends s{constructor(e){super(e),this._values={},this._scope=e.scope,this.opts={...e,_n:e.lines?o:t.nil}}get(){return this._scope}name(e){return new a(e,this._newName(e))}value(e,t){var n;if(void 0===t.ref)throw new Error("CodeGen: ref must be passed in value");const r=this.toName(e),{prefix:i}=r,s=null!==(n=t.key)&&void 0!==n?n:t.ref;let a=this._values[i];if(a){const e=a.get(s);if(e)return e}else a=this._values[i]=new Map;a.set(s,r);const o=this._scope[i]||(this._scope[i]=[]),c=o.length;return o[c]=t.ref,r.setValue(t,{property:i,itemIndex:c}),r}getValue(e,t){const n=this._values[e];if(n)return n.get(t)}scopeRefs(e,n=this._values){return this._reduceValues(n,n=>{if(void 0===n.scopePath)throw new Error(`CodeGen: name "${n}" has no value`);return t._`${e}${n.scopePath}`})}scopeCode(e=this._values,t,n){return this._reduceValues(e,e=>{if(void 0===e.value)throw new Error(`CodeGen: name "${e}" has no value`);return e.value.code},t,n)}_reduceValues(i,s,a={},o){let c=t.nil;for(const A in i){const l=i[A];if(!l)continue;const f=a[A]=a[A]||new Map;l.forEach(i=>{if(f.has(i))return;f.set(i,r.Started);let a=s(i);if(a){const n=this.opts.es5?e.varKinds.var:e.varKinds.const;c=t._`${c}${n} ${i} = ${a};${this.opts._n}`}else{if(!(a=null==o?void 0:o(i)))throw new n(i);c=t._`${c}${a}${this.opts._n}`}f.set(i,r.Completed)})}return c}}}(td),function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.or=e.and=e.not=e.CodeGen=e.operators=e.varKinds=e.ValueScopeName=e.ValueScope=e.Scope=e.Name=e.regexpCode=e.stringify=e.getProperty=e.nil=e.strConcat=e.str=e._=void 0;const t=ed,n=td;var r=ed;Object.defineProperty(e,"_",{enumerable:!0,get:function(){return r._}}),Object.defineProperty(e,"str",{enumerable:!0,get:function(){return r.str}}),Object.defineProperty(e,"strConcat",{enumerable:!0,get:function(){return r.strConcat}}),Object.defineProperty(e,"nil",{enumerable:!0,get:function(){return r.nil}}),Object.defineProperty(e,"getProperty",{enumerable:!0,get:function(){return r.getProperty}}),Object.defineProperty(e,"stringify",{enumerable:!0,get:function(){return r.stringify}}),Object.defineProperty(e,"regexpCode",{enumerable:!0,get:function(){return r.regexpCode}}),Object.defineProperty(e,"Name",{enumerable:!0,get:function(){return r.Name}});var i=td;Object.defineProperty(e,"Scope",{enumerable:!0,get:function(){return i.Scope}}),Object.defineProperty(e,"ValueScope",{enumerable:!0,get:function(){return i.ValueScope}}),Object.defineProperty(e,"ValueScopeName",{enumerable:!0,get:function(){return i.ValueScopeName}}),Object.defineProperty(e,"varKinds",{enumerable:!0,get:function(){return i.varKinds}}),e.operators={GT:new t._Code(">"),GTE:new t._Code(">="),LT:new t._Code("<"),LTE:new t._Code("<="),EQ:new t._Code("==="),NEQ:new t._Code("!=="),NOT:new t._Code("!"),OR:new t._Code("||"),AND:new t._Code("&&"),ADD:new t._Code("+")};class s{optimizeNodes(){return this}optimizeNames(e,t){return this}}class a extends s{constructor(e,t,n){super(),this.varKind=e,this.name=t,this.rhs=n}render({es5:e,_n:t}){const r=e?n.varKinds.var:this.varKind,i=void 0===this.rhs?"":` = ${this.rhs}`;return`${r} ${this.name}${i};`+t}optimizeNames(e,t){if(e[this.name.str])return this.rhs&&(this.rhs=P(this.rhs,e,t)),this}get names(){return this.rhs instanceof t._CodeOrName?this.rhs.names:{}}}class o extends s{constructor(e,t,n){super(),this.lhs=e,this.rhs=t,this.sideEffects=n}render({_n:e}){return`${this.lhs} = ${this.rhs};`+e}optimizeNames(e,n){if(!(this.lhs instanceof t.Name)||e[this.lhs.str]||this.sideEffects)return this.rhs=P(this.rhs,e,n),this}get names(){return I(this.lhs instanceof t.Name?{}:{...this.lhs.names},this.rhs)}}class c extends o{constructor(e,t,n,r){super(e,n,r),this.op=t}render({_n:e}){return`${this.lhs} ${this.op}= ${this.rhs};`+e}}class A extends s{constructor(e){super(),this.label=e,this.names={}}render({_n:e}){return`${this.label}:`+e}}class l extends s{constructor(e){super(),this.label=e,this.names={}}render({_n:e}){return`break${this.label?` ${this.label}`:""};`+e}}class f extends s{constructor(e){super(),this.error=e}render({_n:e}){return`throw ${this.error};`+e}get names(){return this.error.names}}class u extends s{constructor(e){super(),this.code=e}render({_n:e}){return`${this.code};`+e}optimizeNodes(){return`${this.code}`?this:void 0}optimizeNames(e,t){return this.code=P(this.code,e,t),this}get names(){return this.code instanceof t._CodeOrName?this.code.names:{}}}class d extends s{constructor(e=[]){super(),this.nodes=e}render(e){return this.nodes.reduce((t,n)=>t+n.render(e),"")}optimizeNodes(){const{nodes:e}=this;let t=e.length;for(;t--;){const n=e[t].optimizeNodes();Array.isArray(n)?e.splice(t,1,...n):n?e[t]=n:e.splice(t,1)}return e.length>0?this:void 0}optimizeNames(e,t){const{nodes:n}=this;let r=n.length;for(;r--;){const i=n[r];i.optimizeNames(e,t)||(C(e,i.names),n.splice(r,1))}return n.length>0?this:void 0}get names(){return this.nodes.reduce((e,t)=>x(e,t.names),{})}}class h extends d{render(e){return"{"+e._n+super.render(e)+"}"+e._n}}class p extends d{}class m extends h{}m.kind="else";class y extends h{constructor(e,t){super(t),this.condition=e}render(e){let t=`if(${this.condition})`+super.render(e);return this.else&&(t+="else "+this.else.render(e)),t}optimizeNodes(){super.optimizeNodes();const e=this.condition;if(!0===e)return this.nodes;let t=this.else;if(t){const e=t.optimizeNodes();t=this.else=Array.isArray(e)?new m(e):e}return t?!1===e?t instanceof y?t:t.nodes:this.nodes.length?this:new y(N(e),t instanceof y?[t]:t.nodes):!1!==e&&this.nodes.length?this:void 0}optimizeNames(e,t){var n;if(this.else=null===(n=this.else)||void 0===n?void 0:n.optimizeNames(e,t),super.optimizeNames(e,t)||this.else)return this.condition=P(this.condition,e,t),this}get names(){const e=super.names;return I(e,this.condition),this.else&&x(e,this.else.names),e}}y.kind="if";class g extends h{}g.kind="for";class b extends g{constructor(e){super(),this.iteration=e}render(e){return`for(${this.iteration})`+super.render(e)}optimizeNames(e,t){if(super.optimizeNames(e,t))return this.iteration=P(this.iteration,e,t),this}get names(){return x(super.names,this.iteration.names)}}class w extends g{constructor(e,t,n,r){super(),this.varKind=e,this.name=t,this.from=n,this.to=r}render(e){const t=e.es5?n.varKinds.var:this.varKind,{name:r,from:i,to:s}=this;return`for(${t} ${r}=${i}; ${r}<${s}; ${r}++)`+super.render(e)}get names(){const e=I(super.names,this.from);return I(e,this.to)}}class v extends g{constructor(e,t,n,r){super(),this.loop=e,this.varKind=t,this.name=n,this.iterable=r}render(e){return`for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})`+super.render(e)}optimizeNames(e,t){if(super.optimizeNames(e,t))return this.iterable=P(this.iterable,e,t),this}get names(){return x(super.names,this.iterable.names)}}class _ extends h{constructor(e,t,n){super(),this.name=e,this.args=t,this.async=n}render(e){return`${this.async?"async ":""}function ${this.name}(${this.args})`+super.render(e)}}_.kind="func";class E extends d{render(e){return"return "+super.render(e)}}E.kind="return";class k extends h{render(e){let t="try"+super.render(e);return this.catch&&(t+=this.catch.render(e)),this.finally&&(t+=this.finally.render(e)),t}optimizeNodes(){var e,t;return super.optimizeNodes(),null===(e=this.catch)||void 0===e||e.optimizeNodes(),null===(t=this.finally)||void 0===t||t.optimizeNodes(),this}optimizeNames(e,t){var n,r;return super.optimizeNames(e,t),null===(n=this.catch)||void 0===n||n.optimizeNames(e,t),null===(r=this.finally)||void 0===r||r.optimizeNames(e,t),this}get names(){const e=super.names;return this.catch&&x(e,this.catch.names),this.finally&&x(e,this.finally.names),e}}class T extends h{constructor(e){super(),this.error=e}render(e){return`catch(${this.error})`+super.render(e)}}T.kind="catch";class S extends h{render(e){return"finally"+super.render(e)}}function x(e,t){for(const n in t)e[n]=(e[n]||0)+(t[n]||0);return e}function I(e,n){return n instanceof t._CodeOrName?x(e,n.names):e}function P(e,n,r){return e instanceof t.Name?s(e):(i=e)instanceof t._Code&&i._items.some(e=>e instanceof t.Name&&1===n[e.str]&&void 0!==r[e.str])?new t._Code(e._items.reduce((e,n)=>(n instanceof t.Name&&(n=s(n)),n instanceof t._Code?e.push(...n._items):e.push(n),e),[])):e;var i;function s(e){const t=r[e.str];return void 0===t||1!==n[e.str]?e:(delete n[e.str],t)}}function C(e,t){for(const n in t)e[n]=(e[n]||0)-(t[n]||0)}function N(e){return"boolean"==typeof e||"number"==typeof e||null===e?!e:t._`!${M(e)}`}S.kind="finally",e.CodeGen=class{constructor(e,t={}){this._values={},this._blockStarts=[],this._constants={},this.opts={...t,_n:t.lines?"\n":""},this._extScope=e,this._scope=new n.Scope({parent:e}),this._nodes=[new p]}toString(){return this._root.render(this.opts)}name(e){return this._scope.name(e)}scopeName(e){return this._extScope.name(e)}scopeValue(e,t){const n=this._extScope.value(e,t);return(this._values[n.prefix]||(this._values[n.prefix]=new Set)).add(n),n}getScopeValue(e,t){return this._extScope.getValue(e,t)}scopeRefs(e){return this._extScope.scopeRefs(e,this._values)}scopeCode(){return this._extScope.scopeCode(this._values)}_def(e,t,n,r){const i=this._scope.toName(t);return void 0!==n&&r&&(this._constants[i.str]=n),this._leafNode(new a(e,i,n)),i}const(e,t,r){return this._def(n.varKinds.const,e,t,r)}let(e,t,r){return this._def(n.varKinds.let,e,t,r)}var(e,t,r){return this._def(n.varKinds.var,e,t,r)}assign(e,t,n){return this._leafNode(new o(e,t,n))}add(t,n){return this._leafNode(new c(t,e.operators.ADD,n))}code(e){return"function"==typeof e?e():e!==t.nil&&this._leafNode(new u(e)),this}object(...e){const n=["{"];for(const[r,i]of e)n.length>1&&n.push(","),n.push(r),(r!==i||this.opts.es5)&&(n.push(":"),(0,t.addCodeArg)(n,i));return n.push("}"),new t._Code(n)}if(e,t,n){if(this._blockNode(new y(e)),t&&n)this.code(t).else().code(n).endIf();else if(t)this.code(t).endIf();else if(n)throw new Error('CodeGen: "else" body without "then" body');return this}elseIf(e){return this._elseNode(new y(e))}else(){return this._elseNode(new m)}endIf(){return this._endBlockNode(y,m)}_for(e,t){return this._blockNode(e),t&&this.code(t).endFor(),this}for(e,t){return this._for(new b(e),t)}forRange(e,t,r,i,s=(this.opts.es5?n.varKinds.var:n.varKinds.let)){const a=this._scope.toName(e);return this._for(new w(s,a,t,r),()=>i(a))}forOf(e,r,i,s=n.varKinds.const){const a=this._scope.toName(e);if(this.opts.es5){const e=r instanceof t.Name?r:this.var("_arr",r);return this.forRange("_i",0,t._`${e}.length`,n=>{this.var(a,t._`${e}[${n}]`),i(a)})}return this._for(new v("of",s,a,r),()=>i(a))}forIn(e,r,i,s=(this.opts.es5?n.varKinds.var:n.varKinds.const)){if(this.opts.ownProperties)return this.forOf(e,t._`Object.keys(${r})`,i);const a=this._scope.toName(e);return this._for(new v("in",s,a,r),()=>i(a))}endFor(){return this._endBlockNode(g)}label(e){return this._leafNode(new A(e))}break(e){return this._leafNode(new l(e))}return(e){const t=new E;if(this._blockNode(t),this.code(e),1!==t.nodes.length)throw new Error('CodeGen: "return" should have one node');return this._endBlockNode(E)}try(e,t,n){if(!t&&!n)throw new Error('CodeGen: "try" without "catch" and "finally"');const r=new k;if(this._blockNode(r),this.code(e),t){const e=this.name("e");this._currNode=r.catch=new T(e),t(e)}return n&&(this._currNode=r.finally=new S,this.code(n)),this._endBlockNode(T,S)}throw(e){return this._leafNode(new f(e))}block(e,t){return this._blockStarts.push(this._nodes.length),e&&this.code(e).endBlock(t),this}endBlock(e){const t=this._blockStarts.pop();if(void 0===t)throw new Error("CodeGen: not in self-balancing block");const n=this._nodes.length-t;if(n<0||void 0!==e&&n!==e)throw new Error(`CodeGen: wrong number of nodes: ${n} vs ${e} expected`);return this._nodes.length=t,this}func(e,n=t.nil,r,i){return this._blockNode(new _(e,n,r)),i&&this.code(i).endFunc(),this}endFunc(){return this._endBlockNode(_)}optimize(e=1){for(;e-- >0;)this._root.optimizeNodes(),this._root.optimizeNames(this._root.names,this._constants)}_leafNode(e){return this._currNode.nodes.push(e),this}_blockNode(e){this._currNode.nodes.push(e),this._nodes.push(e)}_endBlockNode(e,t){const n=this._currNode;if(n instanceof e||t&&n instanceof t)return this._nodes.pop(),this;throw new Error(`CodeGen: not in block "${t?`${e.kind}/${t.kind}`:e.kind}"`)}_elseNode(e){const t=this._currNode;if(!(t instanceof y))throw new Error('CodeGen: "else" without "if"');return this._currNode=t.else=e,this}get _root(){return this._nodes[0]}get _currNode(){const e=this._nodes;return e[e.length-1]}set _currNode(e){const t=this._nodes;t[t.length-1]=e}},e.not=N;const O=B(e.operators.AND);e.and=function(...e){return e.reduce(O)};const R=B(e.operators.OR);function B(e){return(n,r)=>n===t.nil?r:r===t.nil?n:t._`${M(n)} ${e} ${M(r)}`}function M(e){return e instanceof t.Name?e:t._`(${e})`}e.or=function(...e){return e.reduce(R)}}(Xu);var nd={};Object.defineProperty(nd,"__esModule",{value:!0}),nd.checkStrictMode=nd.getErrorPath=nd.Type=nd.useFunc=nd.setEvaluated=nd.evaluatedPropsToName=nd.mergeEvaluated=nd.eachItem=nd.unescapeJsonPointer=nd.escapeJsonPointer=nd.escapeFragment=nd.unescapeFragment=nd.schemaRefOrVal=nd.schemaHasRulesButRef=nd.schemaHasRules=nd.checkUnknownRules=nd.alwaysValidSchema=nd.toHash=void 0;const rd=Xu,id=ed;function sd(e,t=e.schema){const{opts:n,self:r}=e;if(!n.strictSchema)return;if("boolean"==typeof t)return;const i=r.RULES.keywords;for(const s in t)i[s]||pd(e,`unknown keyword: "${s}"`)}function ad(e,t){if("boolean"==typeof e)return!e;for(const n in e)if(t[n])return!0;return!1}function od(e){return"number"==typeof e?`${e}`:e.replace(/~/g,"~0").replace(/\//g,"~1")}function cd(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function Ad({mergeNames:e,mergeToName:t,mergeValues:n,resultToName:r}){return(i,s,a,o)=>{const c=void 0===a?s:a instanceof rd.Name?(s instanceof rd.Name?e(i,s,a):t(i,s,a),a):s instanceof rd.Name?(t(i,a,s),s):n(s,a);return o!==rd.Name||c instanceof rd.Name?c:r(i,c)}}function ld(e,t){if(!0===t)return e.var("props",!0);const n=e.var("props",rd._`{}`);return void 0!==t&&fd(e,n,t),n}function fd(e,t,n){Object.keys(n).forEach(n=>e.assign(rd._`${t}${(0,rd.getProperty)(n)}`,!0))}nd.toHash=function(e){const t={};for(const n of e)t[n]=!0;return t},nd.alwaysValidSchema=function(e,t){return"boolean"==typeof t?t:0===Object.keys(t).length||(sd(e,t),!ad(t,e.self.RULES.all))},nd.checkUnknownRules=sd,nd.schemaHasRules=ad,nd.schemaHasRulesButRef=function(e,t){if("boolean"==typeof e)return!e;for(const n in e)if("$ref"!==n&&t.all[n])return!0;return!1},nd.schemaRefOrVal=function({topSchemaRef:e,schemaPath:t},n,r,i){if(!i){if("number"==typeof n||"boolean"==typeof n)return n;if("string"==typeof n)return rd._`${n}`}return rd._`${e}${t}${(0,rd.getProperty)(r)}`},nd.unescapeFragment=function(e){return cd(decodeURIComponent(e))},nd.escapeFragment=function(e){return encodeURIComponent(od(e))},nd.escapeJsonPointer=od,nd.unescapeJsonPointer=cd,nd.eachItem=function(e,t){if(Array.isArray(e))for(const n of e)t(n);else t(e)},nd.mergeEvaluated={props:Ad({mergeNames:(e,t,n)=>e.if(rd._`${n} !== true && ${t} !== undefined`,()=>{e.if(rd._`${t} === true`,()=>e.assign(n,!0),()=>e.assign(n,rd._`${n} || {}`).code(rd._`Object.assign(${n}, ${t})`))}),mergeToName:(e,t,n)=>e.if(rd._`${n} !== true`,()=>{!0===t?e.assign(n,!0):(e.assign(n,rd._`${n} || {}`),fd(e,n,t))}),mergeValues:(e,t)=>!0===e||{...e,...t},resultToName:ld}),items:Ad({mergeNames:(e,t,n)=>e.if(rd._`${n} !== true && ${t} !== undefined`,()=>e.assign(n,rd._`${t} === true ? true : ${n} > ${t} ? ${n} : ${t}`)),mergeToName:(e,t,n)=>e.if(rd._`${n} !== true`,()=>e.assign(n,!0===t||rd._`${n} > ${t} ? ${n} : ${t}`)),mergeValues:(e,t)=>!0===e||Math.max(e,t),resultToName:(e,t)=>e.var("items",t)})},nd.evaluatedPropsToName=ld,nd.setEvaluated=fd;const ud={};var dd,hd;function pd(e,t,n=e.opts.strictSchema){if(n){if(t=`strict mode: ${t}`,!0===n)throw new Error(t);e.self.logger.warn(t)}}nd.useFunc=function(e,t){return e.scopeValue("func",{ref:t,code:ud[t.code]||(ud[t.code]=new id._Code(t.code))})},(hd=dd||(nd.Type=dd={}))[hd.Num=0]="Num",hd[hd.Str=1]="Str",nd.getErrorPath=function(e,t,n){if(e instanceof rd.Name){const r=t===dd.Num;return n?r?rd._`"[" + ${e} + "]"`:rd._`"['" + ${e} + "']"`:r?rd._`"/" + ${e}`:rd._`"/" + ${e}.replace(/~/g, "~0").replace(/\\//g, "~1")`}return n?(0,rd.getProperty)(e).toString():"/"+od(e)},nd.checkStrictMode=pd;var md={};Object.defineProperty(md,"__esModule",{value:!0});const yd=Xu,gd={data:new yd.Name("data"),valCxt:new yd.Name("valCxt"),instancePath:new yd.Name("instancePath"),parentData:new yd.Name("parentData"),parentDataProperty:new yd.Name("parentDataProperty"),rootData:new yd.Name("rootData"),dynamicAnchors:new yd.Name("dynamicAnchors"),vErrors:new yd.Name("vErrors"),errors:new yd.Name("errors"),this:new yd.Name("this"),self:new yd.Name("self"),scope:new yd.Name("scope"),json:new yd.Name("json"),jsonPos:new yd.Name("jsonPos"),jsonLen:new yd.Name("jsonLen"),jsonPart:new yd.Name("jsonPart")};md.default=gd,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.extendErrors=e.resetErrorsCount=e.reportExtraError=e.reportError=e.keyword$DataError=e.keywordError=void 0;const t=Xu,n=nd,r=md;function i(e,n){const i=e.const("err",n);e.if(t._`${r.default.vErrors} === null`,()=>e.assign(r.default.vErrors,t._`[${i}]`),t._`${r.default.vErrors}.push(${i})`),e.code(t._`${r.default.errors}++`)}function s(e,n){const{gen:r,validateName:i,schemaEnv:s}=e;s.$async?r.throw(t._`new ${e.ValidationError}(${n})`):(r.assign(t._`${i}.errors`,n),r.return(!1))}e.keywordError={message:({keyword:e})=>t.str`must pass "${e}" keyword validation`},e.keyword$DataError={message:({keyword:e,schemaType:n})=>n?t.str`"${e}" keyword must be ${n} ($data)`:t.str`"${e}" keyword is invalid ($data)`},e.reportError=function(n,r=e.keywordError,a,c){const{it:A}=n,{gen:l,compositeRule:f,allErrors:u}=A,d=o(n,r,a);(null!=c?c:f||u)?i(l,d):s(A,t._`[${d}]`)},e.reportExtraError=function(t,n=e.keywordError,a){const{it:c}=t,{gen:A,compositeRule:l,allErrors:f}=c;i(A,o(t,n,a)),l||f||s(c,r.default.vErrors)},e.resetErrorsCount=function(e,n){e.assign(r.default.errors,n),e.if(t._`${r.default.vErrors} !== null`,()=>e.if(n,()=>e.assign(t._`${r.default.vErrors}.length`,n),()=>e.assign(r.default.vErrors,null)))},e.extendErrors=function({gen:e,keyword:n,schemaValue:i,data:s,errsCount:a,it:o}){if(void 0===a)throw new Error("ajv implementation error");const c=e.name("err");e.forRange("i",a,r.default.errors,a=>{e.const(c,t._`${r.default.vErrors}[${a}]`),e.if(t._`${c}.instancePath === undefined`,()=>e.assign(t._`${c}.instancePath`,(0,t.strConcat)(r.default.instancePath,o.errorPath))),e.assign(t._`${c}.schemaPath`,t.str`${o.errSchemaPath}/${n}`),o.opts.verbose&&(e.assign(t._`${c}.schema`,i),e.assign(t._`${c}.data`,s))})};const a={keyword:new t.Name("keyword"),schemaPath:new t.Name("schemaPath"),params:new t.Name("params"),propertyName:new t.Name("propertyName"),message:new t.Name("message"),schema:new t.Name("schema"),parentSchema:new t.Name("parentSchema")};function o(e,n,i){const{createErrors:s}=e.it;return!1===s?t._`{}`:function(e,n,i={}){const{gen:s,it:o}=e,l=[c(o,i),A(e,i)];return function(e,{params:n,message:i},s){const{keyword:o,data:c,schemaValue:A,it:l}=e,{opts:f,propertyName:u,topSchemaRef:d,schemaPath:h}=l;s.push([a.keyword,o],[a.params,"function"==typeof n?n(e):n||t._`{}`]),f.messages&&s.push([a.message,"function"==typeof i?i(e):i]),f.verbose&&s.push([a.schema,A],[a.parentSchema,t._`${d}${h}`],[r.default.data,c]),u&&s.push([a.propertyName,u])}(e,n,l),s.object(...l)}(e,n,i)}function c({errorPath:e},{instancePath:i}){const s=i?t.str`${e}${(0,n.getErrorPath)(i,n.Type.Str)}`:e;return[r.default.instancePath,(0,t.strConcat)(r.default.instancePath,s)]}function A({keyword:e,it:{errSchemaPath:r}},{schemaPath:i,parentSchema:s}){let o=s?r:t.str`${r}/${e}`;return i&&(o=t.str`${o}${(0,n.getErrorPath)(i,n.Type.Str)}`),[a.schemaPath,o]}}(Zu),Object.defineProperty(Yu,"__esModule",{value:!0}),Yu.boolOrEmptySchema=Yu.topBoolOrEmptySchema=void 0;const bd=Zu,wd=Xu,vd=md,_d={message:"boolean schema is false"};function Ed(e,t){const{gen:n,data:r}=e;(0,bd.reportError)({gen:n,keyword:"false schema",data:r,schema:!1,schemaCode:!1,schemaValue:!1,params:{},it:e},_d,void 0,t)}Yu.topBoolOrEmptySchema=function(e){const{gen:t,schema:n,validateName:r}=e;!1===n?Ed(e,!1):"object"==typeof n&&!0===n.$async?t.return(vd.default.data):(t.assign(wd._`${r}.errors`,null),t.return(!0))},Yu.boolOrEmptySchema=function(e,t){const{gen:n,schema:r}=e;!1===r?(n.var(t,!1),Ed(e)):n.var(t,!0)};var kd={},Td={};Object.defineProperty(Td,"__esModule",{value:!0}),Td.getRules=Td.isJSONType=void 0;const Sd=new Set(["string","number","integer","boolean","null","object","array"]);Td.isJSONType=function(e){return"string"==typeof e&&Sd.has(e)},Td.getRules=function(){const e={number:{type:"number",rules:[]},string:{type:"string",rules:[]},array:{type:"array",rules:[]},object:{type:"object",rules:[]}};return{types:{...e,integer:!0,boolean:!0,null:!0},rules:[{rules:[]},e.number,e.string,e.array,e.object],post:{rules:[]},all:{},keywords:{}}};var xd={};function Id(e,t){return t.rules.some(t=>Pd(e,t))}function Pd(e,t){var n;return void 0!==e[t.keyword]||(null===(n=t.definition.implements)||void 0===n?void 0:n.some(t=>void 0!==e[t]))}Object.defineProperty(xd,"__esModule",{value:!0}),xd.shouldUseRule=xd.shouldUseGroup=xd.schemaHasRulesForType=void 0,xd.schemaHasRulesForType=function({schema:e,self:t},n){const r=t.RULES.types[n];return r&&!0!==r&&Id(e,r)},xd.shouldUseGroup=Id,xd.shouldUseRule=Pd,Object.defineProperty(kd,"__esModule",{value:!0}),kd.reportTypeError=kd.checkDataTypes=kd.checkDataType=kd.coerceAndCheckDataType=kd.getJSONTypes=kd.getSchemaTypes=kd.DataType=void 0;const Cd=Td,Nd=xd,Od=Zu,Rd=Xu,Bd=nd;var Md,$d;function Dd(e){const t=Array.isArray(e)?e:e?[e]:[];if(t.every(Cd.isJSONType))return t;throw new Error("type must be JSONType or JSONType[]: "+t.join(","))}($d=Md||(kd.DataType=Md={}))[$d.Correct=0]="Correct",$d[$d.Wrong=1]="Wrong",kd.getSchemaTypes=function(e){const t=Dd(e.type);if(t.includes("null")){if(!1===e.nullable)throw new Error("type: null contradicts nullable: false")}else{if(!t.length&&void 0!==e.nullable)throw new Error('"nullable" cannot be used without "type"');!0===e.nullable&&t.push("null")}return t},kd.getJSONTypes=Dd,kd.coerceAndCheckDataType=function(e,t){const{gen:n,data:r,opts:i}=e,s=function(e,t){return t?e.filter(e=>Fd.has(e)||"array"===t&&"array"===e):[]}(t,i.coerceTypes),a=t.length>0&&!(0===s.length&&1===t.length&&(0,Nd.schemaHasRulesForType)(e,t[0]));if(a){const a=Ud(t,r,i.strictNumbers,Md.Wrong);n.if(a,()=>{s.length?function(e,t,n){const{gen:r,data:i,opts:s}=e,a=r.let("dataType",Rd._`typeof ${i}`),o=r.let("coerced",Rd._`undefined`);"array"===s.coerceTypes&&r.if(Rd._`${a} == 'object' && Array.isArray(${i}) && ${i}.length == 1`,()=>r.assign(i,Rd._`${i}[0]`).assign(a,Rd._`typeof ${i}`).if(Ud(t,i,s.strictNumbers),()=>r.assign(o,i))),r.if(Rd._`${o} !== undefined`);for(const A of n)(Fd.has(A)||"array"===A&&"array"===s.coerceTypes)&&c(A);function c(e){switch(e){case"string":return void r.elseIf(Rd._`${a} == "number" || ${a} == "boolean"`).assign(o,Rd._`"" + ${i}`).elseIf(Rd._`${i} === null`).assign(o,Rd._`""`);case"number":return void r.elseIf(Rd._`${a} == "boolean" || ${i} === null
15
+ || (${a} == "string" && ${i} && ${i} == +${i})`).assign(o,Rd._`+${i}`);case"integer":return void r.elseIf(Rd._`${a} === "boolean" || ${i} === null
16
+ || (${a} === "string" && ${i} && ${i} == +${i} && !(${i} % 1))`).assign(o,Rd._`+${i}`);case"boolean":return void r.elseIf(Rd._`${i} === "false" || ${i} === 0 || ${i} === null`).assign(o,!1).elseIf(Rd._`${i} === "true" || ${i} === 1`).assign(o,!0);case"null":return r.elseIf(Rd._`${i} === "" || ${i} === 0 || ${i} === false`),void r.assign(o,null);case"array":r.elseIf(Rd._`${a} === "string" || ${a} === "number"
17
+ || ${a} === "boolean" || ${i} === null`).assign(o,Rd._`[${i}]`)}}r.else(),jd(e),r.endIf(),r.if(Rd._`${o} !== undefined`,()=>{r.assign(i,o),function({gen:e,parentData:t,parentDataProperty:n},r){e.if(Rd._`${t} !== undefined`,()=>e.assign(Rd._`${t}[${n}]`,r))}(e,o)})}(e,t,s):jd(e)})}return a};const Fd=new Set(["string","number","integer","boolean","null"]);function Gd(e,t,n,r=Md.Correct){const i=r===Md.Correct?Rd.operators.EQ:Rd.operators.NEQ;let s;switch(e){case"null":return Rd._`${t} ${i} null`;case"array":s=Rd._`Array.isArray(${t})`;break;case"object":s=Rd._`${t} && typeof ${t} == "object" && !Array.isArray(${t})`;break;case"integer":s=a(Rd._`!(${t} % 1) && !isNaN(${t})`);break;case"number":s=a();break;default:return Rd._`typeof ${t} ${i} ${e}`}return r===Md.Correct?s:(0,Rd.not)(s);function a(e=Rd.nil){return(0,Rd.and)(Rd._`typeof ${t} == "number"`,e,n?Rd._`isFinite(${t})`:Rd.nil)}}function Ud(e,t,n,r){if(1===e.length)return Gd(e[0],t,n,r);let i;const s=(0,Bd.toHash)(e);if(s.array&&s.object){const e=Rd._`typeof ${t} != "object"`;i=s.null?e:Rd._`!${t} || ${e}`,delete s.null,delete s.array,delete s.object}else i=Rd.nil;s.number&&delete s.integer;for(const a in s)i=(0,Rd.and)(i,Gd(a,t,n,r));return i}kd.checkDataType=Gd,kd.checkDataTypes=Ud;const Ld={message:({schema:e})=>`must be ${e}`,params:({schema:e,schemaValue:t})=>"string"==typeof e?Rd._`{type: ${e}}`:Rd._`{type: ${t}}`};function jd(e){const t=function(e){const{gen:t,data:n,schema:r}=e,i=(0,Bd.schemaRefOrVal)(e,r,"type");return{gen:t,keyword:"type",data:n,schema:r.type,schemaCode:i,schemaValue:i,parentSchema:r,params:{},it:e}}(e);(0,Od.reportError)(t,Ld)}kd.reportTypeError=jd;var Hd={};Object.defineProperty(Hd,"__esModule",{value:!0}),Hd.assignDefaults=void 0;const zd=Xu,qd=nd;function Qd(e,t,n){const{gen:r,compositeRule:i,data:s,opts:a}=e;if(void 0===n)return;const o=zd._`${s}${(0,zd.getProperty)(t)}`;if(i)return void(0,qd.checkStrictMode)(e,`default is ignored for: ${o}`);let c=zd._`${o} === undefined`;"empty"===a.useDefaults&&(c=zd._`${c} || ${o} === null || ${o} === ""`),r.if(c,zd._`${o} = ${(0,zd.stringify)(n)}`)}Hd.assignDefaults=function(e,t){const{properties:n,items:r}=e.schema;if("object"===t&&n)for(const i in n)Qd(e,i,n[i].default);else"array"===t&&Array.isArray(r)&&r.forEach((t,n)=>Qd(e,n,t.default))};var Vd={},Jd={};Object.defineProperty(Jd,"__esModule",{value:!0}),Jd.validateUnion=Jd.validateArray=Jd.usePattern=Jd.callValidateCode=Jd.schemaProperties=Jd.allSchemaProperties=Jd.noPropertyInData=Jd.propertyInData=Jd.isOwnProperty=Jd.hasPropFunc=Jd.reportMissingProp=Jd.checkMissingProp=Jd.checkReportMissingProp=void 0;const Kd=Xu,Wd=nd,Yd=md,Zd=nd;function Xd(e){return e.scopeValue("func",{ref:Object.prototype.hasOwnProperty,code:Kd._`Object.prototype.hasOwnProperty`})}function eh(e,t,n){return Kd._`${Xd(e)}.call(${t}, ${n})`}function th(e,t,n,r){const i=Kd._`${t}${(0,Kd.getProperty)(n)} === undefined`;return r?(0,Kd.or)(i,(0,Kd.not)(eh(e,t,n))):i}function nh(e){return e?Object.keys(e).filter(e=>"__proto__"!==e):[]}Jd.checkReportMissingProp=function(e,t){const{gen:n,data:r,it:i}=e;n.if(th(n,r,t,i.opts.ownProperties),()=>{e.setParams({missingProperty:Kd._`${t}`},!0),e.error()})},Jd.checkMissingProp=function({gen:e,data:t,it:{opts:n}},r,i){return(0,Kd.or)(...r.map(r=>(0,Kd.and)(th(e,t,r,n.ownProperties),Kd._`${i} = ${r}`)))},Jd.reportMissingProp=function(e,t){e.setParams({missingProperty:t},!0),e.error()},Jd.hasPropFunc=Xd,Jd.isOwnProperty=eh,Jd.propertyInData=function(e,t,n,r){const i=Kd._`${t}${(0,Kd.getProperty)(n)} !== undefined`;return r?Kd._`${i} && ${eh(e,t,n)}`:i},Jd.noPropertyInData=th,Jd.allSchemaProperties=nh,Jd.schemaProperties=function(e,t){return nh(t).filter(n=>!(0,Wd.alwaysValidSchema)(e,t[n]))},Jd.callValidateCode=function({schemaCode:e,data:t,it:{gen:n,topSchemaRef:r,schemaPath:i,errorPath:s},it:a},o,c,A){const l=A?Kd._`${e}, ${t}, ${r}${i}`:t,f=[[Yd.default.instancePath,(0,Kd.strConcat)(Yd.default.instancePath,s)],[Yd.default.parentData,a.parentData],[Yd.default.parentDataProperty,a.parentDataProperty],[Yd.default.rootData,Yd.default.rootData]];a.opts.dynamicRef&&f.push([Yd.default.dynamicAnchors,Yd.default.dynamicAnchors]);const u=Kd._`${l}, ${n.object(...f)}`;return c!==Kd.nil?Kd._`${o}.call(${c}, ${u})`:Kd._`${o}(${u})`};const rh=Kd._`new RegExp`;Jd.usePattern=function({gen:e,it:{opts:t}},n){const r=t.unicodeRegExp?"u":"",{regExp:i}=t.code,s=i(n,r);return e.scopeValue("pattern",{key:s.toString(),ref:s,code:Kd._`${"new RegExp"===i.code?rh:(0,Zd.useFunc)(e,i)}(${n}, ${r})`})},Jd.validateArray=function(e){const{gen:t,data:n,keyword:r,it:i}=e,s=t.name("valid");if(i.allErrors){const e=t.let("valid",!0);return a(()=>t.assign(e,!1)),e}return t.var(s,!0),a(()=>t.break()),s;function a(i){const a=t.const("len",Kd._`${n}.length`);t.forRange("i",0,a,n=>{e.subschema({keyword:r,dataProp:n,dataPropType:Wd.Type.Num},s),t.if((0,Kd.not)(s),i)})}},Jd.validateUnion=function(e){const{gen:t,schema:n,keyword:r,it:i}=e;if(!Array.isArray(n))throw new Error("ajv implementation error");if(n.some(e=>(0,Wd.alwaysValidSchema)(i,e))&&!i.opts.unevaluated)return;const s=t.let("valid",!1),a=t.name("_valid");t.block(()=>n.forEach((n,i)=>{const o=e.subschema({keyword:r,schemaProp:i,compositeRule:!0},a);t.assign(s,Kd._`${s} || ${a}`),e.mergeValidEvaluated(o,a)||t.if((0,Kd.not)(s))})),e.result(s,()=>e.reset(),()=>e.error(!0))},Object.defineProperty(Vd,"__esModule",{value:!0}),Vd.validateKeywordUsage=Vd.validSchemaType=Vd.funcKeywordCode=Vd.macroKeywordCode=void 0;const ih=Xu,sh=md,ah=Jd,oh=Zu;function ch(e){const{gen:t,data:n,it:r}=e;t.if(r.parentData,()=>t.assign(n,ih._`${r.parentData}[${r.parentDataProperty}]`))}function Ah(e,t,n){if(void 0===n)throw new Error(`keyword "${t}" failed to compile`);return e.scopeValue("keyword","function"==typeof n?{ref:n}:{ref:n,code:(0,ih.stringify)(n)})}Vd.macroKeywordCode=function(e,t){const{gen:n,keyword:r,schema:i,parentSchema:s,it:a}=e,o=t.macro.call(a.self,i,s,a),c=Ah(n,r,o);!1!==a.opts.validateSchema&&a.self.validateSchema(o,!0);const A=n.name("valid");e.subschema({schema:o,schemaPath:ih.nil,errSchemaPath:`${a.errSchemaPath}/${r}`,topSchemaRef:c,compositeRule:!0},A),e.pass(A,()=>e.error(!0))},Vd.funcKeywordCode=function(e,t){var n;const{gen:r,keyword:i,schema:s,parentSchema:a,$data:o,it:c}=e;!function({schemaEnv:e},t){if(t.async&&!e.$async)throw new Error("async keyword in sync schema")}(c,t);const A=!o&&t.compile?t.compile.call(c.self,s,a,c):t.validate,l=Ah(r,i,A),f=r.let("valid");function u(n=(t.async?ih._`await `:ih.nil)){const i=c.opts.passContext?sh.default.this:sh.default.self,s=!("compile"in t&&!o||!1===t.schema);r.assign(f,ih._`${n}${(0,ah.callValidateCode)(e,l,i,s)}`,t.modifying)}function d(e){var n;r.if((0,ih.not)(null!==(n=t.valid)&&void 0!==n?n:f),e)}e.block$data(f,function(){if(!1===t.errors)u(),t.modifying&&ch(e),d(()=>e.error());else{const n=t.async?function(){const e=r.let("ruleErrs",null);return r.try(()=>u(ih._`await `),t=>r.assign(f,!1).if(ih._`${t} instanceof ${c.ValidationError}`,()=>r.assign(e,ih._`${t}.errors`),()=>r.throw(t))),e}():function(){const e=ih._`${l}.errors`;return r.assign(e,null),u(ih.nil),e}();t.modifying&&ch(e),d(()=>function(e,t){const{gen:n}=e;n.if(ih._`Array.isArray(${t})`,()=>{n.assign(sh.default.vErrors,ih._`${sh.default.vErrors} === null ? ${t} : ${sh.default.vErrors}.concat(${t})`).assign(sh.default.errors,ih._`${sh.default.vErrors}.length`),(0,oh.extendErrors)(e)},()=>e.error())}(e,n))}}),e.ok(null!==(n=t.valid)&&void 0!==n?n:f)},Vd.validSchemaType=function(e,t,n=!1){return!t.length||t.some(t=>"array"===t?Array.isArray(e):"object"===t?e&&"object"==typeof e&&!Array.isArray(e):typeof e==t||n&&void 0===e)},Vd.validateKeywordUsage=function({schema:e,opts:t,self:n,errSchemaPath:r},i,s){if(Array.isArray(i.keyword)?!i.keyword.includes(s):i.keyword!==s)throw new Error("ajv implementation error");const a=i.dependencies;if(null==a?void 0:a.some(t=>!Object.prototype.hasOwnProperty.call(e,t)))throw new Error(`parent schema must have dependencies of ${s}: ${a.join(",")}`);if(i.validateSchema&&!i.validateSchema(e[s])){const e=`keyword "${s}" value is invalid at path "${r}": `+n.errorsText(i.validateSchema.errors);if("log"!==t.validateSchema)throw new Error(e);n.logger.error(e)}};var lh={};Object.defineProperty(lh,"__esModule",{value:!0}),lh.extendSubschemaMode=lh.extendSubschemaData=lh.getSubschema=void 0;const fh=Xu,uh=nd;lh.getSubschema=function(e,{keyword:t,schemaProp:n,schema:r,schemaPath:i,errSchemaPath:s,topSchemaRef:a}){if(void 0!==t&&void 0!==r)throw new Error('both "keyword" and "schema" passed, only one allowed');if(void 0!==t){const r=e.schema[t];return void 0===n?{schema:r,schemaPath:fh._`${e.schemaPath}${(0,fh.getProperty)(t)}`,errSchemaPath:`${e.errSchemaPath}/${t}`}:{schema:r[n],schemaPath:fh._`${e.schemaPath}${(0,fh.getProperty)(t)}${(0,fh.getProperty)(n)}`,errSchemaPath:`${e.errSchemaPath}/${t}/${(0,uh.escapeFragment)(n)}`}}if(void 0!==r){if(void 0===i||void 0===s||void 0===a)throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');return{schema:r,schemaPath:i,topSchemaRef:a,errSchemaPath:s}}throw new Error('either "keyword" or "schema" must be passed')},lh.extendSubschemaData=function(e,t,{dataProp:n,dataPropType:r,data:i,dataTypes:s,propertyName:a}){if(void 0!==i&&void 0!==n)throw new Error('both "data" and "dataProp" passed, only one allowed');const{gen:o}=t;if(void 0!==n){const{errorPath:i,dataPathArr:s,opts:a}=t;c(o.let("data",fh._`${t.data}${(0,fh.getProperty)(n)}`,!0)),e.errorPath=fh.str`${i}${(0,uh.getErrorPath)(n,r,a.jsPropertySyntax)}`,e.parentDataProperty=fh._`${n}`,e.dataPathArr=[...s,e.parentDataProperty]}function c(n){e.data=n,e.dataLevel=t.dataLevel+1,e.dataTypes=[],t.definedProperties=new Set,e.parentData=t.data,e.dataNames=[...t.dataNames,n]}void 0!==i&&(c(i instanceof fh.Name?i:o.let("data",i,!0)),void 0!==a&&(e.propertyName=a)),s&&(e.dataTypes=s)},lh.extendSubschemaMode=function(e,{jtdDiscriminator:t,jtdMetadata:n,compositeRule:r,createErrors:i,allErrors:s}){void 0!==r&&(e.compositeRule=r),void 0!==i&&(e.createErrors=i),void 0!==s&&(e.allErrors=s),e.jtdDiscriminator=t,e.jtdMetadata=n};var dh={},hh=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var r,i,s;if(Array.isArray(t)){if((r=t.length)!=n.length)return!1;for(i=r;0!==i--;)if(!e(t[i],n[i]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((r=(s=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(i=r;0!==i--;)if(!Object.prototype.hasOwnProperty.call(n,s[i]))return!1;for(i=r;0!==i--;){var a=s[i];if(!e(t[a],n[a]))return!1}return!0}return t!=t&&n!=n},ph={exports:{}},mh=ph.exports=function(e,t,n){"function"==typeof t&&(n=t,t={}),yh(t,"function"==typeof(n=t.cb||n)?n:n.pre||function(){},n.post||function(){},e,"",e)};function yh(e,t,n,r,i,s,a,o,c,A){if(r&&"object"==typeof r&&!Array.isArray(r)){for(var l in t(r,i,s,a,o,c,A),r){var f=r[l];if(Array.isArray(f)){if(l in mh.arrayKeywords)for(var u=0;u<f.length;u++)yh(e,t,n,f[u],i+"/"+l+"/"+u,s,i,l,r,u)}else if(l in mh.propsKeywords){if(f&&"object"==typeof f)for(var d in f)yh(e,t,n,f[d],i+"/"+l+"/"+gh(d),s,i,l,r,d)}else(l in mh.keywords||e.allKeys&&!(l in mh.skipKeywords))&&yh(e,t,n,f,i+"/"+l,s,i,l,r)}n(r,i,s,a,o,c,A)}}function gh(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}mh.keywords={additionalItems:!0,items:!0,contains:!0,additionalProperties:!0,propertyNames:!0,not:!0,if:!0,then:!0,else:!0},mh.arrayKeywords={items:!0,allOf:!0,anyOf:!0,oneOf:!0},mh.propsKeywords={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependencies:!0},mh.skipKeywords={default:!0,enum:!0,const:!0,required:!0,maximum:!0,minimum:!0,exclusiveMaximum:!0,exclusiveMinimum:!0,multipleOf:!0,maxLength:!0,minLength:!0,pattern:!0,format:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxProperties:!0,minProperties:!0};var bh=ph.exports;Object.defineProperty(dh,"__esModule",{value:!0}),dh.getSchemaRefs=dh.resolveUrl=dh.normalizeId=dh._getFullPath=dh.getFullPath=dh.inlineRef=void 0;const wh=nd,vh=hh,_h=bh,Eh=new Set(["type","format","pattern","maxLength","minLength","maxProperties","minProperties","maxItems","minItems","maximum","minimum","uniqueItems","multipleOf","required","enum","const"]);dh.inlineRef=function(e,t=!0){return"boolean"==typeof e||(!0===t?!Th(e):!!t&&Sh(e)<=t)};const kh=new Set(["$ref","$recursiveRef","$recursiveAnchor","$dynamicRef","$dynamicAnchor"]);function Th(e){for(const t in e){if(kh.has(t))return!0;const n=e[t];if(Array.isArray(n)&&n.some(Th))return!0;if("object"==typeof n&&Th(n))return!0}return!1}function Sh(e){let t=0;for(const n in e){if("$ref"===n)return 1/0;if(t++,!Eh.has(n)&&("object"==typeof e[n]&&(0,wh.eachItem)(e[n],e=>t+=Sh(e)),t===1/0))return 1/0}return t}function xh(e,t="",n){!1!==n&&(t=Ch(t));const r=e.parse(t);return Ih(e,r)}function Ih(e,t){return e.serialize(t).split("#")[0]+"#"}dh.getFullPath=xh,dh._getFullPath=Ih;const Ph=/#\/?$/;function Ch(e){return e?e.replace(Ph,""):""}dh.normalizeId=Ch,dh.resolveUrl=function(e,t,n){return n=Ch(n),e.resolve(t,n)};const Nh=/^[a-z_][-a-z0-9._]*$/i;dh.getSchemaRefs=function(e,t){if("boolean"==typeof e)return{};const{schemaId:n,uriResolver:r}=this.opts,i=Ch(e[n]||t),s={"":i},a=xh(r,i,!1),o={},c=new Set;return _h(e,{allKeys:!0},(e,t,r,i)=>{if(void 0===i)return;const f=a+t;let u=s[i];function d(t){const n=this.opts.uriResolver.resolve;if(t=Ch(u?n(u,t):t),c.has(t))throw l(t);c.add(t);let r=this.refs[t];return"string"==typeof r&&(r=this.refs[r]),"object"==typeof r?A(e,r.schema,t):t!==Ch(f)&&("#"===t[0]?(A(e,o[t],t),o[t]=e):this.refs[t]=f),t}function h(e){if("string"==typeof e){if(!Nh.test(e))throw new Error(`invalid anchor "${e}"`);d.call(this,`#${e}`)}}"string"==typeof e[n]&&(u=d.call(this,e[n])),h.call(this,e.$anchor),h.call(this,e.$dynamicAnchor),s[t]=u}),o;function A(e,t,n){if(void 0!==t&&!vh(e,t))throw l(n)}function l(e){return new Error(`reference "${e}" resolves to more than one schema`)}},Object.defineProperty(Wu,"__esModule",{value:!0}),Wu.getData=Wu.KeywordCxt=Wu.validateFunctionCode=void 0;const Oh=Yu,Rh=kd,Bh=xd,Mh=kd,$h=Hd,Dh=Vd,Fh=lh,Gh=Xu,Uh=md,Lh=dh,jh=nd,Hh=Zu;function zh({gen:e,validateName:t,schema:n,schemaEnv:r,opts:i},s){i.code.es5?e.func(t,Gh._`${Uh.default.data}, ${Uh.default.valCxt}`,r.$async,()=>{e.code(Gh._`"use strict"; ${qh(n,i)}`),function(e,t){e.if(Uh.default.valCxt,()=>{e.var(Uh.default.instancePath,Gh._`${Uh.default.valCxt}.${Uh.default.instancePath}`),e.var(Uh.default.parentData,Gh._`${Uh.default.valCxt}.${Uh.default.parentData}`),e.var(Uh.default.parentDataProperty,Gh._`${Uh.default.valCxt}.${Uh.default.parentDataProperty}`),e.var(Uh.default.rootData,Gh._`${Uh.default.valCxt}.${Uh.default.rootData}`),t.dynamicRef&&e.var(Uh.default.dynamicAnchors,Gh._`${Uh.default.valCxt}.${Uh.default.dynamicAnchors}`)},()=>{e.var(Uh.default.instancePath,Gh._`""`),e.var(Uh.default.parentData,Gh._`undefined`),e.var(Uh.default.parentDataProperty,Gh._`undefined`),e.var(Uh.default.rootData,Uh.default.data),t.dynamicRef&&e.var(Uh.default.dynamicAnchors,Gh._`{}`)})}(e,i),e.code(s)}):e.func(t,Gh._`${Uh.default.data}, ${function(e){return Gh._`{${Uh.default.instancePath}="", ${Uh.default.parentData}, ${Uh.default.parentDataProperty}, ${Uh.default.rootData}=${Uh.default.data}${e.dynamicRef?Gh._`, ${Uh.default.dynamicAnchors}={}`:Gh.nil}}={}`}(i)}`,r.$async,()=>e.code(qh(n,i)).code(s))}function qh(e,t){const n="object"==typeof e&&e[t.schemaId];return n&&(t.code.source||t.code.process)?Gh._`/*# sourceURL=${n} */`:Gh.nil}function Qh({schema:e,self:t}){if("boolean"==typeof e)return!e;for(const n in e)if(t.RULES.all[n])return!0;return!1}function Vh(e){return"boolean"!=typeof e.schema}function Jh(e){(0,jh.checkUnknownRules)(e),function(e){const{schema:t,errSchemaPath:n,opts:r,self:i}=e;t.$ref&&r.ignoreKeywordsWithRef&&(0,jh.schemaHasRulesButRef)(t,i.RULES)&&i.logger.warn(`$ref: keywords ignored in schema at path "${n}"`)}(e)}function Kh(e,t){if(e.opts.jtd)return Yh(e,[],!1,t);const n=(0,Rh.getSchemaTypes)(e.schema);Yh(e,n,!(0,Rh.coerceAndCheckDataType)(e,n),t)}function Wh({gen:e,schemaEnv:t,schema:n,errSchemaPath:r,opts:i}){const s=n.$comment;if(!0===i.$comment)e.code(Gh._`${Uh.default.self}.logger.log(${s})`);else if("function"==typeof i.$comment){const n=Gh.str`${r}/$comment`,i=e.scopeValue("root",{ref:t.root});e.code(Gh._`${Uh.default.self}.opts.$comment(${s}, ${n}, ${i}.schema)`)}}function Yh(e,t,n,r){const{gen:i,schema:s,data:a,allErrors:o,opts:c,self:A}=e,{RULES:l}=A;function f(A){(0,Bh.shouldUseGroup)(s,A)&&(A.type?(i.if((0,Mh.checkDataType)(A.type,a,c.strictNumbers)),Zh(e,A),1===t.length&&t[0]===A.type&&n&&(i.else(),(0,Mh.reportTypeError)(e)),i.endIf()):Zh(e,A),o||i.if(Gh._`${Uh.default.errors} === ${r||0}`))}!s.$ref||!c.ignoreKeywordsWithRef&&(0,jh.schemaHasRulesButRef)(s,l)?(c.jtd||function(e,t){!e.schemaEnv.meta&&e.opts.strictTypes&&(function(e,t){t.length&&(e.dataTypes.length?(t.forEach(t=>{Xh(e.dataTypes,t)||ep(e,`type "${t}" not allowed by context "${e.dataTypes.join(",")}"`)}),function(e,t){const n=[];for(const r of e.dataTypes)Xh(t,r)?n.push(r):t.includes("integer")&&"number"===r&&n.push("integer");e.dataTypes=n}(e,t)):e.dataTypes=t)}(e,t),e.opts.allowUnionTypes||function(e,t){t.length>1&&(2!==t.length||!t.includes("null"))&&ep(e,"use allowUnionTypes to allow union type keyword")}(e,t),function(e,t){const n=e.self.RULES.all;for(const r in n){const i=n[r];if("object"==typeof i&&(0,Bh.shouldUseRule)(e.schema,i)){const{type:n}=i.definition;n.length&&!n.some(e=>{return r=e,(n=t).includes(r)||"number"===r&&n.includes("integer");var n,r})&&ep(e,`missing type "${n.join(",")}" for keyword "${r}"`)}}}(e,e.dataTypes))}(e,t),i.block(()=>{for(const e of l.rules)f(e);f(l.post)})):i.block(()=>np(e,"$ref",l.all.$ref.definition))}function Zh(e,t){const{gen:n,schema:r,opts:{useDefaults:i}}=e;i&&(0,$h.assignDefaults)(e,t.type),n.block(()=>{for(const n of t.rules)(0,Bh.shouldUseRule)(r,n)&&np(e,n.keyword,n.definition,t.type)})}function Xh(e,t){return e.includes(t)||"integer"===t&&e.includes("number")}function ep(e,t){t+=` at "${e.schemaEnv.baseId+e.errSchemaPath}" (strictTypes)`,(0,jh.checkStrictMode)(e,t,e.opts.strictTypes)}Wu.validateFunctionCode=function(e){Vh(e)&&(Jh(e),Qh(e))?function(e){const{schema:t,opts:n,gen:r}=e;zh(e,()=>{n.$comment&&t.$comment&&Wh(e),function(e){const{schema:t,opts:n}=e;void 0!==t.default&&n.useDefaults&&n.strictSchema&&(0,jh.checkStrictMode)(e,"default is ignored in the schema root")}(e),r.let(Uh.default.vErrors,null),r.let(Uh.default.errors,0),n.unevaluated&&function(e){const{gen:t,validateName:n}=e;e.evaluated=t.const("evaluated",Gh._`${n}.evaluated`),t.if(Gh._`${e.evaluated}.dynamicProps`,()=>t.assign(Gh._`${e.evaluated}.props`,Gh._`undefined`)),t.if(Gh._`${e.evaluated}.dynamicItems`,()=>t.assign(Gh._`${e.evaluated}.items`,Gh._`undefined`))}(e),Kh(e),function(e){const{gen:t,schemaEnv:n,validateName:r,ValidationError:i,opts:s}=e;n.$async?t.if(Gh._`${Uh.default.errors} === 0`,()=>t.return(Uh.default.data),()=>t.throw(Gh._`new ${i}(${Uh.default.vErrors})`)):(t.assign(Gh._`${r}.errors`,Uh.default.vErrors),s.unevaluated&&function({gen:e,evaluated:t,props:n,items:r}){n instanceof Gh.Name&&e.assign(Gh._`${t}.props`,n),r instanceof Gh.Name&&e.assign(Gh._`${t}.items`,r)}(e),t.return(Gh._`${Uh.default.errors} === 0`))}(e)})}(e):zh(e,()=>(0,Oh.topBoolOrEmptySchema)(e))};class tp{constructor(e,t,n){if((0,Dh.validateKeywordUsage)(e,t,n),this.gen=e.gen,this.allErrors=e.allErrors,this.keyword=n,this.data=e.data,this.schema=e.schema[n],this.$data=t.$data&&e.opts.$data&&this.schema&&this.schema.$data,this.schemaValue=(0,jh.schemaRefOrVal)(e,this.schema,n,this.$data),this.schemaType=t.schemaType,this.parentSchema=e.schema,this.params={},this.it=e,this.def=t,this.$data)this.schemaCode=e.gen.const("vSchema",sp(this.$data,e));else if(this.schemaCode=this.schemaValue,!(0,Dh.validSchemaType)(this.schema,t.schemaType,t.allowUndefined))throw new Error(`${n} value must be ${JSON.stringify(t.schemaType)}`);("code"in t?t.trackErrors:!1!==t.errors)&&(this.errsCount=e.gen.const("_errs",Uh.default.errors))}result(e,t,n){this.failResult((0,Gh.not)(e),t,n)}failResult(e,t,n){this.gen.if(e),n?n():this.error(),t?(this.gen.else(),t(),this.allErrors&&this.gen.endIf()):this.allErrors?this.gen.endIf():this.gen.else()}pass(e,t){this.failResult((0,Gh.not)(e),void 0,t)}fail(e){if(void 0===e)return this.error(),void(this.allErrors||this.gen.if(!1));this.gen.if(e),this.error(),this.allErrors?this.gen.endIf():this.gen.else()}fail$data(e){if(!this.$data)return this.fail(e);const{schemaCode:t}=this;this.fail(Gh._`${t} !== undefined && (${(0,Gh.or)(this.invalid$data(),e)})`)}error(e,t,n){if(t)return this.setParams(t),this._error(e,n),void this.setParams({});this._error(e,n)}_error(e,t){(e?Hh.reportExtraError:Hh.reportError)(this,this.def.error,t)}$dataError(){(0,Hh.reportError)(this,this.def.$dataError||Hh.keyword$DataError)}reset(){if(void 0===this.errsCount)throw new Error('add "trackErrors" to keyword definition');(0,Hh.resetErrorsCount)(this.gen,this.errsCount)}ok(e){this.allErrors||this.gen.if(e)}setParams(e,t){t?Object.assign(this.params,e):this.params=e}block$data(e,t,n=Gh.nil){this.gen.block(()=>{this.check$data(e,n),t()})}check$data(e=Gh.nil,t=Gh.nil){if(!this.$data)return;const{gen:n,schemaCode:r,schemaType:i,def:s}=this;n.if((0,Gh.or)(Gh._`${r} === undefined`,t)),e!==Gh.nil&&n.assign(e,!0),(i.length||s.validateSchema)&&(n.elseIf(this.invalid$data()),this.$dataError(),e!==Gh.nil&&n.assign(e,!1)),n.else()}invalid$data(){const{gen:e,schemaCode:t,schemaType:n,def:r,it:i}=this;return(0,Gh.or)(function(){if(n.length){if(!(t instanceof Gh.Name))throw new Error("ajv implementation error");const e=Array.isArray(n)?n:[n];return Gh._`${(0,Mh.checkDataTypes)(e,t,i.opts.strictNumbers,Mh.DataType.Wrong)}`}return Gh.nil}(),function(){if(r.validateSchema){const n=e.scopeValue("validate$data",{ref:r.validateSchema});return Gh._`!${n}(${t})`}return Gh.nil}())}subschema(e,t){const n=(0,Fh.getSubschema)(this.it,e);(0,Fh.extendSubschemaData)(n,this.it,e),(0,Fh.extendSubschemaMode)(n,e);const r={...this.it,...n,items:void 0,props:void 0};return function(e,t){Vh(e)&&(Jh(e),Qh(e))?function(e,t){const{schema:n,gen:r,opts:i}=e;i.$comment&&n.$comment&&Wh(e),function(e){const t=e.schema[e.opts.schemaId];t&&(e.baseId=(0,Lh.resolveUrl)(e.opts.uriResolver,e.baseId,t))}(e),function(e){if(e.schema.$async&&!e.schemaEnv.$async)throw new Error("async schema in sync schema")}(e);const s=r.const("_errs",Uh.default.errors);Kh(e,s),r.var(t,Gh._`${s} === ${Uh.default.errors}`)}(e,t):(0,Oh.boolOrEmptySchema)(e,t)}(r,t),r}mergeEvaluated(e,t){const{it:n,gen:r}=this;n.opts.unevaluated&&(!0!==n.props&&void 0!==e.props&&(n.props=jh.mergeEvaluated.props(r,e.props,n.props,t)),!0!==n.items&&void 0!==e.items&&(n.items=jh.mergeEvaluated.items(r,e.items,n.items,t)))}mergeValidEvaluated(e,t){const{it:n,gen:r}=this;if(n.opts.unevaluated&&(!0!==n.props||!0!==n.items))return r.if(t,()=>this.mergeEvaluated(e,Gh.Name)),!0}}function np(e,t,n,r){const i=new tp(e,n,t);"code"in n?n.code(i,r):i.$data&&n.validate?(0,Dh.funcKeywordCode)(i,n):"macro"in n?(0,Dh.macroKeywordCode)(i,n):(n.compile||n.validate)&&(0,Dh.funcKeywordCode)(i,n)}Wu.KeywordCxt=tp;const rp=/^\/(?:[^~]|~0|~1)*$/,ip=/^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;function sp(e,{dataLevel:t,dataNames:n,dataPathArr:r}){let i,s;if(""===e)return Uh.default.rootData;if("/"===e[0]){if(!rp.test(e))throw new Error(`Invalid JSON-pointer: ${e}`);i=e,s=Uh.default.rootData}else{const a=ip.exec(e);if(!a)throw new Error(`Invalid JSON-pointer: ${e}`);const o=+a[1];if(i=a[2],"#"===i){if(o>=t)throw new Error(c("property/index",o));return r[t-o]}if(o>t)throw new Error(c("data",o));if(s=n[t-o],!i)return s}let a=s;const o=i.split("/");for(const A of o)A&&(s=Gh._`${s}${(0,Gh.getProperty)((0,jh.unescapeJsonPointer)(A))}`,a=Gh._`${a} && ${s}`);return a;function c(e,n){return`Cannot access ${e} ${n} levels up, current level is ${t}`}}Wu.getData=sp;var ap={};Object.defineProperty(ap,"__esModule",{value:!0});let op=class extends Error{constructor(e){super("validation failed"),this.errors=e,this.ajv=this.validation=!0}};ap.default=op;var cp={};Object.defineProperty(cp,"__esModule",{value:!0});const Ap=dh;class lp extends Error{constructor(e,t,n,r){super(r||`can't resolve reference ${n} from id ${t}`),this.missingRef=(0,Ap.resolveUrl)(e,t,n),this.missingSchema=(0,Ap.normalizeId)((0,Ap.getFullPath)(e,this.missingRef))}}cp.default=lp;var fp={};Object.defineProperty(fp,"__esModule",{value:!0}),fp.resolveSchema=fp.getCompilingSchema=fp.resolveRef=fp.compileSchema=fp.SchemaEnv=void 0;const up=Xu,dp=ap,hp=md,pp=dh,mp=nd,yp=Wu;class gp{constructor(e){var t;let n;this.refs={},this.dynamicAnchors={},"object"==typeof e.schema&&(n=e.schema),this.schema=e.schema,this.schemaId=e.schemaId,this.root=e.root||this,this.baseId=null!==(t=e.baseId)&&void 0!==t?t:(0,pp.normalizeId)(null==n?void 0:n[e.schemaId||"$id"]),this.schemaPath=e.schemaPath,this.localRefs=e.localRefs,this.meta=e.meta,this.$async=null==n?void 0:n.$async,this.refs={}}}function bp(e){const t=vp.call(this,e);if(t)return t;const n=(0,pp.getFullPath)(this.opts.uriResolver,e.root.baseId),{es5:r,lines:i}=this.opts.code,{ownProperties:s}=this.opts,a=new up.CodeGen(this.scope,{es5:r,lines:i,ownProperties:s});let o;e.$async&&(o=a.scopeValue("Error",{ref:dp.default,code:up._`require("ajv/dist/runtime/validation_error").default`}));const c=a.scopeName("validate");e.validateName=c;const A={gen:a,allErrors:this.opts.allErrors,data:hp.default.data,parentData:hp.default.parentData,parentDataProperty:hp.default.parentDataProperty,dataNames:[hp.default.data],dataPathArr:[up.nil],dataLevel:0,dataTypes:[],definedProperties:new Set,topSchemaRef:a.scopeValue("schema",!0===this.opts.code.source?{ref:e.schema,code:(0,up.stringify)(e.schema)}:{ref:e.schema}),validateName:c,ValidationError:o,schema:e.schema,schemaEnv:e,rootId:n,baseId:e.baseId||n,schemaPath:up.nil,errSchemaPath:e.schemaPath||(this.opts.jtd?"":"#"),errorPath:up._`""`,opts:this.opts,self:this};let l;try{this._compilations.add(e),(0,yp.validateFunctionCode)(A),a.optimize(this.opts.code.optimize);const t=a.toString();l=`${a.scopeRefs(hp.default.scope)}return ${t}`,this.opts.code.process&&(l=this.opts.code.process(l,e));const n=new Function(`${hp.default.self}`,`${hp.default.scope}`,l)(this,this.scope.get());if(this.scope.value(c,{ref:n}),n.errors=null,n.schema=e.schema,n.schemaEnv=e,e.$async&&(n.$async=!0),!0===this.opts.code.source&&(n.source={validateName:c,validateCode:t,scopeValues:a._values}),this.opts.unevaluated){const{props:e,items:t}=A;n.evaluated={props:e instanceof up.Name?void 0:e,items:t instanceof up.Name?void 0:t,dynamicProps:e instanceof up.Name,dynamicItems:t instanceof up.Name},n.source&&(n.source.evaluated=(0,up.stringify)(n.evaluated))}return e.validate=n,e}catch(f){throw delete e.validate,delete e.validateName,l&&this.logger.error("Error compiling schema, function code:",l),f}finally{this._compilations.delete(e)}}function wp(e){return(0,pp.inlineRef)(e.schema,this.opts.inlineRefs)?e.schema:e.validate?e:bp.call(this,e)}function vp(e){for(const t of this._compilations)if(_p(t,e))return t}function _p(e,t){return e.schema===t.schema&&e.root===t.root&&e.baseId===t.baseId}function Ep(e,t){let n;for(;"string"==typeof(n=this.refs[t]);)t=n;return n||this.schemas[t]||kp.call(this,e,t)}function kp(e,t){const n=this.opts.uriResolver.parse(t),r=(0,pp._getFullPath)(this.opts.uriResolver,n);let i=(0,pp.getFullPath)(this.opts.uriResolver,e.baseId,void 0);if(Object.keys(e.schema).length>0&&r===i)return Sp.call(this,n,e);const s=(0,pp.normalizeId)(r),a=this.refs[s]||this.schemas[s];if("string"==typeof a){const t=kp.call(this,e,a);if("object"!=typeof(null==t?void 0:t.schema))return;return Sp.call(this,n,t)}if("object"==typeof(null==a?void 0:a.schema)){if(a.validate||bp.call(this,a),s===(0,pp.normalizeId)(t)){const{schema:t}=a,{schemaId:n}=this.opts,r=t[n];return r&&(i=(0,pp.resolveUrl)(this.opts.uriResolver,i,r)),new gp({schema:t,schemaId:n,root:e,baseId:i})}return Sp.call(this,n,a)}}fp.SchemaEnv=gp,fp.compileSchema=bp,fp.resolveRef=function(e,t,n){var r;n=(0,pp.resolveUrl)(this.opts.uriResolver,t,n);const i=e.refs[n];if(i)return i;let s=Ep.call(this,e,n);if(void 0===s){const i=null===(r=e.localRefs)||void 0===r?void 0:r[n],{schemaId:a}=this.opts;i&&(s=new gp({schema:i,schemaId:a,root:e,baseId:t}))}return void 0!==s?e.refs[n]=wp.call(this,s):void 0},fp.getCompilingSchema=vp,fp.resolveSchema=kp;const Tp=new Set(["properties","patternProperties","enum","dependencies","definitions"]);function Sp(e,{baseId:t,schema:n,root:r}){var i;if("/"!==(null===(i=e.fragment)||void 0===i?void 0:i[0]))return;for(const o of e.fragment.slice(1).split("/")){if("boolean"==typeof n)return;const e=n[(0,mp.unescapeFragment)(o)];if(void 0===e)return;const r="object"==typeof(n=e)&&n[this.opts.schemaId];!Tp.has(o)&&r&&(t=(0,pp.resolveUrl)(this.opts.uriResolver,t,r))}let s;if("boolean"!=typeof n&&n.$ref&&!(0,mp.schemaHasRulesButRef)(n,this.RULES)){const e=(0,pp.resolveUrl)(this.opts.uriResolver,t,n.$ref);s=kp.call(this,r,e)}const{schemaId:a}=this.opts;return s=s||new gp({schema:n,schemaId:a,root:r,baseId:t}),s.schema!==s.root.schema?s:void 0}const xp={$id:"https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#",description:"Meta-schema for $data reference (JSON AnySchema extension proposal)",type:"object",required:["$data"],properties:{$data:{type:"string",anyOf:[{format:"relative-json-pointer"},{format:"json-pointer"}]}},additionalProperties:!1};var Ip={},Pp={exports:{}};const Cp=RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu),Np=RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u);function Op(e){let t="",n=0,r=0;for(r=0;r<e.length;r++)if(n=e[r].charCodeAt(0),48!==n){if(!(n>=48&&n<=57||n>=65&&n<=70||n>=97&&n<=102))return"";t+=e[r];break}for(r+=1;r<e.length;r++){if(n=e[r].charCodeAt(0),!(n>=48&&n<=57||n>=65&&n<=70||n>=97&&n<=102))return"";t+=e[r]}return t}function Rp(e){return e.length=0,!0}function Bp(e,t,n){if(e.length){const r=Op(e);if(""===r)return n.error=!0,!1;t.push(r),e.length=0}return!0}function Mp(e){if(function(e){let t=0;for(let n=0;n<e.length;n++)":"===e[n]&&t++;return t}(e)<2)return{host:e,isIPV6:!1};const t=function(e){let t=0;const n={error:!1,address:"",zone:""},r=[],i=[];let s=!1,a=!1,o=Bp;for(let c=0;c<e.length;c++){const A=e[c];if("["!==A&&"]"!==A)if(":"!==A)if("%"===A){if(!o(i,r,n))break;o=Rp}else i.push(A);else{if(!0===s&&(a=!0),!o(i,r,n))break;if(++t>7){n.error=!0;break}c>0&&":"===e[c-1]&&(s=!0),r.push(":")}}return i.length&&(o===Rp?n.zone=i.join(""):a?r.push(i.join("")):r.push(Op(i))),n.address=r.join(""),n}(e);if(t.error)return{host:e,isIPV6:!1};{let e=t.address,n=t.address;return t.zone&&(e+="%"+t.zone,n+="%25"+t.zone),{host:e,isIPV6:!0,escapedHost:n}}}var $p={nonSimpleDomain:RegExp.prototype.test.bind(/[^!"$&'()*+,\-.;=_`a-z{}~]/u),recomposeAuthority:function(e){const t=[];if(void 0!==e.userinfo&&(t.push(e.userinfo),t.push("@")),void 0!==e.host){let n=unescape(e.host);if(!Np(n)){const t=Mp(n);n=!0===t.isIPV6?`[${t.escapedHost}]`:e.host}t.push(n)}return"number"!=typeof e.port&&"string"!=typeof e.port||(t.push(":"),t.push(String(e.port))),t.length?t.join(""):void 0},normalizeComponentEncoding:function(e,t){const n=!0!==t?escape:unescape;return void 0!==e.scheme&&(e.scheme=n(e.scheme)),void 0!==e.userinfo&&(e.userinfo=n(e.userinfo)),void 0!==e.host&&(e.host=n(e.host)),void 0!==e.path&&(e.path=n(e.path)),void 0!==e.query&&(e.query=n(e.query)),void 0!==e.fragment&&(e.fragment=n(e.fragment)),e},removeDotSegments:function(e){let t=e;const n=[];let r=-1,i=0;for(;i=t.length;){if(1===i){if("."===t)break;if("/"===t){n.push("/");break}n.push(t);break}if(2===i){if("."===t[0]){if("."===t[1])break;if("/"===t[1]){t=t.slice(2);continue}}else if("/"===t[0]&&("."===t[1]||"/"===t[1])){n.push("/");break}}else if(3===i&&"/.."===t){0!==n.length&&n.pop(),n.push("/");break}if("."===t[0]){if("."===t[1]){if("/"===t[2]){t=t.slice(3);continue}}else if("/"===t[1]){t=t.slice(2);continue}}else if("/"===t[0]&&"."===t[1]){if("/"===t[2]){t=t.slice(2);continue}if("."===t[2]&&"/"===t[3]){t=t.slice(3),0!==n.length&&n.pop();continue}}if(-1===(r=t.indexOf("/",1))){n.push(t);break}n.push(t.slice(0,r)),t=t.slice(r)}return n.join("")},isIPv4:Np,isUUID:Cp,normalizeIPv6:Mp};const{isUUID:Dp}=$p,Fp=/([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-.:;=@]|%[\da-f]{2})+)/iu;function Gp(e){return!0===e.secure||!1!==e.secure&&!!e.scheme&&!(3!==e.scheme.length||"w"!==e.scheme[0]&&"W"!==e.scheme[0]||"s"!==e.scheme[1]&&"S"!==e.scheme[1]||"s"!==e.scheme[2]&&"S"!==e.scheme[2])}function Up(e){return e.host||(e.error=e.error||"HTTP URIs must have a host."),e}function Lp(e){const t="https"===String(e.scheme).toLowerCase();return e.port!==(t?443:80)&&""!==e.port||(e.port=void 0),e.path||(e.path="/"),e}const jp={scheme:"http",domainHost:!0,parse:Up,serialize:Lp},Hp={scheme:"ws",domainHost:!0,parse:function(e){return e.secure=Gp(e),e.resourceName=(e.path||"/")+(e.query?"?"+e.query:""),e.path=void 0,e.query=void 0,e},serialize:function(e){if(e.port!==(Gp(e)?443:80)&&""!==e.port||(e.port=void 0),"boolean"==typeof e.secure&&(e.scheme=e.secure?"wss":"ws",e.secure=void 0),e.resourceName){const[t,n]=e.resourceName.split("?");e.path=t&&"/"!==t?t:void 0,e.query=n,e.resourceName=void 0}return e.fragment=void 0,e}},zp={http:jp,https:{scheme:"https",domainHost:jp.domainHost,parse:Up,serialize:Lp},ws:Hp,wss:{scheme:"wss",domainHost:Hp.domainHost,parse:Hp.parse,serialize:Hp.serialize},urn:{scheme:"urn",parse:function(e,t){if(!e.path)return e.error="URN can not be parsed",e;const n=e.path.match(Fp);if(n){const r=t.scheme||e.scheme||"urn";e.nid=n[1].toLowerCase(),e.nss=n[2];const i=qp(`${r}:${t.nid||e.nid}`);e.path=void 0,i&&(e=i.parse(e,t))}else e.error=e.error||"URN can not be parsed.";return e},serialize:function(e,t){if(void 0===e.nid)throw new Error("URN without nid cannot be serialized");const n=t.scheme||e.scheme||"urn",r=e.nid.toLowerCase(),i=qp(`${n}:${t.nid||r}`);i&&(e=i.serialize(e,t));const s=e,a=e.nss;return s.path=`${r||t.nid}:${a}`,t.skipEscape=!0,s},skipNormalize:!0},"urn:uuid":{scheme:"urn:uuid",parse:function(e,t){const n=e;return n.uuid=n.nss,n.nss=void 0,t.tolerant||n.uuid&&Dp(n.uuid)||(n.error=n.error||"UUID is not valid."),n},serialize:function(e){const t=e;return t.nss=(e.uuid||"").toLowerCase(),t},skipNormalize:!0}};function qp(e){return e&&(zp[e]||zp[e.toLowerCase()])||void 0}Object.setPrototypeOf(zp,null);var Qp={SCHEMES:zp,getSchemeHandler:qp};const{normalizeIPv6:Vp,removeDotSegments:Jp,recomposeAuthority:Kp,normalizeComponentEncoding:Wp,isIPv4:Yp,nonSimpleDomain:Zp}=$p,{SCHEMES:Xp,getSchemeHandler:em}=Qp;function tm(e,t,n,r){const i={};return r||(e=im(nm(e,n),n),t=im(nm(t,n),n)),!(n=n||{}).tolerant&&t.scheme?(i.scheme=t.scheme,i.userinfo=t.userinfo,i.host=t.host,i.port=t.port,i.path=Jp(t.path||""),i.query=t.query):(void 0!==t.userinfo||void 0!==t.host||void 0!==t.port?(i.userinfo=t.userinfo,i.host=t.host,i.port=t.port,i.path=Jp(t.path||""),i.query=t.query):(t.path?("/"===t.path[0]?i.path=Jp(t.path):(void 0===e.userinfo&&void 0===e.host&&void 0===e.port||e.path?e.path?i.path=e.path.slice(0,e.path.lastIndexOf("/")+1)+t.path:i.path=t.path:i.path="/"+t.path,i.path=Jp(i.path)),i.query=t.query):(i.path=e.path,void 0!==t.query?i.query=t.query:i.query=e.query),i.userinfo=e.userinfo,i.host=e.host,i.port=e.port),i.scheme=e.scheme),i.fragment=t.fragment,i}function nm(e,t){const n={host:e.host,scheme:e.scheme,userinfo:e.userinfo,port:e.port,path:e.path,query:e.query,nid:e.nid,nss:e.nss,uuid:e.uuid,fragment:e.fragment,reference:e.reference,resourceName:e.resourceName,secure:e.secure,error:""},r=Object.assign({},t),i=[],s=em(r.scheme||n.scheme);s&&s.serialize&&s.serialize(n,r),void 0!==n.path&&(r.skipEscape?n.path=unescape(n.path):(n.path=escape(n.path),void 0!==n.scheme&&(n.path=n.path.split("%3A").join(":")))),"suffix"!==r.reference&&n.scheme&&i.push(n.scheme,":");const a=Kp(n);if(void 0!==a&&("suffix"!==r.reference&&i.push("//"),i.push(a),n.path&&"/"!==n.path[0]&&i.push("/")),void 0!==n.path){let e=n.path;r.absolutePath||s&&s.absolutePath||(e=Jp(e)),void 0===a&&"/"===e[0]&&"/"===e[1]&&(e="/%2F"+e.slice(2)),i.push(e)}return void 0!==n.query&&i.push("?",n.query),void 0!==n.fragment&&i.push("#",n.fragment),i.join("")}const rm=/^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u;function im(e,t){const n=Object.assign({},t),r={scheme:void 0,userinfo:void 0,host:"",port:void 0,path:"",query:void 0,fragment:void 0};let i=!1;"suffix"===n.reference&&(e=n.scheme?n.scheme+":"+e:"//"+e);const s=e.match(rm);if(s){if(r.scheme=s[1],r.userinfo=s[3],r.host=s[4],r.port=parseInt(s[5],10),r.path=s[6]||"",r.query=s[7],r.fragment=s[8],isNaN(r.port)&&(r.port=s[5]),r.host)if(!1===Yp(r.host)){const e=Vp(r.host);r.host=e.host.toLowerCase(),i=e.isIPV6}else i=!0;void 0!==r.scheme||void 0!==r.userinfo||void 0!==r.host||void 0!==r.port||void 0!==r.query||r.path?void 0===r.scheme?r.reference="relative":void 0===r.fragment?r.reference="absolute":r.reference="uri":r.reference="same-document",n.reference&&"suffix"!==n.reference&&n.reference!==r.reference&&(r.error=r.error||"URI is not a "+n.reference+" reference.");const t=em(n.scheme||r.scheme);if(!(n.unicodeSupport||t&&t.unicodeSupport)&&r.host&&(n.domainHost||t&&t.domainHost)&&!1===i&&Zp(r.host))try{r.host=URL.domainToASCII(r.host.toLowerCase())}catch(a){r.error=r.error||"Host's domain name can not be converted to ASCII: "+a}(!t||t&&!t.skipNormalize)&&(-1!==e.indexOf("%")&&(void 0!==r.scheme&&(r.scheme=unescape(r.scheme)),void 0!==r.host&&(r.host=unescape(r.host))),r.path&&(r.path=escape(unescape(r.path))),r.fragment&&(r.fragment=encodeURI(decodeURIComponent(r.fragment)))),t&&t.parse&&t.parse(r,n)}else r.error=r.error||"URI can not be parsed.";return r}const sm={SCHEMES:Xp,normalize:function(e,t){return"string"==typeof e?e=nm(im(e,t),t):"object"==typeof e&&(e=im(nm(e,t),t)),e},resolve:function(e,t,n){const r=n?Object.assign({scheme:"null"},n):{scheme:"null"},i=tm(im(e,r),im(t,r),r,!0);return r.skipEscape=!0,nm(i,r)},resolveComponent:tm,equal:function(e,t,n){return"string"==typeof e?(e=unescape(e),e=nm(Wp(im(e,n),!0),{...n,skipEscape:!0})):"object"==typeof e&&(e=nm(Wp(e,!0),{...n,skipEscape:!0})),"string"==typeof t?(t=unescape(t),t=nm(Wp(im(t,n),!0),{...n,skipEscape:!0})):"object"==typeof t&&(t=nm(Wp(t,!0),{...n,skipEscape:!0})),e.toLowerCase()===t.toLowerCase()},serialize:nm,parse:im};Pp.exports=sm,Pp.exports.default=sm,Pp.exports.fastUri=sm;var am=Pp.exports;Object.defineProperty(Ip,"__esModule",{value:!0});const om=am;om.code='require("ajv/dist/runtime/uri").default',Ip.default=om,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.CodeGen=e.Name=e.nil=e.stringify=e.str=e._=e.KeywordCxt=void 0;var t=Wu;Object.defineProperty(e,"KeywordCxt",{enumerable:!0,get:function(){return t.KeywordCxt}});var n=Xu;Object.defineProperty(e,"_",{enumerable:!0,get:function(){return n._}}),Object.defineProperty(e,"str",{enumerable:!0,get:function(){return n.str}}),Object.defineProperty(e,"stringify",{enumerable:!0,get:function(){return n.stringify}}),Object.defineProperty(e,"nil",{enumerable:!0,get:function(){return n.nil}}),Object.defineProperty(e,"Name",{enumerable:!0,get:function(){return n.Name}}),Object.defineProperty(e,"CodeGen",{enumerable:!0,get:function(){return n.CodeGen}});const r=ap,i=cp,s=Td,a=fp,o=Xu,c=dh,A=kd,l=nd,f=xp,u=Ip,d=(e,t)=>new RegExp(e,t);d.code="new RegExp";const h=["removeAdditional","useDefaults","coerceTypes"],p=new Set(["validate","serialize","parse","wrapper","root","schema","keyword","pattern","formats","validate$data","func","obj","Error"]),m={errorDataPath:"",format:"`validateFormats: false` can be used instead.",nullable:'"nullable" keyword is supported by default.',jsonPointers:"Deprecated jsPropertySyntax can be used instead.",extendRefs:"Deprecated ignoreKeywordsWithRef can be used instead.",missingRefs:"Pass empty schema with $id that should be ignored to ajv.addSchema.",processCode:"Use option `code: {process: (code, schemaEnv: object) => string}`",sourceCode:"Use option `code: {source: true}`",strictDefaults:"It is default now, see option `strict`.",strictKeywords:"It is default now, see option `strict`.",uniqueItems:'"uniqueItems" keyword is always validated.',unknownFormats:"Disable strict mode or pass `true` to `ajv.addFormat` (or `formats` option).",cache:"Map is used as cache, schema object as key.",serialize:"Map is used as cache, schema object as key.",ajvErrors:"It is default now."},y={ignoreKeywordsWithRef:"",jsPropertySyntax:"",unicode:'"minLength"/"maxLength" account for unicode characters by default.'};function g(e){var t,n,r,i,s,a,o,c,A,l,f,h,p,m,y,g,b,w,v,_,E,k,T,S,x;const I=e.strict,P=null===(t=e.code)||void 0===t?void 0:t.optimize,C=!0===P||void 0===P?1:P||0,N=null!==(r=null===(n=e.code)||void 0===n?void 0:n.regExp)&&void 0!==r?r:d,O=null!==(i=e.uriResolver)&&void 0!==i?i:u.default;return{strictSchema:null===(a=null!==(s=e.strictSchema)&&void 0!==s?s:I)||void 0===a||a,strictNumbers:null===(c=null!==(o=e.strictNumbers)&&void 0!==o?o:I)||void 0===c||c,strictTypes:null!==(l=null!==(A=e.strictTypes)&&void 0!==A?A:I)&&void 0!==l?l:"log",strictTuples:null!==(h=null!==(f=e.strictTuples)&&void 0!==f?f:I)&&void 0!==h?h:"log",strictRequired:null!==(m=null!==(p=e.strictRequired)&&void 0!==p?p:I)&&void 0!==m&&m,code:e.code?{...e.code,optimize:C,regExp:N}:{optimize:C,regExp:N},loopRequired:null!==(y=e.loopRequired)&&void 0!==y?y:200,loopEnum:null!==(g=e.loopEnum)&&void 0!==g?g:200,meta:null===(b=e.meta)||void 0===b||b,messages:null===(w=e.messages)||void 0===w||w,inlineRefs:null===(v=e.inlineRefs)||void 0===v||v,schemaId:null!==(_=e.schemaId)&&void 0!==_?_:"$id",addUsedSchema:null===(E=e.addUsedSchema)||void 0===E||E,validateSchema:null===(k=e.validateSchema)||void 0===k||k,validateFormats:null===(T=e.validateFormats)||void 0===T||T,unicodeRegExp:null===(S=e.unicodeRegExp)||void 0===S||S,int32range:null===(x=e.int32range)||void 0===x||x,uriResolver:O}}class b{constructor(e={}){this.schemas={},this.refs={},this.formats={},this._compilations=new Set,this._loading={},this._cache=new Map,e=this.opts={...e,...g(e)};const{es5:t,lines:n}=this.opts.code;this.scope=new o.ValueScope({scope:{},prefixes:p,es5:t,lines:n}),this.logger=function(e){if(!1===e)return S;if(void 0===e)return console;if(e.log&&e.warn&&e.error)return e;throw new Error("logger must implement log, warn and error methods")}(e.logger);const r=e.validateFormats;e.validateFormats=!1,this.RULES=(0,s.getRules)(),w.call(this,m,e,"NOT SUPPORTED"),w.call(this,y,e,"DEPRECATED","warn"),this._metaOpts=T.call(this),e.formats&&E.call(this),this._addVocabularies(),this._addDefaultMetaSchema(),e.keywords&&k.call(this,e.keywords),"object"==typeof e.meta&&this.addMetaSchema(e.meta),_.call(this),e.validateFormats=r}_addVocabularies(){this.addKeyword("$async")}_addDefaultMetaSchema(){const{$data:e,meta:t,schemaId:n}=this.opts;let r=f;"id"===n&&(r={...f},r.id=r.$id,delete r.$id),t&&e&&this.addMetaSchema(r,r[n],!1)}defaultMeta(){const{meta:e,schemaId:t}=this.opts;return this.opts.defaultMeta="object"==typeof e?e[t]||e:void 0}validate(e,t){let n;if("string"==typeof e){if(n=this.getSchema(e),!n)throw new Error(`no schema with key or ref "${e}"`)}else n=this.compile(e);const r=n(t);return"$async"in n||(this.errors=n.errors),r}compile(e,t){const n=this._addSchema(e,t);return n.validate||this._compileSchemaEnv(n)}compileAsync(e,t){if("function"!=typeof this.opts.loadSchema)throw new Error("options.loadSchema should be a function");const{loadSchema:n}=this.opts;return r.call(this,e,t);async function r(e,t){await s.call(this,e.$schema);const n=this._addSchema(e,t);return n.validate||a.call(this,n)}async function s(e){e&&!this.getSchema(e)&&await r.call(this,{$ref:e},!0)}async function a(e){try{return this._compileSchemaEnv(e)}catch(t){if(!(t instanceof i.default))throw t;return o.call(this,t),await c.call(this,t.missingSchema),a.call(this,e)}}function o({missingSchema:e,missingRef:t}){if(this.refs[e])throw new Error(`AnySchema ${e} is loaded but ${t} cannot be resolved`)}async function c(e){const n=await A.call(this,e);this.refs[e]||await s.call(this,n.$schema),this.refs[e]||this.addSchema(n,e,t)}async function A(e){const t=this._loading[e];if(t)return t;try{return await(this._loading[e]=n(e))}finally{delete this._loading[e]}}}addSchema(e,t,n,r=this.opts.validateSchema){if(Array.isArray(e)){for(const t of e)this.addSchema(t,void 0,n,r);return this}let i;if("object"==typeof e){const{schemaId:t}=this.opts;if(i=e[t],void 0!==i&&"string"!=typeof i)throw new Error(`schema ${t} must be string`)}return t=(0,c.normalizeId)(t||i),this._checkUnique(t),this.schemas[t]=this._addSchema(e,n,t,r,!0),this}addMetaSchema(e,t,n=this.opts.validateSchema){return this.addSchema(e,t,!0,n),this}validateSchema(e,t){if("boolean"==typeof e)return!0;let n;if(n=e.$schema,void 0!==n&&"string"!=typeof n)throw new Error("$schema must be a string");if(n=n||this.opts.defaultMeta||this.defaultMeta(),!n)return this.logger.warn("meta-schema not available"),this.errors=null,!0;const r=this.validate(n,e);if(!r&&t){const e="schema is invalid: "+this.errorsText();if("log"!==this.opts.validateSchema)throw new Error(e);this.logger.error(e)}return r}getSchema(e){let t;for(;"string"==typeof(t=v.call(this,e));)e=t;if(void 0===t){const{schemaId:n}=this.opts,r=new a.SchemaEnv({schema:{},schemaId:n});if(t=a.resolveSchema.call(this,r,e),!t)return;this.refs[e]=t}return t.validate||this._compileSchemaEnv(t)}removeSchema(e){if(e instanceof RegExp)return this._removeAllSchemas(this.schemas,e),this._removeAllSchemas(this.refs,e),this;switch(typeof e){case"undefined":return this._removeAllSchemas(this.schemas),this._removeAllSchemas(this.refs),this._cache.clear(),this;case"string":{const t=v.call(this,e);return"object"==typeof t&&this._cache.delete(t.schema),delete this.schemas[e],delete this.refs[e],this}case"object":{const t=e;this._cache.delete(t);let n=e[this.opts.schemaId];return n&&(n=(0,c.normalizeId)(n),delete this.schemas[n],delete this.refs[n]),this}default:throw new Error("ajv.removeSchema: invalid parameter")}}addVocabulary(e){for(const t of e)this.addKeyword(t);return this}addKeyword(e,t){let n;if("string"==typeof e)n=e,"object"==typeof t&&(this.logger.warn("these parameters are deprecated, see docs for addKeyword"),t.keyword=n);else{if("object"!=typeof e||void 0!==t)throw new Error("invalid addKeywords parameters");if(n=(t=e).keyword,Array.isArray(n)&&!n.length)throw new Error("addKeywords: keyword must be string or non-empty array")}if(I.call(this,n,t),!t)return(0,l.eachItem)(n,e=>P.call(this,e)),this;N.call(this,t);const r={...t,type:(0,A.getJSONTypes)(t.type),schemaType:(0,A.getJSONTypes)(t.schemaType)};return(0,l.eachItem)(n,0===r.type.length?e=>P.call(this,e,r):e=>r.type.forEach(t=>P.call(this,e,r,t))),this}getKeyword(e){const t=this.RULES.all[e];return"object"==typeof t?t.definition:!!t}removeKeyword(e){const{RULES:t}=this;delete t.keywords[e],delete t.all[e];for(const n of t.rules){const t=n.rules.findIndex(t=>t.keyword===e);t>=0&&n.rules.splice(t,1)}return this}addFormat(e,t){return"string"==typeof t&&(t=new RegExp(t)),this.formats[e]=t,this}errorsText(e=this.errors,{separator:t=", ",dataVar:n="data"}={}){return e&&0!==e.length?e.map(e=>`${n}${e.instancePath} ${e.message}`).reduce((e,n)=>e+t+n):"No errors"}$dataMetaSchema(e,t){const n=this.RULES.all;e=JSON.parse(JSON.stringify(e));for(const r of t){const t=r.split("/").slice(1);let i=e;for(const e of t)i=i[e];for(const e in n){const t=n[e];if("object"!=typeof t)continue;const{$data:r}=t.definition,s=i[e];r&&s&&(i[e]=R(s))}}return e}_removeAllSchemas(e,t){for(const n in e){const r=e[n];t&&!t.test(n)||("string"==typeof r?delete e[n]:r&&!r.meta&&(this._cache.delete(r.schema),delete e[n]))}}_addSchema(e,t,n,r=this.opts.validateSchema,i=this.opts.addUsedSchema){let s;const{schemaId:o}=this.opts;if("object"==typeof e)s=e[o];else{if(this.opts.jtd)throw new Error("schema must be object");if("boolean"!=typeof e)throw new Error("schema must be object or boolean")}let A=this._cache.get(e);if(void 0!==A)return A;n=(0,c.normalizeId)(s||n);const l=c.getSchemaRefs.call(this,e,n);return A=new a.SchemaEnv({schema:e,schemaId:o,meta:t,baseId:n,localRefs:l}),this._cache.set(A.schema,A),i&&!n.startsWith("#")&&(n&&this._checkUnique(n),this.refs[n]=A),r&&this.validateSchema(e,!0),A}_checkUnique(e){if(this.schemas[e]||this.refs[e])throw new Error(`schema with key or id "${e}" already exists`)}_compileSchemaEnv(e){if(e.meta?this._compileMetaSchema(e):a.compileSchema.call(this,e),!e.validate)throw new Error("ajv implementation error");return e.validate}_compileMetaSchema(e){const t=this.opts;this.opts=this._metaOpts;try{a.compileSchema.call(this,e)}finally{this.opts=t}}}function w(e,t,n,r="error"){for(const i in e){const s=i;s in t&&this.logger[r](`${n}: option ${i}. ${e[s]}`)}}function v(e){return e=(0,c.normalizeId)(e),this.schemas[e]||this.refs[e]}function _(){const e=this.opts.schemas;if(e)if(Array.isArray(e))this.addSchema(e);else for(const t in e)this.addSchema(e[t],t)}function E(){for(const e in this.opts.formats){const t=this.opts.formats[e];t&&this.addFormat(e,t)}}function k(e){if(Array.isArray(e))this.addVocabulary(e);else{this.logger.warn("keywords option as map is deprecated, pass array");for(const t in e){const n=e[t];n.keyword||(n.keyword=t),this.addKeyword(n)}}}function T(){const e={...this.opts};for(const t of h)delete e[t];return e}b.ValidationError=r.default,b.MissingRefError=i.default,e.default=b;const S={log(){},warn(){},error(){}},x=/^[a-z_$][a-z0-9_$:-]*$/i;function I(e,t){const{RULES:n}=this;if((0,l.eachItem)(e,e=>{if(n.keywords[e])throw new Error(`Keyword ${e} is already defined`);if(!x.test(e))throw new Error(`Keyword ${e} has invalid name`)}),t&&t.$data&&!("code"in t)&&!("validate"in t))throw new Error('$data keyword must have "code" or "validate" function')}function P(e,t,n){var r;const i=null==t?void 0:t.post;if(n&&i)throw new Error('keyword with "post" flag cannot have "type"');const{RULES:s}=this;let a=i?s.post:s.rules.find(({type:e})=>e===n);if(a||(a={type:n,rules:[]},s.rules.push(a)),s.keywords[e]=!0,!t)return;const o={keyword:e,definition:{...t,type:(0,A.getJSONTypes)(t.type),schemaType:(0,A.getJSONTypes)(t.schemaType)}};t.before?C.call(this,a,o,t.before):a.rules.push(o),s.all[e]=o,null===(r=t.implements)||void 0===r||r.forEach(e=>this.addKeyword(e))}function C(e,t,n){const r=e.rules.findIndex(e=>e.keyword===n);r>=0?e.rules.splice(r,0,t):(e.rules.push(t),this.logger.warn(`rule ${n} is not defined`))}function N(e){let{metaSchema:t}=e;void 0!==t&&(e.$data&&this.opts.$data&&(t=R(t)),e.validateSchema=this.compile(t,!0))}const O={$ref:"https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#"};function R(e){return{anyOf:[e,O]}}}(Ku);var cm={},Am={},lm={};Object.defineProperty(lm,"__esModule",{value:!0});const fm={keyword:"id",code(){throw new Error('NOT SUPPORTED: keyword "id", use "$id" for schema ID')}};lm.default=fm;var um={};Object.defineProperty(um,"__esModule",{value:!0}),um.callRef=um.getValidate=void 0;const dm=cp,hm=Jd,pm=Xu,mm=md,ym=fp,gm=nd,bm={keyword:"$ref",schemaType:"string",code(e){const{gen:t,schema:n,it:r}=e,{baseId:i,schemaEnv:s,validateName:a,opts:o,self:c}=r,{root:A}=s;if(("#"===n||"#/"===n)&&i===A.baseId)return function(){if(s===A)return vm(e,a,s,s.$async);const n=t.scopeValue("root",{ref:A});return vm(e,pm._`${n}.validate`,A,A.$async)}();const l=ym.resolveRef.call(c,A,i,n);if(void 0===l)throw new dm.default(r.opts.uriResolver,i,n);return l instanceof ym.SchemaEnv?function(t){const n=wm(e,t);vm(e,n,t,t.$async)}(l):function(r){const i=t.scopeValue("schema",!0===o.code.source?{ref:r,code:(0,pm.stringify)(r)}:{ref:r}),s=t.name("valid"),a=e.subschema({schema:r,dataTypes:[],schemaPath:pm.nil,topSchemaRef:i,errSchemaPath:n},s);e.mergeEvaluated(a),e.ok(s)}(l)}};function wm(e,t){const{gen:n}=e;return t.validate?n.scopeValue("validate",{ref:t.validate}):pm._`${n.scopeValue("wrapper",{ref:t})}.validate`}function vm(e,t,n,r){const{gen:i,it:s}=e,{allErrors:a,schemaEnv:o,opts:c}=s,A=c.passContext?mm.default.this:pm.nil;function l(e){const t=pm._`${e}.errors`;i.assign(mm.default.vErrors,pm._`${mm.default.vErrors} === null ? ${t} : ${mm.default.vErrors}.concat(${t})`),i.assign(mm.default.errors,pm._`${mm.default.vErrors}.length`)}function f(e){var t;if(!s.opts.unevaluated)return;const r=null===(t=null==n?void 0:n.validate)||void 0===t?void 0:t.evaluated;if(!0!==s.props)if(r&&!r.dynamicProps)void 0!==r.props&&(s.props=gm.mergeEvaluated.props(i,r.props,s.props));else{const t=i.var("props",pm._`${e}.evaluated.props`);s.props=gm.mergeEvaluated.props(i,t,s.props,pm.Name)}if(!0!==s.items)if(r&&!r.dynamicItems)void 0!==r.items&&(s.items=gm.mergeEvaluated.items(i,r.items,s.items));else{const t=i.var("items",pm._`${e}.evaluated.items`);s.items=gm.mergeEvaluated.items(i,t,s.items,pm.Name)}}r?function(){if(!o.$async)throw new Error("async schema referenced by sync schema");const n=i.let("valid");i.try(()=>{i.code(pm._`await ${(0,hm.callValidateCode)(e,t,A)}`),f(t),a||i.assign(n,!0)},e=>{i.if(pm._`!(${e} instanceof ${s.ValidationError})`,()=>i.throw(e)),l(e),a||i.assign(n,!1)}),e.ok(n)}():e.result((0,hm.callValidateCode)(e,t,A),()=>f(t),()=>l(t))}um.getValidate=wm,um.callRef=vm,um.default=bm,Object.defineProperty(Am,"__esModule",{value:!0});const _m=um,Em=["$schema","$id","$defs","$vocabulary",{keyword:"$comment"},"definitions",lm.default,_m.default];Am.default=Em;var km={},Tm={};Object.defineProperty(Tm,"__esModule",{value:!0});const Sm=Xu,xm=Sm.operators,Im={maximum:{okStr:"<=",ok:xm.LTE,fail:xm.GT},minimum:{okStr:">=",ok:xm.GTE,fail:xm.LT},exclusiveMaximum:{okStr:"<",ok:xm.LT,fail:xm.GTE},exclusiveMinimum:{okStr:">",ok:xm.GT,fail:xm.LTE}},Pm={message:({keyword:e,schemaCode:t})=>Sm.str`must be ${Im[e].okStr} ${t}`,params:({keyword:e,schemaCode:t})=>Sm._`{comparison: ${Im[e].okStr}, limit: ${t}}`},Cm={keyword:Object.keys(Im),type:"number",schemaType:"number",$data:!0,error:Pm,code(e){const{keyword:t,data:n,schemaCode:r}=e;e.fail$data(Sm._`${n} ${Im[t].fail} ${r} || isNaN(${n})`)}};Tm.default=Cm;var Nm={};Object.defineProperty(Nm,"__esModule",{value:!0});const Om=Xu,Rm={keyword:"multipleOf",type:"number",schemaType:"number",$data:!0,error:{message:({schemaCode:e})=>Om.str`must be multiple of ${e}`,params:({schemaCode:e})=>Om._`{multipleOf: ${e}}`},code(e){const{gen:t,data:n,schemaCode:r,it:i}=e,s=i.opts.multipleOfPrecision,a=t.let("res"),o=s?Om._`Math.abs(Math.round(${a}) - ${a}) > 1e-${s}`:Om._`${a} !== parseInt(${a})`;e.fail$data(Om._`(${r} === 0 || (${a} = ${n}/${r}, ${o}))`)}};Nm.default=Rm;var Bm={},Mm={};function $m(e){const t=e.length;let n,r=0,i=0;for(;i<t;)r++,n=e.charCodeAt(i++),n>=55296&&n<=56319&&i<t&&(n=e.charCodeAt(i),56320==(64512&n)&&i++);return r}Object.defineProperty(Mm,"__esModule",{value:!0}),Mm.default=$m,$m.code='require("ajv/dist/runtime/ucs2length").default',Object.defineProperty(Bm,"__esModule",{value:!0});const Dm=Xu,Fm=nd,Gm=Mm,Um={keyword:["maxLength","minLength"],type:"string",schemaType:"number",$data:!0,error:{message:({keyword:e,schemaCode:t})=>Dm.str`must NOT have ${"maxLength"===e?"more":"fewer"} than ${t} characters`,params:({schemaCode:e})=>Dm._`{limit: ${e}}`},code(e){const{keyword:t,data:n,schemaCode:r,it:i}=e,s="maxLength"===t?Dm.operators.GT:Dm.operators.LT,a=!1===i.opts.unicode?Dm._`${n}.length`:Dm._`${(0,Fm.useFunc)(e.gen,Gm.default)}(${n})`;e.fail$data(Dm._`${a} ${s} ${r}`)}};Bm.default=Um;var Lm={};Object.defineProperty(Lm,"__esModule",{value:!0});const jm=Jd,Hm=Xu,zm={keyword:"pattern",type:"string",schemaType:"string",$data:!0,error:{message:({schemaCode:e})=>Hm.str`must match pattern "${e}"`,params:({schemaCode:e})=>Hm._`{pattern: ${e}}`},code(e){const{data:t,$data:n,schema:r,schemaCode:i,it:s}=e,a=s.opts.unicodeRegExp?"u":"",o=n?Hm._`(new RegExp(${i}, ${a}))`:(0,jm.usePattern)(e,r);e.fail$data(Hm._`!${o}.test(${t})`)}};Lm.default=zm;var qm={};Object.defineProperty(qm,"__esModule",{value:!0});const Qm=Xu,Vm={keyword:["maxProperties","minProperties"],type:"object",schemaType:"number",$data:!0,error:{message:({keyword:e,schemaCode:t})=>Qm.str`must NOT have ${"maxProperties"===e?"more":"fewer"} than ${t} properties`,params:({schemaCode:e})=>Qm._`{limit: ${e}}`},code(e){const{keyword:t,data:n,schemaCode:r}=e,i="maxProperties"===t?Qm.operators.GT:Qm.operators.LT;e.fail$data(Qm._`Object.keys(${n}).length ${i} ${r}`)}};qm.default=Vm;var Jm={};Object.defineProperty(Jm,"__esModule",{value:!0});const Km=Jd,Wm=Xu,Ym=nd,Zm={keyword:"required",type:"object",schemaType:"array",$data:!0,error:{message:({params:{missingProperty:e}})=>Wm.str`must have required property '${e}'`,params:({params:{missingProperty:e}})=>Wm._`{missingProperty: ${e}}`},code(e){const{gen:t,schema:n,schemaCode:r,data:i,$data:s,it:a}=e,{opts:o}=a;if(!s&&0===n.length)return;const c=n.length>=o.loopRequired;if(a.allErrors?function(){if(c||s)e.block$data(Wm.nil,A);else for(const t of n)(0,Km.checkReportMissingProp)(e,t)}():function(){const a=t.let("missing");if(c||s){const n=t.let("valid",!0);e.block$data(n,()=>function(n,s){e.setParams({missingProperty:n}),t.forOf(n,r,()=>{t.assign(s,(0,Km.propertyInData)(t,i,n,o.ownProperties)),t.if((0,Wm.not)(s),()=>{e.error(),t.break()})},Wm.nil)}(a,n)),e.ok(n)}else t.if((0,Km.checkMissingProp)(e,n,a)),(0,Km.reportMissingProp)(e,a),t.else()}(),o.strictRequired){const t=e.parentSchema.properties,{definedProperties:r}=e.it;for(const e of n)if(void 0===(null==t?void 0:t[e])&&!r.has(e)){const t=`required property "${e}" is not defined at "${a.schemaEnv.baseId+a.errSchemaPath}" (strictRequired)`;(0,Ym.checkStrictMode)(a,t,a.opts.strictRequired)}}function A(){t.forOf("prop",r,n=>{e.setParams({missingProperty:n}),t.if((0,Km.noPropertyInData)(t,i,n,o.ownProperties),()=>e.error())})}}};Jm.default=Zm;var Xm={};Object.defineProperty(Xm,"__esModule",{value:!0});const ey=Xu,ty={keyword:["maxItems","minItems"],type:"array",schemaType:"number",$data:!0,error:{message:({keyword:e,schemaCode:t})=>ey.str`must NOT have ${"maxItems"===e?"more":"fewer"} than ${t} items`,params:({schemaCode:e})=>ey._`{limit: ${e}}`},code(e){const{keyword:t,data:n,schemaCode:r}=e,i="maxItems"===t?ey.operators.GT:ey.operators.LT;e.fail$data(ey._`${n}.length ${i} ${r}`)}};Xm.default=ty;var ny={},ry={};Object.defineProperty(ry,"__esModule",{value:!0});const iy=hh;iy.code='require("ajv/dist/runtime/equal").default',ry.default=iy,Object.defineProperty(ny,"__esModule",{value:!0});const sy=kd,ay=Xu,oy=nd,cy=ry,Ay={keyword:"uniqueItems",type:"array",schemaType:"boolean",$data:!0,error:{message:({params:{i:e,j:t}})=>ay.str`must NOT have duplicate items (items ## ${t} and ${e} are identical)`,params:({params:{i:e,j:t}})=>ay._`{i: ${e}, j: ${t}}`},code(e){const{gen:t,data:n,$data:r,schema:i,parentSchema:s,schemaCode:a,it:o}=e;if(!r&&!i)return;const c=t.let("valid"),A=s.items?(0,sy.getSchemaTypes)(s.items):[];function l(r,i){const s=t.name("item"),a=(0,sy.checkDataTypes)(A,s,o.opts.strictNumbers,sy.DataType.Wrong),l=t.const("indices",ay._`{}`);t.for(ay._`;${r}--;`,()=>{t.let(s,ay._`${n}[${r}]`),t.if(a,ay._`continue`),A.length>1&&t.if(ay._`typeof ${s} == "string"`,ay._`${s} += "_"`),t.if(ay._`typeof ${l}[${s}] == "number"`,()=>{t.assign(i,ay._`${l}[${s}]`),e.error(),t.assign(c,!1).break()}).code(ay._`${l}[${s}] = ${r}`)})}function f(r,i){const s=(0,oy.useFunc)(t,cy.default),a=t.name("outer");t.label(a).for(ay._`;${r}--;`,()=>t.for(ay._`${i} = ${r}; ${i}--;`,()=>t.if(ay._`${s}(${n}[${r}], ${n}[${i}])`,()=>{e.error(),t.assign(c,!1).break(a)})))}e.block$data(c,function(){const r=t.let("i",ay._`${n}.length`),i=t.let("j");e.setParams({i:r,j:i}),t.assign(c,!0),t.if(ay._`${r} > 1`,()=>(A.length>0&&!A.some(e=>"object"===e||"array"===e)?l:f)(r,i))},ay._`${a} === false`),e.ok(c)}};ny.default=Ay;var ly={};Object.defineProperty(ly,"__esModule",{value:!0});const fy=Xu,uy=nd,dy=ry,hy={keyword:"const",$data:!0,error:{message:"must be equal to constant",params:({schemaCode:e})=>fy._`{allowedValue: ${e}}`},code(e){const{gen:t,data:n,$data:r,schemaCode:i,schema:s}=e;r||s&&"object"==typeof s?e.fail$data(fy._`!${(0,uy.useFunc)(t,dy.default)}(${n}, ${i})`):e.fail(fy._`${s} !== ${n}`)}};ly.default=hy;var py={};Object.defineProperty(py,"__esModule",{value:!0});const my=Xu,yy=nd,gy=ry,by={keyword:"enum",schemaType:"array",$data:!0,error:{message:"must be equal to one of the allowed values",params:({schemaCode:e})=>my._`{allowedValues: ${e}}`},code(e){const{gen:t,data:n,$data:r,schema:i,schemaCode:s,it:a}=e;if(!r&&0===i.length)throw new Error("enum must have non-empty array");const o=i.length>=a.opts.loopEnum;let c;const A=()=>null!=c?c:c=(0,yy.useFunc)(t,gy.default);let l;if(o||r)l=t.let("valid"),e.block$data(l,function(){t.assign(l,!1),t.forOf("v",s,e=>t.if(my._`${A()}(${n}, ${e})`,()=>t.assign(l,!0).break()))});else{if(!Array.isArray(i))throw new Error("ajv implementation error");const e=t.const("vSchema",s);l=(0,my.or)(...i.map((t,r)=>function(e,t){const r=i[t];return"object"==typeof r&&null!==r?my._`${A()}(${n}, ${e}[${t}])`:my._`${n} === ${r}`}(e,r)))}e.pass(l)}};py.default=by,Object.defineProperty(km,"__esModule",{value:!0});const wy=Nm,vy=Bm,_y=Lm,Ey=qm,ky=Jm,Ty=Xm,Sy=ny,xy=ly,Iy=py,Py=[Tm.default,wy.default,vy.default,_y.default,Ey.default,ky.default,Ty.default,Sy.default,{keyword:"type",schemaType:["string","array"]},{keyword:"nullable",schemaType:"boolean"},xy.default,Iy.default];km.default=Py;var Cy={},Ny={};Object.defineProperty(Ny,"__esModule",{value:!0}),Ny.validateAdditionalItems=void 0;const Oy=Xu,Ry=nd,By={keyword:"additionalItems",type:"array",schemaType:["boolean","object"],before:"uniqueItems",error:{message:({params:{len:e}})=>Oy.str`must NOT have more than ${e} items`,params:({params:{len:e}})=>Oy._`{limit: ${e}}`},code(e){const{parentSchema:t,it:n}=e,{items:r}=t;Array.isArray(r)?My(e,r):(0,Ry.checkStrictMode)(n,'"additionalItems" is ignored when "items" is not an array of schemas')}};function My(e,t){const{gen:n,schema:r,data:i,keyword:s,it:a}=e;a.items=!0;const o=n.const("len",Oy._`${i}.length`);if(!1===r)e.setParams({len:t.length}),e.pass(Oy._`${o} <= ${t.length}`);else if("object"==typeof r&&!(0,Ry.alwaysValidSchema)(a,r)){const r=n.var("valid",Oy._`${o} <= ${t.length}`);n.if((0,Oy.not)(r),()=>function(r){n.forRange("i",t.length,o,t=>{e.subschema({keyword:s,dataProp:t,dataPropType:Ry.Type.Num},r),a.allErrors||n.if((0,Oy.not)(r),()=>n.break())})}(r)),e.ok(r)}}Ny.validateAdditionalItems=My,Ny.default=By;var $y={},Dy={};Object.defineProperty(Dy,"__esModule",{value:!0}),Dy.validateTuple=void 0;const Fy=Xu,Gy=nd,Uy=Jd,Ly={keyword:"items",type:"array",schemaType:["object","array","boolean"],before:"uniqueItems",code(e){const{schema:t,it:n}=e;if(Array.isArray(t))return jy(e,"additionalItems",t);n.items=!0,(0,Gy.alwaysValidSchema)(n,t)||e.ok((0,Uy.validateArray)(e))}};function jy(e,t,n=e.schema){const{gen:r,parentSchema:i,data:s,keyword:a,it:o}=e;!function(e){const{opts:r,errSchemaPath:i}=o,s=n.length,c=s===e.minItems&&(s===e.maxItems||!1===e[t]);if(r.strictTuples&&!c){const e=`"${a}" is ${s}-tuple, but minItems or maxItems/${t} are not specified or different at path "${i}"`;(0,Gy.checkStrictMode)(o,e,r.strictTuples)}}(i),o.opts.unevaluated&&n.length&&!0!==o.items&&(o.items=Gy.mergeEvaluated.items(r,n.length,o.items));const c=r.name("valid"),A=r.const("len",Fy._`${s}.length`);n.forEach((t,n)=>{(0,Gy.alwaysValidSchema)(o,t)||(r.if(Fy._`${A} > ${n}`,()=>e.subschema({keyword:a,schemaProp:n,dataProp:n},c)),e.ok(c))})}Dy.validateTuple=jy,Dy.default=Ly,Object.defineProperty($y,"__esModule",{value:!0});const Hy=Dy,zy={keyword:"prefixItems",type:"array",schemaType:["array"],before:"uniqueItems",code:e=>(0,Hy.validateTuple)(e,"items")};$y.default=zy;var qy={};Object.defineProperty(qy,"__esModule",{value:!0});const Qy=Xu,Vy=nd,Jy=Jd,Ky=Ny,Wy={keyword:"items",type:"array",schemaType:["object","boolean"],before:"uniqueItems",error:{message:({params:{len:e}})=>Qy.str`must NOT have more than ${e} items`,params:({params:{len:e}})=>Qy._`{limit: ${e}}`},code(e){const{schema:t,parentSchema:n,it:r}=e,{prefixItems:i}=n;r.items=!0,(0,Vy.alwaysValidSchema)(r,t)||(i?(0,Ky.validateAdditionalItems)(e,i):e.ok((0,Jy.validateArray)(e)))}};qy.default=Wy;var Yy={};Object.defineProperty(Yy,"__esModule",{value:!0});const Zy=Xu,Xy=nd,eg={keyword:"contains",type:"array",schemaType:["object","boolean"],before:"uniqueItems",trackErrors:!0,error:{message:({params:{min:e,max:t}})=>void 0===t?Zy.str`must contain at least ${e} valid item(s)`:Zy.str`must contain at least ${e} and no more than ${t} valid item(s)`,params:({params:{min:e,max:t}})=>void 0===t?Zy._`{minContains: ${e}}`:Zy._`{minContains: ${e}, maxContains: ${t}}`},code(e){const{gen:t,schema:n,parentSchema:r,data:i,it:s}=e;let a,o;const{minContains:c,maxContains:A}=r;s.opts.next?(a=void 0===c?1:c,o=A):a=1;const l=t.const("len",Zy._`${i}.length`);if(e.setParams({min:a,max:o}),void 0===o&&0===a)return void(0,Xy.checkStrictMode)(s,'"minContains" == 0 without "maxContains": "contains" keyword ignored');if(void 0!==o&&a>o)return(0,Xy.checkStrictMode)(s,'"minContains" > "maxContains" is always invalid'),void e.fail();if((0,Xy.alwaysValidSchema)(s,n)){let t=Zy._`${l} >= ${a}`;return void 0!==o&&(t=Zy._`${t} && ${l} <= ${o}`),void e.pass(t)}s.items=!0;const f=t.name("valid");function u(){const e=t.name("_valid"),n=t.let("count",0);d(e,()=>t.if(e,()=>function(e){t.code(Zy._`${e}++`),void 0===o?t.if(Zy._`${e} >= ${a}`,()=>t.assign(f,!0).break()):(t.if(Zy._`${e} > ${o}`,()=>t.assign(f,!1).break()),1===a?t.assign(f,!0):t.if(Zy._`${e} >= ${a}`,()=>t.assign(f,!0)))}(n)))}function d(n,r){t.forRange("i",0,l,t=>{e.subschema({keyword:"contains",dataProp:t,dataPropType:Xy.Type.Num,compositeRule:!0},n),r()})}void 0===o&&1===a?d(f,()=>t.if(f,()=>t.break())):0===a?(t.let(f,!0),void 0!==o&&t.if(Zy._`${i}.length > 0`,u)):(t.let(f,!1),u()),e.result(f,()=>e.reset())}};Yy.default=eg;var tg={};!function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.validateSchemaDeps=e.validatePropertyDeps=e.error=void 0;const t=Xu,n=nd,r=Jd;e.error={message:({params:{property:e,depsCount:n,deps:r}})=>t.str`must have ${1===n?"property":"properties"} ${r} when property ${e} is present`,params:({params:{property:e,depsCount:n,deps:r,missingProperty:i}})=>t._`{property: ${e},
18
+ missingProperty: ${i},
19
+ depsCount: ${n},
20
+ deps: ${r}}`};const i={keyword:"dependencies",type:"object",schemaType:"object",error:e.error,code(e){const[t,n]=function({schema:e}){const t={},n={};for(const r in e)"__proto__"!==r&&((Array.isArray(e[r])?t:n)[r]=e[r]);return[t,n]}(e);s(e,t),a(e,n)}};function s(e,n=e.schema){const{gen:i,data:s,it:a}=e;if(0===Object.keys(n).length)return;const o=i.let("missing");for(const c in n){const A=n[c];if(0===A.length)continue;const l=(0,r.propertyInData)(i,s,c,a.opts.ownProperties);e.setParams({property:c,depsCount:A.length,deps:A.join(", ")}),a.allErrors?i.if(l,()=>{for(const t of A)(0,r.checkReportMissingProp)(e,t)}):(i.if(t._`${l} && (${(0,r.checkMissingProp)(e,A,o)})`),(0,r.reportMissingProp)(e,o),i.else())}}function a(e,t=e.schema){const{gen:i,data:s,keyword:a,it:o}=e,c=i.name("valid");for(const A in t)(0,n.alwaysValidSchema)(o,t[A])||(i.if((0,r.propertyInData)(i,s,A,o.opts.ownProperties),()=>{const t=e.subschema({keyword:a,schemaProp:A},c);e.mergeValidEvaluated(t,c)},()=>i.var(c,!0)),e.ok(c))}e.validatePropertyDeps=s,e.validateSchemaDeps=a,e.default=i}(tg);var ng={};Object.defineProperty(ng,"__esModule",{value:!0});const rg=Xu,ig=nd,sg={keyword:"propertyNames",type:"object",schemaType:["object","boolean"],error:{message:"property name must be valid",params:({params:e})=>rg._`{propertyName: ${e.propertyName}}`},code(e){const{gen:t,schema:n,data:r,it:i}=e;if((0,ig.alwaysValidSchema)(i,n))return;const s=t.name("valid");t.forIn("key",r,n=>{e.setParams({propertyName:n}),e.subschema({keyword:"propertyNames",data:n,dataTypes:["string"],propertyName:n,compositeRule:!0},s),t.if((0,rg.not)(s),()=>{e.error(!0),i.allErrors||t.break()})}),e.ok(s)}};ng.default=sg;var ag={};Object.defineProperty(ag,"__esModule",{value:!0});const og=Jd,cg=Xu,Ag=md,lg=nd,fg={keyword:"additionalProperties",type:["object"],schemaType:["boolean","object"],allowUndefined:!0,trackErrors:!0,error:{message:"must NOT have additional properties",params:({params:e})=>cg._`{additionalProperty: ${e.additionalProperty}}`},code(e){const{gen:t,schema:n,parentSchema:r,data:i,errsCount:s,it:a}=e;if(!s)throw new Error("ajv implementation error");const{allErrors:o,opts:c}=a;if(a.props=!0,"all"!==c.removeAdditional&&(0,lg.alwaysValidSchema)(a,n))return;const A=(0,og.allSchemaProperties)(r.properties),l=(0,og.allSchemaProperties)(r.patternProperties);function f(e){t.code(cg._`delete ${i}[${e}]`)}function u(r){if("all"===c.removeAdditional||c.removeAdditional&&!1===n)f(r);else{if(!1===n)return e.setParams({additionalProperty:r}),e.error(),void(o||t.break());if("object"==typeof n&&!(0,lg.alwaysValidSchema)(a,n)){const n=t.name("valid");"failing"===c.removeAdditional?(d(r,n,!1),t.if((0,cg.not)(n),()=>{e.reset(),f(r)})):(d(r,n),o||t.if((0,cg.not)(n),()=>t.break()))}}}function d(t,n,r){const i={keyword:"additionalProperties",dataProp:t,dataPropType:lg.Type.Str};!1===r&&Object.assign(i,{compositeRule:!0,createErrors:!1,allErrors:!1}),e.subschema(i,n)}t.forIn("key",i,n=>{A.length||l.length?t.if(function(n){let i;if(A.length>8){const e=(0,lg.schemaRefOrVal)(a,r.properties,"properties");i=(0,og.isOwnProperty)(t,e,n)}else i=A.length?(0,cg.or)(...A.map(e=>cg._`${n} === ${e}`)):cg.nil;return l.length&&(i=(0,cg.or)(i,...l.map(t=>cg._`${(0,og.usePattern)(e,t)}.test(${n})`))),(0,cg.not)(i)}(n),()=>u(n)):u(n)}),e.ok(cg._`${s} === ${Ag.default.errors}`)}};ag.default=fg;var ug={};Object.defineProperty(ug,"__esModule",{value:!0});const dg=Wu,hg=Jd,pg=nd,mg=ag,yg={keyword:"properties",type:"object",schemaType:"object",code(e){const{gen:t,schema:n,parentSchema:r,data:i,it:s}=e;"all"===s.opts.removeAdditional&&void 0===r.additionalProperties&&mg.default.code(new dg.KeywordCxt(s,mg.default,"additionalProperties"));const a=(0,hg.allSchemaProperties)(n);for(const f of a)s.definedProperties.add(f);s.opts.unevaluated&&a.length&&!0!==s.props&&(s.props=pg.mergeEvaluated.props(t,(0,pg.toHash)(a),s.props));const o=a.filter(e=>!(0,pg.alwaysValidSchema)(s,n[e]));if(0===o.length)return;const c=t.name("valid");for(const f of o)A(f)?l(f):(t.if((0,hg.propertyInData)(t,i,f,s.opts.ownProperties)),l(f),s.allErrors||t.else().var(c,!0),t.endIf()),e.it.definedProperties.add(f),e.ok(c);function A(e){return s.opts.useDefaults&&!s.compositeRule&&void 0!==n[e].default}function l(t){e.subschema({keyword:"properties",schemaProp:t,dataProp:t},c)}}};ug.default=yg;var gg={};Object.defineProperty(gg,"__esModule",{value:!0});const bg=Jd,wg=Xu,vg=nd,_g=nd,Eg={keyword:"patternProperties",type:"object",schemaType:"object",code(e){const{gen:t,schema:n,data:r,parentSchema:i,it:s}=e,{opts:a}=s,o=(0,bg.allSchemaProperties)(n),c=o.filter(e=>(0,vg.alwaysValidSchema)(s,n[e]));if(0===o.length||c.length===o.length&&(!s.opts.unevaluated||!0===s.props))return;const A=a.strictSchema&&!a.allowMatchingProperties&&i.properties,l=t.name("valid");!0===s.props||s.props instanceof wg.Name||(s.props=(0,_g.evaluatedPropsToName)(t,s.props));const{props:f}=s;function u(e){for(const t in A)new RegExp(e).test(t)&&(0,vg.checkStrictMode)(s,`property ${t} matches pattern ${e} (use allowMatchingProperties)`)}function d(n){t.forIn("key",r,r=>{t.if(wg._`${(0,bg.usePattern)(e,n)}.test(${r})`,()=>{const i=c.includes(n);i||e.subschema({keyword:"patternProperties",schemaProp:n,dataProp:r,dataPropType:_g.Type.Str},l),s.opts.unevaluated&&!0!==f?t.assign(wg._`${f}[${r}]`,!0):i||s.allErrors||t.if((0,wg.not)(l),()=>t.break())})})}!function(){for(const e of o)A&&u(e),s.allErrors?d(e):(t.var(l,!0),d(e),t.if(l))}()}};gg.default=Eg;var kg={};Object.defineProperty(kg,"__esModule",{value:!0});const Tg=nd,Sg={keyword:"not",schemaType:["object","boolean"],trackErrors:!0,code(e){const{gen:t,schema:n,it:r}=e;if((0,Tg.alwaysValidSchema)(r,n))return void e.fail();const i=t.name("valid");e.subschema({keyword:"not",compositeRule:!0,createErrors:!1,allErrors:!1},i),e.failResult(i,()=>e.reset(),()=>e.error())},error:{message:"must NOT be valid"}};kg.default=Sg;var xg={};Object.defineProperty(xg,"__esModule",{value:!0});const Ig={keyword:"anyOf",schemaType:"array",trackErrors:!0,code:Jd.validateUnion,error:{message:"must match a schema in anyOf"}};xg.default=Ig;var Pg={};Object.defineProperty(Pg,"__esModule",{value:!0});const Cg=Xu,Ng=nd,Og={keyword:"oneOf",schemaType:"array",trackErrors:!0,error:{message:"must match exactly one schema in oneOf",params:({params:e})=>Cg._`{passingSchemas: ${e.passing}}`},code(e){const{gen:t,schema:n,parentSchema:r,it:i}=e;if(!Array.isArray(n))throw new Error("ajv implementation error");if(i.opts.discriminator&&r.discriminator)return;const s=n,a=t.let("valid",!1),o=t.let("passing",null),c=t.name("_valid");e.setParams({passing:o}),t.block(function(){s.forEach((n,r)=>{let s;(0,Ng.alwaysValidSchema)(i,n)?t.var(c,!0):s=e.subschema({keyword:"oneOf",schemaProp:r,compositeRule:!0},c),r>0&&t.if(Cg._`${c} && ${a}`).assign(a,!1).assign(o,Cg._`[${o}, ${r}]`).else(),t.if(c,()=>{t.assign(a,!0),t.assign(o,r),s&&e.mergeEvaluated(s,Cg.Name)})})}),e.result(a,()=>e.reset(),()=>e.error(!0))}};Pg.default=Og;var Rg={};Object.defineProperty(Rg,"__esModule",{value:!0});const Bg=nd,Mg={keyword:"allOf",schemaType:"array",code(e){const{gen:t,schema:n,it:r}=e;if(!Array.isArray(n))throw new Error("ajv implementation error");const i=t.name("valid");n.forEach((t,n)=>{if((0,Bg.alwaysValidSchema)(r,t))return;const s=e.subschema({keyword:"allOf",schemaProp:n},i);e.ok(i),e.mergeEvaluated(s)})}};Rg.default=Mg;var $g={};Object.defineProperty($g,"__esModule",{value:!0});const Dg=Xu,Fg=nd,Gg={keyword:"if",schemaType:["object","boolean"],trackErrors:!0,error:{message:({params:e})=>Dg.str`must match "${e.ifClause}" schema`,params:({params:e})=>Dg._`{failingKeyword: ${e.ifClause}}`},code(e){const{gen:t,parentSchema:n,it:r}=e;void 0===n.then&&void 0===n.else&&(0,Fg.checkStrictMode)(r,'"if" without "then" and "else" is ignored');const i=Ug(r,"then"),s=Ug(r,"else");if(!i&&!s)return;const a=t.let("valid",!0),o=t.name("_valid");if(function(){const t=e.subschema({keyword:"if",compositeRule:!0,createErrors:!1,allErrors:!1},o);e.mergeEvaluated(t)}(),e.reset(),i&&s){const n=t.let("ifClause");e.setParams({ifClause:n}),t.if(o,c("then",n),c("else",n))}else i?t.if(o,c("then")):t.if((0,Dg.not)(o),c("else"));function c(n,r){return()=>{const i=e.subschema({keyword:n},o);t.assign(a,o),e.mergeValidEvaluated(i,a),r?t.assign(r,Dg._`${n}`):e.setParams({ifClause:n})}}e.pass(a,()=>e.error(!0))}};function Ug(e,t){const n=e.schema[t];return void 0!==n&&!(0,Fg.alwaysValidSchema)(e,n)}$g.default=Gg;var Lg={};Object.defineProperty(Lg,"__esModule",{value:!0});const jg=nd,Hg={keyword:["then","else"],schemaType:["object","boolean"],code({keyword:e,parentSchema:t,it:n}){void 0===t.if&&(0,jg.checkStrictMode)(n,`"${e}" without "if" is ignored`)}};Lg.default=Hg,Object.defineProperty(Cy,"__esModule",{value:!0});const zg=Ny,qg=$y,Qg=Dy,Vg=qy,Jg=Yy,Kg=tg,Wg=ng,Yg=ag,Zg=ug,Xg=gg,eb=kg,tb=xg,nb=Pg,rb=Rg,ib=$g,sb=Lg;Cy.default=function(e=!1){const t=[eb.default,tb.default,nb.default,rb.default,ib.default,sb.default,Wg.default,Yg.default,Kg.default,Zg.default,Xg.default];return e?t.push(qg.default,Vg.default):t.push(zg.default,Qg.default),t.push(Jg.default),t};var ab={},ob={};Object.defineProperty(ob,"__esModule",{value:!0});const cb=Xu,Ab={keyword:"format",type:["number","string"],schemaType:"string",$data:!0,error:{message:({schemaCode:e})=>cb.str`must match format "${e}"`,params:({schemaCode:e})=>cb._`{format: ${e}}`},code(e,t){const{gen:n,data:r,$data:i,schema:s,schemaCode:a,it:o}=e,{opts:c,errSchemaPath:A,schemaEnv:l,self:f}=o;c.validateFormats&&(i?function(){const i=n.scopeValue("formats",{ref:f.formats,code:c.code.formats}),s=n.const("fDef",cb._`${i}[${a}]`),o=n.let("fType"),A=n.let("format");n.if(cb._`typeof ${s} == "object" && !(${s} instanceof RegExp)`,()=>n.assign(o,cb._`${s}.type || "string"`).assign(A,cb._`${s}.validate`),()=>n.assign(o,cb._`"string"`).assign(A,s)),e.fail$data((0,cb.or)(!1===c.strictSchema?cb.nil:cb._`${a} && !${A}`,function(){const e=l.$async?cb._`(${s}.async ? await ${A}(${r}) : ${A}(${r}))`:cb._`${A}(${r})`,n=cb._`(typeof ${A} == "function" ? ${e} : ${A}.test(${r}))`;return cb._`${A} && ${A} !== true && ${o} === ${t} && !${n}`}()))}():function(){const i=f.formats[s];if(!i)return void function(){if(!1!==c.strictSchema)throw new Error(e());function e(){return`unknown format "${s}" ignored in schema at path "${A}"`}f.logger.warn(e())}();if(!0===i)return;const[a,o,u]=function(e){const t=e instanceof RegExp?(0,cb.regexpCode)(e):c.code.formats?cb._`${c.code.formats}${(0,cb.getProperty)(s)}`:void 0,r=n.scopeValue("formats",{key:s,ref:e,code:t});return"object"!=typeof e||e instanceof RegExp?["string",e,r]:[e.type||"string",e.validate,cb._`${r}.validate`]}(i);a===t&&e.pass(function(){if("object"==typeof i&&!(i instanceof RegExp)&&i.async){if(!l.$async)throw new Error("async format in sync schema");return cb._`await ${u}(${r})`}return"function"==typeof o?cb._`${u}(${r})`:cb._`${u}.test(${r})`}())}())}};ob.default=Ab,Object.defineProperty(ab,"__esModule",{value:!0});const lb=[ob.default];ab.default=lb;var fb={};Object.defineProperty(fb,"__esModule",{value:!0}),fb.contentVocabulary=fb.metadataVocabulary=void 0,fb.metadataVocabulary=["title","description","default","deprecated","readOnly","writeOnly","examples"],fb.contentVocabulary=["contentMediaType","contentEncoding","contentSchema"],Object.defineProperty(cm,"__esModule",{value:!0});const ub=km,db=Cy,hb=ab,pb=fb,mb=[Am.default,ub.default,(0,db.default)(),hb.default,pb.metadataVocabulary,pb.contentVocabulary];cm.default=mb;var yb,gb,bb={},wb={};Object.defineProperty(wb,"__esModule",{value:!0}),wb.DiscrError=void 0,(gb=yb||(wb.DiscrError=yb={})).Tag="tag",gb.Mapping="mapping",Object.defineProperty(bb,"__esModule",{value:!0});const vb=Xu,_b=wb,Eb=fp,kb=cp,Tb=nd,Sb={keyword:"discriminator",type:"object",schemaType:"object",error:{message:({params:{discrError:e,tagName:t}})=>e===_b.DiscrError.Tag?`tag "${t}" must be string`:`value of tag "${t}" must be in oneOf`,params:({params:{discrError:e,tag:t,tagName:n}})=>vb._`{error: ${e}, tag: ${n}, tagValue: ${t}}`},code(e){const{gen:t,data:n,schema:r,parentSchema:i,it:s}=e,{oneOf:a}=i;if(!s.opts.discriminator)throw new Error("discriminator: requires discriminator option");const o=r.propertyName;if("string"!=typeof o)throw new Error("discriminator: requires propertyName");if(r.mapping)throw new Error("discriminator: mapping is not supported");if(!a)throw new Error("discriminator: requires oneOf keyword");const c=t.let("valid",!1),A=t.const("tag",vb._`${n}${(0,vb.getProperty)(o)}`);function l(n){const r=t.name("valid"),i=e.subschema({keyword:"oneOf",schemaProp:n},r);return e.mergeEvaluated(i,vb.Name),r}t.if(vb._`typeof ${A} == "string"`,()=>function(){const n=function(){var e;const t={},n=c(i);let r=!0;for(let i=0;i<a.length;i++){let t=a[i];if((null==t?void 0:t.$ref)&&!(0,Tb.schemaHasRulesButRef)(t,s.self.RULES)){const e=t.$ref;if(t=Eb.resolveRef.call(s.self,s.schemaEnv.root,s.baseId,e),t instanceof Eb.SchemaEnv&&(t=t.schema),void 0===t)throw new kb.default(s.opts.uriResolver,s.baseId,e)}const l=null===(e=null==t?void 0:t.properties)||void 0===e?void 0:e[o];if("object"!=typeof l)throw new Error(`discriminator: oneOf subschemas (or referenced schemas) must have "properties/${o}"`);r=r&&(n||c(t)),A(l,i)}if(!r)throw new Error(`discriminator: "${o}" must be required`);return t;function c({required:e}){return Array.isArray(e)&&e.includes(o)}function A(e,t){if(e.const)l(e.const,t);else{if(!e.enum)throw new Error(`discriminator: "properties/${o}" must have "const" or "enum"`);for(const n of e.enum)l(n,t)}}function l(e,n){if("string"!=typeof e||e in t)throw new Error(`discriminator: "${o}" values must be unique strings`);t[e]=n}}();t.if(!1);for(const e in n)t.elseIf(vb._`${A} === ${e}`),t.assign(c,l(n[e]));t.else(),e.error(!1,{discrError:_b.DiscrError.Mapping,tag:A,tagName:o}),t.endIf()}(),()=>e.error(!1,{discrError:_b.DiscrError.Tag,tag:A,tagName:o})),e.ok(c)}};bb.default=Sb;const xb={$schema:"http://json-schema.org/draft-07/schema#",$id:"http://json-schema.org/draft-07/schema#",title:"Core schema meta-schema",definitions:{schemaArray:{type:"array",minItems:1,items:{$ref:"#"}},nonNegativeInteger:{type:"integer",minimum:0},nonNegativeIntegerDefault0:{allOf:[{$ref:"#/definitions/nonNegativeInteger"},{default:0}]},simpleTypes:{enum:["array","boolean","integer","null","number","object","string"]},stringArray:{type:"array",items:{type:"string"},uniqueItems:!0,default:[]}},type:["object","boolean"],properties:{$id:{type:"string",format:"uri-reference"},$schema:{type:"string",format:"uri"},$ref:{type:"string",format:"uri-reference"},$comment:{type:"string"},title:{type:"string"},description:{type:"string"},default:!0,readOnly:{type:"boolean",default:!1},examples:{type:"array",items:!0},multipleOf:{type:"number",exclusiveMinimum:0},maximum:{type:"number"},exclusiveMaximum:{type:"number"},minimum:{type:"number"},exclusiveMinimum:{type:"number"},maxLength:{$ref:"#/definitions/nonNegativeInteger"},minLength:{$ref:"#/definitions/nonNegativeIntegerDefault0"},pattern:{type:"string",format:"regex"},additionalItems:{$ref:"#"},items:{anyOf:[{$ref:"#"},{$ref:"#/definitions/schemaArray"}],default:!0},maxItems:{$ref:"#/definitions/nonNegativeInteger"},minItems:{$ref:"#/definitions/nonNegativeIntegerDefault0"},uniqueItems:{type:"boolean",default:!1},contains:{$ref:"#"},maxProperties:{$ref:"#/definitions/nonNegativeInteger"},minProperties:{$ref:"#/definitions/nonNegativeIntegerDefault0"},required:{$ref:"#/definitions/stringArray"},additionalProperties:{$ref:"#"},definitions:{type:"object",additionalProperties:{$ref:"#"},default:{}},properties:{type:"object",additionalProperties:{$ref:"#"},default:{}},patternProperties:{type:"object",additionalProperties:{$ref:"#"},propertyNames:{format:"regex"},default:{}},dependencies:{type:"object",additionalProperties:{anyOf:[{$ref:"#"},{$ref:"#/definitions/stringArray"}]}},propertyNames:{$ref:"#"},const:!0,enum:{type:"array",items:!0,minItems:1,uniqueItems:!0},type:{anyOf:[{$ref:"#/definitions/simpleTypes"},{type:"array",items:{$ref:"#/definitions/simpleTypes"},minItems:1,uniqueItems:!0}]},format:{type:"string"},contentMediaType:{type:"string"},contentEncoding:{type:"string"},if:{$ref:"#"},then:{$ref:"#"},else:{$ref:"#"},allOf:{$ref:"#/definitions/schemaArray"},anyOf:{$ref:"#/definitions/schemaArray"},oneOf:{$ref:"#/definitions/schemaArray"},not:{$ref:"#"}},default:!0};!function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.MissingRefError=t.ValidationError=t.CodeGen=t.Name=t.nil=t.stringify=t.str=t._=t.KeywordCxt=t.Ajv=void 0;const n=Ku,r=cm,i=bb,s=xb,a=["/properties"],o="http://json-schema.org/draft-07/schema";class c extends n.default{_addVocabularies(){super._addVocabularies(),r.default.forEach(e=>this.addVocabulary(e)),this.opts.discriminator&&this.addKeyword(i.default)}_addDefaultMetaSchema(){if(super._addDefaultMetaSchema(),!this.opts.meta)return;const e=this.opts.$data?this.$dataMetaSchema(s,a):s;this.addMetaSchema(e,o,!1),this.refs["http://json-schema.org/schema"]=o}defaultMeta(){return this.opts.defaultMeta=super.defaultMeta()||(this.getSchema(o)?o:void 0)}}t.Ajv=c,e.exports=t=c,e.exports.Ajv=c,Object.defineProperty(t,"__esModule",{value:!0}),t.default=c;var A=Wu;Object.defineProperty(t,"KeywordCxt",{enumerable:!0,get:function(){return A.KeywordCxt}});var l=Xu;Object.defineProperty(t,"_",{enumerable:!0,get:function(){return l._}}),Object.defineProperty(t,"str",{enumerable:!0,get:function(){return l.str}}),Object.defineProperty(t,"stringify",{enumerable:!0,get:function(){return l.stringify}}),Object.defineProperty(t,"nil",{enumerable:!0,get:function(){return l.nil}}),Object.defineProperty(t,"Name",{enumerable:!0,get:function(){return l.Name}}),Object.defineProperty(t,"CodeGen",{enumerable:!0,get:function(){return l.CodeGen}});var f=ap;Object.defineProperty(t,"ValidationError",{enumerable:!0,get:function(){return f.default}});var u=cp;Object.defineProperty(t,"MissingRefError",{enumerable:!0,get:function(){return u.default}})}(Ju,Ju.exports);const Ib=new(Vu(Ju.exports))({allErrors:!0,strict:!1}),Pb=new Map;let Cb=class extends Error{constructor(e,t=[]){super(e),this.name="ValidationError",this.errors=t}};function Nb(e,t,n,r=!1){const i=function(e,t){const n=t,r=Pb.get(n);if(r&&Date.now()-r.timestamp<36e5)return r.validator;try{const t=Ib.compile(e);return Pb.set(n,{validator:t,timestamp:Date.now()}),t}catch(i){throw new Error(`Schema compilation failed: ${i.message}`)}}(t,n);if(!i(e)){const e=i.errors||[],t=e.map(e=>`${e.instancePath} ${e.message}`).join("; ");if(r)throw new Cb(`ValidationError: Validation failed: ${t}`,e);return console.warn(`[Schema Validation Warning] ${n}: ${t}`),!1}return!0}const Ob="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;
21
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Rb(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Bb(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Mb(e,...t){if(!Rb(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function $b(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.createHasher");Bb(e.outputLen),Bb(e.blockLen)}function Db(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Fb(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Gb(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ub(e,t){return e<<32-t|e>>>t}const Lb=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),jb=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Hb(e){if(Mb(e),Lb)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=jb[e[n]];return t}function zb(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function qb(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(Lb)return Uint8Array.fromHex(e);const t=e.length,n=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let i=0,s=0;i<n;i++,s+=2){const t=zb(e.charCodeAt(s)),n=zb(e.charCodeAt(s+1));if(void 0===t||void 0===n){const t=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+s)}r[i]=16*t+n}return r}function Qb(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}(e)),Mb(e),e}function Vb(...e){let t=0;for(let r=0;r<e.length;r++){const n=e[r];Mb(n),t+=n.length}const n=new Uint8Array(t);for(let r=0,i=0;r<e.length;r++){const t=e[r];n.set(t,i),i+=t.length}return n}let Jb=class{};function Kb(e){const t=t=>e().update(Qb(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Wb(e=32){if(Ob&&"function"==typeof Ob.getRandomValues)return Ob.getRandomValues(new Uint8Array(e));if(Ob&&"function"==typeof Ob.randomBytes)return Uint8Array.from(Ob.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Yb(e,t,n){return e&t^~e&n}function Zb(e,t,n){return e&t^e&n^t&n}class Xb extends Jb{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=Gb(this.buffer)}update(e){Db(this),Mb(e=Qb(e));const{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let s=0;s<i;){const a=Math.min(r-this.pos,i-s);if(a===r){const t=Gb(e);for(;r<=i-s;s+=r)this.process(t,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Db(this),function(e,t){Mb(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:i}=this;let{pos:s}=this;t[s++]=128,Fb(this.buffer.subarray(s)),this.padOffset>r-s&&(this.process(n,0),s=0);for(let l=s;l<r;l++)t[l]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const i=BigInt(32),s=BigInt(4294967295),a=Number(n>>i&s),o=Number(n&s),c=r?4:0,A=r?0:4;e.setUint32(t+c,a,r),e.setUint32(t+A,o,r)}(n,r-8,BigInt(8*this.length),i),this.process(n,0);const a=Gb(e),o=this.outputLen;if(o%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=o/4,A=this.get();if(c>A.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<c;l++)a.setUint32(4*l,A[l],i)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:i,destroyed:s,pos:a}=this;return e.destroyed=s,e.finished=i,e.length=r,e.pos=a,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}}const ew=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),tw=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),nw=new Uint32Array(64);let rw=class extends Xb{constructor(e=32){super(64,e,8,!1),this.A=0|ew[0],this.B=0|ew[1],this.C=0|ew[2],this.D=0|ew[3],this.E=0|ew[4],this.F=0|ew[5],this.G=0|ew[6],this.H=0|ew[7]}get(){const{A:e,B:t,C:n,D:r,E:i,F:s,G:a,H:o}=this;return[e,t,n,r,i,s,a,o]}set(e,t,n,r,i,s,a,o){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|s,this.G=0|a,this.H=0|o}process(e,t){for(let l=0;l<16;l++,t+=4)nw[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){const e=nw[l-15],t=nw[l-2],n=Ub(e,7)^Ub(e,18)^e>>>3,r=Ub(t,17)^Ub(t,19)^t>>>10;nw[l]=r+nw[l-7]+n+nw[l-16]|0}let{A:n,B:r,C:i,D:s,E:a,F:o,G:c,H:A}=this;for(let l=0;l<64;l++){const e=A+(Ub(a,6)^Ub(a,11)^Ub(a,25))+Yb(a,o,c)+tw[l]+nw[l]|0,t=(Ub(n,2)^Ub(n,13)^Ub(n,22))+Zb(n,r,i)|0;A=c,c=o,o=a,a=s+e|0,s=i,i=r,r=n,n=e+t|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,o=o+this.F|0,c=c+this.G|0,A=A+this.H|0,this.set(n,r,i,s,a,o,c,A)}roundClean(){Fb(nw)}destroy(){this.set(0,0,0,0,0,0,0,0),Fb(this.buffer)}};const iw=Kb(()=>new rw),sw=iw;let aw=null;async function ow(){if(!aw){const e=await Promise.resolve().then(()=>lH);aw=e.secp256k1}return aw}async function cw(e,t){try{const n=await ow(),r=uw(e);return n.sign(r,t).toCompactHex()}catch(n){throw new Error(`Signature generation failed: ${n.message}`)}}function Aw(e,t){return"string"==typeof e||"string"==typeof t?("string"==typeof e?e:JSON.stringify(e))===("string"==typeof t?t:JSON.stringify(t)):!("*"!==e.holonId&&e.holonId!==t.holonId||"*"!==e.lensName&&e.lensName!==t.lensName||e.dataId&&"*"!==e.dataId&&t.dataId&&e.dataId!==t.dataId)}async function lw(e,t,n,r={}){const{expiresIn:i=36e5,issuer:s="holosphere",issuerKey:a}=r;if(!Array.isArray(e)||0===e.length)throw new Error("Permissions array cannot be empty");if("object"==typeof t){if(void 0===t.holonId||""===t.holonId)throw new Error('Invalid scope: holonId is required (use "*" for wildcard)');if(void 0===t.lensName||""===t.lensName)throw new Error('Invalid scope: lensName is required (use "*" for wildcard)')}else if("string"==typeof t&&""===t)throw new Error("Invalid scope: cannot be empty string");if(a&&("string"!=typeof a||a.length<32))throw new Error("Invalid issuer key");const o={type:"capability",permissions:e,scope:t,recipient:n,issuer:s,nonce:Date.now().toString(36)+Math.random().toString(36).substring(2,15),issued:Date.now(),expires:Date.now()+i},c=JSON.stringify(o),A=Buffer.from?Buffer.from(c).toString("base64"):btoa(c);return a?`${A}.${await cw(c,a)}`:A}async function fw(e,t,n){try{let r;if("string"==typeof e){const t=e.split(".")[0],n=Buffer.from?Buffer.from(t,"base64").toString("utf8"):atob(t);r=JSON.parse(n)}else r=e;return!(!r||"capability"!==r.type||Date.now()>r.expires||!Aw(r.scope,n)||!r.permissions.includes(t))}catch(r){return!1}}function uw(e){const t="string"==typeof e?e:JSON.stringify(e),n=(new TextEncoder).encode(t);return Hb(sw(n))}const dw="federations";async function hw(e,t){return await Qu(e,t,dw,e.publicKey)||{id:e.publicKey,federatedWith:[],discoveryEnabled:!1,autoAccept:!1,defaultScope:{holonId:"*",lensName:"*"},defaultPermissions:["read"]}}async function pw(e,t,n){return qu(e,t,dw,n)}async function mw(e,t,n,r={}){const i=await hw(e,t),s=i.federatedWith.findIndex(e=>e.pubKey===n);if(s>=0){const e=i.federatedWith[s];r.alias&&(e.alias=r.alias),r.inboundCapabilities&&(e.inboundCapabilities=[...e.inboundCapabilities||[],...r.inboundCapabilities]),e.updatedAt=Date.now(),i.federatedWith[s]=e}else i.federatedWith.push({pubKey:n,alias:r.alias||null,addedAt:Date.now(),addedVia:r.addedVia||"manual",inboundCapabilities:r.inboundCapabilities||[],outboundCapabilities:[]});return pw(e,t,i)}async function yw(e,t,n,r){const i=(await hw(e,t)).federatedWith.find(e=>e.pubKey===n);return i&&i.inboundCapabilities&&i.inboundCapabilities.find(e=>!(e.expires&&e.expires<Date.now())&&Aw(e.scope,r))||null}async function gw(e,t,n,r){const i=await hw(e,t),s=i.federatedWith.find(e=>e.pubKey===n);if(!s)return mw(e,t,n,{addedVia:"capability_received",inboundCapabilities:[r]});s.inboundCapabilities||(s.inboundCapabilities=[]);const a=s.inboundCapabilities.findIndex(e=>JSON.stringify(e.scope)===JSON.stringify(r.scope));return a>=0?s.inboundCapabilities[a]={...r,updatedAt:Date.now()}:s.inboundCapabilities.push({...r,receivedAt:Date.now()}),pw(e,t,i)}async function bw(e,t,n,r,i,s){const a=new Set,o=[];let c=n,A=i,l=s,f=t;for(;a.size<10;){const t=`${f}:${c}:${A}:${l}`;if(a.has(t))return{isCircular:!0,chain:o,reason:"existing_cycle"};if(a.add(t),o.push({holon:c,lens:A,dataId:l}),c===r)return{isCircular:!0,chain:o,reason:"would_create_cycle"};const n=Du(f,c,A,l),i=await Gu(e,n);if(!i)return{isCircular:!1,chain:o};if(!i.hologram||!i.target)return{isCircular:!1,chain:o};f=i.target.appname||f,c=i.target.holonId,A=i.target.lensName||A,l=i.target.dataId||l}return{isCircular:!0,chain:o,reason:"max_depth_exceeded"}}function ww(e,t,n,r,i,s={}){const{authorPubKey:a=null,capability:o=null}=s,c={id:r,hologram:!0,soul:Du(i,e,n,r),target:{appname:i,holonId:e,lensName:n,dataId:r},_meta:{created:Date.now(),sourceHolon:e,source:e}};return a&&(c.crossHolosphere=!0,c.target.authorPubKey=a,c._meta.sourcePubKey=a),o&&(c.capability=o,c._meta.grantedAt=Date.now()),c}async function vw(e,t,n=new Set,r=[],i={}){const{deleteCircular:s=!0,hologramPath:a=null}=i;if(!t||!t.hologram)return t;const{soul:o}=t,c=t.target||{};if(n.has(o)){const i=[...r,o].join(" → ");return console.warn("🔄 Circular reference detected - removing hologram"),console.warn(` Soul: ${o}`),console.warn(` Chain: ${i}`),console.warn(` Source holon: ${c.holonId||"unknown"}`),console.warn(` Lens: ${c.lensName||"unknown"}`),console.warn(` Data ID: ${c.dataId||t.id||"unknown"}`),console.warn(` Resolution depth: ${n.size}`),s&&a&&(console.info(` 🗑️ Deleting circular hologram at: ${a}`),await Fu(e,a,null)),null}if(n.size>=10){const t=[...r,o].join(" → ");return console.warn("⚠️ Max resolution depth (10) exceeded - removing hologram"),console.warn(` Current soul: ${o}`),console.warn(` Chain: ${t}`),console.warn(` Source holon: ${c.holonId||"unknown"}`),console.warn(` Lens: ${c.lensName||"unknown"}`),s&&a&&(console.info(` 🗑️ Deleting deep chain hologram at: ${a}`),await Fu(e,a,null)),null}let A;if(n.add(o),r.push(o),t.crossHolosphere&&c.authorPubKey){let n=t.capability;if(!n&&i.appname){const t=await yw(e,i.appname,c.authorPubKey,{holonId:c.holonId,lensName:c.lensName,dataId:c.dataId});t&&(n=t.token)}if(!n)return console.warn(`❌ Cross-holosphere hologram missing capability: ${o}`),null;if(!(await fw(n,"read",{holonId:c.holonId,lensName:c.lensName,dataId:c.dataId})))return console.warn(`❌ Capability verification failed for cross-holosphere hologram: ${o}`),null;A=await Gu(e,o,{authors:[c.authorPubKey]})}else A=await Gu(e,o);return A?A.hologram?vw(e,A,n,r,{...i,hologramPath:o}):function(e,t){const n=["hologram","soul","target","_meta","id","capability","crossHolosphere"],r={},i=[];for(const o of Object.keys(e))n.includes(o)||(r[o]=e[o],i.push(o));const s=e._meta?.sourceHolon||e._meta?.source||e.target?.holonId,a={...t,...r,_hologram:{isHologram:!0,soul:e.soul,sourceHolon:s,localOverrides:i,crossHolosphere:e.crossHolosphere||!1,sourcePubKey:e._meta?.sourcePubKey||null}};return t._meta?a._meta={...t._meta,source:s}:a._meta={source:s},a}(t,A):null}async function _w(e,t,n,r,i,s,a="reference"){const o=n.id;if(r===i)return console.info(`⏭️ Skipping propagation - source and target are the same holon: ${r}`),!0;if(!0===n.hologram){if(n.target&&n.target.holonId===i)return console.info("🔄 Skipping propagation - would create circular reference:"),console.info(` Data ID: ${o}`),console.info(` Source holon: ${r}`),console.info(` Target holon: ${i}`),console.info(` Hologram points to: ${n.target.holonId}`),console.info(` Lens: ${s}`),console.info(` Original soul: ${n.soul||"unknown"}`),!0;if(n.target){const r=Du(n.target.appname||t,n.target.holonId,n.target.lensName||s,n.target.dataId||o),a=await Gu(e,r);if(a?._meta?.activeHolograms&&a._meta.activeHolograms.some(e=>e.targetHolon===i))return console.info("⏭️ Skipping propagation - target already in activeHolograms:"),console.info(` Data ID: ${o}`),console.info(` Original source: ${n.target.holonId}`),console.info(` Target holon: ${i}`),!0}const a=n.target.holonId,c=n.target.dataId||o,A=n.target.lensName||s,l=n.target.appname||t,f=await bw(e,l,a,i,A,c);if(f.isCircular){const e=f.chain.map(e=>e.holon).join(" → ");return console.warn("🔄 Preventing circular hologram copy:"),console.warn(` Data ID: ${o}`),console.warn(` Original source: ${a}`),console.warn(` Would copy to: ${i}`),console.warn(` Existing chain: ${e}`),console.warn(` Reason: ${f.reason}`),!1}const u=Du(t,i,s,o),d={...n,_meta:{...n._meta,copiedFrom:r,copiedAt:Date.now()}},h=await Fu(e,u,d);return h&&n.target&&(await kw(e,n.target.appname||t,n.target.holonId,n.target.lensName||s,n.target.dataId||o,i),console.info(`📋 Copied hologram to ${i}:`),console.info(` Data ID: ${o}`),console.info(` Original source: ${n.target.holonId}`),console.info(` Copied from: ${r}`)),h}if("reference"===a&&n._meta?.activeHolograms&&n._meta.activeHolograms.some(e=>e.targetHolon===i))return console.info("⏭️ Skipping propagation - target already in activeHolograms:"),console.info(` Data ID: ${o}`),console.info(` Source holon: ${r}`),console.info(` Target holon: ${i}`),!0;if("reference"===a){const n=await bw(e,t,r,i,s,o);if(n.isCircular){const e=n.chain.map(e=>e.holon).join(" → ");return console.warn("🔄 Preventing circular hologram creation:"),console.warn(` Data ID: ${o}`),console.warn(` Would create: ${r} → ${i}`),console.warn(` Existing chain: ${e}`),console.warn(` Reason: ${n.reason}`),!1}const a=ww(r,0,s,o,t),c=Du(t,i,s,o),A=await Fu(e,c,a);return A&&await kw(e,t,r,s,o,i),A}return Fu(e,Du(t,i,s,o),{...n,_meta:{...n._meta,source:r}})}function Ew(e){return e&&e._hologram&&!0===e._hologram.isHologram}async function kw(e,t,n,r,i,s){let a=t,o=n,c=r,A=i,l=Du(a,o,c,A),f=await Gu(e,l);if(!f)return console.warn(`Source data not found at ${l}`),!1;let u=0;for(;!0===f.hologram&&f.target&&u<10;)if(u++,a=f.target.appname||a,o=f.target.holonId,c=f.target.lensName||c,A=f.target.dataId||A,l=Du(a,o,c,A),f=await Gu(e,l),!f)return console.warn(`Real source data not found at ${l}`),!1;u>0&&console.info(`📍 Followed hologram chain (depth: ${u}) to real source: ${o}/${c}/${A}`),f._meta||(f._meta={}),Array.isArray(f._meta.activeHolograms)||(f._meta.activeHolograms=[]);const d=Date.now(),h=f._meta.activeHolograms.findIndex(e=>e.targetHolon===s);return h>=0?f._meta.activeHolograms[h].lastUpdated=d:f._meta.activeHolograms.push({targetHolon:s,created:d,lastUpdated:d}),Fu(e,l,f)}async function Tw(e,t,n,r,i,s){let a=t,o=n,c=r,A=i,l=Du(a,o,c,A),f=await Gu(e,l);if(!f)return!1;let u=0;for(;!0===f.hologram&&f.target&&u<10;)if(u++,a=f.target.appname||a,o=f.target.holonId,c=f.target.lensName||c,A=f.target.dataId||A,l=Du(a,o,c,A),f=await Gu(e,l),!f)return!1;if(!f._meta||!Array.isArray(f._meta.activeHolograms))return!1;const d=f._meta.activeHolograms.length;return f._meta.activeHolograms=f._meta.activeHolograms.filter(e=>e.targetHolon!==s),f._meta.activeHolograms.length<d&&Fu(e,l,f)}async function Sw(e,t,n,r,i,s=null){if(!s){const a=Du(t,n,r,i);s=await Gu(e,a)}if(!s||!s._meta||!Array.isArray(s._meta.activeHolograms))return{refreshed:0,holograms:[]};const a=Date.now(),o=[];for(const c of s._meta.activeHolograms){c.lastUpdated=a;const n=Du(t,c.targetHolon,r,i),s=await Gu(e,n);s&&!0===s.hologram&&(s._meta||(s._meta={}),s._meta.lastUpdated=a,await Fu(e,n,s),o.push({targetHolon:c.targetHolon,dataId:i,timestamp:a}))}return{refreshed:o.length,holograms:o,sourceData:s}}async function xw(e,t,n,r,i,s={}){const{deleteData:a=!0}=s,o=Du(t,n,r,i),c={success:!1,wasHologram:!1,sourceHolon:null,activeHologramsUpdated:!1,error:null};try{const s=await Gu(e,o);if(!s)return console.warn(`🗑️ Hologram not found at ${o}`),c.error="Hologram not found",c;if(!0===s.hologram&&s.target){c.wasHologram=!0,c.sourceHolon=s.target.holonId,console.info("🗑️ Deleting hologram:"),console.info(` Path: ${o}`),console.info(` Data ID: ${i}`),console.info(` From holon: ${n}`),console.info(` Source holon: ${s.target.holonId}`),console.info(` Lens: ${r}`);const a=await Tw(e,s.target.appname||t,s.target.holonId,s.target.lensName||r,s.target.dataId||i,n);c.activeHologramsUpdated=a,a?console.info(" ✓ Removed from activeHolograms on source"):console.warn(" ⚠️ Could not update activeHolograms on source (may already be removed)")}else console.info(`🗑️ Deleting non-hologram data at ${o}`);if(a){const t=await Fu(e,o,null);c.success=t,t?console.info(" ✓ Hologram deleted successfully"):(console.warn(" ⚠️ Failed to delete hologram data"),c.error="Failed to delete hologram data")}else c.success=!0;return c}catch(A){return console.error(`❌ Error deleting hologram at ${o}:`,A),c.error=A.message||"Unknown error",c}}class Iw{constructor(){this.subscriptions=new Map}register(e,t){this.subscriptions.set(e,t)}unregister(e){const t=this.subscriptions.get(e);t&&(t.unsubscribe(),this.subscriptions.delete(e))}unsubscribeAll(){for(const[e,t]of this.subscriptions)t.unsubscribe();this.subscriptions.clear()}count(){return this.subscriptions.size}}const Pw="RFC3986",Cw={RFC1738:e=>String(e).replace(/%20/g,"+"),RFC3986:e=>String(e)},Nw=Array.isArray,Ow=(()=>{const e=[];for(let t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e})(),Rw=1024;function Bw(e,t){if(Nw(e)){const n=[];for(let r=0;r<e.length;r+=1)n.push(t(e[r]));return n}return t(e)}const Mw=Object.prototype.hasOwnProperty,$w={brackets:e=>String(e)+"[]",comma:"comma",indices:(e,t)=>String(e)+"["+t+"]",repeat:e=>String(e)},Dw=Array.isArray,Fw=Array.prototype.push,Gw=function(e,t){Fw.apply(e,Dw(t)?t:[t])},Uw=Date.prototype.toISOString,Lw={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:(e,t,n,r,i)=>{if(0===e.length)return e;let s=e;if("symbol"==typeof e?s=Symbol.prototype.toString.call(e):"string"!=typeof e&&(s=String(e)),"iso-8859-1"===n)return escape(s).replace(/%u[0-9a-f]{4}/gi,function(e){return"%26%23"+parseInt(e.slice(2),16)+"%3B"});let a="";for(let o=0;o<s.length;o+=Rw){const e=s.length>=Rw?s.slice(o,o+Rw):s,t=[];for(let n=0;n<e.length;++n){let r=e.charCodeAt(n);45===r||46===r||95===r||126===r||r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||"RFC1738"===i&&(40===r||41===r)?t[t.length]=e.charAt(n):r<128?t[t.length]=Ow[r]:r<2048?t[t.length]=Ow[192|r>>6]+Ow[128|63&r]:r<55296||r>=57344?t[t.length]=Ow[224|r>>12]+Ow[128|r>>6&63]+Ow[128|63&r]:(n+=1,r=65536+((1023&r)<<10|1023&e.charCodeAt(n)),t[t.length]=Ow[240|r>>18]+Ow[128|r>>12&63]+Ow[128|r>>6&63]+Ow[128|63&r])}a+=t.join("")}return a},encodeValuesOnly:!1,format:Pw,formatter:Cw[Pw],indices:!1,serializeDate:e=>Uw.call(e),skipNulls:!1,strictNullHandling:!1},jw={};function Hw(e,t,n,r,i,s,a,o,c,A,l,f,u,d,h,p,m,y){let g=e,b=y,w=0,v=!1;for(;void 0!==(b=b.get(jw))&&!v;){const t=b.get(e);if(w+=1,void 0!==t){if(t===w)throw new RangeError("Cyclic object value");v=!0}void 0===b.get(jw)&&(w=0)}if("function"==typeof A?g=A(t,g):g instanceof Date?g=u?.(g):"comma"===n&&Dw(g)&&(g=Bw(g,function(e){return e instanceof Date?u?.(e):e})),null===g){if(s)return c&&!p?c(t,Lw.encoder,m,"key",d):t;g=""}if("string"==typeof(_=g)||"number"==typeof _||"boolean"==typeof _||"symbol"==typeof _||"bigint"==typeof _||function(e){return!(!e||"object"!=typeof e||!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e)))}(g)){if(c){const e=p?t:c(t,Lw.encoder,m,"key",d);return[h?.(e)+"="+h?.(c(g,Lw.encoder,m,"value",d))]}return[h?.(t)+"="+h?.(String(g))]}var _;const E=[];if(void 0===g)return E;let k;if("comma"===n&&Dw(g))p&&c&&(g=Bw(g,c)),k=[{value:g.length>0?g.join(",")||null:void 0}];else if(Dw(A))k=A;else{const e=Object.keys(g);k=l?e.sort(l):e}const T=o?String(t).replace(/\./g,"%2E"):String(t),S=r&&Dw(g)&&1===g.length?T+"[]":T;if(i&&Dw(g)&&0===g.length)return S+"[]";for(let x=0;x<k.length;++x){const t=k[x],b="object"==typeof t&&void 0!==t.value?t.value:g[t];if(a&&null===b)continue;const v=f&&o?t.replace(/\./g,"%2E"):t,_=Dw(g)?"function"==typeof n?n(S,v):S:S+(f?"."+v:"["+v+"]");y.set(e,w);const T=new WeakMap;T.set(jw,y),Gw(E,Hw(b,_,n,r,i,s,a,o,"comma"===n&&p&&Dw(g)?null:c,A,l,f,u,d,h,p,m,T))}return E}const zw="4.104.0";let qw,Qw,Vw,Jw,Kw,Ww,Yw,Zw,Xw,ev=!1;class tv{constructor(e){this.body=e}get[Symbol.toStringTag](){return"MultipartBody"}}const nv=()=>{qw||function(e,t={auto:!1}){if(ev)throw new Error(`you must \`import 'openai/shims/${e.kind}'\` before importing anything else from openai`);if(qw)throw new Error(`can't \`import 'openai/shims/${e.kind}'\` after \`import 'openai/shims/${qw}'\``);ev=t.auto,qw=e.kind,Qw=e.fetch,Vw=e.FormData,Jw=e.File,Kw=e.ReadableStream,Ww=e.getMultipartRequestOptions,Yw=e.getDefaultAgent,Zw=e.fileFromPath,Xw=e.isFsReadStream}(function({manuallyImported:e}={}){const t=e?"You may need to use polyfills":"Add one of these imports before your first `import … from 'openai'`:\n- `import 'openai/shims/node'` (if you're running on Node)\n- `import 'openai/shims/web'` (otherwise)\n";let n,r,i,s;try{n=fetch,r=Request,i=Response,s=Headers}catch(a){throw new Error(`this environment is missing the following Web Fetch API type: ${a.message}. ${t}`)}return{kind:"web",fetch:n,Request:r,Response:i,Headers:s,FormData:"undefined"!=typeof FormData?FormData:class{constructor(){throw new Error(`file uploads aren't supported in this environment yet as 'FormData' is undefined. ${t}`)}},Blob:"undefined"!=typeof Blob?Blob:class{constructor(){throw new Error(`file uploads aren't supported in this environment yet as 'Blob' is undefined. ${t}`)}},File:"undefined"!=typeof File?File:class{constructor(){throw new Error(`file uploads aren't supported in this environment yet as 'File' is undefined. ${t}`)}},ReadableStream:"undefined"!=typeof ReadableStream?ReadableStream:class{constructor(){throw new Error(`streaming isn't supported in this environment yet as 'ReadableStream' is undefined. ${t}`)}},getMultipartRequestOptions:async(e,t)=>({...t,body:new tv(e)}),getDefaultAgent:e=>{},fileFromPath:()=>{throw new Error("The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/openai/openai-node#file-uploads")},isFsReadStream:e=>!1}}(),{auto:!0})};nv();class rv extends Error{}class iv extends rv{constructor(e,t,n,r){super(`${iv.makeMessage(e,t,n)}`),this.status=e,this.headers=r,this.request_id=r?.["x-request-id"],this.error=t;const i=t;this.code=i?.code,this.param=i?.param,this.type=i?.type}static makeMessage(e,t,n){const r=t?.message?"string"==typeof t.message?t.message:JSON.stringify(t.message):t?JSON.stringify(t):n;return e&&r?`${e} ${r}`:e?`${e} status code (no body)`:r||"(no status code or body)"}static generate(e,t,n,r){if(!e||!r)return new av({message:n,cause:n_(t)});const i=t?.error;return 400===e?new cv(e,i,n,r):401===e?new Av(e,i,n,r):403===e?new lv(e,i,n,r):404===e?new fv(e,i,n,r):409===e?new uv(e,i,n,r):422===e?new dv(e,i,n,r):429===e?new hv(e,i,n,r):e>=500?new pv(e,i,n,r):new iv(e,i,n,r)}}class sv extends iv{constructor({message:e}={}){super(void 0,void 0,e||"Request was aborted.",void 0)}}class av extends iv{constructor({message:e,cause:t}){super(void 0,void 0,e||"Connection error.",void 0),t&&(this.cause=t)}}class ov extends av{constructor({message:e}={}){super({message:e??"Request timed out."})}}class cv extends iv{}class Av extends iv{}class lv extends iv{}class fv extends iv{}class uv extends iv{}class dv extends iv{}class hv extends iv{}class pv extends iv{}class mv extends rv{constructor(){super("Could not parse response content as the length limit was reached")}}class yv extends rv{constructor(){super("Could not parse response content as the request was rejected by the content filter")}}var gv,bv=function(e,t,n,r,i){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t.set(e,n),n},wv=function(e,t,n,r){if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)};class vv{constructor(){gv.set(this,void 0),this.buffer=new Uint8Array,bv(this,gv,null)}decode(e){if(null==e)return[];const t=e instanceof ArrayBuffer?new Uint8Array(e):"string"==typeof e?(new TextEncoder).encode(e):e;let n=new Uint8Array(this.buffer.length+t.length);n.set(this.buffer),n.set(t,this.buffer.length),this.buffer=n;const r=[];let i;for(;null!=(i=_v(this.buffer,wv(this,gv,"f")));){if(i.carriage&&null==wv(this,gv,"f")){bv(this,gv,i.index);continue}if(null!=wv(this,gv,"f")&&(i.index!==wv(this,gv,"f")+1||i.carriage)){r.push(this.decodeText(this.buffer.slice(0,wv(this,gv,"f")-1))),this.buffer=this.buffer.slice(wv(this,gv,"f")),bv(this,gv,null);continue}const e=null!==wv(this,gv,"f")?i.preceding-1:i.preceding,t=this.decodeText(this.buffer.slice(0,e));r.push(t),this.buffer=this.buffer.slice(i.index),bv(this,gv,null)}return r}decodeText(e){if(null==e)return"";if("string"==typeof e)return e;if("undefined"!=typeof Buffer){if(e instanceof Buffer)return e.toString();if(e instanceof Uint8Array)return Buffer.from(e).toString();throw new rv(`Unexpected: received non-Uint8Array (${e.constructor.name}) stream chunk in an environment with a global "Buffer" defined, which this library assumes to be Node. Please report this error.`)}if("undefined"!=typeof TextDecoder){if(e instanceof Uint8Array||e instanceof ArrayBuffer)return this.textDecoder??(this.textDecoder=new TextDecoder("utf8")),this.textDecoder.decode(e);throw new rv(`Unexpected: received non-Uint8Array/ArrayBuffer (${e.constructor.name}) in a web platform. Please report this error.`)}throw new rv("Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.")}flush(){return this.buffer.length?this.decode("\n"):[]}}function _v(e,t){for(let n=t??0;n<e.length;n++){if(10===e[n])return{preceding:n,index:n+1,carriage:!1};if(13===e[n])return{preceding:n,index:n+1,carriage:!0}}return null}function Ev(e){for(let t=0;t<e.length-1;t++){if(10===e[t]&&10===e[t+1])return t+2;if(13===e[t]&&13===e[t+1])return t+2;if(13===e[t]&&10===e[t+1]&&t+3<e.length&&13===e[t+2]&&10===e[t+3])return t+4}return-1}function kv(e){if(e[Symbol.asyncIterator])return e;const t=e.getReader();return{async next(){try{const e=await t.read();return e?.done&&t.releaseLock(),e}catch(e){throw t.releaseLock(),e}},async return(){const e=t.cancel();return t.releaseLock(),await e,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}gv=new WeakMap,vv.NEWLINE_CHARS=new Set(["\n","\r"]),vv.NEWLINE_REGEXP=/\r\n|[\n\r]/g;class Tv{constructor(e,t){this.iterator=e,this.controller=t}static fromSSEResponse(e,t){let n=!1;return new Tv(async function*(){if(n)throw new Error("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");n=!0;let r=!1;try{for await(const n of async function*(e,t){if(!e.body)throw t.abort(),new rv("Attempted to iterate over a response with no body");const n=new Sv,r=new vv,i=kv(e.body);for await(const s of async function*(e){let t=new Uint8Array;for await(const n of e){if(null==n)continue;const e=n instanceof ArrayBuffer?new Uint8Array(n):"string"==typeof n?(new TextEncoder).encode(n):n;let r,i=new Uint8Array(t.length+e.length);for(i.set(t),i.set(e,t.length),t=i;-1!==(r=Ev(t));)yield t.slice(0,r),t=t.slice(r)}t.length>0&&(yield t)}(i))for(const e of r.decode(s)){const t=n.decode(e);t&&(yield t)}for(const s of r.flush()){const e=n.decode(s);e&&(yield e)}}(e,t))if(!r)if(n.data.startsWith("[DONE]"))r=!0;else if(null===n.event||n.event.startsWith("response.")||n.event.startsWith("transcript.")){let t;try{t=JSON.parse(n.data)}catch(i){throw console.error("Could not parse message into JSON:",n.data),console.error("From chunk:",n.raw),i}if(t&&t.error)throw new iv(void 0,t.error,void 0,zv(e.headers));yield t}else{let e;try{e=JSON.parse(n.data)}catch(i){throw console.error("Could not parse message into JSON:",n.data),console.error("From chunk:",n.raw),i}if("error"==n.event)throw new iv(void 0,e.error,e.message,void 0);yield{event:n.event,data:e}}r=!0}catch(i){if(i instanceof Error&&"AbortError"===i.name)return;throw i}finally{r||t.abort()}},t)}static fromReadableStream(e,t){let n=!1;return new Tv(async function*(){if(n)throw new Error("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");n=!0;let r=!1;try{for await(const t of async function*(){const t=new vv,n=kv(e);for await(const e of n)for(const n of t.decode(e))yield n;for(const e of t.flush())yield e}())r||t&&(yield JSON.parse(t));r=!0}catch(i){if(i instanceof Error&&"AbortError"===i.name)return;throw i}finally{r||t.abort()}},t)}[Symbol.asyncIterator](){return this.iterator()}tee(){const e=[],t=[],n=this.iterator(),r=r=>({next:()=>{if(0===r.length){const r=n.next();e.push(r),t.push(r)}return r.shift()}});return[new Tv(()=>r(e),this.controller),new Tv(()=>r(t),this.controller)]}toReadableStream(){const e=this;let t;const n=new TextEncoder;return new Kw({async start(){t=e[Symbol.asyncIterator]()},async pull(e){try{const{value:r,done:i}=await t.next();if(i)return e.close();const s=n.encode(JSON.stringify(r)+"\n");e.enqueue(s)}catch(r){e.error(r)}},async cancel(){await(t.return?.())}})}}class Sv{constructor(){this.event=null,this.data=[],this.chunks=[]}decode(e){if(e.endsWith("\r")&&(e=e.substring(0,e.length-1)),!e){if(!this.event&&!this.data.length)return null;const e={event:this.event,data:this.data.join("\n"),raw:this.chunks};return this.event=null,this.data=[],this.chunks=[],e}if(this.chunks.push(e),e.startsWith(":"))return null;let[t,n,r]=function(e){const t=e.indexOf(":");return-1!==t?[e.substring(0,t),":",e.substring(t+1)]:[e,"",""]}(e);return r.startsWith(" ")&&(r=r.substring(1)),"event"===t?this.event=r:"data"===t&&this.data.push(r),null}}const xv=e=>null!=e&&"object"==typeof e&&"string"==typeof e.url&&"function"==typeof e.blob,Iv=e=>null!=e&&"object"==typeof e&&"string"==typeof e.name&&"number"==typeof e.lastModified&&Pv(e),Pv=e=>null!=e&&"object"==typeof e&&"number"==typeof e.size&&"string"==typeof e.type&&"function"==typeof e.text&&"function"==typeof e.slice&&"function"==typeof e.arrayBuffer;async function Cv(e,t,n){if(e=await e,Iv(e))return e;if(xv(e)){const r=await e.blob();t||(t=new URL(e.url).pathname.split(/[\\/]/).pop()??"unknown_file");const i=Pv(r)?[await r.arrayBuffer()]:[r];return new Jw(i,t,n)}const r=await async function(e){let t=[];if("string"==typeof e||ArrayBuffer.isView(e)||e instanceof ArrayBuffer)t.push(e);else if(Pv(e))t.push(await e.arrayBuffer());else{if(!Ov(e))throw new Error(`Unexpected data type: ${typeof e}; constructor: ${e?.constructor?.name}; props: ${function(e){return`[${Object.getOwnPropertyNames(e).map(e=>`"${e}"`).join(", ")}]`}(e)}`);for await(const n of e)t.push(n)}return t}(e);if(t||(t=function(e){return Nv(e.name)||Nv(e.filename)||Nv(e.path)?.split(/[\\/]/).pop()}(e)??"unknown_file"),!n?.type){const e=r[0]?.type;"string"==typeof e&&(n={...n,type:e})}return new Jw(r,t,n)}const Nv=e=>"string"==typeof e?e:"undefined"!=typeof Buffer&&e instanceof Buffer?String(e):void 0,Ov=e=>null!=e&&"object"==typeof e&&"function"==typeof e[Symbol.asyncIterator],Rv=e=>e&&"object"==typeof e&&e.body&&"MultipartBody"===e[Symbol.toStringTag],Bv=async e=>{const t=await Mv(e.body);return Ww(t,e)},Mv=async e=>{const t=new Vw;return await Promise.all(Object.entries(e||{}).map(([e,n])=>$v(t,e,n))),t},$v=async(e,t,n)=>{if(void 0!==n){if(null==n)throw new TypeError(`Received null for "${t}"; to pass null in FormData, you must use the string 'null'`);if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)e.append(t,String(n));else if((e=>Iv(e)||xv(e)||Xw(e))(n)){const r=await Cv(n);e.append(t,r)}else if(Array.isArray(n))await Promise.all(n.map(n=>$v(e,t+"[]",n)));else{if("object"!=typeof n)throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${n} instead`);await Promise.all(Object.entries(n).map(([n,r])=>$v(e,`${t}[${n}]`,r)))}}};var Dv;async function Fv(e){const{response:t}=e;if(e.options.stream)return c_("response",t.status,t.url,t.headers,t.body),e.options.__streamClass?e.options.__streamClass.fromSSEResponse(t,e.controller):Tv.fromSSEResponse(t,e.controller);if(204===t.status)return null;if(e.options.__binaryResponse)return t;const n=t.headers.get("content-type"),r=n?.split(";")[0]?.trim();if(r?.includes("application/json")||r?.endsWith("+json")){const e=await t.json();return c_("response",t.status,t.url,t.headers,e),Gv(e,t)}const i=await t.text();return c_("response",t.status,t.url,t.headers,i),i}function Gv(e,t){return!e||"object"!=typeof e||Array.isArray(e)?e:Object.defineProperty(e,"_request_id",{value:t.headers.get("x-request-id"),enumerable:!1})}nv();class Uv extends Promise{constructor(e,t=Fv){super(e=>{e(null)}),this.responsePromise=e,this.parseResponse=t}_thenUnwrap(e){return new Uv(this.responsePromise,async t=>Gv(e(await this.parseResponse(t),t),t.response))}asResponse(){return this.responsePromise.then(e=>e.response)}async withResponse(){const[e,t]=await Promise.all([this.parse(),this.asResponse()]);return{data:e,response:t,request_id:t.headers.get("x-request-id")}}parse(){return this.parsedPromise||(this.parsedPromise=this.responsePromise.then(this.parseResponse)),this.parsedPromise}then(e,t){return this.parse().then(e,t)}catch(e){return this.parse().catch(e)}finally(e){return this.parse().finally(e)}}class Lv{constructor({baseURL:e,maxRetries:t=2,timeout:n=6e5,httpAgent:r,fetch:i}){this.baseURL=e,this.maxRetries=t_("maxRetries",t),this.timeout=t_("timeout",n),this.httpAgent=r,this.fetch=i??Qw}authHeaders(e){return{}}defaultHeaders(e){return{Accept:"application/json","Content-Type":"application/json","User-Agent":this.getUserAgent(),...Wv(),...this.authHeaders(e)}}validateHeaders(e,t){}defaultIdempotencyKey(){return`stainless-node-retry-${A_()}`}get(e,t){return this.methodRequest("get",e,t)}post(e,t){return this.methodRequest("post",e,t)}patch(e,t){return this.methodRequest("patch",e,t)}put(e,t){return this.methodRequest("put",e,t)}delete(e,t){return this.methodRequest("delete",e,t)}methodRequest(e,t,n){return this.request(Promise.resolve(n).then(async n=>{const r=n&&Pv(n?.body)?new DataView(await n.body.arrayBuffer()):n?.body instanceof DataView?n.body:n?.body instanceof ArrayBuffer?new DataView(n.body):n&&ArrayBuffer.isView(n?.body)?new DataView(n.body.buffer):n?.body;return{method:e,path:t,...n,body:r}}))}getAPIList(e,t,n){return this.requestAPIList(t,{method:"get",path:e,...n})}calculateContentLength(e){if("string"==typeof e){if("undefined"!=typeof Buffer)return Buffer.byteLength(e,"utf8").toString();if("undefined"!=typeof TextEncoder)return(new TextEncoder).encode(e).length.toString()}else if(ArrayBuffer.isView(e))return e.byteLength.toString();return null}buildRequest(e,{retryCount:t=0}={}){const n={...e},{method:r,path:i,query:s,headers:a={}}=n,o=ArrayBuffer.isView(n.body)||n.__binaryRequest&&"string"==typeof n.body?n.body:Rv(n.body)?n.body.body:n.body?JSON.stringify(n.body,null,2):null,c=this.calculateContentLength(o),A=this.buildURL(i,s);"timeout"in n&&t_("timeout",n.timeout),n.timeout=n.timeout??this.timeout;const l=n.httpAgent??this.httpAgent??Yw(A),f=n.timeout+1e3;return"number"==typeof l?.options?.timeout&&f>(l.options.timeout??0)&&(l.options.timeout=f),this.idempotencyHeader&&"get"!==r&&(e.idempotencyKey||(e.idempotencyKey=this.defaultIdempotencyKey()),a[this.idempotencyHeader]=e.idempotencyKey),{req:{method:r,...o&&{body:o},headers:this.buildHeaders({options:n,headers:a,contentLength:c,retryCount:t}),...l&&{agent:l},signal:n.signal??null},url:A,timeout:n.timeout}}buildHeaders({options:e,headers:t,contentLength:n,retryCount:r}){const i={};n&&(i["content-length"]=n);const s=this.defaultHeaders(e);return a_(i,s),a_(i,t),Rv(e.body)&&"node"!==qw&&delete i["content-type"],void 0===l_(s,"x-stainless-retry-count")&&void 0===l_(t,"x-stainless-retry-count")&&(i["x-stainless-retry-count"]=String(r)),void 0===l_(s,"x-stainless-timeout")&&void 0===l_(t,"x-stainless-timeout")&&e.timeout&&(i["x-stainless-timeout"]=String(Math.trunc(e.timeout/1e3))),this.validateHeaders(i,t),i}async prepareOptions(e){}async prepareRequest(e,{url:t,options:n}){}parseHeaders(e){return e?Symbol.iterator in e?Object.fromEntries(Array.from(e).map(e=>[...e])):{...e}:{}}makeStatusError(e,t,n,r){return iv.generate(e,t,n,r)}request(e,t=null){return new Uv(this.makeRequest(e,t))}async makeRequest(e,t){const n=await e,r=n.maxRetries??this.maxRetries;null==t&&(t=r),await this.prepareOptions(n);const{req:i,url:s,timeout:a}=this.buildRequest(n,{retryCount:r-t});if(await this.prepareRequest(i,{url:s,options:n}),c_("request",s,n,i.headers),n.signal?.aborted)throw new sv;const o=new AbortController,c=await this.fetchWithTimeout(s,i,a,o).catch(n_);if(c instanceof Error){if(n.signal?.aborted)throw new sv;if(t)return this.retryRequest(n,t);if("AbortError"===c.name)throw new ov;throw new av({cause:c})}const A=zv(c.headers);if(!c.ok){if(t&&this.shouldRetry(c))return c_(`response (error; retrying, ${t} attempts remaining)`,c.status,s,A),this.retryRequest(n,t,A);const e=await c.text().catch(e=>n_(e).message),r=Yv(e),i=r?void 0:e;throw c_(`response (error; ${t?"(error; no more retries left)":"(error; not retryable)"})`,c.status,s,A,i),this.makeStatusError(c.status,r,i,A)}return{response:c,options:n,controller:o}}requestAPIList(e,t){const n=this.makeRequest(t,null);return new Hv(this,n,e)}buildURL(e,t){const n=Xv(e)?new URL(e):new URL(this.baseURL+(this.baseURL.endsWith("/")&&e.startsWith("/")?e.slice(1):e)),r=this.defaultQuery();return i_(r)||(t={...r,...t}),"object"==typeof t&&t&&!Array.isArray(t)&&(n.search=this.stringifyQuery(t)),n.toString()}stringifyQuery(e){return Object.entries(e).filter(([e,t])=>void 0!==t).map(([e,t])=>{if("string"==typeof t||"number"==typeof t||"boolean"==typeof t)return`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;if(null===t)return`${encodeURIComponent(e)}=`;throw new rv(`Cannot stringify type ${typeof t}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`)}).join("&")}async fetchWithTimeout(e,t,n,r){const{signal:i,...s}=t||{};i&&i.addEventListener("abort",()=>r.abort());const a=setTimeout(()=>r.abort(),n),o={signal:r.signal,...s};return o.method&&(o.method=o.method.toUpperCase()),this.fetch.call(void 0,e,o).finally(()=>{clearTimeout(a)})}shouldRetry(e){const t=e.headers.get("x-should-retry");return"true"===t||"false"!==t&&(408===e.status||409===e.status||429===e.status||e.status>=500)}async retryRequest(e,t,n){let r;const i=n?.["retry-after-ms"];if(i){const e=parseFloat(i);Number.isNaN(e)||(r=e)}const s=n?.["retry-after"];if(s&&!r){const e=parseFloat(s);r=Number.isNaN(e)?Date.parse(s)-Date.now():1e3*e}if(!(r&&0<=r&&r<6e4)){const n=e.maxRetries??this.maxRetries;r=this.calculateDefaultRetryTimeoutMillis(t,n)}return await e_(r),this.makeRequest(e,t-1)}calculateDefaultRetryTimeoutMillis(e,t){const n=t-e;return Math.min(.5*Math.pow(2,n),8)*(1-.25*Math.random())*1e3}getUserAgent(){return`${this.constructor.name}/JS ${zw}`}}class jv{constructor(e,t,n,r){Dv.set(this,void 0),function(e,t,n){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");t.set(e,n)}(this,Dv,e),this.options=r,this.response=t,this.body=n}hasNextPage(){return!!this.getPaginatedItems().length&&null!=this.nextPageInfo()}async getNextPage(){const e=this.nextPageInfo();if(!e)throw new rv("No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.");const t={...this.options};if("params"in e&&"object"==typeof t.query)t.query={...t.query,...e.params};else if("url"in e){const n=[...Object.entries(t.query||{}),...e.url.searchParams.entries()];for(const[t,r]of n)e.url.searchParams.set(t,r);t.query=void 0,t.path=e.url.toString()}return await function(e,t){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t.get(e)}(this,Dv).requestAPIList(this.constructor,t)}async*iterPages(){let e=this;for(yield e;e.hasNextPage();)e=await e.getNextPage(),yield e}async*[(Dv=new WeakMap,Symbol.asyncIterator)](){for await(const e of this.iterPages())for(const t of e.getPaginatedItems())yield t}}class Hv extends Uv{constructor(e,t,n){super(t,async t=>new n(e,t.response,await Fv(t),t.options))}async*[Symbol.asyncIterator](){const e=await(this);for await(const t of e)yield t}}const zv=e=>new Proxy(Object.fromEntries(e.entries()),{get(e,t){const n=t.toString();return e[n.toLowerCase()]||e[n]}}),qv={method:!0,path:!0,query:!0,body:!0,headers:!0,maxRetries:!0,stream:!0,timeout:!0,httpAgent:!0,signal:!0,idempotencyKey:!0,__metadata:!0,__binaryRequest:!0,__binaryResponse:!0,__streamClass:!0},Qv=e=>"object"==typeof e&&null!==e&&!i_(e)&&Object.keys(e).every(e=>s_(qv,e)),Vv=e=>"x32"===e?"x32":"x86_64"===e||"x64"===e?"x64":"arm"===e?"arm":"aarch64"===e||"arm64"===e?"arm64":e?`other:${e}`:"unknown",Jv=e=>(e=e.toLowerCase()).includes("ios")?"iOS":"android"===e?"Android":"darwin"===e?"MacOS":"win32"===e?"Windows":"freebsd"===e?"FreeBSD":"openbsd"===e?"OpenBSD":"linux"===e?"Linux":e?`Other:${e}`:"Unknown";let Kv;const Wv=()=>Kv??(Kv=(()=>{if("undefined"!=typeof Deno&&null!=Deno.build)return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":zw,"X-Stainless-OS":Jv(Deno.build.os),"X-Stainless-Arch":Vv(Deno.build.arch),"X-Stainless-Runtime":"deno","X-Stainless-Runtime-Version":"string"==typeof Deno.version?Deno.version:Deno.version?.deno??"unknown"};if("undefined"!=typeof EdgeRuntime)return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":zw,"X-Stainless-OS":"Unknown","X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":"edge","X-Stainless-Runtime-Version":process.version};if("[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0))return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":zw,"X-Stainless-OS":Jv(process.platform),"X-Stainless-Arch":Vv(process.arch),"X-Stainless-Runtime":"node","X-Stainless-Runtime-Version":process.version};const e=function(){if("undefined"==typeof navigator||!navigator)return null;const e=[{key:"edge",pattern:/Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"chrome",pattern:/Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"firefox",pattern:/Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"safari",pattern:/(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/}];for(const{key:t,pattern:n}of e){const e=n.exec(navigator.userAgent);if(e)return{browser:t,version:`${e[1]||0}.${e[2]||0}.${e[3]||0}`}}return null}();return e?{"X-Stainless-Lang":"js","X-Stainless-Package-Version":zw,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":`browser:${e.browser}`,"X-Stainless-Runtime-Version":e.version}:{"X-Stainless-Lang":"js","X-Stainless-Package-Version":zw,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":"unknown","X-Stainless-Runtime-Version":"unknown"}})()),Yv=e=>{try{return JSON.parse(e)}catch(t){return}},Zv=/^[a-z][a-z0-9+.-]*:/i,Xv=e=>Zv.test(e),e_=e=>new Promise(t=>setTimeout(t,e)),t_=(e,t)=>{if("number"!=typeof t||!Number.isInteger(t))throw new rv(`${e} must be an integer`);if(t<0)throw new rv(`${e} must be a positive integer`);return t},n_=e=>{if(e instanceof Error)return e;if("object"==typeof e&&null!==e)try{return new Error(JSON.stringify(e))}catch{}return new Error(e)},r_=e=>"undefined"!=typeof process?process.env?.[e]?.trim()??void 0:"undefined"!=typeof Deno?Deno.env?.get?.(e)?.trim():void 0;function i_(e){if(!e)return!0;for(const t in e)return!1;return!0}function s_(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function a_(e,t){for(const n in t){if(!s_(t,n))continue;const r=n.toLowerCase();if(!r)continue;const i=t[n];null===i?delete e[r]:void 0!==i&&(e[r]=i)}}const o_=new Set(["authorization","api-key"]);function c_(e,...t){if("undefined"!=typeof process&&"true"===process?.env?.DEBUG){const n=t.map(e=>{if(!e)return e;if(e.headers){const t={...e,headers:{...e.headers}};for(const n in e.headers)o_.has(n.toLowerCase())&&(t.headers[n]="REDACTED");return t}let t=null;for(const n in e)o_.has(n.toLowerCase())&&(t??(t={...e}),t[n]="REDACTED");return t??e});console.log(`OpenAI:DEBUG:${e}`,...n)}}const A_=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}),l_=(e,t)=>{const n=t.toLowerCase();if((e=>"function"==typeof e?.get)(e)){const r=t[0]?.toUpperCase()+t.substring(1).replace(/([^\w])(\w)/g,(e,t,n)=>t+n.toUpperCase());for(const i of[t,n,t.toUpperCase(),r]){const t=e.get(i);if(t)return t}}for(const[r,i]of Object.entries(e))if(r.toLowerCase()===n)return Array.isArray(i)?(i.length<=1||console.warn(`Received ${i.length} entries for the ${t} header, using the first entry.`),i[0]):i};function f_(e){return null!=e&&"object"==typeof e&&!Array.isArray(e)}class u_ extends jv{constructor(e,t,n,r){super(e,t,n,r),this.data=n.data||[],this.object=n.object}getPaginatedItems(){return this.data??[]}nextPageParams(){return null}nextPageInfo(){return null}}class d_ extends jv{constructor(e,t,n,r){super(e,t,n,r),this.data=n.data||[],this.has_more=n.has_more||!1}getPaginatedItems(){return this.data??[]}hasNextPage(){return!1!==this.has_more&&super.hasNextPage()}nextPageParams(){const e=this.nextPageInfo();if(!e)return null;if("params"in e)return e.params;const t=Object.fromEntries(e.url.searchParams);return Object.keys(t).length?t:null}nextPageInfo(){const e=this.getPaginatedItems();if(!e.length)return null;const t=e[e.length-1]?.id;return t?{params:{after:t}}:null}}class h_{constructor(e){this._client=e}}let p_=class extends h_{list(e,t={},n){return Qv(t)?this.list(e,{},t):this._client.getAPIList(`/chat/completions/${e}/messages`,g_,{query:t,...n})}},m_=class extends h_{constructor(){super(...arguments),this.messages=new p_(this._client)}create(e,t){return this._client.post("/chat/completions",{body:e,...t,stream:e.stream??!1})}retrieve(e,t){return this._client.get(`/chat/completions/${e}`,t)}update(e,t,n){return this._client.post(`/chat/completions/${e}`,{body:t,...n})}list(e={},t){return Qv(e)?this.list({},e):this._client.getAPIList("/chat/completions",y_,{query:e,...t})}del(e,t){return this._client.delete(`/chat/completions/${e}`,t)}};class y_ extends d_{}class g_ extends d_{}m_.ChatCompletionsPage=y_,m_.Messages=p_;let b_=class extends h_{constructor(){super(...arguments),this.completions=new m_(this._client)}};b_.Completions=m_,b_.ChatCompletionsPage=y_;class w_ extends h_{create(e,t){return this._client.post("/audio/speech",{body:e,...t,headers:{Accept:"application/octet-stream",...t?.headers},__binaryResponse:!0})}}class v_ extends h_{create(e,t){return this._client.post("/audio/transcriptions",Bv({body:e,...t,stream:e.stream??!1,__metadata:{model:e.model}}))}}class __ extends h_{create(e,t){return this._client.post("/audio/translations",Bv({body:e,...t,__metadata:{model:e.model}}))}}class E_ extends h_{constructor(){super(...arguments),this.transcriptions=new v_(this._client),this.translations=new __(this._client),this.speech=new w_(this._client)}}E_.Transcriptions=v_,E_.Translations=__,E_.Speech=w_;class k_ extends h_{create(e,t){return this._client.post("/batches",{body:e,...t})}retrieve(e,t){return this._client.get(`/batches/${e}`,t)}list(e={},t){return Qv(e)?this.list({},e):this._client.getAPIList("/batches",T_,{query:e,...t})}cancel(e,t){return this._client.post(`/batches/${e}/cancel`,t)}}class T_ extends d_{}k_.BatchesPage=T_;var S_,x_,I_,P_,C_,N_,O_,R_,B_,M_,$_,D_,F_,G_=function(e,t,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?i.call(e,n):i?i.value=n:t.set(e,n),n},U_=function(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)};class L_{constructor(){S_.add(this),this.controller=new AbortController,x_.set(this,void 0),I_.set(this,()=>{}),P_.set(this,()=>{}),C_.set(this,void 0),N_.set(this,()=>{}),O_.set(this,()=>{}),R_.set(this,{}),B_.set(this,!1),M_.set(this,!1),$_.set(this,!1),D_.set(this,!1),G_(this,x_,new Promise((e,t)=>{G_(this,I_,e,"f"),G_(this,P_,t,"f")}),"f"),G_(this,C_,new Promise((e,t)=>{G_(this,N_,e,"f"),G_(this,O_,t,"f")}),"f"),U_(this,x_,"f").catch(()=>{}),U_(this,C_,"f").catch(()=>{})}_run(e){setTimeout(()=>{e().then(()=>{this._emitFinal(),this._emit("end")},U_(this,S_,"m",F_).bind(this))},0)}_connected(){this.ended||(U_(this,I_,"f").call(this),this._emit("connect"))}get ended(){return U_(this,B_,"f")}get errored(){return U_(this,M_,"f")}get aborted(){return U_(this,$_,"f")}abort(){this.controller.abort()}on(e,t){return(U_(this,R_,"f")[e]||(U_(this,R_,"f")[e]=[])).push({listener:t}),this}off(e,t){const n=U_(this,R_,"f")[e];if(!n)return this;const r=n.findIndex(e=>e.listener===t);return r>=0&&n.splice(r,1),this}once(e,t){return(U_(this,R_,"f")[e]||(U_(this,R_,"f")[e]=[])).push({listener:t,once:!0}),this}emitted(e){return new Promise((t,n)=>{G_(this,D_,!0,"f"),"error"!==e&&this.once("error",n),this.once(e,t)})}async done(){G_(this,D_,!0,"f"),await U_(this,C_,"f")}_emit(e,...t){if(U_(this,B_,"f"))return;"end"===e&&(G_(this,B_,!0,"f"),U_(this,N_,"f").call(this));const n=U_(this,R_,"f")[e];if(n&&(U_(this,R_,"f")[e]=n.filter(e=>!e.once),n.forEach(({listener:e})=>e(...t))),"abort"===e){const e=t[0];return U_(this,D_,"f")||n?.length||Promise.reject(e),U_(this,P_,"f").call(this,e),U_(this,O_,"f").call(this,e),void this._emit("end")}if("error"===e){const e=t[0];U_(this,D_,"f")||n?.length||Promise.reject(e),U_(this,P_,"f").call(this,e),U_(this,O_,"f").call(this,e),this._emit("end")}}_emitFinal(){}}x_=new WeakMap,I_=new WeakMap,P_=new WeakMap,C_=new WeakMap,N_=new WeakMap,O_=new WeakMap,R_=new WeakMap,B_=new WeakMap,M_=new WeakMap,$_=new WeakMap,D_=new WeakMap,S_=new WeakSet,F_=function(e){if(G_(this,M_,!0,"f"),e instanceof Error&&"AbortError"===e.name&&(e=new sv),e instanceof sv)return G_(this,$_,!0,"f"),this._emit("abort",e);if(e instanceof rv)return this._emit("error",e);if(e instanceof Error){const t=new rv(e.message);return t.cause=e,this._emit("error",t)}return this._emit("error",new rv(String(e)))};var j_,H_,z_,q_,Q_,V_,J_,K_,W_,Y_,Z_,X_,eE,tE,nE,rE,iE,sE,aE,oE,cE,AE,lE=function(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)},fE=function(e,t,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?i.call(e,n):i?i.value=n:t.set(e,n),n};class uE extends L_{constructor(){super(...arguments),j_.add(this),H_.set(this,[]),z_.set(this,{}),q_.set(this,{}),Q_.set(this,void 0),V_.set(this,void 0),J_.set(this,void 0),K_.set(this,void 0),W_.set(this,void 0),Y_.set(this,void 0),Z_.set(this,void 0),X_.set(this,void 0),eE.set(this,void 0)}[(H_=new WeakMap,z_=new WeakMap,q_=new WeakMap,Q_=new WeakMap,V_=new WeakMap,J_=new WeakMap,K_=new WeakMap,W_=new WeakMap,Y_=new WeakMap,Z_=new WeakMap,X_=new WeakMap,eE=new WeakMap,j_=new WeakSet,Symbol.asyncIterator)](){const e=[],t=[];let n=!1;return this.on("event",n=>{const r=t.shift();r?r.resolve(n):e.push(n)}),this.on("end",()=>{n=!0;for(const e of t)e.resolve(void 0);t.length=0}),this.on("abort",e=>{n=!0;for(const n of t)n.reject(e);t.length=0}),this.on("error",e=>{n=!0;for(const n of t)n.reject(e);t.length=0}),{next:async()=>e.length?{value:e.shift(),done:!1}:n?{value:void 0,done:!0}:new Promise((e,n)=>t.push({resolve:e,reject:n})).then(e=>e?{value:e,done:!1}:{value:void 0,done:!0}),return:async()=>(this.abort(),{value:void 0,done:!0})}}static fromReadableStream(e){const t=new uE;return t._run(()=>t._fromReadableStream(e)),t}async _fromReadableStream(e,t){const n=t?.signal;n&&(n.aborted&&this.controller.abort(),n.addEventListener("abort",()=>this.controller.abort())),this._connected();const r=Tv.fromReadableStream(e,this.controller);for await(const i of r)lE(this,j_,"m",tE).call(this,i);if(r.controller.signal?.aborted)throw new sv;return this._addRun(lE(this,j_,"m",nE).call(this))}toReadableStream(){return new Tv(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}static createToolAssistantStream(e,t,n,r,i){const s=new uE;return s._run(()=>s._runToolAssistantStream(e,t,n,r,{...i,headers:{...i?.headers,"X-Stainless-Helper-Method":"stream"}})),s}async _createToolAssistantStream(e,t,n,r,i){const s=i?.signal;s&&(s.aborted&&this.controller.abort(),s.addEventListener("abort",()=>this.controller.abort()));const a={...r,stream:!0},o=await e.submitToolOutputs(t,n,a,{...i,signal:this.controller.signal});this._connected();for await(const c of o)lE(this,j_,"m",tE).call(this,c);if(o.controller.signal?.aborted)throw new sv;return this._addRun(lE(this,j_,"m",nE).call(this))}static createThreadAssistantStream(e,t,n){const r=new uE;return r._run(()=>r._threadAssistantStream(e,t,{...n,headers:{...n?.headers,"X-Stainless-Helper-Method":"stream"}})),r}static createAssistantStream(e,t,n,r){const i=new uE;return i._run(()=>i._runAssistantStream(e,t,n,{...r,headers:{...r?.headers,"X-Stainless-Helper-Method":"stream"}})),i}currentEvent(){return lE(this,Z_,"f")}currentRun(){return lE(this,X_,"f")}currentMessageSnapshot(){return lE(this,Q_,"f")}currentRunStepSnapshot(){return lE(this,eE,"f")}async finalRunSteps(){return await this.done(),Object.values(lE(this,z_,"f"))}async finalMessages(){return await this.done(),Object.values(lE(this,q_,"f"))}async finalRun(){if(await this.done(),!lE(this,V_,"f"))throw Error("Final run was not received.");return lE(this,V_,"f")}async _createThreadAssistantStream(e,t,n){const r=n?.signal;r&&(r.aborted&&this.controller.abort(),r.addEventListener("abort",()=>this.controller.abort()));const i={...t,stream:!0},s=await e.createAndRun(i,{...n,signal:this.controller.signal});this._connected();for await(const a of s)lE(this,j_,"m",tE).call(this,a);if(s.controller.signal?.aborted)throw new sv;return this._addRun(lE(this,j_,"m",nE).call(this))}async _createAssistantStream(e,t,n,r){const i=r?.signal;i&&(i.aborted&&this.controller.abort(),i.addEventListener("abort",()=>this.controller.abort()));const s={...n,stream:!0},a=await e.create(t,s,{...r,signal:this.controller.signal});this._connected();for await(const o of a)lE(this,j_,"m",tE).call(this,o);if(a.controller.signal?.aborted)throw new sv;return this._addRun(lE(this,j_,"m",nE).call(this))}static accumulateDelta(e,t){for(const[n,r]of Object.entries(t)){if(!e.hasOwnProperty(n)){e[n]=r;continue}let t=e[n];if(null!=t)if("index"!==n&&"type"!==n){if("string"==typeof t&&"string"==typeof r)t+=r;else if("number"==typeof t&&"number"==typeof r)t+=r;else{if(!f_(t)||!f_(r)){if(Array.isArray(t)&&Array.isArray(r)){if(t.every(e=>"string"==typeof e||"number"==typeof e)){t.push(...r);continue}for(const e of r){if(!f_(e))throw new Error(`Expected array delta entry to be an object but got: ${e}`);const n=e.index;if(null==n)throw console.error(e),new Error("Expected array delta entry to have an `index` property");if("number"!=typeof n)throw new Error(`Expected array delta entry \`index\` property to be a number but got ${n}`);const r=t[n];null==r?t.push(e):t[n]=this.accumulateDelta(r,e)}continue}throw Error(`Unhandled record type: ${n}, deltaValue: ${r}, accValue: ${t}`)}t=this.accumulateDelta(t,r)}e[n]=t}else e[n]=r;else e[n]=r}return e}_addRun(e){return e}async _threadAssistantStream(e,t,n){return await this._createThreadAssistantStream(t,e,n)}async _runAssistantStream(e,t,n,r){return await this._createAssistantStream(t,e,n,r)}async _runToolAssistantStream(e,t,n,r,i){return await this._createToolAssistantStream(n,e,t,r,i)}}tE=function(e){if(!this.ended)switch(fE(this,Z_,e,"f"),lE(this,j_,"m",sE).call(this,e),e.event){case"thread.created":break;case"thread.run.created":case"thread.run.queued":case"thread.run.in_progress":case"thread.run.requires_action":case"thread.run.completed":case"thread.run.incomplete":case"thread.run.failed":case"thread.run.cancelling":case"thread.run.cancelled":case"thread.run.expired":lE(this,j_,"m",AE).call(this,e);break;case"thread.run.step.created":case"thread.run.step.in_progress":case"thread.run.step.delta":case"thread.run.step.completed":case"thread.run.step.failed":case"thread.run.step.cancelled":case"thread.run.step.expired":lE(this,j_,"m",iE).call(this,e);break;case"thread.message.created":case"thread.message.in_progress":case"thread.message.delta":case"thread.message.completed":case"thread.message.incomplete":lE(this,j_,"m",rE).call(this,e);break;case"error":throw new Error("Encountered an error event in event processing - errors should be processed earlier")}},nE=function(){if(this.ended)throw new rv("stream has ended, this shouldn't happen");if(!lE(this,V_,"f"))throw Error("Final run has not been received");return lE(this,V_,"f")},rE=function(e){const[t,n]=lE(this,j_,"m",oE).call(this,e,lE(this,Q_,"f"));fE(this,Q_,t,"f"),lE(this,q_,"f")[t.id]=t;for(const r of n){const e=t.content[r.index];"text"==e?.type&&this._emit("textCreated",e.text)}switch(e.event){case"thread.message.created":this._emit("messageCreated",e.data);break;case"thread.message.in_progress":break;case"thread.message.delta":if(this._emit("messageDelta",e.data.delta,t),e.data.delta.content)for(const n of e.data.delta.content){if("text"==n.type&&n.text){let e=n.text,r=t.content[n.index];if(!r||"text"!=r.type)throw Error("The snapshot associated with this text delta is not text or missing");this._emit("textDelta",e,r.text)}if(n.index!=lE(this,J_,"f")){if(lE(this,K_,"f"))switch(lE(this,K_,"f").type){case"text":this._emit("textDone",lE(this,K_,"f").text,lE(this,Q_,"f"));break;case"image_file":this._emit("imageFileDone",lE(this,K_,"f").image_file,lE(this,Q_,"f"))}fE(this,J_,n.index,"f")}fE(this,K_,t.content[n.index],"f")}break;case"thread.message.completed":case"thread.message.incomplete":if(void 0!==lE(this,J_,"f")){const t=e.data.content[lE(this,J_,"f")];if(t)switch(t.type){case"image_file":this._emit("imageFileDone",t.image_file,lE(this,Q_,"f"));break;case"text":this._emit("textDone",t.text,lE(this,Q_,"f"))}}lE(this,Q_,"f")&&this._emit("messageDone",e.data),fE(this,Q_,void 0,"f")}},iE=function(e){const t=lE(this,j_,"m",aE).call(this,e);switch(fE(this,eE,t,"f"),e.event){case"thread.run.step.created":this._emit("runStepCreated",e.data);break;case"thread.run.step.delta":const n=e.data.delta;if(n.step_details&&"tool_calls"==n.step_details.type&&n.step_details.tool_calls&&"tool_calls"==t.step_details.type)for(const e of n.step_details.tool_calls)e.index==lE(this,W_,"f")?this._emit("toolCallDelta",e,t.step_details.tool_calls[e.index]):(lE(this,Y_,"f")&&this._emit("toolCallDone",lE(this,Y_,"f")),fE(this,W_,e.index,"f"),fE(this,Y_,t.step_details.tool_calls[e.index],"f"),lE(this,Y_,"f")&&this._emit("toolCallCreated",lE(this,Y_,"f")));this._emit("runStepDelta",e.data.delta,t);break;case"thread.run.step.completed":case"thread.run.step.failed":case"thread.run.step.cancelled":case"thread.run.step.expired":fE(this,eE,void 0,"f"),"tool_calls"==e.data.step_details.type&&lE(this,Y_,"f")&&(this._emit("toolCallDone",lE(this,Y_,"f")),fE(this,Y_,void 0,"f")),this._emit("runStepDone",e.data,t)}},sE=function(e){lE(this,H_,"f").push(e),this._emit("event",e)},aE=function(e){switch(e.event){case"thread.run.step.created":return lE(this,z_,"f")[e.data.id]=e.data,e.data;case"thread.run.step.delta":let t=lE(this,z_,"f")[e.data.id];if(!t)throw Error("Received a RunStepDelta before creation of a snapshot");let n=e.data;if(n.delta){const r=uE.accumulateDelta(t,n.delta);lE(this,z_,"f")[e.data.id]=r}return lE(this,z_,"f")[e.data.id];case"thread.run.step.completed":case"thread.run.step.failed":case"thread.run.step.cancelled":case"thread.run.step.expired":case"thread.run.step.in_progress":lE(this,z_,"f")[e.data.id]=e.data}if(lE(this,z_,"f")[e.data.id])return lE(this,z_,"f")[e.data.id];throw new Error("No snapshot available")},oE=function(e,t){let n=[];switch(e.event){case"thread.message.created":return[e.data,n];case"thread.message.delta":if(!t)throw Error("Received a delta with no existing snapshot (there should be one from message creation)");let r=e.data;if(r.delta.content)for(const e of r.delta.content)if(e.index in t.content){let n=t.content[e.index];t.content[e.index]=lE(this,j_,"m",cE).call(this,e,n)}else t.content[e.index]=e,n.push(e);return[t,n];case"thread.message.in_progress":case"thread.message.completed":case"thread.message.incomplete":if(t)return[t,n];throw Error("Received thread message event with no existing snapshot")}throw Error("Tried to accumulate a non-message event")},cE=function(e,t){return uE.accumulateDelta(t,e)},AE=function(e){switch(fE(this,X_,e.data,"f"),e.event){case"thread.run.created":case"thread.run.queued":case"thread.run.in_progress":break;case"thread.run.requires_action":case"thread.run.cancelled":case"thread.run.failed":case"thread.run.completed":case"thread.run.expired":fE(this,V_,e.data,"f"),lE(this,Y_,"f")&&(this._emit("toolCallDone",lE(this,Y_,"f")),fE(this,Y_,void 0,"f"))}};class dE extends h_{create(e,t){return this._client.post("/assistants",{body:e,...t,headers:{"OpenAI-Beta":"assistants=v2",...t?.headers}})}retrieve(e,t){return this._client.get(`/assistants/${e}`,{...t,headers:{"OpenAI-Beta":"assistants=v2",...t?.headers}})}update(e,t,n){return this._client.post(`/assistants/${e}`,{body:t,...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}list(e={},t){return Qv(e)?this.list({},e):this._client.getAPIList("/assistants",hE,{query:e,...t,headers:{"OpenAI-Beta":"assistants=v2",...t?.headers}})}del(e,t){return this._client.delete(`/assistants/${e}`,{...t,headers:{"OpenAI-Beta":"assistants=v2",...t?.headers}})}}class hE extends d_{}function pE(e){return"function"==typeof e.parse}dE.AssistantsPage=hE;const mE=e=>"assistant"===e?.role,yE=e=>"function"===e?.role,gE=e=>"tool"===e?.role;function bE(e){return"auto-parseable-response-format"===e?.$brand}function wE(e){return"auto-parseable-tool"===e?.$brand}function vE(e,t){const n=e.choices.map(e=>{if("length"===e.finish_reason)throw new mv;if("content_filter"===e.finish_reason)throw new yv;return{...e,message:{...e.message,...e.message.tool_calls?{tool_calls:e.message.tool_calls?.map(e=>function(e,t){const n=e.tools?.find(e=>e.function?.name===t.function.name);return{...t,function:{...t.function,parsed_arguments:wE(n)?n.$parseRaw(t.function.arguments):n?.function.strict?JSON.parse(t.function.arguments):null}}}(t,e))??void 0}:void 0,parsed:e.message.content&&!e.message.refusal?_E(t,e.message.content):null}}});return{...e,choices:n}}function _E(e,t){return"json_schema"!==e.response_format?.type?null:"json_schema"===e.response_format?.type?"$parseRaw"in e.response_format?e.response_format.$parseRaw(t):JSON.parse(t):null}function EE(e,t){if(!e)return!1;const n=e.tools?.find(e=>e.function?.name===t.function.name);return wE(n)||n?.function.strict||!1}function kE(e){return!!bE(e.response_format)||(e.tools?.some(e=>wE(e)||"function"===e.type&&!0===e.function.strict)??!1)}var TE,SE,xE,IE,PE,CE,NE,OE,RE=function(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)};const BE=10;class ME extends L_{constructor(){super(...arguments),TE.add(this),this._chatCompletions=[],this.messages=[]}_addChatCompletion(e){this._chatCompletions.push(e),this._emit("chatCompletion",e);const t=e.choices[0]?.message;return t&&this._addMessage(t),e}_addMessage(e,t=!0){if("content"in e||(e.content=null),this.messages.push(e),t)if(this._emit("message",e),(yE(e)||gE(e))&&e.content)this._emit("functionCallResult",e.content);else if(mE(e)&&e.function_call)this._emit("functionCall",e.function_call);else if(mE(e)&&e.tool_calls)for(const n of e.tool_calls)"function"===n.type&&this._emit("functionCall",n.function)}async finalChatCompletion(){await this.done();const e=this._chatCompletions[this._chatCompletions.length-1];if(!e)throw new rv("stream ended without producing a ChatCompletion");return e}async finalContent(){return await this.done(),RE(this,TE,"m",SE).call(this)}async finalMessage(){return await this.done(),RE(this,TE,"m",xE).call(this)}async finalFunctionCall(){return await this.done(),RE(this,TE,"m",IE).call(this)}async finalFunctionCallResult(){return await this.done(),RE(this,TE,"m",PE).call(this)}async totalUsage(){return await this.done(),RE(this,TE,"m",CE).call(this)}allChatCompletions(){return[...this._chatCompletions]}_emitFinal(){const e=this._chatCompletions[this._chatCompletions.length-1];e&&this._emit("finalChatCompletion",e);const t=RE(this,TE,"m",xE).call(this);t&&this._emit("finalMessage",t);const n=RE(this,TE,"m",SE).call(this);n&&this._emit("finalContent",n);const r=RE(this,TE,"m",IE).call(this);r&&this._emit("finalFunctionCall",r);const i=RE(this,TE,"m",PE).call(this);null!=i&&this._emit("finalFunctionCallResult",i),this._chatCompletions.some(e=>e.usage)&&this._emit("totalUsage",RE(this,TE,"m",CE).call(this))}async _createChatCompletion(e,t,n){const r=n?.signal;r&&(r.aborted&&this.controller.abort(),r.addEventListener("abort",()=>this.controller.abort())),RE(this,TE,"m",NE).call(this,t);const i=await e.chat.completions.create({...t,stream:!1},{...n,signal:this.controller.signal});return this._connected(),this._addChatCompletion(vE(i,t))}async _runChatCompletion(e,t,n){for(const r of t.messages)this._addMessage(r,!1);return await this._createChatCompletion(e,t,n)}async _runFunctions(e,t,n){const r="function",{function_call:i="auto",stream:s,...a}=t,o="string"!=typeof i&&i?.name,{maxChatCompletions:c=BE}=n||{},A={};for(const u of t.functions)A[u.name||u.function.name]=u;const l=t.functions.map(e=>({name:e.name||e.function.name,parameters:e.parameters,description:e.description}));for(const u of t.messages)this._addMessage(u,!1);for(let u=0;u<c;++u){const t=await this._createChatCompletion(e,{...a,function_call:i,functions:l,messages:[...this.messages]},n),s=t.choices[0]?.message;if(!s)throw new rv("missing message in ChatCompletion response");if(!s.function_call)return;const{name:c,arguments:u}=s.function_call,d=A[c];if(!d){const e=`Invalid function_call: ${JSON.stringify(c)}. Available options are: ${l.map(e=>JSON.stringify(e.name)).join(", ")}. Please try again`;this._addMessage({role:r,name:c,content:e});continue}if(o&&o!==c){const e=`Invalid function_call: ${JSON.stringify(c)}. ${JSON.stringify(o)} requested. Please try again`;this._addMessage({role:r,name:c,content:e});continue}let h;try{h=pE(d)?await d.parse(u):u}catch(f){this._addMessage({role:r,name:c,content:f instanceof Error?f.message:String(f)});continue}const p=await d.function(h,this),m=RE(this,TE,"m",OE).call(this,p);if(this._addMessage({role:r,name:c,content:m}),o)return}}async _runTools(e,t,n){const r="tool",{tool_choice:i="auto",stream:s,...a}=t,o="string"!=typeof i&&i?.function?.name,{maxChatCompletions:c=BE}=n||{},A=t.tools.map(e=>{if(wE(e)){if(!e.$callback)throw new rv("Tool given to `.runTools()` that does not have an associated function");return{type:"function",function:{function:e.$callback,name:e.function.name,description:e.function.description||"",parameters:e.function.parameters,parse:e.$parseRaw,strict:!0}}}return e}),l={};for(const d of A)"function"===d.type&&(l[d.function.name||d.function.function.name]=d.function);const f="tools"in t?A.map(e=>"function"===e.type?{type:"function",function:{name:e.function.name||e.function.function.name,parameters:e.function.parameters,description:e.function.description,strict:e.function.strict}}:e):void 0;for(const d of t.messages)this._addMessage(d,!1);for(let d=0;d<c;++d){const t=await this._createChatCompletion(e,{...a,tool_choice:i,tools:f,messages:[...this.messages]},n),s=t.choices[0]?.message;if(!s)throw new rv("missing message in ChatCompletion response");if(!s.tool_calls?.length)return;for(const e of s.tool_calls){if("function"!==e.type)continue;const t=e.id,{name:n,arguments:i}=e.function,s=l[n];if(!s){const e=`Invalid tool_call: ${JSON.stringify(n)}. Available options are: ${Object.keys(l).map(e=>JSON.stringify(e)).join(", ")}. Please try again`;this._addMessage({role:r,tool_call_id:t,content:e});continue}if(o&&o!==n){const e=`Invalid tool_call: ${JSON.stringify(n)}. ${JSON.stringify(o)} requested. Please try again`;this._addMessage({role:r,tool_call_id:t,content:e});continue}let a;try{a=pE(s)?await s.parse(i):i}catch(u){const e=u instanceof Error?u.message:String(u);this._addMessage({role:r,tool_call_id:t,content:e});continue}const c=await s.function(a,this),A=RE(this,TE,"m",OE).call(this,c);if(this._addMessage({role:r,tool_call_id:t,content:A}),o)return}}}}TE=new WeakSet,SE=function(){return RE(this,TE,"m",xE).call(this).content??null},xE=function(){let e=this.messages.length;for(;e-- >0;){const t=this.messages[e];if(mE(t)){const{function_call:e,...n}=t,r={...n,content:t.content??null,refusal:t.refusal??null};return e&&(r.function_call=e),r}}throw new rv("stream ended without producing a ChatCompletionMessage with role=assistant")},IE=function(){for(let e=this.messages.length-1;e>=0;e--){const t=this.messages[e];if(mE(t)&&t?.function_call)return t.function_call;if(mE(t)&&t?.tool_calls?.length)return t.tool_calls.at(-1)?.function}},PE=function(){for(let e=this.messages.length-1;e>=0;e--){const t=this.messages[e];if(yE(t)&&null!=t.content)return t.content;if(gE(t)&&null!=t.content&&"string"==typeof t.content&&this.messages.some(e=>"assistant"===e.role&&e.tool_calls?.some(e=>"function"===e.type&&e.id===t.tool_call_id)))return t.content}},CE=function(){const e={completion_tokens:0,prompt_tokens:0,total_tokens:0};for(const{usage:t}of this._chatCompletions)t&&(e.completion_tokens+=t.completion_tokens,e.prompt_tokens+=t.prompt_tokens,e.total_tokens+=t.total_tokens);return e},NE=function(e){if(null!=e.n&&e.n>1)throw new rv("ChatCompletion convenience helpers only support n=1 at this time. To use n>1, please use chat.completions.create() directly.")},OE=function(e){return"string"==typeof e?e:void 0===e?"undefined":JSON.stringify(e)};class $E extends ME{static runFunctions(e,t,n){const r=new $E,i={...n,headers:{...n?.headers,"X-Stainless-Helper-Method":"runFunctions"}};return r._run(()=>r._runFunctions(e,t,i)),r}static runTools(e,t,n){const r=new $E,i={...n,headers:{...n?.headers,"X-Stainless-Helper-Method":"runTools"}};return r._run(()=>r._runTools(e,t,i)),r}_addMessage(e,t=!0){super._addMessage(e,t),mE(e)&&e.content&&this._emit("content",e.content)}}class DE extends Error{}class FE extends Error{}const GE=e=>function(e,t=511){if("string"!=typeof e)throw new TypeError("expecting str, got "+typeof e);if(!e.trim())throw new Error(`${e} is empty`);return((e,t)=>{const n=e.length;let r=0;const i=e=>{throw new DE(`${e} at position ${r}`)},s=e=>{throw new FE(`${e} at position ${r}`)},a=()=>(f(),r>=n&&i("Unexpected end of input"),'"'===e[r]?o():"{"===e[r]?c():"["===e[r]?A():"null"===e.substring(r,r+4)||16&t&&n-r<4&&"null".startsWith(e.substring(r))?(r+=4,null):"true"===e.substring(r,r+4)||32&t&&n-r<4&&"true".startsWith(e.substring(r))?(r+=4,!0):"false"===e.substring(r,r+5)||32&t&&n-r<5&&"false".startsWith(e.substring(r))?(r+=5,!1):"Infinity"===e.substring(r,r+8)||128&t&&n-r<8&&"Infinity".startsWith(e.substring(r))?(r+=8,1/0):"-Infinity"===e.substring(r,r+9)||256&t&&1<n-r&&n-r<9&&"-Infinity".startsWith(e.substring(r))?(r+=9,-1/0):"NaN"===e.substring(r,r+3)||64&t&&n-r<3&&"NaN".startsWith(e.substring(r))?(r+=3,NaN):l()),o=()=>{const a=r;let o=!1;for(r++;r<n&&('"'!==e[r]||o&&"\\"===e[r-1]);)o="\\"===e[r]&&!o,r++;if('"'==e.charAt(r))try{return JSON.parse(e.substring(a,++r-Number(o)))}catch(c){s(String(c))}else if(1&t)try{return JSON.parse(e.substring(a,r-Number(o))+'"')}catch(c){return JSON.parse(e.substring(a,e.lastIndexOf("\\"))+'"')}i("Unterminated string literal")},c=()=>{r++,f();const s={};try{for(;"}"!==e[r];){if(f(),r>=n&&8&t)return s;const i=o();f(),r++;try{const e=a();Object.defineProperty(s,i,{value:e,writable:!0,enumerable:!0,configurable:!0})}catch(c){if(8&t)return s;throw c}f(),","===e[r]&&r++}}catch(c){if(8&t)return s;i("Expected '}' at end of object")}return r++,s},A=()=>{r++;const n=[];try{for(;"]"!==e[r];)n.push(a()),f(),","===e[r]&&r++}catch(s){if(4&t)return n;i("Expected ']' at end of array")}return r++,n},l=()=>{if(0===r){"-"===e&&2&t&&i("Not sure what '-' is");try{return JSON.parse(e)}catch(o){if(2&t)try{return"."===e[e.length-1]?JSON.parse(e.substring(0,e.lastIndexOf("."))):JSON.parse(e.substring(0,e.lastIndexOf("e")))}catch(c){}s(String(o))}}const a=r;for("-"===e[r]&&r++;e[r]&&!",]}".includes(e[r]);)r++;r!=n||2&t||i("Unterminated number literal");try{return JSON.parse(e.substring(a,r))}catch(o){"-"===e.substring(a,r)&&2&t&&i("Not sure what '-' is");try{return JSON.parse(e.substring(a,e.lastIndexOf("e")))}catch(c){s(String(c))}}},f=()=>{for(;r<n&&" \n\r\t".includes(e[r]);)r++};return a()})(e.trim(),t)}(e,509);var UE,LE,jE,HE,zE,qE,QE,VE,JE,KE,WE,YE,ZE=function(e,t,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?i.call(e,n):i?i.value=n:t.set(e,n),n},XE=function(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)};class ek extends ME{constructor(e){super(),UE.add(this),LE.set(this,void 0),jE.set(this,void 0),HE.set(this,void 0),ZE(this,LE,e,"f"),ZE(this,jE,[],"f")}get currentChatCompletionSnapshot(){return XE(this,HE,"f")}static fromReadableStream(e){const t=new ek(null);return t._run(()=>t._fromReadableStream(e)),t}static createChatCompletion(e,t,n){const r=new ek(t);return r._run(()=>r._runChatCompletion(e,{...t,stream:!0},{...n,headers:{...n?.headers,"X-Stainless-Helper-Method":"stream"}})),r}async _createChatCompletion(e,t,n){super._createChatCompletion;const r=n?.signal;r&&(r.aborted&&this.controller.abort(),r.addEventListener("abort",()=>this.controller.abort())),XE(this,UE,"m",zE).call(this);const i=await e.chat.completions.create({...t,stream:!0},{...n,signal:this.controller.signal});this._connected();for await(const s of i)XE(this,UE,"m",QE).call(this,s);if(i.controller.signal?.aborted)throw new sv;return this._addChatCompletion(XE(this,UE,"m",KE).call(this))}async _fromReadableStream(e,t){const n=t?.signal;n&&(n.aborted&&this.controller.abort(),n.addEventListener("abort",()=>this.controller.abort())),XE(this,UE,"m",zE).call(this),this._connected();const r=Tv.fromReadableStream(e,this.controller);let i;for await(const s of r)i&&i!==s.id&&this._addChatCompletion(XE(this,UE,"m",KE).call(this)),XE(this,UE,"m",QE).call(this,s),i=s.id;if(r.controller.signal?.aborted)throw new sv;return this._addChatCompletion(XE(this,UE,"m",KE).call(this))}[(LE=new WeakMap,jE=new WeakMap,HE=new WeakMap,UE=new WeakSet,zE=function(){this.ended||ZE(this,HE,void 0,"f")},qE=function(e){let t=XE(this,jE,"f")[e.index];return t||(t={content_done:!1,refusal_done:!1,logprobs_content_done:!1,logprobs_refusal_done:!1,done_tool_calls:new Set,current_tool_call_index:null},XE(this,jE,"f")[e.index]=t,t)},QE=function(e){if(this.ended)return;const t=XE(this,UE,"m",YE).call(this,e);this._emit("chunk",e,t);for(const n of e.choices){const e=t.choices[n.index];null!=n.delta.content&&"assistant"===e.message?.role&&e.message?.content&&(this._emit("content",n.delta.content,e.message.content),this._emit("content.delta",{delta:n.delta.content,snapshot:e.message.content,parsed:e.message.parsed})),null!=n.delta.refusal&&"assistant"===e.message?.role&&e.message?.refusal&&this._emit("refusal.delta",{delta:n.delta.refusal,snapshot:e.message.refusal}),null!=n.logprobs?.content&&"assistant"===e.message?.role&&this._emit("logprobs.content.delta",{content:n.logprobs?.content,snapshot:e.logprobs?.content??[]}),null!=n.logprobs?.refusal&&"assistant"===e.message?.role&&this._emit("logprobs.refusal.delta",{refusal:n.logprobs?.refusal,snapshot:e.logprobs?.refusal??[]});const r=XE(this,UE,"m",qE).call(this,e);e.finish_reason&&(XE(this,UE,"m",JE).call(this,e),null!=r.current_tool_call_index&&XE(this,UE,"m",VE).call(this,e,r.current_tool_call_index));for(const t of n.delta.tool_calls??[])r.current_tool_call_index!==t.index&&(XE(this,UE,"m",JE).call(this,e),null!=r.current_tool_call_index&&XE(this,UE,"m",VE).call(this,e,r.current_tool_call_index)),r.current_tool_call_index=t.index;for(const t of n.delta.tool_calls??[]){const n=e.message.tool_calls?.[t.index];n?.type&&("function"===n?.type?this._emit("tool_calls.function.arguments.delta",{name:n.function?.name,index:t.index,arguments:n.function.arguments,parsed_arguments:n.function.parsed_arguments,arguments_delta:t.function?.arguments??""}):nk())}}},VE=function(e,t){if(XE(this,UE,"m",qE).call(this,e).done_tool_calls.has(t))return;const n=e.message.tool_calls?.[t];if(!n)throw new Error("no tool call snapshot");if(!n.type)throw new Error("tool call snapshot missing `type`");if("function"===n.type){const e=XE(this,LE,"f")?.tools?.find(e=>"function"===e.type&&e.function.name===n.function.name);this._emit("tool_calls.function.arguments.done",{name:n.function.name,index:t,arguments:n.function.arguments,parsed_arguments:wE(e)?e.$parseRaw(n.function.arguments):e?.function.strict?JSON.parse(n.function.arguments):null})}else n.type},JE=function(e){const t=XE(this,UE,"m",qE).call(this,e);if(e.message.content&&!t.content_done){t.content_done=!0;const n=XE(this,UE,"m",WE).call(this);this._emit("content.done",{content:e.message.content,parsed:n?n.$parseRaw(e.message.content):null})}e.message.refusal&&!t.refusal_done&&(t.refusal_done=!0,this._emit("refusal.done",{refusal:e.message.refusal})),e.logprobs?.content&&!t.logprobs_content_done&&(t.logprobs_content_done=!0,this._emit("logprobs.content.done",{content:e.logprobs.content})),e.logprobs?.refusal&&!t.logprobs_refusal_done&&(t.logprobs_refusal_done=!0,this._emit("logprobs.refusal.done",{refusal:e.logprobs.refusal}))},KE=function(){if(this.ended)throw new rv("stream has ended, this shouldn't happen");const e=XE(this,HE,"f");if(!e)throw new rv("request ended without sending any chunks");return ZE(this,HE,void 0,"f"),ZE(this,jE,[],"f"),function(e,t){const{id:n,choices:r,created:i,model:s,system_fingerprint:a,...o}=e;return function(e,t){return t&&kE(t)?vE(e,t):{...e,choices:e.choices.map(e=>({...e,message:{...e.message,parsed:null,...e.message.tool_calls?{tool_calls:e.message.tool_calls}:void 0}}))}}({...o,id:n,choices:r.map(({message:t,finish_reason:n,index:r,logprobs:i,...s})=>{if(!n)throw new rv(`missing finish_reason for choice ${r}`);const{content:a=null,function_call:o,tool_calls:c,...A}=t,l=t.role;if(!l)throw new rv(`missing role for choice ${r}`);if(o){const{arguments:e,name:c}=o;if(null==e)throw new rv(`missing function_call.arguments for choice ${r}`);if(!c)throw new rv(`missing function_call.name for choice ${r}`);return{...s,message:{content:a,function_call:{arguments:e,name:c},role:l,refusal:t.refusal??null},finish_reason:n,index:r,logprobs:i}}return c?{...s,index:r,finish_reason:n,logprobs:i,message:{...A,role:l,content:a,refusal:t.refusal??null,tool_calls:c.map((t,n)=>{const{function:i,type:s,id:a,...o}=t,{arguments:c,name:A,...l}=i||{};if(null==a)throw new rv(`missing choices[${r}].tool_calls[${n}].id\n${tk(e)}`);if(null==s)throw new rv(`missing choices[${r}].tool_calls[${n}].type\n${tk(e)}`);if(null==A)throw new rv(`missing choices[${r}].tool_calls[${n}].function.name\n${tk(e)}`);if(null==c)throw new rv(`missing choices[${r}].tool_calls[${n}].function.arguments\n${tk(e)}`);return{...o,id:a,type:s,function:{...l,name:A,arguments:c}}})}}:{...s,message:{...A,content:a,role:l,refusal:t.refusal??null},finish_reason:n,index:r,logprobs:i}}),created:i,model:s,object:"chat.completion",...a?{system_fingerprint:a}:{}},t)}(e,XE(this,LE,"f"))},WE=function(){const e=XE(this,LE,"f")?.response_format;return bE(e)?e:null},YE=function(e){var t,n,r,i;let s=XE(this,HE,"f");const{choices:a,...o}=e;s?Object.assign(s,o):s=ZE(this,HE,{...o,choices:[]},"f");for(const{delta:c,finish_reason:A,index:l,logprobs:f=null,...u}of e.choices){let e=s.choices[l];if(e||(e=s.choices[l]={finish_reason:A,index:l,message:{},logprobs:f,...u}),f)if(e.logprobs){const{content:r,refusal:i,...s}=f;Object.assign(e.logprobs,s),r&&((t=e.logprobs).content??(t.content=[]),e.logprobs.content.push(...r)),i&&((n=e.logprobs).refusal??(n.refusal=[]),e.logprobs.refusal.push(...i))}else e.logprobs=Object.assign({},f);if(A&&(e.finish_reason=A,XE(this,LE,"f")&&kE(XE(this,LE,"f")))){if("length"===A)throw new mv;if("content_filter"===A)throw new yv}if(Object.assign(e,u),!c)continue;const{content:a,refusal:o,function_call:d,role:h,tool_calls:p,...m}=c;if(Object.assign(e.message,m),o&&(e.message.refusal=(e.message.refusal||"")+o),h&&(e.message.role=h),d&&(e.message.function_call?(d.name&&(e.message.function_call.name=d.name),d.arguments&&((r=e.message.function_call).arguments??(r.arguments=""),e.message.function_call.arguments+=d.arguments)):e.message.function_call=d),a&&(e.message.content=(e.message.content||"")+a,!e.message.refusal&&XE(this,UE,"m",WE).call(this)&&(e.message.parsed=GE(e.message.content))),p){e.message.tool_calls||(e.message.tool_calls=[]);for(const{index:t,id:n,type:r,function:s,...a}of p){const o=(i=e.message.tool_calls)[t]??(i[t]={});Object.assign(o,a),n&&(o.id=n),r&&(o.type=r),s&&(o.function??(o.function={name:s.name??"",arguments:""})),s?.name&&(o.function.name=s.name),s?.arguments&&(o.function.arguments+=s.arguments,EE(XE(this,LE,"f"),o)&&(o.function.parsed_arguments=GE(o.function.arguments)))}}}return s},Symbol.asyncIterator)](){const e=[],t=[];let n=!1;return this.on("chunk",n=>{const r=t.shift();r?r.resolve(n):e.push(n)}),this.on("end",()=>{n=!0;for(const e of t)e.resolve(void 0);t.length=0}),this.on("abort",e=>{n=!0;for(const n of t)n.reject(e);t.length=0}),this.on("error",e=>{n=!0;for(const n of t)n.reject(e);t.length=0}),{next:async()=>e.length?{value:e.shift(),done:!1}:n?{value:void 0,done:!0}:new Promise((e,n)=>t.push({resolve:e,reject:n})).then(e=>e?{value:e,done:!1}:{value:void 0,done:!0}),return:async()=>(this.abort(),{value:void 0,done:!0})}}toReadableStream(){return new Tv(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}}function tk(e){return JSON.stringify(e)}function nk(e){}class rk extends ek{static fromReadableStream(e){const t=new rk(null);return t._run(()=>t._fromReadableStream(e)),t}static runFunctions(e,t,n){const r=new rk(null),i={...n,headers:{...n?.headers,"X-Stainless-Helper-Method":"runFunctions"}};return r._run(()=>r._runFunctions(e,t,i)),r}static runTools(e,t,n){const r=new rk(t),i={...n,headers:{...n?.headers,"X-Stainless-Helper-Method":"runTools"}};return r._run(()=>r._runTools(e,t,i)),r}}let ik=class extends h_{parse(e,t){return function(e){for(const t of e??[]){if("function"!==t.type)throw new rv(`Currently only \`function\` tool types support auto-parsing; Received \`${t.type}\``);if(!0!==t.function.strict)throw new rv(`The \`${t.function.name}\` tool is not marked with \`strict: true\`. Only strict function tools can be auto-parsed`)}}(e.tools),this._client.chat.completions.create(e,{...t,headers:{...t?.headers,"X-Stainless-Helper-Method":"beta.chat.completions.parse"}})._thenUnwrap(t=>vE(t,e))}runFunctions(e,t){return e.stream?rk.runFunctions(this._client,e,t):$E.runFunctions(this._client,e,t)}runTools(e,t){return e.stream?rk.runTools(this._client,e,t):$E.runTools(this._client,e,t)}stream(e,t){return ek.createChatCompletion(this._client,e,t)}};class sk extends h_{constructor(){super(...arguments),this.completions=new ik(this._client)}}(sk||(sk={})).Completions=ik;class ak extends h_{create(e,t){return this._client.post("/realtime/sessions",{body:e,...t,headers:{"OpenAI-Beta":"assistants=v2",...t?.headers}})}}class ok extends h_{create(e,t){return this._client.post("/realtime/transcription_sessions",{body:e,...t,headers:{"OpenAI-Beta":"assistants=v2",...t?.headers}})}}class ck extends h_{constructor(){super(...arguments),this.sessions=new ak(this._client),this.transcriptionSessions=new ok(this._client)}}ck.Sessions=ak,ck.TranscriptionSessions=ok;class Ak extends h_{create(e,t,n){return this._client.post(`/threads/${e}/messages`,{body:t,...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}retrieve(e,t,n){return this._client.get(`/threads/${e}/messages/${t}`,{...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}update(e,t,n,r){return this._client.post(`/threads/${e}/messages/${t}`,{body:n,...r,headers:{"OpenAI-Beta":"assistants=v2",...r?.headers}})}list(e,t={},n){return Qv(t)?this.list(e,{},t):this._client.getAPIList(`/threads/${e}/messages`,lk,{query:t,...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}del(e,t,n){return this._client.delete(`/threads/${e}/messages/${t}`,{...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}}class lk extends d_{}Ak.MessagesPage=lk;class fk extends h_{retrieve(e,t,n,r={},i){return Qv(r)?this.retrieve(e,t,n,{},r):this._client.get(`/threads/${e}/runs/${t}/steps/${n}`,{query:r,...i,headers:{"OpenAI-Beta":"assistants=v2",...i?.headers}})}list(e,t,n={},r){return Qv(n)?this.list(e,t,{},n):this._client.getAPIList(`/threads/${e}/runs/${t}/steps`,uk,{query:n,...r,headers:{"OpenAI-Beta":"assistants=v2",...r?.headers}})}}class uk extends d_{}fk.RunStepsPage=uk;let dk=class extends h_{constructor(){super(...arguments),this.steps=new fk(this._client)}create(e,t,n){const{include:r,...i}=t;return this._client.post(`/threads/${e}/runs`,{query:{include:r},body:i,...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers},stream:t.stream??!1})}retrieve(e,t,n){return this._client.get(`/threads/${e}/runs/${t}`,{...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}update(e,t,n,r){return this._client.post(`/threads/${e}/runs/${t}`,{body:n,...r,headers:{"OpenAI-Beta":"assistants=v2",...r?.headers}})}list(e,t={},n){return Qv(t)?this.list(e,{},t):this._client.getAPIList(`/threads/${e}/runs`,hk,{query:t,...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}cancel(e,t,n){return this._client.post(`/threads/${e}/runs/${t}/cancel`,{...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}async createAndPoll(e,t,n){const r=await this.create(e,t,n);return await this.poll(e,r.id,n)}createAndStream(e,t,n){return uE.createAssistantStream(e,this._client.beta.threads.runs,t,n)}async poll(e,t,n){const r={...n?.headers,"X-Stainless-Poll-Helper":"true"};for(n?.pollIntervalMs&&(r["X-Stainless-Custom-Poll-Interval"]=n.pollIntervalMs.toString());;){const{data:i,response:s}=await this.retrieve(e,t,{...n,headers:{...n?.headers,...r}}).withResponse();switch(i.status){case"queued":case"in_progress":case"cancelling":let e=5e3;if(n?.pollIntervalMs)e=n.pollIntervalMs;else{const t=s.headers.get("openai-poll-after-ms");if(t){const n=parseInt(t);isNaN(n)||(e=n)}}await e_(e);break;case"requires_action":case"incomplete":case"cancelled":case"completed":case"failed":case"expired":return i}}}stream(e,t,n){return uE.createAssistantStream(e,this._client.beta.threads.runs,t,n)}submitToolOutputs(e,t,n,r){return this._client.post(`/threads/${e}/runs/${t}/submit_tool_outputs`,{body:n,...r,headers:{"OpenAI-Beta":"assistants=v2",...r?.headers},stream:n.stream??!1})}async submitToolOutputsAndPoll(e,t,n,r){const i=await this.submitToolOutputs(e,t,n,r);return await this.poll(e,i.id,r)}submitToolOutputsStream(e,t,n,r){return uE.createToolAssistantStream(e,t,this._client.beta.threads.runs,n,r)}};class hk extends d_{}dk.RunsPage=hk,dk.Steps=fk,dk.RunStepsPage=uk;class pk extends h_{constructor(){super(...arguments),this.runs=new dk(this._client),this.messages=new Ak(this._client)}create(e={},t){return Qv(e)?this.create({},e):this._client.post("/threads",{body:e,...t,headers:{"OpenAI-Beta":"assistants=v2",...t?.headers}})}retrieve(e,t){return this._client.get(`/threads/${e}`,{...t,headers:{"OpenAI-Beta":"assistants=v2",...t?.headers}})}update(e,t,n){return this._client.post(`/threads/${e}`,{body:t,...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}del(e,t){return this._client.delete(`/threads/${e}`,{...t,headers:{"OpenAI-Beta":"assistants=v2",...t?.headers}})}createAndRun(e,t){return this._client.post("/threads/runs",{body:e,...t,headers:{"OpenAI-Beta":"assistants=v2",...t?.headers},stream:e.stream??!1})}async createAndRunPoll(e,t){const n=await this.createAndRun(e,t);return await this.runs.poll(n.thread_id,n.id,t)}createAndRunStream(e,t){return uE.createThreadAssistantStream(e,this._client.beta.threads,t)}}pk.Runs=dk,pk.RunsPage=hk,pk.Messages=Ak,pk.MessagesPage=lk;class mk extends h_{constructor(){super(...arguments),this.realtime=new ck(this._client),this.chat=new sk(this._client),this.assistants=new dE(this._client),this.threads=new pk(this._client)}}mk.Realtime=ck,mk.Assistants=dE,mk.AssistantsPage=hE,mk.Threads=pk;class yk extends h_{create(e,t){return this._client.post("/completions",{body:e,...t,stream:e.stream??!1})}}class gk extends h_{retrieve(e,t,n){return this._client.get(`/containers/${e}/files/${t}/content`,{...n,headers:{Accept:"application/binary",...n?.headers},__binaryResponse:!0})}}let bk=class extends h_{constructor(){super(...arguments),this.content=new gk(this._client)}create(e,t,n){return this._client.post(`/containers/${e}/files`,Bv({body:t,...n}))}retrieve(e,t,n){return this._client.get(`/containers/${e}/files/${t}`,n)}list(e,t={},n){return Qv(t)?this.list(e,{},t):this._client.getAPIList(`/containers/${e}/files`,wk,{query:t,...n})}del(e,t,n){return this._client.delete(`/containers/${e}/files/${t}`,{...n,headers:{Accept:"*/*",...n?.headers}})}};class wk extends d_{}bk.FileListResponsesPage=wk,bk.Content=gk;class vk extends h_{constructor(){super(...arguments),this.files=new bk(this._client)}create(e,t){return this._client.post("/containers",{body:e,...t})}retrieve(e,t){return this._client.get(`/containers/${e}`,t)}list(e={},t){return Qv(e)?this.list({},e):this._client.getAPIList("/containers",_k,{query:e,...t})}del(e,t){return this._client.delete(`/containers/${e}`,{...t,headers:{Accept:"*/*",...t?.headers}})}}class _k extends d_{}vk.ContainerListResponsesPage=_k,vk.Files=bk,vk.FileListResponsesPage=wk;let Ek=class extends h_{create(e,t){const n=!!e.encoding_format;let r=n?e.encoding_format:"base64";n&&c_("Request","User defined encoding_format:",e.encoding_format);const i=this._client.post("/embeddings",{body:{...e,encoding_format:r},...t});return n?i:(c_("response","Decoding base64 embeddings to float32 array"),i._thenUnwrap(e=>(e&&e.data&&e.data.forEach(e=>{const t=e.embedding;e.embedding=(e=>{if("undefined"!=typeof Buffer){const t=Buffer.from(e,"base64");return Array.from(new Float32Array(t.buffer,t.byteOffset,t.length/Float32Array.BYTES_PER_ELEMENT))}{const t=atob(e),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.charCodeAt(e);return Array.from(new Float32Array(r.buffer))}})(t)}),e)))}};class kk extends h_{retrieve(e,t,n,r){return this._client.get(`/evals/${e}/runs/${t}/output_items/${n}`,r)}list(e,t,n={},r){return Qv(n)?this.list(e,t,{},n):this._client.getAPIList(`/evals/${e}/runs/${t}/output_items`,Tk,{query:n,...r})}}class Tk extends d_{}kk.OutputItemListResponsesPage=Tk;class Sk extends h_{constructor(){super(...arguments),this.outputItems=new kk(this._client)}create(e,t,n){return this._client.post(`/evals/${e}/runs`,{body:t,...n})}retrieve(e,t,n){return this._client.get(`/evals/${e}/runs/${t}`,n)}list(e,t={},n){return Qv(t)?this.list(e,{},t):this._client.getAPIList(`/evals/${e}/runs`,xk,{query:t,...n})}del(e,t,n){return this._client.delete(`/evals/${e}/runs/${t}`,n)}cancel(e,t,n){return this._client.post(`/evals/${e}/runs/${t}`,n)}}class xk extends d_{}Sk.RunListResponsesPage=xk,Sk.OutputItems=kk,Sk.OutputItemListResponsesPage=Tk;class Ik extends h_{constructor(){super(...arguments),this.runs=new Sk(this._client)}create(e,t){return this._client.post("/evals",{body:e,...t})}retrieve(e,t){return this._client.get(`/evals/${e}`,t)}update(e,t,n){return this._client.post(`/evals/${e}`,{body:t,...n})}list(e={},t){return Qv(e)?this.list({},e):this._client.getAPIList("/evals",Pk,{query:e,...t})}del(e,t){return this._client.delete(`/evals/${e}`,t)}}class Pk extends d_{}Ik.EvalListResponsesPage=Pk,Ik.Runs=Sk,Ik.RunListResponsesPage=xk;let Ck=class extends h_{create(e,t){return this._client.post("/files",Bv({body:e,...t}))}retrieve(e,t){return this._client.get(`/files/${e}`,t)}list(e={},t){return Qv(e)?this.list({},e):this._client.getAPIList("/files",Nk,{query:e,...t})}del(e,t){return this._client.delete(`/files/${e}`,t)}content(e,t){return this._client.get(`/files/${e}/content`,{...t,headers:{Accept:"application/binary",...t?.headers},__binaryResponse:!0})}retrieveContent(e,t){return this._client.get(`/files/${e}/content`,t)}async waitForProcessing(e,{pollInterval:t=5e3,maxWait:n=18e5}={}){const r=new Set(["processed","error","deleted"]),i=Date.now();let s=await this.retrieve(e);for(;!s.status||!r.has(s.status);)if(await e_(t),s=await this.retrieve(e),Date.now()-i>n)throw new ov({message:`Giving up on waiting for file ${e} to finish processing after ${n} milliseconds.`});return s}};class Nk extends d_{}Ck.FileObjectsPage=Nk;class Ok extends h_{}let Rk=class extends h_{run(e,t){return this._client.post("/fine_tuning/alpha/graders/run",{body:e,...t})}validate(e,t){return this._client.post("/fine_tuning/alpha/graders/validate",{body:e,...t})}};class Bk extends h_{constructor(){super(...arguments),this.graders=new Rk(this._client)}}Bk.Graders=Rk;class Mk extends h_{create(e,t,n){return this._client.getAPIList(`/fine_tuning/checkpoints/${e}/permissions`,$k,{body:t,method:"post",...n})}retrieve(e,t={},n){return Qv(t)?this.retrieve(e,{},t):this._client.get(`/fine_tuning/checkpoints/${e}/permissions`,{query:t,...n})}del(e,t,n){return this._client.delete(`/fine_tuning/checkpoints/${e}/permissions/${t}`,n)}}class $k extends u_{}Mk.PermissionCreateResponsesPage=$k;let Dk=class extends h_{constructor(){super(...arguments),this.permissions=new Mk(this._client)}};Dk.Permissions=Mk,Dk.PermissionCreateResponsesPage=$k;class Fk extends h_{list(e,t={},n){return Qv(t)?this.list(e,{},t):this._client.getAPIList(`/fine_tuning/jobs/${e}/checkpoints`,Gk,{query:t,...n})}}class Gk extends d_{}Fk.FineTuningJobCheckpointsPage=Gk;class Uk extends h_{constructor(){super(...arguments),this.checkpoints=new Fk(this._client)}create(e,t){return this._client.post("/fine_tuning/jobs",{body:e,...t})}retrieve(e,t){return this._client.get(`/fine_tuning/jobs/${e}`,t)}list(e={},t){return Qv(e)?this.list({},e):this._client.getAPIList("/fine_tuning/jobs",Lk,{query:e,...t})}cancel(e,t){return this._client.post(`/fine_tuning/jobs/${e}/cancel`,t)}listEvents(e,t={},n){return Qv(t)?this.listEvents(e,{},t):this._client.getAPIList(`/fine_tuning/jobs/${e}/events`,jk,{query:t,...n})}pause(e,t){return this._client.post(`/fine_tuning/jobs/${e}/pause`,t)}resume(e,t){return this._client.post(`/fine_tuning/jobs/${e}/resume`,t)}}class Lk extends d_{}class jk extends d_{}Uk.FineTuningJobsPage=Lk,Uk.FineTuningJobEventsPage=jk,Uk.Checkpoints=Fk,Uk.FineTuningJobCheckpointsPage=Gk;class Hk extends h_{constructor(){super(...arguments),this.methods=new Ok(this._client),this.jobs=new Uk(this._client),this.checkpoints=new Dk(this._client),this.alpha=new Bk(this._client)}}Hk.Methods=Ok,Hk.Jobs=Uk,Hk.FineTuningJobsPage=Lk,Hk.FineTuningJobEventsPage=jk,Hk.Checkpoints=Dk,Hk.Alpha=Bk;class zk extends h_{}class qk extends h_{constructor(){super(...arguments),this.graderModels=new zk(this._client)}}qk.GraderModels=zk;class Qk extends h_{createVariation(e,t){return this._client.post("/images/variations",Bv({body:e,...t}))}edit(e,t){return this._client.post("/images/edits",Bv({body:e,...t}))}generate(e,t){return this._client.post("/images/generations",{body:e,...t})}}class Vk extends h_{retrieve(e,t){return this._client.get(`/models/${e}`,t)}list(e){return this._client.getAPIList("/models",Jk,e)}del(e,t){return this._client.delete(`/models/${e}`,t)}}class Jk extends u_{}Vk.ModelsPage=Jk;class Kk extends h_{create(e,t){return this._client.post("/moderations",{body:e,...t})}}function Wk(e,t){const n=e.output.map(e=>{if("function_call"===e.type)return{...e,parsed_arguments:Zk(t,e)};if("message"===e.type){const n=e.content.map(e=>"output_text"===e.type?{...e,parsed:Yk(t,e.text)}:e);return{...e,content:n}}return e}),r=Object.assign({},e,{output:n});return Object.getOwnPropertyDescriptor(e,"output_text")||Xk(r),Object.defineProperty(r,"output_parsed",{enumerable:!0,get(){for(const e of r.output)if("message"===e.type)for(const t of e.content)if("output_text"===t.type&&null!==t.parsed)return t.parsed;return null}}),r}function Yk(e,t){if("json_schema"!==e.text?.format?.type)return null;if("$parseRaw"in e.text?.format){const n=e.text?.format;return n.$parseRaw(t)}return JSON.parse(t)}function Zk(e,t){const n=(r=e.tools??[],i=t.name,r.find(e=>"function"===e.type&&e.name===i));var r,i,s;return{...t,...t,parsed_arguments:(s=n,"auto-parseable-tool"===s?.$brand?n.$parseRaw(t.arguments):n?.strict?JSON.parse(t.arguments):null)}}function Xk(e){const t=[];for(const n of e.output)if("message"===n.type)for(const e of n.content)"output_text"===e.type&&t.push(e.text);e.output_text=t.join("")}class eT extends h_{list(e,t={},n){return Qv(t)?this.list(e,{},t):this._client.getAPIList(`/responses/${e}/input_items`,hT,{query:t,...n})}}var tT,nT,rT,iT,sT,aT,oT,cT,AT,lT=function(e,t,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?i.call(e,n):i?i.value=n:t.set(e,n),n},fT=function(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)};class uT extends L_{constructor(e){super(),tT.add(this),nT.set(this,void 0),rT.set(this,void 0),iT.set(this,void 0),lT(this,nT,e,"f")}static createResponse(e,t,n){const r=new uT(t);return r._run(()=>r._createOrRetrieveResponse(e,t,{...n,headers:{...n?.headers,"X-Stainless-Helper-Method":"stream"}})),r}async _createOrRetrieveResponse(e,t,n){const r=n?.signal;let i;r&&(r.aborted&&this.controller.abort(),r.addEventListener("abort",()=>this.controller.abort())),fT(this,tT,"m",sT).call(this);let s=null;"response_id"in t?(i=await e.responses.retrieve(t.response_id,{stream:!0},{...n,signal:this.controller.signal,stream:!0}),s=t.starting_after??null):i=await e.responses.create({...t,stream:!0},{...n,signal:this.controller.signal}),this._connected();for await(const a of i)fT(this,tT,"m",aT).call(this,a,s);if(i.controller.signal?.aborted)throw new sv;return fT(this,tT,"m",oT).call(this)}[(nT=new WeakMap,rT=new WeakMap,iT=new WeakMap,tT=new WeakSet,sT=function(){this.ended||lT(this,rT,void 0,"f")},aT=function(e,t){if(this.ended)return;const n=(e,n)=>{(null==t||n.sequence_number>t)&&this._emit(e,n)},r=fT(this,tT,"m",cT).call(this,e);switch(n("event",e),e.type){case"response.output_text.delta":{const t=r.output[e.output_index];if(!t)throw new rv(`missing output at index ${e.output_index}`);if("message"===t.type){const r=t.content[e.content_index];if(!r)throw new rv(`missing content at index ${e.content_index}`);if("output_text"!==r.type)throw new rv(`expected content to be 'output_text', got ${r.type}`);n("response.output_text.delta",{...e,snapshot:r.text})}break}case"response.function_call_arguments.delta":{const t=r.output[e.output_index];if(!t)throw new rv(`missing output at index ${e.output_index}`);"function_call"===t.type&&n("response.function_call_arguments.delta",{...e,snapshot:t.arguments});break}default:n(e.type,e)}},oT=function(){if(this.ended)throw new rv("stream has ended, this shouldn't happen");const e=fT(this,rT,"f");if(!e)throw new rv("request ended without sending any events");lT(this,rT,void 0,"f");const t=function(e,t){return function(e,t){return t&&function(e){return!!bE(e.text?.format)}(t)?Wk(e,t):{...e,output_parsed:null,output:e.output.map(e=>"function_call"===e.type?{...e,parsed_arguments:null}:"message"===e.type?{...e,content:e.content.map(e=>({...e,parsed:null}))}:e)}}(e,t)}(e,fT(this,nT,"f"));return lT(this,iT,t,"f"),t},cT=function(e){let t=fT(this,rT,"f");if(!t){if("response.created"!==e.type)throw new rv(`When snapshot hasn't been set yet, expected 'response.created' event, got ${e.type}`);return t=lT(this,rT,e.response,"f"),t}switch(e.type){case"response.output_item.added":t.output.push(e.item);break;case"response.content_part.added":{const n=t.output[e.output_index];if(!n)throw new rv(`missing output at index ${e.output_index}`);"message"===n.type&&n.content.push(e.part);break}case"response.output_text.delta":{const n=t.output[e.output_index];if(!n)throw new rv(`missing output at index ${e.output_index}`);if("message"===n.type){const t=n.content[e.content_index];if(!t)throw new rv(`missing content at index ${e.content_index}`);if("output_text"!==t.type)throw new rv(`expected content to be 'output_text', got ${t.type}`);t.text+=e.delta}break}case"response.function_call_arguments.delta":{const n=t.output[e.output_index];if(!n)throw new rv(`missing output at index ${e.output_index}`);"function_call"===n.type&&(n.arguments+=e.delta);break}case"response.completed":lT(this,rT,e.response,"f")}return t},Symbol.asyncIterator)](){const e=[],t=[];let n=!1;return this.on("event",n=>{const r=t.shift();r?r.resolve(n):e.push(n)}),this.on("end",()=>{n=!0;for(const e of t)e.resolve(void 0);t.length=0}),this.on("abort",e=>{n=!0;for(const n of t)n.reject(e);t.length=0}),this.on("error",e=>{n=!0;for(const n of t)n.reject(e);t.length=0}),{next:async()=>e.length?{value:e.shift(),done:!1}:n?{value:void 0,done:!0}:new Promise((e,n)=>t.push({resolve:e,reject:n})).then(e=>e?{value:e,done:!1}:{value:void 0,done:!0}),return:async()=>(this.abort(),{value:void 0,done:!0})}}async finalResponse(){await this.done();const e=fT(this,iT,"f");if(!e)throw new rv("stream ended without producing a ChatCompletion");return e}}class dT extends h_{constructor(){super(...arguments),this.inputItems=new eT(this._client)}create(e,t){return this._client.post("/responses",{body:e,...t,stream:e.stream??!1})._thenUnwrap(e=>("object"in e&&"response"===e.object&&Xk(e),e))}retrieve(e,t={},n){return this._client.get(`/responses/${e}`,{query:t,...n,stream:t?.stream??!1})}del(e,t){return this._client.delete(`/responses/${e}`,{...t,headers:{Accept:"*/*",...t?.headers}})}parse(e,t){return this._client.responses.create(e,t)._thenUnwrap(t=>Wk(t,e))}stream(e,t){return uT.createResponse(this._client,e,t)}cancel(e,t){return this._client.post(`/responses/${e}/cancel`,{...t,headers:{Accept:"*/*",...t?.headers}})}}class hT extends d_{}dT.InputItems=eT;class pT extends h_{create(e,t,n){return this._client.post(`/uploads/${e}/parts`,Bv({body:t,...n}))}}class mT extends h_{constructor(){super(...arguments),this.parts=new pT(this._client)}create(e,t){return this._client.post("/uploads",{body:e,...t})}cancel(e,t){return this._client.post(`/uploads/${e}/cancel`,t)}complete(e,t,n){return this._client.post(`/uploads/${e}/complete`,{body:t,...n})}}mT.Parts=pT;class yT extends h_{create(e,t,n){return this._client.post(`/vector_stores/${e}/files`,{body:t,...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}retrieve(e,t,n){return this._client.get(`/vector_stores/${e}/files/${t}`,{...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}update(e,t,n,r){return this._client.post(`/vector_stores/${e}/files/${t}`,{body:n,...r,headers:{"OpenAI-Beta":"assistants=v2",...r?.headers}})}list(e,t={},n){return Qv(t)?this.list(e,{},t):this._client.getAPIList(`/vector_stores/${e}/files`,gT,{query:t,...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}del(e,t,n){return this._client.delete(`/vector_stores/${e}/files/${t}`,{...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}async createAndPoll(e,t,n){const r=await this.create(e,t,n);return await this.poll(e,r.id,n)}async poll(e,t,n){const r={...n?.headers,"X-Stainless-Poll-Helper":"true"};for(n?.pollIntervalMs&&(r["X-Stainless-Custom-Poll-Interval"]=n.pollIntervalMs.toString());;){const i=await this.retrieve(e,t,{...n,headers:r}).withResponse(),s=i.data;switch(s.status){case"in_progress":let e=5e3;if(n?.pollIntervalMs)e=n.pollIntervalMs;else{const t=i.response.headers.get("openai-poll-after-ms");if(t){const n=parseInt(t);isNaN(n)||(e=n)}}await e_(e);break;case"failed":case"completed":return s}}}async upload(e,t,n){const r=await this._client.files.create({file:t,purpose:"assistants"},n);return this.create(e,{file_id:r.id},n)}async uploadAndPoll(e,t,n){const r=await this.upload(e,t,n);return await this.poll(e,r.id,n)}content(e,t,n){return this._client.getAPIList(`/vector_stores/${e}/files/${t}/content`,bT,{...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}}class gT extends d_{}class bT extends u_{}yT.VectorStoreFilesPage=gT,yT.FileContentResponsesPage=bT;class wT extends h_{create(e,t,n){return this._client.post(`/vector_stores/${e}/file_batches`,{body:t,...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}retrieve(e,t,n){return this._client.get(`/vector_stores/${e}/file_batches/${t}`,{...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}cancel(e,t,n){return this._client.post(`/vector_stores/${e}/file_batches/${t}/cancel`,{...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}async createAndPoll(e,t,n){const r=await this.create(e,t);return await this.poll(e,r.id,n)}listFiles(e,t,n={},r){return Qv(n)?this.listFiles(e,t,{},n):this._client.getAPIList(`/vector_stores/${e}/file_batches/${t}/files`,gT,{query:n,...r,headers:{"OpenAI-Beta":"assistants=v2",...r?.headers}})}async poll(e,t,n){const r={...n?.headers,"X-Stainless-Poll-Helper":"true"};for(n?.pollIntervalMs&&(r["X-Stainless-Custom-Poll-Interval"]=n.pollIntervalMs.toString());;){const{data:i,response:s}=await this.retrieve(e,t,{...n,headers:r}).withResponse();switch(i.status){case"in_progress":let e=5e3;if(n?.pollIntervalMs)e=n.pollIntervalMs;else{const t=s.headers.get("openai-poll-after-ms");if(t){const n=parseInt(t);isNaN(n)||(e=n)}}await e_(e);break;case"failed":case"cancelled":case"completed":return i}}}async uploadAndPoll(e,{files:t,fileIds:n=[]},r){if(null==t||0==t.length)throw new Error("No `files` provided to process. If you've already uploaded files you should use `.createAndPoll()` instead");const i=r?.maxConcurrency??5,s=Math.min(i,t.length),a=this._client,o=t.values(),c=[...n],A=Array(s).fill(o).map(async function(e){for(let t of e){const e=await a.files.create({file:t,purpose:"assistants"},r);c.push(e.id)}});return await(async e=>{const t=await Promise.allSettled(e),n=t.filter(e=>"rejected"===e.status);if(n.length){for(const e of n)console.error(e.reason);throw new Error(`${n.length} promise(s) failed - see the above errors`)}const r=[];for(const i of t)"fulfilled"===i.status&&r.push(i.value);return r})(A),await this.createAndPoll(e,{file_ids:c})}}class vT extends h_{constructor(){super(...arguments),this.files=new yT(this._client),this.fileBatches=new wT(this._client)}create(e,t){return this._client.post("/vector_stores",{body:e,...t,headers:{"OpenAI-Beta":"assistants=v2",...t?.headers}})}retrieve(e,t){return this._client.get(`/vector_stores/${e}`,{...t,headers:{"OpenAI-Beta":"assistants=v2",...t?.headers}})}update(e,t,n){return this._client.post(`/vector_stores/${e}`,{body:t,...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}list(e={},t){return Qv(e)?this.list({},e):this._client.getAPIList("/vector_stores",_T,{query:e,...t,headers:{"OpenAI-Beta":"assistants=v2",...t?.headers}})}del(e,t){return this._client.delete(`/vector_stores/${e}`,{...t,headers:{"OpenAI-Beta":"assistants=v2",...t?.headers}})}search(e,t,n){return this._client.getAPIList(`/vector_stores/${e}/search`,ET,{body:t,method:"post",...n,headers:{"OpenAI-Beta":"assistants=v2",...n?.headers}})}}class _T extends d_{}class ET extends u_{}vT.VectorStoresPage=_T,vT.VectorStoreSearchResponsesPage=ET,vT.Files=yT,vT.VectorStoreFilesPage=gT,vT.FileContentResponsesPage=bT,vT.FileBatches=wT;class kT extends Lv{constructor({baseURL:e=r_("OPENAI_BASE_URL"),apiKey:t=r_("OPENAI_API_KEY"),organization:n=r_("OPENAI_ORG_ID")??null,project:r=r_("OPENAI_PROJECT_ID")??null,...i}={}){if(void 0===t)throw new rv("The OPENAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the OpenAI client with an apiKey option, like new OpenAI({ apiKey: 'My API Key' }).");const s={apiKey:t,organization:n,project:r,...i,baseURL:e||"https://api.openai.com/v1"};if(!s.dangerouslyAllowBrowser&&"undefined"!=typeof window&&void 0!==window.document&&"undefined"!=typeof navigator)throw new rv("It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew OpenAI({ apiKey, dangerouslyAllowBrowser: true });\n\nhttps://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety\n");super({baseURL:s.baseURL,timeout:s.timeout??6e5,httpAgent:s.httpAgent,maxRetries:s.maxRetries,fetch:s.fetch}),this.completions=new yk(this),this.chat=new b_(this),this.embeddings=new Ek(this),this.files=new Ck(this),this.images=new Qk(this),this.audio=new E_(this),this.moderations=new Kk(this),this.models=new Vk(this),this.fineTuning=new Hk(this),this.graders=new qk(this),this.vectorStores=new vT(this),this.beta=new mk(this),this.batches=new k_(this),this.uploads=new mT(this),this.responses=new dT(this),this.evals=new Ik(this),this.containers=new vk(this),this._options=s,this.apiKey=t,this.organization=n,this.project=r}defaultQuery(){return this._options.defaultQuery}defaultHeaders(e){return{...super.defaultHeaders(e),"OpenAI-Organization":this.organization,"OpenAI-Project":this.project,...this._options.defaultHeaders}}authHeaders(e){return{Authorization:`Bearer ${this.apiKey}`}}stringifyQuery(e){return function(e,t={}){let n=e;const r=function(e=Lw){if(void 0!==e.allowEmptyArrays&&"boolean"!=typeof e.allowEmptyArrays)throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(void 0!==e.encodeDotInKeys&&"boolean"!=typeof e.encodeDotInKeys)throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");const t=e.charset||Lw.charset;if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");let n=Pw;if(void 0!==e.format){if(!Mw.call(Cw,e.format))throw new TypeError("Unknown format option provided.");n=e.format}const r=Cw[n];let i,s=Lw.filter;if(("function"==typeof e.filter||Dw(e.filter))&&(s=e.filter),i=e.arrayFormat&&e.arrayFormat in $w?e.arrayFormat:"indices"in e?e.indices?"indices":"repeat":Lw.arrayFormat,"commaRoundTrip"in e&&"boolean"!=typeof e.commaRoundTrip)throw new TypeError("`commaRoundTrip` must be a boolean, or absent");const a=void 0===e.allowDots?1==!!e.encodeDotInKeys||Lw.allowDots:!!e.allowDots;return{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:Lw.addQueryPrefix,allowDots:a,allowEmptyArrays:"boolean"==typeof e.allowEmptyArrays?!!e.allowEmptyArrays:Lw.allowEmptyArrays,arrayFormat:i,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:Lw.charsetSentinel,commaRoundTrip:!!e.commaRoundTrip,delimiter:void 0===e.delimiter?Lw.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:Lw.encode,encodeDotInKeys:"boolean"==typeof e.encodeDotInKeys?e.encodeDotInKeys:Lw.encodeDotInKeys,encoder:"function"==typeof e.encoder?e.encoder:Lw.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:Lw.encodeValuesOnly,filter:s,format:n,formatter:r,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:Lw.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:Lw.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:Lw.strictNullHandling}}(t);let i,s;"function"==typeof r.filter?(s=r.filter,n=s("",n)):Dw(r.filter)&&(s=r.filter,i=s);const a=[];if("object"!=typeof n||null===n)return"";const o=$w[r.arrayFormat],c="comma"===o&&r.commaRoundTrip;i||(i=Object.keys(n)),r.sort&&i.sort(r.sort);const A=new WeakMap;for(let u=0;u<i.length;++u){const e=i[u];r.skipNulls&&null===n[e]||Gw(a,Hw(n[e],e,o,c,r.allowEmptyArrays,r.strictNullHandling,r.skipNulls,r.encodeDotInKeys,r.encode?r.encoder:null,r.filter,r.sort,r.allowDots,r.serializeDate,r.format,r.formatter,r.encodeValuesOnly,r.charset,A))}const l=a.join(r.delimiter);let f=!0===r.addQueryPrefix?"?":"";return r.charsetSentinel&&("iso-8859-1"===r.charset?f+="utf8=%26%2310003%3B&":f+="utf8=%E2%9C%93&"),l.length>0?f+l:""}(e,{arrayFormat:"brackets"})}}AT=kT,kT.OpenAI=AT,kT.DEFAULT_TIMEOUT=6e5,kT.OpenAIError=rv,kT.APIError=iv,kT.APIConnectionError=av,kT.APIConnectionTimeoutError=ov,kT.APIUserAbortError=sv,kT.NotFoundError=fv,kT.ConflictError=uv,kT.RateLimitError=hv,kT.BadRequestError=cv,kT.AuthenticationError=Av,kT.InternalServerError=pv,kT.PermissionDeniedError=lv,kT.UnprocessableEntityError=dv,kT.toFile=Cv,kT.fileFromPath=Zw,kT.Completions=yk,kT.Chat=b_,kT.ChatCompletionsPage=y_,kT.Embeddings=Ek,kT.Files=Ck,kT.FileObjectsPage=Nk,kT.Images=Qk,kT.Audio=E_,kT.Moderations=Kk,kT.Models=Vk,kT.ModelsPage=Jk,kT.FineTuning=Hk,kT.Graders=qk,kT.VectorStores=vT,kT.VectorStoresPage=_T,kT.VectorStoreSearchResponsesPage=ET,kT.Beta=mk,kT.Batches=k_,kT.BatchesPage=T_,kT.Uploads=mT,kT.Responses=dT,kT.Evals=Ik,kT.EvalListResponsesPage=Pk,kT.Containers=vk,kT.ContainerListResponsesPage=_k;class TT{constructor(e,t={}){if(!e)throw new Error("OpenAI API key is required");this.openai=new kT({apiKey:e}),this.model=t.model||"gpt-4o-mini",this.maxTokens=t.maxTokens||2e3,this.temperature=t.temperature||.7}async sendMessage(e,t,n={}){try{const r=await this.openai.chat.completions.create({model:n.model||this.model,messages:[{role:"system",content:e},{role:"user",content:t}],max_tokens:n.maxTokens||this.maxTokens,temperature:n.temperature??this.temperature});return r.choices[0]?.message?.content?.trim()||""}catch(r){throw new Error(`LLM request failed: ${r.message}`)}}async chat(e,t={}){try{const n=await this.openai.chat.completions.create({model:t.model||this.model,messages:e,max_tokens:t.maxTokens||this.maxTokens,temperature:t.temperature??this.temperature});return n.choices[0]?.message?.content?.trim()||""}catch(n){throw new Error(`LLM chat failed: ${n.message}`)}}async summarize(e,t={}){const n=`You are a helpful assistant that summarizes text concisely while preserving key information. Keep summaries clear and focused.${t.maxLength?` Keep the summary under ${t.maxLength} words.`:""}${t.style?` Style: ${t.style}.`:""}`;return this.sendMessage(n,e,{temperature:.5})}async analyze(e,t){const n=`You are an expert analyst. Analyze the following text from the perspective of "${t}". Provide a clear, structured analysis.`;return this.sendMessage(n,e,{temperature:.3})}async extractKeywords(e,t=10){const n=`Extract the ${t} most important keywords or key phrases from the text. Return ONLY a JSON array of strings, nothing else. Example: ["keyword1", "keyword2"]`,r=await this.sendMessage(n,e,{temperature:.2});try{return JSON.parse(r)}catch{const e=r.match(/\[[\s\S]*\]/);return e?JSON.parse(e[0]):r.split(",").map(e=>e.trim().replace(/["\[\]]/g,""))}}async categorize(e,t){const n=`Categorize the following text into one of these categories: ${t.join(", ")}.\nReturn ONLY a JSON object with: {"category": "chosen_category", "confidence": 0.0-1.0, "reasoning": "brief explanation"}`,r=await this.sendMessage(n,e,{temperature:.2});try{return JSON.parse(r)}catch{const e=r.match(/\{[\s\S]*\}/);return e?JSON.parse(e[0]):{category:t[0],confidence:.5,reasoning:r}}}async translate(e,t){const n=`Translate the following text to ${t}. Return ONLY the translation, nothing else.`;return this.sendMessage(n,e,{temperature:.3})}async generateQuestions(e,t=5){const n=`Generate ${t} insightful questions about the following text. Return ONLY a JSON array of question strings, nothing else. Example: ["Question 1?", "Question 2?"]`,r=await this.sendMessage(n,e,{temperature:.7});try{return JSON.parse(r)}catch{const e=r.match(/\[[\s\S]*\]/);return e?JSON.parse(e[0]):r.split("\n").filter(e=>e.trim().endsWith("?"))}}async getJSON(e,t,n={}){const r=await this.sendMessage(e+"\n\nReturn ONLY valid JSON, no additional text.",t,{...n,temperature:n.temperature??.2});try{return JSON.parse(r)}catch{const e=r.match(/[\[{][\s\S]*[\]}]/);if(e)return JSON.parse(e[0]);throw new Error(`Failed to parse JSON response: ${r.substring(0,100)}`)}}}class ST{constructor(e){this.llm=e}async extractToSchema(e,t,n={}){const r=this._describeSchema(t),i=`You are a data extraction expert. Extract structured information from the provided text according to this JSON schema:\n\n${JSON.stringify(t,null,2)}\n\nSchema field descriptions:\n${r}\n\nRules:\n1. Extract ONLY information present in the text\n2. Use null for fields where information is not available\n3. Follow the exact schema structure and field types\n4. For arrays, include all relevant items found\n5. Return ONLY valid JSON matching the schema`;return await this.llm.getJSON(i,e,{temperature:.2,maxTokens:n.maxTokens||2e3})}_describeSchema(e,t=""){const n=[];if(e.description&&n.push(`${t||"root"}: ${e.description}`),e.properties)for(const[r,i]of Object.entries(e.properties)){const s=t?`${t}.${r}`:r,a=i.type||"any",o=e.required?.includes(r)?" (required)":"",c=i.description||"";n.push(`- ${s} [${a}]${o}: ${c}`),"object"===i.type&&i.properties&&n.push(this._describeSchema(i,s)),"array"===i.type&&i.items&&i.items.properties&&n.push(this._describeSchema(i.items,`${s}[]`))}return n.join("\n")}async extractMultiple(e,t,n={}){const r=`You are a data extraction expert. Extract ALL items matching this schema from the text:\n\n${JSON.stringify(t,null,2)}\n\nReturn a JSON array of all items found. If no items found, return [].\nReturn ONLY valid JSON array.`,i=await this.llm.getJSON(r,e,{temperature:.2,maxTokens:n.maxTokens||3e3});return Array.isArray(i)?i:[i]}async fillMissing(e,t,n){const r=this._findMissingFields(e,n);if(0===r.length)return e;const i=`You have existing data:\n${JSON.stringify(e,null,2)}\n\nExtract ONLY the following missing fields from the text:\n${r.join(", ")}\n\nBased on this schema:\n${JSON.stringify(n,null,2)}\n\nReturn JSON with ONLY the missing fields that you can extract. Do not modify existing fields.`,s=await this.llm.getJSON(i,t,{temperature:.2});return{...e,...s}}_findMissingFields(e,t,n=""){const r=[];if(t.properties)for(const[i,s]of Object.entries(t.properties)){const t=n?`${n}.${i}`:i,a=e[i];null==a?r.push(t):"object"===s.type&&s.properties&&r.push(...this._findMissingFields(a,s,t))}return r}validateExtraction(e,t){const n=[];if(t.required)for(const r of t.required)void 0!==e[r]&&null!==e[r]||n.push(`Missing required field: ${r}`);if(t.properties)for(const[r,i]of Object.entries(t.properties)){const t=e[r];null!=t&&(this._validateType(t,i.type)||n.push(`Invalid type for ${r}: expected ${i.type}, got ${typeof t}`))}return{valid:0===n.length,errors:n}}_validateType(e,t){switch(t){case"string":return"string"==typeof e;case"number":case"integer":return"number"==typeof e;case"boolean":return"boolean"==typeof e;case"array":return Array.isArray(e);case"object":return"object"==typeof e&&!Array.isArray(e);default:return!0}}}class xT{constructor(e){this.llm=e}async add(e,t,n={}){const r=`You are a JSON merge expert. Semantically merge these two JSON objects.\n\nRules:\n1. Combine information from both objects intelligently\n2. For conflicting values, prefer the more complete/detailed one${n.preferSecond?", or prefer the second object":""}\n3. Merge arrays by combining items, removing duplicates by semantic similarity\n4. Preserve all unique information from both objects\n5. Return ONLY valid JSON`,i=`Object 1:\n${JSON.stringify(e,null,2)}\n\nObject 2:\n${JSON.stringify(t,null,2)}`;return this.llm.getJSON(r,i,{temperature:.2})}async subtract(e,t){const n=`Base object (to modify):\n${JSON.stringify(e,null,2)}\n\nConcepts to remove:\n${JSON.stringify(t,null,2)}`;return this.llm.getJSON("You are a JSON manipulation expert. Remove concepts from the first object that are semantically present in the second object.\n\nRules:\n1. Remove fields from obj1 that have semantic equivalents in obj2\n2. For arrays, remove items that are semantically similar to items in obj2\n3. Preserve fields/items in obj1 that have no semantic match in obj2\n4. Remove nested content that matches semantically\n5. Return ONLY valid JSON",n,{temperature:.2})}async union(e,t){const n=`Object 1:\n${JSON.stringify(e,null,2)}\n\nObject 2:\n${JSON.stringify(t,null,2)}`;return this.llm.getJSON("You are a JSON merge expert. Create a semantic union of these two JSON objects.\n\nRules:\n1. Include all unique information from both objects\n2. For duplicate concepts, keep only one (the more complete version)\n3. Deduplicate array items by semantic similarity, not just exact match\n4. Merge nested objects recursively with the same rules\n5. Return ONLY valid JSON",n,{temperature:.2})}async difference(e,t){const n=`Object 1 (original):\n${JSON.stringify(e,null,2)}\n\nObject 2 (new):\n${JSON.stringify(t,null,2)}`;return this.llm.getJSON('You are a JSON comparison expert. Find the semantic differences between these two JSON objects.\n\nReturn a JSON object with:\n- "added": fields/values present in obj2 but not in obj1\n- "removed": fields/values present in obj1 but not in obj2\n- "changed": fields where the value changed (show both old and new)\n\nConsider semantic similarity - fields with different names but same meaning should be considered the same.\nReturn ONLY valid JSON with the structure: {"added": {}, "removed": {}, "changed": {}}',n,{temperature:.2})}async concatenate(e,t){const n=`Object 1:\n${JSON.stringify(e,null,2)}\n\nObject 2:\n${JSON.stringify(t,null,2)}`;return this.llm.getJSON("You are a JSON concatenation expert. Concatenate these two JSON objects.\n\nRules:\n1. For string fields: append obj2 values to obj1 values with appropriate separators\n2. For array fields: append obj2 arrays to obj1 arrays\n3. For number fields: sum the values\n4. For object fields: recursively concatenate\n5. For boolean fields: use logical OR\n6. Preserve the structure of obj1\n7. Return ONLY valid JSON",n,{temperature:.2})}async intersection(e,t){const n=`Object 1:\n${JSON.stringify(e,null,2)}\n\nObject 2:\n${JSON.stringify(t,null,2)}`;return this.llm.getJSON("You are a JSON comparison expert. Find the semantic intersection of these two JSON objects.\n\nRules:\n1. Return only fields/values that are semantically present in BOTH objects\n2. For arrays, return only items that have semantic matches in both\n3. Consider semantic similarity, not just exact matches\n4. Return ONLY valid JSON",n,{temperature:.2})}async transform(e,t){const n=`You are a JSON transformation expert. Transform this JSON object according to the target structure description.\n\nTarget structure: ${t}\n\nRules:\n1. Map existing fields to the new structure\n2. Preserve all information, reorganizing as needed\n3. Use appropriate type conversions\n4. Return ONLY valid JSON`;return this.llm.getJSON(n,JSON.stringify(e,null,2),{temperature:.3})}async simplify(e,t={}){const n=`You are a JSON simplification expert. Simplify this nested JSON object.\n\nRules:\n1. Flatten deeply nested structures where appropriate\n2. Combine redundant fields\n3. Remove null/empty values${t.keepEmpty?" (unless specified to keep)":""}\n4. Use clear, concise field names\n5. Return ONLY valid JSON`;return this.llm.getJSON(n,JSON.stringify(e,null,2),{temperature:.3})}async apply(e,t){const n=`You are a JSON manipulation expert. Apply the following operation to the JSON object:\n\nOperation: ${t}\n\nReturn ONLY valid JSON with the operation applied.`;return this.llm.getJSON(n,JSON.stringify(e,null,2),{temperature:.3})}}class IT{constructor(e,t=null){this.openai=e,this.holosphere=t,this.model="text-embedding-3-small",this.dimensions=1536}setHoloSphere(e){this.holosphere=e}async embed(e){try{return(await this.openai.embeddings.create({model:this.model,input:e})).data[0].embedding}catch(t){throw new Error(`Embedding generation failed: ${t.message}`)}}async embedBatch(e){try{return(await this.openai.embeddings.create({model:this.model,input:e})).data.map(e=>e.embedding)}catch(t){throw new Error(`Batch embedding failed: ${t.message}`)}}cosineSimilarity(e,t){if(e.length!==t.length)throw new Error("Vectors must have same length");let n=0,r=0,i=0;for(let s=0;s<e.length;s++)n+=e[s]*t[s],r+=e[s]*e[s],i+=t[s]*t[s];return n/(Math.sqrt(r)*Math.sqrt(i))}async storeWithEmbedding(e,t,n,r=null){if(!this.holosphere)throw new Error("HoloSphere instance required for storage");const i=r?n[r]:n.content||n.text||n.description||JSON.stringify(n);if(!i)throw new Error("No text found to embed");const s=await this.embed(i),a={...n,_embedding:s,_embeddedField:r||"auto",_embeddedAt:Date.now()};return await this.holosphere.put(e,t,a),a}async semanticSearch(e,t,n,r={}){if(!this.holosphere)throw new Error("HoloSphere instance required for search");const{limit:i=10,threshold:s=.5}=r,a=await this.embed(e),o=await this.holosphere.getAll(t,n),c=[];for(const A of o)if(A._embedding){const e=this.cosineSimilarity(a,A._embedding);e>=s&&c.push({item:{...A,_embedding:void 0},similarity:e})}return c.sort((e,t)=>t.similarity-e.similarity),c.slice(0,i)}async findSimilar(e,t,n,r={}){const i=e.content||e.text||e.description||JSON.stringify(e);return this.semanticSearch(i,t,n,r)}async cluster(e,t=5){const n=await Promise.all(e.map(async e=>{if(e._embedding)return e;const t=e.content||e.text||e.description||JSON.stringify(e),n=await this.embed(t);return{...e,_embedding:n}}));return this._kMeans(n,t).map(e=>e.map(e=>({...e,_embedding:void 0})))}_kMeans(e,t,n=100){if(e.length<=t)return e.map(e=>[e]);let r=[...e].sort(()=>Math.random()-.5).slice(0,t).map(e=>[...e._embedding]),i=new Array(e.length);for(let a=0;a<n;a++){const n=e.map(e=>{let t=1/0,n=0;for(let i=0;i<r.length;i++){const s=1-this.cosineSimilarity(e._embedding,r[i]);s<t&&(t=s,n=i)}return n});if(JSON.stringify(n)===JSON.stringify(i))break;i=n;for(let s=0;s<t;s++){const t=e.filter((e,t)=>i[t]===s);if(t.length>0){r[s]=new Array(this.dimensions).fill(0);for(const e of t)for(let t=0;t<this.dimensions;t++)r[s][t]+=e._embedding[t];for(let e=0;e<this.dimensions;e++)r[s][e]/=t.length}}}const s=Array.from({length:t},()=>[]);return e.forEach((e,t)=>{s[i[t]].push(e)}),s.filter(e=>e.length>0)}}const PT=[{name:"Values & Worldview",prompt:"Answer from the embodied perspective of Values and Worldview - considering ethics, beliefs, culture, and meaning."},{name:"Health & Wellbeing",prompt:"Answer from the embodied perspective of Health & Wellbeing - considering physical, mental, and social health."},{name:"Food & Agriculture",prompt:"Answer from the embodied perspective of Food & Agriculture - considering food systems, nutrition, and farming."},{name:"Business & Trade",prompt:"Answer from the embodied perspective of Business & Trade - considering commerce, markets, and economic exchange."},{name:"Energy & Resources",prompt:"Answer from the embodied perspective of Energy & Resources - considering power, materials, and sustainability."},{name:"Climate & Environment",prompt:"Answer from the embodied perspective of Climate Change - considering environmental impact and adaptation."},{name:"Ecosystems & Biosphere",prompt:"Answer from the embodied perspective of Ecosystems & Biosphere - considering biodiversity and natural systems."},{name:"Water Availability",prompt:"Answer from the embodied perspective of Water Availability - considering water access, quality, and management."},{name:"Habitat & Infrastructure",prompt:"Answer from the embodied perspective of Habitat & Infrastructure - considering built environment and housing."},{name:"Economy & Wealth",prompt:"Answer from the embodied perspective of Economy & Wealth - considering prosperity, inequality, and resources."},{name:"Governance & Institutions",prompt:"Answer from the embodied perspective of Governance & Institutions - considering power, policy, and organization."},{name:"Community & Resilience",prompt:"Answer from the embodied perspective of Community & Resilience - considering social bonds and adaptability."}];class CT{constructor(e,t=null){this.llm=e,this.perspectives=t||PT}setPerspectives(e){this.perspectives=e}static getDefaultPerspectives(){return PT}async ask(e,t={}){const{parallel:n=!0,includeSummary:r=!0}=t,i=t.perspectives||this.perspectives;let s;if(n)s=await Promise.all(i.map(async t=>{const n=await this._askPerspective(e,t);return{perspective:t.name,answer:n}}));else{s=[];for(const t of i){const n=await this._askPerspective(e,t);s.push({perspective:t.name,answer:n})}}let a=null;return r&&(a=await this._summarize(e,s)),{question:e,perspectives:s,summary:a,timestamp:Date.now()}}async _askPerspective(e,t){const n=`You are a wise council member representing a specific perspective.\n\n${t.prompt}\n\nProvide thoughtful, nuanced answers that honor your unique perspective while being constructive and helpful. Be concise but insightful.`;return this.llm.sendMessage(n,e,{temperature:.7})}async _summarize(e,t){const n=`Question: ${e}\n\nPerspectives:\n${t.map(e=>`**${e.perspective}**: ${e.answer}`).join("\n\n")}`;return this.llm.sendMessage("You are a wise facilitator. Synthesize the following perspectives into a balanced summary that:\n1. Identifies common themes and agreements\n2. Notes important tensions or tradeoffs\n3. Provides actionable wisdom\n4. Remains neutral and balanced\n\nBe concise but comprehensive.",n,{temperature:.5})}static createPerspectives(e){return e.map(e=>({name:e,prompt:`Answer from the embodied perspective of ${e} - considering all aspects related to ${e.toLowerCase()}.`}))}async askCustom(e,t,n={}){const r=CT.createPerspectives(t);return this.ask(e,{...n,perspectives:r})}async askSingle(e,t){const n=this.perspectives.find(e=>e.name===t)||{name:t,prompt:`Answer from the perspective of ${t}.`};return this._askPerspective(e,n)}async debate(e,t,n=3){if(2!==t.length)throw new Error("Debate requires exactly 2 perspectives");const r=t.map(e=>this.perspectives.find(t=>t.name===e)||{name:e,prompt:`Argue from the perspective of ${e}.`}),i=[];let s=`Topic: ${e}`;for(let a=0;a<n;a++)for(const e of r){const t=`You are debating from the perspective of ${e.name}.\n${e.prompt}\nRespond to the previous arguments constructively, acknowledging good points but advocating for your perspective.`,n=await this.llm.sendMessage(t,s,{temperature:.7});i.push({perspective:e.name,round:a+1,response:n}),s+=`\n\n${e.name}: ${n}`}return{topic:e,perspectives:t,exchanges:i,conclusion:await this.llm.sendMessage("As a neutral moderator, summarize the key insights from this debate and identify areas of agreement and disagreement.",s,{temperature:.5})}}}const NT={ALLOY:"alloy",ECHO:"echo",FABLE:"fable",ONYX:"onyx",NOVA:"nova",SHIMMER:"shimmer"},OT={TTS_1:"tts-1",TTS_1_HD:"tts-1-hd"};class RT{constructor(e){this.openai=e,this.defaultVoice=NT.ECHO,this.defaultModel=OT.TTS_1}async speak(e,t={}){const{voice:n=this.defaultVoice,model:r=this.defaultModel,speed:i=1,responseFormat:s="mp3"}=t;try{const t=await this.openai.audio.speech.create({model:r,voice:n,input:e,speed:i,response_format:s}),a=await t.arrayBuffer();return Buffer.from(a)}catch(a){throw new Error(`TTS failed: ${a.message}`)}}async speakBase64(e,t={}){return(await this.speak(e,t)).toString("base64")}async speakDataUrl(e,t={}){const n=t.responseFormat||"mp3";return`data:${"mp3"===n?"audio/mpeg":`audio/${n}`};base64,${await this.speakBase64(e,t)}`}setDefaultVoice(e){if(!Object.values(NT).includes(e))throw new Error(`Invalid voice: ${e}. Use one of: ${Object.values(NT).join(", ")}`);this.defaultVoice=e}setDefaultModel(e){if(!Object.values(OT).includes(e))throw new Error(`Invalid model: ${e}. Use one of: ${Object.values(OT).join(", ")}`);this.defaultModel=e}static getVoices(){return Object.values(NT)}static getModels(){return Object.values(OT)}static estimateDuration(e,t=1){return e.split(/\s+/).length/150*60/t}static splitText(e,t=4e3){if(e.length<=t)return[e];const n=[],r=e.split(/(?<=[.!?])\s+/);let i="";for(const s of r)(i+s).length>t?(i&&n.push(i.trim()),i=s):i+=(i?" ":"")+s;return i&&n.push(i.trim()),n}async speakLong(e,t={}){const n=RT.splitText(e,t.maxChars||4e3);return await Promise.all(n.map(e=>this.speak(e,t)))}}class BT{constructor(e,t=null){this.llm=e,this.holosphere=t}setHoloSphere(e){this.holosphere=e}async parse(e,t={}){const n=`You are a query parser. Convert natural language queries into structured JSON filters for a geospatial database.\n\nAvailable holons: ${t.holons?.join(", ")||"any"}\nAvailable lenses: ${t.lenses?.join(", ")||"any"}\n\nReturn a JSON object with:\n{\n "holon": "holon_id or null",\n "lens": "lens_name or null",\n "filters": {\n "field_name": { "op": "eq|ne|gt|gte|lt|lte|contains|in", "value": value }\n },\n "sort": { "field": "field_name", "order": "asc|desc" } or null,\n "limit": number or null,\n "spatial": { "near": "location_name", "radius": "distance" } or null,\n "temporal": { "after": "date", "before": "date" } or null\n}\n\nExamples:\n- "show projects near Rome" -> { "lens": "projects", "spatial": { "near": "Rome" } }\n- "find quests with more than 10 participants" -> { "lens": "quests", "filters": { "participants": { "op": "gt", "value": 10 } } }`;return await this.llm.getJSON(n,e,{temperature:.2})}async execute(e,t={}){if(!this.holosphere)throw new Error("HoloSphere instance required for query execution");const n=await this.parse(e,t.context);let r=[];if(n.holon&&n.lens)r=await this.holosphere.getAll(n.holon,n.lens);else if(n.lens&&t.holons)for(const i of t.holons){const e=await this.holosphere.getAll(i,n.lens);r.push(...e.map(e=>({...e,_holon:i})))}return n.filters&&(r=this._applyFilters(r,n.filters)),n.sort&&(r=this._applySort(r,n.sort)),n.limit&&(r=r.slice(0,n.limit)),{query:e,parsed:n,results:r,count:r.length}}_applyFilters(e,t){return e.filter(e=>{for(const[n,r]of Object.entries(t)){const t=this._getNestedValue(e,n);if(!this._matchCondition(t,r))return!1}return!0})}_getNestedValue(e,t){return t.split(".").reduce((e,t)=>e?.[t],e)}_matchCondition(e,t){const{op:n,value:r}=t;switch(n){case"eq":return e===r;case"ne":return e!==r;case"gt":return e>r;case"gte":return e>=r;case"lt":return e<r;case"lte":return e<=r;case"contains":return String(e).toLowerCase().includes(String(r).toLowerCase());case"in":return Array.isArray(r)&&r.includes(e);default:return!0}}_applySort(e,t){const{field:n,order:r}=t,i="desc"===r?-1:1;return[...e].sort((e,t)=>{const r=this._getNestedValue(e,n),s=this._getNestedValue(t,n);return r<s?-1*i:r>s?1*i:0})}async suggest(e={}){const t=`Suggest 5 useful natural language queries for exploring geospatial data.\n\nAvailable holons: ${e.holons?.join(", ")||"geographic areas"}\nAvailable lenses: ${e.lenses?.join(", ")||"projects, quests, events, resources"}\n\nReturn ONLY a JSON array of query strings.`;return this.llm.getJSON(t,"Generate query suggestions",{temperature:.7})}async explain(e,t){const n=`You are a helpful data analyst. Explain the results of a query in natural language.\n\nOriginal query: ${e}\nNumber of results: ${t.length}\n\nProvide a brief, helpful summary of what was found.`,r=t.slice(0,5);return this.llm.sendMessage(n,`Results sample: ${JSON.stringify(r,null,2)}`,{temperature:.5})}}class MT{constructor(e,t=null){this.llm=e,this.holosphere=t,this.lensDescriptions=new Map}setHoloSphere(e){this.holosphere=e}registerLens(e,t,n=null){this.lensDescriptions.set(e,{description:t,schema:n})}registerLenses(e){for(const[t,n]of Object.entries(e))this.registerLens(t,n.description,n.schema)}async classifyToLens(e){const t=Array.from(this.lensDescriptions.entries());if(0===t.length)throw new Error("No lenses registered. Use registerLens() first.");const n=t.map(([e,t])=>`- ${e}: ${t.description}`).join("\n"),r="string"==typeof e?e:JSON.stringify(e,null,2),i=`You are a content classifier. Classify the following content into the most appropriate lens.\n\nAvailable lenses:\n${n}\n\nReturn JSON: {"lens": "lens_name", "confidence": 0.0-1.0, "reasoning": "brief explanation"}`;return this.llm.getJSON(i,r,{temperature:.2})}async classifyMultiple(e,t=3){const n=Array.from(this.lensDescriptions.entries());if(0===n.length)throw new Error("No lenses registered");const r=n.map(([e,t])=>`- ${e}: ${t.description}`).join("\n"),i="string"==typeof e?e:JSON.stringify(e,null,2),s=`You are a content classifier. Classify the content into up to ${t} appropriate lenses, ranked by fit.\n\nAvailable lenses:\n${r}\n\nReturn JSON array: [{"lens": "name", "confidence": 0.0-1.0}, ...]\nOrder by confidence descending.`;return this.llm.getJSON(s,i,{temperature:.2})}async autoStore(e,t){if(!this.holosphere)throw new Error("HoloSphere instance required for storage");const n=await this.classifyToLens(t),r=await this.holosphere.put(e,n.lens,t);return{lens:n.lens,confidence:n.confidence,reasoning:n.reasoning,stored:!0,result:r}}async suggestNewLens(e){const t=`You are helping design a data organization system. Suggest a new lens (category) for this type of content.\n\nExisting lenses: ${Array.from(this.lensDescriptions.keys()).join(", ")}\n\nReturn JSON: {"name": "lens_name", "description": "what this lens contains"}\nUse lowercase_snake_case for names.`;return this.llm.getJSON(t,e,{temperature:.5})}async suggestSchema(e){const t=JSON.stringify(e,null,2);return this.llm.getJSON("You are a data modeling expert. Analyze this content and suggest a JSON schema for validating similar content.\n\nReturn a valid JSON schema with:\n- Type definitions\n- Required fields\n- Field descriptions\n- Reasonable constraints",t,{temperature:.3})}async validateForLens(e,t){const n=this.lensDescriptions.get(t);if(!n)throw new Error(`Lens not found: ${t}`);if(!n.schema){const r=`Validate if this content is appropriate for the "${t}" lens.\nLens description: ${n.description}\n\nReturn JSON: {"valid": true/false, "issues": ["issue1", "issue2"] or []}`;return this.llm.getJSON(r,JSON.stringify(e,null,2),{temperature:.2})}return{valid:!0,issues:[]}}async analyzeCollection(e){const t=await Promise.all(e.map(e=>this.classifyToLens(e))),n={};for(const r of t)n[r.lens]=(n[r.lens]||0)+1;return{total:e.length,byLens:n,classifications:t}}}class $T{constructor(e,t=null){this.llm=e,this.holosphere=t}setHoloSphere(e){this.holosphere=e}async analyzeRegion(e,t=null,n="general"){if(!this.holosphere)throw new Error("HoloSphere instance required");let r=[];r=t?await this.holosphere.getAll(e,t):await this.holosphere.getAll(e,"default");const i=JSON.stringify(r.slice(0,50),null,2),s=`You are a geospatial data analyst. Analyze the following data from a geographic region.\n\nRegion (holon): ${e}\nLens: ${t||"all"}\nAnalysis aspect: ${n}\nTotal items: ${r.length}\n\nProvide insights about:\n1. Key patterns and trends\n2. Notable clusters or concentrations\n3. Anomalies or outliers\n4. Recommendations for the region\n\nReturn JSON:\n{\n "summary": "brief overview",\n "patterns": ["pattern1", "pattern2"],\n "insights": ["insight1", "insight2"],\n "metrics": {"metric1": value},\n "recommendations": ["rec1", "rec2"],\n "confidence": 0.0-1.0\n}`,a=await this.llm.getJSON(s,i,{temperature:.3});return{holon:e,lens:t,aspect:n,dataCount:r.length,analysis:a,timestamp:Date.now()}}async compareRegions(e,t,n){if(!this.holosphere)throw new Error("HoloSphere instance required");const r=await this.holosphere.getAll(e,n),i=await this.holosphere.getAll(t,n),s=`You are a comparative analyst. Compare data between two geographic regions.\n\nRegion 1 (${e}): ${r.length} items\nRegion 2 (${t}): ${i.length} items\nLens: ${n}\n\nAnalyze and compare:\n1. Similarities between regions\n2. Key differences\n3. Relative strengths of each region\n4. Opportunities for collaboration\n\nReturn JSON:\n{\n "summary": "brief comparison",\n "similarities": ["sim1", "sim2"],\n "differences": ["diff1", "diff2"],\n "region1_strengths": ["strength1"],\n "region2_strengths": ["strength1"],\n "collaboration_opportunities": ["opp1"],\n "metrics_comparison": {"metric": {"region1": val, "region2": val}}\n}`,a=`Region 1 data sample:\n${JSON.stringify(r.slice(0,25),null,2)}\n\nRegion 2 data sample:\n${JSON.stringify(i.slice(0,25),null,2)}`,o=await this.llm.getJSON(s,a,{temperature:.3});return{regions:[e,t],lens:n,dataCounts:{[e]:r.length,[t]:i.length},comparison:o,timestamp:Date.now()}}async spatialTrends(e,t,n={}){if(!this.holosphere)throw new Error("HoloSphere instance required");const r=await this.holosphere.getAll(e,t);let i=r;(n.start||n.end)&&(i=r.filter(e=>{const t=e.timestamp||e.created_at||e.date;if(!t)return!0;const r=new Date(t).getTime();return!(n.start&&r<new Date(n.start).getTime()||n.end&&r>new Date(n.end).getTime())}));const s=`You are a trend analyst. Analyze temporal patterns in geographic data.\n\nRegion: ${e}\nLens: ${t}\nTime range: ${JSON.stringify(n)}\nItems analyzed: ${i.length}\n\nIdentify:\n1. Growth/decline trends\n2. Seasonal patterns\n3. Emerging themes\n4. Predictions\n\nReturn JSON:\n{\n "trends": [{"trend": "description", "direction": "up|down|stable", "strength": 0.0-1.0}],\n "patterns": ["pattern1"],\n "emerging_themes": ["theme1"],\n "predictions": ["pred1"],\n "summary": "overview"\n}`,a=await this.llm.getJSON(s,JSON.stringify(i.slice(0,50),null,2),{temperature:.3});return{holon:e,lens:t,timeRange:n,dataCount:i.length,trends:a,timestamp:Date.now()}}async findHotspots(e,t,n="count"){if(!this.holosphere)throw new Error("HoloSphere instance required");const r=await this.holosphere.getAll(e,t),i=`You are a spatial analyst. Identify hotspots (areas of high concentration/activity) in geographic data.\n\nRegion: ${e}\nLens: ${t}\nMetric: ${n}\nData points: ${r.length}\n\nIdentify:\n1. High-activity areas\n2. Emerging areas\n3. Underserved areas\n4. Recommended focus areas\n\nReturn JSON:\n{\n "hotspots": [{"location": "desc", "intensity": 0.0-1.0, "type": "high_activity|emerging|underserved"}],\n "concentration_patterns": ["pattern1"],\n "recommendations": ["rec1"],\n "summary": "overview"\n}`;return this.llm.getJSON(i,JSON.stringify(r.slice(0,50),null,2),{temperature:.3})}async generateReport(e,t={}){if(!this.holosphere)throw new Error("HoloSphere instance required");const n=t.lenses||["default"],r={};for(const a of n)r[a]=await this.holosphere.getAll(e,a);const i=`You are a regional analyst. Generate a comprehensive report for this geographic region.\n\nRegion: ${e}\nData by lens: ${Object.entries(r).map(([e,t])=>`${e}: ${t.length} items`).join(", ")}\n\nGenerate a professional report including:\n1. Executive Summary\n2. Key Statistics\n3. Notable Patterns\n4. Opportunities\n5. Recommendations\n\nFormat as markdown.`,s={};for(const[a,o]of Object.entries(r))s[a]=o.slice(0,20);return this.llm.sendMessage(i,JSON.stringify(s,null,2),{temperature:.5,maxTokens:2e3})}}class DT{constructor(e,t=null){this.llm=e,this.holosphere=t}setHoloSphere(e){this.holosphere=e}async smartUpcast(e,t,n={}){if(!this.holosphere)throw new Error("HoloSphere instance required");const{maxLevels:r=5,storeResults:i=!0}=n,s=await this.holosphere.getAll(e,t),a=await this._generateSummary(s,e,t),o=hu(e);if(o<=0||r<=0)return{holon:e,lens:t,summary:a,level:o};const c=gu(e,o-1);i&&await this.holosphere.put(c,`${t}_summaries`,{id:e,childHolon:e,summary:a,dataCount:s.length,timestamp:Date.now()});const A=await this.smartUpcast(c,t,{...n,maxLevels:r-1});return{holon:e,lens:t,summary:a,dataCount:s.length,parent:A}}async _generateSummary(e,t,n){if(0===e.length)return{text:"No data in this region",stats:{count:0}};const r=`You are a data summarization expert. Create a concise summary of this geographic data.\n\nRegion: ${t}\nCategory: ${n}\nItems: ${e.length}\n\nGenerate:\n1. A brief text summary (2-3 sentences)\n2. Key statistics\n3. Notable items\n4. Themes/patterns\n\nReturn JSON:\n{\n "text": "summary text",\n "stats": {"count": n, "key_metric": value},\n "notable": ["item1", "item2"],\n "themes": ["theme1", "theme2"]\n}`;return this.llm.getJSON(r,JSON.stringify(e.slice(0,30),null,2),{temperature:.3})}async generateHolonSummary(e){if(!this.holosphere)throw new Error("HoloSphere instance required");const t=["projects","quests","events","resources","default"],n={};for(const s of t)try{const t=await this.holosphere.getAll(e,s);t.length>0&&(n[s]=t)}catch{}const r=`You are a regional analyst. Generate a comprehensive summary of this geographic area.\n\nRegion: ${e}\nData available: ${Object.entries(n).map(([e,t])=>`${e}: ${t.length}`).join(", ")}\n\nGenerate a complete overview including:\n1. Executive summary\n2. Key activities and projects\n3. Community engagement\n4. Resources and assets\n5. Challenges and opportunities\n6. Overall health assessment\n\nReturn JSON:\n{\n "title": "Region Title",\n "executive_summary": "brief overview",\n "highlights": ["highlight1", "highlight2"],\n "activities": {"count": n, "summary": "text"},\n "community": {"engagement_level": "high|medium|low", "notes": "text"},\n "resources": ["resource1"],\n "challenges": ["challenge1"],\n "opportunities": ["opp1"],\n "health_score": 0.0-1.0,\n "recommendations": ["rec1"]\n}`,i={};for(const[s,a]of Object.entries(n))i[s]=a.slice(0,15);return{holon:e,summary:await this.llm.getJSON(r,JSON.stringify(i,null,2),{temperature:.4,maxTokens:2e3}),lensesAnalyzed:Object.keys(n),totalItems:Object.values(n).reduce((e,t)=>e+t.length,0),timestamp:Date.now()}}async aggregateChildren(e,t){if(!this.holosphere)throw new Error("HoloSphere instance required");const n=bu(e,hu(e)+1),r=[];for(const a of n.slice(0,7))try{const e=await this.holosphere.getAll(a,t);if(e.length>0){const n=await this._generateSummary(e,a,t);r.push({holon:a,summary:n})}}catch{}if(0===r.length)return{holon:e,summary:null,message:"No child data found"};const i=`You are aggregating summaries from child regions into a parent region summary.\n\nParent region: ${e}\nChild summaries: ${r.length}\n\nCreate an aggregated summary that:\n1. Synthesizes common themes\n2. Highlights regional diversity\n3. Identifies cross-cutting patterns\n4. Notes outliers\n\nReturn JSON:\n{\n "aggregated_summary": "text",\n "common_themes": ["theme1"],\n "regional_diversity": ["diff1"],\n "patterns": ["pattern1"],\n "total_activity": {"count": n, "trend": "growing|stable|declining"}\n}`,s=await this.llm.getJSON(i,JSON.stringify(r,null,2),{temperature:.3});return{holon:e,lens:t,childCount:r.length,summary:s,timestamp:Date.now()}}async comparePeriods(e,t,n,r){if(!this.holosphere)throw new Error("HoloSphere instance required");const i=await this.holosphere.getAll(e,t),s=(e,t)=>e.filter(e=>{const n=e.timestamp||e.created_at;if(!n)return!1;const r=new Date(n).getTime();return r>=new Date(t.start).getTime()&&r<=new Date(t.end).getTime()}),a=s(i,n),o=s(i,r),c=`Compare data between two time periods for a geographic region.\n\nRegion: ${e}\nPeriod 1: ${JSON.stringify(n)} - ${a.length} items\nPeriod 2: ${JSON.stringify(r)} - ${o.length} items\n\nAnalyze:\n1. Growth/decline\n2. New themes in period 2\n3. Themes that disappeared\n4. Key changes\n\nReturn JSON:\n{\n "growth_rate": percentage,\n "direction": "growth|decline|stable",\n "new_themes": ["theme1"],\n "disappeared": ["theme1"],\n "key_changes": ["change1"],\n "summary": "text"\n}`,A=`Period 1 data:\n${JSON.stringify(a.slice(0,20),null,2)}\n\nPeriod 2 data:\n${JSON.stringify(o.slice(0,20),null,2)}`;return this.llm.getJSON(c,A,{temperature:.3})}}class FT{constructor(e,t=null,n=null){this.llm=e,this.holosphere=t,this.embeddings=n}setHoloSphere(e){this.holosphere=e}setEmbeddings(e){this.embeddings=e}async suggestFederations(e,t={}){if(!this.holosphere)throw new Error("HoloSphere instance required");const{candidateHolons:n=[],lens:r="default",maxSuggestions:i=5}=t,s=await this.holosphere.getAll(e,r);if(0===s.length)return{holon:e,suggestions:[],message:"No data in source holon"};const a=[];for(const A of n.slice(0,10))if(A!==e)try{const e=await this.holosphere.getAll(A,r);e.length>0&&a.push({holon:A,dataCount:e.length,dataSample:e.slice(0,10)})}catch{}if(0===a.length)return{holon:e,suggestions:[],message:"No candidate holons with data"};const o=`You are a federation advisor. Analyze which regions would benefit from federating (sharing data) with the source region.\n\nSource region: ${e}\nSource data count: ${s.length}\n\nConsider:\n1. Content similarity - similar topics benefit from shared visibility\n2. Complementary content - different but related content enables collaboration\n3. Geographic proximity relevance\n4. Potential for knowledge sharing\n\nReturn JSON array:\n[\n {\n "holon": "id",\n "score": 0.0-1.0,\n "reasoning": "why federate",\n "benefits": ["benefit1"],\n "type": "similarity|complementary|geographic"\n }\n]\n\nOrder by score descending, max ${i} suggestions.`,c=`Source data sample:\n${JSON.stringify(s.slice(0,15),null,2)}\n\nCandidate regions:\n${JSON.stringify(a,null,2)}`;return{holon:e,lens:r,suggestions:(await this.llm.getJSON(o,c,{temperature:.3})).slice(0,i),timestamp:Date.now()}}async analyzeFederationHealth(e){if(!this.holosphere)throw new Error("HoloSphere instance required");const t=await this.holosphere.getFederation(e);if(!t||!t.federation||0===t.federation.length)return{holon:e,health:"none",message:"No federations configured",score:0};const n=[];for(const s of t.federation.slice(0,5))try{const e=await this.holosphere.getAll(s,"default");n.push({holon:s,active:e.length>0,dataCount:e.length})}catch{n.push({holon:s,active:!1,error:!0})}const r=`You are a federation health analyst. Assess the health of this holon's federation relationships.\n\nSource holon: ${e}\nFederation partners: ${t.federation.length}\nActive federations: ${n.filter(e=>e.active).length}\n\nFederation details:\n${JSON.stringify(n,null,2)}\n\nAnalyze:\n1. Overall federation health\n2. Active vs inactive relationships\n3. Balance of the federation network\n4. Recommendations\n\nReturn JSON:\n{\n "health_score": 0.0-1.0,\n "status": "healthy|degraded|unhealthy",\n "active_count": n,\n "inactive_count": n,\n "issues": ["issue1"],\n "recommendations": ["rec1"],\n "summary": "text"\n}`,i=await this.llm.getJSON(r,"",{temperature:.3});return{holon:e,federation:t.federation,analysis:i,timestamp:Date.now()}}async optimizeFederation(e){const t=await this.analyzeFederationHealth(e);if("none"===t.health)return{holon:e,suggestions:["Consider establishing initial federations"]};const n=`Based on federation health analysis, suggest optimizations.\n\nHealth analysis:\n${JSON.stringify(t.analysis,null,2)}\n\nSuggest:\n1. Federations to strengthen\n2. Federations to reconsider\n3. New potential federations\n4. Data flow improvements\n\nReturn JSON:\n{\n "strengthen": ["holon_id"],\n "reconsider": ["holon_id"],\n "new_potential": ["description"],\n "improvements": ["improvement1"],\n "priority": "high|medium|low"\n}`;return this.llm.getJSON(n,"",{temperature:.4})}async analyzeDataFlow(e){if(!this.holosphere)throw new Error("HoloSphere instance required");const t=await this.holosphere.getFederation(e);if(!t)return{holon:e,message:"No federation configured"};const n=`Analyze the data flow patterns in a federation network.\n\nSource holon: ${e}\nFederated with: ${t.federation?.join(", ")||"none"}\nNotifies: ${t.notify?.join(", ")||"none"}\n\nConsider:\n1. Bidirectional vs unidirectional relationships\n2. Hub patterns (many connections)\n3. Data propagation paths\n4. Potential bottlenecks\n\nReturn JSON:\n{\n "flow_type": "bidirectional|unidirectional|mixed",\n "topology": "hub|mesh|chain|star",\n "propagation_depth": n,\n "bottlenecks": ["desc"],\n "recommendations": ["rec1"]\n}`;return this.llm.getJSON(n,JSON.stringify(t,null,2),{temperature:.3})}async findBridges(e){if(!this.holosphere)throw new Error("HoloSphere instance required");const t=[];for(const r of e.slice(0,20))try{const e=await this.holosphere.getFederation(r);e&&t.push({holon:r,federations:e.federation||[],notifies:e.notify||[]})}catch{}const n=`Analyze a federation network to identify bridge holons (connectors between clusters).\n\nNetwork:\n${JSON.stringify(t,null,2)}\n\nIdentify:\n1. Bridge holons that connect clusters\n2. Isolated holons\n3. Central hubs\n4. Network clusters\n\nReturn JSON:\n{\n "bridges": [{"holon": "id", "connects": ["cluster1", "cluster2"]}],\n "isolated": ["holon_id"],\n "hubs": [{"holon": "id", "connections": n}],\n "clusters": [["holon1", "holon2"]],\n "network_health": 0.0-1.0\n}`;return this.llm.getJSON(n,"",{temperature:.3})}}class GT{constructor(e,t=null,n=null){this.llm=e,this.holosphere=t,this.embeddings=n}setHoloSphere(e){this.holosphere=e}setEmbeddings(e){this.embeddings=e}async discoverRelationships(e,t=null){if(!this.holosphere)throw new Error("HoloSphere instance required");let n=[];const r=t?[t]:["projects","quests","events","resources","default"];for(const a of r)try{const t=await this.holosphere.getAll(e,a);n.push(...t.map(e=>({...e,_lens:a})))}catch{}if(n.length<2)return{holon:e,relationships:[],message:"Not enough data for relationship discovery"};const i=`You are a relationship discovery expert. Find hidden connections between items in this dataset.\n\nRegion: ${e}\nItems: ${n.length}\n\nLook for:\n1. Thematic connections (shared topics, goals)\n2. Entity connections (shared people, organizations)\n3. Temporal connections (same timeframes)\n4. Causal connections (one enables/requires another)\n5. Geographic connections (same sub-regions)\n\nReturn JSON:\n{\n "relationships": [\n {\n "item1": {"id": "id1", "title": "title"},\n "item2": {"id": "id2", "title": "title"},\n "type": "thematic|entity|temporal|causal|geographic",\n "strength": 0.0-1.0,\n "description": "relationship description"\n }\n ],\n "clusters": [\n {\n "theme": "cluster theme",\n "items": ["id1", "id2"]\n }\n ],\n "key_entities": ["entity1", "entity2"],\n "summary": "overview of relationship network"\n}`,s=await this.llm.getJSON(i,JSON.stringify(n.slice(0,40),null,2),{temperature:.3});return{holon:e,lens:t,itemCount:n.length,relationships:s,timestamp:Date.now()}}async findSimilar(e,t=null,n=null,r={}){if(!this.holosphere)throw new Error("HoloSphere instance required");const{limit:i=10,threshold:s=.5,useEmbeddings:a=!0}=r;if(a&&this.embeddings&&t&&n)return this.embeddings.findSimilar(e,t,n,{limit:i,threshold:s});if(!t)throw new Error("Holon required for LLM-based similarity");const o=n?[n]:["projects","quests","events","resources","default"];let c=[];for(const l of o)try{const e=await this.holosphere.getAll(t,l);c.push(...e.map(e=>({...e,_lens:l})))}catch{}if(0===c.length)return[];const A=`Find items most similar to the reference item.\n\nReference item:\n${JSON.stringify(e,null,2)}\n\nConsider:\n1. Topic/theme similarity\n2. Goal alignment\n3. Participant overlap\n4. Resource requirements\n5. Timeline compatibility\n\nReturn JSON array of similar items with similarity scores:\n[\n {\n "item": {item object},\n "similarity": 0.0-1.0,\n "reasons": ["reason1"]\n }\n]\n\nOrder by similarity descending. Max ${i} items with similarity >= ${s}.`;return(await this.llm.getJSON(A,JSON.stringify(c.slice(0,50),null,2),{temperature:.2})).slice(0,i).filter(e=>e.similarity>=s)}async buildGraph(e,t){const n=await this.discoverRelationships(e,t),r=new Map,i=[];for(const s of n.relationships?.relationships||[])r.has(s.item1.id)||r.set(s.item1.id,{id:s.item1.id,label:s.item1.title}),r.has(s.item2.id)||r.set(s.item2.id,{id:s.item2.id,label:s.item2.title}),i.push({source:s.item1.id,target:s.item2.id,type:s.type,weight:s.strength});return{nodes:Array.from(r.values()),edges:i,clusters:n.relationships?.clusters||[]}}async findCrossHolonRelationships(e,t){if(!this.holosphere)throw new Error("HoloSphere instance required");const n={};for(const i of e.slice(0,5))try{const e=await this.holosphere.getAll(i,t);e.length>0&&(n[i]=e.slice(0,15))}catch{}if(Object.keys(n).length<2)return{message:"Need at least 2 holons with data"};const r=`Find relationships between items across different geographic regions.\n\nRegions and their data:\n${JSON.stringify(n,null,2)}\n\nIdentify:\n1. Cross-region collaborations\n2. Shared themes across regions\n3. Potential synergies\n4. Knowledge transfer opportunities\n\nReturn JSON:\n{\n "cross_relationships": [\n {\n "holon1": "id",\n "item1": "item_id",\n "holon2": "id",\n "item2": "item_id",\n "type": "type",\n "potential": "collaboration|knowledge_share|synergy"\n }\n ],\n "shared_themes": [{"theme": "theme", "holons": ["id1", "id2"]}],\n "opportunities": ["opp1"]\n}`;return this.llm.getJSON(r,"",{temperature:.4})}async suggestConnections(e,t,n){const r=await this.findSimilar(e,t,n,{limit:10}),i=`Based on similar items found, suggest specific actions to create connections.\n\nReference item:\n${JSON.stringify(e,null,2)}\n\nSimilar items found:\n${JSON.stringify(r,null,2)}\n\nSuggest:\n1. Collaboration opportunities\n2. Resource sharing possibilities\n3. Joint initiatives\n4. Knowledge exchange\n\nReturn JSON:\n{\n "collaborations": [{"with": "item_id", "action": "suggested action"}],\n "resource_sharing": [{"items": ["id1", "id2"], "resource": "what to share"}],\n "initiatives": [{"description": "joint initiative", "participants": ["id1"]}],\n "knowledge_exchange": [{"from": "id", "to": "id", "topic": "topic"}]\n}`;return this.llm.getJSON(i,"",{temperature:.5})}async detectPatterns(e,t){const n=await this.discoverRelationships(e,t),r=`Analyze relationships and detect higher-level patterns.\n\nRelationships:\n${JSON.stringify(n.relationships,null,2)}\n\nDetect:\n1. Hub-spoke patterns (central connectors)\n2. Cluster patterns (tight groups)\n3. Bridge patterns (connecting different groups)\n4. Chain patterns (sequential relationships)\n5. Cyclical patterns (mutual dependencies)\n\nReturn JSON:\n{\n "patterns": [\n {\n "type": "hub|cluster|bridge|chain|cycle",\n "description": "pattern description",\n "items": ["id1", "id2"],\n "significance": "why this matters"\n }\n ],\n "network_structure": "description of overall structure",\n "recommendations": ["rec1"]\n}`;return this.llm.getJSON(r,"",{temperature:.3})}}class UT{constructor(e,t=null){this.llm=e,this.holosphere=t}setHoloSphere(e){this.holosphere=e}async breakdown(e,t,n,r={}){if(!e||!e.id)throw new Error("Item must have an id property");const{depth:i=2,stepsPerLevel:s={min:3,max:5},useContext:a=!0,storeResults:o=!0,dependencyField:c="dependencies",parentField:A="parent"}=r,l="number"==typeof s?{min:s,max:s}:s;let f=[];if(a&&this.holosphere)try{f=(await this.holosphere.getAll(t,n)).filter(t=>t.id!==e.id).slice(0,10)}catch{}let u=null;if(this.holosphere)try{u=await this.holosphere.getSchema(n)}catch{}const d=await this._breakdownRecursive(e,t,n,i,l,f,u,c,A,o,0);return{original:e,holonId:t,lensName:n,breakdown:d,totalSubtasks:this._countSubtasks(d),maxDepth:i,timestamp:Date.now()}}async _breakdownRecursive(e,t,n,r,i,s,a,o,c,A,l){if(l>=r)return{item:e,children:[],depth:l};const f=await this._generateSubtasks(e,s,a,i,o,c);if(A&&this.holosphere&&f.length>0){for(const e of f)try{await this.holosphere.write(t,n,e)}catch(d){console.warn(`Failed to store subtask ${e.id}:`,d.message)}if(e._meta?.childTasks!==f.map(e=>e.id))try{await this.holosphere.update(t,n,e.id,{_meta:{...e._meta,childTasks:f.map(e=>e.id),breakdownTimestamp:Date.now()}})}catch{}}const u=[];for(const h of f){const e=await this._breakdownRecursive(h,t,n,r,i,s,a,o,c,A,l+1);u.push(e)}return{item:e,children:u,depth:l}}async _generateSubtasks(e,t,n,r,i,s){const{min:a,max:o}=r,c=`You are a task decomposition expert. Break down the given task/quest into ${a}-${o} concrete, actionable subtasks.\n\nEach subtask should:\n1. Be a clear, specific action\n2. Be smaller and more manageable than the parent\n3. Together with siblings, fully accomplish the parent task\n4. Have a unique ID (format: parentId-1, parentId-2, etc.)\n5. Reference the parent task in the "${s}" field\n6. List any dependencies on sibling tasks in "${i}" array\n\n${n?`Follow this schema structure:\n${JSON.stringify(n,null,2)}`:""}\n\n${t.length>0?`Consider these existing items for context and avoid duplication:\n${JSON.stringify(t.slice(0,5),null,2)}`:""}\n\nReturn a JSON array of subtasks. Each subtask must have:\n- id: unique identifier (parentId-1, parentId-2, etc.)\n- title/name: clear action title\n- description: what needs to be done\n- ${s}: reference to parent id\n- ${i}: array of sibling task ids this depends on (empty if first task)\n- status: "pending"\n- Any other relevant fields from the parent schema\n\nExample output format:\n[\n {\n "id": "parent-1",\n "title": "First subtask",\n "description": "Details...",\n "${s}": "parentId",\n "${i}": [],\n "status": "pending"\n },\n {\n "id": "parent-2",\n "title": "Second subtask (depends on first)",\n "description": "Details...",\n "${s}": "parentId",\n "${i}": ["parent-1"],\n "status": "pending"\n }\n]`,A=`Break down this task into ${a}-${o} subtasks:\n\n${JSON.stringify(e,null,2)}`;try{return(await this.llm.getJSON(c,A,{temperature:.4,maxTokens:2e3})).map((t,n)=>({...t,id:t.id||`${e.id}-${n+1}`,[s]:e.id,[i]:t[i]||[],status:t.status||"pending",_meta:{...t._meta,generatedFrom:e.id,generatedAt:Date.now(),depth:(e._meta?.depth||0)+1}}))}catch(l){return console.error("Failed to generate subtasks:",l),[]}}_countSubtasks(e){return e.children&&0!==e.children.length?e.children.length+e.children.reduce((e,t)=>e+this._countSubtasks(t),0):0}flatten(e){const t=[],n=e=>{if(e.item&&t.push(e.item),e.children)for(const t of e.children)n(t)};return e.breakdown&&n(e.breakdown),t}getDependencyOrder(e){return this.flatten(e).sort((e,t)=>{const n=e._meta?.depth||0,r=t._meta?.depth||0;return n!==r?n-r:(t.dependencies||[]).includes(e.id)?-1:(e.dependencies||[]).includes(t.id)?1:0})}async suggestStrategy(e){return this.llm.getJSON('You are a task decomposition expert. Analyze this task and suggest the best breakdown strategy.\n\nConsider:\n1. Task complexity\n2. Recommended depth (1-4 levels)\n3. Recommended subtasks per level (2-7)\n4. Key areas to focus on\n5. Potential dependencies between subtasks\n\nReturn JSON:\n{\n "complexity": "simple|moderate|complex|very_complex",\n "recommendedDepth": n,\n "recommendedStepsPerLevel": {"min": n, "max": n},\n "focusAreas": ["area1", "area2"],\n "potentialChallenges": ["challenge1"],\n "estimatedTotalSubtasks": n,\n "reasoning": "explanation"\n}',JSON.stringify(e,null,2),{temperature:.3})}async rebalance(e,t={}){const{targetStepsPerLevel:n={min:3,max:5}}=t,r=this.flatten(e),i=`You are a task organization expert. Rebalance these tasks to have ${n.min}-${n.max} items per level.\n\nCurrent tasks:\n${JSON.stringify(r,null,2)}\n\nReorganize by:\n1. Merging tasks that are too granular\n2. Splitting tasks that are too large\n3. Maintaining proper dependency chains\n4. Keeping the same overall scope\n\nReturn JSON with the rebalanced structure:\n{\n "tasks": [...],\n "changes": [{"type": "merge|split|move", "description": "..."}],\n "summary": "what changed"\n}`;return this.llm.getJSON(i,"",{temperature:.3})}async getProgress(e,t,n){if(!this.holosphere)throw new Error("HoloSphere instance required");const r=await this.holosphere.getAll(e,t),i=r.find(e=>e.id===n);if(!i)throw new Error(`Item ${n} not found`);const s=this._findDescendants(n,r),a=s.length,o=s.filter(e=>"completed"===e.status||"done"===e.status).length,c=s.filter(e=>"in_progress"===e.status||"active"===e.status).length,A=a-o-c;return{itemId:n,title:i.title||i.name,total:a,completed:o,inProgress:c,pending:A,percentComplete:a>0?Math.round(o/a*100):0,blockers:this._findBlockers(s),nextUp:this._findNextTasks(s)}}_findDescendants(e,t,n="parent"){const r=[],i=t.filter(t=>t[n]===e);for(const s of i)r.push(s),r.push(...this._findDescendants(s.id,t,n));return r}_findBlockers(e,t="dependencies"){return e.filter(n=>{const r=n[t]||[];return 0!==r.length&&r.some(t=>{const n=e.find(e=>e.id===t);return n&&"completed"!==n.status&&"done"!==n.status})}).map(e=>({id:e.id,title:e.title||e.name,blockedBy:e[t]}))}_findNextTasks(e,t="dependencies"){return e.filter(n=>{if("completed"===n.status||"done"===n.status)return!1;if("in_progress"===n.status||"active"===n.status)return!1;const r=n[t]||[];return 0===r.length||r.every(t=>{const n=e.find(e=>e.id===t);return!n||"completed"===n.status||"done"===n.status})}).slice(0,5).map(e=>({id:e.id,title:e.title||e.name,description:e.description}))}}class LT{constructor(e,t=null){this.llm=e,this.holosphere=t}setHoloSphere(e){this.holosphere=e}async suggestResolution(e,t={}){const{currentResolution:n=null,context:r=null}=t,i=`You are a geospatial planning expert. Analyze this item and suggest the optimal H3 hexagonal resolution (0-15) for organizing it.\n\nH3 Resolution Guide:\n- Resolution 0-2: Continental/country scale (thousands of km)\n- Resolution 3-4: Regional/state scale (hundreds of km)\n- Resolution 5-6: Metropolitan/city scale (tens of km)\n- Resolution 7-8: District/neighborhood scale (km)\n- Resolution 9-10: Block/street scale (hundreds of meters)\n- Resolution 11-12: Building/lot scale (tens of meters)\n- Resolution 13-15: Room/precise scale (meters)\n\nConsider:\n1. Geographic scope mentioned in the item\n2. Number of potential participants/stakeholders\n3. Type of activity (local vs regional)\n4. Resource requirements and logistics\n5. Similar projects' typical scale\n\n${null!==n?`Current resolution: ${n}`:""}\n${r?`Context:\n${JSON.stringify(r,null,2)}`:""}\n\nReturn JSON:\n{\n "recommendedResolution": n,\n "reasoning": "why this resolution",\n "alternativeResolutions": [{"resolution": n, "useCase": "when to use"}],\n "geographicScope": "description of area covered",\n "scaleSuggestions": {\n "expansion": {"resolution": n, "reason": "when to expand"},\n "contraction": {"resolution": n, "reason": "when to focus"}\n }\n}`;return this.llm.getJSON(i,JSON.stringify(e,null,2),{temperature:.3})}async analyzeDistribution(e,t,n={}){if(!this.holosphere)throw new Error("HoloSphere instance required");const{includeChildren:r=!0,maxChildren:i=20}=n,s=await this.holosphere.getAll(e,t),a={};if(r&&du(e)){const n=hu(e);if(n<15){const r=bu(e,n+1);for(const e of r.slice(0,i))try{const n=await this.holosphere.getAll(e,t);n.length>0&&(a[e]={count:n.length,sample:n.slice(0,3)})}catch{}}}const o=`You are a geospatial analyst. Analyze the distribution of data across this H3 hexagonal region.\n\nParent holon: ${e}\nResolution: ${du(e)?hu(e):"N/A"}\nParent data count: ${s.length}\nChildren with data: ${Object.keys(a).length}\n\nAnalyze:\n1. Data density and distribution patterns\n2. Geographic hotspots and cold spots\n3. Coverage gaps\n4. Clustering patterns\n5. Recommendations for better coverage\n\nReturn JSON:\n{\n "distribution": {\n "pattern": "clustered|uniform|sparse|concentrated",\n "density": "high|medium|low",\n "coverage": 0.0-1.0\n },\n "hotspots": [{"holonId": "id", "reason": "why"}],\n "gaps": [{"description": "gap description", "suggestedAction": "what to do"}],\n "clusters": [{"theme": "cluster theme", "holons": ["id1"]}],\n "recommendations": ["rec1"],\n "summary": "overview"\n}`,c=`Parent data sample:\n${JSON.stringify(s.slice(0,10),null,2)}\n\nChildren distribution:\n${JSON.stringify(a,null,2)}`,A=await this.llm.getJSON(o,c,{temperature:.3});return{holonId:e,lensName:t,resolution:du(e)?hu(e):null,parentDataCount:s.length,childrenAnalyzed:Object.keys(a).length,analysis:A,timestamp:Date.now()}}async findNeighborRelevance(e,t,n={}){if(!this.holosphere)throw new Error("HoloSphere instance required");if(!du(e))throw new Error("Invalid H3 cell");const{ringSize:r=1,relevanceThreshold:i=.5}=n,s=await this.holosphere.getAll(e,t),a=vu(e,r).filter(t=>t!==e),o={};for(const f of a)try{const e=await this.holosphere.getAll(f,t);e.length>0&&(o[f]=e.slice(0,5))}catch{}if(0===Object.keys(o).length)return{holonId:e,neighbors:[],message:"No data found in neighboring cells"};const c=`You are a geospatial relevance analyst. Find items in neighboring H3 cells that are relevant to the center cell's data.\n\nCenter cell: ${e}\nRing size: ${r} (immediate neighbors)\n\nConsider:\n1. Thematic overlap\n2. Potential collaborations\n3. Shared resources\n4. Cross-boundary projects\n5. Geographic continuity of activities\n\nReturn JSON:\n{\n "relevantNeighbors": [\n {\n "holonId": "neighbor_id",\n "relevanceScore": 0.0-1.0,\n "relevantItems": [{"id": "item_id", "reason": "why relevant"}],\n "collaborationPotential": "description"\n }\n ],\n "crossBoundaryOpportunities": [\n {\n "description": "opportunity",\n "involvedHolons": ["id1", "id2"],\n "suggestedAction": "what to do"\n }\n ],\n "geographicPatterns": ["pattern1"],\n "summary": "overview"\n}`,A=`Center cell data:\n${JSON.stringify(s.slice(0,10),null,2)}\n\nNeighbor data:\n${JSON.stringify(o,null,2)}`,l=await this.llm.getJSON(c,A,{temperature:.4});return l.relevantNeighbors&&(l.relevantNeighbors=l.relevantNeighbors.filter(e=>e.relevanceScore>=i)),{holonId:e,lensName:t,ringSize:r,neighborsAnalyzed:Object.keys(o).length,analysis:l,timestamp:Date.now()}}async suggestGeographicScope(e,t,n,r={}){if(!this.holosphere)throw new Error("HoloSphere instance required");if(!du(t))throw new Error("Invalid H3 cell");const i=hu(t);let s=[];if(i>0){const e=gu(t,i-1);try{s=await this.holosphere.getAll(e,n)}catch{}}let a=[];if(i<15){const e=bu(t,i+1);for(const t of e.slice(0,7))try{const e=await this.holosphere.getAll(t,n);a.push(...e.slice(0,2))}catch{}}const o=`You are a geographic scope advisor. Analyze whether this item should expand to a larger region (parent holon) or focus on smaller sub-regions (children holons).\n\nCurrent holon: ${t}\nCurrent resolution: ${i}\n\nFactors to consider:\n1. Item's stated scope and goals\n2. Current participation/activity level\n3. Resource requirements\n4. Similar activities in parent/children\n5. Natural geographic boundaries\n\nReturn JSON:\n{\n "currentScopeAssessment": {\n "appropriate": true/false,\n "reasoning": "why"\n },\n "expansionRecommendation": {\n "recommended": true/false,\n "targetResolution": n,\n "reasoning": "why expand",\n "benefits": ["benefit1"],\n "risks": ["risk1"]\n },\n "contractionRecommendation": {\n "recommended": true/false,\n "targetResolution": n,\n "reasoning": "why contract",\n "suggestedFocusAreas": ["description"],\n "benefits": ["benefit1"],\n "risks": ["risk1"]\n },\n "optimalAction": "expand|contract|maintain",\n "summary": "recommendation summary"\n}`,c=`Item to analyze:\n${JSON.stringify(e,null,2)}\n\nParent region data (${s.length} items):\n${JSON.stringify(s.slice(0,5),null,2)}\n\nChildren regions data (${a.length} items):\n${JSON.stringify(a.slice(0,5),null,2)}`;return this.llm.getJSON(o,c,{temperature:.3})}async analyzeCoverage(e,t,n={}){if(!this.holosphere)throw new Error("HoloSphere instance required");if(!du(e))throw new Error("Invalid H3 cell");const{targetResolution:r=null}=n,i=hu(e),s=r||Math.min(i+1,15),a=bu(e,s),o={total:a.length,withData:0,withoutData:0,dataDistribution:{}},c=[],A=[];for(const u of a)try{const e=await this.holosphere.getAll(u,t);e.length>0?(o.withData++,o.dataDistribution[u]=e.length,c.push({holon:u,count:e.length})):(o.withoutData++,A.push(u))}catch{o.withoutData++,A.push(u)}const l=`You are a geographic coverage analyst. Analyze the data coverage in this H3 region.\n\nRegion: ${e}\nResolution: ${i}\nChild resolution analyzed: ${s}\nTotal children: ${o.total}\nChildren with data: ${o.withData}\nChildren without data: ${o.withoutData}\nCoverage ratio: ${(o.withData/o.total*100).toFixed(1)}%\n\nAnalyze:\n1. Coverage patterns\n2. Potential reasons for gaps\n3. Priority areas for expansion\n4. Whether gaps are concerning or expected\n\nReturn JSON:\n{\n "coverageScore": 0.0-1.0,\n "coverageQuality": "excellent|good|moderate|poor|minimal",\n "patterns": {\n "type": "clustered|scattered|peripheral|central|uniform",\n "description": "pattern description"\n },\n "gaps": {\n "count": n,\n "significance": "high|medium|low",\n "likelyReasons": ["reason1"],\n "priorityAreas": ["description of areas to focus"]\n },\n "recommendations": [\n {\n "action": "what to do",\n "priority": "high|medium|low",\n "targetArea": "description"\n }\n ],\n "summary": "overview"\n}`,f=await this.llm.getJSON(l,"",{temperature:.3});return{holonId:e,lensName:t,resolution:i,childResolution:s,coverage:{...o,ratio:o.withData/o.total},childrenWithData:c.slice(0,10),gapCount:A.length,analysis:f,timestamp:Date.now()}}async crossResolutionInsights(e,t,n={}){if(!this.holosphere)throw new Error("HoloSphere instance required");if(!du(e))throw new Error("Invalid H3 cell");const{levels:r=3}=n,i=hu(e),s={},a=await this.holosphere.getAll(e,t);s[i]={holon:e,count:a.length,sample:a.slice(0,5)};let o=e;for(let A=0;A<r&&hu(o)>0;A++){const e=hu(o)-1;o=gu(o,e);try{const n=await this.holosphere.getAll(o,t);s[e]={holon:o,count:n.length,sample:n.slice(0,5)}}catch{}}if(i<15){const n=i+1,r=bu(e,n);let a=0;const o=[];for(const e of r.slice(0,7))try{const n=await this.holosphere.getAll(e,t);a+=n.length,n.length>0&&o.push(...n.slice(0,2))}catch{}s[n]={holon:`${r.length} children`,count:a,sample:o.slice(0,5)}}const c=`You are a multi-scale geographic analyst. Find patterns that emerge across different H3 resolutions.\n\nStarting holon: ${e}\nResolutions analyzed: ${Object.keys(s).sort().join(", ")}\n\nData at each resolution:\n${JSON.stringify(s,null,2)}\n\nAnalyze:\n1. How themes evolve across scales\n2. What appears only at certain resolutions\n3. Aggregation patterns (local vs regional)\n4. Scale-dependent opportunities\n5. Optimal resolution for different activities\n\nReturn JSON:\n{\n "scalePatterns": [\n {\n "pattern": "description",\n "visibleAt": [resolution_numbers],\n "significance": "why this matters"\n }\n ],\n "themeEvolution": {\n "localThemes": ["themes at fine resolution"],\n "regionalThemes": ["themes at coarse resolution"],\n "consistentThemes": ["themes across all scales"]\n },\n "optimalResolutions": {\n "forCollaboration": n,\n "forResources": n,\n "forCommunity": n,\n "reasoning": "why"\n },\n "insights": ["insight1"],\n "recommendations": ["rec1"],\n "summary": "overview"\n}`;return this.llm.getJSON(c,"",{temperature:.4})}async suggestMigration(e,t,n,r={}){if(!this.holosphere)throw new Error("HoloSphere instance required");if(!du(t))throw new Error("Invalid H3 cell");const{searchRadius:i=2}=r,s=vu(t,i),a={};for(const f of s)if(f!==t)try{const e=await this.holosphere.getAll(f,n);e.length>0&&(a[f]={count:e.length,sample:e.slice(0,3)})}catch{}const o=hu(t);let c=null;if(o>0){const e=gu(t,o-1);try{const t=await this.holosphere.getAll(e,n);c={holon:e,count:t.length,sample:t.slice(0,3)}}catch{}}const A=`You are a geographic placement advisor. Determine if this item would be better suited in a different H3 cell.\n\nCurrent location: ${t}\nCurrent resolution: ${o}\n\nConsider:\n1. Thematic fit with existing data in each cell\n2. Geographic scope of the item\n3. Collaboration opportunities\n4. Resource proximity\n5. Community alignment\n\nReturn JSON:\n{\n "currentFit": {\n "score": 0.0-1.0,\n "reasoning": "why current location is/isn't appropriate"\n },\n "migrationRecommended": true/false,\n "suggestedDestinations": [\n {\n "holonId": "cell_id",\n "fitScore": 0.0-1.0,\n "reasoning": "why this location",\n "benefits": ["benefit1"],\n "drawbacks": ["drawback1"]\n }\n ],\n "stayReasons": ["reason to stay if applicable"],\n "moveReasons": ["reason to move if applicable"],\n "recommendation": "stay|move|duplicate",\n "summary": "final recommendation"\n}`,l=`Item to place:\n${JSON.stringify(e,null,2)}\n\nNearby cells with data:\n${JSON.stringify(a,null,2)}\n\n${c?`Parent cell data:\n${JSON.stringify(c,null,2)}`:""}`;return this.llm.getJSON(A,l,{temperature:.3})}async generateGeographicReport(e,t={}){if(!this.holosphere)throw new Error("HoloSphere instance required");const{lenses:n=["projects","quests","events","resources","default"]}=t,r={};for(const o of n)try{const t=await this.holosphere.getAll(e,o);t.length>0&&(r[o]={count:t.length,sample:t.slice(0,5)})}catch{}let i={};if(du(e)){const t=hu(e),[n,r]=mu(e),s=yu(e);i={resolution:t,center:{lat:n,lng:r},areaKm2:_u(e,"km2"),vertexCount:s.length}}const s=`You are a regional activity reporter. Generate a comprehensive report on geographic activity in this H3 region.\n\nRegion: ${e}\nGeographic context: ${JSON.stringify(i,null,2)}\nData available in ${Object.keys(r).length} categories\n\nGenerate a report covering:\n1. Executive summary\n2. Activity overview by category\n3. Key highlights and achievements\n4. Geographic patterns\n5. Opportunities and challenges\n6. Recommendations\n\nReturn JSON:\n{\n "title": "Region Report Title",\n "executiveSummary": "2-3 sentence overview",\n "activityOverview": {\n "totalItems": n,\n "categorySummaries": {"lens": "summary"}\n },\n "highlights": [\n {"title": "highlight", "description": "details", "category": "lens"}\n ],\n "geographicPatterns": ["pattern1"],\n "strengths": ["strength1"],\n "challenges": ["challenge1"],\n "opportunities": ["opportunity1"],\n "recommendations": [\n {"priority": "high|medium|low", "action": "what to do", "rationale": "why"}\n ],\n "metrics": {\n "activityLevel": "high|medium|low",\n "diversity": "high|medium|low",\n "growth": "growing|stable|declining"\n }\n}`,a=await this.llm.getJSON(s,JSON.stringify(r,null,2),{temperature:.4,maxTokens:2e3});return{holonId:e,geoContext:i,lensesAnalyzed:Object.keys(r),totalItems:Object.values(r).reduce((e,t)=>e+t.count,0),report:a,timestamp:Date.now()}}async findGeographicClusters(e,t,n={}){if(!this.holosphere)throw new Error("HoloSphere instance required");if(!du(e))throw new Error("Invalid H3 cell");const{clusterResolution:r=null}=n,i=hu(e),s=r||Math.min(i+1,15),a=bu(e,s),o={};for(const l of a)try{const e=await this.holosphere.getAll(l,t);e.length>0&&(o[l]=e)}catch{}if(Object.keys(o).length<2)return{holonId:e,clusters:[],message:"Not enough data for clustering"};const c=`You are a geographic clustering expert. Find thematic clusters in this spatial data.\n\nRegion: ${e}\nResolution analyzed: ${s}\nCells with data: ${Object.keys(o).length}\n\nIdentify:\n1. Thematic clusters (cells with similar content)\n2. Activity clusters (cells with related activities)\n3. Isolated cells (unique content)\n4. Potential connections between clusters\n\nReturn JSON:\n{\n "clusters": [\n {\n "name": "cluster name",\n "theme": "what unifies this cluster",\n "cells": ["cell_id1", "cell_id2"],\n "strength": 0.0-1.0,\n "characteristics": ["char1"]\n }\n ],\n "isolatedCells": [\n {"cellId": "id", "uniqueAspect": "what makes it unique"}\n ],\n "interClusterConnections": [\n {"cluster1": "name", "cluster2": "name", "connection": "how related"}\n ],\n "spatialPatterns": ["pattern1"],\n "recommendations": ["rec1"]\n}`,A=await this.llm.getJSON(c,JSON.stringify(o,null,2),{temperature:.4});return{holonId:e,lensName:t,clusterResolution:s,cellsAnalyzed:Object.keys(o).length,analysis:A,timestamp:Date.now()}}async analyzeGeographicImpact(e,t,n,r={}){if(!du(t))throw new Error("Invalid H3 cell");const i=hu(t),[s,a]=mu(t),o=_u(t,"km2");let c=null;if(i>0){const e=gu(t,Math.max(0,i-2));c={holon:e,resolution:i-2,areaKm2:_u(e,"km2")}}const A=`You are a geographic impact analyst. Analyze the geographic reach and impact of this item.\n\nItem location: ${t}\nResolution: ${i}\nCenter: ${s.toFixed(4)}, ${a.toFixed(4)}\nArea: ${o.toFixed(2)} km²\n\n${c?`Broader region: ${c.areaKm2.toFixed(2)} km²`:""}\n\nAnalyze:\n1. Direct impact area (immediate cell)\n2. Indirect impact area (spillover effects)\n3. Potential reach (if expanded)\n4. Geographic barriers/enablers\n5. Network effects\n\nReturn JSON:\n{\n "directImpact": {\n "areaKm2": n,\n "description": "direct impact area",\n "affectedPopulation": "estimate or N/A"\n },\n "indirectImpact": {\n "estimatedReach": n,\n "mechanisms": ["how impact spreads"],\n "neighboringAreas": ["affected areas"]\n },\n "potentialReach": {\n "ifExpanded": {\n "maxAreaKm2": n,\n "optimalResolution": n,\n "limitingFactors": ["factor1"]\n }\n },\n "geographicFactors": {\n "enablers": ["what helps geographic spread"],\n "barriers": ["what limits spread"]\n },\n "impactScore": {\n "local": 0.0-1.0,\n "regional": 0.0-1.0,\n "network": 0.0-1.0\n },\n "recommendations": ["how to increase impact"],\n "summary": "impact overview"\n}`;return this.llm.getJSON(A,JSON.stringify(e,null,2),{temperature:.3})}}const jT={ethereum:{name:"Ethereum Mainnet",chainId:1,rpc:"https://eth.llamarpc.com",explorer:"https://etherscan.io",currency:{name:"Ether",symbol:"ETH",decimals:18},type:"mainnet"},polygon:{name:"Polygon Mainnet",chainId:137,rpc:"https://polygon-rpc.com",explorer:"https://polygonscan.com",currency:{name:"MATIC",symbol:"MATIC",decimals:18},type:"mainnet"},arbitrum:{name:"Arbitrum One",chainId:42161,rpc:"https://arb1.arbitrum.io/rpc",explorer:"https://arbiscan.io",currency:{name:"Ether",symbol:"ETH",decimals:18},type:"mainnet"},base:{name:"Base",chainId:8453,rpc:"https://mainnet.base.org",explorer:"https://basescan.org",currency:{name:"Ether",symbol:"ETH",decimals:18},type:"mainnet"},optimism:{name:"Optimism",chainId:10,rpc:"https://mainnet.optimism.io",explorer:"https://optimistic.etherscan.io",currency:{name:"Ether",symbol:"ETH",decimals:18},type:"mainnet"},avalanche:{name:"Avalanche C-Chain",chainId:43114,rpc:"https://api.avax.network/ext/bc/C/rpc",explorer:"https://snowtrace.io",currency:{name:"AVAX",symbol:"AVAX",decimals:18},type:"mainnet"},bsc:{name:"BNB Smart Chain",chainId:56,rpc:"https://bsc-dataseed.binance.org",explorer:"https://bscscan.com",currency:{name:"BNB",symbol:"BNB",decimals:18},type:"mainnet"},sepolia:{name:"Sepolia",chainId:11155111,rpc:"https://rpc.sepolia.org",explorer:"https://sepolia.etherscan.io",currency:{name:"Sepolia ETH",symbol:"ETH",decimals:18},type:"testnet",faucet:"https://sepoliafaucet.com"},goerli:{name:"Goerli",chainId:5,rpc:"https://rpc.goerli.eth.gateway.fm",explorer:"https://goerli.etherscan.io",currency:{name:"Goerli ETH",symbol:"ETH",decimals:18},type:"testnet",faucet:"https://goerlifaucet.com"},mumbai:{name:"Polygon Mumbai",chainId:80001,rpc:"https://rpc-mumbai.maticvigil.com",explorer:"https://mumbai.polygonscan.com",currency:{name:"MATIC",symbol:"MATIC",decimals:18},type:"testnet",faucet:"https://faucet.polygon.technology"},amoy:{name:"Polygon Amoy",chainId:80002,rpc:"https://rpc-amoy.polygon.technology",explorer:"https://amoy.polygonscan.com",currency:{name:"MATIC",symbol:"MATIC",decimals:18},type:"testnet",faucet:"https://faucet.polygon.technology"},arbitrumSepolia:{name:"Arbitrum Sepolia",chainId:421614,rpc:"https://sepolia-rollup.arbitrum.io/rpc",explorer:"https://sepolia.arbiscan.io",currency:{name:"Ether",symbol:"ETH",decimals:18},type:"testnet"},baseSepolia:{name:"Base Sepolia",chainId:84532,rpc:"https://sepolia.base.org",explorer:"https://sepolia.basescan.org",currency:{name:"Ether",symbol:"ETH",decimals:18},type:"testnet"},optimismSepolia:{name:"Optimism Sepolia",chainId:11155420,rpc:"https://sepolia.optimism.io",explorer:"https://sepolia-optimism.etherscan.io",currency:{name:"Ether",symbol:"ETH",decimals:18},type:"testnet"},hardhat:{name:"Hardhat Local",chainId:31337,rpc:"http://127.0.0.1:8545",explorer:null,currency:{name:"Ether",symbol:"ETH",decimals:18},type:"local"},anvil:{name:"Anvil Local",chainId:31337,rpc:"http://127.0.0.1:8545",explorer:null,currency:{name:"Ether",symbol:"ETH",decimals:18},type:"local"},ganache:{name:"Ganache Local",chainId:1337,rpc:"http://127.0.0.1:7545",explorer:null,currency:{name:"Ether",symbol:"ETH",decimals:18},type:"local"}};function HT(e){if("string"==typeof e)return jT[e]||null;for(const[t,n]of Object.entries(jT))if(n.chainId===e)return{...n,key:t};return null}function zT(e){return e in jT}function qT(e,t){const n=jT[e];return n?.explorer?`${n.explorer}/address/${t}`:null}const QT=Object.freeze(Object.defineProperty({__proto__:null,NETWORKS:jT,default:jT,getAddressUrl:qT,getNetwork:HT,getNetworksByType:function(e){return Object.fromEntries(Object.entries(jT).filter(([t,n])=>n.type===e))},getTxUrl:function(e,t){const n=jT[e];return n?.explorer?`${n.explorer}/tx/${t}`:null},isNetworkSupported:zT,listNetworks:function(){return Object.keys(jT)}},Symbol.toStringTag,{value:"Module"}));class VT{constructor(e={}){this.config=e,this.provider=null,this.signer=null,this.network=null,this.networkName=null,this.ethers=null,this._initialized=!1}async _loadEthers(){if(!this.ethers){const e=await Promise.resolve().then(()=>yU);this.ethers=e}return this.ethers}async connect(e,t,n){const r=await this._loadEthers();if(!zT(e)&&!n)throw new Error(`Unsupported network: ${e}. Use a custom rpcUrl or choose from: ${Object.keys(jT).join(", ")}`);const i=HT(e)||{chainId:0,name:e},s=n||i.rpc;if(this.provider=new r.JsonRpcProvider(s,{chainId:i.chainId,name:i.name}),await this.provider.ready,this.network=await this.provider.getNetwork(),this.networkName=e,t){const e=t.startsWith("0x")?t:`0x${t}`;this.signer=new r.Wallet(e,this.provider)}return this._initialized=!0,{provider:this.provider,signer:this.signer,network:this.network,networkName:this.networkName,config:i}}async connectBrowser(e){const t=await this._loadEthers();if("undefined"==typeof window||!window.ethereum)throw new Error("No browser wallet detected. Please install MetaMask or another Web3 wallet.");if(await window.ethereum.request({method:"eth_requestAccounts"}),this.provider=new t.BrowserProvider(window.ethereum),this.signer=await this.provider.getSigner(),this.network=await this.provider.getNetwork(),e&&zT(e)){const t=HT(e);this.network.chainId!==BigInt(t.chainId)&&await this.switchNetwork(e)}const n=await this.signer.getAddress();return this._initialized=!0,{provider:this.provider,signer:this.signer,network:this.network,address:n}}async switchNetwork(e){if("undefined"==typeof window||!window.ethereum)throw new Error("Network switching requires a browser wallet");const t=HT(e);if(!t)throw new Error(`Unknown network: ${e}`);const n="0x"+t.chainId.toString(16);try{await window.ethereum.request({method:"wallet_switchEthereumChain",params:[{chainId:n}]})}catch(i){if(4902!==i.code)throw i;await window.ethereum.request({method:"wallet_addEthereumChain",params:[{chainId:n,chainName:t.name,nativeCurrency:t.currency,rpcUrls:[t.rpc],blockExplorerUrls:t.explorer?[t.explorer]:[]}]})}const r=await this._loadEthers();this.provider=new r.BrowserProvider(window.ethereum),this.signer=await this.provider.getSigner(),this.network=await this.provider.getNetwork(),this.networkName=e}getProvider(){return this._requireInitialized(),this.provider}getSigner(){if(this._requireInitialized(),!this.signer)throw new Error("No signer available. Connect with a private key or use connectBrowser().");return this.signer}async getAddress(){return this.getSigner().getAddress()}async getBalance(e){this._requireInitialized();const t=await this._loadEthers(),n=e||(this.signer?await this.signer.getAddress():null);if(!n)throw new Error("No address provided and no signer available");const r=await this.provider.getBalance(n);return t.formatEther(r)}getNetworkConfig(){return this._requireInitialized(),HT(this.networkName)}getChainId(){return this._requireInitialized(),Number(this.network.chainId)}isOnNetwork(e){if(!this._initialized)return!1;const t=HT(e);return!!t&&this.getChainId()===t.chainId}async getContract(e,t,n=!0){this._requireInitialized();const r=await this._loadEthers(),i=n&&this.signer?this.signer:this.provider;return new r.Contract(e,t,i)}async deployContract(e,t,n=[]){if(this._requireInitialized(),!this.signer)throw new Error("Signer required for contract deployment");const r=new((await this._loadEthers()).ContractFactory)(e,t,this.signer),i=await r.deploy(...n);await i.waitForDeployment();const s=await i.getAddress(),a=i.deploymentTransaction();return{contract:i,address:s,deployTx:a,txHash:a?.hash}}async waitForTransaction(e,t=1){return this._requireInitialized(),this.provider.waitForTransaction(e,t)}async estimateGas(e){return this._requireInitialized(),this.provider.estimateGas(e)}async getGasPrice(){this._requireInitialized();const e=await this._loadEthers(),t=await this.provider.getFeeData();return{gasPrice:t.gasPrice?e.formatUnits(t.gasPrice,"gwei"):null,maxFeePerGas:t.maxFeePerGas?e.formatUnits(t.maxFeePerGas,"gwei"):null,maxPriorityFeePerGas:t.maxPriorityFeePerGas?e.formatUnits(t.maxPriorityFeePerGas,"gwei"):null}}async parseUnits(e,t="ether"){return(await this._loadEthers()).parseUnits(e.toString(),t)}async formatUnits(e,t="ether"){return(await this._loadEthers()).formatUnits(e,t)}_requireInitialized(){if(!this._initialized)throw new Error("ChainManager not initialized. Call connect() or connectBrowser() first.")}isConnected(){return this._initialized&&null!==this.provider}disconnect(){this.provider=null,this.signer=null,this.network=null,this.networkName=null,this._initialized=!1}}const JT=[{type:"constructor",inputs:[{name:"_owner",type:"address",internalType:"address"},{name:"_creatorUserId",type:"string",internalType:"string"},{name:"_name",type:"string",internalType:"string"},{name:"_parameter",type:"uint256",internalType:"uint256"},{name:"_managedFactory",type:"address",internalType:"address"},{name:"_zonedFactory",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"fallback",stateMutability:"payable"},{type:"receive",stateMutability:"payable"},{type:"function",name:"addMember",inputs:[{name:"_userId",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addMember",inputs:[{name:"_memberaddress",type:"address",internalType:"address"},{name:"_membername",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addMembers",inputs:[{name:"_userIds",type:"string[]",internalType:"string[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addParent",inputs:[{name:"_parentaddress",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"botAddress",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"changeName",inputs:[{name:"_address",type:"address",internalType:"address"},{name:"_name",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"changeOwner",inputs:[{name:"_address",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"claim",inputs:[{name:"_userId",type:"string",internalType:"string"},{name:"_beneficiary",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"contractsByType",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"createManagedContract",inputs:[{name:"_creatorUserId",type:"string",internalType:"string"},{name:"_name",type:"string",internalType:"string"},{name:"_parameter",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"function",name:"createZonedContract",inputs:[{name:"_creatorUserId",type:"string",internalType:"string"},{name:"_name",type:"string",internalType:"string"},{name:"_parameter",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"function",name:"creator",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"creatorUserId",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"debugGetContractAddress",inputs:[{name:"contractKey",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"depositEtherForUser",inputs:[{name:"_userId",type:"string",internalType:"string"},{name:"amount",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"payable"},{type:"function",name:"depositTokenForUser",inputs:[{name:"_userId",type:"string",internalType:"string"},{name:"_tokenAddress",type:"address",internalType:"address"},{name:"_amount",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"etherBalance",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"externalContractSplitPercentage",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"flavor",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"getContractAddresses",inputs:[],outputs:[{name:"",type:"string[]",internalType:"string[]"},{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"getContractInfo",inputs:[{name:"key",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"getContractKeys",inputs:[],outputs:[{name:"",type:"string[]",internalType:"string[]"}],stateMutability:"view"},{type:"function",name:"getSize",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"hasClaimed",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"internalContractSplitPercentage",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"isMember",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"isSplitterMember",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"listMembers",inputs:[],outputs:[{name:"",type:"address[]",internalType:"address payable[]"}],stateMutability:"view"},{type:"function",name:"listParents",inputs:[],outputs:[{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"managedFactory",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"manifest",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"name",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"newHolon",inputs:[{name:"_flavor",type:"string",internalType:"string"},{name:"_name",type:"string",internalType:"string"},{name:"_parameter",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"function",name:"percentages",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"removeMember",inputs:[{name:"_memberaddress",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"reward",inputs:[{name:"_tokenaddress",type:"address",internalType:"address"},{name:"_tokenamount",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"payable"},{type:"function",name:"routeCommand",inputs:[{name:"contractName",type:"string",internalType:"string"},{name:"data",type:"bytes",internalType:"bytes"}],outputs:[{name:"",type:"bool",internalType:"bool"},{name:"",type:"bytes",internalType:"bytes"}],stateMutability:"nonpayable"},{type:"function",name:"setContractSplit",inputs:[{name:"_internalPercentage",type:"uint256",internalType:"uint256"},{name:"_externalPercentage",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setFactories",inputs:[{name:"_managedFactory",type:"address",internalType:"address"},{name:"_zonedFactory",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setManifest",inputs:[{name:"_IPFSHash",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setSplit",inputs:[{name:"_userIds",type:"string[]",internalType:"string[]"},{name:"percentage",type:"uint256[]",internalType:"uint256[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"toAddress",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"toName",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"tokenBalance",inputs:[{name:"",type:"string",internalType:"string"},{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"tokensOf",inputs:[{name:"",type:"string",internalType:"string"},{name:"",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"totalDeposited",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"userIdToAddress",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"userIds",inputs:[{name:"",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"version",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"zonedFactory",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"event",name:"AddedMember",inputs:[{name:"member",type:"address",indexed:!1,internalType:"address"},{name:"name",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"AppreciationGiven",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"fromUserId",type:"string",indexed:!1,internalType:"string"},{name:"toUserId",type:"string",indexed:!1,internalType:"string"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"ChangedName",inputs:[{name:"namefrom",type:"string",indexed:!1,internalType:"string"},{name:"nameto",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"ChildContractCreated",inputs:[{name:"parentContract",type:"address",indexed:!0,internalType:"address"},{name:"childContract",type:"address",indexed:!0,internalType:"address"},{name:"parentHolonId",type:"string",indexed:!1,internalType:"string"},{name:"childHolonId",type:"string",indexed:!1,internalType:"string"},{name:"childType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"ChildRewardTriggered",inputs:[{name:"",type:"address",indexed:!1,internalType:"address"},{name:"",type:"address",indexed:!1,internalType:"address"},{name:"",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"ContractSplitConfigured",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"internalPercentage",type:"uint256",indexed:!1,internalType:"uint256"},{name:"externalPercentage",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"DistributionCompleted",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"totalAmount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"recipientCount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"cascadeCount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"FundsAllocated",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"distributionType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"FundsCascaded",inputs:[{name:"fromContract",type:"address",indexed:!0,internalType:"address"},{name:"toContract",type:"address",indexed:!0,internalType:"address"},{name:"fromHolonId",type:"string",indexed:!1,internalType:"string"},{name:"toHolonId",type:"string",indexed:!1,internalType:"string"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"splitType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"FundsClaimed",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"beneficiary",type:"address",indexed:!0,internalType:"address"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"FundsForwarded",inputs:[{name:"",type:"address",indexed:!1,internalType:"address"},{name:"",type:"address",indexed:!1,internalType:"address"},{name:"",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"FundsReceived",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"sender",type:"address",indexed:!0,internalType:"address"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"FundsTransferred",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"recipient",type:"address",indexed:!0,internalType:"address"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"MemberAdded",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"addedBy",type:"address",indexed:!1,internalType:"address"}],anonymous:!1},{type:"event",name:"MemberRemoved",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"MemberRewarded",inputs:[{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"isContract",type:"bool",indexed:!1,internalType:"bool"},{name:"rewardType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"RemovedMember",inputs:[{name:"member",type:"address",indexed:!1,internalType:"address"},{name:"name",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"RewardDistributed",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"totalMembers",type:"uint256",indexed:!1,internalType:"uint256"},{name:"rewardType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"SplitConfigured",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"splitType",type:"string",indexed:!1,internalType:"string"},{name:"values",type:"uint256[]",indexed:!1,internalType:"uint256[]"}],anonymous:!1},{type:"event",name:"WeightChanged",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"oldWeight",type:"uint256",indexed:!1,internalType:"uint256"},{name:"newWeight",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"ZoneAssigned",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"oldZone",type:"uint256",indexed:!1,internalType:"uint256"},{name:"newZone",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{name:"token",type:"address",internalType:"address"}]}],KT=[{type:"constructor",inputs:[{name:"_creator",type:"address",internalType:"address"},{name:"_name",type:"string",internalType:"string"},{name:"_botAddress",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"fallback",stateMutability:"payable"},{type:"receive",stateMutability:"payable"},{type:"function",name:"addMember",inputs:[{name:"_userId",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addMember",inputs:[{name:"_memberaddress",type:"address",internalType:"address"},{name:"_membername",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addMembers",inputs:[{name:"_userIds",type:"string[]",internalType:"string[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addParent",inputs:[{name:"_parentaddress",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"appreciation",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"botAddress",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"changeName",inputs:[{name:"_address",type:"address",internalType:"address"},{name:"_name",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"changeOwner",inputs:[{name:"_address",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"claim",inputs:[{name:"_userId",type:"string",internalType:"string"},{name:"_beneficiary",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"creator",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"depositEtherForUser",inputs:[{name:"_userId",type:"string",internalType:"string"},{name:"amount",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"payable"},{type:"function",name:"depositTokenForUser",inputs:[{name:"_userId",type:"string",internalType:"string"},{name:"_tokenAddress",type:"address",internalType:"address"},{name:"_amount",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"etherBalance",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"flavor",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"getSize",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"getTokensOf",inputs:[{name:"_userId",type:"string",internalType:"string"}],outputs:[{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"hasClaimed",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"isManagedMember",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"isMember",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"listMembers",inputs:[],outputs:[{name:"",type:"address[]",internalType:"address payable[]"}],stateMutability:"view"},{type:"function",name:"listParents",inputs:[],outputs:[{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"manifest",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"maxAppreciation",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"name",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"newHolon",inputs:[{name:"_flavor",type:"string",internalType:"string"},{name:"_name",type:"string",internalType:"string"},{name:"_parameter",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"function",name:"removeMember",inputs:[{name:"_memberaddress",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"reward",inputs:[{name:"_tokenaddress",type:"address",internalType:"address"},{name:"_tokenamount",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"payable"},{type:"function",name:"setAppreciation",inputs:[{name:"_userIds",type:"string[]",internalType:"string[]"},{name:"_appreciationAmounts",type:"uint256[]",internalType:"uint256[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setManifest",inputs:[{name:"_IPFSHash",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setUserAppreciation",inputs:[{name:"_userId",type:"string",internalType:"string"},{name:"_appreciationAmount",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"toAddress",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"toName",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"tokenBalance",inputs:[{name:"",type:"string",internalType:"string"},{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"tokensOf",inputs:[{name:"",type:"string",internalType:"string"},{name:"",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"totalDeposited",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"totalappreciation",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"userIdToAddress",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"userIds",inputs:[{name:"",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"version",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"event",name:"AddedMember",inputs:[{name:"member",type:"address",indexed:!1,internalType:"address"},{name:"name",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"AppreciationGiven",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"fromUserId",type:"string",indexed:!1,internalType:"string"},{name:"toUserId",type:"string",indexed:!1,internalType:"string"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"ChangedName",inputs:[{name:"namefrom",type:"string",indexed:!1,internalType:"string"},{name:"nameto",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"DistributionCompleted",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"totalAmount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"recipientCount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"cascadeCount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"FundsAllocated",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"distributionType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"FundsCascaded",inputs:[{name:"fromContract",type:"address",indexed:!0,internalType:"address"},{name:"toContract",type:"address",indexed:!0,internalType:"address"},{name:"fromHolonId",type:"string",indexed:!1,internalType:"string"},{name:"toHolonId",type:"string",indexed:!1,internalType:"string"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"splitType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"FundsClaimed",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"beneficiary",type:"address",indexed:!0,internalType:"address"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"FundsReceived",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"sender",type:"address",indexed:!0,internalType:"address"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"FundsTransferred",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"recipient",type:"address",indexed:!0,internalType:"address"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"MemberAdded",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"addedBy",type:"address",indexed:!1,internalType:"address"}],anonymous:!1},{type:"event",name:"MemberRemoved",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"MemberRewarded",inputs:[{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"isContract",type:"bool",indexed:!1,internalType:"bool"},{name:"rewardType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"RemovedMember",inputs:[{name:"member",type:"address",indexed:!1,internalType:"address"},{name:"name",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"RewardDistributed",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"totalMembers",type:"uint256",indexed:!1,internalType:"uint256"},{name:"rewardType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"SplitConfigured",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"splitType",type:"string",indexed:!1,internalType:"string"},{name:"values",type:"uint256[]",indexed:!1,internalType:"uint256[]"}],anonymous:!1},{type:"event",name:"WeightChanged",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"oldWeight",type:"uint256",indexed:!1,internalType:"uint256"},{name:"newWeight",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"ZoneAssigned",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"oldZone",type:"uint256",indexed:!1,internalType:"uint256"},{name:"newZone",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1}],WT=[{type:"constructor",inputs:[{name:"creatorUserId",type:"string",internalType:"string"},{name:"_creator",type:"address",internalType:"address"},{name:"_name",type:"string",internalType:"string"},{name:"_nzones",type:"uint256",internalType:"uint256"},{name:"_botAddress",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"fallback",stateMutability:"payable"},{type:"receive",stateMutability:"payable"},{type:"function",name:"a",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"addFederationMember",inputs:[{name:"federationId",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addMember",inputs:[{name:"_memberaddress",type:"address",internalType:"address"},{name:"_membername",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addMember",inputs:[{name:"senderUserId",type:"string",internalType:"string"},{name:"_userId",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addMembers",inputs:[{name:"senderUserId",type:"string",internalType:"string"},{name:"_userIds",type:"string[]",internalType:"string[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addParent",inputs:[{name:"_parentaddress",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addToZone",inputs:[{name:"senderUserId",type:"string",internalType:"string"},{name:"_userId",type:"string",internalType:"string"},{name:"_zone",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addressToUserId",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"b",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"botAddress",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"c",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"calculateRewards",inputs:[],outputs:[{name:"",type:"uint256[]",internalType:"uint256[]"}],stateMutability:"view"},{type:"function",name:"changeName",inputs:[{name:"_address",type:"address",internalType:"address"},{name:"_name",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"changeOwner",inputs:[{name:"_address",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"claim",inputs:[{name:"_userId",type:"string",internalType:"string"},{name:"_beneficiary",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"creator",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"depositEtherForUser",inputs:[{name:"_userId",type:"string",internalType:"string"},{name:"amount",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"payable"},{type:"function",name:"depositTokenForUser",inputs:[{name:"_userId",type:"string",internalType:"string"},{name:"_tokenAddress",type:"address",internalType:"address"},{name:"_amount",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"etherBalance",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"factory",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"flavor",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"getSize",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"getZoneMembers",inputs:[{name:"_zone",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"string[]",internalType:"string[]"}],stateMutability:"view"},{type:"function",name:"hasClaimed",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"isMember",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"isZonedMember",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"listMembers",inputs:[],outputs:[{name:"",type:"address[]",internalType:"address payable[]"}],stateMutability:"view"},{type:"function",name:"listParents",inputs:[],outputs:[{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"manifest",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"name",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"newHolon",inputs:[{name:"_flavor",type:"string",internalType:"string"},{name:"_name",type:"string",internalType:"string"},{name:"_parameter",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"function",name:"nzones",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"percentages",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"removeFromZone",inputs:[{name:"senderUserId",type:"string",internalType:"string"},{name:"_userId",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"removeMember",inputs:[{name:"_memberaddress",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"reward",inputs:[{name:"_tokenaddress",type:"address",internalType:"address"},{name:"_tokenamount",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"payable"},{type:"function",name:"rewards",inputs:[{name:"",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"setManifest",inputs:[{name:"_IPFSHash",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setRewardFunction",inputs:[{name:"senderUserId",type:"string",internalType:"string"},{name:"_a",type:"uint256",internalType:"uint256"},{name:"_b",type:"uint256",internalType:"uint256"},{name:"_c",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"toAddress",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"toName",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"tokenBalance",inputs:[{name:"",type:"string",internalType:"string"},{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"tokensOf",inputs:[{name:"",type:"string",internalType:"string"},{name:"",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"totalDeposited",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"userIdToAddress",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"userIds",inputs:[{name:"",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"version",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"zone",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"zonemembers",inputs:[{name:"",type:"uint256",internalType:"uint256"},{name:"",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"event",name:"AddedMember",inputs:[{name:"member",type:"address",indexed:!1,internalType:"address"},{name:"name",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"AppreciationGiven",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"fromUserId",type:"string",indexed:!1,internalType:"string"},{name:"toUserId",type:"string",indexed:!1,internalType:"string"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"ChangedName",inputs:[{name:"namefrom",type:"string",indexed:!1,internalType:"string"},{name:"nameto",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"DistributionCompleted",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"totalAmount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"recipientCount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"cascadeCount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"FundsAllocated",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"distributionType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"FundsCascaded",inputs:[{name:"fromContract",type:"address",indexed:!0,internalType:"address"},{name:"toContract",type:"address",indexed:!0,internalType:"address"},{name:"fromHolonId",type:"string",indexed:!1,internalType:"string"},{name:"toHolonId",type:"string",indexed:!1,internalType:"string"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"splitType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"FundsClaimed",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"beneficiary",type:"address",indexed:!0,internalType:"address"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"FundsReceived",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"sender",type:"address",indexed:!0,internalType:"address"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"FundsTransferred",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"recipient",type:"address",indexed:!0,internalType:"address"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"MemberAdded",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"addedBy",type:"address",indexed:!1,internalType:"address"}],anonymous:!1},{type:"event",name:"MemberRemoved",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"MemberRewarded",inputs:[{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"isContract",type:"bool",indexed:!1,internalType:"bool"},{name:"rewardType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"RemovedMember",inputs:[{name:"member",type:"address",indexed:!1,internalType:"address"},{name:"name",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"RewardDistributed",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"totalMembers",type:"uint256",indexed:!1,internalType:"uint256"},{name:"rewardType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"SplitConfigured",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"splitType",type:"string",indexed:!1,internalType:"string"},{name:"values",type:"uint256[]",indexed:!1,internalType:"uint256[]"}],anonymous:!1},{type:"event",name:"WeightChanged",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"oldWeight",type:"uint256",indexed:!1,internalType:"uint256"},{name:"newWeight",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"ZoneAssigned",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"oldZone",type:"uint256",indexed:!1,internalType:"uint256"},{name:"newZone",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1}],YT=[{type:"constructor",inputs:[{name:"_name",type:"string",internalType:"string"},{name:"creatorUserId",type:"string",internalType:"string"},{name:"_creator",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"fallback",stateMutability:"payable"},{type:"receive",stateMutability:"payable"},{type:"function",name:"addMember",inputs:[{name:"_userId",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addMember",inputs:[{name:"_memberaddress",type:"address",internalType:"address"},{name:"_membername",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addMembers",inputs:[{name:"_userIds",type:"string[]",internalType:"string[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addParent",inputs:[{name:"_parentaddress",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addressToUserId",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"appreciate",inputs:[{name:"senderUserId",type:"string",internalType:"string"},{name:"_userId",type:"string",internalType:"string"},{name:"_percentage",type:"uint8",internalType:"uint8"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"appreciation",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"botAddress",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"changeName",inputs:[{name:"_address",type:"address",internalType:"address"},{name:"_name",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"changeOwner",inputs:[{name:"_address",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"claim",inputs:[{name:"_userId",type:"string",internalType:"string"},{name:"_beneficiary",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"creator",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"depositEtherForUser",inputs:[{name:"_userId",type:"string",internalType:"string"},{name:"amount",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"payable"},{type:"function",name:"depositTokenForUser",inputs:[{name:"_userId",type:"string",internalType:"string"},{name:"_tokenAddress",type:"address",internalType:"address"},{name:"_amount",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"etherBalance",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"flavor",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"getSize",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"hasClaimed",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"isAppreciativeMember",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"isMember",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"listMembers",inputs:[],outputs:[{name:"",type:"address[]",internalType:"address payable[]"}],stateMutability:"view"},{type:"function",name:"listParents",inputs:[],outputs:[{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"manifest",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"name",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"newHolon",inputs:[{name:"_flavor",type:"string",internalType:"string"},{name:"_name",type:"string",internalType:"string"},{name:"_parameter",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"function",name:"remainingappreciation",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"removeMember",inputs:[{name:"_memberaddress",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"resetAppreciation",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"reward",inputs:[{name:"_tokenaddress",type:"address",internalType:"address"},{name:"_tokenamount",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"payable"},{type:"function",name:"setAppreciation",inputs:[{name:"_userIds",type:"string[]",internalType:"string[]"},{name:"_percentages",type:"uint8[]",internalType:"uint8[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setManifest",inputs:[{name:"_IPFSHash",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"toAddress",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"toName",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"tokenBalance",inputs:[{name:"",type:"string",internalType:"string"},{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"tokensOf",inputs:[{name:"",type:"string",internalType:"string"},{name:"",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"totalDeposited",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"totalappreciation",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"userIdToAddress",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"userIds",inputs:[{name:"",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"version",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"event",name:"AddedMember",inputs:[{name:"member",type:"address",indexed:!1,internalType:"address"},{name:"name",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"AppreciationGiven",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"fromUserId",type:"string",indexed:!1,internalType:"string"},{name:"toUserId",type:"string",indexed:!1,internalType:"string"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"ChangedName",inputs:[{name:"namefrom",type:"string",indexed:!1,internalType:"string"},{name:"nameto",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"DistributionCompleted",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"totalAmount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"recipientCount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"cascadeCount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"FundsAllocated",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"distributionType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"FundsCascaded",inputs:[{name:"fromContract",type:"address",indexed:!0,internalType:"address"},{name:"toContract",type:"address",indexed:!0,internalType:"address"},{name:"fromHolonId",type:"string",indexed:!1,internalType:"string"},{name:"toHolonId",type:"string",indexed:!1,internalType:"string"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"splitType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"FundsClaimed",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"beneficiary",type:"address",indexed:!0,internalType:"address"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"FundsReceived",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"sender",type:"address",indexed:!0,internalType:"address"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"FundsTransferred",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"recipient",type:"address",indexed:!0,internalType:"address"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"MemberAdded",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"addedBy",type:"address",indexed:!1,internalType:"address"}],anonymous:!1},{type:"event",name:"MemberRemoved",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"MemberRewarded",inputs:[{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"isContract",type:"bool",indexed:!1,internalType:"bool"},{name:"rewardType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"RemovedMember",inputs:[{name:"member",type:"address",indexed:!1,internalType:"address"},{name:"name",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"RewardDistributed",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"totalMembers",type:"uint256",indexed:!1,internalType:"uint256"},{name:"rewardType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"SplitConfigured",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"splitType",type:"string",indexed:!1,internalType:"string"},{name:"values",type:"uint256[]",indexed:!1,internalType:"uint256[]"}],anonymous:!1},{type:"event",name:"WeightChanged",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"oldWeight",type:"uint256",indexed:!1,internalType:"uint256"},{name:"newWeight",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"ZoneAssigned",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"oldZone",type:"uint256",indexed:!1,internalType:"uint256"},{name:"newZone",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1}],ZT={abi:[{type:"constructor",inputs:[{name:"_owner",type:"address",internalType:"address"},{name:"_creatorUserId",type:"string",internalType:"string"},{name:"_name",type:"string",internalType:"string"},{name:"_steepness",type:"uint256",internalType:"uint256"},{name:"_nzones",type:"uint256",internalType:"uint256"}],stateMutability:"nonpayable"},{type:"fallback",stateMutability:"payable"},{type:"receive",stateMutability:"payable"},{type:"function",name:"BASIS_POINTS",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"WAD",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"addMember",inputs:[{name:"_userId",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addMembers",inputs:[{name:"_userIds",type:"string[]",internalType:"string[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"assignToZone",inputs:[{name:"_userId",type:"string",internalType:"string"},{name:"_zone",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"cancelElection",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"candidates",inputs:[{name:"",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"claim",inputs:[{name:"_userId",type:"string",internalType:"string"},{name:"_beneficiary",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"creator",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"electionActive",inputs:[],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"etherBalance",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"exteriorPercentage",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"factory",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"finalizeElection",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"flavor",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"getCandidates",inputs:[],outputs:[{name:"",type:"string[]",internalType:"string[]"}],stateMutability:"view"},{type:"function",name:"getInteriorMembers",inputs:[],outputs:[{name:"",type:"string[]",internalType:"string[]"}],stateMutability:"view"},{type:"function",name:"getSize",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"getTokensOf",inputs:[{name:"_userId",type:"string",internalType:"string"}],outputs:[{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"getZoneMembers",inputs:[{name:"_zone",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"string[]",internalType:"string[]"}],stateMutability:"view"},{type:"function",name:"getZoneWeights",inputs:[],outputs:[{name:"",type:"uint256[]",internalType:"uint256[]"}],stateMutability:"view"},{type:"function",name:"hasClaimed",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"hasVoted",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"interiorMembers",inputs:[{name:"",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"interiorPercentage",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"interiorShare",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"isBundleMember",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"isCandidate",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"isExteriorMember",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"isInteriorMember",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"name",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"nominateSelf",inputs:[{name:"_userId",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"nzones",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"owner",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"removeFromExterior",inputs:[{name:"_userId",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"reward",inputs:[{name:"_tokenaddress",type:"address",internalType:"address"},{name:"_tokenamount",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"payable"},{type:"function",name:"setContractSplit",inputs:[{name:"_interior",type:"uint256",internalType:"uint256"},{name:"_exterior",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setInteriorSplit",inputs:[{name:"_userIds",type:"string[]",internalType:"string[]"},{name:"_percentages",type:"uint256[]",internalType:"uint256[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setNzones",inputs:[{name:"_nzones",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setSteepness",inputs:[{name:"_steepness",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"startElection",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"steepness",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"tokenBalance",inputs:[{name:"",type:"string",internalType:"string"},{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"tokensOf",inputs:[{name:"",type:"string",internalType:"string"},{name:"",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"totalDeposited",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"totalWeightedMembers",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"userIdToAddress",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"userIds",inputs:[{name:"",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"vote",inputs:[{name:"_voterId",type:"string",internalType:"string"},{name:"_candidateId",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"votedFor",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"votes",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"zone",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"zoneWeights",inputs:[{name:"",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"zonemembers",inputs:[{name:"",type:"uint256",internalType:"uint256"},{name:"",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"event",name:"CandidateNominated",inputs:[{name:"userId",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"ContractSplitSet",inputs:[{name:"interior",type:"uint256",indexed:!1,internalType:"uint256"},{name:"exterior",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"DistributionCompleted",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"totalAmount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"recipientCount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"cascadeCount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"ElectionCancelled",inputs:[],anonymous:!1},{type:"event",name:"ElectionFinalized",inputs:[{name:"winner",type:"string",indexed:!1,internalType:"string"},{name:"voteCount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"ElectionStarted",inputs:[],anonymous:!1},{type:"event",name:"FundsAllocated",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"distributionType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"FundsClaimed",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"beneficiary",type:"address",indexed:!0,internalType:"address"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"FundsReceived",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"sender",type:"address",indexed:!0,internalType:"address"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"FundsTransferred",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"recipient",type:"address",indexed:!0,internalType:"address"},{name:"tokenAddress",type:"address",indexed:!1,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"InteriorSplitSet",inputs:[{name:"userIds",type:"string[]",indexed:!1,internalType:"string[]"},{name:"percentages",type:"uint256[]",indexed:!1,internalType:"uint256[]"}],anonymous:!1},{type:"event",name:"MemberAdded",inputs:[{name:"userId",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"MemberAddedStd",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"addedBy",type:"address",indexed:!1,internalType:"address"}],anonymous:!1},{type:"event",name:"MemberAssignedToZone",inputs:[{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"zoneNumber",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"MemberRemovedFromZone",inputs:[{name:"userId",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"MemberRewarded",inputs:[{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"isContract",type:"bool",indexed:!1,internalType:"bool"},{name:"rewardType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"OwnershipTransferred",inputs:[{name:"previousOwner",type:"address",indexed:!0,internalType:"address"},{name:"newOwner",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"event",name:"RewardDistributed",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"totalMembers",type:"uint256",indexed:!1,internalType:"uint256"},{name:"rewardType",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"SteepnessSet",inputs:[{name:"steepness",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"VoteCast",inputs:[{name:"voter",type:"string",indexed:!1,internalType:"string"},{name:"candidate",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"ZoneAssigned",inputs:[{name:"contractAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonId",type:"string",indexed:!1,internalType:"string"},{name:"userId",type:"string",indexed:!1,internalType:"string"},{name:"oldZone",type:"uint256",indexed:!1,internalType:"uint256"},{name:"newZone",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{name:"token",type:"address",internalType:"address"}]}],bytecode:"0x60806040526040518060400160405280600681526020017f42756e646c650000000000000000000000000000000000000000000000000000815250600290816200004a9190620006da565b5034801562000057575f80fd5b5060405162007e0338038062007e0383398181016040528101906200007d9190620009a6565b60015f819055505f821180156200009b5750670de0b6b3a764000082105b620000dd576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401620000d49062000ac6565b60405180910390fd5b8460035f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508460045f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055503360055f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508260019081620001ae9190620006da565b5081601381905550806014819055506001600985604051620001d1919062000b26565b90815260200160405180910390205f6101000a81548160ff021916908315150217905550600684908060018154018082558091505060019003905f5260205f20015f909190919091509081620002289190620006da565b50620002396200024460201b60201c565b505050505062000d3a565b60185f620002539190620003e9565b600160145462000264919062000b6b565b67ffffffffffffffff81111562000280576200027f62000480565b5b604051908082528060200260200182016040528015620002af5781602001602082028036833780820191505090505b5060189080519060200190620002c792919062000409565b505f6019819055505f670de0b6b3a764000090505f5b60145481116200037b578160188281548110620002ff57620002fe62000ba5565b5b905f5260205f2001819055508160155f8381526020019081526020015f20805490506200032d919062000bd2565b60195f8282546200033f919062000b6b565b925050819055506200036382601354670de0b6b3a76400006200037f60201b60201c565b91508080620003729062000c1c565b915050620002dd565b5050565b5f808211620003c5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401620003bc9062000cb6565b60405180910390fd5b818385620003d4919062000bd2565b620003e0919062000d03565b90509392505050565b5080545f8255905f5260205f209081019062000406919062000459565b50565b828054828255905f5260205f2090810192821562000446579160200282015b828111156200044557825182559160200191906001019062000428565b5b50905062000455919062000459565b5090565b5b8082111562000472575f815f9055506001016200045a565b5090565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f6002820490506001821680620004f257607f821691505b602082108103620005085762000507620004ad565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f600883026200056c7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff826200052f565b6200057886836200052f565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f620005c2620005bc620005b68462000590565b62000599565b62000590565b9050919050565b5f819050919050565b620005dd83620005a2565b620005f5620005ec82620005c9565b8484546200053b565b825550505050565b5f90565b6200060b620005fd565b62000618818484620005d2565b505050565b5b818110156200063f57620006335f8262000601565b6001810190506200061e565b5050565b601f8211156200068e5762000658816200050e565b620006638462000520565b8101602085101562000673578190505b6200068b620006828562000520565b8301826200061d565b50505b505050565b5f82821c905092915050565b5f620006b05f198460080262000693565b1980831691505092915050565b5f620006ca83836200069f565b9150826002028217905092915050565b620006e58262000476565b67ffffffffffffffff81111562000701576200070062000480565b5b6200070d8254620004da565b6200071a82828562000643565b5f60209050601f83116001811462000750575f84156200073b578287015190505b620007478582620006bd565b865550620007b6565b601f19841662000760866200050e565b5f5b82811015620007895784890151825560018201915060208501945060208101905062000762565b86831015620007a95784890151620007a5601f8916826200069f565b8355505b6001600288020188555050505b505050505050565b5f604051905090565b5f80fd5b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f620007fa82620007cf565b9050919050565b6200080c81620007ee565b811462000817575f80fd5b50565b5f815190506200082a8162000801565b92915050565b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b620008538262000838565b810181811067ffffffffffffffff8211171562000875576200087462000480565b5b80604052505050565b5f62000889620007be565b905062000897828262000848565b919050565b5f67ffffffffffffffff821115620008b957620008b862000480565b5b620008c48262000838565b9050602081019050919050565b5f5b83811015620008f0578082015181840152602081019050620008d3565b5f8484015250505050565b5f620009116200090b846200089c565b6200087e565b90508281526020810184848401111562000930576200092f62000834565b5b6200093d848285620008d1565b509392505050565b5f82601f8301126200095c576200095b62000830565b5b81516200096e848260208601620008fb565b91505092915050565b620009828162000590565b81146200098d575f80fd5b50565b5f81519050620009a08162000977565b92915050565b5f805f805f60a08688031215620009c257620009c1620007c7565b5b5f620009d1888289016200081a565b955050602086015167ffffffffffffffff811115620009f557620009f4620007cb565b5b62000a038882890162000945565b945050604086015167ffffffffffffffff81111562000a275762000a26620007cb565b5b62000a358882890162000945565b935050606062000a488882890162000990565b925050608062000a5b8882890162000990565b9150509295509295909350565b5f82825260208201905092915050565b7f53746565706e657373206d7573742062652030203c2073203c203165313800005f82015250565b5f62000aae601e8362000a68565b915062000abb8262000a78565b602082019050919050565b5f6020820190508181035f83015262000adf8162000aa0565b9050919050565b5f81905092915050565b5f62000afc8262000476565b62000b08818562000ae6565b935062000b1a818560208601620008d1565b80840191505092915050565b5f62000b33828462000af0565b915081905092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f62000b778262000590565b915062000b848362000590565b925082820190508082111562000b9f5762000b9e62000b3e565b5b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f62000bde8262000590565b915062000beb8362000590565b925082820262000bfb8162000590565b9150828204841483151762000c155762000c1462000b3e565b5b5092915050565b5f62000c288262000590565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820362000c5d5762000c5c62000b3e565b5b600182019050919050565b7f4469766973696f6e206279207a65726f000000000000000000000000000000005f82015250565b5f62000c9e60108362000a68565b915062000cab8262000c68565b602082019050919050565b5f6020820190508181035f83015262000ccf8162000c90565b9050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f62000d0f8262000590565b915062000d1c8362000590565b92508262000d2f5762000d2e62000cd6565b5b828204905092915050565b6170bb8062000d485f395ff3fe608060405260043610610338575f3560e01c806377e7fca2116101aa578063c21be6ae116100f6578063dad4ae3711610094578063e1f1c4a71161006e578063e1f1c4a714610ca5578063e8d5940d14610ccf578063ead6252014610cf7578063f59e4f6514610d3357610349565b8063dad4ae3714610c03578063de8fa43114610c3f578063e15b3f5f14610c6957610349565b8063cafa4ffa116100d0578063cafa4ffa14610b4b578063cc18494814610b75578063d118a53f14610bb1578063d7841a1c14610bdb57610349565b8063c21be6ae14610aa9578063c45a015514610ae5578063ca22431314610b0f57610349565b8063873010d911610163578063918f96871161013d578063918f9687146109e1578063981a63dc14610a09578063b801603514610a45578063b99ef1fa14610a6d57610349565b8063873010d91461095157806387563ec11461098d5780638da5cb5b146109b757610349565b806377e7fca2146108355780637a3c22eb1461085f5780637b0a7e33146108875780637c59dd5f146108c35780637ed628bb146108ff578063804d74701461092957610349565b806339bfeae31161028457806357a32534116102225780636a146024116101fc5780636a1460241461078f5780636bd39c52146107b95780636cc6837e146107e35780636d2687c0146107f957610349565b806357a325341461071557806360a1da831461075157806362d73eb81461077957610349565b80634635fd681161025e5780634635fd681461064b57806351599b151461068757806353055481146106c35780635744426e146106ff57610349565b806339bfeae3146105ab578063404880d9146105e7578063441179e51461062357610349565b806321670f22116102f15780633477ee2e116102cb5780633477ee2e146104e3578063363454ee1461051f578063372c3e7c1461055b57806338eccabd1461058357610349565b806321670f221461046157806328c317d71461047d57806333d6e65f146104b957610349565b806302d05d3f1461035557806306a49fce1461037f57806306fdde03146103a957806312feb905146103d35780631821fcab146103fd5780631a2f4ee51461043957610349565b36610349576103475f34610d5d565b005b6103535f34610d5d565b005b348015610360575f80fd5b50610369611149565b604051610376919061509c565b60405180910390f35b34801561038a575f80fd5b5061039361116e565b6040516103a091906151fa565b60405180910390f35b3480156103b4575f80fd5b506103bd611242565b6040516103ca9190615262565b60405180910390f35b3480156103de575f80fd5b506103e76112ce565b6040516103f491906151fa565b60405180910390f35b348015610408575f80fd5b50610423600480360381019061041e91906153bf565b6113a2565b604051610430919061541e565b60405180910390f35b348015610444575f80fd5b5061045f600480360381019061045a9190615461565b6113cf565b005b61047b600480360381019061047691906154c9565b610d5d565b005b348015610488575f80fd5b506104a3600480360381019061049e91906153bf565b6114f8565b6040516104b091906155be565b60405180910390f35b3480156104c4575f80fd5b506104cd6115a1565b6040516104da919061541e565b60405180910390f35b3480156104ee575f80fd5b50610509600480360381019061050491906155de565b6115a7565b6040516105169190615262565b60405180910390f35b34801561052a575f80fd5b50610545600480360381019061054091906153bf565b61164d565b6040516105529190615623565b60405180910390f35b348015610566575f80fd5b50610581600480360381019061057c91906155de565b611682565b005b34801561058e575f80fd5b506105a960048036038101906105a491906153bf565b611723565b005b3480156105b6575f80fd5b506105d160048036038101906105cc91906153bf565b61189c565b6040516105de9190615623565b60405180910390f35b3480156105f2575f80fd5b5061060d600480360381019061060891906153bf565b6118d1565b60405161061a9190615623565b60405180910390f35b34801561062e575f80fd5b506106496004803603810190610644919061563c565b611906565b005b348015610656575f80fd5b50610671600480360381019061066c91906155de565b611c2b565b60405161067e9190615262565b60405180910390f35b348015610692575f80fd5b506106ad60048036038101906106a891906153bf565b611cd1565b6040516106ba9190615623565b60405180910390f35b3480156106ce575f80fd5b506106e960048036038101906106e49190615696565b611d06565b6040516106f6919061541e565b60405180910390f35b34801561070a575f80fd5b50610713611d1b565b005b348015610720575f80fd5b5061073b600480360381019061073691906153bf565b611e3f565b604051610748919061541e565b60405180910390f35b34801561075c575f80fd5b50610777600480360381019061077291906156c1565b611e6c565b005b348015610784575f80fd5b5061078d612201565b005b34801561079a575f80fd5b506107a361245e565b6040516107b0919061541e565b60405180910390f35b3480156107c4575f80fd5b506107cd61246a565b6040516107da919061541e565b60405180910390f35b3480156107ee575f80fd5b506107f7612470565b005b348015610804575f80fd5b5061081f600480360381019061081a91906155de565b612987565b60405161082c9190615262565b60405180910390f35b348015610840575f80fd5b50610849612a2d565b604051610856919061541e565b60405180910390f35b34801561086a575f80fd5b50610885600480360381019061088091906153bf565b612a33565b005b348015610892575f80fd5b506108ad60048036038101906108a891906155de565b612c87565b6040516108ba91906151fa565b60405180910390f35b3480156108ce575f80fd5b506108e960048036038101906108e491906153bf565b612d6c565b6040516108f69190615623565b60405180910390f35b34801561090a575f80fd5b50610913612da1565b6040516109209190615623565b60405180910390f35b348015610934575f80fd5b5061094f600480360381019061094a91906157fd565b612db3565b005b34801561095c575f80fd5b50610977600480360381019061097291906155de565b612fac565b604051610984919061541e565b60405180910390f35b348015610998575f80fd5b506109a1612fcc565b6040516109ae919061541e565b60405180910390f35b3480156109c2575f80fd5b506109cb612fd2565b6040516109d8919061509c565b60405180910390f35b3480156109ec575f80fd5b50610a076004803603810190610a0291906153bf565b612ff7565b005b348015610a14575f80fd5b50610a2f6004803603810190610a2a91906153bf565b6131ab565b604051610a3c9190615262565b60405180910390f35b348015610a50575f80fd5b50610a6b6004803603810190610a669190615904565b61325e565b005b348015610a78575f80fd5b50610a936004803603810190610a8e91906153bf565b61368c565b604051610aa0919061541e565b60405180910390f35b348015610ab4575f80fd5b50610acf6004803603810190610aca91906153bf565b6136b9565b604051610adc919061509c565b60405180910390f35b348015610af0575f80fd5b50610af9613701565b604051610b06919061509c565b60405180910390f35b348015610b1a575f80fd5b50610b356004803603810190610b3091906156c1565b613726565b604051610b42919061541e565b60405180910390f35b348015610b56575f80fd5b50610b5f61375e565b604051610b6c919061541e565b60405180910390f35b348015610b80575f80fd5b50610b9b6004803603810190610b96919061563c565b613764565b604051610ba8919061509c565b60405180910390f35b348015610bbc575f80fd5b50610bc56137c4565b604051610bd29190615a31565b60405180910390f35b348015610be6575f80fd5b50610c016004803603810190610bfc91906155de565b61381a565b005b348015610c0e575f80fd5b50610c296004803603810190610c2491906153bf565b613947565b604051610c369190615623565b60405180910390f35b348015610c4a575f80fd5b50610c5361397c565b604051610c60919061541e565b60405180910390f35b348015610c74575f80fd5b50610c8f6004803603810190610c8a91906153bf565b613988565b604051610c9c919061541e565b60405180910390f35b348015610cb0575f80fd5b50610cb96139b5565b604051610cc6919061541e565b60405180910390f35b348015610cda575f80fd5b50610cf56004803603810190610cf09190615a51565b6139bb565b005b348015610d02575f80fd5b50610d1d6004803603810190610d189190615461565b613ca9565b604051610d2a9190615262565b60405180910390f35b348015610d3e575f80fd5b50610d47613d5a565b604051610d549190615262565b60405180910390f35b610d65613de6565b5f8034118015610da057505f73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b90505f8115610e18573492503373ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff167f37de26b9f29dba736fb8291dad9ace7d2f6dc76e3e5faaeca097145b5298f94b5f86604051610e0b929190615ac7565b60405180910390a3610f8a565b8390505f600d5f8673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f20548273ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401610e93919061509c565b602060405180830381865afa158015610eae573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ed29190615b02565b610edc9190615b5a565b905083811015610f21576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f1890615bd7565b60405180910390fd5b3373ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff167f37de26b9f29dba736fb8291dad9ace7d2f6dc76e3e5faaeca097145b5298f94b8787604051610f80929190615ac7565b60405180910390a3505b5f610f9a84600e54612710613e2a565b90505f8185610fa99190615b5a565b90505f8083118015610fbf57505f601080549050115b15610fde57610fd087848787613e8d565b81610fdb9190615bf5565b90505b5f82118015610fee57505f601954115b1561100d57610fff87838787613fb6565b8161100a9190615bf5565b90505b3073ffffffffffffffffffffffffffffffffffffffff167fd83308e9158842b2115ec5e6f6395db42fff24e4b5506ef42fe33854fafad655878388611087576040518060400160405280600581526020017f45524332300000000000000000000000000000000000000000000000000000008152506110be565b6040518060400160405280600381526020017f45544800000000000000000000000000000000000000000000000000000000008152505b6040516110cd93929190615c28565b60405180910390a23073ffffffffffffffffffffffffffffffffffffffff167fc2d2b959adca67349f750fed9ef9eaefbec59f24fa563c7fa410157130395c4060018761111a578961111c565b5f5b89855f604051611130959493929190615d96565b60405180910390a25050505050611145614184565b5050565b60045f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6060601b805480602002602001604051908101604052809291908181526020015f905b82821015611239578382905f5260205f200180546111ae90615c91565b80601f01602080910402602001604051908101604052809291908181526020018280546111da90615c91565b80156112255780601f106111fc57610100808354040283529160200191611225565b820191905f5260205f20905b81548152906001019060200180831161120857829003601f168201915b505050505081526020019060010190611191565b50505050905090565b6001805461124f90615c91565b80601f016020809104026020016040519081016040528092919081815260200182805461127b90615c91565b80156112c65780601f1061129d576101008083540402835291602001916112c6565b820191905f5260205f20905b8154815290600101906020018083116112a957829003601f168201915b505050505081565b60606010805480602002602001604051908101604052809291908181526020015f905b82821015611399578382905f5260205f2001805461130e90615c91565b80601f016020809104026020016040519081016040528092919081815260200182805461133a90615c91565b80156113855780601f1061135c57610100808354040283529160200191611385565b820191905f5260205f20905b81548152906001019060200180831161136857829003601f168201915b5050505050815260200190600101906112f1565b50505050905090565b6016818051602081018201805184825260208301602085012081835280955050505050505f915090505481565b60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461145e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161145590615e38565b60405180910390fd5b612710818361146d9190615bf5565b146114ad576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114a490615ea0565b60405180910390fd5b81600e8190555080600f819055507f29dd4a83e71eab2a472a8bb7a7bb9467395098acb48b07c8d9ea7294de0ba0ae82826040516114ec929190615ebe565b60405180910390a15050565b6060600c8260405161150a9190615f1f565b908152602001604051809103902080548060200260200160405190810160405280929190818152602001828054801561159557602002820191905f5260205f20905b815f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001906001019080831161154c575b50505050509050919050565b60145481565b601b81815481106115b6575f80fd5b905f5260205f20015f9150905080546115ce90615c91565b80601f01602080910402602001604051908101604052809291908181526020018280546115fa90615c91565b80156116455780601f1061161c57610100808354040283529160200191611645565b820191905f5260205f20905b81548152906001019060200180831161162857829003601f168201915b505050505081565b6008818051602081018201805184825260208301602085012081835280955050505050505f915054906101000a900460ff1681565b60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611711576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161170890615e38565b60405180910390fd5b8060148190555061172061418d565b50565b60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146117b2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016117a990615e38565b60405180910390fd5b6017816040516117c29190615f1f565b90815260200160405180910390205f9054906101000a900460ff1661181c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161181390615f7f565b60405180910390fd5b611825816142ab565b5f6017826040516118369190615f1f565b90815260200160405180910390205f6101000a81548160ff02191690831515021790555061186261418d565b7fe6db474363a3116f4cf525fc0d78d9dd53e214383db31efef8368f08c4bf7991816040516118919190615262565b60405180910390a150565b601e818051602081018201805184825260208301602085012081835280955050505050505f915054906101000a900460ff1681565b6009818051602081018201805184825260208301602085012081835280955050505050505f915054906101000a900460ff1681565b60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611995576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161198c90615e38565b60405180910390fd5b6009826040516119a59190615f1f565b90815260200160405180910390205f9054906101000a900460ff166119ff576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016119f690615fe7565b60405180910390fd5b601454811115611a44576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611a3b9061604f565b60405180910390fd5b5f601783604051611a559190615f1f565b90815260200160405180910390205f9054906101000a900460ff16611a9a577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff611aba565b601683604051611aaa9190615f1f565b9081526020016040518091039020545b9050601783604051611acc9190615f1f565b90815260200160405180910390205f9054906101000a900460ff1615611af657611af5836142ab565b5b81601684604051611b079190615f1f565b90815260200160405180910390208190555060155f8381526020019081526020015f2083908060018154018082558091505060019003905f5260205f20015f909190919091509081611b5991906161ef565b506001601784604051611b6c9190615f1f565b90815260200160405180910390205f6101000a81548160ff021916908315150217905550611b9861418d565b7f9bca84993827a6bd2bc824f45db9e0ae931cf1f7b1706b7c735ba0102300b4ca8383604051611bc99291906162be565b60405180910390a13073ffffffffffffffffffffffffffffffffffffffff167f7d482c93a88a92e4d27ba697265785162f607bc0ac6c55b868232b3ba3fbb63d6001858486604051611c1e94939291906162ec565b60405180910390a2505050565b60068181548110611c3a575f80fd5b905f5260205f20015f915090508054611c5290615c91565b80601f0160208091040260200160405190810160405280929190818152602001828054611c7e90615c91565b8015611cc95780601f10611ca057610100808354040283529160200191611cc9565b820191905f5260205f20905b815481529060010190602001808311611cac57829003601f168201915b505050505081565b601c818051602081018201805184825260208301602085012081835280955050505050505f915054906101000a900460ff1681565b600d602052805f5260405f205f915090505481565b60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611daa576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611da190615e38565b60405180910390fd5b601a5f9054906101000a900460ff16611df8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611def90616387565b60405180910390fd5b5f601a5f6101000a81548160ff0219169083151502179055507f990bb31515adefe5ecd88a4dca3e9772b32d484c81e22cae38d5482e0d9f35e460405160405180910390a1565b600a818051602081018201805184825260208301602085012081835280955050505050505f915090505481565b60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611efb576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ef290615e38565b60405180910390fd5b611f03613de6565b600882604051611f139190615f1f565b90815260200160405180910390205f9054906101000a900460ff1615611f6e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611f65906163ef565b60405180910390fd5b5f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603611fdc576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611fd390616457565b60405180910390fd5b600982604051611fec9190615f1f565b90815260200160405180910390205f9054906101000a900460ff16612046576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161203d906164bf565b60405180910390fd5b5f600a836040516120579190615f1f565b9081526020016040518091039020549050600160088460405161207a9190615f1f565b90815260200160405180910390205f6101000a81548160ff0219169083151502179055505f73ffffffffffffffffffffffffffffffffffffffff166007846040516120c59190615f1f565b90815260200160405180910390205f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff160361216b578160078460405161211f9190615f1f565b90815260200160405180910390205f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b61217583836143c9565b61217f83836144c5565b5f8111156121f4578173ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff167f605614956ef211f270ab0b08a13dd69698dc38d70e20899e1051ae2e1ae6cd5b6001865f866040516121eb94939291906164dd565b60405180910390a35b506121fd614184565b5050565b60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614612290576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161228790615e38565b60405180910390fd5b5f5b601b80549050811015612340575f601d601b83815481106122b6576122b561652e565b5b905f5260205f20016040516122cb91906165db565b9081526020016040518091039020819055505f601c601b83815481106122f4576122f361652e565b5b905f5260205f200160405161230991906165db565b90815260200160405180910390205f6101000a81548160ff0219169083151502179055508080612338906165f1565b915050612292565b50601b5f61234e9190614f5b565b5f5b600680549050811015612415575f601e600683815481106123745761237361652e565b5b905f5260205f200160405161238991906165db565b90815260200160405180910390205f6101000a81548160ff02191690831515021790555060405180602001604052805f815250601f600683815481106123d2576123d161652e565b5b905f5260205f20016040516123e791906165db565b9081526020016040518091039020908161240191906161ef565b50808061240d906165f1565b915050612350565b506001601a5f6101000a81548160ff0219169083151502179055507fc475c26aa25ed8e85a7faa790e5f63b5d7ee1025f12821f4c9bfddd36ab4d11260405160405180910390a1565b670de0b6b3a764000081565b600e5481565b60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146124ff576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016124f690615e38565b60405180910390fd5b601a5f9054906101000a900460ff1661254d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161254490616387565b60405180910390fd5b5f601b8054905011612594576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161258b90616682565b60405180910390fd5b5f601b5f815481106125a9576125a861652e565b5b905f5260205f200180546125bc90615c91565b80601f01602080910402602001604051908101604052809291908181526020018280546125e890615c91565b80156126335780601f1061260a57610100808354040283529160200191612633565b820191905f5260205f20905b81548152906001019060200180831161261657829003601f168201915b505050505090505f601d601b5f815481106126515761265061652e565b5b905f5260205f200160405161266691906165db565b90815260200160405180910390205490505f600190505b601b805490508110156127c05781601d601b83815481106126a1576126a061652e565b5b905f5260205f20016040516126b691906165db565b90815260200160405180910390205411156127ad57601d601b82815481106126e1576126e061652e565b5b905f5260205f20016040516126f691906165db565b9081526020016040518091039020549150601b818154811061271b5761271a61652e565b5b905f5260205f2001805461272e90615c91565b80601f016020809104026020016040519081016040528092919081815260200182805461275a90615c91565b80156127a55780601f1061277c576101008083540402835291602001916127a5565b820191905f5260205f20905b81548152906001019060200180831161278857829003601f168201915b505050505092505b80806127b8906165f1565b91505061267d565b505f6007836040516127d29190615f1f565b90815260200160405180910390205f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690505f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603612870576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161286790616710565b60405180910390fd5b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508160035f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505f601a5f6101000a81548160ff0219169083151502179055507f5e99cd5235d5c8c4f0f8dc2626c83130cf843047e4ecbe4c111076e2b31a0d52848460405161291f9291906162be565b60405180910390a18173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a350505050565b60108181548110612996575f80fd5b905f5260205f20015f9150905080546129ae90615c91565b80601f01602080910402602001604051908101604052809291908181526020018280546129da90615c91565b8015612a255780601f106129fc57610100808354040283529160200191612a25565b820191905f5260205f20905b815481529060010190602001808311612a0857829003601f168201915b505050505081565b600f5481565b60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614612ac2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612ab990615e38565b60405180910390fd5b601a5f9054906101000a900460ff16612b10576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612b0790616387565b60405180910390fd5b600981604051612b209190615f1f565b90815260200160405180910390205f9054906101000a900460ff16612b7a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612b7190616778565b60405180910390fd5b601c81604051612b8a9190615f1f565b90815260200160405180910390205f9054906101000a900460ff1615612be5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612bdc906167e0565b60405180910390fd5b601b81908060018154018082558091505060019003905f5260205f20015f909190919091509081612c1691906161ef565b506001601c82604051612c299190615f1f565b90815260200160405180910390205f6101000a81548160ff0219169083151502179055507f134c877b5bd4770ffc56867fc5d2c549dd813a5db276d378f8d855a04fc7aa1d81604051612c7c9190615262565b60405180910390a150565b606060155f8381526020019081526020015f20805480602002602001604051908101604052809291908181526020015f905b82821015612d61578382905f5260205f20018054612cd690615c91565b80601f0160208091040260200160405190810160405280929190818152602001828054612d0290615c91565b8015612d4d5780601f10612d2457610100808354040283529160200191612d4d565b820191905f5260205f20905b815481529060010190602001808311612d3057829003601f168201915b505050505081526020019060010190612cb9565b505050509050919050565b6011818051602081018201805184825260208301602085012081835280955050505050505f915054906101000a900460ff1681565b601a5f9054906101000a900460ff1681565b60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614612e42576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612e3990615e38565b60405180910390fd5b5f5b8151811015612fa8575f828281518110612e6157612e6061652e565b5b60200260200101519050600981604051612e7b9190615f1f565b90815260200160405180910390205f9054906101000a900460ff1615612ea15750612f95565b6001600982604051612eb39190615f1f565b90815260200160405180910390205f6101000a81548160ff021916908315150217905550600681908060018154018082558091505060019003905f5260205f20015f909190919091509081612f0891906161ef565b507fdfaa3c24567cbffbf024ddfd8dfca7a224b307e94b0df5437facad0f2fea2f9b81604051612f389190615262565b60405180910390a13073ffffffffffffffffffffffffffffffffffffffff167f954917c11fc57299ff064c483b4113756221231fcea3a1a3aa54ebd605a9c1e860018333604051612f8b939291906167fe565b60405180910390a2505b8080612fa0906165f1565b915050612e44565b5050565b60188181548110612fbb575f80fd5b905f5260205f20015f915090505481565b60135481565b60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614613086576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161307d90615e38565b60405180910390fd5b6009816040516130969190615f1f565b90815260200160405180910390205f9054906101000a900460ff166131a85760016009826040516130c79190615f1f565b90815260200160405180910390205f6101000a81548160ff021916908315150217905550600681908060018154018082558091505060019003905f5260205f20015f90919091909150908161311c91906161ef565b507fdfaa3c24567cbffbf024ddfd8dfca7a224b307e94b0df5437facad0f2fea2f9b8160405161314c9190615262565b60405180910390a13073ffffffffffffffffffffffffffffffffffffffff167f954917c11fc57299ff064c483b4113756221231fcea3a1a3aa54ebd605a9c1e86001833360405161319f939291906167fe565b60405180910390a25b50565b601f818051602081018201805184825260208301602085012081835280955050505050505f9150905080546131df90615c91565b80601f016020809104026020016040519081016040528092919081815260200182805461320b90615c91565b80156132565780601f1061322d57610100808354040283529160200191613256565b820191905f5260205f20905b81548152906001019060200180831161323957829003601f168201915b505050505081565b60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146132ed576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016132e490615e38565b60405180910390fd5b8051825114613331576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016133289061688b565b60405180910390fd5b5f5b6010805490508110156133e1575f6012601083815481106133575761335661652e565b5b905f5260205f200160405161336c91906165db565b9081526020016040518091039020819055505f6011601083815481106133955761339461652e565b5b905f5260205f20016040516133aa91906165db565b90815260200160405180910390205f6101000a81548160ff02191690831515021790555080806133d9906165f1565b915050613333565b5060105f6133ef9190614f5b565b5f805b83518110156136095760098482815181106134105761340f61652e565b5b60200260200101516040516134259190615f1f565b90815260200160405180910390205f9054906101000a900460ff1661347f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613476906168f3565b60405180910390fd5b5f8382815181106134935761349261652e565b5b6020026020010151116134db576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016134d29061695b565b60405180910390fd5b60108482815181106134f0576134ef61652e565b5b6020026020010151908060018154018082558091505060019003905f5260205f20015f90919091909150908161352691906161ef565b506001601185838151811061353e5761353d61652e565b5b60200260200101516040516135539190615f1f565b90815260200160405180910390205f6101000a81548160ff02191690831515021790555082818151811061358a5761358961652e565b5b602002602001015160128583815181106135a7576135a661652e565b5b60200260200101516040516135bc9190615f1f565b9081526020016040518091039020819055508281815181106135e1576135e061652e565b5b6020026020010151826135f49190615bf5565b91508080613601906165f1565b9150506133f2565b50612710811461364e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613645906169c3565b60405180910390fd5b7f7749ddba77d660c1351ff548a0bf5b09743d6ad44914e3cb9a29a1f805fb09fe838360405161367f9291906169e1565b60405180910390a1505050565b601d818051602081018201805184825260208301602085012081835280955050505050505f915090505481565b6007818051602081018201805184825260208301602085012081835280955050505050505f915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60055f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600b82805160208101820180518482526020830160208501208183528095505050505050602052805f5260405f205f91509150505481565b60195481565b600c828051602081018201805184825260208301602085012081835280955050505050508181548110613795575f80fd5b905f5260205f20015f915091509054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6060601880548060200260200160405190810160405280929190818152602001828054801561381057602002820191905f5260205f20905b8154815260200190600101908083116137fc575b5050505050905090565b60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146138a9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016138a090615e38565b60405180910390fd5b5f811180156138bf5750670de0b6b3a764000081105b6138fe576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016138f590616a60565b60405180910390fd5b8060138190555061390d61418d565b7f5fad7fda6b8fb652ca59780d340772fed3852ba698b3a4cd40ebc117b8ec57508160405161393c919061541e565b60405180910390a150565b6017818051602081018201805184825260208301602085012081835280955050505050505f915054906101000a900460ff1681565b5f600680549050905090565b6012818051602081018201805184825260208301602085012081835280955050505050505f915090505481565b61271081565b60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614613a4a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613a4190615e38565b60405180910390fd5b601a5f9054906101000a900460ff16613a98576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613a8f90616387565b60405180910390fd5b600982604051613aa89190615f1f565b90815260200160405180910390205f9054906101000a900460ff16613b02576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613af990616ac8565b60405180910390fd5b601c81604051613b129190615f1f565b90815260200160405180910390205f9054906101000a900460ff16613b6c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613b6390616b30565b60405180910390fd5b601e82604051613b7c9190615f1f565b90815260200160405180910390205f9054906101000a900460ff1615613bd7576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613bce90616b98565b60405180910390fd5b6001601e83604051613be99190615f1f565b90815260200160405180910390205f6101000a81548160ff02191690831515021790555080601f83604051613c1e9190615f1f565b90815260200160405180910390209081613c3891906161ef565b50601d81604051613c499190615f1f565b90815260200160405180910390205f815480929190613c67906165f1565b91905055507f137ad23732468494166ec34d1367743690ffa17f6ceac8429cba8fc35d088b6e8282604051613c9d929190616bb6565b60405180910390a15050565b6015602052815f5260405f208181548110613cc2575f80fd5b905f5260205f20015f91509150508054613cdb90615c91565b80601f0160208091040260200160405190810160405280929190818152602001828054613d0790615c91565b8015613d525780601f10613d2957610100808354040283529160200191613d52565b820191905f5260205f20905b815481529060010190602001808311613d3557829003601f168201915b505050505081565b60028054613d6790615c91565b80601f0160208091040260200160405190810160405280929190818152602001828054613d9390615c91565b8015613dde5780601f10613db557610100808354040283529160200191613dde565b820191905f5260205f20905b815481529060010190602001808311613dc157829003601f168201915b505050505081565b60025f5403613e21576040517f3ee5aeb500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60025f81905550565b5f808211613e6d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613e6490616c35565b60405180910390fd5b818385613e7a9190616c53565b613e849190616cc1565b90509392505050565b5f805f90505b601080549050811015613fad575f60108281548110613eb557613eb461652e565b5b905f5260205f20018054613ec890615c91565b80601f0160208091040260200160405190810160405280929190818152602001828054613ef490615c91565b8015613f3f5780601f10613f1657610100808354040283529160200191613f3f565b820191905f5260205f20905b815481529060010190602001808311613f2257829003601f168201915b505050505090505f613f7287601284604051613f5b9190615f1f565b908152602001604051809103902054612710613e2a565b90505f811115613f9857613f898289838989614737565b8380613f94906165f1565b9450505b50508080613fa5906165f1565b915050613e93565b50949350505050565b5f805f90505b601454811161417b575f60155f8381526020019081526020015f208054905090505f8103613fea5750614168565b5f60188381548110613fff57613ffe61652e565b5b905f5260205f200154826140139190616c53565b90505f6140238883601954613e2a565b90505f83826140329190616cc1565b90505f805b85811015614161575f60018761404d9190615b5a565b820361406657828561405f9190615b5a565b9050614078565b83905083836140759190615bf5565b92505b5f81111561414d5761413e60155f8a81526020019081526020015f2083815481106140a6576140a561652e565b5b905f5260205f200180546140b990615c91565b80601f01602080910402602001604051908101604052809291908181526020018280546140e590615c91565b80156141305780601f1061410757610100808354040283529160200191614130565b820191905f5260205f20905b81548152906001019060200180831161411357829003601f168201915b50505050508e838e8e614737565b8880614149906165f1565b9950505b508080614159906165f1565b915050614037565b5050505050505b8080614173906165f1565b915050613fbc565b50949350505050565b60015f81905550565b60185f61419a9190614f79565b60016014546141a99190615bf5565b67ffffffffffffffff8111156141c2576141c161529b565b5b6040519080825280602002602001820160405280156141f05781602001602082028036833780820191505090505b5060189080519060200190614206929190614f97565b505f6019819055505f670de0b6b3a764000090505f5b60145481116142a757816018828154811061423a5761423961652e565b5b905f5260205f2001819055508160155f8381526020019081526020015f20805490506142669190616c53565b60195f8282546142769190615bf5565b9250508190555061429282601354670de0b6b3a7640000613e2a565b9150808061429f906165f1565b91505061421c565b5050565b5f6016826040516142bc9190615f1f565b90815260200160405180910390205490505f60155f8381526020019081526020015f2090505f5b81805490508110156143c357838051906020012082828154811061430a5761430961652e565b5b905f5260205f200160405161431f9190616d8d565b6040518091039020036143b057816001838054905061433e9190615b5a565b8154811061434f5761434e61652e565b5b905f5260205f200182828154811061436a5761436961652e565b5b905f5260205f2001908161437e9190616dca565b50818054806143905761438f616eaf565b5b600190038181905f5260205f20015f6143a99190614fe2565b90556143c3565b80806143bb906165f1565b9150506142e3565b50505050565b5f600a836040516143da9190615f1f565b90815260200160405180910390205490505f8111156144c0575f600a846040516144049190615f1f565b9081526020016040518091039020819055505f8273ffffffffffffffffffffffffffffffffffffffff168260405161443b90616eff565b5f6040518083038185875af1925050503d805f8114614475576040519150601f19603f3d011682016040523d82523d5f602084013e61447a565b606091505b50509050806144be576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016144b590616f5d565b60405180910390fd5b505b505050565b5f600c836040516144d69190615f1f565b908152602001604051809103902080548060200260200160405190810160405280929190818152602001828054801561456157602002820191905f5260205f20905b815f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019060010190808311614518575b505050505090505f5b8151811015614731575f600b856040516145849190615f1f565b90815260200160405180910390205f8484815181106145a6576145a561652e565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205490505f81111561471d575f600b866040516146039190615f1f565b90815260200160405180910390205f8585815181106146255761462461652e565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f208190555080600d5f8585815181106146815761468061652e565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f8282546146d09190615b5a565b9250508190555061471c84828585815181106146ef576146ee61652e565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff16614e419092919063ffffffff16565b5b508080614729906165f1565b91505061456a565b50505050565b5f6007866040516147489190615f1f565b90815260200160405180910390205f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690505f8073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141580156147cb57505f8273ffffffffffffffffffffffffffffffffffffffff163b115b90506008876040516147dd9190615f1f565b90815260200160405180910390205f9054906101000a900460ff16801561483057505f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b15614a715783156148e9575f8273ffffffffffffffffffffffffffffffffffffffff168660405161486090616eff565b5f6040518083038185875af1925050503d805f811461489a576040519150601f19603f3d011682016040523d82523d5f602084013e61489f565b606091505b50509050806148e3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016148da90616fc5565b60405180910390fd5b50614915565b61491482868573ffffffffffffffffffffffffffffffffffffffff16614e419092919063ffffffff16565b5b8173ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff167f7d6a6b7452c2fec7981096e354fb3311f3f3b800ff27def1017b22cbff2751908784886149a6576040518060400160405280600581526020017f45524332300000000000000000000000000000000000000000000000000000008152506149dd565b6040518060400160405280600381526020017f45544800000000000000000000000000000000000000000000000000000000008152505b6040516149ec93929190616fe3565b60405180910390a38173ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff167f71e611184866cc19c5f49af6c856ce9bde5a13bcd197c7499b61ab410ac9439960018a88614a51578a614a53565b5f5b8a604051614a6494939291906164dd565b60405180910390a3614e38565b8315614ab05784600a88604051614a889190615f1f565b90815260200160405180910390205f828254614aa49190615bf5565b92505081905550614c50565b5f600b88604051614ac19190615f1f565b90815260200160405180910390205f8873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205403614b8d57600c87604051614b209190615f1f565b908152602001604051809103902086908060018154018082558091505060019003905f5260205f20015f9091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b84600b88604051614b9e9190615f1f565b90815260200160405180910390205f8873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f828254614bf59190615bf5565b9250508190555084600d5f8873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f828254614c489190615bf5565b925050819055505b5f73ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff167f7d6a6b7452c2fec7981096e354fb3311f3f3b800ff27def1017b22cbff275190875f88614ce1576040518060400160405280600c81526020017f53544f5245445f45524332300000000000000000000000000000000000000000815250614d18565b6040518060400160405280600a81526020017f53544f5245445f455448000000000000000000000000000000000000000000008152505b604051614d2793929190616fe3565b60405180910390a35f601188604051614d409190615f1f565b90815260200160405180910390205f9054906101000a900460ff16614d9a576040518060400160405280600481526020017f7a6f6e6500000000000000000000000000000000000000000000000000000000815250614dd1565b6040518060400160405280600a81526020017f70657263656e74616765000000000000000000000000000000000000000000008152505b90503073ffffffffffffffffffffffffffffffffffffffff167ff9700e8ac41cc506d3f79229bad9981619140b63838136cdb10ac6ba5f6976ab60018a88614e19578a614e1b565b5f5b8a86604051614e2e95949392919061701f565b60405180910390a2505b50505050505050565b614ebb838473ffffffffffffffffffffffffffffffffffffffff1663a9059cbb8585604051602401614e74929190615ac7565b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050614ec0565b505050565b5f8060205f8451602086015f885af180614edf576040513d5f823e3d81fd5b3d92505f519150505f8214614ef8576001811415614f13565b5f8473ffffffffffffffffffffffffffffffffffffffff163b145b15614f5557836040517f5274afe7000000000000000000000000000000000000000000000000000000008152600401614f4c919061509c565b60405180910390fd5b50505050565b5080545f8255905f5260205f2090810190614f76919061501f565b50565b5080545f8255905f5260205f2090810190614f949190615042565b50565b828054828255905f5260205f20908101928215614fd1579160200282015b82811115614fd0578251825591602001919060010190614fb5565b5b509050614fde9190615042565b5090565b508054614fee90615c91565b5f825580601f10614fff575061501c565b601f0160209004905f5260205f209081019061501b9190615042565b5b50565b5b8082111561503e575f81816150359190614fe2565b50600101615020565b5090565b5b80821115615059575f815f905550600101615043565b5090565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6150868261505d565b9050919050565b6150968161507c565b82525050565b5f6020820190506150af5f83018461508d565b92915050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b5f81519050919050565b5f82825260208201905092915050565b5f5b838110156151155780820151818401526020810190506150fa565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61513a826150de565b61514481856150e8565b93506151548185602086016150f8565b61515d81615120565b840191505092915050565b5f6151738383615130565b905092915050565b5f602082019050919050565b5f615191826150b5565b61519b81856150bf565b9350836020820285016151ad856150cf565b805f5b858110156151e857848403895281516151c98582615168565b94506151d48361517b565b925060208a019950506001810190506151b0565b50829750879550505050505092915050565b5f6020820190508181035f8301526152128184615187565b905092915050565b5f82825260208201905092915050565b5f615234826150de565b61523e818561521a565b935061524e8185602086016150f8565b61525781615120565b840191505092915050565b5f6020820190508181035f83015261527a818461522a565b905092915050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6152d182615120565b810181811067ffffffffffffffff821117156152f0576152ef61529b565b5b80604052505050565b5f615302615282565b905061530e82826152c8565b919050565b5f67ffffffffffffffff82111561532d5761532c61529b565b5b61533682615120565b9050602081019050919050565b828183375f83830152505050565b5f61536361535e84615313565b6152f9565b90508281526020810184848401111561537f5761537e615297565b5b61538a848285615343565b509392505050565b5f82601f8301126153a6576153a5615293565b5b81356153b6848260208601615351565b91505092915050565b5f602082840312156153d4576153d361528b565b5b5f82013567ffffffffffffffff8111156153f1576153f061528f565b5b6153fd84828501615392565b91505092915050565b5f819050919050565b61541881615406565b82525050565b5f6020820190506154315f83018461540f565b92915050565b61544081615406565b811461544a575f80fd5b50565b5f8135905061545b81615437565b92915050565b5f80604083850312156154775761547661528b565b5b5f6154848582860161544d565b92505060206154958582860161544d565b9150509250929050565b6154a88161507c565b81146154b2575f80fd5b50565b5f813590506154c38161549f565b92915050565b5f80604083850312156154df576154de61528b565b5b5f6154ec858286016154b5565b92505060206154fd8582860161544d565b9150509250929050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b6155398161507c565b82525050565b5f61554a8383615530565b60208301905092915050565b5f602082019050919050565b5f61556c82615507565b6155768185615511565b935061558183615521565b805f5b838110156155b1578151615598888261553f565b97506155a383615556565b925050600181019050615584565b5085935050505092915050565b5f6020820190508181035f8301526155d68184615562565b905092915050565b5f602082840312156155f3576155f261528b565b5b5f6156008482850161544d565b91505092915050565b5f8115159050919050565b61561d81615609565b82525050565b5f6020820190506156365f830184615614565b92915050565b5f80604083850312156156525761565161528b565b5b5f83013567ffffffffffffffff81111561566f5761566e61528f565b5b61567b85828601615392565b925050602061568c8582860161544d565b9150509250929050565b5f602082840312156156ab576156aa61528b565b5b5f6156b8848285016154b5565b91505092915050565b5f80604083850312156156d7576156d661528b565b5b5f83013567ffffffffffffffff8111156156f4576156f361528f565b5b61570085828601615392565b9250506020615711858286016154b5565b9150509250929050565b5f67ffffffffffffffff8211156157355761573461529b565b5b602082029050602081019050919050565b5f80fd5b5f61575c6157578461571b565b6152f9565b9050808382526020820190506020840283018581111561577f5761577e615746565b5b835b818110156157c657803567ffffffffffffffff8111156157a4576157a3615293565b5b8086016157b18982615392565b85526020850194505050602081019050615781565b5050509392505050565b5f82601f8301126157e4576157e3615293565b5b81356157f484826020860161574a565b91505092915050565b5f602082840312156158125761581161528b565b5b5f82013567ffffffffffffffff81111561582f5761582e61528f565b5b61583b848285016157d0565b91505092915050565b5f67ffffffffffffffff82111561585e5761585d61529b565b5b602082029050602081019050919050565b5f61588161587c84615844565b6152f9565b905080838252602082019050602084028301858111156158a4576158a3615746565b5b835b818110156158cd57806158b9888261544d565b8452602084019350506020810190506158a6565b5050509392505050565b5f82601f8301126158eb576158ea615293565b5b81356158fb84826020860161586f565b91505092915050565b5f806040838503121561591a5761591961528b565b5b5f83013567ffffffffffffffff8111156159375761593661528f565b5b615943858286016157d0565b925050602083013567ffffffffffffffff8111156159645761596361528f565b5b615970858286016158d7565b9150509250929050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b6159ac81615406565b82525050565b5f6159bd83836159a3565b60208301905092915050565b5f602082019050919050565b5f6159df8261597a565b6159e98185615984565b93506159f483615994565b805f5b83811015615a24578151615a0b88826159b2565b9750615a16836159c9565b9250506001810190506159f7565b5085935050505092915050565b5f6020820190508181035f830152615a4981846159d5565b905092915050565b5f8060408385031215615a6757615a6661528b565b5b5f83013567ffffffffffffffff811115615a8457615a8361528f565b5b615a9085828601615392565b925050602083013567ffffffffffffffff811115615ab157615ab061528f565b5b615abd85828601615392565b9150509250929050565b5f604082019050615ada5f83018561508d565b615ae7602083018461540f565b9392505050565b5f81519050615afc81615437565b92915050565b5f60208284031215615b1757615b1661528b565b5b5f615b2484828501615aee565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f615b6482615406565b9150615b6f83615406565b9250828203905081811115615b8757615b86615b2d565b5b92915050565b7f496e73756666696369656e7420746f6b656e2062616c616e63650000000000005f82015250565b5f615bc1601a8361521a565b9150615bcc82615b8d565b602082019050919050565b5f6020820190508181035f830152615bee81615bb5565b9050919050565b5f615bff82615406565b9150615c0a83615406565b9250828201905080821115615c2257615c21615b2d565b5b92915050565b5f606082019050615c3b5f83018661540f565b615c48602083018561540f565b8181036040830152615c5a818461522a565b9050949350505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f6002820490506001821680615ca857607f821691505b602082108103615cbb57615cba615c64565b5b50919050565b5f819050815f5260205f209050919050565b5f8154615cdf81615c91565b615ce9818661521a565b9450600182165f8114615d035760018114615d1957615d4b565b60ff198316865281151560200286019350615d4b565b615d2285615cc1565b5f5b83811015615d4357815481890152600182019150602081019050615d24565b808801955050505b50505092915050565b5f819050919050565b5f819050919050565b5f615d80615d7b615d7684615d54565b615d5d565b615406565b9050919050565b615d9081615d66565b82525050565b5f60a0820190508181035f830152615dae8188615cd3565b9050615dbd602083018761508d565b615dca604083018661540f565b615dd7606083018561540f565b615de46080830184615d87565b9695505050505050565b7f4f6e6c79206f776e6572000000000000000000000000000000000000000000005f82015250565b5f615e22600a8361521a565b9150615e2d82615dee565b602082019050919050565b5f6020820190508181035f830152615e4f81615e16565b9050919050565b7f4d7573742073756d20746f2031303030300000000000000000000000000000005f82015250565b5f615e8a60118361521a565b9150615e9582615e56565b602082019050919050565b5f6020820190508181035f830152615eb781615e7e565b9050919050565b5f604082019050615ed15f83018561540f565b615ede602083018461540f565b9392505050565b5f81905092915050565b5f615ef9826150de565b615f038185615ee5565b9350615f138185602086016150f8565b80840191505092915050565b5f615f2a8284615eef565b915081905092915050565b7f4e6f7420616e206578746572696f72206d656d626572000000000000000000005f82015250565b5f615f6960168361521a565b9150615f7482615f35565b602082019050919050565b5f6020820190508181035f830152615f9681615f5d565b9050919050565b7f4d75737420626520612062756e646c65206d656d6265720000000000000000005f82015250565b5f615fd160178361521a565b9150615fdc82615f9d565b602082019050919050565b5f6020820190508181035f830152615ffe81615fc5565b9050919050565b7f5a6f6e65206f7574206f662072616e67650000000000000000000000000000005f82015250565b5f61603960118361521a565b915061604482616005565b602082019050919050565b5f6020820190508181035f8301526160668161602d565b9050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f600883026160b77fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8261607c565b6160c1868361607c565b95508019841693508086168417925050509392505050565b5f6160f36160ee6160e984615406565b615d5d565b615406565b9050919050565b5f819050919050565b61610c836160d9565b616120616118826160fa565b848454616088565b825550505050565b5f90565b616134616128565b61613f818484616103565b505050565b5b81811015616162576161575f8261612c565b600181019050616145565b5050565b601f8211156161a75761617881615cc1565b6161818461606d565b81016020851015616190578190505b6161a461619c8561606d565b830182616144565b50505b505050565b5f82821c905092915050565b5f6161c75f19846008026161ac565b1980831691505092915050565b5f6161df83836161b8565b9150826002028217905092915050565b6161f8826150de565b67ffffffffffffffff8111156162115761621061529b565b5b61621b8254615c91565b616226828285616166565b5f60209050601f831160018114616257575f8415616245578287015190505b61624f85826161d4565b8655506162b6565b601f19841661626586615cc1565b5f5b8281101561628c57848901518255600182019150602085019450602081019050616267565b868310156162a957848901516162a5601f8916826161b8565b8355505b6001600288020188555050505b505050505050565b5f6040820190508181035f8301526162d6818561522a565b90506162e5602083018461540f565b9392505050565b5f6080820190508181035f8301526163048187615cd3565b90508181036020830152616318818661522a565b9050616327604083018561540f565b616334606083018461540f565b95945050505050565b7f4e6f2061637469766520656c656374696f6e00000000000000000000000000005f82015250565b5f61637160128361521a565b915061637c8261633d565b602082019050919050565b5f6020820190508181035f83015261639e81616365565b9050919050565b7f416c726561647920636c61696d656400000000000000000000000000000000005f82015250565b5f6163d9600f8361521a565b91506163e4826163a5565b602082019050919050565b5f6020820190508181035f830152616406816163cd565b9050919050565b7f496e76616c69642062656e6566696369617279000000000000000000000000005f82015250565b5f61644160138361521a565b915061644c8261640d565b602082019050919050565b5f6020820190508181035f83015261646e81616435565b9050919050565b7f4e6f742061206d656d62657200000000000000000000000000000000000000005f82015250565b5f6164a9600c8361521a565b91506164b482616475565b602082019050919050565b5f6020820190508181035f8301526164d68161649d565b9050919050565b5f6080820190508181035f8301526164f58187615cd3565b90508181036020830152616509818661522a565b9050616518604083018561508d565b616525606083018461540f565b95945050505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f815461656781615c91565b6165718186615ee5565b9450600182165f811461658b57600181146165a0576165d2565b60ff19831686528115158202860193506165d2565b6165a985615cc1565b5f5b838110156165ca578154818901526001820191506020810190506165ab565b838801955050505b50505092915050565b5f6165e6828461655b565b915081905092915050565b5f6165fb82615406565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820361662d5761662c615b2d565b5b600182019050919050565b7f4e6f2063616e64696461746573000000000000000000000000000000000000005f82015250565b5f61666c600d8361521a565b915061667782616638565b602082019050919050565b5f6020820190508181035f83015261669981616660565b9050919050565b7f57696e6e6572206d757374206861766520636c61696d656420746f20726563655f8201527f697665206f776e65727368697000000000000000000000000000000000000000602082015250565b5f6166fa602d8361521a565b9150616705826166a0565b604082019050919050565b5f6020820190508181035f830152616727816166ee565b9050919050565b7f4d7573742062652061206d656d626572000000000000000000000000000000005f82015250565b5f61676260108361521a565b915061676d8261672e565b602082019050919050565b5f6020820190508181035f83015261678f81616756565b9050919050565b7f416c726561647920612063616e646964617465000000000000000000000000005f82015250565b5f6167ca60138361521a565b91506167d582616796565b602082019050919050565b5f6020820190508181035f8301526167f7816167be565b9050919050565b5f6060820190508181035f8301526168168186615cd3565b9050818103602083015261682a818561522a565b9050616839604083018461508d565b949350505050565b7f4172726179206c656e677468206d69736d6174636800000000000000000000005f82015250565b5f61687560158361521a565b915061688082616841565b602082019050919050565b5f6020820190508181035f8301526168a281616869565b9050919050565b7f55736572206d75737420626520612062756e646c65206d656d626572000000005f82015250565b5f6168dd601c8361521a565b91506168e8826168a9565b602082019050919050565b5f6020820190508181035f83015261690a816168d1565b9050919050565b7f50657263656e74616765206d75737420626520706f73697469766500000000005f82015250565b5f616945601b8361521a565b915061695082616911565b602082019050919050565b5f6020820190508181035f83015261697281616939565b9050919050565b7f50657263656e7461676573206d7573742073756d20746f2031303030300000005f82015250565b5f6169ad601d8361521a565b91506169b882616979565b602082019050919050565b5f6020820190508181035f8301526169da816169a1565b9050919050565b5f6040820190508181035f8301526169f98185615187565b90508181036020830152616a0d81846159d5565b90509392505050565b7f53746565706e657373206d7573742062652030203c2073203c203165313800005f82015250565b5f616a4a601e8361521a565b9150616a5582616a16565b602082019050919050565b5f6020820190508181035f830152616a7781616a3e565b9050919050565b7f566f746572206d7573742062652061206d656d626572000000000000000000005f82015250565b5f616ab260168361521a565b9150616abd82616a7e565b602082019050919050565b5f6020820190508181035f830152616adf81616aa6565b9050919050565b7f4e6f7420612076616c69642063616e64696461746500000000000000000000005f82015250565b5f616b1a60158361521a565b9150616b2582616ae6565b602082019050919050565b5f6020820190508181035f830152616b4781616b0e565b9050919050565b7f416c726561647920766f746564000000000000000000000000000000000000005f82015250565b5f616b82600d8361521a565b9150616b8d82616b4e565b602082019050919050565b5f6020820190508181035f830152616baf81616b76565b9050919050565b5f6040820190508181035f830152616bce818561522a565b90508181036020830152616be2818461522a565b90509392505050565b7f4469766973696f6e206279207a65726f000000000000000000000000000000005f82015250565b5f616c1f60108361521a565b9150616c2a82616beb565b602082019050919050565b5f6020820190508181035f830152616c4c81616c13565b9050919050565b5f616c5d82615406565b9150616c6883615406565b9250828202616c7681615406565b91508282048414831517616c8d57616c8c615b2d565b5b5092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f616ccb82615406565b9150616cd683615406565b925082616ce657616ce5616c94565b5b828204905092915050565b5f81905092915050565b5f819050815f5260205f209050919050565b5f8154616d1981615c91565b616d238186616cf1565b9450600182165f8114616d3d5760018114616d5257616d84565b60ff1983168652811515820286019350616d84565b616d5b85616cfb565b5f5b83811015616d7c57815481890152600182019150602081019050616d5d565b838801955050505b50505092915050565b5f616d988284616d0d565b915081905092915050565b5f81549050616db181615c91565b9050919050565b5f819050815f5260205f209050919050565b818103616dd8575050616ead565b616de182616da3565b67ffffffffffffffff811115616dfa57616df961529b565b5b616e048254615c91565b616e0f828285616166565b5f601f831160018114616e3c575f8415616e2a578287015490505b616e3485826161d4565b865550616ea6565b601f198416616e4a87616db8565b9650616e5586615cc1565b5f5b82811015616e7c57848901548255600182019150600185019450602081019050616e57565b86831015616e995784890154616e95601f8916826161b8565b8355505b6001600288020188555050505b5050505050505b565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603160045260245ffd5b50565b5f616eea5f83616cf1565b9150616ef582616edc565b5f82019050919050565b5f616f0982616edf565b9150819050919050565b7f45544820636c61696d206661696c6564000000000000000000000000000000005f82015250565b5f616f4760108361521a565b9150616f5282616f13565b602082019050919050565b5f6020820190508181035f830152616f7481616f3b565b9050919050565b7f455448207472616e73666572206661696c6564000000000000000000000000005f82015250565b5f616faf60138361521a565b9150616fba82616f7b565b602082019050919050565b5f6020820190508181035f830152616fdc81616fa3565b9050919050565b5f606082019050616ff65f83018661540f565b6170036020830185615614565b8181036040830152617015818461522a565b9050949350505050565b5f60a0820190508181035f8301526170378188615cd3565b9050818103602083015261704b818761522a565b905061705a604083018661508d565b617067606083018561540f565b8181036080830152617079818461522a565b9050969550505050505056fea2646970667358221220e61ca743da8bf74312a4d4f6b348b3282428098da8234b281a8987056df9bb6364736f6c63430008140033"},XT=[{type:"function",name:"getFlavorAddress",inputs:[{name:"_name",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"knownflavors",inputs:[{name:"",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"listFlavors",inputs:[],outputs:[{name:"",type:"string[]",internalType:"string[]"}],stateMutability:"view"},{type:"function",name:"listHolons",inputs:[],outputs:[{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"listHolonsOf",inputs:[{name:"_address",type:"address",internalType:"address"}],outputs:[{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"managedFactory",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"newFlavor",inputs:[{name:"_flavorname",type:"string",internalType:"string"},{name:"_flavoraddress",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"newHolon",inputs:[{name:"_flavor",type:"string",internalType:"string"},{name:"_creatorUserId",type:"string",internalType:"string"},{name:"_name",type:"string",internalType:"string"},{name:"_parameter",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"function",name:"newHolonBundle",inputs:[{name:"_creatorUserId",type:"string",internalType:"string"},{name:"_name",type:"string",internalType:"string"},{name:"_parameter",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"function",name:"setFactories",inputs:[{name:"_managedFactory",type:"address",internalType:"address"},{name:"_zonedFactory",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setManagedFactory",inputs:[{name:"_managedFactory",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setZonedFactory",inputs:[{name:"_zonedFactory",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"toAddress",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"zonedFactory",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"event",name:"HolonCreated",inputs:[{name:"holonAddress",type:"address",indexed:!0,internalType:"address"},{name:"holonName",type:"string",indexed:!1,internalType:"string"},{name:"flavor",type:"string",indexed:!1,internalType:"string"},{name:"creator",type:"address",indexed:!0,internalType:"address"},{name:"timestamp",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"NewFlavor",inputs:[{name:"flavor",type:"address",indexed:!0,internalType:"address"},{name:"name",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"NewHolon",inputs:[{name:"name",type:"string",indexed:!1,internalType:"string"},{name:"addr",type:"address",indexed:!1,internalType:"address"}],anonymous:!1}],eS=[{type:"function",name:"createSplitter",inputs:[{name:"_creatorUserId",type:"string",internalType:"string"},{name:"_name",type:"string",internalType:"string"},{name:"_parameter",type:"uint256",internalType:"uint256"},{name:"_managedFactory",type:"address",internalType:"address"},{name:"_zonedFactory",type:"address",internalType:"address"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"function",name:"listHolons",inputs:[],outputs:[{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"listHolonsOf",inputs:[{name:"_address",type:"address",internalType:"address"}],outputs:[{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"managedFactory",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"newHolon",inputs:[{name:"_creatorUserId",type:"string",internalType:"string"},{name:"_name",type:"string",internalType:"string"},{name:"_parameter",type:"uint256",internalType:"uint256"},{name:"_managedFactory",type:"address",internalType:"address"},{name:"_zonedFactory",type:"address",internalType:"address"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"function",name:"setFactories",inputs:[{name:"_managedFactory",type:"address",internalType:"address"},{name:"_zonedFactory",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setManagedFactory",inputs:[{name:"_managedFactory",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setZonedFactory",inputs:[{name:"_zonedFactory",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"toAddress",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"zonedFactory",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"event",name:"NewHolon",inputs:[{name:"name",type:"string",indexed:!1,internalType:"string"},{name:"addr",type:"address",indexed:!1,internalType:"address"}],anonymous:!1}],tS=[{type:"constructor",inputs:[{name:"_botAddress",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"function",name:"botAddress",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"createManaged",inputs:[{name:"_creatorUserId",type:"string",internalType:"string"},{name:"_name",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"function",name:"listHolons",inputs:[],outputs:[{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"listHolonsOf",inputs:[{name:"_address",type:"address",internalType:"address"}],outputs:[{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"newHolon",inputs:[{name:"creatorUserId",type:"string",internalType:"string"},{name:"_name",type:"string",internalType:"string"},{name:"_parameter",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"function",name:"toAddress",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"event",name:"NewHolon",inputs:[{name:"name",type:"string",indexed:!1,internalType:"string"},{name:"addr",type:"address",indexed:!1,internalType:"address"}],anonymous:!1}],nS=[{type:"constructor",inputs:[{name:"_botAddress",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"function",name:"botAddress",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"createZoned",inputs:[{name:"_creatorUserId",type:"string",internalType:"string"},{name:"_name",type:"string",internalType:"string"},{name:"_parameter",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"function",name:"listHolons",inputs:[],outputs:[{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"listHolonsOf",inputs:[{name:"_address",type:"address",internalType:"address"}],outputs:[{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"newHolon",inputs:[{name:"creatorUserId",type:"string",internalType:"string"},{name:"_name",type:"string",internalType:"string"},{name:"_parameter",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"function",name:"toAddress",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"event",name:"NewHolon",inputs:[{name:"name",type:"string",indexed:!1,internalType:"string"},{name:"addr",type:"address",indexed:!1,internalType:"address"}],anonymous:!1}],rS=[{type:"function",name:"listHolons",inputs:[],outputs:[{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"listHolonsOf",inputs:[{name:"_address",type:"address",internalType:"address"}],outputs:[{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"newHolon",inputs:[{name:"creatorUserId",type:"string",internalType:"string"},{name:"_name",type:"string",internalType:"string"},{name:"_parameter",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"function",name:"toAddress",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"event",name:"NewHolon",inputs:[{name:"name",type:"string",indexed:!1,internalType:"string"},{name:"addr",type:"address",indexed:!1,internalType:"address"}],anonymous:!1}],iS=[{type:"function",name:"createBundle",inputs:[{name:"_creatorUserId",type:"string",internalType:"string"},{name:"_name",type:"string",internalType:"string"},{name:"_steepness",type:"uint256",internalType:"uint256"},{name:"_nzones",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"nonpayable"},{type:"function",name:"listHolons",inputs:[],outputs:[{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"listHolonsOf",inputs:[{name:"_address",type:"address",internalType:"address"}],outputs:[{name:"",type:"address[]",internalType:"address[]"}],stateMutability:"view"},{type:"function",name:"toAddress",inputs:[{name:"",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"event",name:"NewHolon",inputs:[{name:"name",type:"string",indexed:!1,internalType:"string"},{name:"addr",type:"address",indexed:!1,internalType:"address"}],anonymous:!1}],sS=[{type:"constructor",inputs:[{name:"initialSupply",type:"uint256",internalType:"uint256"}],stateMutability:"nonpayable"},{type:"function",name:"allowance",inputs:[{name:"owner",type:"address",internalType:"address"},{name:"spender",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"approve",inputs:[{name:"spender",type:"address",internalType:"address"},{name:"value",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"nonpayable"},{type:"function",name:"balanceOf",inputs:[{name:"account",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"decimals",inputs:[],outputs:[{name:"",type:"uint8",internalType:"uint8"}],stateMutability:"view"},{type:"function",name:"name",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"symbol",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"totalSupply",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"transfer",inputs:[{name:"to",type:"address",internalType:"address"},{name:"value",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"nonpayable"},{type:"function",name:"transferFrom",inputs:[{name:"from",type:"address",internalType:"address"},{name:"to",type:"address",internalType:"address"},{name:"value",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"nonpayable"},{type:"event",name:"Approval",inputs:[{name:"owner",type:"address",indexed:!0,internalType:"address"},{name:"spender",type:"address",indexed:!0,internalType:"address"},{name:"value",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"Transfer",inputs:[{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"value",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"error",name:"ERC20InsufficientAllowance",inputs:[{name:"spender",type:"address",internalType:"address"},{name:"allowance",type:"uint256",internalType:"uint256"},{name:"needed",type:"uint256",internalType:"uint256"}]},{type:"error",name:"ERC20InsufficientBalance",inputs:[{name:"sender",type:"address",internalType:"address"},{name:"balance",type:"uint256",internalType:"uint256"},{name:"needed",type:"uint256",internalType:"uint256"}]},{type:"error",name:"ERC20InvalidApprover",inputs:[{name:"approver",type:"address",internalType:"address"}]},{type:"error",name:"ERC20InvalidReceiver",inputs:[{name:"receiver",type:"address",internalType:"address"}]},{type:"error",name:"ERC20InvalidSender",inputs:[{name:"sender",type:"address",internalType:"address"}]},{type:"error",name:"ERC20InvalidSpender",inputs:[{name:"spender",type:"address",internalType:"address"}]}],aS={Splitter:JT,Managed:KT,Zoned:WT,Appreciative:YT,Bundle:ZT,Holons:XT,SplitterFactory:eS,ManagedFactory:tS,ZonedFactory:nS,AppreciativeFactory:rS,BundleFactory:iS,TestToken:sS};class oS{constructor(e){this.chainManager=e,this.deployedContracts={},this.ethers=null}async _loadEthers(){return this.ethers||(this.ethers=await Promise.resolve().then(()=>yU)),this.ethers}async deployAll(e={}){const t=await this._loadEthers(),n=this.chainManager.getSigner(),r=await n.getAddress(),i=e.botAddress||r,s=e.testTokenSupply||"1000000",a=!1!==e.deployTestToken,o=e.onProgress||(()=>{}),c={network:this.chainManager.networkName,chainId:this.chainManager.getChainId(),deployer:r,botAddress:i,timestamp:(new Date).toISOString(),contracts:{}};try{o({step:1,total:a?8:7,message:"Deploying ManagedFactory..."});const e=await this._deployContract(tS.abi,tS.bytecode,[i]);c.contracts.managedFactory=e.address,o({step:1,done:!0,address:e.address}),o({step:2,total:a?8:7,message:"Deploying ZonedFactory..."});const n=await this._deployContract(nS.abi,nS.bytecode,[i]);c.contracts.zonedFactory=n.address,o({step:2,done:!0,address:n.address}),o({step:3,total:a?8:7,message:"Deploying SplitterFactory..."});const r=await this._deployContract(eS.abi,eS.bytecode,[]);c.contracts.splitterFactory=r.address,o({step:3,done:!0,address:r.address}),o({step:4,total:a?8:7,message:"Deploying AppreciativeFactory..."});const A=await this._deployContract(rS.abi,rS.bytecode,[]);c.contracts.appreciativeFactory=A.address,o({step:4,done:!0,address:A.address}),o({step:5,total:a?8:7,message:"Deploying BundleFactory..."});const l=await this._deployContract(iS.abi,iS.bytecode,[]);c.contracts.bundleFactory=l.address,o({step:5,done:!0,address:l.address}),o({step:6,total:a?8:7,message:"Deploying Holons Registry..."});const f=await this._deployContract(XT.abi,XT.bytecode,[]);if(c.contracts.holons=f.address,o({step:6,done:!0,address:f.address}),o({step:7,total:a?8:7,message:"Configuring Holons Registry..."}),await f.contract.setFactories(e.address,n.address),await f.contract.newFlavor("Splitter",r.address),await f.contract.newFlavor("Managed",e.address),await f.contract.newFlavor("Zoned",n.address),await f.contract.newFlavor("Appreciative",A.address),await f.contract.newFlavor("Bundle",l.address),o({step:7,done:!0,message:"Registry configured"}),a){o({step:8,total:8,message:"Deploying TestToken..."});const e=t.parseEther(s),n=await this._deployContract(sS.abi,sS.bytecode,[e]);c.contracts.testToken=n.address,o({step:8,done:!0,address:n.address})}this.deployedContracts=c.contracts,c.explorerUrls={};for(const[t,i]of Object.entries(c.contracts)){const e=qT(c.network,i);e&&(c.explorerUrls[t]=e)}return c}catch(A){throw new Error(`Deployment failed: ${A.message}`)}}async deploySplitter(e,t,n=70,r={}){const i=this.chainManager.getSigner(),s=await i.getAddress(),a=r.creatorUserId||e,o=r.managedFactory||this.deployedContracts.managedFactory,c=r.zonedFactory||this.deployedContracts.zonedFactory;if(!o||!c)throw new Error("Factories not deployed. Run deployAll() first or provide factory addresses.");const A=await this._deployContract(JT.abi,JT.bytecode,[s,a,t,n,o,c]);return await A.contract.setContractSplit(n,100-n),await A.contract.createManagedContract(a,t,0),await A.contract.createZonedContract(a,t,6),{...A,holonId:e,type:"Splitter",splitPercentage:n}}async deployManaged(e,t={}){const n=this.chainManager.getSigner(),r=await n.getAddress(),i=t.botAddress||r;return{...await this._deployContract(KT.abi,KT.bytecode,[r,e,i]),type:"Managed"}}async deployZoned(e,t=6,n={}){const r=this.chainManager.getSigner(),i=await r.getAddress(),s=n.botAddress||i,a=n.creatorUserId||"creator";return{...await this._deployContract(WT.abi,WT.bytecode,[a,i,e,t,s]),type:"Zoned",nZones:t}}async deployAppreciative(e,t,n={}){const r=this.chainManager.getSigner(),i=await r.getAddress();return{...await this._deployContract(YT.abi,YT.bytecode,[e,t,i]),type:"Appreciative"}}async deployBundle(e,t,n=6,r={}){const i=await this._loadEthers(),s=this.chainManager.getSigner(),a=await s.getAddress(),o=r.creatorUserId||"creator",c=t||i.parseEther("0.5"),A=ZT.abi||ZT,l=ZT.bytecode;if(!l)throw new Error("Bundle bytecode not available. Please rebuild contracts.");return{...await this._deployContract(A,l,[a,o,e,c,n]),type:"Bundle",steepness:c,nZones:n,creatorUserId:o,name:e}}async deployBundleDirect(e,t,n={}){const r=n.steepness,i=n.nZones||6;return this.deployBundle(t,r,i,{creatorUserId:e,...n})}async deployTestToken(e="1000000"){const t=(await this._loadEthers()).parseEther(e);return{...await this._deployContract(sS.abi,sS.bytecode,[t]),type:"TestToken",initialSupply:e}}async createHolonBundle(e,t,n=70){if(!this.deployedContracts.holons)throw new Error("Holons registry not deployed. Run deployAll() first.");const r=await this.chainManager.getContract(this.deployedContracts.holons,XT.abi),i=await r.newHolonBundle(e,t,n),s=await i.wait(),a=s.logs.find(e=>{try{const t=r.interface.parseLog(e);return"NewHolon"===t?.name}catch{return!1}});return{address:a?r.interface.parseLog(a).args.addr:await r.toAddress(t),txHash:s.hash,name:t,creatorUserId:e}}async getContract(e,t){const n=aS[t];if(!n)throw new Error(`Unknown contract type: ${t}`);return this.chainManager.getContract(e,n.abi)}getDeployedAddresses(){return{...this.deployedContracts}}loadDeployedAddresses(e){this.deployedContracts={...e}}async _deployContract(e,t,n){const r=await this.chainManager.deployContract(e,t,n);return{contract:r.contract,address:r.address,txHash:r.txHash,explorerUrl:qT(this.chainManager.networkName,r.address)}}}class cS{constructor(e,t,n){this.contract=e,this.type=t,this.chainManager=n,this.ethers=null}async _loadEthers(){return this.ethers||(this.ethers=await Promise.resolve().then(()=>yU)),this.ethers}async addMember(e){const t=await this.contract.addMember(e),n=await t.wait();return{txHash:n.hash,receipt:n}}async addMembers(e){const t=await this.contract.addMembers(e),n=await t.wait();return{txHash:n.hash,receipt:n}}async getMembers(){await this.contract.userIds();try{const e=[];let t=0;for(;;)try{const n=await this.contract.userIds(t);e.push(n),t++}catch{break}return e}catch{return[]}}async isMember(e){try{return"Splitter"===this.type?await this.contract.isSplitterMember(e):await this.contract.isMember(e)}catch{return!1}}async getUserAddress(e){return this.contract.userIdToAddress(e)}async reward(e,t){const n=await this._loadEthers(),r="string"==typeof t?n.parseUnits(t,18):t,i=await this.contract.reward(e,r),s=await i.wait();return{txHash:s.hash,receipt:s}}async rewardEth(e){const t=(await this._loadEthers()).parseEther(e),n=await this.contract.reward("0x0000000000000000000000000000000000000000",t,{value:t}),r=await n.wait();return{txHash:r.hash,receipt:r}}async sendEth(e){const t=await this._loadEthers(),n=this.chainManager.getSigner(),r=t.parseEther(e),i=await n.sendTransaction({to:await this.contract.getAddress(),value:r}),s=await i.wait();return{txHash:s.hash,receipt:s}}async claim(e,t){const n=await this.contract.claim(e,t),r=await n.wait();return{txHash:r.hash,receipt:r}}async getEthBalance(e){const t=await this._loadEthers(),n=await this.contract.etherBalance(e);return t.formatEther(n)}async getTokenBalance(e,t){const n=await this._loadEthers(),r=await this.contract.tokenBalance(e,t);return n.formatUnits(r,18)}async hasClaimed(e){return this.contract.hasClaimed(e)}async getTotalDeposited(e){const t=await this._loadEthers(),n=await this.contract.totalDeposited(e);return t.formatUnits(n,18)}async setContractSplit(e,t){if(this._requireType(["Splitter"]),e+t!==100)throw new Error("Percentages must sum to 100");const n=await this.contract.setContractSplit(e,t),r=await n.wait();return{txHash:r.hash,receipt:r}}async getContractSplit(){this._requireType(["Splitter"]);const e=await this.contract.internalContractSplitPercentage(),t=await this.contract.externalContractSplitPercentage();return{internal:Number(e),external:Number(t)}}async createManagedContract(e,t,n=0){this._requireType(["Splitter"]);const r=await this.contract.createManagedContract(e,t,n),i=await r.wait();return{address:await this.contract.contractsByType(`${t}_managed`),txHash:i.hash,receipt:i}}async createZonedContract(e,t,n=6){this._requireType(["Splitter"]);const r=await this.contract.createZonedContract(e,t,n),i=await r.wait();return{address:await this.contract.contractsByType(`${t}_zoned`),txHash:i.hash,receipt:i}}async getChildContractKeys(){return this._requireType(["Splitter"]),this.contract.getContractKeys()}async getChildContracts(){this._requireType(["Splitter"]);const[e,t]=await this.contract.getContractAddresses();return{keys:e,addresses:t}}async getChildContract(e){return this._requireType(["Splitter"]),this.contract.contractsByType(e)}async setAppreciation(e,t){if(this._requireType(["Managed"]),e.length!==t.length)throw new Error("userIds and amounts arrays must have same length");const n=await this.contract.setAppreciation(e,t),r=await n.wait();return{txHash:r.hash,receipt:r}}async getAppreciation(e){this._requireType(["Managed"]);const t=await this.contract.appreciation(e);return Number(t)}async getTotalAppreciation(){this._requireType(["Managed"]);const e=await this.contract.totalappreciation();return Number(e)}async addToZone(e,t,n){this._requireType(["Zoned"]);const r=await this.contract.addToZone(e,t,n),i=await r.wait();return{txHash:i.hash,receipt:i}}async removeFromZone(e,t){this._requireType(["Zoned"]);const n=await this.contract.removeFromZone(e,t),r=await n.wait();return{txHash:r.hash,receipt:r}}async getZone(e){this._requireType(["Zoned"]);const t=await this.contract.zones(e);return Number(t)}async getNumZones(){this._requireType(["Zoned"]);const e=await this.contract.nzones();return Number(e)}async setZoneParameters(e,t,n,r){this._requireType(["Zoned"]);const i=await this.contract.setRewardFunction(e,t,n,r),s=await i.wait();return{txHash:s.hash,receipt:s}}async appreciate(e,t,n){this._requireType(["Appreciative"]);const r=await this.contract.appreciate(e,t,n),i=await r.wait();return{txHash:i.hash,receipt:i}}async getAppreciationGiven(e){this._requireType(["Appreciative"]);const t=await this.contract.appreciationGiven(e);return Number(t)}async getAppreciationReceived(e){this._requireType(["Appreciative"]);const t=await this.contract.appreciationReceived(e);return Number(t)}async getAppreciationRemaining(e){this._requireType(["Appreciative"]);const t=await this.contract.appreciationRemaining(e);return Number(t)}async setSteepness(e){this._requireType(["Bundle"]);const t=await this._loadEthers(),n="string"==typeof e?t.parseEther(e):e,r=await this.contract.setSteepness(n),i=await r.wait();return{txHash:i.hash,receipt:i}}async getSteepness(){this._requireType(["Bundle"]);const e=await this._loadEthers(),t=await this.contract.steepness();return e.formatEther(t)}async setInteriorSplit(e,t){if(this._requireType(["Bundle"]),100!==t.reduce((e,t)=>e+t,0))throw new Error("Percentages must sum to 100");const n=await this.contract.setInteriorSplit(e,t),r=await n.wait();return{txHash:r.hash,receipt:r}}async startElection(){this._requireType(["Bundle"]);const e=await this.contract.startElection(),t=await e.wait();return{txHash:t.hash,receipt:t}}async nominateSelf(){this._requireType(["Bundle"]);const e=await this.contract.nominateSelf(),t=await e.wait();return{txHash:t.hash,receipt:t}}async vote(e){this._requireType(["Bundle"]);const t=await this.contract.vote(e),n=await t.wait();return{txHash:n.hash,receipt:n}}async finalizeElection(){this._requireType(["Bundle"]);const e=await this.contract.finalizeElection(),t=await e.wait();return{txHash:t.hash,receipt:t}}async getName(){return this.contract.name()}async getOwner(){return this.contract.owner()}async getBotAddress(){try{return await this.contract.botAddress()}catch{return null}}async getCreatorUserId(){try{return await this.contract.creatorUserId()}catch{return null}}async getAddress(){return this.contract.getAddress()}getType(){return this.type}_requireType(e){if(!e.includes(this.type))throw new Error(`Operation only available for ${e.join("/")} contracts. This is a ${this.type} contract.`)}getRawContract(){return this.contract}async call(e,...t){return this.contract[e](...t)}async send(e,...t){const n=await this.contract[e](...t),r=await n.wait();return{txHash:r.hash,receipt:r}}}class AS{constructor(e,t){this.chainManager=e,this.deployer=t||new oS(e),this.holonContracts=new Map,this.storage=null}setStorage(e){this.storage=e}async deploy(e,t="Splitter",n={}){if(this.holonContracts.has(e))throw new Error(`Holon ${e} already has a contract. Use unlink() first to remove it.`);const r=n.name||e,i=n.creatorUserId||e;let s;switch(t){case"Splitter":s=await this.deployer.deploySplitter(e,r,n.splitPercentage||70,{creatorUserId:i,...n});break;case"Managed":s=await this.deployer.deployManaged(r,n);break;case"Zoned":s=await this.deployer.deployZoned(r,n.nZones||6,n);break;case"Appreciative":s=await this.deployer.deployAppreciative(r,i,n);break;case"Bundle":s=await this.deployer.deployBundle(r,n.steepness,n.nZones||6,{creatorUserId:i,...n});break;default:throw new Error(`Unknown contract type: ${t}`)}const a=new cS(s.contract,t,this.chainManager),o={holonId:e,address:s.address,type:t,contract:s.contract,operations:a,deployedAt:(new Date).toISOString(),txHash:s.txHash};return this.holonContracts.set(e,o),await this._saveMapping(e,o),{contract:s.contract,address:s.address,operations:a,txHash:s.txHash,type:t}}async link(e,t,n="Splitter"){if(this.holonContracts.has(e))throw new Error(`Holon ${e} already has a contract. Use unlink() first.`);const r=aS[n];if(!r)throw new Error(`Unknown contract type: ${n}`);const i=await this.chainManager.getContract(t,r.abi);try{await i.name()}catch(o){throw new Error(`Invalid contract at ${t}: ${o.message}`)}const s=new cS(i,n,this.chainManager),a={holonId:e,address:t,type:n,contract:i,operations:s,linkedAt:(new Date).toISOString()};return this.holonContracts.set(e,a),await this._saveMapping(e,a),{contract:i,address:t,operations:s,type:n}}async unlink(e){return!!this.holonContracts.has(e)&&(this.holonContracts.delete(e),this.storage&&await(this.storage.delete?.(`holon_contract:${e}`)),!0)}getContract(e){const t=this.holonContracts.get(e);return t?.contract||null}getAddress(e){const t=this.holonContracts.get(e);return t?.address||null}getOperations(e){const t=this.holonContracts.get(e);return t?.operations||null}getType(e){const t=this.holonContracts.get(e);return t?.type||null}hasContract(e){return this.holonContracts.has(e)}listAll(){const e=[];for(const[t,n]of this.holonContracts)e.push({holonId:t,address:n.address,type:n.type,deployedAt:n.deployedAt,linkedAt:n.linkedAt});return e}getByType(e){const t=[];for(const[n,r]of this.holonContracts)r.type===e&&t.push({holonId:n,address:r.address});return t}async loadFromStorage(){if(!this.storage)return 0;const e=await(this.storage.get?.("holon_contracts_index"))||[];let t=0;for(const r of e)try{const e=await(this.storage.get?.(`holon_contract:${r}`));if(e&&e.address&&e.type){const n=aS[e.type];if(n){const i=await this.chainManager.getContract(e.address,n.abi),s=new cS(i,e.type,this.chainManager);this.holonContracts.set(r,{...e,contract:i,operations:s}),t++}}}catch(n){console.warn(`Failed to load contract for holon ${r}: ${n.message}`)}return t}async _saveMapping(e,t){if(!this.storage)return;await(this.storage.set?.(`holon_contract:${e}`,{holonId:t.holonId,address:t.address,type:t.type,deployedAt:t.deployedAt,linkedAt:t.linkedAt,txHash:t.txHash}));const n=await(this.storage.get?.("holon_contracts_index"))||[];n.includes(e)||(n.push(e),await(this.storage.set?.("holon_contracts_index",n)))}requireOperations(e){const t=this.getOperations(e);if(!t)throw new Error(`Holon ${e} has no linked contract. Deploy or link one first.`);return t}}const lS="6.16.0";function fS(e,t,n){const r=t.split("|").map(e=>e.trim());for(let s=0;s<r.length;s++)switch(t){case"any":return;case"bigint":case"boolean":case"number":case"string":if(typeof e===t)return}const i=new Error(`invalid value for type ${t}`);throw i.code="INVALID_ARGUMENT",i.argument=`value.${n}`,i.value=e,i}async function uS(e){const t=Object.keys(e);return(await Promise.all(t.map(t=>Promise.resolve(e[t])))).reduce((e,n,r)=>(e[t[r]]=n,e),{})}function dS(e,t,n){for(let r in t){let i=t[r];const s=n?n[r]:null;s&&fS(i,s,r),Object.defineProperty(e,r,{enumerable:!0,value:i,writable:!1})}}function hS(e,t){if(null==e)return"null";if(null==t&&(t=new Set),"object"==typeof e){if(t.has(e))return"[Circular]";t.add(e)}if(Array.isArray(e))return"[ "+e.map(e=>hS(e,t)).join(", ")+" ]";if(e instanceof Uint8Array){const t="0123456789abcdef";let n="0x";for(let r=0;r<e.length;r++)n+=t[e[r]>>4],n+=t[15&e[r]];return n}if("object"==typeof e&&"function"==typeof e.toJSON)return hS(e.toJSON(),t);switch(typeof e){case"boolean":case"number":case"symbol":return e.toString();case"bigint":return BigInt(e).toString();case"string":return JSON.stringify(e);case"object":{const n=Object.keys(e);return n.sort(),"{ "+n.map(n=>`${hS(n,t)}: ${hS(e[n],t)}`).join(", ")+" }"}}return"[ COULD NOT SERIALIZE ]"}function pS(e,t){return e&&e.code===t}function mS(e){return pS(e,"CALL_EXCEPTION")}function yS(e,t,n){let r,i=e;{const r=[];if(n){if("message"in n||"code"in n||"name"in n)throw new Error(`value will overwrite populated values: ${hS(n)}`);for(const e in n){if("shortMessage"===e)continue;const t=n[e];r.push(e+"="+hS(t))}}r.push(`code=${t}`),r.push(`version=${lS}`),r.length&&(e+=" ("+r.join(", ")+")")}switch(t){case"INVALID_ARGUMENT":r=new TypeError(e);break;case"NUMERIC_FAULT":case"BUFFER_OVERRUN":r=new RangeError(e);break;default:r=new Error(e)}return dS(r,{code:t}),n&&Object.assign(r,n),null==r.shortMessage&&dS(r,{shortMessage:i}),r}function gS(e,t,n,r){if(!e)throw yS(t,n,r)}function bS(e,t,n,r){gS(e,t,"INVALID_ARGUMENT",{argument:n,value:r})}function wS(e,t,n){null==n&&(n=""),n&&(n=": "+n),gS(e>=t,"missing argument"+n,"MISSING_ARGUMENT",{count:e,expectedCount:t}),gS(e<=t,"too many arguments"+n,"UNEXPECTED_ARGUMENT",{count:e,expectedCount:t})}const vS=["NFD","NFC","NFKD","NFKC"].reduce((e,t)=>{try{if("test"!=="test".normalize(t))throw new Error("bad");if("NFD"===t){if(String.fromCharCode(233).normalize("NFD")!==String.fromCharCode(101,769))throw new Error("broken")}e.push(t)}catch(n){}return e},[]);function _S(e){gS(vS.indexOf(e)>=0,"platform missing String.prototype.normalize","UNSUPPORTED_OPERATION",{operation:"String.prototype.normalize",info:{form:e}})}function ES(e,t,n){if(null==n&&(n=""),e!==t){let e=n,t="new";n&&(e+=".",t+=" "+n),gS(!1,`private constructor; use ${e}from* methods`,"UNSUPPORTED_OPERATION",{operation:t})}}function kS(e,t,n){if(e instanceof Uint8Array)return n?new Uint8Array(e):e;if("string"==typeof e&&e.length%2==0&&e.match(/^0x[0-9a-f]*$/i)){const t=new Uint8Array((e.length-2)/2);let n=2;for(let r=0;r<t.length;r++)t[r]=parseInt(e.substring(n,n+2),16),n+=2;return t}bS(!1,"invalid BytesLike value",t||"value",e)}function TS(e,t){return kS(e,t,!1)}function SS(e,t){return kS(e,t,!0)}function xS(e,t){return!("string"!=typeof e||!e.match(/^0x[0-9A-Fa-f]*$/)||"number"==typeof t&&e.length!==2+2*t||!0===t&&e.length%2!=0)}function IS(e){return xS(e,!0)||e instanceof Uint8Array}const PS="0123456789abcdef";function CS(e){const t=TS(e);let n="0x";for(let r=0;r<t.length;r++){const e=t[r];n+=PS[(240&e)>>4]+PS[15&e]}return n}function NS(e){return"0x"+e.map(e=>CS(e).substring(2)).join("")}function OS(e){return xS(e,!0)?(e.length-2)/2:TS(e).length}function RS(e,t,n){const r=TS(e);return null!=n&&n>r.length&&gS(!1,"cannot slice beyond data bounds","BUFFER_OVERRUN",{buffer:r,length:r.length,offset:n}),CS(r.slice(null==t?0:t,null==n?r.length:n))}function BS(e){let t=CS(e).substring(2);for(;t.startsWith("00");)t=t.substring(2);return"0x"+t}function MS(e,t,n){const r=TS(e);gS(t>=r.length,"padding exceeds data length","BUFFER_OVERRUN",{buffer:new Uint8Array(r),length:t,offset:t+1});const i=new Uint8Array(t);return i.fill(0),n?i.set(r,t-r.length):i.set(r,0),CS(i)}function $S(e,t){return MS(e,t,!0)}function DS(e,t){return MS(e,t,!1)}const FS=BigInt(0),GS=BigInt(1),US=9007199254740991;function LS(e,t){const n=qS(e,"value"),r=BigInt(JS(t,"width"));return gS(n>>r===FS,"overflow","NUMERIC_FAULT",{operation:"fromTwos",fault:"overflow",value:e}),n>>r-GS?-((~n&(GS<<r)-GS)+GS):n}function jS(e,t){let n=zS(e,"value");const r=BigInt(JS(t,"width")),i=GS<<r-GS;return n<FS?(n=-n,gS(n<=i,"too low","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:e}),(~n&(GS<<r)-GS)+GS):(gS(n<i,"too high","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:e}),n)}function HS(e,t){const n=qS(e,"value"),r=BigInt(JS(t,"bits"));return n&(GS<<r)-GS}function zS(e,t){switch(typeof e){case"bigint":return e;case"number":return bS(Number.isInteger(e),"underflow",t||"value",e),bS(e>=-US&&e<=US,"overflow",t||"value",e),BigInt(e);case"string":try{if(""===e)throw new Error("empty string");return"-"===e[0]&&"-"!==e[1]?-BigInt(e.substring(1)):BigInt(e)}catch(n){bS(!1,`invalid BigNumberish string: ${n.message}`,t||"value",e)}}bS(!1,"invalid BigNumberish value",t||"value",e)}function qS(e,t){const n=zS(e,t);return gS(n>=FS,"unsigned value cannot be negative","NUMERIC_FAULT",{fault:"overflow",operation:"getUint",value:e}),n}const QS="0123456789abcdef";function VS(e){if(e instanceof Uint8Array){let t="0x0";for(const n of e)t+=QS[n>>4],t+=QS[15&n];return BigInt(t)}return zS(e)}function JS(e,t){switch(typeof e){case"bigint":return bS(e>=-US&&e<=US,"overflow",t||"value",e),Number(e);case"number":return bS(Number.isInteger(e),"underflow",t||"value",e),bS(e>=-US&&e<=US,"overflow",t||"value",e),e;case"string":try{if(""===e)throw new Error("empty string");return JS(BigInt(e),t)}catch(n){bS(!1,`invalid numeric string: ${n.message}`,t||"value",e)}}bS(!1,"invalid numeric value",t||"value",e)}function KS(e){return JS(VS(e))}function WS(e,t){const n=qS(e,"value");let r=n.toString(16);if(null==t)r.length%2&&(r="0"+r);else{const i=JS(t,"width");if(0===i&&n===FS)return"0x";for(gS(2*i>=r.length,`value exceeds width (${i} bytes)`,"NUMERIC_FAULT",{operation:"toBeHex",fault:"overflow",value:e});r.length<2*i;)r="0"+r}return"0x"+r}function YS(e,t){const n=qS(e,"value");if(n===FS){const e=null!=t?JS(t,"width"):0;return new Uint8Array(e)}let r=n.toString(16);if(r.length%2&&(r="0"+r),null!=t){const n=JS(t,"width");for(;r.length<2*n;)r="00"+r;gS(2*n===r.length,`value exceeds width (${n} bytes)`,"NUMERIC_FAULT",{operation:"toBeArray",fault:"overflow",value:e})}const i=new Uint8Array(r.length/2);for(let s=0;s<i.length;s++){const e=2*s;i[s]=parseInt(r.substring(e,e+2),16)}return i}function ZS(e){let t=CS(IS(e)?e:YS(e)).substring(2);for(;t.startsWith("0");)t=t.substring(1);return""===t&&(t="0"),"0x"+t}const XS="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";let ex=null;function tx(e){if(null==ex){ex={};for(let e=0;e<58;e++)ex[XS[e]]=BigInt(e)}const t=ex[e];return bS(null!=t,"invalid base58 value","letter",e),t}const nx=BigInt(0),rx=BigInt(58);function ix(e){const t=TS(e);let n=VS(t),r="";for(;n;)r=XS[Number(n%rx)]+r,n/=rx;for(let i=0;i<t.length&&!t[i];i++)r=XS[0]+r;return r}function sx(e){let t=nx;for(let n=0;n<e.length;n++)t*=rx,t+=tx(e[n]);return t}function ax(e){e=atob(e);const t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return TS(t)}function ox(e){const t=TS(e);let n="";for(let r=0;r<t.length;r++)n+=String.fromCharCode(t[r]);return btoa(n)}class cx{constructor(t,n,r){__publicField(this,"filter"),__publicField(this,"emitter"),__privateAdd(this,e),__privateSet(this,e,n),dS(this,{emitter:t,filter:r})}async removeListener(){null!=__privateGet(this,e)&&await this.emitter.off(this.filter,__privateGet(this,e))}}function Ax(e,t,n,r,i){if("BAD_PREFIX"===e||"UNEXPECTED_CONTINUE"===e){let e=0;for(let r=t+1;r<n.length&&n[r]>>6==2;r++)e++;return e}return"OVERRUN"===e?n.length-t-1:0}e=new WeakMap;const lx=Object.freeze({error:function(e,t,n,r,i){bS(!1,`invalid codepoint at offset ${t}; ${e}`,"bytes",n)},ignore:Ax,replace:function(e,t,n,r,i){return"OVERLONG"===e?(bS("number"==typeof i,"invalid bad code point for replacement","badCodepoint",i),r.push(i),0):(r.push(65533),Ax(e,t,n))}});function fx(e,t){null==t&&(t=lx.error);const n=TS(e,"bytes"),r=[];let i=0;for(;i<n.length;){const e=n[i++];if(!(e>>7)){r.push(e);continue}let s=null,a=null;if(192==(224&e))s=1,a=127;else if(224==(240&e))s=2,a=2047;else{if(240!=(248&e)){i+=t(128==(192&e)?"UNEXPECTED_CONTINUE":"BAD_PREFIX",i-1,n,r);continue}s=3,a=65535}if(i-1+s>=n.length){i+=t("OVERRUN",i-1,n,r);continue}let o=e&(1<<8-s-1)-1;for(let c=0;c<s;c++){let e=n[i];if(128!=(192&e)){i+=t("MISSING_CONTINUE",i,n,r),o=null;break}o=o<<6|63&e,i++}null!==o&&(o>1114111?i+=t("OUT_OF_RANGE",i-1-s,n,r,o):o>=55296&&o<=57343?i+=t("UTF16_SURROGATE",i-1-s,n,r,o):o<=a?i+=t("OVERLONG",i-1-s,n,r,o):r.push(o))}return r}function ux(e,t){bS("string"==typeof e,"invalid string value","str",e),null!=t&&(_S(t),e=e.normalize(t));let n=[];for(let r=0;r<e.length;r++){const t=e.charCodeAt(r);if(t<128)n.push(t);else if(t<2048)n.push(t>>6|192),n.push(63&t|128);else if(55296==(64512&t)){r++;const i=e.charCodeAt(r);bS(r<e.length&&56320==(64512&i),"invalid surrogate pair","str",e);const s=65536+((1023&t)<<10)+(1023&i);n.push(s>>18|240),n.push(s>>12&63|128),n.push(s>>6&63|128),n.push(63&s|128)}else n.push(t>>12|224),n.push(t>>6&63|128),n.push(63&t|128)}return new Uint8Array(n)}function dx(e,t){return fx(e,t).map(e=>e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode(55296+(e>>10&1023),56320+(1023&e)))).join("")}function hx(e,t){return fx(ux(e,t))}function px(e){return async function(t,n){gS(null==n||!n.cancelled,"request cancelled before sending","CANCELLED");const r=t.url.split(":")[0].toLowerCase();gS("http"===r||"https"===r,`unsupported protocol ${r}`,"UNSUPPORTED_OPERATION",{info:{protocol:r},operation:"request"}),gS("https"===r||!t.credentials||t.allowInsecureAuthentication,"insecure authorized connections unsupported","UNSUPPORTED_OPERATION",{operation:"request"});let i=null;const s=new AbortController,a=setTimeout(()=>{i=yS("request timeout","TIMEOUT"),s.abort()},t.timeout);n&&n.addListener(()=>{i=yS("request cancelled","CANCELLED"),s.abort()});const o=Object.assign({},e,{method:t.method,headers:new Headers(Array.from(t)),body:t.body||void 0,signal:s.signal});let c;try{c=await fetch(t.url,o)}catch(u){if(clearTimeout(a),i)throw i;throw u}clearTimeout(a);const A={};c.headers.forEach((e,t)=>{A[t.toLowerCase()]=e});const l=await c.arrayBuffer(),f=null==l?null:new Uint8Array(l);return{statusCode:c.status,statusMessage:c.statusText,headers:A,body:f}}}let mx=px();const yx=new RegExp("^data:([^;:]*)?(;base64)?,(.*)$","i"),gx=new RegExp("^ipfs://(ipfs/)?(.*)$","i");let bx=!1;async function wx(e,t){try{const t=e.match(yx);if(!t)throw new Error("invalid data");return new Px(200,"OK",{"content-type":t[1]||"text/plain"},t[2]?ax(t[3]):ux(t[3].replace(/%([0-9a-f][0-9a-f])/gi,(e,t)=>String.fromCharCode(parseInt(t,16)))))}catch(n){return new Px(599,"BAD REQUEST (invalid data: URI)",{},null,new xx(e))}}function vx(e){return async function(t,n){try{const n=t.match(gx);if(!n)throw new Error("invalid link");return new xx(`${e}${n[2]}`)}catch(r){return new Px(599,"BAD REQUEST (invalid IPFS URI)",{},null,new xx(t))}}}const _x={data:wx,ipfs:vx("https://gateway.ipfs.io/ipfs/")},Ex=new WeakMap;class kx{constructor(e){__privateAdd(this,t),__privateAdd(this,n),__privateSet(this,t,[]),__privateSet(this,n,!1),Ex.set(e,()=>{if(!__privateGet(this,n)){__privateSet(this,n,!0);for(const e of __privateGet(this,t))setTimeout(()=>{e()},0);__privateSet(this,t,[])}})}addListener(e){gS(!__privateGet(this,n),"singal already cancelled","UNSUPPORTED_OPERATION",{operation:"fetchCancelSignal.addCancelListener"}),__privateGet(this,t).push(e)}get cancelled(){return __privateGet(this,n)}checkSignal(){gS(!this.cancelled,"cancelled","CANCELLED",{})}}function Tx(e){if(null==e)throw new Error("missing signal; should not happen");return e.checkSignal(),e}t=new WeakMap,n=new WeakMap;const Sx=class e{constructor(e){__privateAdd(this,g),__privateAdd(this,r),__privateAdd(this,i),__privateAdd(this,s),__privateAdd(this,a),__privateAdd(this,o),__privateAdd(this,c),__privateAdd(this,A),__privateAdd(this,l),__privateAdd(this,f),__privateAdd(this,u),__privateAdd(this,d),__privateAdd(this,h),__privateAdd(this,p),__privateAdd(this,m),__privateAdd(this,y),__privateSet(this,c,String(e)),__privateSet(this,r,!1),__privateSet(this,i,!0),__privateSet(this,s,{}),__privateSet(this,a,""),__privateSet(this,o,3e5),__privateSet(this,m,{slotInterval:250,maxAttempts:12}),__privateSet(this,y,null)}get url(){return __privateGet(this,c)}set url(e){__privateSet(this,c,String(e))}get body(){return null==__privateGet(this,A)?null:new Uint8Array(__privateGet(this,A))}set body(e){if(null==e)__privateSet(this,A,void 0),__privateSet(this,l,void 0);else if("string"==typeof e)__privateSet(this,A,ux(e)),__privateSet(this,l,"text/plain");else if(e instanceof Uint8Array)__privateSet(this,A,e),__privateSet(this,l,"application/octet-stream");else{if("object"!=typeof e)throw new Error("invalid body");__privateSet(this,A,ux(JSON.stringify(e))),__privateSet(this,l,"application/json")}}hasBody(){return null!=__privateGet(this,A)}get method(){return __privateGet(this,a)?__privateGet(this,a):this.hasBody()?"POST":"GET"}set method(e){null==e&&(e=""),__privateSet(this,a,String(e).toUpperCase())}get headers(){const e=Object.assign({},__privateGet(this,s));return __privateGet(this,f)&&(e.authorization=`Basic ${ox(ux(__privateGet(this,f)))}`),this.allowGzip&&(e["accept-encoding"]="gzip"),null==e["content-type"]&&__privateGet(this,l)&&(e["content-type"]=__privateGet(this,l)),this.body&&(e["content-length"]=String(this.body.length)),e}getHeader(e){return this.headers[e.toLowerCase()]}setHeader(e,t){__privateGet(this,s)[String(e).toLowerCase()]=String(t)}clearHeaders(){__privateSet(this,s,{})}[Symbol.iterator](){const e=this.headers,t=Object.keys(e);let n=0;return{next:()=>{if(n<t.length){const r=t[n++];return{value:[r,e[r]],done:!1}}return{value:void 0,done:!0}}}}get credentials(){return __privateGet(this,f)||null}setCredentials(e,t){bS(!e.match(/:/),"invalid basic authentication username","username","[REDACTED]"),__privateSet(this,f,`${e}:${t}`)}get allowGzip(){return __privateGet(this,i)}set allowGzip(e){__privateSet(this,i,!!e)}get allowInsecureAuthentication(){return!!__privateGet(this,r)}set allowInsecureAuthentication(e){__privateSet(this,r,!!e)}get timeout(){return __privateGet(this,o)}set timeout(e){bS(e>=0,"timeout must be non-zero","timeout",e),__privateSet(this,o,e)}get preflightFunc(){return __privateGet(this,u)||null}set preflightFunc(e){__privateSet(this,u,e)}get processFunc(){return __privateGet(this,d)||null}set processFunc(e){__privateSet(this,d,e)}get retryFunc(){return __privateGet(this,h)||null}set retryFunc(e){__privateSet(this,h,e)}get getUrlFunc(){return __privateGet(this,y)||mx}set getUrlFunc(e){__privateSet(this,y,e)}toString(){return`<FetchRequest method=${JSON.stringify(this.method)} url=${JSON.stringify(this.url)} headers=${JSON.stringify(this.headers)} body=${__privateGet(this,A)?CS(__privateGet(this,A)):"null"}>`}setThrottleParams(e){null!=e.slotInterval&&(__privateGet(this,m).slotInterval=e.slotInterval),null!=e.maxAttempts&&(__privateGet(this,m).maxAttempts=e.maxAttempts)}send(){return gS(null==__privateGet(this,p),"request already sent","UNSUPPORTED_OPERATION",{operation:"fetchRequest.send"}),__privateSet(this,p,new kx(this)),__privateMethod(this,g,b).call(this,0,Cx()+this.timeout,0,this,new Px(0,"",{},null,this))}cancel(){gS(null!=__privateGet(this,p),"request has not been sent","UNSUPPORTED_OPERATION",{operation:"fetchRequest.cancel"});const e=Ex.get(this);if(!e)throw new Error("missing signal; should not happen");e()}redirect(t){const n=this.url.split(":")[0].toLowerCase(),r=t.split(":")[0].toLowerCase();gS("GET"===this.method&&("https"!==n||"http"!==r)&&t.match(/^https?:/),"unsupported redirect","UNSUPPORTED_OPERATION",{operation:`redirect(${this.method} ${JSON.stringify(this.url)} => ${JSON.stringify(t)})`});const i=new e(t);return i.method="GET",i.allowGzip=this.allowGzip,i.timeout=this.timeout,__privateSet(i,s,Object.assign({},__privateGet(this,s))),__privateGet(this,A)&&__privateSet(i,A,new Uint8Array(__privateGet(this,A))),__privateSet(i,l,__privateGet(this,l)),i}clone(){const t=new e(this.url);return __privateSet(t,a,__privateGet(this,a)),__privateGet(this,A)&&__privateSet(t,A,__privateGet(this,A)),__privateSet(t,l,__privateGet(this,l)),__privateSet(t,s,Object.assign({},__privateGet(this,s))),__privateSet(t,f,__privateGet(this,f)),this.allowGzip&&(t.allowGzip=!0),t.timeout=this.timeout,this.allowInsecureAuthentication&&(t.allowInsecureAuthentication=!0),__privateSet(t,u,__privateGet(this,u)),__privateSet(t,d,__privateGet(this,d)),__privateSet(t,h,__privateGet(this,h)),__privateSet(t,m,Object.assign({},__privateGet(this,m))),__privateSet(t,y,__privateGet(this,y)),t}static lockConfig(){bx=!0}static getGateway(e){return _x[e.toLowerCase()]||null}static registerGateway(e,t){if("http"===(e=e.toLowerCase())||"https"===e)throw new Error(`cannot intercept ${e}; use registerGetUrl`);if(bx)throw new Error("gateways locked");_x[e]=t}static registerGetUrl(e){if(bx)throw new Error("gateways locked");mx=e}static createGetUrlFunc(e){return px(e)}static createDataGateway(){return wx}static createIpfsGatewayFunc(e){return vx(e)}};r=new WeakMap,i=new WeakMap,s=new WeakMap,a=new WeakMap,o=new WeakMap,c=new WeakMap,A=new WeakMap,l=new WeakMap,f=new WeakMap,u=new WeakMap,d=new WeakMap,h=new WeakMap,p=new WeakMap,m=new WeakMap,y=new WeakMap,g=new WeakSet,b=async function(e,t,n,r,i){var s,a,o;if(e>=__privateGet(this,m).maxAttempts)return i.makeServerError("exceeded maximum retry limit");gS(Cx()<=t,"timeout","TIMEOUT",{operation:"request.send",reason:"timeout",request:r}),n>0&&await function(e){return new Promise(t=>setTimeout(t,e))}(n);let c=this.clone();const A=(c.url.split(":")[0]||"").toLowerCase();if(A in _x){const e=await _x[A](c.url,Tx(__privateGet(r,p)));if(e instanceof Px){let t=e;if(this.processFunc){Tx(__privateGet(r,p));try{t=await this.processFunc(c,t)}catch(u){null!=u.throttle&&"number"==typeof u.stall||t.makeServerError("error in post-processing function",u).assertOk()}}return t}c=e}this.preflightFunc&&(c=await this.preflightFunc(c));const l=await this.getUrlFunc(c,Tx(__privateGet(r,p)));let f=new Px(l.statusCode,l.statusMessage,l.headers,l.body,r);if(301===f.statusCode||302===f.statusCode){try{const n=f.headers.location||"";return __privateMethod(s=c.redirect(n),g,b).call(s,e+1,t,0,r,f)}catch(u){}return f}if(429===f.statusCode&&(null==this.retryFunc||await this.retryFunc(c,f,e))){const n=f.headers["retry-after"];let i=__privateGet(this,m).slotInterval*Math.trunc(Math.random()*Math.pow(2,e));return"string"==typeof n&&n.match(/^[1-9][0-9]*$/)&&(i=parseInt(n)),__privateMethod(a=c.clone(),g,b).call(a,e+1,t,i,r,f)}if(this.processFunc){Tx(__privateGet(r,p));try{f=await this.processFunc(c,f)}catch(u){null!=u.throttle&&"number"==typeof u.stall||f.makeServerError("error in post-processing function",u).assertOk();let n=__privateGet(this,m).slotInterval*Math.trunc(Math.random()*Math.pow(2,e));return u.stall>=0&&(n=u.stall),__privateMethod(o=c.clone(),g,b).call(o,e+1,t,n,r,f)}}return f};let xx=Sx;const Ix=class e{constructor(e,t,n,r,i){__privateAdd(this,w),__privateAdd(this,v),__privateAdd(this,_),__privateAdd(this,E),__privateAdd(this,k),__privateAdd(this,T),__privateSet(this,w,e),__privateSet(this,v,t),__privateSet(this,_,Object.keys(n).reduce((e,t)=>(e[t.toLowerCase()]=String(n[t]),e),{})),__privateSet(this,E,null==r?null:new Uint8Array(r)),__privateSet(this,k,i||null),__privateSet(this,T,{message:""})}toString(){return`<FetchResponse status=${this.statusCode} body=${__privateGet(this,E)?CS(__privateGet(this,E)):"null"}>`}get statusCode(){return __privateGet(this,w)}get statusMessage(){return __privateGet(this,v)}get headers(){return Object.assign({},__privateGet(this,_))}get body(){return null==__privateGet(this,E)?null:new Uint8Array(__privateGet(this,E))}get bodyText(){try{return null==__privateGet(this,E)?"":dx(__privateGet(this,E))}catch(e){gS(!1,"response body is not valid UTF-8 data","UNSUPPORTED_OPERATION",{operation:"bodyText",info:{response:this}})}}get bodyJson(){try{return JSON.parse(this.bodyText)}catch(e){gS(!1,"response body is not valid JSON","UNSUPPORTED_OPERATION",{operation:"bodyJson",info:{response:this}})}}[Symbol.iterator](){const e=this.headers,t=Object.keys(e);let n=0;return{next:()=>{if(n<t.length){const r=t[n++];return{value:[r,e[r]],done:!1}}return{value:void 0,done:!0}}}}makeServerError(t,n){let r;r=t?`CLIENT ESCALATED SERVER ERROR (${this.statusCode} ${this.statusMessage}; ${t})`:`CLIENT ESCALATED SERVER ERROR (${t=`${this.statusCode} ${this.statusMessage}`})`;const i=new e(599,r,this.headers,this.body,__privateGet(this,k)||void 0);return __privateSet(i,T,{message:t,error:n}),i}throwThrottleError(e,t){null==t?t=-1:bS(Number.isInteger(t)&&t>=0,"invalid stall timeout","stall",t);const n=new Error(e||"throttling requests");throw dS(n,{stall:t,throttle:!0}),n}getHeader(e){return this.headers[e.toLowerCase()]}hasBody(){return null!=__privateGet(this,E)}get request(){return __privateGet(this,k)}ok(){return""===__privateGet(this,T).message&&this.statusCode>=200&&this.statusCode<300}assertOk(){if(this.ok())return;let{message:e,error:t}=__privateGet(this,T);""===e&&(e=`server response ${this.statusCode} ${this.statusMessage}`);let n=null;this.request&&(n=this.request.url);let r=null;try{__privateGet(this,E)&&(r=dx(__privateGet(this,E)))}catch(i){}gS(!1,e,"SERVER_ERROR",{request:this.request||"unknown request",response:this,error:t,info:{requestUrl:n,responseBody:r,responseStatus:`${this.statusCode} ${this.statusMessage}`}})}};w=new WeakMap,v=new WeakMap,_=new WeakMap,E=new WeakMap,k=new WeakMap,T=new WeakMap;let Px=Ix;function Cx(){return(new Date).getTime()}const Nx=BigInt(-1),Ox=BigInt(0),Rx=BigInt(1),Bx=BigInt(5),Mx={};let $x="0000";for(;$x.length<80;)$x+=$x;function Dx(e){let t=$x;for(;t.length<e;)t+=t;return BigInt("1"+t.substring(0,e))}function Fx(e,t,n){const r=BigInt(t.width);if(t.signed){const t=Rx<<r-Rx;gS(null==n||e>=-t&&e<t,"overflow","NUMERIC_FAULT",{operation:n,fault:"overflow",value:e}),e=e>Ox?LS(HS(e,r),r):-LS(HS(-e,r),r)}else{const t=Rx<<r;gS(null==n||e>=0&&e<t,"overflow","NUMERIC_FAULT",{operation:n,fault:"overflow",value:e}),e=(e%t+t)%t&t-Rx}return e}function Gx(e){"number"==typeof e&&(e=`fixed128x${e}`);let t=!0,n=128,r=18;if("string"==typeof e)if("fixed"===e);else if("ufixed"===e)t=!1;else{const i=e.match(/^(u?)fixed([0-9]+)x([0-9]+)$/);bS(i,"invalid fixed format","format",e),t="u"!==i[1],n=parseInt(i[2]),r=parseInt(i[3])}else if(e){const i=e,s=(e,t,n)=>null==i[e]?n:(bS(typeof i[e]===t,"invalid fixed format ("+e+" not "+t+")","format."+e,i[e]),i[e]);t=s("signed","boolean",t),n=s("width","number",n),r=s("decimals","number",r)}return bS(n%8==0,"invalid FixedNumber width (not byte aligned)","format.width",n),bS(r<=80,"invalid FixedNumber decimals (too large)","format.decimals",r),{signed:t,width:n,decimals:r,name:(t?"":"u")+"fixed"+String(n)+"x"+String(r)}}const Ux=class e{constructor(e,t,n){__privateAdd(this,P),__publicField(this,"format"),__privateAdd(this,S),__privateAdd(this,x),__privateAdd(this,I),__publicField(this,"_value"),ES(e,Mx,"FixedNumber"),__privateSet(this,x,t),__privateSet(this,S,n);const r=function(e,t){let n="";e<Ox&&(n="-",e*=Nx);let r=e.toString();if(0===t)return n+r;for(;r.length<=t;)r=$x+r;const i=r.length-t;for(r=r.substring(0,i)+"."+r.substring(i);"0"===r[0]&&"."!==r[1];)r=r.substring(1);for(;"0"===r[r.length-1]&&"."!==r[r.length-2];)r=r.substring(0,r.length-1);return n+r}(t,n.decimals);dS(this,{format:n.name,_value:r}),__privateSet(this,I,Dx(n.decimals))}get signed(){return __privateGet(this,S).signed}get width(){return __privateGet(this,S).width}get decimals(){return __privateGet(this,S).decimals}get value(){return __privateGet(this,x)}addUnsafe(e){return __privateMethod(this,P,O).call(this,e)}add(e){return __privateMethod(this,P,O).call(this,e,"add")}subUnsafe(e){return __privateMethod(this,P,R).call(this,e)}sub(e){return __privateMethod(this,P,R).call(this,e,"sub")}mulUnsafe(e){return __privateMethod(this,P,B).call(this,e)}mul(e){return __privateMethod(this,P,B).call(this,e,"mul")}mulSignal(e){__privateMethod(this,P,C).call(this,e);const t=__privateGet(this,x)*__privateGet(e,x);return gS(t%__privateGet(this,I)===Ox,"precision lost during signalling mul","NUMERIC_FAULT",{operation:"mulSignal",fault:"underflow",value:this}),__privateMethod(this,P,N).call(this,t/__privateGet(this,I),"mulSignal")}divUnsafe(e){return __privateMethod(this,P,M).call(this,e)}div(e){return __privateMethod(this,P,M).call(this,e,"div")}divSignal(e){gS(__privateGet(e,x)!==Ox,"division by zero","NUMERIC_FAULT",{operation:"div",fault:"divide-by-zero",value:this}),__privateMethod(this,P,C).call(this,e);const t=__privateGet(this,x)*__privateGet(this,I);return gS(t%__privateGet(e,x)===Ox,"precision lost during signalling div","NUMERIC_FAULT",{operation:"divSignal",fault:"underflow",value:this}),__privateMethod(this,P,N).call(this,t/__privateGet(e,x),"divSignal")}cmp(e){let t=this.value,n=e.value;const r=this.decimals-e.decimals;return r>0?n*=Dx(r):r<0&&(t*=Dx(-r)),t<n?-1:t>n?1:0}eq(e){return 0===this.cmp(e)}lt(e){return this.cmp(e)<0}lte(e){return this.cmp(e)<=0}gt(e){return this.cmp(e)>0}gte(e){return this.cmp(e)>=0}floor(){let e=__privateGet(this,x);return __privateGet(this,x)<Ox&&(e-=__privateGet(this,I)-Rx),e=__privateGet(this,x)/__privateGet(this,I)*__privateGet(this,I),__privateMethod(this,P,N).call(this,e,"floor")}ceiling(){let e=__privateGet(this,x);return __privateGet(this,x)>Ox&&(e+=__privateGet(this,I)-Rx),e=__privateGet(this,x)/__privateGet(this,I)*__privateGet(this,I),__privateMethod(this,P,N).call(this,e,"ceiling")}round(t){if(null==t&&(t=0),t>=this.decimals)return this;const n=this.decimals-t,r=Bx*Dx(n-1);let i=this.value+r;const s=Dx(n);return i=i/s*s,Fx(i,__privateGet(this,S),"round"),new e(Mx,i,__privateGet(this,S))}isZero(){return __privateGet(this,x)===Ox}isNegative(){return __privateGet(this,x)<Ox}toString(){return this._value}toUnsafeFloat(){return parseFloat(this.toString())}toFormat(t){return e.fromString(this.toString(),t)}static fromValue(t,n,r){const i=null==n?0:JS(n),s=Gx(r);let a=zS(t,"value");const o=i-s.decimals;if(o>0){const e=Dx(o);gS(a%e===Ox,"value loses precision for format","NUMERIC_FAULT",{operation:"fromValue",fault:"underflow",value:t}),a/=e}else o<0&&(a*=Dx(-o));return Fx(a,s,"fromValue"),new e(Mx,a,s)}static fromString(t,n){const r=t.match(/^(-?)([0-9]*)\.?([0-9]*)$/);bS(r&&r[2].length+r[3].length>0,"invalid FixedNumber string value","value",t);const i=Gx(n);let s=r[2]||"0",a=r[3]||"";for(;a.length<i.decimals;)a+=$x;gS(a.substring(i.decimals).match(/^0*$/),"too many decimals for format","NUMERIC_FAULT",{operation:"fromString",fault:"underflow",value:t}),a=a.substring(0,i.decimals);const o=BigInt(r[1]+s+a);return Fx(o,i,"fromString"),new e(Mx,o,i)}static fromBytes(t,n){let r=VS(TS(t,"value"));const i=Gx(n);return i.signed&&(r=LS(r,i.width)),Fx(r,i,"fromBytes"),new e(Mx,r,i)}};S=new WeakMap,x=new WeakMap,I=new WeakMap,P=new WeakSet,C=function(e){bS(this.format===e.format,"incompatible format; use fixedNumber.toFormat","other",e)},N=function(e,t){return e=Fx(e,__privateGet(this,S),t),new Ux(Mx,e,__privateGet(this,S))},O=function(e,t){return __privateMethod(this,P,C).call(this,e),__privateMethod(this,P,N).call(this,__privateGet(this,x)+__privateGet(e,x),t)},R=function(e,t){return __privateMethod(this,P,C).call(this,e),__privateMethod(this,P,N).call(this,__privateGet(this,x)-__privateGet(e,x),t)},B=function(e,t){return __privateMethod(this,P,C).call(this,e),__privateMethod(this,P,N).call(this,__privateGet(this,x)*__privateGet(e,x)/__privateGet(this,I),t)},M=function(e,t){return gS(__privateGet(e,x)!==Ox,"division by zero","NUMERIC_FAULT",{operation:"div",fault:"divide-by-zero",value:this}),__privateMethod(this,P,C).call(this,e),__privateMethod(this,P,N).call(this,__privateGet(this,x)*__privateGet(this,I)/__privateGet(e,x),t)};let Lx=Ux;function jx(e){let t=e.toString(16);for(;t.length<2;)t="0"+t;return"0x"+t}function Hx(e,t,n){let r=0;for(let i=0;i<n;i++)r=256*r+e[t+i];return r}function zx(e,t,n,r){const i=[];for(;n<t+1+r;){const s=qx(e,n);i.push(s.result),gS((n+=s.consumed)<=t+1+r,"child data too short","BUFFER_OVERRUN",{buffer:e,length:r,offset:t})}return{consumed:1+r,result:i}}function qx(e,t){gS(0!==e.length,"data too short","BUFFER_OVERRUN",{buffer:e,length:0,offset:1});const n=t=>{gS(t<=e.length,"data short segment too short","BUFFER_OVERRUN",{buffer:e,length:e.length,offset:t})};if(e[t]>=248){const r=e[t]-247;n(t+1+r);const i=Hx(e,t+1,r);return n(t+1+r+i),zx(e,t,t+1+r,r+i)}if(e[t]>=192){const r=e[t]-192;return n(t+1+r),zx(e,t,t+1,r)}if(e[t]>=184){const r=e[t]-183;n(t+1+r);const i=Hx(e,t+1,r);return n(t+1+r+i),{consumed:1+r+i,result:CS(e.slice(t+1+r,t+1+r+i))}}if(e[t]>=128){const r=e[t]-128;return n(t+1+r),{consumed:1+r,result:CS(e.slice(t+1,t+1+r))}}return{consumed:1,result:jx(e[t])}}function Qx(e){const t=TS(e,"data"),n=qx(t,0);return bS(n.consumed===t.length,"unexpected junk after rlp payload","data",e),n.result}function Vx(e){const t=[];for(;e;)t.unshift(255&e),e>>=8;return t}function Jx(e){if(Array.isArray(e)){let t=[];if(e.forEach(function(e){t=t.concat(Jx(e))}),t.length<=55)return t.unshift(192+t.length),t;const n=Vx(t.length);return n.unshift(247+n.length),n.concat(t)}const t=Array.prototype.slice.call(TS(e,"object"));if(1===t.length&&t[0]<=127)return t;if(t.length<=55)return t.unshift(128+t.length),t;const n=Vx(t.length);return n.unshift(183+n.length),n.concat(t)}const Kx="0123456789abcdef";function Wx(e){let t="0x";for(const n of Jx(e))t+=Kx[n>>4],t+=Kx[15&n];return t}const Yx=["wei","kwei","mwei","gwei","szabo","finney","ether"];function Zx(e,t){let n=18;if("string"==typeof t){const e=Yx.indexOf(t);bS(e>=0,"invalid unit","unit",t),n=3*e}else null!=t&&(n=JS(t,"unit"));return Lx.fromValue(e,n,{decimals:n,width:512}).toString()}function Xx(e,t){bS("string"==typeof e,"value must be a string","value",e);let n=18;if("string"==typeof t){const e=Yx.indexOf(t);bS(e>=0,"invalid unit","unit",t),n=3*e}else null!=t&&(n=JS(t,"unit"));return Lx.fromString(e,{decimals:n,width:512}).value}function eI(e){return Zx(e,18)}function tI(e){return Xx(e,18)}function nI(e){const t=TS(e,"randomBytes");t[6]=15&t[6]|64,t[8]=63&t[8]|128;const n=CS(t);return[n.substring(2,10),n.substring(10,14),n.substring(14,18),n.substring(18,22),n.substring(22,34)].join("-")}const rI=32,iI=new Uint8Array(rI),sI=["then"],aI={},oI=new WeakMap;function cI(e){return oI.get(e)}function AI(e,t){oI.set(e,t)}function lI(e,t){const n=new Error(`deferred error during ABI decoding triggered accessing ${e}`);throw n.error=t,n}function fI(e,t,n){return e.indexOf(null)>=0?t.map((e,t)=>e instanceof uI?fI(cI(e),e,n):e):e.reduce((e,r,i)=>{let s=t.getValue(r);return r in e||(n&&s instanceof uI&&(s=fI(cI(s),s,n)),e[r]=s),e},{})}$=new WeakMap;let uI=class e extends Array{constructor(...e){const t=e[0];let n=e[1],r=(e[2]||[]).slice(),i=!0;t!==aI&&(n=e,r=[],i=!1),super(n.length),__privateAdd(this,$),n.forEach((e,t)=>{this[t]=e});const s=r.reduce((e,t)=>("string"==typeof t&&e.set(t,(e.get(t)||0)+1),e),new Map);if(AI(this,Object.freeze(n.map((e,t)=>{const n=r[t];return null!=n&&1===s.get(n)?n:null}))),__privateSet(this,$,[]),null==__privateGet(this,$)&&__privateGet(this,$),!i)return;Object.freeze(this);const a=new Proxy(this,{get:(e,t,n)=>{if("string"==typeof t){if(t.match(/^[0-9]+$/)){const n=JS(t,"%index");if(n<0||n>=this.length)throw new RangeError("out of result range");const r=e[n];return r instanceof Error&&lI(`index ${n}`,r),r}if(sI.indexOf(t)>=0)return Reflect.get(e,t,n);const r=e[t];if(r instanceof Function)return function(...t){return r.apply(this===n?e:this,t)};if(!(t in e))return e.getValue.apply(this===n?e:this,[t])}return Reflect.get(e,t,n)}});return AI(a,cI(this)),a}toArray(t){const n=[];return this.forEach((r,i)=>{r instanceof Error&&lI(`index ${i}`,r),t&&r instanceof e&&(r=r.toArray(t)),n.push(r)}),n}toObject(e){const t=cI(this);return t.reduce((n,r,i)=>(gS(null!=r,`value at index ${i} unnamed`,"UNSUPPORTED_OPERATION",{operation:"toObject()"}),fI(t,this,e)),{})}slice(t,n){null==t&&(t=0),t<0&&(t+=this.length)<0&&(t=0),null==n&&(n=this.length),n<0&&(n+=this.length)<0&&(n=0),n>this.length&&(n=this.length);const r=cI(this),i=[],s=[];for(let e=t;e<n;e++)i.push(this[e]),s.push(r[e]);return new e(aI,i,s)}filter(t,n){const r=cI(this),i=[],s=[];for(let e=0;e<this.length;e++){const a=this[e];a instanceof Error&&lI(`index ${e}`,a),t.call(n,a,e,this)&&(i.push(a),s.push(r[e]))}return new e(aI,i,s)}map(e,t){const n=[];for(let r=0;r<this.length;r++){const i=this[r];i instanceof Error&&lI(`index ${r}`,i),n.push(e.call(t,i,r,this))}return n}getValue(e){const t=cI(this).indexOf(e);if(-1===t)return;const n=this[t];return n instanceof Error&&lI(`property ${JSON.stringify(e)}`,n.error),n}static fromItems(t,n){return new e(aI,t,n)}};function dI(e){const t=[],n=function(e,r){if(Array.isArray(r))for(let s in r){const a=e.slice();a.push(s);try{n(a,r[s])}catch(i){t.push({path:a,error:i})}}};return n([],e),t}function hI(e){let t=YS(e);return gS(t.length<=rI,"value out-of-bounds","BUFFER_OVERRUN",{buffer:t,length:rI,offset:t.length}),t.length!==rI&&(t=SS(NS([iI.slice(t.length%rI),t]))),t}class pI{constructor(e,t,n,r){__publicField(this,"name"),__publicField(this,"type"),__publicField(this,"localName"),__publicField(this,"dynamic"),dS(this,{name:e,type:t,localName:n,dynamic:r},{name:"string",type:"string",localName:"string",dynamic:"boolean"})}_throwError(e,t){bS(!1,e,this.localName,t)}}class mI{constructor(){__privateAdd(this,G),__privateAdd(this,D),__privateAdd(this,F),__privateSet(this,D,[]),__privateSet(this,F,0)}get data(){return NS(__privateGet(this,D))}get length(){return __privateGet(this,F)}appendWriter(e){return __privateMethod(this,G,U).call(this,SS(e.data))}writeBytes(e){let t=SS(e);const n=t.length%rI;return n&&(t=SS(NS([t,iI.slice(n)]))),__privateMethod(this,G,U).call(this,t)}writeValue(e){return __privateMethod(this,G,U).call(this,hI(e))}writeUpdatableValue(){const e=__privateGet(this,D).length;return __privateGet(this,D).push(iI),__privateSet(this,F,__privateGet(this,F)+rI),t=>{__privateGet(this,D)[e]=hI(t)}}}D=new WeakMap,F=new WeakMap,G=new WeakSet,U=function(e){return __privateGet(this,D).push(e),__privateSet(this,F,__privateGet(this,F)+e.length),e.length},L=new WeakMap,j=new WeakMap,H=new WeakMap,z=new WeakMap,q=new WeakMap,Q=new WeakSet,V=function(e){var t;if(__privateGet(this,z))return __privateMethod(t=__privateGet(this,z),Q,V).call(t,e);__privateSet(this,H,__privateGet(this,H)+e),gS(__privateGet(this,q)<1||__privateGet(this,H)<=__privateGet(this,q)*this.dataLength,`compressed ABI data exceeds inflation ratio of ${__privateGet(this,q)} ( see: https://github.com/ethers-io/ethers.js/issues/4537 )`,"BUFFER_OVERRUN",{buffer:SS(__privateGet(this,L)),offset:__privateGet(this,j),length:e,info:{bytesRead:__privateGet(this,H),dataLength:this.dataLength}})},J=function(e,t,n){let r=Math.ceil(t/rI)*rI;return __privateGet(this,j)+r>__privateGet(this,L).length&&(this.allowLoose&&n&&__privateGet(this,j)+t<=__privateGet(this,L).length?r=t:gS(!1,"data out-of-bounds","BUFFER_OVERRUN",{buffer:SS(__privateGet(this,L)),length:__privateGet(this,L).length,offset:__privateGet(this,j)+r})),__privateGet(this,L).slice(__privateGet(this,j),__privateGet(this,j)+r)};let yI=class e{constructor(e,t,n){__privateAdd(this,Q),__publicField(this,"allowLoose"),__privateAdd(this,L),__privateAdd(this,j),__privateAdd(this,H),__privateAdd(this,z),__privateAdd(this,q),dS(this,{allowLoose:!!t}),__privateSet(this,L,SS(e)),__privateSet(this,H,0),__privateSet(this,z,null),__privateSet(this,q,null!=n?n:1024),__privateSet(this,j,0)}get data(){return CS(__privateGet(this,L))}get dataLength(){return __privateGet(this,L).length}get consumed(){return __privateGet(this,j)}get bytes(){return new Uint8Array(__privateGet(this,L))}subReader(t){const n=new e(__privateGet(this,L).slice(__privateGet(this,j)+t),this.allowLoose,__privateGet(this,q));return __privateSet(n,z,this),n}readBytes(e,t){let n=__privateMethod(this,Q,J).call(this,0,e,!!t);return __privateMethod(this,Q,V).call(this,e),__privateSet(this,j,__privateGet(this,j)+n.length),n.slice(0,e)}readValue(){return VS(this.readBytes(rI))}readIndex(){return KS(this.readBytes(rI))}};function gI(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function bI(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function wI(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");gI(e.outputLen),gI(e.blockLen)}function vI(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function _I(e,t){bI(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const EI="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,kI=e=>e instanceof Uint8Array,TI=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)),SI=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),xI=(e,t)=>e<<32-t|e>>>t;
22
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw new Error("Non little-endian hardware is not supported");const II=async()=>{};async function PI(e,t,n){let r=Date.now();for(let i=0;i<e;i++){n(i);const e=Date.now()-r;e>=0&&e<t||(await II(),r+=e)}}function CI(e){if("string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),!kI(e))throw new Error("expected Uint8Array, got "+typeof e);return e}class NI{clone(){return this._cloneInto()}}const OI={}.toString;function RI(e,t){if(void 0!==t&&"[object Object]"!==OI.call(t))throw new Error("Options should be object or undefined");return Object.assign(e,t)}function BI(e){const t=t=>e().update(CI(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function MI(e=32){if(EI&&"function"==typeof EI.getRandomValues)return EI.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}let $I=class extends NI{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,wI(e);const n=CI(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,i=new Uint8Array(r);i.set(n.length>r?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(e){return vI(this),this.iHash.update(e),this}digestInto(e){vI(this),bI(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:s,outputLen:a}=this;return e.finished=r,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const DI=(e,t,n)=>new $I(e,t).update(n).digest();function FI(e,t,n,r){const{c:i,dkLen:s,DK:a,PRF:o,PRFSalt:c}=function(e,t,n,r){wI(e);const i=RI({dkLen:32,asyncTick:10},r),{c:s,dkLen:a,asyncTick:o}=i;if(gI(s),gI(a),gI(o),s<1)throw new Error("PBKDF2: iterations (c) should be >= 1");const c=CI(t),A=CI(n),l=new Uint8Array(a),f=DI.create(e,c),u=f._cloneInto().update(A);return{c:s,dkLen:a,asyncTick:o,DK:l,PRF:f,PRFSalt:u}}(e,t,n,r);let A;const l=new Uint8Array(4),f=SI(l),u=new Uint8Array(o.outputLen);for(let d=1,h=0;h<s;d++,h+=o.outputLen){const e=a.subarray(h,h+o.outputLen);f.setInt32(0,d,!1),(A=c._cloneInto(A)).update(l).digestInto(u),e.set(u.subarray(0,e.length));for(let t=1;t<i;t++){o._cloneInto(A).update(u).digestInto(u);for(let t=0;t<e.length;t++)e[t]^=u[t]}}return function(e,t,n,r,i){return e.destroy(),t.destroy(),r&&r.destroy(),i.fill(0),n}(o,c,a,A,u)}DI.create=(e,t)=>new $I(e,t);class GI extends NI{constructor(e,t,n,r){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=SI(this.buffer)}update(e){vI(this);const{view:t,buffer:n,blockLen:r}=this,i=(e=CI(e)).length;for(let s=0;s<i;){const a=Math.min(r-this.pos,i-s);if(a===r){const t=SI(e);for(;r<=i-s;s+=r)this.process(t,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){vI(this),_I(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:i}=this;let{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>r-s&&(this.process(n,0),s=0);for(let l=s;l<r;l++)t[l]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const i=BigInt(32),s=BigInt(4294967295),a=Number(n>>i&s),o=Number(n&s),c=r?4:0,A=r?0:4;e.setUint32(t+c,a,r),e.setUint32(t+A,o,r)}(n,r-8,BigInt(8*this.length),i),this.process(n,0);const a=SI(e),o=this.outputLen;if(o%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=o/4,A=this.get();if(c>A.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<c;l++)a.setUint32(4*l,A[l],i)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:i,destroyed:s,pos:a}=this;return e.length=r,e.pos=a,e.finished=i,e.destroyed=s,r%t&&e.buffer.set(n),e}}const UI=(e,t,n)=>e&t^~e&n,LI=(e,t,n)=>e&t^e&n^t&n,jI=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),HI=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),zI=new Uint32Array(64);class qI extends GI{constructor(){super(64,32,8,!1),this.A=0|HI[0],this.B=0|HI[1],this.C=0|HI[2],this.D=0|HI[3],this.E=0|HI[4],this.F=0|HI[5],this.G=0|HI[6],this.H=0|HI[7]}get(){const{A:e,B:t,C:n,D:r,E:i,F:s,G:a,H:o}=this;return[e,t,n,r,i,s,a,o]}set(e,t,n,r,i,s,a,o){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|s,this.G=0|a,this.H=0|o}process(e,t){for(let l=0;l<16;l++,t+=4)zI[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){const e=zI[l-15],t=zI[l-2],n=xI(e,7)^xI(e,18)^e>>>3,r=xI(t,17)^xI(t,19)^t>>>10;zI[l]=r+zI[l-7]+n+zI[l-16]|0}let{A:n,B:r,C:i,D:s,E:a,F:o,G:c,H:A}=this;for(let l=0;l<64;l++){const e=A+(xI(a,6)^xI(a,11)^xI(a,25))+UI(a,o,c)+jI[l]+zI[l]|0,t=(xI(n,2)^xI(n,13)^xI(n,22))+LI(n,r,i)|0;A=c,c=o,o=a,a=s+e|0,s=i,i=r,r=n,n=e+t|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,o=o+this.F|0,c=c+this.G|0,A=A+this.H|0,this.set(n,r,i,s,a,o,c,A)}roundClean(){zI.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const QI=BI(()=>new qI),VI=BigInt(2**32-1),JI=BigInt(32);function KI(e,t=!1){return t?{h:Number(e&VI),l:Number(e>>JI&VI)}:{h:0|Number(e>>JI&VI),l:0|Number(e&VI)}}function WI(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let i=0;i<e.length;i++){const{h:s,l:a}=KI(e[i],t);[n[i],r[i]]=[s,a]}return[n,r]}const YI=(e,t,n)=>e<<n|t>>>32-n,ZI=(e,t,n)=>t<<n|e>>>32-n,XI=(e,t,n)=>t<<n-32|e>>>64-n,eP=(e,t,n)=>e<<n-32|t>>>64-n,tP={fromBig:KI,split:WI,toBig:(e,t)=>BigInt(e>>>0)<<JI|BigInt(t>>>0),shrSH:(e,t,n)=>e>>>n,shrSL:(e,t,n)=>e<<32-n|t>>>n,rotrSH:(e,t,n)=>e>>>n|t<<32-n,rotrSL:(e,t,n)=>e<<32-n|t>>>n,rotrBH:(e,t,n)=>e<<64-n|t>>>n-32,rotrBL:(e,t,n)=>e>>>n-32|t<<64-n,rotr32H:(e,t)=>t,rotr32L:(e,t)=>e,rotlSH:YI,rotlSL:ZI,rotlBH:XI,rotlBL:eP,add:function(e,t,n,r){const i=(t>>>0)+(r>>>0);return{h:e+n+(i/2**32|0)|0,l:0|i}},add3L:(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),add3H:(e,t,n,r)=>t+n+r+(e/2**32|0)|0,add4L:(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),add4H:(e,t,n,r,i)=>t+n+r+i+(e/2**32|0)|0,add5H:(e,t,n,r,i,s)=>t+n+r+i+s+(e/2**32|0)|0,add5L:(e,t,n,r,i)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(i>>>0)},[nP,rP]=(()=>tP.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))))(),iP=new Uint32Array(80),sP=new Uint32Array(80);class aP extends GI{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:e,Al:t,Bh:n,Bl:r,Ch:i,Cl:s,Dh:a,Dl:o,Eh:c,El:A,Fh:l,Fl:f,Gh:u,Gl:d,Hh:h,Hl:p}=this;return[e,t,n,r,i,s,a,o,c,A,l,f,u,d,h,p]}set(e,t,n,r,i,s,a,o,c,A,l,f,u,d,h,p){this.Ah=0|e,this.Al=0|t,this.Bh=0|n,this.Bl=0|r,this.Ch=0|i,this.Cl=0|s,this.Dh=0|a,this.Dl=0|o,this.Eh=0|c,this.El=0|A,this.Fh=0|l,this.Fl=0|f,this.Gh=0|u,this.Gl=0|d,this.Hh=0|h,this.Hl=0|p}process(e,t){for(let g=0;g<16;g++,t+=4)iP[g]=e.getUint32(t),sP[g]=e.getUint32(t+=4);for(let g=16;g<80;g++){const e=0|iP[g-15],t=0|sP[g-15],n=tP.rotrSH(e,t,1)^tP.rotrSH(e,t,8)^tP.shrSH(e,t,7),r=tP.rotrSL(e,t,1)^tP.rotrSL(e,t,8)^tP.shrSL(e,t,7),i=0|iP[g-2],s=0|sP[g-2],a=tP.rotrSH(i,s,19)^tP.rotrBH(i,s,61)^tP.shrSH(i,s,6),o=tP.rotrSL(i,s,19)^tP.rotrBL(i,s,61)^tP.shrSL(i,s,6),c=tP.add4L(r,o,sP[g-7],sP[g-16]),A=tP.add4H(c,n,a,iP[g-7],iP[g-16]);iP[g]=0|A,sP[g]=0|c}let{Ah:n,Al:r,Bh:i,Bl:s,Ch:a,Cl:o,Dh:c,Dl:A,Eh:l,El:f,Fh:u,Fl:d,Gh:h,Gl:p,Hh:m,Hl:y}=this;for(let g=0;g<80;g++){const e=tP.rotrSH(l,f,14)^tP.rotrSH(l,f,18)^tP.rotrBH(l,f,41),t=tP.rotrSL(l,f,14)^tP.rotrSL(l,f,18)^tP.rotrBL(l,f,41),b=l&u^~l&h,w=f&d^~f&p,v=tP.add5L(y,t,w,rP[g],sP[g]),_=tP.add5H(v,m,e,b,nP[g],iP[g]),E=0|v,k=tP.rotrSH(n,r,28)^tP.rotrBH(n,r,34)^tP.rotrBH(n,r,39),T=tP.rotrSL(n,r,28)^tP.rotrBL(n,r,34)^tP.rotrBL(n,r,39),S=n&i^n&a^i&a,x=r&s^r&o^s&o;m=0|h,y=0|p,h=0|u,p=0|d,u=0|l,d=0|f,({h:l,l:f}=tP.add(0|c,0|A,0|_,0|E)),c=0|a,A=0|o,a=0|i,o=0|s,i=0|n,s=0|r;const I=tP.add3L(E,T,x);n=tP.add3H(I,_,k,S),r=0|I}({h:n,l:r}=tP.add(0|this.Ah,0|this.Al,0|n,0|r)),({h:i,l:s}=tP.add(0|this.Bh,0|this.Bl,0|i,0|s)),({h:a,l:o}=tP.add(0|this.Ch,0|this.Cl,0|a,0|o)),({h:c,l:A}=tP.add(0|this.Dh,0|this.Dl,0|c,0|A)),({h:l,l:f}=tP.add(0|this.Eh,0|this.El,0|l,0|f)),({h:u,l:d}=tP.add(0|this.Fh,0|this.Fl,0|u,0|d)),({h:h,l:p}=tP.add(0|this.Gh,0|this.Gl,0|h,0|p)),({h:m,l:y}=tP.add(0|this.Hh,0|this.Hl,0|m,0|y)),this.set(n,r,i,s,a,o,c,A,l,f,u,d,h,p,m,y)}roundClean(){iP.fill(0),sP.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const oP=BI(()=>new aP),cP=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof globalThis)return globalThis;throw new Error("unable to locate global object")}(),AP=cP.crypto||cP.msCrypto;function lP(e){switch(e){case"sha256":return QI.create();case"sha512":return oP.create()}bS(!1,"invalid hashing algorithm name","algorithm",e)}let fP=!1;const uP=function(e,t,n){return function(e,t){const n={sha256:QI,sha512:oP}[e];return bS(null!=n,"invalid hmac algorithm","algorithm",e),DI.create(n,t)}(e,t).update(n).digest()};let dP=uP;function hP(e,t,n){const r=TS(t,"key"),i=TS(n,"data");return CS(dP(e,r,i))}hP._=uP,hP.lock=function(){fP=!0},hP.register=function(e){if(fP)throw new Error("computeHmac is locked");dP=e},Object.freeze(hP);const[pP,mP,yP]=[[],[],[]],gP=BigInt(0),bP=BigInt(1),wP=BigInt(2),vP=BigInt(7),_P=BigInt(256),EP=BigInt(113);for(let uH=0,dH=bP,hH=1,pH=0;uH<24;uH++){[hH,pH]=[pH,(2*hH+3*pH)%5],pP.push(2*(5*pH+hH)),mP.push((uH+1)*(uH+2)/2%64);let e=gP;for(let t=0;t<7;t++)dH=(dH<<bP^(dH>>vP)*EP)%_P,dH&wP&&(e^=bP<<(bP<<BigInt(t))-bP);yP.push(e)}const[kP,TP]=WI(yP,!0),SP=(e,t,n)=>n>32?XI(e,t,n):YI(e,t,n),xP=(e,t,n)=>n>32?eP(e,t,n):ZI(e,t,n);class IP extends NI{constructor(e,t,n,r=!1,i=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.rounds=i,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,gI(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=TI(this.state)}keccak(){!function(e,t=24){const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let r=0;r<10;r++)n[r]=e[r]^e[r+10]^e[r+20]^e[r+30]^e[r+40];for(let r=0;r<10;r+=2){const t=(r+8)%10,i=(r+2)%10,s=n[i],a=n[i+1],o=SP(s,a,1)^n[t],c=xP(s,a,1)^n[t+1];for(let n=0;n<50;n+=10)e[r+n]^=o,e[r+n+1]^=c}let t=e[2],i=e[3];for(let n=0;n<24;n++){const r=mP[n],s=SP(t,i,r),a=xP(t,i,r),o=pP[n];t=e[o],i=e[o+1],e[o]=s,e[o+1]=a}for(let r=0;r<50;r+=10){for(let t=0;t<10;t++)n[t]=e[r+t];for(let t=0;t<10;t++)e[r+t]^=~n[(t+2)%10]&n[(t+4)%10]}e[0]^=kP[r],e[1]^=TP[r]}n.fill(0)}(this.state32,this.rounds),this.posOut=0,this.pos=0}update(e){vI(this);const{blockLen:t,state:n}=this,r=(e=CI(e)).length;for(let i=0;i<r;){const s=Math.min(t-this.pos,r-i);for(let t=0;t<s;t++)n[this.pos++]^=e[i++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,128&t&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){vI(this,!1),bI(e),this.finish();const t=this.state,{blockLen:n}=this;for(let r=0,i=e.length;r<i;){this.posOut>=n&&this.keccak();const s=Math.min(n-this.posOut,i-r);e.set(t.subarray(this.posOut,this.posOut+s),r),this.posOut+=s,r+=s}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return gI(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(_I(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){const{blockLen:t,suffix:n,outputLen:r,rounds:i,enableXOF:s}=this;return e||(e=new IP(t,n,r,s,i)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=i,e.suffix=n,e.outputLen=r,e.enableXOF=s,e.destroyed=this.destroyed,e}}const PP=(()=>BI(()=>new IP(136,1,32)))();let CP=!1;const NP=function(e){return PP(e)};let OP=NP;function RP(e){const t=TS(e,"data");return CS(OP(t))}RP._=NP,RP.lock=function(){CP=!0},RP.register=function(e){if(CP)throw new TypeError("keccak256 is locked");OP=e},Object.freeze(RP);const BP=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),MP=Uint8Array.from({length:16},(e,t)=>t);let $P=[MP],DP=[MP.map(e=>(9*e+5)%16)];for(let uH=0;uH<4;uH++)for(let e of[$P,DP])e.push(e[uH].map(e=>BP[e]));const FP=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>new Uint8Array(e)),GP=$P.map((e,t)=>e.map(e=>FP[t][e])),UP=DP.map((e,t)=>e.map(e=>FP[t][e])),LP=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),jP=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]),HP=(e,t)=>e<<t|e>>>32-t;function zP(e,t,n,r){return 0===e?t^n^r:1===e?t&n|~t&r:2===e?(t|~n)^r:3===e?t&r|n&~r:t^(n|~r)}const qP=new Uint32Array(16);class QP extends GI{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:e,h1:t,h2:n,h3:r,h4:i}=this;return[e,t,n,r,i]}set(e,t,n,r,i){this.h0=0|e,this.h1=0|t,this.h2=0|n,this.h3=0|r,this.h4=0|i}process(e,t){for(let u=0;u<16;u++,t+=4)qP[u]=e.getUint32(t,!0);let n=0|this.h0,r=n,i=0|this.h1,s=i,a=0|this.h2,o=a,c=0|this.h3,A=c,l=0|this.h4,f=l;for(let u=0;u<5;u++){const e=4-u,t=LP[u],d=jP[u],h=$P[u],p=DP[u],m=GP[u],y=UP[u];for(let r=0;r<16;r++){const e=HP(n+zP(u,i,a,c)+qP[h[r]]+t,m[r])+l|0;n=l,l=c,c=0|HP(a,10),a=i,i=e}for(let n=0;n<16;n++){const t=HP(r+zP(e,s,o,A)+qP[p[n]]+d,y[n])+f|0;r=f,f=A,A=0|HP(o,10),o=s,s=t}}this.set(this.h1+a+A|0,this.h2+c+f|0,this.h3+l+r|0,this.h4+n+s|0,this.h0+i+o|0)}roundClean(){qP.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}const VP=BI(()=>new QP);let JP=!1;const KP=function(e){return VP(e)};let WP=KP;function YP(e){const t=TS(e,"data");return CS(WP(t))}YP._=KP,YP.lock=function(){JP=!0},YP.register=function(e){if(JP)throw new TypeError("ripemd160 is locked");WP=e},Object.freeze(YP);let ZP=!1;const XP=function(e,t,n,r,i){return function(e,t,n,r,i){const s={sha256:QI,sha512:oP}[i];return bS(null!=s,"invalid pbkdf2 algorithm","algorithm",i),FI(s,e,t,{c:n,dkLen:r})}(e,t,n,r,i)};let eC=XP;function tC(e,t,n,r,i){const s=TS(e,"password"),a=TS(t,"salt");return CS(eC(s,a,n,r,i))}tC._=XP,tC.lock=function(){ZP=!0},tC.register=function(e){if(ZP)throw new Error("pbkdf2 is locked");eC=e},Object.freeze(tC);let nC=!1;const rC=function(e){return new Uint8Array(function(e){gS(null!=AP,"platform does not support secure random numbers","UNSUPPORTED_OPERATION",{operation:"randomBytes"}),bS(Number.isInteger(e)&&e>0&&e<=1024,"invalid length","length",e);const t=new Uint8Array(e);return AP.getRandomValues(t),t}(e))};let iC=rC;function sC(e){return iC(e)}sC._=rC,sC.lock=function(){nC=!0},sC.register=function(e){if(nC)throw new Error("randomBytes is locked");iC=e},Object.freeze(sC);const aC=(e,t)=>e<<t|e>>>32-t;function oC(e,t,n,r,i,s){let a=e[t++]^n[r++],o=e[t++]^n[r++],c=e[t++]^n[r++],A=e[t++]^n[r++],l=e[t++]^n[r++],f=e[t++]^n[r++],u=e[t++]^n[r++],d=e[t++]^n[r++],h=e[t++]^n[r++],p=e[t++]^n[r++],m=e[t++]^n[r++],y=e[t++]^n[r++],g=e[t++]^n[r++],b=e[t++]^n[r++],w=e[t++]^n[r++],v=e[t++]^n[r++],_=a,E=o,k=c,T=A,S=l,x=f,I=u,P=d,C=h,N=p,O=m,R=y,B=g,M=b,$=w,D=v;for(let F=0;F<8;F+=2)S^=aC(_+B|0,7),C^=aC(S+_|0,9),B^=aC(C+S|0,13),_^=aC(B+C|0,18),N^=aC(x+E|0,7),M^=aC(N+x|0,9),E^=aC(M+N|0,13),x^=aC(E+M|0,18),$^=aC(O+I|0,7),k^=aC($+O|0,9),I^=aC(k+$|0,13),O^=aC(I+k|0,18),T^=aC(D+R|0,7),P^=aC(T+D|0,9),R^=aC(P+T|0,13),D^=aC(R+P|0,18),E^=aC(_+T|0,7),k^=aC(E+_|0,9),T^=aC(k+E|0,13),_^=aC(T+k|0,18),I^=aC(x+S|0,7),P^=aC(I+x|0,9),S^=aC(P+I|0,13),x^=aC(S+P|0,18),R^=aC(O+N|0,7),C^=aC(R+O|0,9),N^=aC(C+R|0,13),O^=aC(N+C|0,18),B^=aC(D+$|0,7),M^=aC(B+D|0,9),$^=aC(M+B|0,13),D^=aC($+M|0,18);i[s++]=a+_|0,i[s++]=o+E|0,i[s++]=c+k|0,i[s++]=A+T|0,i[s++]=l+S|0,i[s++]=f+x|0,i[s++]=u+I|0,i[s++]=d+P|0,i[s++]=h+C|0,i[s++]=p+N|0,i[s++]=m+O|0,i[s++]=y+R|0,i[s++]=g+B|0,i[s++]=b+M|0,i[s++]=w+$|0,i[s++]=v+D|0}function cC(e,t,n,r,i){let s=r+0,a=r+16*i;for(let o=0;o<16;o++)n[a+o]=e[t+16*(2*i-1)+o];for(let o=0;o<i;o++,s+=16,t+=16)oC(n,a,e,t,n,s),o>0&&(a+=16),oC(n,s,e,t+=16,n,a)}function AC(e,t,n){const r=RI({dkLen:32,asyncTick:10,maxmem:1073742848},n),{N:i,r:s,p:a,dkLen:o,asyncTick:c,maxmem:A,onProgress:l}=r;if(gI(i),gI(s),gI(a),gI(o),gI(c),gI(A),void 0!==l&&"function"!=typeof l)throw new Error("progressCb should be function");const f=128*s,u=f/4;if(i<=1||i&i-1||i>=2**(f/8)||i>2**32)throw new Error("Scrypt: N must be larger than 1, a power of 2, less than 2^(128 * r / 8) and less than 2^32");if(a<0||a>137438953440/f)throw new Error("Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)");if(o<0||o>137438953440)throw new Error("Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32");const d=f*(i+a);if(d>A)throw new Error(`Scrypt: parameters too large, ${d} (128 * r * (N + p)) > ${A} (maxmem)`);const h=FI(QI,e,t,{c:1,dkLen:f*a}),p=TI(h),m=TI(new Uint8Array(f*i)),y=TI(new Uint8Array(f));let g=()=>{};if(l){const e=2*i*a,t=Math.max(Math.floor(e/1e4),1);let n=0;g=()=>{n++,!l||n%t&&n!==e||l(n/e)}}return{N:i,r:s,p:a,dkLen:o,blockSize32:u,V:m,B32:p,B:h,tmp:y,blockMixCb:g,asyncTick:c}}function lC(e,t,n,r,i){const s=FI(QI,e,n,{c:1,dkLen:t});return n.fill(0),r.fill(0),i.fill(0),s}let fC=!1,uC=!1;const dC=async function(e,t,n,r,i,s,a){return await async function(e,t,n){const{N:r,r:i,p:s,dkLen:a,blockSize32:o,V:c,B32:A,B:l,tmp:f,blockMixCb:u,asyncTick:d}=AC(e,t,n);for(let h=0;h<s;h++){const e=o*h;for(let n=0;n<o;n++)c[n]=A[e+n];let t=0;await PI(r-1,d,()=>{cC(c,t,c,t+=o,i),u()}),cC(c,(r-1)*o,A,e,i),u(),await PI(r,d,()=>{const t=A[e+o-16]%r;for(let n=0;n<o;n++)f[n]=A[e+n]^c[t*o+n];cC(f,0,A,e,i),u()})}return lC(e,a,l,c,f)}(e,t,{N:n,r:r,p:i,dkLen:s,onProgress:a})},hC=function(e,t,n,r,i,s){return function(e,t,n){const{N:r,r:i,p:s,dkLen:a,blockSize32:o,V:c,B32:A,B:l,tmp:f,blockMixCb:u}=AC(e,t,n);for(let d=0;d<s;d++){const e=o*d;for(let t=0;t<o;t++)c[t]=A[e+t];for(let t=0,n=0;t<r-1;t++)cC(c,n,c,n+=o,i),u();cC(c,(r-1)*o,A,e,i),u();for(let t=0;t<r;t++){const t=A[e+o-16]%r;for(let n=0;n<o;n++)f[n]=A[e+n]^c[t*o+n];cC(f,0,A,e,i),u()}}return lC(e,a,l,c,f)}(e,t,{N:n,r:r,p:i,dkLen:s})};let pC=dC,mC=hC;async function yC(e,t,n,r,i,s,a){const o=TS(e,"passwd"),c=TS(t,"salt");return CS(await pC(o,c,n,r,i,s,a))}function gC(e,t,n,r,i,s){const a=TS(e,"passwd"),o=TS(t,"salt");return CS(mC(a,o,n,r,i,s))}yC._=dC,yC.lock=function(){uC=!0},yC.register=function(e){if(uC)throw new Error("scrypt is locked");pC=e},Object.freeze(yC),gC._=hC,gC.lock=function(){fC=!0},gC.register=function(e){if(fC)throw new Error("scryptSync is locked");mC=e},Object.freeze(gC);const bC=function(e){return lP("sha256").update(e).digest()},wC=function(e){return lP("sha512").update(e).digest()};let vC=bC,_C=wC,EC=!1,kC=!1;function TC(e){const t=TS(e,"data");return CS(vC(t))}function SC(e){const t=TS(e,"data");return CS(_C(t))}TC._=bC,TC.lock=function(){EC=!0},TC.register=function(e){if(EC)throw new Error("sha256 is locked");vC=e},Object.freeze(TC),SC._=wC,SC.lock=function(){kC=!0},SC.register=function(e){if(kC)throw new Error("sha512 is locked");_C=e},Object.freeze(TC);
23
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
24
+ const xC=BigInt(0),IC=BigInt(1),PC=BigInt(2),CC=e=>e instanceof Uint8Array,NC=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function OC(e){if(!CC(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=NC[e[n]];return t}function RC(e){const t=e.toString(16);return 1&t.length?`0${t}`:t}function BC(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return BigInt(""===e?"0":`0x${e}`)}function MC(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let r=0;r<n.length;r++){const t=2*r,i=e.slice(t,t+2),s=Number.parseInt(i,16);if(Number.isNaN(s)||s<0)throw new Error("Invalid byte sequence");n[r]=s}return n}function $C(e){return BC(OC(e))}function DC(e){if(!CC(e))throw new Error("Uint8Array expected");return BC(OC(Uint8Array.from(e).reverse()))}function FC(e,t){return MC(e.toString(16).padStart(2*t,"0"))}function GC(e,t){return FC(e,t).reverse()}function UC(e,t,n){let r;if("string"==typeof t)try{r=MC(t)}catch(s){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${s}`)}else{if(!CC(t))throw new Error(`${e} must be hex string or Uint8Array`);r=Uint8Array.from(t)}const i=r.length;if("number"==typeof n&&i!==n)throw new Error(`${e} expected ${n} bytes, got ${i}`);return r}function LC(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!CC(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}const jC=e=>(PC<<BigInt(e-1))-IC,HC=e=>new Uint8Array(e),zC=e=>Uint8Array.from(e);function qC(e,t,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");let r=HC(e),i=HC(e),s=0;const a=()=>{r.fill(1),i.fill(0),s=0},o=(...e)=>n(i,r,...e),c=(e=HC())=>{i=o(zC([0]),e),r=o(),0!==e.length&&(i=o(zC([1]),e),r=o())},A=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){r=o();const t=r.slice();n.push(t),e+=r.length}return LC(...n)};return(e,t)=>{let n;for(a(),c(e);!(n=t(A()));)c();return a(),n}}const QC={bigint:e=>"bigint"==typeof e,function:e=>"function"==typeof e,boolean:e=>"boolean"==typeof e,string:e=>"string"==typeof e,stringOrUint8Array:e=>"string"==typeof e||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>"function"==typeof e&&Number.isSafeInteger(e.outputLen)};function VC(e,t,n={}){const r=(t,n,r)=>{const i=QC[n];if("function"!=typeof i)throw new Error(`Invalid validator "${n}", expected function`);const s=e[t];if(!(r&&void 0===s||i(s,e)))throw new Error(`Invalid param ${String(t)}=${s} (${typeof s}), expected ${n}`)};for(const[i,s]of Object.entries(t))r(i,s,!1);for(const[i,s]of Object.entries(n))r(i,s,!0);return e}const JC=Object.freeze(Object.defineProperty({__proto__:null,bitGet:function(e,t){return e>>BigInt(t)&IC},bitLen:function(e){let t;for(t=0;e>xC;e>>=IC,t+=1);return t},bitMask:jC,bitSet:(e,t,n)=>e|(n?IC:xC)<<BigInt(t),bytesToHex:OC,bytesToNumberBE:$C,bytesToNumberLE:DC,concatBytes:LC,createHmacDrbg:qC,ensureBytes:UC,equalBytes: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},hexToBytes:MC,hexToNumber:BC,numberToBytesBE:FC,numberToBytesLE:GC,numberToHexUnpadded:RC,numberToVarBytesBE:function(e){return MC(RC(e))},utf8ToBytes:function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))},validateObject:VC},Symbol.toStringTag,{value:"Module"})),KC=BigInt(0),WC=BigInt(1),YC=BigInt(2),ZC=BigInt(3),XC=BigInt(4),eN=BigInt(5),tN=BigInt(8);
25
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function nN(e,t){const n=e%t;return n>=KC?n:t+n}function rN(e,t,n){if(n<=KC||t<KC)throw new Error("Expected power/modulo > 0");if(n===WC)return KC;let r=WC;for(;t>KC;)t&WC&&(r=r*e%n),e=e*e%n,t>>=WC;return r}function iN(e,t,n){let r=e;for(;t-- >KC;)r*=r,r%=n;return r}function sN(e,t){if(e===KC||t<=KC)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=nN(e,t),r=t,i=KC,s=WC;for(;n!==KC;){const e=r%n,t=i-s*(r/n);r=n,n=e,i=s,s=t}if(r!==WC)throw new Error("invert: does not exist");return nN(i,t)}BigInt(9),BigInt(16);const aN=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function oN(e,t){const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function cN(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function AN(e){const t=cN(e);return t+Math.ceil(t/2)}
26
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
27
+ const lN=BigInt(0),fN=BigInt(1);function uN(e){return VC(e.Fp,aN.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"})),VC(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...oN(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}
28
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const{bytesToNumberBE:dN,hexToBytes:hN}=JC,pN={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(e){const{Err:t}=pN;if(e.length<2||2!==e[0])throw new t("Invalid signature integer tag");const n=e[1],r=e.subarray(2,n+2);if(!n||r.length!==n)throw new t("Invalid signature integer: wrong length");if(128&r[0])throw new t("Invalid signature integer: negative");if(0===r[0]&&!(128&r[1]))throw new t("Invalid signature integer: unnecessary leading zero");return{d:dN(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=pN,n="string"==typeof e?hN(e):e;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||48!=n[0])throw new t("Invalid signature tag");if(n[1]!==r-2)throw new t("Invalid signature: incorrect length");const{d:i,l:s}=pN._parseInt(n.subarray(2)),{d:a,l:o}=pN._parseInt(s);if(o.length)throw new t("Invalid signature: left bytes after parsing");return{r:i,s:a}},hexFromSig(e){const t=e=>8&Number.parseInt(e[0],16)?"00"+e:e,n=e=>{const t=e.toString(16);return 1&t.length?`0${t}`:t},r=t(n(e.s)),i=t(n(e.r)),s=r.length/2,a=i.length/2,o=n(s),c=n(a);return`30${n(a+s+4)}02${c}${i}02${o}${r}`}},mN=BigInt(0),yN=BigInt(1);BigInt(2);const gN=BigInt(3);function bN(e){const t=function(e){const t=uN(e);return VC(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}(e),{Fp:n,n:r}=t,i=n.BYTES+1,s=2*n.BYTES+1;function a(e){return nN(e,r)}function o(e){return sN(e,r)}const{ProjectivePoint:c,normPrivateKeyToScalar:A,weierstrassEquation:l,isWithinCurveOrder:f}=function(e){const t=function(e){const t=uN(e);VC(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:i}=t;if(n){if(!r.eql(i,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if("object"!=typeof n||"bigint"!=typeof n.beta||"function"!=typeof n.splitScalar)throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}(e),{Fp:n}=t,r=t.toBytes||((e,t,r)=>{const i=t.toAffine();return LC(Uint8Array.from([4]),n.toBytes(i.x),n.toBytes(i.y))}),i=t.fromBytes||(e=>{const t=e.subarray(1);return{x:n.fromBytes(t.subarray(0,n.BYTES)),y:n.fromBytes(t.subarray(n.BYTES,2*n.BYTES))}});function s(e){const{a:r,b:i}=t,s=n.sqr(e),a=n.mul(s,e);return n.add(n.add(a,n.mul(e,r)),i)}if(!n.eql(n.sqr(t.Gy),s(t.Gx)))throw new Error("bad generator point: equation left != right");function a(e){return"bigint"==typeof e&&mN<e&&e<t.n}function o(e){if(!a(e))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(e){const{allowedPrivateKeyLengths:n,nByteLength:r,wrapPrivateKey:i,n:s}=t;if(n&&"bigint"!=typeof e){if(e instanceof Uint8Array&&(e=OC(e)),"string"!=typeof e||!n.includes(e.length))throw new Error("Invalid key");e=e.padStart(2*r,"0")}let a;try{a="bigint"==typeof e?e:$C(UC("private key",e,r))}catch(c){throw new Error(`private key must be ${r} bytes, hex or bigint, not ${typeof e}`)}return i&&(a=nN(a,s)),o(a),a}const A=new Map;function l(e){if(!(e instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(e,t,r){if(this.px=e,this.py=t,this.pz=r,null==e||!n.isValid(e))throw new Error("x required");if(null==t||!n.isValid(t))throw new Error("y required");if(null==r||!n.isValid(r))throw new Error("z required")}static fromAffine(e){const{x:t,y:r}=e||{};if(!e||!n.isValid(t)||!n.isValid(r))throw new Error("invalid affine point");if(e instanceof f)throw new Error("projective point not allowed");const i=e=>n.eql(e,n.ZERO);return i(t)&&i(r)?f.ZERO:new f(t,r,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(e){const t=n.invertBatch(e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(f.fromAffine)}static fromHex(e){const t=f.fromAffine(i(UC("pointHex",e)));return t.assertValidity(),t}static fromPrivateKey(e){return f.BASE.multiply(c(e))}_setWindowSize(e){this._WINDOW_SIZE=e,A.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:e,y:r}=this.toAffine();if(!n.isValid(e)||!n.isValid(r))throw new Error("bad point: x or y not FE");const i=n.sqr(r),a=s(e);if(!n.eql(i,a))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:e}=this.toAffine();if(n.isOdd)return!n.isOdd(e);throw new Error("Field doesn't support isOdd")}equals(e){l(e);const{px:t,py:r,pz:i}=this,{px:s,py:a,pz:o}=e,c=n.eql(n.mul(t,o),n.mul(s,i)),A=n.eql(n.mul(r,o),n.mul(a,i));return c&&A}negate(){return new f(this.px,n.neg(this.py),this.pz)}double(){const{a:e,b:r}=t,i=n.mul(r,gN),{px:s,py:a,pz:o}=this;let c=n.ZERO,A=n.ZERO,l=n.ZERO,u=n.mul(s,s),d=n.mul(a,a),h=n.mul(o,o),p=n.mul(s,a);return p=n.add(p,p),l=n.mul(s,o),l=n.add(l,l),c=n.mul(e,l),A=n.mul(i,h),A=n.add(c,A),c=n.sub(d,A),A=n.add(d,A),A=n.mul(c,A),c=n.mul(p,c),l=n.mul(i,l),h=n.mul(e,h),p=n.sub(u,h),p=n.mul(e,p),p=n.add(p,l),l=n.add(u,u),u=n.add(l,u),u=n.add(u,h),u=n.mul(u,p),A=n.add(A,u),h=n.mul(a,o),h=n.add(h,h),u=n.mul(h,p),c=n.sub(c,u),l=n.mul(h,d),l=n.add(l,l),l=n.add(l,l),new f(c,A,l)}add(e){l(e);const{px:r,py:i,pz:s}=this,{px:a,py:o,pz:c}=e;let A=n.ZERO,u=n.ZERO,d=n.ZERO;const h=t.a,p=n.mul(t.b,gN);let m=n.mul(r,a),y=n.mul(i,o),g=n.mul(s,c),b=n.add(r,i),w=n.add(a,o);b=n.mul(b,w),w=n.add(m,y),b=n.sub(b,w),w=n.add(r,s);let v=n.add(a,c);return w=n.mul(w,v),v=n.add(m,g),w=n.sub(w,v),v=n.add(i,s),A=n.add(o,c),v=n.mul(v,A),A=n.add(y,g),v=n.sub(v,A),d=n.mul(h,w),A=n.mul(p,g),d=n.add(A,d),A=n.sub(y,d),d=n.add(y,d),u=n.mul(A,d),y=n.add(m,m),y=n.add(y,m),g=n.mul(h,g),w=n.mul(p,w),y=n.add(y,g),g=n.sub(m,g),g=n.mul(h,g),w=n.add(w,g),m=n.mul(y,w),u=n.add(u,m),m=n.mul(v,w),A=n.mul(b,A),A=n.sub(A,m),m=n.mul(b,y),d=n.mul(v,d),d=n.add(d,m),new f(A,u,d)}subtract(e){return this.add(e.negate())}is0(){return this.equals(f.ZERO)}wNAF(e){return d.wNAFCached(this,A,e,e=>{const t=n.invertBatch(e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(f.fromAffine)})}multiplyUnsafe(e){const r=f.ZERO;if(e===mN)return r;if(o(e),e===yN)return this;const{endo:i}=t;if(!i)return d.unsafeLadder(this,e);let{k1neg:s,k1:a,k2neg:c,k2:A}=i.splitScalar(e),l=r,u=r,h=this;for(;a>mN||A>mN;)a&yN&&(l=l.add(h)),A&yN&&(u=u.add(h)),h=h.double(),a>>=yN,A>>=yN;return s&&(l=l.negate()),c&&(u=u.negate()),u=new f(n.mul(u.px,i.beta),u.py,u.pz),l.add(u)}multiply(e){o(e);let r,i,s=e;const{endo:a}=t;if(a){const{k1neg:e,k1:t,k2neg:o,k2:c}=a.splitScalar(s);let{p:A,f:l}=this.wNAF(t),{p:u,f:h}=this.wNAF(c);A=d.constTimeNegate(e,A),u=d.constTimeNegate(o,u),u=new f(n.mul(u.px,a.beta),u.py,u.pz),r=A.add(u),i=l.add(h)}else{const{p:e,f:t}=this.wNAF(s);r=e,i=t}return f.normalizeZ([r,i])[0]}multiplyAndAddUnsafe(e,t,n){const r=f.BASE,i=(e,t)=>t!==mN&&t!==yN&&e.equals(r)?e.multiply(t):e.multiplyUnsafe(t),s=i(this,t).add(i(e,n));return s.is0()?void 0:s}toAffine(e){const{px:t,py:r,pz:i}=this,s=this.is0();null==e&&(e=s?n.ONE:n.inv(i));const a=n.mul(t,e),o=n.mul(r,e),c=n.mul(i,e);if(s)return{x:n.ZERO,y:n.ZERO};if(!n.eql(c,n.ONE))throw new Error("invZ was invalid");return{x:a,y:o}}isTorsionFree(){const{h:e,isTorsionFree:n}=t;if(e===yN)return!0;if(n)return n(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:e,clearCofactor:n}=t;return e===yN?this:n?n(f,this):this.multiplyUnsafe(t.h)}toRawBytes(e=!0){return this.assertValidity(),r(f,this,e)}toHex(e=!0){return OC(this.toRawBytes(e))}}f.BASE=new f(t.Gx,t.Gy,n.ONE),f.ZERO=new f(n.ZERO,n.ONE,n.ZERO);const u=t.nBitLength,d=function(e,t){const n=(e,t)=>{const n=t.negate();return e?n:t},r=e=>({windows:Math.ceil(t/e)+1,windowSize:2**(e-1)});return{constTimeNegate:n,unsafeLadder(t,n){let r=e.ZERO,i=t;for(;n>lN;)n&fN&&(r=r.add(i)),i=i.double(),n>>=fN;return r},precomputeWindow(e,t){const{windows:n,windowSize:i}=r(t),s=[];let a=e,o=a;for(let r=0;r<n;r++){o=a,s.push(o);for(let e=1;e<i;e++)o=o.add(a),s.push(o);a=o.double()}return s},wNAF(t,i,s){const{windows:a,windowSize:o}=r(t);let c=e.ZERO,A=e.BASE;const l=BigInt(2**t-1),f=2**t,u=BigInt(t);for(let e=0;e<a;e++){const t=e*o;let r=Number(s&l);s>>=u,r>o&&(r-=f,s+=fN);const a=t,d=t+Math.abs(r)-1,h=e%2!=0,p=r<0;0===r?A=A.add(n(h,i[a])):c=c.add(n(p,i[d]))}return{p:c,f:A}},wNAFCached(e,t,n,r){const i=e._WINDOW_SIZE||1;let s=t.get(e);return s||(s=this.precomputeWindow(e,i),1!==i&&t.set(e,r(s))),this.wNAF(i,s,n)}}}(f,t.endo?Math.ceil(u/2):u);return{CURVE:t,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:s,isWithinCurveOrder:a}}({...t,toBytes(e,t,r){const i=t.toAffine(),s=n.toBytes(i.x),a=LC;return r?a(Uint8Array.from([t.hasEvenY()?2:3]),s):a(Uint8Array.from([4]),s,n.toBytes(i.y))},fromBytes(e){const t=e.length,r=e[0],a=e.subarray(1);if(t!==i||2!==r&&3!==r){if(t===s&&4===r)return{x:n.fromBytes(a.subarray(0,n.BYTES)),y:n.fromBytes(a.subarray(n.BYTES,2*n.BYTES))};throw new Error(`Point of length ${t} was invalid. Expected ${i} compressed bytes or ${s} uncompressed bytes`)}{const e=$C(a);if(!(mN<(o=e)&&o<n.ORDER))throw new Error("Point is not on curve");const t=l(e);let i=n.sqrt(t);return!(1&~r)!=((i&yN)===yN)&&(i=n.neg(i)),{x:e,y:i}}var o}}),u=e=>OC(FC(e,t.nByteLength));function d(e){return e>r>>yN}const h=(e,t,n)=>$C(e.slice(t,n));class p{constructor(e,t,n){this.r=e,this.s=t,this.recovery=n,this.assertValidity()}static fromCompact(e){const n=t.nByteLength;return e=UC("compactSignature",e,2*n),new p(h(e,0,n),h(e,n,2*n))}static fromDER(e){const{r:t,s:n}=pN.toSig(UC("DER",e));return new p(t,n)}assertValidity(){if(!f(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!f(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(e){return new p(this.r,this.s,e)}recoverPublicKey(e){const{r:r,s:i,recovery:s}=this,A=b(UC("msgHash",e));if(null==s||![0,1,2,3].includes(s))throw new Error("recovery id invalid");const l=2===s||3===s?r+t.n:r;if(l>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const f=1&s?"03":"02",d=c.fromHex(f+u(l)),h=o(l),p=a(-A*h),m=a(i*h),y=c.BASE.multiplyAndAddUnsafe(d,p,m);if(!y)throw new Error("point at infinify");return y.assertValidity(),y}hasHighS(){return d(this.s)}normalizeS(){return this.hasHighS()?new p(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return MC(this.toDERHex())}toDERHex(){return pN.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return MC(this.toCompactHex())}toCompactHex(){return u(this.r)+u(this.s)}}const m={isValidPrivateKey(e){try{return A(e),!0}catch(t){return!1}},normPrivateKeyToScalar:A,randomPrivateKey:()=>{const e=AN(t.n);return function(e,t,n=!1){const r=e.length,i=cN(t),s=AN(t);if(r<16||r<s||r>1024)throw new Error(`expected ${s}-1024 bytes of input, got ${r}`);const a=nN(n?$C(e):DC(e),t-WC)+WC;return n?GC(a,i):FC(a,i)}(t.randomBytes(e),t.n)},precompute:(e=8,t=c.BASE)=>(t._setWindowSize(e),t.multiply(BigInt(3)),t)};function y(e){const t=e instanceof Uint8Array,n="string"==typeof e,r=(t||n)&&e.length;return t?r===i||r===s:n?r===2*i||r===2*s:e instanceof c}const g=t.bits2int||function(e){const n=$C(e),r=8*e.length-t.nBitLength;return r>0?n>>BigInt(r):n},b=t.bits2int_modN||function(e){return a(g(e))},w=jC(t.nBitLength);function v(e){if("bigint"!=typeof e)throw new Error("bigint expected");if(!(mN<=e&&e<w))throw new Error(`bigint expected < 2^${t.nBitLength}`);return FC(e,t.nByteLength)}const _={lowS:t.lowS,prehash:!1},E={lowS:t.lowS,prehash:!1};return c.BASE._setWindowSize(8),{CURVE:t,getPublicKey:function(e,t=!0){return c.fromPrivateKey(e).toRawBytes(t)},getSharedSecret:function(e,t,n=!0){if(y(e))throw new Error("first arg must be private key");if(!y(t))throw new Error("second arg must be public key");return c.fromHex(t).multiply(A(e)).toRawBytes(n)},sign:function(e,r,i=_){const{seed:s,k2sig:l}=function(e,r,i=_){if(["recovered","canonical"].some(e=>e in i))throw new Error("sign() legacy options not supported");const{hash:s,randomBytes:l}=t;let{lowS:u,prehash:h,extraEntropy:m}=i;null==u&&(u=!0),e=UC("msgHash",e),h&&(e=UC("prehashed msgHash",s(e)));const y=b(e),w=A(r),E=[v(w),v(y)];if(null!=m){const e=!0===m?l(n.BYTES):m;E.push(UC("extraEntropy",e))}const k=LC(...E),T=y;return{seed:k,k2sig:function(e){const t=g(e);if(!f(t))return;const n=o(t),r=c.BASE.multiply(t).toAffine(),i=a(r.x);if(i===mN)return;const s=a(n*a(T+i*w));if(s===mN)return;let A=(r.x===i?0:2)|Number(r.y&yN),l=s;return u&&d(s)&&(l=function(e){return d(e)?a(-e):e}(s),A^=1),new p(i,l,A)}}}(e,r,i),u=t;return qC(u.hash.outputLen,u.nByteLength,u.hmac)(s,l)},verify:function(e,n,r,i=E){const s=e;if(n=UC("msgHash",n),r=UC("publicKey",r),"strict"in i)throw new Error("options.strict was renamed to lowS");const{lowS:A,prehash:l}=i;let f,u;try{if("string"==typeof s||s instanceof Uint8Array)try{f=p.fromDER(s)}catch(_){if(!(_ instanceof pN.Err))throw _;f=p.fromCompact(s)}else{if("object"!=typeof s||"bigint"!=typeof s.r||"bigint"!=typeof s.s)throw new Error("PARSE");{const{r:e,s:t}=s;f=new p(e,t)}}u=c.fromHex(r)}catch(k){if("PARSE"===k.message)throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(A&&f.hasHighS())return!1;l&&(n=t.hash(n));const{r:d,s:h}=f,m=b(n),y=o(h),g=a(m*y),w=a(d*y),v=c.BASE.multiplyAndAddUnsafe(u,g,w)?.toAffine();return!!v&&a(v.x)===d},ProjectivePoint:c,Signature:p,utils:m}}
29
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function wN(e){return{hash:e,hmac:(t,...n)=>DI(e,t,function(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!kI(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}(...n)),randomBytes:MI}}BigInt(4);
30
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
31
+ const vN=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),_N=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),EN=BigInt(1),kN=BigInt(2),TN=(e,t)=>(e+t/kN)/t,SN=function(e,t,n=!1,r={}){if(e<=KC)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:i,nByteLength:s}=oN(e,t);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");const a=function(e){if(e%XC===ZC){const t=(e+WC)/XC;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}if(e%tN===eN){const t=(e-eN)/tN;return function(e,n){const r=e.mul(n,YC),i=e.pow(r,t),s=e.mul(n,i),a=e.mul(e.mul(s,YC),i),o=e.mul(s,e.sub(a,e.ONE));if(!e.eql(e.sqr(o),n))throw new Error("Cannot find square root");return o}}return function(e){const t=(e-WC)/YC;let n,r,i;for(n=e-WC,r=0;n%YC===KC;n/=YC,r++);for(i=YC;i<e&&rN(i,t,e)!==e-WC;i++);if(1===r){const t=(e+WC)/XC;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}const s=(n+WC)/YC;return function(e,a){if(e.pow(a,t)===e.neg(e.ONE))throw new Error("Cannot find square root");let o=r,c=e.pow(e.mul(e.ONE,i),n),A=e.pow(a,s),l=e.pow(a,n);for(;!e.eql(l,e.ONE);){if(e.eql(l,e.ZERO))return e.ZERO;let t=1;for(let r=e.sqr(l);t<o&&!e.eql(r,e.ONE);t++)r=e.sqr(r);const n=e.pow(c,WC<<BigInt(o-t-1));c=e.sqr(n),A=e.mul(A,n),l=e.mul(l,c),o=t}return A}}(e)}(e),o=Object.freeze({ORDER:e,BITS:i,BYTES:s,MASK:jC(i),ZERO:KC,ONE:WC,create:t=>nN(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("Invalid field element: expected bigint, got "+typeof t);return KC<=t&&t<e},is0:e=>e===KC,isOdd:e=>(e&WC)===WC,neg:t=>nN(-t,e),eql:(e,t)=>e===t,sqr:t=>nN(t*t,e),add:(t,n)=>nN(t+n,e),sub:(t,n)=>nN(t-n,e),mul:(t,n)=>nN(t*n,e),pow:(e,t)=>function(e,t,n){if(n<KC)throw new Error("Expected power > 0");if(n===KC)return e.ONE;if(n===WC)return t;let r=e.ONE,i=t;for(;n>KC;)n&WC&&(r=e.mul(r,i)),i=e.sqr(i),n>>=WC;return r}(o,e,t),div:(t,n)=>nN(t*sN(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>sN(t,e),sqrt:r.sqrt||(e=>a(o,e)),invertBatch:e=>function(e,t){const n=new Array(t.length),r=t.reduce((t,r,i)=>e.is0(r)?t:(n[i]=t,e.mul(t,r)),e.ONE),i=e.inv(r);return t.reduceRight((t,r,i)=>e.is0(r)?t:(n[i]=e.mul(t,n[i]),e.mul(t,r)),i),n}(o,e),cmov:(e,t,n)=>n?t:e,toBytes:e=>n?GC(e,s):FC(e,s),fromBytes:e=>{if(e.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${e.length}`);return n?DC(e):$C(e)}});return Object.freeze(o)}(vN,void 0,void 0,{sqrt:function(e){const t=vN,n=BigInt(3),r=BigInt(6),i=BigInt(11),s=BigInt(22),a=BigInt(23),o=BigInt(44),c=BigInt(88),A=e*e*e%t,l=A*A*e%t,f=iN(l,n,t)*l%t,u=iN(f,n,t)*l%t,d=iN(u,kN,t)*A%t,h=iN(d,i,t)*d%t,p=iN(h,s,t)*h%t,m=iN(p,o,t)*p%t,y=iN(m,c,t)*m%t,g=iN(y,o,t)*p%t,b=iN(g,n,t)*l%t,w=iN(b,a,t)*h%t,v=iN(w,r,t)*A%t,_=iN(v,kN,t);if(!SN.eql(SN.sqr(_),e))throw new Error("Cannot find square root");return _}}),xN=function(e,t){const n=t=>bN({...e,...wN(t)});return Object.freeze({...n(t),create:n})}({a:BigInt(0),b:BigInt(7),Fp:SN,n:_N,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=_N,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-EN*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,a=BigInt("0x100000000000000000000000000000000"),o=TN(s*e,t),c=TN(-r*e,t);let A=nN(e-o*n-c*i,t),l=nN(-o*r-c*s,t);const f=A>a,u=l>a;if(f&&(A=t-A),u&&(l=t-l),A>a||l>a)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:f,k1:A,k2neg:u,k2:l}}}},QI);BigInt(0),xN.ProjectivePoint;const IN="0x0000000000000000000000000000000000000000",PN="0x0000000000000000000000000000000000000000000000000000000000000000",CN=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),NN=BigInt("1000000000000000000"),ON=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),RN=BigInt("0x8000000000000000000000000000000000000000000000000000000000000000")*BigInt(-1),BN=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),MN="Ethereum Signed Message:\n",$N=BigInt(0),DN=BigInt(1),FN=BigInt(2),GN=BigInt(27),UN=BigInt(28),LN=BigInt(35),jN=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),HN=jN/FN,zN=Symbol.for("nodejs.util.inspect.custom"),qN={};function QN(e){return $S(YS(e),32)}K=new WeakMap,W=new WeakMap,Y=new WeakMap,Z=new WeakMap;let VN=class e{constructor(e,t,n,r){__privateAdd(this,K),__privateAdd(this,W),__privateAdd(this,Y),__privateAdd(this,Z),ES(e,qN,"Signature"),__privateSet(this,K,t),__privateSet(this,W,n),__privateSet(this,Y,r),__privateSet(this,Z,null)}get r(){return __privateGet(this,K)}set r(e){bS(32===OS(e),"invalid r","value",e),__privateSet(this,K,CS(e))}get s(){return bS(parseInt(__privateGet(this,W).substring(0,3))<8,"non-canonical s; use ._s","s",__privateGet(this,W)),__privateGet(this,W)}set s(e){bS(32===OS(e),"invalid s","value",e),__privateSet(this,W,CS(e))}get _s(){return __privateGet(this,W)}isValid(){return BigInt(__privateGet(this,W))<=HN}get v(){return __privateGet(this,Y)}set v(e){const t=JS(e,"value");bS(27===t||28===t,"invalid v","v",e),__privateSet(this,Y,t)}get networkV(){return __privateGet(this,Z)}get legacyChainId(){const t=this.networkV;return null==t?null:e.getChainId(t)}get yParity(){return 27===this.v?0:1}get yParityAndS(){const e=TS(this.s);return this.yParity&&(e[0]|=128),CS(e)}get compactSerialized(){return NS([this.r,this.yParityAndS])}get serialized(){return NS([this.r,this.s,this.yParity?"0x1c":"0x1b"])}getCanonical(){if(this.isValid())return this;const t=jN-BigInt(this._s),n=55-this.v,r=new e(qN,this.r,QN(t),n);return this.networkV&&__privateSet(r,Z,this.networkV),r}clone(){const t=new e(qN,this.r,this._s,this.v);return this.networkV&&__privateSet(t,Z,this.networkV),t}toJSON(){const e=this.networkV;return{_type:"signature",networkV:null!=e?e.toString():null,r:this.r,s:this._s,v:this.v}}[zN](){return this.toString()}toString(){return this.isValid()?`Signature { r: ${this.r}, s: ${this._s}, v: ${this.v} }`:`Signature { r: ${this.r}, s: ${this._s}, v: ${this.v}, valid: false }`}static getChainId(e){const t=zS(e,"v");return t==GN||t==UN?$N:(bS(t>=LN,"invalid EIP-155 v","v",e),(t-LN)/FN)}static getChainIdV(e,t){return zS(e)*FN+BigInt(35+t-27)}static getNormalizedV(e){const t=zS(e);return t===$N||t===GN?27:t===DN||t===UN?28:(bS(t>=LN,"invalid v","v",e),t&DN?27:28)}static from(t){function n(e,n){bS(e,n,"signature",t)}if(null==t)return new e(qN,PN,PN,27);if("string"==typeof t){const r=TS(t,"signature");if(64===r.length){const t=CS(r.slice(0,32)),n=r.slice(32,64),i=128&n[0]?28:27;return n[0]&=127,new e(qN,t,CS(n),i)}if(65===r.length){const t=CS(r.slice(0,32)),n=CS(r.slice(32,64)),i=e.getNormalizedV(r[64]);return new e(qN,t,n,i)}n(!1,"invalid raw signature length")}if(t instanceof e)return t.clone();const r=t.r;n(null!=r,"missing r");const i=QN(r),s=function(e,t){if(null!=e)return QN(e);if(null!=t){n(xS(t,32),"invalid yParityAndS");const e=TS(t);return e[0]&=127,CS(e)}n(!1,"missing s")}(t.s,t.yParityAndS),{networkV:a,v:o}=function(t,r,i){if(null!=t){const n=zS(t);return{networkV:n>=LN?n:void 0,v:e.getNormalizedV(n)}}if(null!=r)return n(xS(r,32),"invalid yParityAndS"),{v:128&TS(r)[0]?28:27};if(null!=i){switch(JS(i,"sig.yParity")){case 0:return{v:27};case 1:return{v:28}}n(!1,"invalid yParity")}n(!1,"missing v")}(t.v,t.yParityAndS,t.yParity),c=new e(qN,i,s,o);return a&&__privateSet(c,Z,a),n(null==t.yParity||JS(t.yParity,"sig.yParity")===c.yParity,"yParity mismatch"),n(null==t.yParityAndS||t.yParityAndS===c.yParityAndS,"yParityAndS mismatch"),c}};X=new WeakMap;let JN=class e{constructor(e){__privateAdd(this,X),bS(32===OS(e),"invalid private key","privateKey","[REDACTED]"),__privateSet(this,X,CS(e))}get privateKey(){return __privateGet(this,X)}get publicKey(){return e.computePublicKey(__privateGet(this,X))}get compressedPublicKey(){return e.computePublicKey(__privateGet(this,X),!0)}sign(e){bS(32===OS(e),"invalid digest length","digest",e);const t=xN.sign(SS(e),SS(__privateGet(this,X)),{lowS:!0});return VN.from({r:WS(t.r,32),s:WS(t.s,32),v:t.recovery?28:27})}computeSharedSecret(t){const n=e.computePublicKey(t);return CS(xN.getSharedSecret(SS(__privateGet(this,X)),TS(n),!1))}static computePublicKey(e,t){let n=TS(e,"key");if(32===n.length)return CS(xN.getPublicKey(n,!!t));if(64===n.length){const e=new Uint8Array(65);e[0]=4,e.set(n,1),n=e}return CS(xN.ProjectivePoint.fromHex(n).toRawBytes(t))}static recoverPublicKey(e,t){bS(32===OS(e),"invalid digest length","digest",e);const n=VN.from(t);let r=xN.Signature.fromCompact(SS(NS([n.r,n.s])));r=r.addRecoveryBit(n.yParity);const i=r.recoverPublicKey(SS(e));return bS(null!=i,"invalid signature for digest","signature",t),"0x"+i.toHex(!1)}static addPoints(t,n,r){const i=xN.ProjectivePoint.fromHex(e.computePublicKey(t).substring(2)),s=xN.ProjectivePoint.fromHex(e.computePublicKey(n).substring(2));return"0x"+i.add(s).toHex(!!r)}};function KN(){hP.lock(),RP.lock(),tC.lock(),sC.lock(),YP.lock(),yC.lock(),gC.lock(),TC.lock(),SC.lock(),sC.lock()}const WN=BigInt(0),YN=BigInt(36);function ZN(e){const t=(e=e.toLowerCase()).substring(2).split(""),n=new Uint8Array(40);for(let i=0;i<40;i++)n[i]=t[i].charCodeAt(0);const r=TS(RP(n));for(let i=0;i<40;i+=2)r[i>>1]>>4>=8&&(t[i]=t[i].toUpperCase()),(15&r[i>>1])>=8&&(t[i+1]=t[i+1].toUpperCase());return"0x"+t.join("")}const XN={};for(let uH=0;uH<10;uH++)XN[String(uH)]=String(uH);for(let uH=0;uH<26;uH++)XN[String.fromCharCode(65+uH)]=String(10+uH);function eO(e){let t=(e=(e=e.toUpperCase()).substring(4)+e.substring(0,2)+"00").split("").map(e=>XN[e]).join("");for(;t.length>=15;){let e=t.substring(0,15);t=parseInt(e,10)%97+t.substring(e.length)}let n=String(98-parseInt(t,10)%97);for(;n.length<2;)n="0"+n;return n}const tO=function(){const e={};for(let t=0;t<36;t++)e["0123456789abcdefghijklmnopqrstuvwxyz"[t]]=BigInt(t);return e}();function nO(e){if(bS("string"==typeof e,"invalid address","address",e),e.match(/^(0x)?[0-9a-fA-F]{40}$/)){e.startsWith("0x")||(e="0x"+e);const t=ZN(e);return bS(!e.match(/([A-F].*[a-f])|([a-f].*[A-F])/)||t===e,"bad address checksum","address",e),t}if(e.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){bS(e.substring(2,4)===eO(e),"bad icap checksum","address",e);let t=function(e){e=e.toLowerCase();let t=WN;for(let n=0;n<e.length;n++)t=t*YN+tO[e[n]];return t}(e.substring(4)).toString(16);for(;t.length<40;)t="0"+t;return ZN("0x"+t)}bS(!1,"invalid address","address",e)}function rO(e){let t=BigInt(nO(e)).toString(36).toUpperCase();for(;t.length<30;)t="0"+t;return"XE"+eO("XE00"+t)+t}function iO(e){const t=nO(e.from);let n=zS(e.nonce,"tx.nonce").toString(16);return n="0"===n?"0x":n.length%2?"0x0"+n:"0x"+n,nO(RS(RP(Wx([t,n])),12))}function sO(e,t,n){const r=nO(e),i=TS(t,"salt"),s=TS(n,"initCodeHash");return bS(32===i.length,"salt must be 32 bytes","salt",t),bS(32===s.length,"initCodeHash must be 32 bytes","initCodeHash",n),nO(RS(RP(NS(["0xff",r,i,s])),12))}function aO(e){return e&&"function"==typeof e.getAddress}function oO(e){try{return nO(e),!0}catch(t){}return!1}async function cO(e,t){const n=await t;return null!=n&&"0x0000000000000000000000000000000000000000"!==n||(gS("string"!=typeof e,"unconfigured name","UNCONFIGURED_NAME",{value:e}),bS(!1,"invalid AddressLike value; did not resolve to a value address","target",e)),nO(n)}function AO(e,t){return"string"==typeof e?e.match(/^0x[0-9a-f]{40}$/i)?nO(e):(gS(null!=t,"ENS resolution requires a provider","UNSUPPORTED_OPERATION",{operation:"resolveName"}),cO(e,t.resolveName(e))):aO(e)?cO(e,e.getAddress()):e&&"function"==typeof e.then?cO(e,e):void bS(!1,"unsupported addressable value","target",e)}const lO={};function fO(e,t){let n=!1;return t<0&&(n=!0,t*=-1),new hO(lO,`${n?"":"u"}int${t}`,e,{signed:n,width:t})}function uO(e,t){return new hO(lO,`bytes${t||""}`,e,{size:t})}const dO=Symbol.for("_ethers_typed");ee=new WeakMap;let hO=class e{constructor(e,t,n,r){__publicField(this,"type"),__publicField(this,"value"),__privateAdd(this,ee),__publicField(this,"_typedSymbol"),null==r&&(r=null),ES(lO,e,"Typed"),dS(this,{_typedSymbol:dO,type:t,value:n}),__privateSet(this,ee,r),this.format()}format(){if("array"===this.type)throw new Error("");if("dynamicArray"===this.type)throw new Error("");return"tuple"===this.type?`tuple(${this.value.map(e=>e.format()).join(",")})`:this.type}defaultValue(){return 0}minValue(){return 0}maxValue(){return 0}isBigInt(){return!!this.type.match(/^u?int[0-9]+$/)}isData(){return this.type.startsWith("bytes")}isString(){return"string"===this.type}get tupleName(){if("tuple"!==this.type)throw TypeError("not a tuple");return __privateGet(this,ee)}get arrayLength(){if("array"!==this.type)throw TypeError("not an array");return!0===__privateGet(this,ee)?-1:!1===__privateGet(this,ee)?this.value.length:null}static from(t,n){return new e(lO,t,n)}static uint8(e){return fO(e,8)}static uint16(e){return fO(e,16)}static uint24(e){return fO(e,24)}static uint32(e){return fO(e,32)}static uint40(e){return fO(e,40)}static uint48(e){return fO(e,48)}static uint56(e){return fO(e,56)}static uint64(e){return fO(e,64)}static uint72(e){return fO(e,72)}static uint80(e){return fO(e,80)}static uint88(e){return fO(e,88)}static uint96(e){return fO(e,96)}static uint104(e){return fO(e,104)}static uint112(e){return fO(e,112)}static uint120(e){return fO(e,120)}static uint128(e){return fO(e,128)}static uint136(e){return fO(e,136)}static uint144(e){return fO(e,144)}static uint152(e){return fO(e,152)}static uint160(e){return fO(e,160)}static uint168(e){return fO(e,168)}static uint176(e){return fO(e,176)}static uint184(e){return fO(e,184)}static uint192(e){return fO(e,192)}static uint200(e){return fO(e,200)}static uint208(e){return fO(e,208)}static uint216(e){return fO(e,216)}static uint224(e){return fO(e,224)}static uint232(e){return fO(e,232)}static uint240(e){return fO(e,240)}static uint248(e){return fO(e,248)}static uint256(e){return fO(e,256)}static uint(e){return fO(e,256)}static int8(e){return fO(e,-8)}static int16(e){return fO(e,-16)}static int24(e){return fO(e,-24)}static int32(e){return fO(e,-32)}static int40(e){return fO(e,-40)}static int48(e){return fO(e,-48)}static int56(e){return fO(e,-56)}static int64(e){return fO(e,-64)}static int72(e){return fO(e,-72)}static int80(e){return fO(e,-80)}static int88(e){return fO(e,-88)}static int96(e){return fO(e,-96)}static int104(e){return fO(e,-104)}static int112(e){return fO(e,-112)}static int120(e){return fO(e,-120)}static int128(e){return fO(e,-128)}static int136(e){return fO(e,-136)}static int144(e){return fO(e,-144)}static int152(e){return fO(e,-152)}static int160(e){return fO(e,-160)}static int168(e){return fO(e,-168)}static int176(e){return fO(e,-176)}static int184(e){return fO(e,-184)}static int192(e){return fO(e,-192)}static int200(e){return fO(e,-200)}static int208(e){return fO(e,-208)}static int216(e){return fO(e,-216)}static int224(e){return fO(e,-224)}static int232(e){return fO(e,-232)}static int240(e){return fO(e,-240)}static int248(e){return fO(e,-248)}static int256(e){return fO(e,-256)}static int(e){return fO(e,-256)}static bytes1(e){return uO(e,1)}static bytes2(e){return uO(e,2)}static bytes3(e){return uO(e,3)}static bytes4(e){return uO(e,4)}static bytes5(e){return uO(e,5)}static bytes6(e){return uO(e,6)}static bytes7(e){return uO(e,7)}static bytes8(e){return uO(e,8)}static bytes9(e){return uO(e,9)}static bytes10(e){return uO(e,10)}static bytes11(e){return uO(e,11)}static bytes12(e){return uO(e,12)}static bytes13(e){return uO(e,13)}static bytes14(e){return uO(e,14)}static bytes15(e){return uO(e,15)}static bytes16(e){return uO(e,16)}static bytes17(e){return uO(e,17)}static bytes18(e){return uO(e,18)}static bytes19(e){return uO(e,19)}static bytes20(e){return uO(e,20)}static bytes21(e){return uO(e,21)}static bytes22(e){return uO(e,22)}static bytes23(e){return uO(e,23)}static bytes24(e){return uO(e,24)}static bytes25(e){return uO(e,25)}static bytes26(e){return uO(e,26)}static bytes27(e){return uO(e,27)}static bytes28(e){return uO(e,28)}static bytes29(e){return uO(e,29)}static bytes30(e){return uO(e,30)}static bytes31(e){return uO(e,31)}static bytes32(e){return uO(e,32)}static address(t){return new e(lO,"address",t)}static bool(t){return new e(lO,"bool",!!t)}static bytes(t){return new e(lO,"bytes",t)}static string(t){return new e(lO,"string",t)}static array(e,t){throw new Error("not implemented yet")}static tuple(e,t){throw new Error("not implemented yet")}static overrides(t){return new e(lO,"overrides",Object.assign({},t))}static isTyped(e){return e&&"object"==typeof e&&"_typedSymbol"in e&&e._typedSymbol===dO}static dereference(t,n){if(e.isTyped(t)){if(t.type!==n)throw new Error(`invalid type: expecetd ${n}, got ${t.type}`);return t.value}return t}};class pO extends pI{constructor(e){super("address","address",e,!1)}defaultValue(){return"0x0000000000000000000000000000000000000000"}encode(e,t){let n=hO.dereference(t,"string");try{n=nO(n)}catch(r){return this._throwError(r.message,t)}return e.writeValue(n)}decode(e){return nO(WS(e.readValue(),20))}}class mO extends pI{constructor(e){super(e.name,e.type,"_",e.dynamic),__publicField(this,"coder"),this.coder=e}defaultValue(){return this.coder.defaultValue()}encode(e,t){return this.coder.encode(e,t)}decode(e){return this.coder.decode(e)}}function yO(e,t,n){let r=[];if(Array.isArray(n))r=n;else if(n&&"object"==typeof n){let e={};r=t.map(t=>{const r=t.localName;return gS(r,"cannot encode object for signature with missing names","INVALID_ARGUMENT",{argument:"values",info:{coder:t},value:n}),gS(!e[r],"cannot encode object for signature with duplicate names","INVALID_ARGUMENT",{argument:"values",info:{coder:t},value:n}),e[r]=!0,n[r]})}else bS(!1,"invalid tuple value","tuple",n);bS(t.length===r.length,"types/value length mismatch","tuple",n);let i=new mI,s=new mI,a=[];t.forEach((e,t)=>{let n=r[t];if(e.dynamic){let t=s.length;e.encode(s,n);let r=i.writeUpdatableValue();a.push(e=>{r(e+t)})}else e.encode(i,n)}),a.forEach(e=>{e(i.length)});let o=e.appendWriter(i);return o+=e.appendWriter(s),o}function gO(e,t){let n=[],r=[],i=e.subReader(0);return t.forEach(t=>{let s=null;if(t.dynamic){let n=e.readIndex(),r=i.subReader(n);try{s=t.decode(r)}catch(a){if(pS(a,"BUFFER_OVERRUN"))throw a;s=a,s.baseType=t.name,s.name=t.localName,s.type=t.type}}else try{s=t.decode(e)}catch(a){if(pS(a,"BUFFER_OVERRUN"))throw a;s=a,s.baseType=t.name,s.name=t.localName,s.type=t.type}if(null==s)throw new Error("investigate");n.push(s),r.push(t.localName||null)}),uI.fromItems(n,r)}class bO extends pI{constructor(e,t,n){super("array",e.type+"["+(t>=0?t:"")+"]",n,-1===t||e.dynamic),__publicField(this,"coder"),__publicField(this,"length"),dS(this,{coder:e,length:t})}defaultValue(){const e=this.coder.defaultValue(),t=[];for(let n=0;n<this.length;n++)t.push(e);return t}encode(e,t){const n=hO.dereference(t,"array");Array.isArray(n)||this._throwError("expected array value",n);let r=this.length;-1===r&&(r=n.length,e.writeValue(n.length)),wS(n.length,r,"coder array"+(this.localName?" "+this.localName:""));let i=[];for(let s=0;s<n.length;s++)i.push(this.coder);return yO(e,i,n)}decode(e){let t=this.length;-1===t&&(t=e.readIndex(),gS(t*rI<=e.dataLength,"insufficient data length","BUFFER_OVERRUN",{buffer:e.bytes,offset:t*rI,length:e.dataLength}));let n=[];for(let r=0;r<t;r++)n.push(new mO(this.coder));return gO(e,n)}}class wO extends pI{constructor(e){super("bool","bool",e,!1)}defaultValue(){return!1}encode(e,t){const n=hO.dereference(t,"bool");return e.writeValue(n?1:0)}decode(e){return!!e.readValue()}}class vO extends pI{constructor(e,t){super(e,e,t,!0)}defaultValue(){return"0x"}encode(e,t){t=SS(t);let n=e.writeValue(t.length);return n+=e.writeBytes(t),n}decode(e){return e.readBytes(e.readIndex(),!0)}}class _O extends vO{constructor(e){super("bytes",e)}decode(e){return CS(super.decode(e))}}class EO extends pI{constructor(e,t){let n="bytes"+String(e);super(n,n,t,!1),__publicField(this,"size"),dS(this,{size:e},{size:"number"})}defaultValue(){return"0x0000000000000000000000000000000000000000000000000000000000000000".substring(0,2+2*this.size)}encode(e,t){let n=SS(hO.dereference(t,this.type));return n.length!==this.size&&this._throwError("incorrect data length",t),e.writeBytes(n)}decode(e){return CS(e.readBytes(this.size))}}const kO=new Uint8Array([]);class TO extends pI{constructor(e){super("null","",e,!1)}defaultValue(){return null}encode(e,t){return null!=t&&this._throwError("not null",t),e.writeBytes(kO)}decode(e){return e.readBytes(0),null}}const SO=BigInt(0),xO=BigInt(1),IO=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");class PO extends pI{constructor(e,t,n){const r=(t?"int":"uint")+8*e;super(r,r,n,!1),__publicField(this,"size"),__publicField(this,"signed"),dS(this,{size:e,signed:t},{size:"number",signed:"boolean"})}defaultValue(){return 0}encode(e,t){let n=zS(hO.dereference(t,this.type)),r=HS(IO,256);if(this.signed){let e=HS(r,8*this.size-1);(n>e||n<-(e+xO))&&this._throwError("value out-of-bounds",t),n=jS(n,256)}else(n<SO||n>HS(r,8*this.size))&&this._throwError("value out-of-bounds",t);return e.writeValue(n)}decode(e){let t=HS(e.readValue(),8*this.size);return this.signed&&(t=LS(t,8*this.size)),t}}class CO extends vO{constructor(e){super("string",e)}defaultValue(){return""}encode(e,t){return super.encode(e,ux(hO.dereference(t,"string")))}decode(e){return dx(super.decode(e))}}class NO extends pI{constructor(e,t){let n=!1;const r=[];e.forEach(e=>{e.dynamic&&(n=!0),r.push(e.type)}),super("tuple","tuple("+r.join(",")+")",t,n),__publicField(this,"coders"),dS(this,{coders:Object.freeze(e.slice())})}defaultValue(){const e=[];this.coders.forEach(t=>{e.push(t.defaultValue())});const t=this.coders.reduce((e,t)=>{const n=t.localName;return n&&(e[n]||(e[n]=0),e[n]++),e},{});return this.coders.forEach((n,r)=>{let i=n.localName;i&&1===t[i]&&("length"===i&&(i="_length"),null==e[i]&&(e[i]=e[r]))}),Object.freeze(e)}encode(e,t){const n=hO.dereference(t,"tuple");return yO(e,this.coders,n)}decode(e){return gO(e,this.coders)}}function OO(e,t){return{address:nO(e),storageKeys:t.map((e,t)=>(bS(xS(e,32),"invalid slot",`storageKeys[${t}]`,e),e.toLowerCase()))}}function RO(e){if(Array.isArray(e))return e.map((t,n)=>Array.isArray(t)?(bS(2===t.length,"invalid slot set",`value[${n}]`,t),OO(t[0],t[1])):(bS(null!=t&&"object"==typeof t,"invalid address-slot set","value",e),OO(t.address,t.storageKeys)));bS(null!=e&&"object"==typeof e,"invalid access list","value",e);const t=Object.keys(e).map(t=>{const n=e[t].reduce((e,t)=>(e[t]=!0,e),{});return OO(t,Object.keys(n).sort())});return t.sort((e,t)=>e.address.localeCompare(t.address)),t}function BO(e){return{address:nO(e.address),nonce:zS(null!=e.nonce?e.nonce:0),chainId:zS(null!=e.chainId?e.chainId:0),signature:VN.from(e.signature)}}function MO(e){let t;return t="string"==typeof e?JN.computePublicKey(e,!1):e.publicKey,nO(RP("0x"+t.substring(4)).substring(26))}function $O(e,t){return MO(JN.recoverPublicKey(e,t))}const DO=BigInt(0),FO=BigInt(2),GO=BigInt(27),UO=BigInt(28),LO=BigInt(35),jO=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),HO=Symbol.for("nodejs.util.inspect.custom"),zO=131072,qO=128;function QO(e,t){let n=e.toString(16);for(;n.length<2;)n="0"+n;return n+=TC(t).substring(4),"0x"+n}function VO(e){return"0x"===e?null:nO(e)}function JO(e,t){try{return RO(e)}catch(n){bS(!1,n.message,t,e)}}function KO(e,t){try{if(!Array.isArray(e))throw new Error("authorizationList: invalid array");const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(!Array.isArray(r))throw new Error(`authorization[${n}]: invalid array`);if(6!==r.length)throw new Error(`authorization[${n}]: wrong length`);if(!r[1])throw new Error(`authorization[${n}]: null address`);t.push({address:VO(r[1]),nonce:YO(r[2],"nonce"),chainId:YO(r[0],"chainId"),signature:VN.from({yParity:WO(r[3],"yParity"),r:$S(r[4],32),s:$S(r[5],32)})})}return t}catch(n){bS(!1,n.message,t,e)}}function WO(e,t){return"0x"===e?0:JS(e,t)}function YO(e,t){if("0x"===e)return DO;const n=zS(e,t);return bS(n<=jO,"value exceeds uint size",t,n),n}function ZO(e,t){const n=zS(e,"value"),r=YS(n);return bS(r.length<=32,"value too large",`tx.${t}`,n),r}function XO(e){return RO(e).map(e=>[e.address,e.storageKeys])}function eR(e,t){bS(Array.isArray(e),`invalid ${t}`,"value",e);for(let n=0;n<e.length;n++)bS(xS(e[n],32),"invalid ${ param } hash",`value[${n}]`,e[n]);return e}function tR(e,t){let n;try{if(n=WO(t[0],"yParity"),0!==n&&1!==n)throw new Error("bad yParity")}catch(a){bS(!1,"invalid yParity","yParity",t[0])}const r=$S(t[1],32),i=$S(t[2],32),s=VN.from({r:r,s:i,yParity:n});e.signature=s}te=new WeakMap,ne=new WeakMap,re=new WeakMap,ie=new WeakMap,se=new WeakMap,ae=new WeakMap,oe=new WeakMap,ce=new WeakMap,Ae=new WeakMap,le=new WeakMap,fe=new WeakMap,ue=new WeakMap,de=new WeakMap,he=new WeakMap,pe=new WeakMap,me=new WeakMap,ye=new WeakMap,ge=new WeakMap,be=new WeakSet,we=function(e,t){gS(!e||null!=this.signature,"cannot serialize unsigned transaction; maybe you meant .unsignedSerialized","UNSUPPORTED_OPERATION",{operation:".serialized"});const n=e?this.signature:null;switch(this.inferType()){case 0:return function(e,t){const n=[ZO(e.nonce,"nonce"),ZO(e.gasPrice||0,"gasPrice"),ZO(e.gasLimit,"gasLimit"),e.to||"0x",ZO(e.value,"value"),e.data];let r=DO;if(e.chainId!=DO)r=zS(e.chainId,"tx.chainId"),bS(!t||null==t.networkV||t.legacyChainId===r,"tx.chainId/sig.v mismatch","sig",t);else if(e.signature){const t=e.signature.legacyChainId;null!=t&&(r=t)}if(!t)return r!==DO&&(n.push(YS(r)),n.push("0x"),n.push("0x")),Wx(n);let i=BigInt(27+t.yParity);return r!==DO?i=VN.getChainIdV(r,t.v):BigInt(t.v)!==i&&bS(!1,"tx.chainId/sig.v mismatch","sig",t),n.push(YS(i)),n.push(YS(t.r)),n.push(YS(t._s)),Wx(n)}(this,n);case 1:return function(e,t){const n=[ZO(e.chainId,"chainId"),ZO(e.nonce,"nonce"),ZO(e.gasPrice||0,"gasPrice"),ZO(e.gasLimit,"gasLimit"),e.to||"0x",ZO(e.value,"value"),e.data,XO(e.accessList||[])];return t&&(n.push(ZO(t.yParity,"recoveryParam")),n.push(YS(t.r)),n.push(YS(t.s))),NS(["0x01",Wx(n)])}(this,n);case 2:return function(e,t){const n=[ZO(e.chainId,"chainId"),ZO(e.nonce,"nonce"),ZO(e.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),ZO(e.maxFeePerGas||0,"maxFeePerGas"),ZO(e.gasLimit,"gasLimit"),e.to||"0x",ZO(e.value,"value"),e.data,XO(e.accessList||[])];return t&&(n.push(ZO(t.yParity,"yParity")),n.push(YS(t.r)),n.push(YS(t.s))),NS(["0x02",Wx(n)])}(this,n);case 3:return function(e,t,n){const r=[ZO(e.chainId,"chainId"),ZO(e.nonce,"nonce"),ZO(e.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),ZO(e.maxFeePerGas||0,"maxFeePerGas"),ZO(e.gasLimit,"gasLimit"),e.to||IN,ZO(e.value,"value"),e.data,XO(e.accessList||[]),ZO(e.maxFeePerBlobGas||0,"maxFeePerBlobGas"),eR(e.blobVersionedHashes||[],"blobVersionedHashes")];if(t&&(r.push(ZO(t.yParity,"yParity")),r.push(YS(t.r)),r.push(YS(t.s)),n)){if(null!=e.blobWrapperVersion){const t=YS(e.blobWrapperVersion),i=[];for(const{proof:e}of n){const t=TS(e),n=t.length/qO;for(let e=0;e<t.length;e+=n)i.push(t.subarray(e,e+n))}return NS(["0x03",Wx([r,t,n.map(e=>e.data),n.map(e=>e.commitment),i])])}return NS(["0x03",Wx([r,n.map(e=>e.data),n.map(e=>e.commitment),n.map(e=>e.proof)])])}return NS(["0x03",Wx(r)])}(this,n,t?this.blobs:null);case 4:return function(e,t){const n=[ZO(e.chainId,"chainId"),ZO(e.nonce,"nonce"),ZO(e.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),ZO(e.maxFeePerGas||0,"maxFeePerGas"),ZO(e.gasLimit,"gasLimit"),e.to||"0x",ZO(e.value,"value"),e.data,XO(e.accessList||[]),(r=e.authorizationList||[],r.map(e=>[ZO(e.chainId,"chainId"),e.address,ZO(e.nonce,"nonce"),ZO(e.signature.yParity,"yParity"),YS(e.signature.r),YS(e.signature._s)]))];var r;return t&&(n.push(ZO(t.yParity,"yParity")),n.push(YS(t.r)),n.push(YS(t.s))),NS(["0x04",Wx(n)])}(this,n)}gS(!1,"unsupported transaction type","UNSUPPORTED_OPERATION",{operation:".serialized"})};let nR=class e{constructor(){__privateAdd(this,be),__privateAdd(this,te),__privateAdd(this,ne),__privateAdd(this,re),__privateAdd(this,ie),__privateAdd(this,se),__privateAdd(this,ae),__privateAdd(this,oe),__privateAdd(this,ce),__privateAdd(this,Ae),__privateAdd(this,le),__privateAdd(this,fe),__privateAdd(this,ue),__privateAdd(this,de),__privateAdd(this,he),__privateAdd(this,pe),__privateAdd(this,me),__privateAdd(this,ye),__privateAdd(this,ge),__privateSet(this,te,null),__privateSet(this,ne,null),__privateSet(this,ie,0),__privateSet(this,se,DO),__privateSet(this,ae,null),__privateSet(this,oe,null),__privateSet(this,ce,null),__privateSet(this,re,"0x"),__privateSet(this,Ae,DO),__privateSet(this,le,DO),__privateSet(this,fe,null),__privateSet(this,ue,null),__privateSet(this,de,null),__privateSet(this,he,null),__privateSet(this,pe,null),__privateSet(this,me,null),__privateSet(this,ye,null),__privateSet(this,ge,null)}get type(){return __privateGet(this,te)}set type(e){switch(e){case null:__privateSet(this,te,null);break;case 0:case"legacy":__privateSet(this,te,0);break;case 1:case"berlin":case"eip-2930":__privateSet(this,te,1);break;case 2:case"london":case"eip-1559":__privateSet(this,te,2);break;case 3:case"cancun":case"eip-4844":__privateSet(this,te,3);break;case 4:case"pectra":case"eip-7702":__privateSet(this,te,4);break;default:bS(!1,"unsupported transaction type","type",e)}}get typeName(){switch(this.type){case 0:return"legacy";case 1:return"eip-2930";case 2:return"eip-1559";case 3:return"eip-4844";case 4:return"eip-7702"}return null}get to(){const e=__privateGet(this,ne);return null==e&&3===this.type?IN:e}set to(e){__privateSet(this,ne,null==e?null:nO(e))}get nonce(){return __privateGet(this,ie)}set nonce(e){__privateSet(this,ie,JS(e,"value"))}get gasLimit(){return __privateGet(this,se)}set gasLimit(e){__privateSet(this,se,zS(e))}get gasPrice(){const e=__privateGet(this,ae);return null!=e||0!==this.type&&1!==this.type?e:DO}set gasPrice(e){__privateSet(this,ae,null==e?null:zS(e,"gasPrice"))}get maxPriorityFeePerGas(){const e=__privateGet(this,oe);return null==e?2===this.type||3===this.type?DO:null:e}set maxPriorityFeePerGas(e){__privateSet(this,oe,null==e?null:zS(e,"maxPriorityFeePerGas"))}get maxFeePerGas(){const e=__privateGet(this,ce);return null==e?2===this.type||3===this.type?DO:null:e}set maxFeePerGas(e){__privateSet(this,ce,null==e?null:zS(e,"maxFeePerGas"))}get data(){return __privateGet(this,re)}set data(e){__privateSet(this,re,CS(e))}get value(){return __privateGet(this,Ae)}set value(e){__privateSet(this,Ae,zS(e,"value"))}get chainId(){return __privateGet(this,le)}set chainId(e){__privateSet(this,le,zS(e))}get signature(){return __privateGet(this,fe)||null}set signature(e){__privateSet(this,fe,null==e?null:VN.from(e))}isValid(){const e=this.signature;if(e&&!e.isValid())return!1;const t=this.authorizationList;if(t)for(const n of t)if(!n.signature.isValid())return!1;return!0}get accessList(){const e=__privateGet(this,ue)||null;return null==e?1===this.type||2===this.type||3===this.type?[]:null:e}set accessList(e){__privateSet(this,ue,null==e?null:RO(e))}get authorizationList(){const e=__privateGet(this,ye)||null;return null==e&&4===this.type?[]:e}set authorizationList(e){__privateSet(this,ye,null==e?null:e.map(e=>BO(e)))}get maxFeePerBlobGas(){const e=__privateGet(this,de);return null==e&&3===this.type?DO:e}set maxFeePerBlobGas(e){__privateSet(this,de,null==e?null:zS(e,"maxFeePerBlobGas"))}get blobVersionedHashes(){let e=__privateGet(this,he);return null==e&&3===this.type?[]:e}set blobVersionedHashes(e){if(null!=e){bS(Array.isArray(e),"blobVersionedHashes must be an Array","value",e),e=e.slice();for(let t=0;t<e.length;t++)bS(xS(e[t],32),"invalid blobVersionedHash",`value[${t}]`,e[t])}__privateSet(this,he,e)}get blobs(){return null==__privateGet(this,me)?null:__privateGet(this,me).map(e=>Object.assign({},e))}set blobs(e){if(null==e)return void __privateSet(this,me,null);const t=[],n=[];for(let r=0;r<e.length;r++){const i=e[r];if(IS(i)){gS(__privateGet(this,pe),"adding a raw blob requires a KZG library","UNSUPPORTED_OPERATION",{operation:"set blobs()"});let e=TS(i);if(bS(e.length<=zO,"blob is too large",`blobs[${r}]`,i),e.length!==zO){const t=new Uint8Array(zO);t.set(e),e=t}const s=__privateGet(this,pe).blobToKzgCommitment(e),a=CS(__privateGet(this,pe).computeBlobKzgProof(e,s));t.push({data:CS(e),commitment:CS(s),proof:a}),n.push(QO(1,s))}else{const e=CS(i.data),r=CS(i.commitment),s=CS(i.proof);t.push({data:e,commitment:r,proof:s}),n.push(QO(1,r))}}__privateSet(this,me,t),__privateSet(this,he,n)}get kzg(){return __privateGet(this,pe)}set kzg(e){__privateSet(this,pe,null==e?null:function(e){return{blobToKzgCommitment:t=>{if("computeBlobProof"in e){if("blobToKzgCommitment"in e&&"function"==typeof e.blobToKzgCommitment)return TS(e.blobToKzgCommitment(CS(t)))}else if("blobToKzgCommitment"in e&&"function"==typeof e.blobToKzgCommitment)return TS(e.blobToKzgCommitment(t));if("blobToKZGCommitment"in e&&"function"==typeof e.blobToKZGCommitment)return TS(e.blobToKZGCommitment(CS(t)));bS(!1,"unsupported KZG library","kzg",e)},computeBlobKzgProof:(t,n)=>"computeBlobProof"in e&&"function"==typeof e.computeBlobProof?TS(e.computeBlobProof(CS(t),CS(n))):"computeBlobKzgProof"in e&&"function"==typeof e.computeBlobKzgProof?e.computeBlobKzgProof(t,n):"computeBlobKZGProof"in e&&"function"==typeof e.computeBlobKZGProof?TS(e.computeBlobKZGProof(CS(t),CS(n))):void bS(!1,"unsupported KZG library","kzg",e)}}(e))}get blobWrapperVersion(){return __privateGet(this,ge)}set blobWrapperVersion(e){__privateSet(this,ge,e)}get hash(){return null==this.signature?null:RP(__privateMethod(this,be,we).call(this,!0,!1))}get unsignedHash(){return RP(this.unsignedSerialized)}get from(){return null==this.signature?null:$O(this.unsignedHash,this.signature.getCanonical())}get fromPublicKey(){return null==this.signature?null:JN.recoverPublicKey(this.unsignedHash,this.signature.getCanonical())}isSigned(){return null!=this.signature}get serialized(){return __privateMethod(this,be,we).call(this,!0,!0)}get unsignedSerialized(){return __privateMethod(this,be,we).call(this,!1,!1)}inferType(){const e=this.inferTypes();return e.indexOf(2)>=0?2:e.pop()}inferTypes(){const e=null!=this.gasPrice,t=null!=this.maxFeePerGas||null!=this.maxPriorityFeePerGas,n=null!=this.accessList,r=null!=__privateGet(this,de)||__privateGet(this,he);null!=this.maxFeePerGas&&null!=this.maxPriorityFeePerGas&&gS(this.maxFeePerGas>=this.maxPriorityFeePerGas,"priorityFee cannot be more than maxFee","BAD_DATA",{value:this}),gS(!t||0!==this.type&&1!==this.type,"transaction type cannot have maxFeePerGas or maxPriorityFeePerGas","BAD_DATA",{value:this}),gS(0!==this.type||!n,"legacy transaction cannot have accessList","BAD_DATA",{value:this});const i=[];return null!=this.type?i.push(this.type):this.authorizationList&&this.authorizationList.length?i.push(4):t?i.push(2):e?(i.push(1),n||i.push(0)):n?(i.push(1),i.push(2)):(r&&this.to||(i.push(0),i.push(1),i.push(2)),i.push(3)),i.sort(),i}isLegacy(){return 0===this.type}isBerlin(){return 1===this.type}isLondon(){return 2===this.type}isCancun(){return 3===this.type}clone(){return e.from(this)}toJSON(){const e=e=>null==e?null:e.toString();return{type:this.type,to:this.to,data:this.data,nonce:this.nonce,gasLimit:e(this.gasLimit),gasPrice:e(this.gasPrice),maxPriorityFeePerGas:e(this.maxPriorityFeePerGas),maxFeePerGas:e(this.maxFeePerGas),value:e(this.value),chainId:e(this.chainId),sig:this.signature?this.signature.toJSON():null,accessList:this.accessList}}[HO](){return this.toString()}toString(){const e=[],t=t=>{let n=this[t];"string"==typeof n&&(n=JSON.stringify(n)),e.push(`${t}: ${n}`)};this.type&&t("type"),t("to"),t("data"),t("nonce"),t("gasLimit"),t("value"),null!=this.chainId&&t("chainId"),this.signature&&(t("from"),e.push(`signature: ${this.signature.toString()}`));const n=this.authorizationList;if(n){const t=[];for(const e of n){const n=[];n.push(`address: ${JSON.stringify(e.address)}`),null!=e.nonce&&n.push(`nonce: ${e.nonce}`),null!=e.chainId&&n.push(`chainId: ${e.chainId}`),e.signature&&n.push(`signature: ${e.signature.toString()}`),t.push(`Authorization { ${n.join(", ")} }`)}e.push(`authorizations: [ ${t.join(", ")} ]`)}return`Transaction { ${e.join(", ")} }`}static from(t){if(null==t)return new e;if("string"==typeof t){const n=TS(t);if(n[0]>=127)return e.from(function(e){const t=Qx(e);bS(Array.isArray(t)&&(9===t.length||6===t.length),"invalid field count for legacy transaction","data",e);const n={type:0,nonce:WO(t[0],"nonce"),gasPrice:YO(t[1],"gasPrice"),gasLimit:YO(t[2],"gasLimit"),to:VO(t[3]),value:YO(t[4],"value"),data:CS(t[5]),chainId:DO};if(6===t.length)return n;const r=YO(t[6],"v"),i=YO(t[7],"r"),s=YO(t[8],"s");if(i===DO&&s===DO)n.chainId=r;else{let e=(r-LO)/FO;e<DO&&(e=DO),n.chainId=e,bS(e!==DO||r===GO||r===UO,"non-canonical legacy v","v",t[6]),n.signature=VN.from({r:$S(t[7],32),s:$S(t[8],32),v:r})}return n}(n));switch(n[0]){case 1:return e.from(function(e){const t=Qx(TS(e).slice(1));bS(Array.isArray(t)&&(8===t.length||11===t.length),"invalid field count for transaction type: 1","data",CS(e));const n={type:1,chainId:YO(t[0],"chainId"),nonce:WO(t[1],"nonce"),gasPrice:YO(t[2],"gasPrice"),gasLimit:YO(t[3],"gasLimit"),to:VO(t[4]),value:YO(t[5],"value"),data:CS(t[6]),accessList:JO(t[7],"accessList")};return 8===t.length||tR(n,t.slice(8)),n}(n));case 2:return e.from(function(e){const t=Qx(TS(e).slice(1));bS(Array.isArray(t)&&(9===t.length||12===t.length),"invalid field count for transaction type: 2","data",CS(e));const n={type:2,chainId:YO(t[0],"chainId"),nonce:WO(t[1],"nonce"),maxPriorityFeePerGas:YO(t[2],"maxPriorityFeePerGas"),maxFeePerGas:YO(t[3],"maxFeePerGas"),gasPrice:null,gasLimit:YO(t[4],"gasLimit"),to:VO(t[5]),value:YO(t[6],"value"),data:CS(t[7]),accessList:JO(t[8],"accessList")};return 9===t.length||tR(n,t.slice(9)),n}(n));case 3:return e.from(function(e){let t=Qx(TS(e).slice(1)),n="3",r=null,i=null;if(4===t.length&&Array.isArray(t[0])){n="3 (network format)";const e=t[1],r=t[2],s=t[3];bS(Array.isArray(e),"invalid network format: blobs not an array","fields[1]",e),bS(Array.isArray(r),"invalid network format: commitments not an array","fields[2]",r),bS(Array.isArray(s),"invalid network format: proofs not an array","fields[3]",s),bS(e.length===r.length,"invalid network format: blobs/commitments length mismatch","fields",t),bS(e.length===s.length,"invalid network format: blobs/proofs length mismatch","fields",t),i=[];for(let n=0;n<t[1].length;n++)i.push({data:e[n],commitment:r[n],proof:s[n]});t=t[0]}else if(5===t.length&&Array.isArray(t[0])){n="3 (EIP-7594 network format)",r=JS(t[1]);const e=t[2],s=t[3],a=t[4];bS(1===r,`unsupported EIP-7594 network format version: ${r}`,"fields[1]",r),bS(Array.isArray(e),"invalid EIP-7594 network format: blobs not an array","fields[2]",e),bS(Array.isArray(s),"invalid EIP-7594 network format: commitments not an array","fields[3]",s),bS(Array.isArray(a),"invalid EIP-7594 network format: proofs not an array","fields[4]",a),bS(e.length===s.length,"invalid network format: blobs/commitments length mismatch","fields",t),bS(e.length*qO===a.length,"invalid network format: blobs/proofs length mismatch","fields",t),i=[];for(let t=0;t<e.length;t++){const n=[];for(let e=0;e<qO;e++)n.push(a[t*qO+e]);i.push({data:e[t],commitment:s[t],proof:NS(n)})}t=t[0]}bS(Array.isArray(t)&&(11===t.length||14===t.length),`invalid field count for transaction type: ${n}`,"data",CS(e));const s={type:3,chainId:YO(t[0],"chainId"),nonce:WO(t[1],"nonce"),maxPriorityFeePerGas:YO(t[2],"maxPriorityFeePerGas"),maxFeePerGas:YO(t[3],"maxFeePerGas"),gasPrice:null,gasLimit:YO(t[4],"gasLimit"),to:VO(t[5]),value:YO(t[6],"value"),data:CS(t[7]),accessList:JO(t[8],"accessList"),maxFeePerBlobGas:YO(t[9],"maxFeePerBlobGas"),blobVersionedHashes:t[10],blobWrapperVersion:r};i&&(s.blobs=i),bS(null!=s.to,`invalid address for transaction type: ${n}`,"data",e),bS(Array.isArray(s.blobVersionedHashes),"invalid blobVersionedHashes: must be an array","data",e);for(let a=0;a<s.blobVersionedHashes.length;a++)bS(xS(s.blobVersionedHashes[a],32),`invalid blobVersionedHash at index ${a}: must be length 32`,"data",e);return 11===t.length||tR(s,t.slice(11)),s}(n));case 4:return e.from(function(e){const t=Qx(TS(e).slice(1));bS(Array.isArray(t)&&(10===t.length||13===t.length),"invalid field count for transaction type: 4","data",CS(e));const n={type:4,chainId:YO(t[0],"chainId"),nonce:WO(t[1],"nonce"),maxPriorityFeePerGas:YO(t[2],"maxPriorityFeePerGas"),maxFeePerGas:YO(t[3],"maxFeePerGas"),gasPrice:null,gasLimit:YO(t[4],"gasLimit"),to:VO(t[5]),value:YO(t[6],"value"),data:CS(t[7]),accessList:JO(t[8],"accessList"),authorizationList:KO(t[9],"authorizationList")};return 10===t.length||tR(n,t.slice(10)),n}(n))}gS(!1,"unsupported transaction type","UNSUPPORTED_OPERATION",{operation:"from"})}const n=new e;return null!=t.type&&(n.type=t.type),null!=t.to&&(n.to=t.to),null!=t.nonce&&(n.nonce=t.nonce),null!=t.gasLimit&&(n.gasLimit=t.gasLimit),null!=t.gasPrice&&(n.gasPrice=t.gasPrice),null!=t.maxPriorityFeePerGas&&(n.maxPriorityFeePerGas=t.maxPriorityFeePerGas),null!=t.maxFeePerGas&&(n.maxFeePerGas=t.maxFeePerGas),null!=t.maxFeePerBlobGas&&(n.maxFeePerBlobGas=t.maxFeePerBlobGas),null!=t.data&&(n.data=t.data),null!=t.value&&(n.value=t.value),null!=t.chainId&&(n.chainId=t.chainId),null!=t.signature&&(n.signature=VN.from(t.signature)),null!=t.accessList&&(n.accessList=t.accessList),null!=t.authorizationList&&(n.authorizationList=t.authorizationList),null!=t.blobVersionedHashes&&(n.blobVersionedHashes=t.blobVersionedHashes),null!=t.kzg&&(n.kzg=t.kzg),null!=t.blobWrapperVersion&&(n.blobWrapperVersion=t.blobWrapperVersion),null!=t.blobs&&(n.blobs=t.blobs),null!=t.hash&&(bS(n.isSigned(),"unsigned transaction cannot define '.hash'","tx",t),bS(n.hash===t.hash,"hash mismatch","tx",t)),null!=t.from&&(bS(n.isSigned(),"unsigned transaction cannot define '.from'","tx",t),bS(n.from.toLowerCase()===(t.from||"").toLowerCase(),"from mismatch","tx",t)),n}};function rR(e){return bS("string"==typeof e.address,"invalid address for hashAuthorization","auth.address",e),RP(NS(["0x05",Wx([null!=e.chainId?YS(e.chainId):"0x",nO(e.address),null!=e.nonce?YS(e.nonce):"0x"])]))}function iR(e,t){return $O(rR(e),t)}function sR(e){return RP(ux(e))}const aR=new Map([[8217,"apostrophe"],[8260,"fraction slash"],[12539,"middle dot"]]);function oR(e){return function(e){let t=0;return()=>e[t++]}(function(e){let t=0;function n(){return e[t++]<<8|e[t++]}let r=n(),i=1,s=[0,1];for(let w=1;w<r;w++)s.push(i+=n());let a=n(),o=t;t+=a;let c=0,A=0;function l(){return 0==c&&(A=A<<8|e[t++],c=8),A>>--c&1}const f=2**31,u=f>>>1,d=u>>1,h=f-1;let p=0;for(let w=0;w<31;w++)p=p<<1|l();let m=[],y=0,g=f;for(;;){let e=Math.floor(((p-y+1)*i-1)/g),t=0,n=r;for(;n-t>1;){let r=t+n>>>1;e<s[r]?n=r:t=r}if(0==t)break;m.push(t);let a=y+Math.floor(g*s[t]/i),o=y+Math.floor(g*s[t+1]/i)-1;for(;0==((a^o)&u);)p=p<<1&h|l(),a=a<<1&h,o=o<<1&h|1;for(;a&~o&d;)p=p&u|p<<1&h>>>1|l(),a=a<<1^u,o=(o^u)<<1|u|1;y=a,g=1+o-a}let b=r-4;return m.map(t=>{switch(t-b){case 3:return b+65792+(e[o++]<<16|e[o++]<<8|e[o++]);case 2:return b+256+(e[o++]<<8|e[o++]);case 1:return b+e[o++];default:return t-1}})}(function(e){let t=[];[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"].forEach((e,n)=>t[e.charCodeAt(0)]=n);let n=e.length,r=new Uint8Array(6*n>>3);for(let i=0,s=0,a=0,o=0;i<n;i++)o=o<<6|t[e.charCodeAt(i)],a+=6,a>=8&&(r[s++]=o>>(a-=8));return r}(e)))}function cR(e){return 1&e?~e>>1:e>>1}function AR(e,t){let n=Array(e);for(let r=0,i=0;r<e;r++)n[r]=i+=cR(t());return n}function lR(e,t=0){let n=[];for(;;){let r=e(),i=e();if(!i)break;t+=r;for(let e=0;e<i;e++)n.push(t+e);t+=i+1}return n}function fR(e){return dR(()=>{let t=lR(e);if(t.length)return t})}function uR(e){let t=[];for(;;){let n=e();if(0==n)break;t.push(pR(n,e))}for(;;){let n=e()-1;if(n<0)break;t.push(mR(n,e))}return t.flat()}function dR(e){let t=[];for(;;){let n=e(t.length);if(!n)break;t.push(n)}return t}function hR(e,t,n){let r=Array(e).fill().map(()=>[]);for(let i=0;i<t;i++)AR(e,n).forEach((e,t)=>r[t].push(e));return r}function pR(e,t){let n=1+t(),r=t(),i=dR(t);return hR(i.length,1+e,t).flatMap((e,t)=>{let[s,...a]=e;return Array(i[t]).fill().map((e,t)=>{let i=t*r;return[s+t*n,a.map(e=>e+i)]})})}function mR(e,t){return hR(1+t(),1+e,t).map(e=>[e[0],e.slice(1)])}function yR(e){return`{${function(e){return e.toString(16).toUpperCase().padStart(2,"0")}(e)}}`}function gR(e){let t=e.length;if(t<4096)return String.fromCodePoint(...e);let n=[];for(let r=0;r<t;)n.push(String.fromCodePoint(...e.slice(r,r+=4096)));return n.join("")}function bR(e,t){let n=e.length,r=n-t.length;for(let i=0;0==r&&i<n;i++)r=e[i]-t[i];return r}const wR=44032,vR=4352,_R=4449,ER=4519;function kR(e){return e>>24&255}function TR(e){return 16777215&e}let SR,xR,IR,PR;function CR(e){return e>=wR&&e<55204}function NR(e,t){if(e>=vR&&e<4371&&t>=_R&&t<4470)return wR+588*(e-vR)+28*(t-_R);if(CR(e)&&t>ER&&t<4547&&(e-wR)%28==0)return e+(t-ER);{let n=PR.get(e);return n&&(n=n.get(t),n)?n:-1}}function OR(e){SR||function(){let e=oR("AEUDTAHBCFQATQDRADAAcgAgADQAFAAsABQAHwAOACQADQARAAoAFwAHABIACAAPAAUACwAFAAwABAAQAAMABwAEAAoABQAIAAIACgABAAQAFAALAAIACwABAAIAAQAHAAMAAwAEAAsADAAMAAwACgANAA0AAwAKAAkABAAdAAYAZwDSAdsDJgC0CkMB8xhZAqfoC190UGcThgBurwf7PT09Pb09AjgJum8OjDllxHYUKXAPxzq6tABAxgK8ysUvWAgMPT09PT09PSs6LT2HcgWXWwFLoSMEEEl5RFVMKvO0XQ8ExDdJMnIgsj26PTQyy8FfEQ8AY8IPAGcEbwRwBHEEcgRzBHQEdQR2BHcEeAR6BHsEfAR+BIAEgfndBQoBYgULAWIFDAFiBNcE2ATZBRAFEQUvBdALFAsVDPcNBw13DYcOMA4xDjMB4BllHI0B2grbAMDpHLkQ7QHVAPRNQQFnGRUEg0yEB2uaJF8AJpIBpob5AERSMAKNoAXqaQLUBMCzEiACnwRZEkkVsS7tANAsBG0RuAQLEPABv9HICTUBXigPZwRBApMDOwAamhtaABqEAY8KvKx3LQ4ArAB8UhwEBAVSagD8AEFZADkBIadVj2UMUgx5Il4ANQC9AxIB1BlbEPMAs30CGxlXAhwZKQIECBc6EbsCoxngzv7UzRQA8M0BawL6ZwkN7wABAD33OQRcsgLJCjMCjqUChtw/km+NAsXPAoP2BT84PwURAK0RAvptb6cApQS/OMMey5HJS84UdxpxTPkCogVFITaTOwERAK5pAvkNBOVyA7q3BKlOJSALAgUIBRcEdASpBXqzABXFSWZOawLCOqw//AolCZdvv3dSBkEQGyelEPcMMwG1ATsN7UvYBPEGOwTJH30ZGQ/NlZwIpS3dDO0m4y6hgFoj9SqDBe1L9DzdC01RaA9ZC2UJ4zpjgU4DIQENIosK3Q05CG0Q8wrJaw3lEUUHOQPVSZoApQcBCxEdNRW1JhBirAsJOXcG+xr2C48mrxMpevwF0xohBk0BKRr/AM8u54WwWjFcHE9fBgMLJSPHFKhQIA0lQLd4SBobBxUlqQKRQ3BKh1E2HpMh9jw9DWYuE1F8B/U8BRlPC4E8nkarRQ4R0j6NPUgiSUwsBDV/LC8niwnPD4UMuXxyAVkJIQmxDHETMREXN8UIOQcZLZckJxUIIUaVYJoE958D8xPRAwsFPwlBBxMDtRwtEy4VKQUNgSTXAvM21S6zAo9WgAEXBcsPJR/fEFBH4A7pCJsCZQODJesALRUhABcimwhDYwBfj9hTBS7LCMdqbCN0A2cU52ERcweRDlcHpxwzFb8c4XDIXguGCCijrwlbAXUJmQFfBOMICTVbjKAgQWdTi1gYmyBhQT9d/AIxDGUVn0S9h3gCiw9rEhsBNQFzBzkNAQJ3Ee0RaxCVCOuGBDW1M/g6JQRPIYMgEQonA09szgsnJvkM+GkBoxJiAww0PXfuZ6tgtiQX/QcZMsVBYCHxC5JPzQycGsEYQlQuGeQHvwPzGvMn6kFXBf8DowMTOk0z7gS9C2kIiwk/AEkOoxcH1xhqCnGM0AExiwG3mQNXkYMCb48GNwcLAGcLhwV55QAdAqcIowAFAM8DVwA5Aq0HnQAZAIVBAT0DJy8BIeUCjwOTCDHLAZUvAfMpBBvDDBUA9zduSgLDsQKAamaiBd1YAo4CSTUBTSUEBU5HUQOvceEA2wBLBhPfRwEVq0rLGuNDAd9vKwDHAPsABTUHBUEBzQHzbQC3AV8LMQmis7UBTekpAIMAFWsB1wKJAN0ANQB/8QFTAE0FWfkF0wJPSQERMRgrV2EBuwMfATMBDQB5BsuNpckHHwRtB9MCEBsV4QLvLge1AQMi3xPNQsUCvd5VoWACZIECYkJbTa9bNyACofcCaJgCZgkCn4Q4GwsCZjsCZiYEbgR/A38TA36SOQY5dxc5gjojIwJsHQIyNjgKAm3HAm2u74ozZ0UrAWcA3gDhAEoFB5gMjQD+C8IADbUCdy8CdqI/AnlLQwJ4uh1c20WuRtcCfD8CesgCfQkCfPAFWQUgSABIfWMkAoFtAoAAAoAFAn+uSVhKWxUXSswC0QEC0MxLJwOITwOH5kTFkTIC8qFdAwMDrkvOTC0lA89NTE2vAos/AorYwRsHHUNnBbcCjjcCjlxAl4ECjtkCjlx4UbRTNQpS1FSFApP7ApMMAOkAHFUeVa9V0AYsGymVhjLheGZFOzkCl58C77JYIagAWSUClo8ClnycAKlZrFoJgU0AOwKWtQKWTlxEXNECmcsCmWRcyl0HGQKcmznCOp0CnBYCn5sCnriKAB0PMSoPAp3xAp6SALU9YTRh7wKe0wKgbgGpAp6fHwKeTqVjyGQnJSsCJ68CJn4CoPsCoEwCot0CocQCpi8Cpc4Cp/8AfQKn8mh8aLEAA0lqHGrRAqzjAqyuAq1nAq0CAlcdAlXcArHh1wMfTmyXArK9DQKy6Bds4G1jbUhfAyXNArZcOz9ukAMpRQK4XgK5RxUCuSp3cDZw4QK9GQK72nCWAzIRAr6IcgIDM3ECvhpzInNPAsPLAsMEc4J0SzVFdOADPKcDPJoDPb8CxXwCxkcCxhCJAshpUQLIRALJTwLJLgJknQLd0nh5YXiueSVL0AMYo2cCAmH0GfOVJHsLXpJeuxECz2sCz2wvS1PS8xOfAMatAs9zASnqA04SfksFAtwnAtuKAtJPA1JcA1NfAQEDVYyAiT8AyxbtYEWCHILTgs6DjQLaxwLZ3oQQhEmnPAOGpQAvA2QOhnFZ+QBVAt9lAt64c3cC4i/tFAHzMCcB9JsB8tKHAuvzAulweQLq+QLq5AD5RwG5Au6JAuuclqqXAwLuPwOF4Jh5cOBxoQLzAwBpA44WmZMC9xMDkW4DkocC95gC+dkC+GaaHJqruzebHgOdgwL++gEbADmfHJ+zAwWNA6ZqA6bZANHFAwZqoYiiBQkDDEkCwAA/AwDhQRdTARHzA2sHl2cFAJMtK7evvdsBiZkUfxEEOQH7KQUhDp0JnwCS/SlXxQL3AZ0AtwW5AG8LbUEuFCaNLgFDAYD8AbUmAHUDDgRtACwCFgyhAAAKAj0CagPdA34EkQEgRQUhfAoABQBEABMANhICdwEABdUDa+8KxQIA9wqfJ7+xt+UBkSFBQgHpFH8RNMCJAAQAGwBaAkUChIsABjpTOpSNbQC4Oo860ACNOME63AClAOgAywE6gTo7Ofw5+Tt2iTpbO56JOm85GAFWATMBbAUvNV01njWtNWY1dTW2NcU1gjWRNdI14TWeNa017jX9NbI1wTYCNhE1xjXVNhY2JzXeNe02LjY9Ni41LSE2OjY9Njw2yTcIBJA8VzY4Nt03IDcPNsogN4k3MAoEsDxnNiQ3GTdsOo03IULUQwdC4EMLHA8PCZsobShRVQYA6X8A6bABFCnXAukBowC9BbcAbwNzBL8MDAMMAQgDAAkKCwsLCQoGBAVVBI/DvwDz9b29kaUCb0QtsRTNLt4eGBcSHAMZFhYZEhYEARAEBUEcQRxBHEEcQRxBHEEaQRxBHEFCSTxBPElISUhBNkM2QTYbNklISVmBVIgBFLWZAu0BhQCjBcEAbykBvwGJAaQcEZ0ePCklMAAhMvAIMAL54gC7Bm8EescjzQMpARQpKgDUABavAj626xQAJP0A3etzuf4NNRA7efy2Z9NQrCnC0OSyANz5BBIbJ5IFDR6miIavYS6tprjjmuKebxm5C74Q225X1pkaYYPb6f1DK4k3xMEBb9S2WMjEibTNWhsRJIA+vwNVEiXTE5iXs/wezV66oFLfp9NZGYW+Gk19J2+bCT6Ye2w6LDYdgzKMUabk595eLBCXANz9HUpWbATq9vqXVx9XDg+Pc9Xp4+bsS005SVM/BJBM4687WUuf+Uj9dEi8aDNaPxtpbDxcG1THTImUMZq4UCaaNYpsVqraNyKLJXDYsFZ/5jl7bLRtO88t7P3xZaAxhb5OdPMXqsSkp1WCieG8jXm1U99+blvLlXzPCS+M93VnJCiK+09LfaSaBAVBomyDgJua8dfUzR7ga34IvR2Nvj+A9heJ6lsl1KG4NkI1032Cnff1m1wof2B9oHJK4bi6JkEdSqeNeiuo6QoZZincoc73/TH9SXF8sCE7XyuYyW8WSgbGFCjPV0ihLKhdPs08Tx82fYAkLLc4I2wdl4apY7GU5lHRFzRWJep7Ww3wbeA3qmd59/86P4xuNaqDpygXt6M85glSBHOCGgJDnt+pN9bK7HApMguX6+06RZNjzVmcZJ+wcUrJ9//bpRNxNuKpNl9uFds+S9tdx7LaM5ZkIrPj6nIU9mnbFtVbs9s/uLgl8MVczAwet+iOEzzBlYW7RCMgE6gyNLeq6+1tIx4dpgZnd0DksJS5f+JNDpwwcPNXaaVspq1fbQajOrJgK0ofKtJ1Ne90L6VO4MOl5S886p7u6xo7OLjG8TGL+HU1JXGJgppg4nNbNJ5nlzSpuPYy21JUEcUA94PoFiZfjZue+QnyQ80ekOuZVkxx4g+cvhJfHgNl4hy1/a6+RKcKlar/J29y//EztlbVPHVUeQ1zX86eQVAjR/M3dA9w4W8LfaXp4EgM85wOWasli837PzVMOnsLzR+k3o75/lRPAJSE1xAKQzEi5v10ke+VBvRt1cwQRMd+U5mLCTGVd6XiZtgBG5cDi0w22GKcVNvHiu5LQbZEDVtz0onn7k5+heuKXVsZtSzilkLRAUmjMXEMB3J9YC50XBxPiz53SC+EhnPl9WsKCv92SM/OFFIMJZYfl0WW8tIO3UxYcwdMAj7FSmgrsZ2aAZO03BOhP1bNNZItyXYQFTpC3SG1VuPDqH9GkiCDmE+JwxyIVSO5siDErAOpEXFgjy6PQtOVDj+s6e1r8heWVvmZnTciuf4EiNZzCAd7SOMhXERIOlsHIMG399i9aLTy3m2hRLZjJVDNLS53iGIK11dPqQt0zBDyg6qc7YqkDm2M5Ve6dCWCaCbTXX2rToaIgz6+zh4lYUi/+6nqcFMAkQJKHYLK0wYk5N9szV6xihDbDDFr45lN1K4aCXBq/FitPSud9gLt5ZVn+ZqGX7cwm2z5EGMgfFpIFyhGGuDPmso6TItTMwny+7uPnLCf4W6goFQFV0oQSsc9VfMmVLcLr6ZetDZbaSFTLqnSO/bIPjA3/zAUoqgGFAEQS4IhuMzEp2I3jJzbzkk/IEmyax+rhZTwd6f+CGtwPixu8IvzACquPWPREu9ZvGkUzpRwvRRuaNN6cr0W1wWits9ICdYJ7ltbgMiSL3sTPeufgNcVqMVWFkCPDH4jG2jA0XcVgQj62Cb29v9f/z/+2KbYvIv/zzjpQAPkliaVDzNrW57TZ/ZOyZD0nlfMmAIBIAGAI0D3k/mdN4xr9v85ZbZbbqfH2jGd5hUqNZWwl5SPfoGmfElmazUIeNL1j/mkF7VNAzTq4jNt8JoQ11NQOcmhprXoxSxfRGJ9LDEOAQ+dmxAQH90iti9e2u/MoeuaGcDTHoC+xsmEeWmxEKefQuIzHbpw5Tc5cEocboAD09oipWQhtTO1wivf/O+DRe2rpl/E9wlrzBorjJsOeG1B/XPW4EaJEFdNlECEZga5ZoGRHXgYouGRuVkm8tDESiEyFNo+3s5M5puSdTyUL2llnINVHEt91XUNW4ewdMgJ4boJfEyt/iY5WXqbA+A2Fkt5Z0lutiWhe9nZIyIUjyXDC3UsaG1t+eNx6z4W/OYoTB7A6x+dNSTOi9AInctbESqm5gvOLww7OWXPrmHwVZasrl4eD113pm+JtT7JVOvnCXqdzzdTRHgJ0PiGTFYW5Gvt9R9LD6Lzfs0v/TZZHSmyVNq7viIHE6DBK7Qp07Iz55EM8SYtQvZf/obBniTWi5C2/ovHfw4VndkE5XYdjOhCMRjDeOEfXeN/CwfGduiUIfsoFeUxXeQXba7c7972XNv8w+dTjjUM0QeNAReW+J014dKAD/McQYXT7c0GQPIkn3Ll6R7gGjuiQoZD0TEeEqQpKoZ15g/0OPQI17QiSv9AUROa/V/TQN3dvLArec3RrsYlvBm1b8LWzltdugsC50lNKYLEp2a+ZZYqPejULRlOJh5zj/LVMyTDvwKhMxxwuDkxJ1QpoNI0OTWLom4Z71SNzI9TV1iXJrIu9Wcnd+MCaAw8o1jSXd94YU/1gnkrC9BUEOtQvEIQ7g0i6h+KL2JKk8Ydl7HruvgWMSAmNe+LshGhV4qnWHhO9/RIPQzY1tHRj2VqOyNsDpK0cww+56AdDC4gsWwY0XxoucIWIqs/GcwnWqlaT0KPr8mbK5U94/301i1WLt4YINTVvCFBrFZbIbY8eycOdeJ2teD5IfPLCRg7jjcFTwlMFNl9zdh/o3E/hHPwj7BWg0MU09pPrBLbrCgm54A6H+I6v27+jL5gkjWg/iYdks9jbfVP5y/n0dlgWEMlKasl7JvFZd56LfybW1eeaVO0gxTfXZwD8G4SI116yx7UKVRgui6Ya1YpixqXeNLc8IxtAwCU5IhwQgn+NqHnRaDv61CxKhOq4pOX7M6pkA+Pmpd4j1vn6ACUALoLLc4vpXci8VidLxzm7qFBe7s+quuJs6ETYmnpgS3LwSZxPIltgBDXz8M1k/W2ySNv2f9/NPhxLGK2D21dkHeSGmenRT3Yqcdl0m/h3OYr8V+lXNYGf8aCCpd4bWjE4QIPj7vUKN4Nrfs7ML6Y2OyS830JCnofg/k7lpFpt4SqZc5HGg1HCOrHvOdC8bP6FGDbE/VV0mX4IakzbdS/op+Kt3G24/8QbBV7y86sGSQ/vZzU8FXs7u6jIvwchsEP2BpIhW3G8uWNwa3HmjfH/ZjhhCWvluAcF+nMf14ClKg5hGgtPLJ98ueNAkc5Hs2WZlk2QHvfreCK1CCGO6nMZVSb99VM/ajr8WHTte9JSmkXq/i/U943HEbdzW6Re/S88dKgg8pGOLlAeNiqrcLkUR3/aClFpMXcOUP3rmETcWSfMXZE3TUOi8i+fqRnTYLflVx/Vb/6GJ7eIRZUA6k3RYR3iFSK9c4iDdNwJuZL2FKz/IK5VimcNWEqdXjSoxSgmF0UPlDoUlNrPcM7ftmA8Y9gKiqKEHuWN+AZRIwtVSxye2Kf8rM3lhJ5XcBXU9n4v0Oy1RU2M+4qM8AQPVwse8ErNSob5oFPWxuqZnVzo1qB/IBxkM3EVUKFUUlO3e51259GgNcJbCmlvrdjtoTW7rChm1wyCKzpCTwozUUEOIcWLneRLgMXh+SjGSFkAllzbGS5HK7LlfCMRNRDSvbQPjcXaenNYxCvu2Qyznz6StuxVj66SgI0T8B6/sfHAJYZaZ78thjOSIFumNWLQbeZixDCCC+v0YBtkxiBB3jefHqZ/dFHU+crbj6OvS1x/JDD7vlm7zOVPwpUC01nhxZuY/63E7g");SR=new Map(fR(e).flatMap((e,t)=>e.map(e=>[e,t+1<<24]))),xR=new Set(lR(e)),IR=new Map,PR=new Map;for(let[t,n]of uR(e)){if(!xR.has(t)&&2==n.length){let[e,r]=n,i=PR.get(e);i||(i=new Map,PR.set(e,i)),i.set(r,t)}IR.set(t,n.reverse())}}();let t=[],n=[],r=!1;function i(e){let n=SR.get(e);n&&(r=!0,e|=n),t.push(e)}for(let s of e)for(;;){if(s<128)t.push(s);else if(CR(s)){let e=s-wR,t=e%588/28|0,n=e%28;i(vR+(e/588|0)),i(_R+t),n>0&&i(ER+n)}else{let e=IR.get(s);e?n.push(...e):i(s)}if(!n.length)break;s=n.pop()}if(r&&t.length>1){let e=kR(t[0]);for(let n=1;n<t.length;n++){let r=kR(t[n]);if(0==r||e<=r){e=r;continue}let i=n-1;for(;;){let n=t[i+1];if(t[i+1]=t[i],t[i]=n,!i)break;if(e=kR(t[--i]),e<=r)break}e=kR(t[n])}}return t}function RR(e){return OR(e).map(TR)}function BR(e){return function(e){let t=[],n=[],r=-1,i=0;for(let s of e){let e=kR(s),a=TR(s);if(-1==r)0==e?r=a:t.push(a);else if(i>0&&i>=e)0==e?(t.push(r,...n),n.length=0,r=a):n.push(a),i=e;else{let s=NR(r,a);s>=0?r=s:0==i&&0==e?(t.push(r),r=a):(n.push(a),i=e)}}return r>=0&&t.push(r,...n),t}(OR(e))}const MR=e=>Array.from(e);function $R(e,t){return e.P.has(t)||e.Q.has(t)}class DR extends Array{get is_emoji(){return!0}}let FR,GR,UR,LR,jR,HR,zR,qR,QR,VR,JR;function KR(){if(FR)return;let e=oR("AEEUdwmgDS8BxQKKAP4BOgDjATAAngDUAIMAoABoAOAAagCOAEQAhABMAHIAOwA9ACsANgAmAGIAHgAuACgAJwAXAC0AGgAjAB8ALwAUACkAEgAeAAkAGwARABkAFgA5ACgALQArADcAFQApABAAHgAiABAAGgAeABMAGAUhBe8BFxREN8sF2wC5AK5HAW8ArQkDzQCuhzc3NzcBP68NEfMABQdHBuw5BV8FYAA9MzkI9r4ZBg7QyQAWA9CeOwLNCjcCjqkChuA/lm+RAsXTAoP6ASfnEQDytQFJAjWVCkeXAOsA6godAB/cwdAUE0WlBCN/AQUCQRjFD/MRBjHxDQSJbw0jBzUAswBxme+tnIcAYwabAysG8QAjAEMMmxcDqgPKQyDXCMMxA7kUQwD3NXOrAKmFIAAfBC0D3x4BJQDBGdUFAhEgVD8JnwmQJiNWYUzrg0oAGwAUAB0AFnNcACkAFgBP9h3gPfsDOWDKneY2ChglX1UDYD30ABsAFAAdABZzIGRAnwDD8wAjAEEMzRbDqgMB2sAFYwXqAtCnAsS4AwpUJKRtFHsadUz9AMMVbwLpABM1NJEX0ZkCgYMBEyMAxRVvAukAEzUBUFAtmUwSAy4DBTER33EftQHfSwB5MxJ/AjkWKQLzL8E/cwBB6QH9LQDPDtO9ASNriQC5DQANAwCK21EFI91zHwCoL9kBqQcHBwcHKzUDowBvAQohPvU3fAQgHwCyAc8CKQMA5zMSezr7ULgFmDp/LzVQBgEGAi8FYQVgt8AFcTtlQhpCWEmfe5tmZ6IAExsDzQ8t+X8rBKtTAltbAn0jsy8Bl6utPWMDTR8Ei2kRANkDBrNHNysDBzECQWUAcwFpJ3kAiyUhAJ0BUb8AL3EfAbfNAz81KUsFWwF3YQZtAm0A+VEfAzEJDQBRSQCzAQBlAHsAM70GD/v3IZWHBwARKQAxALsjTwHZAeMPEzmXgIHwABIAGQA8AEUAQDt3gdvIEGcQZAkGTRFMdEIVEwK0D64L7REdDNkq09PgADSxB/MDWwfzA1sDWwfzB/MDWwfzA1sDWwNbA1scEvAi28gQZw9QBHUFlgWTBN4IiyZREYkHMAjaVBV0JhxPA00BBCMtSSQ7mzMTJUpMFE0LCAQ2SmyvfUADTzGzVP2QqgPTMlc5dAkGHnkSqAAyD3skNb1OhnpPcagKU0+2tYdJak5vAsY6sEAACikJm2/Dd1YGRRAfJ6kQ+ww3AbkBPw3xS9wE9QY/BM0fgRkdD9GVoAipLeEM8SbnLqWAXiP5KocF8Uv4POELUVFsD10LaQnnOmeBUgMlAREijwrhDT0IcRD3Cs1vDekRSQc9A9lJngCpBwULFR05FbkmFGKwCw05ewb/GvoLkyazEy17AAXXGiUGUQEtGwMA0y7rhbRaNVwgT2MGBwspI8sUrFAkDSlAu3hMGh8HGSWtApVDdEqLUToelyH6PEENai4XUYAH+TwJGVMLhTyiRq9FEhHWPpE9TCJNTDAEOYMsMyePCdMPiQy9fHYBXQklCbUMdRM1ERs3yQg9Bx0xlygnGQglRplgngT7owP3E9UDDwVDCUUHFwO5HDETMhUtBRGBKNsC9zbZLrcCk1aEARsFzw8pH+MQVEfkDu0InwJpA4cl7wAxFSUAGyKfCEdnAGOP3FMJLs8Iy2pwI3gDaxTrZRF3B5UOWwerHDcVwxzlcMxeD4YMKKezCV8BeQmdAWME5wgNNV+MpCBFZ1eLXBifIGVBQ14AAjUMaRWjRMGHfAKPD28SHwE5AXcHPQ0FAnsR8RFvEJkI74YINbkz/DopBFMhhyAVCisDU2zSCysm/Qz8bQGnEmYDEDRBd/Jnr2C6KBgBBx0yyUFkIfULlk/RDKAaxRhGVDIZ6AfDA/ca9yfuQVsGAwOnBxc6UTPyBMELbQiPCUMATQ6nGwfbGG4KdYzUATWPAbudA1uVhwJzkwY7Bw8Aaw+LBX3pACECqwinAAkA0wNbAD0CsQehAB0AiUUBQQMrMwEl6QKTA5cINc8BmTMB9y0EH8cMGQD7O25OAsO1AoBuZqYF4VwCkgJNOQFRKQQJUktVA7N15QDfAE8GF+NLARmvTs8e50cB43MvAMsA/wAJOQcJRQHRAfdxALsBYws1Caa3uQFR7S0AhwAZbwHbAo0A4QA5AIP1AVcAUQVd/QXXAlNNARU1HC9bZQG/AyMBNwERAH0Gz5GpzQsjBHEH1wIQHxXlAu8yB7kFAyLjE9FCyQK94lkAMhoKPAqrCqpgX2Q3CjV2PVQAEh+sPss/UgVVO1c7XDtXO1w7VztcO1c7XDtXO1wDm8Pmw+YKcF9JYe8Mqg3YRMw6TRPfYFVgNhPMLbsUxRXSJVoZQRrAJwkl6FUNDwgt12Y0CDA0eRfAAEMpbINFY4oeNApPHOtTlVT8LR8AtUumM7MNsBsZREQFS3XxYi4WEgomAmSFAmJGX1GzAV83JAKh+wJonAJmDQKfiDgfDwJmPwJmKgRyBIMDfxcDfpY5Cjl7GzmGOicnAmwhAjI6OA4CbcsCbbLzjgM3a0kvAWsA4gDlAE4JB5wMkQECD8YAEbkCdzMCdqZDAnlPRwJ4viFg30WyRvcCfEMCeswCfQ0CfPRIBEiBZygALxlJXEpfGRtK0ALRBQLQ0EsrA4hTA4fqRMmRNgLypV0HAwOyS9JMMSkH001QTbMCi0MCitzFHwshR2sJuwKOOwKOYESbhQKO3QKOYHxRuFM5AQ5S2FSJApP/ApMQAO0AIFUiVbNV1AosHymZijLleGpFPz0Cl6MC77ZYJawAXSkClpMCloCgAK1ZsFoNhVEAPwKWuQKWUlxIXNUCmc8CmWhczl0LHQKcnznGOqECnBoCn58CnryOACETNS4TAp31Ap6WALlBYThh8wKe1wKgcgGtAp6jIwKeUqljzGQrKS8CJ7MCJoICoP8CoFDbAqYzAqXSAqgDAIECp/ZogGi1AAdNaiBq1QKs5wKssgKtawKtBgJXIQJV4AKx5dsDH1JsmwKywRECsuwbbORtZ21MYwMl0QK2YD9DbpQDKUkCuGICuUsZArkue3A6cOUCvR0DLbYDMhUCvoxyBgMzdQK+HnMmc1MCw88CwwhzhnRPOUl05AM8qwEDPJ4DPcMCxYACxksCxhSNAshtVQLISALJUwLJMgJkoQLd1nh9ZXiyeSlL1AMYp2cGAmH4GfeVKHsPXpZevxUCz28Cz3AzT1fW9xejAMqxAs93AS3uA04Wfk8JAtwrAtuOAtJTA1JgA1NjAQUDVZCAjUMEzxrxZEl5A4LSg5EC2ssC2eKEFIRNp0ADhqkAMwNkEoZ1Xf0AWQLfaQLevHd7AuIz7RgB8zQrAfSfAfLWiwLr9wLpdH0DAur9AuroAP1LAb0C7o0C66CWrpcHAu5DA4XkmH1w5HGlAvMHAG0DjhqZlwL3FwORcgOSiwL3nAL53QL4apogmq+/O5siA52HAv7+AR8APZ8gAZ+3AwWRA6ZuA6bdANXJAwZuoYyiCQ0DDE0BEwEjB3EGZb1rCQC/BG/DFY8etxEAG3k9ACcDNxJRA42DAWcrJQCM8wAlAOanC6OVCLsGI6fJBgCvBRnDBvElRUYFFoAFcD9GSDNCKUK8X3kZX8QAls0FOgCQVCGbwTsuYDoZutcONxjOGJHJ/gVfBWAFXwVgBWsFYAVfBWAFXwVgBV8FYAVfBWBOHQjfjW8KCgoKbF7xMwTRA7kGN8PDAMMEr8MA70gxFroFTj5xPnhCR0K+X30/X/AAWBkzswCNBsxzzASm70aCRS4rDDMeLz49fnXfcsH5GcoscQFz13Y4HwVnBXLJycnACNdRYwgICAqEXoWTxgA7P4kACxbZBu21Kw0AjMsTAwkVAOVtJUUsJ1JCuULESUArXy9gPi9AKwnJRQYKTD9LPoA+iT54PnkCkULEUUpDX9NWV3JVEjQAc1w3A3IBE3YnX+g7QiMJb6MKaiszRCUuQrNCxDPMCcwEX9EWJzYREBEEBwIHKn6l33JCNVIfybPJtAltydPUCmhBZw/tEKsZAJOVJU1CLRuxbUHOQAo7P0s+eEJHHA8SJVRPdGM0NVrpvBoKhfUlM0JHHGUQUhEWO1xLSj8MO0ucNAqJIzVCRxv9EFsqKyA4OQgNj2nwZgp5ZNFgE2A1K3YHS2AhQQojJmC7DgpzGG1WYFUZCQYHZO9gHWCdYIVgu2BTYJlwFh8GvRbcXbG8YgtDHrMBwzPVyQonHQgkCyYBgQJ0Ajc4nVqIAwGSCsBPIgDsK3SWEtIVBa5N8gGjAo+kVwVIZwD/AEUSCDweX4ITrRQsJ8K3TwBXFDwEAB0TvzVcAtoTS20RIwDgVgZ9BBImYgA5AL4Coi8LFnezOkCnIQFjAY4KBAPh9RcGsgZSBsEAJctdsWIRu2kTkQstRw7DAcMBKgpPBGIGMDAwKCYnKTQaLg4AKRSVAFwCdl+YUZ0JdicFD3lPAdt1F9ZZKCGxuE3yBxkFVGcA/wBFEgiCBwAOLHQSjxOtQDg1z7deFRMAZ8QTAGtKb1ApIiPHADkAvgKiLy1DFtYCmBiDAlDDWNB0eo7fpaMO/aEVRRv0ATEQZBIODyMEAc8JQhCbDRgzFD4TAEMAu9YBCgCsAOkAm5I3ABwAYxvONnR+MhXJAxgKQyxL2+kkJhMbhQKDBMkSsvF0AD9BNQ6uQC7WqSQHwxEAEEIu1hkhAH2z4iQPwyJPHNWpdyYBRSpnJALzoBAEVPPsH20MxA0CCEQKRgAFyAtFAlMNwwjEDUQJRArELtapMg7DDZgJIw+TGukEIwvDFkMAqAtDEMMMBhioe+QAO3MMRAACrgnEBSPY9Q0FDnbSBoMAB8MSYxkSxAEJAPIJAAB8FWMOFtMc/HcXwxhDAC7DAvOowwAewwJdKDKHAAHDAALrFUQVwwAbwyvzpWMWv8wA/ABpAy++bcYDUKPD0KhDCwKmJ1MAAmMA5+UZwxAagwipBRL/eADfw6fDGOMCGsOjk3l6BwOpo4sAEsMOGxMAA5sAbcMOAAvDp0MJGkMDwgipnNIPAwfIqUMGAOGDAAPzABXDAAcDAAnDAGmTABrDAA7DChjDjnEWAwABYwAOcwAuUyYABsMAF8MIKQANUgC6wy4AA8MADqMq8wCyYgAcIwAB8wqpAAXOCx0V4wAHowBCwwEKAGnDAAuDAB3DAAjDCakABdIAbqcZ3QCZCCkABdIAAAFDAAfjAB2jCCkABqIACYMAGzMAbSMA5sOIAAhjAAhDABTDBAkpAAbSAOOTAAlDC6kOzPtnAAdDAG6kQFAATwAKwwwAA0MACbUDPwAHIwAZgwACE6cDAAojAApDAAoDp/MGwwAJIwADEwAQQwgAFEMAEXMAD5MADfMADcMAGRMOFiMAFUMAbqMWuwHDAMIAE0MLAGkzEgDhUwACQwAEWgAXgwUjAAbYABjDBSYBgzBaAEFNALcQBxUMegAwMngBrA0IZgJ0KxQHBREPd1N0ZzKRJwaIHAZqNT4DqQq8BwngAB4DAwt2AX56T1ocKQNXAh1GATQGC3tOxYNagkgAMQA5CQADAQEAWxLjAIOYNAEzAH7tFRk6TglSAF8NAAlYAQ+S1ACAQwQorQBiAN4dAJ1wPyeTANVzuQDX3AIeEMp9eyMgXiUAEdkBkJizKltbVVAaRMqRAAEAhyQ/SDEz6BmfVwB6ATEsOClKIRcDOF0E/832AFNt5AByAnkCRxGCOs94NjXdAwINGBonDBwPALW2AwICAgAAAAAAAAYDBQMDARrUAwAtAAAAAgEGBgYGBgYFBQUFBQUEBQYHCAkEBQUFBQQAAAICAAAAIgCNAJAAlT0A6gC7ANwApEQAwgCyAK0AqADuAKYA2gCjAOcBCAEDAMcAgQBiANIA1AEDAN4A8gCQAKkBMQDqAN8A3AsBCQ8yO9ra2tq8xuLT1tRJOB0BUgFcNU0BWgFpAWgBWwFMUUlLbhMBUxsNEAs6PhMOACcUKy0vMj5AQENDQ0RFFEYGJFdXV1dZWVhZL1pbXVxcI2NnZ2ZoZypsbnZ1eHh4eHh4enp6enp6enp6enp8fH18e2IARPIASQCaAHgAMgBm+ACOAFcAVwA3AnbvAIsABfj4AGQAk/IAnwBPAGIAZP//sACFAIUAaQBWALEAJAC2AIMCQAJDAPwA5wD+AP4A6AD/AOkA6QDoAOYALwJ7AVEBQAE+AVQBPgE+AT4BOQE4ATgBOAEcAVgXADEQCAEAUx8SHgsdHhYAjgCWAKYAUQBqIAIxAHYAbwCXAxUDJzIDIUlGTzEAkQJPAMcCVwKkAMAClgKWApYClgKWApYCiwKWApYClgKWApYClgKVApUCmAKgApcClgKWApQClAKUApQCkgKVAnUB1AKXAp8ClgKWApUeAIETBQD+DQOfAmECOh8BVBg9AuIZEjMbAU4/G1WZAXusRAFpYQEFA0FPAQYAmTEeIJdyADFoAHEANgCRA5zMk/C2jGINwjMWygIZCaXdfDILBCs5dAE7YnQBugDlhoiHhoiGiYqKhouOjIaNkI6Ij4qQipGGkoaThpSSlYaWhpeKmIaZhpqGm4aci52QnoqfhuIC4XTpAt90AIp0LHSoAIsAdHQEQwRABEIERQRDBEkERgRBBEcESQRIBEQERgRJAJ5udACrA490ALxuAQ10ANFZdHQA13QCFHQA/mJ0AP4BIQD+APwA/AD9APwDhGZ03ASMK23HAP4A/AD8AP0A/CR0dACRYnQA/gCRASEA/gCRAvQA/gCRA4RmdNwEjCttxyR0AP9idAEhAP4A/gD8APwA/QD8AP8A/AD8AP0A/AOEZnTcBIwrbcckdHQAkWJ0ASEA/gCRAP4AkQL0AP4AkQOEZnTcBIwrbcckdAJLAT50AlIBQXQCU8l0dAJfdHQDpgL0A6YDpgOnA6cDpwOnA4RmdNwEjCttxyR0dACRYnQBIQOmAJEDpgCRAvQDpgCRA4RmdNwEjCttxyR0BDh0AJEEOQCRDpU5dSgCADR03gV2CwArdAEFAM5iCnR0AF1iAAYcOgp0dACRCnQAXAEIwWZ0CnRmdHQAkWZ0CnRmdEXgAFF03gp0dEY0tlT2u3SOAQTwscwhjZZKrhYcBSfFp9XNbKiVDOD2b+cpe4/Z17mQnbtzzhaeQtE2GGj0IDNTjRUSyTxxw/RPHW/+vS7d1NfRt9z9QPZg4X7QFfhCnkvgNPIItOsC2eV6hPannZNHlZ9xrwZXIMOlu3jSoQSq78WEjwLjw1ELSlF1aBvfzwk5ZX7AUvQzjPQKbDuQ+sm4wNOp4A6AdVuRS0t1y/DZpg4R6m7FNjM9HgvW7Bi88zaMjOo6lM8wtBBdj8LP4ylv3zCXPhebMKJc066o9sF71oFW/8JXu86HJbwDID5lzw5GWLR/LhT0Qqnp2JQxNZNfcbLIzPy+YypqRm/lBmGmex+82+PisxUumSeJkALIT6rJezxMH+CTJmQtt5uwTVbL3ptmjDUQzlSIvWi8Tl7ng1NpuRn1Ng4n14Qc+3Iil7OwkvNWogLSPkn3pihIFytyIGmMhOe3n1tWsuMy9BdKyqF4Z3v2SgggTL9KVvMXPnCbRe+oOuFFP3HejBG/w9gvmfNYvg6JuWia2lcSSN1uIjBktzoIazOHPJZ7kKHPz8mRWVdW3lA8WGF9dQF6Bm673boov3BUWDU2JNcahR23GtfHKLOz/viZ+rYnZFaIznXO67CYEJ1fXuTRpZhYZkKe54xeoagkNGLs+NTZHE0rX45/XvQ2RGADX6vcAvdxIUBV27wxGm2zjZo4X3ILgAlrOFheuZ6wtsvaIj4yLY7qqawlliaIcrz2G+c3vscAnCkCuMzMmZvMfu9lLwTvfX+3cVSyPdN9ZwgDZhfjRgNJcLiJ67b9xx8JHswprbiE3v9UphotAPIgnXVIN5KmMc0piXhc6cChPnN+MRhG9adtdttQTTwSIpl8I4/j//d3sz1326qTBTpPRM/Hgh3kzqEXs8ZAk4ErQhNO8hzrQ0DLkWMA/N+91tn2MdOJnWC2FCZehkQrwzwbKOjhvZsbM95QoeL9skYyMf4srVPVJSgg7pOLUtr/n9eT99oe9nLtFRpjA9okV2Kj8h9k5HaC0oivRD8VyXkJ81tcd4fHNXPCfloIQasxsuO18/46dR2jgul/UIet2G0kRvnyONMKhHs6J26FEoqSqd+rfYjeEGwHWVDpX1fh1jBBcKGMqRepju9Y00mDVHC+Xdij/j44rKfvfjGinNs1jO/0F3jB83XCDINN/HB84axlP+3E/klktRo+vl3U/aiyMJbIodE1XSsDn6UAzIoMtUObY2+k/4gY/l+AkZJ5Sj2vQrkyLm3FoxjhDX+31UXBFf9XrAH31fFqoBmDEZvhvvpnZ87N+oZEu7U9O/nnk+QWj3x8uyoRbEnf+O5UMr9i0nHP38IF5AvzrBW8YWBUR0mIAzIvndQq9N3v/Jto3aPjPXUPl8ASdPPyAp7jENf8bk7VMM9ol9XGmlBmeDMuGqt+WzuL6CXAxXjIhCPM5vACchgMJ/8XBGLO/D1isVvGhwwHHr1DLaI5mn2Jr/b1pUD90uciDaS8cXNDzCWvNmT/PhQe5e8nTnnnkt8Ds/SIjibcum/fqDhKopxAY8AkSrPn+IGDEKOO+U3XOP6djFs2H5N9+orhOahiQk5KnEUWa+CzkVzhp8bMHRbg81qhjjXuIKbHjSLSIBKWqockGtKinY+z4/RdBUF6pcc3JmnlxVcNgrI4SEzKUZSwcD2QCyxzKve+gAmg6ZuSRkpPFa6mfThu7LJNu3H5K42uCpNvPAsoedolKV/LHe/eJ+BbaG5MG0NaSGVPRUmNFMFFSSpXEcXwbVh7UETOZZtoVNRGOIbbkig3McEtR68cG0RZAoJevWYo7Dg/lZ1CQzblWeUvVHmr8fY4Nqd9JJiH/zEX24mJviH60fAyFr0A3c4bC1j3yZU60VgJxXn8JgJXLUIsiBnmKmMYz+7yBQFBvqb2eYnuW59joZBf56/wXvWIR4R8wTmV80i1mZy+S4+BUES+hzjk0uXpC///z/IlqHZ1monzlXp8aCfhGKMti73FI1KbL1q6IKO4fuBuZ59gagjn5xU79muMpHXg6S+e+gDM/U9BKLHbl9l6o8czQKl4RUkJJiqftQG2i3BMg/TQlUYFkJDYBOOvAugYuzYSDnZbDDd/aSd9x0Oe6F+bJcHfl9+gp6L5/TgA+BdFFovbfCrQ40s5vMPw8866pNX8zyFGeFWdxIpPVp9Rg1UPOVFbFZrvaFq/YAzHQgqMWpahMYfqHpmwXfHL1/kpYmGuHFwT55mQu0dylfNuq2Oq0hTMCPwqfxnuBIPLXfci4Y1ANy+1CUipQxld/izVh16WyG2Q0CQQ9NqtAnx1HCHwDj7sYxOSB0wopZSnOzxQOcExmxrVTF2BkOthVpGfuhaGECfCJpJKpjnihY+xOT2QJxN61+9K6QSqtv2Shr82I3jgJrqBg0wELFZPjvHpvzTtaJnLK6Vb97Yn933koO/saN7fsjwNKzp4l2lJVx2orjCGzC/4ZL4zCver6aQYtC5sdoychuFE6ufOiog+VWi5UDkbmvmtah/3aArEBIi39s5ILUnlFLgilcGuz9CQshEY7fw2ouoILAYPVT/gyAIq3TFAIwVsl+ktkRz/qGfnCDGrm5gsl/l9QdvCWGsjPz3dU7XuqKfdUrr/6XIgjp4rey6AJBmCmUJMjITHVdFb5m1p+dLMCL8t55zD42cmftmLEJC0Da04YiRCVUBLLa8D071/N5UBNBXDh0LFsmhV/5B5ExOB4j3WVG/S3lfK5o+V6ELHvy6RR9n4ac+VsK4VE4yphPvV+kG9FegTBH4ZRXL2HytUHCduJazB/KykjfetYxOXTLws267aGOd+I+JhKP//+VnXmS90OD/jvLcVu0asyqcuYN1mSb6XTlCkqv1vigZPIYwNF/zpWcT1GR/6aEIRjkh0yhg4LXJfaGobYJTY4JI58KiAKgmmgAKWdl5nYCeLqavRJGQNuYuZtZFGx+IkI4w4NS2xwbetNMunOjBu/hmKCI/w7tfiiyUd//4rbTeWt4izBY8YvGIN6vyKYmP/8X8wHKCeN+WRcKM70+tXKNGyevU9H2Dg5BsljnTf8YbsJ1TmMs74Ce2XlHisleguhyeg44rQOHZuw/6HTkhnnurK2d62q6yS7210SsAIaR+jXMQA+svkrLpsUY+F30Uw89uOdGAR6vo4FIME0EfVVeHTu6eKicfhSqOeXJhbftcd08sWEnNUL1C9fnprTgd83IMut8onVUF0hvqzZfHduPjbjwEXIcoYmy+P6tcJZHmeOv6VrvEdkHDJecjHuHeWANe79VG662qTjA/HCvumVv3qL+LrOcpqGps2ZGwQdFJ7PU4iuyRlBrwfO+xnPyr47s2cXVbWzAyznDiBGjCM3ksxjjqM62GE9C8f5U38kB3VjtabKp/nRdvMESPGDG90bWRLAt1Qk5DyLuazRR1YzdC1c+hZXvAWV8xA72S4A8B67vjVhbba3MMop293FeEXpe7zItMWrJG/LOH9ByOXmYnNJfjmfuX9KbrpgLOba4nZ+fl8Gbdv/ihv+6wFGKHCYrVwmhFC0J3V2bn2tIB1wCc1CST3d3X2OyxhguXcs4sm679UngzofuSeBewMFJboIQHbUh/m2JhW2hG9DIvG2t7yZIzKBTz9wBtnNC+2pCRYhSIuQ1j8xsz5VvqnyUIthvuoyyu7fNIrg/KQUVmGQaqkqZk/Vx5b33/gsEs8yX7SC1J+NV4icz6bvIE7C5G6McBaI8rVg56q5QBJWxn/87Q1sPK4+sQa8fLU5gXo4paaq4cOcQ4wR0VBHPGjKh+UlPCbA1nLXyEUX45qZ8J7/Ln4FPJE2TdzD0Z8MLSNQiykMMmSyOCiFfy84Rq60emYB2vD09KjYwsoIpeDcBDTElBbXxND72yhd9pC/1CMid/5HUMvAL27OtcIJDzNKpRPNqPOpyt2aPGz9QWIs9hQ9LiX5s8m9hjTUu/f7MyIatjjd+tSfQ3ufZxPpmJhTaBtZtKLUcfOCUqADuO+QoH8B9v6U+P0HV1GLQmtoNFTb3s74ivZgjES0qfK+8RdGgBbcCMSy8eBvh98+et1KIFqSe1KQPyXULBMTsIYnysIwiZBJYdI20vseV+wuJkcqGemehKjaAb9L57xZm3g2zX0bZ2xk/fU+bCo7TlnbW7JuF1YdURo/2Gw7VclDG1W7LOtas2LX4upifZ/23rzpsnY/ALfRgrcWP5hYmV9VxVOQA1fZvp9F2UNU+7d7xRyVm5wiLp3/0dlV7vdw1PMiZrbDAYzIVqEjRY2YU03sJhPnlwIPcZUG5ltL6S8XCxU1eYS5cjr34veBmXAvy7yN4ZjArIG0dfD/5UpBNlX1ZPoxJOwyqRi3wQWtOzd4oNKh0LkoTm8cwqgIfKhqqGOhwo71I+zXnMemTv2B2AUzABWyFztGgGULjDDzWYwJUVBTjKCn5K2QGMK1CQT7SzziOjo+BhAmqBjzuc3xYym2eedGeOIRJVyTwDw37iCMe4g5Vbnsb5ZBdxOAnMT7HU4DHpxWGuQ7GeiY30Cpbvzss55+5Km1YsbD5ea3NI9QNYIXol5apgSu9dZ8f8xS5dtHpido5BclDuLWY4lhik0tbJa07yJhH0BOyEut/GRbYTS6RfiTYWGMCkNpfSHi7HvdiTglEVHKZXaVhezH4kkXiIvKopYAlPusftpE4a5IZwvw1x/eLvoDIh/zpo9FiQInsTb2SAkKHV42XYBjpJDg4374XiVb3ws4qM0s9eSQ5HzsMU4OZJKuopFjBM+dAZEl8RUMx5uU2N486Kr141tVsGQfGjORYMCJAMsxELeNT4RmWjRcpdTGBwcx6XN9drWqPmJzcrGrH4+DRc7+n1w3kPZwu0BkNr6hQrqgo7JTB9A5kdJ/H7P4cWBMwsmuixAzJB3yrQpnGIq90lxAXLzDCdn1LPibsRt7rHNjgQBklRgPZ8vTbjXdgXrTWQsK5MdrXXQVPp0Rinq3frzZKJ0qD6Qhc40VzAraUXlob1gvkhK3vpmHgI6FRlQZNx6eRqkp0zy4AQlX813fAPtL3jMRaitGFFjo0zmErloC+h+YYdVQ6k4F/epxAoF0BmqEoKNTt6j4vQZNQ2BoqF9Vj53TOIoNmDiu9Xp15RkIgQIGcoLpfoIbenzpGUAtqFJp5W+LLnx38jHeECTJ/navKY1NWfN0sY1T8/pB8kIH3DU3DX+u6W3YwpypBMYOhbSxGjq84RZ84fWJow8pyHqn4S/9J15EcCMsXqrfwyd9mhiu3+rEo9pPpoJkdZqHjra4NvzFwuThNKy6hao/SlLw3ZADUcUp3w3SRVfW2rhl80zOgTYnKE0Hs2qp1J6H3xqPqIkvUDRMFDYyRbsFI3M9MEyovPk8rlw7/0a81cDVLmBsR2ze2pBuKb23fbeZC0uXoIvDppfTwIDxk1Oq2dGesGc+oJXWJLGkOha3CX+DUnzgAp9HGH9RsPZN63Hn4RMA5eSVhPHO+9RcRb/IOgtW31V1Q5IPGtoxPjC+MEJbVlIMYADd9aHYWUIQKopuPOHmoqSkubnAKnzgKHqgIOfW5RdAgotN6BN+O2ZYHkuemLnvQ8U9THVrS1RtLmKbcC7PeeDsYznvqzeg6VCNwmr0Yyx1wnLjyT84BZz3EJyCptD3yeueAyDWIs0L2qs/VQ3HUyqfrja0V1LdDzqAikeWuV4sc7RLIB69jEIBjCkyZedoUHqCrOvShVzyd73OdrJW0hPOuQv2qOoHDc9xVb6Yu6uq3Xqp2ZaH46A7lzevbxQEmfrzvAYSJuZ4WDk1Hz3QX1LVdiUK0EvlAGAYlG3Md30r7dcPN63yqBCIj25prpvZP0nI4+EgWoFG95V596CurXpKRBGRjQlHCvy5Ib/iW8nZJWwrET3mgd6mEhfP4KCuaLjopWs7h+MdXFdIv8dHQJgg1xi1eYqB0uDYjxwVmri0Sv5XKut/onqapC+FQiC2C1lvYJ9MVco6yDYsS3AANUfMtvtbYI2hfwZatiSsnoUeMZd34GVjkMMKA+XnjJpXgRW2SHTZplVowPmJsvXy6w3cfO1AK2dvtZEKTkC/TY9LFiKHCG0DnrMQdGm2lzlBHM9iEYynH2UcVMhUEjsc0oDBTgo2ZSQ1gzkAHeWeBXYFjYLuuf8yzTCy7/RFR81WDjXMbq2BOH5dURnxo6oivmxL3cKzKInlZkD31nvpHB9Kk7GfcfE1t+1V64b9LtgeJGlpRFxQCAqWJ5DoY77ski8gsOEOr2uywZaoO/NGa0X0y1pNQHBi3b2SUGNpcZxDT7rLbBf1FSnQ8guxGW3W+36BW0gBje4DOz6Ba6SVk0xiKgt+q2JOFyr4SYfnu+Ic1QZYIuwHBrgzr6UvOcSCzPTOo7D6IC4ISeS7zkl4h+2VoeHpnG/uWR3+ysNgPcOIXQbv0n4mr3BwQcdKJxgPSeyuP/z1Jjg4e9nUvoXegqQVIE30EHx5GHv+FAVUNTowYDJgyFhf5IvlYmEqRif6+WN1MkEJmDcQITx9FX23a4mxy1AQRsOHO/+eImX9l8EMJI3oPWzVXxSOeHU1dUWYr2uAA7AMb+vAEZSbU3qob9ibCyXeypEMpZ6863o6QPqlqGHZkuWABSTVNd4cOh9hv3qEpSx2Zy/DJMP6cItEmiBJ5PFqQnDEIt3NrA3COlOSgz43D7gpNFNJ5MBh4oFzhDPiglC2ypsNU4ISywY2erkyb1NC3Qh/IfWj0eDgZI4/ln8WPfBsT3meTjq1Uqt1E7Zl/qftqkx6aM9KueMCekSnMrcHj1CqTWWzEzPsZGcDe3Ue4Ws+XFYVxNbOFF8ezkvQGR6ZOtOLU2lQEnMBStx47vE6Pb7AYMBRj2OOfZXfisjJnpTfSNjo6sZ6qSvNxZNmDeS7Gk3yYyCk1HtKN2UnhMIjOXUzAqDv90lx9O/q/AT1ZMnit5XQe9wmQxnE/WSH0CqZ9/2Hy+Sfmpeg8RwsHI5Z8kC8H293m/LHVVM/BA7HaTJYg5Enk7M/xWpq0192ACfBai2LA/qrCjCr6Dh1BIMzMXINBmX96MJ5Hn2nxln/RXPFhwHxUmSV0EV2V0jm86/dxxuYSU1W7sVkEbN9EzkG0QFwPhyHKyb3t+Fj5WoUUTErcazE/N6EW6Lvp0d//SDPj7EV9UdJN+Amnf3Wwk3A0SlJ9Z00yvXZ7n3z70G47Hfsow8Wq1JXcfwnA+Yxa5mFsgV464KKP4T31wqIgzFPd3eCe3j5ory5fBF2hgCFyVFrLzI9eetNXvM7oQqyFgDo4CTp/hDV9NMX9JDHQ/nyHTLvZLNLF6ftn2OxjGm8+PqOwhxnPHWipkE/8wbtyri80Sr7pMNkQGMfo4ZYK9OcCC4ESVFFbLMIvlxSoRqWie0wxqnLfcLSXMSpMMQEJYDVObYsXIQNv4TGNwjq1kvT1UOkicTrG3IaBZ3XdScS3u8sgeZPVpOLkbiF940FjbCeNRINNvDbd01EPBrTCPpm12m43ze1bBB59Ia6Ovhnur/Nvx3IxwSWol+3H2qfCJR8df6aQf4v6WiONxkK+IqT4pKQrZK/LplgDI/PJZbOep8dtbV7oCr6CgfpWa8NczOkPx81iSHbsNhVSJBOtrLIMrL31LK9TqHqAbAHe0RLmmV806kRLDLNEhUEJfm9u0sxpkL93Zgd6rw+tqBfTMi59xqXHLXSHwSbSBl0EK0+loECOPtrl+/nsaFe197di4yUgoe4jKoAJDXc6DGDjrQOoFDWZJ9HXwt8xDrQP+7aRwWKWI1GF8s8O4KzxWBBcwnl3vnl1Oez3oh6Ea1vjR7/z7DDTrFtqU2W/KAEzAuXDNZ7MY73MF216dzdSbWmUp4lcm7keJfWaMHgut9x5C9mj66Z0lJ+yhsjVvyiWrfk1lzPOTdhG15Y7gQlXtacvI7qv/XNSscDwqkgwHT/gUsD5yB7LdRRvJxQGYINn9hTpodKFVSTPrtGvyQw+HlRFXIkodErAGu9Iy1YpfSPc3jkFh5CX3lPxv7aqjE/JAfTIpEjGb/H7MO0e2vsViSW1qa/Lmi4/n4DEI3g7lYrcanspDfEpKkdV1OjSLOy0BCUqVoECaB55vs06rXl4jqmLsPsFM/7vYJ0vrBhDCm/00A/H81l1uekJ/6Lml3Hb9+NKiLqATJmDpyzfYZFHumEjC662L0Bwkxi7E9U4cQA0XMVDuMYAIeLMPgQaMVOd8fmt5SflFIfuBoszeAw7ow5gXPE2Y/yBc/7jExARUf/BxIHQBF5Sn3i61w4z5xJdCyO1F1X3+3ax+JSvMeZ7S6QSKp1Fp/sjYz6Z+VgCZzibGeEoujryfMulH7Rai5kAft9ebcW50DyJr2uo2z97mTWIu45YsSnNSMrrNUuG1XsYBtD9TDYzQffKB87vWbkM4EbPAFgoBV4GQS+vtFDUqOFAoi1nTtmIOvg38N4hT2Sn8r8clmBCXspBlMBYTnrqFJGBT3wZOzAyJDre9dHH7+x7qaaKDOB4UQALD5ecS0DE4obubQEiuJZ0EpBVpLuYcce8Aa4PYd/V4DLDAJBYKQPCWTcrEaZ5HYbJi11Gd6hjGom1ii18VHYnG28NKpkz2UKVPxlhYSp8uZr367iOmoy7zsxehW9wzcy2zG0a80PBMCRQMb32hnaHeOR8fnNDzZhaNYhkOdDsBUZ3loDMa1YP0uS0cjUP3b/6DBlqmZOeNABDsLl5BI5QJups8uxAuWJdkUB/pO6Zax6tsg7fN5mjjDgMGngO+DPcKqiHIDbFIGudxtPTIyDi9SFMKBDcfdGQRv41q1AqmxgkVfJMnP8w/Bc7N9/TR6C7mGObFqFkIEom8sKi2xYqJLTCHK7cxzaZvqODo22c3wisBCP4HeAgcRbNPAsBkNRhSmD48dHupdBRw4mIvtS5oeF6zeT1KMCyhMnmhpkFAGWnGscoNkwvQ8ZM5lE/vgTHFYL99OuNxdFBxTEDd5v2qLR8y9WkXsWgG6kZNndFG+pO/UAkOCipqIhL3hq7cRSdrCq7YhUsTocEcnaFa6nVkhnSeRYUA1YO0z5itF9Sly3VlxYDw239TJJH6f3EUfYO5lb7bcFcz8Bp7Oo8QmnsUHOz/fagVUBtKEw1iT88j+aKkv8cscKNkMxjYr8344D1kFoZ7/td1W6LCNYN594301tUGRmFjAzeRg5vyoM1F6+bJZ/Q54jN/k8SFd3DxPTYaAUsivsBfgTn7Mx8H2SpPt4GOdYRnEJOH6jHM2p6SgB0gzIRq6fHxGMmSmqaPCmlfwxiuloaVIitLGN8wie2CDWhkzLoCJcODh7KIOAqbHEvXdUxaS4TTTs07Clzj/6GmVs9kiZDerMxEnhUB6QQPlcfqkG9882RqHoLiHGBoHfQuXIsAG8GTAtao2KVwRnvvam8jo1e312GQAKWEa4sUVEAMG4G6ckcONDwRcg1e2D3+ohXgY4UAWF8wHKQMrSnzCgfFpsxh+aHXMGtPQroQasRY4U6UdG0rz1Vjbka0MekOGRZQEvqQFlxseFor8zWFgHek3v29+WqN6gaK5gZOTOMZzpQIC1201LkMCXild3vWXSc5UX9xcFYfbRPzGFa1FDcPfPB/jUEq/FeGt419CI3YmBlVoHsa4KdcwQP5ZSwHHhFJ7/Ph/Rap/4vmG91eDwPP0lDfCDRCLszTqfzM71xpmiKi2HwS4WlqvGNwtvwF5Dqpn6KTq8ax00UMPkxDcZrEEEsIvHiUXXEphdb4GB4FymlPwBz4Gperqq5pW7TQ6/yNRhW8VT5NhuP0udlxo4gILq5ZxAZk8ZGh3g4CqxJlPKY7AQxupfUcVpWT5VItp1+30UqoyP4wWsRo3olRRgkWZZ2ZN6VC3OZFeXB8NbnUrSdikNptD1QiGuKkr8EmSR/AK9Rw+FF3s5uwuPbvHGiPeFOViltMK7AUaOsq9+x9cndk3iJEE5LKZRlWJbKOZweROzmPNVPkjE3K/TyA57Rs68TkZ3MR8akKpm7cFjnjPd/DdkWjgYoKHSr5Wu5ssoBYU4acRs5g2DHxUmdq8VXOXRbunD8QN0LhgkssgahcdoYsNvuXGUK/KXD/7oFb+VGdhqIn02veuM5bLudJOc2Ky0GMaG4W/xWBxIJcL7yliJOXOpx0AkBqUgzlDczmLT4iILXDxxtRR1oZa2JWFgiAb43obrJnG/TZC2KSK2wqOzRZTXavZZFMb1f3bXvVaNaK828w9TO610gk8JNf3gMfETzXXsbcvRGCG9JWQZ6+cDPqc4466Yo2RcKH+PILeKOqtnlbInR3MmBeGG3FH10yzkybuqEC2HSQwpA0An7d9+73BkDUTm30bZmoP/RGbgFN+GrCOfADgqr0WbI1a1okpFms8iHYw9hm0zUvlEMivBRxModrbJJ+9/p3jUdQQ9BCtQdxnOGrT5dzRUmw0593/mbRSdBg0nRvRZM5/E16m7ZHmDEtWhwvfdZCZ8J8M12W0yRMszXamWfQTwIZ4ayYktrnscQuWr8idp3PjT2eF/jmtdhIfcpMnb+IfZY2FebW6UY/AK3jP4u3Tu4zE4qlnQgLFbM19EBIsNf7KhjdbqQ/D6yiDb+NlEi2SKD+ivXVUK8ib0oBo366gXkR8ZxGjpJIDcEgZPa9TcYe0TIbiPl/rPUQDu3XBJ9X/GNq3FAUsKsll57DzaGMrjcT+gctp+9MLYXCq+sqP81eVQ0r9lt+gcQfZbACRbEjvlMskztZG8gbC8Qn9tt26Q7y7nDrbZq/LEz7kR6Jc6pg3N9rVX8Y5MJrGlML9p9lU4jbTkKqCveeZUJjHB03m2KRKR2TytoFkTXOLg7keU1s1lrPMQJpoOKLuAAC+y1HlJucU6ysB5hsXhvSPPLq5J7JtnqHKZ4vYjC4Vy8153QY+6780xDuGARsGbOs1WqzH0QS765rnSKEbbKlkO8oI/VDwUd0is13tKpqILu1mDJFNy/iJAWcvDgjxvusIT+PGz3ST/J9r9Mtfd0jpaGeiLYIqXc7DiHSS8TcjFVksi66PEkxW1z6ujbLLUGNNYnzOWpH8BZGK4bCK7iR+MbIv8ncDAz1u4StN3vTTzewr9IQjk9wxFxn+6N1ddKs0vffJiS08N3a4G1SVrlZ97Q/M+8G9fe5AP6d9/Qq4WRnORVhofPIKEdCr3llspUfE0oKIIYoByBRPh+bX1HLS3JWGJRhIvE1aW4NTd8ePi4Z+kXb+Z8snYfSNcqijhAgVsx4RCM54cXUiYkjeBmmC4ajOHrChoELscJJC7+9jjMjw5BagZKlgRMiSNYz7h7vvZIoQqbtQmspc0cUk1G/73iXtSpROl5wtLgQi0mW2Ex8i3WULhcggx6E1LMVHUsdc9GHI1PH3U2Ko0PyGdn9KdVOLm7FPBui0i9a0HpA60MsewVE4z8CAt5d401Gv6zXlIT5Ybit1VIA0FCs7wtvYreru1fUyW3oLAZ/+aTnZrOcYRNVA8spoRtlRoWflsRClFcgzkqiHOrf0/SVw+EpVaFlJ0g4Kxq1MMOmiQdpMNpte8lMMQqm6cIFXlnGbfJllysKDi+0JJMotkqgIxOSQgU9dn/lWkeVf8nUm3iwX2Nl3WDw9i6AUK3vBAbZZrcJpDQ/N64AVwjT07Jef30GSSmtNu2WlW7YoyW2FlWfZFQUwk867EdLYKk9VG6JgEnBiBxkY7LMo4YLQJJlAo9l/oTvJkSARDF/XtyAzM8O2t3eT/iXa6wDN3WewNmQHdPfsxChU/KtLG2Mn8i4ZqKdSlIaBZadxJmRzVS/o4yA65RTSViq60oa395Lqw0pzY4SipwE0SXXsKV+GZraGSkr/RW08wPRvqvSUkYBMA9lPx4m24az+IHmCbXA+0faxTRE9wuGeO06DIXa6QlKJ3puIyiuAVfPr736vzo2pBirS+Vxel3TMm3JKhz9o2ZoRvaFVpIkykb0Hcm4oHFBMcNSNj7/4GJt43ogonY2Vg4nsDQIWxAcorpXACzgBqQPjYsE/VUpXpwNManEru4NwMCFPkXvMoqvoeLN3qyu/N1eWEHttMD65v19l/0kH2mR35iv/FI+yjoHJ9gPMz67af3Mq/BoWXqu3rphiWMXVkmnPSEkpGpUI2h1MThideGFEOK6YZHPwYzMBvpNC7+ZHxPb7epfefGyIB4JzO9DTNEYnDLVVHdQyvOEVefrk6Uv5kTQYVYWWdqrdcIl7yljwwIWdfQ/y+2QB3eR/qxYObuYyB4gTbo2in4PzarU1sO9nETkmj9/AoxDA+JM3GMqQtJR4jtduHtnoCLxd1gQUscHRB/MoRYIEsP2pDZ9KvHgtlk1iTbWWbHhohwFEYX7y51fUV2nuUmnoUcqnWIQAAgl9LTVX+Bc0QGNEhChxHR4YjfE51PUdGfsSFE6ck7BL3/hTf9jLq4G1IafINxOLKeAtO7quulYvH5YOBc+zX7CrMgWnW47/jfRsWnJjYYoE7xMfWV2HN2iyIqLI");const t=()=>lR(e),n=()=>new Set(t()),r=(e,t)=>t.forEach(t=>e.add(t));FR=new Map(uR(e)),GR=n(),UR=t(),LR=new Set(t().map(e=>UR[e])),UR=new Set(UR),jR=n(),n();let i=fR(e),s=e();const a=()=>{let e=new Set;return t().forEach(t=>r(e,i[t])),r(e,t()),e};HR=dR(t=>{let n=dR(e).map(e=>e+96);if(n.length){let r=t>=s;return n[0]-=32,n=gR(n),r&&(n=`Restricted[${n}]`),{N:n,P:a(),Q:a(),M:!e(),R:r}}}),zR=n(),qR=new Map;let o=t().concat(MR(zR)).sort((e,t)=>e-t);o.forEach((t,n)=>{let r=e(),i=o[n]=r?o[n-r]:{V:[],M:new Map};i.V.push(t),zR.has(t)||qR.set(t,i)});for(let{V:l,M:f}of new Set(qR.values())){let e=[];for(let n of l){let t=HR.filter(e=>$R(e,n)),i=e.find(({G:e})=>t.some(t=>e.has(t)));i||(i={G:new Set,V:[]},e.push(i)),i.V.push(n),r(i.G,t)}let t=e.flatMap(e=>MR(e.G));for(let{G:n,V:r}of e){let e=new Set(t.filter(e=>!n.has(e)));for(let t of r)f.set(t,e)}}QR=new Set;let c=new Set;const A=e=>QR.has(e)?c.add(e):QR.add(e);for(let l of HR){for(let e of l.P)A(e);for(let e of l.Q)A(e)}for(let l of QR)qR.has(l)||c.has(l)||qR.set(l,1);r(QR,RR(QR)),VR=function(e){let t=[],n=lR(e);return function e({S:n,B:r},i,s){if(!(4&n&&s===i[i.length-1])){2&n&&(s=i[i.length-1]),1&n&&t.push(i);for(let t of r)for(let n of t.Q)e(t,[...i,n],s)}}(function t(r){return{S:e(),B:dR(()=>{let r=lR(e).map(e=>n[e]);if(r.length)return t(r)}),Q:r}}([]),[]),t}(e).map(e=>DR.from(e)).sort(bR),JR=new Map;for(let l of VR){let e=[JR];for(let t of l){let n=e.map(e=>{let n=e.get(t);return n||(n=new Map,e.set(t,n)),n});65039===t?e.push(...n):e=n}for(let t of e)t.V=l}}function WR(e){return(XR(e)?"":`${YR(ZR([e]))} `)+yR(e)}function YR(e){return`"${e}"‎`}function ZR(e,t=1/0,n=yR){let r=[];var i;i=e[0],KR(),UR.has(i)&&r.push("◌"),e.length>t&&(t>>=1,e=[...e.slice(0,t),8230,...e.slice(-t)]);let s=0,a=e.length;for(let o=0;o<a;o++){let t=e[o];XR(t)&&(r.push(gR(e.slice(s,o))),r.push(n(t)),s=o+1)}return r.push(gR(e.slice(s,a))),r.join("")}function XR(e){return KR(),jR.has(e)}function eB(e){return new Error(`disallowed character: ${WR(e)}`)}function tB(e,t){let n=WR(t),r=HR.find(e=>e.P.has(t));return r&&(n=`${r.N} ${n}`),new Error(`illegal mixture: ${e.N} + ${n}`)}function nB(e){return new Error(`illegal placement: ${e}`)}function rB(e){return e.filter(e=>65039!=e)}function iB(e,t){let n,r=JR,i=e.length;for(;i&&(r=r.get(e[--i]),r);){let{V:t}=r;t&&(n=t,e.length=i)}return n}const sB=new Uint8Array(32);function aB(e){return bS(0!==e.length,"invalid ENS name; empty component","comp",e),e}function oB(e){const t=ux(cB(e)),n=[];if(0===e.length)return n;let r=0;for(let i=0;i<t.length;i++)46===t[i]&&(n.push(aB(t.slice(r,i))),r=i+1);return bS(r<t.length,"invalid ENS name; empty component","name",e),n.push(aB(t.slice(r))),n}function cB(e){try{if(0===e.length)throw new Error("empty label");return function(e){return t=function(e,t,n){if(!e)return[];KR();let r=0;return e.split(".").map(e=>{let i=function(e){let t=[];for(let n=0,r=e.length;n<r;){let r=e.codePointAt(n);n+=r<65536?1:2,t.push(r)}return t}(e),s={input:i,offset:r};r+=i.length+1;try{let e,r=s.tokens=function(e,t,n){let r=[],i=[];for(e=e.slice().reverse();e.length;){let s=iB(e);if(s)i.length&&(r.push(t(i)),i=[]),r.push(n(s));else{let t=e.pop();if(QR.has(t))i.push(t);else{let e=FR.get(t);if(e)i.push(...e);else if(!GR.has(t))throw eB(t)}}}return i.length&&r.push(t(i)),r}(i,t,n),a=r.length;if(!a)throw new Error("empty label");let o=s.output=r.flat();if(function(e){for(let t=e.lastIndexOf(95);t>0;)if(95!==e[--t])throw new Error("underscore allowed only at start")}(o),!(s.emoji=a>1||r[0].is_emoji)&&o.every(e=>e<128))!function(e){if(e.length>=4&&45==e[2]&&45==e[3])throw new Error(`invalid label extension: "${gR(e.slice(0,4))}"`)}(o),e="ASCII";else{let t=r.flatMap(e=>e.is_emoji?[]:e);if(t.length){if(UR.has(o[0]))throw nB("leading combining mark");for(let e=1;e<a;e++){let t=r[e];if(!t.is_emoji&&UR.has(t[0]))throw nB(`emoji + combining mark: "${gR(r[e-1])} + ${ZR([t[0]])}"`)}!function(e){let t=e[0],n=aR.get(t);if(n)throw nB(`leading ${n}`);let r=e.length,i=-1;for(let s=1;s<r;s++){t=e[s];let r=aR.get(t);if(r){if(i==s)throw nB(`${n} + ${r}`);i=s+1,n=r}}if(i==r)throw nB(`trailing ${n}`)}(o);let n=MR(new Set(t)),[i]=function(e){let t=HR;for(let n of e){let e=t.filter(e=>$R(e,n));if(!e.length)throw HR.some(e=>$R(e,n))?tB(t[0],n):eB(n);if(t=e,1==e.length)break}return t}(n);!function(e,t){for(let n of t)if(!$R(e,n))throw tB(e,n);if(e.M){let e=RR(t);for(let t=1,n=e.length;t<n;t++)if(LR.has(e[t])){let r=t+1;for(let i;r<n&&LR.has(i=e[r]);r++)for(let n=t;n<r;n++)if(e[n]==i)throw new Error(`duplicate non-spacing marks: ${WR(i)}`);if(r-t>4)throw new Error(`excessive non-spacing marks: ${YR(ZR(e.slice(t-1,r)))} (${r-t}/4)`);t=r}}}(i,t),function(e,t){let n,r=[];for(let i of t){let e=qR.get(i);if(1===e)return;if(e){let t=e.M.get(i);if(n=n?n.filter(e=>t.has(e)):MR(t),!n.length)return}else r.push(i)}if(n)for(let i of n)if(r.every(e=>$R(i,e)))throw new Error(`whole-script confusable: ${e.N}/${i.N}`)}(i,n),e=i.N}else e="Emoji"}s.type=e}catch(a){s.error=a}return s})}(e,BR,rB),t.map(({input:e,error:n,output:r})=>{if(n){let r=n.message;throw new Error(1==t.length?r:`Invalid label ${YR(ZR(e,63))}: ${r}`)}return gR(r)}).join(".");var t}(e)}catch(t){bS(!1,`invalid ENS name (${t.message})`,"name",e)}}function AB(e){try{return 0!==oB(e).length}catch(t){}return!1}function lB(e){bS("string"==typeof e,"invalid ENS name; not a string","name",e),bS(e.length,"invalid ENS name (empty label)","name",e);let t=sB;const n=oB(e);for(;n.length;)t=RP(NS([t,RP(n.pop())]));return CS(t)}function fB(e,t){const n=null!=t?t:63;return bS(n<=255,"DNS encoded label cannot exceed 255","length",n),CS(NS(oB(e).map(t=>{bS(t.length<=n,`label ${JSON.stringify(e)} exceeds ${n} bytes`,"name",e);const r=new Uint8Array(t.length+1);return r.set(t,1),r[0]=r.length-1,r})))+"00"}function uB(e){return"string"==typeof e&&(e=ux(e)),RP(NS([ux(MN),ux(String(e.length)),e]))}function dB(e,t){return $O(uB(e),t)}sB.fill(0);const hB=new RegExp("^bytes([0-9]+)$"),pB=new RegExp("^(u?int)([0-9]*)$"),mB=new RegExp("^(.*)\\[([0-9]*)\\]$");function yB(e,t,n){switch(e){case"address":return TS(n?$S(t,32):nO(t));case"string":return ux(t);case"bytes":return TS(t);case"bool":return t=t?"0x01":"0x00",TS(n?$S(t,32):t)}let r=e.match(pB);if(r){let i="int"===r[1],s=parseInt(r[2]||"256");return bS((!r[2]||r[2]===String(s))&&s%8==0&&0!==s&&s<=256,"invalid number type","type",e),n&&(s=256),i&&(t=jS(t,s)),TS($S(YS(t),s/8))}if(r=e.match(hB),r){const i=parseInt(r[1]);return bS(String(i)===r[1]&&0!==i&&i<=32,"invalid bytes type","type",e),bS(OS(t)===i,`invalid value for ${e}`,"value",t),n?TS(DS(t,32)):t}if(r=e.match(mB),r&&Array.isArray(t)){const n=r[1];bS(parseInt(r[2]||String(t.length))===t.length,`invalid array length for ${e}`,"value",t);const i=[];return t.forEach(function(e){i.push(yB(n,e,!0))}),TS(NS(i))}bS(!1,"invalid type","type",e)}function gB(e,t){bS(e.length===t.length,"wrong number of values; expected ${ types.length }","values",t);const n=[];return e.forEach(function(e,r){n.push(yB(e,t[r]))}),CS(NS(n))}function bB(e,t){return RP(gB(e,t))}function wB(e,t){return TC(gB(e,t))}const vB=new Uint8Array(32);vB.fill(0);const _B=BigInt(-1),EB=BigInt(0),kB=BigInt(1),TB=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),SB=WS(kB,32),xB=WS(EB,32),IB={name:"string",version:"string",chainId:"uint256",verifyingContract:"address",salt:"bytes32"},PB=["name","version","chainId","verifyingContract","salt"];function CB(e){return function(t){return bS("string"==typeof t,`invalid domain value for ${JSON.stringify(e)}`,`domain.${e}`,t),t}}const NB={name:CB("name"),version:CB("version"),chainId:function(e){const t=zS(e,"domain.chainId");return bS(t>=0,"invalid chain ID","domain.chainId",e),Number.isSafeInteger(t)?Number(t):ZS(t)},verifyingContract:function(e){try{return nO(e).toLowerCase()}catch(t){}bS(!1,'invalid domain value "verifyingContract"',"domain.verifyingContract",e)},salt:function(e){const t=TS(e,"domain.salt");return bS(32===t.length,'invalid domain value "salt"',"domain.salt",e),CS(t)}};function OB(e){{const t=e.match(/^(u?)int(\d+)$/);if(t){const n=""===t[1],r=parseInt(t[2]);bS(r%8==0&&0!==r&&r<=256&&t[2]===String(r),"invalid numeric width","type",e);const i=HS(TB,n?r-1:r),s=n?(i+kB)*_B:EB;return function(t){const r=zS(t,"value");return bS(r>=s&&r<=i,`value out-of-bounds for ${e}`,"value",r),WS(n?jS(r,256):r,32)}}}{const t=e.match(/^bytes(\d+)$/);if(t){const n=parseInt(t[1]);return bS(0!==n&&n<=32&&t[1]===String(n),"invalid bytes width","type",e),function(t){return bS(TS(t).length===n,`invalid length for ${e}`,"value",t),function(e){const t=TS(e),n=t.length%32;return n?NS([t,vB.slice(n)]):CS(t)}(t)}}}switch(e){case"address":return function(e){return $S(nO(e),32)};case"bool":return function(e){return e?SB:xB};case"bytes":return function(e){return RP(e)};case"string":return function(e){return sR(e)}}return null}function RB(e,t){return`${e}(${t.map(({name:e,type:t})=>t+" "+e).join(",")})`}function BB(e){const t=e.match(/^([^\x5b]*)((\x5b\d*\x5d)*)(\x5b(\d*)\x5d)$/);return t?{base:t[1],index:t[2]+t[4],array:{base:t[1],prefix:t[1]+t[2],count:t[5]?parseInt(t[5]):-1}}:{base:e}}ve=new WeakMap,_e=new WeakMap,Ee=new WeakMap,ke=new WeakSet,Te=function(e){{const t=OB(e);if(t)return t}const t=BB(e).array;if(t){const e=t.prefix,n=this.getEncoder(e);return r=>{bS(-1===t.count||t.count===r.length,`array length mismatch; expected length ${t.count}`,"value",r);let i=r.map(n);return __privateGet(this,_e).has(e)&&(i=i.map(RP)),RP(NS(i))}}const n=this.types[e];if(n){const t=sR(__privateGet(this,_e).get(e));return e=>{const r=n.map(({name:t,type:n})=>{const r=this.getEncoder(n)(e[t]);return __privateGet(this,_e).has(n)?RP(r):r});return r.unshift(t),NS(r)}}bS(!1,`unknown type: ${e}`,"type",e)};let MB=class e{constructor(e){__privateAdd(this,ke),__publicField(this,"primaryType"),__privateAdd(this,ve),__privateAdd(this,_e),__privateAdd(this,Ee),__privateSet(this,_e,new Map),__privateSet(this,Ee,new Map);const t=new Map,n=new Map,r=new Map,i={};Object.keys(e).forEach(s=>{i[s]=e[s].map(({name:t,type:n})=>{let{base:r,index:i}=BB(n);return"int"!==r||e.int||(r="int256"),"uint"!==r||e.uint||(r="uint256"),{name:t,type:r+(i||"")}}),t.set(s,new Set),n.set(s,[]),r.set(s,new Set)}),__privateSet(this,ve,JSON.stringify(i));for(const a in i){const r=new Set;for(const s of i[a]){bS(!r.has(s.name),`duplicate variable name ${JSON.stringify(s.name)} in ${JSON.stringify(a)}`,"types",e),r.add(s.name);const i=BB(s.type).base;bS(i!==a,`circular type reference to ${JSON.stringify(i)}`,"types",e),OB(i)||(bS(n.has(i),`unknown type ${JSON.stringify(i)}`,"types",e),n.get(i).push(a),t.get(a).add(i))}}const s=Array.from(n.keys()).filter(e=>0===n.get(e).length);bS(0!==s.length,"missing primary type","types",e),bS(1===s.length,`ambiguous primary types or unused types: ${s.map(e=>JSON.stringify(e)).join(", ")}`,"types",e),dS(this,{primaryType:s[0]}),function i(s,a){bS(!a.has(s),`circular type reference to ${JSON.stringify(s)}`,"types",e),a.add(s);for(const e of t.get(s))if(n.has(e)){i(e,a);for(const t of a)r.get(t).add(e)}a.delete(s)}(this.primaryType,new Set);for(const[a,o]of r){const e=Array.from(o);e.sort(),__privateGet(this,_e).set(a,RB(a,i[a])+e.map(e=>RB(e,i[e])).join(""))}}get types(){return JSON.parse(__privateGet(this,ve))}getEncoder(e){let t=__privateGet(this,Ee).get(e);return t||(t=__privateMethod(this,ke,Te).call(this,e),__privateGet(this,Ee).set(e,t)),t}encodeType(e){const t=__privateGet(this,_e).get(e);return bS(t,`unknown type: ${JSON.stringify(e)}`,"name",e),t}encodeData(e,t){return this.getEncoder(e)(t)}hashStruct(e,t){return RP(this.encodeData(e,t))}encode(e){return this.encodeData(this.primaryType,e)}hash(e){return this.hashStruct(this.primaryType,e)}_visit(e,t,n){if(OB(e))return n(e,t);const r=BB(e).array;if(r)return bS(-1===r.count||r.count===t.length,`array length mismatch; expected length ${r.count}`,"value",t),t.map(e=>this._visit(r.prefix,e,n));const i=this.types[e];if(i)return i.reduce((e,{name:r,type:i})=>(e[r]=this._visit(i,t[r],n),e),{});bS(!1,`unknown type: ${e}`,"type",e)}visit(e,t){return this._visit(this.primaryType,e,t)}static from(t){return new e(t)}static getPrimaryType(t){return e.from(t).primaryType}static hashStruct(t,n,r){return e.from(n).hashStruct(t,r)}static hashDomain(t){const n=[];for(const e in t){if(null==t[e])continue;const r=IB[e];bS(r,`invalid typed-data domain key: ${JSON.stringify(e)}`,"domain",t),n.push({name:e,type:r})}return n.sort((e,t)=>PB.indexOf(e.name)-PB.indexOf(t.name)),e.hashStruct("EIP712Domain",{EIP712Domain:n},t)}static encode(t,n,r){return NS(["0x1901",e.hashDomain(t),e.from(n).hash(r)])}static hash(t,n,r){return RP(e.encode(t,n,r))}static async resolveNames(t,n,r,i){t=Object.assign({},t);for(const e in t)null==t[e]&&delete t[e];const s={};t.verifyingContract&&!xS(t.verifyingContract,20)&&(s[t.verifyingContract]="0x");const a=e.from(n);a.visit(r,(e,t)=>("address"!==e||xS(t,20)||(s[t]="0x"),t));for(const e in s)s[e]=await i(e);return t.verifyingContract&&s[t.verifyingContract]&&(t.verifyingContract=s[t.verifyingContract]),{domain:t,value:r=a.visit(r,(e,t)=>"address"===e&&s[t]?s[t]:t)}}static getPayload(t,n,r){e.hashDomain(t);const i={},s=[];PB.forEach(e=>{const n=t[e];null!=n&&(i[e]=NB[e](n),s.push({name:e,type:IB[e]}))});const a=e.from(n);n=a.types;const o=Object.assign({},n);return bS(null==o.EIP712Domain,"types must not contain EIP712Domain type","types.EIP712Domain",n),o.EIP712Domain=s,a.encode(r),{types:o,domain:i,primaryType:a.primaryType,message:a.visit(r,(e,t)=>{if(e.match(/^bytes(\d*)/))return CS(TS(t));if(e.match(/^u?int/))return zS(t).toString();switch(e){case"address":return t.toLowerCase();case"bool":return!!t;case"string":return bS("string"==typeof t,"invalid string","value",t),t}bS(!1,"unsupported type","type",e)})}}};function $B(e,t,n,r){return $O(MB.hash(e,t,n),r)}function DB(e){const t=new Set;return e.forEach(e=>t.add(e)),Object.freeze(t)}const FB=DB("external public payable override".split(" ")),GB="constant external internal payable private public pure view override",UB=DB(GB.split(" ")),LB="constructor error event fallback function receive struct",jB=DB(LB.split(" ")),HB="calldata memory storage payable indexed",zB=DB(HB.split(" ")),qB=DB([LB,HB,"tuple returns",GB].join(" ").split(" ")),QB={"(":"OPEN_PAREN",")":"CLOSE_PAREN","[":"OPEN_BRACKET","]":"CLOSE_BRACKET",",":"COMMA","@":"AT"},VB=new RegExp("^(\\s*)"),JB=new RegExp("^([0-9]+)"),KB=new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)"),WB=new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)$"),YB=new RegExp("^(address|bool|bytes([0-9]*)|string|u?int([0-9]*))$"),ZB=class e{constructor(e){__privateAdd(this,Ie),__privateAdd(this,Se),__privateAdd(this,xe),__privateSet(this,Se,0),__privateSet(this,xe,e.slice())}get offset(){return __privateGet(this,Se)}get length(){return __privateGet(this,xe).length-__privateGet(this,Se)}clone(){return new e(__privateGet(this,xe))}reset(){__privateSet(this,Se,0)}popKeyword(e){const t=this.peek();if("KEYWORD"!==t.type||!e.has(t.text))throw new Error(`expected keyword ${t.text}`);return this.pop().text}popType(e){if(this.peek().type!==e){const t=this.peek();throw new Error(`expected ${e}; got ${t.type} ${JSON.stringify(t.text)}`)}return this.pop().text}popParen(){const e=this.peek();if("OPEN_PAREN"!==e.type)throw new Error("bad start");const t=__privateMethod(this,Ie,Pe).call(this,__privateGet(this,Se)+1,e.match+1);return __privateSet(this,Se,e.match+1),t}popParams(){const e=this.peek();if("OPEN_PAREN"!==e.type)throw new Error("bad start");const t=[];for(;__privateGet(this,Se)<e.match-1;){const e=this.peek().linkNext;t.push(__privateMethod(this,Ie,Pe).call(this,__privateGet(this,Se)+1,e)),__privateSet(this,Se,e)}return __privateSet(this,Se,e.match+1),t}peek(){if(__privateGet(this,Se)>=__privateGet(this,xe).length)throw new Error("out-of-bounds");return __privateGet(this,xe)[__privateGet(this,Se)]}peekKeyword(e){const t=this.peekType("KEYWORD");return null!=t&&e.has(t)?t:null}peekType(e){if(0===this.length)return null;const t=this.peek();return t.type===e?t.text:null}pop(){const e=this.peek();return __privateWrapper(this,Se)._++,e}toString(){const e=[];for(let t=__privateGet(this,Se);t<__privateGet(this,xe).length;t++){const n=__privateGet(this,xe)[t];e.push(`${n.type}:${n.text}`)}return`<TokenString ${e.join(" ")}>`}};Se=new WeakMap,xe=new WeakMap,Ie=new WeakSet,Pe=function(e=0,t=0){return new ZB(__privateGet(this,xe).slice(e,t).map(t=>Object.freeze(Object.assign({},t,{match:t.match-e,linkBack:t.linkBack-e,linkNext:t.linkNext-e}))))};let XB=ZB;function eM(e){const t=[],n=t=>{const n=s<e.length?JSON.stringify(e[s]):"$EOI";throw new Error(`invalid token ${n} at ${s}: ${t}`)};let r=[],i=[],s=0;for(;s<e.length;){let a=e.substring(s),o=a.match(VB);o&&(s+=o[1].length,a=e.substring(s));const c={depth:r.length,linkBack:-1,linkNext:-1,match:-1,type:"",text:"",offset:s,value:-1};t.push(c);let A=QB[a[0]]||"";if(A){if(c.type=A,c.text=a[0],s++,"OPEN_PAREN"===A)r.push(t.length-1),i.push(t.length-1);else if("CLOSE_PAREN"==A)0===r.length&&n("no matching open bracket"),c.match=r.pop(),t[c.match].match=t.length-1,c.depth--,c.linkBack=i.pop(),t[c.linkBack].linkNext=t.length-1;else if("COMMA"===A)c.linkBack=i.pop(),t[c.linkBack].linkNext=t.length-1,i.push(t.length-1);else if("OPEN_BRACKET"===A)c.type="BRACKET";else if("CLOSE_BRACKET"===A){let e=t.pop().text;if(t.length>0&&"NUMBER"===t[t.length-1].type){const n=t.pop().text;e=n+e,t[t.length-1].value=JS(n)}if(0===t.length||"BRACKET"!==t[t.length-1].type)throw new Error("missing opening bracket");t[t.length-1].text+=e}}else if(o=a.match(KB),o){if(c.text=o[1],s+=c.text.length,qB.has(c.text)){c.type="KEYWORD";continue}if(c.text.match(YB)){c.type="TYPE";continue}c.type="ID"}else{if(o=a.match(JB),!o)throw new Error(`unexpected token ${JSON.stringify(a[0])} at position ${s}`);c.text=o[1],c.type="NUMBER",s+=c.text.length}}return new XB(t.map(e=>Object.freeze(e)))}function tM(e,t){let n=[];for(const r in t.keys())e.has(r)&&n.push(r);if(n.length>1)throw new Error(`conflicting types: ${n.join(", ")}`)}function nM(e,t){if(t.peekKeyword(jB)){const n=t.pop().text;if(n!==e)throw new Error(`expected ${e}, got ${n}`)}return t.popType("ID")}function rM(e,t){const n=new Set;for(;;){const r=e.peekType("KEYWORD");if(null==r||t&&!t.has(r))break;if(e.pop(),n.has(r))throw new Error(`duplicate keywords: ${JSON.stringify(r)}`);n.add(r)}return Object.freeze(n)}function iM(e){let t=rM(e,UB);return tM(t,DB("constant payable nonpayable".split(" "))),tM(t,DB("pure view payable nonpayable".split(" "))),t.has("view")?"view":t.has("pure")?"pure":t.has("payable")?"payable":t.has("nonpayable")?"nonpayable":t.has("constant")?"view":"nonpayable"}function sM(e,t){return e.popParams().map(e=>bM.from(e,t))}function aM(e){if(e.peekType("AT")){if(e.pop(),e.peekType("NUMBER"))return zS(e.pop().text);throw new Error("invalid gas")}return null}function oM(e){if(e.length)throw new Error(`unexpected tokens at offset ${e.offset}: ${e.toString()}`)}const cM=new RegExp(/^(.*)\[([0-9]*)\]$/);function AM(e){const t=e.match(YB);if(bS(t,"invalid type","type",e),"uint"===e)return"uint256";if("int"===e)return"int256";if(t[2]){const n=parseInt(t[2]);bS(0!==n&&n<=32,"invalid bytes length","type",e)}else if(t[3]){const n=parseInt(t[3]);bS(0!==n&&n<=256&&n%8==0,"invalid numeric width","type",e)}return e}const lM={},fM=Symbol.for("_ethers_internal"),uM="_ParamTypeInternal",dM="_ErrorInternal",hM="_EventInternal",pM="_ConstructorInternal",mM="_FallbackInternal",yM="_FunctionInternal",gM="_StructInternal";Ce=new WeakSet,Ne=function(e,t,n,r){if(this.isArray()){if(!Array.isArray(t))throw new Error("invalid array value");if(-1!==this.arrayLength&&t.length!==this.arrayLength)throw new Error("array is wrong length");const i=this.arrayChildren,s=t.slice();return s.forEach((t,r)=>{var a;__privateMethod(a=i,Ce,Ne).call(a,e,t,n,e=>{s[r]=e})}),void r(s)}if(this.isTuple()){const i=this.components;let s;if(Array.isArray(t))s=t.slice();else{if(null==t||"object"!=typeof t)throw new Error("invalid tuple value");s=i.map(e=>{if(!e.name)throw new Error("cannot use object value with unnamed components");if(!(e.name in t))throw new Error(`missing value for component ${e.name}`);return t[e.name]})}if(s.length!==this.components.length)throw new Error("array is wrong length");return s.forEach((t,r)=>{var a;__privateMethod(a=i[r],Ce,Ne).call(a,e,t,n,e=>{s[r]=e})}),void r(s)}const i=n(this.type,t);i.then?e.push(async function(){r(await i)}()):r(i)};let bM=class e{constructor(e,t,n,r,i,s,a,o){if(__privateAdd(this,Ce),__publicField(this,"name"),__publicField(this,"type"),__publicField(this,"baseType"),__publicField(this,"indexed"),__publicField(this,"components"),__publicField(this,"arrayLength"),__publicField(this,"arrayChildren"),ES(e,lM,"ParamType"),Object.defineProperty(this,fM,{value:uM}),s&&(s=Object.freeze(s.slice())),"array"===r){if(null==a||null==o)throw new Error("")}else if(null!=a||null!=o)throw new Error("");if("tuple"===r){if(null==s)throw new Error("")}else if(null!=s)throw new Error("");dS(this,{name:t,type:n,baseType:r,indexed:i,components:s,arrayLength:a,arrayChildren:o})}format(e){if(null==e&&(e="sighash"),"json"===e){const t=this.name||"";if(this.isArray()){const e=JSON.parse(this.arrayChildren.format("json"));return e.name=t,e.type+=`[${this.arrayLength<0?"":String(this.arrayLength)}]`,JSON.stringify(e)}const n={type:"tuple"===this.baseType?"tuple":this.type,name:t};return"boolean"==typeof this.indexed&&(n.indexed=this.indexed),this.isTuple()&&(n.components=this.components.map(t=>JSON.parse(t.format(e)))),JSON.stringify(n)}let t="";return this.isArray()?(t+=this.arrayChildren.format(e),t+=`[${this.arrayLength<0?"":String(this.arrayLength)}]`):this.isTuple()?t+="("+this.components.map(t=>t.format(e)).join("full"===e?", ":",")+")":t+=this.type,"sighash"!==e&&(!0===this.indexed&&(t+=" indexed"),"full"===e&&this.name&&(t+=" "+this.name)),t}isArray(){return"array"===this.baseType}isTuple(){return"tuple"===this.baseType}isIndexable(){return null!=this.indexed}walk(e,t){if(this.isArray()){if(!Array.isArray(e))throw new Error("invalid array value");if(-1!==this.arrayLength&&e.length!==this.arrayLength)throw new Error("array is wrong length");const n=this;return e.map(e=>n.arrayChildren.walk(e,t))}if(this.isTuple()){if(!Array.isArray(e))throw new Error("invalid tuple value");if(e.length!==this.components.length)throw new Error("array is wrong length");const n=this;return e.map((e,r)=>n.components[r].walk(e,t))}return t(this.type,e)}async walkAsync(e,t){const n=[],r=[e];return __privateMethod(this,Ce,Ne).call(this,n,e,t,e=>{r[0]=e}),n.length&&await Promise.all(n),r[0]}static from(t,n){if(e.isParamType(t))return t;if("string"==typeof t)try{return e.from(eM(t),n)}catch(o){bS(!1,"invalid param type","obj",t)}else if(t instanceof XB){let r="",i="",s=null;rM(t,DB(["tuple"])).has("tuple")||t.peekType("OPEN_PAREN")?(i="tuple",s=t.popParams().map(t=>e.from(t)),r=`tuple(${s.map(e=>e.format()).join(",")})`):(r=AM(t.popType("TYPE")),i=r);let a=null,o=null;for(;t.length&&t.peekType("BRACKET");){const n=t.pop();a=new e(lM,"",r,i,null,s,o,a),o=n.value,r+=n.text,i="array",s=null}let c=null;if(rM(t,zB).has("indexed")){if(!n)throw new Error("");c=!0}const A=t.peekType("ID")?t.pop().text:"";if(t.length)throw new Error("leftover tokens");return new e(lM,A,r,i,c,s,o,a)}const r=t.name;bS(!r||"string"==typeof r&&r.match(WB),"invalid name","obj.name",r);let i=t.indexed;null!=i&&(bS(n,"parameter cannot be indexed","obj.indexed",t.indexed),i=!!i);let s=t.type,a=s.match(cM);if(a){const n=parseInt(a[2]||"-1"),o=e.from({type:a[1],components:t.components});return new e(lM,r||"",s,"array",i,null,n,o)}if("tuple"===s||s.startsWith("tuple(")||s.startsWith("(")){const n=null!=t.components?t.components.map(t=>e.from(t)):null;return new e(lM,r||"",s,"tuple",i,n,null,null)}return s=AM(t.type),new e(lM,r||"",s,s,i,null,null,null)}static isParamType(e){return e&&e[fM]===uM}};class wM{constructor(e,t,n){__publicField(this,"type"),__publicField(this,"inputs"),ES(e,lM,"Fragment"),dS(this,{type:t,inputs:n=Object.freeze(n.slice())})}static from(e){if("string"==typeof e){try{wM.from(JSON.parse(e))}catch(t){}return wM.from(eM(e))}if(e instanceof XB)switch(e.peekKeyword(jB)){case"constructor":return TM.from(e);case"error":return EM.from(e);case"event":return kM.from(e);case"fallback":case"receive":return SM.from(e);case"function":return xM.from(e);case"struct":return IM.from(e)}else if("object"==typeof e){switch(e.type){case"constructor":return TM.from(e);case"error":return EM.from(e);case"event":return kM.from(e);case"fallback":case"receive":return SM.from(e);case"function":return xM.from(e);case"struct":return IM.from(e)}gS(!1,`unsupported type: ${e.type}`,"UNSUPPORTED_OPERATION",{operation:"Fragment.from"})}bS(!1,"unsupported frgament object","obj",e)}static isConstructor(e){return TM.isFragment(e)}static isError(e){return EM.isFragment(e)}static isEvent(e){return kM.isFragment(e)}static isFunction(e){return xM.isFragment(e)}static isStruct(e){return IM.isFragment(e)}}class vM extends wM{constructor(e,t,n,r){super(e,t,r),__publicField(this,"name"),bS("string"==typeof n&&n.match(WB),"invalid identifier","name",n),r=Object.freeze(r.slice()),dS(this,{name:n})}}function _M(e,t){return"("+t.map(t=>t.format(e)).join("full"===e?", ":",")+")"}class EM extends vM{constructor(e,t,n){super(e,"error",t,n),Object.defineProperty(this,fM,{value:dM})}get selector(){return sR(this.format("sighash")).substring(0,10)}format(e){if(null==e&&(e="sighash"),"json"===e)return JSON.stringify({type:"error",name:this.name,inputs:this.inputs.map(t=>JSON.parse(t.format(e)))});const t=[];return"sighash"!==e&&t.push("error"),t.push(this.name+_M(e,this.inputs)),t.join(" ")}static from(e){if(EM.isFragment(e))return e;if("string"==typeof e)return EM.from(eM(e));if(e instanceof XB){const t=nM("error",e),n=sM(e);return oM(e),new EM(lM,t,n)}return new EM(lM,e.name,e.inputs?e.inputs.map(bM.from):[])}static isFragment(e){return e&&e[fM]===dM}}class kM extends vM{constructor(e,t,n,r){super(e,"event",t,n),__publicField(this,"anonymous"),Object.defineProperty(this,fM,{value:hM}),dS(this,{anonymous:r})}get topicHash(){return sR(this.format("sighash"))}format(e){if(null==e&&(e="sighash"),"json"===e)return JSON.stringify({type:"event",anonymous:this.anonymous,name:this.name,inputs:this.inputs.map(t=>JSON.parse(t.format(e)))});const t=[];return"sighash"!==e&&t.push("event"),t.push(this.name+_M(e,this.inputs)),"sighash"!==e&&this.anonymous&&t.push("anonymous"),t.join(" ")}static getTopicHash(e,t){return t=(t||[]).map(e=>bM.from(e)),new kM(lM,e,t,!1).topicHash}static from(e){if(kM.isFragment(e))return e;if("string"==typeof e)try{return kM.from(eM(e))}catch(t){bS(!1,"invalid event fragment","obj",e)}else if(e instanceof XB){const t=nM("event",e),n=sM(e,!0),r=!!rM(e,DB(["anonymous"])).has("anonymous");return oM(e),new kM(lM,t,n,r)}return new kM(lM,e.name,e.inputs?e.inputs.map(e=>bM.from(e,!0)):[],!!e.anonymous)}static isFragment(e){return e&&e[fM]===hM}}class TM extends wM{constructor(e,t,n,r,i){super(e,t,n),__publicField(this,"payable"),__publicField(this,"gas"),Object.defineProperty(this,fM,{value:pM}),dS(this,{payable:r,gas:i})}format(e){if(gS(null!=e&&"sighash"!==e,"cannot format a constructor for sighash","UNSUPPORTED_OPERATION",{operation:"format(sighash)"}),"json"===e)return JSON.stringify({type:"constructor",stateMutability:this.payable?"payable":"undefined",payable:this.payable,gas:null!=this.gas?this.gas:void 0,inputs:this.inputs.map(t=>JSON.parse(t.format(e)))});const t=[`constructor${_M(e,this.inputs)}`];return this.payable&&t.push("payable"),null!=this.gas&&t.push(`@${this.gas.toString()}`),t.join(" ")}static from(e){if(TM.isFragment(e))return e;if("string"==typeof e)try{return TM.from(eM(e))}catch(t){bS(!1,"invalid constuctor fragment","obj",e)}else if(e instanceof XB){rM(e,DB(["constructor"]));const t=sM(e),n=!!rM(e,FB).has("payable"),r=aM(e);return oM(e),new TM(lM,"constructor",t,n,r)}return new TM(lM,"constructor",e.inputs?e.inputs.map(bM.from):[],!!e.payable,null!=e.gas?e.gas:null)}static isFragment(e){return e&&e[fM]===pM}}class SM extends wM{constructor(e,t,n){super(e,"fallback",t),__publicField(this,"payable"),Object.defineProperty(this,fM,{value:mM}),dS(this,{payable:n})}format(e){const t=0===this.inputs.length?"receive":"fallback";if("json"===e){const e=this.payable?"payable":"nonpayable";return JSON.stringify({type:t,stateMutability:e})}return`${t}()${this.payable?" payable":""}`}static from(e){if(SM.isFragment(e))return e;if("string"==typeof e)try{return SM.from(eM(e))}catch(t){bS(!1,"invalid fallback fragment","obj",e)}else if(e instanceof XB){const t=e.toString();if(bS(e.peekKeyword(DB(["fallback","receive"])),"type must be fallback or receive","obj",t),"receive"===e.popKeyword(DB(["fallback","receive"]))){const t=sM(e);return bS(0===t.length,"receive cannot have arguments","obj.inputs",t),rM(e,DB(["payable"])),oM(e),new SM(lM,[],!0)}let n=sM(e);n.length?bS(1===n.length&&"bytes"===n[0].type,"invalid fallback inputs","obj.inputs",n.map(e=>e.format("minimal")).join(", ")):n=[bM.from("bytes")];const r=iM(e);if(bS("nonpayable"===r||"payable"===r,"fallback cannot be constants","obj.stateMutability",r),rM(e,DB(["returns"])).has("returns")){const t=sM(e);bS(1===t.length&&"bytes"===t[0].type,"invalid fallback outputs","obj.outputs",t.map(e=>e.format("minimal")).join(", "))}return oM(e),new SM(lM,n,"payable"===r)}if("receive"===e.type)return new SM(lM,[],!0);if("fallback"===e.type){const t=[bM.from("bytes")],n="payable"===e.stateMutability;return new SM(lM,t,n)}bS(!1,"invalid fallback description","obj",e)}static isFragment(e){return e&&e[fM]===mM}}class xM extends vM{constructor(e,t,n,r,i,s){super(e,"function",t,r),__publicField(this,"constant"),__publicField(this,"outputs"),__publicField(this,"stateMutability"),__publicField(this,"payable"),__publicField(this,"gas"),Object.defineProperty(this,fM,{value:yM}),dS(this,{constant:"view"===n||"pure"===n,gas:s,outputs:i=Object.freeze(i.slice()),payable:"payable"===n,stateMutability:n})}get selector(){return sR(this.format("sighash")).substring(0,10)}format(e){if(null==e&&(e="sighash"),"json"===e)return JSON.stringify({type:"function",name:this.name,constant:this.constant,stateMutability:"nonpayable"!==this.stateMutability?this.stateMutability:void 0,payable:this.payable,gas:null!=this.gas?this.gas:void 0,inputs:this.inputs.map(t=>JSON.parse(t.format(e))),outputs:this.outputs.map(t=>JSON.parse(t.format(e)))});const t=[];return"sighash"!==e&&t.push("function"),t.push(this.name+_M(e,this.inputs)),"sighash"!==e&&("nonpayable"!==this.stateMutability&&t.push(this.stateMutability),this.outputs&&this.outputs.length&&(t.push("returns"),t.push(_M(e,this.outputs))),null!=this.gas&&t.push(`@${this.gas.toString()}`)),t.join(" ")}static getSelector(e,t){return t=(t||[]).map(e=>bM.from(e)),new xM(lM,e,"view",t,[],null).selector}static from(e){if(xM.isFragment(e))return e;if("string"==typeof e)try{return xM.from(eM(e))}catch(n){bS(!1,"invalid function fragment","obj",e)}else if(e instanceof XB){const t=nM("function",e),n=sM(e),r=iM(e);let i=[];rM(e,DB(["returns"])).has("returns")&&(i=sM(e));const s=aM(e);return oM(e),new xM(lM,t,r,n,i,s)}let t=e.stateMutability;return null==t&&(t="payable","boolean"==typeof e.constant?(t="view",e.constant||(t="payable","boolean"!=typeof e.payable||e.payable||(t="nonpayable"))):"boolean"!=typeof e.payable||e.payable||(t="nonpayable")),new xM(lM,e.name,t,e.inputs?e.inputs.map(bM.from):[],e.outputs?e.outputs.map(bM.from):[],null!=e.gas?e.gas:null)}static isFragment(e){return e&&e[fM]===yM}}class IM extends vM{constructor(e,t,n){super(e,"struct",t,n),Object.defineProperty(this,fM,{value:gM})}format(){throw new Error("@TODO")}static from(e){if("string"==typeof e)try{return IM.from(eM(e))}catch(t){bS(!1,"invalid struct fragment","obj",e)}else if(e instanceof XB){const t=nM("struct",e),n=sM(e);return oM(e),new IM(lM,t,n)}return new IM(lM,e.name,e.inputs?e.inputs.map(bM.from):[])}static isFragment(e){return e&&e[fM]===gM}}const PM=new Map;PM.set(0,"GENERIC_PANIC"),PM.set(1,"ASSERT_FALSE"),PM.set(17,"OVERFLOW"),PM.set(18,"DIVIDE_BY_ZERO"),PM.set(33,"ENUM_RANGE_ERROR"),PM.set(34,"BAD_STORAGE_DATA"),PM.set(49,"STACK_UNDERFLOW"),PM.set(50,"ARRAY_RANGE_ERROR"),PM.set(65,"OUT_OF_MEMORY"),PM.set(81,"UNINITIALIZED_FUNCTION_CALL");const CM=new RegExp(/^bytes([0-9]*)$/),NM=new RegExp(/^(u?int)([0-9]*)$/);let OM=null,RM=1024;Oe=new WeakSet,Re=function(e){if(e.isArray())return new bO(__privateMethod(this,Oe,Re).call(this,e.arrayChildren),e.arrayLength,e.name);if(e.isTuple())return new NO(e.components.map(e=>__privateMethod(this,Oe,Re).call(this,e)),e.name);switch(e.baseType){case"address":return new pO(e.name);case"bool":return new wO(e.name);case"string":return new CO(e.name);case"bytes":return new _O(e.name);case"":return new TO(e.name)}let t=e.type.match(NM);if(t){let n=parseInt(t[2]||"256");return bS(0!==n&&n<=256&&n%8==0,"invalid "+t[1]+" bit length","param",e),new PO(n/8,"int"===t[1],e.name)}if(t=e.type.match(CM),t){let n=parseInt(t[1]);return bS(0!==n&&n<=32,"invalid bytes length","param",e),new EO(n,e.name)}bS(!1,"invalid type","type",e.type)};let BM=class e{constructor(){__privateAdd(this,Oe)}getDefaultValue(e){const t=e.map(e=>__privateMethod(this,Oe,Re).call(this,bM.from(e)));return new NO(t,"_").defaultValue()}encode(e,t){wS(t.length,e.length,"types/values length mismatch");const n=e.map(e=>__privateMethod(this,Oe,Re).call(this,bM.from(e))),r=new NO(n,"_"),i=new mI;return r.encode(i,t),i.data}decode(e,t,n){const r=e.map(e=>__privateMethod(this,Oe,Re).call(this,bM.from(e)));return new NO(r,"_").decode(new yI(t,n,RM))}static _setDefaultMaxInflation(e){bS("number"==typeof e&&Number.isInteger(e),"invalid defaultMaxInflation factor","value",e),RM=e}static defaultAbiCoder(){return null==OM&&(OM=new e),OM}static getBuiltinCallException(t,n,r){return function(e,t,n,r){let i="missing revert data",s=null,a=null;if(n){i="execution reverted";const e=TS(n);if(n=CS(n),0===e.length)i+=" (no data present; likely require(false) occurred",s="require(false)";else if(e.length%32!=4)i+=" (could not decode reason; invalid data length)";else if("0x08c379a0"===CS(e.slice(0,4)))try{s=r.decode(["string"],e.slice(4))[0],a={signature:"Error(string)",name:"Error",args:[s]},i+=`: ${JSON.stringify(s)}`}catch(c){i+=" (could not decode reason; invalid string data)"}else if("0x4e487b71"===CS(e.slice(0,4)))try{const t=Number(r.decode(["uint256"],e.slice(4))[0]);a={signature:"Panic(uint256)",name:"Panic",args:[t]},s=`Panic due to ${PM.get(t)||"UNKNOWN"}(${t})`,i+=`: ${s}`}catch(c){i+=" (could not decode panic code)"}else i+=" (unknown custom error)"}const o={to:t.to?nO(t.to):null,data:t.data||"0x"};return t.from&&(o.from=nO(t.from)),yS(i,"CALL_EXCEPTION",{action:e,data:n,reason:s,transaction:o,invocation:null,revert:a})}(t,n,r,e.defaultAbiCoder())}};function MM(e){const t=ux(e);if(t.length>31)throw new Error("bytes32 string must be less than 32 bytes");return DS(t,32)}function $M(e){const t=TS(e,"bytes");if(32!==t.length)throw new Error("invalid bytes32 - not 32 bytes long");if(0!==t[31])throw new Error("invalid bytes32 string - no null terminator");let n=31;for(;0===t[n-1];)n--;return dx(t.slice(0,n))}class DM{constructor(e,t,n){__publicField(this,"fragment"),__publicField(this,"name"),__publicField(this,"signature"),__publicField(this,"topic"),__publicField(this,"args");const r=e.name,i=e.format();dS(this,{fragment:e,name:r,signature:i,topic:t,args:n})}}class FM{constructor(e,t,n,r){__publicField(this,"fragment"),__publicField(this,"name"),__publicField(this,"args"),__publicField(this,"signature"),__publicField(this,"selector"),__publicField(this,"value");const i=e.name,s=e.format();dS(this,{fragment:e,name:i,args:n,signature:s,selector:t,value:r})}}class GM{constructor(e,t,n){__publicField(this,"fragment"),__publicField(this,"name"),__publicField(this,"args"),__publicField(this,"signature"),__publicField(this,"selector");const r=e.name,i=e.format();dS(this,{fragment:e,name:r,args:n,signature:i,selector:t})}}class UM{constructor(e){__publicField(this,"hash"),__publicField(this,"_isIndexed"),dS(this,{hash:e,_isIndexed:!0})}static isIndexed(e){return!(!e||!e._isIndexed)}}const LM={0:"generic panic",1:"assert(false)",17:"arithmetic overflow",18:"division or modulo by zero",33:"enum overflow",34:"invalid encoded storage byte array accessed",49:"out-of-bounds array access; popping on an empty array",50:"out-of-bounds access of an array or bytesN",65:"out of memory",81:"uninitialized function"},jM={"0x08c379a0":{signature:"Error(string)",name:"Error",inputs:["string"],reason:e=>`reverted with reason string ${JSON.stringify(e)}`},"0x4e487b71":{signature:"Panic(uint256)",name:"Panic",inputs:["uint256"],reason:e=>{let t="unknown panic code";return e>=0&&e<=255&&LM[e.toString()]&&(t=LM[e.toString()]),`reverted with panic code 0x${e.toString(16)} (${t})`}}};Be=new WeakMap,Me=new WeakMap,$e=new WeakMap,De=new WeakMap,Fe=new WeakSet,Ge=function(e,t,n){if(xS(e)){const t=e.toLowerCase();for(const e of __privateGet(this,$e).values())if(t===e.selector)return e;return null}if(-1===e.indexOf("(")){const r=[];for(const[t,n]of __privateGet(this,$e))t.split("(")[0]===e&&r.push(n);if(t){const e=t.length>0?t[t.length-1]:null;let n=t.length,i=!0;hO.isTyped(e)&&"overrides"===e.type&&(i=!1,n--);for(let t=r.length-1;t>=0;t--){const e=r[t].inputs.length;e===n||i&&e===n-1||r.splice(t,1)}for(let s=r.length-1;s>=0;s--){const e=r[s].inputs;for(let n=0;n<t.length;n++)if(hO.isTyped(t[n])){if(n>=e.length){if("overrides"===t[n].type)continue;r.splice(s,1);break}if(t[n].type!==e[n].baseType){r.splice(s,1);break}}}}if(1===r.length&&t&&t.length!==r[0].inputs.length){const e=t[t.length-1];(null==e||Array.isArray(e)||"object"!=typeof e)&&r.splice(0,1)}return 0===r.length?null:(r.length>1&&n&&bS(!1,`ambiguous function description (i.e. matches ${r.map(e=>JSON.stringify(e.format())).join(", ")})`,"key",e),r[0])}return __privateGet(this,$e).get(xM.from(e).format())||null},Ue=function(e,t,n){if(xS(e)){const t=e.toLowerCase();for(const e of __privateGet(this,Me).values())if(t===e.topicHash)return e;return null}if(-1===e.indexOf("(")){const r=[];for(const[t,n]of __privateGet(this,Me))t.split("(")[0]===e&&r.push(n);if(t){for(let e=r.length-1;e>=0;e--)r[e].inputs.length<t.length&&r.splice(e,1);for(let e=r.length-1;e>=0;e--){const n=r[e].inputs;for(let i=0;i<t.length;i++)if(hO.isTyped(t[i])&&t[i].type!==n[i].baseType){r.splice(e,1);break}}}return 0===r.length?null:(r.length>1&&n&&bS(!1,`ambiguous event description (i.e. matches ${r.map(e=>JSON.stringify(e.format())).join(", ")})`,"key",e),r[0])}return __privateGet(this,Me).get(kM.from(e).format())||null};let HM=class e{constructor(e){__privateAdd(this,Fe),__publicField(this,"fragments"),__publicField(this,"deploy"),__publicField(this,"fallback"),__publicField(this,"receive"),__privateAdd(this,Be),__privateAdd(this,Me),__privateAdd(this,$e),__privateAdd(this,De);let t=[];t="string"==typeof e?JSON.parse(e):e,__privateSet(this,$e,new Map),__privateSet(this,Be,new Map),__privateSet(this,Me,new Map);const n=[];for(const a of t)try{n.push(wM.from(a))}catch(s){console.log(`[Warning] Invalid Fragment ${JSON.stringify(a)}:`,s.message)}dS(this,{fragments:Object.freeze(n)});let r=null,i=!1;__privateSet(this,De,this.getAbiCoder()),this.fragments.forEach((e,t)=>{let n;switch(e.type){case"constructor":return this.deploy?void console.log("duplicate definition - constructor"):void dS(this,{deploy:e});case"fallback":return void(0===e.inputs.length?i=!0:(bS(!r||e.payable!==r.payable,"conflicting fallback fragments",`fragments[${t}]`,e),r=e,i=r.payable));case"function":n=__privateGet(this,$e);break;case"event":n=__privateGet(this,Me);break;case"error":n=__privateGet(this,Be);break;default:return}const s=e.format();n.has(s)||n.set(s,e)}),this.deploy||dS(this,{deploy:TM.from("constructor()")}),dS(this,{fallback:r,receive:i})}format(e){const t=e?"minimal":"full";return this.fragments.map(e=>e.format(t))}formatJson(){const e=this.fragments.map(e=>e.format("json"));return JSON.stringify(e.map(e=>JSON.parse(e)))}getAbiCoder(){return BM.defaultAbiCoder()}getFunctionName(e){const t=__privateMethod(this,Fe,Ge).call(this,e,null,!1);return bS(t,"no matching function","key",e),t.name}hasFunction(e){return!!__privateMethod(this,Fe,Ge).call(this,e,null,!1)}getFunction(e,t){return __privateMethod(this,Fe,Ge).call(this,e,t||null,!0)}forEachFunction(e){const t=Array.from(__privateGet(this,$e).keys());t.sort((e,t)=>e.localeCompare(t));for(let n=0;n<t.length;n++){const r=t[n];e(__privateGet(this,$e).get(r),n)}}getEventName(e){const t=__privateMethod(this,Fe,Ue).call(this,e,null,!1);return bS(t,"no matching event","key",e),t.name}hasEvent(e){return!!__privateMethod(this,Fe,Ue).call(this,e,null,!1)}getEvent(e,t){return __privateMethod(this,Fe,Ue).call(this,e,t||null,!0)}forEachEvent(e){const t=Array.from(__privateGet(this,Me).keys());t.sort((e,t)=>e.localeCompare(t));for(let n=0;n<t.length;n++){const r=t[n];e(__privateGet(this,Me).get(r),n)}}getError(e,t){if(xS(e)){const t=e.toLowerCase();if(jM[t])return EM.from(jM[t].signature);for(const e of __privateGet(this,Be).values())if(t===e.selector)return e;return null}if(-1===e.indexOf("(")){const t=[];for(const[n,r]of __privateGet(this,Be))n.split("(")[0]===e&&t.push(r);return 0===t.length?"Error"===e?EM.from("error Error(string)"):"Panic"===e?EM.from("error Panic(uint256)"):null:(t.length>1&&bS(!1,`ambiguous error description (i.e. ${t.map(e=>JSON.stringify(e.format())).join(", ")})`,"name",e),t[0])}if("Error(string)"===(e=EM.from(e).format()))return EM.from("error Error(string)");if("Panic(uint256)"===e)return EM.from("error Panic(uint256)");return __privateGet(this,Be).get(e)||null}forEachError(e){const t=Array.from(__privateGet(this,Be).keys());t.sort((e,t)=>e.localeCompare(t));for(let n=0;n<t.length;n++){const r=t[n];e(__privateGet(this,Be).get(r),n)}}_decodeParams(e,t){return __privateGet(this,De).decode(e,t)}_encodeParams(e,t){return __privateGet(this,De).encode(e,t)}encodeDeploy(e){return this._encodeParams(this.deploy.inputs,e||[])}decodeErrorResult(e,t){if("string"==typeof e){const t=this.getError(e);bS(t,"unknown error","fragment",e),e=t}return bS(RS(t,0,4)===e.selector,`data signature does not match error ${e.name}.`,"data",t),this._decodeParams(e.inputs,RS(t,4))}encodeErrorResult(e,t){if("string"==typeof e){const t=this.getError(e);bS(t,"unknown error","fragment",e),e=t}return NS([e.selector,this._encodeParams(e.inputs,t||[])])}decodeFunctionData(e,t){if("string"==typeof e){const t=this.getFunction(e);bS(t,"unknown function","fragment",e),e=t}return bS(RS(t,0,4)===e.selector,`data signature does not match function ${e.name}.`,"data",t),this._decodeParams(e.inputs,RS(t,4))}encodeFunctionData(e,t){if("string"==typeof e){const t=this.getFunction(e);bS(t,"unknown function","fragment",e),e=t}return NS([e.selector,this._encodeParams(e.inputs,t||[])])}decodeFunctionResult(e,t){if("string"==typeof e){const t=this.getFunction(e);bS(t,"unknown function","fragment",e),e=t}let n="invalid length for result data";const r=SS(t);if(r.length%32==0)try{return __privateGet(this,De).decode(e.outputs,r)}catch(i){n="could not decode result data"}gS(!1,n,"BAD_DATA",{value:CS(r),info:{method:e.name,signature:e.format()}})}makeError(e,t){const n=TS(e,"data"),r=BM.getBuiltinCallException("call",t,n);if(r.message.startsWith("execution reverted (unknown custom error)")){const e=CS(n.slice(0,4)),t=this.getError(e);if(t)try{const e=__privateGet(this,De).decode(t.inputs,n.slice(4));r.revert={name:t.name,signature:t.format(),args:e},r.reason=r.revert.signature,r.message=`execution reverted: ${r.reason}`}catch(s){r.message="execution reverted (coult not decode custom error)"}}const i=this.parseTransaction(t);return i&&(r.invocation={method:i.name,signature:i.signature,args:i.args}),r}encodeFunctionResult(e,t){if("string"==typeof e){const t=this.getFunction(e);bS(t,"unknown function","fragment",e),e=t}return CS(__privateGet(this,De).encode(e.outputs,t||[]))}encodeFilterTopics(e,t){if("string"==typeof e){const t=this.getEvent(e);bS(t,"unknown event","eventFragment",e),e=t}gS(t.length<=e.inputs.length,`too many arguments for ${e.format()}`,"UNEXPECTED_ARGUMENT",{count:t.length,expectedCount:e.inputs.length});const n=[];e.anonymous||n.push(e.topicHash);const r=(e,t)=>"string"===e.type?sR(t):"bytes"===e.type?RP(CS(t)):("bool"===e.type&&"boolean"==typeof t?t=t?"0x01":"0x00":e.type.match(/^u?int/)?t=WS(t):e.type.match(/^bytes/)?t=DS(t,32):"address"===e.type&&__privateGet(this,De).encode(["address"],[t]),$S(CS(t),32));for(t.forEach((t,i)=>{const s=e.inputs[i];s.indexed?null==t?n.push(null):"array"===s.baseType||"tuple"===s.baseType?bS(!1,"filtering with tuples or arrays not supported","contract."+s.name,t):Array.isArray(t)?n.push(t.map(e=>r(s,e))):n.push(r(s,t)):bS(null==t,"cannot filter non-indexed parameters; must be null","contract."+s.name,t)});n.length&&null===n[n.length-1];)n.pop();return n}encodeEventLog(e,t){if("string"==typeof e){const t=this.getEvent(e);bS(t,"unknown event","eventFragment",e),e=t}const n=[],r=[],i=[];return e.anonymous||n.push(e.topicHash),bS(t.length===e.inputs.length,"event arguments/values mismatch","values",t),e.inputs.forEach((e,s)=>{const a=t[s];if(e.indexed)if("string"===e.type)n.push(sR(a));else if("bytes"===e.type)n.push(RP(a));else{if("tuple"===e.baseType||"array"===e.baseType)throw new Error("not implemented");n.push(__privateGet(this,De).encode([e.type],[a]))}else r.push(e),i.push(a)}),{data:__privateGet(this,De).encode(r,i),topics:n}}decodeEventLog(e,t,n){if("string"==typeof e){const t=this.getEvent(e);bS(t,"unknown event","eventFragment",e),e=t}if(null!=n&&!e.anonymous){const t=e.topicHash;bS(xS(n[0],32)&&n[0].toLowerCase()===t,"fragment/topic mismatch","topics[0]",n[0]),n=n.slice(1)}const r=[],i=[],s=[];e.inputs.forEach((e,t)=>{e.indexed?"string"===e.type||"bytes"===e.type||"tuple"===e.baseType||"array"===e.baseType?(r.push(bM.from({type:"bytes32",name:e.name})),s.push(!0)):(r.push(e),s.push(!1)):(i.push(e),s.push(!1))});const a=null!=n?__privateGet(this,De).decode(r,NS(n)):null,o=__privateGet(this,De).decode(i,t,!0),c=[],A=[];let l=0,f=0;return e.inputs.forEach((e,t)=>{let n=null;if(e.indexed)if(null==a)n=new UM(null);else if(s[t])n=new UM(a[f++]);else try{n=a[f++]}catch(r){n=r}else try{n=o[l++]}catch(r){n=r}c.push(n),A.push(e.name||null)}),uI.fromItems(c,A)}parseTransaction(e){const t=TS(e.data,"tx.data"),n=zS(null!=e.value?e.value:0,"tx.value"),r=this.getFunction(CS(t.slice(0,4)));if(!r)return null;const i=__privateGet(this,De).decode(r.inputs,t.slice(4));return new FM(r,r.selector,i,n)}parseCallResult(e){throw new Error("@TODO")}parseLog(e){const t=this.getEvent(e.topics[0]);return!t||t.anonymous?null:new DM(t,t.topicHash,this.decodeEventLog(t,e.data,e.topics))}parseError(e){const t=CS(e),n=this.getError(RS(t,0,4));if(!n)return null;const r=__privateGet(this,De).decode(n.inputs,RS(t,4));return new GM(n,n.selector,r)}static from(t){return t instanceof e?t:"string"==typeof t?new e(JSON.parse(t)):"function"==typeof t.formatJson?new e(t.formatJson()):"function"==typeof t.format?new e(t.format("json")):new e(t)}};const zM=BigInt(0);function qM(e){return null==e?null:e}function QM(e){return null==e?null:e.toString()}class VM{constructor(e,t,n){__publicField(this,"gasPrice"),__publicField(this,"maxFeePerGas"),__publicField(this,"maxPriorityFeePerGas"),dS(this,{gasPrice:qM(e),maxFeePerGas:qM(t),maxPriorityFeePerGas:qM(n)})}toJSON(){const{gasPrice:e,maxFeePerGas:t,maxPriorityFeePerGas:n}=this;return{_type:"FeeData",gasPrice:QM(e),maxFeePerGas:QM(t),maxPriorityFeePerGas:QM(n)}}}function JM(e){const t={};e.to&&(t.to=e.to),e.from&&(t.from=e.from),e.data&&(t.data=CS(e.data));const n="chainId,gasLimit,gasPrice,maxFeePerBlobGas,maxFeePerGas,maxPriorityFeePerGas,value".split(/,/);for(const i of n)i in e&&null!=e[i]&&(t[i]=zS(e[i],`request.${i}`));const r="type,nonce".split(/,/);for(const i of r)i in e&&null!=e[i]&&(t[i]=JS(e[i],`request.${i}`));return e.accessList&&(t.accessList=RO(e.accessList)),e.authorizationList&&(t.authorizationList=e.authorizationList.slice()),"blockTag"in e&&(t.blockTag=e.blockTag),"enableCcipRead"in e&&(t.enableCcipRead=!!e.enableCcipRead),"customData"in e&&(t.customData=e.customData),"blobVersionedHashes"in e&&e.blobVersionedHashes&&(t.blobVersionedHashes=e.blobVersionedHashes.slice()),"kzg"in e&&(t.kzg=e.kzg),"blobWrapperVersion"in e&&(t.blobWrapperVersion=e.blobWrapperVersion),"blobs"in e&&e.blobs&&(t.blobs=e.blobs.map(e=>IS(e)?CS(e):Object.assign({},e))),t}class KM{constructor(e,t){__publicField(this,"provider"),__publicField(this,"number"),__publicField(this,"hash"),__publicField(this,"timestamp"),__publicField(this,"parentHash"),__publicField(this,"parentBeaconBlockRoot"),__publicField(this,"nonce"),__publicField(this,"difficulty"),__publicField(this,"gasLimit"),__publicField(this,"gasUsed"),__publicField(this,"stateRoot"),__publicField(this,"receiptsRoot"),__publicField(this,"blobGasUsed"),__publicField(this,"excessBlobGas"),__publicField(this,"miner"),__publicField(this,"prevRandao"),__publicField(this,"extraData"),__publicField(this,"baseFeePerGas"),__privateAdd(this,Le),__privateSet(this,Le,e.transactions.map(e=>"string"!=typeof e?new ZM(e,t):e)),dS(this,{provider:t,hash:qM(e.hash),number:e.number,timestamp:e.timestamp,parentHash:e.parentHash,parentBeaconBlockRoot:e.parentBeaconBlockRoot,nonce:e.nonce,difficulty:e.difficulty,gasLimit:e.gasLimit,gasUsed:e.gasUsed,blobGasUsed:e.blobGasUsed,excessBlobGas:e.excessBlobGas,miner:e.miner,prevRandao:qM(e.prevRandao),extraData:e.extraData,baseFeePerGas:qM(e.baseFeePerGas),stateRoot:e.stateRoot,receiptsRoot:e.receiptsRoot})}get transactions(){return __privateGet(this,Le).map(e=>"string"==typeof e?e:e.hash)}get prefetchedTransactions(){const e=__privateGet(this,Le).slice();return 0===e.length?[]:(gS("object"==typeof e[0],"transactions were not prefetched with block request","UNSUPPORTED_OPERATION",{operation:"transactionResponses()"}),e)}toJSON(){const{baseFeePerGas:e,difficulty:t,extraData:n,gasLimit:r,gasUsed:i,hash:s,miner:a,prevRandao:o,nonce:c,number:A,parentHash:l,parentBeaconBlockRoot:f,stateRoot:u,receiptsRoot:d,timestamp:h,transactions:p}=this;return{_type:"Block",baseFeePerGas:QM(e),difficulty:QM(t),extraData:n,gasLimit:QM(r),gasUsed:QM(i),blobGasUsed:QM(this.blobGasUsed),excessBlobGas:QM(this.excessBlobGas),hash:s,miner:a,prevRandao:o,nonce:c,number:A,parentHash:l,timestamp:h,parentBeaconBlockRoot:f,stateRoot:u,receiptsRoot:d,transactions:p}}[Symbol.iterator](){let e=0;const t=this.transactions;return{next:()=>e<this.length?{value:t[e++],done:!1}:{value:void 0,done:!0}}}get length(){return __privateGet(this,Le).length}get date(){return null==this.timestamp?null:new Date(1e3*this.timestamp)}async getTransaction(e){let t;if("number"==typeof e)t=__privateGet(this,Le)[e];else{const n=e.toLowerCase();for(const e of __privateGet(this,Le)){if("string"==typeof e){if(e!==n)continue;t=e;break}if(e.hash===n){t=e;break}}}if(null==t)throw new Error("no such tx");return"string"==typeof t?await this.provider.getTransaction(t):t}getPrefetchedTransaction(e){const t=this.prefetchedTransactions;if("number"==typeof e)return t[e];e=e.toLowerCase();for(const n of t)if(n.hash===e)return n;bS(!1,"no matching transaction","indexOrHash",e)}isMined(){return!!this.hash}isLondon(){return!!this.baseFeePerGas}orphanedEvent(){if(!this.isMined())throw new Error("");return{orphan:"drop-block",hash:this.hash,number:this.number}}}Le=new WeakMap;class WM{constructor(e,t){__publicField(this,"provider"),__publicField(this,"transactionHash"),__publicField(this,"blockHash"),__publicField(this,"blockNumber"),__publicField(this,"removed"),__publicField(this,"address"),__publicField(this,"data"),__publicField(this,"topics"),__publicField(this,"index"),__publicField(this,"transactionIndex"),this.provider=t;const n=Object.freeze(e.topics.slice());dS(this,{transactionHash:e.transactionHash,blockHash:e.blockHash,blockNumber:e.blockNumber,removed:e.removed,address:e.address,data:e.data,topics:n,index:e.index,transactionIndex:e.transactionIndex})}toJSON(){const{address:e,blockHash:t,blockNumber:n,data:r,index:i,removed:s,topics:a,transactionHash:o,transactionIndex:c}=this;return{_type:"log",address:e,blockHash:t,blockNumber:n,data:r,index:i,removed:s,topics:a,transactionHash:o,transactionIndex:c}}async getBlock(){const e=await this.provider.getBlock(this.blockHash);return gS(!!e,"failed to find transaction","UNKNOWN_ERROR",{}),e}async getTransaction(){const e=await this.provider.getTransaction(this.transactionHash);return gS(!!e,"failed to find transaction","UNKNOWN_ERROR",{}),e}async getTransactionReceipt(){const e=await this.provider.getTransactionReceipt(this.transactionHash);return gS(!!e,"failed to find transaction receipt","UNKNOWN_ERROR",{}),e}removedEvent(){return{orphan:"drop-log",log:{transactionHash:(e=this).transactionHash,blockHash:e.blockHash,blockNumber:e.blockNumber,address:e.address,data:e.data,topics:Object.freeze(e.topics.slice()),index:e.index}};var e}}class YM{constructor(e,t){__publicField(this,"provider"),__publicField(this,"to"),__publicField(this,"from"),__publicField(this,"contractAddress"),__publicField(this,"hash"),__publicField(this,"index"),__publicField(this,"blockHash"),__publicField(this,"blockNumber"),__publicField(this,"logsBloom"),__publicField(this,"gasUsed"),__publicField(this,"blobGasUsed"),__publicField(this,"cumulativeGasUsed"),__publicField(this,"gasPrice"),__publicField(this,"blobGasPrice"),__publicField(this,"type"),__publicField(this,"status"),__publicField(this,"root"),__privateAdd(this,je),__privateSet(this,je,Object.freeze(e.logs.map(e=>new WM(e,t))));let n=zM;null!=e.effectiveGasPrice?n=e.effectiveGasPrice:null!=e.gasPrice&&(n=e.gasPrice),dS(this,{provider:t,to:e.to,from:e.from,contractAddress:e.contractAddress,hash:e.hash,index:e.index,blockHash:e.blockHash,blockNumber:e.blockNumber,logsBloom:e.logsBloom,gasUsed:e.gasUsed,cumulativeGasUsed:e.cumulativeGasUsed,blobGasUsed:e.blobGasUsed,gasPrice:n,blobGasPrice:e.blobGasPrice,type:e.type,status:e.status,root:e.root})}get logs(){return __privateGet(this,je)}toJSON(){const{to:e,from:t,contractAddress:n,hash:r,index:i,blockHash:s,blockNumber:a,logsBloom:o,logs:c,status:A,root:l}=this;return{_type:"TransactionReceipt",blockHash:s,blockNumber:a,contractAddress:n,cumulativeGasUsed:QM(this.cumulativeGasUsed),from:t,gasPrice:QM(this.gasPrice),blobGasUsed:QM(this.blobGasUsed),blobGasPrice:QM(this.blobGasPrice),gasUsed:QM(this.gasUsed),hash:r,index:i,logs:c,logsBloom:o,root:l,status:A,to:e}}get length(){return this.logs.length}[Symbol.iterator](){let e=0;return{next:()=>e<this.length?{value:this.logs[e++],done:!1}:{value:void 0,done:!0}}}get fee(){return this.gasUsed*this.gasPrice}async getBlock(){const e=await this.provider.getBlock(this.blockHash);if(null==e)throw new Error("TODO");return e}async getTransaction(){const e=await this.provider.getTransaction(this.hash);if(null==e)throw new Error("TODO");return e}async getResult(){return await this.provider.getTransactionResult(this.hash)}async confirmations(){return await this.provider.getBlockNumber()-this.blockNumber+1}removedEvent(){return e$(this)}reorderedEvent(e){return gS(!e||e.isMined(),"unmined 'other' transction cannot be orphaned","UNSUPPORTED_OPERATION",{operation:"reorderedEvent(other)"}),XM(this,e)}}je=new WeakMap,He=new WeakMap;let ZM=class e{constructor(e,t){__publicField(this,"provider"),__publicField(this,"blockNumber"),__publicField(this,"blockHash"),__publicField(this,"index"),__publicField(this,"hash"),__publicField(this,"type"),__publicField(this,"to"),__publicField(this,"from"),__publicField(this,"nonce"),__publicField(this,"gasLimit"),__publicField(this,"gasPrice"),__publicField(this,"maxPriorityFeePerGas"),__publicField(this,"maxFeePerGas"),__publicField(this,"maxFeePerBlobGas"),__publicField(this,"data"),__publicField(this,"value"),__publicField(this,"chainId"),__publicField(this,"signature"),__publicField(this,"accessList"),__publicField(this,"blobVersionedHashes"),__publicField(this,"authorizationList"),__privateAdd(this,He),this.provider=t,this.blockNumber=null!=e.blockNumber?e.blockNumber:null,this.blockHash=null!=e.blockHash?e.blockHash:null,this.hash=e.hash,this.index=e.index,this.type=e.type,this.from=e.from,this.to=e.to||null,this.gasLimit=e.gasLimit,this.nonce=e.nonce,this.data=e.data,this.value=e.value,this.gasPrice=e.gasPrice,this.maxPriorityFeePerGas=null!=e.maxPriorityFeePerGas?e.maxPriorityFeePerGas:null,this.maxFeePerGas=null!=e.maxFeePerGas?e.maxFeePerGas:null,this.maxFeePerBlobGas=null!=e.maxFeePerBlobGas?e.maxFeePerBlobGas:null,this.chainId=e.chainId,this.signature=e.signature,this.accessList=null!=e.accessList?e.accessList:null,this.blobVersionedHashes=null!=e.blobVersionedHashes?e.blobVersionedHashes:null,this.authorizationList=null!=e.authorizationList?e.authorizationList:null,__privateSet(this,He,-1)}toJSON(){const{blockNumber:e,blockHash:t,index:n,hash:r,type:i,to:s,from:a,nonce:o,data:c,signature:A,accessList:l,blobVersionedHashes:f}=this;return{_type:"TransactionResponse",accessList:l,blockNumber:e,blockHash:t,blobVersionedHashes:f,chainId:QM(this.chainId),data:c,from:a,gasLimit:QM(this.gasLimit),gasPrice:QM(this.gasPrice),hash:r,maxFeePerGas:QM(this.maxFeePerGas),maxPriorityFeePerGas:QM(this.maxPriorityFeePerGas),maxFeePerBlobGas:QM(this.maxFeePerBlobGas),nonce:o,signature:A,to:s,index:n,type:i,value:QM(this.value)}}async getBlock(){let e=this.blockNumber;if(null==e){const t=await this.getTransaction();t&&(e=t.blockNumber)}if(null==e)return null;const t=this.provider.getBlock(e);if(null==t)throw new Error("TODO");return t}async getTransaction(){return this.provider.getTransaction(this.hash)}async confirmations(){if(null==this.blockNumber){const{tx:e,blockNumber:t}=await uS({tx:this.getTransaction(),blockNumber:this.provider.getBlockNumber()});return null==e||null==e.blockNumber?0:t-e.blockNumber+1}return await this.provider.getBlockNumber()-this.blockNumber+1}async wait(e,t){const n=null==e?1:e,r=null==t?0:t;let i=__privateGet(this,He),s=-1,a=-1===i;const o=async()=>{if(a)return null;const{blockNumber:e,nonce:t}=await uS({blockNumber:this.provider.getBlockNumber(),nonce:this.provider.getTransactionCount(this.from)});if(t<this.nonce)return void(i=e);if(a)return null;const r=await this.getTransaction();if(!r||null==r.blockNumber)for(-1===s&&(s=i-3,s<__privateGet(this,He)&&(s=__privateGet(this,He)));s<=e;){if(a)return null;const t=await this.provider.getBlock(s,!0);if(null==t)return;for(const e of t)if(e===this.hash)return;for(let r=0;r<t.length;r++){const s=await t.getTransaction(r);if(s.from===this.from&&s.nonce===this.nonce){if(a)return null;const t=await this.provider.getTransactionReceipt(s.hash);if(null==t)return;if(e-t.blockNumber+1<n)return;let r="replaced";s.data===this.data&&s.to===this.to&&s.value===this.value?r="repriced":"0x"===s.data&&s.from===s.to&&s.value===zM&&(r="cancelled"),gS(!1,"transaction was replaced","TRANSACTION_REPLACED",{cancelled:"replaced"===r||"cancelled"===r,reason:r,replacement:s.replaceableTransaction(i),hash:s.hash,receipt:t})}}s++}},c=e=>{if(null==e||0!==e.status)return e;gS(!1,"transaction execution reverted","CALL_EXCEPTION",{action:"sendTransaction",data:null,reason:null,invocation:null,revert:null,transaction:{to:e.to,from:e.from,data:""},receipt:e})},A=await this.provider.getTransactionReceipt(this.hash);if(0===n)return c(A);if(A){if(1===n||await A.confirmations()>=n)return c(A)}else if(await o(),0===n)return null;const l=new Promise((e,t)=>{const s=[],A=()=>{s.forEach(e=>e())};if(s.push(()=>{a=!0}),r>0){const e=setTimeout(()=>{A(),t(yS("wait for transaction timeout","TIMEOUT"))},r);s.push(()=>{clearTimeout(e)})}const l=async r=>{if(await r.confirmations()>=n){A();try{e(c(r))}catch(i){t(i)}}};if(s.push(()=>{this.provider.off(this.hash,l)}),this.provider.on(this.hash,l),i>=0){const e=async()=>{try{await o()}catch(n){if(pS(n,"TRANSACTION_REPLACED"))return A(),void t(n)}a||this.provider.once("block",e)};s.push(()=>{this.provider.off("block",e)}),this.provider.once("block",e)}});return await l}isMined(){return null!=this.blockHash}isLegacy(){return 0===this.type}isBerlin(){return 1===this.type}isLondon(){return 2===this.type}isCancun(){return 3===this.type}removedEvent(){return gS(this.isMined(),"unmined transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),e$(this)}reorderedEvent(e){return gS(this.isMined(),"unmined transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),gS(!e||e.isMined(),"unmined 'other' transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),XM(this,e)}replaceableTransaction(t){bS(Number.isInteger(t)&&t>=0,"invalid startBlock","startBlock",t);const n=new e(this,this.provider);return __privateSet(n,He,t),n}};function XM(e,t){return{orphan:"reorder-transaction",tx:e,other:t}}function e$(e){return{orphan:"drop-transaction",tx:e}}class t$ extends WM{constructor(e,t,n){super(e,e.provider),__publicField(this,"interface"),__publicField(this,"fragment"),__publicField(this,"args"),dS(this,{args:t.decodeEventLog(n,e.data,e.topics),fragment:n,interface:t})}get eventName(){return this.fragment.name}get eventSignature(){return this.fragment.format()}}class n$ extends WM{constructor(e,t){super(e,e.provider),__publicField(this,"error"),dS(this,{error:t})}}class r$ extends YM{constructor(e,t,n){super(n,t),__privateAdd(this,ze),__privateSet(this,ze,e)}get logs(){return super.logs.map(e=>{const t=e.topics.length?__privateGet(this,ze).getEvent(e.topics[0]):null;if(t)try{return new t$(e,__privateGet(this,ze),t)}catch(n){return new n$(e,n)}return e})}}ze=new WeakMap;class i$ extends ZM{constructor(e,t,n){super(n,t),__privateAdd(this,qe),__privateSet(this,qe,e)}async wait(e,t){const n=await super.wait(e,t);return null==n?null:new r$(__privateGet(this,qe),this.provider,n)}}qe=new WeakMap;class s$ extends cx{constructor(e,t,n,r){super(e,t,n),__publicField(this,"log"),dS(this,{log:r})}async getBlock(){return await this.log.getBlock()}async getTransaction(){return await this.log.getTransaction()}async getTransactionReceipt(){return await this.log.getTransactionReceipt()}}class a$ extends s${constructor(e,t,n,r,i){super(e,t,n,new t$(i,e.interface,r)),dS(this,{args:e.interface.decodeEventLog(r,this.log.data,this.log.topics),fragment:r})}get eventName(){return this.fragment.name}get eventSignature(){return this.fragment.format()}}const o$=BigInt(0);function c$(e){return e&&"function"==typeof e.call}function A$(e){return e&&"function"==typeof e.estimateGas}function l$(e){return e&&"function"==typeof e.resolveName}function f$(e){return e&&"function"==typeof e.sendTransaction}function u$(e){if(null!=e){if(l$(e))return e;if(e.provider)return e.provider}}class d${constructor(e,t,n){if(__privateAdd(this,Qe),__publicField(this,"fragment"),dS(this,{fragment:t}),t.inputs.length<n.length)throw new Error("too many arguments");const r=h$(e.runner,"resolveName"),i=l$(r)?r:null;__privateSet(this,Qe,async function(){const r=await Promise.all(t.inputs.map((e,t)=>null==n[t]?null:e.walkAsync(n[t],(e,t)=>"address"===e?Array.isArray(t)?Promise.all(t.map(e=>AO(e,i))):AO(t,i):t)));return e.interface.encodeFilterTopics(t,r)}())}getTopicFilter(){return __privateGet(this,Qe)}}function h$(e,t){return null==e?null:"function"==typeof e[t]?e:e.provider&&"function"==typeof e.provider[t]?e.provider:null}function p$(e){return null==e?null:e.provider||null}async function m$(e,t){const n=hO.dereference(e,"overrides");bS("object"==typeof n,"invalid overrides parameter","overrides",e);const r=JM(n);return bS(null==r.to||(t||[]).indexOf("to")>=0,"cannot override to","overrides.to",r.to),bS(null==r.data||(t||[]).indexOf("data")>=0,"cannot override data","overrides.data",r.data),r.from&&(r.from=r.from),r}async function y$(e,t,n){const r=h$(e,"resolveName"),i=l$(r)?r:null;return await Promise.all(t.map((e,t)=>e.walkAsync(n[t],(e,t)=>(t=hO.dereference(t,e),"address"===e?AO(t,i):t))))}function g$(e){const t=async function(t){const n=await m$(t,["data"]);n.to=await e.getAddress(),n.from&&(n.from=await AO(n.from,u$(e.runner)));const r=e.interface,i=zS(n.value||o$,"overrides.value")===o$,s="0x"===(n.data||"0x");return!r.fallback||r.fallback.payable||!r.receive||s||i||bS(!1,"cannot send data to receive or send value to non-payable fallback","overrides",t),bS(r.fallback||s,"cannot send data to receive-only contract","overrides.data",n.data),bS(r.receive||r.fallback&&r.fallback.payable||i,"cannot send value to non-payable fallback","overrides.value",n.value),bS(r.fallback||s,"cannot send data to receive-only contract","overrides.data",n.data),n},n=async function(n){const r=e.runner;gS(f$(r),"contract runner does not support sending transactions","UNSUPPORTED_OPERATION",{operation:"sendTransaction"});const i=await r.sendTransaction(await t(n)),s=p$(e.runner);return new i$(e.interface,s,i)},r=async e=>await n(e);return dS(r,{_contract:e,estimateGas:async function(n){const r=h$(e.runner,"estimateGas");return gS(A$(r),"contract runner does not support gas estimation","UNSUPPORTED_OPERATION",{operation:"estimateGas"}),await r.estimateGas(await t(n))},populateTransaction:t,send:n,staticCall:async function(n){const r=h$(e.runner,"call");gS(c$(r),"contract runner does not support calling","UNSUPPORTED_OPERATION",{operation:"call"});const i=await t(n);try{return await r.call(i)}catch(s){if(mS(s)&&s.data)throw e.interface.makeError(s.data,i);throw s}}}),r}Qe=new WeakMap;const b$=Symbol.for("_ethersInternal_contract"),w$=new WeakMap;function v$(e){return w$.get(e[b$])}async function _$(e,t){let n,r=null;if(Array.isArray(t)){const r=function(t){if(xS(t,32))return t;const n=e.interface.getEvent(t);return bS(n,"unknown fragment","name",t),n.topicHash};n=t.map(e=>null==e?null:Array.isArray(e)?e.map(r):r(e))}else"*"===t?n=[null]:"string"==typeof t?xS(t,32)?n=[t]:(r=e.interface.getEvent(t),bS(r,"unknown fragment","event",t),n=[r.topicHash]):(i=t)&&"object"==typeof i&&"getTopicFilter"in i&&"function"==typeof i.getTopicFilter&&i.fragment?n=await t.getTopicFilter():"fragment"in t?(r=t.fragment,n=[r.topicHash]):bS(!1,"unknown event name","event",t);var i;return n=n.map(e=>{if(null==e)return null;if(Array.isArray(e)){const t=Array.from(new Set(e.map(e=>e.toLowerCase())).values());return 1===t.length?t[0]:(t.sort(),t)}return e.toLowerCase()}),{fragment:r,tag:n.map(e=>null==e?"null":Array.isArray(e)?e.join("|"):e).join("&"),topics:n}}async function E$(e,t){const{subs:n}=v$(e);return n.get((await _$(e,t)).tag)||null}async function k$(e,t,n){const r=p$(e.runner);gS(r,"contract runner does not support subscribing","UNSUPPORTED_OPERATION",{operation:t});const{fragment:i,tag:s,topics:a}=await _$(e,n),{addr:o,subs:c}=v$(e);let A=c.get(s);if(!A){const t={address:o||e,topics:a},l=t=>{let r=i;if(null==r)try{r=e.interface.getEvent(t.topics[0])}catch(s){}if(r){const s=r,a=i?e.interface.decodeEventLog(i,t.data,t.topics):[];S$(e,n,a,r=>new a$(e,r,n,s,t))}else S$(e,n,[],r=>new s$(e,r,n,t))};let f=[];A={tag:s,listeners:[],start:()=>{f.length||f.push(r.on(t,l))},stop:async()=>{if(0==f.length)return;let e=f;f=[],await Promise.all(e),r.off(t,l)}},c.set(s,A)}return A}let T$=Promise.resolve();async function S$(e,t,n,r){try{await T$}catch(s){}const i=async function(e,t,n,r){await T$;const i=await E$(e,t);if(!i)return!1;const a=i.listeners.length;return i.listeners=i.listeners.filter(({listener:t,once:i})=>{const a=Array.from(n);r&&a.push(r(i?null:t));try{t.call(e,...a)}catch(s){}return!i}),0===i.listeners.length&&(i.stop(),v$(e).subs.delete(i.tag)),a>0}(e,t,n,r);return T$=i,await i}const x$=["then"];Ve=b$;let I$=class e{constructor(e,t,n,r){__publicField(this,"target"),__publicField(this,"interface"),__publicField(this,"runner"),__publicField(this,"filters"),__publicField(this,Ve),__publicField(this,"fallback"),bS("string"==typeof e||aO(e),"invalid value for Contract target","target",e),null==n&&(n=null);const i=HM.from(t);let s;dS(this,{target:e,runner:n,interface:i}),Object.defineProperty(this,b$,{value:{}});let a=null,o=null;if(r){const e=p$(n);o=new i$(this.interface,e,r)}let c=new Map;if("string"==typeof e)if(xS(e))a=e,s=Promise.resolve(e);else{const t=h$(n,"resolveName");if(!l$(t))throw yS("contract runner does not support name resolution","UNSUPPORTED_OPERATION",{operation:"resolveName"});s=t.resolveName(e).then(t=>{if(null==t)throw yS("an ENS name used for a contract target must be correctly configured","UNCONFIGURED_NAME",{value:e});return v$(this).addr=t,t})}else s=e.getAddress().then(e=>{if(null==e)throw new Error("TODO");return v$(this).addr=e,e});var A;return A={addrPromise:s,addr:a,deployTx:o,subs:c},w$.set(this[b$],A),dS(this,{filters:new Proxy({},{get:(e,t,n)=>{if("symbol"==typeof t||x$.indexOf(t)>=0)return Reflect.get(e,t,n);try{return this.getEvent(t)}catch(r){if(!pS(r,"INVALID_ARGUMENT")||"key"!==r.argument)throw r}},has:(e,t)=>x$.indexOf(t)>=0?Reflect.has(e,t):Reflect.has(e,t)||this.interface.hasEvent(String(t))})}),dS(this,{fallback:i.receive||i.fallback?g$(this):null}),new Proxy(this,{get:(e,t,n)=>{if("symbol"==typeof t||t in e||x$.indexOf(t)>=0)return Reflect.get(e,t,n);try{return e.getFunction(t)}catch(r){if(!pS(r,"INVALID_ARGUMENT")||"key"!==r.argument)throw r}},has:(e,t)=>"symbol"==typeof t||t in e||x$.indexOf(t)>=0?Reflect.has(e,t):e.interface.hasFunction(t)})}connect(t){return new e(this.target,this.interface,t)}attach(t){return new e(t,this.interface,this.runner)}async getAddress(){return await v$(this).addrPromise}async getDeployedCode(){const e=p$(this.runner);gS(e,"runner does not support .provider","UNSUPPORTED_OPERATION",{operation:"getDeployedCode"});const t=await e.getCode(await this.getAddress());return"0x"===t?null:t}async waitForDeployment(){const e=this.deploymentTransaction();if(e)return await e.wait(),this;if(null!=await this.getDeployedCode())return this;const t=p$(this.runner);return gS(null!=t,"contract runner does not support .provider","UNSUPPORTED_OPERATION",{operation:"waitForDeployment"}),new Promise((e,n)=>{const r=async()=>{try{if(null!=await this.getDeployedCode())return e(this);t.once("block",r)}catch(i){n(i)}};r()})}deploymentTransaction(){return v$(this).deployTx}getFunction(e){"string"!=typeof e&&(e=e.format());const t=function(e,t){const n=function(...n){const r=e.interface.getFunction(t,n);return gS(r,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:t,args:n}}),r},r=async function(...t){const r=n(...t);let i={};if(r.inputs.length+1===t.length&&(i=await m$(t.pop()),i.from&&(i.from=await AO(i.from,u$(e.runner)))),r.inputs.length!==t.length)throw new Error("internal error: fragment inputs doesn't match arguments; should not happen");const s=await y$(e.runner,r.inputs,t);return Object.assign({},i,await uS({to:e.getAddress(),data:e.interface.encodeFunctionData(r,s)}))},i=async function(...e){const t=await a(...e);return 1===t.length?t[0]:t},s=async function(...t){const n=e.runner;gS(f$(n),"contract runner does not support sending transactions","UNSUPPORTED_OPERATION",{operation:"sendTransaction"});const i=await n.sendTransaction(await r(...t)),s=p$(e.runner);return new i$(e.interface,s,i)},a=async function(...t){const i=h$(e.runner,"call");gS(c$(i),"contract runner does not support calling","UNSUPPORTED_OPERATION",{operation:"call"});const s=await r(...t);let a="0x";try{a=await i.call(s)}catch(c){if(mS(c)&&c.data)throw e.interface.makeError(c.data,s);throw c}const o=n(...t);return e.interface.decodeFunctionResult(o,a)},o=async(...e)=>n(...e).constant?await i(...e):await s(...e);return dS(o,{name:e.interface.getFunctionName(t),_contract:e,_key:t,getFragment:n,estimateGas:async function(...t){const n=h$(e.runner,"estimateGas");return gS(A$(n),"contract runner does not support gas estimation","UNSUPPORTED_OPERATION",{operation:"estimateGas"}),await n.estimateGas(await r(...t))},populateTransaction:r,send:s,staticCall:i,staticCallResult:a}),Object.defineProperty(o,"fragment",{configurable:!1,enumerable:!0,get:()=>{const n=e.interface.getFunction(t);return gS(n,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:t}}),n}}),o}(this,e);return t}getEvent(e){return"string"!=typeof e&&(e=e.format()),function(e,t){const n=function(...n){const r=e.interface.getEvent(t,n);return gS(r,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:t,args:n}}),r},r=function(...t){return new d$(e,n(...t),t)};return dS(r,{name:e.interface.getEventName(t),_contract:e,_key:t,getFragment:n}),Object.defineProperty(r,"fragment",{configurable:!1,enumerable:!0,get:()=>{const n=e.interface.getEvent(t);return gS(n,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:t}}),n}}),r}(this,e)}async queryTransaction(e){throw new Error("@TODO")}async queryFilter(e,t,n){null==t&&(t=0),null==n&&(n="latest");const{addr:r,addrPromise:i}=v$(this),s=r||await i,{fragment:a,topics:o}=await _$(this,e),c={address:s,topics:o,fromBlock:t,toBlock:n},A=p$(this.runner);return gS(A,"contract runner does not have a provider","UNSUPPORTED_OPERATION",{operation:"queryFilter"}),(await A.getLogs(c)).map(e=>{let t=a;if(null==t)try{t=this.interface.getEvent(e.topics[0])}catch(n){}if(t)try{return new t$(e,this.interface,t)}catch(n){return new n$(e,n)}return new WM(e,A)})}async on(e,t){const n=await k$(this,"on",e);return n.listeners.push({listener:t,once:!1}),n.start(),this}async once(e,t){const n=await k$(this,"once",e);return n.listeners.push({listener:t,once:!0}),n.start(),this}async emit(e,...t){return await S$(this,e,t,null)}async listenerCount(e){if(e){const t=await E$(this,e);return t?t.listeners.length:0}const{subs:t}=v$(this);let n=0;for(const{listeners:r}of t.values())n+=r.length;return n}async listeners(e){if(e){const t=await E$(this,e);return t?t.listeners.map(({listener:e})=>e):[]}const{subs:t}=v$(this);let n=[];for(const{listeners:r}of t.values())n=n.concat(r.map(({listener:e})=>e));return n}async off(e,t){const n=await E$(this,e);if(!n)return this;if(t){const e=n.listeners.map(({listener:e})=>e).indexOf(t);e>=0&&n.listeners.splice(e,1)}return null!=t&&0!==n.listeners.length||(n.stop(),v$(this).subs.delete(n.tag)),this}async removeAllListeners(e){if(e){const t=await E$(this,e);if(!t)return this;t.stop(),v$(this).subs.delete(t.tag)}else{const{subs:e}=v$(this);for(const{tag:t,stop:n}of e.values())n(),e.delete(t)}return this}async addListener(e,t){return await this.on(e,t)}async removeListener(e,t){return await this.off(e,t)}static buildClass(t){return class extends e{constructor(e,n=null){super(e,t,n)}}}static from(e,t,n){return null==n&&(n=null),new this(e,t,n)}};class P$ extends(function(){return I$}()){}class C${constructor(e,t,n){__publicField(this,"interface"),__publicField(this,"bytecode"),__publicField(this,"runner");const r=HM.from(e);t instanceof Uint8Array||("object"==typeof t&&(t=t.object),t.startsWith("0x")||(t="0x"+t)),dS(this,{bytecode:t=CS(TS(t)),interface:r,runner:n||null})}attach(e){return new I$(e,this.interface,this.runner)}async getDeployTransaction(...e){let t={};const n=this.interface.deploy;if(n.inputs.length+1===e.length&&(t=await m$(e.pop())),n.inputs.length!==e.length)throw new Error("incorrect number of arguments to constructor");const r=await y$(this.runner,n.inputs,e),i=NS([this.bytecode,this.interface.encodeDeploy(r)]);return Object.assign({},t,{data:i})}async deploy(...e){const t=await this.getDeployTransaction(...e);gS(this.runner&&"function"==typeof this.runner.sendTransaction,"factory runner does not support sending transactions","UNSUPPORTED_OPERATION",{operation:"sendTransaction"});const n=await this.runner.sendTransaction(t),r=iO(n);return new I$(r,this.interface,this.runner,n)}connect(e){return new C$(this.interface,this.bytecode,e)}static fromSolidity(e,t){bS(null!=e,"bad compiler output","output",e),"string"==typeof e&&(e=JSON.parse(e));const n=e.abi;let r="";return e.bytecode?r=e.bytecode:e.evm&&e.evm.bytecode&&(r=e.evm.bytecode),new this(n,r,t)}}function N$(e){return e.match(/^ipfs:\/\/ipfs\//i)?e=e.substring(12):e.match(/^ipfs:\/\//i)?e=e.substring(7):bS(!1,"unsupported IPFS format","link",e),`https://gateway.ipfs.io/ipfs/${e}`}class O${constructor(e){__publicField(this,"name"),dS(this,{name:e})}connect(e){return this}supportsCoinType(e){return!1}async encodeAddress(e,t){throw new Error("unsupported coin")}async decodeAddress(e,t){throw new Error("unsupported coin")}}const R$=new RegExp("^(ipfs)://(.*)$","i"),B$=[new RegExp("^(https)://(.*)$","i"),new RegExp("^(data):(.*)$","i"),R$,new RegExp("^eip155:[0-9]+/(erc[0-9]+):(.*)$","i")],M$=class e{constructor(e,t,n){__privateAdd(this,We),__publicField(this,"provider"),__publicField(this,"address"),__publicField(this,"name"),__privateAdd(this,Je),__privateAdd(this,Ke),dS(this,{provider:e,address:t,name:n}),__privateSet(this,Je,null),__privateSet(this,Ke,new P$(t,["function supportsInterface(bytes4) view returns (bool)","function resolve(bytes, bytes) view returns (bytes)","function addr(bytes32) view returns (address)","function addr(bytes32, uint) view returns (bytes)","function text(bytes32, string) view returns (string)","function contenthash(bytes32) view returns (bytes)"],e))}async supportsWildcard(){return null==__privateGet(this,Je)&&__privateSet(this,Je,(async()=>{try{return await __privateGet(this,Ke).supportsInterface("0x9061b923")}catch(e){if(pS(e,"CALL_EXCEPTION"))return!1;throw __privateSet(this,Je,null),e}})()),await __privateGet(this,Je)}async getAddress(e){if(null==e&&(e=60),60===e)try{const e=await __privateMethod(this,We,Ye).call(this,"addr(bytes32)");return null==e||e===IN?null:e}catch(i){if(pS(i,"CALL_EXCEPTION"))return null;throw i}if(e>=0&&e<2147483648){let t=e+2147483648;const n=await __privateMethod(this,We,Ye).call(this,"addr(bytes32,uint)",[t]);if(xS(n,20))return nO(n)}let t=null;for(const s of this.provider.plugins)if(s instanceof O$&&s.supportsCoinType(e)){t=s;break}if(null==t)return null;const n=await __privateMethod(this,We,Ye).call(this,"addr(bytes32,uint)",[e]);if(null==n||"0x"===n)return null;const r=await t.decodeAddress(e,n);if(null!=r)return r;gS(!1,"invalid coin data","UNSUPPORTED_OPERATION",{operation:`getAddress(${e})`,info:{coinType:e,data:n}})}async getText(e){const t=await __privateMethod(this,We,Ye).call(this,"text(bytes32,string)",[e]);return null==t||"0x"===t?null:t}async getContentHash(){const e=await __privateMethod(this,We,Ye).call(this,"contenthash(bytes32)");if(null==e||"0x"===e)return null;const t=e.match(/^0x(e3010170|e5010172)(([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f]*))$/);if(t){const e="e3010170"===t[1]?"ipfs":"ipns",n=parseInt(t[4],16);if(t[5].length===2*n)return`${e}://${ix("0x"+t[2])}`}const n=e.match(/^0xe40101fa011b20([0-9a-f]*)$/);if(n&&64===n[1].length)return`bzz://${n[1]}`;gS(!1,"invalid or unsupported content hash data","UNSUPPORTED_OPERATION",{operation:"getContentHash()",info:{data:e}})}async getAvatar(){return(await this._getAvatar()).url}async _getAvatar(){const e=[{type:"name",value:this.name}];try{const r=await this.getText("avatar");if(null==r)return e.push({type:"!avatar",value:""}),{url:null,linkage:e};e.push({type:"avatar",value:r});for(let i=0;i<B$.length;i++){const s=r.match(B$[i]);if(null==s)continue;const a=s[1].toLowerCase();switch(a){case"https":case"data":return e.push({type:"url",value:r}),{linkage:e,url:r};case"ipfs":{const t=N$(r);return e.push({type:"ipfs",value:r}),e.push({type:"url",value:t}),{linkage:e,url:t}}case"erc721":case"erc1155":{const i="erc721"===a?"tokenURI(uint256)":"uri(uint256)";e.push({type:a,value:r});const o=await this.getAddress();if(null==o)return e.push({type:"!owner",value:""}),{url:null,linkage:e};const c=(s[2]||"").split("/");if(2!==c.length)return e.push({type:`!${a}caip`,value:s[2]||""}),{url:null,linkage:e};const A=c[1],l=new P$(c[0],["function tokenURI(uint) view returns (string)","function ownerOf(uint) view returns (address)","function uri(uint) view returns (string)","function balanceOf(address, uint256) view returns (uint)"],this.provider);if("erc721"===a){const t=await l.ownerOf(A);if(o!==t)return e.push({type:"!owner",value:t}),{url:null,linkage:e};e.push({type:"owner",value:t})}else if("erc1155"===a){const t=await l.balanceOf(o,A);if(!t)return e.push({type:"!balance",value:"0"}),{url:null,linkage:e};e.push({type:"balance",value:t.toString()})}let f=await l[i](A);if(null==f||"0x"===f)return e.push({type:"!metadata-url",value:""}),{url:null,linkage:e};e.push({type:"metadata-url-base",value:f}),"erc1155"===a&&(f=f.replace("{id}",WS(A,32).substring(2)),e.push({type:"metadata-url-expanded",value:f})),f.match(/^ipfs:/i)&&(f=N$(f)),e.push({type:"metadata-url",value:f});let u={};const d=await new xx(f).send();d.assertOk();try{u=d.bodyJson}catch(t){try{e.push({type:"!metadata",value:d.bodyText})}catch(n){const t=d.body;return t&&e.push({type:"!metadata",value:CS(t)}),{url:null,linkage:e}}return{url:null,linkage:e}}if(!u)return e.push({type:"!metadata",value:""}),{url:null,linkage:e};e.push({type:"metadata",value:JSON.stringify(u)});let h=u.image;if("string"!=typeof h)return e.push({type:"!imageUrl",value:""}),{url:null,linkage:e};if(h.match(/^(https:\/\/|data:)/i));else{if(null==h.match(R$))return e.push({type:"!imageUrl-ipfs",value:h}),{url:null,linkage:e};e.push({type:"imageUrl-ipfs",value:h}),h=N$(h)}return e.push({type:"url",value:h}),{linkage:e,url:h}}}}}catch(t){}return{linkage:e,url:null}}static async getEnsAddress(e){const t=await e.getNetwork(),n=t.getPlugin("org.ethers.plugins.network.Ens");return gS(n,"network does not support ENS","UNSUPPORTED_OPERATION",{operation:"getEnsAddress",info:{network:t}}),n.address}static async fromName(t,n){var r;let i=n;for(;;){if(""===i||"."===i)return null;if("eth"!==n&&"eth"===i)return null;const s=await __privateMethod(r=e,Ze,Xe).call(r,t,i);if(null!=s){const r=new e(t,s,n);return i===n||await r.supportsWildcard()?r:null}i=i.split(".").slice(1).join(".")}}};Je=new WeakMap,Ke=new WeakMap,We=new WeakSet,Ye=async function(e,t){t=(t||[]).slice();const n=__privateGet(this,Ke).interface;t.unshift(lB(this.name));let r=null;await this.supportsWildcard()&&(r=n.getFunction(e),gS(r,"missing fragment","UNKNOWN_ERROR",{info:{funcName:e}}),t=[fB(this.name,255),n.encodeFunctionData(r,t)],e="resolve(bytes,bytes)"),t.push({enableCcipRead:!0});try{const i=await __privateGet(this,Ke)[e](...t);return r?n.decodeFunctionResult(r,i)[0]:i}catch(i){if(!pS(i,"CALL_EXCEPTION"))throw i}return null},Ze=new WeakSet,Xe=async function(e,t){const n=await M$.getEnsAddress(e);try{const r=new P$(n,["function resolver(bytes32) view returns (address)"],e),i=await r.resolver(lB(t),{enableCcipRead:!0});return i===IN?null:i}catch(r){throw r}return null},__privateAdd(M$,Ze);let $$=M$;const D$=BigInt(0);function F$(e,t){return function(n){return null==n?t:e(n)}}function G$(e,t){return n=>{if(t&&null==n)return null;if(!Array.isArray(n))throw new Error("not an array");return n.map(t=>e(t))}}function U$(e,t){return n=>{const r={};for(const s in e){let a=s;if(t&&s in t&&!(a in n))for(const e of t[s])if(e in n){a=e;break}try{const t=e[s](n[a]);void 0!==t&&(r[s]=t)}catch(i){gS(!1,`invalid value for value.${s} (${i instanceof Error?i.message:"not-an-error"})`,"BAD_DATA",{value:n})}}return r}}function L$(e){return bS(xS(e,!0),"invalid data","value",e),e}function j$(e){return bS(xS(e,32),"invalid hash","value",e),e}const H$=U$({address:nO,blockHash:j$,blockNumber:JS,data:L$,index:JS,removed:F$(function(e){switch(e){case!0:case"true":return!0;case!1:case"false":return!1}bS(!1,`invalid boolean; ${JSON.stringify(e)}`,"value",e)},!1),topics:G$(j$),transactionHash:j$,transactionIndex:JS},{index:["logIndex"]}),z$=U$({hash:F$(j$),parentHash:j$,parentBeaconBlockRoot:F$(j$,null),number:JS,timestamp:JS,nonce:F$(L$),difficulty:zS,gasLimit:zS,gasUsed:zS,stateRoot:F$(j$,null),receiptsRoot:F$(j$,null),blobGasUsed:F$(zS,null),excessBlobGas:F$(zS,null),miner:F$(nO),prevRandao:F$(j$,null),extraData:L$,baseFeePerGas:F$(zS)},{prevRandao:["mixHash"]}),q$=U$({transactionIndex:JS,blockNumber:JS,transactionHash:j$,address:nO,topics:G$(j$),data:L$,index:JS,blockHash:j$},{index:["logIndex"]}),Q$=U$({to:F$(nO,null),from:F$(nO,null),contractAddress:F$(nO,null),index:JS,root:F$(CS),gasUsed:zS,blobGasUsed:F$(zS,null),logsBloom:F$(L$),blockHash:j$,hash:j$,logs:G$(function(e){return q$(e)}),blockNumber:JS,cumulativeGasUsed:zS,effectiveGasPrice:F$(zS),blobGasPrice:F$(zS,null),status:F$(JS),type:F$(JS,0)},{effectiveGasPrice:["gasPrice"],hash:["transactionHash"],index:["transactionIndex"]});function V$(e){e.to&&zS(e.to)===D$&&(e.to="0x0000000000000000000000000000000000000000");const t=U$({hash:j$,index:F$(JS,void 0),type:e=>"0x"===e||null==e?0:JS(e),accessList:F$(RO,null),blobVersionedHashes:F$(G$(j$,!0),null),authorizationList:F$(G$(e=>{let t;if(e.signature)t=e.signature;else{let n=e.yParity;"0x1b"===n?n=0:"0x1c"===n&&(n=1),t=Object.assign({},e,{yParity:n})}return{address:nO(e.address),chainId:zS(e.chainId),nonce:zS(e.nonce),signature:VN.from(t)}},!1),null),blockHash:F$(j$,null),blockNumber:F$(JS,null),transactionIndex:F$(JS,null),from:nO,gasPrice:F$(zS),maxPriorityFeePerGas:F$(zS),maxFeePerGas:F$(zS),maxFeePerBlobGas:F$(zS,null),gasLimit:zS,to:F$(nO,null),value:zS,nonce:JS,data:L$,creates:F$(nO,null),chainId:F$(zS,null)},{data:["input"],gasLimit:["gas"],index:["transactionIndex"]})(e);if(null==t.to&&null==t.creates&&(t.creates=iO(t)),1!==e.type&&2!==e.type||null!=e.accessList||(t.accessList=[]),e.signature?t.signature=VN.from(e.signature):t.signature=VN.from(e),null==t.chainId){const e=t.signature.legacyChainId;null!=e&&(t.chainId=e)}return t.blockHash&&zS(t.blockHash)===D$&&(t.blockHash=null),t}class J${constructor(e){__publicField(this,"name"),dS(this,{name:e})}clone(){return new J$(this.name)}}class K$ extends J${constructor(e,t){null==e&&(e=0),super(`org.ethers.network.plugins.GasCost#${e||0}`),__publicField(this,"effectiveBlock"),__publicField(this,"txBase"),__publicField(this,"txCreate"),__publicField(this,"txDataZero"),__publicField(this,"txDataNonzero"),__publicField(this,"txAccessListStorageKey"),__publicField(this,"txAccessListAddress");const n={effectiveBlock:e};function r(e,r){let i=(t||{})[e];null==i&&(i=r),bS("number"==typeof i,`invalud value for ${e}`,"costs",t),n[e]=i}r("txBase",21e3),r("txCreate",32e3),r("txDataZero",4),r("txDataNonzero",16),r("txAccessListStorageKey",1900),r("txAccessListAddress",2400),dS(this,n)}clone(){return new K$(this.effectiveBlock,this)}}class W$ extends J${constructor(e,t){super("org.ethers.plugins.network.Ens"),__publicField(this,"address"),__publicField(this,"targetNetwork"),dS(this,{address:e||"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",targetNetwork:null==t?1:t})}clone(){return new W$(this.address,this.targetNetwork)}}et=new WeakMap;let Y$=class e extends J${constructor(e){super("org.ethers.plugins.network.FeeData"),__privateAdd(this,et),__privateSet(this,et,e)}get feeDataFunc(){return __privateGet(this,et)}async getFeeData(e){return await __privateGet(this,et).call(this,e)}clone(){return new e(__privateGet(this,et))}};class Z$ extends J${constructor(e,t){super("org.ethers.plugins.network.FetchUrlFeeDataPlugin"),__privateAdd(this,tt),__privateAdd(this,nt),__privateSet(this,tt,e),__privateSet(this,nt,t)}get url(){return __privateGet(this,tt)}get processFunc(){return __privateGet(this,nt)}clone(){return this}}tt=new WeakMap,nt=new WeakMap;const X$=new Map;rt=new WeakMap,it=new WeakMap,st=new WeakMap;let eD=class e{constructor(e,t){__privateAdd(this,rt),__privateAdd(this,it),__privateAdd(this,st),__privateSet(this,rt,e),__privateSet(this,it,zS(t)),__privateSet(this,st,new Map)}toJSON(){return{name:this.name,chainId:String(this.chainId)}}get name(){return __privateGet(this,rt)}set name(e){__privateSet(this,rt,e)}get chainId(){return __privateGet(this,it)}set chainId(e){__privateSet(this,it,zS(e,"chainId"))}matches(e){if(null==e)return!1;if("string"==typeof e){try{return this.chainId===zS(e)}catch(t){}return this.name===e}if("number"==typeof e||"bigint"==typeof e){try{return this.chainId===zS(e)}catch(t){}return!1}if("object"==typeof e){if(null!=e.chainId){try{return this.chainId===zS(e.chainId)}catch(t){}return!1}return null!=e.name&&this.name===e.name}return!1}get plugins(){return Array.from(__privateGet(this,st).values())}attachPlugin(e){if(__privateGet(this,st).get(e.name))throw new Error(`cannot replace existing plugin: ${e.name} `);return __privateGet(this,st).set(e.name,e.clone()),this}getPlugin(e){return __privateGet(this,st).get(e)||null}getPlugins(e){return this.plugins.filter(t=>t.name.split("#")[0]===e)}clone(){const t=new e(this.name,this.chainId);return this.plugins.forEach(e=>{t.attachPlugin(e.clone())}),t}computeIntrinsicGas(e){const t=this.getPlugin("org.ethers.plugins.network.GasCost")||new K$;let n=t.txBase;if(null==e.to&&(n+=t.txCreate),e.data)for(let r=2;r<e.data.length;r+=2)"00"===e.data.substring(r,r+2)?n+=t.txDataZero:n+=t.txDataNonzero;if(e.accessList){const r=RO(e.accessList);for(const e in r)n+=t.txAccessListAddress+t.txAccessListStorageKey*r[e].storageKeys.length}return n}static from(t){if(function(){function e(e,t,n){const r=function(){const r=new eD(e,t);return null!=n.ensNetwork&&r.attachPlugin(new W$(null,n.ensNetwork)),r.attachPlugin(new K$),(n.plugins||[]).forEach(e=>{r.attachPlugin(e)}),r};eD.register(e,r),eD.register(t,r),n.altNames&&n.altNames.forEach(e=>{eD.register(e,r)})}rD||(rD=!0,e("mainnet",1,{ensNetwork:1,altNames:["homestead"]}),e("ropsten",3,{ensNetwork:3}),e("rinkeby",4,{ensNetwork:4}),e("goerli",5,{ensNetwork:5}),e("kovan",42,{ensNetwork:42}),e("sepolia",11155111,{ensNetwork:11155111}),e("holesky",17e3,{ensNetwork:17e3}),e("classic",61,{}),e("classicKotti",6,{}),e("arbitrum",42161,{ensNetwork:1}),e("arbitrum-goerli",421613,{}),e("arbitrum-sepolia",421614,{}),e("base",8453,{ensNetwork:1}),e("base-goerli",84531,{}),e("base-sepolia",84532,{}),e("bnb",56,{ensNetwork:1}),e("bnbt",97,{}),e("filecoin",314,{}),e("filecoin-calibration",314159,{}),e("linea",59144,{ensNetwork:1}),e("linea-goerli",59140,{}),e("linea-sepolia",59141,{}),e("matic",137,{ensNetwork:1,plugins:[nD("https://gasstation.polygon.technology/v2")]}),e("matic-amoy",80002,{}),e("matic-mumbai",80001,{altNames:["maticMumbai","maticmum"],plugins:[nD("https://gasstation-testnet.polygon.technology/v2")]}),e("optimism",10,{ensNetwork:1,plugins:[]}),e("optimism-goerli",420,{}),e("optimism-sepolia",11155420,{}),e("xdai",100,{ensNetwork:1}))}(),null==t)return e.from("mainnet");if("number"==typeof t&&(t=BigInt(t)),"string"==typeof t||"bigint"==typeof t){const n=X$.get(t);if(n)return n();if("bigint"==typeof t)return new e("unknown",t);bS(!1,"unknown network","network",t)}if("function"==typeof t.clone)return t.clone();if("object"==typeof t){bS("string"==typeof t.name&&"number"==typeof t.chainId,"invalid network object name or chainId","network",t);const n=new e(t.name,t.chainId);return(t.ensAddress||null!=t.ensNetwork)&&n.attachPlugin(new W$(t.ensAddress,t.ensNetwork)),n}bS(!1,"invalid network","network",t)}static register(e,t){"number"==typeof e&&(e=BigInt(e));const n=X$.get(e);n&&bS(!1,`conflicting network for ${JSON.stringify(n.name)}`,"nameOrChainId",e),X$.set(e,t)}};function tD(e,t){const n=String(e);if(!n.match(/^[0-9.]+$/))throw new Error(`invalid gwei value: ${e}`);const r=n.split(".");if(1===r.length&&r.push(""),2!==r.length)throw new Error(`invalid gwei value: ${e}`);for(;r[1].length<t;)r[1]+="0";if(r[1].length>9){let e=BigInt(r[1].substring(0,9));r[1].substring(9).match(/^0+$/)||e++,r[1]=e.toString()}return BigInt(r[0]+r[1])}function nD(e){return new Z$(e,async(e,t,n)=>{let r;n.setHeader("User-Agent","ethers");try{const[t,i]=await Promise.all([n.send(),e()]);r=t;const s=r.bodyJson.standard;return{gasPrice:i.gasPrice,maxFeePerGas:tD(s.maxFee,9),maxPriorityFeePerGas:tD(s.maxPriorityFee,9)}}catch(i){gS(!1,`error encountered with polygon gas station (${JSON.stringify(n.url)})`,"SERVER_ERROR",{request:n,response:r,error:i})}})}let rD=!1;function iD(e){return JSON.parse(JSON.stringify(e))}class sD{constructor(e){__privateAdd(this,lt),__privateAdd(this,at),__privateAdd(this,ot),__privateAdd(this,ct),__privateAdd(this,At),__privateSet(this,at,e),__privateSet(this,ot,null),__privateSet(this,ct,4e3),__privateSet(this,At,-2)}get pollingInterval(){return __privateGet(this,ct)}set pollingInterval(e){__privateSet(this,ct,e)}start(){__privateGet(this,ot)||(__privateSet(this,ot,__privateGet(this,at)._setTimeout(__privateMethod(this,lt,ft).bind(this),__privateGet(this,ct))),__privateMethod(this,lt,ft).call(this))}stop(){__privateGet(this,ot)&&(__privateGet(this,at)._clearTimeout(__privateGet(this,ot)),__privateSet(this,ot,null))}pause(e){this.stop(),e&&__privateSet(this,At,-2)}resume(){this.start()}}at=new WeakMap,ot=new WeakMap,ct=new WeakMap,At=new WeakMap,lt=new WeakSet,ft=async function(){try{const e=await __privateGet(this,at).getBlockNumber();if(-2===__privateGet(this,At))return void __privateSet(this,At,e);if(e!==__privateGet(this,At)){for(let t=__privateGet(this,At)+1;t<=e;t++){if(null==__privateGet(this,ot))return;await __privateGet(this,at).emit("block",t)}__privateSet(this,At,e)}}catch(e){}null!=__privateGet(this,ot)&&__privateSet(this,ot,__privateGet(this,at)._setTimeout(__privateMethod(this,lt,ft).bind(this),__privateGet(this,ct)))};class aD{constructor(e){__privateAdd(this,ut),__privateAdd(this,dt),__privateAdd(this,ht),__privateSet(this,ut,e),__privateSet(this,ht,!1),__privateSet(this,dt,e=>{this._poll(e,__privateGet(this,ut))})}async _poll(e,t){throw new Error("sub-classes must override this")}start(){__privateGet(this,ht)||(__privateSet(this,ht,!0),__privateGet(this,dt).call(this,-2),__privateGet(this,ut).on("block",__privateGet(this,dt)))}stop(){__privateGet(this,ht)&&(__privateSet(this,ht,!1),__privateGet(this,ut).off("block",__privateGet(this,dt)))}pause(e){this.stop()}resume(){this.start()}}ut=new WeakMap,dt=new WeakMap,ht=new WeakMap;class oD extends aD{constructor(e,t){super(e),__privateAdd(this,pt),__privateAdd(this,mt),__privateSet(this,pt,t),__privateSet(this,mt,-2)}pause(e){e&&__privateSet(this,mt,-2),super.pause(e)}async _poll(e,t){const n=await t.getBlock(__privateGet(this,pt));null!=n&&(-2===__privateGet(this,mt)?__privateSet(this,mt,n.number):n.number>__privateGet(this,mt)&&(t.emit(__privateGet(this,pt),n.number),__privateSet(this,mt,n.number)))}}pt=new WeakMap,mt=new WeakMap;class cD extends aD{constructor(e,t){super(e),__privateAdd(this,yt),__privateSet(this,yt,iD(t))}async _poll(e,t){throw new Error("@TODO")}}yt=new WeakMap;class AD extends aD{constructor(e,t){super(e),__privateAdd(this,gt),__privateSet(this,gt,t)}async _poll(e,t){const n=await t.getTransactionReceipt(__privateGet(this,gt));n&&t.emit(__privateGet(this,gt),n)}}gt=new WeakMap;class lD{constructor(e,t){__privateAdd(this,kt),__privateAdd(this,bt),__privateAdd(this,wt),__privateAdd(this,vt),__privateAdd(this,_t),__privateAdd(this,Et),__privateSet(this,bt,e),__privateSet(this,wt,iD(t)),__privateSet(this,vt,__privateMethod(this,kt,Tt).bind(this)),__privateSet(this,_t,!1),__privateSet(this,Et,-2)}start(){__privateGet(this,_t)||(__privateSet(this,_t,!0),-2===__privateGet(this,Et)&&__privateGet(this,bt).getBlockNumber().then(e=>{__privateSet(this,Et,e)}),__privateGet(this,bt).on("block",__privateGet(this,vt)))}stop(){__privateGet(this,_t)&&(__privateSet(this,_t,!1),__privateGet(this,bt).off("block",__privateGet(this,vt)))}pause(e){this.stop(),e&&__privateSet(this,Et,-2)}resume(){this.start()}}bt=new WeakMap,wt=new WeakMap,vt=new WeakMap,_t=new WeakMap,Et=new WeakMap,kt=new WeakSet,Tt=async function(e){if(-2===__privateGet(this,Et))return;const t=iD(__privateGet(this,wt));t.fromBlock=__privateGet(this,Et)+1,t.toBlock=e;const n=await __privateGet(this,bt).getLogs(t);if(0!==n.length)for(const r of n)__privateGet(this,bt).emit(__privateGet(this,wt),r),__privateSet(this,Et,r.blockNumber);else __privateGet(this,Et)<e-60&&__privateSet(this,Et,e-60)};const fD=BigInt(2);function uD(e){return e&&"function"==typeof e.then}function dD(e,t){return e+":"+JSON.stringify(t,(e,t)=>{if(null==t)return"null";if("bigint"==typeof t)return`bigint:${t.toString()}`;if("string"==typeof t)return t.toLowerCase();if("object"==typeof t&&!Array.isArray(t)){const e=Object.keys(t);return e.sort(),e.reduce((e,n)=>(e[n]=t[n],e),{})}return t})}class hD{constructor(e){__publicField(this,"name"),dS(this,{name:e})}start(){}stop(){}pause(e){}resume(){}}function pD(e){return(e=Array.from(new Set(e).values())).sort(),e}async function mD(e,t){if(null==e)throw new Error("invalid event");if(Array.isArray(e)&&(e={topics:e}),"string"==typeof e)switch(e){case"block":case"debug":case"error":case"finalized":case"network":case"pending":case"safe":return{type:e,tag:e}}if(xS(e,32)){const t=e.toLowerCase();return{type:"transaction",tag:dD("tx",{hash:t}),hash:t}}if(e.orphan){const t=e;return{type:"orphan",tag:dD("orphan",t),filter:(n=t,JSON.parse(JSON.stringify(n)))}}var n;if(e.address||e.topics){const n=e,r={topics:(n.topics||[]).map(e=>null==e?null:Array.isArray(e)?pD(e.map(e=>e.toLowerCase())):e.toLowerCase())};if(n.address){const e=[],i=[],s=n=>{xS(n)?e.push(n):i.push((async()=>{e.push(await AO(n,t))})())};Array.isArray(n.address)?n.address.forEach(s):s(n.address),i.length&&await Promise.all(i),r.address=pD(e.map(e=>e.toLowerCase()))}return{filter:r,tag:dD("event",r),type:"event"}}bS(!1,"unknown ProviderEvent","event",e)}function yD(){return(new Date).getTime()}const gD={cacheTimeout:250,pollingInterval:4e3};class bD{constructor(e,t){if(__privateAdd(this,Ft),__privateAdd(this,St),__privateAdd(this,xt),__privateAdd(this,It),__privateAdd(this,Pt),__privateAdd(this,Ct),__privateAdd(this,Nt),__privateAdd(this,Ot),__privateAdd(this,Rt),__privateAdd(this,Bt),__privateAdd(this,Mt),__privateAdd(this,$t),__privateAdd(this,Dt),__privateSet(this,Dt,Object.assign({},gD,t||{})),"any"===e)__privateSet(this,Nt,!0),__privateSet(this,Ct,null);else if(e){const t=eD.from(e);__privateSet(this,Nt,!1),__privateSet(this,Ct,Promise.resolve(t)),setTimeout(()=>{this.emit("network",t,null)},0)}else __privateSet(this,Nt,!1),__privateSet(this,Ct,null);__privateSet(this,Rt,-1),__privateSet(this,Ot,new Map),__privateSet(this,St,new Map),__privateSet(this,xt,new Map),__privateSet(this,It,null),__privateSet(this,Pt,!1),__privateSet(this,Bt,1),__privateSet(this,Mt,new Map),__privateSet(this,$t,!1)}get pollingInterval(){return __privateGet(this,Dt).pollingInterval}get provider(){return this}get plugins(){return Array.from(__privateGet(this,xt).values())}attachPlugin(e){if(__privateGet(this,xt).get(e.name))throw new Error(`cannot replace existing plugin: ${e.name} `);return __privateGet(this,xt).set(e.name,e.connect(this)),this}getPlugin(e){return __privateGet(this,xt).get(e)||null}get disableCcipRead(){return __privateGet(this,$t)}set disableCcipRead(e){__privateSet(this,$t,!!e)}async ccipReadFetch(e,t,n){if(this.disableCcipRead||0===n.length||null==e.to)return null;const r=e.to.toLowerCase(),i=t.toLowerCase(),s=[];for(let o=0;o<n.length;o++){const t=n[o],c=t.replace("{sender}",r).replace("{data}",i),A=new xx(c);-1===t.indexOf("{data}")&&(A.body={data:i,sender:r}),this.emit("debug",{action:"sendCcipReadFetchRequest",request:A,index:o,urls:n});let l,f="unknown error";try{l=await A.send()}catch(a){s.push(a.message),this.emit("debug",{action:"receiveCcipReadFetchError",request:A,result:{error:a}});continue}try{const e=l.bodyJson;if(e.data)return this.emit("debug",{action:"receiveCcipReadFetchResult",request:A,result:e}),e.data;e.message&&(f=e.message),this.emit("debug",{action:"receiveCcipReadFetchError",request:A,result:e})}catch(a){}gS(l.statusCode<400||l.statusCode>=500,`response not found during CCIP fetch: ${f}`,"OFFCHAIN_FAULT",{reason:"404_MISSING_RESOURCE",transaction:e,info:{url:t,errorMessage:f}}),s.push(f)}gS(!1,`error encountered during CCIP fetch: ${s.map(e=>JSON.stringify(e)).join(", ")}`,"OFFCHAIN_FAULT",{reason:"500_SERVER_ERROR",transaction:e,info:{urls:n,errorMessages:s}})}_wrapBlock(e,t){return new KM(function(e){const t=z$(e);return t.transactions=e.transactions.map(e=>"string"==typeof e?e:V$(e)),t}(e),this)}_wrapLog(e,t){return new WM(function(e){return H$(e)}(e),this)}_wrapTransactionReceipt(e,t){return new YM(function(e){return Q$(e)}(e),this)}_wrapTransactionResponse(e,t){return new ZM(V$(e),this)}_detectNetwork(){gS(!1,"sub-classes must implement this","UNSUPPORTED_OPERATION",{operation:"_detectNetwork"})}async _perform(e){gS(!1,`unsupported method: ${e.method}`,"UNSUPPORTED_OPERATION",{operation:e.method,info:e})}async getBlockNumber(){const e=JS(await __privateMethod(this,Ft,Gt).call(this,{method:"getBlockNumber"}),"%response");return __privateGet(this,Rt)>=0&&__privateSet(this,Rt,e),e}_getAddress(e){return AO(e,this)}_getBlockTag(e){if(null==e)return"latest";switch(e){case"earliest":return"0x0";case"finalized":case"latest":case"pending":case"safe":return e}return xS(e)?xS(e,32)?e:ZS(e):("bigint"==typeof e&&(e=JS(e,"blockTag")),"number"==typeof e?e>=0?ZS(e):__privateGet(this,Rt)>=0?ZS(__privateGet(this,Rt)+e):this.getBlockNumber().then(t=>ZS(t+e)):void bS(!1,"invalid blockTag","blockTag",e))}_getFilter(e){const t=(e.topics||[]).map(e=>null==e?null:Array.isArray(e)?pD(e.map(e=>e.toLowerCase())):e.toLowerCase()),n="blockHash"in e?e.blockHash:void 0,r=(e,r,i)=>{let s;switch(e.length){case 0:break;case 1:s=e[0];break;default:e.sort(),s=e}if(n&&(null!=r||null!=i))throw new Error("invalid filter");const a={};return s&&(a.address=s),t.length&&(a.topics=t),r&&(a.fromBlock=r),i&&(a.toBlock=i),n&&(a.blockHash=n),a};let i,s,a=[];if(e.address)if(Array.isArray(e.address))for(const o of e.address)a.push(this._getAddress(o));else a.push(this._getAddress(e.address));return"fromBlock"in e&&(i=this._getBlockTag(e.fromBlock)),"toBlock"in e&&(s=this._getBlockTag(e.toBlock)),a.filter(e=>"string"!=typeof e).length||null!=i&&"string"!=typeof i||null!=s&&"string"!=typeof s?Promise.all([Promise.all(a),i,s]).then(e=>r(e[0],e[1],e[2])):r(a,i,s)}_getTransactionRequest(e){const t=JM(e),n=[];if(["to","from"].forEach(e=>{if(null==t[e])return;const r=AO(t[e],this);uD(r)?n.push(async function(){t[e]=await r}()):t[e]=r}),null!=t.blockTag){const e=this._getBlockTag(t.blockTag);uD(e)?n.push(async function(){t.blockTag=await e}()):t.blockTag=e}return n.length?async function(){return await Promise.all(n),t}():t}async getNetwork(){if(null==__privateGet(this,Ct)){const e=(async()=>{try{const e=await this._detectNetwork();return this.emit("network",e,null),e}catch(t){throw __privateGet(this,Ct)===e&&__privateSet(this,Ct,null),t}})();return __privateSet(this,Ct,e),(await e).clone()}const e=__privateGet(this,Ct),[t,n]=await Promise.all([e,this._detectNetwork()]);return t.chainId!==n.chainId&&(__privateGet(this,Nt)?(this.emit("network",n,t),__privateGet(this,Ct)===e&&__privateSet(this,Ct,Promise.resolve(n))):gS(!1,`network changed: ${t.chainId} => ${n.chainId} `,"NETWORK_ERROR",{event:"changed"})),t.clone()}async getFeeData(){const e=await this.getNetwork(),t=async()=>{const{_block:t,gasPrice:n,priorityFee:r}=await uS({_block:__privateMethod(this,Ft,Ht).call(this,"latest",!1),gasPrice:(async()=>{try{return zS(await __privateMethod(this,Ft,Gt).call(this,{method:"getGasPrice"}),"%response")}catch(e){}return null})(),priorityFee:(async()=>{try{return zS(await __privateMethod(this,Ft,Gt).call(this,{method:"getPriorityFee"}),"%response")}catch(e){}return null})()});let i=null,s=null;const a=this._wrapBlock(t,e);return a&&a.baseFeePerGas&&(s=null!=r?r:BigInt("1000000000"),i=a.baseFeePerGas*fD+s),new VM(n,i,s)},n=e.getPlugin("org.ethers.plugins.network.FetchUrlFeeDataPlugin");if(n){const e=new xx(n.url),r=await n.processFunc(t,this,e);return new VM(r.gasPrice,r.maxFeePerGas,r.maxPriorityFeePerGas)}return await t()}async estimateGas(e){let t=this._getTransactionRequest(e);return uD(t)&&(t=await t),zS(await __privateMethod(this,Ft,Gt).call(this,{method:"estimateGas",transaction:t}),"%response")}async call(e){const{tx:t,blockTag:n}=await uS({tx:this._getTransactionRequest(e),blockTag:this._getBlockTag(e.blockTag)});return await __privateMethod(this,Ft,Lt).call(this,__privateMethod(this,Ft,Ut).call(this,t,n,e.enableCcipRead?0:-1))}async getBalance(e,t){return zS(await __privateMethod(this,Ft,jt).call(this,{method:"getBalance"},e,t),"%response")}async getTransactionCount(e,t){return JS(await __privateMethod(this,Ft,jt).call(this,{method:"getTransactionCount"},e,t),"%response")}async getCode(e,t){return CS(await __privateMethod(this,Ft,jt).call(this,{method:"getCode"},e,t))}async getStorage(e,t,n){const r=zS(t,"position");return CS(await __privateMethod(this,Ft,jt).call(this,{method:"getStorage",position:r},e,n))}async broadcastTransaction(e){const{blockNumber:t,hash:n,network:r}=await uS({blockNumber:this.getBlockNumber(),hash:this._perform({method:"broadcastTransaction",signedTransaction:e}),network:this.getNetwork()}),i=nR.from(e);if(i.hash!==n)throw new Error("@TODO: the returned hash did not match");return this._wrapTransactionResponse(i,r).replaceableTransaction(t)}async getBlock(e,t){const{network:n,params:r}=await uS({network:this.getNetwork(),params:__privateMethod(this,Ft,Ht).call(this,e,!!t)});return null==r?null:this._wrapBlock(r,n)}async getTransaction(e){const{network:t,params:n}=await uS({network:this.getNetwork(),params:__privateMethod(this,Ft,Gt).call(this,{method:"getTransaction",hash:e})});return null==n?null:this._wrapTransactionResponse(n,t)}async getTransactionReceipt(e){const{network:t,params:n}=await uS({network:this.getNetwork(),params:__privateMethod(this,Ft,Gt).call(this,{method:"getTransactionReceipt",hash:e})});if(null==n)return null;if(null==n.gasPrice&&null==n.effectiveGasPrice){const t=await __privateMethod(this,Ft,Gt).call(this,{method:"getTransaction",hash:e});if(null==t)throw new Error("report this; could not find tx or effectiveGasPrice");n.effectiveGasPrice=t.gasPrice}return this._wrapTransactionReceipt(n,t)}async getTransactionResult(e){const{result:t}=await uS({network:this.getNetwork(),result:__privateMethod(this,Ft,Gt).call(this,{method:"getTransactionResult",hash:e})});return null==t?null:CS(t)}async getLogs(e){let t=this._getFilter(e);uD(t)&&(t=await t);const{network:n,params:r}=await uS({network:this.getNetwork(),params:__privateMethod(this,Ft,Gt).call(this,{method:"getLogs",filter:t})});return r.map(e=>this._wrapLog(e,n))}_getProvider(e){gS(!1,"provider cannot connect to target network","UNSUPPORTED_OPERATION",{operation:"_getProvider()"})}async getResolver(e){return await $$.fromName(this,e)}async getAvatar(e){const t=await this.getResolver(e);return t?await t.getAvatar():null}async resolveName(e){const t=await this.getResolver(e);return t?await t.getAddress():null}async lookupAddress(e){const t=lB((e=nO(e)).substring(2).toLowerCase()+".addr.reverse");try{const n=await $$.getEnsAddress(this),r=new P$(n,["function resolver(bytes32) view returns (address)"],this),i=await r.resolver(t);if(null==i||i===IN)return null;const s=new P$(i,["function name(bytes32) view returns (string)"],this),a=await s.name(t);return await this.resolveName(a)!==e?null:a}catch(n){if(pS(n,"BAD_DATA")&&"0x"===n.value)return null;if(pS(n,"CALL_EXCEPTION"))return null;throw n}return null}async waitForTransaction(e,t,n){const r=null!=t?t:1;return 0===r?this.getTransactionReceipt(e):new Promise(async(t,i)=>{let s=null;const a=async n=>{try{const i=await this.getTransactionReceipt(e);if(null!=i&&n-i.blockNumber+1>=r)return t(i),void(s&&(clearTimeout(s),s=null))}catch(i){console.log("EEE",i)}this.once("block",a)};null!=n&&(s=setTimeout(()=>{null!=s&&(s=null,this.off("block",a),i(yS("timeout","TIMEOUT",{reason:"timeout"})))},n)),a(await this.getBlockNumber())})}async waitForBlock(e){gS(!1,"not implemented yet","NOT_IMPLEMENTED",{operation:"waitForBlock"})}_clearTimeout(e){const t=__privateGet(this,Mt).get(e);t&&(t.timer&&clearTimeout(t.timer),__privateGet(this,Mt).delete(e))}_setTimeout(e,t){null==t&&(t=0);const n=__privateWrapper(this,Bt)._++,r=()=>{__privateGet(this,Mt).delete(n),e()};if(this.paused)__privateGet(this,Mt).set(n,{timer:null,func:r,time:t});else{const e=setTimeout(r,t);__privateGet(this,Mt).set(n,{timer:e,func:r,time:yD()})}return n}_forEachSubscriber(e){for(const t of __privateGet(this,St).values())e(t.subscriber)}_getSubscriber(e){switch(e.type){case"debug":case"error":case"network":return new hD(e.type);case"block":{const e=new sD(this);return e.pollingInterval=this.pollingInterval,e}case"safe":case"finalized":return new oD(this,e.type);case"event":return new lD(this,e.filter);case"transaction":return new AD(this,e.hash);case"orphan":return new cD(this,e.filter)}throw new Error(`unsupported event: ${e.type}`)}_recoverSubscriber(e,t){for(const n of __privateGet(this,St).values())if(n.subscriber===e){n.started&&n.subscriber.stop(),n.subscriber=t,n.started&&t.start(),null!=__privateGet(this,It)&&t.pause(__privateGet(this,It));break}}async on(e,t){const n=await __privateMethod(this,Ft,qt).call(this,e);return n.listeners.push({listener:t,once:!1}),n.started||(n.subscriber.start(),n.started=!0,null!=__privateGet(this,It)&&n.subscriber.pause(__privateGet(this,It))),this}async once(e,t){const n=await __privateMethod(this,Ft,qt).call(this,e);return n.listeners.push({listener:t,once:!0}),n.started||(n.subscriber.start(),n.started=!0,null!=__privateGet(this,It)&&n.subscriber.pause(__privateGet(this,It))),this}async emit(e,...t){const n=await __privateMethod(this,Ft,zt).call(this,e,t);if(!n||0===n.listeners.length)return!1;const r=n.listeners.length;return n.listeners=n.listeners.filter(({listener:n,once:r})=>{const i=new cx(this,r?null:n,e);try{n.call(this,...t,i)}catch(s){}return!r}),0===n.listeners.length&&(n.started&&n.subscriber.stop(),__privateGet(this,St).delete(n.tag)),r>0}async listenerCount(e){if(e){const t=await __privateMethod(this,Ft,zt).call(this,e);return t?t.listeners.length:0}let t=0;for(const{listeners:n}of __privateGet(this,St).values())t+=n.length;return t}async listeners(e){if(e){const t=await __privateMethod(this,Ft,zt).call(this,e);return t?t.listeners.map(({listener:e})=>e):[]}let t=[];for(const{listeners:n}of __privateGet(this,St).values())t=t.concat(n.map(({listener:e})=>e));return t}async off(e,t){const n=await __privateMethod(this,Ft,zt).call(this,e);if(!n)return this;if(t){const e=n.listeners.map(({listener:e})=>e).indexOf(t);e>=0&&n.listeners.splice(e,1)}return t&&0!==n.listeners.length||(n.started&&n.subscriber.stop(),__privateGet(this,St).delete(n.tag)),this}async removeAllListeners(e){if(e){const{tag:t,started:n,subscriber:r}=await __privateMethod(this,Ft,qt).call(this,e);n&&r.stop(),__privateGet(this,St).delete(t)}else for(const[t,{started:n,subscriber:r}]of __privateGet(this,St))n&&r.stop(),__privateGet(this,St).delete(t);return this}async addListener(e,t){return await this.on(e,t)}async removeListener(e,t){return this.off(e,t)}get destroyed(){return __privateGet(this,Pt)}destroy(){this.removeAllListeners();for(const e of __privateGet(this,Mt).keys())this._clearTimeout(e);__privateSet(this,Pt,!0)}get paused(){return null!=__privateGet(this,It)}set paused(e){!!e!==this.paused&&(this.paused?this.resume():this.pause(!1))}pause(e){if(__privateSet(this,Rt,-1),null!=__privateGet(this,It)){if(__privateGet(this,It)==!!e)return;gS(!1,"cannot change pause type; resume first","UNSUPPORTED_OPERATION",{operation:"pause"})}this._forEachSubscriber(t=>t.pause(e)),__privateSet(this,It,!!e);for(const t of __privateGet(this,Mt).values())t.timer&&clearTimeout(t.timer),t.time=yD()-t.time}resume(){if(null!=__privateGet(this,It)){this._forEachSubscriber(e=>e.resume()),__privateSet(this,It,null);for(const e of __privateGet(this,Mt).values()){let t=e.time;t<0&&(t=0),e.time=yD(),setTimeout(e.func,t)}}}}function wD(e,t){try{const n=vD(e,t);if(n)return dx(n)}catch(n){}return null}function vD(e,t){if("0x"===e)return null;try{const n=JS(RS(e,t,t+32)),r=JS(RS(e,n,n+32));return RS(e,n+32,n+32+r)}catch(n){}return null}function _D(e){const t=YS(e);if(t.length>32)throw new Error("internal; should not happen");const n=new Uint8Array(32);return n.set(t,32-t.length),n}function ED(e){if(e.length%32==0)return e;const t=new Uint8Array(32*Math.ceil(e.length/32));return t.set(e),t}St=new WeakMap,xt=new WeakMap,It=new WeakMap,Pt=new WeakMap,Ct=new WeakMap,Nt=new WeakMap,Ot=new WeakMap,Rt=new WeakMap,Bt=new WeakMap,Mt=new WeakMap,$t=new WeakMap,Dt=new WeakMap,Ft=new WeakSet,Gt=async function(e){const t=__privateGet(this,Dt).cacheTimeout;if(t<0)return await this._perform(e);const n=dD(e.method,e);let r=__privateGet(this,Ot).get(n);return r||(r=this._perform(e),__privateGet(this,Ot).set(n,r),setTimeout(()=>{__privateGet(this,Ot).get(n)===r&&__privateGet(this,Ot).delete(n)},t)),await r},Ut=async function(e,t,n){gS(n<10,"CCIP read exceeded maximum redirections","OFFCHAIN_FAULT",{reason:"TOO_MANY_REDIRECTS",transaction:Object.assign({},e,{blockTag:t,enableCcipRead:!0})});const r=JM(e);try{return CS(await this._perform({method:"call",transaction:r,blockTag:t}))}catch(i){if(!this.disableCcipRead&&mS(i)&&i.data&&n>=0&&"latest"===t&&null!=r.to&&"0x556f1830"===RS(i.data,0,4)){const e=i.data,a=await AO(r.to,this);let o;try{o=function(e){const t={sender:"",urls:[],calldata:"",selector:"",extraData:"",errorArgs:[]};gS(OS(e)>=160,"insufficient OffchainLookup data","OFFCHAIN_FAULT",{reason:"insufficient OffchainLookup data"});const n=RS(e,0,32);gS(RS(n,0,12)===RS(SD,0,12),"corrupt OffchainLookup sender","OFFCHAIN_FAULT",{reason:"corrupt OffchainLookup sender"}),t.sender=RS(n,12);try{const n=[],r=JS(RS(e,32,64)),i=JS(RS(e,r,r+32)),s=RS(e,r+32);for(let e=0;e<i;e++){const t=wD(s,32*e);if(null==t)throw new Error("abort");n.push(t)}t.urls=n}catch(i){gS(!1,"corrupt OffchainLookup urls","OFFCHAIN_FAULT",{reason:"corrupt OffchainLookup urls"})}try{const n=vD(e,64);if(null==n)throw new Error("abort");t.calldata=n}catch(i){gS(!1,"corrupt OffchainLookup calldata","OFFCHAIN_FAULT",{reason:"corrupt OffchainLookup calldata"})}gS(RS(e,100,128)===RS(SD,0,28),"corrupt OffchainLookup callbaackSelector","OFFCHAIN_FAULT",{reason:"corrupt OffchainLookup callbaackSelector"}),t.selector=RS(e,96,100);try{const n=vD(e,128);if(null==n)throw new Error("abort");t.extraData=n}catch(i){gS(!1,"corrupt OffchainLookup extraData","OFFCHAIN_FAULT",{reason:"corrupt OffchainLookup extraData"})}return t.errorArgs="sender,urls,calldata,selector,extraData".split(/,/).map(e=>t[e]),t}(RS(i.data,4))}catch(s){gS(!1,s.message,"OFFCHAIN_FAULT",{reason:"BAD_DATA",transaction:r,info:{data:e}})}gS(o.sender.toLowerCase()===a.toLowerCase(),"CCIP Read sender mismatch","CALL_EXCEPTION",{action:"call",data:e,reason:"OffchainLookup",transaction:r,invocation:null,revert:{signature:"OffchainLookup(address,string[],bytes,bytes4,bytes)",name:"OffchainLookup",args:o.errorArgs}});const c=await this.ccipReadFetch(r,o.calldata,o.urls);gS(null!=c,"CCIP Read failed to fetch data","OFFCHAIN_FAULT",{reason:"FETCH_FAILED",transaction:r,info:{data:i.data,errorArgs:o.errorArgs}});const A={to:a,data:NS([o.selector,TD([c,o.extraData])])};this.emit("debug",{action:"sendCcipReadCall",transaction:A});try{const e=await __privateMethod(this,Ft,Ut).call(this,A,t,n+1);return this.emit("debug",{action:"receiveCcipReadCallResult",transaction:Object.assign({},A),result:e}),e}catch(s){throw this.emit("debug",{action:"receiveCcipReadCallError",transaction:Object.assign({},A),error:s}),s}}throw i}},Lt=async function(e){const{value:t}=await uS({network:this.getNetwork(),value:e});return t},jt=async function(e,t,n){let r=this._getAddress(t),i=this._getBlockTag(n);return"string"==typeof r&&"string"==typeof i||([r,i]=await Promise.all([r,i])),await __privateMethod(this,Ft,Lt).call(this,__privateMethod(this,Ft,Gt).call(this,Object.assign(e,{address:r,blockTag:i})))},Ht=async function(e,t){if(xS(e,32))return await __privateMethod(this,Ft,Gt).call(this,{method:"getBlock",blockHash:e,includeTransactions:t});let n=this._getBlockTag(e);return"string"!=typeof n&&(n=await n),await __privateMethod(this,Ft,Gt).call(this,{method:"getBlock",blockTag:n,includeTransactions:t})},zt=async function(e,t){let n=await mD(e,this);return"event"===n.type&&t&&t.length>0&&!0===t[0].removed&&(n=await mD({orphan:"drop-log",log:t[0]},this)),__privateGet(this,St).get(n.tag)||null},qt=async function(e){const t=await mD(e,this),n=t.tag;let r=__privateGet(this,St).get(n);return r||(r={subscriber:this._getSubscriber(t),tag:n,addressableMap:new WeakMap,nameMap:new Map,started:!1,listeners:[]},__privateGet(this,St).set(n,r)),r};const kD=new Uint8Array([]);function TD(e){const t=[];let n=0;for(let r=0;r<e.length;r++)t.push(kD),n+=32;for(let r=0;r<e.length;r++){const i=TS(e[r]);t[r]=_D(n),t.push(_D(i.length)),t.push(ED(i)),n+=32+32*Math.ceil(i.length/32)}return NS(t)}const SD="0x0000000000000000000000000000000000000000000000000000000000000000";function xD(e,t){if(e.provider)return e.provider;gS(!1,"missing provider","UNSUPPORTED_OPERATION",{operation:t})}async function ID(e,t){let n=JM(t);if(null!=n.to&&(n.to=AO(n.to,e)),null!=n.from){const t=n.from;n.from=Promise.all([e.getAddress(),AO(t,e)]).then(([e,t])=>(bS(e.toLowerCase()===t.toLowerCase(),"transaction from mismatch","tx.from",t),e))}else n.from=e.getAddress();return await uS(n)}class PD{constructor(e){__publicField(this,"provider"),dS(this,{provider:e||null})}async getNonce(e){return xD(this,"getTransactionCount").getTransactionCount(await this.getAddress(),e)}async populateCall(e){return await ID(this,e)}async populateTransaction(e){const t=xD(this,"populateTransaction"),n=await ID(this,e);null==n.nonce&&(n.nonce=await this.getNonce("pending")),null==n.gasLimit&&(n.gasLimit=await this.estimateGas(n));const r=await this.provider.getNetwork();null!=n.chainId?bS(zS(n.chainId)===r.chainId,"transaction chainId mismatch","tx.chainId",e.chainId):n.chainId=r.chainId;const i=null!=n.maxFeePerGas||null!=n.maxPriorityFeePerGas;if(null==n.gasPrice||2!==n.type&&!i?0!==n.type&&1!==n.type||!i||bS(!1,"pre-eip-1559 transaction do not support maxFeePerGas/maxPriorityFeePerGas","tx",e):bS(!1,"eip-1559 transaction do not support gasPrice","tx",e),2!==n.type&&null!=n.type||null==n.maxFeePerGas||null==n.maxPriorityFeePerGas)if(0===n.type||1===n.type){const e=await t.getFeeData();gS(null!=e.gasPrice,"network does not support gasPrice","UNSUPPORTED_OPERATION",{operation:"getGasPrice"}),null==n.gasPrice&&(n.gasPrice=e.gasPrice)}else{const e=await t.getFeeData();if(null==n.type)if(null!=e.maxFeePerGas&&null!=e.maxPriorityFeePerGas)if(n.authorizationList&&n.authorizationList.length?n.type=4:n.type=2,null!=n.gasPrice){const e=n.gasPrice;delete n.gasPrice,n.maxFeePerGas=e,n.maxPriorityFeePerGas=e}else null==n.maxFeePerGas&&(n.maxFeePerGas=e.maxFeePerGas),null==n.maxPriorityFeePerGas&&(n.maxPriorityFeePerGas=e.maxPriorityFeePerGas);else null!=e.gasPrice?(gS(!i,"network does not support EIP-1559","UNSUPPORTED_OPERATION",{operation:"populateTransaction"}),null==n.gasPrice&&(n.gasPrice=e.gasPrice),n.type=0):gS(!1,"failed to get consistent fee data","UNSUPPORTED_OPERATION",{operation:"signer.getFeeData"});else 2!==n.type&&3!==n.type&&4!==n.type||(null==n.maxFeePerGas&&(n.maxFeePerGas=e.maxFeePerGas),null==n.maxPriorityFeePerGas&&(n.maxPriorityFeePerGas=e.maxPriorityFeePerGas))}else n.type=2;return await uS(n)}async populateAuthorization(e){const t=Object.assign({},e);return null==t.chainId&&(t.chainId=(await xD(this,"getNetwork").getNetwork()).chainId),null==t.nonce&&(t.nonce=await this.getNonce()),t}async estimateGas(e){return xD(this,"estimateGas").estimateGas(await this.populateCall(e))}async call(e){return xD(this,"call").call(await this.populateCall(e))}async resolveName(e){const t=xD(this,"resolveName");return await t.resolveName(e)}async sendTransaction(e){const t=xD(this,"sendTransaction"),n=await this.populateTransaction(e);delete n.from;const r=nR.from(n);return await t.broadcastTransaction(await this.signTransaction(r))}authorize(e){gS(!1,"authorization not implemented for this signer","UNSUPPORTED_OPERATION",{operation:"authorize"})}}Qt=new WeakSet,Vt=function(e,t){gS(!1,`VoidSigner cannot sign ${e}`,"UNSUPPORTED_OPERATION",{operation:t})};let CD=class e extends PD{constructor(e,t){super(t),__privateAdd(this,Qt),__publicField(this,"address"),dS(this,{address:e})}async getAddress(){return this.address}connect(t){return new e(this.address,t)}async signTransaction(e){__privateMethod(this,Qt,Vt).call(this,"transactions","signTransaction")}async signMessage(e){__privateMethod(this,Qt,Vt).call(this,"messages","signMessage")}async signTypedData(e,t,n){__privateMethod(this,Qt,Vt).call(this,"typed-data","signTypedData")}};const ND=new Set;function OD(e){ND.has(e)||(ND.add(e),console.log("========= NOTICE ========="),console.log(`Request-Rate Exceeded for ${e} (this message will not be repeated)`),console.log(""),console.log("The default API keys for each service are provided as a highly-throttled,"),console.log("community resource for low-traffic projects and early prototyping."),console.log(""),console.log("While your application will continue to function, we highly recommended"),console.log("signing up for your own API keys to improve performance, increase your"),console.log("request rate/limit and enable other perks, such as metrics and advanced APIs."),console.log(""),console.log("For more details: https://docs.ethers.org/api-keys/"),console.log("=========================="))}class RD{constructor(e){__privateAdd(this,en),__privateAdd(this,Jt),__privateAdd(this,Kt),__privateAdd(this,Wt),__privateAdd(this,Yt),__privateAdd(this,Zt),__privateAdd(this,Xt),__privateSet(this,Jt,e),__privateSet(this,Kt,null),__privateSet(this,Wt,__privateMethod(this,en,tn).bind(this)),__privateSet(this,Yt,!1),__privateSet(this,Zt,null),__privateSet(this,Xt,!1)}_subscribe(e){throw new Error("subclasses must override this")}_emitResults(e,t){throw new Error("subclasses must override this")}_recover(e){throw new Error("subclasses must override this")}start(){__privateGet(this,Yt)||(__privateSet(this,Yt,!0),__privateMethod(this,en,tn).call(this,-2))}stop(){__privateGet(this,Yt)&&(__privateSet(this,Yt,!1),__privateSet(this,Xt,!0),__privateMethod(this,en,nn).call(this),__privateGet(this,Jt).off("block",__privateGet(this,Wt)))}pause(e){e&&__privateMethod(this,en,nn).call(this),__privateGet(this,Jt).off("block",__privateGet(this,Wt))}resume(){this.start()}}Jt=new WeakMap,Kt=new WeakMap,Wt=new WeakMap,Yt=new WeakMap,Zt=new WeakMap,Xt=new WeakMap,en=new WeakSet,tn=async function(e){try{null==__privateGet(this,Kt)&&__privateSet(this,Kt,this._subscribe(__privateGet(this,Jt)));let e=null;try{e=await __privateGet(this,Kt)}catch(t){if(!pS(t,"UNSUPPORTED_OPERATION")||"eth_newFilter"!==t.operation)throw t}if(null==e)return __privateSet(this,Kt,null),void __privateGet(this,Jt)._recoverSubscriber(this,this._recover(__privateGet(this,Jt)));const n=await __privateGet(this,Jt).getNetwork();if(__privateGet(this,Zt)||__privateSet(this,Zt,n),__privateGet(this,Zt).chainId!==n.chainId)throw new Error("chaid changed");if(__privateGet(this,Xt))return;const r=await __privateGet(this,Jt).send("eth_getFilterChanges",[e]);await this._emitResults(__privateGet(this,Jt),r)}catch(t){console.log("@TODO",t)}__privateGet(this,Jt).once("block",__privateGet(this,Wt))},nn=function(){const e=__privateGet(this,Kt);e&&(__privateSet(this,Kt,null),e.then(e=>{__privateGet(this,Jt).destroyed||__privateGet(this,Jt).send("eth_uninstallFilter",[e])}))};class BD extends RD{constructor(e,t){var n;super(e),__privateAdd(this,rn),__privateSet(this,rn,(n=t,JSON.parse(JSON.stringify(n))))}_recover(e){return new lD(e,__privateGet(this,rn))}async _subscribe(e){return await e.send("eth_newFilter",[__privateGet(this,rn)])}async _emitResults(e,t){for(const n of t)e.emit(__privateGet(this,rn),e._wrapLog(n,e._network))}}rn=new WeakMap;class MD extends RD{async _subscribe(e){return await e.send("eth_newPendingTransactionFilter",[])}async _emitResults(e,t){for(const n of t)e.emit("pending",n)}}const $D="bigint,boolean,function,number,string,symbol".split(/,/g);function DD(e){if(null==e||$D.indexOf(typeof e)>=0)return e;if("function"==typeof e.getAddress)return e;if(Array.isArray(e))return e.map(DD);if("object"==typeof e)return Object.keys(e).reduce((t,n)=>(t[n]=e[n],t),{});throw new Error(`should not happen: ${e} (${typeof e})`)}function FD(e){return new Promise(t=>{setTimeout(t,e)})}function GD(e){return e?e.toLowerCase():e}function UD(e){return e&&"number"==typeof e.pollingInterval}const LD={polling:!1,staticNetwork:null,batchStallTime:10,batchMaxSize:1<<20,batchMaxCount:100,cacheTimeout:250,pollingInterval:4e3};class jD extends PD{constructor(e,t){super(e),__publicField(this,"address"),dS(this,{address:t=nO(t)})}connect(e){gS(!1,"cannot reconnect JsonRpcSigner","UNSUPPORTED_OPERATION",{operation:"signer.connect"})}async getAddress(){return this.address}async populateTransaction(e){return await this.populateCall(e)}async sendUncheckedTransaction(e){const t=DD(e),n=[];if(t.from){const r=t.from;n.push((async()=>{const n=await AO(r,this.provider);bS(null!=n&&n.toLowerCase()===this.address.toLowerCase(),"from address mismatch","transaction",e),t.from=n})())}else t.from=this.address;if(null==t.gasLimit&&n.push((async()=>{t.gasLimit=await this.provider.estimateGas({...t,from:this.address})})()),null!=t.to){const e=t.to;n.push((async()=>{t.to=await AO(e,this.provider)})())}n.length&&await Promise.all(n);const r=this.provider.getRpcTransaction(t);return this.provider.send("eth_sendTransaction",[r])}async sendTransaction(e){const t=await this.provider.getBlockNumber(),n=await this.sendUncheckedTransaction(e);return await new Promise((e,r)=>{const i=[1e3,100];let s=0;const a=async()=>{try{const r=await this.provider.getTransaction(n);if(null!=r)return void e(r.replaceableTransaction(t))}catch(o){if(pS(o,"CANCELLED")||pS(o,"BAD_DATA")||pS(o,"NETWORK_ERROR")||pS(o,"UNSUPPORTED_OPERATION"))return null==o.info&&(o.info={}),o.info.sendTransactionHash=n,void r(o);if(pS(o,"INVALID_ARGUMENT")&&(s++,null==o.info&&(o.info={}),o.info.sendTransactionHash=n,s>10))return void r(o);this.provider.emit("error",yS("failed to fetch transation after sending (will try again)","UNKNOWN_ERROR",{error:o}))}this.provider._setTimeout(()=>{a()},i.pop()||4e3)};a()})}async signTransaction(e){const t=DD(e);if(t.from){const n=await AO(t.from,this.provider);bS(null!=n&&n.toLowerCase()===this.address.toLowerCase(),"from address mismatch","transaction",e),t.from=n}else t.from=this.address;const n=this.provider.getRpcTransaction(t);return await this.provider.send("eth_signTransaction",[n])}async signMessage(e){const t="string"==typeof e?ux(e):e;return await this.provider.send("personal_sign",[CS(t),this.address.toLowerCase()])}async signTypedData(e,t,n){const r=DD(n),i=await MB.resolveNames(e,t,r,async e=>{const t=await AO(e);return bS(null!=t,"TypedData does not support null address","value",e),t});return await this.provider.send("eth_signTypedData_v4",[this.address.toLowerCase(),JSON.stringify(MB.getPayload(i.domain,t,i.value))])}async unlock(e){return this.provider.send("personal_unlockAccount",[this.address.toLowerCase(),e,null])}async _legacySignMessage(e){const t="string"==typeof e?ux(e):e;return await this.provider.send("eth_sign",[this.address.toLowerCase(),CS(t)])}}class HD extends bD{constructor(e,t){super(e,t),__privateAdd(this,un),__privateAdd(this,sn),__privateAdd(this,an),__privateAdd(this,on),__privateAdd(this,cn),__privateAdd(this,An),__privateAdd(this,ln),__privateAdd(this,fn),__privateSet(this,an,1),__privateSet(this,sn,Object.assign({},LD,t||{})),__privateSet(this,on,[]),__privateSet(this,cn,null),__privateSet(this,ln,null),__privateSet(this,fn,null);{let e=null;const t=new Promise(t=>{e=t});__privateSet(this,An,{promise:t,resolve:e})}const n=this._getOption("staticNetwork");"boolean"==typeof n?(bS(!n||"any"!==e,"staticNetwork cannot be used on special network 'any'","options",t),n&&null!=e&&__privateSet(this,ln,eD.from(e))):n&&(bS(null==e||n.matches(e),"staticNetwork MUST match network object","options",t),__privateSet(this,ln,n))}_getOption(e){return __privateGet(this,sn)[e]}get _network(){return gS(__privateGet(this,ln),"network is not available yet","NETWORK_ERROR"),__privateGet(this,ln)}async _perform(e){if("call"===e.method||"estimateGas"===e.method){let t=e.transaction;if(t&&null!=t.type&&zS(t.type)&&null==t.maxFeePerGas&&null==t.maxPriorityFeePerGas){const n=await this.getFeeData();null==n.maxFeePerGas&&null==n.maxPriorityFeePerGas&&(e=Object.assign({},e,{transaction:Object.assign({},t,{type:void 0})}))}}const t=this.getRpcRequest(e);return null!=t?await this.send(t.method,t.args):super._perform(e)}async _detectNetwork(){const e=this._getOption("staticNetwork");if(e){if(!0!==e)return e;if(__privateGet(this,ln))return __privateGet(this,ln)}return __privateGet(this,fn)?await __privateGet(this,fn):this.ready?(__privateSet(this,fn,(async()=>{try{const e=eD.from(zS(await this.send("eth_chainId",[])));return __privateSet(this,fn,null),e}catch(e){throw __privateSet(this,fn,null),e}})()),await __privateGet(this,fn)):(__privateSet(this,fn,(async()=>{const e={id:__privateWrapper(this,an)._++,method:"eth_chainId",params:[],jsonrpc:"2.0"};let t;this.emit("debug",{action:"sendRpcPayload",payload:e});try{t=(await this._send(e))[0],__privateSet(this,fn,null)}catch(n){throw __privateSet(this,fn,null),this.emit("debug",{action:"receiveRpcError",error:n}),n}if(this.emit("debug",{action:"receiveRpcResult",result:t}),"result"in t)return eD.from(zS(t.result));throw this.getRpcError(e,t)})()),await __privateGet(this,fn))}_start(){null!=__privateGet(this,An)&&null!=__privateGet(this,An).resolve&&(__privateGet(this,An).resolve(),__privateSet(this,An,null),(async()=>{for(;null==__privateGet(this,ln)&&!this.destroyed;)try{__privateSet(this,ln,await this._detectNetwork())}catch(e){if(this.destroyed)break;console.log("JsonRpcProvider failed to detect network and cannot start up; retry in 1s (perhaps the URL is wrong or the node is not started)"),this.emit("error",yS("failed to bootstrap network detection","NETWORK_ERROR",{event:"initial-network-discovery",info:{error:e}})),await FD(1e3)}__privateMethod(this,un,dn).call(this)})())}async _waitUntilReady(){if(null!=__privateGet(this,An))return await __privateGet(this,An).promise}_getSubscriber(e){return"pending"===e.type?new MD(this):"event"===e.type?this._getOption("polling")?new lD(this,e.filter):new BD(this,e.filter):"orphan"===e.type&&"drop-log"===e.filter.orphan?new hD("orphan"):super._getSubscriber(e)}get ready(){return null==__privateGet(this,An)}getRpcTransaction(e){const t={};return["chainId","gasLimit","gasPrice","type","maxFeePerGas","maxPriorityFeePerGas","nonce","value"].forEach(n=>{if(null==e[n])return;let r=n;"gasLimit"===n&&(r="gas"),t[r]=ZS(zS(e[n],`tx.${n}`))}),["from","to","data"].forEach(n=>{null!=e[n]&&(t[n]=CS(e[n]))}),e.accessList&&(t.accessList=RO(e.accessList)),e.blobVersionedHashes&&(t.blobVersionedHashes=e.blobVersionedHashes.map(e=>e.toLowerCase())),e.authorizationList&&(t.authorizationList=e.authorizationList.map(e=>{const t=BO(e);return{address:t.address,nonce:ZS(t.nonce),chainId:ZS(t.chainId),yParity:ZS(t.signature.yParity),r:ZS(t.signature.r),s:ZS(t.signature.s)}})),t}getRpcRequest(e){switch(e.method){case"chainId":return{method:"eth_chainId",args:[]};case"getBlockNumber":return{method:"eth_blockNumber",args:[]};case"getGasPrice":return{method:"eth_gasPrice",args:[]};case"getPriorityFee":return{method:"eth_maxPriorityFeePerGas",args:[]};case"getBalance":return{method:"eth_getBalance",args:[GD(e.address),e.blockTag]};case"getTransactionCount":return{method:"eth_getTransactionCount",args:[GD(e.address),e.blockTag]};case"getCode":return{method:"eth_getCode",args:[GD(e.address),e.blockTag]};case"getStorage":return{method:"eth_getStorageAt",args:[GD(e.address),"0x"+e.position.toString(16),e.blockTag]};case"broadcastTransaction":return{method:"eth_sendRawTransaction",args:[e.signedTransaction]};case"getBlock":if("blockTag"in e)return{method:"eth_getBlockByNumber",args:[e.blockTag,!!e.includeTransactions]};if("blockHash"in e)return{method:"eth_getBlockByHash",args:[e.blockHash,!!e.includeTransactions]};break;case"getTransaction":return{method:"eth_getTransactionByHash",args:[e.hash]};case"getTransactionReceipt":return{method:"eth_getTransactionReceipt",args:[e.hash]};case"call":return{method:"eth_call",args:[this.getRpcTransaction(e.transaction),e.blockTag]};case"estimateGas":return{method:"eth_estimateGas",args:[this.getRpcTransaction(e.transaction)]};case"getLogs":return e.filter&&null!=e.filter.address&&(Array.isArray(e.filter.address)?e.filter.address=e.filter.address.map(GD):e.filter.address=GD(e.filter.address)),{method:"eth_getLogs",args:[e.filter]}}return null}getRpcError(e,t){const{method:n}=e,{error:r}=t;if("eth_estimateGas"===n&&r.message){const t=r.message;if(!t.match(/revert/i)&&t.match(/insufficient funds/i))return yS("insufficient funds","INSUFFICIENT_FUNDS",{transaction:e.params[0],info:{payload:e,error:r}});if(t.match(/nonce/i)&&t.match(/too low/i))return yS("nonce has already been used","NONCE_EXPIRED",{transaction:e.params[0],info:{payload:e,error:r}})}if("eth_call"===n||"eth_estimateGas"===n){const t=QD(r),i=BM.getBuiltinCallException("eth_call"===n?"call":"estimateGas",e.params[0],t?t.data:null);return i.info={error:r,payload:e},i}const i=JSON.stringify(function(e){const t=[];return VD(e,t),t}(r));if("string"==typeof r.message&&r.message.match(/user denied|ethers-user-denied/i))return yS("user rejected action","ACTION_REJECTED",{action:{eth_sign:"signMessage",personal_sign:"signMessage",eth_signTypedData_v4:"signTypedData",eth_signTransaction:"signTransaction",eth_sendTransaction:"sendTransaction",eth_requestAccounts:"requestAccess",wallet_requestAccounts:"requestAccess"}[n]||"unknown",reason:"rejected",info:{payload:e,error:r}});if("eth_sendRawTransaction"===n||"eth_sendTransaction"===n){const t=e.params[0];if(i.match(/insufficient funds|base fee exceeds gas limit/i))return yS("insufficient funds for intrinsic transaction cost","INSUFFICIENT_FUNDS",{transaction:t,info:{error:r}});if(i.match(/nonce/i)&&i.match(/too low/i))return yS("nonce has already been used","NONCE_EXPIRED",{transaction:t,info:{error:r}});if(i.match(/replacement transaction/i)&&i.match(/underpriced/i))return yS("replacement fee too low","REPLACEMENT_UNDERPRICED",{transaction:t,info:{error:r}});if(i.match(/only replay-protected/i))return yS("legacy pre-eip-155 transactions not supported","UNSUPPORTED_OPERATION",{operation:n,info:{transaction:t,info:{error:r}}})}let s=!!i.match(/the method .* does not exist/i);return s||r&&r.details&&r.details.startsWith("Unauthorized method:")&&(s=!0),s?yS("unsupported operation","UNSUPPORTED_OPERATION",{operation:e.method,info:{error:r,payload:e}}):yS("could not coalesce error","UNKNOWN_ERROR",{error:r,payload:e})}send(e,t){if(this.destroyed)return Promise.reject(yS("provider destroyed; cancelled request","UNSUPPORTED_OPERATION",{operation:e}));const n=__privateWrapper(this,an)._++,r=new Promise((r,i)=>{__privateGet(this,on).push({resolve:r,reject:i,payload:{method:e,params:t,id:n,jsonrpc:"2.0"}})});return __privateMethod(this,un,dn).call(this),r}async getSigner(e){null==e&&(e=0);const t=this.send("eth_accounts",[]);if("number"==typeof e){const n=await t;if(e>=n.length)throw new Error("no such account");return new jD(this,n[e])}const{accounts:n}=await uS({network:this.getNetwork(),accounts:t});e=nO(e);for(const r of n)if(nO(r)===e)return new jD(this,e);throw new Error("invalid account")}async listAccounts(){return(await this.send("eth_accounts",[])).map(e=>new jD(this,e))}destroy(){__privateGet(this,cn)&&(clearTimeout(__privateGet(this,cn)),__privateSet(this,cn,null));for(const{payload:e,reject:t}of __privateGet(this,on))t(yS("provider destroyed; cancelled request","UNSUPPORTED_OPERATION",{operation:e.method}));__privateSet(this,on,[]),super.destroy()}}sn=new WeakMap,an=new WeakMap,on=new WeakMap,cn=new WeakMap,An=new WeakMap,ln=new WeakMap,fn=new WeakMap,un=new WeakSet,dn=function(){if(__privateGet(this,cn))return;const e=1===this._getOption("batchMaxCount")?0:this._getOption("batchStallTime");__privateSet(this,cn,setTimeout(()=>{__privateSet(this,cn,null);const e=__privateGet(this,on);for(__privateSet(this,on,[]);e.length;){const t=[e.shift()];for(;e.length&&t.length!==__privateGet(this,sn).batchMaxCount;)if(t.push(e.shift()),JSON.stringify(t.map(e=>e.payload)).length>__privateGet(this,sn).batchMaxSize){e.unshift(t.pop());break}(async()=>{const e=1===t.length?t[0].payload:t.map(e=>e.payload);this.emit("debug",{action:"sendRpcPayload",payload:e});try{const n=await this._send(e);this.emit("debug",{action:"receiveRpcResult",result:n});for(const{resolve:e,reject:r,payload:i}of t){if(this.destroyed){r(yS("provider destroyed; cancelled request","UNSUPPORTED_OPERATION",{operation:i.method}));continue}const t=n.filter(e=>e.id===i.id)[0];if(null==t){const e=yS("missing response for request","BAD_DATA",{value:n,info:{payload:i}});this.emit("error",e),r(e);continue}"error"in t?r(this.getRpcError(i,t)):e(t.result)}}catch(n){this.emit("debug",{action:"receiveRpcError",error:n});for(const{reject:e}of t)e(n)}})()}},e))};class zD extends HD{constructor(e,t){super(e,t),__privateAdd(this,hn);let n=this._getOption("pollingInterval");null==n&&(n=LD.pollingInterval),__privateSet(this,hn,n)}_getSubscriber(e){const t=super._getSubscriber(e);return UD(t)&&(t.pollingInterval=__privateGet(this,hn)),t}get pollingInterval(){return __privateGet(this,hn)}set pollingInterval(e){if(!Number.isInteger(e)||e<0)throw new Error("invalid interval");__privateSet(this,hn,e),this._forEachSubscriber(e=>{UD(e)&&(e.pollingInterval=__privateGet(this,hn))})}}hn=new WeakMap;class qD extends zD{constructor(e,t,n){null==e&&(e="http://localhost:8545"),super(t,n),__privateAdd(this,pn),__privateSet(this,pn,"string"==typeof e?new xx(e):e.clone())}_getConnection(){return __privateGet(this,pn).clone()}async send(e,t){return await this._start(),await super.send(e,t)}async _send(e){const t=this._getConnection();t.body=JSON.stringify(e),t.setHeader("content-type","application/json");const n=await t.send();n.assertOk();let r=n.bodyJson;return Array.isArray(r)||(r=[r]),r}}function QD(e){if(null==e)return null;if("string"==typeof e.message&&e.message.match(/revert/i)&&xS(e.data))return{message:e.message,data:e.data};if("object"==typeof e){for(const t in e){const n=QD(e[t]);if(n)return n}return null}if("string"==typeof e)try{return QD(JSON.parse(e))}catch(t){}return null}function VD(e,t){if(null!=e){if("string"==typeof e.message&&t.push(e.message),"object"==typeof e)for(const n in e)VD(e[n],t);if("string"==typeof e)try{return VD(JSON.parse(e),t)}catch(n){}}}pn=new WeakMap;const JD="9f7d929b018cdffb338517efa06f58359e86ff1ffd350bc889738523659e7972";class KD extends qD{constructor(e,t){null==e&&(e="mainnet");const n=eD.from(e);null==t&&(t=JD);const r={polling:!0,staticNetwork:n};super(KD.getRequest(n,t),n,r),__publicField(this,"apiKey"),dS(this,{apiKey:t})}_getProvider(e){try{return new KD(e,this.apiKey)}catch(t){}return super._getProvider(e)}static getRequest(e,t){null==t&&(t=JD);const n=new xx(`https://${function(e){switch(e){case"mainnet":return"rpc.ankr.com/eth";case"goerli":return"rpc.ankr.com/eth_goerli";case"sepolia":return"rpc.ankr.com/eth_sepolia";case"arbitrum":return"rpc.ankr.com/arbitrum";case"base":return"rpc.ankr.com/base";case"base-goerli":return"rpc.ankr.com/base_goerli";case"base-sepolia":return"rpc.ankr.com/base_sepolia";case"bnb":return"rpc.ankr.com/bsc";case"bnbt":return"rpc.ankr.com/bsc_testnet_chapel";case"filecoin":return"rpc.ankr.com/filecoin";case"filecoin-calibration":return"rpc.ankr.com/filecoin_testnet";case"matic":return"rpc.ankr.com/polygon";case"matic-mumbai":return"rpc.ankr.com/polygon_mumbai";case"optimism":return"rpc.ankr.com/optimism";case"optimism-goerli":return"rpc.ankr.com/optimism_testnet";case"optimism-sepolia":return"rpc.ankr.com/optimism_sepolia"}bS(!1,"unsupported network","network",e)}(e.name)}/${t}`);return n.allowGzip=!0,t===JD&&(n.retryFunc=async(e,t,n)=>(OD("AnkrProvider"),!0)),n}getRpcError(e,t){return"eth_sendRawTransaction"===e.method&&t&&t.error&&"INTERNAL_ERROR: could not replace existing tx"===t.error.message&&(t.error.message="replacement transaction underpriced"),super.getRpcError(e,t)}isCommunityResource(){return this.apiKey===JD}}const WD="_gg7wSSi0KMBsdKnGVfHDueq6xMB9EkC";class YD extends qD{constructor(e,t){null==e&&(e="mainnet");const n=eD.from(e);null==t&&(t=WD),super(YD.getRequest(n,t),n,{staticNetwork:n}),__publicField(this,"apiKey"),dS(this,{apiKey:t})}_getProvider(e){try{return new YD(e,this.apiKey)}catch(t){}return super._getProvider(e)}async _perform(e){if("getTransactionResult"===e.method){const{trace:n,tx:r}=await uS({trace:this.send("trace_transaction",[e.hash]),tx:this.getTransaction(e.hash)});if(null==n||null==r)return null;let i,s=!1;try{i=n[0].result.output,s="Reverted"===n[0].error}catch(t){}if(i)return gS(!s,"an error occurred during transaction executions","CALL_EXCEPTION",{action:"getTransactionResult",data:i,reason:null,transaction:r,invocation:null,revert:null}),i;gS(!1,"could not parse trace result","BAD_DATA",{value:n})}return await super._perform(e)}isCommunityResource(){return this.apiKey===WD}static getRequest(e,t){null==t&&(t=WD);const n=new xx(`https://${function(e){switch(e){case"mainnet":return"eth-mainnet.g.alchemy.com";case"goerli":return"eth-goerli.g.alchemy.com";case"sepolia":return"eth-sepolia.g.alchemy.com";case"arbitrum":return"arb-mainnet.g.alchemy.com";case"arbitrum-goerli":return"arb-goerli.g.alchemy.com";case"arbitrum-sepolia":return"arb-sepolia.g.alchemy.com";case"base":return"base-mainnet.g.alchemy.com";case"base-goerli":return"base-goerli.g.alchemy.com";case"base-sepolia":return"base-sepolia.g.alchemy.com";case"matic":return"polygon-mainnet.g.alchemy.com";case"matic-amoy":return"polygon-amoy.g.alchemy.com";case"matic-mumbai":return"polygon-mumbai.g.alchemy.com";case"optimism":return"opt-mainnet.g.alchemy.com";case"optimism-goerli":return"opt-goerli.g.alchemy.com";case"optimism-sepolia":return"opt-sepolia.g.alchemy.com"}bS(!1,"unsupported network","network",e)}(e.name)}/v2/${t}`);return n.allowGzip=!0,t===WD&&(n.retryFunc=async(e,t,n)=>(OD("alchemy"),!0)),n}}function ZD(e){switch(e){case"mainnet":return"39f1d67cedf8b7831010a665328c9197";case"arbitrum":return"0550c209db33c3abf4cc927e1e18cea1";case"bnb":return"98b5a77e531614387366f6fc5da097f8";case"matic":return"cd9d4d70377471aa7c142ec4a4205249"}bS(!1,"unsupported network","network",e)}class XD extends qD{constructor(e,t){null==e&&(e="mainnet");const n=eD.from(e);null==t&&(t=ZD(n.name)),super(XD.getRequest(n,t),n,{staticNetwork:n}),__publicField(this,"apiKey"),dS(this,{apiKey:t})}_getProvider(e){try{return new XD(e,this.apiKey)}catch(t){}return super._getProvider(e)}isCommunityResource(){return this.apiKey===ZD(this._network.name)}static getRequest(e,t){null==t&&(t=ZD(e.name));const n=new xx(`https://${function(e){switch(e){case"mainnet":return"ethereum-mainnet.core.chainstack.com";case"arbitrum":return"arbitrum-mainnet.core.chainstack.com";case"bnb":return"bsc-mainnet.core.chainstack.com";case"matic":return"polygon-mainnet.core.chainstack.com"}bS(!1,"unsupported network","network",e)}(e.name)}/${t}`);return n.allowGzip=!0,t===ZD(e.name)&&(n.retryFunc=async(e,t,n)=>(OD("ChainstackProvider"),!0)),n}}class eF extends qD{constructor(e){null==e&&(e="mainnet");const t=eD.from(e);bS("mainnet"===t.name,"unsupported network","network",e),super("https://cloudflare-eth.com/",t,{staticNetwork:t})}}const tF="1 11155111 17000 560048 2741 11124 33111 33139 42170 42161 421614 43114 43113 8453 84532 80069 80094 199 1029 81457 168587773 56 97 42220 11142220 252 2523 100 999 737373 747474 59144 59141 5000 5003 43521 143 10143 1287 1284 1285 10 11155420 204 5611 80002 137 534352 534351 1329 1328 146 14601 988 2201 1923 1924 167013 167000 130 1301 480 4801 51 50 324 300".split(/ /g),nF="org.ethers.plugins.provider.Etherscan";class rF extends J${constructor(e){super(nF),__publicField(this,"baseUrl"),dS(this,{baseUrl:e})}clone(){return new rF(this.baseUrl)}}const iF=["enableCcipRead"];let sF=1;class aF extends bD{constructor(e,t){const n=null!=t?t:null;super(),__publicField(this,"network"),__publicField(this,"apiKey"),__privateAdd(this,mn);const r=eD.from(e);bS(tF.indexOf(`${r.chainId}`)>=0,"unsupported network","network",r),__privateSet(this,mn,r.getPlugin(nF)),dS(this,{apiKey:n,network:r})}getBaseUrl(){if(__privateGet(this,mn))return __privateGet(this,mn).baseUrl;switch(this.network.name){case"mainnet":return"https://api.etherscan.io";case"goerli":return"https://api-goerli.etherscan.io";case"sepolia":return"https://api-sepolia.etherscan.io";case"holesky":return"https://api-holesky.etherscan.io";case"arbitrum":return"https://api.arbiscan.io";case"arbitrum-goerli":return"https://api-goerli.arbiscan.io";case"base":return"https://api.basescan.org";case"base-sepolia":return"https://api-sepolia.basescan.org";case"bnb":return"https://api.bscscan.com";case"bnbt":return"https://api-testnet.bscscan.com";case"matic":return"https://api.polygonscan.com";case"matic-amoy":return"https://api-amoy.polygonscan.com";case"matic-mumbai":return"https://api-testnet.polygonscan.com";case"optimism":return"https://api-optimistic.etherscan.io";case"optimism-goerli":return"https://api-goerli-optimistic.etherscan.io"}bS(!1,"unsupported network","network",this.network)}getUrl(e,t){let n=Object.keys(t).reduce((e,n)=>{const r=t[n];return null!=r&&(e+=`&${n}=${r}`),e},"");return this.apiKey&&(n+=`&apikey=${this.apiKey}`),`https://api.etherscan.io/v2/api?chainid=${this.network.chainId}&module=${e}${n}`}getPostUrl(){return`https://api.etherscan.io/v2/api?chainid=${this.network.chainId}`}getPostData(e,t){return t.module=e,t.apikey=this.apiKey,t.chainid=this.network.chainId,t}async detectNetwork(){return this.network}async fetch(e,t,n){const r=sF++,i=n?this.getPostUrl():this.getUrl(e,t),s=n?this.getPostData(e,t):null;this.emit("debug",{action:"sendRequest",id:r,url:i,payload:s});const a=new xx(i);a.setThrottleParams({slotInterval:1e3}),a.retryFunc=(e,t,n)=>(this.isCommunityResource()&&OD("Etherscan"),Promise.resolve(!0)),a.processFunc=async(t,n)=>{const i=n.hasBody()?JSON.parse(dx(n.body)):{},s=("string"==typeof i.result?i.result:"").toLowerCase().indexOf("rate limit")>=0;return"proxy"===e?i&&0==i.status&&"NOTOK"==i.message&&s&&(this.emit("debug",{action:"receiveError",id:r,reason:"proxy-NOTOK",error:i}),n.throwThrottleError(i.result,2e3)):s&&(this.emit("debug",{action:"receiveError",id:r,reason:"null result",error:i.result}),n.throwThrottleError(i.result,2e3)),n},s&&(a.setHeader("content-type","application/x-www-form-urlencoded; charset=UTF-8"),a.body=Object.keys(s).map(e=>`${e}=${s[e]}`).join("&"));const o=await a.send();try{o.assertOk()}catch(A){this.emit("debug",{action:"receiveError",id:r,error:A,reason:"assertOk"}),gS(!1,"response error","SERVER_ERROR",{request:a,response:o})}o.hasBody()||(this.emit("debug",{action:"receiveError",id:r,error:"missing body",reason:"null body"}),gS(!1,"missing response","SERVER_ERROR",{request:a,response:o}));const c=JSON.parse(dx(o.body));return"proxy"===e?("2.0"!=c.jsonrpc&&(this.emit("debug",{action:"receiveError",id:r,result:c,reason:"invalid JSON-RPC"}),gS(!1,"invalid JSON-RPC response (missing jsonrpc='2.0')","SERVER_ERROR",{request:a,response:o,info:{result:c}})),c.error&&(this.emit("debug",{action:"receiveError",id:r,result:c,reason:"JSON-RPC error"}),gS(!1,"error response","SERVER_ERROR",{request:a,response:o,info:{result:c}})),this.emit("debug",{action:"receiveRequest",id:r,result:c}),c.result):0!=c.status||"No records found"!==c.message&&"No transactions found"!==c.message?((1!=c.status||"string"==typeof c.message&&!c.message.match(/^OK/))&&(this.emit("debug",{action:"receiveError",id:r,result:c}),gS(!1,"error response","SERVER_ERROR",{request:a,response:o,info:{result:c}})),this.emit("debug",{action:"receiveRequest",id:r,result:c}),c.result):(this.emit("debug",{action:"receiveRequest",id:r,result:c}),c.result)}_getTransactionPostData(e){const t={};for(let n in e){if(iF.indexOf(n)>=0)continue;if(null==e[n])continue;let r=e[n];if(!("type"===n&&0===r||"blockTag"===n&&"latest"===r)){if({type:!0,gasLimit:!0,gasPrice:!0,maxFeePerGs:!0,maxPriorityFeePerGas:!0,nonce:!0,value:!0}[n])r=ZS(r);else if("accessList"===n)r="["+RO(r).map(e=>`{address:"${e.address}",storageKeys:["${e.storageKeys.join('","')}"]}`).join(",")+"]";else if("blobVersionedHashes"===n){if(0===r.length)continue;gS(!1,"Etherscan API does not support blobVersionedHashes","UNSUPPORTED_OPERATION",{operation:"_getTransactionPostData",info:{transaction:e}})}else r=CS(r);t[n]=r}}return t}_checkError(e,t,n){let r="";if(pS(t,"SERVER_ERROR")){try{r=t.info.result.error.message}catch(i){}if(!r)try{r=t.info.message}catch(i){}}if("estimateGas"===e.method&&!r.match(/revert/i)&&r.match(/insufficient funds/i)&&gS(!1,"insufficient funds","INSUFFICIENT_FUNDS",{transaction:e.transaction}),("call"===e.method||"estimateGas"===e.method)&&r.match(/execution reverted/i)){let n="";try{n=t.info.result.error.data}catch(s){}const r=BM.getBuiltinCallException(e.method,e.transaction,n);throw r.info={request:e,error:t},r}if(r&&"broadcastTransaction"===e.method){const t=nR.from(e.signedTransaction);r.match(/replacement/i)&&r.match(/underpriced/i)&&gS(!1,"replacement fee too low","REPLACEMENT_UNDERPRICED",{transaction:t}),r.match(/insufficient funds/)&&gS(!1,"insufficient funds for intrinsic transaction cost","INSUFFICIENT_FUNDS",{transaction:t}),r.match(/same hash was already imported|transaction nonce is too low|nonce too low/)&&gS(!1,"nonce has already been used","NONCE_EXPIRED",{transaction:t})}throw t}async _detectNetwork(){return this.network}async _perform(e){switch(e.method){case"chainId":return this.network.chainId;case"getBlockNumber":return this.fetch("proxy",{action:"eth_blockNumber"});case"getGasPrice":return this.fetch("proxy",{action:"eth_gasPrice"});case"getPriorityFee":if("mainnet"===this.network.name)return"1000000000";if("optimism"===this.network.name)return"1000000";throw new Error("fallback onto the AbstractProvider default");case"getBalance":return this.fetch("account",{action:"balance",address:e.address,tag:e.blockTag});case"getTransactionCount":return this.fetch("proxy",{action:"eth_getTransactionCount",address:e.address,tag:e.blockTag});case"getCode":return this.fetch("proxy",{action:"eth_getCode",address:e.address,tag:e.blockTag});case"getStorage":return this.fetch("proxy",{action:"eth_getStorageAt",address:e.address,position:e.position,tag:e.blockTag});case"broadcastTransaction":return this.fetch("proxy",{action:"eth_sendRawTransaction",hex:e.signedTransaction},!0).catch(t=>this._checkError(e,t,e.signedTransaction));case"getBlock":if("blockTag"in e)return this.fetch("proxy",{action:"eth_getBlockByNumber",tag:e.blockTag,boolean:e.includeTransactions?"true":"false"});gS(!1,"getBlock by blockHash not supported by Etherscan","UNSUPPORTED_OPERATION",{operation:"getBlock(blockHash)"});case"getTransaction":return this.fetch("proxy",{action:"eth_getTransactionByHash",txhash:e.hash});case"getTransactionReceipt":return this.fetch("proxy",{action:"eth_getTransactionReceipt",txhash:e.hash});case"call":{if("latest"!==e.blockTag)throw new Error("EtherscanProvider does not support blockTag for call");const n=this._getTransactionPostData(e.transaction);n.module="proxy",n.action="eth_call";try{return await this.fetch("proxy",n,!0)}catch(t){return this._checkError(e,t,e.transaction)}}case"estimateGas":{const n=this._getTransactionPostData(e.transaction);n.module="proxy",n.action="eth_estimateGas";try{return await this.fetch("proxy",n,!0)}catch(t){return this._checkError(e,t,e.transaction)}}}return super._perform(e)}async getNetwork(){return this.network}async getEtherPrice(){return"mainnet"!==this.network.name?0:parseFloat((await this.fetch("stats",{action:"ethprice"})).ethusd)}async getContract(e){let t=this._getAddress(e);var n;(n=t)&&"function"==typeof n.then&&(t=await t);try{const e=await this.fetch("contract",{action:"getabi",address:t}),n=JSON.parse(e);return new P$(t,n,this)}catch(r){return null}}isCommunityResource(){return null==this.apiKey}}mn=new WeakMap;const oF=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof globalThis)return globalThis;throw new Error("unable to locate global object")}().WebSocket;class cF{constructor(e,t){__privateAdd(this,yn),__privateAdd(this,gn),__privateAdd(this,bn),__privateAdd(this,wn),__privateAdd(this,vn),__privateSet(this,yn,e),__privateSet(this,gn,JSON.stringify(t)),__privateSet(this,bn,null),__privateSet(this,wn,null),__privateSet(this,vn,null)}get filter(){return JSON.parse(__privateGet(this,gn))}start(){__privateSet(this,bn,__privateGet(this,yn).send("eth_subscribe",this.filter).then(e=>(__privateGet(this,yn)._register(e,this),e)))}stop(){__privateGet(this,bn).then(e=>{__privateGet(this,yn).destroyed||__privateGet(this,yn).send("eth_unsubscribe",[e])}),__privateSet(this,bn,null)}pause(e){gS(e,"preserve logs while paused not supported by SocketSubscriber yet","UNSUPPORTED_OPERATION",{operation:"pause(false)"}),__privateSet(this,wn,!!e)}resume(){__privateSet(this,wn,null)}_handleMessage(e){if(null!=__privateGet(this,bn)&&null===__privateGet(this,wn)){let t=__privateGet(this,vn);t=null==t?this._emit(__privateGet(this,yn),e):t.then(async()=>{await this._emit(__privateGet(this,yn),e)}),__privateSet(this,vn,t.then(()=>{__privateGet(this,vn)===t&&__privateSet(this,vn,null)}))}}async _emit(e,t){throw new Error("sub-classes must implemente this; _emit")}}yn=new WeakMap,gn=new WeakMap,bn=new WeakMap,wn=new WeakMap,vn=new WeakMap;class AF extends cF{constructor(e){super(e,["newHeads"])}async _emit(e,t){e.emit("block",parseInt(t.number))}}class lF extends cF{constructor(e){super(e,["newPendingTransactions"])}async _emit(e,t){e.emit("pending",t)}}class fF extends cF{constructor(e,t){super(e,["logs",t]),__privateAdd(this,_n),__privateSet(this,_n,JSON.stringify(t))}get logFilter(){return JSON.parse(__privateGet(this,_n))}async _emit(e,t){e.emit(this.logFilter,e._wrapLog(t,e._network))}}_n=new WeakMap;class uF extends HD{constructor(e,t){const n=Object.assign({},null!=t?t:{});bS(null==n.batchMaxCount||1===n.batchMaxCount,"sockets-based providers do not support batches","options.batchMaxCount",t),n.batchMaxCount=1,null==n.staticNetwork&&(n.staticNetwork=!0),super(e,n),__privateAdd(this,En),__privateAdd(this,kn),__privateAdd(this,Tn),__privateSet(this,En,new Map),__privateSet(this,kn,new Map),__privateSet(this,Tn,new Map)}_getSubscriber(e){switch(e.type){case"close":return new hD("close");case"block":return new AF(this);case"pending":return new lF(this);case"event":return new fF(this,e.filter);case"orphan":if("drop-log"===e.filter.orphan)return new hD("drop-log")}return super._getSubscriber(e)}_register(e,t){__privateGet(this,kn).set(e,t);const n=__privateGet(this,Tn).get(e);if(n){for(const e of n)t._handleMessage(e);__privateGet(this,Tn).delete(e)}}async _send(e){bS(!Array.isArray(e),"WebSocket does not support batch send","payload",e);const t=new Promise((t,n)=>{__privateGet(this,En).set(e.id,{payload:e,resolve:t,reject:n})});return await this._waitUntilReady(),await this._write(JSON.stringify(e)),[await t]}async _processMessage(e){const t=JSON.parse(e);if(t&&"object"==typeof t&&"id"in t){const e=__privateGet(this,En).get(t.id);if(null==e)return void this.emit("error",yS("received result for unknown id","UNKNOWN_ERROR",{reasonCode:"UNKNOWN_ID",result:t}));__privateGet(this,En).delete(t.id),e.resolve(t)}else{if(!t||"eth_subscription"!==t.method)return void this.emit("error",yS("received unexpected message","UNKNOWN_ERROR",{reasonCode:"UNEXPECTED_MESSAGE",result:t}));{const e=t.params.subscription,n=__privateGet(this,kn).get(e);if(n)n._handleMessage(t.params.result);else{let n=__privateGet(this,Tn).get(e);null==n&&(n=[],__privateGet(this,Tn).set(e,n)),n.push(t.params.result)}}}}async _write(e){throw new Error("sub-classes must override this")}}En=new WeakMap,kn=new WeakMap,Tn=new WeakMap;class dF extends uF{constructor(e,t,n){super(t,n),__privateAdd(this,Sn),__privateAdd(this,xn),"string"==typeof e?(__privateSet(this,Sn,()=>new oF(e)),__privateSet(this,xn,__privateGet(this,Sn).call(this))):"function"==typeof e?(__privateSet(this,Sn,e),__privateSet(this,xn,e())):(__privateSet(this,Sn,null),__privateSet(this,xn,e)),this.websocket.onopen=async()=>{try{await this._start(),this.resume()}catch(e){console.log("failed to start WebsocketProvider",e)}},this.websocket.onmessage=e=>{this._processMessage(e.data)}}get websocket(){if(null==__privateGet(this,xn))throw new Error("websocket closed");return __privateGet(this,xn)}async _write(e){this.websocket.send(e)}async destroy(){null!=__privateGet(this,xn)&&(__privateGet(this,xn).close(),__privateSet(this,xn,null)),super.destroy()}}Sn=new WeakMap,xn=new WeakMap;const hF="84842078b09946638c03157f83405213";class pF extends dF{constructor(e,t){const n=new mF(e,t),r=n._getConnection();gS(!r.credentials,"INFURA WebSocket project secrets unsupported","UNSUPPORTED_OPERATION",{operation:"InfuraProvider.getWebSocketProvider()"}),super(r.url.replace(/^http/i,"ws").replace("/v3/","/ws/v3/"),n._network),__publicField(this,"projectId"),__publicField(this,"projectSecret"),dS(this,{projectId:n.projectId,projectSecret:n.projectSecret})}isCommunityResource(){return this.projectId===hF}}class mF extends qD{constructor(e,t,n){null==e&&(e="mainnet");const r=eD.from(e);null==t&&(t=hF),null==n&&(n=null),super(mF.getRequest(r,t,n),r,{staticNetwork:r}),__publicField(this,"projectId"),__publicField(this,"projectSecret"),dS(this,{projectId:t,projectSecret:n})}_getProvider(e){try{return new mF(e,this.projectId,this.projectSecret)}catch(t){}return super._getProvider(e)}isCommunityResource(){return this.projectId===hF}static getWebSocketProvider(e,t){return new pF(e,t)}static getRequest(e,t,n){null==t&&(t=hF),null==n&&(n=null);const r=new xx(`https://${function(e){switch(e){case"mainnet":return"mainnet.infura.io";case"goerli":return"goerli.infura.io";case"sepolia":return"sepolia.infura.io";case"arbitrum":return"arbitrum-mainnet.infura.io";case"arbitrum-goerli":return"arbitrum-goerli.infura.io";case"arbitrum-sepolia":return"arbitrum-sepolia.infura.io";case"base":return"base-mainnet.infura.io";case"base-goerlia":case"base-goerli":return"base-goerli.infura.io";case"base-sepolia":return"base-sepolia.infura.io";case"bnb":return"bsc-mainnet.infura.io";case"bnbt":return"bsc-testnet.infura.io";case"linea":return"linea-mainnet.infura.io";case"linea-goerli":return"linea-goerli.infura.io";case"linea-sepolia":return"linea-sepolia.infura.io";case"matic":return"polygon-mainnet.infura.io";case"matic-amoy":return"polygon-amoy.infura.io";case"matic-mumbai":return"polygon-mumbai.infura.io";case"optimism":return"optimism-mainnet.infura.io";case"optimism-goerli":return"optimism-goerli.infura.io";case"optimism-sepolia":return"optimism-sepolia.infura.io"}bS(!1,"unsupported network","network",e)}(e.name)}/v3/${t}`);return r.allowGzip=!0,n&&r.setCredentials("",n),t===hF&&(r.retryFunc=async(e,t,n)=>(OD("InfuraProvider"),!0)),r}}const yF="919b412a057b5e9c9b6dce193c5a60242d6efadb";class gF extends qD{constructor(e,t){null==e&&(e="mainnet");const n=eD.from(e);null==t&&(t=yF),super(gF.getRequest(n,t),n,{staticNetwork:n}),__publicField(this,"token"),dS(this,{token:t})}_getProvider(e){try{return new gF(e,this.token)}catch(t){}return super._getProvider(e)}isCommunityResource(){return this.token===yF}static getRequest(e,t){null==t&&(t=yF);const n=new xx(`https://${function(e){switch(e){case"mainnet":return"ethers.quiknode.pro";case"goerli":return"ethers.ethereum-goerli.quiknode.pro";case"sepolia":return"ethers.ethereum-sepolia.quiknode.pro";case"holesky":return"ethers.ethereum-holesky.quiknode.pro";case"arbitrum":return"ethers.arbitrum-mainnet.quiknode.pro";case"arbitrum-goerli":return"ethers.arbitrum-goerli.quiknode.pro";case"arbitrum-sepolia":return"ethers.arbitrum-sepolia.quiknode.pro";case"base":return"ethers.base-mainnet.quiknode.pro";case"base-goerli":return"ethers.base-goerli.quiknode.pro";case"base-spolia":return"ethers.base-sepolia.quiknode.pro";case"bnb":return"ethers.bsc.quiknode.pro";case"bnbt":return"ethers.bsc-testnet.quiknode.pro";case"matic":return"ethers.matic.quiknode.pro";case"matic-mumbai":return"ethers.matic-testnet.quiknode.pro";case"optimism":return"ethers.optimism.quiknode.pro";case"optimism-goerli":return"ethers.optimism-goerli.quiknode.pro";case"optimism-sepolia":return"ethers.optimism-sepolia.quiknode.pro";case"xdai":return"ethers.xdai.quiknode.pro"}bS(!1,"unsupported network","network",e)}(e.name)}/${t}`);return n.allowGzip=!0,t===yF&&(n.retryFunc=async(e,t,n)=>(OD("QuickNodeProvider"),!0)),n}}const bF=BigInt("1"),wF=BigInt("2");function vF(){return(new Date).getTime()}function _F(e){return JSON.stringify(e,(e,t)=>"bigint"==typeof t?{type:"bigint",value:t.toString()}:t)}const EF={stallTimeout:400,priority:1,weight:1},kF={blockNumber:-2,requests:0,lateResponses:0,errorResponses:0,outOfSync:-1,unsupportedEvents:0,rollingDuration:0,score:0,_network:null,_updateNumber:null,_totalTime:0,_lastFatalError:null,_lastFatalErrorTimestamp:0};function TF(e){if(null==e)return"null";if(Array.isArray(e))return"["+e.map(TF).join(",")+"]";if("object"==typeof e&&"function"==typeof e.toJSON)return TF(e.toJSON());switch(typeof e){case"boolean":case"symbol":return e.toString();case"bigint":case"number":return BigInt(e).toString();case"string":return JSON.stringify(e);case"object":{const t=Object.keys(e);return t.sort(),"{"+t.map(t=>`${JSON.stringify(t)}:${TF(e[t])}`).join(",")+"}"}}throw console.log("Could not serialize",e),new Error("Hmm...")}function SF(e,t){if("error"in t){const e=t.error;let n;return n=pS(e,"CALL_EXCEPTION")?TF(Object.assign({},e,{shortMessage:void 0,reason:void 0,info:void 0})):TF(e),{tag:n,value:e}}const n=t.result;return{tag:TF(n),value:n}}function xF(e,t){const n=new Map;for(const{value:i,tag:s,weight:a}of t){const e=n.get(s)||{value:i,weight:0};e.weight+=a,n.set(s,e)}let r=null;for(const i of n.values())i.weight>=e&&(!r||i.weight>r.weight)&&(r=i);if(r)return r.value}function IF(e,t){let n=0;const r=new Map;let i=null;const s=[];for(const{value:o,tag:c,weight:A}of t)if(o instanceof Error){const e=r.get(c)||{value:o,weight:0};e.weight+=A,r.set(c,e),(null==i||e.weight>i.weight)&&(i=e)}else s.push(BigInt(o)),n+=A;if(n<e)return i&&i.weight>=e?i.value:void 0;s.sort((e,t)=>e<t?-1:t>e?1:0);const a=Math.floor(s.length/2);return s.length%2?s[a]:(s[a-1]+s[a]+bF)/wF}function PF(e,t){const n=xF(e,t);if(void 0!==n)return n;for(const r of t)if(r.value)return r.value}class CF extends bD{constructor(e,t,n){super(t,n),__privateAdd(this,Nn),__publicField(this,"quorum"),__publicField(this,"eventQuorum"),__publicField(this,"eventWorkers"),__privateAdd(this,In),__privateAdd(this,Pn),__privateAdd(this,Cn),__privateSet(this,In,e.map(e=>e instanceof bD?Object.assign({provider:e},EF,kF):Object.assign({},EF,e,kF))),__privateSet(this,Pn,-2),__privateSet(this,Cn,null),n&&null!=n.quorum?this.quorum=n.quorum:this.quorum=Math.ceil(__privateGet(this,In).reduce((e,t)=>e+t.weight,0)/2),this.eventQuorum=1,this.eventWorkers=1,bS(this.quorum<=__privateGet(this,In).reduce((e,t)=>e+t.weight,0),"quorum exceed provider weight","quorum",this.quorum)}get providerConfigs(){return __privateGet(this,In).map(e=>{const t=Object.assign({},e);for(const n in t)"_"===n[0]&&delete t[n];return t})}async _detectNetwork(){return eD.from(zS(await this._perform({method:"chainId"})))}async _translatePerform(e,t){switch(t.method){case"broadcastTransaction":return await e.broadcastTransaction(t.signedTransaction);case"call":return await e.call(Object.assign({},t.transaction,{blockTag:t.blockTag}));case"chainId":return(await e.getNetwork()).chainId;case"estimateGas":return await e.estimateGas(t.transaction);case"getBalance":return await e.getBalance(t.address,t.blockTag);case"getBlock":{const n="blockHash"in t?t.blockHash:t.blockTag;return await e.getBlock(n,t.includeTransactions)}case"getBlockNumber":return await e.getBlockNumber();case"getCode":return await e.getCode(t.address,t.blockTag);case"getGasPrice":return(await e.getFeeData()).gasPrice;case"getPriorityFee":return(await e.getFeeData()).maxPriorityFeePerGas;case"getLogs":return await e.getLogs(t.filter);case"getStorage":return await e.getStorage(t.address,t.position,t.blockTag);case"getTransaction":return await e.getTransaction(t.hash);case"getTransactionCount":return await e.getTransactionCount(t.address,t.blockTag);case"getTransactionReceipt":return await e.getTransactionReceipt(t.hash);case"getTransactionResult":return await e.getTransactionResult(t.hash)}}async _perform(e){if("broadcastTransaction"===e.method){const t=__privateGet(this,In).map(e=>null),n=__privateGet(this,In).map(async({provider:n,weight:r},i)=>{try{const s=await n._perform(e);t[i]=Object.assign(SF(e.method,{result:s}),{weight:r})}catch(s){t[i]=Object.assign(SF(e.method,{error:s}),{weight:r})}});for(;;){const e=t.filter(e=>null!=e);for(const{value:t}of e)if(!(t instanceof Error))return t;const r=xF(this.quorum,t.filter(e=>null!=e));if(pS(r,"INSUFFICIENT_FUNDS"))throw r;const i=n.filter((e,n)=>null==t[n]);if(0===i.length)break;await Promise.race(i)}const r=PF(this.quorum,t);if(gS(void 0!==r,"problem multi-broadcasting","SERVER_ERROR",{request:"%sub-requests",info:{request:e,results:t.map(_F)}}),r instanceof Error)throw r;return r}await __privateMethod(this,Nn,Bn).call(this);const t=new Set;let n=0;for(;;){const r=__privateMethod(this,Nn,Rn).call(this,t,e);if(null==r)break;if(n+=r.config.weight,n>=this.quorum)break}const r=await __privateMethod(this,Nn,$n).call(this,t,e);for(const i of t)i.perform&&null==i.result&&i.config.lateResponses++;return r}async destroy(){for(const{provider:e}of __privateGet(this,In))e.destroy();super.destroy()}}In=new WeakMap,Pn=new WeakMap,Cn=new WeakMap,Nn=new WeakSet,On=function(e){const t=Array.from(e).map(e=>e.config),n=__privateGet(this,In).slice();!function(e){for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1)),r=e[t];e[t]=e[n],e[n]=r}}(n),n.sort((e,t)=>e.priority-t.priority);for(const r of n)if(!r._lastFatalError&&-1===t.indexOf(r))return r;return null},Rn=function(e,t){const n=__privateMethod(this,Nn,On).call(this,e);if(null==n)return null;const r={config:n,result:null,didBump:!1,perform:null,staller:null},i=vF();return r.perform=(async()=>{try{n.requests++;const e=await this._translatePerform(n.provider,t);r.result={result:e}}catch(s){n.errorResponses++,r.result={error:s}}const e=vF()-i;n._totalTime+=e,n.rollingDuration=.95*n.rollingDuration+.05*e,r.perform=null})(),r.staller=(async()=>{var e;await(e=n.stallTimeout,new Promise(t=>{setTimeout(t,e)})),r.staller=null})(),e.add(r),r},Bn=async function(){let e=__privateGet(this,Cn);if(!e){const t=[];__privateGet(this,In).forEach(e=>{t.push((async()=>{await async function(e){for(;(e.blockNumber<0||e.blockNumber<0)&&(e._updateNumber||(e._updateNumber=(async()=>{try{const t=await e.provider.getBlockNumber();t>e.blockNumber&&(e.blockNumber=t)}catch(t){e.blockNumber=-2,e._lastFatalError=t,e._lastFatalErrorTimestamp=vF()}e._updateNumber=null})()),await e._updateNumber,e.outOfSync++,!e._lastFatalError););}(e),e._lastFatalError||(e._network=await e.provider.getNetwork())})())}),__privateSet(this,Cn,e=(async()=>{await Promise.all(t);let e=null;for(const t of __privateGet(this,In)){if(t._lastFatalError)continue;const n=t._network;null==e?e=n.chainId:n.chainId!==e&&gS(!1,"cannot mix providers on different networks","UNSUPPORTED_OPERATION",{operation:"new FallbackProvider"})}})())}await e},Mn=async function(e,t){const n=[];for(const r of e)if(null!=r.result){const{tag:e,value:i}=SF(t.method,r.result);n.push({tag:e,value:i,weight:r.config.weight})}if(!(n.reduce((e,t)=>e+t.weight,0)<this.quorum)){switch(t.method){case"getBlockNumber":{-2===__privateGet(this,Pn)&&__privateSet(this,Pn,Math.ceil(JS(IF(this.quorum,__privateGet(this,In).filter(e=>!e._lastFatalError).map(e=>({value:e.blockNumber,tag:JS(e.blockNumber).toString(),weight:e.weight}))))));const e=function(e,t){if(1===e)return JS(IF(e,t),"%internal");const n=new Map,r=(e,t)=>{const r=n.get(e)||{result:e,weight:0};r.weight+=t,n.set(e,r)};for(const{weight:a,value:o}of t){const e=JS(o);r(e-1,a),r(e,a),r(e+1,a)}let i,s=0;for(const{weight:a,result:o}of n.values())a>=e&&(a>s||null!=i&&a===s&&o>i)&&(s=a,i=o);return i}(this.quorum,n);if(void 0===e)return;return e>__privateGet(this,Pn)&&__privateSet(this,Pn,e),__privateGet(this,Pn)}case"getGasPrice":case"getPriorityFee":case"estimateGas":return IF(this.quorum,n);case"getBlock":return"blockTag"in t&&"pending"===t.blockTag?PF(this.quorum,n):xF(this.quorum,n);case"call":case"chainId":case"getBalance":case"getTransactionCount":case"getCode":case"getStorage":case"getTransaction":case"getTransactionReceipt":case"getLogs":return xF(this.quorum,n);case"broadcastTransaction":return PF(this.quorum,n)}gS(!1,"unsupported method","UNSUPPORTED_OPERATION",{operation:`_perform(${_F(t.method)})`})}},$n=async function(e,t){if(0===e.size)throw new Error("no runners?!");const n=[];let r=0;for(const s of e)s.perform&&n.push(s.perform),s.staller?n.push(s.staller):s.didBump||(s.didBump=!0,r++);const i=await __privateMethod(this,Nn,Mn).call(this,e,t);if(void 0!==i){if(i instanceof Error)throw i;return i}for(let s=0;s<r;s++)__privateMethod(this,Nn,Rn).call(this,e,t);return gS(n.length>0,"quorum not met","SERVER_ERROR",{request:"%sub-requests",info:{request:t,results:Array.from(e).map(e=>_F(e.result))}}),await Promise.race(n),await __privateMethod(this,Nn,$n).call(this,e,t)};const NF="goerli kovan sepolia classicKotti optimism-goerli arbitrum-goerli matic-mumbai bnbt".split(" ");function OF(e,t){null==t&&(t={});const n=e=>"-"!==t[e]&&("string"==typeof t.exclusive?e===t.exclusive:!Array.isArray(t.exclusive)||-1!==t.exclusive.indexOf(e));if("string"==typeof e&&e.match(/^https?:/))return new qD(e);if("string"==typeof e&&e.match(/^wss?:/)||(r=e)&&"function"==typeof r.send&&"function"==typeof r.close)return new dF(e);var r;let i=null;try{i=eD.from(e)}catch(o){}const s=[];if(n("publicPolygon")&&i&&("matic"===i.name?s.push(new qD("https://polygon-rpc.com/",i,{staticNetwork:i})):"matic-amoy"===i.name&&s.push(new qD("https://rpc-amoy.polygon.technology/",i,{staticNetwork:i}))),n("alchemy"))try{s.push(new YD(e,t.alchemy))}catch(o){}if(n("ankr")&&null!=t.ankr)try{s.push(new KD(e,t.ankr))}catch(o){}if(n("chainstack"))try{s.push(new XD(e,t.chainstack))}catch(o){}if(n("cloudflare"))try{s.push(new eF(e))}catch(o){}if(n("etherscan"))try{s.push(new aF(e,t.etherscan))}catch(o){}if(n("infura"))try{let n,r=t.infura;"object"==typeof r&&(n=r.projectSecret,r=r.projectId),s.push(new mF(e,r,n))}catch(o){}if(n("quicknode"))try{let n=t.quicknode;s.push(new gF(e,n))}catch(o){}if(gS(s.length,"unsupported default network","UNSUPPORTED_OPERATION",{operation:"getDefaultProvider"}),1===s.length)return s[0];let a=Math.floor(s.length/2);return a>2&&(a=2),i&&-1!==NF.indexOf(i.name)&&(a=1),t&&t.quorum&&(a=t.quorum),new CF(s,void 0,{quorum:a})}Dn=new WeakMap,Fn=new WeakMap;let RF=class e extends PD{constructor(e){super(e.provider),__publicField(this,"signer"),__privateAdd(this,Dn),__privateAdd(this,Fn),dS(this,{signer:e}),__privateSet(this,Dn,null),__privateSet(this,Fn,0)}async getAddress(){return this.signer.getAddress()}connect(t){return new e(this.signer.connect(t))}async getNonce(e){if("pending"===e){null==__privateGet(this,Dn)&&__privateSet(this,Dn,super.getNonce("pending"));const e=__privateGet(this,Fn);return await __privateGet(this,Dn)+e}return super.getNonce(e)}increment(){__privateWrapper(this,Fn)._++}reset(){__privateSet(this,Fn,0),__privateSet(this,Dn,null)}async sendTransaction(e){const t=this.getNonce("pending");return this.increment(),(e=await this.signer.populateTransaction(e)).nonce=await t,await this.signer.sendTransaction(e)}signTransaction(e){return this.signer.signTransaction(e)}signMessage(e){return this.signer.signMessage(e)}signTypedData(e,t,n){return this.signer.signTypedData(e,t,n)}};Gn=new WeakMap,Un=new WeakMap;let BF=class e extends zD{constructor(e,t,n){const r=Object.assign({},null!=n?n:{},{batchMaxCount:1});bS(e&&e.request,"invalid EIP-1193 provider","ethereum",e),super(t,r),__privateAdd(this,Gn),__privateAdd(this,Un),__privateSet(this,Un,null),n&&n.providerInfo&&__privateSet(this,Un,n.providerInfo),__privateSet(this,Gn,async(t,n)=>{const r={method:t,params:n};this.emit("debug",{action:"sendEip1193Request",payload:r});try{const t=await e.request(r);return this.emit("debug",{action:"receiveEip1193Result",result:t}),t}catch(i){const e=new Error(i.message);throw e.code=i.code,e.data=i.data,e.payload=r,this.emit("debug",{action:"receiveEip1193Error",error:e}),e}})}get providerInfo(){return __privateGet(this,Un)}async send(e,t){return await this._start(),await super.send(e,t)}async _send(e){bS(!Array.isArray(e),"EIP-1193 does not support batch request","payload",e);try{const t=await __privateGet(this,Gn).call(this,e.method,e.params||[]);return[{id:e.id,result:t}]}catch(t){return[{id:e.id,error:{code:t.code,data:t.data,message:t.message}}]}}getRpcError(e,t){switch((t=JSON.parse(JSON.stringify(t))).error.code||-1){case 4001:t.error.message=`ethers-user-denied: ${t.error.message}`;break;case 4200:t.error.message=`ethers-unsupported: ${t.error.message}`}return super.getRpcError(e,t)}async hasSigner(e){null==e&&(e=0);const t=await this.send("eth_accounts",[]);return"number"==typeof e?t.length>e:(e=e.toLowerCase(),0!==t.filter(t=>t.toLowerCase()===e).length)}async getSigner(e){if(null==e&&(e=0),!(await this.hasSigner(e)))try{await __privateGet(this,Gn).call(this,"eth_requestAccounts",[])}catch(t){const e=t.payload;throw this.getRpcError(e,{id:e.id,error:t})}return await super.getSigner(e)}static async discover(t){if(null==t&&(t={}),t.provider)return new e(t.provider);const n=t.window?t.window:"undefined"!=typeof window?window:null;if(null==n)return null;const r=t.anyProvider;if(r&&n.ethereum)return new e(n.ethereum);if(!("addEventListener"in n&&"dispatchEvent"in n&&"removeEventListener"in n))return null;const i=t.timeout?t.timeout:300;return 0===i?null:await new Promise((s,a)=>{let o=[];const c=e=>{o.push(e.detail),r&&A()},A=()=>{if(clearTimeout(l),o.length)if(t&&t.filter){const n=t.filter(o.map(e=>Object.assign({},e.info)));if(null==n)s(null);else if(n instanceof e)s(n);else{let t=null;if(n.uuid&&(t=o.filter(e=>n.uuid===e.info.uuid)[0]),t){const{provider:n,info:r}=t;s(new e(n,void 0,{providerInfo:r}))}else a(yS("filter returned unknown info","UNSUPPORTED_OPERATION",{value:n}))}}else{const{provider:t,info:n}=o[0];s(new e(t,void 0,{providerInfo:n}))}else s(null);n.removeEventListener("eip6963:announceProvider",c)},l=setTimeout(()=>{A()},i);n.addEventListener("eip6963:announceProvider",c),n.dispatchEvent(new Event("eip6963:requestProvider"))})}};class MF extends qD{constructor(e,t){null==e&&(e="mainnet");const n=eD.from(e);null==t&&(t=null),super(MF.getRequest(n),n,{staticNetwork:n}),__publicField(this,"apiKey"),dS(this,{apiKey:t})}_getProvider(e){try{return new MF(e,this.apiKey)}catch(t){}return super._getProvider(e)}isCommunityResource(){return null===this.apiKey}getRpcRequest(e){const t=super.getRpcRequest(e);return t&&"eth_estimateGas"===t.method&&1==t.args.length&&(t.args=t.args.slice(),t.args.push("latest")),t}getRpcError(e,t){const n=t?t.error:null;if(n&&-32015===n.code&&!xS(n.data||"",!0)){const e={"assert(false)":"01","arithmetic underflow or overflow":"11","division or modulo by zero":"12","out-of-bounds array access; popping on an empty array":"31","out-of-bounds access of an array or bytesN":"32"};let t="";"VM execution error."===n.message?t=e[n.data]||"":e[n.message||""]&&(t=e[n.message||""]),t&&(n.message+=` (reverted: ${n.data})`,n.data="0x4e487b7100000000000000000000000000000000000000000000000000000000000000"+t)}else n&&-32e3===n.code&&"wrong transaction nonce"===n.message&&(n.message+=" (nonce too low)");return super.getRpcError(e,t)}static getRequest(e){const t=new xx(function(e){switch(e){case"mainnet":return"https://eth.blockscout.com/api/eth-rpc";case"sepolia":return"https://eth-sepolia.blockscout.com/api/eth-rpc";case"holesky":return"https://eth-holesky.blockscout.com/api/eth-rpc";case"classic":return"https://etc.blockscout.com/api/eth-rpc";case"arbitrum":return"https://arbitrum.blockscout.com/api/eth-rpc";case"base":return"https://base.blockscout.com/api/eth-rpc";case"base-sepolia":return"https://base-sepolia.blockscout.com/api/eth-rpc";case"matic":return"https://polygon.blockscout.com/api/eth-rpc";case"optimism":return"https://optimism.blockscout.com/api/eth-rpc";case"optimism-sepolia":return"https://optimism-sepolia.blockscout.com/api/eth-rpc";case"xdai":return"https://gnosis.blockscout.com/api/eth-rpc"}bS(!1,"unsupported network","network",e)}(e.name));return t.allowGzip=!0,t}}const $F="62e1ad51b37b8e00394bda3b";class DF extends qD{constructor(e,t,n){null==e&&(e="mainnet");const r=eD.from(e);null==t&&(t=$F),null==n&&(n=null);const i={staticNetwork:r};super(DF.getRequest(r,t,n),r,i),__publicField(this,"applicationId"),__publicField(this,"applicationSecret"),dS(this,{applicationId:t,applicationSecret:n})}_getProvider(e){try{return new DF(e,this.applicationId,this.applicationSecret)}catch(t){}return super._getProvider(e)}static getRequest(e,t,n){null==t&&(t=$F);const r=new xx(`https://${function(e){switch(e){case"mainnet":return"eth-mainnet.gateway.pokt.network";case"goerli":return"eth-goerli.gateway.pokt.network";case"matic":return"poly-mainnet.gateway.pokt.network";case"matic-mumbai":return"polygon-mumbai-rpc.gateway.pokt.network"}bS(!1,"unsupported network","network",e)}(e.name)}/v1/lb/${t}`);return r.allowGzip=!0,n&&r.setCredentials("",n),t===$F&&(r.retryFunc=async(e,t,n)=>(OD("PocketProvider"),!0)),r}isCommunityResource(){return this.applicationId===$F}}const FF=void 0;Ln=new WeakMap;let GF=class e extends PD{constructor(e,t){super(t),__publicField(this,"address"),__privateAdd(this,Ln),bS(e&&"function"==typeof e.sign,"invalid private key","privateKey","[ REDACTED ]"),__privateSet(this,Ln,e),dS(this,{address:MO(this.signingKey.publicKey)})}get signingKey(){return __privateGet(this,Ln)}get privateKey(){return this.signingKey.privateKey}async getAddress(){return this.address}connect(t){return new e(__privateGet(this,Ln),t)}async signTransaction(e){e=JM(e);const{to:t,from:n}=await uS({to:e.to?AO(e.to,this):void 0,from:e.from?AO(e.from,this):void 0});null!=t&&(e.to=t),null!=n&&(e.from=n),null!=e.from&&(bS(nO(e.from)===this.address,"transaction from address mismatch","tx.from",e.from),delete e.from);const r=nR.from(e);return r.signature=this.signingKey.sign(r.unsignedHash),r.serialized}async signMessage(e){return this.signMessageSync(e)}signMessageSync(e){return this.signingKey.sign(uB(e)).serialized}authorizeSync(e){bS("string"==typeof e.address,"invalid address for authorizeSync","auth.address",e);const t=this.signingKey.sign(rR(e));return Object.assign({},{address:nO(e.address),nonce:zS(e.nonce||0),chainId:zS(e.chainId||0)},{signature:t})}async authorize(e){return e=Object.assign({},e,{address:await AO(e.address,this)}),this.authorizeSync(await this.populateAuthorization(e))}async signTypedData(e,t,n){const r=await MB.resolveNames(e,t,n,async e=>{gS(null!=this.provider,"cannot resolve ENS names without a provider","UNSUPPORTED_OPERATION",{operation:"resolveName",info:{name:e}});const t=await this.provider.resolveName(e);return gS(null!=t,"unconfigured ENS name","UNCONFIGURED_NAME",{value:e}),t});return this.signingKey.sign(MB.hash(r.domain,t,r.value)).serialized}};const UF=/^[a-z]*$/i;function LF(e,t){let n=97;return e.reduce((e,r)=>(r===t?n++:r.match(UF)?e.push(String.fromCharCode(n)+r):(n=97,e.push(r)),e),[])}function jF(e){return bS("0"===e[0],"unsupported auwl data","data",e),function(e,t){for(let i=28;i>=0;i--)e=e.split(" !#$%&'()*+,-./<=>?@[]^_`{|}~"[i]).join(t.substring(2*i,2*i+2));const n=[],r=e.replace(/(:|([0-9])|([A-Z][a-z]*))/g,(e,t,r,i)=>{if(r)for(let s=parseInt(r);s>=0;s--)n.push(";");else n.push(t.toLowerCase());return""});if(r)throw new Error(`leftovers: ${JSON.stringify(r)}`);return LF(LF(n,";"),":")}(e.substring(59),e.substring(1,59))}class HF{constructor(e){__publicField(this,"locale"),dS(this,{locale:e})}split(e){return e.toLowerCase().split(/\s+/g)}join(e){return e.join(" ")}}class zF extends HF{constructor(e,t,n){super(e),__privateAdd(this,qn),__privateAdd(this,jn),__privateAdd(this,Hn),__privateAdd(this,zn),__privateSet(this,jn,t),__privateSet(this,Hn,n),__privateSet(this,zn,null)}get _data(){return __privateGet(this,jn)}_decodeWords(){return jF(__privateGet(this,jn))}getWord(e){const t=__privateMethod(this,qn,Qn).call(this);return bS(e>=0&&e<t.length,`invalid word index: ${e}`,"index",e),t[e]}getWordIndex(e){return __privateMethod(this,qn,Qn).call(this).indexOf(e)}}jn=new WeakMap,Hn=new WeakMap,zn=new WeakMap,qn=new WeakSet,Qn=function(){if(null==__privateGet(this,zn)){const e=this._decodeWords();if(sR(e.join("\n")+"\n")!==__privateGet(this,Hn))throw new Error(`BIP39 Wordlist for ${this.locale} FAILED`);__privateSet(this,zn,e)}return __privateGet(this,zn)};let qF=null;class QF extends zF{constructor(){super("en","0erleonalorenseinceregesticitStanvetearctssi#ch2Athck&tneLl0And#Il.yLeOutO=S|S%b/ra@SurdU'0Ce[Cid|CountCu'Hie=IdOu,-Qui*Ro[TT]T%T*[Tu$0AptDD-tD*[Ju,M.UltV<)Vi)0Rob-0FairF%dRaid0A(EEntRee0Ead0MRRp%tS!_rmBumCoholErtI&LLeyLowMo,O}PhaReadySoT Ways0A>urAz(gOngOuntU'd0Aly,Ch%Ci|G G!GryIm$K!Noun)Nu$O` Sw T&naTiqueXietyY1ArtOlogyPe?P!Pro=Ril1ChCt-EaEnaGueMMedM%MyOundR<+Re,Ri=RowTTefa@Ti,Tw%k0KPe@SaultSetSi,SumeThma0H!>OmTa{T&dT.udeTra@0Ct]D.Gu,NtTh%ToTumn0Era+OcadoOid0AkeA*AyEsomeFulKw?d0Is:ByChel%C#D+GL<)Lc#y~MbooN<aNn RRelyRga(R*lSeS-SketTt!3A^AnAutyCau'ComeEfF%eG(Ha=H(dLie=LowLtN^Nef./TrayTt Twe&Y#d3Cyc!DKeNdOlogyRdR`Tt _{AdeAmeAnketA,EakE[IndOodO[omOu'UeUrUsh_rdAtDyIlMbNeNusOkO,Rd R(gRrowSsTtomUn)XY_{etA(AndA[A=EadEezeI{Id+IefIghtIngIskOccoliOk&OnzeOomO` OwnUsh2Bb!DdyD+tFf$oIldLbLkL!tNd!Nk Rd&Rg R,SS(e[SyTt Y Zz:Bba+B(B!CtusGeKe~LmM aMpNN$N)lNdyNn#NoeNvasNy#Pab!P.$Pta(RRb#RdRgoRpetRryRtSeShS(o/!Su$TT$ogT^Teg%yTt!UghtU'Ut]Ve3Il(gL yM|NsusNturyRe$Rta(_irAlkAmp]An+AosApt Ar+A'AtEapE{Ee'EfErryE,I{&IefIldIm}yOi)Oo'R#-U{!UnkUrn0G?Nnam#Rc!Tiz&TyVil_imApArifyAwAyE<ErkEv I{I|IffImbIn-IpO{OgO'O`OudOwnUbUmpU, Ut^_^A,C#utDeFfeeIlInL!@L%LumnMb(eMeMf%tM-Mm#Mp<yNc tNdu@NfirmNg*[N}@Nsid NtrolNv()OkOlPp PyR$ReRnR*@/Tt#U^UntryUp!Ur'Us(V Yo>_{Ad!AftAmA}AshAt AwlAzyEamEd.EekEwI{etImeIspIt-OpO[Ou^OwdUci$UelUi'Umb!Un^UshYY,$2BeLtu*PPbo?dRiousRr|Rta(R=Sh]/omTe3C!:DMa+MpN)Ng R(gShUght WnY3AlBa>BrisCadeCemb CideCl(eC%a>C*a'ErF&'F(eFyG*eLayLiv M<dMi'Ni$Nti,NyP?tP&dPos.P`PutyRi=ScribeS tSignSkSpair/royTailTe@VelopVi)Vo>3AgramAlAm#dAryCeE'lEtFf G.$Gn.yLemmaNn NosaurRe@RtSag*eScov Sea'ShSmi[S%d Splay/<)V tVideV%)Zzy5Ct%Cum|G~Lph(Ma(Na>NkeyN%OrSeUb!Ve_ftAg#AmaA,-AwEamE[IftIllInkIpI=OpUmY2CkMbNeR(g/T^Ty1Arf1Nam-:G G!RlyRnR`Sily/Sy1HoOlogyOnomy0GeItUca>1F%t0G1GhtTh 2BowD E@r-Eg<tEm|Eph<tEvat%I>Se0B?kBodyBra)Er+Ot]PloyPow Pty0Ab!A@DD![D%'EmyErgyF%)Ga+G(eH<)JoyLi,OughR-hRollSu*T Ti*TryVelope1Isode0U$Uip0AA'OdeOs]R%Upt0CapeSayS&)Ta>0Ern$H-s1Id&)IlOkeOl=1A@Amp!Ce[Ch<+C.eCludeCu'Ecu>Erci'Hau,Hib.I!I,ItOt-P<dPe@Pi*Pla(Po'P*[T&dTra0EEbrow:Br-CeCultyDeIntI`~L'MeMilyMousNNcyNtasyRmSh]TT$Th TigueUltV%.e3Atu*Bru?yD $EEdElMa!N)/iv$T^V W3B Ct]EldGu*LeLmLt N$NdNeNg NishReRmR,Sc$ShTT}[X_gAmeAshAtAv%EeIghtIpOatO{O%Ow UidUshY_mCusGIlLd~owOdOtR)Re,R+tRkRtu}RumRw?dSsil/ UndX_gi!AmeEqu|EshI&dIn+OgOntO,OwnOz&U.2ElNNnyRna)RyTu*:D+tInLaxy~ yMePRa+Rba+Rd&Rl-Rm|SSpTeTh U+Ze3N $NiusN*Nt!Nu(e/u*2O,0AntFtGg!Ng RaffeRlVe_dAn)A*A[IdeImp'ObeOomOryO=OwUe_tDde[LdOdO'RillaSpelSsipV nWn_bA)A(AntApeA[Av.yEatE&IdIefItOc yOupOwUnt_rdE[IdeIltIt?N3M:B.IrLfMm M, NdPpyRb%RdRshR=,TVeWkZ?d3AdAl`ArtAvyD+hogIght~oLmetLpNRo3Dd&Gh~NtPRe/%y5BbyCkeyLdLeLiday~owMeNeyOdPeRnRr%R'Sp.$/TelUrV 5BGeM<Mb!M%Nd*dNgryNtRd!RryRtSb<d3Brid:1EOn0EaEntifyLe2N%e4LLeg$L}[0A+Ita>M&'Mu}Pa@Po'Pro=Pul'0ChCludeComeC*a'DexD-a>Do%Du,ryF<tFl-tF%mHa!H .Iti$Je@JuryMa>N Noc|PutQuiryS<eSe@SideSpi*/$lTa@T e,ToVe,V.eVol=3On0L<dOla>Sue0Em1Ory:CketGu?RZz3AlousAns~yWel9BInKeUr}yY5D+I)MpNg!Ni%Nk/:Ng?oo3EnEpT^upY3CkDD}yNdNgdomSsTT^&TeTt&Wi4EeIfeO{Ow:BBelB%Dd DyKeMpNgua+PtopR+T T(UghUndryVaWWnWsu.Y Zy3Ad AfArnA=Ctu*FtGG$G&dIsu*M#NdNg`NsOp?dSs#Tt Vel3ArB tyBr?yC&'FeFtGhtKeMbM.NkOnQuid/Tt!VeZ?d5AdAnB, C$CkG-NelyNgOpTt yUdUn+VeY$5CkyGga+Mb N?N^Xury3R-s:Ch(eDG-G}tIdIlInJ%KeMm$NNa+Nda>NgoNs]Nu$P!Rb!R^Rg(R(eRketRria+SkSs/ T^T i$ThTrixTt XimumZe3AdowAnAsu*AtCh<-D$DiaLodyLtMb M%yNt]NuRcyR+R.RryShSsa+T$Thod3Dd!DnightLk~]M-NdNimumN%Nu>Rac!Rr%S ySs/akeXXedXtu*5Bi!DelDifyMM|N.%NkeyN, N`OnR$ReRn(gSqu.oTh T]T%Unta(U'VeVie5ChFf(LeLtiplySc!SeumShroomS-/Tu$3Self/ yTh:I=MePk(Rrow/yT]Tu*3ArCkEdGati=G!@I` PhewR=/TTw%kUtr$V WsXt3CeGht5B!I'M(eeOd!Rm$R`SeTab!TeTh(gTi)VelW5C!?Mb R'T:K0EyJe@Li+Scu*S =Ta(Vious0CurE<Tob 0Or1FF Fi)T&2L1Ay0DI=Ymp-0It0CeEI#L(eLy1EnEraIn]Po'T]1An+B.Ch?dD D(?yG<I|Ig($Ph<0Tr-h0H 0Tdo%T TputTside0AlEnEr0NN 0Yg&0/ 0O}:CtDd!GeIrLa)LmNdaNelN-N` P RadeR|RkRrotRtySsT^ThTi|TrolTt nU'VeYm|3A)AnutArAs<tL-<NN$tyNcilOp!Pp Rfe@Rm.Rs#T2O}OtoRa'Ys-$0AnoCn-Ctu*E)GGe#~LotNkO} Pe/olT^Zza_)A}tA,-A>AyEa'Ed+U{UgUn+2EmEtIntL?LeLi)NdNyOlPul?Rt]S.]Ssib!/TatoTt yV tyWd W _@i)Ai'Ed-tEf Epa*Es|EttyEv|I)IdeIm?yIntI%.yIs#Iva>IzeOb!mO)[Odu)Of.OgramOje@Omo>OofOp tyOsp O>@OudOvide2Bl-Dd(g~LpL'Mpk(N^PilPpyR^a'R.yRpo'R'ShTZz!3Ramid:99Al.yAntumArt E,]I{ItIzO>:Bb.Cco#CeCkD?DioIlInI'~yMpN^NdomN+PidReTeTh V&WZ%3AdyAlAs#BelBuildC$lCei=CipeC%dCyc!Du)F!@F%mFu'G]G*tGul?Je@LaxLea'LiefLyMa(Memb M(dMo=Nd NewNtOp&PairPeatPla)P%tQui*ScueSemb!Si,Sour)Sp#'SultTi*T*atTurnUn]Ve$ViewW?d2Y`m0BBb#CeChDeD+F!GhtGidNgOtPp!SkTu$V$V 5AdA,BotBu,CketM<)OfOkieOmSeTa>UghUndU>Y$5Bb DeGLeNNwayR$:DDd!D}[FeIlLadLm#L#LtLu>MeMp!NdTisfyToshiU)Usa+VeY1A!AnA*Att E}HemeHoolI&)I[%sOrp]OutRapRe&RiptRub1AAr^As#AtC#dC*tCt]Cur.yEdEkGm|Le@~M(?Ni%N'Nt&)RiesRvi)Ss]Tt!TupV&_dowAftAllowA*EdEllEriffIeldIftI}IpIv O{OeOotOpOrtOuld O=RimpRugUff!Y0Bl(gCkDeE+GhtGnL|Lk~yLv Mil?Mp!N)NgR&/ Tua>XZe1A>Et^IIllInIrtUll0AbAmEepEnd I)IdeIghtImOg<OtOwUsh0AllArtI!OkeOo`0A{AkeApIffOw0ApCc Ci$CkDaFtL?Ldi LidLut]L=Me#eNgOnRryRtUlUndUpUr)U`0A)A*Ati$AwnEakEci$EedEllEndH eI)Id IkeInIr.L.OilOns%O#OrtOtRayReadR(gY0Ua*UeezeUir*l_b!AdiumAffA+AirsAmpAndArtA>AyEakEelEmEpE*oI{IllIngO{Oma^O}OolOryO=Ra>gyReetRikeR#gRugg!Ud|UffUmb!Y!0Bje@Bm.BwayC)[ChDd&Ff G?G+,ItMm NNnyN'tP PplyP*meReRfa)R+Rpri'RroundR=ySpe@/a(1AllowAmpApArmE?EetIftImIngIt^Ord1MbolMptomRup/em:B!Ck!GIlL|LkNkPeR+tSk/eTtooXi3A^Am~NN<tNnisNtRm/Xt_nkAtEmeEnE%yE*EyIngIsOughtReeRi=RowUmbUnd 0CketDeG LtMb MeNyPRedSsueT!5A,BaccoDayDdl EGe` I!tK&MatoM%rowNeNgueNightOlO`PP-Pp!R^RnadoRtoi'SsT$Uri,W?dW WnY_{AdeAff-Ag-A(Ansf ApAshA=lAyEatEeEndI$IbeI{Igg ImIpOphyOub!U{UeUlyUmpetU,U`Y2BeIt]Mb!NaN}lRkeyRnRt!1El=EntyI)InI,O1PeP-$:5Ly5B*lla0Ab!Awa*C!Cov D DoFairFoldHappyIf%mIqueItIv 'KnownLo{TilUsu$Veil1Da>GradeHoldOnP Set1B<Ge0A+EEdEfulE![U$0Il.y:C<tCuumGueLidL!yL=NNishP%Rious/Ult3H-!L=tNd%Ntu*NueRbRifyRs]RyS'lT <3Ab!Br<tCiousCt%yDeoEw~a+Nta+Ol(Rtu$RusSaS.Su$T$Vid5C$I)IdLc<oLumeTeYa+:GeG#ItLk~LnutNtRfa*RmRri%ShSp/eT VeY3Al`Ap#ArA'lA` BDd(gEk&dIrdLcome/T_!AtEatEelEnE*IpIsp 0DeD`FeLd~NNdowNeNgNkNn Nt ReSdomSeShT}[5LfM<Nd OdOlRdRkRldRryR`_pE{E,!I,I>Ong::Rd3Ar~ow9UUngU`:3BraRo9NeO","0x3c8acc1e7b08d8e76f9fda015ef48dc8c710a73cb7e0f77b2c18a9b5a7adde60")}static wordlist(){return null==qF&&(qF=new QF),qF}}function VF(e){return(1<<e)-1<<8-e&255}function JF(e){return(1<<e)-1&255}function KF(e,t){_S("NFKD"),null==t&&(t=QF.wordlist());const n=t.split(e);bS(n.length%3==0&&n.length>=12&&n.length<=24,"invalid mnemonic length","mnemonic","[ REDACTED ]");const r=new Uint8Array(Math.ceil(11*n.length/8));let i=0;for(let o=0;o<n.length;o++){let e=t.getWordIndex(n[o].normalize("NFKD"));bS(e>=0,`invalid mnemonic word at index ${o}`,"mnemonic","[ REDACTED ]");for(let t=0;t<11;t++)e&1<<10-t&&(r[i>>3]|=1<<7-i%8),i++}const s=32*n.length/3,a=VF(n.length/3);return bS((TS(TC(r.slice(0,s/8)))[0]&a)===(r[r.length-1]&a),"invalid mnemonic checksum","mnemonic","[ REDACTED ]"),CS(r.slice(0,s/8))}function WF(e,t){bS(e.length%4==0&&e.length>=16&&e.length<=32,"invalid entropy size","entropy","[ REDACTED ]"),null==t&&(t=QF.wordlist());const n=[0];let r=11;for(let a=0;a<e.length;a++)r>8?(n[n.length-1]<<=8,n[n.length-1]|=e[a],r-=8):(n[n.length-1]<<=r,n[n.length-1]|=e[a]>>8-r,n.push(e[a]&JF(8-r)),r+=3);const i=e.length/4,s=parseInt(TC(e).substring(2,4),16)&VF(i);return n[n.length-1]<<=i,n[n.length-1]|=s>>8-i,t.join(n.map(e=>t.getWord(e)))}const YF={};class ZF{constructor(e,t,n,r,i){__publicField(this,"phrase"),__publicField(this,"password"),__publicField(this,"wordlist"),__publicField(this,"entropy"),null==r&&(r=""),null==i&&(i=QF.wordlist()),ES(e,YF,"Mnemonic"),dS(this,{phrase:n,password:r,wordlist:i,entropy:t})}computeSeed(){const e=ux("mnemonic"+this.password,"NFKD");return tC(ux(this.phrase,"NFKD"),e,2048,64,"sha512")}static fromPhrase(e,t,n){const r=KF(e,n);return e=WF(TS(r),n),new ZF(YF,r,e,t,n)}static fromEntropy(e,t,n){const r=TS(e,"entropy"),i=WF(r,n);return new ZF(YF,CS(r),i,t,n)}static entropyToPhrase(e,t){return WF(TS(e,"entropy"),t)}static phraseToEntropy(e,t){return KF(e,t)}static isValidMnemonic(e,t){try{return KF(e,t),!0}catch(n){}return!1}}
32
+ /*! MIT License. Copyright 2015-2022 Richard Moore <me@ricmoo.com>. See LICENSE.txt. */var XF,eG,tG,nG=function(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)},rG=function(e,t,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?i.call(e,n):i?i.value=n:t.set(e,n),n};const iG={16:10,24:12,32:14},sG=[1,2,4,8,16,32,64,128,27,54,108,216,171,77,154,47,94,188,99,198,151,53,106,212,179,125,250,239,197,145],aG=[99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22],oG=[82,9,106,213,48,54,165,56,191,64,163,158,129,243,215,251,124,227,57,130,155,47,255,135,52,142,67,68,196,222,233,203,84,123,148,50,166,194,35,61,238,76,149,11,66,250,195,78,8,46,161,102,40,217,36,178,118,91,162,73,109,139,209,37,114,248,246,100,134,104,152,22,212,164,92,204,93,101,182,146,108,112,72,80,253,237,185,218,94,21,70,87,167,141,157,132,144,216,171,0,140,188,211,10,247,228,88,5,184,179,69,6,208,44,30,143,202,63,15,2,193,175,189,3,1,19,138,107,58,145,17,65,79,103,220,234,151,242,207,206,240,180,230,115,150,172,116,34,231,173,53,133,226,249,55,232,28,117,223,110,71,241,26,113,29,41,197,137,111,183,98,14,170,24,190,27,252,86,62,75,198,210,121,32,154,219,192,254,120,205,90,244,31,221,168,51,136,7,199,49,177,18,16,89,39,128,236,95,96,81,127,169,25,181,74,13,45,229,122,159,147,201,156,239,160,224,59,77,174,42,245,176,200,235,187,60,131,83,153,97,23,43,4,126,186,119,214,38,225,105,20,99,85,33,12,125],cG=[3328402341,4168907908,4000806809,4135287693,4294111757,3597364157,3731845041,2445657428,1613770832,33620227,3462883241,1445669757,3892248089,3050821474,1303096294,3967186586,2412431941,528646813,2311702848,4202528135,4026202645,2992200171,2387036105,4226871307,1101901292,3017069671,1604494077,1169141738,597466303,1403299063,3832705686,2613100635,1974974402,3791519004,1033081774,1277568618,1815492186,2118074177,4126668546,2211236943,1748251740,1369810420,3521504564,4193382664,3799085459,2883115123,1647391059,706024767,134480908,2512897874,1176707941,2646852446,806885416,932615841,168101135,798661301,235341577,605164086,461406363,3756188221,3454790438,1311188841,2142417613,3933566367,302582043,495158174,1479289972,874125870,907746093,3698224818,3025820398,1537253627,2756858614,1983593293,3084310113,2108928974,1378429307,3722699582,1580150641,327451799,2790478837,3117535592,0,3253595436,1075847264,3825007647,2041688520,3059440621,3563743934,2378943302,1740553945,1916352843,2487896798,2555137236,2958579944,2244988746,3151024235,3320835882,1336584933,3992714006,2252555205,2588757463,1714631509,293963156,2319795663,3925473552,67240454,4269768577,2689618160,2017213508,631218106,1269344483,2723238387,1571005438,2151694528,93294474,1066570413,563977660,1882732616,4059428100,1673313503,2008463041,2950355573,1109467491,537923632,3858759450,4260623118,3218264685,2177748300,403442708,638784309,3287084079,3193921505,899127202,2286175436,773265209,2479146071,1437050866,4236148354,2050833735,3362022572,3126681063,840505643,3866325909,3227541664,427917720,2655997905,2749160575,1143087718,1412049534,999329963,193497219,2353415882,3354324521,1807268051,672404540,2816401017,3160301282,369822493,2916866934,3688947771,1681011286,1949973070,336202270,2454276571,201721354,1210328172,3093060836,2680341085,3184776046,1135389935,3294782118,965841320,831886756,3554993207,4068047243,3588745010,2345191491,1849112409,3664604599,26054028,2983581028,2622377682,1235855840,3630984372,2891339514,4092916743,3488279077,3395642799,4101667470,1202630377,268961816,1874508501,4034427016,1243948399,1546530418,941366308,1470539505,1941222599,2546386513,3421038627,2715671932,3899946140,1042226977,2521517021,1639824860,227249030,260737669,3765465232,2084453954,1907733956,3429263018,2420656344,100860677,4160157185,470683154,3261161891,1781871967,2924959737,1773779408,394692241,2579611992,974986535,664706745,3655459128,3958962195,731420851,571543859,3530123707,2849626480,126783113,865375399,765172662,1008606754,361203602,3387549984,2278477385,2857719295,1344809080,2782912378,59542671,1503764984,160008576,437062935,1707065306,3622233649,2218934982,3496503480,2185314755,697932208,1512910199,504303377,2075177163,2824099068,1841019862,739644986],AG=[2781242211,2230877308,2582542199,2381740923,234877682,3184946027,2984144751,1418839493,1348481072,50462977,2848876391,2102799147,434634494,1656084439,3863849899,2599188086,1167051466,2636087938,1082771913,2281340285,368048890,3954334041,3381544775,201060592,3963727277,1739838676,4250903202,3930435503,3206782108,4149453988,2531553906,1536934080,3262494647,484572669,2923271059,1783375398,1517041206,1098792767,49674231,1334037708,1550332980,4098991525,886171109,150598129,2481090929,1940642008,1398944049,1059722517,201851908,1385547719,1699095331,1587397571,674240536,2704774806,252314885,3039795866,151914247,908333586,2602270848,1038082786,651029483,1766729511,3447698098,2682942837,454166793,2652734339,1951935532,775166490,758520603,3000790638,4004797018,4217086112,4137964114,1299594043,1639438038,3464344499,2068982057,1054729187,1901997871,2534638724,4121318227,1757008337,0,750906861,1614815264,535035132,3363418545,3988151131,3201591914,1183697867,3647454910,1265776953,3734260298,3566750796,3903871064,1250283471,1807470800,717615087,3847203498,384695291,3313910595,3617213773,1432761139,2484176261,3481945413,283769337,100925954,2180939647,4037038160,1148730428,3123027871,3813386408,4087501137,4267549603,3229630528,2315620239,2906624658,3156319645,1215313976,82966005,3747855548,3245848246,1974459098,1665278241,807407632,451280895,251524083,1841287890,1283575245,337120268,891687699,801369324,3787349855,2721421207,3431482436,959321879,1469301956,4065699751,2197585534,1199193405,2898814052,3887750493,724703513,2514908019,2696962144,2551808385,3516813135,2141445340,1715741218,2119445034,2872807568,2198571144,3398190662,700968686,3547052216,1009259540,2041044702,3803995742,487983883,1991105499,1004265696,1449407026,1316239930,504629770,3683797321,168560134,1816667172,3837287516,1570751170,1857934291,4014189740,2797888098,2822345105,2754712981,936633572,2347923833,852879335,1133234376,1500395319,3084545389,2348912013,1689376213,3533459022,3762923945,3034082412,4205598294,133428468,634383082,2949277029,2398386810,3913789102,403703816,3580869306,2297460856,1867130149,1918643758,607656988,4049053350,3346248884,1368901318,600565992,2090982877,2632479860,557719327,3717614411,3697393085,2249034635,2232388234,2430627952,1115438654,3295786421,2865522278,3633334344,84280067,33027830,303828494,2747425121,1600795957,4188952407,3496589753,2434238086,1486471617,658119965,3106381470,953803233,334231800,3005978776,857870609,3151128937,1890179545,2298973838,2805175444,3056442267,574365214,2450884487,550103529,1233637070,4289353045,2018519080,2057691103,2399374476,4166623649,2148108681,387583245,3664101311,836232934,3330556482,3100665960,3280093505,2955516313,2002398509,287182607,3413881008,4238890068,3597515707,975967766],lG=[1671808611,2089089148,2006576759,2072901243,4061003762,1807603307,1873927791,3310653893,810573872,16974337,1739181671,729634347,4263110654,3613570519,2883997099,1989864566,3393556426,2191335298,3376449993,2106063485,4195741690,1508618841,1204391495,4027317232,2917941677,3563566036,2734514082,2951366063,2629772188,2767672228,1922491506,3227229120,3082974647,4246528509,2477669779,644500518,911895606,1061256767,4144166391,3427763148,878471220,2784252325,3845444069,4043897329,1905517169,3631459288,827548209,356461077,67897348,3344078279,593839651,3277757891,405286936,2527147926,84871685,2595565466,118033927,305538066,2157648768,3795705826,3945188843,661212711,2999812018,1973414517,152769033,2208177539,745822252,439235610,455947803,1857215598,1525593178,2700827552,1391895634,994932283,3596728278,3016654259,695947817,3812548067,795958831,2224493444,1408607827,3513301457,0,3979133421,543178784,4229948412,2982705585,1542305371,1790891114,3410398667,3201918910,961245753,1256100938,1289001036,1491644504,3477767631,3496721360,4012557807,2867154858,4212583931,1137018435,1305975373,861234739,2241073541,1171229253,4178635257,33948674,2139225727,1357946960,1011120188,2679776671,2833468328,1374921297,2751356323,1086357568,2408187279,2460827538,2646352285,944271416,4110742005,3168756668,3066132406,3665145818,560153121,271589392,4279952895,4077846003,3530407890,3444343245,202643468,322250259,3962553324,1608629855,2543990167,1154254916,389623319,3294073796,2817676711,2122513534,1028094525,1689045092,1575467613,422261273,1939203699,1621147744,2174228865,1339137615,3699352540,577127458,712922154,2427141008,2290289544,1187679302,3995715566,3100863416,339486740,3732514782,1591917662,186455563,3681988059,3762019296,844522546,978220090,169743370,1239126601,101321734,611076132,1558493276,3260915650,3547250131,2901361580,1655096418,2443721105,2510565781,3828863972,2039214713,3878868455,3359869896,928607799,1840765549,2374762893,3580146133,1322425422,2850048425,1823791212,1459268694,4094161908,3928346602,1706019429,2056189050,2934523822,135794696,3134549946,2022240376,628050469,779246638,472135708,2800834470,3032970164,3327236038,3894660072,3715932637,1956440180,522272287,1272813131,3185336765,2340818315,2323976074,1888542832,1044544574,3049550261,1722469478,1222152264,50660867,4127324150,236067854,1638122081,895445557,1475980887,3117443513,2257655686,3243809217,489110045,2662934430,3778599393,4162055160,2561878936,288563729,1773916777,3648039385,2391345038,2493985684,2612407707,505560094,2274497927,3911240169,3460925390,1442818645,678973480,3749357023,2358182796,2717407649,2306869641,219617805,3218761151,3862026214,1120306242,1756942440,1103331905,2578459033,762796589,252780047,2966125488,1425844308,3151392187,372911126],fG=[1667474886,2088535288,2004326894,2071694838,4075949567,1802223062,1869591006,3318043793,808472672,16843522,1734846926,724270422,4278065639,3621216949,2880169549,1987484396,3402253711,2189597983,3385409673,2105378810,4210693615,1499065266,1195886990,4042263547,2913856577,3570689971,2728590687,2947541573,2627518243,2762274643,1920112356,3233831835,3082273397,4261223649,2475929149,640051788,909531756,1061110142,4160160501,3435941763,875846760,2779116625,3857003729,4059105529,1903268834,3638064043,825316194,353713962,67374088,3351728789,589522246,3284360861,404236336,2526454071,84217610,2593830191,117901582,303183396,2155911963,3806477791,3958056653,656894286,2998062463,1970642922,151591698,2206440989,741110872,437923380,454765878,1852748508,1515908788,2694904667,1381168804,993742198,3604373943,3014905469,690584402,3823320797,791638366,2223281939,1398011302,3520161977,0,3991743681,538992704,4244381667,2981218425,1532751286,1785380564,3419096717,3200178535,960056178,1246420628,1280103576,1482221744,3486468741,3503319995,4025428677,2863326543,4227536621,1128514950,1296947098,859002214,2240123921,1162203018,4193849577,33687044,2139062782,1347481760,1010582648,2678045221,2829640523,1364325282,2745433693,1077985408,2408548869,2459086143,2644360225,943212656,4126475505,3166494563,3065430391,3671750063,555836226,269496352,4294908645,4092792573,3537006015,3452783745,202118168,320025894,3974901699,1600119230,2543297077,1145359496,387397934,3301201811,2812801621,2122220284,1027426170,1684319432,1566435258,421079858,1936954854,1616945344,2172753945,1330631070,3705438115,572679748,707427924,2425400123,2290647819,1179044492,4008585671,3099120491,336870440,3739122087,1583276732,185277718,3688593069,3772791771,842159716,976899700,168435220,1229577106,101059084,606366792,1549591736,3267517855,3553849021,2897014595,1650632388,2442242105,2509612081,3840161747,2038008818,3890688725,3368567691,926374254,1835907034,2374863873,3587531953,1313788572,2846482505,1819063512,1448540844,4109633523,3941213647,1701162954,2054852340,2930698567,134748176,3132806511,2021165296,623210314,774795868,471606328,2795958615,3031746419,3334885783,3907527627,3722280097,1953799400,522133822,1263263126,3183336545,2341176845,2324333839,1886425312,1044267644,3048588401,1718004428,1212733584,50529542,4143317495,235803164,1633788866,892690282,1465383342,3115962473,2256965911,3250673817,488449850,2661202215,3789633753,4177007595,2560144171,286339874,1768537042,3654906025,2391705863,2492770099,2610673197,505291324,2273808917,3924369609,3469625735,1431699370,673740880,3755965093,2358021891,2711746649,2307489801,218961690,3217021541,3873845719,1111672452,1751693520,1094828930,2576986153,757954394,252645662,2964376443,1414855848,3149649517,370555436],uG=[1374988112,2118214995,437757123,975658646,1001089995,530400753,2902087851,1273168787,540080725,2910219766,2295101073,4110568485,1340463100,3307916247,641025152,3043140495,3736164937,632953703,1172967064,1576976609,3274667266,2169303058,2370213795,1809054150,59727847,361929877,3211623147,2505202138,3569255213,1484005843,1239443753,2395588676,1975683434,4102977912,2572697195,666464733,3202437046,4035489047,3374361702,2110667444,1675577880,3843699074,2538681184,1649639237,2976151520,3144396420,4269907996,4178062228,1883793496,2403728665,2497604743,1383856311,2876494627,1917518562,3810496343,1716890410,3001755655,800440835,2261089178,3543599269,807962610,599762354,33778362,3977675356,2328828971,2809771154,4077384432,1315562145,1708848333,101039829,3509871135,3299278474,875451293,2733856160,92987698,2767645557,193195065,1080094634,1584504582,3178106961,1042385657,2531067453,3711829422,1306967366,2438237621,1908694277,67556463,1615861247,429456164,3602770327,2302690252,1742315127,2968011453,126454664,3877198648,2043211483,2709260871,2084704233,4169408201,0,159417987,841739592,504459436,1817866830,4245618683,260388950,1034867998,908933415,168810852,1750902305,2606453969,607530554,202008497,2472011535,3035535058,463180190,2160117071,1641816226,1517767529,470948374,3801332234,3231722213,1008918595,303765277,235474187,4069246893,766945465,337553864,1475418501,2943682380,4003061179,2743034109,4144047775,1551037884,1147550661,1543208500,2336434550,3408119516,3069049960,3102011747,3610369226,1113818384,328671808,2227573024,2236228733,3535486456,2935566865,3341394285,496906059,3702665459,226906860,2009195472,733156972,2842737049,294930682,1206477858,2835123396,2700099354,1451044056,573804783,2269728455,3644379585,2362090238,2564033334,2801107407,2776292904,3669462566,1068351396,742039012,1350078989,1784663195,1417561698,4136440770,2430122216,775550814,2193862645,2673705150,1775276924,1876241833,3475313331,3366754619,270040487,3902563182,3678124923,3441850377,1851332852,3969562369,2203032232,3868552805,2868897406,566021896,4011190502,3135740889,1248802510,3936291284,699432150,832877231,708780849,3332740144,899835584,1951317047,4236429990,3767586992,866637845,4043610186,1106041591,2144161806,395441711,1984812685,1139781709,3433712980,3835036895,2664543715,1282050075,3240894392,1181045119,2640243204,25965917,4203181171,4211818798,3009879386,2463879762,3910161971,1842759443,2597806476,933301370,1509430414,3943906441,3467192302,3076639029,3776767469,2051518780,2631065433,1441952575,404016761,1942435775,1408749034,1610459739,3745345300,2017778566,3400528769,3110650942,941896748,3265478751,371049330,3168937228,675039627,4279080257,967311729,135050206,3635733660,1683407248,2076935265,3576870512,1215061108,3501741890],dG=[1347548327,1400783205,3273267108,2520393566,3409685355,4045380933,2880240216,2471224067,1428173050,4138563181,2441661558,636813900,4233094615,3620022987,2149987652,2411029155,1239331162,1730525723,2554718734,3781033664,46346101,310463728,2743944855,3328955385,3875770207,2501218972,3955191162,3667219033,768917123,3545789473,692707433,1150208456,1786102409,2029293177,1805211710,3710368113,3065962831,401639597,1724457132,3028143674,409198410,2196052529,1620529459,1164071807,3769721975,2226875310,486441376,2499348523,1483753576,428819965,2274680428,3075636216,598438867,3799141122,1474502543,711349675,129166120,53458370,2592523643,2782082824,4063242375,2988687269,3120694122,1559041666,730517276,2460449204,4042459122,2706270690,3446004468,3573941694,533804130,2328143614,2637442643,2695033685,839224033,1973745387,957055980,2856345839,106852767,1371368976,4181598602,1033297158,2933734917,1179510461,3046200461,91341917,1862534868,4284502037,605657339,2547432937,3431546947,2003294622,3182487618,2282195339,954669403,3682191598,1201765386,3917234703,3388507166,0,2198438022,1211247597,2887651696,1315723890,4227665663,1443857720,507358933,657861945,1678381017,560487590,3516619604,975451694,2970356327,261314535,3535072918,2652609425,1333838021,2724322336,1767536459,370938394,182621114,3854606378,1128014560,487725847,185469197,2918353863,3106780840,3356761769,2237133081,1286567175,3152976349,4255350624,2683765030,3160175349,3309594171,878443390,1988838185,3704300486,1756818940,1673061617,3403100636,272786309,1075025698,545572369,2105887268,4174560061,296679730,1841768865,1260232239,4091327024,3960309330,3497509347,1814803222,2578018489,4195456072,575138148,3299409036,446754879,3629546796,4011996048,3347532110,3252238545,4270639778,915985419,3483825537,681933534,651868046,2755636671,3828103837,223377554,2607439820,1649704518,3270937875,3901806776,1580087799,4118987695,3198115200,2087309459,2842678573,3016697106,1003007129,2802849917,1860738147,2077965243,164439672,4100872472,32283319,2827177882,1709610350,2125135846,136428751,3874428392,3652904859,3460984630,3572145929,3593056380,2939266226,824852259,818324884,3224740454,930369212,2801566410,2967507152,355706840,1257309336,4148292826,243256656,790073846,2373340630,1296297904,1422699085,3756299780,3818836405,457992840,3099667487,2135319889,77422314,1560382517,1945798516,788204353,1521706781,1385356242,870912086,325965383,2358957921,2050466060,2388260884,2313884476,4006521127,901210569,3990953189,1014646705,1503449823,1062597235,2031621326,3212035895,3931371469,1533017514,350174575,2256028891,2177544179,1052338372,741876788,1606591296,1914052035,213705253,2334669897,1107234197,1899603969,3725069491,2631447780,2422494913,1635502980,1893020342,1950903388,1120974935],hG=[2807058932,1699970625,2764249623,1586903591,1808481195,1173430173,1487645946,59984867,4199882800,1844882806,1989249228,1277555970,3623636965,3419915562,1149249077,2744104290,1514790577,459744698,244860394,3235995134,1963115311,4027744588,2544078150,4190530515,1608975247,2627016082,2062270317,1507497298,2200818878,567498868,1764313568,3359936201,2305455554,2037970062,1047239e3,1910319033,1337376481,2904027272,2892417312,984907214,1243112415,830661914,861968209,2135253587,2011214180,2927934315,2686254721,731183368,1750626376,4246310725,1820824798,4172763771,3542330227,48394827,2404901663,2871682645,671593195,3254988725,2073724613,145085239,2280796200,2779915199,1790575107,2187128086,472615631,3029510009,4075877127,3802222185,4107101658,3201631749,1646252340,4270507174,1402811438,1436590835,3778151818,3950355702,3963161475,4020912224,2667994737,273792366,2331590177,104699613,95345982,3175501286,2377486676,1560637892,3564045318,369057872,4213447064,3919042237,1137477952,2658625497,1119727848,2340947849,1530455833,4007360968,172466556,266959938,516552836,0,2256734592,3980931627,1890328081,1917742170,4294704398,945164165,3575528878,958871085,3647212047,2787207260,1423022939,775562294,1739656202,3876557655,2530391278,2443058075,3310321856,547512796,1265195639,437656594,3121275539,719700128,3762502690,387781147,218828297,3350065803,2830708150,2848461854,428169201,122466165,3720081049,1627235199,648017665,4122762354,1002783846,2117360635,695634755,3336358691,4234721005,4049844452,3704280881,2232435299,574624663,287343814,612205898,1039717051,840019705,2708326185,793451934,821288114,1391201670,3822090177,376187827,3113855344,1224348052,1679968233,2361698556,1058709744,752375421,2431590963,1321699145,3519142200,2734591178,188127444,2177869557,3727205754,2384911031,3215212461,2648976442,2450346104,3432737375,1180849278,331544205,3102249176,4150144569,2952102595,2159976285,2474404304,766078933,313773861,2570832044,2108100632,1668212892,3145456443,2013908262,418672217,3070356634,2594734927,1852171925,3867060991,3473416636,3907448597,2614737639,919489135,164948639,2094410160,2997825956,590424639,2486224549,1723872674,3157750862,3399941250,3501252752,3625268135,2555048196,3673637356,1343127501,4130281361,3599595085,2957853679,1297403050,81781910,3051593425,2283490410,532201772,1367295589,3926170974,895287692,1953757831,1093597963,492483431,3528626907,1446242576,1192455638,1636604631,209336225,344873464,1015671571,669961897,3375740769,3857572124,2973530695,3747192018,1933530610,3464042516,935293895,3454686199,2858115069,1863638845,3683022916,4085369519,3292445032,875313188,1080017571,3279033885,621591778,1233856572,2504130317,24197544,3017672716,3835484340,3247465558,2220981195,3060847922,1551124588,1463996600],pG=[4104605777,1097159550,396673818,660510266,2875968315,2638606623,4200115116,3808662347,821712160,1986918061,3430322568,38544885,3856137295,718002117,893681702,1654886325,2975484382,3122358053,3926825029,4274053469,796197571,1290801793,1184342925,3556361835,2405426947,2459735317,1836772287,1381620373,3196267988,1948373848,3764988233,3385345166,3263785589,2390325492,1480485785,3111247143,3780097726,2293045232,548169417,3459953789,3746175075,439452389,1362321559,1400849762,1685577905,1806599355,2174754046,137073913,1214797936,1174215055,3731654548,2079897426,1943217067,1258480242,529487843,1437280870,3945269170,3049390895,3313212038,923313619,679998e3,3215307299,57326082,377642221,3474729866,2041877159,133361907,1776460110,3673476453,96392454,878845905,2801699524,777231668,4082475170,2330014213,4142626212,2213296395,1626319424,1906247262,1846563261,562755902,3708173718,1040559837,3871163981,1418573201,3294430577,114585348,1343618912,2566595609,3186202582,1078185097,3651041127,3896688048,2307622919,425408743,3371096953,2081048481,1108339068,2216610296,0,2156299017,736970802,292596766,1517440620,251657213,2235061775,2933202493,758720310,265905162,1554391400,1532285339,908999204,174567692,1474760595,4002861748,2610011675,3234156416,3693126241,2001430874,303699484,2478443234,2687165888,585122620,454499602,151849742,2345119218,3064510765,514443284,4044981591,1963412655,2581445614,2137062819,19308535,1928707164,1715193156,4219352155,1126790795,600235211,3992742070,3841024952,836553431,1669664834,2535604243,3323011204,1243905413,3141400786,4180808110,698445255,2653899549,2989552604,2253581325,3252932727,3004591147,1891211689,2487810577,3915653703,4237083816,4030667424,2100090966,865136418,1229899655,953270745,3399679628,3557504664,4118925222,2061379749,3079546586,2915017791,983426092,2022837584,1607244650,2118541908,2366882550,3635996816,972512814,3283088770,1568718495,3499326569,3576539503,621982671,2895723464,410887952,2623762152,1002142683,645401037,1494807662,2595684844,1335535747,2507040230,4293295786,3167684641,367585007,3885750714,1865862730,2668221674,2960971305,2763173681,1059270954,2777952454,2724642869,1320957812,2194319100,2429595872,2815956275,77089521,3973773121,3444575871,2448830231,1305906550,4021308739,2857194700,2516901860,3518358430,1787304780,740276417,1699839814,1592394909,2352307457,2272556026,188821243,1729977011,3687994002,274084841,3594982253,3613494426,2701949495,4162096729,322734571,2837966542,1640576439,484830689,1202797690,3537852828,4067639125,349075736,3342319475,4157467219,4255800159,1030690015,1155237496,2951971274,1757691577,607398968,2738905026,499347990,3794078908,1011452712,227885567,2818666809,213114376,3034881240,1455525988,3414450555,850817237,1817998408,3092726480],mG=[0,235474187,470948374,303765277,941896748,908933415,607530554,708780849,1883793496,2118214995,1817866830,1649639237,1215061108,1181045119,1417561698,1517767529,3767586992,4003061179,4236429990,4069246893,3635733660,3602770327,3299278474,3400528769,2430122216,2664543715,2362090238,2193862645,2835123396,2801107407,3035535058,3135740889,3678124923,3576870512,3341394285,3374361702,3810496343,3977675356,4279080257,4043610186,2876494627,2776292904,3076639029,3110650942,2472011535,2640243204,2403728665,2169303058,1001089995,899835584,666464733,699432150,59727847,226906860,530400753,294930682,1273168787,1172967064,1475418501,1509430414,1942435775,2110667444,1876241833,1641816226,2910219766,2743034109,2976151520,3211623147,2505202138,2606453969,2302690252,2269728455,3711829422,3543599269,3240894392,3475313331,3843699074,3943906441,4178062228,4144047775,1306967366,1139781709,1374988112,1610459739,1975683434,2076935265,1775276924,1742315127,1034867998,866637845,566021896,800440835,92987698,193195065,429456164,395441711,1984812685,2017778566,1784663195,1683407248,1315562145,1080094634,1383856311,1551037884,101039829,135050206,437757123,337553864,1042385657,807962610,573804783,742039012,2531067453,2564033334,2328828971,2227573024,2935566865,2700099354,3001755655,3168937228,3868552805,3902563182,4203181171,4102977912,3736164937,3501741890,3265478751,3433712980,1106041591,1340463100,1576976609,1408749034,2043211483,2009195472,1708848333,1809054150,832877231,1068351396,766945465,599762354,159417987,126454664,361929877,463180190,2709260871,2943682380,3178106961,3009879386,2572697195,2538681184,2236228733,2336434550,3509871135,3745345300,3441850377,3274667266,3910161971,3877198648,4110568485,4211818798,2597806476,2497604743,2261089178,2295101073,2733856160,2902087851,3202437046,2968011453,3936291284,3835036895,4136440770,4169408201,3535486456,3702665459,3467192302,3231722213,2051518780,1951317047,1716890410,1750902305,1113818384,1282050075,1584504582,1350078989,168810852,67556463,371049330,404016761,841739592,1008918595,775550814,540080725,3969562369,3801332234,4035489047,4269907996,3569255213,3669462566,3366754619,3332740144,2631065433,2463879762,2160117071,2395588676,2767645557,2868897406,3102011747,3069049960,202008497,33778362,270040487,504459436,875451293,975658646,675039627,641025152,2084704233,1917518562,1615861247,1851332852,1147550661,1248802510,1484005843,1451044056,933301370,967311729,733156972,632953703,260388950,25965917,328671808,496906059,1206477858,1239443753,1543208500,1441952575,2144161806,1908694277,1675577880,1842759443,3610369226,3644379585,3408119516,3307916247,4011190502,3776767469,4077384432,4245618683,2809771154,2842737049,3144396420,3043140495,2673705150,2438237621,2203032232,2370213795],yG=[0,185469197,370938394,487725847,741876788,657861945,975451694,824852259,1483753576,1400783205,1315723890,1164071807,1950903388,2135319889,1649704518,1767536459,2967507152,3152976349,2801566410,2918353863,2631447780,2547432937,2328143614,2177544179,3901806776,3818836405,4270639778,4118987695,3299409036,3483825537,3535072918,3652904859,2077965243,1893020342,1841768865,1724457132,1474502543,1559041666,1107234197,1257309336,598438867,681933534,901210569,1052338372,261314535,77422314,428819965,310463728,3409685355,3224740454,3710368113,3593056380,3875770207,3960309330,4045380933,4195456072,2471224067,2554718734,2237133081,2388260884,3212035895,3028143674,2842678573,2724322336,4138563181,4255350624,3769721975,3955191162,3667219033,3516619604,3431546947,3347532110,2933734917,2782082824,3099667487,3016697106,2196052529,2313884476,2499348523,2683765030,1179510461,1296297904,1347548327,1533017514,1786102409,1635502980,2087309459,2003294622,507358933,355706840,136428751,53458370,839224033,957055980,605657339,790073846,2373340630,2256028891,2607439820,2422494913,2706270690,2856345839,3075636216,3160175349,3573941694,3725069491,3273267108,3356761769,4181598602,4063242375,4011996048,3828103837,1033297158,915985419,730517276,545572369,296679730,446754879,129166120,213705253,1709610350,1860738147,1945798516,2029293177,1239331162,1120974935,1606591296,1422699085,4148292826,4233094615,3781033664,3931371469,3682191598,3497509347,3446004468,3328955385,2939266226,2755636671,3106780840,2988687269,2198438022,2282195339,2501218972,2652609425,1201765386,1286567175,1371368976,1521706781,1805211710,1620529459,2105887268,1988838185,533804130,350174575,164439672,46346101,870912086,954669403,636813900,788204353,2358957921,2274680428,2592523643,2441661558,2695033685,2880240216,3065962831,3182487618,3572145929,3756299780,3270937875,3388507166,4174560061,4091327024,4006521127,3854606378,1014646705,930369212,711349675,560487590,272786309,457992840,106852767,223377554,1678381017,1862534868,1914052035,2031621326,1211247597,1128014560,1580087799,1428173050,32283319,182621114,401639597,486441376,768917123,651868046,1003007129,818324884,1503449823,1385356242,1333838021,1150208456,1973745387,2125135846,1673061617,1756818940,2970356327,3120694122,2802849917,2887651696,2637442643,2520393566,2334669897,2149987652,3917234703,3799141122,4284502037,4100872472,3309594171,3460984630,3545789473,3629546796,2050466060,1899603969,1814803222,1730525723,1443857720,1560382517,1075025698,1260232239,575138148,692707433,878443390,1062597235,243256656,91341917,409198410,325965383,3403100636,3252238545,3704300486,3620022987,3874428392,3990953189,4042459122,4227665663,2460449204,2578018489,2226875310,2411029155,3198115200,3046200461,2827177882,2743944855],gG=[0,218828297,437656594,387781147,875313188,958871085,775562294,590424639,1750626376,1699970625,1917742170,2135253587,1551124588,1367295589,1180849278,1265195639,3501252752,3720081049,3399941250,3350065803,3835484340,3919042237,4270507174,4085369519,3102249176,3051593425,2734591178,2952102595,2361698556,2177869557,2530391278,2614737639,3145456443,3060847922,2708326185,2892417312,2404901663,2187128086,2504130317,2555048196,3542330227,3727205754,3375740769,3292445032,3876557655,3926170974,4246310725,4027744588,1808481195,1723872674,1910319033,2094410160,1608975247,1391201670,1173430173,1224348052,59984867,244860394,428169201,344873464,935293895,984907214,766078933,547512796,1844882806,1627235199,2011214180,2062270317,1507497298,1423022939,1137477952,1321699145,95345982,145085239,532201772,313773861,830661914,1015671571,731183368,648017665,3175501286,2957853679,2807058932,2858115069,2305455554,2220981195,2474404304,2658625497,3575528878,3625268135,3473416636,3254988725,3778151818,3963161475,4213447064,4130281361,3599595085,3683022916,3432737375,3247465558,3802222185,4020912224,4172763771,4122762354,3201631749,3017672716,2764249623,2848461854,2331590177,2280796200,2431590963,2648976442,104699613,188127444,472615631,287343814,840019705,1058709744,671593195,621591778,1852171925,1668212892,1953757831,2037970062,1514790577,1463996600,1080017571,1297403050,3673637356,3623636965,3235995134,3454686199,4007360968,3822090177,4107101658,4190530515,2997825956,3215212461,2830708150,2779915199,2256734592,2340947849,2627016082,2443058075,172466556,122466165,273792366,492483431,1047239e3,861968209,612205898,695634755,1646252340,1863638845,2013908262,1963115311,1446242576,1530455833,1277555970,1093597963,1636604631,1820824798,2073724613,1989249228,1436590835,1487645946,1337376481,1119727848,164948639,81781910,331544205,516552836,1039717051,821288114,669961897,719700128,2973530695,3157750862,2871682645,2787207260,2232435299,2283490410,2667994737,2450346104,3647212047,3564045318,3279033885,3464042516,3980931627,3762502690,4150144569,4199882800,3070356634,3121275539,2904027272,2686254721,2200818878,2384911031,2570832044,2486224549,3747192018,3528626907,3310321856,3359936201,3950355702,3867060991,4049844452,4234721005,1739656202,1790575107,2108100632,1890328081,1402811438,1586903591,1233856572,1149249077,266959938,48394827,369057872,418672217,1002783846,919489135,567498868,752375421,209336225,24197544,376187827,459744698,945164165,895287692,574624663,793451934,1679968233,1764313568,2117360635,1933530610,1343127501,1560637892,1243112415,1192455638,3704280881,3519142200,3336358691,3419915562,3907448597,3857572124,4075877127,4294704398,3029510009,3113855344,2927934315,2744104290,2159976285,2377486676,2594734927,2544078150],bG=[0,151849742,303699484,454499602,607398968,758720310,908999204,1059270954,1214797936,1097159550,1517440620,1400849762,1817998408,1699839814,2118541908,2001430874,2429595872,2581445614,2194319100,2345119218,3034881240,3186202582,2801699524,2951971274,3635996816,3518358430,3399679628,3283088770,4237083816,4118925222,4002861748,3885750714,1002142683,850817237,698445255,548169417,529487843,377642221,227885567,77089521,1943217067,2061379749,1640576439,1757691577,1474760595,1592394909,1174215055,1290801793,2875968315,2724642869,3111247143,2960971305,2405426947,2253581325,2638606623,2487810577,3808662347,3926825029,4044981591,4162096729,3342319475,3459953789,3576539503,3693126241,1986918061,2137062819,1685577905,1836772287,1381620373,1532285339,1078185097,1229899655,1040559837,923313619,740276417,621982671,439452389,322734571,137073913,19308535,3871163981,4021308739,4104605777,4255800159,3263785589,3414450555,3499326569,3651041127,2933202493,2815956275,3167684641,3049390895,2330014213,2213296395,2566595609,2448830231,1305906550,1155237496,1607244650,1455525988,1776460110,1626319424,2079897426,1928707164,96392454,213114376,396673818,514443284,562755902,679998e3,865136418,983426092,3708173718,3557504664,3474729866,3323011204,4180808110,4030667424,3945269170,3794078908,2507040230,2623762152,2272556026,2390325492,2975484382,3092726480,2738905026,2857194700,3973773121,3856137295,4274053469,4157467219,3371096953,3252932727,3673476453,3556361835,2763173681,2915017791,3064510765,3215307299,2156299017,2307622919,2459735317,2610011675,2081048481,1963412655,1846563261,1729977011,1480485785,1362321559,1243905413,1126790795,878845905,1030690015,645401037,796197571,274084841,425408743,38544885,188821243,3613494426,3731654548,3313212038,3430322568,4082475170,4200115116,3780097726,3896688048,2668221674,2516901860,2366882550,2216610296,3141400786,2989552604,2837966542,2687165888,1202797690,1320957812,1437280870,1554391400,1669664834,1787304780,1906247262,2022837584,265905162,114585348,499347990,349075736,736970802,585122620,972512814,821712160,2595684844,2478443234,2293045232,2174754046,3196267988,3079546586,2895723464,2777952454,3537852828,3687994002,3234156416,3385345166,4142626212,4293295786,3841024952,3992742070,174567692,57326082,410887952,292596766,777231668,660510266,1011452712,893681702,1108339068,1258480242,1343618912,1494807662,1715193156,1865862730,1948373848,2100090966,2701949495,2818666809,3004591147,3122358053,2235061775,2352307457,2535604243,2653899549,3915653703,3764988233,4219352155,4067639125,3444575871,3294430577,3746175075,3594982253,836553431,953270745,600235211,718002117,367585007,484830689,133361907,251657213,2041877159,1891211689,1806599355,1654886325,1568718495,1418573201,1335535747,1184342925];function wG(e){const t=[];for(let n=0;n<e.length;n+=4)t.push(e[n]<<24|e[n+1]<<16|e[n+2]<<8|e[n+3]);return t}class vG{get key(){return nG(this,XF,"f").slice()}constructor(e){if(XF.set(this,void 0),eG.set(this,void 0),tG.set(this,void 0),!(this instanceof vG))throw Error("AES must be instanitated with `new`");rG(this,XF,new Uint8Array(e),"f");const t=iG[this.key.length];if(null==t)throw new TypeError("invalid key size (must be 16, 24 or 32 bytes)");rG(this,tG,[],"f"),rG(this,eG,[],"f");for(let A=0;A<=t;A++)nG(this,tG,"f").push([0,0,0,0]),nG(this,eG,"f").push([0,0,0,0]);const n=4*(t+1),r=this.key.length/4,i=wG(this.key);let s;for(let A=0;A<r;A++)s=A>>2,nG(this,tG,"f")[s][A%4]=i[A],nG(this,eG,"f")[t-s][A%4]=i[A];let a,o=0,c=r;for(;c<n;){if(a=i[r-1],i[0]^=aG[a>>16&255]<<24^aG[a>>8&255]<<16^aG[255&a]<<8^aG[a>>24&255]^sG[o]<<24,o+=1,8!=r)for(let t=1;t<r;t++)i[t]^=i[t-1];else{for(let e=1;e<r/2;e++)i[e]^=i[e-1];a=i[r/2-1],i[r/2]^=aG[255&a]^aG[a>>8&255]<<8^aG[a>>16&255]<<16^aG[a>>24&255]<<24;for(let e=r/2+1;e<r;e++)i[e]^=i[e-1]}let e,s,A=0;for(;A<r&&c<n;)e=c>>2,s=c%4,nG(this,tG,"f")[e][s]=i[A],nG(this,eG,"f")[t-e][s]=i[A++],c++}for(let A=1;A<t;A++)for(let e=0;e<4;e++)a=nG(this,eG,"f")[A][e],nG(this,eG,"f")[A][e]=mG[a>>24&255]^yG[a>>16&255]^gG[a>>8&255]^bG[255&a]}encrypt(e){if(16!=e.length)throw new TypeError("invalid plaintext size (must be 16 bytes)");const t=nG(this,tG,"f").length-1,n=[0,0,0,0];let r=wG(e);for(let a=0;a<4;a++)r[a]^=nG(this,tG,"f")[0][a];for(let a=1;a<t;a++){for(let e=0;e<4;e++)n[e]=cG[r[e]>>24&255]^AG[r[(e+1)%4]>>16&255]^lG[r[(e+2)%4]>>8&255]^fG[255&r[(e+3)%4]]^nG(this,tG,"f")[a][e];r=n.slice()}const i=new Uint8Array(16);let s=0;for(let a=0;a<4;a++)s=nG(this,tG,"f")[t][a],i[4*a]=255&(aG[r[a]>>24&255]^s>>24),i[4*a+1]=255&(aG[r[(a+1)%4]>>16&255]^s>>16),i[4*a+2]=255&(aG[r[(a+2)%4]>>8&255]^s>>8),i[4*a+3]=255&(aG[255&r[(a+3)%4]]^s);return i}decrypt(e){if(16!=e.length)throw new TypeError("invalid ciphertext size (must be 16 bytes)");const t=nG(this,eG,"f").length-1,n=[0,0,0,0];let r=wG(e);for(let a=0;a<4;a++)r[a]^=nG(this,eG,"f")[0][a];for(let a=1;a<t;a++){for(let e=0;e<4;e++)n[e]=uG[r[e]>>24&255]^dG[r[(e+3)%4]>>16&255]^hG[r[(e+2)%4]>>8&255]^pG[255&r[(e+1)%4]]^nG(this,eG,"f")[a][e];r=n.slice()}const i=new Uint8Array(16);let s=0;for(let a=0;a<4;a++)s=nG(this,eG,"f")[t][a],i[4*a]=255&(oG[r[a]>>24&255]^s>>24),i[4*a+1]=255&(oG[r[(a+3)%4]>>16&255]^s>>16),i[4*a+2]=255&(oG[r[(a+2)%4]>>8&255]^s>>8),i[4*a+3]=255&(oG[255&r[(a+1)%4]]^s);return i}}XF=new WeakMap,eG=new WeakMap,tG=new WeakMap;class _G{constructor(e,t,n){if(n&&!(this instanceof n))throw new Error(`${e} must be instantiated with "new"`);Object.defineProperties(this,{aes:{enumerable:!0,value:new vG(t)},name:{enumerable:!0,value:e}})}}var EG,kG,TG=function(e,t,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?i.call(e,n):i?i.value=n:t.set(e,n),n},SG=function(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)};class xG extends _G{constructor(e,t){if(super("ECC",e,xG),EG.set(this,void 0),kG.set(this,void 0),t){if(t.length%16)throw new TypeError("invalid iv size (must be 16 bytes)");TG(this,EG,new Uint8Array(t),"f")}else TG(this,EG,new Uint8Array(16),"f");TG(this,kG,this.iv,"f")}get iv(){return new Uint8Array(SG(this,EG,"f"))}encrypt(e){if(e.length%16)throw new TypeError("invalid plaintext size (must be multiple of 16 bytes)");const t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=16){for(let t=0;t<16;t++)SG(this,kG,"f")[t]^=e[n+t];TG(this,kG,this.aes.encrypt(SG(this,kG,"f")),"f"),t.set(SG(this,kG,"f"),n)}return t}decrypt(e){if(e.length%16)throw new TypeError("invalid ciphertext size (must be multiple of 16 bytes)");const t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=16){const r=this.aes.decrypt(e.subarray(n,n+16));for(let i=0;i<16;i++)t[n+i]=r[i]^SG(this,kG,"f")[i],SG(this,kG,"f")[i]=e[n+i]}return t}}EG=new WeakMap,kG=new WeakMap;var IG,PG,CG,NG=function(e,t,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?i.call(e,n):i?i.value=n:t.set(e,n),n},OG=function(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)};class RG extends _G{constructor(e,t){super("CTR",e,RG),IG.set(this,void 0),PG.set(this,void 0),CG.set(this,void 0),NG(this,CG,new Uint8Array(16),"f"),OG(this,CG,"f").fill(0),NG(this,IG,OG(this,CG,"f"),"f"),NG(this,PG,16,"f"),null==t&&(t=1),"number"==typeof t?this.setCounterValue(t):this.setCounterBytes(t)}get counter(){return new Uint8Array(OG(this,CG,"f"))}setCounterValue(e){if(!Number.isInteger(e)||e<0||e>Number.MAX_SAFE_INTEGER)throw new TypeError("invalid counter initial integer value");for(let t=15;t>=0;--t)OG(this,CG,"f")[t]=e%256,e=Math.floor(e/256)}setCounterBytes(e){if(16!==e.length)throw new TypeError("invalid counter initial Uint8Array value length");OG(this,CG,"f").set(e)}increment(){for(let e=15;e>=0;e--){if(255!==OG(this,CG,"f")[e]){OG(this,CG,"f")[e]++;break}OG(this,CG,"f")[e]=0}}encrypt(e){var t,n;const r=new Uint8Array(e);for(let i=0;i<r.length;i++)16===OG(this,PG,"f")&&(NG(this,IG,this.aes.encrypt(OG(this,CG,"f")),"f"),NG(this,PG,0,"f"),this.increment()),r[i]^=OG(this,IG,"f")[(NG(this,PG,(n=OG(this,PG,"f"),t=n++,n),"f"),t)];return r}decrypt(e){return this.encrypt(e)}}function BG(e){return"string"!=typeof e||e.startsWith("0x")||(e="0x"+e),SS(e)}function MG(e,t){for(e=String(e);e.length<t;)e="0"+e;return e}function $G(e){return"string"==typeof e?ux(e,"NFKC"):SS(e)}function DG(e,t){const n=t.match(/^([a-z0-9$_.-]*)(:([a-z]+))?(!)?$/i);bS(null!=n,"invalid path","path",t);const r=n[1],i=n[3],s="!"===n[4];let a=e;for(const o of r.toLowerCase().split(".")){if(Array.isArray(a)){if(!o.match(/^[0-9]+$/))break;a=a[parseInt(o)]}else if("object"==typeof a){let e=null;for(const t in a)if(t.toLowerCase()===o){e=a[t];break}a=e}else a=null;if(null==a)break}if(bS(!s||null!=a,"missing required value","path",r),i&&null!=a){if("int"===i){if("string"==typeof a&&a.match(/^-?[0-9]+$/))return parseInt(a);if(Number.isSafeInteger(a))return a}if("number"===i&&"string"==typeof a&&a.match(/^-?[0-9.]*$/))return parseFloat(a);if("data"===i&&"string"==typeof a)return BG(a);if("array"===i&&Array.isArray(a))return a;if(i===typeof a)return a;bS(!1,`wrong type found for ${i} `,"path",r)}return a}IG=new WeakMap,PG=new WeakMap,CG=new WeakMap;const FG="m/44'/60'/0'/0/0";function GG(e){try{const t=JSON.parse(e);if(3===(null!=t.version?parseInt(t.version):0))return!0}catch(t){}return!1}function UG(e,t){const n=TS(t),r=DG(e,"crypto.ciphertext:data!");bS(CS(RP(NS([n.slice(16,32),r]))).substring(2)===DG(e,"crypto.mac:string!").toLowerCase(),"incorrect password","password","[ REDACTED ]");const i=function(e,t,n){if("aes-128-ctr"===DG(e,"crypto.cipher:string")){const r=DG(e,"crypto.cipherparams.iv:data!");return CS(new RG(t,r).decrypt(n))}gS(!1,"unsupported cipher","UNSUPPORTED_OPERATION",{operation:"decrypt"})}(e,n.slice(0,16),r),s=MO(i);if(e.address){let t=e.address.toLowerCase();t.startsWith("0x")||(t="0x"+t),bS(nO(t)===s,"keystore address/privateKey mismatch","address",e.address)}const a={address:s,privateKey:i};if("0.1"===DG(e,"x-ethers.version:string")){const t=n.slice(32,64),r=DG(e,"x-ethers.mnemonicCiphertext:data!"),i=DG(e,"x-ethers.mnemonicCounter:data!"),s=new RG(t,i);a.mnemonic={path:DG(e,"x-ethers.path:string")||FG,locale:DG(e,"x-ethers.locale:string")||"en",entropy:CS(TS(s.decrypt(r)))}}return a}function LG(e){const t=DG(e,"crypto.kdf:string");if(t&&"string"==typeof t){if("scrypt"===t.toLowerCase()){const n=DG(e,"crypto.kdfparams.salt:data!"),r=DG(e,"crypto.kdfparams.n:int!"),i=DG(e,"crypto.kdfparams.r:int!"),s=DG(e,"crypto.kdfparams.p:int!");bS(r>0&&!(r&r-1),"invalid kdf.N","kdf.N",r),bS(i>0&&s>0,"invalid kdf","kdf",t);const a=DG(e,"crypto.kdfparams.dklen:int!");return bS(32===a,"invalid kdf.dklen","kdf.dflen",a),{name:"scrypt",salt:n,N:r,r:i,p:s,dkLen:64}}if("pbkdf2"===t.toLowerCase()){const t=DG(e,"crypto.kdfparams.salt:data!"),n=DG(e,"crypto.kdfparams.prf:string!"),r=n.split("-").pop();bS("sha256"===r||"sha512"===r,"invalid kdf.pdf","kdf.pdf",n);const i=DG(e,"crypto.kdfparams.c:int!"),s=DG(e,"crypto.kdfparams.dklen:int!");return bS(32===s,"invalid kdf.dklen","kdf.dklen",s),{name:"pbkdf2",salt:t,count:i,dkLen:s,algorithm:r}}}bS(!1,"unsupported key-derivation function","kdf",t)}function jG(e,t){const n=JSON.parse(e),r=$G(t),i=LG(n);if("pbkdf2"===i.name){const{salt:e,count:t,dkLen:s,algorithm:a}=i;return UG(n,tC(r,e,t,s,a))}gS("scrypt"===i.name,"cannot be reached","UNKNOWN_ERROR",{params:i});const{salt:s,N:a,r:o,p:c,dkLen:A}=i;return UG(n,gC(r,s,a,o,c,A))}function HG(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}async function zG(e,t,n){const r=JSON.parse(e),i=$G(t),s=LG(r);if("pbkdf2"===s.name){n&&(n(0),await HG(0));const{salt:e,count:t,dkLen:a,algorithm:o}=s,c=tC(i,e,t,a,o);return n&&(n(1),await HG(0)),UG(r,c)}gS("scrypt"===s.name,"cannot be reached","UNKNOWN_ERROR",{params:s});const{salt:a,N:o,r:c,p:A,dkLen:l}=s;return UG(r,await yC(i,a,o,c,A,l,n))}function qG(e){const t=null!=e.salt?TS(e.salt,"options.salt"):sC(32);let n=1<<17,r=8,i=1;return e.scrypt&&(e.scrypt.N&&(n=e.scrypt.N),e.scrypt.r&&(r=e.scrypt.r),e.scrypt.p&&(i=e.scrypt.p)),bS("number"==typeof n&&n>0&&Number.isSafeInteger(n)&&(BigInt(n)&BigInt(n-1))===BigInt(0),"invalid scrypt N parameter","options.N",n),bS("number"==typeof r&&r>0&&Number.isSafeInteger(r),"invalid scrypt r parameter","options.r",r),bS("number"==typeof i&&i>0&&Number.isSafeInteger(i),"invalid scrypt p parameter","options.p",i),{name:"scrypt",dkLen:32,salt:t,N:n,r:r,p:i}}function QG(e,t,n,r){const i=TS(n.privateKey,"privateKey"),s=null!=r.iv?TS(r.iv,"options.iv"):sC(16);bS(16===s.length,"invalid options.iv length","options.iv",r.iv);const a=null!=r.uuid?TS(r.uuid,"options.uuid"):sC(16);bS(16===a.length,"invalid options.uuid length","options.uuid",r.iv);const o=e.slice(0,16),c=e.slice(16,32),A=TS(new RG(o,s).encrypt(i)),l=RP(NS([c,A])),f={address:n.address.substring(2).toLowerCase(),id:nI(a),version:3,Crypto:{cipher:"aes-128-ctr",cipherparams:{iv:CS(s).substring(2)},ciphertext:CS(A).substring(2),kdf:"scrypt",kdfparams:{salt:CS(t.salt).substring(2),n:t.N,dklen:32,p:t.p,r:t.r},mac:l.substring(2)}};if(n.mnemonic){const t=null!=r.client?r.client:`ethers/${lS}`,i=n.mnemonic.path||FG,s=n.mnemonic.locale||"en",a=e.slice(32,64),o=TS(n.mnemonic.entropy,"account.mnemonic.entropy"),c=sC(16),A=TS(new RG(a,c).encrypt(o)),l=new Date,u="UTC--"+l.getUTCFullYear()+"-"+MG(l.getUTCMonth()+1,2)+"-"+MG(l.getUTCDate(),2)+"T"+MG(l.getUTCHours(),2)+"-"+MG(l.getUTCMinutes(),2)+"-"+MG(l.getUTCSeconds(),2)+".0Z--"+f.address;f["x-ethers"]={client:t,gethFilename:u,path:i,locale:s,mnemonicCounter:CS(c).substring(2),mnemonicCiphertext:CS(A).substring(2),version:"0.1"}}return JSON.stringify(f)}function VG(e,t,n){null==n&&(n={});const r=$G(t),i=qG(n);return QG(TS(gC(r,i.salt,i.N,i.r,i.p,64)),i,e,n)}async function JG(e,t,n){null==n&&(n={});const r=$G(t),i=qG(n);return QG(TS(await yC(r,i.salt,i.N,i.r,i.p,64,n.progressCallback)),i,e,n)}const KG="m/44'/60'/0'/0/0",WG=new Uint8Array([66,105,116,99,111,105,110,32,115,101,101,100]),YG=2147483648,ZG=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");function XG(e,t){let n="";for(;e;)n="0123456789abcdef"[e%16]+n,e=Math.trunc(e/16);for(;n.length<2*t;)n="0"+n;return"0x"+n}function eU(e){const t=TS(e);return ix(NS([t,RS(TC(TC(t)),0,4)]))}const tU={};function nU(e,t,n,r){const i=new Uint8Array(37);e&YG?(gS(null!=r,"cannot derive child of neutered node","UNSUPPORTED_OPERATION",{operation:"deriveChild"}),i.set(TS(r),1)):i.set(TS(n));for(let a=24;a>=0;a-=8)i[33+(a>>3)]=e>>24-a&255;const s=TS(hP("sha512",t,i));return{IL:s.slice(0,32),IR:s.slice(32)}}function rU(e,t){const n=t.split("/");bS(n.length>0,"invalid path","path",t),"m"===n[0]&&(bS(0===e.depth,`cannot derive root path (i.e. path starting with "m/") for a node at non-zero depth ${e.depth}`,"path",t),n.shift());let r=e;for(let i=0;i<n.length;i++){const e=n[i];if(e.match(/^[0-9]+'$/)){const t=parseInt(e.substring(0,e.length-1));bS(t<YG,"invalid path index",`path[${i}]`,e),r=r.deriveChild(YG+t)}else if(e.match(/^[0-9]+$/)){const t=parseInt(e);bS(t<YG,"invalid path index",`path[${i}]`,e),r=r.deriveChild(t)}else bS(!1,"invalid path component",`path[${i}]`,e)}return r}const iU=class e extends GF{constructor(e,t,n,r,i,s,a,o,c){super(t,c),__privateAdd(this,Vn),__publicField(this,"publicKey"),__publicField(this,"fingerprint"),__publicField(this,"parentFingerprint"),__publicField(this,"mnemonic"),__publicField(this,"chainCode"),__publicField(this,"path"),__publicField(this,"index"),__publicField(this,"depth"),ES(e,tU,"HDNodeWallet"),dS(this,{publicKey:t.compressedPublicKey}),dS(this,{parentFingerprint:n,fingerprint:RS(YP(TC(this.publicKey)),0,4),chainCode:r,path:i,index:s,depth:a}),dS(this,{mnemonic:o})}connect(t){return new e(tU,this.signingKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,this.mnemonic,t)}async encrypt(e,t){return await JG(__privateMethod(this,Vn,Jn).call(this),e,{progressCallback:t})}encryptSync(e){return VG(__privateMethod(this,Vn,Jn).call(this),e)}get extendedKey(){return gS(this.depth<256,"Depth too deep","UNSUPPORTED_OPERATION",{operation:"extendedKey"}),eU(NS(["0x0488ADE4",XG(this.depth,1),this.parentFingerprint,XG(this.index,4),this.chainCode,NS(["0x00",this.privateKey])]))}hasPath(){return null!=this.path}neuter(){return new aU(tU,this.address,this.publicKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,this.provider)}deriveChild(t){const n=JS(t,"index");bS(n<=4294967295,"invalid index","index",n);let r=this.path;r&&(r+="/"+(2147483647&n),n&YG&&(r+="'"));const{IR:i,IL:s}=nU(n,this.chainCode,this.publicKey,this.privateKey),a=new JN(WS((VS(s)+BigInt(this.privateKey))%ZG,32));return new e(tU,a,this.fingerprint,CS(i),r,n,this.depth+1,this.mnemonic,this.provider)}derivePath(e){return rU(this,e)}static fromExtendedKey(t){const n=YS(sx(t));bS(82===n.length||eU(n.slice(0,78))===t,"invalid extended key","extendedKey","[ REDACTED ]");const r=n[4],i=CS(n.slice(5,9)),s=parseInt(CS(n.slice(9,13)).substring(2),16),a=CS(n.slice(13,45)),o=n.slice(45,78);switch(CS(n.slice(0,4))){case"0x0488b21e":case"0x043587cf":{const e=CS(o);return new aU(tU,MO(e),e,i,a,null,s,r,null)}case"0x0488ade4":case"0x04358394 ":if(0!==o[0])break;return new e(tU,new JN(o.slice(1)),i,a,null,s,r,null,null)}bS(!1,"invalid extended key prefix","extendedKey","[ REDACTED ]")}static createRandom(t,n,r){var i;null==t&&(t=""),null==n&&(n=KG),null==r&&(r=QF.wordlist());const s=ZF.fromEntropy(sC(16),t,r);return __privateMethod(i=e,Kn,Wn).call(i,s.computeSeed(),s).derivePath(n)}static fromMnemonic(t,n){var r;return n||(n=KG),__privateMethod(r=e,Kn,Wn).call(r,t.computeSeed(),t).derivePath(n)}static fromPhrase(t,n,r,i){var s;null==n&&(n=""),null==r&&(r=KG),null==i&&(i=QF.wordlist());const a=ZF.fromPhrase(t,n,i);return __privateMethod(s=e,Kn,Wn).call(s,a.computeSeed(),a).derivePath(r)}static fromSeed(t){var n;return __privateMethod(n=e,Kn,Wn).call(n,t,null)}};Vn=new WeakSet,Jn=function(){const e={address:this.address,privateKey:this.privateKey},t=this.mnemonic;return this.path&&t&&"en"===t.wordlist.locale&&""===t.password&&(e.mnemonic={path:this.path,locale:"en",entropy:t.entropy}),e},Kn=new WeakSet,Wn=function(e,t){bS(IS(e),"invalid seed","seed","[REDACTED]");const n=TS(e,"seed");bS(n.length>=16&&n.length<=64,"invalid seed","seed","[REDACTED]");const r=TS(hP("sha512",WG,n)),i=new JN(CS(r.slice(0,32)));return new iU(tU,i,"0x00000000",CS(r.slice(32)),"m",0,0,t,null)},__privateAdd(iU,Kn);let sU=iU;class aU extends CD{constructor(e,t,n,r,i,s,a,o,c){super(t,c),__publicField(this,"publicKey"),__publicField(this,"fingerprint"),__publicField(this,"parentFingerprint"),__publicField(this,"chainCode"),__publicField(this,"path"),__publicField(this,"index"),__publicField(this,"depth"),ES(e,tU,"HDNodeVoidWallet"),dS(this,{publicKey:n}),dS(this,{publicKey:n,fingerprint:RS(YP(TC(n)),0,4),parentFingerprint:r,chainCode:i,path:s,index:a,depth:o})}connect(e){return new aU(tU,this.address,this.publicKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,e)}get extendedKey(){return gS(this.depth<256,"Depth too deep","UNSUPPORTED_OPERATION",{operation:"extendedKey"}),eU(NS(["0x0488B21E",XG(this.depth,1),this.parentFingerprint,XG(this.index,4),this.chainCode,this.publicKey]))}hasPath(){return null!=this.path}deriveChild(e){const t=JS(e,"index");bS(t<=4294967295,"invalid index","index",t);let n=this.path;n&&(n+="/"+(2147483647&t),t&YG&&(n+="'"));const{IR:r,IL:i}=nU(t,this.chainCode,this.publicKey,null),s=JN.addPoints(i,this.publicKey,!0),a=MO(s);return new aU(tU,a,s,this.fingerprint,CS(r),n,t,this.depth+1,this.provider)}derivePath(e){return rU(this,e)}}function oU(e){const t=JS(e,"index");return bS(t>=0&&t<YG,"invalid account index","index",t),`m/44'/60'/${t}'/0/0`}function cU(e){const t=JS(e,"index");return bS(t>=0&&t<YG,"invalid account index","index",t),`m/44'/60'/0'/0/${t}`}function AU(e){try{if(JSON.parse(e).encseed)return!0}catch(t){}return!1}function lU(e,t){const n=JSON.parse(e),r=$G(t),i=nO(DG(n,"ethaddr:string!")),s=BG(DG(n,"encseed:string!"));bS(s&&s.length%16==0,"invalid encseed","json",e);const a=TS(tC(r,r,2e3,32,"sha256")).slice(0,16),o=s.slice(0,16),c=s.slice(16),A=function(e){if(e.length<16)throw new TypeError("PKCS#7 invalid length");const t=e[e.length-1];if(t>16)throw new TypeError("PKCS#7 padding byte out of range");const n=e.length-t;for(let r=0;r<t;r++)if(e[n+r]!==t)throw new TypeError("PKCS#7 invalid padding byte");return new Uint8Array(e.subarray(0,n))}(TS(new xG(a,o).decrypt(c)));let l="";for(let f=0;f<A.length;f++)l+=String.fromCharCode(A[f]);return{address:i,privateKey:sR(l)}}function fU(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}const uU=class e extends GF{constructor(e,t){"string"!=typeof e||e.startsWith("0x")||(e="0x"+e),super("string"==typeof e?new JN(e):e,t)}connect(t){return new e(this.signingKey,t)}async encrypt(e,t){const n={address:this.address,privateKey:this.privateKey};return await JG(n,e,{progressCallback:t})}encryptSync(e){return VG({address:this.address,privateKey:this.privateKey},e)}static async fromEncryptedJson(t,n,r){var i;let s=null;return GG(t)?s=await zG(t,n,r):AU(t)&&(r&&(r(0),await fU(0)),s=lU(t,n),r&&(r(1),await fU(0))),__privateMethod(i=e,Yn,Zn).call(i,s)}static fromEncryptedJsonSync(t,n){var r;let i=null;return GG(t)?i=jG(t,n):AU(t)?i=lU(t,n):bS(!1,"invalid JSON wallet","json","[ REDACTED ]"),__privateMethod(r=e,Yn,Zn).call(r,i)}static createRandom(e){const t=sU.createRandom();return e?t.connect(e):t}static fromPhrase(e,t){const n=sU.fromPhrase(e);return t?n.connect(t):n}};Yn=new WeakSet,Zn=function(e){if(bS(e,"invalid JSON wallet","json","[ REDACTED ]"),"mnemonic"in e&&e.mnemonic&&"en"===e.mnemonic.locale){const t=ZF.fromEntropy(e.mnemonic.entropy),n=sU.fromMnemonic(t,e.mnemonic.path);if(n.address===e.address&&n.privateKey===e.privateKey)return n;console.log("WARNING: JSON mismatch address/privateKey != mnemonic; fallback onto private key")}const t=new uU(e.privateKey);return bS(t.address===e.address,"address/privateKey mismatch","json","[ REDACTED ]"),t},__privateAdd(uU,Yn);let dU=uU;class hU extends zF{constructor(e,t,n,r){super(e,t,r),__privateAdd(this,Xn),__privateSet(this,Xn,n)}get _accent(){return __privateGet(this,Xn)}_decodeWords(){return function(e,t){let n=jF(e).join(",");return t.split(/,/g).forEach(e=>{const r=e.match(/^([a-z]*)([0-9]+)([0-9])(.*)$/);bS(null!==r,"internal error parsing accents","accents",t);let i=0;const s=function(e,t){const n=(1<<e)-1,r=[];let i=0,s=0,a=0;for(let o=0;o<t.length;o++)for(i=i<<6|")!@#$%^&*(ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".indexOf(t[o]),s+=6;s>=e;){const t=i>>s-e;i&=(1<<s-e)-1,s-=e,0===t?a+=n:(r.push(t+a),a=0)}return r}(parseInt(r[3]),r[4]),a=parseInt(r[2]),o=new RegExp(`([${r[1]}])`,"g");n=n.replace(o,(e,t)=>(0===--s[i]&&(t=String.fromCharCode(t.charCodeAt(0),a),i++),t))}),n.split(",")}(this._data,this._accent)}}Xn=new WeakMap;const pU={en:QF.wordlist()},mU=Object.freeze(Object.defineProperty({__proto__:null,AbiCoder:BM,AbstractProvider:bD,AbstractSigner:PD,AlchemyProvider:YD,AnkrProvider:KD,BaseContract:I$,BaseWallet:GF,Block:KM,BlockscoutProvider:MF,BrowserProvider:BF,ChainstackProvider:XD,CloudflareProvider:eF,ConstructorFragment:TM,Contract:P$,ContractEventPayload:a$,ContractFactory:C$,ContractTransactionReceipt:r$,ContractTransactionResponse:i$,ContractUnknownEventPayload:s$,EnsPlugin:W$,EnsResolver:$$,ErrorDescription:GM,ErrorFragment:EM,EtherSymbol:"Ξ",EtherscanPlugin:rF,EtherscanProvider:aF,EventFragment:kM,EventLog:t$,EventPayload:cx,FallbackFragment:SM,FallbackProvider:CF,FeeData:VM,FeeDataNetworkPlugin:Y$,FetchCancelSignal:kx,FetchRequest:xx,FetchResponse:Px,FetchUrlFeeDataNetworkPlugin:Z$,FixedNumber:Lx,Fragment:wM,FunctionFragment:xM,GasCostPlugin:K$,HDNodeVoidWallet:aU,HDNodeWallet:sU,Indexed:UM,InfuraProvider:mF,InfuraWebSocketProvider:pF,Interface:HM,IpcSocketProvider:FF,JsonRpcApiProvider:HD,JsonRpcProvider:qD,JsonRpcSigner:jD,LangEn:QF,Log:WM,LogDescription:DM,MaxInt256:BN,MaxUint256:ON,MessagePrefix:MN,MinInt256:RN,Mnemonic:ZF,MulticoinProviderPlugin:O$,N:CN,NamedFragment:vM,Network:eD,NetworkPlugin:J$,NonceManager:RF,ParamType:bM,PocketProvider:DF,QuickNodeProvider:gF,Result:uI,Signature:VN,SigningKey:JN,SocketBlockSubscriber:AF,SocketEventSubscriber:fF,SocketPendingSubscriber:lF,SocketProvider:uF,SocketSubscriber:cF,StructFragment:IM,Transaction:nR,TransactionDescription:FM,TransactionReceipt:YM,TransactionResponse:ZM,Typed:hO,TypedDataEncoder:MB,UndecodedEventLog:n$,UnmanagedSubscriber:hD,Utf8ErrorFuncs:lx,VoidSigner:CD,Wallet:dU,WebSocketProvider:dF,WeiPerEther:NN,Wordlist:HF,WordlistOwl:zF,WordlistOwlA:hU,ZeroAddress:IN,ZeroHash:PN,accessListify:RO,assert:gS,assertArgument:bS,assertArgumentCount:wS,assertNormalize:_S,assertPrivate:ES,authorizationify:BO,checkResultErrors:dI,computeAddress:MO,computeHmac:hP,concat:NS,copyRequest:JM,dataLength:OS,dataSlice:RS,decodeBase58:sx,decodeBase64:ax,decodeBytes32String:$M,decodeRlp:Qx,decryptCrowdsaleJson:lU,decryptKeystoreJson:zG,decryptKeystoreJsonSync:jG,defaultPath:KG,defineProperties:dS,dnsEncode:fB,encodeBase58:ix,encodeBase64:ox,encodeBytes32String:MM,encodeRlp:Wx,encryptKeystoreJson:JG,encryptKeystoreJsonSync:VG,ensNormalize:cB,formatEther:eI,formatUnits:Zx,fromTwos:LS,getAccountPath:oU,getAddress:nO,getBigInt:zS,getBytes:TS,getBytesCopy:SS,getCreate2Address:sO,getCreateAddress:iO,getDefaultProvider:OF,getIcapAddress:rO,getIndexedAccountPath:cU,getNumber:JS,getUint:qS,hashAuthorization:rR,hashMessage:uB,hexlify:CS,id:sR,isAddress:oO,isAddressable:aO,isBytesLike:IS,isCallException:mS,isCrowdsaleJson:AU,isError:pS,isHexString:xS,isKeystoreJson:GG,isValidName:AB,keccak256:RP,lock:KN,makeError:yS,mask:HS,namehash:lB,parseEther:tI,parseUnits:Xx,pbkdf2:tC,randomBytes:sC,recoverAddress:$O,resolveAddress:AO,resolveProperties:uS,ripemd160:YP,scrypt:yC,scryptSync:gC,sha256:TC,sha512:SC,showThrottleMessage:OD,solidityPacked:gB,solidityPackedKeccak256:bB,solidityPackedSha256:wB,stripZerosLeft:BS,toBeArray:YS,toBeHex:WS,toBigInt:VS,toNumber:KS,toQuantity:ZS,toTwos:jS,toUtf8Bytes:ux,toUtf8CodePoints:hx,toUtf8String:dx,uuidV4:nI,verifyAuthorization:iR,verifyMessage:dB,verifyTypedData:$B,version:lS,wordlists:pU,zeroPadBytes:DS,zeroPadValue:$S},Symbol.toStringTag,{value:"Module"})),yU=Object.freeze(Object.defineProperty({__proto__:null,AbiCoder:BM,AbstractProvider:bD,AbstractSigner:PD,AlchemyProvider:YD,AnkrProvider:KD,BaseContract:I$,BaseWallet:GF,Block:KM,BlockscoutProvider:MF,BrowserProvider:BF,ChainstackProvider:XD,CloudflareProvider:eF,ConstructorFragment:TM,Contract:P$,ContractEventPayload:a$,ContractFactory:C$,ContractTransactionReceipt:r$,ContractTransactionResponse:i$,ContractUnknownEventPayload:s$,EnsPlugin:W$,EnsResolver:$$,ErrorDescription:GM,ErrorFragment:EM,EtherSymbol:"Ξ",EtherscanPlugin:rF,EtherscanProvider:aF,EventFragment:kM,EventLog:t$,EventPayload:cx,FallbackFragment:SM,FallbackProvider:CF,FeeData:VM,FeeDataNetworkPlugin:Y$,FetchCancelSignal:kx,FetchRequest:xx,FetchResponse:Px,FetchUrlFeeDataNetworkPlugin:Z$,FixedNumber:Lx,Fragment:wM,FunctionFragment:xM,GasCostPlugin:K$,HDNodeVoidWallet:aU,HDNodeWallet:sU,Indexed:UM,InfuraProvider:mF,InfuraWebSocketProvider:pF,Interface:HM,IpcSocketProvider:FF,JsonRpcApiProvider:HD,JsonRpcProvider:qD,JsonRpcSigner:jD,LangEn:QF,Log:WM,LogDescription:DM,MaxInt256:BN,MaxUint256:ON,MessagePrefix:MN,MinInt256:RN,Mnemonic:ZF,MulticoinProviderPlugin:O$,N:CN,NamedFragment:vM,Network:eD,NetworkPlugin:J$,NonceManager:RF,ParamType:bM,PocketProvider:DF,QuickNodeProvider:gF,Result:uI,Signature:VN,SigningKey:JN,SocketBlockSubscriber:AF,SocketEventSubscriber:fF,SocketPendingSubscriber:lF,SocketProvider:uF,SocketSubscriber:cF,StructFragment:IM,Transaction:nR,TransactionDescription:FM,TransactionReceipt:YM,TransactionResponse:ZM,Typed:hO,TypedDataEncoder:MB,UndecodedEventLog:n$,UnmanagedSubscriber:hD,Utf8ErrorFuncs:lx,VoidSigner:CD,Wallet:dU,WebSocketProvider:dF,WeiPerEther:NN,Wordlist:HF,WordlistOwl:zF,WordlistOwlA:hU,ZeroAddress:IN,ZeroHash:PN,accessListify:RO,assert:gS,assertArgument:bS,assertArgumentCount:wS,assertNormalize:_S,assertPrivate:ES,authorizationify:BO,checkResultErrors:dI,computeAddress:MO,computeHmac:hP,concat:NS,copyRequest:JM,dataLength:OS,dataSlice:RS,decodeBase58:sx,decodeBase64:ax,decodeBytes32String:$M,decodeRlp:Qx,decryptCrowdsaleJson:lU,decryptKeystoreJson:zG,decryptKeystoreJsonSync:jG,defaultPath:KG,defineProperties:dS,dnsEncode:fB,encodeBase58:ix,encodeBase64:ox,encodeBytes32String:MM,encodeRlp:Wx,encryptKeystoreJson:JG,encryptKeystoreJsonSync:VG,ensNormalize:cB,ethers:mU,formatEther:eI,formatUnits:Zx,fromTwos:LS,getAccountPath:oU,getAddress:nO,getBigInt:zS,getBytes:TS,getBytesCopy:SS,getCreate2Address:sO,getCreateAddress:iO,getDefaultProvider:OF,getIcapAddress:rO,getIndexedAccountPath:cU,getNumber:JS,getUint:qS,hashAuthorization:rR,hashMessage:uB,hexlify:CS,id:sR,isAddress:oO,isAddressable:aO,isBytesLike:IS,isCallException:mS,isCrowdsaleJson:AU,isError:pS,isHexString:xS,isKeystoreJson:GG,isValidName:AB,keccak256:RP,lock:KN,makeError:yS,mask:HS,namehash:lB,parseEther:tI,parseUnits:Xx,pbkdf2:tC,randomBytes:sC,recoverAddress:$O,resolveAddress:AO,resolveProperties:uS,ripemd160:YP,scrypt:yC,scryptSync:gC,sha256:TC,sha512:SC,showThrottleMessage:OD,solidityPacked:gB,solidityPackedKeccak256:bB,solidityPackedSha256:wB,stripZerosLeft:BS,toBeArray:YS,toBeHex:WS,toBigInt:VS,toNumber:KS,toQuantity:ZS,toTwos:jS,toUtf8Bytes:ux,toUtf8CodePoints:hx,toUtf8String:dx,uuidV4:nI,verifyAuthorization:iR,verifyMessage:dB,verifyTypedData:$B,version:lS,wordlists:pU,zeroPadBytes:DS,zeroPadValue:$S},Symbol.toStringTag,{value:"Module"})),gU=30078,bU=30079,wU=30080;class vU extends Error{constructor(e,t=null){super(e),this.name="AuthorizationError",this.requiredPermission=t}}class _U extends Error{constructor(e){super(e),this.name="ValidationError"}}const EU=function(e){return class extends e{hasContracts(){return null!==this._contracts}_requireContracts(){if(!this._contracts)throw new Error("Contracts not initialized. Call initContracts() first.");return this._contracts}async initContracts(e){const t=new VT(e),n=await t.connect(e.network,e.privateKey,e.rpcUrl),r=new oS(t),i=new AS(t,r);return this._contracts={chainManager:t,deployer:r,holonContracts:i,network:e.network},{...n,address:e.privateKey?await t.getAddress():null}}async initContractsBrowser(e){const t=new VT,n=await t.connectBrowser(e),r=new oS(t),i=new AS(t,r);return this._contracts={chainManager:t,deployer:r,holonContracts:i,network:t.networkName},n}async deployContracts(e={}){const{deployer:t}=this._requireContracts();return t.deployAll(e)}loadDeployedContracts(e){const{deployer:t}=this._requireContracts();t.loadDeployedAddresses(e)}getDeployedContracts(){const{deployer:e}=this._requireContracts();return e.getDeployedAddresses()}async deployHolonContract(e,t="Splitter",n={}){const{holonContracts:r}=this._requireContracts();return r.deploy(e,t,n)}async linkHolonContract(e,t,n="Splitter"){const{holonContracts:r}=this._requireContracts();return r.link(e,t,n)}async unlinkHolonContract(e){const{holonContracts:t}=this._requireContracts();return t.unlink(e)}getHolonContract(e){return this._contracts?this._contracts.holonContracts.getContract(e):null}getHolonContractAddress(e){return this._contracts?this._contracts.holonContracts.getAddress(e):null}hasHolonContract(e){return!!this._contracts&&this._contracts.holonContracts.hasContract(e)}listHolonContracts(){return this._contracts?this._contracts.holonContracts.listAll():[]}getHolonOperations(e){const{holonContracts:t}=this._requireContracts();return t.requireOperations(e)}async contractAddMember(e,t){return this.getHolonOperations(e).addMember(t)}async contractAddMembers(e,t){return this.getHolonOperations(e).addMembers(t)}async contractIsMember(e,t){return this.getHolonOperations(e).isMember(t)}async contractReward(e,t,n){return this.getHolonOperations(e).reward(t,n)}async contractRewardEth(e,t){return this.getHolonOperations(e).rewardEth(t)}async contractSendEth(e,t){return this.getHolonOperations(e).sendEth(t)}async contractClaim(e,t,n){return this.getHolonOperations(e).claim(t,n)}async contractGetEthBalance(e,t){return this.getHolonOperations(e).getEthBalance(t)}async contractGetTokenBalance(e,t,n){return this.getHolonOperations(e).getTokenBalance(t,n)}async contractSetSplit(e,t,n){return this.getHolonOperations(e).setContractSplit(t,n)}async contractGetSplit(e){return this.getHolonOperations(e).getContractSplit()}async contractCreateManaged(e,t,n){return this.getHolonOperations(e).createManagedContract(t,n)}async contractCreateZoned(e,t,n,r=6){return this.getHolonOperations(e).createZonedContract(t,n,r)}async contractGetChildContracts(e){return this.getHolonOperations(e).getChildContracts()}async contractSetAppreciation(e,t,n){return this.getHolonOperations(e).setAppreciation(t,n)}async contractGetAppreciation(e,t){return this.getHolonOperations(e).getAppreciation(t)}async contractGetTotalAppreciation(e){return this.getHolonOperations(e).getTotalAppreciation()}async contractAddToZone(e,t,n,r){return this.getHolonOperations(e).addToZone(t,n,r)}async contractRemoveFromZone(e,t,n){return this.getHolonOperations(e).removeFromZone(t,n)}async contractGetZone(e,t){return this.getHolonOperations(e).getZone(t)}async contractSetZoneParams(e,t,n,r,i){return this.getHolonOperations(e).setZoneParameters(t,n,r,i)}async contractAppreciate(e,t,n,r){return this.getHolonOperations(e).appreciate(t,n,r)}async contractGetAppreciationGiven(e,t){return this.getHolonOperations(e).getAppreciationGiven(t)}async contractGetAppreciationReceived(e,t){return this.getHolonOperations(e).getAppreciationReceived(t)}async contractSetSteepness(e,t){return this.getHolonOperations(e).setSteepness(t)}async contractGetSteepness(e){return this.getHolonOperations(e).getSteepness()}async contractSetInteriorSplit(e,t,n){return this.getHolonOperations(e).setInteriorSplit(t,n)}async contractStartElection(e){return this.getHolonOperations(e).startElection()}async contractNominate(e){return this.getHolonOperations(e).nominateSelf()}async contractVote(e,t){return this.getHolonOperations(e).vote(t)}async contractFinalizeElection(e){return this.getHolonOperations(e).finalizeElection()}async contractGetName(e){return this.getHolonOperations(e).getName()}async contractGetOwner(e){return this.getHolonOperations(e).getOwner()}async contractGetBotAddress(e){return this.getHolonOperations(e).getBotAddress()}async contractGetTotalDeposited(e,t){return this.getHolonOperations(e).getTotalDeposited(t)}getNetworkUtils(){return QT}getChainManager(){return this._contracts?.chainManager||null}}}(function(e){return class extends e{async addFederatedHolosphere(e,t={}){if(!e||"string"!=typeof e)throw new _U("pubKey must be a valid public key string");return mw(this.client,this.config.appName,e,t)}async removeFederatedHolosphere(e){return async function(e,t,n){const r=await hw(e,t),i=r.federatedWith.length;return r.federatedWith=r.federatedWith.filter(e=>e.pubKey!==n),r.federatedWith.length!==i&&pw(e,t,r)}(this.client,this.config.appName,e)}async getFederatedHolospheres(){return async function(e,t){return(await hw(e,t)).federatedWith.map(e=>e.pubKey)}(this.client,this.config.appName)}async getFederationRegistry(){return hw(this.client,this.config.appName)}async storeInboundCapability(e,t){return gw(this.client,this.config.appName,e,t)}async readFromFederatedSource(e,t,n,r=null){const i=await yw(this.client,this.config.appName,e,{holonId:t,lensName:n,dataId:r});if(!i)throw new vU("No valid capability for federated source","read");if(!(await this.verifyCapability(i.token,"read",{holonId:t,lensName:n,dataId:r})))throw new vU("Capability verification failed","read");if(r){const i=Du(this.config.appName,t,n,r);return Ru(this.client,i,3e4,{authors:[e],includeAuthor:!0})}{const r=Du(this.config.appName,t,n);return Bu(this.client,r,3e4,{authors:[e],includeAuthor:!0})}}async createCrossHolosphereHologram(e,t,n,r,i,s={}){const{embedCapability:a=!0}=s,o=await yw(this.client,this.config.appName,e,{holonId:t,lensName:n,dataId:r});if(!o)throw new vU("No valid capability for cross-holosphere hologram","read");const c=ww(t,0,n,r,this.config.appName,{authorPubKey:e,capability:a?o.token:null}),A=Du(this.config.appName,i,n,r);return await Fu(this.client,A,c),c}async issueCapabilityForFederation(e,t,n,r={}){const{expiresIn:i=36e5,trackInRegistry:s=!0}=r,a=await lw(n,t,e,{expiresIn:i,issuerKey:this.client.privateKey});return s&&(await async function(e,t,n){return(await hw(e,t)).federatedWith.find(e=>e.pubKey===n)||null}(this.client,this.config.appName,e)||await mw(this.client,this.config.appName,e,{addedVia:"capability_issued"}),await async function(e,t,n,r){const i=await hw(e,t),s=i.federatedWith.find(e=>e.pubKey===n);if(!s)throw new Error(`Partner ${n} not found in federation registry`);return s.outboundCapabilities||(s.outboundCapabilities=[]),s.outboundCapabilities.push({tokenHash:r.tokenHash,scope:r.scope,permissions:r.permissions,issuedAt:Date.now(),expires:r.expires}),pw(e,t,i)}(this.client,this.config.appName,e,{tokenHash:await this._hashToken(a),scope:t,permissions:n,expires:Date.now()+i})),a}async _hashToken(e){const t=new TextEncoder;return Hb(sw(t.encode(e)))}async sendFederationRequest(e,t={}){return async function(e,t,n,r={}){const{scope:i={holonId:"*",lensName:"*"},permissions:s=["read"],message:a="Federation request",expiresIn:o=2592e6}=r,c=await lw(s,i,n,{issuerKey:e.privateKey,expiresIn:o}),A={kind:gU,created_at:Math.floor(Date.now()/1e3),tags:[["d",`federation-request-${n.slice(0,16)}`],["p",n],["holosphere",t],["scope",JSON.stringify(i)],["permissions",s.join(",")]],content:JSON.stringify({message:a,offeredCapability:c,requestedScope:i,requestedPermissions:s})},l=await e.publish(A);return{eventId:l.id||null,targetPubKey:n,scope:i,permissions:s,offeredCapability:c,...l}}(this.client,this.config.appName,e,t)}async subscribeFederationRequests(e){return async function(e,t){const n={kinds:[gU],"#p":[e.publicKey]};return e.subscribe(n,e=>{try{const n=JSON.parse(e.content),r=e.tags.find(e=>"scope"===e[0]),i=e.tags.find(e=>"permissions"===e[0]),s=e.tags.find(e=>"holosphere"===e[0]),a={eventId:e.id,requesterPubKey:e.pubkey,appname:s?.[1],scope:r?JSON.parse(r[1]):{holonId:"*",lensName:"*"},permissions:i?i[1].split(","):["read"],message:n.message,offeredCapability:n.offeredCapability,timestamp:e.created_at};t(a)}catch(n){console.error("Failed to parse federation request:",n)}})}(this.client,e)}async acceptFederationRequest(e,t={}){return async function(e,t,n,r={}){const{scope:i=n.scope,permissions:s=n.permissions,alias:a=null,expiresIn:o=2592e6}=r,c=await lw(s,i,n.requesterPubKey,{issuerKey:e.privateKey,expiresIn:o});await mw(e,t,n.requesterPubKey,{alias:a,addedVia:"nostr_discovery",inboundCapabilities:[{token:n.offeredCapability,scope:n.scope,permissions:n.permissions,expires:Date.now()+o}]});const A={kind:bU,created_at:Math.floor(Date.now()/1e3),tags:[["d",`federation-accept-${n.requesterPubKey.slice(0,16)}`],["p",n.requesterPubKey],["e",n.eventId],["holosphere",t],["scope",JSON.stringify(i)],["permissions",s.join(",")]],content:JSON.stringify({acceptedScope:i,grantedCapability:c})},l=await e.publish(A);return{eventId:l.id||null,requesterPubKey:n.requesterPubKey,grantedCapability:c,acceptedScope:i,...l}}(this.client,this.config.appName,e,t)}async declineFederationRequest(e,t=""){return async function(e,t,n,r=""){const i={kind:wU,created_at:Math.floor(Date.now()/1e3),tags:[["d",`federation-decline-${n.requesterPubKey.slice(0,16)}`],["p",n.requesterPubKey],["e",n.eventId],["holosphere",t]],content:JSON.stringify({reason:r})},s=await e.publish(i);return{eventId:s.id||null,requesterPubKey:n.requesterPubKey,reason:r,...s}}(this.client,this.config.appName,e,t)}async subscribeFederationAcceptances(e){return async function(e,t,n){const r={kinds:[bU],"#p":[e.publicKey]};return e.subscribe(r,async r=>{try{const i=JSON.parse(r.content),s=r.tags.find(e=>"scope"===e[0]),a=r.tags.find(e=>"permissions"===e[0]);await gw(e,t,r.pubkey,{token:i.grantedCapability,scope:s?JSON.parse(s[1]):i.acceptedScope,permissions:a?a[1].split(","):["read"],expires:Date.now()+2592e6}),n({accepterPubKey:r.pubkey,originalRequestId:r.tags.find(e=>"e"===e[0])?.[1],acceptedScope:i.acceptedScope,grantedCapability:i.grantedCapability,timestamp:r.created_at})}catch(i){console.error("Failed to parse federation acceptance:",i)}})}(this.client,this.config.appName,e)}async subscribeFederationDeclines(e){return async function(e,t){const n={kinds:[wU],"#p":[e.publicKey]};return e.subscribe(n,e=>{try{const n=JSON.parse(e.content);t({declinerPubKey:e.pubkey,originalRequestId:e.tags.find(e=>"e"===e[0])?.[1],reason:n.reason||"",timestamp:e.created_at})}catch(n){console.error("Failed to parse federation decline:",n)}})}(this.client,e)}async getPendingFederationRequests(e={}){return async function(e,t={}){const n=t.since||Math.floor((Date.now()-2592e6)/1e3),r={kinds:[gU],authors:[e.publicKey],since:n},i=await e.query(r),s={kinds:[bU,wU],"#p":[e.publicKey],since:n},a=await e.query(s),o=new Set;for(const l of a){const e=l.tags.find(e=>"e"===e[0]);e&&o.add(e[1])}const c=[];for(const l of i)if(!o.has(l.id))try{const e=JSON.parse(l.content),t=l.tags.find(e=>"p"===e[0]),n=l.tags.find(e=>"scope"===e[0]),r=l.tags.find(e=>"permissions"===e[0]);c.push({eventId:l.id,targetPubKey:t?.[1],scope:n?JSON.parse(n[1]):{holonId:"*",lensName:"*"},permissions:r?r[1].split(","):["read"],message:e.message,timestamp:l.created_at})}catch(A){console.error("Failed to parse pending request:",A)}return c}(this.client,e)}}}
33
+ /**
34
+ * @fileoverview HoloSphere - Holonic Geospatial Communication Infrastructure
35
+ *
36
+ * This is the main entry point for the HoloSphere library, providing a comprehensive
37
+ * distributed P2P geospatial communication system. It combines H3 hexagonal indexing
38
+ * for spatial organization, Nostr protocol for distributed storage, smart contracts
39
+ * for fund distribution, and AI services for intelligent data processing.
40
+ *
41
+ * @module holosphere
42
+ * @author HoloSphere Team
43
+ * @license MIT
44
+ */((kU=class extends _f{constructor(e){super(e),this.schemas=new Map,this._cache=new Map,this.subscriptionRegistry=new Iw,this._ai=null;const t=e.openaiKey||this._getEnv("OPENAI_API_KEY");if(t){const n={...e.aiOptions,model:e.aiOptions?.model||this._getEnv("HOLOSPHERE_AI_MODEL"),temperature:e.aiOptions?.temperature??this._parseFloat(this._getEnv("HOLOSPHERE_AI_TEMPERATURE"))};this._initializeAI(t,n)}this._contracts=null}_getEnv(e){if("undefined"!=typeof process&&process.env)return process.env[e]}_parseFloat(e){if(null==e)return;const t=parseFloat(e);return isNaN(t)?void 0:t}_initializeAI(e,t={}){const n={...t.llm,model:t.model||t.llm?.model,temperature:t.temperature??t.llm?.temperature};this._ai={llm:new TT(e,n)};const r=new(0,require("openai").default)({apiKey:e});this._ai.openai=r,this._ai.embeddings=new IT(r,this),this._ai.schemaExtractor=new ST(this._ai.llm),this._ai.jsonOps=new xT(this._ai.llm),this._ai.council=new CT(this._ai.llm),this._ai.tts=new RT(r),this._ai.nlQuery=new BT(this._ai.llm,this),this._ai.classifier=new MT(this._ai.llm,this),this._ai.spatial=new $T(this._ai.llm,this),this._ai.aggregation=new DT(this._ai.llm,this),this._ai.federationAdvisor=new FT(this._ai.llm,this,this._ai.embeddings),this._ai.relationships=new GT(this._ai.llm,this,this._ai.embeddings),this._ai.taskBreakdown=new UT(this._ai.llm,this),this._ai.h3ai=new LT(this._ai.llm,this)}hasAI(){return null!==this._ai}getAIServices(){return this._ai}async toHolon(e,t,n){return function(e,t,n){if("number"!=typeof e||e<-90||e>90)throw new RangeError(`Invalid latitude: ${e}. Must be between -90 and 90.`);if("number"!=typeof t||t<-180||t>180)throw new RangeError(`Invalid longitude: ${t}. Must be between -180 and 180.`);if(!Number.isInteger(n)||n<0||n>15)throw new RangeError(`Invalid resolution: ${n}. Must be integer between 0 and 15.`);try{return pu(e,t,n)}catch(r){throw new Error(`H3 conversion failed: ${r.message}`)}}(e,t,n)}async getParents(e,t){return Su(e,t)}async getChildren(e){return function(e){if(!xu(e))throw new Error(`Invalid H3 holon ID: ${e}`);try{const t=hu(e);if(t>=15)throw new Error("Cannot get children of resolution 15 cell (maximum resolution)");return bu(e,t+1)}catch(t){throw new Error(`Failed to get children: ${t.message}`)}}(e)}isValidH3(e){return xu(e)}async write(e,t,n,r={}){if(!e||"string"!=typeof e)throw new Cb("ValidationError: holonId must be a non-empty string");if(!t||"string"!=typeof t)throw new Cb("ValidationError: lensName must be a non-empty string");if(!n||"object"!=typeof n)throw new Cb("ValidationError: data must be an object");const i=r.capabilityToken||r.capability;if(i&&!(await this.verifyCapability(i,"write",{holonId:e,lensName:t})))throw new vU("AuthorizationError: Invalid capability token for write operation","write");n.id||(n.id=`${Date.now()}-${Math.random().toString(36).substr(2,9)}`);const s=Du(this.config.appName,e,t,n.id);this._log("DEBUG","write",{holonId:e,lensName:t,dataId:n.id,path:s});const a=await Gu(this.client,s);if(a&&!0===a.hologram&&a.target){const e=["hologram","soul","target","id","_meta"],i=Object.keys(a).filter(t=>!e.includes(t)),o={...a},c={};for(const[t,r]of Object.entries(n))e.includes(t)||"_hologram"===t||(i.includes(t)?o[t]=r:c[t]=r);if(Object.keys(c).length>0&&!1!==r.validate&&this.schemas.has(t)){const e=Du(a.target.appname||this.config.appName,a.target.holonId,a.target.lensName,a.target.dataId),n={...await Gu(this.client,e),...c},i=this.schemas.get(t),s=void 0!==r.strict?r.strict:i.strict;i.schema&&"object"==typeof i.schema&&!i.schema.$ref&&Nb(n,i.schema,t,s)}const A=Date.now();if(await Fu(this.client,s,o),Object.keys(c).length>0){const e=Du(a.target.appname||this.config.appName,a.target.holonId,a.target.lensName,a.target.dataId);await Lu(this.client,e,c),await Sw(this.client,a.target.appname||this.config.appName,a.target.holonId,a.target.lensName,a.target.dataId)}const l=Date.now();return this._metrics.writes++,this._metrics.totalWriteTime||(this._metrics.totalWriteTime=0),this._metrics.totalWriteTime+=l-A,!0}if(n._meta||(n._meta={}),n._meta.createdAt=n._meta.createdAt||Date.now(),n._meta.updatedAt=Date.now(),!1!==r.validate&&this.schemas.has(t)){const e=this.schemas.get(t),i=void 0!==r.strict?r.strict:e.strict;e.schema&&"object"==typeof e.schema&&!e.schema.$ref&&Nb(n,e.schema,t,i)}const o=Date.now();await Fu(this.client,s,n);const c=Date.now();this._metrics.writes++,this._metrics.totalWriteTime||(this._metrics.totalWriteTime=0),this._metrics.totalWriteTime+=c-o;const{autoPropagate:A=!0}=r;return A&&!n.hologram&&await this.propagate(e,t,n,r.propagationOptions||{}),!0}async _resolveHolograms(e,t=new Set){if(!e)return e;if(Array.isArray(e)){const t=[];for(const n of e){const e=await this._resolveHolograms(n,new Set);null!==e&&t.push(e)}return t}if(e&&"object"==typeof e&&!0===e.hologram&&e.target){const n=Du(e.target.appname||this.config.appName,e.target.holonId,e.target.lensName,e.target.dataId);if(this._log("DEBUG","resolving hologram",{hologramId:e.id,sourcePath:n,targetHolon:e.target.holonId,targetLens:e.target.lensName,targetDataId:e.target.dataId}),t.has(n))return this._log("WARN","Circular hologram reference detected",{sourcePath:n}),null;t.add(n);let r={};e.target.authorPubKey&&(r.authors=[e.target.authorPubKey],r.includeAuthor=!0);const i=await Gu(this.client,n,r);if(this._log("DEBUG","hologram source fetched",{found:!!i,sourcePath:n}),i){let n=i;if(!0===i.hologram&&i.target&&(n=await this._resolveHolograms(i,t),null===n))return null;const r=["hologram","soul","target","_meta","id","capability","crossHolosphere"],s={};for(const[t,i]of Object.entries(e))r.includes(t)||(s[t]=i);const a={...n,...s,_hologram:{isHologram:!0,soul:e.soul,sourceHolon:e.target.holonId,source:e.target,localOverrides:Object.keys(s),crossHolosphere:e.crossHolosphere||!1}};return n._meta?a._meta={...n._meta,source:e.target.holonId}:a._meta={source:e.target.holonId},a}return null}return e}async read(e,t,n=null,r={}){if(!e||"string"!=typeof e)throw new Cb("ValidationError: holonId must be a non-empty string");if(!t||"string"!=typeof t)throw new Cb("ValidationError: lensName must be a non-empty string");const i=r.capabilityToken||r.capability;if(i&&!(await this.verifyCapability(i,"read",{holonId:e,lensName:t,dataId:n})))throw new vU("AuthorizationError: Invalid capability token for read operation","read");const s=Date.now();let a;if(n){const r=Du(this.config.appName,e,t,n);this._log("DEBUG","read",{holonId:e,lensName:t,dataId:n,path:r}),a=await Gu(this.client,r),this._log("DEBUG","read result",{found:!!a,isHologram:!0===a?.hologram})}else{const n=Du(this.config.appName,e,t);this._log("DEBUG","readAll",{holonId:e,lensName:t,path:n}),a=await Uu(this.client,n),this._log("DEBUG","readAll result",{count:Array.isArray(a)?a.length:0})}const{resolveHolograms:o=!0}=r;o&&a&&(this._log("DEBUG","resolving holograms",{itemCount:Array.isArray(a)?a.length:1}),a=await this._resolveHolograms(a));const c=Date.now();return this._metrics.reads++,this._metrics.totalReadTime||(this._metrics.totalReadTime=0),this._metrics.totalReadTime+=c-s,a}async update(e,t,n,r,i={}){if(!e||"string"!=typeof e)throw new Cb("ValidationError: holonId must be a non-empty string");if(!t||"string"!=typeof t)throw new Cb("ValidationError: lensName must be a non-empty string");if(!n||"string"!=typeof n)throw new Cb("ValidationError: dataId must be a non-empty string");if(!r||"object"!=typeof r)throw new Cb("ValidationError: updates must be an object");const s=i.capabilityToken||i.capability;if(s&&!(await this.verifyCapability(s,"write",{holonId:e,lensName:t,dataId:n})))throw new vU("AuthorizationError: Invalid capability token for update operation","write");const a=Du(this.config.appName,e,t,n),o=await Gu(this.client,a);if(!o)return!1;if(!0===o.hologram&&o.target)return this.write(e,t,{...o,...r,id:n},i);const c={...o,...r};if(c._meta=c._meta||{},c._meta.updatedAt=Date.now(),!1!==i.validate&&this.schemas.has(t)){const e=this.schemas.get(t),n=void 0!==i.strict?i.strict:e.strict;e.schema&&"object"==typeof e.schema&&!e.schema.$ref&&Nb(c,e.schema,t,n)}const A=Date.now();await Fu(this.client,a,c);const l=Date.now();return this._metrics.writes++,this._metrics.totalWriteTime||(this._metrics.totalWriteTime=0),this._metrics.totalWriteTime+=l-A,o._meta&&o._meta.activeHolograms&&await Sw(this.client,this.config.appName,e,t,n),!0}async delete(e,t,n,r={}){if(!e||"string"!=typeof e)throw new Cb("ValidationError: holonId must be a non-empty string");if(!t||"string"!=typeof t)throw new Cb("ValidationError: lensName must be a non-empty string");if(!n||"string"!=typeof n)throw new Cb("ValidationError: dataId must be a non-empty string");const i=Du(this.config.appName,e,t,n),s=await Gu(this.client,i);if(!s)return!1;const a=s.owner||s._creator,o=!a||a===this.client.publicKey,c=r.capabilityToken||r.capability;if(o){if(c&&!(await this.verifyCapability(c,"delete",{holonId:e,lensName:t,dataId:n})))throw new vU("AuthorizationError: Invalid capability token for delete operation","delete")}else{if(!c)throw new vU("AuthorizationError: Capability token required for delete operation","delete");if(!(await this.verifyCapability(c,"delete",{holonId:e,lensName:t,dataId:n})))throw new vU("AuthorizationError: Invalid capability token for delete operation","delete")}return!0===s.hologram?this.deleteHologram(e,t,n,r):(await ju(this.client,i),this._metrics.deletes++,!0)}async writeGlobal(e,t){return qu(this.client,this.config.appName,e,t)}async readGlobal(e,t=null){return Qu(this.client,this.config.appName,e,t)}async updateGlobal(e,t,n){return async function(e,t,n,r,i){return Lu(e,`${t}/${n}/${r}`,i)}(this.client,this.config.appName,e,t,n)}async deleteGlobal(e,t){return async function(e,t,n,r){return ju(e,`${t}/${n}/${r}`)}(this.client,this.config.appName,e,t)}async getAllGlobal(e){return async function(e,t,n){return Uu(e,`${t}/${n}`)}(this.client,this.config.appName,e)}async deleteAllGlobal(e){return async function(e,t,n){return Hu(e,`${t}/${n}`)}(this.client,this.config.appName,e)}async getAll(e,t){return this.read(e,t,null)}async deleteAll(e,t){const n=Du(this.config.appName,e,t);return Hu(this.client,n)}async setSchema(e,t,n=!1){if(!e||"string"!=typeof e)throw new Cb("ValidationError: lensName must be a non-empty string");if(null==t)throw new Cb("ValidationError: schema cannot be null or undefined");let r;if("string"==typeof t)r={$ref:t};else{if("object"!=typeof t)throw new Cb("ValidationError: schema must be an object or URI string");if(!(t.$ref||t.type||t.properties||t.items||t.allOf||t.anyOf||t.oneOf||t.$schema))throw new Cb("ValidationError: Invalid JSON Schema format");r=t}this.schemas.set(e,{schema:r,strict:n,timestamp:Date.now()})}async getSchema(e){const t=this.schemas.get(e);return t?t.schema:null}async clearSchema(e){this.schemas.delete(e)}async federate(e,t,n,r={}){const{direction:i="outbound",mode:s="reference",filter:a=null}=r;if(e===t)throw new Error("Cannot federate a holon with itself");if(!["inbound","outbound","bidirectional"].includes(i))throw new Error(`Invalid direction: ${i}. Must be 'inbound', 'outbound', or 'bidirectional'`);return await async function(e,t,n,r,i,s={}){const{direction:a="outbound",mode:o="reference"}=s,c={sourceHolon:n,targetHolon:r,lensName:i,direction:a,mode:o,created:Date.now()};return Fu(e,Du(t,n,i,"_federation"),c)}(this.client,this.config.appName,e,t,n,r),"outbound"!==i&&"bidirectional"!==i||await this._propagateExistingData(e,t,n,{mode:s,filter:a}),"inbound"!==i&&"bidirectional"!==i||await this._propagateExistingData(t,e,n,{mode:s,filter:a}),this._metrics.federations=(this._metrics.federations||0)+1,!0}async _propagateExistingData(e,t,n,r={}){const{mode:i="reference",filter:s=null}=r,a=await this.read(e,n,null,{resolveHolograms:!1});if(!a)return;const o=Array.isArray(a)?a:[a];for(const c of o)!0!==c.hologram&&(s&&!s(c)||await _w(this.client,this.config.appName,c,e,t,n,i))}async getFederatedData(e,t,n={}){const{resolveHolograms:r=!0}=n,i=Du(this.config.appName,e,t),s=await Uu(this.client,i);return s&&r?this._resolveHolograms(s):s}async unfederate(e,t,n){const r=Du(this.config.appName,e,n,"_federation");try{await ju(this.client,r)}catch(i){}return!0}async updateHologramOverrides(e,t,n,r){return async function(e,t,n,r,i,s){const a=Du(t,n,r,i),o=await Gu(e,a);if(!o)return console.warn(`Hologram not found at ${a}`),!1;if(!o.hologram)return console.warn(`Data at ${a} is not a hologram, cannot update overrides`),!1;const c=["hologram","soul","target","_meta","id"],A={};for(const[l,f]of Object.entries(s))c.includes(l)||(A[l]=f);return Fu(e,a,{...o,...A})}(this.client,this.config.appName,e,t,n,r)}createHologram(e,t,n,r=null){return ww(e,0,t,n.id,this.config.appName)}async getActiveHolograms(e,t,n){const r=Du(this.config.appName,e,t,n),i=await Gu(this.client,r);return i&&i._meta&&i._meta.activeHolograms?i._meta.activeHolograms:[]}async removeActiveHologram(e,t,n,r){return Tw(this.client,this.config.appName,e,t,n,r)}async deleteHologram(e,t,n,r={}){return xw(this.client,this.config.appName,e,t,n,r)}async propagateData(e,t,n,r,i={}){const s=i.mode||"reference";return _w(this.client,this.config.appName,e,t,n,r,s)}async resolveHologram(e,t={}){return vw(this.client,e,new Set,[],{...t,appname:this.config.appName})}isHologram(e){return function(e){return e&&!0===e.hologram}(e)}isResolvedHologram(e){return Ew(e)}getHologramSource(e){return function(e){return Ew(e)?{soul:e._hologram.soul,sourceHolon:e._hologram.sourceHolon,localOverrides:e._hologram.localOverrides||[]}:null}(e)}async cleanupCircularHolograms(e,t,n={}){return async function(e,t,n,r,i={}){const{dryRun:s=!1}=i,a={scanned:0,circularFound:0,deleted:0,errors:[],details:[]};console.info(`🧹 ${s?"[DRY RUN] ":""}Cleaning up circular holograms in ${n}/${r}...`);try{Du(t,n,r);const i=Du(t,n,r,"_index"),o=await Gu(e,i);if(!o||!Array.isArray(o.items))return console.warn(` No index found for ${n}/${r}, cannot scan for circular references`),console.info(" Tip: Provide specific IDs to check using cleanupCircularHologramsByIds()"),a;for(const c of o.items){a.scanned++;const i=Du(t,n,r,c),o=await Gu(e,i);if(!o||!0!==o.hologram||!o.target)continue;const A=o.target.holonId,l=o.target.dataId||c,f=o.target.lensName||r,u=Du(o.target.appname||t,A,f,l),d=await Gu(e,u);if(d&&!0===d.hologram&&d.target&&d.target.holonId===n){a.circularFound++;const o={itemId:c,path:i,pointsTo:`${A}/${f}/${l}`,circularWith:`${d.target.holonId}/${d.target.lensName}/${d.target.dataId}`};if(a.details.push(o),console.warn(" 🔄 Found circular hologram:"),console.warn(` ${n}/${r}/${c} → ${A}/${f}/${l} → ${n}`),!s){const i=await xw(e,t,n,r,c);i.success?(a.deleted++,console.info(" ✓ Deleted circular hologram")):(a.errors.push({itemId:c,error:i.error}),console.error(` ❌ Failed to delete: ${i.error}`))}}}return console.info(`🧹 Cleanup complete for ${n}/${r}:`),console.info(` Scanned: ${a.scanned}`),console.info(` Circular found: ${a.circularFound}`),console.info(` Deleted: ${a.deleted}`),a.errors.length>0&&console.warn(` Errors: ${a.errors.length}`),a}catch(o){return console.error("❌ Error during cleanup:",o),a.errors.push({error:o.message}),a}}(this.client,this.config.appName,e,t,n)}async cleanupCircularHologramsByIds(e,t,n,r={}){return async function(e,t,n,r,i,s={}){const{dryRun:a=!1}=s,o={scanned:0,circularFound:0,deleted:0,errors:[],details:[]};console.info(`🧹 ${a?"[DRY RUN] ":""}Cleaning up circular holograms for ${i.length} IDs in ${n}/${r}...`);for(const c of i){o.scanned++;const i=Du(t,n,r,c),s=await Gu(e,i);if(!s||!0!==s.hologram||!s.target)continue;const A=s.target.holonId,l=s.target.dataId||c,f=s.target.lensName||r,u=Du(s.target.appname||t,A,f,l),d=await Gu(e,u);if(d&&!0===d.hologram&&d.target&&d.target.holonId===n){o.circularFound++;const s={itemId:c,path:i,pointsTo:`${A}/${f}/${l}`,circularWith:`${d.target.holonId}/${d.target.lensName}/${d.target.dataId}`};if(o.details.push(s),console.warn(` 🔄 Found circular hologram: ${c}`),console.warn(` Chain: ${n} → ${A} → ${n}`),!a){const i=await xw(e,t,n,r,c);i.success?(o.deleted++,console.info(" ✓ Deleted")):(o.errors.push({itemId:c,error:i.error}),console.error(` ❌ Failed: ${i.error}`))}}}return console.info(`🧹 Cleanup complete: scanned=${o.scanned}, circular=${o.circularFound}, deleted=${o.deleted}`),o}(this.client,this.config.appName,e,t,n,r)}async propagate(e,t,n,r={}){const i=await this.getFederation(e),s=i?.federated||i?.outbound||[];if(!s||0===s.length)return;const{useHolograms:a=!0,resolveExisting:o=!0}=r,c=[];for(const A of s){const r=await this.propagateData(n,e,A,t,{useHolograms:a,resolveExisting:o});c.push({parent:A,...r})}return c}async getFederation(e){if(!e)throw new Error("getFederation: Missing holon ID");const t=await this.readGlobal("federation",e);if(!t)return null;if(Array.isArray(t.inbound)||(t.inbound=[]),Array.isArray(t.outbound)||(t.outbound=[]),t.lensConfig&&"object"==typeof t.lensConfig||(t.lensConfig={}),t.partnerNames&&"object"==typeof t.partnerNames||(t.partnerNames={}),!Array.isArray(t.federated)){const e=new Set([...t.inbound,...t.outbound]);t.federated=Array.from(e)}return t}async federateHolon(e,t,n={}){const{lensConfig:r={inbound:[],outbound:[]},partnerName:i=null,skipPropagation:s=!1}=n;if(e===t)throw new Error("Cannot federate a holon with itself");let a=await this.readGlobal("federation",e)||{id:e,name:e,federated:[],inbound:[],outbound:[],lensConfig:{},partnerNames:{},timestamp:Date.now()};Array.isArray(a.federated)||(a.federated=[]),Array.isArray(a.inbound)||(a.inbound=[]),Array.isArray(a.outbound)||(a.outbound=[]),a.lensConfig&&"object"==typeof a.lensConfig||(a.lensConfig={}),a.partnerNames&&"object"==typeof a.partnerNames||(a.partnerNames={}),a.federated.includes(t)||a.federated.push(t),i&&(a.partnerNames[t]=i),r.outbound&&r.outbound.length>0?a.outbound.includes(t)||a.outbound.push(t):a.outbound=a.outbound.filter(e=>e!==t),r.inbound&&r.inbound.length>0?a.inbound.includes(t)||a.inbound.push(t):a.inbound=a.inbound.filter(e=>e!==t),a.lensConfig[t]={inbound:r.inbound||[],outbound:r.outbound||[],timestamp:Date.now()};const o=await this.writeGlobal("federation",a);if(this.clearCache("federation"),o&&!s){for(const n of r.inbound||[])await this.federate(t,e,n,{direction:"outbound",mode:"reference"});for(const n of r.outbound||[])await this.federate(e,t,n,{direction:"outbound",mode:"reference"})}return o}async unfederateHolon(e,t){const n=await this.readGlobal("federation",e);if(!n)return!1;const r=n.lensConfig?.[t];n.federated=(n.federated||[]).filter(e=>e!==t),n.inbound=(n.inbound||[]).filter(e=>e!==t),n.outbound=(n.outbound||[]).filter(e=>e!==t),n.lensConfig&&delete n.lensConfig[t];const i=await this.writeGlobal("federation",n);if(this.clearCache("federation"),i&&r){for(const n of r.inbound||[])await this.unfederate(t,e,n);for(const n of r.outbound||[])await this.unfederate(e,t,n)}return i}async getFederatedConfig(e,t){const n=await this.readGlobal("federation",e);return n&&n.lensConfig&&n.lensConfig[t]||null}async upcast(e,t,n,r={}){return async function(e,t,n,r,i={}){const{maxLevel:s=3,operation:a="concatenate"}=i,o=e.client,c=e.config.appName;if(!xu(t))throw new Error("Upcast only supported for geographic (H3) holons, not noospheric holons");const A=Su(t).slice(0,s);if(0===A.length)return!0;const l=A.map(async e=>async function(e,t,n,r,i,s,a){const o=ww(n,0,i,s,t);return o._meta.operation=a,o._meta.upcast=!0,Fu(e,`${t}/${r}/${i}/${s}`,o)}(o,c,t,e,n,r,a));return await Promise.all(l),!0}(this,e,t,n,r)}subscribe(e,t,n,r={}){if("function"!=typeof n)throw new TypeError("callback must be a function");const i=Du(this.config.appName,e,t),s={realtimeOnly:!0,...r},a=`${e}-${t}-${Date.now()}-${Math.random().toString(36).substr(2,9)}`;let o=null,c=!1;return async function(e,t,n,r={}){const{throttle:i=0,filter:s=null,includeFederated:a=!1,triggerInitial:o=!1,realtimeOnly:c=!0,resolveHolograms:A=!0}=r;let l=0,f=null;const u=new Set;let d=!0;const h=await zu(e,t,async(t,r)=>{if(!d)return;const a=`${r}-${t?.id||""}-${t?._meta?.timestamp||Date.now()}`;if(u.has(a))return;u.add(a);let o=t;if(A&&t&&!0===t.hologram)try{if(o=await vw(e,t),!o)return}catch(h){return void console.warn("Failed to resolve hologram in subscription:",h)}if(s&&!s(o,r))return;const c=Date.now();if(i>0&&c-l<i)return f&&clearTimeout(f),void(f=setTimeout(()=>{l=Date.now(),n(o,r)},i-(c-l)));l=c,n(o,r)},{realtimeOnly:c});return{path:t,unsubscribe:()=>{d=!1,f&&clearTimeout(f),h&&h.unsubscribe&&h.unsubscribe(),u.clear()}}}(this.client,i,n,s).then(e=>{o=e,c?e.unsubscribe():this.subscriptionRegistry.register(a,e)}).catch(e=>{this._log("ERROR","Subscription setup failed",{path:i,error:e.message})}),this._metrics.subscriptions=(this._metrics.subscriptions||0)+1,{unsubscribe:()=>{c=!0,o&&this.subscriptionRegistry.unregister(a)}}}async subscribeGlobal(e,t,n,r={}){return async function(e,t,n,r,i,s={}){return zu(e,r?`${t}/${n}/${r}`:`${t}/${n}`,i,s)}(this.client,this.config.appName,e,t,n,r)}async getPublicKey(e){return async function(e){return Hb((await ow()).getPublicKey(e))}(e)}async sign(e,t){return cw(e,t)}async verify(e,t,n){return async function(e,t,n){try{if(!n||"string"!=typeof n||n.length<64)throw new Error("Invalid public key format");const r=await ow(),i=uw(e);return r.verify(t,i,n)}catch(r){if("Invalid public key format"===r.message)throw r;return!1}}(e,t,n)}async issueCapability(e,t,n,r){return lw(e,t,n,r)}async verifyCapability(e,t,n){return fw(e,t,n)}async publishNostr(e,t,n="social"){!function(e,t=!0,n=!1){if(!e||"object"!=typeof e){if(n)throw new Cb("ValidationError: Invalid Nostr event format");return!1}if("number"!=typeof e.kind){if(n)throw new Cb("ValidationError: Invalid Nostr event format - kind must be a number");return!1}if(!Array.isArray(e.tags)){if(n)throw new Cb("ValidationError: Invalid Nostr event format - tags must be an array");return!1}if("string"!=typeof e.content){if(n)throw new Cb("ValidationError: Invalid Nostr event format - content must be a string");return!1}if("number"!=typeof e.created_at){if(n)throw new Cb("ValidationError: Invalid Nostr event format - created_at must be a number");return!1}if(!t){if("string"!=typeof e.id){if(n)throw new Cb("ValidationError: Invalid Nostr event format - id must be a string");return!1}if("string"!=typeof e.pubkey){if(n)throw new Cb("ValidationError: Invalid Nostr event format - pubkey must be a string");return!1}if("string"!=typeof e.sig&&n)throw new Cb("ValidationError: Invalid Nostr event format - sig must be a string")}}(e,!0,!0);const r=function(e,t){const n={kind:e.kind,content:e.content,tags:e.tags||[],created_at:e.created_at||Math.floor(Date.now()/1e3)};return Fa(n,function(e){const t=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)t[n/2]=parseInt(e.substr(n,2),16);return t}(t))}({...e,tags:[...e.tags||[],["h",t],["l",n]]},this.client.privateKey),i={...r,protocol:"nostr"},s=Du(this.config.appName,t,n,r.id);return await Fu(this.client,s,i),!0}async publishActivityPub(e,t,n="social"){!function(e,t=!1,n=!1){if(!e||"object"!=typeof e){if(t)throw new Cb("ValidationError: Invalid ActivityPub object format");return!1}if(!e["@context"]){if(t)throw new Cb("ValidationError: Invalid ActivityPub object format - @context is required");return!1}if("string"!=typeof e.type){if(t)throw new Cb("ValidationError: Invalid ActivityPub object format - type must be a string");return!1}if(n&&"string"!=typeof e.id&&t)throw new Cb("ValidationError: Invalid ActivityPub object format - id must be a string")}(e,!0);const r=function(e){const t=e.id||`ap-${Date.now()}-${Math.random().toString(36).substr(2,9)}`;return{id:t,protocol:"activitypub",type:e.type,actor:e.actor,published:e.published,content:e.content||e.name,originalObject:{...e,id:t},_meta:{timestamp:e.published?new Date(e.published).getTime():Date.now(),protocol:"activitypub"}}}({...e,actor:e.actor||this.client.publicKey});return this.write(t,n,r)}async querySocial(e,t={}){const n=t.lens||"social",r=await this.read(e,n);return r?(Array.isArray(r)?r:[r]).filter(e=>!(t.protocol&&"all"!==t.protocol&&e.protocol!==t.protocol||t.type&&e.type!==t.type||t.since&&e.created_at<t.since||t.until&&e.created_at>t.until)):[]}async verifyNostrEvent(e){const{id:t,pubkey:n,created_at:r,kind:i,tags:s,content:a,sig:o}=e;return function(e){return Ga(e)}({id:t,pubkey:n,created_at:r,kind:i,tags:s,content:a,sig:o})}metrics(){const e=this._metrics.reads||0,t=this._metrics.writes||0,n=this._metrics.totalReadTime||0,r=this._metrics.totalWriteTime||0;return{reads:e,writes:t,deletes:this._metrics.deletes||0,federations:this._metrics.federations||0,subscriptions:this._metrics.subscriptions||0,avgReadTime:e>0?n/e:0,avgWriteTime:t>0?r/t:0}}async put(e,t,n,r={}){return this.write(e,t,n,r)}async get(e,t,n=null,r={}){return this.read(e,t,n,r)}async remove(e,t,n,r={}){return this.delete(e,t,n,r)}async putGlobal(e,t){return this.writeGlobal(e,t)}async getGlobal(e,t=null){return this.readGlobal(e,t)}async removeGlobal(e,t){return this.deleteGlobal(e,t)}async defineSchema(e,t,n=!1){return this.setSchema(e,t,n)}async fetchSchema(e){return this.getSchema(e)}async removeSchema(e){return this.clearSchema(e)}async store(e,t,n,r={}){return this.write(e,t,n,r)}async fetch(e,t,n=null,r={}){return this.read(e,t,n,r)}async save(e,t,n,r={}){return this.write(e,t,n,r)}async load(e,t,n=null,r={}){return this.read(e,t,n,r)}clearCache(e=null){if(e)for(const t of this._cache.keys())t.includes(e)&&this._cache.delete(t);else this._cache.clear()}},class extends kU{_requireAI(){if(!this._ai)throw new Error("AI services not initialized. Provide openaiKey in config.")}async summarize(e,t={}){return this._requireAI(),this._ai.llm.summarize(e,t)}async analyze(e,t,n={}){return this._requireAI(),this._ai.llm.analyze(e,t,n)}async extractKeywords(e,t={}){return this._requireAI(),this._ai.llm.extractKeywords(e,t)}async categorize(e,t,n={}){return this._requireAI(),this._ai.llm.categorize(e,t,n)}async translate(e,t,n={}){return this._requireAI(),this._ai.llm.translate(e,t,n)}async generateQuestions(e,t={}){return this._requireAI(),this._ai.llm.generateQuestions(e,t)}async extractToSchema(e,t,n={}){this._requireAI();const r=await this.getSchema(t);if(!r)throw new Error(`No schema found for lens: ${t}`);return this._ai.schemaExtractor.extractToSchema(e,r,n)}async jsonAdd(e,t,n={}){return this._requireAI(),this._ai.jsonOps.add(e,t,n)}async jsonSubtract(e,t,n={}){return this._requireAI(),this._ai.jsonOps.subtract(e,t,n)}async jsonUnion(e,t,n={}){return this._requireAI(),this._ai.jsonOps.union(e,t,n)}async jsonDifference(e,t,n={}){return this._requireAI(),this._ai.jsonOps.difference(e,t,n)}async jsonConcatenate(e,t,n={}){return this._requireAI(),this._ai.jsonOps.concatenate(e,t,n)}async embed(e){return this._requireAI(),this._ai.embeddings.embed(e)}async semanticSearch(e,t,n,r={}){return this._requireAI(),this._ai.embeddings.semanticSearch(e,t,n,r)}async storeWithEmbedding(e,t,n,r="description"){return this._requireAI(),this._ai.embeddings.storeWithEmbedding(e,t,n,r)}async askCouncil(e,t={}){return this._requireAI(),this._ai.council.ask(e,t)}async askCouncilCustom(e,t,n={}){return this._requireAI(),this._ai.council.askCustom(e,t,n)}async textToSpeech(e,t="nova",n={}){return this._requireAI(),this._ai.tts.speak(e,t,n)}async textToSpeechBase64(e,t="nova",n={}){return this._requireAI(),this._ai.tts.speakBase64(e,t,n)}async nlQuery(e,t=null,n=null,r={}){return this._requireAI(),this._ai.nlQuery.execute(e,t,n,r)}async parseNLQuery(e){return this._requireAI(),this._ai.nlQuery.parse(e)}async classifyToLens(e,t={}){return this._requireAI(),this._ai.classifier.classifyToLens(e,t)}async autoStore(e,t,n={}){return this._requireAI(),this._ai.classifier.autoStore(e,t,n)}registerLensForClassification(e,t,n=[]){this._requireAI(),this._ai.classifier.registerLens(e,t,n)}async analyzeRegion(e,t=null,n=null,r={}){return this._requireAI(),this._ai.spatial.analyzeRegion(e,t,n,r)}async compareRegions(e,t,n=null){return this._requireAI(),this._ai.spatial.compareRegions(e,t,n)}async spatialTrends(e,t,n=null){return this._requireAI(),this._ai.spatial.spatialTrends(e,t,n)}async smartUpcast(e,t,n={}){return this._requireAI(),this._ai.aggregation.smartUpcast(e,t,n)}async generateHolonSummary(e){return this._requireAI(),this._ai.aggregation.generateHolonSummary(e)}async suggestFederations(e,t={}){return this._requireAI(),this._ai.federationAdvisor.suggestFederations(e,t)}async analyzeFederationHealth(e){return this._requireAI(),this._ai.federationAdvisor.analyzeFederationHealth(e)}async optimizeFederation(e){return this._requireAI(),this._ai.federationAdvisor.optimizeFederation(e)}async discoverRelationships(e,t=null){return this._requireAI(),this._ai.relationships.discoverRelationships(e,t)}async findSimilar(e,t,n=null,r={}){return this._requireAI(),this._ai.relationships.findSimilar(e,t,n,r)}async buildRelationshipGraph(e,t){return this._requireAI(),this._ai.relationships.buildGraph(e,t)}async suggestConnections(e,t,n){return this._requireAI(),this._ai.relationships.suggestConnections(e,t,n)}async breakdown(e,t,n,r={}){return this._requireAI(),this._ai.taskBreakdown.breakdown(e,t,n,r)}async suggestBreakdownStrategy(e){return this._requireAI(),this._ai.taskBreakdown.suggestStrategy(e)}flattenBreakdown(e){return this._requireAI(),this._ai.taskBreakdown.flatten(e)}getBreakdownDependencyOrder(e){return this._requireAI(),this._ai.taskBreakdown.getDependencyOrder(e)}async getBreakdownProgress(e,t,n){return this._requireAI(),this._ai.taskBreakdown.getProgress(e,t,n)}async suggestH3Resolution(e,t={}){return this._requireAI(),this._ai.h3ai.suggestResolution(e,t)}async analyzeH3Distribution(e,t,n={}){return this._requireAI(),this._ai.h3ai.analyzeDistribution(e,t,n)}async findH3NeighborRelevance(e,t,n={}){return this._requireAI(),this._ai.h3ai.findNeighborRelevance(e,t,n)}async suggestGeographicScope(e,t,n,r={}){return this._requireAI(),this._ai.h3ai.suggestGeographicScope(e,t,n,r)}async analyzeH3Coverage(e,t,n={}){return this._requireAI(),this._ai.h3ai.analyzeCoverage(e,t,n)}async crossH3ResolutionInsights(e,t,n={}){return this._requireAI(),this._ai.h3ai.crossResolutionInsights(e,t,n)}async suggestH3Migration(e,t,n,r={}){return this._requireAI(),this._ai.h3ai.suggestMigration(e,t,n,r)}async generateH3Report(e,t={}){return this._requireAI(),this._ai.h3ai.generateGeographicReport(e,t)}async findH3Clusters(e,t,n={}){return this._requireAI(),this._ai.h3ai.findGeographicClusters(e,t,n)}async analyzeH3Impact(e,t,n,r={}){return this._requireAI(),this._ai.h3ai.analyzeGeographicImpact(e,t,n,r)}})));var kU;"undefined"!=typeof window&&(window.h3=Tu);const TU=Object.freeze(Object.defineProperty({__proto__:null,IndexedDBStorage:class extends Sl{constructor(){super(),this.db=null,this.dbName="",this.storeName="events"}async init(e){return this.dbName=`holosphere_${e}`,new Promise((e,t)=>{const n=indexedDB.open(this.dbName,1);n.onerror=()=>t(n.error),n.onsuccess=()=>{this.db=n.result,e(void 0)},n.onupgradeneeded=e=>{const t=e.target.result;t.objectStoreNames.contains(this.storeName)||t.createObjectStore(this.storeName,{keyPath:"key"}).createIndex("key","key",{unique:!1})}})}async put(e,t){return new Promise((n,r)=>{if(!this.db)return void r(new Error("Database not initialized"));const i=this.db.transaction([this.storeName],"readwrite").objectStore(this.storeName).put({key:e,event:t,timestamp:Date.now()});i.onsuccess=()=>n(void 0),i.onerror=()=>r(i.error)})}async get(e){return new Promise((t,n)=>{if(!this.db)return void n(new Error("Database not initialized"));const r=this.db.transaction([this.storeName],"readonly").objectStore(this.storeName).get(e);r.onsuccess=()=>{const e=r.result;t(e?e.event:null)},r.onerror=()=>n(r.error)})}async getAll(e){return new Promise((t,n)=>{if(!this.db)return void n(new Error("Database not initialized"));const r=this.db.transaction([this.storeName],"readonly").objectStore(this.storeName),i=[];let s;if(e){const t=IDBKeyRange.bound(e,e+"￿",!1,!1);s=r.openCursor(t)}else s=r.openCursor();s.onsuccess=e=>{const n=e.target.result;n?(i.push(n.value.event),n.continue()):t(i)},s.onerror=()=>n(s.error)})}async delete(e){return new Promise((t,n)=>{if(!this.db)return void n(new Error("Database not initialized"));const r=this.db.transaction([this.storeName],"readwrite").objectStore(this.storeName).delete(e);r.onsuccess=()=>t(void 0),r.onerror=()=>n(r.error)})}async clear(){return new Promise((e,t)=>{if(!this.db)return void t(new Error("Database not initialized"));const n=this.db.transaction([this.storeName],"readwrite").objectStore(this.storeName).clear();n.onsuccess=()=>e(void 0),n.onerror=()=>t(n.error)})}async close(){this.db&&(this.db.close(),this.db=null)}}},Symbol.toStringTag,{value:"Module"}));class SU extends Sl{constructor(){super(),this.data=new Map,this.namespace=null}async init(e){this.namespace=e,SU._globalStore||(SU._globalStore=new Map),SU._globalStore.has(e)||SU._globalStore.set(e,new Map),this.data=SU._globalStore.get(e)}async put(e,t){this.data.set(e,JSON.parse(JSON.stringify(t)))}async get(e){const t=this.data.get(e);return t?JSON.parse(JSON.stringify(t)):null}async getAll(e){const t=[];for(const[n,r]of this.data.entries())n.startsWith(e)&&t.push(JSON.parse(JSON.stringify(r)));return t}async delete(e){this.data.delete(e)}async clear(){this.data.clear()}async close(){}}SU._globalStore=null;const xU=Object.freeze(Object.defineProperty({__proto__:null,MemoryStorage:SU},Symbol.toStringTag,{value:"Module"})),IU=Vu(function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}),PU=Object.freeze(Object.defineProperty({__proto__:null,default:IU},Symbol.toStringTag,{value:"Module"}));var CU={exports:{}},NU={},OU={};Object.defineProperty(OU,"__esModule",{value:!0}),OU.dynamicAnchor=void 0;const RU=Xu,BU=md,MU=fp,$U=um,DU={keyword:"$dynamicAnchor",schemaType:"string",code:e=>FU(e,e.schema)};function FU(e,t){const{gen:n,it:r}=e;r.schemaEnv.root.dynamicAnchors[t]=!0;const i=RU._`${BU.default.dynamicAnchors}${(0,RU.getProperty)(t)}`,s="#"===r.errSchemaPath?r.validateName:function(e){const{schemaEnv:t,schema:n,self:r}=e.it,{root:i,baseId:s,localRefs:a,meta:o}=t.root,{schemaId:c}=r.opts,A=new MU.SchemaEnv({schema:n,schemaId:c,root:i,baseId:s,localRefs:a,meta:o});return MU.compileSchema.call(r,A),(0,$U.getValidate)(e,A)}(e);n.if(RU._`!${i}`,()=>n.assign(i,s))}OU.dynamicAnchor=FU,OU.default=DU;var GU={};Object.defineProperty(GU,"__esModule",{value:!0}),GU.dynamicRef=void 0;const UU=Xu,LU=md,jU=um,HU={keyword:"$dynamicRef",schemaType:"string",code:e=>zU(e,e.schema)};function zU(e,t){const{gen:n,keyword:r,it:i}=e;if("#"!==t[0])throw new Error(`"${r}" only supports hash fragment reference`);const s=t.slice(1);if(i.allErrors)a();else{const t=n.let("valid",!1);a(t),e.ok(t)}function a(e){if(i.schemaEnv.root.dynamicAnchors[s]){const t=n.let("_v",UU._`${LU.default.dynamicAnchors}${(0,UU.getProperty)(s)}`);n.if(t,o(t,e),o(i.validateName,e))}else o(i.validateName,e)()}function o(t,r){return r?()=>n.block(()=>{(0,jU.callRef)(e,t),n.let(r,!0)}):()=>(0,jU.callRef)(e,t)}}GU.dynamicRef=zU,GU.default=HU;var qU={};Object.defineProperty(qU,"__esModule",{value:!0});const QU=OU,VU=nd,JU={keyword:"$recursiveAnchor",schemaType:"boolean",code(e){e.schema?(0,QU.dynamicAnchor)(e,""):(0,VU.checkStrictMode)(e.it,"$recursiveAnchor: false is ignored")}};qU.default=JU;var KU={};Object.defineProperty(KU,"__esModule",{value:!0});const WU=GU,YU={keyword:"$recursiveRef",schemaType:"string",code:e=>(0,WU.dynamicRef)(e,e.schema)};KU.default=YU,Object.defineProperty(NU,"__esModule",{value:!0});const ZU=GU,XU=qU,eL=KU,tL=[OU.default,ZU.default,XU.default,eL.default];NU.default=tL;var nL={},rL={};Object.defineProperty(rL,"__esModule",{value:!0});const iL=tg,sL={keyword:"dependentRequired",type:"object",schemaType:"object",error:iL.error,code:e=>(0,iL.validatePropertyDeps)(e)};rL.default=sL;var aL={};Object.defineProperty(aL,"__esModule",{value:!0});const oL=tg,cL={keyword:"dependentSchemas",type:"object",schemaType:"object",code:e=>(0,oL.validateSchemaDeps)(e)};aL.default=cL;var AL={};Object.defineProperty(AL,"__esModule",{value:!0});const lL=nd,fL={keyword:["maxContains","minContains"],type:"array",schemaType:"number",code({keyword:e,parentSchema:t,it:n}){void 0===t.contains&&(0,lL.checkStrictMode)(n,`"${e}" without "contains" is ignored`)}};AL.default=fL,Object.defineProperty(nL,"__esModule",{value:!0});const uL=aL,dL=AL,hL=[rL.default,uL.default,dL.default];nL.default=hL;var pL={},mL={};Object.defineProperty(mL,"__esModule",{value:!0});const yL=Xu,gL=nd,bL=md,wL={keyword:"unevaluatedProperties",type:"object",schemaType:["boolean","object"],trackErrors:!0,error:{message:"must NOT have unevaluated properties",params:({params:e})=>yL._`{unevaluatedProperty: ${e.unevaluatedProperty}}`},code(e){const{gen:t,schema:n,data:r,errsCount:i,it:s}=e;if(!i)throw new Error("ajv implementation error");const{allErrors:a,props:o}=s;function c(r){if(!1===n)return e.setParams({unevaluatedProperty:r}),e.error(),void(a||t.break());if(!(0,gL.alwaysValidSchema)(s,n)){const n=t.name("valid");e.subschema({keyword:"unevaluatedProperties",dataProp:r,dataPropType:gL.Type.Str},n),a||t.if((0,yL.not)(n),()=>t.break())}}o instanceof yL.Name?t.if(yL._`${o} !== true`,()=>t.forIn("key",r,e=>t.if(function(e,t){return yL._`!${e} || !${e}[${t}]`}(o,e),()=>c(e)))):!0!==o&&t.forIn("key",r,e=>void 0===o?c(e):t.if(function(e,t){const n=[];for(const r in e)!0===e[r]&&n.push(yL._`${t} !== ${r}`);return(0,yL.and)(...n)}(o,e),()=>c(e))),s.props=!0,e.ok(yL._`${i} === ${bL.default.errors}`)}};mL.default=wL;var vL={};Object.defineProperty(vL,"__esModule",{value:!0});const _L=Xu,EL=nd,kL={keyword:"unevaluatedItems",type:"array",schemaType:["boolean","object"],error:{message:({params:{len:e}})=>_L.str`must NOT have more than ${e} items`,params:({params:{len:e}})=>_L._`{limit: ${e}}`},code(e){const{gen:t,schema:n,data:r,it:i}=e,s=i.items||0;if(!0===s)return;const a=t.const("len",_L._`${r}.length`);if(!1===n)e.setParams({len:s}),e.fail(_L._`${a} > ${s}`);else if("object"==typeof n&&!(0,EL.alwaysValidSchema)(i,n)){const n=t.var("valid",_L._`${a} <= ${s}`);t.if((0,_L.not)(n),()=>function(n,r){t.forRange("i",r,a,r=>{e.subschema({keyword:"unevaluatedItems",dataProp:r,dataPropType:EL.Type.Num},n),i.allErrors||t.if((0,_L.not)(n),()=>t.break())})}(n,s)),e.ok(n)}i.items=!0}};vL.default=kL,Object.defineProperty(pL,"__esModule",{value:!0});const TL=vL,SL=[mL.default,TL.default];pL.default=SL;var xL={};Object.defineProperty(xL,"__esModule",{value:!0});const IL={$schema:"https://json-schema.org/draft/2019-09/schema",$id:"https://json-schema.org/draft/2019-09/schema",$vocabulary:{"https://json-schema.org/draft/2019-09/vocab/core":!0,"https://json-schema.org/draft/2019-09/vocab/applicator":!0,"https://json-schema.org/draft/2019-09/vocab/validation":!0,"https://json-schema.org/draft/2019-09/vocab/meta-data":!0,"https://json-schema.org/draft/2019-09/vocab/format":!1,"https://json-schema.org/draft/2019-09/vocab/content":!0},$recursiveAnchor:!0,title:"Core and Validation specifications meta-schema",allOf:[{$ref:"meta/core"},{$ref:"meta/applicator"},{$ref:"meta/validation"},{$ref:"meta/meta-data"},{$ref:"meta/format"},{$ref:"meta/content"}],type:["object","boolean"],properties:{definitions:{$comment:"While no longer an official keyword as it is replaced by $defs, this keyword is retained in the meta-schema to prevent incompatible extensions as it remains in common use.",type:"object",additionalProperties:{$recursiveRef:"#"},default:{}},dependencies:{$comment:'"dependencies" is no longer a keyword, but schema authors should avoid redefining it to facilitate a smooth transition to "dependentSchemas" and "dependentRequired"',type:"object",additionalProperties:{anyOf:[{$recursiveRef:"#"},{$ref:"meta/validation#/$defs/stringArray"}]}}}},PL={$schema:"https://json-schema.org/draft/2019-09/schema",$id:"https://json-schema.org/draft/2019-09/meta/applicator",$vocabulary:{"https://json-schema.org/draft/2019-09/vocab/applicator":!0},$recursiveAnchor:!0,title:"Applicator vocabulary meta-schema",type:["object","boolean"],properties:{additionalItems:{$recursiveRef:"#"},unevaluatedItems:{$recursiveRef:"#"},items:{anyOf:[{$recursiveRef:"#"},{$ref:"#/$defs/schemaArray"}]},contains:{$recursiveRef:"#"},additionalProperties:{$recursiveRef:"#"},unevaluatedProperties:{$recursiveRef:"#"},properties:{type:"object",additionalProperties:{$recursiveRef:"#"},default:{}},patternProperties:{type:"object",additionalProperties:{$recursiveRef:"#"},propertyNames:{format:"regex"},default:{}},dependentSchemas:{type:"object",additionalProperties:{$recursiveRef:"#"}},propertyNames:{$recursiveRef:"#"},if:{$recursiveRef:"#"},then:{$recursiveRef:"#"},else:{$recursiveRef:"#"},allOf:{$ref:"#/$defs/schemaArray"},anyOf:{$ref:"#/$defs/schemaArray"},oneOf:{$ref:"#/$defs/schemaArray"},not:{$recursiveRef:"#"}},$defs:{schemaArray:{type:"array",minItems:1,items:{$recursiveRef:"#"}}}},CL={$schema:"https://json-schema.org/draft/2019-09/schema",$id:"https://json-schema.org/draft/2019-09/meta/content",$vocabulary:{"https://json-schema.org/draft/2019-09/vocab/content":!0},$recursiveAnchor:!0,title:"Content vocabulary meta-schema",type:["object","boolean"],properties:{contentMediaType:{type:"string"},contentEncoding:{type:"string"},contentSchema:{$recursiveRef:"#"}}},NL={$schema:"https://json-schema.org/draft/2019-09/schema",$id:"https://json-schema.org/draft/2019-09/meta/core",$vocabulary:{"https://json-schema.org/draft/2019-09/vocab/core":!0},$recursiveAnchor:!0,title:"Core vocabulary meta-schema",type:["object","boolean"],properties:{$id:{type:"string",format:"uri-reference",$comment:"Non-empty fragments not allowed.",pattern:"^[^#]*#?$"},$schema:{type:"string",format:"uri"},$anchor:{type:"string",pattern:"^[A-Za-z][-A-Za-z0-9.:_]*$"},$ref:{type:"string",format:"uri-reference"},$recursiveRef:{type:"string",format:"uri-reference"},$recursiveAnchor:{type:"boolean",default:!1},$vocabulary:{type:"object",propertyNames:{type:"string",format:"uri"},additionalProperties:{type:"boolean"}},$comment:{type:"string"},$defs:{type:"object",additionalProperties:{$recursiveRef:"#"},default:{}}}},OL={$schema:"https://json-schema.org/draft/2019-09/schema",$id:"https://json-schema.org/draft/2019-09/meta/format",$vocabulary:{"https://json-schema.org/draft/2019-09/vocab/format":!0},$recursiveAnchor:!0,title:"Format vocabulary meta-schema",type:["object","boolean"],properties:{format:{type:"string"}}},RL={$schema:"https://json-schema.org/draft/2019-09/schema",$id:"https://json-schema.org/draft/2019-09/meta/meta-data",$vocabulary:{"https://json-schema.org/draft/2019-09/vocab/meta-data":!0},$recursiveAnchor:!0,title:"Meta-data vocabulary meta-schema",type:["object","boolean"],properties:{title:{type:"string"},description:{type:"string"},default:!0,deprecated:{type:"boolean",default:!1},readOnly:{type:"boolean",default:!1},writeOnly:{type:"boolean",default:!1},examples:{type:"array",items:!0}}},BL={$schema:"https://json-schema.org/draft/2019-09/schema",$id:"https://json-schema.org/draft/2019-09/meta/validation",$vocabulary:{"https://json-schema.org/draft/2019-09/vocab/validation":!0},$recursiveAnchor:!0,title:"Validation vocabulary meta-schema",type:["object","boolean"],properties:{multipleOf:{type:"number",exclusiveMinimum:0},maximum:{type:"number"},exclusiveMaximum:{type:"number"},minimum:{type:"number"},exclusiveMinimum:{type:"number"},maxLength:{$ref:"#/$defs/nonNegativeInteger"},minLength:{$ref:"#/$defs/nonNegativeIntegerDefault0"},pattern:{type:"string",format:"regex"},maxItems:{$ref:"#/$defs/nonNegativeInteger"},minItems:{$ref:"#/$defs/nonNegativeIntegerDefault0"},uniqueItems:{type:"boolean",default:!1},maxContains:{$ref:"#/$defs/nonNegativeInteger"},minContains:{$ref:"#/$defs/nonNegativeInteger",default:1},maxProperties:{$ref:"#/$defs/nonNegativeInteger"},minProperties:{$ref:"#/$defs/nonNegativeIntegerDefault0"},required:{$ref:"#/$defs/stringArray"},dependentRequired:{type:"object",additionalProperties:{$ref:"#/$defs/stringArray"}},const:!0,enum:{type:"array",items:!0},type:{anyOf:[{$ref:"#/$defs/simpleTypes"},{type:"array",items:{$ref:"#/$defs/simpleTypes"},minItems:1,uniqueItems:!0}]}},$defs:{nonNegativeInteger:{type:"integer",minimum:0},nonNegativeIntegerDefault0:{$ref:"#/$defs/nonNegativeInteger",default:0},simpleTypes:{enum:["array","boolean","integer","null","number","object","string"]},stringArray:{type:"array",items:{type:"string"},uniqueItems:!0,default:[]}}},ML=["/properties"];xL.default=function(e){return[IL,PL,CL,NL,t(this,OL),RL,t(this,BL)].forEach(e=>this.addMetaSchema(e,void 0,!1)),this;function t(t,n){return e?t.$dataMetaSchema(n,ML):n}},function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.MissingRefError=t.ValidationError=t.CodeGen=t.Name=t.nil=t.stringify=t.str=t._=t.KeywordCxt=t.Ajv2019=void 0;const n=Ku,r=cm,i=NU,s=nL,a=pL,o=bb,c=xL,A="https://json-schema.org/draft/2019-09/schema";class l extends n.default{constructor(e={}){super({...e,dynamicRef:!0,next:!0,unevaluated:!0})}_addVocabularies(){super._addVocabularies(),this.addVocabulary(i.default),r.default.forEach(e=>this.addVocabulary(e)),this.addVocabulary(s.default),this.addVocabulary(a.default),this.opts.discriminator&&this.addKeyword(o.default)}_addDefaultMetaSchema(){super._addDefaultMetaSchema();const{$data:e,meta:t}=this.opts;t&&(c.default.call(this,e),this.refs["http://json-schema.org/schema"]=A)}defaultMeta(){return this.opts.defaultMeta=super.defaultMeta()||(this.getSchema(A)?A:void 0)}}t.Ajv2019=l,e.exports=t=l,e.exports.Ajv2019=l,Object.defineProperty(t,"__esModule",{value:!0}),t.default=l;var f=Wu;Object.defineProperty(t,"KeywordCxt",{enumerable:!0,get:function(){return f.KeywordCxt}});var u=Xu;Object.defineProperty(t,"_",{enumerable:!0,get:function(){return u._}}),Object.defineProperty(t,"str",{enumerable:!0,get:function(){return u.str}}),Object.defineProperty(t,"stringify",{enumerable:!0,get:function(){return u.stringify}}),Object.defineProperty(t,"nil",{enumerable:!0,get:function(){return u.nil}}),Object.defineProperty(t,"Name",{enumerable:!0,get:function(){return u.Name}}),Object.defineProperty(t,"CodeGen",{enumerable:!0,get:function(){return u.CodeGen}});var d=ap;Object.defineProperty(t,"ValidationError",{enumerable:!0,get:function(){return d.default}});var h=cp;Object.defineProperty(t,"MissingRefError",{enumerable:!0,get:function(){return h.default}})}(CU,CU.exports);var $L=CU.exports;const DL=er({__proto__:null,default:Vu($L)},[$L]);var FL,GL={exports:{}};FL=GL,function(){function e(t,n){return n?function(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}(t):t.slice?e[r(t)]:function(n,i){t(n={exports:{}}),e[r(i)]=n.exports};function r(e){return e.split("/").slice(-1).toString().replace(".js","")}}var t=FL;e(function(e){String.random=function(e,t){var n="";for(e=e||24,t=t||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";e-- >0;)n+=t.charAt(Math.floor(Math.random()*t.length));return n},String.match=function(e,t){var n,r;return"string"==typeof e&&("string"==typeof t&&(t={"=":t}),e===(n=(t=t||{})["="]||t["*"]||t[">"]||t["<"])||r===t["="]&&(n=t["*"]||t[">"],e.slice(0,(n||"").length)===n||r===t["*"]&&(r!==t[">"]&&r!==t["<"]?e>=t[">"]&&e<=t["<"]:r!==t[">"]&&e>=t[">"]||r!==t["<"]&&e<=t["<"])))},String.hash=function(e,t){if("string"==typeof e){if(t=t||0,!e.length)return t;for(var n=0,r=e.length;n<r;++n)t=(t<<5)-t+e.charCodeAt(n),t|=0;return t}};var t,n,r,i,s,a,o,c,A=Object.prototype.hasOwnProperty;Object.plain=function(e){return!!e&&(e instanceof Object&&e.constructor===Object||"Object"===Object.prototype.toString.call(e).match(/^\[object (\w+)\]$/)[1])},Object.empty=function(e,t){for(var n in e)if(A.call(e,n)&&(!t||-1==t.indexOf(n)))return!1;return!0},Object.keys=Object.keys||function(e){var t=[];for(var n in e)A.call(e,n)&&t.push(n);return t},i=setTimeout,s=0,a=0,o=typeof setImmediate!=""+t&&setImmediate||(typeof MessageChannel==""+t?i:((n=new MessageChannel).port1.onmessage=function(e){""==e.data&&r()},function(e){r=e,n.port2.postMessage("")})),c=i.check=i.check||typeof performance!=""+t&&performance||{now:function(){return+new Date}},i.hold=i.hold||9,i.poll=i.poll||function(e){i.hold>=c.now()-s&&a++<3333?e():o(function(){s=c.now(),e()},a=0)},function(){var e,t=setTimeout,n=t.turn=t.turn||function(e){1==r.push(e)&&i(a)},r=n.s=[],i=t.poll,s=0,a=function(){(e=r[s++])&&e(),s!=r.length&&99!=s||(r=n.s=r.slice(s),s=0),r.length&&i(a)}}(),function(){var e,t=setTimeout,n=t.turn;(t.each=t.each||function(t,r,i,s){s=s||9,function a(o,c,A){if(c=(o=(t||[]).splice(0,s)).length){for(var l=0;l<c&&e===(A=r(o[l]));l++);if(e===A)return void n(a)}i&&i(A)}()})()}()})(e,"./shim"),e(function(e){e.exports=function e(t,n,r){if(!t)return{to:e};var i="function"==typeof n;if(t=(this.tag||(this.tag={}))[t]||i&&(this.tag[t]={tag:t,to:e._={next:function(e){var t;(t=this.to)&&t.next(e)}}}),i){var s={off:e.off||(e.off=function(){if(this.next===e._.next)return!0;this===this.the.last&&(this.the.last=this.back),this.to.back=this.back,this.next=e._.next,this.back.to=this.to,this.the.last===this.the&&delete this.on.tag[this.the.tag]}),to:e._,next:n,the:t,on:this,as:r};return(s.back=t.last||t).to=s,t.last=s}return(t=t.to)&&void 0!==n&&t.next(n),t}})(e,"./onto"),e(function(e){e.exports=function(e){return null===e||"string"==typeof e||"boolean"==typeof e||"number"==typeof e&&e!=1/0&&e!=-1/0&&e==e||!!e&&"string"==typeof e["#"]&&1===Object.keys(e).length&&e["#"]}})(e,"./valid"),e(function(t){function n(){var e=+new Date;return o<e?(s=0,o=e+n.drift):o=e+(s+=1)/a+n.drift}e("./shim"),n.drift=0;var r,i=-1/0,s=0,a=999,o=i;n.is=function(e,t,n){var r=t&&e&&e._&&e._[">"]||n;if(r)return"number"==typeof(r=r[t])?r:i},n.ify=function(e,t,n,i,s){(e=e||{})._=e._||{},s&&(e._["#"]=s);var a=e._[">"]||(e._[">"]={});return r!==t&&"_"!==t&&("number"==typeof n&&(a[t]=n),r!==i&&(e[t]=i)),e},t.exports=n})(e,"./state"),e(function(t){e("./shim"),t.exports=function(e){var t={s:{}},n=t.s;e=e||{max:999,age:9e3},t.check=function(e){return!!n[e]&&r(e)};var r=t.track=function(i){var s=n[i]||(n[i]={});return s.was=t.now=+new Date,t.to||(t.to=setTimeout(t.drop,e.age+9)),r.ed&&r.ed(i),s};return t.drop=function(r){t.to=null,t.now=+new Date;var i=Object.keys(n);console.STAT&&console.STAT(t.now,+new Date-t.now,"dup drop keys"),setTimeout.each(i,function(i){var s=n[i];s&&(r||e.age)>t.now-s.was||delete n[i]},0,99)},t}})(e,"./dup"),e(function(t){e("./onto"),t.exports=function(e,t){if(this.on){var r=(this.opt||{}).lack||9e3;if("function"!=typeof e){if(!e)return;var i=e["#"]||e,s=(this.tag||"")[i];if(!s)return;return t&&(s=this.on(i,t),clearTimeout(s.err),s.err=setTimeout(function(){s.off()},r)),!0}if(i=t&&t["#"]||n(9),!e)return i;var a=this.on(i,e,t);return a.err=a.err||setTimeout(function(){a.off(),a.next({err:"Error: No ACK yet.",lack:!0})},r),i}};var n=String.random||function(){return Math.random().toString(36).slice(2)}})(e,"./ask"),e(function(n){function r(e){return e instanceof r?(this._={$:this}).$:this instanceof r?r.create(this._={$:this,opt:e}):new r(e)}r.is=function(e){return e instanceof r||e&&e._&&e===e._.$||!1},r.version=.202,r.chain=r.prototype,r.chain.toJSON=function(){},e("./shim"),r.valid=e("./valid"),r.state=e("./state"),r.on=e("./onto"),r.dup=e("./dup"),r.ask=e("./ask"),function(){function e(n){if(n)if(n.out!==e){var i,s=this.as,c=s.at||s,A=c.$,l=c.dup,f=n.DBG;if((i=n["#"])||(i=n["#"]=o(9)),!l.check(i)){if(l.track(i),i=n._,n._="function"==typeof i?i:function(){},n.$&&n.$===(n.$._||"").$||(n.$=A),n["@"]&&!n.put&&function(e){var t,n=e["@"]||"";if(t=n._)t.acks=(t.acks||0)+1,(t.err=e.err)&&(e["@"]=t["#"],a(t)),t.ok=e.ok||t.ok,t.stop||t.crack||(t.crack=t.match&&t.match.push(function(){d(t)})),d(t);else{var r=(r=e.$)&&(r=r._)&&(r=r.root)&&(r=r.dup);if(!(r=r.check(n)))return;e["@"]=r["#"]||e["@"]}}(n),!c.ask(n["@"],n)){if(f&&(f.u=+new Date),n.put)return void t(n);n.get&&r.on.get(n,A)}f&&(f.uc=+new Date),this.to.next(n),f&&(f.ua=+new Date),n.nts||n.NTS||(n.out=e,c.on("out",n),f&&(f.ue=+new Date))}}else this.to.next(n)}function t(t){if(t){var r=t._||"",s=r.root=((r.$=t.$||"")._||"").root;if(t["@"]&&r.faith&&!r.miss)return t.out=e,void s.on("out",t);r.latch=s.hatch,r.match=s.hatch=[];var o=t.put,l=r.DBG=t.DBG,f=+new Date;if(h=h||f,!o["#"]||!o["."]){l&&(l.p=f),r["#"]=t["#"],r.msg=t,r.all=0,r.stun=1;var u=Object.keys(o);console.STAT&&console.STAT(f,((l||r).pk=+new Date)-f,"put sort");var d,y,g,b,v,_,E,k=0;!function e(s){if(d!=k){if(d=k,!(g=u[k]))return console.STAT&&console.STAT(f,((l||r).pd=+new Date)-f,"put"),void a(r);(b=o[g])?(E=b._)?g!==E["#"]?_=p+m(g)+"soul not same.":(v=E[">"])||(_=p+m(g)+"no state."):_=p+m(g)+"no meta.":_=p+m(g)+"no node.",y=Object.keys(b||{})}if(_)return t.err=r.err=_,void a(r);var h,T=0;for(s=s||0;s++<9&&(h=y[T++]);)if("_"!==h){var S=b[h],x=v[h];if(i===x){_=p+m(h)+"on"+m(g)+"no state.";break}if(!A(S)){_=p+m(h)+"on"+m(g)+"bad "+typeof S+m(S);break}n(S,h,g,x,t),++w}(y=y.slice(T)).length?c(e):(++k,y=null,e(s))}()}}}function n(e,t,r,i,s){var a,o=s._||"",c=o.root,A=c.graph,f=A[r]||u,d=l(f,t,1),h=f[t],p=o.DBG;(a=console.STAT)&&(A[r]&&h||(a.has=(a.has||0)+1));var m=b();if(i>m)return setTimeout(function(){n(e,t,r,i,s)},(a=i-m)>g?g:a),void(console.STAT&&console.STAT((p||o).Hf=+new Date,a,"future"));if(!(i<d)&&(o.faith||i!==d||!(e===h||y(e)<=y(h))||o.miss)){o.stun++;var w=s["#"]+o.all++,v={toString:function(){return w},_:o};v.toJSON=v.toString,c.dup.track(v)["#"]=s["#"],p&&(p.ph=p.ph||+new Date),c.on("put",{"#":v,"@":s["@"],put:{"#":r,".":t,":":e,">":i},ok:s.ok,_:o})}}function s(e){var t;(t=(e._||"").DBG)&&(t.pa=+new Date,t.pm=t.pm||+new Date);var n,r=this.as,i=r.graph,s=e._,o=e.put,c=o["#"],A=o["."],l=o[":"],u=o[">"];e["#"],(n=s.msg)&&(n=n.put)&&(n=n[c])&&f(n,A,u,l,c),i[c]=f(i[c],A,u,l,c),(n=(r.next||"")[c])&&n.on("in",e),a(s),this.to.next(e)}function a(t,n){var r;if(!t.stop&&(t.err||!(0<--t.stun))&&(t.stop=1,r=t.root)){var i=t.match;i.end=1,i===r.hatch&&(!(i=t.latch)||i.end?delete r.hatch:r.hatch=i),t.hatch&&t.hatch(),setTimeout.each(t.match,function(e){e&&e()}),!(n=t.msg)||t.err||n.err||(n.out=e,t.root.on("out",n),v())}}function d(e){e&&e.root&&(e.stun||e.acks!==e.all||e.root.on("in",{"@":e["#"],err:e.err,ok:e.err?i:e.ok||{"":1}}))}r.create=function(t){t.root=t.root||t,t.graph=t.graph||{},t.on=t.on||r.on,t.ask=t.ask||r.ask,t.dup=t.dup||r.dup();var n=t.$.opt(t.opt);return t.once||(t.on("in",e,t),t.on("out",e,t),t.on("put",s,t),r.on("create",t),t.on("create",t)),t.once=1,n},r.on.put=t;var h,p="Error: Invalid graph!",m=function(e){return" '"+(""+e).slice(0,9)+"...' "},y=JSON.stringify,g=2147483647,b=r.state,w=0,v=function(){w>999&&w/-(h-(h=+new Date))>1&&(r.window&&console.log("Warning: You're syncing 1K+ records a second, faster than DOM can update - consider limiting query."),v=function(){w=0})}}(),function(){function e(e,t){var n=+new Date,r=e._||{},s=r.DBG=e.DBG,a=e["#"],c=o(9),A=Object.keys(t||"").sort(),u=((t||"")._||"")["#"];A.length;var d=e.$._.root,h=t===d.graph[u];console.STAT&&console.STAT(n,((s||r).gk=+new Date)-n,"got keys"),t&&function e(){n=+new Date;for(var r,p,m,y=0,g={};y<9&&(r=A[y++]);)f(g,r,l(t,r),t[r],u);A=A.slice(y),(p={})[u]=g,g=p,h&&((m=function(){}).ram=m.faith=!0),p=A.length,console.STAT&&console.STAT(n,-(n-(n=+new Date)),"got copied some"),s&&(s.ga=+new Date),d.on("in",{"@":a,"#":c,put:g,"%":p?c=o(9):i,$:d.$,_:m,DBG:s,FOO:1}),console.STAT&&console.STAT(n,+new Date-n,"got in"),p&&setTimeout.turn(e)}(),t||d.on("in",{"@":e["#"]})}r.on.get=function(t,n){var r=n._,s=t.get,a=s["#"],o=r.graph[a],c=s["."],A=(r.next||(r.next={}))[a],u=(t._||{}).DBG=t.DBG;if(u&&(u.g=+new Date),!o)return r.on("get",t);if(c){if(("string"!=typeof c||i===o[c])&&!((A||"").next||"")[c])return void r.on("get",t);o=f({},c,l(o,c),o[c],a)}o&&e(t,o),r.on("get",t)},r.on.get.ack=e}(),r.chain.opt=function(e){e=e||{};var t=this._,n=e.peers||e;return Object.plain(e)||(e={}),Object.plain(t.opt)||(t.opt=e),"string"==typeof n&&(n=[n]),Object.plain(t.opt.peers)||(t.opt.peers={}),n instanceof Array&&(e.peers={},n.forEach(function(n){var r={};r.id=r.url=n,e.peers[n]=t.opt.peers[n]=t.opt.peers[n]||r})),a(e,function e(t){var n=this[t];this&&this.hasOwnProperty(t)||"string"==typeof n||Object.empty(n)?this[t]=n:(!n||n.constructor===Object||n instanceof Array)&&a(n,e)}),t.opt.from=e,r.on("opt",t),t.opt.uuid=t.opt.uuid||function(e){return r.state().toString(36).replace(".","")+String.random(e||12)},this};var i,s,a=function(e,t){Object.keys(e).forEach(t,e)},o=String.random,c=setTimeout.turn,A=r.valid,l=r.state.is,f=r.state.ify,u={};r.log=function(){return!r.log.off&&s.log.apply(s,arguments),[].slice.call(arguments).join(" ")},r.log.once=function(e,t,n){return(n=r.log.once)[e]=n[e]||0,n[e]++||r.log(t)},"undefined"!=typeof window&&((window.GUN=window.Gun=r).window=window);try{void 0!==t&&(t.exports=r)}catch(d){}n.exports=r,(r.window||{}).console=(r.window||{}).console||{log:function(){}},(s=console).only=function(e,t){return s.only.i&&e===s.only.i&&s.only.i++&&(s.log.apply(s,arguments)||t)},r.log.once("welcome","Hello wonderful person! :) Thanks for using GUN, please ask for help on http://chat.gun.eco if anything takes you longer than 5min to figure out!")})(e,"./root"),e(function(t){e("./root").chain.back=function(e,t){if(-1===(e=e||1)||1/0===e)return this._.root.$;if(1===e)return(this._.back||this._).$;var i=this._;if("string"==typeof e&&(e=e.split(".")),e instanceof Array){for(var s=0,a=e.length,o=i;s<a;s++)o=(o||r)[e[s]];return n!==o?t?this:o:(o=i.back)?o.$.back(e,t):void 0}if("function"==typeof e){var c;for(o={back:i};(o=o.back)&&n===(c=e(o,t)););return c}return"number"==typeof e?(i.back||i).$.back(e-1):this};var n,r={}})(e,"./back"),e(function(t){var n=e("./root");function r(e,t){if(t=t||this.as||e.$._,(!e.$$||this===n.on)&&e.put&&!t.soul){var r=e.put||"",i=r["="]||r[":"],s=t.root,a=s.$.get(r["#"]).get(r["."])._;if("string"==typeof(i=A(i))){if(!(a.echo||(a.echo={}))[t.id]||(s.pass||"")[t.id]){if(o=s.pass){if(o[i+t.id])return;o[i+t.id]=1}(a.echo||(a.echo={}))[t.id]=t,t.has&&(t.link=i);var o,c=s.$.get(a.link=i)._;(c.echo||(c.echo={}))[a.id]=a,((o=t.ask||"")[""]||t.lex)&&c.on("out",{get:{"#":i}}),setTimeout.each(Object.keys(o),function(e,t){e&&(t=o[e])&&t.on("out",{get:{"#":i,".":e}})},0,99)}}else this===n.on&&((a.echo||(a.echo={}))[t.id]=t)}}function i(e,t){var n,r,s=e.put||"",o=a!==s["="]?s["="]:s[":"],c=t.root;if(a===o){if(t.soul&&a!==t.put)return;if(r=(e.$$||e.$||"")._||"",e["@"]&&(a!==r.put||a!==t.put))return;return(n=t.link||e.linked)&&delete(c.$.get(n)._.echo||"")[t.id],t.has&&(t.link=null),t.put=a,void setTimeout.each(Object.keys(t.next||""),function(e,r){(r=t.next[e])&&(n&&delete(c.$.get(n).get(e)._.echo||"")[r.id],r.on("in",{get:e,put:a,$:r.$}))},0,99)}t.soul||e.$$||(n=A(o),r=e.$._||"",(n!==r.link&&(!t.has||r.link)||(c.pass||"")[t.id]&&"string"!=typeof n)&&(delete(r.echo||"")[t.id],i({get:t.get,put:a,$:e.$,linked:e.linked=e.linked||r.link},t)))}function s(e,t){var r=this.as,i=r.$._;i.root;var s=r.get||"",o=(e.put||"")[s["#"]]||"";if(!e.put||"string"==typeof s["."]&&a===o[s["."]]){if(a!==i.put)return;if(!i.soul&&!i.has)return;return i.ack=(i.ack||0)+1,void i.on("in",{get:i.get,put:i.put=a,$:i.$,"@":e["@"]})}(e._||{}).miss=1,n.on.put(e)}n.chain.chain=function(e){var t,r=this,i=r._,s=new(e||r).constructor(r),a=s._;return a.root=t=i.root,a.id=++t.once,a.back=r._,a.on=n.on,a.on("in",n.on.in,a),a.on("out",n.on.out,a),s},n.on.out=function(e){var t,n,r=this.as,i=r.back,o=r.root;if(e.$||(e.$=r.$),this.to.next(e),!r.err){if(t=e.get){if(o.pass&&(o.pass[r.id]=r),r.lex&&Object.keys(r.lex).forEach(function(e){n[e]=r.lex[e]},n=e.get=e.get||{}),t["#"]||r.soul){if(t["#"]=t["#"]||r.soul,e["#"]||(e["#"]=c(9)),i=o.$.get(t["#"])._,t=t["."]){if(l(i.put,t)&&(n=i.ask&&i.ask[t],(i.ask||(i.ask={}))[t]=i.$.get(t)._,i.on("in",{get:t,put:{"#":i.soul,".":t,":":i.put[t],">":u(o.graph[i.soul],t)}}),n))return}else{if(n=i.ask&&i.ask[""],(i.ask||(i.ask={}))[""]=i,a!==i.put&&(i.on("in",i),n))return;e.$=i.$}return o.ask(s,e),o.on("in",e)}if(t["."])return r.get?(e={get:{".":r.get},$:r.$},(i.ask||(i.ask={}))[r.get]=e.$._,i.on("out",e)):(e={get:r.lex?e.get:{},$:r.$},i.on("out",e));if((r.ask||(r.ask={}))[""]=r,r.get)return t["."]=r.get,(i.ask||(i.ask={}))[r.get]=e.$._,i.on("out",e)}return i.on("out",e)}r.on("in",{put:r.put=a,$:r.$})},n.on.in=function(e,t){var n,s=(t=t||this.as).root,c=e.$||(e.$=t.$),l=(c||"")._||o,f=e.put||"",h=f["#"],p=f["."],m=a!==f["="]?f["="]:f[":"],y=f[">"]||-1/0;if(a!==e.put&&(a===f["#"]||a===f["."]||a===f[":"]&&a===f["="]||a===f[">"]))return A(f)?void t.on("in",{$:l.back.$,put:{"#":h=l.back.soul,".":p=l.has||l.get,"=":f,">":u(l.back.put,p)},via:e}):(h=((f||"")._||"")["#"])?(c=t.root.$.get(h),setTimeout.each(Object.keys(f).sort(),function(n){"_"!=n&&a!==(y=u(f,n))&&t.on("in",{$:c,put:{"#":h,".":n,"=":f[n],">":y},VIA:e})})):void console.log("chain not yet supported for",f,"...",e,t);(e.seen||"")[t.id]||((e.seen||(e.seen=function(){}))[t.id]=t,t!==l&&(Object.keys(e).forEach(function(t){f[t]=e[t]},f={}),f.get=t.get||f.get,t.soul||t.has?l.soul&&(f.$=t.$,f.$$=f.$$||l.$):f.$$$=f.$$$||t.$,e=f),i(e,t),(t.soul||e.$$)&&y>=u(s.graph[h],p)&&((f=s.$.get(h)._).put=d(f.put,p,y,m,h)),!l.soul&&y>=u(s.graph[h],p)&&(n=(s.$.get(h)._.next||"")[p])&&(n.put=m,"string"==typeof(f=A(m))&&(n.put=s.$.get(f)._.put||m)),this.to&&this.to.next(e),t.any&&setTimeout.each(Object.keys(t.any),function(n){(n=t.any[n])&&n(e)},0,99),t.echo&&setTimeout.each(Object.keys(t.echo),function(n){(n=t.echo[n])&&n.on("in",e)},0,99),((e.$$||"")._||l).soul&&(n=t.next)&&(n=n[p])&&(f={},Object.keys(e).forEach(function(t){f[t]=e[t]}),f.$=(e.$$||e.$).get(f.get=p),delete f.$$,delete f.$$$,n.on("in",f)),r(e,t))},n.on.link=r,n.on.unlink=i;var a,o={},c=String.random,A=n.valid,l=function(e,t){return e&&Object.prototype.hasOwnProperty.call(e,t)},f=n.state,u=f.is,d=f.ify})(e,"./chain"),e(function(t){var n=e("./root");function r(e){var t=this.at||this.on;if(!e||t.soul||t.has)return this.off();if(e=(e=(e=e.$||e)._||e).id){var n;if(t.map,(n=this.seen||(this.seen={}))[e])return!0;n[e]=!0}}n.chain.get=function(e,t,o){var c,A;if("string"==typeof e){if(0==e.length)return(c=this.chain())._.err={err:n.log("0 length key!",e)},t&&t.call(c,c._.err),c;(c=((f=this._).next||s)[e])||(c=e&&function(e,t){var n=t._,r=n.next,i=t.chain()._;return r||(r=n.next={}),r[i.get=e]=i,t===n.root.$?i.soul=e:(n.soul||n.has)&&(i.has=e),i}(e,this)),c=c&&c.$}else{if("function"==typeof e){let s=function(e,t,r){if(!s.stun&&(!(a=d.pass)||a[l])){var a,o=e.$._,c=(e.$$||"")._,A=(c||o).put,p=!o.has&&!o.soul,m={};if((p||i===A)&&(A=i===((a=e.put)||"")["="]?i===(a||"")[":"]?a:a[":"]:a["="]),"string"==typeof(a=n.valid(A))&&(A=i===(a=d.$.get(a)._.put)?u.not?i:A:a),!u.not||i!==A){if(i===u.stun){if((a=d.stun)&&a.on&&(f.$.back(function(e){if(a.on(""+e.id,m={}),(m.run||0)<s.id)return m}),!m.run&&a.on(""+o.id,m={}),!m.run&&c&&a.on(""+c.id,m={}),s.id>m.run&&(m.stun&&!m.stun.end||(m.stun=a.on("stun"),m.stun=m.stun&&m.stun.last),m.stun&&!m.stun.end)))return void((m.stun.add||(m.stun.add={}))[l]=function(){s(e,t,1)});if(i===A&&(r=0),(a=d.hatch)&&!a.end&&i===u.hatch&&!r){if(h[o.$._.id])return;return h[o.$._.id]=1,void a.push(function(){s(e,t,1)})}h={}}if(d.pass){if(d.pass[l+o.id])return;d.pass[l+o.id]=1}u.on?u.ok.call(o.$,A,o.get,e,t||s):u.v2020?u.ok(e,t||s):(Object.keys(e).forEach(function(t){a[t]=e[t]},a={}),(e=a).put=A,u.ok.call(u.as,e,t||s))}}};if(!0===t)return function(e,t,r,s){var a,o=e._,c=0;(a=o.soul||o.link)?t(a,s,o):o.jam?o.jam.push([t,s]):(o.jam=[[t,s]],e.get(function(e,t){if(!(i===e.put&&!o.root.opt.super&&(a=Object.keys(o.root.opt.peers).length)&&++c<=a)){t.rid(e);var r,s=(s=e.$)&&s._||{},A=0;for(a=o.jam,delete o.jam;r=a[A++];){var l=r[0];r=r[1],l&&l(s.link||s.soul||n.valid(e.put)||((e.put||{})._||{})["#"],r,e,t)}}},{out:{get:{".":!0}}}))}(this,e,0,o),this;var l,f=(c=this)._,u=t||{},d=f.root;u.at=f,u.ok=e;var h={};return s.at=f,(f.any||(f.any={}))[l=String.random(7)]=s,s.off=function(){s.stun=1,f.any&&delete f.any[l]},s.rid=r,s.id=u.run||++d.once,A=d.pass,(d.pass={})[l]=1,u.out=u.out||{get:{}},f.on("out",u.out),d.pass=A,c}if("number"==typeof e)return this.get(""+e,t,o);if("string"==typeof(A=a(e)))return this.get(A,t,o);(A=this.get.next)&&(c=A(this,e))}return c?(t&&"function"==typeof t&&c.get(t,o),c):((c=this.chain())._.err={err:n.log("Invalid get request!",e)},t&&t.call(c,c._.err),c)};var i,s={},a=n.valid})(e,"./get"),e(function(t){var n=e("./root");function r(e,t){if(t){t=(t._||"").id||t;var r,i=e.root.stun||(e.root.stun={on:n.on}),s={};e.stun||(e.stun=i.on("stun",function(){})),(r=i.on(""+t))&&r.the.last.next(s),s.run>=e.run||i.on(""+t,function(t){if(e.stun.end)return this.off(),void this.to.next(t);t.run=t.run||e.run,t.stun=t.stun||e.stun})}}function i(e){if(e.err)i.end(e.stun,e.root);else if(!e.todo.length&&!e.end&&Object.empty(e.wait)){e.end=1;var t,r=e.$.back(-1)._,s=r.root,a=r.ask(function(t){s.on("ack",t),t.err&&!t.lack&&n.log(t),++o>(e.acks||0)&&this.off(),e.ack&&e.ack(t,this)},e.opt),o=0,c=e.stun;(t=function(){c&&(i.end(c,s),setTimeout.each(Object.keys(c=c.add||""),function(e){(e=c[e])&&e()}))}).hatch=t,e.ack&&!e.ok&&(e.ok=e.acks||9),e.via._.on("out",{put:e.out=e.graph,ok:e.ok&&{"@":e.ok+1},opt:e.opt,"#":a,_:t})}}n.chain.put=function(e,t,a){var l=this,f=l._,u=f.root;(a=a||{}).root=f.root,a.run||(a.run=u.once),r(a,f.id),a.ack=a.ack||t,a.via=a.via||l,a.data=a.data||e,a.soul||(a.soul=f.soul||"string"==typeof t&&t);var d=a.state=a.state||n.state();return"function"==typeof e?(e(function(e){a.data=e,l.put(s,s,a)}),l):a.soul?(a.$=u.$.get(a.soul),a.todo=[{it:a.data,ref:a.$}],a.turn=a.turn||o,a.ran=a.ran||i,function e(){var t,s,o,l,f,u=a.todo,h=u.pop(),p=h.it;if(h.ref&&h.ref._.id,r(a,h.ref),(l=h.todo)&&(p=p[s=l.pop()],l.length&&u.push(h)),s&&(u.path||(u.path=[])).push(s),!(t=c(p))&&!(f=n.is(p))){if(!Object.plain(p))return void i.err(a,"Invalid data: "+function(e,t){return e&&(t=e.constructor)&&t.name||typeof e}(p)+" at "+(a.via.back(function(e){e.get&&l.push(e.get)},l=[])||l.join("."))+"."+(u.path||[]).join("."));for(var m=a.seen||(a.seen=[]),y=m.length;y--;)if(p===(l=m[y]).it){t=p=l.link;break}}if(s&&t)h.node=A(h.node,s,d,p);else{let e=function(t,n){var i=o.link["#"];n&&(n.off(),n.rid(t));var s=i||t.soul||(l=(t.$$||t.$)._||"").soul||l.link||((l=l.put||"")._||"")["#"]||l["#"]||((l=t.put||"")&&t.$$?l["#"]:(l["="]||l[":"]||"")["#"]);!i&&r(a,t.$),s||h.link["#"]?(s||(s=[],(t.$$||t.$).back(function(e){if(l=e.soul||e.link)return s.push(l);s.push(e.get)}),s=s.reverse().join("/")),o.link["#"]=s,!f&&(((a.graph||(a.graph={}))[s]=o.node||(o.node={_:{}}))._["#"]=s),delete a.wait[g],o.wait&&setTimeout.each(o.wait,function(e){e&&e()}),a.ran(a)):(h.wait||(h.wait=[])).push(function(){e(t,n)})};if(!a.seen)return void i.err(a,"Data at root of graph must be a node (an object).");a.seen.push(o={it:p,link:{},todo:f?[]:Object.keys(p).sort().reverse(),path:(u.path||[]).slice(),up:h}),h.node=A(h.node,s,d,o.link),!f&&o.todo.length&&u.push(o);var g=a.seen.length;(a.wait||(a.wait={}))[g]="",l=(o.ref=f?p:s?h.ref.get(s):h.ref)._,(l=p&&(p._||"")["#"]||l.soul||l.link)?e({soul:l}):o.ref.get(e,{run:a.run,v2020:1,out:{get:{".":" "}}})}if(!u.length)return a.ran(a);a.turn(e)}(),l):(function(e){var t,n=e.via._;e.via=e.via.back(function(n){if(n.soul||!n.get)return n.$;t=e.data,(e.data={})[n.get]=t}),e.via&&e.via._.soul||(e.via=n.root.$.get(((e.data||"")._||"")["#"]||n.$.back("opt.uuid")())),e.via.put(e.data,e.ack,e)}(a),l)},i.end=function(e,t){e.end=a,e.the.to===e&&e===e.the.last&&delete t.stun,e.off()},i.err=function(e,t){(e.ack||a).call(e,e.out={err:e.err=n.log(t)}),e.ran(e)};var s,a=function(){},o=setTimeout.turn,c=n.valid,A=n.state.ify})(e,"./put"),e(function(t){var n=e("./root");e("./chain"),e("./back"),e("./put"),e("./get"),t.exports=n})(e,"./index"),e(function(t){var n,r=e("./index");r.chain.on=function(e,t,n,r){var i,s=this,a=s._;if(a.root,"string"==typeof e)return t?(i=a.on(e,t,n||a,r),n&&n.$&&(n.subs||(n.subs=[])).push(i),s):a.on(e);var o=t;return(o=!0===o?{change:!0}:o||{}).not=1,o.on=1,s.get(e,o),s},r.chain.once=function(e,t){if(t=t||{},!e)return function(e,t,n){return r.log.once("valonce","Chainable val is experimental, its behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."),(n=e.chain())._.nix=e.once(function(e,t){n._.on("in",this._)}),n._.lex=e._.lex,n}(this);var i=this,s=i._,a=s.root;s.put;var o,c=String.random(7);return i.get(function(i,A,l,f){var u=this,d=u._,h=d.one||(d.one={});function p(m){d.has||d.soul||(d={put:i,get:A}),n===(o=d.put)&&(o=((l.$$||"")._||"").put),"string"!=typeof r.valid(o)||(o=a.$.get(o)._.put)!==n||m?f.stun||""!==h[c]&&(h[c]="",(s.soul||s.has)&&f.off(),e.call(u,o,d.get),clearTimeout(h[c])):h[c]=setTimeout(function(){p(1)},t.wait||99)}f.stun||""!==h[c]&&(!0!==(o=r.valid(i))?"string"!=typeof o&&(clearTimeout((s.one||"")[c]),clearTimeout(h[c]),h[c]=setTimeout(p,t.wait||99)):p())},{on:1}),i},r.chain.off=function(){var e,t=this._,n=t.back;if(n)return t.ack=0,(e=n.next)&&e[t.get]&&delete e[t.get],(e=n.any)&&(delete n.any,n.any={}),(e=n.ask)&&delete e[t.get],(e=n.put)&&delete e[t.get],(e=t.soul)&&delete n.root.graph[e],(e=t.map)&&Object.keys(e).forEach(function(t,r){(r=e[t]).link&&n.root.$.get(r.link).off()}),(e=t.next)&&Object.keys(e).forEach(function(t,n){e[t].$.off()}),t.on("off",{}),this}})(e,"./on"),e(function(t){var n=e("./index"),r=n.chain.get.next;function i(e){this.to.next(e);var t,r=this.as,i=e.$._,s=e.put;(i.soul||e.$$)&&((t=r.lex)&&!String.match(e.get||(s||"")["."],t["."]||t["#"]||t)||n.on.link(e,r))}n.chain.get.next=function(e,t){var n;return Object.plain(t)?(n=((n=t["#"])||"")["="]||n)?e.get(n):((n=e.chain()._).lex=t,e.on("in",function(e){String.match(e.get||(e.put||"")["."],t["."]||t["#"]||t)&&n.on("in",e),this.to.next(e)}),n.$):(r||a)(e,t)},n.chain.map=function(e,t,r){var o,c,A=this,l=A._;return Object.plain(e)&&(o=e["."]?e:{".":e},e=s),e?(n.log.once("mapfn","Map functions are experimental, their behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."),c=A.chain(),A.map().on(function(t,r,i,o){var A=(e||a).call(this,t,r,i,o);if(s!==A){if(t===A)return c._.on("in",i);if(n.is(A))return c._.on("in",A._);var l={};Object.keys(i.put).forEach(function(e){l[e]=i.put[e]},l),l["="]=A,c._.on("in",{get:r,put:l})}}),c):((c=l.each)||((l.each=c=A.chain())._.lex=o||c._.lex||l.lex,c._.nix=A.back("nix"),A.on("in",i,c._)),c)};var s,a=function(){}})(e,"./map"),e(function(t){var n=e("./index");n.chain.set=function(e,t,r){var i,s,a=this,o=a.back(-1);return t=t||function(){},(r=r||{}).item=r.item||e,(i=((e||"")._||"")["#"])&&((e={})["#"]=i),"string"==typeof(s=n.valid(e))?a.get(i=s).put(e,t,r):n.is(e)?(a.put(function(r){e.get(function(e,i,o){if(!e)return t.call(a,{err:n.log('Only a node can be linked! Not "'+o.put+'"!')});(s={})[e]={"#":e},r(s)},!0)}),e):(Object.plain(e)&&(e=o.get(i=a.back("opt.uuid")()).put(e)),a.get(i||o.back("opt.uuid")(7)).put(e,t,r))}})(e,"./set"),e(function(t){e("./shim");var n,r=function(){},i=JSON.parseAsync||function(e,t,n){var r=+new Date;try{t(void 0,JSON.parse(e,n),s.sucks(+new Date-r))}catch(i){t(i)}},s=JSON.stringifyAsync||function(e,t,n,r){var i=+new Date;try{t(void 0,JSON.stringify(e,n,r),s.sucks(+new Date-i))}catch(a){t(a)}};s.sucks=function(e){e>99&&(console.log("Warning: JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."),s.sucks=r)};try{t.exports=function(e){var t=function(){},r=e.opt||{};r.log=r.log||console.log,r.gap=r.gap||r.wait||0,r.max=r.max||.3*(r.memory?999*r.memory*999:3e8),r.pack=r.pack||.01*r.max*.01,r.puff=r.puff||9;var a=setTimeout.turn||setTimeout,o=e.dup,c=o.check,A=o.track,l=t.hear=function(e,n){if(e){if(r.max<=e.length)return t.say({dam:"!",err:"Message too big!"},n);t===this&&(l.d+=e.length||0,++l.c);var s,o=n.SH=+new Date,c=e[0];return"["===c?(i(e,function(e,i){if(e||!i)return t.say({dam:"!",err:"DAM JSON parse error."},n);console.STAT&&console.STAT(+new Date,i.length,"# on hear batch");var s=r.puff;!function e(){for(var r,o=+new Date,c=0;c<s&&(r=i[c++]);)t.hear(r,n);i=i.slice(c),console.STAT&&console.STAT(o,+new Date-o,"hear loop"),f(n),i.length&&a(e,0)}()}),void(e="")):"{"===c||(e["#"]||Object.plain(e))&&(s=e)?s?l.one(s,n,o):void i(e,function(e,r){if(e||!r)return t.say({dam:"!",err:"DAM JSON parse error."},n);l.one(r,n,o)}):void 0}};function f(e){var t=e.batch,n="string"==typeof t;if(n&&(t+="]"),e.batch=e.tail=null,t&&!(n?3>t.length:!t.length)){if(!n)try{t=1===t.length?t[0]:JSON.stringify(t)}catch(i){return r.log("DAM JSON stringify error",i)}t&&u(t,e)}}function u(e,n){try{var r=n.wire;n.say?n.say(e):r.send&&r.send(e),t.say.d+=e.length||0,++t.say.c}catch(i){(n.queue=n.queue||[]).push(e)}}return l.one=function(n,r,i){var s,a,l,f,u;if(n.DBG&&(n.DBG=u={DBG:n.DBG}),u&&(u.h=i),u&&(u.hp=+new Date),(s=n["#"])||(s=n["#"]=String.random(9)),!((l=c(s))||(a=n["##"])&&(l=n["@"]||n.get&&s)&&o.check(f=l+a))){if((n._=function(){}).via=t.leap=r,(l=n["><"])&&"string"==typeof l&&l.slice(0,99).split(",").forEach(function(e){this[e]=1},n._.yo={}),l=n.dam)return(l=t.hear[l])&&l(n,r,e),void A(s);(l=n.ok)&&(n._.near=l["/"]),i=+new Date,u&&(u.is=i),r.SI=s,A.ed=function(e){s===e&&(A.ed=0,(e=o.s[s])&&(e.via=r,n.get&&(e.it=n)))},e.on("in",t.last=n),u&&(u.hd=+new Date),console.STAT&&console.STAT(i,+new Date-i,n.get?"msg get":n.put?"msg put":"msg"),A(s),f&&A(f),t.leap=t.last=null}},l.c=l.d=0,function(){var e,i=0;function l(e,t){var n;return t instanceof Object?(Object.keys(t).sort().forEach(d,{to:n={},on:t}),n):t}function d(e){this.to[e]=this.on[e]}t.hash=function(e,n){var r,i,o,c=+new Date;s(e.put,function s(A,l){var f=(i||(i=o=l||"")).slice(0,32768);r=String.hash(f,r),(i=i.slice(32768))?a(s,0):(console.STAT&&console.STAT(c,+new Date-c,"say json+hash"),e._.$put=o,e["##"]=r,t.say(e,n),delete e._.$put)},l)},(t.say=function(s,c){var l;if((l=this)&&(l=l.to)&&l.next&&l.next(s),!s)return!1;var d,h,p,m=s["@"],y=s._||(s._=function(){}),g=s.DBG,b=+new Date;if(y.y=y.y||b,c||g&&(g.y=b),(d=s["#"])||(d=s["#"]=String.random(9)),!e&&A(d),(h=s["##"])||n===s.put||y.via||!m){if(!c&&m&&(c=(l=o.s[m])&&(l.via||(l=l.it)&&(l=l._)&&l.via)||(l=t.last)&&m===l["#"]&&t.leap),!c&&m){if(o.s[m])return;return console.STAT&&console.STAT(+new Date,++i,"total no peer to ack to"),!1}if(m&&!s.put&&!h&&((o.s[m]||"").it||"")["##"])return!1;if(!c&&t.way)return t.way(s);if(g&&(g.yh=+new Date),p=y.raw){if(g&&(g.yr=+new Date),!c||!c.id){if(!Object.plain(c||r.peers))return!1;b=+new Date,r.puff;var w=r.peers,v=Object.keys(c||r.peers||{});return console.STAT&&console.STAT(b,+new Date-b,"peer keys"),void function n(){var r=+new Date;e=1;var i=y.raw;y.raw=p;for(var o,l=0;l<9&&(o=(v||"")[l++]);)(o=w[o]||(c||"")[o])&&t.say(s,o);y.raw=i,e=0,v=v.slice(l),console.STAT&&console.STAT(r,+new Date-r,"say loop"),v.length&&(a(n,0),m&&A(m))}()}if(!c.wire&&t.wire&&t.wire(c),d!==c.last){if(c.last=d,c===y.via)return!1;if((l=y.yo)&&(l[c.url]||l[c.pid]||l[c.id]))return!1;if(console.STAT&&console.STAT(b,((g||y).yp=+new Date)-(y.y||b),"say prep"),!e&&m&&A(m),c.batch){if(c.tail=(l=c.tail||0)+p.length,c.tail<=r.pack)return void(c.batch+=(l?",":"")+p);f(c)}c.batch="[";var _=+new Date;setTimeout(function(){console.STAT&&console.STAT(_,+new Date-_,"0ms TO"),f(c)},r.gap),u(p,c),console.STAT&&m===c.SI&&console.STAT(b,+new Date-c.SH,"say ack")}}else t.raw(s,c)}else t.hash(s,c)}).c=t.say.d=0,t.raw=function(e,i){if(!e)return"";var a,A,l=e._||{};if(A=l.raw)return A;if("string"==typeof e)return e;var f=e["##"],u=e["@"];if(f&&u){if(!l.via&&c(u+f))return!1;if(A=(o.s[u]||"").it){if(f===A["##"])return!1;A["##"]||(A["##"]=f)}}if(!e.dam&&!e["@"]){var d=0,h=[];for(var p in A=r.peers){var m=A[p];if(h.push(m.url||m.pid||m.id),++d>6)break}d>1&&(e["><"]=h.join())}if(e.put&&(A=e.ok)&&(e.ok={"@":(A["@"]||1)-1,"/":A["/"]==e._.near?t.near:A["/"]}),a=l.$put)return A={},Object.keys(e).forEach(function(t){A[t]=e[t]}),A.put=":])([:",void s(A,function(e,t){if(!e){var r=+new Date;A=t.indexOf('"put":":])([:"'),y(n,t=t.slice(0,A+6)+a+t.slice(A+14)),console.STAT&&console.STAT(r,+new Date-r,"say slice")}});function y(n,r){n||(l.raw=r,t.say(e,i))}s(e,y)}}(),t.near=0,t.hi=function(n){var i;n.wire?(n.id?r.peers[n.url||n.id]=n:(i=n.id=n.id||n.url||String.random(9),t.say({dam:"?",pid:e.opt.pid},r.peers[i]=n),delete o.s[n.last]),n.met||(t.near++,n.met=+new Date,e.on("hi",n)),i=n.queue,n.queue=[],setTimeout.each(i||[],function(e){u(e,n)},0,9)):t.wire(n.length&&{url:n,id:n}||n)},t.bye=function(n){n.met&&--t.near,delete n.met,e.on("bye",n);var r=+new Date;r-=n.met||r,t.bye.time=((t.bye.time||r)+r)/2},t.hear["!"]=function(e,t){r.log("Error:",e.err)},t.hear["?"]=function(e,n){e.pid&&(n.pid||(n.pid=e.pid),e["@"])||(t.say({dam:"?",pid:r.pid,"@":e["#"]},n),delete o.s[n.last])},t.hear.mob=function(e,n){if(e.peers){var r=Object.keys(e.peers),i=r[Math.random()*r.length|0];i&&(t.bye(n),t.hi(i))}},e.on("create",function(e){e.opt.pid=e.opt.pid||String.random(9),this.to.next(e),e.on("out",t.say)}),e.on("bye",function(e,t){e=r.peers[e.id||e]||e,this.to.next(e),e.bye?e.bye():(t=e.wire)&&t.close&&t.close(),delete r.peers[e.id],e.wire=null}),e.on("bye",function(e,n){this.to.next(e),(n=console.STAT)&&(n.peers=t.near),(n=e.url)&&setTimeout(function(){},r.lack||9e3)}),e.on("hi",function(n,i){if(this.to.next(n),(i=console.STAT)&&(i.peers=t.near),!r.super){var s=Object.keys(e.next||"");s.length>9999&&!console.SUBS&&console.log(console.SUBS="Warning: You have more than 10K live GETs, which might use more bandwidth than your screen can show - consider `.off()`."),setTimeout.each(s,function(i){var s=e.next[i];r.super||(s.ask||"")[""]?t.say({get:{"#":i}},n):setTimeout.each(Object.keys(s.ask||""),function(r){r&&t.say({"##":String.hash((e.graph[i]||"")[r]),get:{"#":i,".":r}},n)})})}}),t}}catch(a){}})(e,"./mesh"),e(function(t){var n=e("./index");n.Mesh=e("./mesh"),n.on("opt",function(e){if(this.to.next(e),!e.once){var t=e.opt;if(!1!==t.WebSocket){var r=n.window||{},i=t.WebSocket||r.WebSocket||r.webkitWebSocket||r.mozWebSocket;if(i){t.WebSocket=i;var s=t.mesh=t.mesh||n.Mesh(e);s.wire||t.wire,s.wire=t.wire=c,setTimeout(function(){!t.super&&e.on("out",{dam:"hi"})},1);var a=1998,o=""+void 0!=typeof document&&document}}}function c(e){try{if(!e||!e.url)return r&&r(e);var n=e.url.replace(/^http/,"ws"),r=e.wire=new t.WebSocket(n);return r.onclose=function(){A(e),t.mesh.bye(e)},r.onerror=function(t){A(e)},r.onopen=function(){t.mesh.hi(e)},r.onmessage=function(n){n&&t.mesh.hear(n.data||n,e)},r}catch(i){t.mesh.bye(e)}}function A(e){clearTimeout(e.defer),t.peers[e.url]&&(o&&e.retry<=0||(e.retry=(e.retry||t.retry+1||60)-(-e.tried+(e.tried=+new Date)<4*a?1:0),e.defer=setTimeout(function t(){if(o&&o.hidden)return setTimeout(t,a);c(e)},a)))}})})(e,"./websocket"),e(function(e){if("undefined"!=typeof Gun){var t;try{t=(Gun.window||function(){}).localStorage}catch(r){}t||(Gun.log("Warning: No localStorage exists to persist data to!"),t={setItem:function(e,t){this[e]=t},removeItem:function(e){delete this[e]},getItem:function(e){return this[e]}});var n=JSON.stringifyAsync||function(e,t,n,i){try{t(void 0,JSON.stringify(e,n,i))}catch(r){t(r)}};Gun.on("create",function e(i){this.to.next(i);var s=i.opt;i.graph;var a,o,c,A,l=[];if(!1!==s.localStorage){s.prefix=s.file||"gun/";try{a=e[s.prefix]=e[s.prefix]||JSON.parse(c=t.getItem(s.prefix))||{}}catch(r){a=e[s.prefix]={}}c=(c||"").length,i.on("get",function(e){this.to.next(e);var t,n,r,i=e.get;i&&(t=i["#"])&&((n=a[t]||void 0)&&(r=i["."])&&!Object.plain(r)&&(n=Gun.state.ify({},r,Gun.state.is(n,r),n[r],t)),Gun.on.get.ack(e,n))}),i.on("put",function(e){this.to.next(e);var t=e.put,n=t["#"],r=t["."],s=e["#"],u=e.ok||"";(i.next||"")[n]&&(a[n]=Gun.state.ify(a[n],r,t[">"],t[":"],n),A&&c>4999880?i.on("in",{"@":s,err:"localStorage max!"}):(e["@"]||e._.via&&!(Math.random()<u["@"]/u["/"])||l.push(s),o||(o=setTimeout(f,9+c/333))))})}function f(){if(l.length||!((setTimeout.turn||"").s||"").length){var e=l;clearTimeout(o),o=!1,l=[],n(a,function(n,o){try{!n&&t.setItem(s.prefix,o)}catch(r){n=A=r||"localStorage failure"}n&&(Gun.log(n+" Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"),i.on("localStorage:error",{err:n,get:s.prefix,put:a})),c=o.length,setTimeout.each(e,function(e){i.on("in",{"@":e,err:n,ok:0})},0,99)})}else setTimeout(f,99)}})}})(e,"./localStorage")}(),function(){if(""+_!=typeof Gun){var e=function(e){console.warn("Warning! Deprecated internal utility will break in next version:",e)},t=Gun;t.fn=t.fn||{is:function(t){return e("fn"),!!t&&"function"==typeof t}},t.bi=t.bi||{is:function(t){return e("bi"),t instanceof Boolean||"boolean"==typeof t}},t.num=t.num||{is:function(t){return e("num"),!r(t)&&(t-parseFloat(t)+1>=0||1/0===t||-1/0===t)}},t.text=t.text||{is:function(t){return e("text"),"string"==typeof t}},t.text.ify=t.text.ify||function(n){return e("text.ify"),t.text.is(n)?n:"undefined"!=typeof JSON?JSON.stringify(n):n&&n.toString?n.toString():n},t.text.random=t.text.random||function(t,n){e("text.random");var r="";for(t=t||24,n=n||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";t>0;)r+=n.charAt(Math.floor(Math.random()*n.length)),t--;return r},t.text.match=t.text.match||function(t,n){var r,i;return e("text.match"),"string"==typeof t&&("string"==typeof n&&(n={"=":n}),t===(r=(n=n||{})["="]||n["*"]||n[">"]||n["<"])||i===n["="]&&(r=n["*"]||n[">"]||n["<"],t.slice(0,(r||"").length)===r||i===n["*"]&&(i!==n[">"]&&i!==n["<"]?t>=n[">"]&&t<=n["<"]:i!==n[">"]&&t>=n[">"]||i!==n["<"]&&t<=n["<"])))},t.text.hash=t.text.hash||function(t,n){if(e("text.hash"),"string"==typeof t){if(n=n||0,!t.length)return n;for(var r=0,i=t.length;r<i;++r)n=(n<<5)-n+t.charCodeAt(r),n|=0;return n}},t.list=t.list||{is:function(t){return e("list"),t instanceof Array}},t.list.slit=t.list.slit||Array.prototype.slice,t.list.sort=t.list.sort||function(t){return e("list.sort"),function(e,n){return e&&n?(e=e[t])<(n=n[t])?-1:e>n?1:0:0}},t.list.map=t.list.map||function(t,n,r){return e("list.map"),a(t,n,r)},t.list.index=1,t.obj=t.boj||{is:function(t){return e("obj"),!!t&&(t instanceof Object&&t.constructor===Object||"Object"===Object.prototype.toString.call(t).match(/^\[object (\w+)\]$/)[1])}},t.obj.put=t.obj.put||function(t,n,r){return e("obj.put"),(t||{})[n]=r,t},t.obj.has=t.obj.has||function(t,n){return e("obj.has"),t&&Object.prototype.hasOwnProperty.call(t,n)},t.obj.del=t.obj.del||function(t,n){if(e("obj.del"),t)return t[n]=null,delete t[n],t},t.obj.as=t.obj.as||function(t,n,r,i){return e("obj.as"),t[n]=t[n]||(i===r?{}:r)},t.obj.ify=t.obj.ify||function(t){if(e("obj.ify"),i(t))return t;try{t=JSON.parse(t)}catch(n){t={}}return t},function(){function n(e,t){s(this,t)&&void 0!==this[t]||(this[t]=e)}t.obj.to=t.obj.to||function(t,r){return e("obj.to"),a(t,n,r=r||{}),r}}(),t.obj.copy=t.obj.copy||function(t){return e("obj.copy"),t?JSON.parse(JSON.stringify(t)):t},function(){function n(e,t){var n=this.n;if(!n||!(t===n||i(n)&&s(n,t)))return void 0!==t||void 0}t.obj.empty=t.obj.empty||function(t,r){return e("obj.empty"),!t||!a(t,n,{n:r})}}(),function(){function n(e,t){if(2===arguments.length)return n.r=n.r||{},void(n.r[e]=t);n.r=n.r||[],n.r.push(e)}var a,o=Object.keys;Object.keys=Object.keys||function(e){return a(e,function(e,t,n){n(t)})},t.obj.map=a=t.obj.map||function(a,c,A){e("obj.map");var l,f,u,d,h,p=0,m="function"==typeof c;if(n.r=l,o&&i(a)&&(d=o(a),h=!0),A=A||{},r(a)||d)for(f=(d||a).length;p<f;p++){var y=p+t.list.index;if(m){if((u=h?c.call(A,a[d[p]],d[p],n):c.call(A,a[p],y,n))!==l)return u}else if(c===a[h?d[p]:p])return d?d[p]:y}else for(p in a)if(m){if(s(a,p)&&(u=A?c.call(A,a[p],p,n):c(a[p],p,n))!==l)return u}else if(c===a[p])return p;return m?n.r:t.list.index?0:-1}}(),t.time=t.time||{},t.time.is=t.time.is||function(t){return e("time"),t?t instanceof Date:+(new Date).getTime()};var n=t.fn.is,r=t.list.is,i=(v=t.obj).is,s=v.has,a=v.map,o={is:function(t){return e("val.is"),t!==_&&(null===t||t!==1/0&&(!!(f(t)||A(t)||l(t))||o.link.is(t)||!1))}};o.link=o.rel={_:"#"},function(){function t(e,t){var n=this;return n.id?n.id=!1:t==c&&f(e)?void(n.id=e):n.id=!1}o.link.is=function(n){if(e("val.link.is"),n&&n[c]&&!n._&&i(n)){var r={};if(a(n,t,r),r.id)return r.id}return!1}}(),o.link.ify=function(t){return e("val.link.ify"),u({},c,t)},t.obj.has._=".";var c=o.link._,A=t.bi.is,l=t.num.is,f=t.text.is,u=(i=(v=t.obj).is,v.put);a=v.map,t.val=t.val||o;var d={_:"_",soul:function(t,n){return e("node.soul"),t&&t._&&t._[n||m]}};d.soul.ify=function(t,n){return e("node.soul.ify"),n="string"==typeof n?{soul:n}:n||{},(t=t||{})._=t._||{},t._[m]=n.soul||t._[m]||p(),t},d.soul._=o.link._,function(){function t(e,t){if(t!==d._)return!o.is(e)||void(this.cb&&this.cb.call(this.as,e,t,this.n,this.s))}d.is=function(n,r,s){var o;return e("node.is"),!!i(n)&&!!(o=d.soul(n))&&!a(n,t,{as:s,cb:r,s:o,n:n})}}(),function(){function t(e,t){var n,r=this.o;r.map?void 0===(n=r.map.call(this.as,e,""+t,r.node))?h(r.node,t):r.node&&(r.node[t]=n):o.is(e)&&(r.node[t]=e)}d.ify=function(n,r,i){return e("node.ify"),r?"string"==typeof r?r={soul:r}:"function"==typeof r&&(r={map:r}):r={},r.map&&(r.node=r.map.call(i,n,_,r.node||{})),(r.node=d.soul.ify(r.node||{},r))&&a(n,t,{o:r,as:i}),r.node}}(),i=(v=t.obj).is;var h=v.del,p=(a=v.map,t.text.random),m=d.soul._;t.node=t.node||d;var y=t.state;y.lex=function(){return e("state.lex"),y().toString(36).replace(".","")},y.to=function(t,n,r){e("state.to");var s=(t||{})[n];return i(s)&&(s=g(s)),y.ify(r,n,y.is(t,n),s,d.soul(t))},function(){function t(e,t){b!==t&&y.ify(this.o,t,this.s)}y.map=function(r,o,c){var A;e("state.map");var f=i(f=r||o)?f:null;return r=n(r=r||o)?r:null,f&&!r?(o=l(o)?o:y(),f[b]=f[b]||{},a(f,t,{o:f,s:o}),f):(c=c||i(o)?o:A,o=l(o)?o:y(),function(e,n,i,a){if(!r)return t.call({o:i,s:o},e,n),e;r.call(c||this||{},e,n,i,a),s(i,n)&&A===i[n]||t.call({o:i,s:o},e,n)})}}(),(v=t.obj).as,s=v.has,i=v.is,a=v.map;var g=v.copy,b=(l=t.num.is,n=t.fn.is,d._),w={};!function(){function t(e,t){if(!e||t!==d.soul(e)||!d.is(e,this.fn,this.as))return!0;this.cb&&(n.n=e,n.as=this.as,this.cb.call(n.as,e,t,n))}function n(e){e&&d.is(n.n,e,n.as)}w.is=function(n,r,s,o){return e("graph.is"),!(!n||!i(n)||E(n)||a(n,t,{cb:r,fn:s,as:o}))}}(),function(){function n(e,t){var n;return(n=function(e,t){for(var n,r=e.seen,i=r.length;i--;)if(n=r[i],t.obj===n.obj)return n;r.push(t)}(e,t))?n:(t.env=e,t.soul=a,d.ify(t.obj,r,t)&&(t.link=t.link||o.link.ify(d.soul(t.node)),t.obj!==e.shell&&(e.graph[o.link.is(t.link)]=t.node)),t)}function r(e,t,r){var i,a,A=this,l=A.env;if(d._===t&&s(e,o.link._))return r._;if(i=c(e,t,r,A,l)){if(t||(A.node=A.node||r||{},s(e,d._)&&d.soul(e)&&(A.node._=g(e._)),A.node=d.soul.ify(A.node,o.link.is(A.link)),A.link=A.link||o.link.ify(d.soul(A.node))),(a=l.map)&&(a.call(l.as||{},e,t,r,A),s(r,t))){if(e=r[t],_===e)return void h(r,t);if(!(i=c(e,t,r,A,l)))return}if(!t)return A.node;if(!0===i)return e;if((a=n(l,{obj:e,path:A.path.concat(t)})).node)return a.link}}function a(e){var t=this,n=o.link.is(t.link),r=t.env.graph;t.link=t.link||o.link.ify(e),t.link[o.link._]=e,t.node&&t.node[d._]&&(t.node[d._][o.link._]=e),s(r,n)&&(r[e]=r[n],h(r,n))}function c(e,n,r,s,a){var A;return!!o.is(e)||(i(e)?1:(A=a.invalid)?c(e=A.call(a.as||{},e,n,r),n,r,s,a):(a.err="Invalid value at '"+s.path.concat(n).join(".")+"'!",void(t.list.is(e)&&(a.err+=" Use `.set(item)` instead of an Array."))))}w.ify=function(t,r,i){e("graph.ify");var s={path:[],obj:t};return r?"string"==typeof r?r={soul:r}:"function"==typeof r&&(r.map=r):r={},"string"==typeof i&&(r.soul=r.soul||i,i=_),r.soul&&(s.link=o.link.ify(r.soul)),r.shell=(i||{}).shell,r.graph=r.graph||{},r.seen=r.seen||[],r.as=r.as||i,n(r,s),r.root=s.node,r.graph}}(),w.node=function(t){e("graph.node");var n=d.soul(t);if(n)return u({},n,t)},function(){function t(e,t){var n,r;if(d._!==t)(n=o.link.is(e))?(r=this.opt.seen[n])?this.obj[t]=r:this.obj[t]=this.opt.seen[n]=w.to(this.graph,n,this.opt):this.obj[t]=e;else{if(E(e,o.link._))return;this.obj[t]=g(e)}}w.to=function(n,r,i){if(e("graph.to"),n){var s={};return i=i||{seen:{}},a(n[r],t,{obj:s,graph:n,opt:i}),s}}}(),n=t.fn.is,i=(v=t.obj).is,h=v.del,s=v.has;var v,_,E=v.empty;u=v.put,a=v.map,g=v.copy,t.graph=t.graph||w}}();var UL=GL.exports;const LL=er({__proto__:null,default:Vu(UL)},[UL]);class jL extends Jb{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,$b(e);const n=Qb(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,i=new Uint8Array(r);i.set(n.length>r?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),Fb(i)}update(e){return Db(this),this.iHash.update(e),this}digestInto(e){Db(this),Mb(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:s,outputLen:a}=this;return e.finished=r,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const HL=(e,t,n)=>new jL(e,t).update(n).digest();HL.create=(e,t)=>new jL(e,t);
45
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
46
+ const zL=BigInt(0),qL=BigInt(1);function QL(e,t=""){if("boolean"!=typeof e)throw new Error((t&&`"${t}"`)+"expected boolean, got type="+typeof e);return e}function VL(e,t,n=""){const r=Rb(e),i=e?.length,s=void 0!==t;if(!r||s&&i!==t)throw new Error((n&&`"${n}" `)+"expected Uint8Array"+(s?` of length ${t}`:"")+", got "+(r?`length=${i}`:"type="+typeof e));return e}function JL(e){const t=e.toString(16);return 1&t.length?"0"+t:t}function KL(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?zL:BigInt("0x"+e)}function WL(e){return KL(Hb(e))}function YL(e){return Mb(e),KL(Hb(Uint8Array.from(e).reverse()))}function ZL(e,t){return qb(e.toString(16).padStart(2*t,"0"))}function XL(e,t){return ZL(e,t).reverse()}function ej(e,t,n){let r;if("string"==typeof t)try{r=qb(t)}catch(i){throw new Error(e+" must be hex string or Uint8Array, cause: "+i)}else{if(!Rb(t))throw new Error(e+" must be hex string or Uint8Array");r=Uint8Array.from(t)}return r.length,r}const tj=e=>"bigint"==typeof e&&zL<=e;function nj(e){let t;for(t=0;e>zL;e>>=qL,t+=1);return t}const rj=e=>(qL<<BigInt(e))-qL;function ij(e,t,n={}){if(!e||"object"!=typeof e)throw new Error("expected valid options object");function r(t,n,r){const i=e[t];if(r&&void 0===i)return;const s=typeof i;if(s!==n||null===i)throw new Error(`param "${t}" is invalid: expected ${n}, got ${s}`)}Object.entries(t).forEach(([e,t])=>r(e,t,!1)),Object.entries(n).forEach(([e,t])=>r(e,t,!0))}function sj(e){const t=new WeakMap;return(n,...r)=>{const i=t.get(n);if(void 0!==i)return i;const s=e(n,...r);return t.set(n,s),s}}
47
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const aj=BigInt(0),oj=BigInt(1),cj=BigInt(2),Aj=BigInt(3),lj=BigInt(4),fj=BigInt(5),uj=BigInt(7),dj=BigInt(8),hj=BigInt(9),pj=BigInt(16);function mj(e,t){const n=e%t;return n>=aj?n:t+n}function yj(e,t,n){let r=e;for(;t-- >aj;)r*=r,r%=n;return r}function gj(e,t){if(e===aj)throw new Error("invert: expected non-zero number");if(t<=aj)throw new Error("invert: expected positive modulus, got "+t);let n=mj(e,t),r=t,i=aj,s=oj;for(;n!==aj;){const e=r%n,t=i-s*(r/n);r=n,n=e,i=s,s=t}if(r!==oj)throw new Error("invert: does not exist");return mj(i,t)}function bj(e,t,n){if(!e.eql(e.sqr(t),n))throw new Error("Cannot find square root")}function wj(e,t){const n=(e.ORDER+oj)/lj,r=e.pow(t,n);return bj(e,r,t),r}function vj(e,t){const n=(e.ORDER-fj)/dj,r=e.mul(t,cj),i=e.pow(r,n),s=e.mul(t,i),a=e.mul(e.mul(s,cj),i),o=e.mul(s,e.sub(a,e.ONE));return bj(e,o,t),o}function _j(e){if(e<Aj)throw new Error("sqrt is not defined for small field");let t=e-oj,n=0;for(;t%cj===aj;)t/=cj,n++;let r=cj;const i=xj(e);for(;1===Tj(i,r);)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===n)return wj;let s=i.pow(r,t);const a=(t+oj)/cj;return function(e,r){if(e.is0(r))return r;if(1!==Tj(e,r))throw new Error("Cannot find square root");let i=n,o=e.mul(e.ONE,s),c=e.pow(r,t),A=e.pow(r,a);for(;!e.eql(c,e.ONE);){if(e.is0(c))return e.ZERO;let t=1,n=e.sqr(c);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===i)throw new Error("Cannot find square root");const r=oj<<BigInt(i-t-1),s=e.pow(o,r);i=t,o=e.sqr(s),c=e.mul(c,o),A=e.mul(A,s)}return A}}const Ej=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function kj(e,t,n=!1){const r=new Array(t.length).fill(n?e.ZERO:void 0),i=t.reduce((t,n,i)=>e.is0(n)?t:(r[i]=t,e.mul(t,n)),e.ONE),s=e.inv(i);return t.reduceRight((t,n,i)=>e.is0(n)?t:(r[i]=e.mul(t,r[i]),e.mul(t,n)),s),r}function Tj(e,t){const n=(e.ORDER-oj)/cj,r=e.pow(t,n),i=e.eql(r,e.ONE),s=e.eql(r,e.ZERO),a=e.eql(r,e.neg(e.ONE));if(!i&&!s&&!a)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function Sj(e,t){void 0!==t&&Bb(t);const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function xj(e,t,n=!1,r={}){if(e<=aj)throw new Error("invalid field: expected ORDER > 0, got "+e);let i,s,a,o=!1;if("object"==typeof t&&null!=t){if(r.sqrt||n)throw new Error("cannot specify opts in two arguments");const e=t;e.BITS&&(i=e.BITS),e.sqrt&&(s=e.sqrt),"boolean"==typeof e.isLE&&(n=e.isLE),"boolean"==typeof e.modFromBytes&&(o=e.modFromBytes),a=e.allowedLengths}else"number"==typeof t&&(i=t),r.sqrt&&(s=r.sqrt);const{nBitLength:c,nByteLength:A}=Sj(e,i);if(A>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l;const f=Object.freeze({ORDER:e,isLE:n,BITS:c,BYTES:A,MASK:rj(c),ZERO:aj,ONE:oj,allowedLengths:a,create:t=>mj(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("invalid field element: expected bigint, got "+typeof t);return aj<=t&&t<e},is0:e=>e===aj,isValidNot0:e=>!f.is0(e)&&f.isValid(e),isOdd:e=>(e&oj)===oj,neg:t=>mj(-t,e),eql:(e,t)=>e===t,sqr:t=>mj(t*t,e),add:(t,n)=>mj(t+n,e),sub:(t,n)=>mj(t-n,e),mul:(t,n)=>mj(t*n,e),pow:(e,t)=>function(e,t,n){if(n<aj)throw new Error("invalid exponent, negatives unsupported");if(n===aj)return e.ONE;if(n===oj)return t;let r=e.ONE,i=t;for(;n>aj;)n&oj&&(r=e.mul(r,i)),i=e.sqr(i),n>>=oj;return r}(f,e,t),div:(t,n)=>mj(t*gj(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>gj(t,e),sqrt:s||(t=>{return l||(l=(n=e)%lj===Aj?wj:n%dj===fj?vj:n%pj===hj?function(e){const t=xj(e),n=_j(e),r=n(t,t.neg(t.ONE)),i=n(t,r),s=n(t,t.neg(r)),a=(e+uj)/pj;return(e,t)=>{let n=e.pow(t,a),o=e.mul(n,r);const c=e.mul(n,i),A=e.mul(n,s),l=e.eql(e.sqr(o),t),f=e.eql(e.sqr(c),t);n=e.cmov(n,o,l),o=e.cmov(A,c,f);const u=e.eql(e.sqr(o),t),d=e.cmov(n,o,u);return bj(e,d,t),d}}(n):_j(n)),l(f,t);var n}),toBytes:e=>n?XL(e,A):ZL(e,A),fromBytes:(t,r=!0)=>{if(a){if(!a.includes(t.length)||t.length>A)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+t.length);const e=new Uint8Array(A);e.set(t,n?0:e.length-t.length),t=e}if(t.length!==A)throw new Error("Field.fromBytes: expected "+A+" bytes, got "+t.length);let i=n?YL(t):WL(t);if(o&&(i=mj(i,e)),!r&&!f.isValid(i))throw new Error("invalid field element: outside of range 0..ORDER");return i},invertBatch:e=>kj(f,e),cmov:(e,t,n)=>n?t:e});return Object.freeze(f)}function Ij(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function Pj(e){const t=Ij(e);return t+Math.ceil(t/2)}
48
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
49
+ const Cj=BigInt(0),Nj=BigInt(1);function Oj(e,t){const n=t.negate();return e?n:t}function Rj(e,t){const n=kj(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function Bj(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Mj(e,t){Bj(e,t);const n=2**e;return{windows:Math.ceil(t/e)+1,windowSize:2**(e-1),mask:rj(e),maxNumber:n,shiftBy:BigInt(e)}}function $j(e,t,n){const{windowSize:r,mask:i,maxNumber:s,shiftBy:a}=n;let o=Number(e&i),c=e>>a;o>r&&(o-=s,c+=Nj);const A=t*r;return{nextN:c,offset:A+Math.abs(o)-1,isZero:0===o,isNeg:o<0,isNegF:t%2!=0,offsetF:A}}const Dj=new WeakMap,Fj=new WeakMap;function Gj(e){return Fj.get(e)||1}function Uj(e){if(e!==Cj)throw new Error("invalid wNAF")}class Lj{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>Cj;)t&Nj&&(n=n.add(r)),r=r.double(),t>>=Nj;return n}precomputeWindow(e,t){const{windows:n,windowSize:r}=Mj(t,this.bits),i=[];let s=e,a=s;for(let o=0;o<n;o++){a=s,i.push(a);for(let e=1;e<r;e++)a=a.add(s),i.push(a);s=a.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let r=this.ZERO,i=this.BASE;const s=Mj(e,this.bits);for(let a=0;a<s.windows;a++){const{nextN:e,offset:o,isZero:c,isNeg:A,isNegF:l,offsetF:f}=$j(n,a,s);n=e,c?i=i.add(Oj(l,t[f])):r=r.add(Oj(A,t[o]))}return Uj(n),{p:r,f:i}}wNAFUnsafe(e,t,n,r=this.ZERO){const i=Mj(e,this.bits);for(let s=0;s<i.windows&&n!==Cj;s++){const{nextN:e,offset:a,isZero:o,isNeg:c}=$j(n,s,i);if(n=e,!o){const e=t[a];r=r.add(c?e.negate():e)}}return Uj(n),r}getPrecomputes(e,t,n){let r=Dj.get(t);return r||(r=this.precomputeWindow(t,e),1!==e&&("function"==typeof n&&(r=n(r)),Dj.set(t,r))),r}cached(e,t,n){const r=Gj(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){const i=Gj(e);return 1===i?this._unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)}createCache(e,t){Bj(t,this.bits),Fj.set(e,t),Dj.delete(e)}hasCache(e){return 1!==Gj(e)}}function jj(e,t,n){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return function(e){ij(e,Ej.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"}))}(t),t}return xj(e,{isLE:n})}
50
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
51
+ const Hj=(e,t)=>(e+(e>=0?t:-t)/Wj)/t;function zj(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function qj(e,t){const n={};for(let r of Object.keys(t))n[r]=void 0===e[r]?t[r]:e[r];return QL(n.lowS,"lowS"),QL(n.prehash,"prehash"),void 0!==n.format&&zj(n.format),n}class Qj extends Error{constructor(e=""){super(e)}}const Vj={Err:Qj,_tlv:{encode:(e,t)=>{const{Err:n}=Vj;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(1&t.length)throw new n("tlv.encode: unpadded data");const r=t.length/2,i=JL(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const s=r>127?JL(i.length/2|128):"";return JL(e)+s+i+t},decode(e,t){const{Err:n}=Vj;let r=0;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(t.length<2||t[r++]!==e)throw new n("tlv.decode: wrong tlv");const i=t[r++];let s=0;if(128&i){const e=127&i;if(!e)throw new n("tlv.decode(long): indefinite length not supported");if(e>4)throw new n("tlv.decode(long): byte length is too big");const a=t.subarray(r,r+e);if(a.length!==e)throw new n("tlv.decode: length bytes not complete");if(0===a[0])throw new n("tlv.decode(long): zero leftmost byte");for(const t of a)s=s<<8|t;if(r+=e,s<128)throw new n("tlv.decode(long): not minimal encoding")}else s=i;const a=t.subarray(r,r+s);if(a.length!==s)throw new n("tlv.decode: wrong value length");return{v:a,l:t.subarray(r+s)}}},_int:{encode(e){const{Err:t}=Vj;if(e<Jj)throw new t("integer: negative integers are not allowed");let n=JL(e);if(8&Number.parseInt(n[0],16)&&(n="00"+n),1&n.length)throw new t("unexpected DER parsing assertion: unpadded hex");return n},decode(e){const{Err:t}=Vj;if(128&e[0])throw new t("invalid signature integer: negative");if(0===e[0]&&!(128&e[1]))throw new t("invalid signature integer: unnecessary leading zero");return WL(e)}},toSig(e){const{Err:t,_int:n,_tlv:r}=Vj,i=ej("signature",e),{v:s,l:a}=r.decode(48,i);if(a.length)throw new t("invalid signature: left bytes after parsing");const{v:o,l:c}=r.decode(2,s),{v:A,l:l}=r.decode(2,c);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:n.decode(o),s:n.decode(A)}},hexFromSig(e){const{_tlv:t,_int:n}=Vj,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},Jj=BigInt(0),Kj=BigInt(1),Wj=BigInt(2),Yj=BigInt(3),Zj=BigInt(4);function Xj(e,t){const{BYTES:n}=e;let r;if("bigint"==typeof t)r=t;else{let s=ej("private key",t);try{r=e.fromBytes(s)}catch(i){throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof t}`)}}if(!e.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function eH(e,t={}){const n=function(e,t,n={},r){if(void 0===r&&(r="edwards"===e),!t||"object"!=typeof t)throw new Error(`expected valid ${e} CURVE object`);for(const o of["p","n","h"]){const e=t[o];if(!("bigint"==typeof e&&e>Cj))throw new Error(`CURVE.${o} must be positive bigint`)}const i=jj(t.p,n.Fp,r),s=jj(t.n,n.Fn,r),a=["Gx","Gy","a","b"];for(const o of a)if(!i.isValid(t[o]))throw new Error(`CURVE.${o} must be valid field element of CURVE.Fp`);return{CURVE:t=Object.freeze(Object.assign({},t)),Fp:i,Fn:s}}("weierstrass",e,t),{Fp:r,Fn:i}=n;let s=n.CURVE;const{h:a,n:o}=s;ij(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:c}=t;if(c&&(!r.is0(s.a)||"bigint"!=typeof c.beta||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const A=nH(r,i);function l(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const f=t.toBytes||function(e,t,n){const{x:i,y:s}=t.toAffine(),a=r.toBytes(i);return QL(n,"isCompressed"),n?(l(),Vb(tH(!r.isOdd(s)),a)):Vb(Uint8Array.of(4),a,r.toBytes(s))},u=t.fromBytes||function(e){VL(e,void 0,"Point");const{publicKey:t,publicKeyUncompressed:n}=A,i=e.length,s=e[0],a=e.subarray(1);if(i!==t||2!==s&&3!==s){if(i===n&&4===s){const e=r.BYTES,t=r.fromBytes(a.subarray(0,e)),n=r.fromBytes(a.subarray(e,2*e));if(!h(t,n))throw new Error("bad point: is not on curve");return{x:t,y:n}}throw new Error(`bad point: got length ${i}, expected compressed=${t} or uncompressed=${n}`)}{const e=r.fromBytes(a);if(!r.isValid(e))throw new Error("bad point: is not on curve, wrong x");const t=d(e);let n;try{n=r.sqrt(t)}catch(o){const e=o instanceof Error?": "+o.message:"";throw new Error("bad point: is not on curve, sqrt error"+e)}return l(),!(1&~s)!==r.isOdd(n)&&(n=r.neg(n)),{x:e,y:n}}};function d(e){const t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,s.a)),s.b)}function h(e,t){const n=r.sqr(t),i=d(e);return r.eql(n,i)}if(!h(s.Gx,s.Gy))throw new Error("bad curve params: generator point");const p=r.mul(r.pow(s.a,Yj),Zj),m=r.mul(r.sqr(s.b),BigInt(27));if(r.is0(r.add(p,m)))throw new Error("bad curve params: a or b");function y(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw new Error(`bad point coordinate ${e}`);return t}function g(e){if(!(e instanceof E))throw new Error("ProjectivePoint expected")}function b(e){if(!c||!c.basises)throw new Error("no endo");return function(e,t,n){const[[r,i],[s,a]]=t,o=Hj(a*e,n),c=Hj(-i*e,n);let A=e-o*r-c*s,l=-o*i-c*a;const f=A<Jj,u=l<Jj;f&&(A=-A),u&&(l=-l);const d=rj(Math.ceil(nj(n)/2))+Kj;if(A<Jj||A>=d||l<Jj||l>=d)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:f,k1:A,k2neg:u,k2:l}}(e,c.basises,i.ORDER)}const w=sj((e,t)=>{const{X:n,Y:i,Z:s}=e;if(r.eql(s,r.ONE))return{x:n,y:i};const a=e.is0();null==t&&(t=a?r.ONE:r.inv(s));const o=r.mul(n,t),c=r.mul(i,t),A=r.mul(s,t);if(a)return{x:r.ZERO,y:r.ZERO};if(!r.eql(A,r.ONE))throw new Error("invZ was invalid");return{x:o,y:c}}),v=sj(e=>{if(e.is0()){if(t.allowInfinityPoint&&!r.is0(e.Y))return;throw new Error("bad point: ZERO")}const{x:n,y:i}=e.toAffine();if(!r.isValid(n)||!r.isValid(i))throw new Error("bad point: x or y not field elements");if(!h(n,i))throw new Error("bad point: equation left != right");if(!e.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function _(e,t,n,i,s){return n=new E(r.mul(n.X,e),n.Y,n.Z),t=Oj(i,t),n=Oj(s,n),t.add(n)}class E{constructor(e,t,n){this.X=y("x",e),this.Y=y("y",t,!0),this.Z=y("z",n),Object.freeze(this)}static CURVE(){return s}static fromAffine(e){const{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw new Error("invalid affine point");if(e instanceof E)throw new Error("projective point not allowed");return r.is0(t)&&r.is0(n)?E.ZERO:new E(t,n,r.ONE)}static fromBytes(e){const t=E.fromAffine(u(VL(e,void 0,"point")));return t.assertValidity(),t}static fromHex(e){return E.fromBytes(ej("pointHex",e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return T.createCache(this,e),t||this.multiply(Yj),this}assertValidity(){v(this)}hasEvenY(){const{y:e}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(e)}equals(e){g(e);const{X:t,Y:n,Z:i}=this,{X:s,Y:a,Z:o}=e,c=r.eql(r.mul(t,o),r.mul(s,i)),A=r.eql(r.mul(n,o),r.mul(a,i));return c&&A}negate(){return new E(this.X,r.neg(this.Y),this.Z)}double(){const{a:e,b:t}=s,n=r.mul(t,Yj),{X:i,Y:a,Z:o}=this;let c=r.ZERO,A=r.ZERO,l=r.ZERO,f=r.mul(i,i),u=r.mul(a,a),d=r.mul(o,o),h=r.mul(i,a);return h=r.add(h,h),l=r.mul(i,o),l=r.add(l,l),c=r.mul(e,l),A=r.mul(n,d),A=r.add(c,A),c=r.sub(u,A),A=r.add(u,A),A=r.mul(c,A),c=r.mul(h,c),l=r.mul(n,l),d=r.mul(e,d),h=r.sub(f,d),h=r.mul(e,h),h=r.add(h,l),l=r.add(f,f),f=r.add(l,f),f=r.add(f,d),f=r.mul(f,h),A=r.add(A,f),d=r.mul(a,o),d=r.add(d,d),f=r.mul(d,h),c=r.sub(c,f),l=r.mul(d,u),l=r.add(l,l),l=r.add(l,l),new E(c,A,l)}add(e){g(e);const{X:t,Y:n,Z:i}=this,{X:a,Y:o,Z:c}=e;let A=r.ZERO,l=r.ZERO,f=r.ZERO;const u=s.a,d=r.mul(s.b,Yj);let h=r.mul(t,a),p=r.mul(n,o),m=r.mul(i,c),y=r.add(t,n),b=r.add(a,o);y=r.mul(y,b),b=r.add(h,p),y=r.sub(y,b),b=r.add(t,i);let w=r.add(a,c);return b=r.mul(b,w),w=r.add(h,m),b=r.sub(b,w),w=r.add(n,i),A=r.add(o,c),w=r.mul(w,A),A=r.add(p,m),w=r.sub(w,A),f=r.mul(u,b),A=r.mul(d,m),f=r.add(A,f),A=r.sub(p,f),f=r.add(p,f),l=r.mul(A,f),p=r.add(h,h),p=r.add(p,h),m=r.mul(u,m),b=r.mul(d,b),p=r.add(p,m),m=r.sub(h,m),m=r.mul(u,m),b=r.add(b,m),h=r.mul(p,b),l=r.add(l,h),h=r.mul(w,b),A=r.mul(y,A),A=r.sub(A,h),h=r.mul(y,p),f=r.mul(w,f),f=r.add(f,h),new E(A,l,f)}subtract(e){return this.add(e.negate())}is0(){return this.equals(E.ZERO)}multiply(e){const{endo:n}=t;if(!i.isValidNot0(e))throw new Error("invalid scalar: out of range");let r,s;const a=e=>T.cached(this,e,e=>Rj(E,e));if(n){const{k1neg:t,k1:i,k2neg:o,k2:c}=b(e),{p:A,f:l}=a(i),{p:f,f:u}=a(c);s=l.add(u),r=_(n.beta,A,f,t,o)}else{const{p:t,f:n}=a(e);r=t,s=n}return Rj(E,[r,s])[0]}multiplyUnsafe(e){const{endo:n}=t,r=this;if(!i.isValid(e))throw new Error("invalid scalar: out of range");if(e===Jj||r.is0())return E.ZERO;if(e===Kj)return r;if(T.hasCache(this))return this.multiply(e);if(n){const{k1neg:t,k1:i,k2neg:s,k2:a}=b(e),{p1:o,p2:c}=function(e,t,n,r){let i=t,s=e.ZERO,a=e.ZERO;for(;n>Cj||r>Cj;)n&Nj&&(s=s.add(i)),r&Nj&&(a=a.add(i)),i=i.double(),n>>=Nj,r>>=Nj;return{p1:s,p2:a}}(E,r,i,a);return _(n.beta,o,c,t,s)}return T.unsafe(r,e)}multiplyAndAddUnsafe(e,t,n){const r=this.multiplyUnsafe(t).add(e.multiplyUnsafe(n));return r.is0()?void 0:r}toAffine(e){return w(this,e)}isTorsionFree(){const{isTorsionFree:e}=t;return a===Kj||(e?e(E,this):T.unsafe(this,o).is0())}clearCofactor(){const{clearCofactor:e}=t;return a===Kj?this:e?e(E,this):this.multiplyUnsafe(a)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}toBytes(e=!0){return QL(e,"isCompressed"),this.assertValidity(),f(E,this,e)}toHex(e=!0){return Hb(this.toBytes(e))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(e=!0){return this.toBytes(e)}_setWindowSize(e){this.precompute(e)}static normalizeZ(e){return Rj(E,e)}static msm(e,t){return function(e,t,n,r){!function(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}(n,e),function(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}(r,t);const i=n.length,s=r.length;if(i!==s)throw new Error("arrays of points and scalars must have equal length");const a=e.ZERO,o=nj(BigInt(i));let c=1;o>12?c=o-3:o>4?c=o-2:o>0&&(c=2);const A=rj(c),l=new Array(Number(A)+1).fill(a);let f=a;for(let u=Math.floor((t.BITS-1)/c)*c;u>=0;u-=c){l.fill(a);for(let t=0;t<s;t++){const e=r[t],i=Number(e>>BigInt(u)&A);l[i]=l[i].add(n[t])}let e=a;for(let t=l.length-1,n=a;t>0;t--)n=n.add(l[t]),e=e.add(n);if(f=f.add(e),0!==u)for(let t=0;t<c;t++)f=f.double()}return f}(E,i,e,t)}static fromPrivateKey(e){return E.BASE.multiply(Xj(i,e))}}E.BASE=new E(s.Gx,s.Gy,r.ONE),E.ZERO=new E(r.ZERO,r.ONE,r.ZERO),E.Fp=r,E.Fn=i;const k=i.BITS,T=new Lj(E,t.endo?Math.ceil(k/2):k);return E.BASE.precompute(8),E}function tH(e){return Uint8Array.of(e?2:3)}function nH(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function rH(e,t,n={}){$b(t),ij(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||Wb,i=n.hmac||((e,...n)=>HL(t,e,Vb(...n))),{Fp:s,Fn:a}=e,{ORDER:o,BITS:c}=a,{keygen:A,getPublicKey:l,getSharedSecret:f,utils:u,lengths:d}=function(e,t={}){const{Fn:n}=e,r=t.randomBytes||Wb,i=Object.assign(nH(e.Fp,n),{seed:Pj(n.ORDER)});function s(e){try{return!!Xj(n,e)}catch(t){return!1}}function a(e=r(i.seed)){return function(e,t,n=!1){const r=e.length,i=Ij(t),s=Pj(t);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const a=mj(n?YL(e):WL(e),t-oj)+oj;return n?XL(a,i):ZL(a,i)}(VL(e,i.seed,"seed"),n.ORDER)}function o(t,r=!0){return e.BASE.multiply(Xj(n,t)).toBytes(r)}function c(t){if("bigint"==typeof t)return!1;if(t instanceof e)return!0;const{secretKey:r,publicKey:s,publicKeyUncompressed:a}=i;if(n.allowedLengths||r===s)return;const o=ej("key",t).length;return o===s||o===a}const A={isValidSecretKey:s,isValidPublicKey:function(t,n){const{publicKey:r,publicKeyUncompressed:s}=i;try{const i=t.length;return!(!0===n&&i!==r||!1===n&&i!==s||!e.fromBytes(t))}catch(a){return!1}},randomSecretKey:a,isValidPrivateKey:s,randomPrivateKey:a,normPrivateKeyToScalar:e=>Xj(n,e),precompute:(t=8,n=e.BASE)=>n.precompute(t,!1)};return Object.freeze({getPublicKey:o,getSharedSecret:function(t,r,i=!0){if(!0===c(t))throw new Error("first arg must be private key");if(!1===c(r))throw new Error("second arg must be public key");const s=Xj(n,t);return e.fromHex(r).multiply(s).toBytes(i)},keygen:function(e){const t=a(e);return{secretKey:t,publicKey:o(t)}},Point:e,utils:A,lengths:i})}(e,n),h={prehash:!1,lowS:"boolean"==typeof n.lowS&&n.lowS,format:void 0,extraEntropy:!1},p="compact";function m(e){return e>o>>Kj}function y(e,t){if(!a.isValidNot0(t))throw new Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}class g{constructor(e,t,n){this.r=y("r",e),this.s=y("s",t),null!=n&&(this.recovery=n),Object.freeze(this)}static fromBytes(e,t=p){let n;if(function(e,t){zj(t);const n=d.signature;VL(e,"compact"===t?n:"recovered"===t?n+1:void 0,`${t} signature`)}(e,t),"der"===t){const{r:t,s:n}=Vj.toSig(VL(e));return new g(t,n)}"recovered"===t&&(n=e[0],t="compact",e=e.subarray(1));const r=a.BYTES,i=e.subarray(0,r),s=e.subarray(r,2*r);return new g(a.fromBytes(i),a.fromBytes(s),n)}static fromHex(e,t){return this.fromBytes(qb(e),t)}addRecoveryBit(e){return new g(this.r,this.s,e)}recoverPublicKey(t){const n=s.ORDER,{r:r,s:i,recovery:c}=this;if(null==c||![0,1,2,3].includes(c))throw new Error("recovery id invalid");if(o*Wj<n&&c>1)throw new Error("recovery id is ambiguous for h>1 curve");const A=2===c||3===c?r+o:r;if(!s.isValid(A))throw new Error("recovery id 2 or 3 invalid");const l=s.toBytes(A),f=e.fromBytes(Vb(tH(!(1&c)),l)),u=a.inv(A),d=w(ej("msgHash",t)),h=a.create(-d*u),p=a.create(i*u),m=e.BASE.multiplyUnsafe(h).add(f.multiplyUnsafe(p));if(m.is0())throw new Error("point at infinify");return m.assertValidity(),m}hasHighS(){return m(this.s)}toBytes(e=p){if(zj(e),"der"===e)return qb(Vj.hexFromSig(this));const t=a.toBytes(this.r),n=a.toBytes(this.s);if("recovered"===e){if(null==this.recovery)throw new Error("recovery bit must be present");return Vb(Uint8Array.of(this.recovery),t,n)}return Vb(t,n)}toHex(e){return Hb(this.toBytes(e))}assertValidity(){}static fromCompact(e){return g.fromBytes(ej("sig",e),"compact")}static fromDER(e){return g.fromBytes(ej("sig",e),"der")}normalizeS(){return this.hasHighS()?new g(this.r,a.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Hb(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Hb(this.toBytes("compact"))}}const b=n.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const t=WL(e),n=8*e.length-c;return n>0?t>>BigInt(n):t},w=n.bits2int_modN||function(e){return a.create(b(e))},v=rj(c);function _(e){return function(e,t,n,r){if(!function(e,t,n){return tj(e)&&tj(t)&&tj(n)&&t<=e&&e<n}(t,n,r))throw new Error("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}("num < 2^"+c,e,Jj,v),a.toBytes(e)}function E(e,n){return VL(e,void 0,"message"),n?VL(t(e),void 0,"prehashed message"):e}return Object.freeze({keygen:A,getPublicKey:l,getSharedSecret:f,utils:u,lengths:d,Point:e,sign:function(n,s,o={}){n=ej("message",n);const{seed:c,k2sig:A}=function(t,n,i){if(["recovered","canonical"].some(e=>e in i))throw new Error("sign() legacy options not supported");const{lowS:s,prehash:o,extraEntropy:c}=qj(i,h);t=E(t,o);const A=w(t),l=Xj(a,n),f=[_(l),_(A)];if(null!=c&&!1!==c){const e=!0===c?r(d.secretKey):c;f.push(ej("extraEntropy",e))}const u=Vb(...f),p=A;return{seed:u,k2sig:function(t){const n=b(t);if(!a.isValidNot0(n))return;const r=a.inv(n),i=e.BASE.multiply(n).toAffine(),o=a.create(i.x);if(o===Jj)return;const c=a.create(r*a.create(p+o*l));if(c===Jj)return;let A=(i.x===o?0:2)|Number(i.y&Kj),f=c;return s&&m(c)&&(f=a.neg(c),A^=1),new g(o,f,A)}}}(n,s,o);return function(e,t,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");const r=e=>new Uint8Array(e),i=e=>Uint8Array.of(e);let s=r(e),a=r(e),o=0;const c=()=>{s.fill(1),a.fill(0),o=0},A=(...e)=>n(a,s,...e),l=(e=r(0))=>{a=A(i(0),e),s=A(),0!==e.length&&(a=A(i(1),e),s=A())},f=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){s=A();const t=s.slice();n.push(t),e+=s.length}return Vb(...n)};return(e,t)=>{let n;for(c(),l(e);!(n=t(f()));)l();return c(),n}}(t.outputLen,a.BYTES,i)(c,A)},verify:function(t,n,r,i={}){const{lowS:s,prehash:o,format:c}=qj(i,h);if(r=ej("publicKey",r),n=E(ej("message",n),o),"strict"in i)throw new Error("options.strict was renamed to lowS");const A=void 0===c?function(e){let t;const n="string"==typeof e||Rb(e),r=!n&&null!==e&&"object"==typeof e&&"bigint"==typeof e.r&&"bigint"==typeof e.s;if(!n&&!r)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(r)t=new g(e.r,e.s);else if(n){try{t=g.fromBytes(ej("sig",e),"der")}catch(i){if(!(i instanceof Vj.Err))throw i}if(!t)try{t=g.fromBytes(ej("sig",e),"compact")}catch(s){return!1}}return t||!1}(t):g.fromBytes(ej("sig",t),c);if(!1===A)return!1;try{const t=e.fromBytes(r);if(s&&A.hasHighS())return!1;const{r:i,s:o}=A,c=w(n),l=a.inv(o),f=a.create(c*l),u=a.create(i*l),d=e.BASE.multiplyUnsafe(f).add(t.multiplyUnsafe(u));return!d.is0()&&a.create(d.x)===i}catch(l){return!1}},recoverPublicKey:function(e,t,n={}){const{prehash:r}=qj(n,h);return t=E(t,r),g.fromBytes(e,"recovered").recoverPublicKey(t).toBytes()},Signature:g,hash:t})}function iH(e){const{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:i}=function(e){const{CURVE:t,curveOpts:n}=function(e){const t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp;let r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(e=>Math.ceil(e/2)))):void 0;return{CURVE:t,curveOpts:{Fp:n,Fn:xj(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}(e),r={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:n,hash:e.hash,ecdsaOpts:r}}(e);return function(e,t){const n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,Sj(n.Fn.ORDER,n.Fn.BITS))})}(e,rH(eH(t,n),r,i))}
52
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
53
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
54
+ const sH={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},aH={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},oH=BigInt(2),cH=xj(sH.p,{sqrt:function(e){const t=sH.p,n=BigInt(3),r=BigInt(6),i=BigInt(11),s=BigInt(22),a=BigInt(23),o=BigInt(44),c=BigInt(88),A=e*e*e%t,l=A*A*e%t,f=yj(l,n,t)*l%t,u=yj(f,n,t)*l%t,d=yj(u,oH,t)*A%t,h=yj(d,i,t)*d%t,p=yj(h,s,t)*h%t,m=yj(p,o,t)*p%t,y=yj(m,c,t)*m%t,g=yj(y,o,t)*p%t,b=yj(g,n,t)*l%t,w=yj(b,a,t)*h%t,v=yj(w,r,t)*A%t,_=yj(v,oH,t);if(!cH.eql(cH.sqr(_),e))throw new Error("Cannot find square root");return _}}),AH=function(e,t){const n=t=>iH({...e,hash:t});return{...n(t),create:n}}({...sH,Fp:cH,lowS:!0,endo:aH},iw),lH=Object.freeze(Object.defineProperty({__proto__:null,secp256k1:AH},Symbol.toStringTag,{value:"Module"}));return EU}();
55
+ //# sourceMappingURL=holosphere.min.js.map