@xyo-network/os-runtime 4.2.9 → 4.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/os-runtime",
3
- "version": "4.2.9",
3
+ "version": "4.2.11",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -46,7 +46,7 @@
46
46
  "@xyo-network/archivist": "^3.6.9",
47
47
  "@xyo-network/archivist-indexeddb": "^3.6.9",
48
48
  "@xyo-network/archivist-model": "^3.6.9",
49
- "@xyo-network/bios": "^4.2.9",
49
+ "@xyo-network/bios": "^4.2.11",
50
50
  "@xyo-network/bridge-model": "^3.6.9",
51
51
  "@xyo-network/diviner-abstract": "^3.6.9",
52
52
  "@xyo-network/diviner-model": "^3.6.9",
@@ -54,8 +54,8 @@
54
54
  "@xyo-network/diviner-payload-indexeddb": "^3.6.9",
55
55
  "@xyo-network/diviner-payload-model": "^3.6.9",
56
56
  "@xyo-network/diviner-temporal-indexing-model": "^3.6.9",
57
- "@xyo-network/kernel": "^4.2.9",
58
- "@xyo-network/kernel-model": "^4.2.9",
57
+ "@xyo-network/kernel": "^4.2.11",
58
+ "@xyo-network/kernel-model": "^4.2.11",
59
59
  "@xyo-network/manifest": "^3.6.9",
60
60
  "@xyo-network/manifest-wrapper": "^3.6.9",
61
61
  "@xyo-network/module-event-emitter": "^3.6.9",
@@ -64,10 +64,10 @@
64
64
  "@xyo-network/module-model": "^3.6.9",
65
65
  "@xyo-network/module-resolver": "^3.6.9",
66
66
  "@xyo-network/node-model": "^3.6.9",
67
- "@xyo-network/os-model": "^4.2.9",
67
+ "@xyo-network/os-model": "^4.2.11",
68
68
  "@xyo-network/payload-builder": "^3.6.9",
69
69
  "@xyo-network/payload-model": "^3.6.9",
70
- "@xyo-network/storage-model": "^4.2.9",
70
+ "@xyo-network/storage-model": "^4.2.11",
71
71
  "@xyo-network/wallet-model": "^3.6.9",
72
72
  "async-mutex": "^0.5.0",
73
73
  "chalk": "^5.4.1",
@@ -88,8 +88,8 @@
88
88
  "@types/yargs": "^17.0.33",
89
89
  "@xylabs/ts-scripts-yarn3": "^4.2.6",
90
90
  "@xylabs/tsconfig": "^4.2.6",
91
- "@xyo-network/bios-model": "^4.2.9",
92
- "@xyo-network/bios-nodejs": "^4.2.9",
91
+ "@xyo-network/bios-model": "^4.2.11",
92
+ "@xyo-network/bios-nodejs": "^4.2.11",
93
93
  "vitest": "^2.1.8"
94
94
  },
95
95
  "publishConfig": {
@@ -0,0 +1,57 @@
1
+ import { assertEx } from '@xylabs/assert'
2
+ import type {
3
+ RegisteredDapp, WindowDappNodeSet, XyOsContext,
4
+ } from '@xyo-network/os-model'
5
+
6
+ import { RunningDappCache } from '../classes/index.ts'
7
+ import { DappSeedPhraseRepository } from '../wallet/index.ts'
8
+
9
+ /** Helper class to simulate full dapp initialization by the OS */
10
+ export interface DappInitializerConfig<T extends RegisteredDapp = RegisteredDapp> {
11
+ allowedNames: string[]
12
+ dapp: T
13
+ xnsNetwork: string | undefined
14
+ xnsNodeUrl: string | undefined
15
+ xyOs: XyOsContext
16
+ }
17
+
18
+ export class DappInitializer<T extends RegisteredDapp = RegisteredDapp> {
19
+ private _config: DappInitializerConfig
20
+
21
+ constructor(config: DappInitializerConfig) {
22
+ this._config = config
23
+ }
24
+
25
+ get config() {
26
+ return assertEx(this._config, () => new Error('Options not set'))
27
+ }
28
+
29
+ async install(): Promise<WindowDappNodeSet> {
30
+ const dappWithWalletId = await this.installDappWallet()
31
+
32
+ return await this.initializeDappContext(dappWithWalletId)
33
+ }
34
+
35
+ private async initializeDappContext(dappWithWalletId: T): Promise<WindowDappNodeSet> {
36
+ const {
37
+ allowedNames, xnsNetwork, xnsNodeUrl, xyOs,
38
+ } = this.config
39
+
40
+ return await RunningDappCache.findOrCreate(dappWithWalletId, xyOs, allowedNames ?? [], xnsNodeUrl, xnsNetwork)
41
+ }
42
+
43
+ private async installDappWallet(): Promise<T> {
44
+ const { xyOs, dapp } = this.config
45
+ const dappSeedPhraseRepository = new DappSeedPhraseRepository(xyOs, [dapp.config.name])
46
+ const walletId = await dappSeedPhraseRepository.findOrCreate(dapp.config.name)
47
+
48
+ // Update the dapp with the walletId
49
+ return {
50
+ ...dapp,
51
+ config: {
52
+ ...dapp.config,
53
+ walletId,
54
+ },
55
+ } as T
56
+ }
57
+ }
@@ -1 +1,2 @@
1
+ export * from './DappInitializer.ts'
1
2
  export * from './monitor/index.ts'