@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.
- package/dist/neutral/Caller.d.ts.map +1 -1
- package/dist/neutral/DappCallerBase.d.ts +2 -2
- package/dist/neutral/OsCallerBase.d.ts +2 -2
- package/dist/neutral/RunningDappCache.d.ts.map +1 -1
- package/dist/neutral/XyOs.d.ts +4 -5
- package/dist/neutral/XyOs.d.ts.map +1 -1
- package/dist/neutral/XyOsBase.d.ts +122 -3
- package/dist/neutral/XyOsBase.d.ts.map +1 -1
- package/dist/neutral/XyOsDapp.d.ts +3 -3
- package/dist/neutral/XyOsDapp.d.ts.map +1 -1
- package/dist/neutral/access/Caller.d.ts +1 -1
- package/dist/neutral/access/Caller.d.ts.map +1 -1
- package/dist/neutral/access/RunningAccessDappCache.d.ts.map +1 -1
- package/dist/neutral/access/interfaces/registered-names/helpers/resource/AbstractXnsCaller.d.ts +1 -1
- package/dist/neutral/adapter/Base.d.ts.map +1 -1
- package/dist/neutral/classes/lib/DappCreatorParams.d.ts +3 -3
- package/dist/neutral/classes/lib/DappCreatorParams.d.ts.map +1 -1
- package/dist/neutral/classes/lib/Insertable.d.ts +1 -3
- package/dist/neutral/classes/lib/Insertable.d.ts.map +1 -1
- package/dist/neutral/classes/settings/CallerBase.d.ts +1 -1
- package/dist/neutral/classes/settings/SettingsQueries.d.ts.map +1 -1
- package/dist/neutral/dapp/context/creator/Creator.d.ts +1 -1
- package/dist/neutral/dapp/context/creator/Creator.d.ts.map +1 -1
- package/dist/neutral/dapp/context/creator/createDappContext.d.ts.map +1 -1
- package/dist/neutral/event/bus/EventBus.d.ts +1 -1
- package/dist/neutral/event/bus/EventBus.d.ts.map +1 -1
- package/dist/neutral/helpers/monitor/XyOsMonitor.d.ts +2 -2
- package/dist/neutral/helpers/monitor/XyOsMonitor.d.ts.map +1 -1
- package/dist/neutral/helpers/monitor/types.d.ts +2 -2
- package/dist/neutral/helpers/monitor/types.d.ts.map +1 -1
- package/dist/neutral/index.mjs +42 -36
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/lib/Listener.d.ts +1 -1
- package/dist/neutral/lib/Listener.d.ts.map +1 -1
- package/dist/neutral/loadOsNode.d.ts.map +1 -1
- package/dist/neutral/profileModuleEvents.d.ts +1 -3
- package/dist/neutral/profileModuleEvents.d.ts.map +1 -1
- package/dist/neutral/registration/DappRegistrationService.d.ts +3 -3
- package/dist/neutral/registration/DappRegistrationService.d.ts.map +1 -1
- package/dist/neutral/registration/DappRegistry.d.ts.map +1 -1
- package/dist/neutral/registration/ValidateDappAccessDiviner/Config.d.ts +1 -1
- package/dist/neutral/registration/ValidateDappAccessDiviner/Config.d.ts.map +1 -1
- package/dist/neutral/scripts/xyos/lib/headless.d.ts.map +1 -1
- package/dist/neutral/signer/Signers.d.ts.map +1 -1
- package/dist/neutral/stack/Manager.d.ts +2 -6
- package/dist/neutral/stack/Manager.d.ts.map +1 -1
- package/dist/neutral/system/ManageSystemDapps.d.ts +2 -2
- package/dist/neutral/system/ManageSystemDapps.d.ts.map +1 -1
- package/dist/node/Caller.d.ts.map +1 -1
- package/dist/node/DappCallerBase.d.ts +2 -2
- package/dist/node/OsCallerBase.d.ts +2 -2
- package/dist/node/RunningDappCache.d.ts.map +1 -1
- package/dist/node/XyOs.d.ts +4 -5
- package/dist/node/XyOs.d.ts.map +1 -1
- package/dist/node/XyOsBase.d.ts +122 -3
- package/dist/node/XyOsBase.d.ts.map +1 -1
- package/dist/node/XyOsDapp.d.ts +3 -3
- package/dist/node/XyOsDapp.d.ts.map +1 -1
- package/dist/node/access/Caller.d.ts +1 -1
- package/dist/node/access/Caller.d.ts.map +1 -1
- package/dist/node/access/RunningAccessDappCache.d.ts.map +1 -1
- package/dist/node/access/interfaces/registered-names/helpers/resource/AbstractXnsCaller.d.ts +1 -1
- package/dist/node/adapter/Base.d.ts.map +1 -1
- package/dist/node/classes/lib/DappCreatorParams.d.ts +3 -3
- package/dist/node/classes/lib/DappCreatorParams.d.ts.map +1 -1
- package/dist/node/classes/lib/Insertable.d.ts +1 -3
- package/dist/node/classes/lib/Insertable.d.ts.map +1 -1
- package/dist/node/classes/settings/CallerBase.d.ts +1 -1
- package/dist/node/classes/settings/SettingsQueries.d.ts.map +1 -1
- package/dist/node/dapp/context/creator/Creator.d.ts +1 -1
- package/dist/node/dapp/context/creator/Creator.d.ts.map +1 -1
- package/dist/node/dapp/context/creator/createDappContext.d.ts.map +1 -1
- package/dist/node/event/bus/EventBus.d.ts +1 -1
- package/dist/node/event/bus/EventBus.d.ts.map +1 -1
- package/dist/node/helpers/monitor/XyOsMonitor.d.ts +2 -2
- package/dist/node/helpers/monitor/XyOsMonitor.d.ts.map +1 -1
- package/dist/node/helpers/monitor/types.d.ts +2 -2
- package/dist/node/helpers/monitor/types.d.ts.map +1 -1
- package/dist/node/index.mjs +42 -36
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/lib/Listener.d.ts +1 -1
- package/dist/node/lib/Listener.d.ts.map +1 -1
- package/dist/node/loadOsNode.d.ts.map +1 -1
- package/dist/node/profileModuleEvents.d.ts +1 -3
- package/dist/node/profileModuleEvents.d.ts.map +1 -1
- package/dist/node/registration/DappRegistrationService.d.ts +3 -3
- package/dist/node/registration/DappRegistrationService.d.ts.map +1 -1
- package/dist/node/registration/DappRegistry.d.ts.map +1 -1
- package/dist/node/registration/ValidateDappAccessDiviner/Config.d.ts +1 -1
- package/dist/node/registration/ValidateDappAccessDiviner/Config.d.ts.map +1 -1
- package/dist/node/scripts/xyos/index.mjs +27 -24
- package/dist/node/scripts/xyos/index.mjs.map +1 -1
- package/dist/node/scripts/xyos/lib/headless.d.ts.map +1 -1
- package/dist/node/signer/Signers.d.ts.map +1 -1
- package/dist/node/stack/Manager.d.ts +2 -6
- package/dist/node/stack/Manager.d.ts.map +1 -1
- package/dist/node/system/ManageSystemDapps.d.ts +2 -2
- package/dist/node/system/ManageSystemDapps.d.ts.map +1 -1
- package/package.json +134 -49
- package/dist/neutral/signer/Signer.spec.d.ts +0 -2
- package/dist/neutral/signer/Signer.spec.d.ts.map +0 -1
- package/dist/neutral/spec/boot.spec.d.ts +0 -2
- package/dist/neutral/spec/boot.spec.d.ts.map +0 -1
- package/dist/node/signer/Signer.spec.d.ts +0 -2
- package/dist/node/signer/Signer.spec.d.ts.map +0 -1
- package/dist/node/spec/boot.spec.d.ts +0 -2
- package/dist/node/spec/boot.spec.d.ts.map +0 -1
- package/src/Caller.ts +0 -200
- package/src/DappCallerBase.ts +0 -55
- package/src/DefaultsQueries.ts +0 -27
- package/src/OsCallerBase.ts +0 -59
- package/src/PubSubBridgeCaller.ts +0 -33
- package/src/RunningDappCache.ts +0 -58
- package/src/XyOs.ts +0 -166
- package/src/XyOsBase.ts +0 -135
- package/src/XyOsDapp.ts +0 -106
- package/src/access/Caller.ts +0 -85
- package/src/access/Queries.ts +0 -38
- package/src/access/Resource.ts +0 -65
- package/src/access/RunningAccessDappCache.ts +0 -21
- package/src/access/index.ts +0 -4
- package/src/access/interfaces/index.ts +0 -1
- package/src/access/interfaces/registered-names/helpers/AccessNodeQueries.ts +0 -68
- package/src/access/interfaces/registered-names/helpers/index.ts +0 -2
- package/src/access/interfaces/registered-names/helpers/resource/AbstractXnsCaller.ts +0 -42
- package/src/access/interfaces/registered-names/helpers/resource/RegistrationsResource.ts +0 -52
- package/src/access/interfaces/registered-names/helpers/resource/RegistrationsResourceQueries.ts +0 -23
- package/src/access/interfaces/registered-names/helpers/resource/index.ts +0 -3
- package/src/access/interfaces/registered-names/index.ts +0 -1
- package/src/adapter/Base.ts +0 -106
- package/src/adapter/Network.ts +0 -31
- package/src/adapter/Settings.ts +0 -30
- package/src/adapter/index.ts +0 -2
- package/src/adapters/OsPubSubBridgeNetwork.ts +0 -10
- package/src/adapters/OsSettings.ts +0 -7
- package/src/adapters/OsXyoPublicNetwork.ts +0 -9
- package/src/adapters/index.ts +0 -3
- package/src/classes/dapp/DefaultsResource.ts +0 -67
- package/src/classes/dapp/index.ts +0 -1
- package/src/classes/index.ts +0 -4
- package/src/classes/lib/DappCreatorParams.ts +0 -18
- package/src/classes/lib/Insertable.ts +0 -10
- package/src/classes/lib/index.ts +0 -2
- package/src/classes/menu/Caller.ts +0 -76
- package/src/classes/menu/Queries.ts +0 -60
- package/src/classes/menu/Resource.ts +0 -105
- package/src/classes/menu/index.ts +0 -2
- package/src/classes/settings/Caller.ts +0 -78
- package/src/classes/settings/CallerBase.ts +0 -27
- package/src/classes/settings/Resource.ts +0 -81
- package/src/classes/settings/SettingsQueries.ts +0 -56
- package/src/classes/settings/badge/Caller.ts +0 -30
- package/src/classes/settings/badge/Queries.ts +0 -19
- package/src/classes/settings/badge/Resource.ts +0 -50
- package/src/classes/settings/badge/index.ts +0 -2
- package/src/classes/settings/index.ts +0 -5
- package/src/dapp/context/creator/Creator.ts +0 -122
- package/src/dapp/context/creator/DefaultPayloads/DappAccessPayloads.ts +0 -20
- package/src/dapp/context/creator/DefaultPayloads/DefaultPayloads.ts +0 -40
- package/src/dapp/context/creator/DefaultPayloads/NodeInfoPayload.ts +0 -33
- package/src/dapp/context/creator/DefaultPayloads/index.ts +0 -1
- package/src/dapp/context/creator/ExternalModulePermissions/ExternalModulePermissions.ts +0 -59
- package/src/dapp/context/creator/ExternalModulePermissions/index.ts +0 -1
- package/src/dapp/context/creator/createDappContext.ts +0 -61
- package/src/dapp/context/creator/index.ts +0 -3
- package/src/dapp/context/index.ts +0 -1
- package/src/dapp/index.ts +0 -1
- package/src/event/bus/Connection.ts +0 -31
- package/src/event/bus/EventBus.ts +0 -160
- package/src/event/bus/PubSubConnection.ts +0 -28
- package/src/event/bus/index.ts +0 -3
- package/src/event/connections/DappAccessRequest.ts +0 -11
- package/src/event/connections/DappsReady.ts +0 -9
- package/src/event/connections/ExposeDappRequest.ts +0 -11
- package/src/event/connections/OsPubSubNetworkReady.ts +0 -12
- package/src/event/connections/OsSettingsReady.ts +0 -12
- package/src/event/connections/OsXyoPublicReady.ts +0 -12
- package/src/event/connections/index.ts +0 -6
- package/src/event/index.ts +0 -2
- package/src/helpers/index.ts +0 -1
- package/src/helpers/monitor/XyOsMonitor.ts +0 -52
- package/src/helpers/monitor/index.ts +0 -2
- package/src/helpers/monitor/types.ts +0 -8
- package/src/index.ts +0 -29
- package/src/initializer/DappInitializer.ts +0 -57
- package/src/initializer/index.ts +0 -1
- package/src/intent/Caller.ts +0 -74
- package/src/intent/Resource.ts +0 -66
- package/src/intent/index.ts +0 -2
- package/src/lib/ExternalStore.ts +0 -7
- package/src/lib/Listener.ts +0 -1
- package/src/lib/ModuleAccountPaths.ts +0 -23
- package/src/lib/ModuleNames.ts +0 -3
- package/src/lib/NameTransforms.ts +0 -34
- package/src/lib/PayloadStore.ts +0 -105
- package/src/lib/ResourceStores.ts +0 -7
- package/src/lib/index.ts +0 -11
- package/src/lib/initializeXns.ts +0 -16
- package/src/lib/isEqual.ts +0 -42
- package/src/lib/isPayload.ts +0 -24
- package/src/lib/tokenPlacesSplit.ts +0 -17
- package/src/loadOsNode.ts +0 -44
- package/src/manifest/index.ts +0 -2
- package/src/manifest/manifestReplacementTokens.ts +0 -6
- package/src/manifest/os-node.manifest.json +0 -132
- package/src/manifests/dapp-window.manifest.json +0 -36
- package/src/manifests/index.ts +0 -1
- package/src/models/access/ValidDappAccessInterfaces.ts +0 -6
- package/src/models/access/index.ts +0 -1
- package/src/models/index.ts +0 -1
- package/src/profileModuleEvents.ts +0 -43
- package/src/registration/DappRegistrationService.ts +0 -180
- package/src/registration/DappRegistry.ts +0 -129
- package/src/registration/ValidateDappAccessDiviner/Config.ts +0 -24
- package/src/registration/ValidateDappAccessDiviner/Diviner.ts +0 -133
- package/src/registration/ValidateDappAccessDiviner/index.ts +0 -2
- package/src/registration/index.ts +0 -2
- package/src/scripts/xyos/command/config.ts +0 -19
- package/src/scripts/xyos/command/create.ts +0 -22
- package/src/scripts/xyos/command/index.ts +0 -7
- package/src/scripts/xyos/command/manifest.ts +0 -19
- package/src/scripts/xyos/command/start.ts +0 -35
- package/src/scripts/xyos/index.ts +0 -31
- package/src/scripts/xyos/lib/createFromTemplate.ts +0 -11
- package/src/scripts/xyos/lib/headless.ts +0 -68
- package/src/scripts/xyos/lib/index.ts +0 -2
- package/src/signer/Signer.spec.ts +0 -65
- package/src/signer/Signers.ts +0 -74
- package/src/signer/index.ts +0 -1
- package/src/spec/boot.spec.ts +0 -89
- package/src/stack/Base.ts +0 -165
- package/src/stack/Manager.ts +0 -51
- package/src/stack/Map.ts +0 -22
- package/src/stack/OsPubSubNetworkStack.ts +0 -70
- package/src/stack/OsSettingsStack.ts +0 -24
- package/src/stack/XyoPublicNetworkStack.ts +0 -32
- package/src/stack/index.ts +0 -6
- package/src/system/ManageSystemDapps.ts +0 -148
- package/src/system/Queries.ts +0 -69
- package/src/system/index.ts +0 -1
- package/src/types/global.d.ts +0 -9
- package/src/types/images.d.ts +0 -5
- package/src/utils/buildWalletSeedPhrasePayload.ts +0 -51
- package/src/utils/getApiDomain.ts +0 -14
- package/src/utils/index.ts +0 -3
- package/src/utils/renameObjKey.ts +0 -22
- package/src/wallet/DappSeedPhraseRepository.ts +0 -99
- package/src/wallet/SeedPhraseRepository.ts +0 -31
- package/src/wallet/index.ts +0 -2
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import type {
|
|
3
|
-
RegisteredDapp, WindowDappNodeSet, XyOsContext,
|
|
4
|
-
} from '@xyo-network/os-model'
|
|
5
|
-
|
|
6
|
-
import { RunningDappCache } from '../RunningDappCache.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/initializer/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './DappInitializer.ts'
|
package/src/intent/Caller.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
|
|
2
|
-
import type {
|
|
3
|
-
DappId, DappIntent, DappIntentTypes, XyOsContext,
|
|
4
|
-
} from '@xyo-network/os-model'
|
|
5
|
-
import { DappIntentSchema, DappMode } from '@xyo-network/os-model'
|
|
6
|
-
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
7
|
-
|
|
8
|
-
import { DappCallerBase } from '../DappCallerBase.ts'
|
|
9
|
-
|
|
10
|
-
export class DappIntentCaller extends DappCallerBase {
|
|
11
|
-
static OsDappName = 'XyOs'
|
|
12
|
-
constructor(context: XyOsContext) {
|
|
13
|
-
super(context)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Build a new intent
|
|
18
|
-
* @param sourceDappId
|
|
19
|
-
* @param intent
|
|
20
|
-
* @param targetDappId
|
|
21
|
-
* @param targetMode
|
|
22
|
-
* @param params?
|
|
23
|
-
* @returns DappIntent
|
|
24
|
-
*/
|
|
25
|
-
static buildIntent(
|
|
26
|
-
sourceDappId: DappId,
|
|
27
|
-
intent: DappIntentTypes,
|
|
28
|
-
targetDappId?: DappId,
|
|
29
|
-
targetMode: DappMode = DappMode.Window,
|
|
30
|
-
params?: DappIntent['params'],
|
|
31
|
-
): DappIntent {
|
|
32
|
-
return {
|
|
33
|
-
intent,
|
|
34
|
-
params: params || '',
|
|
35
|
-
schema: DappIntentSchema,
|
|
36
|
-
sourceDappId,
|
|
37
|
-
targetDappId,
|
|
38
|
-
targetMode: targetMode || DappMode.Window,
|
|
39
|
-
timestamp: Date.now(),
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Add a new intent
|
|
44
|
-
async addIntent(id: DappId, intent: DappIntentTypes, mode: DappMode) {
|
|
45
|
-
const intentArchivist = await this.getDappIntentArchivist()
|
|
46
|
-
const newIntent = DappIntentCaller.buildIntent(id, intent, mode)
|
|
47
|
-
await intentArchivist.insert([newIntent])
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Get all intents
|
|
51
|
-
async allIntents() {
|
|
52
|
-
const archivist = await this.getDappIntentArchivist()
|
|
53
|
-
return await archivist.all()
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Get the latest intent saved to the archivist
|
|
57
|
-
async latestIntent() {
|
|
58
|
-
const archivist = await this.getDappIntentArchivist()
|
|
59
|
-
return (await archivist.all()).at(-1) as WithStorageMeta<DappIntent>
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Get the latest intent for a dapp
|
|
63
|
-
async latestIntentForDappName(dappName: DappId) {
|
|
64
|
-
const diviner = await this.getDappIntentArchivistPayloadDiviner()
|
|
65
|
-
const query = {
|
|
66
|
-
limit: 1,
|
|
67
|
-
order: 'desc',
|
|
68
|
-
schema: PayloadDivinerQuerySchema,
|
|
69
|
-
sourceDappId: dappName,
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return (await diviner.divine([query])) as DappIntent[]
|
|
73
|
-
}
|
|
74
|
-
}
|
package/src/intent/Resource.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import type { DappIntent, XyOsContext } from '@xyo-network/os-model'
|
|
3
|
-
import { isDappIntent } from '@xyo-network/os-model'
|
|
4
|
-
import type { WithSources, WithStorageMeta } from '@xyo-network/payload-model'
|
|
5
|
-
|
|
6
|
-
import { DappCallerBase } from '../DappCallerBase.ts'
|
|
7
|
-
import type { Listener, ResourceStore } from '../lib/index.ts'
|
|
8
|
-
import { PayloadStore } from '../lib/index.ts'
|
|
9
|
-
|
|
10
|
-
export type DappIntentViews = 'latestDappIntent' | 'allDappIntents'
|
|
11
|
-
const NO_RESULTS: [] = []
|
|
12
|
-
|
|
13
|
-
export class DappIntentResource extends DappCallerBase implements ResourceStore<DappIntentViews> {
|
|
14
|
-
private _allDappIntents: PayloadStore<DappIntent> | undefined
|
|
15
|
-
private _latestDappIntent: PayloadStore<DappIntent> | undefined
|
|
16
|
-
|
|
17
|
-
constructor(context: XyOsContext) {
|
|
18
|
-
super(context)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
get allDappIntents() {
|
|
22
|
-
return assertEx(this._allDappIntents, () => 'allDappIntents not set')
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
get latestDappIntent() {
|
|
26
|
-
return assertEx(this._latestDappIntent, () => 'latestDappIntent not set')
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
get subscriptions() {
|
|
30
|
-
return {
|
|
31
|
-
allDappIntents: (cb: Listener) => this.allDappIntents.subscribe(cb),
|
|
32
|
-
latestDappIntent: (cb: Listener) => this.latestDappIntent.subscribe(cb),
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
get views() {
|
|
37
|
-
return {
|
|
38
|
-
allDappIntents: () => this.allDappIntents.getSnapshot(),
|
|
39
|
-
latestDappIntent: () => this.latestDappIntent.getSnapshot(),
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
cleanupListeners() {
|
|
44
|
-
this.latestDappIntent.cleanupListeners()
|
|
45
|
-
this.allDappIntents.cleanupListeners()
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async start() {
|
|
49
|
-
const archivist = await this.getDappIntentArchivist()
|
|
50
|
-
|
|
51
|
-
this._allDappIntents = await PayloadStore.create<DappIntent>({
|
|
52
|
-
archivist,
|
|
53
|
-
getLatest: async () => (await archivist.all()) as WithStorageMeta<WithSources<DappIntent>>[],
|
|
54
|
-
idFunction: isDappIntent,
|
|
55
|
-
})
|
|
56
|
-
this._latestDappIntent = await PayloadStore.create<DappIntent>({
|
|
57
|
-
archivist,
|
|
58
|
-
getLatest: async () => {
|
|
59
|
-
const all = await archivist.all()
|
|
60
|
-
const result = all.length > 0 ? [all.at(-1)] : NO_RESULTS
|
|
61
|
-
return result as WithStorageMeta<WithSources<DappIntent>>[]
|
|
62
|
-
},
|
|
63
|
-
idFunction: isDappIntent,
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
}
|
package/src/intent/index.ts
DELETED
package/src/lib/ExternalStore.ts
DELETED
package/src/lib/Listener.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type Listener = (...args: Array<unknown>) => void
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { DevelopArchivist, NodeSentinel } from './ModuleNames.ts'
|
|
2
|
-
|
|
3
|
-
export const RemoteNodeArchivistOffsetPaths: Record<string, Record<string, string>> = {
|
|
4
|
-
Kerplunk: { [DevelopArchivist]: '118' },
|
|
5
|
-
Local: { [DevelopArchivist]: '115' },
|
|
6
|
-
Main: { [DevelopArchivist]: '121' },
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const ModuleOffsetPaths: Record<string, string> = {
|
|
10
|
-
IdWitness: '1',
|
|
11
|
-
DomainWitness: '2',
|
|
12
|
-
LocationWitness: '3',
|
|
13
|
-
SchemaWitness: '4',
|
|
14
|
-
CryptoCardsGameWitness: '5',
|
|
15
|
-
CryptoCardsMoveWitness: '6',
|
|
16
|
-
EthereumGasEtherchainV2Witness: '7',
|
|
17
|
-
CoingeckoCryptoMarketWitness: '8',
|
|
18
|
-
UniswapCryptoMarketWitness: '9',
|
|
19
|
-
EthereumGasEtherscanWitness: '10',
|
|
20
|
-
[NodeSentinel]: '11',
|
|
21
|
-
[DevelopArchivist]: '12',
|
|
22
|
-
BowserSystemInfoPluginWitness: '13',
|
|
23
|
-
}
|
package/src/lib/ModuleNames.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export class NameTransforms {
|
|
2
|
-
private value: string
|
|
3
|
-
constructor(value: string) {
|
|
4
|
-
this.value = value
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
static deSlug(value: string) {
|
|
8
|
-
return value
|
|
9
|
-
.replaceAll('-', ' ')
|
|
10
|
-
.split(' ')
|
|
11
|
-
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
12
|
-
.join(' ')
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
static moduleName(value: string) {
|
|
16
|
-
return value.replaceAll(' ', '')
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
static slug(value: string) {
|
|
20
|
-
return value.replaceAll(' ', '-').toLocaleLowerCase()
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
deSlug() {
|
|
24
|
-
return NameTransforms.deSlug(this.value)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
moduleName() {
|
|
28
|
-
return NameTransforms.moduleName(this.value)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
slug() {
|
|
32
|
-
return NameTransforms.slug(this.value)
|
|
33
|
-
}
|
|
34
|
-
}
|
package/src/lib/PayloadStore.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import type { ArchivistInstance, ArchivistModuleEventData } from '@xyo-network/archivist'
|
|
2
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
3
|
-
|
|
4
|
-
import type { ExternalStore } from './ExternalStore.ts'
|
|
5
|
-
import { isEqual } from './isEqual.ts'
|
|
6
|
-
import type { Listener } from './Listener.ts'
|
|
7
|
-
|
|
8
|
-
export interface PayloadStoreConfig<T extends Payload = Payload> {
|
|
9
|
-
archivist: ArchivistInstance
|
|
10
|
-
getLatest: () => Promise<T[]>
|
|
11
|
-
idFunction: (schema: Payload) => boolean
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class PayloadStore<T extends Payload = Payload> implements ExternalStore {
|
|
15
|
-
latest: T[] = []
|
|
16
|
-
private archivist: ArchivistInstance
|
|
17
|
-
private deleteListeners: WeakRef<(args: ArchivistModuleEventData['deleted']) => void>[] = []
|
|
18
|
-
private insertListeners: WeakRef<(args: ArchivistModuleEventData['inserted']) => void>[] = []
|
|
19
|
-
private listeners: Listener[] = []
|
|
20
|
-
|
|
21
|
-
private constructor(archivist: ArchivistInstance) {
|
|
22
|
-
this.archivist = archivist
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Initialize listeners on the archivist that update class member variables when new payloads are inserted
|
|
27
|
-
*/
|
|
28
|
-
static async create<T extends Payload = Payload>({
|
|
29
|
-
archivist, getLatest, idFunction,
|
|
30
|
-
}: PayloadStoreConfig<T>) {
|
|
31
|
-
const instance = new this<T>(archivist)
|
|
32
|
-
|
|
33
|
-
const insertListener = async ({ payloads }: ArchivistModuleEventData['inserted']) => {
|
|
34
|
-
// if any of the newly inserted payloads pass the idFunction check, rerun the query
|
|
35
|
-
if (payloads.some(idFunction)) {
|
|
36
|
-
const latest = await getLatest()
|
|
37
|
-
if (isEqual(latest, instance.latest)) return
|
|
38
|
-
instance.latest = latest
|
|
39
|
-
instance.emitChange()
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// when payloads are deleted, rerun the diviner query
|
|
44
|
-
const deleteListener = async () => {
|
|
45
|
-
instance.latest = await getLatest()
|
|
46
|
-
instance.emitChange()
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const weakRefInsertListener = new WeakRef(insertListener)
|
|
50
|
-
const weakRefDeleteListener = new WeakRef(deleteListener)
|
|
51
|
-
const insertListenerRef = weakRefInsertListener.deref()
|
|
52
|
-
const deleteListenerRef = weakRefDeleteListener.deref()
|
|
53
|
-
|
|
54
|
-
if (insertListenerRef) instance.archivist.on('inserted', insertListenerRef)
|
|
55
|
-
if (deleteListenerRef) instance.archivist.on('deleted', deleteListenerRef)
|
|
56
|
-
|
|
57
|
-
instance.insertListeners.push(weakRefInsertListener)
|
|
58
|
-
instance.deleteListeners.push(weakRefDeleteListener)
|
|
59
|
-
|
|
60
|
-
instance.latest = await getLatest()
|
|
61
|
-
return instance
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Remove all listeners and reset their class members
|
|
66
|
-
*/
|
|
67
|
-
cleanupListeners() {
|
|
68
|
-
this.removeListeners(this.insertListeners, 'inserted')
|
|
69
|
-
this.removeListeners(this.deleteListeners, 'deleted')
|
|
70
|
-
this.insertListeners = []
|
|
71
|
-
this.deleteListeners = []
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Get the current value of the store
|
|
76
|
-
*/
|
|
77
|
-
getSnapshot(): T[] {
|
|
78
|
-
return this.latest
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Add a call back function that is invoked when new Payloads are inserted
|
|
83
|
-
* @param onStoreChange
|
|
84
|
-
*/
|
|
85
|
-
subscribe(onStoreChange: Listener) {
|
|
86
|
-
this.listeners.push(onStoreChange)
|
|
87
|
-
return () => {
|
|
88
|
-
this.listeners = this.listeners.filter(l => l !== onStoreChange)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
private emitChange() {
|
|
93
|
-
for (const listener of this.listeners) {
|
|
94
|
-
listener()
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
99
|
-
private removeListeners(listeners: WeakRef<(args: any) => void>[], eventName: string) {
|
|
100
|
-
for (const listener of listeners) {
|
|
101
|
-
const listenerRef = listener.deref()
|
|
102
|
-
if (listenerRef) this.archivist.off(eventName, listenerRef)
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
package/src/lib/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from './ExternalStore.ts'
|
|
2
|
-
export * from './initializeXns.ts'
|
|
3
|
-
export * from './isEqual.ts'
|
|
4
|
-
export * from './isPayload.ts'
|
|
5
|
-
export * from './Listener.ts'
|
|
6
|
-
export * from './ModuleAccountPaths.ts'
|
|
7
|
-
export * from './ModuleNames.ts'
|
|
8
|
-
export * from './NameTransforms.ts'
|
|
9
|
-
export * from './PayloadStore.ts'
|
|
10
|
-
export * from './ResourceStores.ts'
|
|
11
|
-
export * from './tokenPlacesSplit.ts'
|
package/src/lib/initializeXns.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { asDivinerInstance } from '@xyo-network/diviner-model'
|
|
2
|
-
import { ResolveHelper } from '@xyo-network/module-model'
|
|
3
|
-
import { NameRegistrarTransformer } from '@xyo-network/module-resolver'
|
|
4
|
-
import type { NodeInstance } from '@xyo-network/node-model'
|
|
5
|
-
|
|
6
|
-
export const initializeXns = async (xnsNode: NodeInstance) => {
|
|
7
|
-
if (ResolveHelper.transformers.length === 0) {
|
|
8
|
-
const registrarDiviner = asDivinerInstance(await xnsNode?.resolve('AddressRecords:AddressRecordIndexDiviner'))
|
|
9
|
-
if (registrarDiviner) {
|
|
10
|
-
const transformer = new NameRegistrarTransformer(registrarDiviner, 'xyo')
|
|
11
|
-
ResolveHelper.transformers = [transformer]
|
|
12
|
-
return true
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return false
|
|
16
|
-
}
|
package/src/lib/isEqual.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { isObject } from '@xylabs/sdk-js'
|
|
2
|
-
|
|
3
|
-
export function isEqual(a: unknown, b: unknown): boolean {
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
-
if ((a as any) === (b as any)) return true
|
|
6
|
-
|
|
7
|
-
if (typeof a !== typeof b) return false
|
|
8
|
-
|
|
9
|
-
if (isObject(a) && isObject(b)) {
|
|
10
|
-
const aKeys = Object.keys(a)
|
|
11
|
-
const bKeys = Object.keys(b)
|
|
12
|
-
|
|
13
|
-
if (aKeys.length !== bKeys.length) {
|
|
14
|
-
return false
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
for (const key of aKeys) {
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
-
if (!b.hasOwnProperty(key) || !isEqual((a as any)[key], (b as any)[key])) {
|
|
20
|
-
return false
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return true
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
28
|
-
if (a.length !== b.length) {
|
|
29
|
-
return false
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
for (const [i, element] of a.entries()) {
|
|
33
|
-
if (!isEqual(element, b[i])) {
|
|
34
|
-
return false
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return true
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return false
|
|
42
|
-
}
|
package/src/lib/isPayload.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { AsObjectFactory } from '@xylabs/sdk-js'
|
|
2
|
-
import type { Payload, Schema } from '@xyo-network/payload-model'
|
|
3
|
-
|
|
4
|
-
export const isObject = (x: unknown): x is Record<string | symbol | number, unknown> => {
|
|
5
|
-
return typeof x === 'object' && !Array.isArray(x)
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const isAnyPayload = (obj: unknown): obj is Payload => {
|
|
9
|
-
if (isObject(obj)) {
|
|
10
|
-
return typeof obj.schema === 'string'
|
|
11
|
-
}
|
|
12
|
-
return false
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const isPayload
|
|
16
|
-
= <T extends Payload>(schema: Schema[]) =>
|
|
17
|
-
(obj: unknown): obj is T => {
|
|
18
|
-
if (isAnyPayload(obj)) {
|
|
19
|
-
return schema.includes(obj.schema)
|
|
20
|
-
}
|
|
21
|
-
return false
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const asPayload = <T extends Payload>(schema: Schema[]) => AsObjectFactory.create(isPayload<T>(schema))
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
|
|
3
|
-
export const tokenPlacesSplit = (value: bigint, places: number): [bigint, bigint] => {
|
|
4
|
-
assertEx(places >= 0, () => 'Places has to be >= 0')
|
|
5
|
-
const factor = BigInt(10 ** Math.abs(places))
|
|
6
|
-
const remainder = value % factor
|
|
7
|
-
const wholeValue = value / factor
|
|
8
|
-
return [wholeValue, remainder]
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const tokenPlacesSplitString = (value: bigint | undefined, places: number): string => {
|
|
12
|
-
if (value === undefined) {
|
|
13
|
-
return '-'
|
|
14
|
-
}
|
|
15
|
-
const [wholeValue, remainder] = tokenPlacesSplit(value, places)
|
|
16
|
-
return `${wholeValue}.${remainder.toString().padStart(Math.abs(places), '0')}`
|
|
17
|
-
}
|
package/src/loadOsNode.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { IndexedDbArchivist } from '@xyo-network/archivist-indexeddb'
|
|
2
|
-
import { IndexedDbPayloadDiviner } from '@xyo-network/diviner-payload-indexeddb'
|
|
3
|
-
import type { PackageManifestPayload } from '@xyo-network/manifest'
|
|
4
|
-
import { ManifestWrapper } from '@xyo-network/manifest-wrapper'
|
|
5
|
-
import { ModuleFactoryLocator } from '@xyo-network/module-factory-locator'
|
|
6
|
-
import type { ModuleFactoryLocatorInstance } from '@xyo-network/module-model'
|
|
7
|
-
import type { AttachableNodeInstance } from '@xyo-network/node-model'
|
|
8
|
-
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
9
|
-
|
|
10
|
-
import { osNodeManifest } from './manifest/index.ts'
|
|
11
|
-
|
|
12
|
-
// NOTE: Path "0'" is reserved for the exposed node in the kernel
|
|
13
|
-
const OS_NODE_PATH = "1'"
|
|
14
|
-
|
|
15
|
-
const getDefaultOsNodeLocator = (): ModuleFactoryLocator => {
|
|
16
|
-
const locator = new ModuleFactoryLocator()
|
|
17
|
-
locator.register(IndexedDbArchivist.factory(), { 'network.xyo.archivist.persistence.scope': 'device' })
|
|
18
|
-
locator.register(IndexedDbPayloadDiviner.factory(), { 'network.xyo.archivist.persistence.scope': 'device' })
|
|
19
|
-
return locator
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const loadOsNode = async (
|
|
23
|
-
osWallet: WalletInstance,
|
|
24
|
-
locator?: ModuleFactoryLocatorInstance,
|
|
25
|
-
): Promise<[AttachableNodeInstance]> => {
|
|
26
|
-
try {
|
|
27
|
-
// Create wallets for the OS & kernel nodes
|
|
28
|
-
const osNodeWallet = await osWallet.derivePath(OS_NODE_PATH)
|
|
29
|
-
|
|
30
|
-
// Create the OS node manifest
|
|
31
|
-
const osNodeLocator: ModuleFactoryLocatorInstance = locator ?? getDefaultOsNodeLocator()
|
|
32
|
-
const manifestWrapper = new ManifestWrapper(osNodeManifest as unknown as PackageManifestPayload, osNodeWallet, osNodeLocator)
|
|
33
|
-
|
|
34
|
-
// Create the OS & kernel nodes
|
|
35
|
-
const osNode = (await manifestWrapper.loadNodes())[0]
|
|
36
|
-
|
|
37
|
-
return [osNode]
|
|
38
|
-
} catch (e) {
|
|
39
|
-
const error = e as Error
|
|
40
|
-
console.error(`Error creating os node: ${error.message}`)
|
|
41
|
-
console.error(`Error creating os node: ${error.stack}`)
|
|
42
|
-
throw new Error(`Error creating os node: ${error.message}`)
|
|
43
|
-
}
|
|
44
|
-
}
|
package/src/manifest/index.ts
DELETED