@xyo-network/os-runtime 3.0.8 → 3.0.10

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 (52) hide show
  1. package/dist/neutral/index.d.ts +88 -70
  2. package/dist/neutral/index.mjs +99 -152
  3. package/dist/neutral/index.mjs.map +1 -1
  4. package/package.json +53 -52
  5. package/src/Caller.ts +1 -3
  6. package/src/DefaultsQueries.ts +2 -6
  7. package/src/XyOs.ts +18 -15
  8. package/src/XyOsBase.ts +1 -3
  9. package/src/XyOsDapp.ts +6 -6
  10. package/src/access-interfaces/ValidDappAccessInterfaces.ts +1 -3
  11. package/src/access-interfaces/registered-names/helpers/AccessNodeQueries.ts +1 -3
  12. package/src/access-interfaces/registered-names/helpers/resource/RegistrationsResource.ts +2 -6
  13. package/src/adapter/Base.ts +2 -6
  14. package/src/adapters/OsPubSubBridgeNetwork.ts +1 -3
  15. package/src/classes/cache/RunningDappCache.ts +2 -6
  16. package/src/classes/dapp/DefaultsResource.ts +2 -6
  17. package/src/classes/dapp/access/Caller.ts +1 -3
  18. package/src/classes/dapp/access/Queries.ts +2 -6
  19. package/src/classes/dapp/access/Resource.ts +2 -6
  20. package/src/classes/index.ts +1 -0
  21. package/src/classes/lib/Insertable.ts +1 -3
  22. package/src/classes/menu/Caller.ts +1 -3
  23. package/src/classes/menu/Queries.ts +1 -3
  24. package/src/classes/menu/Resource.ts +2 -6
  25. package/src/classes/node/Creator.ts +4 -10
  26. package/src/classes/node/DefaultPayloads/DappAccessPayloads.ts +1 -3
  27. package/src/classes/node/DefaultPayloads/DefaultPayloads.ts +1 -3
  28. package/src/classes/node/DefaultPayloads/SigningKeyPayloads.ts +2 -6
  29. package/src/classes/node/ExternalModulePermissions/ExternalModulePermissions.ts +1 -3
  30. package/src/classes/node/createDappContext.ts +2 -6
  31. package/src/classes/registration/DappRegistrationService.ts +4 -12
  32. package/src/classes/registration/ValidateDappAccessDiviner/Config.ts +1 -3
  33. package/src/classes/registration/ValidateDappAccessDiviner/Diviner.ts +2 -6
  34. package/src/classes/settings/Resource.ts +2 -6
  35. package/src/classes/settings/SettingsQueries.ts +2 -6
  36. package/src/classes/settings/badge/Resource.ts +1 -3
  37. package/src/classes/signer/Signers.ts +69 -0
  38. package/src/classes/signer/index.ts +1 -0
  39. package/src/event/bus/EventBus.ts +2 -8
  40. package/src/helpers/monitor/XyOsMonitor.ts +1 -3
  41. package/src/intent/Caller.ts +1 -3
  42. package/src/intent/Resource.ts +2 -6
  43. package/src/lib/ModuleAccountPaths.ts +1 -3
  44. package/src/lib/PayloadStore.ts +1 -3
  45. package/src/lib/isPayload.ts +1 -3
  46. package/src/profileModuleEvents.ts +2 -6
  47. package/src/stack/Manager.ts +9 -6
  48. package/src/stack/OsPubSubNetworkStack.ts +4 -12
  49. package/src/stack/OsSettingsStack.ts +2 -6
  50. package/src/stack/XyoPublicNetworkStack.ts +2 -6
  51. package/src/utils/buildWalletSeedPhrasePayload.ts +2 -6
  52. package/src/wallet/DappSeedPhraseRepository.ts +1 -3
@@ -1,12 +1,8 @@
1
1
  import type { Address } from '@xylabs/hex'
2
2
  import { HDWallet } from '@xyo-network/account'
3
3
  import { AbstractDiviner } from '@xyo-network/diviner-abstract'
4
- import type {
5
- NodeManifestPayload, PackageManifestPayload,
6
- } from '@xyo-network/manifest'
7
- import {
8
- ManifestWrapper, PackageManifestPayloadSchema,
9
- } from '@xyo-network/manifest'
4
+ import type { NodeManifestPayload, PackageManifestPayload } from '@xyo-network/manifest'
5
+ import { ManifestWrapper, PackageManifestPayloadSchema } from '@xyo-network/manifest'
10
6
  import type { NodeInstance } from '@xyo-network/node-model'
11
7
  import type {
12
8
  DappPackageManifestPayload,
@@ -2,13 +2,9 @@ import { assertEx } from '@xylabs/assert'
2
2
  import type {
3
3
  NodeBackground, WalletSeedPhrase, XyOsContext,
4
4
  } from '@xyo-network/os-model'
5
- import {
6
- isNodeBackground, isWalletSeedPhrase,
7
- } from '@xyo-network/os-model'
5
+ import { isNodeBackground, isWalletSeedPhrase } from '@xyo-network/os-model'
8
6
 
9
- import type {
10
- Listener, ResourceStore,
11
- } from '../../lib/index.ts'
7
+ import type { Listener, ResourceStore } from '../../lib/index.ts'
12
8
  import { PayloadStore } from '../../lib/index.ts'
13
9
  import { OsSettingsCallerBase } from './CallerBase.ts'
14
10
  import { OsSettingsQueries } from './SettingsQueries.ts'
@@ -1,11 +1,7 @@
1
1
  import type { DivinerInstance } from '@xyo-network/diviner-model'
2
2
  import { PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
3
- import type {
4
- NodeBackground, WalletSeedPhrase,
5
- } from '@xyo-network/os-model'
6
- import {
7
- NodeBackgroundSchema, WalletSeedPhraseSchema,
8
- } from '@xyo-network/os-model'
3
+ import type { NodeBackground, WalletSeedPhrase } from '@xyo-network/os-model'
4
+ import { NodeBackgroundSchema, WalletSeedPhraseSchema } from '@xyo-network/os-model'
9
5
  import type { WithMeta } from '@xyo-network/payload-model'
10
6
 
11
7
  const NO_RESULTS: WithMeta<WalletSeedPhrase>[] = []
@@ -1,7 +1,5 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
- import type {
3
- OsBadge, XyOsContext,
4
- } from '@xyo-network/os-model'
2
+ import type { OsBadge, XyOsContext } from '@xyo-network/os-model'
5
3
  import { isBadgeWithMeta } from '@xyo-network/os-model'
6
4
 
7
5
  import type { ResourceStore } from '../../../lib/index.ts'
@@ -0,0 +1,69 @@
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
+ async initialize() {
39
+ for (const [walletKindName, signerPaths] of this.paths) {
40
+ for (const [signerName, walletPath] of signerPaths.entries()) {
41
+ await this.initializeSigners(walletKindName, signerName, walletPath)
42
+ }
43
+ }
44
+ }
45
+
46
+ private async initializeSigners(walletKindName: WalletKind, signerName: string, path: string) {
47
+ // test if the name and path are valid
48
+ assertEx(signerName, () => 'Name not found in signer paths')
49
+ assertEx(path, () => 'Path not found in signer paths')
50
+
51
+ // test if the wallet exists
52
+ const phrase = assertEx(await this.walletStore.get(walletKindName), () => `Wallet not found: ${walletKindName}`)
53
+
54
+ if (path) {
55
+ // get the signer map for the wallet kind or create a new one
56
+ const signerMap = this.signerAccounts.get(walletKindName) ?? new Map()
57
+
58
+ // derive the wallet from the path
59
+ const wallet = await HDWallet.fromPhrase(phrase)
60
+ const derivedWallet = await wallet.derivePath(path)
61
+
62
+ // add the derived wallet to the signer map
63
+ signerMap.set(signerName, derivedWallet)
64
+
65
+ // set the signer map for the wallet kind
66
+ this.signerAccounts.set(walletKindName, signerMap)
67
+ }
68
+ }
69
+ }
@@ -0,0 +1 @@
1
+ export * from './Signers.ts'
@@ -87,11 +87,7 @@ export class EventBus implements EventBusInterface {
87
87
  return this
88
88
  }
89
89
  // Later versions could include a node that has a payload diviner to query past events
90
- this._archivist = await MemoryArchivist.create({
91
- config: {
92
- name: storeName, schema: MemoryArchivistConfigSchema,
93
- },
94
- })
90
+ this._archivist = await MemoryArchivist.create({ config: { name: storeName, schema: MemoryArchivistConfigSchema } })
95
91
 
96
92
  // start listening to inserted events from publishers
97
93
  // NOTE: This is a very basic implementation and could be optimized by indexing on connection, eventName, and callback
@@ -129,9 +125,7 @@ export class EventBus implements EventBusInterface {
129
125
  // Create publisher callback
130
126
  const connectionPublisherCallback: PublisherEventListener = async ({ payloads }) => {
131
127
  // build the event payload
132
- const event: EventBusEvent = {
133
- name: eventName, schema: 'network.xyo.event.bus.event',
134
- }
128
+ const event: EventBusEvent = { name: eventName, schema: 'network.xyo.event.bus.event' }
135
129
  const eventPayloads = payloads ?? []
136
130
  event.sources = await PayloadBuilder.dataHashes(eventPayloads)
137
131
  // Sync events to archivist
@@ -30,9 +30,7 @@ export abstract class XyOsMonitor {
30
30
  }
31
31
 
32
32
  stopTimer(eventConfig: MonitorEventConfig): void {
33
- const {
34
- additionalProperties, name,
35
- } = eventConfig
33
+ const { additionalProperties, name } = eventConfig
36
34
  const start = this.performanceTimers.get(name)
37
35
  if (start) {
38
36
  const end = performance.now()
@@ -2,9 +2,7 @@ import { PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
2
2
  import type {
3
3
  DappId, DappIntent, DappIntentTypes, XyOsContext,
4
4
  } from '@xyo-network/os-model'
5
- import {
6
- DappIntentSchema, DappMode,
7
- } from '@xyo-network/os-model'
5
+ import { DappIntentSchema, DappMode } from '@xyo-network/os-model'
8
6
  import type { WithMeta } from '@xyo-network/payload-model'
9
7
 
10
8
  import { DappCallerBase } from '../DappCallerBase.ts'
@@ -1,14 +1,10 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
- import type {
3
- DappIntent, XyOsContext,
4
- } from '@xyo-network/os-model'
2
+ import type { DappIntent, XyOsContext } from '@xyo-network/os-model'
5
3
  import { isDappIntent } from '@xyo-network/os-model'
6
4
  import type { WithMeta } from '@xyo-network/payload-model'
7
5
 
8
6
  import { DappCallerBase } from '../DappCallerBase.ts'
9
- import type {
10
- Listener, ResourceStore,
11
- } from '../lib/index.ts'
7
+ import type { Listener, ResourceStore } from '../lib/index.ts'
12
8
  import { PayloadStore } from '../lib/index.ts'
13
9
 
14
10
  export type DappIntentViews = 'latestDappIntent' | 'allDappIntents'
@@ -1,6 +1,4 @@
1
- import {
2
- DevelopArchivist, NodeSentinel,
3
- } from './ModuleNames.ts'
1
+ import { DevelopArchivist, NodeSentinel } from './ModuleNames.ts'
4
2
 
5
3
  export const RemoteNodeArchivistOffsetPaths: Record<string, Record<string, string>> = {
6
4
  Kerplunk: { [DevelopArchivist]: '118' },
@@ -1,6 +1,4 @@
1
- import type {
2
- ArchivistInstance, ArchivistModuleEventData,
3
- } from '@xyo-network/archivist'
1
+ import type { ArchivistInstance, ArchivistModuleEventData } from '@xyo-network/archivist'
4
2
  import type {
5
3
  Payload, WithMeta, WithSources,
6
4
  } from '@xyo-network/payload-model'
@@ -1,7 +1,5 @@
1
1
  import { AsObjectFactory } from '@xylabs/object'
2
- import type {
3
- Payload, Schema,
4
- } from '@xyo-network/payload-model'
2
+ import type { Payload, Schema } from '@xyo-network/payload-model'
5
3
 
6
4
  export const isObject = (x: unknown): x is Record<string | symbol | number, unknown> => {
7
5
  return typeof x === 'object' && !Array.isArray(x)
@@ -17,16 +17,12 @@ export const profileModuleEvents = (mod: ModuleInstance) => {
17
17
  mod.onAny(async (eventName, args) => {
18
18
  const mod = modRef.deref()
19
19
  if (mod) {
20
- const data = profileData[mod.address] ?? {
21
- allEventCount: 0, eventCounts: {},
22
- }
20
+ const data = profileData[mod.address] ?? { allEventCount: 0, eventCounts: {} }
23
21
  profileData[mod.address] = data
24
22
  data.allEventCount += 1
25
23
  data.eventCounts[eventName] = (data.eventCounts[eventName] ?? 0) + 1
26
24
  if (eventName === 'querySendStarted') {
27
- const {
28
- query, payloads = [],
29
- } = args as QuerySendStartedEventArgs
25
+ const { query, payloads = [] } = args as QuerySendStartedEventArgs
30
26
  const pairs = await PayloadBuilder.dataHashPairs(payloads)
31
27
  const foundPair = pairs.find(([, hash]) => hash === query.query)
32
28
  if (foundPair) {
@@ -21,7 +21,11 @@ export class StackManager {
21
21
  this.stackMap = stackMap
22
22
  }
23
23
 
24
- private get stacks() {
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,17 +35,16 @@ export class StackManager {
31
35
 
32
36
  initialize(context: XyOsContext) {
33
37
  for (const [key, stackSet] of Object.entries(this.stackMap)) {
34
- const {
35
- stack: Stack, adapters: stackNodeModuleId,
36
- } = stackSet
38
+ console.log('stack-initialize', key)
39
+ const { stack: Stack, adapters: stackNodeModuleId } = stackSet
37
40
  const initializedStack = new Stack(context, stackNodeModuleId)
38
41
  initializedStack.initialize()
39
- this.stacks.set(key, initializedStack)
42
+ this.initializedStacks.set(key, initializedStack)
40
43
  }
41
44
  }
42
45
 
43
46
  stop() {
44
- for (const stack of this.stacks.values()) {
47
+ for (const stack of this.initializedStacks.values()) {
45
48
  stack.stop()
46
49
  }
47
50
  }
@@ -1,19 +1,11 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
2
  import type { NodeInstance } from '@xyo-network/node-model'
3
- import {
4
- asAttachableNodeInstance, asNodeInstance,
5
- } from '@xyo-network/node-model'
6
- import type {
7
- AdapterSetCreator, XyOsContext,
8
- } from '@xyo-network/os-model'
9
- import {
10
- ExposedNodeOuterNodeName, PubSubBridgeNodeNodeName,
11
- } from '@xyo-network/os-model'
3
+ import { asAttachableNodeInstance, asNodeInstance } from '@xyo-network/node-model'
4
+ import type { AdapterSetCreator, XyOsContext } from '@xyo-network/os-model'
5
+ import { ExposedNodeOuterNodeName, PubSubBridgeNodeNodeName } from '@xyo-network/os-model'
12
6
 
13
7
  import type { EventBusPubSubConnection } from '../event/index.ts'
14
- import {
15
- osPubSubNetworkReadyConnection, OsPubSubNetworkReadyEvent,
16
- } from '../event/index.ts'
8
+ import { osPubSubNetworkReadyConnection, OsPubSubNetworkReadyEvent } from '../event/index.ts'
17
9
  import { initializeXns } from '../lib/index.ts'
18
10
  import { StackBase } from './Base.ts'
19
11
 
@@ -1,11 +1,7 @@
1
- import type {
2
- AdapterSetCreator, XyOsContext,
3
- } from '@xyo-network/os-model'
1
+ import type { AdapterSetCreator, XyOsContext } from '@xyo-network/os-model'
4
2
 
5
3
  import type { EventBusPubSubConnection } from '../event/index.ts'
6
- import {
7
- osSettingsReadyConnection, OsSettingsReadyEvent,
8
- } from '../event/index.ts'
4
+ import { osSettingsReadyConnection, OsSettingsReadyEvent } from '../event/index.ts'
9
5
  import { StackBase } from './Base.ts'
10
6
 
11
7
  export class OsSettingsStack extends StackBase {
@@ -1,12 +1,8 @@
1
- import type {
2
- AdapterSetCreator, XyOsContext,
3
- } from '@xyo-network/os-model'
1
+ import type { AdapterSetCreator, XyOsContext } from '@xyo-network/os-model'
4
2
  import { XyoPublicNodeName } from '@xyo-network/os-model'
5
3
 
6
4
  import type { EventBusPubSubConnection } from '../event/index.ts'
7
- import {
8
- osXyoPublicNetworkReadyConnection, OsXyoPublicNetworkReadyEvent,
9
- } from '../event/index.ts'
5
+ import { osXyoPublicNetworkReadyConnection, OsXyoPublicNetworkReadyEvent } from '../event/index.ts'
10
6
  import { StackBase } from './Base.ts'
11
7
 
12
8
  export class XyoPublicNetworkStack extends StackBase {
@@ -31,17 +31,13 @@ export const buildWalletSeedPhrasePayload = async (mnemonic: string, label: Wall
31
31
  language, mnemonic: mnemonic.split(' '), standard,
32
32
  },
33
33
  }
34
- const meta = {
35
- label, timestamp: Date.now(),
36
- }
34
+ const meta = { label, timestamp: Date.now() }
37
35
  const builder = new PayloadBuilder<WalletSeedPhrase>({
38
36
  fields, meta, schema: WalletSeedPhraseSchema,
39
37
  })
40
38
  const payload = await builder.build()
41
39
  const rootHash = await PayloadBuilder.hash(payload)
42
- return {
43
- payload, rootHash,
44
- }
40
+ return { payload, rootHash }
45
41
  }
46
42
 
47
43
  /**
@@ -8,9 +8,7 @@ import type { WithMeta } from '@xyo-network/payload-model'
8
8
  import { v4 as uuid } from 'uuid'
9
9
 
10
10
  import { OsCallerBase } from '../OsCallerBase.ts'
11
- import type {
12
- SeedPhraseId, SeedPhraseRepository,
13
- } from './SeedPhraseRepository.ts'
11
+ import type { SeedPhraseId, SeedPhraseRepository } from './SeedPhraseRepository.ts'
14
12
 
15
13
  export class DappSeedPhraseRepository extends OsCallerBase implements SeedPhraseRepository {
16
14
  // record of all dapps that have requested a seed phrase with the OS