@xyo-network/os-runtime 5.0.5 → 5.0.7
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.mjs +3070 -3077
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/node/index.mjs +3070 -3077
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/scripts/xyos/index.mjs +605 -603
- package/dist/node/scripts/xyos/index.mjs.map +1 -1
- package/dist/types/Caller.d.ts +1 -1
- package/dist/types/RunningDappCache.d.ts.map +1 -0
- package/dist/types/XyOs.d.ts +2 -2
- package/dist/types/XyOs.d.ts.map +1 -1
- package/dist/types/{classes/dapp/access → access}/Caller.d.ts +1 -1
- package/dist/types/access/Caller.d.ts.map +1 -0
- package/dist/types/access/Queries.d.ts.map +1 -0
- package/dist/types/{classes/dapp/access → access}/Resource.d.ts +3 -3
- package/dist/types/access/Resource.d.ts.map +1 -0
- package/dist/types/access/RunningAccessDappCache.d.ts.map +1 -0
- package/dist/types/{classes/dapp/access → access}/index.d.ts +1 -0
- package/dist/types/access/index.d.ts.map +1 -0
- package/dist/types/access/interfaces/index.d.ts +2 -0
- package/dist/types/access/interfaces/index.d.ts.map +1 -0
- package/dist/types/access/interfaces/registered-names/helpers/AccessNodeQueries.d.ts.map +1 -0
- package/dist/types/access/interfaces/registered-names/helpers/index.d.ts.map +1 -0
- package/dist/types/access/interfaces/registered-names/helpers/resource/AbstractXnsCaller.d.ts.map +1 -0
- package/dist/types/{access-interfaces → access/interfaces}/registered-names/helpers/resource/RegistrationsResource.d.ts +2 -2
- package/dist/types/access/interfaces/registered-names/helpers/resource/RegistrationsResource.d.ts.map +1 -0
- package/dist/types/access/interfaces/registered-names/helpers/resource/RegistrationsResourceQueries.d.ts.map +1 -0
- package/dist/types/access/interfaces/registered-names/helpers/resource/index.d.ts.map +1 -0
- package/dist/types/access/interfaces/registered-names/index.d.ts.map +1 -0
- package/dist/types/classes/dapp/index.d.ts +0 -1
- package/dist/types/classes/dapp/index.d.ts.map +1 -1
- package/dist/types/classes/index.d.ts +0 -5
- package/dist/types/classes/index.d.ts.map +1 -1
- package/dist/types/{classes/node → dapp/context/creator}/Creator.d.ts +1 -1
- package/dist/types/dapp/context/creator/Creator.d.ts.map +1 -0
- package/dist/types/{classes/node → dapp/context/creator}/DefaultPayloads/DappAccessPayloads.d.ts +1 -1
- package/dist/types/dapp/context/creator/DefaultPayloads/DappAccessPayloads.d.ts.map +1 -0
- package/dist/types/dapp/context/creator/DefaultPayloads/DefaultPayloads.d.ts.map +1 -0
- package/dist/types/{classes/node → dapp/context/creator}/DefaultPayloads/NodeInfoPayload.d.ts +1 -1
- package/dist/types/dapp/context/creator/DefaultPayloads/NodeInfoPayload.d.ts.map +1 -0
- package/dist/types/dapp/context/creator/DefaultPayloads/index.d.ts.map +1 -0
- package/dist/types/dapp/context/creator/ExternalModulePermissions/ExternalModulePermissions.d.ts.map +1 -0
- package/dist/types/dapp/context/creator/ExternalModulePermissions/index.d.ts.map +1 -0
- package/dist/types/dapp/context/creator/createDappContext.d.ts.map +1 -0
- package/dist/types/dapp/context/creator/index.d.ts.map +1 -0
- package/dist/types/dapp/context/index.d.ts +2 -0
- package/dist/types/dapp/context/index.d.ts.map +1 -0
- package/dist/types/dapp/index.d.ts +2 -0
- package/dist/types/dapp/index.d.ts.map +1 -0
- package/dist/types/helpers/index.d.ts +0 -1
- package/dist/types/helpers/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +8 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/initializer/DappInitializer.d.ts.map +1 -0
- package/dist/types/initializer/index.d.ts +2 -0
- package/dist/types/initializer/index.d.ts.map +1 -0
- package/dist/types/models/access/ValidDappAccessInterfaces.d.ts.map +1 -0
- package/dist/types/models/access/index.d.ts +2 -0
- package/dist/types/models/access/index.d.ts.map +1 -0
- package/dist/types/models/index.d.ts +2 -0
- package/dist/types/models/index.d.ts.map +1 -0
- package/dist/types/{classes/registration → registration}/DappRegistrationService.d.ts +1 -1
- package/dist/types/registration/DappRegistrationService.d.ts.map +1 -0
- package/dist/types/{classes/registration → registration}/DappRegistry.d.ts +1 -1
- package/dist/types/registration/DappRegistry.d.ts.map +1 -0
- package/dist/types/registration/ValidateDappAccessDiviner/Config.d.ts.map +1 -0
- package/dist/types/registration/ValidateDappAccessDiviner/Diviner.d.ts.map +1 -0
- package/dist/types/registration/ValidateDappAccessDiviner/index.d.ts.map +1 -0
- package/dist/types/registration/index.d.ts.map +1 -0
- package/dist/types/signer/Signers.d.ts.map +1 -0
- package/dist/types/signer/index.d.ts.map +1 -0
- package/dist/types/{classes/system → system}/ManageSystemDapps.d.ts +1 -1
- package/dist/types/system/ManageSystemDapps.d.ts.map +1 -0
- package/dist/types/system/Queries.d.ts.map +1 -0
- package/dist/types/system/index.d.ts.map +1 -0
- package/package.json +43 -48
- package/src/{classes/cache/RunningDappCache.ts → RunningDappCache.ts} +2 -2
- package/src/XyOs.ts +3 -3
- package/src/{classes/dapp/access → access}/Caller.ts +3 -2
- package/src/{classes/dapp/access → access}/Resource.ts +3 -3
- package/src/{classes/dapp/access → access}/index.ts +1 -0
- package/src/access/interfaces/index.ts +1 -0
- package/src/{access-interfaces → access/interfaces}/registered-names/helpers/AccessNodeQueries.ts +1 -1
- package/src/{access-interfaces → access/interfaces}/registered-names/helpers/resource/RegistrationsResource.ts +2 -2
- package/src/classes/dapp/index.ts +0 -1
- package/src/classes/index.ts +0 -5
- package/src/{classes/node → dapp/context/creator}/Creator.ts +3 -3
- package/src/{classes/node → dapp/context/creator}/DefaultPayloads/DappAccessPayloads.ts +2 -2
- package/src/{classes/node → dapp/context/creator}/DefaultPayloads/DefaultPayloads.ts +2 -2
- package/src/{classes/node → dapp/context/creator}/DefaultPayloads/NodeInfoPayload.ts +1 -1
- package/src/{classes/node → dapp/context/creator}/createDappContext.ts +2 -2
- package/src/dapp/context/index.ts +1 -0
- package/src/dapp/index.ts +1 -0
- package/src/helpers/index.ts +0 -1
- package/src/index.ts +8 -1
- package/src/{helpers → initializer}/DappInitializer.ts +1 -1
- package/src/initializer/index.ts +1 -0
- package/src/{access-interfaces → models/access}/index.ts +0 -1
- package/src/models/index.ts +1 -0
- package/src/{classes/registration → registration}/DappRegistrationService.ts +5 -5
- package/src/{classes/registration → registration}/DappRegistry.ts +1 -1
- package/src/{classes/registration → registration}/ValidateDappAccessDiviner/Diviner.ts +1 -1
- package/src/{classes/system → system}/ManageSystemDapps.ts +1 -1
- package/dist/types/access-interfaces/ValidDappAccessInterfaces.d.ts.map +0 -1
- package/dist/types/access-interfaces/index.d.ts +0 -3
- package/dist/types/access-interfaces/index.d.ts.map +0 -1
- package/dist/types/access-interfaces/registered-names/helpers/AccessNodeQueries.d.ts.map +0 -1
- package/dist/types/access-interfaces/registered-names/helpers/index.d.ts.map +0 -1
- package/dist/types/access-interfaces/registered-names/helpers/resource/AbstractXnsCaller.d.ts.map +0 -1
- package/dist/types/access-interfaces/registered-names/helpers/resource/RegistrationsResource.d.ts.map +0 -1
- package/dist/types/access-interfaces/registered-names/helpers/resource/RegistrationsResourceQueries.d.ts.map +0 -1
- package/dist/types/access-interfaces/registered-names/helpers/resource/index.d.ts.map +0 -1
- package/dist/types/access-interfaces/registered-names/index.d.ts.map +0 -1
- package/dist/types/classes/cache/RunningAccessDappCache.d.ts.map +0 -1
- package/dist/types/classes/cache/RunningDappCache.d.ts.map +0 -1
- package/dist/types/classes/cache/index.d.ts +0 -3
- package/dist/types/classes/cache/index.d.ts.map +0 -1
- package/dist/types/classes/dapp/access/Caller.d.ts.map +0 -1
- package/dist/types/classes/dapp/access/Queries.d.ts.map +0 -1
- package/dist/types/classes/dapp/access/Resource.d.ts.map +0 -1
- package/dist/types/classes/dapp/access/index.d.ts.map +0 -1
- package/dist/types/classes/node/Creator.d.ts.map +0 -1
- package/dist/types/classes/node/DefaultPayloads/DappAccessPayloads.d.ts.map +0 -1
- package/dist/types/classes/node/DefaultPayloads/DefaultPayloads.d.ts.map +0 -1
- package/dist/types/classes/node/DefaultPayloads/NodeInfoPayload.d.ts.map +0 -1
- package/dist/types/classes/node/DefaultPayloads/index.d.ts.map +0 -1
- package/dist/types/classes/node/ExternalModulePermissions/ExternalModulePermissions.d.ts.map +0 -1
- package/dist/types/classes/node/ExternalModulePermissions/index.d.ts.map +0 -1
- package/dist/types/classes/node/createDappContext.d.ts.map +0 -1
- package/dist/types/classes/node/index.d.ts.map +0 -1
- package/dist/types/classes/registration/DappRegistrationService.d.ts.map +0 -1
- package/dist/types/classes/registration/DappRegistry.d.ts.map +0 -1
- package/dist/types/classes/registration/ValidateDappAccessDiviner/Config.d.ts.map +0 -1
- package/dist/types/classes/registration/ValidateDappAccessDiviner/Diviner.d.ts.map +0 -1
- package/dist/types/classes/registration/ValidateDappAccessDiviner/index.d.ts.map +0 -1
- package/dist/types/classes/registration/index.d.ts.map +0 -1
- package/dist/types/classes/signer/Signers.d.ts.map +0 -1
- package/dist/types/classes/signer/index.d.ts.map +0 -1
- package/dist/types/classes/system/ManageSystemDapps.d.ts.map +0 -1
- package/dist/types/classes/system/Queries.d.ts.map +0 -1
- package/dist/types/classes/system/index.d.ts.map +0 -1
- package/dist/types/helpers/DappInitializer.d.ts.map +0 -1
- package/src/classes/cache/index.ts +0 -2
- /package/dist/types/{classes/cache/RunningDappCache.d.ts → RunningDappCache.d.ts} +0 -0
- /package/dist/types/{classes/dapp/access → access}/Queries.d.ts +0 -0
- /package/dist/types/{classes/cache → access}/RunningAccessDappCache.d.ts +0 -0
- /package/dist/types/{access-interfaces → access/interfaces}/registered-names/helpers/AccessNodeQueries.d.ts +0 -0
- /package/dist/types/{access-interfaces → access/interfaces}/registered-names/helpers/index.d.ts +0 -0
- /package/dist/types/{access-interfaces → access/interfaces}/registered-names/helpers/resource/AbstractXnsCaller.d.ts +0 -0
- /package/dist/types/{access-interfaces → access/interfaces}/registered-names/helpers/resource/RegistrationsResourceQueries.d.ts +0 -0
- /package/dist/types/{access-interfaces → access/interfaces}/registered-names/helpers/resource/index.d.ts +0 -0
- /package/dist/types/{access-interfaces → access/interfaces}/registered-names/index.d.ts +0 -0
- /package/dist/types/{classes/node → dapp/context/creator}/DefaultPayloads/DefaultPayloads.d.ts +0 -0
- /package/dist/types/{classes/node → dapp/context/creator}/DefaultPayloads/index.d.ts +0 -0
- /package/dist/types/{classes/node → dapp/context/creator}/ExternalModulePermissions/ExternalModulePermissions.d.ts +0 -0
- /package/dist/types/{classes/node → dapp/context/creator}/ExternalModulePermissions/index.d.ts +0 -0
- /package/dist/types/{classes/node → dapp/context/creator}/createDappContext.d.ts +0 -0
- /package/dist/types/{classes/node → dapp/context/creator}/index.d.ts +0 -0
- /package/dist/types/{helpers → initializer}/DappInitializer.d.ts +0 -0
- /package/dist/types/{access-interfaces → models/access}/ValidDappAccessInterfaces.d.ts +0 -0
- /package/dist/types/{classes/registration → registration}/ValidateDappAccessDiviner/Config.d.ts +0 -0
- /package/dist/types/{classes/registration → registration}/ValidateDappAccessDiviner/Diviner.d.ts +0 -0
- /package/dist/types/{classes/registration → registration}/ValidateDappAccessDiviner/index.d.ts +0 -0
- /package/dist/types/{classes/registration → registration}/index.d.ts +0 -0
- /package/dist/types/{classes/signer → signer}/Signers.d.ts +0 -0
- /package/dist/types/{classes/signer → signer}/index.d.ts +0 -0
- /package/dist/types/{classes/system → system}/Queries.d.ts +0 -0
- /package/dist/types/{classes/system → system}/index.d.ts +0 -0
- /package/src/{classes/dapp/access → access}/Queries.ts +0 -0
- /package/src/{classes/cache → access}/RunningAccessDappCache.ts +0 -0
- /package/src/{access-interfaces → access/interfaces}/registered-names/helpers/index.ts +0 -0
- /package/src/{access-interfaces → access/interfaces}/registered-names/helpers/resource/AbstractXnsCaller.ts +0 -0
- /package/src/{access-interfaces → access/interfaces}/registered-names/helpers/resource/RegistrationsResourceQueries.ts +0 -0
- /package/src/{access-interfaces → access/interfaces}/registered-names/helpers/resource/index.ts +0 -0
- /package/src/{access-interfaces → access/interfaces}/registered-names/index.ts +0 -0
- /package/src/{classes/node → dapp/context/creator}/DefaultPayloads/index.ts +0 -0
- /package/src/{classes/node → dapp/context/creator}/ExternalModulePermissions/ExternalModulePermissions.ts +0 -0
- /package/src/{classes/node → dapp/context/creator}/ExternalModulePermissions/index.ts +0 -0
- /package/src/{classes/node → dapp/context/creator}/index.ts +0 -0
- /package/src/{access-interfaces → models/access}/ValidDappAccessInterfaces.ts +0 -0
- /package/src/{classes/registration → registration}/ValidateDappAccessDiviner/Config.ts +0 -0
- /package/src/{classes/registration → registration}/ValidateDappAccessDiviner/index.ts +0 -0
- /package/src/{classes/registration → registration}/index.ts +0 -0
- /package/src/{classes/signer → signer}/Signers.ts +0 -0
- /package/src/{classes/signer → signer}/index.ts +0 -0
- /package/src/{classes/system → system}/Queries.ts +0 -0
- /package/src/{classes/system → system}/index.ts +0 -0
|
@@ -48,188 +48,258 @@ import { boot } from "@xyo-network/bios";
|
|
|
48
48
|
import { Kernel } from "@xyo-network/kernel";
|
|
49
49
|
import { ModuleFactoryLocator as ModuleFactoryLocator5 } from "@xyo-network/module-factory-locator";
|
|
50
50
|
|
|
51
|
-
// src/
|
|
52
|
-
import { HDWallet } from "@xyo-network/account";
|
|
53
|
-
import { PayloadDivinerQuerySchema } from "@xyo-network/diviner-payload-model";
|
|
54
|
-
import { DappWalletSeedPhraseSchema } from "@xyo-network/os-model";
|
|
55
|
-
import { v4 as uuid } from "uuid";
|
|
56
|
-
|
|
57
|
-
// src/OsCallerBase.ts
|
|
51
|
+
// src/event/bus/Connection.ts
|
|
58
52
|
import { assertEx } from "@xylabs/assert";
|
|
59
|
-
import {
|
|
60
|
-
|
|
61
|
-
var DappsArchivistModuleName = "DappsArchivist";
|
|
62
|
-
var DappsArchivistDevelopmentModuleName = `${DappsArchivistModuleName}Development`;
|
|
63
|
-
var DappsArchivistPayloadDivinerModuleName = "DappsArchivistPayloadDiviner";
|
|
64
|
-
var DappsArchivistPayloadDevelopmentDivinerModuleName = `${DappsArchivistPayloadDivinerModuleName}Development`;
|
|
65
|
-
var RegisteredDappInterfacesArchivistModuleName = "RegisteredDappInterfacesArchivist";
|
|
66
|
-
var OsCallerBase = class {
|
|
53
|
+
import { BaseEmitter } from "@xyo-network/module-event-emitter";
|
|
54
|
+
var EventBusConnection = class extends BaseEmitter {
|
|
67
55
|
static {
|
|
68
|
-
__name(this, "
|
|
69
|
-
}
|
|
70
|
-
context;
|
|
71
|
-
constructor(context) {
|
|
72
|
-
this.context = context;
|
|
73
|
-
}
|
|
74
|
-
// Get the dapps archivist
|
|
75
|
-
async getDappsArchivist() {
|
|
76
|
-
const mod = assertEx(await this.context.root.resolve(DappsArchivistModuleName), () => `${DappsArchivistModuleName} not found`);
|
|
77
|
-
return asArchivistInstance(mod, () => `${DappsArchivistModuleName} is not an archivist`);
|
|
78
|
-
}
|
|
79
|
-
// Get the dapps archivist development
|
|
80
|
-
async getDappsArchivistDevelopment() {
|
|
81
|
-
const mod = assertEx(await this.context.root.resolve(DappsArchivistDevelopmentModuleName), () => `${DappsArchivistDevelopmentModuleName} not found`);
|
|
82
|
-
return asArchivistInstance(mod, () => `${DappsArchivistDevelopmentModuleName} is not an archivist`);
|
|
56
|
+
__name(this, "EventBusConnection");
|
|
83
57
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
58
|
+
_id;
|
|
59
|
+
description;
|
|
60
|
+
type;
|
|
61
|
+
constructor(request) {
|
|
62
|
+
super({});
|
|
63
|
+
this.description = request.description;
|
|
64
|
+
this.type = request.type;
|
|
88
65
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const mod = assertEx(await this.context.root.resolve(DappsArchivistPayloadDevelopmentDivinerModuleName), () => `${DappsArchivistPayloadDevelopmentDivinerModuleName} not found`);
|
|
92
|
-
return asDivinerInstance(mod, () => `${DappsArchivistPayloadDevelopmentDivinerModuleName} is not a diviner`);
|
|
66
|
+
get id() {
|
|
67
|
+
return assertEx(this._id, () => "Connection ID not set. Did you forget to call buildConnection()?");
|
|
93
68
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const mod = assertEx(await this.context.root.resolve(RegisteredDappInterfacesArchivistModuleName), () => `${RegisteredDappInterfacesArchivistModuleName} not found`);
|
|
97
|
-
return asArchivistInstance(mod, () => `${RegisteredDappInterfacesArchivistModuleName} is not an archivist`);
|
|
69
|
+
buildConnection(id) {
|
|
70
|
+
this._id = id;
|
|
98
71
|
}
|
|
99
72
|
};
|
|
100
73
|
|
|
101
|
-
// src/
|
|
102
|
-
|
|
74
|
+
// src/event/bus/EventBus.ts
|
|
75
|
+
import { findAs } from "@xylabs/array";
|
|
76
|
+
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
77
|
+
import { forget } from "@xylabs/forget";
|
|
78
|
+
import { asArchivistInstance, MemoryArchivist, MemoryArchivistConfigSchema } from "@xyo-network/archivist";
|
|
79
|
+
import { asOptionalEventBusEvent, isPubSubConnections } from "@xyo-network/os-model";
|
|
80
|
+
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
81
|
+
import { Mutex } from "async-mutex";
|
|
82
|
+
import { v4 as uuid } from "uuid";
|
|
83
|
+
var EventBus = class {
|
|
103
84
|
static {
|
|
104
|
-
__name(this, "
|
|
105
|
-
}
|
|
106
|
-
allowedNames;
|
|
107
|
-
// record of all dapps that have requested a seed phrase with the OS
|
|
108
|
-
dappIdRepository;
|
|
109
|
-
// record of all walletIds that have been issued to registered dapps
|
|
110
|
-
walletIdRepository;
|
|
111
|
-
constructor(xyOs, allowedNames) {
|
|
112
|
-
super(xyOs), this.allowedNames = allowedNames, this.dappIdRepository = /* @__PURE__ */ new Map(), this.walletIdRepository = /* @__PURE__ */ new Map();
|
|
85
|
+
__name(this, "EventBus");
|
|
113
86
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
};
|
|
124
|
-
await archivist.insert([
|
|
125
|
-
payload
|
|
126
|
-
]);
|
|
127
|
-
this.dappIdRepository.set(dappId, payload);
|
|
128
|
-
this.walletIdRepository.set(walletId, payload);
|
|
129
|
-
return walletId;
|
|
87
|
+
// Internal Archivist to store event data
|
|
88
|
+
_archivist;
|
|
89
|
+
// Store all connections
|
|
90
|
+
connections = {};
|
|
91
|
+
// Store all publisher callbacks for later removal
|
|
92
|
+
publisherCallbacks = {};
|
|
93
|
+
startMutex = new Mutex();
|
|
94
|
+
get archivist() {
|
|
95
|
+
return asArchivistInstance(assertEx2(this._archivist, () => "Archivist not found. Did you forget to call start()?"), "not a valid archivist instance");
|
|
130
96
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const existingPayload2 = await this.checkDappId(dappName);
|
|
138
|
-
if (existingPayload2) return existingPayload2.walletId;
|
|
139
|
-
throw new Error(`failed to add seed phrase: ${dappName}`);
|
|
140
|
-
} catch (e) {
|
|
141
|
-
console.error(e);
|
|
142
|
-
throw new Error(`failed to add seed phrase: ${dappName}`);
|
|
143
|
-
}
|
|
97
|
+
addConnection(connection) {
|
|
98
|
+
const id = uuid();
|
|
99
|
+
this.connections[id] = connection;
|
|
100
|
+
connection.buildConnection(id);
|
|
101
|
+
if (isPubSubConnections(connection)) {
|
|
102
|
+
this.handlePublisherAdd(connection);
|
|
144
103
|
} else {
|
|
145
|
-
throw new Error(
|
|
104
|
+
throw new Error("Unsupported connection type. Must be PubSub");
|
|
146
105
|
}
|
|
106
|
+
return connection;
|
|
147
107
|
}
|
|
148
|
-
|
|
149
|
-
|
|
108
|
+
removeConnection(connectionId) {
|
|
109
|
+
const connection = this.connections[connectionId];
|
|
110
|
+
if (!connection) {
|
|
111
|
+
throw new Error("Connection not found " + connectionId);
|
|
112
|
+
}
|
|
113
|
+
if (connection && isPubSubConnections(connection)) {
|
|
114
|
+
this.handlePublisherRemove(connection);
|
|
115
|
+
}
|
|
116
|
+
delete this.connections[connectionId];
|
|
150
117
|
}
|
|
151
|
-
async
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
118
|
+
async start(storeName = "EventBusArchivist") {
|
|
119
|
+
return await this.startMutex.runExclusive(async () => {
|
|
120
|
+
if (this._archivist) {
|
|
121
|
+
console.warn("EventBus already started");
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
this._archivist = await MemoryArchivist.create({
|
|
125
|
+
config: {
|
|
126
|
+
name: storeName,
|
|
127
|
+
schema: MemoryArchivistConfigSchema
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
this.archivist.on("inserted", ({ payloads }) => {
|
|
131
|
+
const eventBusEvent = findAs(payloads, asOptionalEventBusEvent);
|
|
132
|
+
if (!eventBusEvent) return;
|
|
133
|
+
for (const connectionId in this.connections) {
|
|
134
|
+
const connection = this.connections[connectionId];
|
|
135
|
+
if (isPubSubConnections(connection) && connection.subscribableEvents) {
|
|
136
|
+
for (const [eventName, callback] of connection.subscribableEvents.entries()) {
|
|
137
|
+
if (eventName !== eventBusEvent.name) continue;
|
|
138
|
+
if (callback) {
|
|
139
|
+
const forgettable = /* @__PURE__ */ __name(async () => await callback({
|
|
140
|
+
payloads
|
|
141
|
+
}), "forgettable");
|
|
142
|
+
forget(forgettable());
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return this;
|
|
149
|
+
});
|
|
166
150
|
}
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
151
|
+
handlePublisherAdd(connection) {
|
|
152
|
+
for (const eventName of connection.publishableEvents ?? []) {
|
|
153
|
+
const connectionPublisherCallback = /* @__PURE__ */ __name(async ({ payloads }) => {
|
|
154
|
+
const event = {
|
|
155
|
+
name: eventName,
|
|
156
|
+
schema: "network.xyo.event.bus.event"
|
|
157
|
+
};
|
|
158
|
+
const eventPayloads = payloads ?? [];
|
|
159
|
+
event.sources = await PayloadBuilder.dataHashes(eventPayloads);
|
|
160
|
+
try {
|
|
161
|
+
await this.archivist.insert([
|
|
162
|
+
event,
|
|
163
|
+
...payloads ?? []
|
|
164
|
+
]);
|
|
165
|
+
} catch (e) {
|
|
166
|
+
console.error("Error inserting event into archivist", e);
|
|
167
|
+
}
|
|
168
|
+
}, "connectionPublisherCallback");
|
|
169
|
+
connection.on(eventName, connectionPublisherCallback);
|
|
170
|
+
const callbackId = connection.id + eventName;
|
|
171
|
+
this.publisherCallbacks[callbackId] = connectionPublisherCallback;
|
|
172
|
+
}
|
|
182
173
|
}
|
|
183
|
-
|
|
184
|
-
|
|
174
|
+
handlePublisherRemove(connection) {
|
|
175
|
+
for (const [, event] of connection.publishableEvents?.entries() ?? []) {
|
|
176
|
+
const id = connection.id + event;
|
|
177
|
+
const callback = this.publisherCallbacks[id];
|
|
178
|
+
if (callback) connection.off(event, callback);
|
|
179
|
+
}
|
|
185
180
|
}
|
|
186
181
|
};
|
|
187
182
|
|
|
188
|
-
// src/
|
|
189
|
-
|
|
190
|
-
import { toJsonString } from "@xylabs/object";
|
|
191
|
-
import { asArchivistInstance as asArchivistInstance2 } from "@xyo-network/archivist-model";
|
|
192
|
-
import { asDivinerInstance as asDivinerInstance2 } from "@xyo-network/diviner-model";
|
|
193
|
-
var DappArchivistModuleName = "DappArchivist";
|
|
194
|
-
var IntentArchivistModuleName = "IntentArchivist";
|
|
195
|
-
var IntentArchivistPayloadDivinerModuleName = "IntentArchivistPayloadDiviner";
|
|
196
|
-
var DappArchivistPayloadDivinerModuleName = "DappArchivistPayloadDiviner";
|
|
197
|
-
var DappCallerBase = class {
|
|
183
|
+
// src/event/bus/PubSubConnection.ts
|
|
184
|
+
var EventBusPubSubConnection = class extends EventBusConnection {
|
|
198
185
|
static {
|
|
199
|
-
__name(this, "
|
|
200
|
-
}
|
|
201
|
-
context;
|
|
202
|
-
constructor(context) {
|
|
203
|
-
this.context = context;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Get the DappArchivist
|
|
207
|
-
*/
|
|
208
|
-
async getDappArchivist() {
|
|
209
|
-
const mod = assertEx2(await this.context.root.resolve(DappArchivistModuleName), () => `${DappArchivistModuleName} not found [${toJsonString(this.context.root.publicChildren())}]`);
|
|
210
|
-
return asArchivistInstance2(mod, () => `${DappArchivistModuleName} is not an archivist`);
|
|
186
|
+
__name(this, "EventBusPubSubConnection");
|
|
211
187
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
188
|
+
publishableEvents;
|
|
189
|
+
subscribableEvents;
|
|
190
|
+
constructor(request) {
|
|
191
|
+
super(request);
|
|
192
|
+
if (request.type !== "PubSub") {
|
|
193
|
+
throw new Error("Invalid connection type. Must be PubSub");
|
|
194
|
+
}
|
|
195
|
+
this.publishableEvents = request.publishableEvents;
|
|
196
|
+
this.subscribableEvents = request.subscribableEvents;
|
|
218
197
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// src/event/connections/DappAccessRequest.ts
|
|
201
|
+
var DappAccessRequestEvent = "dappAccessRequest";
|
|
202
|
+
var dappAccessRequestConnectionRequest = {
|
|
203
|
+
publishableEvents: [
|
|
204
|
+
DappAccessRequestEvent
|
|
205
|
+
],
|
|
206
|
+
type: "PubSub"
|
|
207
|
+
};
|
|
208
|
+
var dappAccessRequestConnection = /* @__PURE__ */ __name(() => new EventBusPubSubConnection(dappAccessRequestConnectionRequest), "dappAccessRequestConnection");
|
|
209
|
+
|
|
210
|
+
// src/event/connections/ExposeDappRequest.ts
|
|
211
|
+
var ExposeDappRequestEvent = "exposeDappRequest";
|
|
212
|
+
var exposeDappConnectionRequest = {
|
|
213
|
+
publishableEvents: [
|
|
214
|
+
ExposeDappRequestEvent
|
|
215
|
+
],
|
|
216
|
+
type: "PubSub"
|
|
217
|
+
};
|
|
218
|
+
var exposeDappRequestConnection = /* @__PURE__ */ __name(() => new EventBusPubSubConnection(exposeDappConnectionRequest), "exposeDappRequestConnection");
|
|
219
|
+
|
|
220
|
+
// src/event/connections/OsPubSubNetworkReady.ts
|
|
221
|
+
var OsPubSubNetworkReadyEvent = "osPubSubNetworkReady";
|
|
222
|
+
var osPubSubNetworkConnectionRequest = {
|
|
223
|
+
publishableEvents: [
|
|
224
|
+
OsPubSubNetworkReadyEvent
|
|
225
|
+
],
|
|
226
|
+
type: "PubSub"
|
|
227
|
+
};
|
|
228
|
+
var osPubSubNetworkReadyConnection = /* @__PURE__ */ __name(() => new EventBusPubSubConnection(osPubSubNetworkConnectionRequest), "osPubSubNetworkReadyConnection");
|
|
229
|
+
|
|
230
|
+
// src/event/connections/OsSettingsReady.ts
|
|
231
|
+
var OsSettingsReadyEvent = "osSettingsReady";
|
|
232
|
+
var osSettingsConnectionRequest = {
|
|
233
|
+
publishableEvents: [
|
|
234
|
+
OsSettingsReadyEvent
|
|
235
|
+
],
|
|
236
|
+
type: "PubSub"
|
|
237
|
+
};
|
|
238
|
+
var osSettingsReadyConnection = /* @__PURE__ */ __name(() => new EventBusPubSubConnection(osSettingsConnectionRequest), "osSettingsReadyConnection");
|
|
239
|
+
|
|
240
|
+
// src/event/connections/OsXyoPublicReady.ts
|
|
241
|
+
var OsXyoPublicNetworkReadyEvent = "osXyoPublicNetworkReady";
|
|
242
|
+
var osXyoPublicNetworkConnectionRequest = {
|
|
243
|
+
publishableEvents: [
|
|
244
|
+
OsXyoPublicNetworkReadyEvent
|
|
245
|
+
],
|
|
246
|
+
type: "PubSub"
|
|
247
|
+
};
|
|
248
|
+
var osXyoPublicNetworkReadyConnection = /* @__PURE__ */ __name(() => new EventBusPubSubConnection(osXyoPublicNetworkConnectionRequest), "osXyoPublicNetworkReadyConnection");
|
|
249
|
+
|
|
250
|
+
// src/lib/initializeXns.ts
|
|
251
|
+
import { asDivinerInstance } from "@xyo-network/diviner-model";
|
|
252
|
+
import { ResolveHelper } from "@xyo-network/module-model";
|
|
253
|
+
import { NameRegistrarTransformer } from "@xyo-network/module-resolver";
|
|
254
|
+
var initializeXns = /* @__PURE__ */ __name(async (xnsNode) => {
|
|
255
|
+
if (ResolveHelper.transformers.length === 0) {
|
|
256
|
+
const registrarDiviner = asDivinerInstance(await xnsNode?.resolve("AddressRecords:AddressRecordIndexDiviner"));
|
|
257
|
+
if (registrarDiviner) {
|
|
258
|
+
const transformer = new NameRegistrarTransformer(registrarDiviner, "xyo");
|
|
259
|
+
ResolveHelper.transformers = [
|
|
260
|
+
transformer
|
|
261
|
+
];
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
225
264
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
265
|
+
return false;
|
|
266
|
+
}, "initializeXns");
|
|
267
|
+
|
|
268
|
+
// src/lib/NameTransforms.ts
|
|
269
|
+
var NameTransforms = class _NameTransforms {
|
|
270
|
+
static {
|
|
271
|
+
__name(this, "NameTransforms");
|
|
272
|
+
}
|
|
273
|
+
value;
|
|
274
|
+
constructor(value) {
|
|
275
|
+
this.value = value;
|
|
276
|
+
}
|
|
277
|
+
static deSlug(value) {
|
|
278
|
+
return value.replaceAll("-", " ").split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
279
|
+
}
|
|
280
|
+
static moduleName(value) {
|
|
281
|
+
return value.replaceAll(" ", "");
|
|
282
|
+
}
|
|
283
|
+
static slug(value) {
|
|
284
|
+
return value.replaceAll(" ", "-").toLocaleLowerCase();
|
|
285
|
+
}
|
|
286
|
+
deSlug() {
|
|
287
|
+
return _NameTransforms.deSlug(this.value);
|
|
288
|
+
}
|
|
289
|
+
moduleName() {
|
|
290
|
+
return _NameTransforms.moduleName(this.value);
|
|
291
|
+
}
|
|
292
|
+
slug() {
|
|
293
|
+
return _NameTransforms.slug(this.value);
|
|
230
294
|
}
|
|
231
295
|
};
|
|
232
296
|
|
|
297
|
+
// src/loadOsNode.ts
|
|
298
|
+
import { IndexedDbArchivist } from "@xyo-network/archivist-indexeddb";
|
|
299
|
+
import { IndexedDbPayloadDiviner } from "@xyo-network/diviner-payload-indexeddb";
|
|
300
|
+
import { ManifestWrapper } from "@xyo-network/manifest-wrapper";
|
|
301
|
+
import { ModuleFactoryLocator } from "@xyo-network/module-factory-locator";
|
|
302
|
+
|
|
233
303
|
// src/manifest/os-node.manifest.json
|
|
234
304
|
var os_node_manifest_default = {
|
|
235
305
|
$schema: "https://raw.githubusercontent.com/XYOracleNetwork/sdk-xyo-client-js/main/packages/manifest/src/compilations/dapp-package-manifest-schema.json",
|
|
@@ -364,56 +434,91 @@ var os_node_manifest_default = {
|
|
|
364
434
|
schema: "network.xyo.manifest.package.dapp"
|
|
365
435
|
};
|
|
366
436
|
|
|
367
|
-
// src/
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
437
|
+
// src/loadOsNode.ts
|
|
438
|
+
var OS_NODE_PATH = "1'";
|
|
439
|
+
var getDefaultOsNodeLocator = /* @__PURE__ */ __name(() => {
|
|
440
|
+
const locator = new ModuleFactoryLocator();
|
|
441
|
+
locator.register(IndexedDbArchivist, {
|
|
442
|
+
"network.xyo.archivist.persistence.scope": "device"
|
|
443
|
+
});
|
|
444
|
+
locator.register(IndexedDbPayloadDiviner, {
|
|
445
|
+
"network.xyo.archivist.persistence.scope": "device"
|
|
446
|
+
});
|
|
447
|
+
return locator;
|
|
448
|
+
}, "getDefaultOsNodeLocator");
|
|
449
|
+
var loadOsNode = /* @__PURE__ */ __name(async (osWallet, locator) => {
|
|
450
|
+
try {
|
|
451
|
+
const osNodeWallet = await osWallet.derivePath(OS_NODE_PATH);
|
|
452
|
+
const osNodeLocator = locator ?? getDefaultOsNodeLocator();
|
|
453
|
+
const manifestWrapper = new ManifestWrapper(os_node_manifest_default, osNodeWallet, osNodeLocator);
|
|
454
|
+
const osNode = (await manifestWrapper.loadNodes())[0];
|
|
455
|
+
return [
|
|
456
|
+
osNode
|
|
457
|
+
];
|
|
458
|
+
} catch (e) {
|
|
459
|
+
const error = e;
|
|
460
|
+
console.error(`Error creating os node: ${error.message}`);
|
|
461
|
+
console.error(`Error creating os node: ${error.stack}`);
|
|
462
|
+
throw new Error(`Error creating os node: ${error.message}`);
|
|
381
463
|
}
|
|
382
|
-
|
|
383
|
-
}, "initializeXns");
|
|
464
|
+
}, "loadOsNode");
|
|
384
465
|
|
|
385
|
-
// src/
|
|
386
|
-
|
|
466
|
+
// src/registration/DappRegistrationService.ts
|
|
467
|
+
import { forget as forget2 } from "@xylabs/forget";
|
|
468
|
+
import { fulfilled, rejected } from "@xylabs/promise";
|
|
469
|
+
import { ModuleFactoryLocator as ModuleFactoryLocator4 } from "@xyo-network/module-factory-locator";
|
|
470
|
+
import { DappIntentTypes, DappMode as DappMode2, isRegisteredDappAccessDappSet, isRegisteredDappExposedDappSet } from "@xyo-network/os-model";
|
|
471
|
+
|
|
472
|
+
// src/intent/Caller.ts
|
|
473
|
+
import { PayloadDivinerQuerySchema } from "@xyo-network/diviner-payload-model";
|
|
474
|
+
import { DappIntentSchema, DappMode } from "@xyo-network/os-model";
|
|
475
|
+
|
|
476
|
+
// src/DappCallerBase.ts
|
|
477
|
+
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
478
|
+
import { toJsonString } from "@xylabs/object";
|
|
479
|
+
import { asArchivistInstance as asArchivistInstance2 } from "@xyo-network/archivist-model";
|
|
480
|
+
import { asDivinerInstance as asDivinerInstance2 } from "@xyo-network/diviner-model";
|
|
481
|
+
var DappArchivistModuleName = "DappArchivist";
|
|
482
|
+
var IntentArchivistModuleName = "IntentArchivist";
|
|
483
|
+
var IntentArchivistPayloadDivinerModuleName = "IntentArchivistPayloadDiviner";
|
|
484
|
+
var DappArchivistPayloadDivinerModuleName = "DappArchivistPayloadDiviner";
|
|
485
|
+
var DappCallerBase = class {
|
|
387
486
|
static {
|
|
388
|
-
__name(this, "
|
|
389
|
-
}
|
|
390
|
-
value;
|
|
391
|
-
constructor(value) {
|
|
392
|
-
this.value = value;
|
|
393
|
-
}
|
|
394
|
-
static deSlug(value) {
|
|
395
|
-
return value.replaceAll("-", " ").split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
487
|
+
__name(this, "DappCallerBase");
|
|
396
488
|
}
|
|
397
|
-
|
|
398
|
-
|
|
489
|
+
context;
|
|
490
|
+
constructor(context) {
|
|
491
|
+
this.context = context;
|
|
399
492
|
}
|
|
400
|
-
|
|
401
|
-
|
|
493
|
+
/**
|
|
494
|
+
* Get the DappArchivist
|
|
495
|
+
*/
|
|
496
|
+
async getDappArchivist() {
|
|
497
|
+
const mod = assertEx3(await this.context.root.resolve(DappArchivistModuleName), () => `${DappArchivistModuleName} not found [${toJsonString(this.context.root.publicChildren())}]`);
|
|
498
|
+
return asArchivistInstance2(mod, () => `${DappArchivistModuleName} is not an archivist`);
|
|
402
499
|
}
|
|
403
|
-
|
|
404
|
-
|
|
500
|
+
/**
|
|
501
|
+
* Get the DappArchivistPayloadDiviner
|
|
502
|
+
*/
|
|
503
|
+
async getDappArchivistPayloadDiviner() {
|
|
504
|
+
const mod = assertEx3(await this.context.root.resolve(DappArchivistPayloadDivinerModuleName), () => `${DappArchivistPayloadDivinerModuleName} not found`);
|
|
505
|
+
return asDivinerInstance2(mod, () => `${DappArchivistPayloadDivinerModuleName} is not a diviner`);
|
|
405
506
|
}
|
|
406
|
-
|
|
407
|
-
|
|
507
|
+
/**
|
|
508
|
+
* Get the IntentArchivist
|
|
509
|
+
*/
|
|
510
|
+
async getDappIntentArchivist() {
|
|
511
|
+
const mod = assertEx3(await this.context.root.resolve(IntentArchivistModuleName), () => `${IntentArchivistModuleName} not found`);
|
|
512
|
+
return asArchivistInstance2(mod, () => `${IntentArchivistModuleName} is not an archivist`);
|
|
408
513
|
}
|
|
409
|
-
|
|
410
|
-
|
|
514
|
+
// Get the IntentArchivistPayloadDiviner
|
|
515
|
+
async getDappIntentArchivistPayloadDiviner() {
|
|
516
|
+
const mod = assertEx3(await this.context.root.resolve(IntentArchivistPayloadDivinerModuleName), () => `${IntentArchivistPayloadDivinerModuleName} not found`);
|
|
517
|
+
return asDivinerInstance2(mod, () => `${IntentArchivistPayloadDivinerModuleName} is not a diviner`);
|
|
411
518
|
}
|
|
412
519
|
};
|
|
413
520
|
|
|
414
521
|
// src/intent/Caller.ts
|
|
415
|
-
import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema2 } from "@xyo-network/diviner-payload-model";
|
|
416
|
-
import { DappIntentSchema, DappMode } from "@xyo-network/os-model";
|
|
417
522
|
var DappIntentCaller = class _DappIntentCaller extends DappCallerBase {
|
|
418
523
|
static {
|
|
419
524
|
__name(this, "DappIntentCaller");
|
|
@@ -466,7 +571,7 @@ var DappIntentCaller = class _DappIntentCaller extends DappCallerBase {
|
|
|
466
571
|
const query = {
|
|
467
572
|
limit: 1,
|
|
468
573
|
order: "desc",
|
|
469
|
-
schema:
|
|
574
|
+
schema: PayloadDivinerQuerySchema,
|
|
470
575
|
sourceDappId: dappName
|
|
471
576
|
};
|
|
472
577
|
return await diviner.divine([
|
|
@@ -475,215 +580,326 @@ var DappIntentCaller = class _DappIntentCaller extends DappCallerBase {
|
|
|
475
580
|
}
|
|
476
581
|
};
|
|
477
582
|
|
|
478
|
-
// src/
|
|
479
|
-
import {
|
|
480
|
-
import
|
|
481
|
-
import { ModuleFactoryLocator as ModuleFactoryLocator3 } from "@xyo-network/module-factory-locator";
|
|
482
|
-
import { DappIntentTypes, DappMode as DappMode2, isRegisteredDappAccessDappSet, isRegisteredDappExposedDappSet } from "@xyo-network/os-model";
|
|
583
|
+
// src/system/ManageSystemDapps.ts
|
|
584
|
+
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
|
|
585
|
+
import semver from "semver";
|
|
483
586
|
|
|
484
|
-
// src/
|
|
485
|
-
import { assertEx as
|
|
486
|
-
import {
|
|
487
|
-
|
|
587
|
+
// src/OsCallerBase.ts
|
|
588
|
+
import { assertEx as assertEx4 } from "@xylabs/assert";
|
|
589
|
+
import { asArchivistInstance as asArchivistInstance3 } from "@xyo-network/archivist-model";
|
|
590
|
+
import { asDivinerInstance as asDivinerInstance3 } from "@xyo-network/diviner-model";
|
|
591
|
+
var DappsArchivistModuleName = "DappsArchivist";
|
|
592
|
+
var DappsArchivistDevelopmentModuleName = `${DappsArchivistModuleName}Development`;
|
|
593
|
+
var DappsArchivistPayloadDivinerModuleName = "DappsArchivistPayloadDiviner";
|
|
594
|
+
var DappsArchivistPayloadDevelopmentDivinerModuleName = `${DappsArchivistPayloadDivinerModuleName}Development`;
|
|
595
|
+
var RegisteredDappInterfacesArchivistModuleName = "RegisteredDappInterfacesArchivist";
|
|
596
|
+
var OsCallerBase = class {
|
|
488
597
|
static {
|
|
489
|
-
__name(this, "
|
|
598
|
+
__name(this, "OsCallerBase");
|
|
490
599
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
constructor(request) {
|
|
495
|
-
super({});
|
|
496
|
-
this.description = request.description;
|
|
497
|
-
this.type = request.type;
|
|
600
|
+
context;
|
|
601
|
+
constructor(context) {
|
|
602
|
+
this.context = context;
|
|
498
603
|
}
|
|
499
|
-
|
|
500
|
-
|
|
604
|
+
// Get the dapps archivist
|
|
605
|
+
async getDappsArchivist() {
|
|
606
|
+
const mod = assertEx4(await this.context.root.resolve(DappsArchivistModuleName), () => `${DappsArchivistModuleName} not found`);
|
|
607
|
+
return asArchivistInstance3(mod, () => `${DappsArchivistModuleName} is not an archivist`);
|
|
501
608
|
}
|
|
502
|
-
|
|
503
|
-
|
|
609
|
+
// Get the dapps archivist development
|
|
610
|
+
async getDappsArchivistDevelopment() {
|
|
611
|
+
const mod = assertEx4(await this.context.root.resolve(DappsArchivistDevelopmentModuleName), () => `${DappsArchivistDevelopmentModuleName} not found`);
|
|
612
|
+
return asArchivistInstance3(mod, () => `${DappsArchivistDevelopmentModuleName} is not an archivist`);
|
|
613
|
+
}
|
|
614
|
+
// Get the dapps archivist payload diviner
|
|
615
|
+
async getDappsArchivistPayloadDiviner() {
|
|
616
|
+
const mod = assertEx4(await this.context.root.resolve(DappsArchivistPayloadDivinerModuleName), () => `${DappsArchivistPayloadDivinerModuleName} not found`);
|
|
617
|
+
return asDivinerInstance3(mod, () => `${DappsArchivistPayloadDivinerModuleName} is not a diviner`);
|
|
618
|
+
}
|
|
619
|
+
// Get the dapps archivist payload diviner development
|
|
620
|
+
async getDappsArchivistPayloadDivinerDevelopment() {
|
|
621
|
+
const mod = assertEx4(await this.context.root.resolve(DappsArchivistPayloadDevelopmentDivinerModuleName), () => `${DappsArchivistPayloadDevelopmentDivinerModuleName} not found`);
|
|
622
|
+
return asDivinerInstance3(mod, () => `${DappsArchivistPayloadDevelopmentDivinerModuleName} is not a diviner`);
|
|
623
|
+
}
|
|
624
|
+
// Get the registered dapp interfaces archivist
|
|
625
|
+
async getRegisteredDappInterfacesArchivist() {
|
|
626
|
+
const mod = assertEx4(await this.context.root.resolve(RegisteredDappInterfacesArchivistModuleName), () => `${RegisteredDappInterfacesArchivistModuleName} not found`);
|
|
627
|
+
return asArchivistInstance3(mod, () => `${RegisteredDappInterfacesArchivistModuleName} is not an archivist`);
|
|
504
628
|
}
|
|
505
629
|
};
|
|
506
630
|
|
|
507
|
-
// src/
|
|
508
|
-
import {
|
|
509
|
-
import {
|
|
510
|
-
import {
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
631
|
+
// src/system/Queries.ts
|
|
632
|
+
import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema2 } from "@xyo-network/diviner-payload-model";
|
|
633
|
+
import { DappConfigSchema, DappIconSchema, DappWidgetConfigSchema, UnregisteredDappAccessSchema } from "@xyo-network/os-model";
|
|
634
|
+
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
635
|
+
var SystemDappQueries = {
|
|
636
|
+
async getDappAccess(diviner, name, version) {
|
|
637
|
+
const accessQuery = {
|
|
638
|
+
order: "desc",
|
|
639
|
+
registeringDappId: name,
|
|
640
|
+
schema: PayloadDivinerQuerySchema2,
|
|
641
|
+
schemas: [
|
|
642
|
+
UnregisteredDappAccessSchema
|
|
643
|
+
],
|
|
644
|
+
version
|
|
645
|
+
};
|
|
646
|
+
return await diviner.divine([
|
|
647
|
+
accessQuery
|
|
648
|
+
]);
|
|
649
|
+
},
|
|
650
|
+
async getLatestConfig(diviner, name) {
|
|
651
|
+
const configQuery = {
|
|
652
|
+
limit: 1,
|
|
653
|
+
name,
|
|
654
|
+
order: "desc",
|
|
655
|
+
schema: PayloadDivinerQuerySchema2,
|
|
656
|
+
schemas: [
|
|
657
|
+
DappConfigSchema
|
|
658
|
+
]
|
|
659
|
+
};
|
|
660
|
+
const [dappConfig] = await diviner.divine([
|
|
661
|
+
configQuery
|
|
662
|
+
]);
|
|
663
|
+
return dappConfig;
|
|
664
|
+
},
|
|
665
|
+
async getLatestIcon(diviner, name, version) {
|
|
666
|
+
const iconQuery = {
|
|
667
|
+
name,
|
|
668
|
+
order: "desc",
|
|
669
|
+
schema: PayloadDivinerQuerySchema2,
|
|
670
|
+
schemas: [
|
|
671
|
+
DappIconSchema
|
|
672
|
+
],
|
|
673
|
+
version
|
|
674
|
+
};
|
|
675
|
+
const [dappIcon] = await diviner.divine([
|
|
676
|
+
iconQuery
|
|
677
|
+
]);
|
|
678
|
+
return dappIcon;
|
|
679
|
+
},
|
|
680
|
+
async getWidgetConfigs(diviner, name, version) {
|
|
681
|
+
const widgetConfigQuery = {
|
|
682
|
+
dappId: name,
|
|
683
|
+
order: "desc",
|
|
684
|
+
schema: PayloadDivinerQuerySchema2,
|
|
685
|
+
schemas: [
|
|
686
|
+
DappWidgetConfigSchema
|
|
687
|
+
],
|
|
688
|
+
version
|
|
689
|
+
};
|
|
690
|
+
const widgetConfigs = await diviner.divine([
|
|
691
|
+
widgetConfigQuery
|
|
692
|
+
]);
|
|
693
|
+
const uniqueConfigs = {};
|
|
694
|
+
for (const widgetConfig of widgetConfigs) {
|
|
695
|
+
const hash = await PayloadBuilder2.dataHash(widgetConfig);
|
|
696
|
+
uniqueConfigs[widgetConfig.mode ?? hash] = widgetConfig;
|
|
697
|
+
}
|
|
698
|
+
return Object.values(uniqueConfigs);
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
// src/system/ManageSystemDapps.ts
|
|
703
|
+
var ManageSystemDapps = class extends OsCallerBase {
|
|
517
704
|
static {
|
|
518
|
-
__name(this, "
|
|
705
|
+
__name(this, "ManageSystemDapps");
|
|
519
706
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
return asArchivistInstance3(assertEx4(this._archivist, () => "Archivist not found. Did you forget to call start()?"), "not a valid archivist instance");
|
|
707
|
+
defaultSystemNames;
|
|
708
|
+
defaultSystemDapps;
|
|
709
|
+
defaultSystemDappParams;
|
|
710
|
+
locator;
|
|
711
|
+
developmentMode;
|
|
712
|
+
onErrorCallbacks;
|
|
713
|
+
constructor(context, defaultSystemNames, defaultSystemDapps, defaultSystemDappParams, locator, developmentMode) {
|
|
714
|
+
super(context), this.defaultSystemNames = defaultSystemNames, this.defaultSystemDapps = defaultSystemDapps, this.defaultSystemDappParams = defaultSystemDappParams, this.locator = locator, this.developmentMode = developmentMode, this.onErrorCallbacks = [];
|
|
529
715
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
} else {
|
|
537
|
-
throw new Error("Unsupported connection type. Must be PubSub");
|
|
538
|
-
}
|
|
539
|
-
return connection;
|
|
716
|
+
/**
|
|
717
|
+
* Add a callback to listen for errors throwing during system dapp registration
|
|
718
|
+
* @param {ErrorListener} errorListener
|
|
719
|
+
*/
|
|
720
|
+
addErrorListener(errorListener) {
|
|
721
|
+
this.onErrorCallbacks.push(errorListener);
|
|
540
722
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
this.handlePublisherRemove(connection);
|
|
548
|
-
}
|
|
549
|
-
delete this.connections[connectionId];
|
|
723
|
+
/**
|
|
724
|
+
* Installs the dapps into the OS and builds the appropriate DappSet
|
|
725
|
+
*/
|
|
726
|
+
async install() {
|
|
727
|
+
await this.insertPayloads();
|
|
728
|
+
return await this.latestSets();
|
|
550
729
|
}
|
|
551
|
-
async
|
|
552
|
-
|
|
553
|
-
if (this._archivist) {
|
|
554
|
-
console.warn("EventBus already started");
|
|
555
|
-
return this;
|
|
556
|
-
}
|
|
557
|
-
this._archivist = await MemoryArchivist.create({
|
|
558
|
-
config: {
|
|
559
|
-
name: storeName,
|
|
560
|
-
schema: MemoryArchivistConfigSchema
|
|
561
|
-
}
|
|
562
|
-
});
|
|
563
|
-
this.archivist.on("inserted", ({ payloads }) => {
|
|
564
|
-
const eventBusEvent = findAs(payloads, asOptionalEventBusEvent);
|
|
565
|
-
if (!eventBusEvent) return;
|
|
566
|
-
for (const connectionId in this.connections) {
|
|
567
|
-
const connection = this.connections[connectionId];
|
|
568
|
-
if (isPubSubConnections(connection) && connection.subscribableEvents) {
|
|
569
|
-
for (const [eventName, callback] of connection.subscribableEvents.entries()) {
|
|
570
|
-
if (eventName !== eventBusEvent.name) continue;
|
|
571
|
-
if (callback) {
|
|
572
|
-
const forgettable = /* @__PURE__ */ __name(async () => await callback({
|
|
573
|
-
payloads
|
|
574
|
-
}), "forgettable");
|
|
575
|
-
forget(forgettable());
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
});
|
|
581
|
-
return this;
|
|
582
|
-
});
|
|
730
|
+
async freshInstall(archivist) {
|
|
731
|
+
await archivist.insert(this.defaultSystemDapps);
|
|
583
732
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
733
|
+
async insertPayloads() {
|
|
734
|
+
const archivist = this.developmentMode ? await this.getDappsArchivistDevelopment() : await this.getDappsArchivist();
|
|
735
|
+
try {
|
|
736
|
+
const allPayloads = await archivist.all();
|
|
737
|
+
if (allPayloads.length === 0) {
|
|
738
|
+
await this.freshInstall(archivist);
|
|
739
|
+
return true;
|
|
740
|
+
}
|
|
741
|
+
for (const systemDappPayload of this.defaultSystemDapps) {
|
|
593
742
|
try {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
...payloads ?? []
|
|
597
|
-
]);
|
|
743
|
+
const validSemver = semver.valid(systemDappPayload.version);
|
|
744
|
+
if (!validSemver) throw new Error("semver is a valid type (string) but was not able to be parsed");
|
|
598
745
|
} catch (e) {
|
|
599
|
-
console.error(
|
|
746
|
+
console.error(`${systemDappPayload.version} does not appear to be a valid semver value`, e);
|
|
747
|
+
continue;
|
|
600
748
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
749
|
+
const [existing] = await archivist.get([
|
|
750
|
+
await PayloadBuilder3.dataHash(systemDappPayload)
|
|
751
|
+
]);
|
|
752
|
+
if (existing) continue;
|
|
753
|
+
await archivist.insert([
|
|
754
|
+
systemDappPayload
|
|
755
|
+
]);
|
|
756
|
+
}
|
|
757
|
+
return true;
|
|
758
|
+
} catch (e) {
|
|
759
|
+
console.error("error installing system dapps");
|
|
760
|
+
throw e;
|
|
605
761
|
}
|
|
606
762
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
763
|
+
async latestSets() {
|
|
764
|
+
const diviner = this.developmentMode ? await this.getDappsArchivistPayloadDivinerDevelopment() : await this.getDappsArchivistPayloadDiviner();
|
|
765
|
+
const dappSets = [];
|
|
766
|
+
const failedPayloads = [];
|
|
767
|
+
for (const name of this.defaultSystemNames) {
|
|
768
|
+
try {
|
|
769
|
+
const dappConfig = await SystemDappQueries.getLatestConfig(diviner, name);
|
|
770
|
+
if (!dappConfig) {
|
|
771
|
+
console.error(`No config found for dapp ${name}`);
|
|
772
|
+
continue;
|
|
773
|
+
}
|
|
774
|
+
const dappIcon = await SystemDappQueries.getLatestIcon(diviner, name, dappConfig.version);
|
|
775
|
+
if (!dappIcon) {
|
|
776
|
+
console.error(`No icon found for dapp ${dappConfig.name}`);
|
|
777
|
+
failedPayloads.push(dappConfig);
|
|
778
|
+
continue;
|
|
779
|
+
}
|
|
780
|
+
const dappAccess = await SystemDappQueries.getDappAccess(diviner, name, dappConfig.version);
|
|
781
|
+
const dappParams = this.defaultSystemDappParams[dappConfig.name];
|
|
782
|
+
if (!dappParams) {
|
|
783
|
+
console.error(`No params found for dapp ${dappConfig.name}. Did you forget to add it to OsDappParams?`);
|
|
784
|
+
failedPayloads.push(dappConfig);
|
|
785
|
+
continue;
|
|
786
|
+
}
|
|
787
|
+
const dappWidgetConfigs = await SystemDappQueries.getWidgetConfigs(diviner, name, dappConfig.version);
|
|
788
|
+
dappSets.push({
|
|
789
|
+
dapp: {
|
|
790
|
+
accessors: dappAccess,
|
|
791
|
+
config: dappConfig,
|
|
792
|
+
icon: dappIcon,
|
|
793
|
+
params: dappParams,
|
|
794
|
+
widgetConfigs: dappWidgetConfigs
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
} catch {
|
|
798
|
+
console.error(`Failed to build dapp ${name}`);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
if (failedPayloads.length > 0) {
|
|
802
|
+
for (const cb of this.onErrorCallbacks) cb(failedPayloads);
|
|
612
803
|
}
|
|
804
|
+
return dappSets;
|
|
613
805
|
}
|
|
614
806
|
};
|
|
615
807
|
|
|
616
|
-
// src/
|
|
617
|
-
|
|
808
|
+
// src/wallet/DappSeedPhraseRepository.ts
|
|
809
|
+
import { HDWallet } from "@xyo-network/account";
|
|
810
|
+
import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema3 } from "@xyo-network/diviner-payload-model";
|
|
811
|
+
import { DappWalletSeedPhraseSchema } from "@xyo-network/os-model";
|
|
812
|
+
import { v4 as uuid2 } from "uuid";
|
|
813
|
+
var DappSeedPhraseRepository = class extends OsCallerBase {
|
|
618
814
|
static {
|
|
619
|
-
__name(this, "
|
|
815
|
+
__name(this, "DappSeedPhraseRepository");
|
|
620
816
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
817
|
+
allowedNames;
|
|
818
|
+
// record of all dapps that have requested a seed phrase with the OS
|
|
819
|
+
dappIdRepository;
|
|
820
|
+
// record of all walletIds that have been issued to registered dapps
|
|
821
|
+
walletIdRepository;
|
|
822
|
+
constructor(xyOs, allowedNames) {
|
|
823
|
+
super(xyOs), this.allowedNames = allowedNames, this.dappIdRepository = /* @__PURE__ */ new Map(), this.walletIdRepository = /* @__PURE__ */ new Map();
|
|
824
|
+
}
|
|
825
|
+
async add(dappId) {
|
|
826
|
+
const archivist = await this.getDappsArchivist();
|
|
827
|
+
const seedPhrase = this.newPhrase();
|
|
828
|
+
const walletId = uuid2();
|
|
829
|
+
const payload = {
|
|
830
|
+
dappId,
|
|
831
|
+
schema: DappWalletSeedPhraseSchema,
|
|
832
|
+
seedPhrase,
|
|
833
|
+
walletId
|
|
834
|
+
};
|
|
835
|
+
await archivist.insert([
|
|
836
|
+
payload
|
|
837
|
+
]);
|
|
838
|
+
this.dappIdRepository.set(dappId, payload);
|
|
839
|
+
this.walletIdRepository.set(walletId, payload);
|
|
840
|
+
return walletId;
|
|
841
|
+
}
|
|
842
|
+
async findOrCreate(dappName) {
|
|
843
|
+
if (this.allowedNames.includes(dappName)) {
|
|
844
|
+
const existingPayload = await this.checkDappId(dappName);
|
|
845
|
+
if (existingPayload) return existingPayload.walletId;
|
|
846
|
+
try {
|
|
847
|
+
await this.add(dappName);
|
|
848
|
+
const existingPayload2 = await this.checkDappId(dappName);
|
|
849
|
+
if (existingPayload2) return existingPayload2.walletId;
|
|
850
|
+
throw new Error(`failed to add seed phrase: ${dappName}`);
|
|
851
|
+
} catch (e) {
|
|
852
|
+
console.error(e);
|
|
853
|
+
throw new Error(`failed to add seed phrase: ${dappName}`);
|
|
854
|
+
}
|
|
855
|
+
} else {
|
|
856
|
+
throw new Error(`${dappName} is not allowed to register a seed phase. NOTE: this is a safeguard till 3rd party dApps can be validated`);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
async request(walletId) {
|
|
860
|
+
return (await this.checkWalletId(walletId))?.seedPhrase;
|
|
861
|
+
}
|
|
862
|
+
async checkDappId(dappId) {
|
|
863
|
+
const diviner = await this.getDappsArchivistPayloadDiviner();
|
|
864
|
+
const query = {
|
|
865
|
+
dappId,
|
|
866
|
+
limit: 1,
|
|
867
|
+
order: "desc",
|
|
868
|
+
schema: PayloadDivinerQuerySchema3,
|
|
869
|
+
schemas: [
|
|
870
|
+
DappWalletSeedPhraseSchema
|
|
871
|
+
]
|
|
872
|
+
};
|
|
873
|
+
const results = await diviner.divine([
|
|
874
|
+
query
|
|
875
|
+
]);
|
|
876
|
+
return results.length > 0 ? results[0] : void 0;
|
|
877
|
+
}
|
|
878
|
+
async checkWalletId(walletId) {
|
|
879
|
+
const diviner = await this.getDappsArchivistPayloadDiviner();
|
|
880
|
+
const query = {
|
|
881
|
+
limit: 1,
|
|
882
|
+
order: "desc",
|
|
883
|
+
schema: PayloadDivinerQuerySchema3,
|
|
884
|
+
schemas: [
|
|
885
|
+
DappWalletSeedPhraseSchema
|
|
886
|
+
],
|
|
887
|
+
walletId
|
|
888
|
+
};
|
|
889
|
+
const results = await diviner.divine([
|
|
890
|
+
query
|
|
891
|
+
]);
|
|
892
|
+
return results.length > 0 ? results[0] : void 0;
|
|
893
|
+
}
|
|
894
|
+
newPhrase() {
|
|
895
|
+
return HDWallet.generateMnemonic();
|
|
630
896
|
}
|
|
631
897
|
};
|
|
632
898
|
|
|
633
|
-
// src/event/connections/DappAccessRequest.ts
|
|
634
|
-
var DappAccessRequestEvent = "dappAccessRequest";
|
|
635
|
-
var dappAccessRequestConnectionRequest = {
|
|
636
|
-
publishableEvents: [
|
|
637
|
-
DappAccessRequestEvent
|
|
638
|
-
],
|
|
639
|
-
type: "PubSub"
|
|
640
|
-
};
|
|
641
|
-
var dappAccessRequestConnection = /* @__PURE__ */ __name(() => new EventBusPubSubConnection(dappAccessRequestConnectionRequest), "dappAccessRequestConnection");
|
|
642
|
-
|
|
643
|
-
// src/event/connections/ExposeDappRequest.ts
|
|
644
|
-
var ExposeDappRequestEvent = "exposeDappRequest";
|
|
645
|
-
var exposeDappConnectionRequest = {
|
|
646
|
-
publishableEvents: [
|
|
647
|
-
ExposeDappRequestEvent
|
|
648
|
-
],
|
|
649
|
-
type: "PubSub"
|
|
650
|
-
};
|
|
651
|
-
var exposeDappRequestConnection = /* @__PURE__ */ __name(() => new EventBusPubSubConnection(exposeDappConnectionRequest), "exposeDappRequestConnection");
|
|
652
|
-
|
|
653
|
-
// src/event/connections/OsPubSubNetworkReady.ts
|
|
654
|
-
var OsPubSubNetworkReadyEvent = "osPubSubNetworkReady";
|
|
655
|
-
var osPubSubNetworkConnectionRequest = {
|
|
656
|
-
publishableEvents: [
|
|
657
|
-
OsPubSubNetworkReadyEvent
|
|
658
|
-
],
|
|
659
|
-
type: "PubSub"
|
|
660
|
-
};
|
|
661
|
-
var osPubSubNetworkReadyConnection = /* @__PURE__ */ __name(() => new EventBusPubSubConnection(osPubSubNetworkConnectionRequest), "osPubSubNetworkReadyConnection");
|
|
662
|
-
|
|
663
|
-
// src/event/connections/OsSettingsReady.ts
|
|
664
|
-
var OsSettingsReadyEvent = "osSettingsReady";
|
|
665
|
-
var osSettingsConnectionRequest = {
|
|
666
|
-
publishableEvents: [
|
|
667
|
-
OsSettingsReadyEvent
|
|
668
|
-
],
|
|
669
|
-
type: "PubSub"
|
|
670
|
-
};
|
|
671
|
-
var osSettingsReadyConnection = /* @__PURE__ */ __name(() => new EventBusPubSubConnection(osSettingsConnectionRequest), "osSettingsReadyConnection");
|
|
672
|
-
|
|
673
|
-
// src/event/connections/OsXyoPublicReady.ts
|
|
674
|
-
var OsXyoPublicNetworkReadyEvent = "osXyoPublicNetworkReady";
|
|
675
|
-
var osXyoPublicNetworkConnectionRequest = {
|
|
676
|
-
publishableEvents: [
|
|
677
|
-
OsXyoPublicNetworkReadyEvent
|
|
678
|
-
],
|
|
679
|
-
type: "PubSub"
|
|
680
|
-
};
|
|
681
|
-
var osXyoPublicNetworkReadyConnection = /* @__PURE__ */ __name(() => new EventBusPubSubConnection(osXyoPublicNetworkConnectionRequest), "osXyoPublicNetworkReadyConnection");
|
|
682
|
-
|
|
683
899
|
// src/XyOsDapp.ts
|
|
684
900
|
import { assertEx as assertEx6 } from "@xylabs/assert";
|
|
685
|
-
import { ManifestWrapper } from "@xyo-network/manifest-wrapper";
|
|
686
|
-
import { ModuleFactoryLocator as
|
|
901
|
+
import { ManifestWrapper as ManifestWrapper2 } from "@xyo-network/manifest-wrapper";
|
|
902
|
+
import { ModuleFactoryLocator as ModuleFactoryLocator3 } from "@xyo-network/module-factory-locator";
|
|
687
903
|
import { DappPackageManifestPayloadSchema } from "@xyo-network/os-model";
|
|
688
904
|
|
|
689
905
|
// src/manifests/dapp-window.manifest.json
|
|
@@ -727,7 +943,7 @@ var dapp_window_manifest_default = {
|
|
|
727
943
|
// src/XyOsBase.ts
|
|
728
944
|
import { assertEx as assertEx5 } from "@xylabs/assert";
|
|
729
945
|
import { BaseEmitter as BaseEmitter2 } from "@xyo-network/module-event-emitter";
|
|
730
|
-
import { ModuleFactoryLocator } from "@xyo-network/module-factory-locator";
|
|
946
|
+
import { ModuleFactoryLocator as ModuleFactoryLocator2 } from "@xyo-network/module-factory-locator";
|
|
731
947
|
import { Mutex as Mutex2 } from "async-mutex";
|
|
732
948
|
var XyOsContextBase = class extends BaseEmitter2 {
|
|
733
949
|
static {
|
|
@@ -758,7 +974,7 @@ var XyOsContextBase = class extends BaseEmitter2 {
|
|
|
758
974
|
return assertEx5(this.params.manifest, () => "Missing manifest");
|
|
759
975
|
}
|
|
760
976
|
get platformLocator() {
|
|
761
|
-
this._platformLocator = this._platformLocator ?? this.params.platformLocator ?? new
|
|
977
|
+
this._platformLocator = this._platformLocator ?? this.params.platformLocator ?? new ModuleFactoryLocator2();
|
|
762
978
|
return this._platformLocator;
|
|
763
979
|
}
|
|
764
980
|
get possibleRoot() {
|
|
@@ -858,16 +1074,16 @@ var XyOsDapp = class extends XyOsContextBase {
|
|
|
858
1074
|
return await this._bootMutex.runExclusive(async () => {
|
|
859
1075
|
console.log("XyOsDapp:boot:start", wallet.address, this.dapp.id);
|
|
860
1076
|
assertEx6(this._root === void 0, () => "Dapp already booted");
|
|
861
|
-
const finalLocator = locator ? (this.params.locator ?? new
|
|
1077
|
+
const finalLocator = locator ? (this.params.locator ?? new ModuleFactoryLocator3()).merge(locator) : this.params.locator ?? new ModuleFactoryLocator3();
|
|
862
1078
|
console.log("XyOsDapp:boot:finalLocator", finalLocator);
|
|
863
|
-
const dappNodesWrapper = new
|
|
1079
|
+
const dappNodesWrapper = new ManifestWrapper2({
|
|
864
1080
|
...this.manifest,
|
|
865
1081
|
schema: DappPackageManifestPayloadSchema
|
|
866
1082
|
}, wallet, finalLocator);
|
|
867
1083
|
const dappNodes = await dappNodesWrapper.loadNodes();
|
|
868
1084
|
const dappManifestWallet = await wallet.derivePath("99999");
|
|
869
1085
|
dapp_window_manifest_default.nodes[0].config.name = this.dapp.name + "Root";
|
|
870
|
-
const wrapper = new
|
|
1086
|
+
const wrapper = new ManifestWrapper2({
|
|
871
1087
|
...dapp_window_manifest_default,
|
|
872
1088
|
schema: DappPackageManifestPayloadSchema
|
|
873
1089
|
}, dappManifestWallet, finalLocator);
|
|
@@ -886,210 +1102,29 @@ var XyOsDapp = class extends XyOsContextBase {
|
|
|
886
1102
|
}
|
|
887
1103
|
};
|
|
888
1104
|
|
|
889
|
-
// src/
|
|
890
|
-
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
|
|
891
|
-
import semver from "semver";
|
|
892
|
-
|
|
893
|
-
// src/classes/system/Queries.ts
|
|
894
|
-
import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema3 } from "@xyo-network/diviner-payload-model";
|
|
895
|
-
import { DappConfigSchema, DappIconSchema, DappWidgetConfigSchema, UnregisteredDappAccessSchema } from "@xyo-network/os-model";
|
|
896
|
-
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
897
|
-
var SystemDappQueries = {
|
|
898
|
-
async getDappAccess(diviner, name, version) {
|
|
899
|
-
const accessQuery = {
|
|
900
|
-
order: "desc",
|
|
901
|
-
registeringDappId: name,
|
|
902
|
-
schema: PayloadDivinerQuerySchema3,
|
|
903
|
-
schemas: [
|
|
904
|
-
UnregisteredDappAccessSchema
|
|
905
|
-
],
|
|
906
|
-
version
|
|
907
|
-
};
|
|
908
|
-
return await diviner.divine([
|
|
909
|
-
accessQuery
|
|
910
|
-
]);
|
|
911
|
-
},
|
|
912
|
-
async getLatestConfig(diviner, name) {
|
|
913
|
-
const configQuery = {
|
|
914
|
-
limit: 1,
|
|
915
|
-
name,
|
|
916
|
-
order: "desc",
|
|
917
|
-
schema: PayloadDivinerQuerySchema3,
|
|
918
|
-
schemas: [
|
|
919
|
-
DappConfigSchema
|
|
920
|
-
]
|
|
921
|
-
};
|
|
922
|
-
const [dappConfig] = await diviner.divine([
|
|
923
|
-
configQuery
|
|
924
|
-
]);
|
|
925
|
-
return dappConfig;
|
|
926
|
-
},
|
|
927
|
-
async getLatestIcon(diviner, name, version) {
|
|
928
|
-
const iconQuery = {
|
|
929
|
-
name,
|
|
930
|
-
order: "desc",
|
|
931
|
-
schema: PayloadDivinerQuerySchema3,
|
|
932
|
-
schemas: [
|
|
933
|
-
DappIconSchema
|
|
934
|
-
],
|
|
935
|
-
version
|
|
936
|
-
};
|
|
937
|
-
const [dappIcon] = await diviner.divine([
|
|
938
|
-
iconQuery
|
|
939
|
-
]);
|
|
940
|
-
return dappIcon;
|
|
941
|
-
},
|
|
942
|
-
async getWidgetConfigs(diviner, name, version) {
|
|
943
|
-
const widgetConfigQuery = {
|
|
944
|
-
dappId: name,
|
|
945
|
-
order: "desc",
|
|
946
|
-
schema: PayloadDivinerQuerySchema3,
|
|
947
|
-
schemas: [
|
|
948
|
-
DappWidgetConfigSchema
|
|
949
|
-
],
|
|
950
|
-
version
|
|
951
|
-
};
|
|
952
|
-
const widgetConfigs = await diviner.divine([
|
|
953
|
-
widgetConfigQuery
|
|
954
|
-
]);
|
|
955
|
-
const uniqueConfigs = {};
|
|
956
|
-
for (const widgetConfig of widgetConfigs) {
|
|
957
|
-
const hash = await PayloadBuilder2.dataHash(widgetConfig);
|
|
958
|
-
uniqueConfigs[widgetConfig.mode ?? hash] = widgetConfig;
|
|
959
|
-
}
|
|
960
|
-
return Object.values(uniqueConfigs);
|
|
961
|
-
}
|
|
962
|
-
};
|
|
963
|
-
|
|
964
|
-
// src/classes/system/ManageSystemDapps.ts
|
|
965
|
-
var ManageSystemDapps = class extends OsCallerBase {
|
|
966
|
-
static {
|
|
967
|
-
__name(this, "ManageSystemDapps");
|
|
968
|
-
}
|
|
969
|
-
defaultSystemNames;
|
|
970
|
-
defaultSystemDapps;
|
|
971
|
-
defaultSystemDappParams;
|
|
972
|
-
locator;
|
|
973
|
-
developmentMode;
|
|
974
|
-
onErrorCallbacks;
|
|
975
|
-
constructor(context, defaultSystemNames, defaultSystemDapps, defaultSystemDappParams, locator, developmentMode) {
|
|
976
|
-
super(context), this.defaultSystemNames = defaultSystemNames, this.defaultSystemDapps = defaultSystemDapps, this.defaultSystemDappParams = defaultSystemDappParams, this.locator = locator, this.developmentMode = developmentMode, this.onErrorCallbacks = [];
|
|
977
|
-
}
|
|
978
|
-
/**
|
|
979
|
-
* Add a callback to listen for errors throwing during system dapp registration
|
|
980
|
-
* @param {ErrorListener} errorListener
|
|
981
|
-
*/
|
|
982
|
-
addErrorListener(errorListener) {
|
|
983
|
-
this.onErrorCallbacks.push(errorListener);
|
|
984
|
-
}
|
|
985
|
-
/**
|
|
986
|
-
* Installs the dapps into the OS and builds the appropriate DappSet
|
|
987
|
-
*/
|
|
988
|
-
async install() {
|
|
989
|
-
await this.insertPayloads();
|
|
990
|
-
return await this.latestSets();
|
|
991
|
-
}
|
|
992
|
-
async freshInstall(archivist) {
|
|
993
|
-
await archivist.insert(this.defaultSystemDapps);
|
|
994
|
-
}
|
|
995
|
-
async insertPayloads() {
|
|
996
|
-
const archivist = this.developmentMode ? await this.getDappsArchivistDevelopment() : await this.getDappsArchivist();
|
|
997
|
-
try {
|
|
998
|
-
const allPayloads = await archivist.all();
|
|
999
|
-
if (allPayloads.length === 0) {
|
|
1000
|
-
await this.freshInstall(archivist);
|
|
1001
|
-
return true;
|
|
1002
|
-
}
|
|
1003
|
-
for (const systemDappPayload of this.defaultSystemDapps) {
|
|
1004
|
-
try {
|
|
1005
|
-
const validSemver = semver.valid(systemDappPayload.version);
|
|
1006
|
-
if (!validSemver) throw new Error("semver is a valid type (string) but was not able to be parsed");
|
|
1007
|
-
} catch (e) {
|
|
1008
|
-
console.error(`${systemDappPayload.version} does not appear to be a valid semver value`, e);
|
|
1009
|
-
continue;
|
|
1010
|
-
}
|
|
1011
|
-
const [existing] = await archivist.get([
|
|
1012
|
-
await PayloadBuilder3.dataHash(systemDappPayload)
|
|
1013
|
-
]);
|
|
1014
|
-
if (existing) continue;
|
|
1015
|
-
await archivist.insert([
|
|
1016
|
-
systemDappPayload
|
|
1017
|
-
]);
|
|
1018
|
-
}
|
|
1019
|
-
return true;
|
|
1020
|
-
} catch (e) {
|
|
1021
|
-
console.error("error installing system dapps");
|
|
1022
|
-
throw e;
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
async latestSets() {
|
|
1026
|
-
const diviner = this.developmentMode ? await this.getDappsArchivistPayloadDivinerDevelopment() : await this.getDappsArchivistPayloadDiviner();
|
|
1027
|
-
const dappSets = [];
|
|
1028
|
-
const failedPayloads = [];
|
|
1029
|
-
for (const name of this.defaultSystemNames) {
|
|
1030
|
-
try {
|
|
1031
|
-
const dappConfig = await SystemDappQueries.getLatestConfig(diviner, name);
|
|
1032
|
-
if (!dappConfig) {
|
|
1033
|
-
console.error(`No config found for dapp ${name}`);
|
|
1034
|
-
continue;
|
|
1035
|
-
}
|
|
1036
|
-
const dappIcon = await SystemDappQueries.getLatestIcon(diviner, name, dappConfig.version);
|
|
1037
|
-
if (!dappIcon) {
|
|
1038
|
-
console.error(`No icon found for dapp ${dappConfig.name}`);
|
|
1039
|
-
failedPayloads.push(dappConfig);
|
|
1040
|
-
continue;
|
|
1041
|
-
}
|
|
1042
|
-
const dappAccess = await SystemDappQueries.getDappAccess(diviner, name, dappConfig.version);
|
|
1043
|
-
const dappParams = this.defaultSystemDappParams[dappConfig.name];
|
|
1044
|
-
if (!dappParams) {
|
|
1045
|
-
console.error(`No params found for dapp ${dappConfig.name}. Did you forget to add it to OsDappParams?`);
|
|
1046
|
-
failedPayloads.push(dappConfig);
|
|
1047
|
-
continue;
|
|
1048
|
-
}
|
|
1049
|
-
const dappWidgetConfigs = await SystemDappQueries.getWidgetConfigs(diviner, name, dappConfig.version);
|
|
1050
|
-
dappSets.push({
|
|
1051
|
-
dapp: {
|
|
1052
|
-
accessors: dappAccess,
|
|
1053
|
-
config: dappConfig,
|
|
1054
|
-
icon: dappIcon,
|
|
1055
|
-
params: dappParams,
|
|
1056
|
-
widgetConfigs: dappWidgetConfigs
|
|
1057
|
-
}
|
|
1058
|
-
});
|
|
1059
|
-
} catch {
|
|
1060
|
-
console.error(`Failed to build dapp ${name}`);
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
if (failedPayloads.length > 0) {
|
|
1064
|
-
for (const cb of this.onErrorCallbacks) cb(failedPayloads);
|
|
1065
|
-
}
|
|
1066
|
-
return dappSets;
|
|
1067
|
-
}
|
|
1068
|
-
};
|
|
1069
|
-
|
|
1070
|
-
// src/classes/registration/DappRegistry.ts
|
|
1105
|
+
// src/registration/DappRegistry.ts
|
|
1071
1106
|
import { HDWallet as HDWallet3 } from "@xyo-network/account";
|
|
1072
1107
|
import { DappRegisteredSchema, DappRegisteredState, isRegisteredDappAccess } from "@xyo-network/os-model";
|
|
1073
1108
|
|
|
1074
|
-
// src/
|
|
1109
|
+
// src/registration/ValidateDappAccessDiviner/Config.ts
|
|
1075
1110
|
import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
|
|
1076
1111
|
var FailedAccessorSchema = "network.xyo.os.failed.accessor.registration";
|
|
1077
1112
|
var isFailedAccessor = isPayloadOfSchemaType(FailedAccessorSchema);
|
|
1078
1113
|
var ValidateDappAccessDivinerConfigSchema = "network.xyo.os.dapp.access.registration.validate";
|
|
1079
1114
|
|
|
1080
|
-
// src/
|
|
1115
|
+
// src/registration/ValidateDappAccessDiviner/Diviner.ts
|
|
1081
1116
|
import { HDWallet as HDWallet2 } from "@xyo-network/account";
|
|
1082
1117
|
import { AbstractDiviner } from "@xyo-network/diviner-abstract";
|
|
1083
|
-
import { ManifestWrapper as
|
|
1118
|
+
import { ManifestWrapper as ManifestWrapper3, PackageManifestPayloadSchema } from "@xyo-network/manifest";
|
|
1084
1119
|
import { isDappPackageManifestPayload, isUnregisteredDappAccess, RegisteredDappAccessSchema } from "@xyo-network/os-model";
|
|
1085
1120
|
|
|
1086
|
-
// src/access
|
|
1121
|
+
// src/models/access/ValidDappAccessInterfaces.ts
|
|
1087
1122
|
import { RegisteredNames, RegisteredNamesInterface } from "@xyo-network/os-model";
|
|
1088
1123
|
var ValidDappAccessInterfaces = {
|
|
1089
1124
|
[RegisteredNames]: RegisteredNamesInterface
|
|
1090
1125
|
};
|
|
1091
1126
|
|
|
1092
|
-
// src/
|
|
1127
|
+
// src/registration/ValidateDappAccessDiviner/Diviner.ts
|
|
1093
1128
|
var ValidateDappAccessDiviner = class extends AbstractDiviner {
|
|
1094
1129
|
static {
|
|
1095
1130
|
__name(this, "ValidateDappAccessDiviner");
|
|
@@ -1176,11 +1211,11 @@ var getNodeChildren = /* @__PURE__ */ __name(async (manifestToTest, dappParams)
|
|
|
1176
1211
|
return children;
|
|
1177
1212
|
}, "getNodeChildren");
|
|
1178
1213
|
var getNodeToTest = /* @__PURE__ */ __name(async (manifestToTest, dappParams) => {
|
|
1179
|
-
const dappManifestWrapper = new
|
|
1214
|
+
const dappManifestWrapper = new ManifestWrapper3(manifestToTest, await HDWallet2.random(), dappParams.locator);
|
|
1180
1215
|
return await dappManifestWrapper.loadNodes();
|
|
1181
1216
|
}, "getNodeToTest");
|
|
1182
1217
|
|
|
1183
|
-
// src/
|
|
1218
|
+
// src/registration/DappRegistry.ts
|
|
1184
1219
|
var DappRegistry = class {
|
|
1185
1220
|
static {
|
|
1186
1221
|
__name(this, "DappRegistry");
|
|
@@ -1276,7 +1311,7 @@ var DappRegistry = class {
|
|
|
1276
1311
|
}
|
|
1277
1312
|
};
|
|
1278
1313
|
|
|
1279
|
-
// src/
|
|
1314
|
+
// src/registration/DappRegistrationService.ts
|
|
1280
1315
|
var DappRegistrationService = class {
|
|
1281
1316
|
static {
|
|
1282
1317
|
__name(this, "DappRegistrationService");
|
|
@@ -1302,7 +1337,7 @@ var DappRegistrationService = class {
|
|
|
1302
1337
|
dappNames: [],
|
|
1303
1338
|
dappParams: {},
|
|
1304
1339
|
dappPayloads: []
|
|
1305
|
-
}, locator = new
|
|
1340
|
+
}, locator = new ModuleFactoryLocator4(), developmentMode) {
|
|
1306
1341
|
this.context = context;
|
|
1307
1342
|
this.params = params;
|
|
1308
1343
|
this.locator = locator;
|
|
@@ -1398,7 +1433,7 @@ var DappRegistrationService = class {
|
|
|
1398
1433
|
}
|
|
1399
1434
|
};
|
|
1400
1435
|
|
|
1401
|
-
// src/
|
|
1436
|
+
// src/signer/Signers.ts
|
|
1402
1437
|
import { assertEx as assertEx7 } from "@xylabs/assert";
|
|
1403
1438
|
import { HDWallet as HDWallet4 } from "@xyo-network/account";
|
|
1404
1439
|
var Signers = class {
|
|
@@ -1449,39 +1484,6 @@ var Signers = class {
|
|
|
1449
1484
|
}
|
|
1450
1485
|
};
|
|
1451
1486
|
|
|
1452
|
-
// src/loadOsNode.ts
|
|
1453
|
-
import { IndexedDbArchivist } from "@xyo-network/archivist-indexeddb";
|
|
1454
|
-
import { IndexedDbPayloadDiviner } from "@xyo-network/diviner-payload-indexeddb";
|
|
1455
|
-
import { ManifestWrapper as ManifestWrapper3 } from "@xyo-network/manifest-wrapper";
|
|
1456
|
-
import { ModuleFactoryLocator as ModuleFactoryLocator4 } from "@xyo-network/module-factory-locator";
|
|
1457
|
-
var OS_NODE_PATH = "1'";
|
|
1458
|
-
var getDefaultOsNodeLocator = /* @__PURE__ */ __name(() => {
|
|
1459
|
-
const locator = new ModuleFactoryLocator4();
|
|
1460
|
-
locator.register(IndexedDbArchivist, {
|
|
1461
|
-
"network.xyo.archivist.persistence.scope": "device"
|
|
1462
|
-
});
|
|
1463
|
-
locator.register(IndexedDbPayloadDiviner, {
|
|
1464
|
-
"network.xyo.archivist.persistence.scope": "device"
|
|
1465
|
-
});
|
|
1466
|
-
return locator;
|
|
1467
|
-
}, "getDefaultOsNodeLocator");
|
|
1468
|
-
var loadOsNode = /* @__PURE__ */ __name(async (osWallet, locator) => {
|
|
1469
|
-
try {
|
|
1470
|
-
const osNodeWallet = await osWallet.derivePath(OS_NODE_PATH);
|
|
1471
|
-
const osNodeLocator = locator ?? getDefaultOsNodeLocator();
|
|
1472
|
-
const manifestWrapper = new ManifestWrapper3(os_node_manifest_default, osNodeWallet, osNodeLocator);
|
|
1473
|
-
const osNode = (await manifestWrapper.loadNodes())[0];
|
|
1474
|
-
return [
|
|
1475
|
-
osNode
|
|
1476
|
-
];
|
|
1477
|
-
} catch (e) {
|
|
1478
|
-
const error = e;
|
|
1479
|
-
console.error(`Error creating os node: ${error.message}`);
|
|
1480
|
-
console.error(`Error creating os node: ${error.stack}`);
|
|
1481
|
-
throw new Error(`Error creating os node: ${error.message}`);
|
|
1482
|
-
}
|
|
1483
|
-
}, "loadOsNode");
|
|
1484
|
-
|
|
1485
1487
|
// src/stack/Base.ts
|
|
1486
1488
|
import { assertEx as assertEx8 } from "@xylabs/assert";
|
|
1487
1489
|
import { forget as forget3 } from "@xylabs/forget";
|