@xyo-network/os-runtime 4.2.10 → 4.2.12
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/dist/neutral/helpers/DappInitializer.d.ts +18 -0
- package/dist/neutral/helpers/DappInitializer.d.ts.map +1 -0
- package/dist/neutral/helpers/index.d.ts +1 -0
- package/dist/neutral/helpers/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +40 -2
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/node/helpers/DappInitializer.d.ts +18 -0
- package/dist/node/helpers/DappInitializer.d.ts.map +1 -0
- package/dist/node/helpers/index.d.ts +1 -0
- package/dist/node/helpers/index.d.ts.map +1 -1
- package/dist/node/index.mjs +40 -2
- package/dist/node/index.mjs.map +1 -1
- package/package.json +8 -8
- package/src/helpers/DappInitializer.ts +57 -0
- package/src/helpers/index.ts +1 -0
- package/src/spec/boot.test.ts +89 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/os-runtime",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.12",
|
|
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.
|
|
49
|
+
"@xyo-network/bios": "^4.2.12",
|
|
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.
|
|
58
|
-
"@xyo-network/kernel-model": "^4.2.
|
|
57
|
+
"@xyo-network/kernel": "^4.2.12",
|
|
58
|
+
"@xyo-network/kernel-model": "^4.2.12",
|
|
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.
|
|
67
|
+
"@xyo-network/os-model": "^4.2.12",
|
|
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.
|
|
70
|
+
"@xyo-network/storage-model": "^4.2.12",
|
|
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.
|
|
92
|
-
"@xyo-network/bios-nodejs": "^4.2.
|
|
91
|
+
"@xyo-network/bios-model": "^4.2.12",
|
|
92
|
+
"@xyo-network/bios-nodejs": "^4.2.12",
|
|
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
|
+
}
|
package/src/helpers/index.ts
CHANGED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { WalletInstance } from '@xyo-network/account'
|
|
2
|
+
import { HDWallet } from '@xyo-network/account'
|
|
3
|
+
import type { BiosExternalInterface } from '@xyo-network/bios-model'
|
|
4
|
+
import { boot } from '@xyo-network/bios-nodejs'
|
|
5
|
+
import { Kernel } from '@xyo-network/kernel'
|
|
6
|
+
import type { KernelExternal } from '@xyo-network/kernel-model'
|
|
7
|
+
import type { WalletKindSignerPaths } from '@xyo-network/os-model'
|
|
8
|
+
import {
|
|
9
|
+
beforeEach,
|
|
10
|
+
describe, expect, test,
|
|
11
|
+
} from 'vitest'
|
|
12
|
+
|
|
13
|
+
import type { DappRegistrationServiceParams } from '../classes/index.ts'
|
|
14
|
+
import { XyOs } from '../XyOs.ts'
|
|
15
|
+
|
|
16
|
+
describe('os', () => {
|
|
17
|
+
let bios: BiosExternalInterface
|
|
18
|
+
let osWallet: WalletInstance
|
|
19
|
+
let kernel: KernelExternal
|
|
20
|
+
|
|
21
|
+
const testSigner0Path = '0/0'
|
|
22
|
+
const testSigner1Path = '0/1'
|
|
23
|
+
const userPaths = new Map([['testSigner0', testSigner0Path], ['testSigner1', testSigner1Path]])
|
|
24
|
+
const paths: WalletKindSignerPaths = new Map([['user', userPaths]])
|
|
25
|
+
|
|
26
|
+
beforeEach(async () => {
|
|
27
|
+
bios = await boot()
|
|
28
|
+
const osWalletSeedPhrase = await bios.seedPhraseStore.get('os')
|
|
29
|
+
osWallet = await HDWallet.fromPhrase(osWalletSeedPhrase as string)
|
|
30
|
+
kernel = new Kernel({ bios })
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
describe('boot', () => {
|
|
34
|
+
test('with default params', async () => {
|
|
35
|
+
const xyOs = new XyOs()
|
|
36
|
+
await xyOs.boot(osWallet)
|
|
37
|
+
expect(xyOs).toBeDefined()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('with dapps', async () => {
|
|
41
|
+
const dappsConfiguration: DappRegistrationServiceParams = {
|
|
42
|
+
dappNames: ['testDapp'],
|
|
43
|
+
dappParams: {},
|
|
44
|
+
dappPayloads: [],
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const xyOs = new XyOs({ dappsConfiguration })
|
|
48
|
+
await xyOs.boot(osWallet)
|
|
49
|
+
expect(xyOs).toBeDefined()
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('default stacks', async () => {
|
|
53
|
+
const bios = await boot()
|
|
54
|
+
const kernel = new Kernel()
|
|
55
|
+
await kernel.boot(bios)
|
|
56
|
+
const xyOs = new XyOs({ kernel })
|
|
57
|
+
expect(xyOs).toBeDefined()
|
|
58
|
+
if (xyOs) {
|
|
59
|
+
const osWalletSeedPhrase = await bios.seedPhraseStore.get('os')
|
|
60
|
+
expect(osWalletSeedPhrase).toBeDefined()
|
|
61
|
+
const osWallet = await HDWallet.fromPhrase(osWalletSeedPhrase as string)
|
|
62
|
+
expect(osWallet).toBeDefined()
|
|
63
|
+
await xyOs.boot(osWallet)
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('no stacks', async () => {
|
|
68
|
+
const xyOs = new XyOs({ stackMap: {} })
|
|
69
|
+
expect(xyOs).toBeDefined()
|
|
70
|
+
if (xyOs) {
|
|
71
|
+
await xyOs.boot(osWallet)
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('supports users signing', async () => {
|
|
76
|
+
const params = { kernel, signerPaths: paths }
|
|
77
|
+
|
|
78
|
+
const xyOs = new XyOs(params)
|
|
79
|
+
|
|
80
|
+
expect(xyOs).toBeDefined()
|
|
81
|
+
|
|
82
|
+
if (xyOs) {
|
|
83
|
+
await xyOs.boot(osWallet)
|
|
84
|
+
expect(xyOs.user).toBeDefined()
|
|
85
|
+
expect(xyOs.user.signers).toBeDefined()
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
})
|