@xyo-network/os-runtime 7.2.1 → 7.3.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 (249) hide show
  1. package/dist/neutral/Caller.d.ts.map +1 -1
  2. package/dist/neutral/DappCallerBase.d.ts +2 -2
  3. package/dist/neutral/OsCallerBase.d.ts +2 -2
  4. package/dist/neutral/RunningDappCache.d.ts.map +1 -1
  5. package/dist/neutral/XyOs.d.ts +4 -5
  6. package/dist/neutral/XyOs.d.ts.map +1 -1
  7. package/dist/neutral/XyOsBase.d.ts +122 -3
  8. package/dist/neutral/XyOsBase.d.ts.map +1 -1
  9. package/dist/neutral/XyOsDapp.d.ts +3 -3
  10. package/dist/neutral/XyOsDapp.d.ts.map +1 -1
  11. package/dist/neutral/access/Caller.d.ts +1 -1
  12. package/dist/neutral/access/Caller.d.ts.map +1 -1
  13. package/dist/neutral/access/RunningAccessDappCache.d.ts.map +1 -1
  14. package/dist/neutral/access/interfaces/registered-names/helpers/resource/AbstractXnsCaller.d.ts +1 -1
  15. package/dist/neutral/adapter/Base.d.ts.map +1 -1
  16. package/dist/neutral/classes/lib/DappCreatorParams.d.ts +3 -3
  17. package/dist/neutral/classes/lib/DappCreatorParams.d.ts.map +1 -1
  18. package/dist/neutral/classes/lib/Insertable.d.ts +1 -3
  19. package/dist/neutral/classes/lib/Insertable.d.ts.map +1 -1
  20. package/dist/neutral/classes/settings/CallerBase.d.ts +1 -1
  21. package/dist/neutral/classes/settings/SettingsQueries.d.ts.map +1 -1
  22. package/dist/neutral/dapp/context/creator/Creator.d.ts +1 -1
  23. package/dist/neutral/dapp/context/creator/Creator.d.ts.map +1 -1
  24. package/dist/neutral/dapp/context/creator/createDappContext.d.ts.map +1 -1
  25. package/dist/neutral/event/bus/EventBus.d.ts +1 -1
  26. package/dist/neutral/event/bus/EventBus.d.ts.map +1 -1
  27. package/dist/neutral/helpers/monitor/XyOsMonitor.d.ts +2 -2
  28. package/dist/neutral/helpers/monitor/XyOsMonitor.d.ts.map +1 -1
  29. package/dist/neutral/helpers/monitor/types.d.ts +2 -2
  30. package/dist/neutral/helpers/monitor/types.d.ts.map +1 -1
  31. package/dist/neutral/index.mjs +42 -36
  32. package/dist/neutral/index.mjs.map +1 -1
  33. package/dist/neutral/lib/Listener.d.ts +1 -1
  34. package/dist/neutral/lib/Listener.d.ts.map +1 -1
  35. package/dist/neutral/loadOsNode.d.ts.map +1 -1
  36. package/dist/neutral/profileModuleEvents.d.ts +1 -3
  37. package/dist/neutral/profileModuleEvents.d.ts.map +1 -1
  38. package/dist/neutral/registration/DappRegistrationService.d.ts +3 -3
  39. package/dist/neutral/registration/DappRegistrationService.d.ts.map +1 -1
  40. package/dist/neutral/registration/DappRegistry.d.ts.map +1 -1
  41. package/dist/neutral/registration/ValidateDappAccessDiviner/Config.d.ts +1 -1
  42. package/dist/neutral/registration/ValidateDappAccessDiviner/Config.d.ts.map +1 -1
  43. package/dist/neutral/scripts/xyos/lib/headless.d.ts.map +1 -1
  44. package/dist/neutral/signer/Signers.d.ts.map +1 -1
  45. package/dist/neutral/stack/Manager.d.ts +2 -6
  46. package/dist/neutral/stack/Manager.d.ts.map +1 -1
  47. package/dist/neutral/system/ManageSystemDapps.d.ts +2 -2
  48. package/dist/neutral/system/ManageSystemDapps.d.ts.map +1 -1
  49. package/dist/node/Caller.d.ts.map +1 -1
  50. package/dist/node/DappCallerBase.d.ts +2 -2
  51. package/dist/node/OsCallerBase.d.ts +2 -2
  52. package/dist/node/RunningDappCache.d.ts.map +1 -1
  53. package/dist/node/XyOs.d.ts +4 -5
  54. package/dist/node/XyOs.d.ts.map +1 -1
  55. package/dist/node/XyOsBase.d.ts +122 -3
  56. package/dist/node/XyOsBase.d.ts.map +1 -1
  57. package/dist/node/XyOsDapp.d.ts +3 -3
  58. package/dist/node/XyOsDapp.d.ts.map +1 -1
  59. package/dist/node/access/Caller.d.ts +1 -1
  60. package/dist/node/access/Caller.d.ts.map +1 -1
  61. package/dist/node/access/RunningAccessDappCache.d.ts.map +1 -1
  62. package/dist/node/access/interfaces/registered-names/helpers/resource/AbstractXnsCaller.d.ts +1 -1
  63. package/dist/node/adapter/Base.d.ts.map +1 -1
  64. package/dist/node/classes/lib/DappCreatorParams.d.ts +3 -3
  65. package/dist/node/classes/lib/DappCreatorParams.d.ts.map +1 -1
  66. package/dist/node/classes/lib/Insertable.d.ts +1 -3
  67. package/dist/node/classes/lib/Insertable.d.ts.map +1 -1
  68. package/dist/node/classes/settings/CallerBase.d.ts +1 -1
  69. package/dist/node/classes/settings/SettingsQueries.d.ts.map +1 -1
  70. package/dist/node/dapp/context/creator/Creator.d.ts +1 -1
  71. package/dist/node/dapp/context/creator/Creator.d.ts.map +1 -1
  72. package/dist/node/dapp/context/creator/createDappContext.d.ts.map +1 -1
  73. package/dist/node/event/bus/EventBus.d.ts +1 -1
  74. package/dist/node/event/bus/EventBus.d.ts.map +1 -1
  75. package/dist/node/helpers/monitor/XyOsMonitor.d.ts +2 -2
  76. package/dist/node/helpers/monitor/XyOsMonitor.d.ts.map +1 -1
  77. package/dist/node/helpers/monitor/types.d.ts +2 -2
  78. package/dist/node/helpers/monitor/types.d.ts.map +1 -1
  79. package/dist/node/index.mjs +42 -36
  80. package/dist/node/index.mjs.map +1 -1
  81. package/dist/node/lib/Listener.d.ts +1 -1
  82. package/dist/node/lib/Listener.d.ts.map +1 -1
  83. package/dist/node/loadOsNode.d.ts.map +1 -1
  84. package/dist/node/profileModuleEvents.d.ts +1 -3
  85. package/dist/node/profileModuleEvents.d.ts.map +1 -1
  86. package/dist/node/registration/DappRegistrationService.d.ts +3 -3
  87. package/dist/node/registration/DappRegistrationService.d.ts.map +1 -1
  88. package/dist/node/registration/DappRegistry.d.ts.map +1 -1
  89. package/dist/node/registration/ValidateDappAccessDiviner/Config.d.ts +1 -1
  90. package/dist/node/registration/ValidateDappAccessDiviner/Config.d.ts.map +1 -1
  91. package/dist/node/scripts/xyos/index.mjs +27 -24
  92. package/dist/node/scripts/xyos/index.mjs.map +1 -1
  93. package/dist/node/scripts/xyos/lib/headless.d.ts.map +1 -1
  94. package/dist/node/signer/Signers.d.ts.map +1 -1
  95. package/dist/node/stack/Manager.d.ts +2 -6
  96. package/dist/node/stack/Manager.d.ts.map +1 -1
  97. package/dist/node/system/ManageSystemDapps.d.ts +2 -2
  98. package/dist/node/system/ManageSystemDapps.d.ts.map +1 -1
  99. package/package.json +134 -49
  100. package/dist/neutral/signer/Signer.spec.d.ts +0 -2
  101. package/dist/neutral/signer/Signer.spec.d.ts.map +0 -1
  102. package/dist/neutral/spec/boot.spec.d.ts +0 -2
  103. package/dist/neutral/spec/boot.spec.d.ts.map +0 -1
  104. package/dist/node/signer/Signer.spec.d.ts +0 -2
  105. package/dist/node/signer/Signer.spec.d.ts.map +0 -1
  106. package/dist/node/spec/boot.spec.d.ts +0 -2
  107. package/dist/node/spec/boot.spec.d.ts.map +0 -1
  108. package/src/Caller.ts +0 -200
  109. package/src/DappCallerBase.ts +0 -55
  110. package/src/DefaultsQueries.ts +0 -27
  111. package/src/OsCallerBase.ts +0 -59
  112. package/src/PubSubBridgeCaller.ts +0 -33
  113. package/src/RunningDappCache.ts +0 -58
  114. package/src/XyOs.ts +0 -166
  115. package/src/XyOsBase.ts +0 -135
  116. package/src/XyOsDapp.ts +0 -106
  117. package/src/access/Caller.ts +0 -85
  118. package/src/access/Queries.ts +0 -38
  119. package/src/access/Resource.ts +0 -65
  120. package/src/access/RunningAccessDappCache.ts +0 -21
  121. package/src/access/index.ts +0 -4
  122. package/src/access/interfaces/index.ts +0 -1
  123. package/src/access/interfaces/registered-names/helpers/AccessNodeQueries.ts +0 -68
  124. package/src/access/interfaces/registered-names/helpers/index.ts +0 -2
  125. package/src/access/interfaces/registered-names/helpers/resource/AbstractXnsCaller.ts +0 -42
  126. package/src/access/interfaces/registered-names/helpers/resource/RegistrationsResource.ts +0 -52
  127. package/src/access/interfaces/registered-names/helpers/resource/RegistrationsResourceQueries.ts +0 -23
  128. package/src/access/interfaces/registered-names/helpers/resource/index.ts +0 -3
  129. package/src/access/interfaces/registered-names/index.ts +0 -1
  130. package/src/adapter/Base.ts +0 -106
  131. package/src/adapter/Network.ts +0 -31
  132. package/src/adapter/Settings.ts +0 -30
  133. package/src/adapter/index.ts +0 -2
  134. package/src/adapters/OsPubSubBridgeNetwork.ts +0 -10
  135. package/src/adapters/OsSettings.ts +0 -7
  136. package/src/adapters/OsXyoPublicNetwork.ts +0 -9
  137. package/src/adapters/index.ts +0 -3
  138. package/src/classes/dapp/DefaultsResource.ts +0 -67
  139. package/src/classes/dapp/index.ts +0 -1
  140. package/src/classes/index.ts +0 -4
  141. package/src/classes/lib/DappCreatorParams.ts +0 -18
  142. package/src/classes/lib/Insertable.ts +0 -10
  143. package/src/classes/lib/index.ts +0 -2
  144. package/src/classes/menu/Caller.ts +0 -76
  145. package/src/classes/menu/Queries.ts +0 -60
  146. package/src/classes/menu/Resource.ts +0 -105
  147. package/src/classes/menu/index.ts +0 -2
  148. package/src/classes/settings/Caller.ts +0 -78
  149. package/src/classes/settings/CallerBase.ts +0 -27
  150. package/src/classes/settings/Resource.ts +0 -81
  151. package/src/classes/settings/SettingsQueries.ts +0 -56
  152. package/src/classes/settings/badge/Caller.ts +0 -30
  153. package/src/classes/settings/badge/Queries.ts +0 -19
  154. package/src/classes/settings/badge/Resource.ts +0 -50
  155. package/src/classes/settings/badge/index.ts +0 -2
  156. package/src/classes/settings/index.ts +0 -5
  157. package/src/dapp/context/creator/Creator.ts +0 -122
  158. package/src/dapp/context/creator/DefaultPayloads/DappAccessPayloads.ts +0 -20
  159. package/src/dapp/context/creator/DefaultPayloads/DefaultPayloads.ts +0 -40
  160. package/src/dapp/context/creator/DefaultPayloads/NodeInfoPayload.ts +0 -33
  161. package/src/dapp/context/creator/DefaultPayloads/index.ts +0 -1
  162. package/src/dapp/context/creator/ExternalModulePermissions/ExternalModulePermissions.ts +0 -59
  163. package/src/dapp/context/creator/ExternalModulePermissions/index.ts +0 -1
  164. package/src/dapp/context/creator/createDappContext.ts +0 -61
  165. package/src/dapp/context/creator/index.ts +0 -3
  166. package/src/dapp/context/index.ts +0 -1
  167. package/src/dapp/index.ts +0 -1
  168. package/src/event/bus/Connection.ts +0 -31
  169. package/src/event/bus/EventBus.ts +0 -160
  170. package/src/event/bus/PubSubConnection.ts +0 -28
  171. package/src/event/bus/index.ts +0 -3
  172. package/src/event/connections/DappAccessRequest.ts +0 -11
  173. package/src/event/connections/DappsReady.ts +0 -9
  174. package/src/event/connections/ExposeDappRequest.ts +0 -11
  175. package/src/event/connections/OsPubSubNetworkReady.ts +0 -12
  176. package/src/event/connections/OsSettingsReady.ts +0 -12
  177. package/src/event/connections/OsXyoPublicReady.ts +0 -12
  178. package/src/event/connections/index.ts +0 -6
  179. package/src/event/index.ts +0 -2
  180. package/src/helpers/index.ts +0 -1
  181. package/src/helpers/monitor/XyOsMonitor.ts +0 -52
  182. package/src/helpers/monitor/index.ts +0 -2
  183. package/src/helpers/monitor/types.ts +0 -8
  184. package/src/index.ts +0 -29
  185. package/src/initializer/DappInitializer.ts +0 -57
  186. package/src/initializer/index.ts +0 -1
  187. package/src/intent/Caller.ts +0 -74
  188. package/src/intent/Resource.ts +0 -66
  189. package/src/intent/index.ts +0 -2
  190. package/src/lib/ExternalStore.ts +0 -7
  191. package/src/lib/Listener.ts +0 -1
  192. package/src/lib/ModuleAccountPaths.ts +0 -23
  193. package/src/lib/ModuleNames.ts +0 -3
  194. package/src/lib/NameTransforms.ts +0 -34
  195. package/src/lib/PayloadStore.ts +0 -105
  196. package/src/lib/ResourceStores.ts +0 -7
  197. package/src/lib/index.ts +0 -11
  198. package/src/lib/initializeXns.ts +0 -16
  199. package/src/lib/isEqual.ts +0 -42
  200. package/src/lib/isPayload.ts +0 -24
  201. package/src/lib/tokenPlacesSplit.ts +0 -17
  202. package/src/loadOsNode.ts +0 -44
  203. package/src/manifest/index.ts +0 -2
  204. package/src/manifest/manifestReplacementTokens.ts +0 -6
  205. package/src/manifest/os-node.manifest.json +0 -132
  206. package/src/manifests/dapp-window.manifest.json +0 -36
  207. package/src/manifests/index.ts +0 -1
  208. package/src/models/access/ValidDappAccessInterfaces.ts +0 -6
  209. package/src/models/access/index.ts +0 -1
  210. package/src/models/index.ts +0 -1
  211. package/src/profileModuleEvents.ts +0 -43
  212. package/src/registration/DappRegistrationService.ts +0 -180
  213. package/src/registration/DappRegistry.ts +0 -129
  214. package/src/registration/ValidateDappAccessDiviner/Config.ts +0 -24
  215. package/src/registration/ValidateDappAccessDiviner/Diviner.ts +0 -133
  216. package/src/registration/ValidateDappAccessDiviner/index.ts +0 -2
  217. package/src/registration/index.ts +0 -2
  218. package/src/scripts/xyos/command/config.ts +0 -19
  219. package/src/scripts/xyos/command/create.ts +0 -22
  220. package/src/scripts/xyos/command/index.ts +0 -7
  221. package/src/scripts/xyos/command/manifest.ts +0 -19
  222. package/src/scripts/xyos/command/start.ts +0 -35
  223. package/src/scripts/xyos/index.ts +0 -31
  224. package/src/scripts/xyos/lib/createFromTemplate.ts +0 -11
  225. package/src/scripts/xyos/lib/headless.ts +0 -68
  226. package/src/scripts/xyos/lib/index.ts +0 -2
  227. package/src/signer/Signer.spec.ts +0 -65
  228. package/src/signer/Signers.ts +0 -74
  229. package/src/signer/index.ts +0 -1
  230. package/src/spec/boot.spec.ts +0 -89
  231. package/src/stack/Base.ts +0 -165
  232. package/src/stack/Manager.ts +0 -51
  233. package/src/stack/Map.ts +0 -22
  234. package/src/stack/OsPubSubNetworkStack.ts +0 -70
  235. package/src/stack/OsSettingsStack.ts +0 -24
  236. package/src/stack/XyoPublicNetworkStack.ts +0 -32
  237. package/src/stack/index.ts +0 -6
  238. package/src/system/ManageSystemDapps.ts +0 -148
  239. package/src/system/Queries.ts +0 -69
  240. package/src/system/index.ts +0 -1
  241. package/src/types/global.d.ts +0 -9
  242. package/src/types/images.d.ts +0 -5
  243. package/src/utils/buildWalletSeedPhrasePayload.ts +0 -51
  244. package/src/utils/getApiDomain.ts +0 -14
  245. package/src/utils/index.ts +0 -3
  246. package/src/utils/renameObjKey.ts +0 -22
  247. package/src/wallet/DappSeedPhraseRepository.ts +0 -99
  248. package/src/wallet/SeedPhraseRepository.ts +0 -31
  249. package/src/wallet/index.ts +0 -2
@@ -1,60 +0,0 @@
1
- import type { DivinerInstance } from '@xyo-network/diviner-model'
2
- import type { PayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model'
3
- import { PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
4
- import type {
5
- DappNavItem,
6
- DappNavItemSelection,
7
- DappNavMenuConfig,
8
- } from '@xyo-network/os-model'
9
- import {
10
- DappNavItemSchema,
11
- DappNavItemSelectionSchema,
12
- DappNavMenuConfigSchema,
13
- } from '@xyo-network/os-model'
14
- import type { WithSources } from '@xyo-network/payload-model'
15
-
16
- const NO_ITEMS: unknown[] = []
17
-
18
- export const DappMenuQueries = {
19
- async getMenuConfigs(diviner: DivinerInstance): Promise<WithSources<DappNavMenuConfig>[]> {
20
- const query: PayloadDivinerQueryPayload = {
21
- limit: 1,
22
- order: 'desc',
23
- schema: PayloadDivinerQuerySchema,
24
- schemas: [DappNavMenuConfigSchema],
25
- }
26
- return (await diviner.divine([query])) as WithSources<DappNavMenuConfig>[]
27
- },
28
-
29
- async getMenuItems(diviner: DivinerInstance) {
30
- const query: PayloadDivinerQueryPayload = {
31
- order: 'desc',
32
- schema: PayloadDivinerQuerySchema,
33
- schemas: [DappNavItemSchema],
34
- }
35
-
36
- const results = (await diviner.divine([query])) as WithSources<DappNavItem>[]
37
- return results.length > 0 ? results : (NO_ITEMS as WithSources<DappNavItem>[])
38
- },
39
-
40
- async getNavItemSelections(diviner: DivinerInstance) {
41
- const query: PayloadDivinerQueryPayload = {
42
- limit: 1,
43
- order: 'desc',
44
- schema: PayloadDivinerQuerySchema,
45
- schemas: [DappNavItemSelectionSchema],
46
- }
47
- const results = (await diviner.divine([query])) as WithSources<DappNavItemSelection>[]
48
- return results.length > 0 ? results : (NO_ITEMS as WithSources<DappNavItemSelection>[])
49
- },
50
-
51
- async getVisibleMenuItems(diviner: DivinerInstance) {
52
- const query: PayloadDivinerQueryPayload = {
53
- order: 'desc',
54
- schema: PayloadDivinerQuerySchema,
55
- schemas: [DappNavItemSchema],
56
- }
57
- const results = (await diviner.divine([query])) as WithSources<DappNavItem>[]
58
- return results.filter(menuItem => menuItem.hidden !== true).toSorted((a, b) => ((a.weight ?? 0) > (b.weight ?? 0) ? 1 : -1))
59
- },
60
- }
@@ -1,105 +0,0 @@
1
- import { assertEx } from '@xylabs/sdk-js'
2
- import type {
3
- DappNavItem, DappNavItemSelection, DappNavMenuConfig, XyOsContext,
4
- } from '@xyo-network/os-model'
5
- import { isDappNavItemSelection, isDappNavMenuConfig } from '@xyo-network/os-model'
6
- import type { Payload, WithSources } from '@xyo-network/payload-model'
7
-
8
- import { DappCaller } from '../../Caller.ts'
9
- import type { Listener, ResourceStore } from '../../lib/index.ts'
10
- import { PayloadStore } from '../../lib/index.ts'
11
- import { DappMenuQueries } from './Queries.ts'
12
-
13
- export type DappMenuResourceViews = 'menuConfigs' | 'menuItems' | 'menuItemsVisible' | 'menuItemSelections'
14
-
15
- export type NavPayloadType<T extends Payload = Payload> = WithSources<T>[]
16
-
17
- /**
18
- * A Repository for interacting with dapp menu items and config
19
- */
20
- export class DappMenuResource extends DappCaller implements ResourceStore<DappMenuResourceViews> {
21
- private _menuConfigListener: PayloadStore<DappNavMenuConfig> | undefined
22
- private _menuItemListener: PayloadStore<DappNavItem> | undefined
23
- private _menuItemSelectionListener: PayloadStore<DappNavItemSelection> | undefined
24
- private _menuItemVisibleListener: PayloadStore<DappNavItem> | undefined
25
-
26
- constructor(xyOsContext: XyOsContext) {
27
- super(xyOsContext)
28
- }
29
-
30
- get menuConfigListener() {
31
- return assertEx(this._menuConfigListener, () => 'menuConfigListener note found')
32
- }
33
-
34
- get menuItemListener() {
35
- return assertEx(this._menuItemListener, () => 'menuItemListener note found')
36
- }
37
-
38
- get menuItemSelectionListener() {
39
- return assertEx(this._menuItemSelectionListener, () => 'menuItemSelectionListener note found')
40
- }
41
-
42
- get menuItemVisibleListener() {
43
- return assertEx(this._menuItemVisibleListener, () => 'menuItemVisibleListener note found')
44
- }
45
-
46
- /** subscribe to latest set of payloads */
47
- get subscriptions() {
48
- return {
49
- menuConfigs: (cb: Listener) => this.menuConfigListener.subscribe(cb),
50
- menuItemSelections: (cb: Listener) => this.menuItemSelectionListener.subscribe(cb),
51
- menuItems: (cb: Listener) => this.menuItemListener.subscribe(cb),
52
- menuItemsVisible: (cb: Listener) => this.menuItemVisibleListener.subscribe(cb),
53
- }
54
- }
55
-
56
- /**
57
- * Return the latest menu payloads from the repository
58
- */
59
- get views() {
60
- return {
61
- menuConfigs: () => this.menuConfigListener.getSnapshot(),
62
- menuItemSelections: () => this.menuItemSelectionListener.getSnapshot(),
63
- menuItems: () => this.menuItemListener.getSnapshot(),
64
- menuItemsVisible: () => this.menuItemVisibleListener.getSnapshot(),
65
- }
66
- }
67
-
68
- /**
69
- * Remove all listeners and reset their class members
70
- */
71
- cleanupListeners() {
72
- this.menuConfigListener.cleanupListeners()
73
- this.menuItemListener.cleanupListeners()
74
- this.menuItemSelectionListener.cleanupListeners()
75
- }
76
-
77
- /**
78
- * Start the resource
79
- */
80
- async start(): Promise<void> {
81
- const dappArchivist = await this.getDappArchivist()
82
- const dappArchivistPayloadDiviner = await this.getDappArchivistPayloadDiviner()
83
-
84
- this._menuConfigListener = await PayloadStore.create<DappNavMenuConfig>({
85
- archivist: dappArchivist,
86
- getLatest: async () => await DappMenuQueries.getMenuConfigs(dappArchivistPayloadDiviner),
87
- idFunction: isDappNavMenuConfig,
88
- })
89
- this._menuItemListener = await PayloadStore.create<DappNavItem>({
90
- archivist: dappArchivist,
91
- getLatest: async () => await DappMenuQueries.getMenuItems(dappArchivistPayloadDiviner),
92
- idFunction: isDappNavMenuConfig,
93
- })
94
- this._menuItemVisibleListener = await PayloadStore.create<DappNavItem>({
95
- archivist: dappArchivist,
96
- getLatest: async () => await DappMenuQueries.getVisibleMenuItems(dappArchivistPayloadDiviner),
97
- idFunction: isDappNavMenuConfig,
98
- })
99
- this._menuItemSelectionListener = await PayloadStore.create<DappNavItemSelection>({
100
- archivist: dappArchivist,
101
- getLatest: async () => await DappMenuQueries.getNavItemSelections(dappArchivistPayloadDiviner),
102
- idFunction: isDappNavItemSelection,
103
- })
104
- }
105
- }
@@ -1,2 +0,0 @@
1
- export * from './Caller.ts'
2
- export * from './Resource.ts'
@@ -1,78 +0,0 @@
1
- import { assertEx } from '@xylabs/sdk-js'
2
- import type {
3
- NodeBackground, WalletSeedPhrase, XyOsContext,
4
- } from '@xyo-network/os-model'
5
-
6
- import { isEqual } from '../../lib/index.ts'
7
- import { buildUserWalletSeedPhrasePayload } from '../../utils/index.ts'
8
- import { OsSettingsCallerBase } from './CallerBase.ts'
9
- import { OsSettingsQueries } from './SettingsQueries.ts'
10
-
11
- export class OsSettingsCaller extends OsSettingsCallerBase {
12
- constructor(context: XyOsContext) {
13
- super(context)
14
- }
15
-
16
- /**
17
- * Add a node background to the settings
18
- * @param payload
19
- */
20
- async addNodeBackground(payload: NodeBackground) {
21
- const archivist = await this.getOsSettingsArchivist()
22
- await archivist.insert([payload])
23
- }
24
-
25
- /**
26
- * Add a wallet seed phrase to the settings
27
- * @param payload
28
- */
29
- async addWalletSeedPhrase(payload: WalletSeedPhrase) {
30
- // NOTE: Since setting the seed phrase in OS takes precedence
31
- // over the BIOS when the two phrases differ, we'll set the seed
32
- // phrase in the OS first. That way if the latter saves fail we can
33
- // still recover on next boot.
34
-
35
- // Save seed phrase to OS settings
36
- const archivist = await this.getOsSettingsArchivist()
37
- await archivist.insert([payload])
38
-
39
- // Save seed phrase to BIOS
40
- const phrase = payload.mnemonic.mnemonic.join(' ')
41
- await this.context.kernel?.bios?.seedPhraseStore.set('user', phrase)
42
- }
43
-
44
- /**
45
- * Get the latest node background
46
- */
47
- async getLatestNodeBackground(): Promise<NodeBackground | null> {
48
- const diviner = await this.getOsSettingsPayloadDiviner()
49
- const [result] = (await OsSettingsQueries.getNodeBackground(diviner)) as NodeBackground[]
50
- return result ?? null
51
- }
52
-
53
- async getLatestUserWallet(): Promise<WalletSeedPhrase> {
54
- // Get the seed phrase from the OS settings
55
- const diviner = await this.getOsSettingsPayloadDiviner()
56
- const archivist = await this.getOsSettingsArchivist()
57
- const storedSeedPhrasePayload = (await OsSettingsQueries.getLatestUserWallet(diviner, archivist)).pop()
58
- // Get the seed phrase from the BIOS
59
- const biosWalletSeedPhrase = assertEx(await this.context.kernel?.bios?.seedPhraseStore.get('user'), () => 'No user seed phrase found from BIOS')
60
- const biosWalletSeedPhraseParts = biosWalletSeedPhrase.split(' ')
61
- // If there is no stored seed phrase in the OS, use the seed phrase from the BIOS
62
- if (!storedSeedPhrasePayload?.mnemonic?.mnemonic) {
63
- // Create new wallet payload from BIOS seed phrase
64
- const { payload: biosSeedPhrasePayload } = await buildUserWalletSeedPhrasePayload(biosWalletSeedPhrase)
65
- // Store the BIOS seed phrase in the OS settings
66
- await this.addWalletSeedPhrase(biosSeedPhrasePayload)
67
- // Return BIOS seed phrase payload
68
- return biosSeedPhrasePayload
69
- } else if (!isEqual(storedSeedPhrasePayload.mnemonic.mnemonic, biosWalletSeedPhraseParts)) {
70
- // If there is a seed phrase in the OS settings that does not match the BIOS seed phrase
71
- // Update bios with existing user seed phrase
72
- const updatedBiosSeedPhrase = storedSeedPhrasePayload.mnemonic.mnemonic.join(' ')
73
- await this.context.kernel?.bios?.seedPhraseStore.set('user', updatedBiosSeedPhrase)
74
- }
75
- // Return stored seed phrase
76
- return storedSeedPhrasePayload
77
- }
78
- }
@@ -1,27 +0,0 @@
1
- import { assertEx } from '@xylabs/sdk-js'
2
- import { asArchivistInstance } from '@xyo-network/archivist-model'
3
- import { asDivinerInstance } from '@xyo-network/diviner-model'
4
- import type { XyOsContext } from '@xyo-network/os-model'
5
-
6
- const OsSettingsArchivistModuleName = 'OsSettingsNode:OsSettingsArchivist'
7
- const OsSettingsArchivistPayloadDivinerModuleName = 'OsSettingsNode:OsSettingsArchivistPayloadDiviner'
8
-
9
- export class OsSettingsCallerBase {
10
- protected context: XyOsContext
11
- constructor(context: XyOsContext) {
12
- this.context = context
13
- }
14
-
15
- async getOsSettingsArchivist() {
16
- const mod = assertEx(await this.context.root.resolve(OsSettingsArchivistModuleName), () => `${OsSettingsArchivistModuleName} not found`)
17
- return asArchivistInstance(mod, () => `${OsSettingsArchivistModuleName} is not an archivist`, { required: true })
18
- }
19
-
20
- async getOsSettingsPayloadDiviner() {
21
- const mod = assertEx(
22
- await this.context.root.resolve(OsSettingsArchivistPayloadDivinerModuleName),
23
- () => `${OsSettingsArchivistPayloadDivinerModuleName} not found`,
24
- )
25
- return asDivinerInstance(mod, () => `${OsSettingsArchivistPayloadDivinerModuleName} is not a diviner`, { required: true })
26
- }
27
- }
@@ -1,81 +0,0 @@
1
- import { assertEx } from '@xylabs/sdk-js'
2
- import type {
3
- NodeBackground, WalletSeedPhrase, XyOsContext,
4
- } from '@xyo-network/os-model'
5
- import { isNodeBackground, isWalletSeedPhrase } from '@xyo-network/os-model'
6
-
7
- import type { Listener, ResourceStore } from '../../lib/index.ts'
8
- import { PayloadStore } from '../../lib/index.ts'
9
- import { OsSettingsCallerBase } from './CallerBase.ts'
10
- import { OsSettingsQueries } from './SettingsQueries.ts'
11
-
12
- export type OsSettingsResourceViews = 'wallets' | 'latestUserWallet' | 'nodeBackground'
13
-
14
- export class OsSettingsResource extends OsSettingsCallerBase implements ResourceStore<OsSettingsResourceViews> {
15
- private _latestUserWalletListener: PayloadStore<WalletSeedPhrase> | undefined
16
- private _nodeBackgroundListener: PayloadStore<NodeBackground> | undefined
17
- private _walletsListener: PayloadStore<WalletSeedPhrase> | undefined
18
-
19
- constructor(context: XyOsContext) {
20
- super(context)
21
- }
22
-
23
- get latestUserWalletListener() {
24
- return assertEx(this._latestUserWalletListener, () => 'Latest user wallet listener not set')
25
- }
26
-
27
- get nodeBackgroundListener() {
28
- return assertEx(this._nodeBackgroundListener, () => 'Node background listener not set')
29
- }
30
-
31
- get subscriptions() {
32
- return {
33
- latestUserWallet: (cb: Listener) => this.walletsListener.subscribe(cb),
34
- nodeBackground: (cb: Listener) => this.nodeBackgroundListener.subscribe(cb),
35
- wallets: (cb: Listener) => this.walletsListener.subscribe(cb),
36
- }
37
- }
38
-
39
- get views() {
40
- return {
41
- latestUserWallet: () => this.latestUserWalletListener.latest,
42
- nodeBackground: () => this.nodeBackgroundListener.latest,
43
- wallets: () => this.walletsListener.latest,
44
- }
45
- }
46
-
47
- get walletsListener() {
48
- return assertEx(this._walletsListener, () => 'Wallets listener not set')
49
- }
50
-
51
- cleanupListeners() {
52
- this.walletsListener.cleanupListeners()
53
- this.latestUserWalletListener.cleanupListeners()
54
- }
55
-
56
- /**
57
- * start listeners
58
- */
59
- async start() {
60
- const archivist = await this.getOsSettingsArchivist()
61
- const diviner = await this.getOsSettingsPayloadDiviner()
62
-
63
- this._walletsListener = await PayloadStore.create<WalletSeedPhrase>({
64
- archivist,
65
- getLatest: async () => await OsSettingsQueries.getWallets(diviner),
66
- idFunction: isWalletSeedPhrase,
67
- })
68
-
69
- this._latestUserWalletListener = await PayloadStore.create<WalletSeedPhrase>({
70
- archivist,
71
- getLatest: async () => await OsSettingsQueries.getLatestUserWallet(diviner),
72
- idFunction: isWalletSeedPhrase,
73
- })
74
-
75
- this._nodeBackgroundListener = await PayloadStore.create<NodeBackground>({
76
- archivist,
77
- getLatest: async () => await OsSettingsQueries.getNodeBackground(diviner),
78
- idFunction: isNodeBackground,
79
- })
80
- }
81
- }
@@ -1,56 +0,0 @@
1
- import type { ArchivistInstance } from '@xyo-network/archivist-model'
2
- import type { DivinerInstance } from '@xyo-network/diviner-model'
3
- import { PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
4
- import type { NodeBackground, WalletSeedPhrase } from '@xyo-network/os-model'
5
- import { NodeBackgroundSchema, WalletSeedPhraseSchema } from '@xyo-network/os-model'
6
- import { PayloadBuilder } from '@xyo-network/payload-builder'
7
- import type { WithSources } from '@xyo-network/payload-model'
8
-
9
- const NO_RESULTS: WithSources<WalletSeedPhrase>[] = []
10
-
11
- export const OsSettingsQueries = {
12
- async getLatestUserWallet(diviner: DivinerInstance, archivist?: ArchivistInstance): Promise<WalletSeedPhrase[]> {
13
- const query = {
14
- limit: 1,
15
- order: 'desc',
16
- schema: PayloadDivinerQuerySchema,
17
- schemas: [WalletSeedPhraseSchema],
18
- }
19
- const results = (await diviner.divine([query])) as WalletSeedPhrase[]
20
- const wallet = results.find(payload => payload.$label === 'userWallet')
21
- if (wallet) return [wallet]
22
- // Check for legacy payload and optionally migrate by re-minting it in the updates format.
23
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
- const legacyWallet = results.find(payload => (payload as any).$meta.label === 'userWallet')
25
- if (legacyWallet && archivist) {
26
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
- const legacyMeta = (legacyWallet as any).$meta
28
- const newWalletPayloadFields = {
29
- mnemonic: legacyWallet.mnemonic,
30
- $label: legacyMeta.label,
31
- $timestamp: legacyMeta.$timestamp,
32
- }
33
- const payload = new PayloadBuilder<WalletSeedPhrase>({ schema: WalletSeedPhraseSchema }).fields(newWalletPayloadFields).build()
34
- await archivist.insert([payload])
35
- return [payload]
36
- }
37
- return NO_RESULTS
38
- },
39
- async getNodeBackground(diviner: DivinerInstance) {
40
- const query = {
41
- limit: 1,
42
- order: 'desc',
43
- schema: PayloadDivinerQuerySchema,
44
- schemas: [NodeBackgroundSchema],
45
- }
46
- return (await diviner.divine([query])) as WithSources<NodeBackground>[]
47
- },
48
- async getWallets(diviner: DivinerInstance) {
49
- const query = {
50
- order: 'desc',
51
- schema: PayloadDivinerQuerySchema,
52
- schemas: [WalletSeedPhraseSchema],
53
- }
54
- return (await diviner.divine([query])) as WithSources<WalletSeedPhrase>[]
55
- },
56
- }
@@ -1,30 +0,0 @@
1
- import type { ValidOsAchievements } from '@xyo-network/os-model'
2
- import { OsBadgeSchema } from '@xyo-network/os-model'
3
-
4
- import { OsSettingsCallerBase } from '../CallerBase.ts'
5
- import { OsBadgeQueries } from './Queries.ts'
6
-
7
- export class OsBadgeCaller extends OsSettingsCallerBase {
8
- /**
9
- * @param achievement
10
- */
11
- async getBadge(achievement: ValidOsAchievements) {
12
- const diviner = await this.getOsSettingsPayloadDiviner()
13
- const results = await OsBadgeQueries.getBadge(achievement, diviner)
14
- return results[0] ?? null
15
- }
16
-
17
- /**
18
- * @param achievement
19
- */
20
- async saveBadge(achievement: ValidOsAchievements) {
21
- const badge = {
22
- achievement,
23
- schema: OsBadgeSchema,
24
- timestamp: Date.now(),
25
- }
26
-
27
- const archivist = await this.getOsSettingsArchivist()
28
- return await archivist.insert([badge])
29
- }
30
- }
@@ -1,19 +0,0 @@
1
- import type { DivinerInstance } from '@xyo-network/diviner-model'
2
- import { PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
3
- import type { OsBadge } from '@xyo-network/os-model'
4
- import { OsBadgeSchema } from '@xyo-network/os-model'
5
- import type { WithSources } from '@xyo-network/payload-model'
6
-
7
- export const OsBadgeQueries = {
8
- getBadge: async (achievement: string, diviner: DivinerInstance) => {
9
- const query = {
10
- achievement,
11
- limit: 1,
12
- order: 'desc',
13
- schema: PayloadDivinerQuerySchema,
14
- schemas: [OsBadgeSchema],
15
- }
16
-
17
- return (await diviner.divine([query])) as WithSources<OsBadge>[]
18
- },
19
- }
@@ -1,50 +0,0 @@
1
- import { assertEx } from '@xylabs/sdk-js'
2
- import type { OsBadge, XyOsContext } from '@xyo-network/os-model'
3
- import { isBadgeWithMeta } from '@xyo-network/os-model'
4
-
5
- import type { ResourceStore } from '../../../lib/index.ts'
6
- import { PayloadStore } from '../../../lib/index.ts'
7
- import { OsSettingsCallerBase } from '../CallerBase.ts'
8
- import { OsBadgeQueries } from './Queries.ts'
9
-
10
- export type OsBadgeResourceViews = 'savedSeedPhrase'
11
-
12
- export class OsBadgeResource extends OsSettingsCallerBase implements ResourceStore<OsBadgeResourceViews> {
13
- static readonly views: OsBadgeResourceViews[] = ['savedSeedPhrase']
14
-
15
- private _savedSeedPhrase: PayloadStore<OsBadge> | undefined
16
-
17
- constructor(xyOsContext: XyOsContext) {
18
- super(xyOsContext)
19
- }
20
-
21
- get savedSeedPhrase() {
22
- return assertEx(this._savedSeedPhrase, () => 'Saved seed phrase listener not set')
23
- }
24
-
25
- get subscriptions() {
26
- return { savedSeedPhrase: (cb: () => void) => this.savedSeedPhrase.subscribe(cb) }
27
- }
28
-
29
- get views() {
30
- return { savedSeedPhrase: () => this.savedSeedPhrase.latest }
31
- }
32
-
33
- cleanupListeners() {
34
- this.savedSeedPhrase.cleanupListeners()
35
- }
36
-
37
- /**
38
- * start listeners
39
- */
40
- async start() {
41
- const diviner = await this.getOsSettingsPayloadDiviner()
42
- const archivist = await this.getOsSettingsArchivist()
43
-
44
- this._savedSeedPhrase = await PayloadStore.create<OsBadge>({
45
- archivist,
46
- getLatest: async () => await OsBadgeQueries.getBadge('savedSeedPhrase', diviner),
47
- idFunction: isBadgeWithMeta,
48
- })
49
- }
50
- }
@@ -1,2 +0,0 @@
1
- export * from './Caller.ts'
2
- export * from './Resource.ts'
@@ -1,5 +0,0 @@
1
- export * from './badge/index.ts'
2
- export * from './Caller.ts'
3
- export * from './CallerBase.ts'
4
- export * from './Resource.ts'
5
- export * from './SettingsQueries.ts'
@@ -1,122 +0,0 @@
1
- import { assertEx } from '@xylabs/sdk-js'
2
- import { asArchivistInstance } from '@xyo-network/archivist-model'
3
- import { replaceManifestTokens } from '@xyo-network/kernel'
4
- import { DappPackageManifestPayloadSchema } from '@xyo-network/manifest'
5
- import type { ManifestWrapper } from '@xyo-network/manifest-wrapper'
6
- import { ModuleFactoryLocator } from '@xyo-network/module-factory-locator'
7
- import type { ModuleFactoryLocatorInstance } from '@xyo-network/module-model'
8
- import type { NodeInstance } from '@xyo-network/node-model'
9
- import type {
10
- DappId, DappPackageManifestPayload, ExternalModule, XyOsContext,
11
- } from '@xyo-network/os-model'
12
- import type { WalletInstance } from '@xyo-network/wallet-model'
13
-
14
- import type { DappNodesCreatorParams } from '../../../classes/lib/index.ts'
15
- import { DappCallerBase } from '../../../DappCallerBase.ts'
16
- import { manifestReplacementTokens } from '../../../manifest/index.ts'
17
- import { DefaultPayloads } from './DefaultPayloads/index.ts'
18
- import { ExternalModulePermissions } from './ExternalModulePermissions/index.ts'
19
-
20
- export type TargetDappManifestParams = ConstructorParameters<typeof ManifestWrapper<DappPackageManifestPayload>>
21
-
22
- export class DappContextCreator {
23
- // Designated offset path for the wallet used by windowed dapps. In the future, other offsets could be used for other dapp modes
24
- private static DAPP_WINDOW_WALLET_PATH = '1'
25
-
26
- private context: XyOsContext
27
- private dappId: DappId
28
- private externalPermissions?: ExternalModule[]
29
- private rootWallet: WalletInstance
30
- private sharedLocator?: ModuleFactoryLocatorInstance
31
- private targetDappManifestParams: TargetDappManifestParams
32
-
33
- constructor(
34
- targetDappManifestParams: TargetDappManifestParams,
35
- dappId: DappId,
36
- context: XyOsContext,
37
- rootWallet: WalletInstance,
38
- externalPermissions?: ExternalModule[],
39
- sharedLocator?: ModuleFactoryLocatorInstance,
40
- ) {
41
- this.targetDappManifestParams = targetDappManifestParams
42
- this.dappId = dappId
43
- this.context = context
44
- this.rootWallet = rootWallet
45
- this.externalPermissions = externalPermissions
46
- this.sharedLocator = sharedLocator
47
- }
48
-
49
- static async create(params: DappNodesCreatorParams, xnsNodeUrl: string | undefined, xnsNetwork: string | undefined) {
50
- const {
51
- config, locator, context, wallet,
52
- } = params
53
- const {
54
- payload, dappName, publicChildren, privateChildren,
55
- } = config
56
-
57
- const { external, manifestPayload } = this.parseDappPackageManifestPayload(payload, xnsNodeUrl, xnsNetwork)
58
- console.debug('[DEBUG] dApp manifest', manifestPayload)
59
-
60
- // derive a wallet for the dapp to use from the root wallet
61
- const dappWallet = await wallet.derivePath(DappContextCreator.DAPP_WINDOW_WALLET_PATH)
62
- const targetDappManifestParams: TargetDappManifestParams = [manifestPayload,
63
- dappWallet,
64
- locator ?? new ModuleFactoryLocator(),
65
- publicChildren,
66
- privateChildren]
67
-
68
- const instance = new this(targetDappManifestParams, dappName, context, wallet, external?.modules, locator)
69
- return instance
70
- }
71
-
72
- // Add default payloads to the archivist shared between the os and the dapp
73
- static async primeDappArchivist(dappContext: XyOsContext, osContext: XyOsContext, dappName: DappId) {
74
- const dappCaller = new DappCallerBase(dappContext)
75
- const dappArchivist = await dappCaller.getDappArchivist()
76
- const defaultPayloads = new DefaultPayloads(dappArchivist, osContext, dappName)
77
-
78
- await defaultPayloads.insert()
79
- }
80
-
81
- // Reset the dapp archivist to remove all payloads
82
- static async resetDappArchivist(context: XyOsContext) {
83
- const dappModule = await context.root.resolve('DappArchivist')
84
- const dappArchivist = assertEx(asArchivistInstance(dappModule), () => 'resetDappArchivist: DappArchivist not found')
85
-
86
- await dappArchivist.clear()
87
- }
88
-
89
- private static parseDappPackageManifestPayload(payload: DappPackageManifestPayload, xnsNodeUrl: string | undefined, xnsNetwork: string | undefined) {
90
- // extract external permissions from package manifest payload
91
- const { external, ...manifestWithoutExternals } = payload
92
- const manifestPayloadRaw: DappPackageManifestPayload = {
93
- ...manifestWithoutExternals,
94
- schema: DappPackageManifestPayloadSchema,
95
- }
96
- console.log('DappContextCreator:parseDappPackageManifestPayload', xnsNodeUrl, xnsNetwork)
97
- const manifestPayload = replaceManifestTokens(manifestPayloadRaw, manifestReplacementTokens(xnsNodeUrl, xnsNetwork))
98
- return { external, manifestPayload }
99
- }
100
-
101
- async loadDappContext(context: XyOsContext): Promise<XyOsContext> {
102
- console.log('DappNodesCreator:loadDappContext', this.dappId)
103
- // build nodes and attach to dappNodes to dappWindowNode
104
- const dapp
105
- = (await context.dappByName(this.dappId))
106
- ?? (await (async () => {
107
- const dapp = await context.buildDapp(this.targetDappManifestParams[0], this.dappId)
108
- await dapp.boot(this.rootWallet, this.sharedLocator)
109
- return dapp
110
- })())
111
- await this.handleExternalModulePermissions(dapp.root)
112
- await DappContextCreator.primeDappArchivist(dapp, this.context, this.dappId)
113
-
114
- return dapp
115
- }
116
-
117
- // try to satisfy the external permissions requested by a dapp
118
- private async handleExternalModulePermissions(dappWindowNode: NodeInstance) {
119
- const externalModulePermissions = new ExternalModulePermissions(this.context, dappWindowNode, this.dappId, this.externalPermissions)
120
- await externalModulePermissions.permit()
121
- }
122
- }
@@ -1,20 +0,0 @@
1
- import type { DappName, XyOsContext } from '@xyo-network/os-model'
2
-
3
- import type { DefaultPayloadsInsertable } from '../../../../classes/lib/index.ts'
4
- import { OsCallerBase } from '../../../../OsCallerBase.ts'
5
-
6
- export class DappAccessPayloads implements DefaultPayloadsInsertable {
7
- private context: XyOsContext
8
- constructor(
9
- context: XyOsContext,
10
- _dappName: DappName,
11
- ) {
12
- this.context = context
13
- }
14
-
15
- async payloads() {
16
- const osCaller = new OsCallerBase(this.context)
17
- const archivist = await osCaller.getRegisteredDappInterfacesArchivist()
18
- return await archivist.all()
19
- }
20
- }