@xyo-network/os-runtime 3.0.9 → 3.0.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/dist/neutral/index.d.ts +101 -72
- package/dist/neutral/index.mjs +2617 -2534
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +14 -13
- package/src/XyOs.ts +23 -3
- package/src/XyOsBase.ts +11 -1
- package/src/XyOsDapp.ts +10 -1
- package/src/classes/index.ts +1 -0
- package/src/classes/node/Creator.ts +1 -1
- package/src/classes/registration/DappRegistrationService.ts +11 -2
- package/src/classes/signer/Signers.ts +73 -0
- package/src/classes/signer/index.ts +1 -0
- package/src/stack/Manager.ts +8 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/os-runtime",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.11",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -39,16 +39,17 @@
|
|
|
39
39
|
"@xyo-network/archivist": "^3.0.7",
|
|
40
40
|
"@xyo-network/archivist-indexeddb": "^3.0.7",
|
|
41
41
|
"@xyo-network/archivist-model": "^3.0.7",
|
|
42
|
-
"@xyo-network/bios": "^3.0.
|
|
43
|
-
"@xyo-network/
|
|
44
|
-
"@xyo-network/
|
|
45
|
-
"@xyo-network/diviner-
|
|
46
|
-
"@xyo-network/diviner-
|
|
47
|
-
"@xyo-network/diviner-payload-
|
|
48
|
-
"@xyo-network/diviner-payload-
|
|
49
|
-
"@xyo-network/diviner-
|
|
50
|
-
"@xyo-network/
|
|
51
|
-
"@xyo-network/kernel
|
|
42
|
+
"@xyo-network/bios": "^3.0.11",
|
|
43
|
+
"@xyo-network/bios-model": "^3.0.11",
|
|
44
|
+
"@xyo-network/bridge-model": "^3.0.5",
|
|
45
|
+
"@xyo-network/diviner-abstract": "^3.0.5",
|
|
46
|
+
"@xyo-network/diviner-model": "^3.0.5",
|
|
47
|
+
"@xyo-network/diviner-payload-generic": "^3.0.5",
|
|
48
|
+
"@xyo-network/diviner-payload-indexeddb": "^3.0.5",
|
|
49
|
+
"@xyo-network/diviner-payload-model": "^3.0.5",
|
|
50
|
+
"@xyo-network/diviner-temporal-indexing-model": "^3.0.5",
|
|
51
|
+
"@xyo-network/kernel": "^3.0.11",
|
|
52
|
+
"@xyo-network/kernel-model": "^3.0.11",
|
|
52
53
|
"@xyo-network/manifest": "^3.0.7",
|
|
53
54
|
"@xyo-network/manifest-wrapper": "^3.0.7",
|
|
54
55
|
"@xyo-network/module-abstract": "^3.0.7",
|
|
@@ -57,7 +58,7 @@
|
|
|
57
58
|
"@xyo-network/module-model": "^3.0.7",
|
|
58
59
|
"@xyo-network/module-resolver": "^3.0.7",
|
|
59
60
|
"@xyo-network/node-model": "^3.0.7",
|
|
60
|
-
"@xyo-network/os-model": "^3.0.
|
|
61
|
+
"@xyo-network/os-model": "^3.0.11",
|
|
61
62
|
"@xyo-network/payload-builder": "^3.0.7",
|
|
62
63
|
"@xyo-network/payload-model": "^3.0.7",
|
|
63
64
|
"@xyo-network/wallet-model": "^3.0.7",
|
|
@@ -71,7 +72,7 @@
|
|
|
71
72
|
"@types/uuid": "^10.0.0",
|
|
72
73
|
"@xylabs/ts-scripts-yarn3": "^4.0.0",
|
|
73
74
|
"@xylabs/tsconfig": "^4.0.0",
|
|
74
|
-
"@xyo-network/bios-nodejs": "^3.0.
|
|
75
|
+
"@xyo-network/bios-nodejs": "^3.0.11",
|
|
75
76
|
"typescript": "^5.5.4",
|
|
76
77
|
"vitest": "^2.0.5"
|
|
77
78
|
},
|
package/src/XyOs.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
DappId,
|
|
11
11
|
DappPackageManifestPayload,
|
|
12
12
|
DappParams,
|
|
13
|
+
SignersExternal,
|
|
13
14
|
StackInitializer,
|
|
14
15
|
XyOsContext,
|
|
15
16
|
XyOsDappContext,
|
|
@@ -17,13 +18,14 @@ import type {
|
|
|
17
18
|
} from '@xyo-network/os-model'
|
|
18
19
|
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
19
20
|
|
|
21
|
+
import { Signers } from './classes/index.ts'
|
|
20
22
|
import type { DappRegistrationServiceParams } from './classes/registration/index.ts'
|
|
21
23
|
import { DappRegistrationService } from './classes/registration/index.ts'
|
|
22
24
|
import { EventBus } from './event/index.ts'
|
|
23
25
|
import type { MonitorEventConfig, XyOsMonitor } from './helpers/index.ts'
|
|
24
26
|
import { NameTransforms } from './lib/index.ts'
|
|
25
27
|
import { loadOsNode } from './loadOsNode.ts'
|
|
26
|
-
import type { OsPubSubNetworkStack } from './stack/index.ts'
|
|
28
|
+
import type { OsPubSubNetworkStack, UninitializedStackMap } from './stack/index.ts'
|
|
27
29
|
import { OsStackMap, StackManager } from './stack/index.ts'
|
|
28
30
|
import type { XyOsContextParams } from './XyOsBase.ts'
|
|
29
31
|
import { XyOsContextBase } from './XyOsBase.ts'
|
|
@@ -32,6 +34,7 @@ export interface XyOsParams<TManifest extends PackageManifest = PackageManifest>
|
|
|
32
34
|
dappsConfiguration?: DappRegistrationServiceParams
|
|
33
35
|
developmentMode?: boolean
|
|
34
36
|
kernel?: XyOsContext['kernel']
|
|
37
|
+
stackMap?: UninitializedStackMap
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
export class XyOs extends XyOsContextBase<XyOsParams> implements XyOsContext {
|
|
@@ -40,18 +43,26 @@ export class XyOs extends XyOsContextBase<XyOsParams> implements XyOsContext {
|
|
|
40
43
|
protected _kernel: KernelExternal
|
|
41
44
|
protected _locator: ModuleFactoryLocator
|
|
42
45
|
protected dappRegistrationService: DappRegistrationService
|
|
46
|
+
protected signers: SignersExternal | undefined
|
|
43
47
|
private stackManager: StackManager
|
|
44
48
|
|
|
45
49
|
constructor({
|
|
46
|
-
eventBus = new EventBus(),
|
|
50
|
+
eventBus = new EventBus(),
|
|
51
|
+
kernel = new Kernel(),
|
|
52
|
+
locator = new ModuleFactoryLocator(),
|
|
53
|
+
dappsConfiguration,
|
|
54
|
+
developmentMode,
|
|
55
|
+
stackMap = OsStackMap,
|
|
56
|
+
...params
|
|
47
57
|
}: XyOsParams = {}) {
|
|
48
58
|
super({
|
|
49
59
|
eventBus, kernel, locator, ...params,
|
|
50
60
|
})
|
|
51
61
|
this._locator = locator
|
|
52
62
|
this._kernel = kernel
|
|
53
|
-
this.stackManager = new StackManager(
|
|
63
|
+
this.stackManager = new StackManager(stackMap)
|
|
54
64
|
this.dappRegistrationService = new DappRegistrationService(this, dappsConfiguration, this.locator, developmentMode)
|
|
65
|
+
if (this.signerPaths && this.kernel?.bios?.seedPhraseStore) this.signers = new Signers(this.signerPaths, this.kernel?.bios?.seedPhraseStore)
|
|
55
66
|
}
|
|
56
67
|
|
|
57
68
|
static get monitoring(): XyOsMonitor | undefined {
|
|
@@ -82,6 +93,14 @@ export class XyOs extends XyOsContextBase<XyOsParams> implements XyOsContext {
|
|
|
82
93
|
return this._locator
|
|
83
94
|
}
|
|
84
95
|
|
|
96
|
+
get stacks() {
|
|
97
|
+
return this.stackManager.stacks
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
override get user() {
|
|
101
|
+
return { signers: this.signers?.getWalletKindSigner('user') }
|
|
102
|
+
}
|
|
103
|
+
|
|
85
104
|
static async monitor<T>(fn: () => Promise<T>, eventConfig: MonitorEventConfig): Promise<T> {
|
|
86
105
|
const { name, additionalProperties } = eventConfig
|
|
87
106
|
const monitor = this.monitoring
|
|
@@ -108,6 +127,7 @@ export class XyOs extends XyOsContextBase<XyOsParams> implements XyOsContext {
|
|
|
108
127
|
this._root = root
|
|
109
128
|
|
|
110
129
|
this.stackManager.initialize(this)
|
|
130
|
+
if (this.signers) await this.signers.initialize()
|
|
111
131
|
})
|
|
112
132
|
}
|
|
113
133
|
|
package/src/XyOsBase.ts
CHANGED
|
@@ -8,7 +8,8 @@ import { BaseEmitter } from '@xyo-network/module-abstract'
|
|
|
8
8
|
import { ModuleFactoryLocator } from '@xyo-network/module-factory-locator'
|
|
9
9
|
import type { NodeInstance } from '@xyo-network/node-model'
|
|
10
10
|
import type {
|
|
11
|
-
DappId, DappPackageManifestPayload, DappParams, EventBusInterface,
|
|
11
|
+
DappId, DappPackageManifestPayload, DappParams, EventBusInterface, OsUser,
|
|
12
|
+
StackInitializer, WalletKindSignerPaths, XyOsContext, XyOsDappContext,
|
|
12
13
|
} from '@xyo-network/os-model'
|
|
13
14
|
import { Mutex } from 'async-mutex'
|
|
14
15
|
|
|
@@ -17,6 +18,7 @@ export interface XyOsContextParams<TManifest extends PackageManifest = PackageMa
|
|
|
17
18
|
locator?: ModuleFactoryLocator
|
|
18
19
|
manifest?: TManifest
|
|
19
20
|
platformLocator?: ModuleFactoryLocator
|
|
21
|
+
signerPaths?: WalletKindSignerPaths
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
export class XyOsContextBase<TParams extends XyOsContextParams | void = void> extends BaseEmitter<
|
|
@@ -71,10 +73,18 @@ export class XyOsContextBase<TParams extends XyOsContextParams | void = void> ex
|
|
|
71
73
|
return []
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
get signerPaths() {
|
|
77
|
+
return this.params.signerPaths
|
|
78
|
+
}
|
|
79
|
+
|
|
74
80
|
get state() {
|
|
75
81
|
return this._root ? 'running' : 'stopped'
|
|
76
82
|
}
|
|
77
83
|
|
|
84
|
+
get user(): OsUser {
|
|
85
|
+
throw new Error('Method not implemented. [user]')
|
|
86
|
+
}
|
|
87
|
+
|
|
78
88
|
boot(_wallet: WalletInstance, _locator: ModuleFactoryLocator) {
|
|
79
89
|
throw new Error('Method not implemented. [boot]')
|
|
80
90
|
}
|
package/src/XyOsDapp.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { WalletInstance } from '@xyo-network/account'
|
|
|
3
3
|
import { ManifestWrapper } from '@xyo-network/manifest-wrapper'
|
|
4
4
|
import { ModuleFactoryLocator } from '@xyo-network/module-factory-locator'
|
|
5
5
|
import type {
|
|
6
|
-
DappPackageManifestPayload, XyOsContext, XyOsDappContext, XyOsDappDetails,
|
|
6
|
+
DappPackageManifestPayload, OsUser, XyOsContext, XyOsDappContext, XyOsDappDetails,
|
|
7
7
|
} from '@xyo-network/os-model'
|
|
8
8
|
import { DappPackageManifestPayloadSchema } from '@xyo-network/os-model'
|
|
9
9
|
|
|
@@ -15,6 +15,7 @@ export interface XyOsDappContextParams extends XyOsContextParams<DappPackageMani
|
|
|
15
15
|
dapp: XyOsDappDetails
|
|
16
16
|
locator: ModuleFactoryLocator
|
|
17
17
|
parent: XyOsContext
|
|
18
|
+
user: OsUser
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export class XyOsDapp extends XyOsContextBase<XyOsDappContextParams> implements XyOsDappContext {
|
|
@@ -52,6 +53,14 @@ export class XyOsDapp extends XyOsContextBase<XyOsDappContextParams> implements
|
|
|
52
53
|
return this.params.parent
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
get stacks() {
|
|
57
|
+
return []
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
override get user() {
|
|
61
|
+
return this.params.user
|
|
62
|
+
}
|
|
63
|
+
|
|
55
64
|
override async boot(wallet: WalletInstance, locator?: ModuleFactoryLocator): Promise<void> {
|
|
56
65
|
return await this._bootMutex.runExclusive(async () => {
|
|
57
66
|
console.log('XyOsDapp:boot:start', wallet.address, this.dapp.id)
|
package/src/classes/index.ts
CHANGED
|
@@ -62,7 +62,7 @@ export class DappContextCreator {
|
|
|
62
62
|
// Reset the dapp archivist to remove all payloads
|
|
63
63
|
static async resetDappArchivist(context: XyOsContext) {
|
|
64
64
|
const dappModule = await context.root.resolve('DappArchivist')
|
|
65
|
-
const dappArchivist = assertEx(asArchivistInstance(dappModule), () => 'DappArchivist not found')
|
|
65
|
+
const dappArchivist = assertEx(asArchivistInstance(dappModule), () => 'resetDappArchivist: DappArchivist not found')
|
|
66
66
|
|
|
67
67
|
await dappArchivist.clear()
|
|
68
68
|
}
|
|
@@ -76,16 +76,17 @@ export class DappRegistrationService {
|
|
|
76
76
|
this.addConnectionRequests()
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
buildDapp(
|
|
79
|
+
async buildDapp(
|
|
80
80
|
manifest: DappPackageManifestPayload,
|
|
81
81
|
dappId = NameTransforms.slug(manifest.nodes[0]?.config.name),
|
|
82
82
|
name = NameTransforms.moduleName(manifest.nodes[0]?.config.name),
|
|
83
|
-
):
|
|
83
|
+
): Promise<XyOsDappContext> {
|
|
84
84
|
const dapp = new XyOsDapp({
|
|
85
85
|
dapp: { id: dappId, name },
|
|
86
86
|
locator: this.locator,
|
|
87
87
|
manifest,
|
|
88
88
|
parent: this.context,
|
|
89
|
+
user: await this.getUser(),
|
|
89
90
|
}) as XyOsDappContext
|
|
90
91
|
this.builtDapps[dappId] = dapp
|
|
91
92
|
return dapp
|
|
@@ -130,6 +131,14 @@ export class DappRegistrationService {
|
|
|
130
131
|
this.context.eventBus.addConnection(this.exposeDappRequestConnection)
|
|
131
132
|
}
|
|
132
133
|
|
|
134
|
+
/**
|
|
135
|
+
* A method to get the user property from context and eventually modify it before handing it to a dapp
|
|
136
|
+
* i.e. curating user-approved signers
|
|
137
|
+
*/
|
|
138
|
+
private getUser(): Promisable<XyOsContext['user']> {
|
|
139
|
+
return this.context.user
|
|
140
|
+
}
|
|
141
|
+
|
|
133
142
|
private async postRegistrationHandlers(registeredDapp: RegisteredDappSetResult) {
|
|
134
143
|
if (registeredDapp.dapp) {
|
|
135
144
|
if (isRegisteredDappExposedDappSet(registeredDapp)) {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { type AccountInstance, HDWallet } from '@xyo-network/account'
|
|
3
|
+
import type {
|
|
4
|
+
WalletKind,
|
|
5
|
+
WalletSeedPhraseStore,
|
|
6
|
+
} from '@xyo-network/bios-model'
|
|
7
|
+
import type {
|
|
8
|
+
SignerAccounts, SignersExternal, WalletKindSignerPaths,
|
|
9
|
+
} from '@xyo-network/os-model'
|
|
10
|
+
|
|
11
|
+
export class Signers implements SignersExternal {
|
|
12
|
+
private _paths: WalletKindSignerPaths
|
|
13
|
+
private _signerAccounts: Map<WalletKind, SignerAccounts>
|
|
14
|
+
private _walletStore: WalletSeedPhraseStore
|
|
15
|
+
|
|
16
|
+
constructor(paths: WalletKindSignerPaths, walletStore: WalletSeedPhraseStore) {
|
|
17
|
+
this._paths = paths
|
|
18
|
+
this._walletStore = walletStore
|
|
19
|
+
this._signerAccounts = new Map()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private get paths(): WalletKindSignerPaths {
|
|
23
|
+
return assertEx(this._paths, () => 'Paths not initialized')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private get signerAccounts(): Map<WalletKind, SignerAccounts> {
|
|
27
|
+
return assertEx(this._signerAccounts, () => 'Signer accounts not initialized')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private get walletStore(): WalletSeedPhraseStore {
|
|
31
|
+
return assertEx(this._walletStore, () => 'Wallet store not initialized')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getSigner(walletKind: WalletKind, signer: string): AccountInstance | undefined {
|
|
35
|
+
return this.signerAccounts.get(walletKind)?.get(signer)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getWalletKindSigner(walletKind: WalletKind): SignerAccounts | undefined {
|
|
39
|
+
return this.signerAccounts.get(walletKind)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async initialize() {
|
|
43
|
+
for (const [walletKindName, signerPaths] of this.paths) {
|
|
44
|
+
for (const [signerName, walletPath] of signerPaths.entries()) {
|
|
45
|
+
await this.initializeSigners(walletKindName, signerName, walletPath)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private async initializeSigners(walletKindName: WalletKind, signerName: string, path: string) {
|
|
51
|
+
// test if the name and path are valid
|
|
52
|
+
assertEx(signerName, () => 'Name not found in signer paths')
|
|
53
|
+
assertEx(path, () => 'Path not found in signer paths')
|
|
54
|
+
|
|
55
|
+
// test if the wallet exists
|
|
56
|
+
const phrase = assertEx(await this.walletStore.get(walletKindName), () => `Wallet not found: ${walletKindName}`)
|
|
57
|
+
|
|
58
|
+
if (path) {
|
|
59
|
+
// get the signer map for the wallet kind or create a new one
|
|
60
|
+
const signerMap = this.signerAccounts.get(walletKindName) ?? new Map()
|
|
61
|
+
|
|
62
|
+
// derive the wallet from the path
|
|
63
|
+
const wallet = await HDWallet.fromPhrase(phrase)
|
|
64
|
+
const derivedWallet = await wallet.derivePath(path)
|
|
65
|
+
|
|
66
|
+
// add the derived wallet to the signer map
|
|
67
|
+
signerMap.set(signerName, derivedWallet)
|
|
68
|
+
|
|
69
|
+
// set the signer map for the wallet kind
|
|
70
|
+
this.signerAccounts.set(walletKindName, signerMap)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Signers.ts'
|
package/src/stack/Manager.ts
CHANGED
|
@@ -21,7 +21,11 @@ export class StackManager {
|
|
|
21
21
|
this.stackMap = stackMap
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
get stacks() {
|
|
25
|
+
return Object.keys(this.initializedStacksMap)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private get initializedStacks() {
|
|
25
29
|
return this.initializedStacksMap
|
|
26
30
|
}
|
|
27
31
|
|
|
@@ -31,15 +35,16 @@ export class StackManager {
|
|
|
31
35
|
|
|
32
36
|
initialize(context: XyOsContext) {
|
|
33
37
|
for (const [key, stackSet] of Object.entries(this.stackMap)) {
|
|
38
|
+
console.log('stack-initialize', key)
|
|
34
39
|
const { stack: Stack, adapters: stackNodeModuleId } = stackSet
|
|
35
40
|
const initializedStack = new Stack(context, stackNodeModuleId)
|
|
36
41
|
initializedStack.initialize()
|
|
37
|
-
this.
|
|
42
|
+
this.initializedStacks.set(key, initializedStack)
|
|
38
43
|
}
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
stop() {
|
|
42
|
-
for (const stack of this.
|
|
47
|
+
for (const stack of this.initializedStacks.values()) {
|
|
43
48
|
stack.stop()
|
|
44
49
|
}
|
|
45
50
|
}
|