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