@xyo-network/os-runtime 7.4.0 → 7.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (551) hide show
  1. package/dist/neutral/Caller.d.ts +68 -0
  2. package/dist/neutral/Caller.d.ts.map +1 -0
  3. package/dist/neutral/DappCallerBase.d.ts +23 -0
  4. package/dist/neutral/DappCallerBase.d.ts.map +1 -0
  5. package/dist/neutral/DefaultsQueries.d.ts +8 -0
  6. package/dist/neutral/DefaultsQueries.d.ts.map +1 -0
  7. package/dist/neutral/OsCallerBase.d.ts +16 -0
  8. package/dist/neutral/OsCallerBase.d.ts.map +1 -0
  9. package/dist/neutral/PubSubBridgeCaller.d.ts +11 -0
  10. package/dist/neutral/PubSubBridgeCaller.d.ts.map +1 -0
  11. package/dist/neutral/RunningDappCache.d.ts +12 -0
  12. package/dist/neutral/RunningDappCache.d.ts.map +1 -0
  13. package/dist/neutral/XyOs.d.ts +48 -0
  14. package/dist/neutral/XyOs.d.ts.map +1 -0
  15. package/dist/neutral/XyOsBase.d.ts +170 -0
  16. package/dist/neutral/XyOsBase.d.ts.map +1 -0
  17. package/dist/neutral/XyOsDapp.d.ts +33 -0
  18. package/dist/neutral/XyOsDapp.d.ts.map +1 -0
  19. package/dist/neutral/access/Caller.d.ts +23 -0
  20. package/dist/neutral/access/Caller.d.ts.map +1 -0
  21. package/dist/neutral/access/Queries.d.ts +8 -0
  22. package/dist/neutral/access/Queries.d.ts.map +1 -0
  23. package/dist/neutral/access/Resource.d.ts +23 -0
  24. package/dist/neutral/access/Resource.d.ts.map +1 -0
  25. package/dist/neutral/access/RunningAccessDappCache.d.ts +12 -0
  26. package/dist/neutral/access/RunningAccessDappCache.d.ts.map +1 -0
  27. package/dist/neutral/access/index.d.ts +5 -0
  28. package/dist/neutral/access/index.d.ts.map +1 -0
  29. package/dist/neutral/access/interfaces/index.d.ts +2 -0
  30. package/dist/neutral/access/interfaces/index.d.ts.map +1 -0
  31. package/dist/neutral/access/interfaces/registered-names/helpers/AccessNodeQueries.d.ts +16 -0
  32. package/dist/neutral/access/interfaces/registered-names/helpers/AccessNodeQueries.d.ts.map +1 -0
  33. package/dist/neutral/access/interfaces/registered-names/helpers/index.d.ts +3 -0
  34. package/dist/neutral/access/interfaces/registered-names/helpers/index.d.ts.map +1 -0
  35. package/dist/neutral/access/interfaces/registered-names/helpers/resource/AbstractXnsCaller.d.ts +21 -0
  36. package/dist/neutral/access/interfaces/registered-names/helpers/resource/AbstractXnsCaller.d.ts.map +1 -0
  37. package/dist/neutral/access/interfaces/registered-names/helpers/resource/RegistrationsResource.d.ts +22 -0
  38. package/dist/neutral/access/interfaces/registered-names/helpers/resource/RegistrationsResource.d.ts.map +1 -0
  39. package/dist/neutral/access/interfaces/registered-names/helpers/resource/RegistrationsResourceQueries.d.ts +9 -0
  40. package/dist/neutral/access/interfaces/registered-names/helpers/resource/RegistrationsResourceQueries.d.ts.map +1 -0
  41. package/dist/neutral/access/interfaces/registered-names/helpers/resource/index.d.ts +4 -0
  42. package/dist/neutral/access/interfaces/registered-names/helpers/resource/index.d.ts.map +1 -0
  43. package/dist/neutral/access/interfaces/registered-names/index.d.ts +2 -0
  44. package/dist/neutral/access/interfaces/registered-names/index.d.ts.map +1 -0
  45. package/dist/neutral/adapter/Base.d.ts +17 -0
  46. package/dist/neutral/adapter/Base.d.ts.map +1 -0
  47. package/dist/neutral/adapter/Network.d.ts +15 -0
  48. package/dist/neutral/adapter/Network.d.ts.map +1 -0
  49. package/dist/neutral/adapter/Settings.d.ts +14 -0
  50. package/dist/neutral/adapter/Settings.d.ts.map +1 -0
  51. package/dist/neutral/adapter/index.d.ts +3 -0
  52. package/dist/neutral/adapter/index.d.ts.map +1 -0
  53. package/dist/neutral/adapters/OsPubSubBridgeNetwork.d.ts +3 -0
  54. package/dist/neutral/adapters/OsPubSubBridgeNetwork.d.ts.map +1 -0
  55. package/dist/neutral/adapters/OsSettings.d.ts +3 -0
  56. package/dist/neutral/adapters/OsSettings.d.ts.map +1 -0
  57. package/dist/neutral/adapters/OsXyoPublicNetwork.d.ts +3 -0
  58. package/dist/neutral/adapters/OsXyoPublicNetwork.d.ts.map +1 -0
  59. package/dist/neutral/adapters/index.d.ts +4 -0
  60. package/dist/neutral/adapters/index.d.ts.map +1 -0
  61. package/dist/neutral/classes/dapp/DefaultsResource.d.ts +26 -0
  62. package/dist/neutral/classes/dapp/DefaultsResource.d.ts.map +1 -0
  63. package/dist/neutral/classes/dapp/index.d.ts +2 -0
  64. package/dist/neutral/classes/dapp/index.d.ts.map +1 -0
  65. package/dist/neutral/classes/index.d.ts +5 -0
  66. package/dist/neutral/classes/index.d.ts.map +1 -0
  67. package/dist/neutral/classes/lib/DappCreatorParams.d.ts +16 -0
  68. package/dist/neutral/classes/lib/DappCreatorParams.d.ts.map +1 -0
  69. package/dist/neutral/classes/lib/Insertable.d.ts +10 -0
  70. package/dist/neutral/classes/lib/Insertable.d.ts.map +1 -0
  71. package/dist/neutral/classes/lib/index.d.ts +3 -0
  72. package/dist/neutral/classes/lib/index.d.ts.map +1 -0
  73. package/dist/neutral/classes/menu/Caller.d.ts +14 -0
  74. package/dist/neutral/classes/menu/Caller.d.ts.map +1 -0
  75. package/dist/neutral/classes/menu/Queries.d.ts +10 -0
  76. package/dist/neutral/classes/menu/Queries.d.ts.map +1 -0
  77. package/dist/neutral/classes/menu/Resource.d.ts +46 -0
  78. package/dist/neutral/classes/menu/Resource.d.ts.map +1 -0
  79. package/dist/neutral/classes/menu/index.d.ts +3 -0
  80. package/dist/neutral/classes/menu/index.d.ts.map +1 -0
  81. package/dist/neutral/classes/settings/Caller.d.ts +21 -0
  82. package/dist/neutral/classes/settings/Caller.d.ts.map +1 -0
  83. package/dist/neutral/classes/settings/CallerBase.d.ts +8 -0
  84. package/dist/neutral/classes/settings/CallerBase.d.ts.map +1 -0
  85. package/dist/neutral/classes/settings/Resource.d.ts +30 -0
  86. package/dist/neutral/classes/settings/Resource.d.ts.map +1 -0
  87. package/dist/neutral/classes/settings/SettingsQueries.d.ts +10 -0
  88. package/dist/neutral/classes/settings/SettingsQueries.d.ts.map +1 -0
  89. package/dist/neutral/classes/settings/badge/Caller.d.ts +13 -0
  90. package/dist/neutral/classes/settings/badge/Caller.d.ts.map +1 -0
  91. package/dist/neutral/classes/settings/badge/Queries.d.ts +7 -0
  92. package/dist/neutral/classes/settings/badge/Queries.d.ts.map +1 -0
  93. package/dist/neutral/classes/settings/badge/Resource.d.ts +23 -0
  94. package/dist/neutral/classes/settings/badge/Resource.d.ts.map +1 -0
  95. package/dist/neutral/classes/settings/badge/index.d.ts +3 -0
  96. package/dist/neutral/classes/settings/badge/index.d.ts.map +1 -0
  97. package/dist/neutral/classes/settings/index.d.ts +6 -0
  98. package/dist/neutral/classes/settings/index.d.ts.map +1 -0
  99. package/dist/neutral/dapp/context/creator/Creator.d.ts +23 -0
  100. package/dist/neutral/dapp/context/creator/Creator.d.ts.map +1 -0
  101. package/dist/neutral/dapp/context/creator/DefaultPayloads/DappAccessPayloads.d.ts +8 -0
  102. package/dist/neutral/dapp/context/creator/DefaultPayloads/DappAccessPayloads.d.ts.map +1 -0
  103. package/dist/neutral/dapp/context/creator/DefaultPayloads/DefaultPayloads.d.ts +10 -0
  104. package/dist/neutral/dapp/context/creator/DefaultPayloads/DefaultPayloads.d.ts.map +1 -0
  105. package/dist/neutral/dapp/context/creator/DefaultPayloads/NodeInfoPayload.d.ts +8 -0
  106. package/dist/neutral/dapp/context/creator/DefaultPayloads/NodeInfoPayload.d.ts.map +1 -0
  107. package/dist/neutral/dapp/context/creator/DefaultPayloads/index.d.ts +2 -0
  108. package/dist/neutral/dapp/context/creator/DefaultPayloads/index.d.ts.map +1 -0
  109. package/dist/neutral/dapp/context/creator/ExternalModulePermissions/ExternalModulePermissions.d.ts +15 -0
  110. package/dist/neutral/dapp/context/creator/ExternalModulePermissions/ExternalModulePermissions.d.ts.map +1 -0
  111. package/dist/neutral/dapp/context/creator/ExternalModulePermissions/index.d.ts +2 -0
  112. package/dist/neutral/dapp/context/creator/ExternalModulePermissions/index.d.ts.map +1 -0
  113. package/dist/neutral/dapp/context/creator/createDappContext.d.ts +3 -0
  114. package/dist/neutral/dapp/context/creator/createDappContext.d.ts.map +1 -0
  115. package/dist/neutral/dapp/context/creator/index.d.ts +4 -0
  116. package/dist/neutral/dapp/context/creator/index.d.ts.map +1 -0
  117. package/dist/neutral/dapp/context/index.d.ts +2 -0
  118. package/dist/neutral/dapp/context/index.d.ts.map +1 -0
  119. package/dist/neutral/dapp/index.d.ts +2 -0
  120. package/dist/neutral/dapp/index.d.ts.map +1 -0
  121. package/dist/neutral/event/bus/Connection.d.ts +16 -0
  122. package/dist/neutral/event/bus/Connection.d.ts.map +1 -0
  123. package/dist/neutral/event/bus/EventBus.d.ts +24 -0
  124. package/dist/neutral/event/bus/EventBus.d.ts.map +1 -0
  125. package/dist/neutral/event/bus/PubSubConnection.d.ts +12 -0
  126. package/dist/neutral/event/bus/PubSubConnection.d.ts.map +1 -0
  127. package/dist/neutral/event/bus/index.d.ts +4 -0
  128. package/dist/neutral/event/bus/index.d.ts.map +1 -0
  129. package/dist/neutral/event/connections/DappAccessRequest.d.ts +4 -0
  130. package/dist/neutral/event/connections/DappAccessRequest.d.ts.map +1 -0
  131. package/dist/neutral/event/connections/DappsReady.d.ts +3 -0
  132. package/dist/neutral/event/connections/DappsReady.d.ts.map +1 -0
  133. package/dist/neutral/event/connections/ExposeDappRequest.d.ts +4 -0
  134. package/dist/neutral/event/connections/ExposeDappRequest.d.ts.map +1 -0
  135. package/dist/neutral/event/connections/OsPubSubNetworkReady.d.ts +4 -0
  136. package/dist/neutral/event/connections/OsPubSubNetworkReady.d.ts.map +1 -0
  137. package/dist/neutral/event/connections/OsSettingsReady.d.ts +4 -0
  138. package/dist/neutral/event/connections/OsSettingsReady.d.ts.map +1 -0
  139. package/dist/neutral/event/connections/OsXyoPublicReady.d.ts +4 -0
  140. package/dist/neutral/event/connections/OsXyoPublicReady.d.ts.map +1 -0
  141. package/dist/neutral/event/connections/index.d.ts +7 -0
  142. package/dist/neutral/event/connections/index.d.ts.map +1 -0
  143. package/dist/neutral/event/index.d.ts +3 -0
  144. package/dist/neutral/event/index.d.ts.map +1 -0
  145. package/dist/neutral/helpers/index.d.ts +2 -0
  146. package/dist/neutral/helpers/index.d.ts.map +1 -0
  147. package/dist/neutral/helpers/monitor/XyOsMonitor.d.ts +14 -0
  148. package/dist/neutral/helpers/monitor/XyOsMonitor.d.ts.map +1 -0
  149. package/dist/neutral/helpers/monitor/index.d.ts +3 -0
  150. package/dist/neutral/helpers/monitor/index.d.ts.map +1 -0
  151. package/dist/neutral/helpers/monitor/types.d.ts +7 -0
  152. package/dist/neutral/helpers/monitor/types.d.ts.map +1 -0
  153. package/dist/neutral/index.d.ts +30 -0
  154. package/dist/neutral/index.d.ts.map +1 -0
  155. package/dist/neutral/index.mjs +3660 -0
  156. package/dist/neutral/index.mjs.map +7 -0
  157. package/dist/neutral/initializer/DappInitializer.d.ts +18 -0
  158. package/dist/neutral/initializer/DappInitializer.d.ts.map +1 -0
  159. package/dist/neutral/initializer/index.d.ts +2 -0
  160. package/dist/neutral/initializer/index.d.ts.map +1 -0
  161. package/dist/neutral/intent/Caller.d.ts +23 -0
  162. package/dist/neutral/intent/Caller.d.ts.map +1 -0
  163. package/dist/neutral/intent/Resource.d.ts +23 -0
  164. package/dist/neutral/intent/Resource.d.ts.map +1 -0
  165. package/dist/neutral/intent/index.d.ts +3 -0
  166. package/dist/neutral/intent/index.d.ts.map +1 -0
  167. package/dist/neutral/lib/ExternalStore.d.ts +7 -0
  168. package/dist/neutral/lib/ExternalStore.d.ts.map +1 -0
  169. package/dist/neutral/lib/Listener.d.ts +2 -0
  170. package/dist/neutral/lib/Listener.d.ts.map +1 -0
  171. package/dist/neutral/lib/ModuleAccountPaths.d.ts +3 -0
  172. package/dist/neutral/lib/ModuleAccountPaths.d.ts.map +1 -0
  173. package/dist/neutral/lib/ModuleNames.d.ts +3 -0
  174. package/dist/neutral/lib/ModuleNames.d.ts.map +1 -0
  175. package/dist/neutral/lib/NameTransforms.d.ts +11 -0
  176. package/dist/neutral/lib/NameTransforms.d.ts.map +1 -0
  177. package/dist/neutral/lib/PayloadStore.d.ts +37 -0
  178. package/dist/neutral/lib/PayloadStore.d.ts.map +1 -0
  179. package/dist/neutral/lib/ResourceStores.d.ts +7 -0
  180. package/dist/neutral/lib/ResourceStores.d.ts.map +1 -0
  181. package/dist/neutral/lib/index.d.ts +12 -0
  182. package/dist/neutral/lib/index.d.ts.map +1 -0
  183. package/dist/neutral/lib/initializeXns.d.ts +3 -0
  184. package/dist/neutral/lib/initializeXns.d.ts.map +1 -0
  185. package/dist/neutral/lib/isEqual.d.ts +2 -0
  186. package/dist/neutral/lib/isEqual.d.ts.map +1 -0
  187. package/dist/neutral/lib/isPayload.d.ts +6 -0
  188. package/dist/neutral/lib/isPayload.d.ts.map +1 -0
  189. package/dist/neutral/lib/tokenPlacesSplit.d.ts +3 -0
  190. package/dist/neutral/lib/tokenPlacesSplit.d.ts.map +1 -0
  191. package/dist/neutral/loadOsNode.d.ts +5 -0
  192. package/dist/neutral/loadOsNode.d.ts.map +1 -0
  193. package/dist/neutral/manifest/index.d.ts +3 -0
  194. package/dist/neutral/manifest/index.d.ts.map +1 -0
  195. package/dist/neutral/manifest/manifestReplacementTokens.d.ts +4 -0
  196. package/dist/neutral/manifest/manifestReplacementTokens.d.ts.map +1 -0
  197. package/dist/neutral/manifests/index.d.ts +2 -0
  198. package/dist/neutral/manifests/index.d.ts.map +1 -0
  199. package/dist/neutral/models/access/ValidDappAccessInterfaces.d.ts +5 -0
  200. package/dist/neutral/models/access/ValidDappAccessInterfaces.d.ts.map +1 -0
  201. package/dist/neutral/models/access/index.d.ts +2 -0
  202. package/dist/neutral/models/access/index.d.ts.map +1 -0
  203. package/dist/neutral/models/index.d.ts +2 -0
  204. package/dist/neutral/models/index.d.ts.map +1 -0
  205. package/dist/neutral/profileModuleEvents.d.ts +9 -0
  206. package/dist/neutral/profileModuleEvents.d.ts.map +1 -0
  207. package/dist/neutral/registration/DappRegistrationService.d.ts +37 -0
  208. package/dist/neutral/registration/DappRegistrationService.d.ts.map +1 -0
  209. package/dist/neutral/registration/DappRegistry.d.ts +26 -0
  210. package/dist/neutral/registration/DappRegistry.d.ts.map +1 -0
  211. package/dist/neutral/registration/ValidateDappAccessDiviner/Config.d.ts +23 -0
  212. package/dist/neutral/registration/ValidateDappAccessDiviner/Config.d.ts.map +1 -0
  213. package/dist/neutral/registration/ValidateDappAccessDiviner/Diviner.d.ts +9 -0
  214. package/dist/neutral/registration/ValidateDappAccessDiviner/Diviner.d.ts.map +1 -0
  215. package/dist/neutral/registration/ValidateDappAccessDiviner/index.d.ts +3 -0
  216. package/dist/neutral/registration/ValidateDappAccessDiviner/index.d.ts.map +1 -0
  217. package/dist/neutral/registration/index.d.ts +3 -0
  218. package/dist/neutral/registration/index.d.ts.map +1 -0
  219. package/dist/neutral/scripts/xyos/command/config.d.ts +3 -0
  220. package/dist/neutral/scripts/xyos/command/config.d.ts.map +1 -0
  221. package/dist/neutral/scripts/xyos/command/create.d.ts +3 -0
  222. package/dist/neutral/scripts/xyos/command/create.d.ts.map +1 -0
  223. package/dist/neutral/scripts/xyos/command/index.d.ts +6 -0
  224. package/dist/neutral/scripts/xyos/command/index.d.ts.map +1 -0
  225. package/dist/neutral/scripts/xyos/command/manifest.d.ts +3 -0
  226. package/dist/neutral/scripts/xyos/command/manifest.d.ts.map +1 -0
  227. package/dist/neutral/scripts/xyos/command/start.d.ts +3 -0
  228. package/dist/neutral/scripts/xyos/command/start.d.ts.map +1 -0
  229. package/dist/neutral/scripts/xyos/index.d.ts +2 -0
  230. package/dist/neutral/scripts/xyos/index.d.ts.map +1 -0
  231. package/dist/neutral/scripts/xyos/lib/createFromTemplate.d.ts +7 -0
  232. package/dist/neutral/scripts/xyos/lib/createFromTemplate.d.ts.map +1 -0
  233. package/dist/neutral/scripts/xyos/lib/headless.d.ts +8 -0
  234. package/dist/neutral/scripts/xyos/lib/headless.d.ts.map +1 -0
  235. package/dist/neutral/scripts/xyos/lib/index.d.ts +3 -0
  236. package/dist/neutral/scripts/xyos/lib/index.d.ts.map +1 -0
  237. package/dist/neutral/signer/Signers.d.ts +17 -0
  238. package/dist/neutral/signer/Signers.d.ts.map +1 -0
  239. package/dist/neutral/signer/index.d.ts +2 -0
  240. package/dist/neutral/signer/index.d.ts.map +1 -0
  241. package/dist/neutral/stack/Base.d.ts +41 -0
  242. package/dist/neutral/stack/Base.d.ts.map +1 -0
  243. package/dist/neutral/stack/Manager.d.ts +19 -0
  244. package/dist/neutral/stack/Manager.d.ts.map +1 -0
  245. package/dist/neutral/stack/Map.d.ts +3 -0
  246. package/dist/neutral/stack/Map.d.ts.map +1 -0
  247. package/dist/neutral/stack/OsPubSubNetworkStack.d.ts +14 -0
  248. package/dist/neutral/stack/OsPubSubNetworkStack.d.ts.map +1 -0
  249. package/dist/neutral/stack/OsSettingsStack.d.ts +9 -0
  250. package/dist/neutral/stack/OsSettingsStack.d.ts.map +1 -0
  251. package/dist/neutral/stack/XyoPublicNetworkStack.d.ts +9 -0
  252. package/dist/neutral/stack/XyoPublicNetworkStack.d.ts.map +1 -0
  253. package/dist/neutral/stack/index.d.ts +7 -0
  254. package/dist/neutral/stack/index.d.ts.map +1 -0
  255. package/dist/neutral/system/ManageSystemDapps.d.ts +33 -0
  256. package/dist/neutral/system/ManageSystemDapps.d.ts.map +1 -0
  257. package/dist/neutral/system/Queries.d.ts +9 -0
  258. package/dist/neutral/system/Queries.d.ts.map +1 -0
  259. package/dist/neutral/system/index.d.ts +2 -0
  260. package/dist/neutral/system/index.d.ts.map +1 -0
  261. package/dist/neutral/utils/buildWalletSeedPhrasePayload.d.ts +30 -0
  262. package/dist/neutral/utils/buildWalletSeedPhrasePayload.d.ts.map +1 -0
  263. package/dist/neutral/utils/getApiDomain.d.ts +3 -0
  264. package/dist/neutral/utils/getApiDomain.d.ts.map +1 -0
  265. package/dist/neutral/utils/index.d.ts +4 -0
  266. package/dist/neutral/utils/index.d.ts.map +1 -0
  267. package/dist/neutral/utils/renameObjKey.d.ts +7 -0
  268. package/dist/neutral/utils/renameObjKey.d.ts.map +1 -0
  269. package/dist/neutral/wallet/DappSeedPhraseRepository.d.ts +16 -0
  270. package/dist/neutral/wallet/DappSeedPhraseRepository.d.ts.map +1 -0
  271. package/dist/neutral/wallet/SeedPhraseRepository.d.ts +28 -0
  272. package/dist/neutral/wallet/SeedPhraseRepository.d.ts.map +1 -0
  273. package/dist/neutral/wallet/index.d.ts +3 -0
  274. package/dist/neutral/wallet/index.d.ts.map +1 -0
  275. package/dist/node/Caller.d.ts +68 -0
  276. package/dist/node/Caller.d.ts.map +1 -0
  277. package/dist/node/DappCallerBase.d.ts +23 -0
  278. package/dist/node/DappCallerBase.d.ts.map +1 -0
  279. package/dist/node/DefaultsQueries.d.ts +8 -0
  280. package/dist/node/DefaultsQueries.d.ts.map +1 -0
  281. package/dist/node/OsCallerBase.d.ts +16 -0
  282. package/dist/node/OsCallerBase.d.ts.map +1 -0
  283. package/dist/node/PubSubBridgeCaller.d.ts +11 -0
  284. package/dist/node/PubSubBridgeCaller.d.ts.map +1 -0
  285. package/dist/node/RunningDappCache.d.ts +12 -0
  286. package/dist/node/RunningDappCache.d.ts.map +1 -0
  287. package/dist/node/XyOs.d.ts +48 -0
  288. package/dist/node/XyOs.d.ts.map +1 -0
  289. package/dist/node/XyOsBase.d.ts +170 -0
  290. package/dist/node/XyOsBase.d.ts.map +1 -0
  291. package/dist/node/XyOsDapp.d.ts +33 -0
  292. package/dist/node/XyOsDapp.d.ts.map +1 -0
  293. package/dist/node/access/Caller.d.ts +23 -0
  294. package/dist/node/access/Caller.d.ts.map +1 -0
  295. package/dist/node/access/Queries.d.ts +8 -0
  296. package/dist/node/access/Queries.d.ts.map +1 -0
  297. package/dist/node/access/Resource.d.ts +23 -0
  298. package/dist/node/access/Resource.d.ts.map +1 -0
  299. package/dist/node/access/RunningAccessDappCache.d.ts +12 -0
  300. package/dist/node/access/RunningAccessDappCache.d.ts.map +1 -0
  301. package/dist/node/access/index.d.ts +5 -0
  302. package/dist/node/access/index.d.ts.map +1 -0
  303. package/dist/node/access/interfaces/index.d.ts +2 -0
  304. package/dist/node/access/interfaces/index.d.ts.map +1 -0
  305. package/dist/node/access/interfaces/registered-names/helpers/AccessNodeQueries.d.ts +16 -0
  306. package/dist/node/access/interfaces/registered-names/helpers/AccessNodeQueries.d.ts.map +1 -0
  307. package/dist/node/access/interfaces/registered-names/helpers/index.d.ts +3 -0
  308. package/dist/node/access/interfaces/registered-names/helpers/index.d.ts.map +1 -0
  309. package/dist/node/access/interfaces/registered-names/helpers/resource/AbstractXnsCaller.d.ts +21 -0
  310. package/dist/node/access/interfaces/registered-names/helpers/resource/AbstractXnsCaller.d.ts.map +1 -0
  311. package/dist/node/access/interfaces/registered-names/helpers/resource/RegistrationsResource.d.ts +22 -0
  312. package/dist/node/access/interfaces/registered-names/helpers/resource/RegistrationsResource.d.ts.map +1 -0
  313. package/dist/node/access/interfaces/registered-names/helpers/resource/RegistrationsResourceQueries.d.ts +9 -0
  314. package/dist/node/access/interfaces/registered-names/helpers/resource/RegistrationsResourceQueries.d.ts.map +1 -0
  315. package/dist/node/access/interfaces/registered-names/helpers/resource/index.d.ts +4 -0
  316. package/dist/node/access/interfaces/registered-names/helpers/resource/index.d.ts.map +1 -0
  317. package/dist/node/access/interfaces/registered-names/index.d.ts +2 -0
  318. package/dist/node/access/interfaces/registered-names/index.d.ts.map +1 -0
  319. package/dist/node/adapter/Base.d.ts +17 -0
  320. package/dist/node/adapter/Base.d.ts.map +1 -0
  321. package/dist/node/adapter/Network.d.ts +15 -0
  322. package/dist/node/adapter/Network.d.ts.map +1 -0
  323. package/dist/node/adapter/Settings.d.ts +14 -0
  324. package/dist/node/adapter/Settings.d.ts.map +1 -0
  325. package/dist/node/adapter/index.d.ts +3 -0
  326. package/dist/node/adapter/index.d.ts.map +1 -0
  327. package/dist/node/adapters/OsPubSubBridgeNetwork.d.ts +3 -0
  328. package/dist/node/adapters/OsPubSubBridgeNetwork.d.ts.map +1 -0
  329. package/dist/node/adapters/OsSettings.d.ts +3 -0
  330. package/dist/node/adapters/OsSettings.d.ts.map +1 -0
  331. package/dist/node/adapters/OsXyoPublicNetwork.d.ts +3 -0
  332. package/dist/node/adapters/OsXyoPublicNetwork.d.ts.map +1 -0
  333. package/dist/node/adapters/index.d.ts +4 -0
  334. package/dist/node/adapters/index.d.ts.map +1 -0
  335. package/dist/node/classes/dapp/DefaultsResource.d.ts +26 -0
  336. package/dist/node/classes/dapp/DefaultsResource.d.ts.map +1 -0
  337. package/dist/node/classes/dapp/index.d.ts +2 -0
  338. package/dist/node/classes/dapp/index.d.ts.map +1 -0
  339. package/dist/node/classes/index.d.ts +5 -0
  340. package/dist/node/classes/index.d.ts.map +1 -0
  341. package/dist/node/classes/lib/DappCreatorParams.d.ts +16 -0
  342. package/dist/node/classes/lib/DappCreatorParams.d.ts.map +1 -0
  343. package/dist/node/classes/lib/Insertable.d.ts +10 -0
  344. package/dist/node/classes/lib/Insertable.d.ts.map +1 -0
  345. package/dist/node/classes/lib/index.d.ts +3 -0
  346. package/dist/node/classes/lib/index.d.ts.map +1 -0
  347. package/dist/node/classes/menu/Caller.d.ts +14 -0
  348. package/dist/node/classes/menu/Caller.d.ts.map +1 -0
  349. package/dist/node/classes/menu/Queries.d.ts +10 -0
  350. package/dist/node/classes/menu/Queries.d.ts.map +1 -0
  351. package/dist/node/classes/menu/Resource.d.ts +46 -0
  352. package/dist/node/classes/menu/Resource.d.ts.map +1 -0
  353. package/dist/node/classes/menu/index.d.ts +3 -0
  354. package/dist/node/classes/menu/index.d.ts.map +1 -0
  355. package/dist/node/classes/settings/Caller.d.ts +21 -0
  356. package/dist/node/classes/settings/Caller.d.ts.map +1 -0
  357. package/dist/node/classes/settings/CallerBase.d.ts +8 -0
  358. package/dist/node/classes/settings/CallerBase.d.ts.map +1 -0
  359. package/dist/node/classes/settings/Resource.d.ts +30 -0
  360. package/dist/node/classes/settings/Resource.d.ts.map +1 -0
  361. package/dist/node/classes/settings/SettingsQueries.d.ts +10 -0
  362. package/dist/node/classes/settings/SettingsQueries.d.ts.map +1 -0
  363. package/dist/node/classes/settings/badge/Caller.d.ts +13 -0
  364. package/dist/node/classes/settings/badge/Caller.d.ts.map +1 -0
  365. package/dist/node/classes/settings/badge/Queries.d.ts +7 -0
  366. package/dist/node/classes/settings/badge/Queries.d.ts.map +1 -0
  367. package/dist/node/classes/settings/badge/Resource.d.ts +23 -0
  368. package/dist/node/classes/settings/badge/Resource.d.ts.map +1 -0
  369. package/dist/node/classes/settings/badge/index.d.ts +3 -0
  370. package/dist/node/classes/settings/badge/index.d.ts.map +1 -0
  371. package/dist/node/classes/settings/index.d.ts +6 -0
  372. package/dist/node/classes/settings/index.d.ts.map +1 -0
  373. package/dist/node/dapp/context/creator/Creator.d.ts +23 -0
  374. package/dist/node/dapp/context/creator/Creator.d.ts.map +1 -0
  375. package/dist/node/dapp/context/creator/DefaultPayloads/DappAccessPayloads.d.ts +8 -0
  376. package/dist/node/dapp/context/creator/DefaultPayloads/DappAccessPayloads.d.ts.map +1 -0
  377. package/dist/node/dapp/context/creator/DefaultPayloads/DefaultPayloads.d.ts +10 -0
  378. package/dist/node/dapp/context/creator/DefaultPayloads/DefaultPayloads.d.ts.map +1 -0
  379. package/dist/node/dapp/context/creator/DefaultPayloads/NodeInfoPayload.d.ts +8 -0
  380. package/dist/node/dapp/context/creator/DefaultPayloads/NodeInfoPayload.d.ts.map +1 -0
  381. package/dist/node/dapp/context/creator/DefaultPayloads/index.d.ts +2 -0
  382. package/dist/node/dapp/context/creator/DefaultPayloads/index.d.ts.map +1 -0
  383. package/dist/node/dapp/context/creator/ExternalModulePermissions/ExternalModulePermissions.d.ts +15 -0
  384. package/dist/node/dapp/context/creator/ExternalModulePermissions/ExternalModulePermissions.d.ts.map +1 -0
  385. package/dist/node/dapp/context/creator/ExternalModulePermissions/index.d.ts +2 -0
  386. package/dist/node/dapp/context/creator/ExternalModulePermissions/index.d.ts.map +1 -0
  387. package/dist/node/dapp/context/creator/createDappContext.d.ts +3 -0
  388. package/dist/node/dapp/context/creator/createDappContext.d.ts.map +1 -0
  389. package/dist/node/dapp/context/creator/index.d.ts +4 -0
  390. package/dist/node/dapp/context/creator/index.d.ts.map +1 -0
  391. package/dist/node/dapp/context/index.d.ts +2 -0
  392. package/dist/node/dapp/context/index.d.ts.map +1 -0
  393. package/dist/node/dapp/index.d.ts +2 -0
  394. package/dist/node/dapp/index.d.ts.map +1 -0
  395. package/dist/node/event/bus/Connection.d.ts +16 -0
  396. package/dist/node/event/bus/Connection.d.ts.map +1 -0
  397. package/dist/node/event/bus/EventBus.d.ts +24 -0
  398. package/dist/node/event/bus/EventBus.d.ts.map +1 -0
  399. package/dist/node/event/bus/PubSubConnection.d.ts +12 -0
  400. package/dist/node/event/bus/PubSubConnection.d.ts.map +1 -0
  401. package/dist/node/event/bus/index.d.ts +4 -0
  402. package/dist/node/event/bus/index.d.ts.map +1 -0
  403. package/dist/node/event/connections/DappAccessRequest.d.ts +4 -0
  404. package/dist/node/event/connections/DappAccessRequest.d.ts.map +1 -0
  405. package/dist/node/event/connections/DappsReady.d.ts +3 -0
  406. package/dist/node/event/connections/DappsReady.d.ts.map +1 -0
  407. package/dist/node/event/connections/ExposeDappRequest.d.ts +4 -0
  408. package/dist/node/event/connections/ExposeDappRequest.d.ts.map +1 -0
  409. package/dist/node/event/connections/OsPubSubNetworkReady.d.ts +4 -0
  410. package/dist/node/event/connections/OsPubSubNetworkReady.d.ts.map +1 -0
  411. package/dist/node/event/connections/OsSettingsReady.d.ts +4 -0
  412. package/dist/node/event/connections/OsSettingsReady.d.ts.map +1 -0
  413. package/dist/node/event/connections/OsXyoPublicReady.d.ts +4 -0
  414. package/dist/node/event/connections/OsXyoPublicReady.d.ts.map +1 -0
  415. package/dist/node/event/connections/index.d.ts +7 -0
  416. package/dist/node/event/connections/index.d.ts.map +1 -0
  417. package/dist/node/event/index.d.ts +3 -0
  418. package/dist/node/event/index.d.ts.map +1 -0
  419. package/dist/node/helpers/index.d.ts +2 -0
  420. package/dist/node/helpers/index.d.ts.map +1 -0
  421. package/dist/node/helpers/monitor/XyOsMonitor.d.ts +14 -0
  422. package/dist/node/helpers/monitor/XyOsMonitor.d.ts.map +1 -0
  423. package/dist/node/helpers/monitor/index.d.ts +3 -0
  424. package/dist/node/helpers/monitor/index.d.ts.map +1 -0
  425. package/dist/node/helpers/monitor/types.d.ts +7 -0
  426. package/dist/node/helpers/monitor/types.d.ts.map +1 -0
  427. package/dist/node/index.d.ts +30 -0
  428. package/dist/node/index.d.ts.map +1 -0
  429. package/dist/node/index.mjs +3660 -0
  430. package/dist/node/index.mjs.map +7 -0
  431. package/dist/node/initializer/DappInitializer.d.ts +18 -0
  432. package/dist/node/initializer/DappInitializer.d.ts.map +1 -0
  433. package/dist/node/initializer/index.d.ts +2 -0
  434. package/dist/node/initializer/index.d.ts.map +1 -0
  435. package/dist/node/intent/Caller.d.ts +23 -0
  436. package/dist/node/intent/Caller.d.ts.map +1 -0
  437. package/dist/node/intent/Resource.d.ts +23 -0
  438. package/dist/node/intent/Resource.d.ts.map +1 -0
  439. package/dist/node/intent/index.d.ts +3 -0
  440. package/dist/node/intent/index.d.ts.map +1 -0
  441. package/dist/node/lib/ExternalStore.d.ts +7 -0
  442. package/dist/node/lib/ExternalStore.d.ts.map +1 -0
  443. package/dist/node/lib/Listener.d.ts +2 -0
  444. package/dist/node/lib/Listener.d.ts.map +1 -0
  445. package/dist/node/lib/ModuleAccountPaths.d.ts +3 -0
  446. package/dist/node/lib/ModuleAccountPaths.d.ts.map +1 -0
  447. package/dist/node/lib/ModuleNames.d.ts +3 -0
  448. package/dist/node/lib/ModuleNames.d.ts.map +1 -0
  449. package/dist/node/lib/NameTransforms.d.ts +11 -0
  450. package/dist/node/lib/NameTransforms.d.ts.map +1 -0
  451. package/dist/node/lib/PayloadStore.d.ts +37 -0
  452. package/dist/node/lib/PayloadStore.d.ts.map +1 -0
  453. package/dist/node/lib/ResourceStores.d.ts +7 -0
  454. package/dist/node/lib/ResourceStores.d.ts.map +1 -0
  455. package/dist/node/lib/index.d.ts +12 -0
  456. package/dist/node/lib/index.d.ts.map +1 -0
  457. package/dist/node/lib/initializeXns.d.ts +3 -0
  458. package/dist/node/lib/initializeXns.d.ts.map +1 -0
  459. package/dist/node/lib/isEqual.d.ts +2 -0
  460. package/dist/node/lib/isEqual.d.ts.map +1 -0
  461. package/dist/node/lib/isPayload.d.ts +6 -0
  462. package/dist/node/lib/isPayload.d.ts.map +1 -0
  463. package/dist/node/lib/tokenPlacesSplit.d.ts +3 -0
  464. package/dist/node/lib/tokenPlacesSplit.d.ts.map +1 -0
  465. package/dist/node/loadOsNode.d.ts +5 -0
  466. package/dist/node/loadOsNode.d.ts.map +1 -0
  467. package/dist/node/manifest/index.d.ts +3 -0
  468. package/dist/node/manifest/index.d.ts.map +1 -0
  469. package/dist/node/manifest/manifestReplacementTokens.d.ts +4 -0
  470. package/dist/node/manifest/manifestReplacementTokens.d.ts.map +1 -0
  471. package/dist/node/manifests/index.d.ts +2 -0
  472. package/dist/node/manifests/index.d.ts.map +1 -0
  473. package/dist/node/models/access/ValidDappAccessInterfaces.d.ts +5 -0
  474. package/dist/node/models/access/ValidDappAccessInterfaces.d.ts.map +1 -0
  475. package/dist/node/models/access/index.d.ts +2 -0
  476. package/dist/node/models/access/index.d.ts.map +1 -0
  477. package/dist/node/models/index.d.ts +2 -0
  478. package/dist/node/models/index.d.ts.map +1 -0
  479. package/dist/node/profileModuleEvents.d.ts +9 -0
  480. package/dist/node/profileModuleEvents.d.ts.map +1 -0
  481. package/dist/node/registration/DappRegistrationService.d.ts +37 -0
  482. package/dist/node/registration/DappRegistrationService.d.ts.map +1 -0
  483. package/dist/node/registration/DappRegistry.d.ts +26 -0
  484. package/dist/node/registration/DappRegistry.d.ts.map +1 -0
  485. package/dist/node/registration/ValidateDappAccessDiviner/Config.d.ts +23 -0
  486. package/dist/node/registration/ValidateDappAccessDiviner/Config.d.ts.map +1 -0
  487. package/dist/node/registration/ValidateDappAccessDiviner/Diviner.d.ts +9 -0
  488. package/dist/node/registration/ValidateDappAccessDiviner/Diviner.d.ts.map +1 -0
  489. package/dist/node/registration/ValidateDappAccessDiviner/index.d.ts +3 -0
  490. package/dist/node/registration/ValidateDappAccessDiviner/index.d.ts.map +1 -0
  491. package/dist/node/registration/index.d.ts +3 -0
  492. package/dist/node/registration/index.d.ts.map +1 -0
  493. package/dist/node/scripts/xyos/command/config.d.ts +3 -0
  494. package/dist/node/scripts/xyos/command/config.d.ts.map +1 -0
  495. package/dist/node/scripts/xyos/command/create.d.ts +3 -0
  496. package/dist/node/scripts/xyos/command/create.d.ts.map +1 -0
  497. package/dist/node/scripts/xyos/command/index.d.ts +6 -0
  498. package/dist/node/scripts/xyos/command/index.d.ts.map +1 -0
  499. package/dist/node/scripts/xyos/command/manifest.d.ts +3 -0
  500. package/dist/node/scripts/xyos/command/manifest.d.ts.map +1 -0
  501. package/dist/node/scripts/xyos/command/start.d.ts +3 -0
  502. package/dist/node/scripts/xyos/command/start.d.ts.map +1 -0
  503. package/dist/node/scripts/xyos/index.d.ts +2 -0
  504. package/dist/node/scripts/xyos/index.d.ts.map +1 -0
  505. package/dist/node/scripts/xyos/index.mjs +2044 -0
  506. package/dist/node/scripts/xyos/index.mjs.map +7 -0
  507. package/dist/node/scripts/xyos/lib/createFromTemplate.d.ts +7 -0
  508. package/dist/node/scripts/xyos/lib/createFromTemplate.d.ts.map +1 -0
  509. package/dist/node/scripts/xyos/lib/headless.d.ts +8 -0
  510. package/dist/node/scripts/xyos/lib/headless.d.ts.map +1 -0
  511. package/dist/node/scripts/xyos/lib/index.d.ts +3 -0
  512. package/dist/node/scripts/xyos/lib/index.d.ts.map +1 -0
  513. package/dist/node/signer/Signers.d.ts +17 -0
  514. package/dist/node/signer/Signers.d.ts.map +1 -0
  515. package/dist/node/signer/index.d.ts +2 -0
  516. package/dist/node/signer/index.d.ts.map +1 -0
  517. package/dist/node/stack/Base.d.ts +41 -0
  518. package/dist/node/stack/Base.d.ts.map +1 -0
  519. package/dist/node/stack/Manager.d.ts +19 -0
  520. package/dist/node/stack/Manager.d.ts.map +1 -0
  521. package/dist/node/stack/Map.d.ts +3 -0
  522. package/dist/node/stack/Map.d.ts.map +1 -0
  523. package/dist/node/stack/OsPubSubNetworkStack.d.ts +14 -0
  524. package/dist/node/stack/OsPubSubNetworkStack.d.ts.map +1 -0
  525. package/dist/node/stack/OsSettingsStack.d.ts +9 -0
  526. package/dist/node/stack/OsSettingsStack.d.ts.map +1 -0
  527. package/dist/node/stack/XyoPublicNetworkStack.d.ts +9 -0
  528. package/dist/node/stack/XyoPublicNetworkStack.d.ts.map +1 -0
  529. package/dist/node/stack/index.d.ts +7 -0
  530. package/dist/node/stack/index.d.ts.map +1 -0
  531. package/dist/node/system/ManageSystemDapps.d.ts +33 -0
  532. package/dist/node/system/ManageSystemDapps.d.ts.map +1 -0
  533. package/dist/node/system/Queries.d.ts +9 -0
  534. package/dist/node/system/Queries.d.ts.map +1 -0
  535. package/dist/node/system/index.d.ts +2 -0
  536. package/dist/node/system/index.d.ts.map +1 -0
  537. package/dist/node/utils/buildWalletSeedPhrasePayload.d.ts +30 -0
  538. package/dist/node/utils/buildWalletSeedPhrasePayload.d.ts.map +1 -0
  539. package/dist/node/utils/getApiDomain.d.ts +3 -0
  540. package/dist/node/utils/getApiDomain.d.ts.map +1 -0
  541. package/dist/node/utils/index.d.ts +4 -0
  542. package/dist/node/utils/index.d.ts.map +1 -0
  543. package/dist/node/utils/renameObjKey.d.ts +7 -0
  544. package/dist/node/utils/renameObjKey.d.ts.map +1 -0
  545. package/dist/node/wallet/DappSeedPhraseRepository.d.ts +16 -0
  546. package/dist/node/wallet/DappSeedPhraseRepository.d.ts.map +1 -0
  547. package/dist/node/wallet/SeedPhraseRepository.d.ts +28 -0
  548. package/dist/node/wallet/SeedPhraseRepository.d.ts.map +1 -0
  549. package/dist/node/wallet/index.d.ts +3 -0
  550. package/dist/node/wallet/index.d.ts.map +1 -0
  551. package/package.json +8 -8
@@ -0,0 +1,3660 @@
1
+ // src/access/Caller.ts
2
+ import { assertEx as assertEx16 } from "@xylabs/sdk-js";
3
+ import { asNodeInstance as asNodeInstance2 } from "@xyo-network/node-model";
4
+ import { isRegisteredDappAccessDappSet as isRegisteredDappAccessDappSet2 } from "@xyo-network/os-model";
5
+ import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
6
+ import { ModuleFactoryLocator as ModuleFactoryLocator9 } from "@xyo-network/sdk-js";
7
+
8
+ // src/OsCallerBase.ts
9
+ import { assertEx } from "@xylabs/sdk-js";
10
+ import { asArchivistInstance } from "@xyo-network/archivist-model";
11
+ import { asDivinerInstance } from "@xyo-network/diviner-model";
12
+ var DappsArchivistModuleName = "DappsArchivist";
13
+ var DappsArchivistDevelopmentModuleName = `${DappsArchivistModuleName}Development`;
14
+ var DappsArchivistPayloadDivinerModuleName = "DappsArchivistPayloadDiviner";
15
+ var DappsArchivistPayloadDevelopmentDivinerModuleName = `${DappsArchivistPayloadDivinerModuleName}Development`;
16
+ var RegisteredDappInterfacesArchivistModuleName = "RegisteredDappInterfacesArchivist";
17
+ var OsCallerBase = class {
18
+ context;
19
+ constructor(context) {
20
+ this.context = context;
21
+ }
22
+ // Get the dapps archivist
23
+ async getDappsArchivist() {
24
+ const mod = assertEx(await this.context.root.resolve(DappsArchivistModuleName), () => `${DappsArchivistModuleName} not found`);
25
+ return asArchivistInstance(mod, () => `${DappsArchivistModuleName} is not an archivist`, { required: true });
26
+ }
27
+ // Get the dapps archivist development
28
+ async getDappsArchivistDevelopment() {
29
+ const mod = assertEx(
30
+ await this.context.root.resolve(DappsArchivistDevelopmentModuleName),
31
+ () => `${DappsArchivistDevelopmentModuleName} not found`
32
+ );
33
+ return asArchivistInstance(mod, () => `${DappsArchivistDevelopmentModuleName} is not an archivist`, { required: true });
34
+ }
35
+ // Get the dapps archivist payload diviner
36
+ async getDappsArchivistPayloadDiviner() {
37
+ const mod = assertEx(
38
+ await this.context.root.resolve(DappsArchivistPayloadDivinerModuleName),
39
+ () => `${DappsArchivistPayloadDivinerModuleName} not found`
40
+ );
41
+ return asDivinerInstance(mod, () => `${DappsArchivistPayloadDivinerModuleName} is not a diviner`, { required: true });
42
+ }
43
+ // Get the dapps archivist payload diviner development
44
+ async getDappsArchivistPayloadDivinerDevelopment() {
45
+ const mod = assertEx(
46
+ await this.context.root.resolve(DappsArchivistPayloadDevelopmentDivinerModuleName),
47
+ () => `${DappsArchivistPayloadDevelopmentDivinerModuleName} not found`
48
+ );
49
+ return asDivinerInstance(mod, () => `${DappsArchivistPayloadDevelopmentDivinerModuleName} is not a diviner`, { required: true });
50
+ }
51
+ // Get the registered dapp interfaces archivist
52
+ async getRegisteredDappInterfacesArchivist() {
53
+ const mod = assertEx(
54
+ await this.context.root.resolve(RegisteredDappInterfacesArchivistModuleName),
55
+ () => `${RegisteredDappInterfacesArchivistModuleName} not found`
56
+ );
57
+ return asArchivistInstance(mod, () => `${RegisteredDappInterfacesArchivistModuleName} is not an archivist`, { required: true });
58
+ }
59
+ };
60
+
61
+ // src/RunningDappCache.ts
62
+ import { assertEx as assertEx15 } from "@xylabs/sdk-js";
63
+ import { Mutex as Mutex3 } from "async-mutex";
64
+
65
+ // src/dapp/context/creator/createDappContext.ts
66
+ import { GenericPayloadDiviner } from "@xyo-network/diviner-payload-generic";
67
+ import { HDWallet as HDWallet2, ModuleFactoryLocator as ModuleFactoryLocator2 } from "@xyo-network/sdk-js";
68
+
69
+ // src/wallet/DappSeedPhraseRepository.ts
70
+ import { PayloadDivinerQuerySchema } from "@xyo-network/diviner-payload-model";
71
+ import { DappWalletSeedPhraseSchema } from "@xyo-network/os-model";
72
+ import { HDWallet } from "@xyo-network/sdk-js";
73
+ import { v4 as uuid } from "uuid";
74
+ var DappSeedPhraseRepository = class extends OsCallerBase {
75
+ allowedNames;
76
+ // record of all dapps that have requested a seed phrase with the OS
77
+ dappIdRepository = /* @__PURE__ */ new Map();
78
+ // record of all walletIds that have been issued to registered dapps
79
+ walletIdRepository = /* @__PURE__ */ new Map();
80
+ constructor(xyOs, allowedNames) {
81
+ super(xyOs);
82
+ this.allowedNames = allowedNames;
83
+ }
84
+ async add(dappId) {
85
+ const archivist = await this.getDappsArchivist();
86
+ const seedPhrase = this.newPhrase();
87
+ const walletId = uuid();
88
+ const payload = {
89
+ dappId,
90
+ schema: DappWalletSeedPhraseSchema,
91
+ seedPhrase,
92
+ walletId
93
+ };
94
+ await archivist.insert([payload]);
95
+ this.dappIdRepository.set(dappId, payload);
96
+ this.walletIdRepository.set(walletId, payload);
97
+ return walletId;
98
+ }
99
+ async findOrCreate(dappName) {
100
+ if (this.allowedNames.includes(dappName)) {
101
+ const existingPayload = await this.checkDappId(dappName);
102
+ if (existingPayload) return existingPayload.walletId;
103
+ try {
104
+ await this.add(dappName);
105
+ const existingPayload2 = await this.checkDappId(dappName);
106
+ if (existingPayload2) return existingPayload2.walletId;
107
+ throw new Error(`failed to add seed phrase: ${dappName}`);
108
+ } catch (e) {
109
+ console.error(e);
110
+ throw new Error(`failed to add seed phrase: ${dappName}`, { cause: e });
111
+ }
112
+ } else {
113
+ throw new Error(`${dappName} is not allowed to register a seed phase. NOTE: this is a safeguard till 3rd party dApps can be validated`);
114
+ }
115
+ }
116
+ async request(walletId) {
117
+ return (await this.checkWalletId(walletId))?.seedPhrase;
118
+ }
119
+ async checkDappId(dappId) {
120
+ const diviner = await this.getDappsArchivistPayloadDiviner();
121
+ const query = {
122
+ dappId,
123
+ limit: 1,
124
+ order: "desc",
125
+ schema: PayloadDivinerQuerySchema,
126
+ schemas: [DappWalletSeedPhraseSchema]
127
+ };
128
+ const results = await diviner.divine([query]);
129
+ return results.length > 0 ? results[0] : void 0;
130
+ }
131
+ async checkWalletId(walletId) {
132
+ const diviner = await this.getDappsArchivistPayloadDiviner();
133
+ const query = {
134
+ limit: 1,
135
+ order: "desc",
136
+ schema: PayloadDivinerQuerySchema,
137
+ schemas: [DappWalletSeedPhraseSchema],
138
+ walletId
139
+ };
140
+ const results = await diviner.divine([query]);
141
+ return results.length > 0 ? results[0] : void 0;
142
+ }
143
+ newPhrase() {
144
+ return HDWallet.generateMnemonic();
145
+ }
146
+ };
147
+
148
+ // src/dapp/context/creator/Creator.ts
149
+ import { assertEx as assertEx3 } from "@xylabs/sdk-js";
150
+ import { asArchivistInstance as asArchivistInstance3 } from "@xyo-network/archivist-model";
151
+ import { replaceManifestTokens } from "@xyo-network/kernel";
152
+ import { DappPackageManifestPayloadSchema } from "@xyo-network/os-model";
153
+ import { ModuleFactoryLocator } from "@xyo-network/sdk-js";
154
+
155
+ // src/DappCallerBase.ts
156
+ import { assertEx as assertEx2, toSafeJsonString } from "@xylabs/sdk-js";
157
+ import { asArchivistInstance as asArchivistInstance2 } from "@xyo-network/archivist-model";
158
+ import { asDivinerInstance as asDivinerInstance2 } from "@xyo-network/diviner-model";
159
+ var DappArchivistModuleName = "DappArchivist";
160
+ var IntentArchivistModuleName = "IntentArchivist";
161
+ var IntentArchivistPayloadDivinerModuleName = "IntentArchivistPayloadDiviner";
162
+ var DappArchivistPayloadDivinerModuleName = "DappArchivistPayloadDiviner";
163
+ var DappCallerBase = class {
164
+ context;
165
+ constructor(context) {
166
+ this.context = context;
167
+ }
168
+ /**
169
+ * Get the DappArchivist
170
+ */
171
+ async getDappArchivist() {
172
+ const mod = assertEx2(
173
+ await this.context.root.resolve(DappArchivistModuleName),
174
+ () => `${DappArchivistModuleName} not found [${toSafeJsonString(this.context.root.publicChildren())}]`
175
+ );
176
+ return asArchivistInstance2(mod, () => `${DappArchivistModuleName} is not an archivist`, { required: true });
177
+ }
178
+ /**
179
+ * Get the DappArchivistPayloadDiviner
180
+ */
181
+ async getDappArchivistPayloadDiviner() {
182
+ const mod = assertEx2(
183
+ await this.context.root.resolve(DappArchivistPayloadDivinerModuleName),
184
+ () => `${DappArchivistPayloadDivinerModuleName} not found`
185
+ );
186
+ return asDivinerInstance2(mod, () => `${DappArchivistPayloadDivinerModuleName} is not a diviner`, { required: true });
187
+ }
188
+ /**
189
+ * Get the IntentArchivist
190
+ */
191
+ async getDappIntentArchivist() {
192
+ const mod = assertEx2(await this.context.root.resolve(IntentArchivistModuleName), () => `${IntentArchivistModuleName} not found`);
193
+ return asArchivistInstance2(mod, () => `${IntentArchivistModuleName} is not an archivist`, { required: true });
194
+ }
195
+ // Get the IntentArchivistPayloadDiviner
196
+ async getDappIntentArchivistPayloadDiviner() {
197
+ const mod = assertEx2(
198
+ await this.context.root.resolve(IntentArchivistPayloadDivinerModuleName),
199
+ () => `${IntentArchivistPayloadDivinerModuleName} not found`
200
+ );
201
+ return asDivinerInstance2(mod, () => `${IntentArchivistPayloadDivinerModuleName} is not a diviner`, { required: true });
202
+ }
203
+ };
204
+
205
+ // src/manifest/manifestReplacementTokens.ts
206
+ import { getXnsDomain } from "@xyo-network/kernel";
207
+ var manifestReplacementTokens = (xnsNodeUrl, xnsNetwork) => ({ "[REPLACE_WITH_NS_NODE_URL]": getXnsDomain(xnsNodeUrl, xnsNetwork) });
208
+
209
+ // src/manifest/os-node.manifest.json
210
+ var os_node_manifest_default = {
211
+ $schema: "https://raw.githubusercontent.com/XYOracleNetwork/sdk-xyo-client-js/main/packages/manifest/src/compilations/dapp-package-manifest-schema.json",
212
+ nodes: [
213
+ {
214
+ config: {
215
+ accountPath: "0'",
216
+ name: "OsNode",
217
+ schema: "network.xyo.node.config"
218
+ },
219
+ modules: {
220
+ private: [],
221
+ public: [
222
+ {
223
+ config: {
224
+ accountPath: "1'",
225
+ name: "OSArchivist",
226
+ dbName: "OSArchivist-2025-01-13",
227
+ labels: {
228
+ "network.xyo.archivist.persistence.scope": "device"
229
+ },
230
+ storeName: "payloads",
231
+ parents: {
232
+ read: [
233
+ "Archivist"
234
+ ]
235
+ },
236
+ schema: "network.xyo.archivist.config"
237
+ }
238
+ },
239
+ {
240
+ config: {
241
+ accountPath: "3'",
242
+ name: "DappsArchivist",
243
+ dbName: "DappsArchivist-2025-01-13",
244
+ labels: {
245
+ "network.xyo.archivist.persistence.scope": "device"
246
+ },
247
+ storeName: "payloads",
248
+ schema: "network.xyo.archivist.config"
249
+ }
250
+ },
251
+ {
252
+ config: {
253
+ archivist: "DappsArchivist",
254
+ dbVersion: 1,
255
+ name: "DappsArchivistPayloadDiviner",
256
+ labels: {
257
+ "network.xyo.archivist.persistence.scope": "device"
258
+ },
259
+ schema: "network.xyo.diviner.payload.generic.config"
260
+ }
261
+ },
262
+ {
263
+ config: {
264
+ accountPath: "4'",
265
+ dbName: "IntentArchivist-2025-01-13",
266
+ name: "IntentArchivist",
267
+ storeName: "payloads",
268
+ labels: {
269
+ "network.xyo.archivist.persistence.scope": "device"
270
+ },
271
+ schema: "network.xyo.archivist.config"
272
+ }
273
+ },
274
+ {
275
+ config: {
276
+ accountPath: "7",
277
+ archivist: "IntentArchivist",
278
+ dbVersion: 1,
279
+ name: "IntentArchivistPayloadDiviner",
280
+ labels: {
281
+ "network.xyo.archivist.persistence.scope": "device"
282
+ },
283
+ schema: "network.xyo.diviner.payload.generic.config",
284
+ storeName: "payloads"
285
+ }
286
+ },
287
+ {
288
+ config: {
289
+ accountPath: "8",
290
+ name: "RegisteredDappInterfacesArchivist",
291
+ schema: "network.xyo.archivist.memory.config"
292
+ }
293
+ },
294
+ {
295
+ config: {
296
+ accountPath: "9'",
297
+ name: "DappsArchivistDevelopment",
298
+ parents: {
299
+ write: [
300
+ "DappsArchivist"
301
+ ]
302
+ },
303
+ schema: "network.xyo.archivist.memory.config"
304
+ }
305
+ },
306
+ {
307
+ config: {
308
+ accountPath: "10",
309
+ archivist: "DappsArchivistDevelopment",
310
+ dbVersion: 1,
311
+ name: "DappsArchivistPayloadDivinerDevelopment",
312
+ labels: {
313
+ "network.xyo.generic.payload.diviner": "GenericPayloadDiviner"
314
+ },
315
+ schema: "network.xyo.diviner.payload.generic.config"
316
+ }
317
+ },
318
+ {
319
+ config: {
320
+ name: "OsPubSubNetworkStackNode",
321
+ schema: "network.xyo.node.config"
322
+ }
323
+ },
324
+ {
325
+ config: {
326
+ name: "OsSettingsStackNode",
327
+ schema: "network.xyo.node.config"
328
+ }
329
+ },
330
+ {
331
+ config: {
332
+ name: "OsXyoPublicNetworkStackNode",
333
+ schema: "network.xyo.node.config"
334
+ }
335
+ }
336
+ ]
337
+ }
338
+ }
339
+ ],
340
+ schema: "network.xyo.manifest.package.dapp"
341
+ };
342
+
343
+ // src/dapp/context/creator/DefaultPayloads/DefaultPayloads.ts
344
+ import { PayloadBuilder } from "@xyo-network/payload-builder";
345
+
346
+ // src/classes/lib/Insertable.ts
347
+ var createInsertable = (insertable, ...params) => new insertable(...params);
348
+
349
+ // src/dapp/context/creator/DefaultPayloads/DappAccessPayloads.ts
350
+ var DappAccessPayloads = class {
351
+ context;
352
+ constructor(context, _dappName) {
353
+ this.context = context;
354
+ }
355
+ async payloads() {
356
+ const osCaller = new OsCallerBase(this.context);
357
+ const archivist = await osCaller.getRegisteredDappInterfacesArchivist();
358
+ return await archivist.all();
359
+ }
360
+ };
361
+
362
+ // src/dapp/context/creator/DefaultPayloads/NodeInfoPayload.ts
363
+ import { NodeOsInfoSchema } from "@xyo-network/os-model";
364
+ var NodeInfoPayload = class {
365
+ _context;
366
+ constructor(context, _dappName) {
367
+ this._context = context;
368
+ }
369
+ async payloads() {
370
+ const exposedNode = this._context.exposedNode;
371
+ if (exposedNode) {
372
+ console.debug("[DEBUG]", "Found Exposed Node Address", exposedNode?.address);
373
+ } else {
374
+ console.error("exposedNode not found");
375
+ }
376
+ await Promise.resolve();
377
+ const nodeOsInfo = {
378
+ publicAddress: exposedNode?.address ?? "",
379
+ schema: NodeOsInfoSchema
380
+ };
381
+ return [nodeOsInfo];
382
+ }
383
+ };
384
+
385
+ // src/dapp/context/creator/DefaultPayloads/DefaultPayloads.ts
386
+ var DefaultPayloads = class {
387
+ dappArchivist;
388
+ dappName;
389
+ xyOs;
390
+ constructor(dappArchivist, xyOs, dappName) {
391
+ this.dappArchivist = dappArchivist;
392
+ this.xyOs = xyOs;
393
+ this.dappName = dappName;
394
+ }
395
+ async insert() {
396
+ const insertables = [NodeInfoPayload, DappAccessPayloads];
397
+ const insertPayloads = [];
398
+ for (const insertable of insertables) {
399
+ const classInstance = createInsertable(insertable, this.xyOs, this.dappName);
400
+ const payloads = await classInstance.payloads();
401
+ insertPayloads.push(...payloads);
402
+ }
403
+ for (const payload of insertPayloads) {
404
+ const [existing] = await this.dappArchivist.get([await PayloadBuilder.dataHash(payload)]);
405
+ if (existing) continue;
406
+ await this.dappArchivist.insert([payload]);
407
+ }
408
+ }
409
+ };
410
+
411
+ // src/dapp/context/creator/ExternalModulePermissions/ExternalModulePermissions.ts
412
+ var ALLOWED_MODULES_FROM_PARENT = ["IntentArchivist", "OsSettingsNode", "OsPubSubNetworkStackNode", "OsXyoPublicNetworkStackNode"];
413
+ var ExternalModulePermissions = class {
414
+ context;
415
+ dappName;
416
+ dappWindowNode;
417
+ externalPermissions;
418
+ constructor(context, dappWindowNode, dappName, externalPermissions) {
419
+ this.context = context;
420
+ this.dappWindowNode = dappWindowNode;
421
+ this.dappName = dappName;
422
+ this.externalPermissions = externalPermissions;
423
+ }
424
+ async permit() {
425
+ for (const permission of this.externalPermissions ?? []) {
426
+ await this.permitExternalModule(permission);
427
+ }
428
+ }
429
+ getExternalModuleName(permission) {
430
+ return permission.name;
431
+ }
432
+ async permitExternalModule(externalPermission) {
433
+ const externalModuleName = this.getExternalModuleName(externalPermission);
434
+ if (ALLOWED_MODULES_FROM_PARENT.includes(externalModuleName)) {
435
+ const mod = await this.resolveExternalModule(externalModuleName);
436
+ await this.registerAndAttachModule(mod);
437
+ } else {
438
+ console.warn(`${this.dappName} requested ${externalModuleName} but it was not fulfilled`);
439
+ }
440
+ }
441
+ async registerAndAttachModule(mod) {
442
+ if (mod) {
443
+ await this.dappWindowNode.register?.(mod);
444
+ await this.dappWindowNode.attach(mod.address, true);
445
+ }
446
+ }
447
+ async resolveExternalModule(id) {
448
+ return await this.context.root.resolve(id);
449
+ }
450
+ };
451
+
452
+ // src/dapp/context/creator/Creator.ts
453
+ var DappContextCreator = class _DappContextCreator {
454
+ // Designated offset path for the wallet used by windowed dapps. In the future, other offsets could be used for other dapp modes
455
+ static DAPP_WINDOW_WALLET_PATH = "1";
456
+ context;
457
+ dappId;
458
+ externalPermissions;
459
+ rootWallet;
460
+ sharedLocator;
461
+ targetDappManifestParams;
462
+ constructor(targetDappManifestParams, dappId, context, rootWallet, externalPermissions, sharedLocator) {
463
+ this.targetDappManifestParams = targetDappManifestParams;
464
+ this.dappId = dappId;
465
+ this.context = context;
466
+ this.rootWallet = rootWallet;
467
+ this.externalPermissions = externalPermissions;
468
+ this.sharedLocator = sharedLocator;
469
+ }
470
+ static async create(params, xnsNodeUrl, xnsNetwork) {
471
+ const {
472
+ config,
473
+ locator,
474
+ context,
475
+ wallet
476
+ } = params;
477
+ const {
478
+ payload,
479
+ dappName,
480
+ publicChildren,
481
+ privateChildren
482
+ } = config;
483
+ const { external, manifestPayload } = this.parseDappPackageManifestPayload(payload, xnsNodeUrl, xnsNetwork);
484
+ console.debug("[DEBUG] dApp manifest", manifestPayload);
485
+ const dappWallet = await wallet.derivePath(_DappContextCreator.DAPP_WINDOW_WALLET_PATH);
486
+ const targetDappManifestParams = [
487
+ manifestPayload,
488
+ dappWallet,
489
+ locator ?? new ModuleFactoryLocator(),
490
+ publicChildren,
491
+ privateChildren
492
+ ];
493
+ const instance = new this(targetDappManifestParams, dappName, context, wallet, external?.modules, locator);
494
+ return instance;
495
+ }
496
+ // Add default payloads to the archivist shared between the os and the dapp
497
+ static async primeDappArchivist(dappContext, osContext, dappName) {
498
+ const dappCaller = new DappCallerBase(dappContext);
499
+ const dappArchivist = await dappCaller.getDappArchivist();
500
+ const defaultPayloads = new DefaultPayloads(dappArchivist, osContext, dappName);
501
+ await defaultPayloads.insert();
502
+ }
503
+ // Reset the dapp archivist to remove all payloads
504
+ static async resetDappArchivist(context) {
505
+ const dappModule = await context.root.resolve("DappArchivist");
506
+ const dappArchivist = assertEx3(asArchivistInstance3(dappModule), () => "resetDappArchivist: DappArchivist not found");
507
+ await dappArchivist.clear();
508
+ }
509
+ static parseDappPackageManifestPayload(payload, xnsNodeUrl, xnsNetwork) {
510
+ const { external, ...manifestWithoutExternals } = payload;
511
+ const manifestPayloadRaw = {
512
+ ...manifestWithoutExternals,
513
+ schema: DappPackageManifestPayloadSchema
514
+ };
515
+ console.log("DappContextCreator:parseDappPackageManifestPayload", xnsNodeUrl, xnsNetwork);
516
+ const manifestPayload = replaceManifestTokens(manifestPayloadRaw, manifestReplacementTokens(xnsNodeUrl, xnsNetwork));
517
+ return { external, manifestPayload };
518
+ }
519
+ async loadDappContext(context) {
520
+ console.log("DappNodesCreator:loadDappContext", this.dappId);
521
+ const dapp = await context.dappByName(this.dappId) ?? await (async () => {
522
+ const dapp2 = await context.buildDapp(this.targetDappManifestParams[0], this.dappId);
523
+ await dapp2.boot(this.rootWallet, this.sharedLocator);
524
+ return dapp2;
525
+ })();
526
+ await this.handleExternalModulePermissions(dapp.root);
527
+ await _DappContextCreator.primeDappArchivist(dapp, this.context, this.dappId);
528
+ return dapp;
529
+ }
530
+ // try to satisfy the external permissions requested by a dapp
531
+ async handleExternalModulePermissions(dappWindowNode) {
532
+ const externalModulePermissions = new ExternalModulePermissions(this.context, dappWindowNode, this.dappId, this.externalPermissions);
533
+ await externalModulePermissions.permit();
534
+ }
535
+ };
536
+
537
+ // src/dapp/context/creator/createDappContext.ts
538
+ var GenericPayloadDivinerTags = { "network.xyo.generic.payload.diviner": "GenericPayloadDiviner" };
539
+ var resolveLocator = (existingLocator) => {
540
+ const locator = existingLocator ?? new ModuleFactoryLocator2();
541
+ locator.register(GenericPayloadDiviner.factory(), GenericPayloadDivinerTags);
542
+ return locator;
543
+ };
544
+ var createDappContext = async (dapp, context, allowedNames, xnsNodeUrl, xnsNetwork) => {
545
+ console.log("createNodes");
546
+ try {
547
+ const dappSeedPhraseRepository = new DappSeedPhraseRepository(context, allowedNames);
548
+ const seedPhrase = await dappSeedPhraseRepository.request(dapp.config.walletId);
549
+ if (!seedPhrase) {
550
+ throw new Error(`unable to find seed phrase for walletId: ${JSON.stringify(dapp.config, null, 2)}`);
551
+ }
552
+ const wallet = await HDWallet2.fromPhrase(seedPhrase);
553
+ const dappName = dapp.config.name;
554
+ const { config: dappConfig, params: dappParams } = dapp;
555
+ const locator = resolveLocator((dappParams.locator ?? new ModuleFactoryLocator2()).merge(context.platformLocator));
556
+ const params = {
557
+ config: { dappName, payload: dappConfig.manifest },
558
+ context,
559
+ locator,
560
+ wallet
561
+ };
562
+ const dappContextCreator = await DappContextCreator.create(params, xnsNodeUrl, xnsNetwork);
563
+ const dappContext = await dappContextCreator.loadDappContext(context);
564
+ return {
565
+ context: dappContext,
566
+ dappWallet: wallet
567
+ };
568
+ } catch (e) {
569
+ const error = e;
570
+ console.error(`Error creating dappWindow node: ${error.message}`);
571
+ console.error(`Error creating dappWindow node: ${error.stack}`);
572
+ throw new Error(`Error creating dappWindow node: ${error.message}`, { cause: e });
573
+ }
574
+ };
575
+
576
+ // src/XyOs.ts
577
+ import { assertEx as assertEx14 } from "@xylabs/sdk-js";
578
+ import { boot } from "@xyo-network/bios";
579
+ import { Kernel } from "@xyo-network/kernel";
580
+ import { ModuleFactoryLocator as ModuleFactoryLocator8 } from "@xyo-network/sdk-js";
581
+
582
+ // src/event/bus/Connection.ts
583
+ import { assertEx as assertEx4, BaseEmitter } from "@xylabs/sdk-js";
584
+ var EventBusConnection = class extends BaseEmitter {
585
+ _id;
586
+ description;
587
+ type;
588
+ constructor(request) {
589
+ super({});
590
+ this.description = request.description;
591
+ this.type = request.type;
592
+ }
593
+ get id() {
594
+ return assertEx4(this._id, () => "Connection ID not set. Did you forget to call buildConnection()?");
595
+ }
596
+ buildConnection(id) {
597
+ this._id = id;
598
+ }
599
+ };
600
+
601
+ // src/event/bus/EventBus.ts
602
+ import {
603
+ assertEx as assertEx5,
604
+ findAs,
605
+ forget
606
+ } from "@xylabs/sdk-js";
607
+ import { asArchivistInstance as asArchivistInstance4 } from "@xyo-network/archivist";
608
+ import {
609
+ asOptionalEventBusEvent,
610
+ isPubSubConnections
611
+ } from "@xyo-network/os-model";
612
+ import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
613
+ import { asSchema } from "@xyo-network/payload-model";
614
+ import { MemoryArchivist, MemoryArchivistConfigSchema } from "@xyo-network/sdk-js";
615
+ import { Mutex } from "async-mutex";
616
+ import { v4 as uuid2 } from "uuid";
617
+ var EventBus = class {
618
+ // Internal Archivist to store event data
619
+ _archivist;
620
+ // Store all connections
621
+ connections = {};
622
+ // Store all publisher callbacks for later removal
623
+ publisherCallbacks = {};
624
+ startMutex = new Mutex();
625
+ get archivist() {
626
+ return asArchivistInstance4(
627
+ assertEx5(this._archivist, () => "Archivist not found. Did you forget to call start()?"),
628
+ "not a valid archivist instance",
629
+ { required: true }
630
+ );
631
+ }
632
+ addConnection(connection) {
633
+ const id = uuid2();
634
+ this.connections[id] = connection;
635
+ connection.buildConnection(id);
636
+ if (isPubSubConnections(connection)) {
637
+ this.handlePublisherAdd(connection);
638
+ } else {
639
+ throw new Error("Unsupported connection type. Must be PubSub");
640
+ }
641
+ return connection;
642
+ }
643
+ removeConnection(connectionId) {
644
+ const connection = this.connections[connectionId];
645
+ if (!connection) {
646
+ throw new Error("Connection not found " + connectionId);
647
+ }
648
+ if (connection && isPubSubConnections(connection)) {
649
+ this.handlePublisherRemove(connection);
650
+ }
651
+ delete this.connections[connectionId];
652
+ }
653
+ async start(storeName = "EventBusArchivist") {
654
+ return await this.startMutex.runExclusive(async () => {
655
+ if (this._archivist) {
656
+ console.warn("EventBus already started");
657
+ return this;
658
+ }
659
+ this._archivist = await MemoryArchivist.create({ config: { name: storeName, schema: MemoryArchivistConfigSchema } });
660
+ this.archivist.on("inserted", ({ payloads }) => {
661
+ const eventBusEvent = findAs(payloads, asOptionalEventBusEvent);
662
+ if (!eventBusEvent) return;
663
+ for (const connectionId in this.connections) {
664
+ const connection = this.connections[connectionId];
665
+ if (isPubSubConnections(connection) && connection.subscribableEvents) {
666
+ for (const [eventName, callback] of connection.subscribableEvents.entries()) {
667
+ if (eventName !== eventBusEvent.name) continue;
668
+ if (callback) {
669
+ const forgettable = async () => await callback({ payloads });
670
+ forget(forgettable());
671
+ }
672
+ }
673
+ }
674
+ }
675
+ });
676
+ return this;
677
+ });
678
+ }
679
+ handlePublisherAdd(connection) {
680
+ for (const eventName of connection.publishableEvents ?? []) {
681
+ const connectionPublisherCallback = async ({ payloads }) => {
682
+ const event = { name: eventName, schema: asSchema("network.xyo.event.bus.event", true) };
683
+ const eventPayloads = payloads ?? [];
684
+ event.sources = await PayloadBuilder2.dataHashes(eventPayloads);
685
+ try {
686
+ await this.archivist.insert([event, ...payloads ?? []]);
687
+ } catch (e) {
688
+ console.error("Error inserting event into archivist", e);
689
+ }
690
+ };
691
+ connection.on(eventName, connectionPublisherCallback);
692
+ const callbackId = connection.id + eventName;
693
+ this.publisherCallbacks[callbackId] = connectionPublisherCallback;
694
+ }
695
+ }
696
+ handlePublisherRemove(connection) {
697
+ for (const [, event] of connection.publishableEvents?.entries() ?? []) {
698
+ const id = connection.id + event;
699
+ const callback = this.publisherCallbacks[id];
700
+ if (callback) connection.off(event, callback);
701
+ }
702
+ }
703
+ };
704
+
705
+ // src/event/bus/PubSubConnection.ts
706
+ var EventBusPubSubConnection = class extends EventBusConnection {
707
+ publishableEvents;
708
+ subscribableEvents;
709
+ constructor(request) {
710
+ super(request);
711
+ if (request.type !== "PubSub") {
712
+ throw new Error("Invalid connection type. Must be PubSub");
713
+ }
714
+ this.publishableEvents = request.publishableEvents;
715
+ this.subscribableEvents = request.subscribableEvents;
716
+ }
717
+ };
718
+
719
+ // src/event/connections/DappAccessRequest.ts
720
+ var DappAccessRequestEvent = "dappAccessRequest";
721
+ var dappAccessRequestConnectionRequest = {
722
+ publishableEvents: [DappAccessRequestEvent],
723
+ type: "PubSub"
724
+ };
725
+ var dappAccessRequestConnection = () => new EventBusPubSubConnection(dappAccessRequestConnectionRequest);
726
+
727
+ // src/event/connections/DappsReady.ts
728
+ var dappsReadyConnectionRequest = {
729
+ publishableEvents: ["dappsReady"],
730
+ type: "PubSub"
731
+ };
732
+ var dappsReadyConnection = () => new EventBusPubSubConnection(dappsReadyConnectionRequest);
733
+
734
+ // src/event/connections/ExposeDappRequest.ts
735
+ var ExposeDappRequestEvent = "exposeDappRequest";
736
+ var exposeDappConnectionRequest = {
737
+ publishableEvents: [ExposeDappRequestEvent],
738
+ type: "PubSub"
739
+ };
740
+ var exposeDappRequestConnection = () => new EventBusPubSubConnection(exposeDappConnectionRequest);
741
+
742
+ // src/event/connections/OsPubSubNetworkReady.ts
743
+ var OsPubSubNetworkReadyEvent = "osPubSubNetworkReady";
744
+ var osPubSubNetworkConnectionRequest = {
745
+ publishableEvents: [OsPubSubNetworkReadyEvent],
746
+ type: "PubSub"
747
+ };
748
+ var osPubSubNetworkReadyConnection = () => new EventBusPubSubConnection(osPubSubNetworkConnectionRequest);
749
+
750
+ // src/event/connections/OsSettingsReady.ts
751
+ var OsSettingsReadyEvent = "osSettingsReady";
752
+ var osSettingsConnectionRequest = {
753
+ publishableEvents: [OsSettingsReadyEvent],
754
+ type: "PubSub"
755
+ };
756
+ var osSettingsReadyConnection = () => new EventBusPubSubConnection(osSettingsConnectionRequest);
757
+
758
+ // src/event/connections/OsXyoPublicReady.ts
759
+ var OsXyoPublicNetworkReadyEvent = "osXyoPublicNetworkReady";
760
+ var osXyoPublicNetworkConnectionRequest = {
761
+ publishableEvents: [OsXyoPublicNetworkReadyEvent],
762
+ type: "PubSub"
763
+ };
764
+ var osXyoPublicNetworkReadyConnection = () => new EventBusPubSubConnection(osXyoPublicNetworkConnectionRequest);
765
+
766
+ // src/lib/initializeXns.ts
767
+ import { asDivinerInstance as asDivinerInstance3 } from "@xyo-network/diviner-model";
768
+ import { ResolveHelper } from "@xyo-network/module";
769
+ import { NameRegistrarTransformer } from "@xyo-network/module-resolver";
770
+ var initializeXns = async (xnsNode) => {
771
+ if (ResolveHelper.transformers.length === 0) {
772
+ const registrarDiviner = asDivinerInstance3(await xnsNode?.resolve("AddressRecords:AddressRecordIndexDiviner"));
773
+ if (registrarDiviner) {
774
+ const transformer = new NameRegistrarTransformer(registrarDiviner, "xyo");
775
+ ResolveHelper.transformers = [transformer];
776
+ return true;
777
+ }
778
+ }
779
+ return false;
780
+ };
781
+
782
+ // src/lib/isEqual.ts
783
+ import { isObject } from "@xylabs/sdk-js";
784
+ function isEqual(a, b) {
785
+ if (a === b) return true;
786
+ if (typeof a !== typeof b) return false;
787
+ if (isObject(a) && isObject(b)) {
788
+ const aRecord = a;
789
+ const bRecord = b;
790
+ const aKeys = Object.keys(aRecord);
791
+ const bKeys = Object.keys(bRecord);
792
+ if (aKeys.length !== bKeys.length) {
793
+ return false;
794
+ }
795
+ for (const key of aKeys) {
796
+ if (!Object.hasOwn(bRecord, key) || !isEqual(aRecord[key], bRecord[key])) {
797
+ return false;
798
+ }
799
+ }
800
+ return true;
801
+ }
802
+ if (Array.isArray(a) && Array.isArray(b)) {
803
+ if (a.length !== b.length) {
804
+ return false;
805
+ }
806
+ for (const [i, element] of a.entries()) {
807
+ if (!isEqual(element, b[i])) {
808
+ return false;
809
+ }
810
+ }
811
+ return true;
812
+ }
813
+ return false;
814
+ }
815
+
816
+ // src/lib/isPayload.ts
817
+ import { AsObjectFactory } from "@xylabs/sdk-js";
818
+ var isObject2 = (x) => {
819
+ return typeof x === "object" && !Array.isArray(x);
820
+ };
821
+ var isAnyPayload = (obj) => {
822
+ if (isObject2(obj)) {
823
+ return typeof obj.schema === "string";
824
+ }
825
+ return false;
826
+ };
827
+ var isPayload = (schema) => (obj) => {
828
+ if (isAnyPayload(obj)) {
829
+ return schema.includes(obj.schema);
830
+ }
831
+ return false;
832
+ };
833
+ var asPayload = (schema) => AsObjectFactory.create(isPayload(schema));
834
+
835
+ // src/lib/ModuleNames.ts
836
+ var DevelopArchivist = "DevelopArchivist";
837
+ var NodeSentinel = "NodeSentinel";
838
+
839
+ // src/lib/ModuleAccountPaths.ts
840
+ var RemoteNodeArchivistOffsetPaths = {
841
+ Kerplunk: { [DevelopArchivist]: "118" },
842
+ Local: { [DevelopArchivist]: "115" },
843
+ Main: { [DevelopArchivist]: "121" }
844
+ };
845
+ var ModuleOffsetPaths = {
846
+ IdWitness: "1",
847
+ DomainWitness: "2",
848
+ LocationWitness: "3",
849
+ SchemaWitness: "4",
850
+ CryptoCardsGameWitness: "5",
851
+ CryptoCardsMoveWitness: "6",
852
+ EthereumGasEtherchainV2Witness: "7",
853
+ CoingeckoCryptoMarketWitness: "8",
854
+ UniswapCryptoMarketWitness: "9",
855
+ EthereumGasEtherscanWitness: "10",
856
+ [NodeSentinel]: "11",
857
+ [DevelopArchivist]: "12",
858
+ BowserSystemInfoPluginWitness: "13"
859
+ };
860
+
861
+ // src/lib/NameTransforms.ts
862
+ var NameTransforms = class _NameTransforms {
863
+ value;
864
+ constructor(value) {
865
+ this.value = value;
866
+ }
867
+ static deSlug(value) {
868
+ return value.replaceAll("-", " ").split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
869
+ }
870
+ static moduleName(value) {
871
+ return value.replaceAll(" ", "");
872
+ }
873
+ static slug(value) {
874
+ return value.replaceAll(" ", "-").toLocaleLowerCase();
875
+ }
876
+ deSlug() {
877
+ return _NameTransforms.deSlug(this.value);
878
+ }
879
+ moduleName() {
880
+ return _NameTransforms.moduleName(this.value);
881
+ }
882
+ slug() {
883
+ return _NameTransforms.slug(this.value);
884
+ }
885
+ };
886
+
887
+ // src/lib/PayloadStore.ts
888
+ var PayloadStore = class {
889
+ latest = [];
890
+ archivist;
891
+ deleteListeners = [];
892
+ insertListeners = [];
893
+ listeners = [];
894
+ constructor(archivist) {
895
+ this.archivist = archivist;
896
+ }
897
+ /**
898
+ * Initialize listeners on the archivist that update class member variables when new payloads are inserted
899
+ */
900
+ static async create({
901
+ archivist,
902
+ getLatest,
903
+ idFunction
904
+ }) {
905
+ const instance = new this(archivist);
906
+ const insertListener = async ({ payloads }) => {
907
+ if (payloads.some(idFunction)) {
908
+ const latest = await getLatest();
909
+ if (isEqual(latest, instance.latest)) return;
910
+ instance.latest = latest;
911
+ instance.emitChange();
912
+ }
913
+ };
914
+ const deleteListener = async () => {
915
+ instance.latest = await getLatest();
916
+ instance.emitChange();
917
+ };
918
+ const weakRefInsertListener = new WeakRef(insertListener);
919
+ const weakRefDeleteListener = new WeakRef(deleteListener);
920
+ const insertListenerRef = weakRefInsertListener.deref();
921
+ const deleteListenerRef = weakRefDeleteListener.deref();
922
+ if (insertListenerRef) instance.archivist.on("inserted", insertListenerRef);
923
+ if (deleteListenerRef) instance.archivist.on("deleted", deleteListenerRef);
924
+ instance.insertListeners.push(weakRefInsertListener);
925
+ instance.deleteListeners.push(weakRefDeleteListener);
926
+ instance.latest = await getLatest();
927
+ return instance;
928
+ }
929
+ /**
930
+ * Remove all listeners and reset their class members
931
+ */
932
+ cleanupListeners() {
933
+ this.removeListeners(this.insertListeners, "inserted");
934
+ this.removeListeners(this.deleteListeners, "deleted");
935
+ this.insertListeners = [];
936
+ this.deleteListeners = [];
937
+ }
938
+ /**
939
+ * Get the current value of the store
940
+ */
941
+ getSnapshot() {
942
+ return this.latest;
943
+ }
944
+ /**
945
+ * Add a call back function that is invoked when new Payloads are inserted
946
+ * @param onStoreChange
947
+ */
948
+ subscribe(onStoreChange) {
949
+ this.listeners.push(onStoreChange);
950
+ return () => {
951
+ this.listeners = this.listeners.filter((l) => l !== onStoreChange);
952
+ };
953
+ }
954
+ emitChange() {
955
+ for (const listener of this.listeners) {
956
+ listener();
957
+ }
958
+ }
959
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
960
+ removeListeners(listeners, eventName) {
961
+ for (const listener of listeners) {
962
+ const listenerRef = listener.deref();
963
+ if (listenerRef) this.archivist.off(eventName, listenerRef);
964
+ }
965
+ }
966
+ };
967
+
968
+ // src/lib/tokenPlacesSplit.ts
969
+ import { assertEx as assertEx6 } from "@xylabs/sdk-js";
970
+ var tokenPlacesSplit = (value, places) => {
971
+ assertEx6(places >= 0, () => "Places has to be >= 0");
972
+ const factor = BigInt(10 ** Math.abs(places));
973
+ const remainder = value % factor;
974
+ const wholeValue = value / factor;
975
+ return [wholeValue, remainder];
976
+ };
977
+ var tokenPlacesSplitString = (value, places) => {
978
+ if (value === void 0) {
979
+ return "-";
980
+ }
981
+ const [wholeValue, remainder] = tokenPlacesSplit(value, places);
982
+ return `${wholeValue}.${remainder.toString().padStart(Math.abs(places), "0")}`;
983
+ };
984
+
985
+ // src/loadOsNode.ts
986
+ import { IndexedDbArchivist } from "@xyo-network/archivist-indexeddb";
987
+ import { IndexedDbPayloadDiviner } from "@xyo-network/diviner-payload-indexeddb";
988
+ import { ManifestWrapper, ModuleFactoryLocator as ModuleFactoryLocator3 } from "@xyo-network/sdk-js";
989
+ var OS_NODE_PATH = "1'";
990
+ var getDefaultOsNodeLocator = () => {
991
+ const locator = new ModuleFactoryLocator3();
992
+ locator.register(IndexedDbArchivist.factory(), { "network.xyo.archivist.persistence.scope": "device" });
993
+ locator.register(IndexedDbPayloadDiviner.factory(), { "network.xyo.archivist.persistence.scope": "device" });
994
+ return locator;
995
+ };
996
+ var loadOsNode = async (osWallet, locator) => {
997
+ try {
998
+ const osNodeWallet = await osWallet.derivePath(OS_NODE_PATH);
999
+ const osNodeLocator = locator ?? getDefaultOsNodeLocator();
1000
+ const manifestWrapper = new ManifestWrapper(os_node_manifest_default, osNodeWallet, osNodeLocator);
1001
+ const osNode = (await manifestWrapper.loadNodes())[0];
1002
+ return [osNode];
1003
+ } catch (e) {
1004
+ const error = e;
1005
+ console.error(`Error creating os node: ${error.message}`);
1006
+ console.error(`Error creating os node: ${error.stack}`);
1007
+ throw new Error(`Error creating os node: ${error.message}`, { cause: e });
1008
+ }
1009
+ };
1010
+
1011
+ // src/registration/DappRegistrationService.ts
1012
+ import {
1013
+ forget as forget2,
1014
+ fulfilled,
1015
+ rejected
1016
+ } from "@xylabs/sdk-js";
1017
+ import {
1018
+ DappIntentTypes,
1019
+ DappMode as DappMode2,
1020
+ isRegisteredDappAccessDappSet,
1021
+ isRegisteredDappExposedDappSet
1022
+ } from "@xyo-network/os-model";
1023
+ import { ModuleFactoryLocator as ModuleFactoryLocator7 } from "@xyo-network/sdk-js";
1024
+
1025
+ // src/intent/Caller.ts
1026
+ import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema2 } from "@xyo-network/diviner-payload-model";
1027
+ import { DappIntentSchema, DappMode } from "@xyo-network/os-model";
1028
+ var DappIntentCaller = class _DappIntentCaller extends DappCallerBase {
1029
+ static OsDappName = "XyOs";
1030
+ constructor(context) {
1031
+ super(context);
1032
+ }
1033
+ /**
1034
+ * Build a new intent
1035
+ * @param sourceDappId
1036
+ * @param intent
1037
+ * @param targetDappId
1038
+ * @param targetMode
1039
+ * @param params?
1040
+ * @returns DappIntent
1041
+ */
1042
+ static buildIntent(sourceDappId, intent, targetDappId, targetMode = DappMode.Window, params) {
1043
+ return {
1044
+ intent,
1045
+ params: params ?? "",
1046
+ schema: DappIntentSchema,
1047
+ sourceDappId,
1048
+ targetDappId,
1049
+ targetMode: targetMode ?? DappMode.Window,
1050
+ timestamp: Date.now()
1051
+ };
1052
+ }
1053
+ // Add a new intent
1054
+ async addIntent(id, intent, mode) {
1055
+ const intentArchivist = await this.getDappIntentArchivist();
1056
+ const newIntent = _DappIntentCaller.buildIntent(id, intent, mode);
1057
+ await intentArchivist.insert([newIntent]);
1058
+ }
1059
+ // Get all intents
1060
+ async allIntents() {
1061
+ const archivist = await this.getDappIntentArchivist();
1062
+ return await archivist.all();
1063
+ }
1064
+ // Get the latest intent saved to the archivist
1065
+ async latestIntent() {
1066
+ const archivist = await this.getDappIntentArchivist();
1067
+ return (await archivist.all()).at(-1);
1068
+ }
1069
+ // Get the latest intent for a dapp
1070
+ async latestIntentForDappName(dappName) {
1071
+ const diviner = await this.getDappIntentArchivistPayloadDiviner();
1072
+ const query = {
1073
+ limit: 1,
1074
+ order: "desc",
1075
+ schema: PayloadDivinerQuerySchema2,
1076
+ sourceDappId: dappName
1077
+ };
1078
+ return await diviner.divine([query]);
1079
+ }
1080
+ };
1081
+
1082
+ // src/intent/Resource.ts
1083
+ import { assertEx as assertEx7 } from "@xylabs/sdk-js";
1084
+ import { isDappIntent } from "@xyo-network/os-model";
1085
+ var NO_RESULTS = [];
1086
+ var DappIntentResource = class extends DappCallerBase {
1087
+ _allDappIntents;
1088
+ _latestDappIntent;
1089
+ constructor(context) {
1090
+ super(context);
1091
+ }
1092
+ get allDappIntents() {
1093
+ return assertEx7(this._allDappIntents, () => "allDappIntents not set");
1094
+ }
1095
+ get latestDappIntent() {
1096
+ return assertEx7(this._latestDappIntent, () => "latestDappIntent not set");
1097
+ }
1098
+ get subscriptions() {
1099
+ return {
1100
+ allDappIntents: (cb) => this.allDappIntents.subscribe(cb),
1101
+ latestDappIntent: (cb) => this.latestDappIntent.subscribe(cb)
1102
+ };
1103
+ }
1104
+ get views() {
1105
+ return {
1106
+ allDappIntents: () => this.allDappIntents.getSnapshot(),
1107
+ latestDappIntent: () => this.latestDappIntent.getSnapshot()
1108
+ };
1109
+ }
1110
+ cleanupListeners() {
1111
+ this.latestDappIntent.cleanupListeners();
1112
+ this.allDappIntents.cleanupListeners();
1113
+ }
1114
+ async start() {
1115
+ const archivist = await this.getDappIntentArchivist();
1116
+ this._allDappIntents = await PayloadStore.create({
1117
+ archivist,
1118
+ getLatest: async () => await archivist.all(),
1119
+ idFunction: isDappIntent
1120
+ });
1121
+ this._latestDappIntent = await PayloadStore.create({
1122
+ archivist,
1123
+ getLatest: async () => {
1124
+ const all = await archivist.all();
1125
+ const result = all.length > 0 ? [all.at(-1)] : NO_RESULTS;
1126
+ return result;
1127
+ },
1128
+ idFunction: isDappIntent
1129
+ });
1130
+ }
1131
+ };
1132
+
1133
+ // src/system/ManageSystemDapps.ts
1134
+ import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
1135
+ import semver from "semver";
1136
+
1137
+ // src/system/Queries.ts
1138
+ import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema3 } from "@xyo-network/diviner-payload-model";
1139
+ import {
1140
+ DappConfigSchema,
1141
+ DappIconSchema,
1142
+ DappWidgetConfigSchema,
1143
+ UnregisteredDappAccessSchema
1144
+ } from "@xyo-network/os-model";
1145
+ import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
1146
+ var SystemDappQueries = {
1147
+ async getDappAccess(diviner, name, version) {
1148
+ const accessQuery = {
1149
+ order: "desc",
1150
+ registeringDappId: name,
1151
+ schema: PayloadDivinerQuerySchema3,
1152
+ schemas: [UnregisteredDappAccessSchema],
1153
+ version
1154
+ };
1155
+ return await diviner.divine([accessQuery]);
1156
+ },
1157
+ async getLatestConfig(diviner, name) {
1158
+ const configQuery = {
1159
+ limit: 1,
1160
+ name,
1161
+ order: "desc",
1162
+ schema: PayloadDivinerQuerySchema3,
1163
+ schemas: [DappConfigSchema]
1164
+ };
1165
+ const [dappConfig] = await diviner.divine([configQuery]);
1166
+ return dappConfig;
1167
+ },
1168
+ async getLatestIcon(diviner, name, version) {
1169
+ const iconQuery = {
1170
+ name,
1171
+ order: "desc",
1172
+ schema: PayloadDivinerQuerySchema3,
1173
+ schemas: [DappIconSchema],
1174
+ version
1175
+ };
1176
+ const [dappIcon] = await diviner.divine([iconQuery]);
1177
+ return dappIcon;
1178
+ },
1179
+ async getWidgetConfigs(diviner, name, version) {
1180
+ const widgetConfigQuery = {
1181
+ dappId: name,
1182
+ order: "desc",
1183
+ schema: PayloadDivinerQuerySchema3,
1184
+ schemas: [DappWidgetConfigSchema],
1185
+ version
1186
+ };
1187
+ const widgetConfigs = await diviner.divine([widgetConfigQuery]);
1188
+ const uniqueConfigs = {};
1189
+ for (const widgetConfig of widgetConfigs) {
1190
+ const hash = await PayloadBuilder3.dataHash(widgetConfig);
1191
+ uniqueConfigs[widgetConfig.mode ?? hash] = widgetConfig;
1192
+ }
1193
+ return Object.values(uniqueConfigs);
1194
+ }
1195
+ };
1196
+
1197
+ // src/system/ManageSystemDapps.ts
1198
+ var ManageSystemDapps = class extends OsCallerBase {
1199
+ defaultSystemDappParams;
1200
+ defaultSystemDapps;
1201
+ defaultSystemNames;
1202
+ developmentMode;
1203
+ locator;
1204
+ onErrorCallbacks = [];
1205
+ constructor(context, defaultSystemNames, defaultSystemDapps, defaultSystemDappParams, locator, developmentMode) {
1206
+ super(context);
1207
+ this.defaultSystemNames = defaultSystemNames;
1208
+ this.defaultSystemDapps = defaultSystemDapps;
1209
+ this.defaultSystemDappParams = defaultSystemDappParams;
1210
+ this.locator = locator;
1211
+ this.developmentMode = developmentMode;
1212
+ }
1213
+ /**
1214
+ * Add a callback to listen for errors throwing during system dapp registration
1215
+ * @param errorListener
1216
+ */
1217
+ addErrorListener(errorListener) {
1218
+ this.onErrorCallbacks.push(errorListener);
1219
+ }
1220
+ /**
1221
+ * Installs the dapps into the OS and builds the appropriate DappSet
1222
+ */
1223
+ async install() {
1224
+ await this.insertPayloads();
1225
+ return await this.latestSets();
1226
+ }
1227
+ async freshInstall(archivist) {
1228
+ await archivist.insert(this.defaultSystemDapps);
1229
+ }
1230
+ async insertPayloads() {
1231
+ const archivist = this.developmentMode ? await this.getDappsArchivistDevelopment() : await this.getDappsArchivist();
1232
+ try {
1233
+ const allPayloads = await archivist.all();
1234
+ if (allPayloads.length === 0) {
1235
+ await this.freshInstall(archivist);
1236
+ return true;
1237
+ }
1238
+ for (const systemDappPayload of this.defaultSystemDapps) {
1239
+ try {
1240
+ const validSemver = semver.valid(systemDappPayload.version);
1241
+ if (!validSemver) throw new Error("semver is a valid type (string) but was not able to be parsed");
1242
+ } catch (e) {
1243
+ console.error(`${systemDappPayload.version} does not appear to be a valid semver value`, e);
1244
+ continue;
1245
+ }
1246
+ const [existing] = await archivist.get([await PayloadBuilder4.dataHash(systemDappPayload)]);
1247
+ if (existing) continue;
1248
+ await archivist.insert([systemDappPayload]);
1249
+ }
1250
+ return true;
1251
+ } catch (e) {
1252
+ console.error("error installing system dapps");
1253
+ throw e;
1254
+ }
1255
+ }
1256
+ async latestSets() {
1257
+ const diviner = this.developmentMode ? await this.getDappsArchivistPayloadDivinerDevelopment() : await this.getDappsArchivistPayloadDiviner();
1258
+ const dappSets = [];
1259
+ const failedPayloads = [];
1260
+ for (const name of this.defaultSystemNames) {
1261
+ try {
1262
+ const dappConfig = await SystemDappQueries.getLatestConfig(diviner, name);
1263
+ if (!dappConfig) {
1264
+ console.error(`No config found for dapp ${name}`);
1265
+ continue;
1266
+ }
1267
+ const dappIcon = await SystemDappQueries.getLatestIcon(diviner, name, dappConfig.version);
1268
+ if (!dappIcon) {
1269
+ console.error(`No icon found for dapp ${dappConfig.name}`);
1270
+ failedPayloads.push(dappConfig);
1271
+ continue;
1272
+ }
1273
+ const dappAccess = await SystemDappQueries.getDappAccess(diviner, name, dappConfig.version);
1274
+ const dappParams = this.defaultSystemDappParams[dappConfig.name];
1275
+ if (!dappParams) {
1276
+ console.error(`No params found for dapp ${dappConfig.name}. Did you forget to add it to OsDappParams?`);
1277
+ failedPayloads.push(dappConfig);
1278
+ continue;
1279
+ }
1280
+ const dappWidgetConfigs = await SystemDappQueries.getWidgetConfigs(diviner, name, dappConfig.version);
1281
+ dappSets.push({
1282
+ dapp: {
1283
+ accessors: dappAccess,
1284
+ config: dappConfig,
1285
+ icon: dappIcon,
1286
+ params: dappParams,
1287
+ widgetConfigs: dappWidgetConfigs
1288
+ }
1289
+ });
1290
+ } catch {
1291
+ console.error(`Failed to build dapp ${name}`);
1292
+ }
1293
+ }
1294
+ if (failedPayloads.length > 0) {
1295
+ for (const cb of this.onErrorCallbacks) cb(failedPayloads);
1296
+ }
1297
+ return dappSets;
1298
+ }
1299
+ };
1300
+
1301
+ // src/XyOsDapp.ts
1302
+ import { assertEx as assertEx9 } from "@xylabs/sdk-js";
1303
+ import { DappPackageManifestPayloadSchema as DappPackageManifestPayloadSchema2 } from "@xyo-network/os-model";
1304
+ import {
1305
+ ManifestWrapper as ManifestWrapper2,
1306
+ ModuleFactoryLocator as ModuleFactoryLocator5
1307
+ } from "@xyo-network/sdk-js";
1308
+
1309
+ // src/manifests/dapp-window.manifest.json
1310
+ var dapp_window_manifest_default = {
1311
+ $schema: "https://raw.githubusercontent.com/XYOracleNetwork/sdk-xyo-client-js/main/packages/manifest/src/compilations/dapp-package-manifest-schema.json",
1312
+ nodes: [
1313
+ {
1314
+ config: {
1315
+ accountPath: "0'",
1316
+ name: "Dapp",
1317
+ schema: "network.xyo.node.config"
1318
+ },
1319
+ modules: {
1320
+ private: [],
1321
+ public: [
1322
+ {
1323
+ config: {
1324
+ accountPath: "0'/0'",
1325
+ name: "DappArchivist",
1326
+ schema: "network.xyo.archivist.memory.config"
1327
+ }
1328
+ },
1329
+ {
1330
+ config: {
1331
+ accountPath: "0'/1'",
1332
+ archivist: "DappArchivist",
1333
+ labels: {
1334
+ "network.xyo.generic.payload.diviner": "GenericPayloadDiviner"
1335
+ },
1336
+ name: "DappArchivistPayloadDiviner",
1337
+ schema: "network.xyo.diviner.payload.generic.config"
1338
+ }
1339
+ }
1340
+ ]
1341
+ }
1342
+ }
1343
+ ],
1344
+ schema: "network.xyo.manifest.package.dapp"
1345
+ };
1346
+
1347
+ // src/XyOsBase.ts
1348
+ import { assertEx as assertEx8, BaseEmitter as BaseEmitter2 } from "@xylabs/sdk-js";
1349
+ import { ModuleFactoryLocator as ModuleFactoryLocator4 } from "@xyo-network/sdk-js";
1350
+ import { Mutex as Mutex2 } from "async-mutex";
1351
+ var XyOsContextBase = class extends BaseEmitter2 {
1352
+ _bootMutex = new Mutex2();
1353
+ _platformLocator;
1354
+ _root;
1355
+ get bios() {
1356
+ return this.kernel?.bios;
1357
+ }
1358
+ get eventBus() {
1359
+ return assertEx8(this.params.eventBus, () => "Missing event bus");
1360
+ }
1361
+ get exposedNode() {
1362
+ throw new Error("Method not implemented. [exposedNode]");
1363
+ }
1364
+ get exposedNodeOuter() {
1365
+ throw new Error("Method not implemented. [exposedNodeOuter]");
1366
+ }
1367
+ get installedDapps() {
1368
+ return [];
1369
+ }
1370
+ get kernel() {
1371
+ return void 0;
1372
+ }
1373
+ get manifest() {
1374
+ return assertEx8(this.params.manifest, () => "Missing manifest");
1375
+ }
1376
+ get platformLocator() {
1377
+ this._platformLocator = this._platformLocator ?? this.params.platformLocator ?? new ModuleFactoryLocator4();
1378
+ return this._platformLocator;
1379
+ }
1380
+ get possibleRoot() {
1381
+ return this._root;
1382
+ }
1383
+ get root() {
1384
+ return assertEx8(this._root, () => "XyOs root not set (probably not yet booted)");
1385
+ }
1386
+ get runningDapps() {
1387
+ return [];
1388
+ }
1389
+ get signerPaths() {
1390
+ return this.params.signerPaths;
1391
+ }
1392
+ get state() {
1393
+ return this._root ? "running" : "stopped";
1394
+ }
1395
+ get user() {
1396
+ throw new Error("Method not implemented. [user]");
1397
+ }
1398
+ boot(_wallet, _locator) {
1399
+ throw new Error("Method not implemented. [boot]");
1400
+ }
1401
+ buildDapp(_manifest, _dappId) {
1402
+ throw new Error("Method not implemented. [buildDapp]");
1403
+ }
1404
+ dappByName(_dappId) {
1405
+ throw new Error("Method not implemented. [runningDapp]");
1406
+ }
1407
+ getDappParams(_dappId) {
1408
+ throw new Error("Method not implemented. [getDappParams]");
1409
+ }
1410
+ getStack(_stackName) {
1411
+ throw new Error("Method not implemented. [getStack]");
1412
+ }
1413
+ installDapp(_dappId) {
1414
+ throw new Error("Method not implemented. [installDapp]");
1415
+ }
1416
+ monitor(_fn, _eventConfig) {
1417
+ throw new Error("Method not implemented. [monitor]");
1418
+ }
1419
+ shutdown() {
1420
+ throw new Error("Method not implemented. [shutdown]");
1421
+ }
1422
+ startDapp(_dappId) {
1423
+ throw new Error("Method not implemented. [startDapp]");
1424
+ }
1425
+ stopDapp(_dappId) {
1426
+ throw new Error("Method not implemented. [stopDapp]");
1427
+ }
1428
+ uninstallDapp(_dappId) {
1429
+ throw new Error("Method not implemented. [uninstallDapp]");
1430
+ }
1431
+ };
1432
+
1433
+ // src/XyOsDapp.ts
1434
+ var XyOsDapp = class extends XyOsContextBase {
1435
+ dapp;
1436
+ constructor(params) {
1437
+ super(params);
1438
+ this.dapp = { ...params.dapp };
1439
+ }
1440
+ get eventBus() {
1441
+ return this.parent.eventBus;
1442
+ }
1443
+ get exposedNode() {
1444
+ return this.parent.exposedNode;
1445
+ }
1446
+ get exposedNodeOuter() {
1447
+ return this.parent.exposedNodeOuter;
1448
+ }
1449
+ /**
1450
+ * @deprecated Dapps should not have access to the bios. This is done for the
1451
+ * settings dapp, but should be refactored out. Bios could possibly be an
1452
+ * optional property of the parent context passed in for dapps that require
1453
+ * elevated permissions.
1454
+ * ^^^ I believe we may want this here in that is a dApp requests access to the bios it will optionally be there
1455
+ */
1456
+ get kernel() {
1457
+ return assertEx9(this.parent.kernel, () => "Missing kernel");
1458
+ }
1459
+ get parent() {
1460
+ return this.params.parent;
1461
+ }
1462
+ get stacks() {
1463
+ return [];
1464
+ }
1465
+ get user() {
1466
+ return this.params.user;
1467
+ }
1468
+ async boot(wallet, locator) {
1469
+ return await this._bootMutex.runExclusive(async () => {
1470
+ console.log("XyOsDapp:boot:start", wallet.address, this.dapp.id);
1471
+ assertEx9(this._root === void 0, () => "Dapp already booted");
1472
+ const finalLocator = locator ? (this.params.locator ?? new ModuleFactoryLocator5()).merge(locator) : this.params.locator ?? new ModuleFactoryLocator5();
1473
+ console.log("XyOsDapp:boot:finalLocator", finalLocator);
1474
+ const dappNodesWrapper = new ManifestWrapper2({ ...this.manifest, schema: DappPackageManifestPayloadSchema2 }, wallet, finalLocator);
1475
+ const dappNodes = await dappNodesWrapper.loadNodes();
1476
+ const manifest = dapp_window_manifest_default;
1477
+ const dappManifestWallet = await wallet.derivePath("99999");
1478
+ manifest.nodes[0].config.name = this.dapp.name + "Root";
1479
+ const wrapper = new ManifestWrapper2(
1480
+ { ...manifest, schema: DappPackageManifestPayloadSchema2 },
1481
+ dappManifestWallet,
1482
+ finalLocator
1483
+ );
1484
+ const node = await wrapper.loadNodeFromIndex(0);
1485
+ for (const dappNode of dappNodes) {
1486
+ await node.register(dappNode);
1487
+ await node.attach(dappNode.address, true);
1488
+ }
1489
+ this._root = node;
1490
+ console.log("XyOsDapp:boot:finish", wallet.address, this.dapp.id);
1491
+ return this;
1492
+ });
1493
+ }
1494
+ getStack(stackName) {
1495
+ return this.parent.getStack(stackName);
1496
+ }
1497
+ };
1498
+
1499
+ // src/registration/DappRegistry.ts
1500
+ import {
1501
+ DappRegisteredSchema,
1502
+ DappRegisteredState,
1503
+ isRegisteredDappAccess
1504
+ } from "@xyo-network/os-model";
1505
+ import { HDWallet as HDWallet4 } from "@xyo-network/sdk-js";
1506
+
1507
+ // src/registration/ValidateDappAccessDiviner/Config.ts
1508
+ import { asSchema as asSchema2, isPayloadOfSchemaType } from "@xyo-network/payload-model";
1509
+ var FailedAccessorSchema = asSchema2("network.xyo.os.failed.accessor.registration", true);
1510
+ var isFailedAccessor = isPayloadOfSchemaType(FailedAccessorSchema);
1511
+ var ValidateDappAccessDivinerConfigSchema = asSchema2("network.xyo.os.dapp.access.registration.validate", true);
1512
+
1513
+ // src/registration/ValidateDappAccessDiviner/Diviner.ts
1514
+ import { AbstractDiviner } from "@xyo-network/diviner-abstract";
1515
+ import {
1516
+ isDappPackageManifestPayload,
1517
+ isUnregisteredDappAccess,
1518
+ RegisteredDappAccessSchema
1519
+ } from "@xyo-network/os-model";
1520
+ import {
1521
+ HDWallet as HDWallet3,
1522
+ ManifestWrapper as ManifestWrapper3,
1523
+ ModuleFactoryLocator as ModuleFactoryLocator6,
1524
+ PackageManifestPayloadSchema
1525
+ } from "@xyo-network/sdk-js";
1526
+
1527
+ // src/models/access/ValidDappAccessInterfaces.ts
1528
+ import { RegisteredNames, RegisteredNamesInterface } from "@xyo-network/os-model";
1529
+ var ValidDappAccessInterfaces = { [RegisteredNames]: RegisteredNamesInterface };
1530
+
1531
+ // src/registration/ValidateDappAccessDiviner/Diviner.ts
1532
+ var ValidateDappAccessDiviner = class extends AbstractDiviner {
1533
+ static configSchemas = [ValidateDappAccessDivinerConfigSchema];
1534
+ async divineHandler(payloads) {
1535
+ const dappManifest = payloads?.filter(isDappPackageManifestPayload) ?? [];
1536
+ const accessors = payloads?.filter(isUnregisteredDappAccess) ?? [];
1537
+ const dappParams = this.params.dappParams;
1538
+ if (dappManifest.length > 1) {
1539
+ throw new Error("Only one dapp manifest payload is allowed");
1540
+ }
1541
+ if (dappManifest.length === 0 || accessors.length === 0) {
1542
+ return [];
1543
+ }
1544
+ const registeredAccessors = [];
1545
+ const failedAccessors = [];
1546
+ for (const access of accessors) {
1547
+ try {
1548
+ if (access) {
1549
+ const dappAccessInterface = ValidDappAccessInterfaces[access.name];
1550
+ if (!dappAccessInterface) {
1551
+ console.warn("Invalid dapp access interface", access.name);
1552
+ continue;
1553
+ }
1554
+ const dappManifestToTest = dappPackageManifestToPackageManifest(dappManifest[0]);
1555
+ const dappChildren = await getNodeChildren(dappManifestToTest, dappParams);
1556
+ const interfaceChildren = await getNodeChildren(dappAccessInterface.manifest, dappParams);
1557
+ const valid = compareChildren(interfaceChildren, dappChildren);
1558
+ if (valid) {
1559
+ const payload = {
1560
+ ...access,
1561
+ schema: RegisteredDappAccessSchema,
1562
+ timestamp: Date.now()
1563
+ };
1564
+ registeredAccessors.push(payload);
1565
+ } else {
1566
+ const failedRegistration = {
1567
+ accessor: access,
1568
+ errorMessage: "Invalid dapp access interface",
1569
+ schema: FailedAccessorSchema
1570
+ };
1571
+ failedAccessors.push(failedRegistration);
1572
+ }
1573
+ }
1574
+ } catch (e) {
1575
+ failedAccessors.push(
1576
+ {
1577
+ accessor: access,
1578
+ errorMessage: e.message,
1579
+ schema: FailedAccessorSchema
1580
+ }
1581
+ );
1582
+ }
1583
+ }
1584
+ return [...registeredAccessors, ...failedAccessors];
1585
+ }
1586
+ };
1587
+ var compareChildren = (interfaceChildren, dappChildren) => {
1588
+ return interfaceChildren.every((interfaceChild) => Object.values(interfaceChild).every((interfaceChildName) => dappChildren.some((dappChild) => Object.values(dappChild).includes(interfaceChildName))));
1589
+ };
1590
+ var dappPackageManifestToPackageManifest = (dappPackageManifest) => {
1591
+ return {
1592
+ ...dappPackageManifest,
1593
+ schema: PackageManifestPayloadSchema
1594
+ };
1595
+ };
1596
+ var getChildrenFromNode = async (node) => {
1597
+ const nodeManifest = (await node.state())?.[0];
1598
+ return nodeManifest.status?.children;
1599
+ };
1600
+ var getNodeChildren = async (manifestToTest, dappParams) => {
1601
+ const testNodes = await getNodeToTest(manifestToTest, dappParams);
1602
+ const children = [];
1603
+ for (const node of testNodes) {
1604
+ const nodeChildren = await getChildrenFromNode(node);
1605
+ if (nodeChildren) {
1606
+ children.push(nodeChildren);
1607
+ }
1608
+ }
1609
+ return children;
1610
+ };
1611
+ var getNodeToTest = async (manifestToTest, dappParams) => {
1612
+ const dappManifestWrapper = new ManifestWrapper3(manifestToTest, await HDWallet3.random(), dappParams.locator ?? new ModuleFactoryLocator6());
1613
+ return await dappManifestWrapper.loadNodes();
1614
+ };
1615
+
1616
+ // src/registration/DappRegistry.ts
1617
+ var DappRegistry = class {
1618
+ dappRegistry = /* @__PURE__ */ new Map();
1619
+ dappSeedPhraseRepository;
1620
+ constructor(dappSeedPhraseRepository) {
1621
+ this.dappSeedPhraseRepository = dappSeedPhraseRepository;
1622
+ }
1623
+ /**
1624
+ * Register a Dapp with window manager and if successful, return its id
1625
+ * @param dapp Manifest and UI of the Dapp to register
1626
+ * @returns dapp with registration fields
1627
+ */
1628
+ async registerDapp(dapp) {
1629
+ if (dapp) {
1630
+ const {
1631
+ exposedModuleIds,
1632
+ manifest,
1633
+ modes,
1634
+ name,
1635
+ version,
1636
+ params,
1637
+ widgetConfigs
1638
+ } = this.extractDappProperties(dapp);
1639
+ try {
1640
+ const walletId = await this.dappSeedPhraseRepository.findOrCreate(name);
1641
+ const registeredAccessors = await this.validateDappAccessPayloads(manifest, dapp.accessors, params);
1642
+ const registeredDapp = {
1643
+ accessors: registeredAccessors,
1644
+ config: {
1645
+ exposedModuleIds,
1646
+ manifest,
1647
+ modes,
1648
+ name,
1649
+ schema: DappRegisteredSchema,
1650
+ state: DappRegisteredState.Registered,
1651
+ version,
1652
+ // attach the walletId to a registered dapp so it can request it back in the future
1653
+ walletId
1654
+ },
1655
+ params,
1656
+ widgetConfigs
1657
+ };
1658
+ if (this.dappRegistry.get(name)) {
1659
+ console.warn("tried to register two dapps with the same name", name);
1660
+ return null;
1661
+ }
1662
+ this.dappRegistry.set(name, registeredDapp);
1663
+ return registeredDapp;
1664
+ } catch (e) {
1665
+ console.error("Error registeringDapp", e);
1666
+ return null;
1667
+ }
1668
+ } else {
1669
+ return null;
1670
+ }
1671
+ }
1672
+ /**
1673
+ * Unregister a dapp so it can no longer be launched
1674
+ * @param dappId
1675
+ */
1676
+ unregisterDapp(dappId) {
1677
+ this.dappRegistry.delete(dappId);
1678
+ }
1679
+ extractDappProperties(dapp) {
1680
+ const {
1681
+ params,
1682
+ config,
1683
+ widgetConfigs
1684
+ } = dapp;
1685
+ const {
1686
+ exposedModuleIds,
1687
+ manifest,
1688
+ modes,
1689
+ name,
1690
+ sources,
1691
+ version
1692
+ } = config;
1693
+ return {
1694
+ exposedModuleIds,
1695
+ manifest,
1696
+ modes,
1697
+ name,
1698
+ params,
1699
+ sources,
1700
+ version,
1701
+ widgetConfigs
1702
+ };
1703
+ }
1704
+ async validateDappAccessPayloads(manifest, accessors = [], params) {
1705
+ const validateDappAccess = await ValidateDappAccessDiviner.create({
1706
+ account: await HDWallet4.random(),
1707
+ config: { schema: ValidateDappAccessDivinerConfigSchema },
1708
+ dappParams: params
1709
+ });
1710
+ const payloads = await validateDappAccess.divine([manifest, ...accessors]);
1711
+ const failedAccessors = payloads.filter(isFailedAccessor);
1712
+ const registeredAccessors = payloads.filter(isRegisteredDappAccess);
1713
+ if (failedAccessors.length > 0) {
1714
+ console.error("Failed to register all dapp accessors", failedAccessors);
1715
+ }
1716
+ return registeredAccessors;
1717
+ }
1718
+ };
1719
+
1720
+ // src/registration/DappRegistrationService.ts
1721
+ var DappRegistrationService = class {
1722
+ // Dapps that have been built with their own context
1723
+ builtDapps = {};
1724
+ dappRegistry;
1725
+ dappSeedPhraseRepository;
1726
+ manageSystemDapps;
1727
+ // Dapps that have been registered with dappAccessRequests
1728
+ registeredAccessDappSets = /* @__PURE__ */ new Set();
1729
+ // Dapps that have been registered with the dapp registry
1730
+ registeredDappSets = /* @__PURE__ */ new Set();
1731
+ // Dapps that have been registered with exposeDappRequests
1732
+ registeredExposedDappSets = /* @__PURE__ */ new Set();
1733
+ context;
1734
+ dappAccessRequestConnection = dappAccessRequestConnection();
1735
+ developmentMode;
1736
+ exposeDappRequestConnection = exposeDappRequestConnection();
1737
+ locator;
1738
+ params;
1739
+ constructor(context, params, locator = new ModuleFactoryLocator7(), developmentMode) {
1740
+ this.context = context;
1741
+ this.params = params ?? {
1742
+ dappNames: [],
1743
+ dappParams: {},
1744
+ dappPayloads: []
1745
+ };
1746
+ this.locator = locator;
1747
+ this.developmentMode = developmentMode;
1748
+ this.manageSystemDapps = new ManageSystemDapps(
1749
+ context,
1750
+ this.params?.dappNames ?? [],
1751
+ this.params?.dappPayloads ?? [],
1752
+ this.params?.dappParams ?? {},
1753
+ this.locator,
1754
+ this.developmentMode
1755
+ );
1756
+ this.dappSeedPhraseRepository = new DappSeedPhraseRepository(context, this.params?.dappNames ?? []);
1757
+ this.dappRegistry = new DappRegistry(this.dappSeedPhraseRepository);
1758
+ this.addConnectionRequests();
1759
+ }
1760
+ async buildDapp(manifest, dappId = NameTransforms.slug(manifest.nodes[0]?.config.name), name = NameTransforms.moduleName(manifest.nodes[0]?.config.name)) {
1761
+ const dapp = new XyOsDapp({
1762
+ dapp: { id: dappId, name },
1763
+ locator: this.locator,
1764
+ manifest,
1765
+ parent: this.context,
1766
+ user: await this.getUser()
1767
+ });
1768
+ this.builtDapps[dappId] = dapp;
1769
+ return dapp;
1770
+ }
1771
+ getParamsForRegisteredDapp(dappId) {
1772
+ return this.params?.dappParams[dappId];
1773
+ }
1774
+ async start() {
1775
+ const systemDapps = await this.context.monitor(async () => await this.manageSystemDapps.install(), { name: "Install System dApps" });
1776
+ const activeDapps = systemDapps.filter(({ dapp }) => dapp.icon.active === true);
1777
+ const results = await Promise.allSettled(
1778
+ activeDapps.map(async (dappSet) => {
1779
+ const { dapp } = dappSet;
1780
+ const registeredDapp = await this.dappRegistry.registerDapp(dapp);
1781
+ const result = { dapp: registeredDapp, dappIcon: dapp.icon };
1782
+ const forgetHandlers = async () => {
1783
+ try {
1784
+ await this.postRegistrationHandlers(result);
1785
+ } catch (e) {
1786
+ console.error("Error in post registration handlers", e);
1787
+ }
1788
+ };
1789
+ forget2(forgetHandlers());
1790
+ return result;
1791
+ })
1792
+ );
1793
+ const failed = results.filter(rejected).map((result) => {
1794
+ const reason = result.reason;
1795
+ return reason instanceof Error ? reason.message : String(reason);
1796
+ });
1797
+ const succeeded = results.filter(fulfilled).map((result) => result.value);
1798
+ for (const registeredDapp of succeeded) this.registeredDappSets.add(registeredDapp);
1799
+ return { failed, succeeded };
1800
+ }
1801
+ addConnectionRequests() {
1802
+ this.context.eventBus.addConnection(this.dappAccessRequestConnection);
1803
+ this.context.eventBus.addConnection(this.exposeDappRequestConnection);
1804
+ }
1805
+ /**
1806
+ * A method to get the user property from context and eventually modify it before handing it to a dapp
1807
+ * i.e. curating user-approved signers
1808
+ */
1809
+ getUser() {
1810
+ return this.context.user;
1811
+ }
1812
+ async postRegistrationHandlers(registeredDapp) {
1813
+ if (registeredDapp.dapp) {
1814
+ if (isRegisteredDappExposedDappSet(registeredDapp)) {
1815
+ this.registeredExposedDappSets.add(registeredDapp);
1816
+ const exposeIntent = DappIntentCaller.buildIntent(
1817
+ DappIntentCaller.OsDappName,
1818
+ DappIntentTypes.Launch,
1819
+ registeredDapp.dapp.config.name,
1820
+ DappMode2.Exposed
1821
+ );
1822
+ await this.exposeDappRequestConnection.emit(ExposeDappRequestEvent, { payloads: [registeredDapp.dapp.config, exposeIntent] });
1823
+ }
1824
+ if (isRegisteredDappAccessDappSet(registeredDapp)) {
1825
+ this.registeredAccessDappSets.add(registeredDapp);
1826
+ await this.dappAccessRequestConnection.emit(DappAccessRequestEvent, { payloads: registeredDapp.dapp.accessors });
1827
+ }
1828
+ }
1829
+ }
1830
+ };
1831
+
1832
+ // src/signer/Signers.ts
1833
+ import { assertEx as assertEx10 } from "@xylabs/sdk-js";
1834
+ import { HDWallet as HDWallet5 } from "@xyo-network/sdk-js";
1835
+ var Signers = class {
1836
+ _paths;
1837
+ _signerAccounts;
1838
+ _walletStore;
1839
+ constructor(paths, walletStore) {
1840
+ this._paths = paths;
1841
+ this._walletStore = walletStore;
1842
+ this._signerAccounts = /* @__PURE__ */ new Map();
1843
+ }
1844
+ get paths() {
1845
+ return assertEx10(this._paths, () => "Paths not initialized");
1846
+ }
1847
+ get signerAccounts() {
1848
+ return assertEx10(this._signerAccounts, () => "Signer accounts not initialized");
1849
+ }
1850
+ get walletStore() {
1851
+ return assertEx10(this._walletStore, () => "Wallet store not initialized");
1852
+ }
1853
+ getSigner(walletKind, signer) {
1854
+ return this.signerAccounts.get(walletKind)?.get(signer);
1855
+ }
1856
+ getWalletKindSigner(walletKind) {
1857
+ return this.signerAccounts.get(walletKind);
1858
+ }
1859
+ async initialize() {
1860
+ for (const [walletKindName, signerPaths] of this.paths) {
1861
+ for (const [signerName, walletPath] of signerPaths.entries()) {
1862
+ await this.initializeSigners(walletKindName, signerName, walletPath);
1863
+ }
1864
+ }
1865
+ }
1866
+ async initializeSigners(walletKindName, signerName, path) {
1867
+ assertEx10(signerName, () => "Name not found in signer paths");
1868
+ assertEx10(path, () => "Path not found in signer paths");
1869
+ const phrase = assertEx10(await this.walletStore.get(walletKindName), () => `Wallet not found: ${walletKindName}`);
1870
+ if (path) {
1871
+ const signerMap = this.signerAccounts.get(walletKindName) ?? /* @__PURE__ */ new Map();
1872
+ const wallet = await HDWallet5.fromPhrase(phrase);
1873
+ const derivedWallet = await wallet.derivePath(path);
1874
+ signerMap.set(signerName, derivedWallet);
1875
+ this.signerAccounts.set(walletKindName, signerMap);
1876
+ }
1877
+ }
1878
+ };
1879
+
1880
+ // src/stack/Base.ts
1881
+ import {
1882
+ assertEx as assertEx11,
1883
+ BaseEmitter as BaseEmitter3,
1884
+ forget as forget3
1885
+ } from "@xylabs/sdk-js";
1886
+ import { isModuleInstance } from "@xyo-network/module-model";
1887
+ import { asAttachableNodeInstance } from "@xyo-network/node-model";
1888
+ var StackBase = class extends BaseEmitter3 {
1889
+ // flag to check that all adapters are initialized
1890
+ initialized = false;
1891
+ // adapters to initialize into the stack
1892
+ _adapterSet;
1893
+ _context;
1894
+ // stack node
1895
+ _stack;
1896
+ // stack node module identifier for the stack
1897
+ _stackNodeModuleId;
1898
+ // list of initialized nodes
1899
+ initializedNodes = [];
1900
+ // list of listeners - lister type not important since its only recalled to stop listening
1901
+ listeners = [];
1902
+ constructor(context, adapterSet, stackNodeModuleId) {
1903
+ super({});
1904
+ this._context = context;
1905
+ this._adapterSet = adapterSet(assertEx11(this.context.kernel, () => "Kernel access required"));
1906
+ this._stackNodeModuleId = stackNodeModuleId;
1907
+ }
1908
+ get adapterSet() {
1909
+ return assertEx11(this._adapterSet, () => `${this.stackNodeModuleId} adapters not initialized`);
1910
+ }
1911
+ get context() {
1912
+ return assertEx11(this._context, () => `${this.stackNodeModuleId} stack context not initialized`);
1913
+ }
1914
+ get stack() {
1915
+ return assertEx11(this._stack, () => `${this.stackNodeModuleId} stack node not initialized`);
1916
+ }
1917
+ get stackNodeModuleId() {
1918
+ return assertEx11(this._stackNodeModuleId, () => "Stack node module identifier not initialized");
1919
+ }
1920
+ initialize() {
1921
+ this.assignStack();
1922
+ for (const adapter of this.adapterSet) {
1923
+ const driverReadyListener = async ({ node }) => await this.handleDriverReady(node);
1924
+ adapter.on("driverReady", driverReadyListener);
1925
+ this.listeners.push({
1926
+ adapter,
1927
+ eventName: "driverReady",
1928
+ listener: driverReadyListener
1929
+ });
1930
+ const driverErrorListener = async ({ error }) => {
1931
+ console.error(`Error updating ${this.stackNodeModuleId} stack node`, error);
1932
+ await this.emit("driverError", { error });
1933
+ };
1934
+ adapter.on("driverError", driverErrorListener);
1935
+ this.listeners.push({
1936
+ adapter,
1937
+ eventName: "driverError",
1938
+ listener: driverErrorListener
1939
+ });
1940
+ const startAdapter = async () => await adapter.start();
1941
+ forget3(startAdapter());
1942
+ }
1943
+ }
1944
+ /**
1945
+ * Stops the stack
1946
+ */
1947
+ stop() {
1948
+ for (const {
1949
+ eventName,
1950
+ listener,
1951
+ adapter
1952
+ } of this.listeners) {
1953
+ adapter.off(eventName, listener);
1954
+ }
1955
+ }
1956
+ /**
1957
+ * Adds a node to the stack. Idempotent to avoid adding the
1958
+ * same node multiple times
1959
+ * @param node The node to add to the stack
1960
+ * @returns
1961
+ */
1962
+ async addNodeToStackNode(node) {
1963
+ const stackNode = await this.getStackNode();
1964
+ const existingModule = await stackNode.resolve(node.address, { direction: "down" });
1965
+ if (isModuleInstance(existingModule)) return;
1966
+ await stackNode.register?.(node);
1967
+ await stackNode.attach?.(node.address, true);
1968
+ }
1969
+ assignStack() {
1970
+ const assign = async () => {
1971
+ const stackNode = await this.getStackNode();
1972
+ this._stack = stackNode;
1973
+ };
1974
+ forget3(assign());
1975
+ }
1976
+ async getStackNode() {
1977
+ const mod = assertEx11(await this.context.root.resolve(this.stackNodeModuleId), () => `${this.stackNodeModuleId} not found`);
1978
+ return asAttachableNodeInstance(mod, () => `${this.stackNodeModuleId} not a NodeInstance`, { required: true });
1979
+ }
1980
+ async handleDriverReady(node) {
1981
+ try {
1982
+ await this.emit("driverReady", { node });
1983
+ await this.addNodeToStackNode(node);
1984
+ await this.updateInitializationState(node);
1985
+ } catch (error) {
1986
+ console.error(`Error updating ${this.stackNodeModuleId} stack node`, node.id, error);
1987
+ await this.emit("stackError", { error });
1988
+ }
1989
+ }
1990
+ async updateInitializationState(node) {
1991
+ this.initializedNodes.push(node);
1992
+ this.initialized = this.adapterSet.every((n) => n.initialized);
1993
+ if (this.initialized) {
1994
+ await this.emit("initialized", { stack: await this.getStackNode() });
1995
+ }
1996
+ }
1997
+ };
1998
+
1999
+ // src/stack/Manager.ts
2000
+ var StackManager = class {
2001
+ initializedStacksMap = /* @__PURE__ */ new Map();
2002
+ stackMap;
2003
+ constructor(stackMap) {
2004
+ this.stackMap = stackMap;
2005
+ }
2006
+ get stacks() {
2007
+ return Object.keys(this.initializedStacksMap);
2008
+ }
2009
+ get initializedStacks() {
2010
+ return this.initializedStacksMap;
2011
+ }
2012
+ getStack(key) {
2013
+ return this.initializedStacksMap.get(key);
2014
+ }
2015
+ initialize(context) {
2016
+ for (const [key, stackSet] of Object.entries(this.stackMap)) {
2017
+ console.log("stack-initialize", key);
2018
+ const { stack: Stack, adapters: stackNodeModuleId } = stackSet;
2019
+ const initializedStack = new Stack(context, stackNodeModuleId);
2020
+ initializedStack.initialize();
2021
+ this.initializedStacks.set(key, initializedStack);
2022
+ }
2023
+ }
2024
+ stop() {
2025
+ for (const stack of this.initializedStacks.values()) {
2026
+ stack.stop();
2027
+ }
2028
+ }
2029
+ };
2030
+
2031
+ // src/adapters/OsPubSubBridgeNetwork.ts
2032
+ import { ExposedNodeOuterNodeName, PubSubBridgeNodeNodeName } from "@xyo-network/os-model";
2033
+
2034
+ // src/adapter/Base.ts
2035
+ import {
2036
+ assertEx as assertEx12,
2037
+ BaseEmitter as BaseEmitter4,
2038
+ forget as forget4
2039
+ } from "@xylabs/sdk-js";
2040
+ import { asArchivistInstance as asArchivistInstance5 } from "@xyo-network/archivist";
2041
+ import { asAttachableNodeInstance as asAttachableNodeInstance2 } from "@xyo-network/node-model";
2042
+ import {
2043
+ asSchema as asSchema3
2044
+ } from "@xyo-network/payload-model";
2045
+ import { v4 as uuid3 } from "uuid";
2046
+ var NodeAdapterBase = class extends BaseEmitter4 {
2047
+ initialized = false;
2048
+ _id = "";
2049
+ driverName;
2050
+ kernel;
2051
+ constructor(kernel, driverName) {
2052
+ super({});
2053
+ this._id = uuid3();
2054
+ this.kernel = kernel;
2055
+ this.driverName = driverName;
2056
+ }
2057
+ get id() {
2058
+ return assertEx12(this._id, () => "NodeAdapterBase id not initialized");
2059
+ }
2060
+ async start() {
2061
+ try {
2062
+ const moduleAttachedInsertListener = ({ payloads }) => {
2063
+ const moduleAttachedEvent = this.findModuleEventPayloads(payloads);
2064
+ for (const payload of moduleAttachedEvent) {
2065
+ if (payload.name === this.driverName) {
2066
+ this.validateAndReturnDriver();
2067
+ }
2068
+ }
2069
+ };
2070
+ const eventsArchivist = await this.getEventsArchivist();
2071
+ const weakRefInsertListener = new WeakRef(moduleAttachedInsertListener);
2072
+ const insertListenerRef = weakRefInsertListener.deref();
2073
+ if (insertListenerRef) eventsArchivist.on("inserted", insertListenerRef);
2074
+ const node = this.validateAndReturnDriver();
2075
+ if (node) return node;
2076
+ this.initialized = false;
2077
+ } catch (error) {
2078
+ await this.emit("driverError", { error });
2079
+ }
2080
+ }
2081
+ findModuleEventPayloads(payloads) {
2082
+ return payloads.filter((payload) => {
2083
+ const payloadToTest = payload;
2084
+ return payloadToTest.event === "driverReady" && payloadToTest.schema === asSchema3("network.xyo.kernel.module.event", true);
2085
+ });
2086
+ }
2087
+ async getEventsArchivist() {
2088
+ const mod = assertEx12(await (await this.kernel.getNode()).resolve("KernelNode:ModuleEvents"), () => "KernelNode:ModuleEvents not found");
2089
+ return asArchivistInstance5(mod, () => `${mod.id} is not an archivist`, { required: true });
2090
+ }
2091
+ validateAndReturnDriver() {
2092
+ const mod = this.kernel.initialized[this.driverName];
2093
+ if (mod) {
2094
+ const node = asAttachableNodeInstance2(mod, () => `${mod.id} is not a node`, { required: true });
2095
+ this.initialized = true;
2096
+ const emit = async () => await this.emit("driverReady", { node });
2097
+ forget4(emit());
2098
+ return node;
2099
+ }
2100
+ }
2101
+ };
2102
+
2103
+ // src/adapter/Network.ts
2104
+ var NetworkAdapter = class extends NodeAdapterBase {
2105
+ _connection;
2106
+ constructor(kernel, driverName) {
2107
+ super(kernel, driverName);
2108
+ this.on("driverReady", ({ node }) => {
2109
+ this._connection = node;
2110
+ });
2111
+ }
2112
+ get connection() {
2113
+ return this._connection;
2114
+ }
2115
+ get hasConnection() {
2116
+ return !!this.connection;
2117
+ }
2118
+ removeConnection() {
2119
+ this._connection = void 0;
2120
+ }
2121
+ };
2122
+
2123
+ // src/adapter/Settings.ts
2124
+ var SettingsAdapter = class extends NodeAdapterBase {
2125
+ _settings = void 0;
2126
+ constructor(kernel, driverName) {
2127
+ super(kernel, driverName);
2128
+ this.on("driverReady", ({ node }) => {
2129
+ this._settings = node;
2130
+ });
2131
+ }
2132
+ get hasSettings() {
2133
+ return !!this.settings;
2134
+ }
2135
+ get settings() {
2136
+ return this._settings;
2137
+ }
2138
+ removeSettings() {
2139
+ this._settings = void 0;
2140
+ }
2141
+ };
2142
+
2143
+ // src/adapters/OsPubSubBridgeNetwork.ts
2144
+ var OsPubSubBridgeNetworkAdapters = (kernel) => [
2145
+ new NetworkAdapter(kernel, PubSubBridgeNodeNodeName),
2146
+ new NetworkAdapter(kernel, ExposedNodeOuterNodeName)
2147
+ ];
2148
+
2149
+ // src/adapters/OsSettings.ts
2150
+ import { OsSettingsNodeName } from "@xyo-network/os-model";
2151
+ var OsSettingsAdapters = (kernel) => [new SettingsAdapter(kernel, OsSettingsNodeName)];
2152
+
2153
+ // src/adapters/OsXyoPublicNetwork.ts
2154
+ import { XyoPublicNodeName } from "@xyo-network/os-model";
2155
+ var OsXyoPublicNetworkAdapters = (kernel) => [
2156
+ new NetworkAdapter(kernel, XyoPublicNodeName)
2157
+ ];
2158
+
2159
+ // src/stack/OsPubSubNetworkStack.ts
2160
+ import { assertEx as assertEx13 } from "@xylabs/sdk-js";
2161
+ import { asAttachableNodeInstance as asAttachableNodeInstance3, asNodeInstance } from "@xyo-network/node-model";
2162
+ import { ExposedNodeOuterNodeName as ExposedNodeOuterNodeName2, PubSubBridgeNodeNodeName as PubSubBridgeNodeNodeName2 } from "@xyo-network/os-model";
2163
+ var OsPubSubNetworkStack = class extends StackBase {
2164
+ _exposedNode;
2165
+ _exposedNodeOuter;
2166
+ busConnection = osPubSubNetworkReadyConnection();
2167
+ constructor(context, adapters) {
2168
+ super(context, adapters, "OsPubSubNetworkStackNode");
2169
+ }
2170
+ get exposedNode() {
2171
+ return this._exposedNode;
2172
+ }
2173
+ get exposedNodeOuter() {
2174
+ return this._exposedNodeOuter;
2175
+ }
2176
+ initialize() {
2177
+ super.initialize();
2178
+ this.context.eventBus.addConnection(this.busConnection);
2179
+ this.on("initialized", () => this.busConnection.emit(OsPubSubNetworkReadyEvent, {}));
2180
+ super.on("driverReady", async ({ node }) => {
2181
+ if (node.id === PubSubBridgeNodeNodeName2) {
2182
+ const httpBridge = assertEx13(await node.resolve("NsHttpBridge"), () => "HttpBridge not found");
2183
+ const xnsNode = asNodeInstance(await httpBridge.resolve("XNS"));
2184
+ if (xnsNode) {
2185
+ const initializedXns = await initializeXns(xnsNode);
2186
+ console.log(`Xns: ${initializedXns}`);
2187
+ } else {
2188
+ console.log("Xns: Failed to contact Xns Node");
2189
+ }
2190
+ }
2191
+ });
2192
+ super.on("driverReady", async ({ node }) => {
2193
+ if (node.id === ExposedNodeOuterNodeName2) {
2194
+ this._exposedNodeOuter = node;
2195
+ const mod = assertEx13(await node.resolve("ExposedNode"), () => "ExposedNode not found");
2196
+ const exposedNode = asAttachableNodeInstance3(mod, () => "ExposedNode is not a node");
2197
+ this._exposedNode = exposedNode;
2198
+ }
2199
+ });
2200
+ super.on("driverError", (error) => console.error("Unable to assign exposed node(s) to context", error));
2201
+ }
2202
+ stop() {
2203
+ super.stop();
2204
+ this._exposedNode = void 0;
2205
+ this._exposedNodeOuter = void 0;
2206
+ if (this.busConnection._id)
2207
+ this.context.eventBus.removeConnection(this.busConnection.id);
2208
+ }
2209
+ };
2210
+
2211
+ // src/stack/OsSettingsStack.ts
2212
+ var OsSettingsStack = class extends StackBase {
2213
+ busConnection = osSettingsReadyConnection();
2214
+ constructor(context, adapters) {
2215
+ super(context, adapters, "OsSettingsStackNode");
2216
+ }
2217
+ initialize() {
2218
+ super.initialize();
2219
+ this.context.eventBus.addConnection(this.busConnection);
2220
+ this.on("initialized", () => this.busConnection.emit(OsSettingsReadyEvent, {}));
2221
+ }
2222
+ stop() {
2223
+ super.stop();
2224
+ }
2225
+ };
2226
+
2227
+ // src/stack/XyoPublicNetworkStack.ts
2228
+ import { XyoPublicNodeName as XyoPublicNodeName2 } from "@xyo-network/os-model";
2229
+ var XyoPublicNetworkStack = class extends StackBase {
2230
+ busConnection = osXyoPublicNetworkReadyConnection();
2231
+ constructor(context, adapters) {
2232
+ super(context, adapters, "OsXyoPublicNetworkStackNode");
2233
+ }
2234
+ initialize() {
2235
+ super.initialize();
2236
+ this.context.eventBus.addConnection(this.busConnection);
2237
+ this.on("initialized", () => this.busConnection.emit(OsXyoPublicNetworkReadyEvent, {}));
2238
+ this.on("driverReady", ({ node }) => {
2239
+ if (node.id === XyoPublicNodeName2) {
2240
+ console.log("XyoPublicNode ready");
2241
+ }
2242
+ });
2243
+ this.on("driverError", (error) => console.error("Error loading driver", error));
2244
+ }
2245
+ stop() {
2246
+ super.stop();
2247
+ }
2248
+ };
2249
+
2250
+ // src/stack/Map.ts
2251
+ var OsStackMap = {
2252
+ osPubSubNetworkStack: {
2253
+ stack: OsPubSubNetworkStack,
2254
+ adapters: OsPubSubBridgeNetworkAdapters
2255
+ },
2256
+ xyoPublicNetworkStack: {
2257
+ stack: XyoPublicNetworkStack,
2258
+ adapters: OsXyoPublicNetworkAdapters
2259
+ },
2260
+ osSettingsStack: {
2261
+ stack: OsSettingsStack,
2262
+ adapters: OsSettingsAdapters
2263
+ }
2264
+ };
2265
+
2266
+ // src/XyOs.ts
2267
+ var XyOs = class _XyOs extends XyOsContextBase {
2268
+ _exposedNode;
2269
+ _exposedNodeOuter;
2270
+ _kernel;
2271
+ _locator;
2272
+ dappRegistrationService;
2273
+ signers;
2274
+ stackManager;
2275
+ constructor({
2276
+ logger = console,
2277
+ eventBus = new EventBus(),
2278
+ kernel = new Kernel({ logger }),
2279
+ locator = new ModuleFactoryLocator8(),
2280
+ dappsConfiguration,
2281
+ developmentMode,
2282
+ stackMap = OsStackMap,
2283
+ ...params
2284
+ } = {}) {
2285
+ super({
2286
+ eventBus,
2287
+ kernel,
2288
+ locator,
2289
+ ...params
2290
+ });
2291
+ this._locator = locator;
2292
+ this._kernel = kernel;
2293
+ this.stackManager = new StackManager(stackMap);
2294
+ this.dappRegistrationService = new DappRegistrationService(this, dappsConfiguration, this.locator, developmentMode);
2295
+ if (this.signerPaths && this.kernel?.bios?.seedPhraseStore) this.signers = new Signers(this.signerPaths, this.kernel?.bios?.seedPhraseStore);
2296
+ }
2297
+ static get monitoring() {
2298
+ return;
2299
+ }
2300
+ static get xyOsGlobal() {
2301
+ return getXyOsGlobal();
2302
+ }
2303
+ get bios() {
2304
+ return assertEx14(this.params.kernel?.bios, () => "Missing bios");
2305
+ }
2306
+ get exposedNode() {
2307
+ return this.stackManager.getStack("osPubSubNetworkStack")?.exposedNode;
2308
+ }
2309
+ get exposedNodeOuter() {
2310
+ return this.stackManager.getStack("osPubSubNetworkStack")?.exposedNodeOuter;
2311
+ }
2312
+ get kernel() {
2313
+ return assertEx14(this.params.kernel, () => "Missing kernel");
2314
+ }
2315
+ get locator() {
2316
+ return this._locator;
2317
+ }
2318
+ get stacks() {
2319
+ return this.stackManager.stacks;
2320
+ }
2321
+ get user() {
2322
+ return { signers: this.signers?.getWalletKindSigner("user") };
2323
+ }
2324
+ static async monitor(fn, eventConfig) {
2325
+ const { name, additionalProperties } = eventConfig;
2326
+ const monitor = this.monitoring;
2327
+ monitor?.startTimer(name);
2328
+ const result = await fn();
2329
+ monitor?.stopTimer({ additionalProperties, name });
2330
+ return result;
2331
+ }
2332
+ async boot(wallet, locator = new ModuleFactoryLocator8()) {
2333
+ console.warn("XyOs:boot", wallet.address);
2334
+ const fullLocator = this._locator.merge(locator);
2335
+ return await this._bootMutex.runExclusive(async () => {
2336
+ await this.eventBus.start();
2337
+ if (this.kernel?.status === "created") {
2338
+ await this.kernel.boot(await boot(), { locator: fullLocator, kernelDrivers: [] });
2339
+ }
2340
+ if (this.kernel?.status !== "booted") {
2341
+ throw new Error("Kernel not booted");
2342
+ }
2343
+ assertEx14(this._root === void 0, () => "XyOs already booted");
2344
+ const [root] = await _XyOs.monitor(async () => await loadOsNode(wallet, fullLocator), { name: "Load XyOs" });
2345
+ this._root = root;
2346
+ this.stackManager.initialize(this);
2347
+ if (this.signers) await this.signers.initialize();
2348
+ return this;
2349
+ });
2350
+ }
2351
+ buildDapp(manifest, dappId = NameTransforms.slug(manifest.nodes[0]?.config.name), name = NameTransforms.moduleName(manifest.nodes[0]?.config.name)) {
2352
+ return this.dappRegistrationService.buildDapp(manifest, dappId, name);
2353
+ }
2354
+ dappByName(dappId) {
2355
+ return this.dappRegistrationService.builtDapps[dappId];
2356
+ }
2357
+ getDappParams(dappId) {
2358
+ return this.dappRegistrationService.getParamsForRegisteredDapp(dappId);
2359
+ }
2360
+ getStack(stackName) {
2361
+ return assertEx14(this.stackManager.getStack(stackName), () => `Stack not found: ${stackName}`);
2362
+ }
2363
+ async monitor(fn, eventConfig) {
2364
+ return await _XyOs.monitor(fn, eventConfig);
2365
+ }
2366
+ shutdown() {
2367
+ assertEx14(this._root !== void 0, () => "XyOs not booted");
2368
+ this._root = void 0;
2369
+ this.stackManager.stop();
2370
+ }
2371
+ };
2372
+
2373
+ // src/RunningDappCache.ts
2374
+ var findOrCreateMutex = new Mutex3();
2375
+ var RunningDappCache = class _RunningDappCache {
2376
+ static _cache = {};
2377
+ static async findOrCreate(dapp, xyOs, allowedNames, xnsNodeUrl, xnsNetwork) {
2378
+ const dappId = dapp.config.name;
2379
+ return await XyOs.monitor(
2380
+ async () => await findOrCreateMutex.runExclusive(async () => {
2381
+ const existingWindowDappSet = _RunningDappCache.get(dappId);
2382
+ if (existingWindowDappSet) {
2383
+ console.debug("[DEBUG]", `RunningDappCache, using existing node for ${dappId}`);
2384
+ const existingDappContext = assertEx15(existingWindowDappSet.context, () => "No context found in existing dapp node");
2385
+ await DappContextCreator.primeDappArchivist(existingDappContext, xyOs, dappId);
2386
+ return existingWindowDappSet;
2387
+ }
2388
+ console.debug("[DEBUG]", "RunningDappCache:creating", dappId);
2389
+ const windowDappSet = await createDappContext(dapp, xyOs, allowedNames, xnsNodeUrl, xnsNetwork);
2390
+ _RunningDappCache.set(dappId, windowDappSet);
2391
+ return windowDappSet;
2392
+ }),
2393
+ { additionalProperties: { dappId }, name: "Loading dApp" }
2394
+ );
2395
+ }
2396
+ static get(key) {
2397
+ return this._cache[key];
2398
+ }
2399
+ static has(key) {
2400
+ return key ? !!this._cache[key] : false;
2401
+ }
2402
+ static set(key, value) {
2403
+ this._cache[key] = value;
2404
+ }
2405
+ };
2406
+
2407
+ // src/access/RunningAccessDappCache.ts
2408
+ var RunningDappAccessCache = class {
2409
+ static _cache = {};
2410
+ static get(key) {
2411
+ return this._cache[key];
2412
+ }
2413
+ static has(key) {
2414
+ return key ? !!this._cache[key] : false;
2415
+ }
2416
+ static set(key, value) {
2417
+ this._cache[key] = value;
2418
+ }
2419
+ };
2420
+
2421
+ // src/access/Caller.ts
2422
+ var DappAccessCaller = class extends OsCallerBase {
2423
+ allowedNames;
2424
+ platformLocator;
2425
+ registeredDapps;
2426
+ xnsNetwork;
2427
+ xnsNodeUrl;
2428
+ constructor(context, registeredDapps, allowedNames, xnsNodeUrl, xnsNetwork, platformLocator = new ModuleFactoryLocator9()) {
2429
+ super(context);
2430
+ this.registeredDapps = registeredDapps;
2431
+ this.allowedNames = allowedNames;
2432
+ this.xnsNodeUrl = xnsNodeUrl;
2433
+ this.xnsNetwork = xnsNetwork;
2434
+ this.platformLocator = platformLocator;
2435
+ }
2436
+ async start() {
2437
+ const registeredDappAccessDappSets = this.registeredDapps.filter(isRegisteredDappAccessDappSet2);
2438
+ for (const registeredDappSet of registeredDappAccessDappSets) {
2439
+ const context = await this.buildRunningDappCache(registeredDappSet, this.allowedNames);
2440
+ for (const dappAccessor of registeredDappSet.dapp.accessors) {
2441
+ await this.cacheAccessNode(dappAccessor, context);
2442
+ await this.saveRegisteredDappInterfaces(dappAccessor);
2443
+ }
2444
+ }
2445
+ }
2446
+ async buildRunningDappCache(registeredDappSet, allowedNames) {
2447
+ const { context } = await RunningDappCache.findOrCreate(registeredDappSet.dapp, this.context, allowedNames, this.xnsNodeUrl, this.xnsNetwork);
2448
+ if (!context) throw new Error("Dapp context not found");
2449
+ return context;
2450
+ }
2451
+ async cacheAccessNode(dappAccessor, context) {
2452
+ const accessNodeId = dappAccessor.rootModuleId;
2453
+ const accessNodeModule = assertEx16(await context.root.resolve(accessNodeId), () => "Access Node Module not found");
2454
+ const accessNode = asNodeInstance2(accessNodeModule, () => "Access Node Module is not a NodeInstance", { required: true });
2455
+ RunningDappAccessCache.set(dappAccessor.registeringDappId, accessNode);
2456
+ }
2457
+ async saveRegisteredDappInterfaces(registeredDappAccess) {
2458
+ const archivist = await this.getRegisteredDappInterfacesArchivist();
2459
+ const hash = await PayloadBuilder5.dataHash(registeredDappAccess);
2460
+ const [existing] = await archivist.get([hash]);
2461
+ if (existing) return;
2462
+ await archivist.insert([registeredDappAccess]);
2463
+ console.debug("[DEBUG] -", `Registered ${registeredDappAccess.registeringDappId} with ${registeredDappAccess.name} interface`);
2464
+ }
2465
+ };
2466
+
2467
+ // src/access/interfaces/registered-names/helpers/AccessNodeQueries.ts
2468
+ import { assertEx as assertEx17 } from "@xylabs/sdk-js";
2469
+ import { asArchivistInstance as asArchivistInstance6 } from "@xyo-network/archivist-model";
2470
+ var AccessNodeQueries = class {
2471
+ xyOsContext;
2472
+ accessRequest;
2473
+ registeredDappAccess;
2474
+ constructor(xyOsContext, accessRequest, registeredDappAccess) {
2475
+ this.xyOsContext = xyOsContext;
2476
+ this.accessRequest = accessRequest;
2477
+ this.registeredDappAccess = registeredDappAccess;
2478
+ }
2479
+ get nameServiceNamesAccessNode() {
2480
+ return assertEx17(RunningDappAccessCache.get(this.registeredDappAccess.registeringDappId), () => "No access node found");
2481
+ }
2482
+ // Refresh the archivist in the dapp
2483
+ async refresh() {
2484
+ const archivist = await this.getArchivistFromDappNode();
2485
+ await archivist.clear();
2486
+ await this.run();
2487
+ console.log("refreshed");
2488
+ }
2489
+ // Run the access node queries
2490
+ async run() {
2491
+ const payloads = await this.getPayloadsFromAccessNode();
2492
+ await this.insertAccessNodePayloadsIntoDappNodeArchivist(payloads);
2493
+ return payloads;
2494
+ }
2495
+ async getArchivistFromDappNode() {
2496
+ const archivistPath = this.accessRequest?.destinationArchivist ?? "DappArchivist";
2497
+ const mod = assertEx17(await this.xyOsContext.root.resolve(archivistPath), () => `Unable to find archivist at ${archivistPath}`);
2498
+ return asArchivistInstance6(mod, () => `Module at ${archivistPath} is not an archivist`, { required: true });
2499
+ }
2500
+ async getPayloadsFromAccessNode() {
2501
+ const archivistFromAccessNode = await this.resolveArchivistFromAccessNode();
2502
+ return await archivistFromAccessNode.all();
2503
+ }
2504
+ async insertAccessNodePayloadsIntoDappNodeArchivist(payloads) {
2505
+ const archivist = await this.getArchivistFromDappNode();
2506
+ await archivist.clear();
2507
+ await archivist.insert(payloads);
2508
+ }
2509
+ async resolveArchivistFromAccessNode() {
2510
+ const archivist = assertEx17(
2511
+ await this.nameServiceNamesAccessNode.resolve("PublicXnsArchivist"),
2512
+ () => "Unable to find archivist at PublicXnsArchivist"
2513
+ );
2514
+ return asArchivistInstance6(archivist, () => "PublicXnsArchivist is not an archivist", { required: true });
2515
+ }
2516
+ };
2517
+
2518
+ // src/access/interfaces/registered-names/helpers/resource/AbstractXnsCaller.ts
2519
+ import { assertEx as assertEx18 } from "@xylabs/sdk-js";
2520
+ import { asArchivistInstance as asArchivistInstance7 } from "@xyo-network/archivist-model";
2521
+ import { asDivinerInstance as asDivinerInstance4 } from "@xyo-network/diviner-model";
2522
+ var XnsArchivistPayloadDivinerModuleName = "XnsArchivistPayloadDiviner";
2523
+ var XnsArchivistModuleName = "XnsArchivist";
2524
+ var XnsRegistrationsArchivistModuleName = "XnsRegistrationsArchivist";
2525
+ var AbstractXnsCaller = class {
2526
+ context;
2527
+ constructor(context) {
2528
+ this.context = context;
2529
+ }
2530
+ /**
2531
+ * Get the XnsArchivist
2532
+ */
2533
+ async getXnsArchivist(pathPrefix) {
2534
+ const fullyQualifiedPath = pathPrefix ? `${pathPrefix}:${XnsArchivistModuleName}` : XnsArchivistModuleName;
2535
+ const mod = assertEx18(await this.context.root.resolve(fullyQualifiedPath), () => `${fullyQualifiedPath} not found`);
2536
+ return asArchivistInstance7(mod, () => `${fullyQualifiedPath} is not an archivist`, { required: true });
2537
+ }
2538
+ /**
2539
+ * Get the XnsArchivistPayloadDiviner
2540
+ */
2541
+ async getXnsArchivistPayloadDiviner(pathPrefix) {
2542
+ const fullyQualifiedPath = pathPrefix ? `${pathPrefix}:${XnsArchivistPayloadDivinerModuleName}` : XnsArchivistPayloadDivinerModuleName;
2543
+ const mod = assertEx18(await this.context.root.resolve(fullyQualifiedPath), () => `${fullyQualifiedPath} not found`);
2544
+ return asDivinerInstance4(mod, () => `${fullyQualifiedPath} is not an diviner`, { required: true });
2545
+ }
2546
+ /**
2547
+ * Get the XnsRegistrationsArchivist
2548
+ */
2549
+ async getXnsRegistrationsArchivist(pathPrefix) {
2550
+ const fullyQualifiedPath = pathPrefix ? `${pathPrefix}:${XnsRegistrationsArchivistModuleName}` : XnsRegistrationsArchivistModuleName;
2551
+ const mod = assertEx18(await this.context.root.resolve(fullyQualifiedPath), () => `${fullyQualifiedPath} not found`);
2552
+ return asArchivistInstance7(mod, () => `${fullyQualifiedPath} is not an archivist`, { required: true });
2553
+ }
2554
+ };
2555
+
2556
+ // src/access/interfaces/registered-names/helpers/resource/RegistrationsResource.ts
2557
+ import { assertEx as assertEx19 } from "@xylabs/sdk-js";
2558
+ import { isTemporalIndexingDivinerResultIndex } from "@xyo-network/diviner-temporal-indexing-model";
2559
+
2560
+ // src/access/interfaces/registered-names/helpers/resource/RegistrationsResourceQueries.ts
2561
+ import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema4 } from "@xyo-network/diviner-payload-model";
2562
+ import { TemporalIndexingDivinerResultIndexSchema } from "@xyo-network/diviner-temporal-indexing-model";
2563
+ var XnsRegistrationsResourceQueries = {
2564
+ getAllRegistrations: async (diviner) => {
2565
+ const query = {
2566
+ limit: 100,
2567
+ order: "desc",
2568
+ schema: PayloadDivinerQuerySchema4,
2569
+ schemas: [TemporalIndexingDivinerResultIndexSchema]
2570
+ };
2571
+ return await diviner.divine([query]);
2572
+ },
2573
+ getRecentRegistrations: async (archivist) => {
2574
+ return (await archivist.all()).toReversed();
2575
+ }
2576
+ };
2577
+
2578
+ // src/access/interfaces/registered-names/helpers/resource/RegistrationsResource.ts
2579
+ var XnsRegistrationsResource = class extends AbstractXnsCaller {
2580
+ _allRegistrations;
2581
+ pathPrefix;
2582
+ constructor(context, pathPrefix) {
2583
+ super(context);
2584
+ this.pathPrefix = pathPrefix;
2585
+ }
2586
+ get allRegistrations() {
2587
+ return assertEx19(this._allRegistrations);
2588
+ }
2589
+ get subscriptions() {
2590
+ return { allRegistrations: (cb) => this.allRegistrations.subscribe(cb) };
2591
+ }
2592
+ get views() {
2593
+ return { allRegistrations: () => this.allRegistrations.getSnapshot() };
2594
+ }
2595
+ cleanupListeners() {
2596
+ this.allRegistrations.cleanupListeners();
2597
+ }
2598
+ async start() {
2599
+ const xnsArchivistPayloadDiviner = await this.getXnsArchivistPayloadDiviner(this.pathPrefix);
2600
+ const xnsArchivist = await this.getXnsArchivist(this.pathPrefix);
2601
+ this._allRegistrations = await PayloadStore.create({
2602
+ archivist: xnsArchivist,
2603
+ getLatest: async () => await XnsRegistrationsResourceQueries.getAllRegistrations(xnsArchivistPayloadDiviner),
2604
+ idFunction: isTemporalIndexingDivinerResultIndex
2605
+ });
2606
+ }
2607
+ };
2608
+
2609
+ // src/access/Queries.ts
2610
+ import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema5 } from "@xyo-network/diviner-payload-model";
2611
+ import { DappAccessRequestSchema, RegisteredDappAccessSchema as RegisteredDappAccessSchema2 } from "@xyo-network/os-model";
2612
+ var noResults = [];
2613
+ var DappAccessRequestQueries = {
2614
+ async getAccessRequests(diviner) {
2615
+ const query = {
2616
+ limit: 1,
2617
+ schema: PayloadDivinerQuerySchema5,
2618
+ schemas: [DappAccessRequestSchema]
2619
+ };
2620
+ const results = await diviner.divine([query]);
2621
+ if (results.length === 0) {
2622
+ return noResults;
2623
+ }
2624
+ return results;
2625
+ },
2626
+ async getRegisteredInterfaces(diviner) {
2627
+ const query = {
2628
+ limit: 1,
2629
+ schema: PayloadDivinerQuerySchema5,
2630
+ schemas: [RegisteredDappAccessSchema2]
2631
+ };
2632
+ const results = await diviner.divine([query]);
2633
+ if (results.length === 0) {
2634
+ return noResults;
2635
+ }
2636
+ return results;
2637
+ }
2638
+ };
2639
+
2640
+ // src/access/Resource.ts
2641
+ import { assertEx as assertEx20 } from "@xylabs/sdk-js";
2642
+ import { isDappAccessRequestWithMeta, isRegisteredDappAccess as isRegisteredDappAccess2 } from "@xyo-network/os-model";
2643
+ var DappAccessRequestResource = class extends DappCallerBase {
2644
+ _accessRequestListener;
2645
+ _registeredInterfacesListener;
2646
+ constructor(context) {
2647
+ super(context);
2648
+ }
2649
+ get accessRequestListener() {
2650
+ return assertEx20(this._accessRequestListener, () => "accessRequests note found");
2651
+ }
2652
+ get registeredInterfacesListener() {
2653
+ return assertEx20(this._registeredInterfacesListener, () => "registeredInterfaces note found");
2654
+ }
2655
+ get subscriptions() {
2656
+ return {
2657
+ accessRequests: (cb) => this.accessRequestListener.subscribe(cb),
2658
+ registeredInterfaces: (cb) => this.registeredInterfacesListener.subscribe(cb)
2659
+ };
2660
+ }
2661
+ get views() {
2662
+ return {
2663
+ accessRequests: () => this.accessRequestListener.getSnapshot(),
2664
+ registeredInterfaces: () => this.registeredInterfacesListener.getSnapshot()
2665
+ };
2666
+ }
2667
+ cleanupListeners() {
2668
+ this.accessRequestListener.cleanupListeners();
2669
+ }
2670
+ // Start the resource
2671
+ async start() {
2672
+ const archivist = await this.getDappArchivist();
2673
+ const diviner = await this.getDappArchivistPayloadDiviner();
2674
+ this._accessRequestListener = await PayloadStore.create({
2675
+ archivist,
2676
+ getLatest: async () => await DappAccessRequestQueries.getAccessRequests(diviner),
2677
+ idFunction: isDappAccessRequestWithMeta
2678
+ });
2679
+ this._registeredInterfacesListener = await PayloadStore.create({
2680
+ archivist,
2681
+ getLatest: async () => await DappAccessRequestQueries.getRegisteredInterfaces(diviner),
2682
+ idFunction: isRegisteredDappAccess2
2683
+ });
2684
+ }
2685
+ };
2686
+
2687
+ // src/Caller.ts
2688
+ import { assertEx as assertEx21 } from "@xylabs/sdk-js";
2689
+ import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema7 } from "@xyo-network/diviner-payload-model";
2690
+ import {
2691
+ DappAccessRequestSchema as DappAccessRequestSchema2,
2692
+ DappInjectableParamsSchema as DappInjectableParamsSchema2,
2693
+ DappIntentTypes as DappIntentTypes2,
2694
+ DappMode as DappMode3,
2695
+ RegisteredDappAccessSchema as RegisteredDappAccessSchema3
2696
+ } from "@xyo-network/os-model";
2697
+ import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
2698
+
2699
+ // src/DefaultsQueries.ts
2700
+ import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema6 } from "@xyo-network/diviner-payload-model";
2701
+ import { DappInjectableParamsSchema, NodeOsInfoSchema as NodeOsInfoSchema2 } from "@xyo-network/os-model";
2702
+ var DappDefaultsResourceQueries = {
2703
+ async getDappInjectableParamsFromRoute(diviner) {
2704
+ const query = {
2705
+ limit: 1,
2706
+ order: "desc",
2707
+ schema: PayloadDivinerQuerySchema6,
2708
+ schemas: [DappInjectableParamsSchema],
2709
+ source: "route"
2710
+ };
2711
+ return await diviner.divine([query]);
2712
+ },
2713
+ async getNodeOsInfo(diviner) {
2714
+ const query = {
2715
+ limit: 1,
2716
+ order: "desc",
2717
+ schema: PayloadDivinerQuerySchema6,
2718
+ schemas: [NodeOsInfoSchema2]
2719
+ };
2720
+ return await diviner.divine([query]);
2721
+ }
2722
+ };
2723
+
2724
+ // src/Caller.ts
2725
+ var DappCaller = class extends DappCallerBase {
2726
+ constructor(context) {
2727
+ super(context);
2728
+ }
2729
+ /**
2730
+ * Add payloads to the dapp archivist
2731
+ * @param payloads
2732
+ * @param force
2733
+ */
2734
+ async addPayloadsToDappArchivist(payloads = [], force = false) {
2735
+ const dappArchivist = await this.getDappArchivist();
2736
+ if (force) {
2737
+ await dappArchivist.insert(payloads);
2738
+ } else {
2739
+ for (const payload of payloads) {
2740
+ const hash = await PayloadBuilder6.dataHash(payload);
2741
+ const [existing] = await dappArchivist.get([hash]);
2742
+ if (existing) continue;
2743
+ await dappArchivist.insert([payload]);
2744
+ }
2745
+ }
2746
+ }
2747
+ /**
2748
+ * Build Access Request
2749
+ * @param mode
2750
+ * @param registeredDappAccessHash
2751
+ * @param requestingDappId
2752
+ * @param destinationArchivist
2753
+ */
2754
+ buildAccessRequest(mode, registeredDappAccessHash, requestingDappId, destinationArchivist) {
2755
+ const accessRequest = {
2756
+ destinationArchivist,
2757
+ mode,
2758
+ registeredDappAccessHash,
2759
+ requestingDappId,
2760
+ schema: DappAccessRequestSchema2,
2761
+ timestamp: Date.now()
2762
+ };
2763
+ return accessRequest;
2764
+ }
2765
+ /**
2766
+ * Get all available dapp access requests
2767
+ */
2768
+ async getDappAccessPayloads() {
2769
+ const diviner = await this.getDappArchivistPayloadDiviner();
2770
+ const query = {
2771
+ order: "desc",
2772
+ schema: PayloadDivinerQuerySchema7,
2773
+ schemas: [RegisteredDappAccessSchema3]
2774
+ };
2775
+ return diviner.divine([query]);
2776
+ }
2777
+ /**
2778
+ * Get the most recent dapp injectable params
2779
+ * @returns Promise
2780
+ */
2781
+ async getDappInjectableParams() {
2782
+ const diviner = await this.getDappArchivistPayloadDiviner();
2783
+ return await DappDefaultsResourceQueries.getDappInjectableParamsFromRoute(diviner);
2784
+ }
2785
+ /**
2786
+ * Get the most recent dapp intent
2787
+ * @param name
2788
+ */
2789
+ async getRegisteredDappAccessByName(name) {
2790
+ const diviner = await this.getDappArchivistPayloadDiviner();
2791
+ const query = {
2792
+ limit: 1,
2793
+ name,
2794
+ schema: PayloadDivinerQuerySchema7,
2795
+ schemas: [RegisteredDappAccessSchema3]
2796
+ };
2797
+ const [payload] = assertEx21(await diviner.divine([query]), () => "Unable to find registered dapp access");
2798
+ return payload;
2799
+ }
2800
+ /**
2801
+ * Get the user wallet
2802
+ */
2803
+ getUserAccount(dappName) {
2804
+ const account = this.context.user.signers?.get(dappName);
2805
+ if (account) {
2806
+ return account;
2807
+ } else {
2808
+ throw new Error("Unable to find user wallet");
2809
+ }
2810
+ }
2811
+ /**
2812
+ * Get all wallets for the user
2813
+ */
2814
+ getUserAccountsAll() {
2815
+ return [...this.context.user.signers?.values() ?? []];
2816
+ }
2817
+ /**
2818
+ * Make Dapp Access Request
2819
+ * @param requestingDappId
2820
+ * @param registeredDappAccessHash
2821
+ * @param mode
2822
+ * @param destinationArchivist
2823
+ */
2824
+ async makeDappAccessRequest(requestingDappId, registeredDappAccessHash, mode, destinationArchivist) {
2825
+ const archivist = await this.getDappArchivist();
2826
+ const registeredDappAccessPayload = await archivist.get([registeredDappAccessHash]);
2827
+ if (!registeredDappAccessPayload) {
2828
+ throw new Error("No registered dapp access found");
2829
+ }
2830
+ const accessRequest = this.buildAccessRequest(mode, registeredDappAccessHash, requestingDappId, destinationArchivist);
2831
+ await archivist.insert([accessRequest]);
2832
+ }
2833
+ /**
2834
+ * Make Dapp Intent Request
2835
+ * @param sourceDappId
2836
+ * @param targetDappId
2837
+ * @param intent
2838
+ * @param mode
2839
+ */
2840
+ async makeDappIntentRequest(sourceDappId, targetDappId, intent = DappIntentTypes2.Launch, mode = DappMode3.Window, params) {
2841
+ if (!sourceDappId) {
2842
+ throw new Error("No source dapp id provided, dApps must declare a sourceDappId");
2843
+ }
2844
+ const archivist = await this.getDappArchivist();
2845
+ const dappIntent = DappIntentCaller.buildIntent(sourceDappId, intent, targetDappId, mode, params);
2846
+ return await archivist.insert([dappIntent]);
2847
+ }
2848
+ /**
2849
+ * Set the dapp injectable params
2850
+ * @param searchParams
2851
+ * @param pathname
2852
+ */
2853
+ async setDappInjectableRouteParams(searchParams = new URLSearchParams(), pathname) {
2854
+ const dappArchivist = await this.getDappArchivist();
2855
+ const params = {};
2856
+ for (const [key, value] of searchParams.entries()) {
2857
+ params[key] = value;
2858
+ }
2859
+ const payload = {
2860
+ params,
2861
+ path: pathname,
2862
+ schema: DappInjectableParamsSchema2,
2863
+ source: "route",
2864
+ timestamp: Date.now()
2865
+ };
2866
+ await dappArchivist.insert([payload]);
2867
+ }
2868
+ };
2869
+
2870
+ // src/classes/dapp/DefaultsResource.ts
2871
+ import { assertEx as assertEx22 } from "@xylabs/sdk-js";
2872
+ import { isDappInjectableParams, isNodeOsInfo } from "@xyo-network/os-model";
2873
+ var DappDefaultsResource = class extends DappCallerBase {
2874
+ _dappInjectableParamsFromRouteListener;
2875
+ _nodeOsInfoListener;
2876
+ constructor(context) {
2877
+ super(context);
2878
+ }
2879
+ get dappInjectableParamsFromRouteListener() {
2880
+ return assertEx22(this._dappInjectableParamsFromRouteListener, () => "DappInjectableParams not found");
2881
+ }
2882
+ get nodeOsInfoListener() {
2883
+ return assertEx22(this._nodeOsInfoListener, () => "NodeOsInfo not found");
2884
+ }
2885
+ get subscriptions() {
2886
+ return {
2887
+ dappInjectableParamsFromRoute: (cb) => this.dappInjectableParamsFromRouteListener.subscribe(cb),
2888
+ nodeOsInfo: (cb) => this.nodeOsInfoListener.subscribe(cb)
2889
+ };
2890
+ }
2891
+ get views() {
2892
+ return {
2893
+ dappInjectableParamsFromRoute: () => this.dappInjectableParamsFromRouteListener.getSnapshot(),
2894
+ nodeOsInfo: () => this.nodeOsInfoListener.getSnapshot()
2895
+ };
2896
+ }
2897
+ cleanupListeners() {
2898
+ this.nodeOsInfoListener.cleanupListeners();
2899
+ }
2900
+ async start() {
2901
+ const archivist = await this.getDappArchivist();
2902
+ const diviner = await this.getDappArchivistPayloadDiviner();
2903
+ this._nodeOsInfoListener = await PayloadStore.create({
2904
+ archivist,
2905
+ getLatest: async () => await DappDefaultsResourceQueries.getNodeOsInfo(diviner),
2906
+ idFunction: isNodeOsInfo
2907
+ });
2908
+ this._dappInjectableParamsFromRouteListener = await PayloadStore.create({
2909
+ archivist,
2910
+ getLatest: async () => await DappDefaultsResourceQueries.getDappInjectableParamsFromRoute(diviner),
2911
+ idFunction: isDappInjectableParams
2912
+ });
2913
+ }
2914
+ };
2915
+
2916
+ // src/classes/menu/Caller.ts
2917
+ import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema8 } from "@xyo-network/diviner-payload-model";
2918
+ import {
2919
+ DappInjectableParamsSchema as DappInjectableParamsSchema3,
2920
+ DappNavItemSelectionSchema
2921
+ } from "@xyo-network/os-model";
2922
+ import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
2923
+ var DappMenuCaller = class extends DappCaller {
2924
+ constructor(context) {
2925
+ super(context);
2926
+ }
2927
+ /**
2928
+ * Add new Payloads to the dappArchivist if they haven't already
2929
+ * @param payloads
2930
+ */
2931
+ async add(payloads, force = false) {
2932
+ const dappArchivist = await this.getDappArchivist();
2933
+ for (const payload of payloads) {
2934
+ const hash = await PayloadBuilder7.dataHash(payload);
2935
+ const [existing] = await dappArchivist.get([hash]);
2936
+ if (!existing || force) {
2937
+ await dappArchivist.insert(payloads);
2938
+ }
2939
+ }
2940
+ }
2941
+ async currentNavSelection() {
2942
+ const diviner = await this.getDappArchivistPayloadDiviner();
2943
+ const query = {
2944
+ limit: 1,
2945
+ order: "desc",
2946
+ schema: PayloadDivinerQuerySchema8,
2947
+ schemas: [DappNavItemSelectionSchema]
2948
+ };
2949
+ return await diviner.divine([query]);
2950
+ }
2951
+ /*
2952
+ * Indicate to the system that a nav item was selected
2953
+ *
2954
+ * @param {string} path
2955
+ * @params {string} injectableParamsPath
2956
+ * @returns Promise
2957
+ */
2958
+ async makeNavItemSelection(path, injectableParamsPath) {
2959
+ const dappArchivist = await this.getDappArchivist();
2960
+ const payload = {
2961
+ path,
2962
+ schema: DappNavItemSelectionSchema,
2963
+ timestamp: Date.now()
2964
+ };
2965
+ await dappArchivist.insert([payload]);
2966
+ if (injectableParamsPath) {
2967
+ const injectableParams = {
2968
+ params: {},
2969
+ path: injectableParamsPath,
2970
+ schema: DappInjectableParamsSchema3,
2971
+ source: "route",
2972
+ timestamp: Date.now()
2973
+ };
2974
+ await dappArchivist.insert([injectableParams]);
2975
+ }
2976
+ }
2977
+ };
2978
+
2979
+ // src/classes/menu/Resource.ts
2980
+ import { assertEx as assertEx23 } from "@xylabs/sdk-js";
2981
+ import { isDappNavItemSelection, isDappNavMenuConfig } from "@xyo-network/os-model";
2982
+
2983
+ // src/classes/menu/Queries.ts
2984
+ import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema9 } from "@xyo-network/diviner-payload-model";
2985
+ import {
2986
+ DappNavItemSchema,
2987
+ DappNavItemSelectionSchema as DappNavItemSelectionSchema2,
2988
+ DappNavMenuConfigSchema
2989
+ } from "@xyo-network/os-model";
2990
+ var NO_ITEMS = [];
2991
+ var DappMenuQueries = {
2992
+ async getMenuConfigs(diviner) {
2993
+ const query = {
2994
+ limit: 1,
2995
+ order: "desc",
2996
+ schema: PayloadDivinerQuerySchema9,
2997
+ schemas: [DappNavMenuConfigSchema]
2998
+ };
2999
+ return await diviner.divine([query]);
3000
+ },
3001
+ async getMenuItems(diviner) {
3002
+ const query = {
3003
+ order: "desc",
3004
+ schema: PayloadDivinerQuerySchema9,
3005
+ schemas: [DappNavItemSchema]
3006
+ };
3007
+ const results = await diviner.divine([query]);
3008
+ return results.length > 0 ? results : NO_ITEMS;
3009
+ },
3010
+ async getNavItemSelections(diviner) {
3011
+ const query = {
3012
+ limit: 1,
3013
+ order: "desc",
3014
+ schema: PayloadDivinerQuerySchema9,
3015
+ schemas: [DappNavItemSelectionSchema2]
3016
+ };
3017
+ const results = await diviner.divine([query]);
3018
+ return results.length > 0 ? results : NO_ITEMS;
3019
+ },
3020
+ async getVisibleMenuItems(diviner) {
3021
+ const query = {
3022
+ order: "desc",
3023
+ schema: PayloadDivinerQuerySchema9,
3024
+ schemas: [DappNavItemSchema]
3025
+ };
3026
+ const results = await diviner.divine([query]);
3027
+ return results.filter((menuItem) => menuItem.hidden !== true).toSorted((a, b) => (a.weight ?? 0) > (b.weight ?? 0) ? 1 : -1);
3028
+ }
3029
+ };
3030
+
3031
+ // src/classes/menu/Resource.ts
3032
+ var DappMenuResource = class extends DappCaller {
3033
+ _menuConfigListener;
3034
+ _menuItemListener;
3035
+ _menuItemSelectionListener;
3036
+ _menuItemVisibleListener;
3037
+ constructor(xyOsContext) {
3038
+ super(xyOsContext);
3039
+ }
3040
+ get menuConfigListener() {
3041
+ return assertEx23(this._menuConfigListener, () => "menuConfigListener note found");
3042
+ }
3043
+ get menuItemListener() {
3044
+ return assertEx23(this._menuItemListener, () => "menuItemListener note found");
3045
+ }
3046
+ get menuItemSelectionListener() {
3047
+ return assertEx23(this._menuItemSelectionListener, () => "menuItemSelectionListener note found");
3048
+ }
3049
+ get menuItemVisibleListener() {
3050
+ return assertEx23(this._menuItemVisibleListener, () => "menuItemVisibleListener note found");
3051
+ }
3052
+ /** subscribe to latest set of payloads */
3053
+ get subscriptions() {
3054
+ return {
3055
+ menuConfigs: (cb) => this.menuConfigListener.subscribe(cb),
3056
+ menuItemSelections: (cb) => this.menuItemSelectionListener.subscribe(cb),
3057
+ menuItems: (cb) => this.menuItemListener.subscribe(cb),
3058
+ menuItemsVisible: (cb) => this.menuItemVisibleListener.subscribe(cb)
3059
+ };
3060
+ }
3061
+ /**
3062
+ * Return the latest menu payloads from the repository
3063
+ */
3064
+ get views() {
3065
+ return {
3066
+ menuConfigs: () => this.menuConfigListener.getSnapshot(),
3067
+ menuItemSelections: () => this.menuItemSelectionListener.getSnapshot(),
3068
+ menuItems: () => this.menuItemListener.getSnapshot(),
3069
+ menuItemsVisible: () => this.menuItemVisibleListener.getSnapshot()
3070
+ };
3071
+ }
3072
+ /**
3073
+ * Remove all listeners and reset their class members
3074
+ */
3075
+ cleanupListeners() {
3076
+ this.menuConfigListener.cleanupListeners();
3077
+ this.menuItemListener.cleanupListeners();
3078
+ this.menuItemSelectionListener.cleanupListeners();
3079
+ }
3080
+ /**
3081
+ * Start the resource
3082
+ */
3083
+ async start() {
3084
+ const dappArchivist = await this.getDappArchivist();
3085
+ const dappArchivistPayloadDiviner = await this.getDappArchivistPayloadDiviner();
3086
+ this._menuConfigListener = await PayloadStore.create({
3087
+ archivist: dappArchivist,
3088
+ getLatest: async () => await DappMenuQueries.getMenuConfigs(dappArchivistPayloadDiviner),
3089
+ idFunction: isDappNavMenuConfig
3090
+ });
3091
+ this._menuItemListener = await PayloadStore.create({
3092
+ archivist: dappArchivist,
3093
+ getLatest: async () => await DappMenuQueries.getMenuItems(dappArchivistPayloadDiviner),
3094
+ idFunction: isDappNavMenuConfig
3095
+ });
3096
+ this._menuItemVisibleListener = await PayloadStore.create({
3097
+ archivist: dappArchivist,
3098
+ getLatest: async () => await DappMenuQueries.getVisibleMenuItems(dappArchivistPayloadDiviner),
3099
+ idFunction: isDappNavMenuConfig
3100
+ });
3101
+ this._menuItemSelectionListener = await PayloadStore.create({
3102
+ archivist: dappArchivist,
3103
+ getLatest: async () => await DappMenuQueries.getNavItemSelections(dappArchivistPayloadDiviner),
3104
+ idFunction: isDappNavItemSelection
3105
+ });
3106
+ }
3107
+ };
3108
+
3109
+ // src/classes/settings/badge/Caller.ts
3110
+ import { OsBadgeSchema as OsBadgeSchema2 } from "@xyo-network/os-model";
3111
+
3112
+ // src/classes/settings/CallerBase.ts
3113
+ import { assertEx as assertEx24 } from "@xylabs/sdk-js";
3114
+ import { asArchivistInstance as asArchivistInstance8 } from "@xyo-network/archivist-model";
3115
+ import { asDivinerInstance as asDivinerInstance5 } from "@xyo-network/diviner-model";
3116
+ var OsSettingsArchivistModuleName = "OsSettingsNode:OsSettingsArchivist";
3117
+ var OsSettingsArchivistPayloadDivinerModuleName = "OsSettingsNode:OsSettingsArchivistPayloadDiviner";
3118
+ var OsSettingsCallerBase = class {
3119
+ context;
3120
+ constructor(context) {
3121
+ this.context = context;
3122
+ }
3123
+ async getOsSettingsArchivist() {
3124
+ const mod = assertEx24(await this.context.root.resolve(OsSettingsArchivistModuleName), () => `${OsSettingsArchivistModuleName} not found`);
3125
+ return asArchivistInstance8(mod, () => `${OsSettingsArchivistModuleName} is not an archivist`, { required: true });
3126
+ }
3127
+ async getOsSettingsPayloadDiviner() {
3128
+ const mod = assertEx24(
3129
+ await this.context.root.resolve(OsSettingsArchivistPayloadDivinerModuleName),
3130
+ () => `${OsSettingsArchivistPayloadDivinerModuleName} not found`
3131
+ );
3132
+ return asDivinerInstance5(mod, () => `${OsSettingsArchivistPayloadDivinerModuleName} is not a diviner`, { required: true });
3133
+ }
3134
+ };
3135
+
3136
+ // src/classes/settings/badge/Queries.ts
3137
+ import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema10 } from "@xyo-network/diviner-payload-model";
3138
+ import { OsBadgeSchema } from "@xyo-network/os-model";
3139
+ var OsBadgeQueries = {
3140
+ getBadge: async (achievement, diviner) => {
3141
+ const query = {
3142
+ achievement,
3143
+ limit: 1,
3144
+ order: "desc",
3145
+ schema: PayloadDivinerQuerySchema10,
3146
+ schemas: [OsBadgeSchema]
3147
+ };
3148
+ return await diviner.divine([query]);
3149
+ }
3150
+ };
3151
+
3152
+ // src/classes/settings/badge/Caller.ts
3153
+ var OsBadgeCaller = class extends OsSettingsCallerBase {
3154
+ /**
3155
+ * @param achievement
3156
+ */
3157
+ async getBadge(achievement) {
3158
+ const diviner = await this.getOsSettingsPayloadDiviner();
3159
+ const results = await OsBadgeQueries.getBadge(achievement, diviner);
3160
+ return results[0] ?? null;
3161
+ }
3162
+ /**
3163
+ * @param achievement
3164
+ */
3165
+ async saveBadge(achievement) {
3166
+ const badge = {
3167
+ achievement,
3168
+ schema: OsBadgeSchema2,
3169
+ timestamp: Date.now()
3170
+ };
3171
+ const archivist = await this.getOsSettingsArchivist();
3172
+ return await archivist.insert([badge]);
3173
+ }
3174
+ };
3175
+
3176
+ // src/classes/settings/badge/Resource.ts
3177
+ import { assertEx as assertEx25 } from "@xylabs/sdk-js";
3178
+ import { isBadgeWithMeta } from "@xyo-network/os-model";
3179
+ var OsBadgeResource = class extends OsSettingsCallerBase {
3180
+ static views = ["savedSeedPhrase"];
3181
+ _savedSeedPhrase;
3182
+ constructor(xyOsContext) {
3183
+ super(xyOsContext);
3184
+ }
3185
+ get savedSeedPhrase() {
3186
+ return assertEx25(this._savedSeedPhrase, () => "Saved seed phrase listener not set");
3187
+ }
3188
+ get subscriptions() {
3189
+ return { savedSeedPhrase: (cb) => this.savedSeedPhrase.subscribe(cb) };
3190
+ }
3191
+ get views() {
3192
+ return { savedSeedPhrase: () => this.savedSeedPhrase.latest };
3193
+ }
3194
+ cleanupListeners() {
3195
+ this.savedSeedPhrase.cleanupListeners();
3196
+ }
3197
+ /**
3198
+ * start listeners
3199
+ */
3200
+ async start() {
3201
+ const diviner = await this.getOsSettingsPayloadDiviner();
3202
+ const archivist = await this.getOsSettingsArchivist();
3203
+ this._savedSeedPhrase = await PayloadStore.create({
3204
+ archivist,
3205
+ getLatest: async () => await OsBadgeQueries.getBadge("savedSeedPhrase", diviner),
3206
+ idFunction: isBadgeWithMeta
3207
+ });
3208
+ }
3209
+ };
3210
+
3211
+ // src/classes/settings/Caller.ts
3212
+ import { assertEx as assertEx26 } from "@xylabs/sdk-js";
3213
+
3214
+ // src/utils/buildWalletSeedPhrasePayload.ts
3215
+ import { WalletSeedPhraseSchema } from "@xyo-network/os-model";
3216
+ import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/payload-builder";
3217
+ var language = "english";
3218
+ var standard = "bip-39";
3219
+ var userWalletLabel = "userWallet";
3220
+ var buildWalletSeedPhrasePayload = async (mnemonic, $label) => {
3221
+ const fields = {
3222
+ mnemonic: {
3223
+ language,
3224
+ mnemonic: mnemonic.split(" "),
3225
+ standard
3226
+ },
3227
+ $label,
3228
+ $timestamp: Date.now()
3229
+ };
3230
+ const payload = new PayloadBuilder8({ schema: WalletSeedPhraseSchema }).fields(fields).build();
3231
+ const rootHash = await PayloadBuilder8.hash(payload);
3232
+ return { payload, rootHash };
3233
+ };
3234
+ var buildUserWalletSeedPhrasePayload = (mnemonic) => {
3235
+ return buildWalletSeedPhrasePayload(mnemonic, userWalletLabel);
3236
+ };
3237
+
3238
+ // src/utils/getApiDomain.ts
3239
+ var getApiDomain = (scope, apiDomain) => {
3240
+ if (apiDomain !== void 0) {
3241
+ return apiDomain;
3242
+ }
3243
+ if (scope === "localhost") {
3244
+ return "http://localhost:8080";
3245
+ }
3246
+ if (scope === "beta") {
3247
+ return "https://beta.archivist.xyo.network";
3248
+ }
3249
+ return "https://archivist.xyo.network";
3250
+ };
3251
+
3252
+ // src/utils/renameObjKey.ts
3253
+ var renameObjKey = (oldObj, oldKey, newKey) => {
3254
+ const oldObjKeys = Object.keys(oldObj);
3255
+ const newObj = oldObjKeys.reduce(
3256
+ (acc, val) => {
3257
+ if (val === oldKey) {
3258
+ acc[newKey] = oldObj[oldKey];
3259
+ } else {
3260
+ acc[val] = oldObj[val];
3261
+ }
3262
+ return acc;
3263
+ },
3264
+ {}
3265
+ );
3266
+ return newObj;
3267
+ };
3268
+
3269
+ // src/classes/settings/SettingsQueries.ts
3270
+ import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema11 } from "@xyo-network/diviner-payload-model";
3271
+ import { NodeBackgroundSchema, WalletSeedPhraseSchema as WalletSeedPhraseSchema2 } from "@xyo-network/os-model";
3272
+ import { PayloadBuilder as PayloadBuilder9 } from "@xyo-network/payload-builder";
3273
+ var NO_RESULTS2 = [];
3274
+ var OsSettingsQueries = {
3275
+ async getLatestUserWallet(diviner, archivist) {
3276
+ const query = {
3277
+ limit: 1,
3278
+ order: "desc",
3279
+ schema: PayloadDivinerQuerySchema11,
3280
+ schemas: [WalletSeedPhraseSchema2]
3281
+ };
3282
+ const results = await diviner.divine([query]);
3283
+ const wallet = results.find((payload) => payload.$label === "userWallet");
3284
+ if (wallet) return [wallet];
3285
+ const legacyWallet = results.find((payload) => payload.$meta?.label === "userWallet");
3286
+ if (legacyWallet && archivist) {
3287
+ const legacyMeta = legacyWallet.$meta;
3288
+ const newWalletPayloadFields = {
3289
+ mnemonic: legacyWallet.mnemonic,
3290
+ $label: legacyMeta?.label,
3291
+ $timestamp: legacyMeta?.$timestamp
3292
+ };
3293
+ const payload = new PayloadBuilder9({ schema: WalletSeedPhraseSchema2 }).fields(newWalletPayloadFields).build();
3294
+ await archivist.insert([payload]);
3295
+ return [payload];
3296
+ }
3297
+ return NO_RESULTS2;
3298
+ },
3299
+ async getNodeBackground(diviner) {
3300
+ const query = {
3301
+ limit: 1,
3302
+ order: "desc",
3303
+ schema: PayloadDivinerQuerySchema11,
3304
+ schemas: [NodeBackgroundSchema]
3305
+ };
3306
+ return await diviner.divine([query]);
3307
+ },
3308
+ async getWallets(diviner) {
3309
+ const query = {
3310
+ order: "desc",
3311
+ schema: PayloadDivinerQuerySchema11,
3312
+ schemas: [WalletSeedPhraseSchema2]
3313
+ };
3314
+ return await diviner.divine([query]);
3315
+ }
3316
+ };
3317
+
3318
+ // src/classes/settings/Caller.ts
3319
+ var OsSettingsCaller = class extends OsSettingsCallerBase {
3320
+ constructor(context) {
3321
+ super(context);
3322
+ }
3323
+ /**
3324
+ * Add a node background to the settings
3325
+ * @param payload
3326
+ */
3327
+ async addNodeBackground(payload) {
3328
+ const archivist = await this.getOsSettingsArchivist();
3329
+ await archivist.insert([payload]);
3330
+ }
3331
+ /**
3332
+ * Add a wallet seed phrase to the settings
3333
+ * @param payload
3334
+ */
3335
+ async addWalletSeedPhrase(payload) {
3336
+ const archivist = await this.getOsSettingsArchivist();
3337
+ await archivist.insert([payload]);
3338
+ const phrase = payload.mnemonic.mnemonic.join(" ");
3339
+ await this.context.kernel?.bios?.seedPhraseStore.set("user", phrase);
3340
+ }
3341
+ /**
3342
+ * Get the latest node background
3343
+ */
3344
+ async getLatestNodeBackground() {
3345
+ const diviner = await this.getOsSettingsPayloadDiviner();
3346
+ const [result] = await OsSettingsQueries.getNodeBackground(diviner);
3347
+ return result ?? null;
3348
+ }
3349
+ async getLatestUserWallet() {
3350
+ const diviner = await this.getOsSettingsPayloadDiviner();
3351
+ const archivist = await this.getOsSettingsArchivist();
3352
+ const storedSeedPhrasePayload = (await OsSettingsQueries.getLatestUserWallet(diviner, archivist)).pop();
3353
+ const biosWalletSeedPhrase = assertEx26(await this.context.kernel?.bios?.seedPhraseStore.get("user"), () => "No user seed phrase found from BIOS");
3354
+ const biosWalletSeedPhraseParts = biosWalletSeedPhrase.split(" ");
3355
+ if (!storedSeedPhrasePayload?.mnemonic?.mnemonic) {
3356
+ const { payload: biosSeedPhrasePayload } = await buildUserWalletSeedPhrasePayload(biosWalletSeedPhrase);
3357
+ await this.addWalletSeedPhrase(biosSeedPhrasePayload);
3358
+ return biosSeedPhrasePayload;
3359
+ } else if (!isEqual(storedSeedPhrasePayload.mnemonic.mnemonic, biosWalletSeedPhraseParts)) {
3360
+ const updatedBiosSeedPhrase = storedSeedPhrasePayload.mnemonic.mnemonic.join(" ");
3361
+ await this.context.kernel?.bios?.seedPhraseStore.set("user", updatedBiosSeedPhrase);
3362
+ }
3363
+ return storedSeedPhrasePayload;
3364
+ }
3365
+ };
3366
+
3367
+ // src/classes/settings/Resource.ts
3368
+ import { assertEx as assertEx27 } from "@xylabs/sdk-js";
3369
+ import { isNodeBackground, isWalletSeedPhrase } from "@xyo-network/os-model";
3370
+ var OsSettingsResource = class extends OsSettingsCallerBase {
3371
+ _latestUserWalletListener;
3372
+ _nodeBackgroundListener;
3373
+ _walletsListener;
3374
+ constructor(context) {
3375
+ super(context);
3376
+ }
3377
+ get latestUserWalletListener() {
3378
+ return assertEx27(this._latestUserWalletListener, () => "Latest user wallet listener not set");
3379
+ }
3380
+ get nodeBackgroundListener() {
3381
+ return assertEx27(this._nodeBackgroundListener, () => "Node background listener not set");
3382
+ }
3383
+ get subscriptions() {
3384
+ return {
3385
+ latestUserWallet: (cb) => this.walletsListener.subscribe(cb),
3386
+ nodeBackground: (cb) => this.nodeBackgroundListener.subscribe(cb),
3387
+ wallets: (cb) => this.walletsListener.subscribe(cb)
3388
+ };
3389
+ }
3390
+ get views() {
3391
+ return {
3392
+ latestUserWallet: () => this.latestUserWalletListener.latest,
3393
+ nodeBackground: () => this.nodeBackgroundListener.latest,
3394
+ wallets: () => this.walletsListener.latest
3395
+ };
3396
+ }
3397
+ get walletsListener() {
3398
+ return assertEx27(this._walletsListener, () => "Wallets listener not set");
3399
+ }
3400
+ cleanupListeners() {
3401
+ this.walletsListener.cleanupListeners();
3402
+ this.latestUserWalletListener.cleanupListeners();
3403
+ }
3404
+ /**
3405
+ * start listeners
3406
+ */
3407
+ async start() {
3408
+ const archivist = await this.getOsSettingsArchivist();
3409
+ const diviner = await this.getOsSettingsPayloadDiviner();
3410
+ this._walletsListener = await PayloadStore.create({
3411
+ archivist,
3412
+ getLatest: async () => await OsSettingsQueries.getWallets(diviner),
3413
+ idFunction: isWalletSeedPhrase
3414
+ });
3415
+ this._latestUserWalletListener = await PayloadStore.create({
3416
+ archivist,
3417
+ getLatest: async () => await OsSettingsQueries.getLatestUserWallet(diviner),
3418
+ idFunction: isWalletSeedPhrase
3419
+ });
3420
+ this._nodeBackgroundListener = await PayloadStore.create({
3421
+ archivist,
3422
+ getLatest: async () => await OsSettingsQueries.getNodeBackground(diviner),
3423
+ idFunction: isNodeBackground
3424
+ });
3425
+ }
3426
+ };
3427
+
3428
+ // src/helpers/monitor/XyOsMonitor.ts
3429
+ var DEFAULT_MONITORING_EVENT_NAME = "System Task Duration";
3430
+ globalThis.getXyOsGlobal = globalThis.getXyOsGlobal ?? (() => {
3431
+ return { tracking: { trackEvent: (_event, _properties) => void {} } };
3432
+ });
3433
+ var xyOsGlobal = globalThis.getXyOsGlobal();
3434
+ var XyOsMonitor = class _XyOsMonitor {
3435
+ static trackEvent = xyOsGlobal.tracking.trackEvent;
3436
+ performanceTimers = /* @__PURE__ */ new Map();
3437
+ startTimer(name) {
3438
+ this.performanceTimers.set(name, performance.now());
3439
+ }
3440
+ stopTimer(eventConfig) {
3441
+ const { additionalProperties, name } = eventConfig;
3442
+ const start = this.performanceTimers.get(name);
3443
+ if (start) {
3444
+ const end = performance.now();
3445
+ const duration = end - start;
3446
+ this.performanceTimers.delete(name);
3447
+ const connection = this.connection();
3448
+ _XyOsMonitor.trackEvent(DEFAULT_MONITORING_EVENT_NAME, {
3449
+ downloadSpeedMbps: connection?.downlink,
3450
+ duration: duration.toString(),
3451
+ effectiveConnectionSpeed: connection?.effectiveType,
3452
+ name,
3453
+ roundTripTime: connection?.rtt,
3454
+ ...additionalProperties
3455
+ });
3456
+ }
3457
+ }
3458
+ };
3459
+
3460
+ // src/initializer/DappInitializer.ts
3461
+ import { assertEx as assertEx28 } from "@xylabs/sdk-js";
3462
+ var DappInitializer = class {
3463
+ _config;
3464
+ constructor(config) {
3465
+ this._config = config;
3466
+ }
3467
+ get config() {
3468
+ return assertEx28(this._config, () => new Error("Options not set"));
3469
+ }
3470
+ async install() {
3471
+ const dappWithWalletId = await this.installDappWallet();
3472
+ return await this.initializeDappContext(dappWithWalletId);
3473
+ }
3474
+ async initializeDappContext(dappWithWalletId) {
3475
+ const {
3476
+ allowedNames,
3477
+ xnsNetwork,
3478
+ xnsNodeUrl,
3479
+ xyOs
3480
+ } = this.config;
3481
+ return await RunningDappCache.findOrCreate(dappWithWalletId, xyOs, allowedNames ?? [], xnsNodeUrl, xnsNetwork);
3482
+ }
3483
+ async installDappWallet() {
3484
+ const { xyOs, dapp } = this.config;
3485
+ const dappSeedPhraseRepository = new DappSeedPhraseRepository(xyOs, [dapp.config.name]);
3486
+ const walletId = await dappSeedPhraseRepository.findOrCreate(dapp.config.name);
3487
+ return {
3488
+ ...dapp,
3489
+ config: {
3490
+ ...dapp.config,
3491
+ walletId
3492
+ }
3493
+ };
3494
+ }
3495
+ };
3496
+
3497
+ // src/profileModuleEvents.ts
3498
+ import { PayloadBuilder as PayloadBuilder10 } from "@xyo-network/payload-builder";
3499
+ var DISPLAY_EVENT_COUNT_FREQUENCY = 100;
3500
+ var profileData = {};
3501
+ var profileModuleEvents = (mod) => {
3502
+ const modRef = new WeakRef(mod);
3503
+ mod.onAny(async (eventName, args) => {
3504
+ const mod2 = modRef.deref();
3505
+ if (mod2) {
3506
+ const data = profileData[mod2.address] ?? { allEventCount: 0, eventCounts: {} };
3507
+ profileData[mod2.address] = data;
3508
+ data.allEventCount += 1;
3509
+ data.eventCounts[eventName] = (data.eventCounts[eventName] ?? 0) + 1;
3510
+ if (eventName === "querySendStarted") {
3511
+ const { query, payloads = [] } = args;
3512
+ const pairs = await PayloadBuilder10.dataHashPairs(payloads);
3513
+ const foundPair = pairs.find(([, hash]) => hash === query.query);
3514
+ if (foundPair) {
3515
+ const [payload] = foundPair;
3516
+ console.log(`querySendStarted: ${payload.schema}`);
3517
+ }
3518
+ }
3519
+ if (eventName === "querySendFinished") {
3520
+ const { query } = args;
3521
+ console.log(`querySendFinished: ${query.query}`);
3522
+ }
3523
+ if (data.allEventCount % DISPLAY_EVENT_COUNT_FREQUENCY === 0) {
3524
+ console.log(`[PROFILE] - ${mod2.id} Event Counts:`);
3525
+ console.log(data.eventCounts);
3526
+ }
3527
+ }
3528
+ });
3529
+ };
3530
+
3531
+ // src/PubSubBridgeCaller.ts
3532
+ import { assertEx as assertEx29 } from "@xylabs/sdk-js";
3533
+ import { asBridgeInstance } from "@xyo-network/bridge-model";
3534
+ import { BridgedPubSubModuleName } from "@xyo-network/os-model";
3535
+ var PubSubBridgeCaller = class {
3536
+ node;
3537
+ constructor(node) {
3538
+ this.node = node;
3539
+ }
3540
+ async exposeAddresses(addresses, options) {
3541
+ const pubSubBridge = await this.getPubSubBridge();
3542
+ for (const address of addresses) {
3543
+ console.log(`Exposing: ${address}`);
3544
+ await pubSubBridge.expose(address, options);
3545
+ }
3546
+ }
3547
+ async unExposeAddresses(addresses) {
3548
+ const pubSubBridge = await this.getPubSubBridge();
3549
+ for (const address of addresses) {
3550
+ await pubSubBridge.unexpose?.(address);
3551
+ }
3552
+ }
3553
+ async getPubSubBridge() {
3554
+ const mod = assertEx29(await this.node.resolve(BridgedPubSubModuleName), () => `${BridgedPubSubModuleName} not found`);
3555
+ return asBridgeInstance(mod, () => `${BridgedPubSubModuleName} is not a bridge`, { required: true });
3556
+ }
3557
+ };
3558
+ export {
3559
+ AbstractXnsCaller,
3560
+ AccessNodeQueries,
3561
+ DappAccessCaller,
3562
+ DappAccessRequestEvent,
3563
+ DappAccessRequestQueries,
3564
+ DappAccessRequestResource,
3565
+ DappArchivistModuleName,
3566
+ DappArchivistPayloadDivinerModuleName,
3567
+ DappCaller,
3568
+ DappCallerBase,
3569
+ DappContextCreator,
3570
+ DappDefaultsResource,
3571
+ DappDefaultsResourceQueries,
3572
+ DappInitializer,
3573
+ DappIntentCaller,
3574
+ DappIntentResource,
3575
+ DappMenuCaller,
3576
+ DappMenuResource,
3577
+ DappRegistrationService,
3578
+ DappRegistry,
3579
+ DappSeedPhraseRepository,
3580
+ DappsArchivistDevelopmentModuleName,
3581
+ DappsArchivistModuleName,
3582
+ DappsArchivistPayloadDevelopmentDivinerModuleName,
3583
+ DappsArchivistPayloadDivinerModuleName,
3584
+ DevelopArchivist,
3585
+ EventBus,
3586
+ EventBusConnection,
3587
+ EventBusPubSubConnection,
3588
+ ExposeDappRequestEvent,
3589
+ ExternalModulePermissions,
3590
+ IntentArchivistModuleName,
3591
+ IntentArchivistPayloadDivinerModuleName,
3592
+ ManageSystemDapps,
3593
+ ModuleOffsetPaths,
3594
+ NameTransforms,
3595
+ NetworkAdapter,
3596
+ NodeSentinel,
3597
+ OsBadgeCaller,
3598
+ OsBadgeResource,
3599
+ OsCallerBase,
3600
+ OsPubSubBridgeNetworkAdapters,
3601
+ OsPubSubNetworkReadyEvent,
3602
+ OsPubSubNetworkStack,
3603
+ OsSettingsAdapters,
3604
+ OsSettingsCaller,
3605
+ OsSettingsCallerBase,
3606
+ OsSettingsQueries,
3607
+ OsSettingsReadyEvent,
3608
+ OsSettingsResource,
3609
+ OsSettingsStack,
3610
+ OsStackMap,
3611
+ OsXyoPublicNetworkAdapters,
3612
+ OsXyoPublicNetworkReadyEvent,
3613
+ PayloadStore,
3614
+ PubSubBridgeCaller,
3615
+ RegisteredDappInterfacesArchivistModuleName,
3616
+ RemoteNodeArchivistOffsetPaths,
3617
+ RunningDappCache,
3618
+ SettingsAdapter,
3619
+ Signers,
3620
+ StackBase,
3621
+ StackManager,
3622
+ ValidDappAccessInterfaces,
3623
+ XnsArchivistModuleName,
3624
+ XnsArchivistPayloadDivinerModuleName,
3625
+ XnsRegistrationsArchivistModuleName,
3626
+ XnsRegistrationsResource,
3627
+ XnsRegistrationsResourceQueries,
3628
+ XyOs,
3629
+ XyOsContextBase,
3630
+ XyOsDapp,
3631
+ XyOsMonitor,
3632
+ XyoPublicNetworkStack,
3633
+ asPayload,
3634
+ buildUserWalletSeedPhrasePayload,
3635
+ buildWalletSeedPhrasePayload,
3636
+ createDappContext,
3637
+ createInsertable,
3638
+ dappAccessRequestConnection,
3639
+ dappsReadyConnection,
3640
+ exposeDappRequestConnection,
3641
+ getApiDomain,
3642
+ initializeXns,
3643
+ isAnyPayload,
3644
+ isEqual,
3645
+ isObject2 as isObject,
3646
+ isPayload,
3647
+ loadOsNode,
3648
+ manifestReplacementTokens,
3649
+ os_node_manifest_default as osNodeManifest,
3650
+ osPubSubNetworkReadyConnection,
3651
+ osSettingsReadyConnection,
3652
+ osXyoPublicNetworkReadyConnection,
3653
+ profileData,
3654
+ profileModuleEvents,
3655
+ renameObjKey,
3656
+ tokenPlacesSplit,
3657
+ tokenPlacesSplitString,
3658
+ userWalletLabel
3659
+ };
3660
+ //# sourceMappingURL=index.mjs.map