@xyo-network/os-runtime 3.0.15 → 3.0.17
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 +2 -2
- package/dist/neutral/Caller.d.ts.map +1 -1
- package/dist/neutral/classes/node/DefaultPayloads/DefaultPayloads.d.ts.map +1 -1
- package/dist/neutral/classes/signer/Signers.d.ts +1 -1
- package/dist/neutral/classes/signer/Signers.d.ts.map +1 -1
- package/dist/neutral/index.mjs +733 -795
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +8 -7
- package/src/Caller.ts +2 -17
- package/src/classes/node/DefaultPayloads/DefaultPayloads.ts +1 -2
- package/src/classes/signer/Signers.ts +4 -4
- package/dist/neutral/classes/node/DefaultPayloads/SigningKeyPayloads.d.ts +0 -13
- package/dist/neutral/classes/node/DefaultPayloads/SigningKeyPayloads.d.ts.map +0 -1
- package/src/classes/node/DefaultPayloads/SigningKeyPayloads.ts +0 -81
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/access-interfaces/registered-names/helpers/AccessNodeQueries.ts
|
|
2
|
-
import { assertEx as
|
|
2
|
+
import { assertEx as assertEx25 } from "@xylabs/assert";
|
|
3
3
|
import { asArchivistInstance as asArchivistInstance7 } from "@xyo-network/archivist-model";
|
|
4
4
|
|
|
5
5
|
// src/classes/cache/RunningAccessDappCache.ts
|
|
@@ -17,11 +17,11 @@ var RunningDappAccessCache = class {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
// src/classes/cache/RunningDappCache.ts
|
|
20
|
-
import { assertEx as
|
|
20
|
+
import { assertEx as assertEx24 } from "@xylabs/assert";
|
|
21
21
|
import { Mutex as Mutex3 } from "async-mutex";
|
|
22
22
|
|
|
23
23
|
// src/XyOs.ts
|
|
24
|
-
import { assertEx as
|
|
24
|
+
import { assertEx as assertEx23 } from "@xylabs/assert";
|
|
25
25
|
import { boot } from "@xyo-network/bios";
|
|
26
26
|
import { Kernel } from "@xyo-network/kernel";
|
|
27
27
|
import { ModuleFactoryLocator as ModuleFactoryLocator7 } from "@xyo-network/module-factory-locator";
|
|
@@ -530,8 +530,7 @@ import {
|
|
|
530
530
|
DappInjectableParamsSchema as DappInjectableParamsSchema2,
|
|
531
531
|
DappIntentTypes,
|
|
532
532
|
DappMode as DappMode2,
|
|
533
|
-
RegisteredDappAccessSchema as RegisteredDappAccessSchema2
|
|
534
|
-
SigningKeySchema
|
|
533
|
+
RegisteredDappAccessSchema as RegisteredDappAccessSchema2
|
|
535
534
|
} from "@xyo-network/os-model";
|
|
536
535
|
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
537
536
|
|
|
@@ -733,19 +732,8 @@ var DappCaller = class extends DappCallerBase {
|
|
|
733
732
|
/**
|
|
734
733
|
* Get all wallets for the user
|
|
735
734
|
*/
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
const query = {
|
|
739
|
-
order: "desc",
|
|
740
|
-
schema: PayloadDivinerQuerySchema4,
|
|
741
|
-
schemas: [SigningKeySchema]
|
|
742
|
-
};
|
|
743
|
-
const payloads = assertEx8(await diviner.divine([query]), () => "Unable to find user wallet");
|
|
744
|
-
if (payloads?.length) {
|
|
745
|
-
return payloads;
|
|
746
|
-
} else {
|
|
747
|
-
throw new Error("Unable to find user wallet");
|
|
748
|
-
}
|
|
735
|
+
getUserAccountsAll() {
|
|
736
|
+
return [...this.context.user.signers?.values() ?? []];
|
|
749
737
|
}
|
|
750
738
|
/**
|
|
751
739
|
* Make Dapp Access Request
|
|
@@ -990,7 +978,7 @@ var DappMenuResource = class extends DappCaller {
|
|
|
990
978
|
};
|
|
991
979
|
|
|
992
980
|
// src/classes/node/createDappContext.ts
|
|
993
|
-
import { HDWallet as
|
|
981
|
+
import { HDWallet as HDWallet2 } from "@xyo-network/account";
|
|
994
982
|
import { GenericPayloadDiviner } from "@xyo-network/diviner-payload-generic";
|
|
995
983
|
import { ModuleFactoryLocator as ModuleFactoryLocator2 } from "@xyo-network/module-factory-locator";
|
|
996
984
|
|
|
@@ -1073,8 +1061,8 @@ var DappSeedPhraseRepository = class extends OsCallerBase {
|
|
|
1073
1061
|
};
|
|
1074
1062
|
|
|
1075
1063
|
// src/classes/node/Creator.ts
|
|
1076
|
-
import { assertEx as
|
|
1077
|
-
import { asArchivistInstance as
|
|
1064
|
+
import { assertEx as assertEx10 } from "@xylabs/assert";
|
|
1065
|
+
import { asArchivistInstance as asArchivistInstance3 } from "@xyo-network/archivist-model";
|
|
1078
1066
|
import { PackageManifestPayloadSchema } from "@xyo-network/manifest";
|
|
1079
1067
|
|
|
1080
1068
|
// src/manifest/ManifestReplaceableTokens.ts
|
|
@@ -1223,7 +1211,7 @@ var os_node_manifest_default = {
|
|
|
1223
1211
|
};
|
|
1224
1212
|
|
|
1225
1213
|
// src/classes/node/DefaultPayloads/DefaultPayloads.ts
|
|
1226
|
-
import { PayloadBuilder as
|
|
1214
|
+
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
|
|
1227
1215
|
|
|
1228
1216
|
// src/classes/node/DefaultPayloads/DappAccessPayloads.ts
|
|
1229
1217
|
var DappAccessPayloads = class {
|
|
@@ -1259,615 +1247,257 @@ var NodeInfoPayload = class {
|
|
|
1259
1247
|
}
|
|
1260
1248
|
};
|
|
1261
1249
|
|
|
1262
|
-
// src/classes/node/DefaultPayloads/
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1250
|
+
// src/classes/node/DefaultPayloads/DefaultPayloads.ts
|
|
1251
|
+
var DefaultPayloads = class {
|
|
1252
|
+
constructor(dappArchivist, xyOs, dappName) {
|
|
1253
|
+
this.dappArchivist = dappArchivist;
|
|
1254
|
+
this.xyOs = xyOs;
|
|
1255
|
+
this.dappName = dappName;
|
|
1256
|
+
}
|
|
1257
|
+
async insert() {
|
|
1258
|
+
const insertables = [NodeInfoPayload, DappAccessPayloads];
|
|
1259
|
+
const insertPayloads = [];
|
|
1260
|
+
for (const insertable of insertables) {
|
|
1261
|
+
const classInstance = createInsertable(insertable, this.xyOs, this.dappName);
|
|
1262
|
+
const payloads = await classInstance.payloads();
|
|
1263
|
+
insertPayloads.push(...payloads);
|
|
1264
|
+
}
|
|
1265
|
+
for (const payload of insertPayloads) {
|
|
1266
|
+
const [existing] = await this.dappArchivist.get([await PayloadBuilder4.dataHash(payload)]);
|
|
1267
|
+
if (existing) continue;
|
|
1268
|
+
await this.dappArchivist.insert([payload]);
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
};
|
|
1271
1272
|
|
|
1272
|
-
// src/classes/
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
var OsSettingsArchivistModuleName = "OsSettingsNode:OsSettingsArchivist";
|
|
1277
|
-
var OsSettingsArchivistPayloadDivinerModuleName = "OsSettingsNode:OsSettingsArchivistPayloadDiviner";
|
|
1278
|
-
var OsSettingsCallerBase = class {
|
|
1279
|
-
constructor(context) {
|
|
1273
|
+
// src/classes/node/ExternalModulePermissions/ExternalModulePermissions.ts
|
|
1274
|
+
var ALLOWED_MODULES_FROM_PARENT = ["IntentArchivist", "OsSettingsNode", "OsPubSubNetworkStackNode", "OsXyoPublicNetworkStackNode"];
|
|
1275
|
+
var ExternalModulePermissions = class {
|
|
1276
|
+
constructor(context, dappWindowNode, dappName, externalPermissions) {
|
|
1280
1277
|
this.context = context;
|
|
1278
|
+
this.dappWindowNode = dappWindowNode;
|
|
1279
|
+
this.dappName = dappName;
|
|
1280
|
+
this.externalPermissions = externalPermissions;
|
|
1281
1281
|
}
|
|
1282
|
-
async
|
|
1283
|
-
const
|
|
1284
|
-
|
|
1282
|
+
async permit() {
|
|
1283
|
+
for (const permission of this.externalPermissions ?? []) {
|
|
1284
|
+
await this.permitExternalModule(permission);
|
|
1285
|
+
}
|
|
1285
1286
|
}
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
await this.context.root.resolve(OsSettingsArchivistPayloadDivinerModuleName),
|
|
1289
|
-
() => `${OsSettingsArchivistPayloadDivinerModuleName} not found`
|
|
1290
|
-
);
|
|
1291
|
-
return asDivinerInstance4(mod, () => `${OsSettingsArchivistPayloadDivinerModuleName} is not a diviner`);
|
|
1287
|
+
getExternalModuleName(permission) {
|
|
1288
|
+
return permission.name;
|
|
1292
1289
|
}
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
achievement,
|
|
1302
|
-
limit: 1,
|
|
1303
|
-
order: "desc",
|
|
1304
|
-
schema: PayloadDivinerQuerySchema8,
|
|
1305
|
-
schemas: [OsBadgeSchema]
|
|
1306
|
-
};
|
|
1307
|
-
return await diviner.divine([query]);
|
|
1290
|
+
async permitExternalModule(externalPermission) {
|
|
1291
|
+
const externalModuleName = this.getExternalModuleName(externalPermission);
|
|
1292
|
+
if (ALLOWED_MODULES_FROM_PARENT.includes(externalModuleName)) {
|
|
1293
|
+
const mod = await this.resolveExternalModule(externalModuleName);
|
|
1294
|
+
await this.registerAndAttachModule(mod);
|
|
1295
|
+
} else {
|
|
1296
|
+
console.warn(`${this.dappName} requested ${externalModuleName} but it was not fulfilled`);
|
|
1297
|
+
}
|
|
1308
1298
|
}
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
* @param {ValidOsAchievements} achievement
|
|
1315
|
-
*/
|
|
1316
|
-
async getBadge(achievement) {
|
|
1317
|
-
const diviner = await this.getOsSettingsPayloadDiviner();
|
|
1318
|
-
const results = await OsBadgeQueries.getBadge(achievement, diviner);
|
|
1319
|
-
return results[0] ?? null;
|
|
1299
|
+
async registerAndAttachModule(mod) {
|
|
1300
|
+
if (mod) {
|
|
1301
|
+
await this.dappWindowNode.register?.(mod);
|
|
1302
|
+
await this.dappWindowNode.attach(mod.address, true);
|
|
1303
|
+
}
|
|
1320
1304
|
}
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
*/
|
|
1324
|
-
async saveBadge(achievement) {
|
|
1325
|
-
const badge = {
|
|
1326
|
-
achievement,
|
|
1327
|
-
schema: OsBadgeSchema2,
|
|
1328
|
-
timestamp: Date.now()
|
|
1329
|
-
};
|
|
1330
|
-
const archivist = await this.getOsSettingsArchivist();
|
|
1331
|
-
return await archivist.insert([badge]);
|
|
1305
|
+
async resolveExternalModule(id) {
|
|
1306
|
+
return await this.context.root.resolve(id);
|
|
1332
1307
|
}
|
|
1333
1308
|
};
|
|
1334
1309
|
|
|
1335
|
-
// src/classes/
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
get savedSeedPhrase() {
|
|
1345
|
-
return assertEx11(this._savedSeedPhrase, () => "Saved seed phrase listener not set");
|
|
1346
|
-
}
|
|
1347
|
-
get subscriptions() {
|
|
1348
|
-
return { savedSeedPhrase: (cb) => this.savedSeedPhrase.subscribe(cb) };
|
|
1310
|
+
// src/classes/node/Creator.ts
|
|
1311
|
+
var DappContextCreator = class _DappContextCreator {
|
|
1312
|
+
constructor(targetDappManifestParams, dappId, context, rootWallet, externalPermissions, sharedLocator) {
|
|
1313
|
+
this.targetDappManifestParams = targetDappManifestParams;
|
|
1314
|
+
this.dappId = dappId;
|
|
1315
|
+
this.context = context;
|
|
1316
|
+
this.rootWallet = rootWallet;
|
|
1317
|
+
this.externalPermissions = externalPermissions;
|
|
1318
|
+
this.sharedLocator = sharedLocator;
|
|
1349
1319
|
}
|
|
1350
|
-
|
|
1351
|
-
|
|
1320
|
+
// Designated offset path for the wallet used by windowed dapps. In the future, other offsets could be used for other dapp modes
|
|
1321
|
+
static DAPP_WINDOW_WALLET_PATH = "1";
|
|
1322
|
+
static async create(params, xnsNodeUrl, xnsNetwork) {
|
|
1323
|
+
const {
|
|
1324
|
+
config,
|
|
1325
|
+
locator,
|
|
1326
|
+
context,
|
|
1327
|
+
wallet
|
|
1328
|
+
} = params;
|
|
1329
|
+
const {
|
|
1330
|
+
payload,
|
|
1331
|
+
dappName,
|
|
1332
|
+
publicChildren,
|
|
1333
|
+
privateChildren
|
|
1334
|
+
} = config;
|
|
1335
|
+
const { external, manifestPayload } = this.parseDappPackageManifestPayload(payload, xnsNodeUrl, xnsNetwork);
|
|
1336
|
+
console.debug("[DEBUG] dApp manifest", manifestPayload);
|
|
1337
|
+
const dappWallet = await wallet.derivePath(_DappContextCreator.DAPP_WINDOW_WALLET_PATH);
|
|
1338
|
+
const targetDappManifestParams = [manifestPayload, dappWallet, locator, publicChildren, privateChildren];
|
|
1339
|
+
const instance = new this(targetDappManifestParams, dappName, context, wallet, external?.modules, locator);
|
|
1340
|
+
return instance;
|
|
1352
1341
|
}
|
|
1353
|
-
|
|
1354
|
-
|
|
1342
|
+
// Add default payloads to the archivist shared between the os and the dapp
|
|
1343
|
+
static async primeDappArchivist(dappContext, osContext, dappName) {
|
|
1344
|
+
const dappCaller = new DappCallerBase(dappContext);
|
|
1345
|
+
const dappArchivist = await dappCaller.getDappArchivist();
|
|
1346
|
+
const defaultPayloads = new DefaultPayloads(dappArchivist, osContext, dappName);
|
|
1347
|
+
await defaultPayloads.insert();
|
|
1355
1348
|
}
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
const archivist = await this.getOsSettingsArchivist();
|
|
1362
|
-
this._savedSeedPhrase = await PayloadStore.create({
|
|
1363
|
-
archivist,
|
|
1364
|
-
getLatest: async () => await OsBadgeQueries.getBadge("savedSeedPhrase", diviner),
|
|
1365
|
-
idFunction: isBadgeWithMeta
|
|
1366
|
-
});
|
|
1349
|
+
// Reset the dapp archivist to remove all payloads
|
|
1350
|
+
static async resetDappArchivist(context) {
|
|
1351
|
+
const dappModule = await context.root.resolve("DappArchivist");
|
|
1352
|
+
const dappArchivist = assertEx10(asArchivistInstance3(dappModule), () => "resetDappArchivist: DappArchivist not found");
|
|
1353
|
+
await dappArchivist.clear();
|
|
1367
1354
|
}
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
|
|
1377
|
-
var language = "english";
|
|
1378
|
-
var standard = "bip-39";
|
|
1379
|
-
var userWalletLabel = "userWallet";
|
|
1380
|
-
var buildWalletSeedPhrasePayload = async (mnemonic, label) => {
|
|
1381
|
-
const fields = {
|
|
1382
|
-
mnemonic: {
|
|
1383
|
-
language,
|
|
1384
|
-
mnemonic: mnemonic.split(" "),
|
|
1385
|
-
standard
|
|
1386
|
-
}
|
|
1387
|
-
};
|
|
1388
|
-
const meta = { label, timestamp: Date.now() };
|
|
1389
|
-
const builder = new PayloadBuilder4({
|
|
1390
|
-
fields,
|
|
1391
|
-
meta,
|
|
1392
|
-
schema: WalletSeedPhraseSchema
|
|
1393
|
-
});
|
|
1394
|
-
const payload = await builder.build();
|
|
1395
|
-
const rootHash = await PayloadBuilder4.hash(payload);
|
|
1396
|
-
return { payload, rootHash };
|
|
1397
|
-
};
|
|
1398
|
-
var buildUserWalletSeedPhrasePayload = (mnemonic) => {
|
|
1399
|
-
return buildWalletSeedPhrasePayload(mnemonic, userWalletLabel);
|
|
1400
|
-
};
|
|
1401
|
-
|
|
1402
|
-
// src/utils/getApiDomain.ts
|
|
1403
|
-
var getApiDomain = (scope, apiDomain) => {
|
|
1404
|
-
if (apiDomain !== void 0) {
|
|
1405
|
-
return apiDomain;
|
|
1355
|
+
static parseDappPackageManifestPayload(payload, xnsNodeUrl, xnsNetwork) {
|
|
1356
|
+
const { external, ...manifestWithoutExternals } = payload;
|
|
1357
|
+
const manifestPayloadRaw = {
|
|
1358
|
+
...manifestWithoutExternals,
|
|
1359
|
+
schema: PackageManifestPayloadSchema
|
|
1360
|
+
};
|
|
1361
|
+
const manifestPayload = ReplaceManifestTokens(manifestPayloadRaw, xnsNodeUrl, xnsNetwork);
|
|
1362
|
+
return { external, manifestPayload };
|
|
1406
1363
|
}
|
|
1407
|
-
|
|
1408
|
-
|
|
1364
|
+
async loadDappContext(context) {
|
|
1365
|
+
console.log("DappNodesCreator:loadDappContext", this.dappId);
|
|
1366
|
+
const dapp = await context.dappByName(this.dappId) ?? await (async () => {
|
|
1367
|
+
const dapp2 = await context.buildDapp(this.targetDappManifestParams[0], this.dappId);
|
|
1368
|
+
await dapp2.boot(this.rootWallet, this.sharedLocator);
|
|
1369
|
+
return dapp2;
|
|
1370
|
+
})();
|
|
1371
|
+
await this.handleExternalModulePermissions(dapp.root);
|
|
1372
|
+
await _DappContextCreator.primeDappArchivist(dapp, this.context, this.dappId);
|
|
1373
|
+
return dapp;
|
|
1409
1374
|
}
|
|
1410
|
-
|
|
1411
|
-
|
|
1375
|
+
// try to satisfy the external permissions requested by a dapp
|
|
1376
|
+
async handleExternalModulePermissions(dappWindowNode) {
|
|
1377
|
+
const externalModulePermissions = new ExternalModulePermissions(this.context, dappWindowNode, this.dappId, this.externalPermissions);
|
|
1378
|
+
await externalModulePermissions.permit();
|
|
1412
1379
|
}
|
|
1413
|
-
return "https://archivist.xyo.network";
|
|
1414
1380
|
};
|
|
1415
1381
|
|
|
1416
|
-
// src/
|
|
1417
|
-
var
|
|
1418
|
-
|
|
1419
|
-
const
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
acc[newKey] = oldObj[oldKey];
|
|
1423
|
-
} else {
|
|
1424
|
-
acc[val] = oldObj[val];
|
|
1425
|
-
}
|
|
1426
|
-
return acc;
|
|
1427
|
-
},
|
|
1428
|
-
{}
|
|
1429
|
-
);
|
|
1430
|
-
return newObj;
|
|
1382
|
+
// src/classes/node/createDappContext.ts
|
|
1383
|
+
var GenericPayloadDivinerTags = { "network.xyo.generic.payload.diviner": "GenericPayloadDiviner" };
|
|
1384
|
+
var resolveLocator = (existingLocator) => {
|
|
1385
|
+
const locator = existingLocator ?? new ModuleFactoryLocator2();
|
|
1386
|
+
locator.register(GenericPayloadDiviner, GenericPayloadDivinerTags);
|
|
1387
|
+
return locator;
|
|
1431
1388
|
};
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
async getNodeBackground(diviner) {
|
|
1450
|
-
const query = {
|
|
1451
|
-
limit: 1,
|
|
1452
|
-
order: "desc",
|
|
1453
|
-
schema: PayloadDivinerQuerySchema9,
|
|
1454
|
-
schemas: [NodeBackgroundSchema]
|
|
1389
|
+
var createDappContext = async (dapp, context, allowedNames, xnsNodeUrl, xnsNetwork) => {
|
|
1390
|
+
console.log("createNodes");
|
|
1391
|
+
try {
|
|
1392
|
+
const dappSeedPhraseRepository = new DappSeedPhraseRepository(context, allowedNames);
|
|
1393
|
+
const seedPhrase = await dappSeedPhraseRepository.request(dapp.config.walletId);
|
|
1394
|
+
if (!seedPhrase) {
|
|
1395
|
+
throw new Error(`unable to find seed phrase for walletId: ${JSON.stringify(dapp.config, null, 2)}`);
|
|
1396
|
+
}
|
|
1397
|
+
const wallet = await HDWallet2.fromPhrase(seedPhrase);
|
|
1398
|
+
const dappName = dapp.config.name;
|
|
1399
|
+
const { config: dappConfig, params: dappParams } = dapp;
|
|
1400
|
+
const locator = resolveLocator((dappParams.locator ?? new ModuleFactoryLocator2()).merge(context.platformLocator));
|
|
1401
|
+
const params = {
|
|
1402
|
+
config: { dappName, payload: dappConfig.manifest },
|
|
1403
|
+
context,
|
|
1404
|
+
locator,
|
|
1405
|
+
wallet
|
|
1455
1406
|
};
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
schema: PayloadDivinerQuerySchema9,
|
|
1462
|
-
schemas: [WalletSeedPhraseSchema2]
|
|
1407
|
+
const dappContextCreator = await DappContextCreator.create(params, xnsNodeUrl, xnsNetwork);
|
|
1408
|
+
const dappContext = await dappContextCreator.loadDappContext(context);
|
|
1409
|
+
return {
|
|
1410
|
+
context: dappContext,
|
|
1411
|
+
dappWallet: wallet
|
|
1463
1412
|
};
|
|
1464
|
-
|
|
1413
|
+
} catch (e) {
|
|
1414
|
+
const error = e;
|
|
1415
|
+
console.error(`Error creating dappWindow node: ${error.message}`);
|
|
1416
|
+
console.error(`Error creating dappWindow node: ${error.stack}`);
|
|
1417
|
+
throw new Error(`Error creating dappWindow node: ${error.message}`);
|
|
1465
1418
|
}
|
|
1466
1419
|
};
|
|
1467
1420
|
|
|
1468
|
-
// src/classes/
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
const archivist = await this.getOsSettingsArchivist();
|
|
1479
|
-
await archivist.insert([payload]);
|
|
1480
|
-
}
|
|
1481
|
-
/**
|
|
1482
|
-
* Add a wallet seed phrase to the settings
|
|
1483
|
-
* @param {WalletSeedPhrase} payload
|
|
1484
|
-
*/
|
|
1485
|
-
async addWalletSeedPhrase(payload) {
|
|
1486
|
-
const archivist = await this.getOsSettingsArchivist();
|
|
1487
|
-
await archivist.insert([payload]);
|
|
1488
|
-
const phrase = payload.mnemonic.mnemonic.join(" ");
|
|
1489
|
-
await this.context.kernel?.bios?.seedPhraseStore.set("user", phrase);
|
|
1490
|
-
}
|
|
1491
|
-
/**
|
|
1492
|
-
* Get the latest node background
|
|
1493
|
-
*/
|
|
1494
|
-
async getLatestNodeBackground() {
|
|
1495
|
-
const diviner = await this.getOsSettingsPayloadDiviner();
|
|
1496
|
-
const [result] = await OsSettingsQueries.getNodeBackground(diviner);
|
|
1497
|
-
return result ?? null;
|
|
1498
|
-
}
|
|
1499
|
-
async getLatestUserWallet() {
|
|
1500
|
-
const diviner = await this.getOsSettingsPayloadDiviner();
|
|
1501
|
-
const storedSeedPhrasePayload = (await OsSettingsQueries.getLatestUserWallet(diviner)).pop();
|
|
1502
|
-
const biosWalletSeedPhrase = assertEx12(await this.context.kernel?.bios?.seedPhraseStore.get("user"), () => "No user seed phrase found from BIOS");
|
|
1503
|
-
const biosWalletSeedPhraseParts = biosWalletSeedPhrase.split(" ");
|
|
1504
|
-
if (!storedSeedPhrasePayload?.mnemonic?.mnemonic) {
|
|
1505
|
-
const { payload: biosSeedPhrasePayload } = await buildUserWalletSeedPhrasePayload(biosWalletSeedPhrase);
|
|
1506
|
-
await this.addWalletSeedPhrase(biosSeedPhrasePayload);
|
|
1507
|
-
return biosSeedPhrasePayload;
|
|
1508
|
-
} else if (!isEqual(storedSeedPhrasePayload.mnemonic.mnemonic, biosWalletSeedPhraseParts)) {
|
|
1509
|
-
const updatedBiosSeedPhrase = storedSeedPhrasePayload.mnemonic.mnemonic.join(" ");
|
|
1510
|
-
await this.context.kernel?.bios?.seedPhraseStore.set("user", updatedBiosSeedPhrase);
|
|
1511
|
-
}
|
|
1512
|
-
return storedSeedPhrasePayload;
|
|
1513
|
-
}
|
|
1514
|
-
};
|
|
1421
|
+
// src/classes/registration/DappRegistrationService.ts
|
|
1422
|
+
import { forget as forget2 } from "@xylabs/forget";
|
|
1423
|
+
import { fulfilled, rejected } from "@xylabs/promise";
|
|
1424
|
+
import { ModuleFactoryLocator as ModuleFactoryLocator5 } from "@xyo-network/module-factory-locator";
|
|
1425
|
+
import {
|
|
1426
|
+
DappIntentTypes as DappIntentTypes2,
|
|
1427
|
+
DappMode as DappMode3,
|
|
1428
|
+
isRegisteredDappAccessDappSet as isRegisteredDappAccessDappSet2,
|
|
1429
|
+
isRegisteredDappExposedDappSet
|
|
1430
|
+
} from "@xyo-network/os-model";
|
|
1515
1431
|
|
|
1516
|
-
// src/
|
|
1517
|
-
import { assertEx as
|
|
1518
|
-
import {
|
|
1519
|
-
var
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
constructor(
|
|
1524
|
-
super(
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
return assertEx13(this._latestUserWalletListener, () => "Latest user wallet listener not set");
|
|
1528
|
-
}
|
|
1529
|
-
get nodeBackgroundListener() {
|
|
1530
|
-
return assertEx13(this._nodeBackgroundListener, () => "Node background listener not set");
|
|
1531
|
-
}
|
|
1532
|
-
get subscriptions() {
|
|
1533
|
-
return {
|
|
1534
|
-
latestUserWallet: (cb) => this.walletsListener.subscribe(cb),
|
|
1535
|
-
nodeBackground: (cb) => this.nodeBackgroundListener.subscribe(cb),
|
|
1536
|
-
wallets: (cb) => this.walletsListener.subscribe(cb)
|
|
1537
|
-
};
|
|
1538
|
-
}
|
|
1539
|
-
get views() {
|
|
1540
|
-
return {
|
|
1541
|
-
latestUserWallet: () => this.latestUserWalletListener.latest,
|
|
1542
|
-
nodeBackground: () => this.nodeBackgroundListener.latest,
|
|
1543
|
-
wallets: () => this.walletsListener.latest
|
|
1544
|
-
};
|
|
1545
|
-
}
|
|
1546
|
-
get walletsListener() {
|
|
1547
|
-
return assertEx13(this._walletsListener, () => "Wallets listener not set");
|
|
1432
|
+
// src/event/bus/Connection.ts
|
|
1433
|
+
import { assertEx as assertEx11 } from "@xylabs/assert";
|
|
1434
|
+
import { BaseEmitter } from "@xyo-network/module-abstract";
|
|
1435
|
+
var EventBusConnection = class extends BaseEmitter {
|
|
1436
|
+
_id;
|
|
1437
|
+
description;
|
|
1438
|
+
type;
|
|
1439
|
+
constructor(request) {
|
|
1440
|
+
super({});
|
|
1441
|
+
this.description = request.description;
|
|
1442
|
+
this.type = request.type;
|
|
1548
1443
|
}
|
|
1549
|
-
|
|
1550
|
-
this.
|
|
1551
|
-
this.latestUserWalletListener.cleanupListeners();
|
|
1444
|
+
get id() {
|
|
1445
|
+
return assertEx11(this._id, () => "Connection ID not set. Did you forget to call buildConnection()?");
|
|
1552
1446
|
}
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
*/
|
|
1556
|
-
async start() {
|
|
1557
|
-
const archivist = await this.getOsSettingsArchivist();
|
|
1558
|
-
const diviner = await this.getOsSettingsPayloadDiviner();
|
|
1559
|
-
this._walletsListener = await PayloadStore.create({
|
|
1560
|
-
archivist,
|
|
1561
|
-
getLatest: async () => await OsSettingsQueries.getWallets(diviner),
|
|
1562
|
-
idFunction: isWalletSeedPhrase
|
|
1563
|
-
});
|
|
1564
|
-
this._latestUserWalletListener = await PayloadStore.create({
|
|
1565
|
-
archivist,
|
|
1566
|
-
getLatest: async () => await OsSettingsQueries.getLatestUserWallet(diviner),
|
|
1567
|
-
idFunction: isWalletSeedPhrase
|
|
1568
|
-
});
|
|
1569
|
-
this._nodeBackgroundListener = await PayloadStore.create({
|
|
1570
|
-
archivist,
|
|
1571
|
-
getLatest: async () => await OsSettingsQueries.getNodeBackground(diviner),
|
|
1572
|
-
idFunction: isNodeBackground
|
|
1573
|
-
});
|
|
1447
|
+
buildConnection(id) {
|
|
1448
|
+
this._id = id;
|
|
1574
1449
|
}
|
|
1575
1450
|
};
|
|
1576
1451
|
|
|
1577
|
-
// src/
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1452
|
+
// src/event/bus/EventBus.ts
|
|
1453
|
+
import { assertEx as assertEx12 } from "@xylabs/assert";
|
|
1454
|
+
import { forget } from "@xylabs/forget";
|
|
1455
|
+
import {
|
|
1456
|
+
asArchivistInstance as asArchivistInstance4,
|
|
1457
|
+
MemoryArchivist,
|
|
1458
|
+
MemoryArchivistConfigSchema
|
|
1459
|
+
} from "@xyo-network/archivist";
|
|
1460
|
+
import {
|
|
1461
|
+
isEventBusEvent,
|
|
1462
|
+
isPubSubConnections
|
|
1463
|
+
} from "@xyo-network/os-model";
|
|
1464
|
+
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
|
|
1465
|
+
import { Mutex } from "async-mutex";
|
|
1466
|
+
import { v4 as uuid2 } from "uuid";
|
|
1467
|
+
var EventBus = class {
|
|
1468
|
+
// Internal Archivist to store event data
|
|
1469
|
+
_archivist;
|
|
1470
|
+
// Store all connections
|
|
1471
|
+
connections = {};
|
|
1472
|
+
// Store all publisher callbacks for later removal
|
|
1473
|
+
publisherCallbacks = {};
|
|
1474
|
+
startMutex = new Mutex();
|
|
1475
|
+
get archivist() {
|
|
1476
|
+
return asArchivistInstance4(
|
|
1477
|
+
assertEx12(this._archivist, () => "Archivist not found. Did you forget to call start()?"),
|
|
1478
|
+
"not a valid archivist instance"
|
|
1479
|
+
);
|
|
1586
1480
|
}
|
|
1587
|
-
|
|
1588
|
-
const
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
additionalDappAccountSigningKeyPayloads.push(signingKeyPayload);
|
|
1596
|
-
}
|
|
1481
|
+
addConnection(connection) {
|
|
1482
|
+
const id = uuid2();
|
|
1483
|
+
this.connections[id] = connection;
|
|
1484
|
+
connection.buildConnection(id);
|
|
1485
|
+
if (isPubSubConnections(connection)) {
|
|
1486
|
+
this.handlePublisherAdd(connection);
|
|
1487
|
+
} else {
|
|
1488
|
+
throw new Error("Unsupported connection type. Must be PubSub");
|
|
1597
1489
|
}
|
|
1598
|
-
return
|
|
1599
|
-
}
|
|
1600
|
-
async resolveUserWallet() {
|
|
1601
|
-
const settingsCaller = new OsSettingsCaller(this.context);
|
|
1602
|
-
const latestWallet = await settingsCaller.getLatestUserWallet();
|
|
1603
|
-
const phrase = mnemonicArrayToString(latestWallet.mnemonic.mnemonic);
|
|
1604
|
-
const assertedPhrase = assertEx14(phrase, () => "No phrase found in latest wallet");
|
|
1605
|
-
return await HDWallet2.fromPhrase(assertedPhrase);
|
|
1490
|
+
return connection;
|
|
1606
1491
|
}
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
schema: SigningKeySchema2
|
|
1615
|
-
};
|
|
1492
|
+
removeConnection(connectionId) {
|
|
1493
|
+
const connection = this.connections[connectionId];
|
|
1494
|
+
if (!connection) {
|
|
1495
|
+
throw new Error("Connection not found " + connectionId);
|
|
1496
|
+
}
|
|
1497
|
+
if (connection && isPubSubConnections(connection)) {
|
|
1498
|
+
this.handlePublisherRemove(connection);
|
|
1616
1499
|
}
|
|
1617
|
-
|
|
1618
|
-
};
|
|
1619
|
-
|
|
1620
|
-
// src/classes/node/DefaultPayloads/DefaultPayloads.ts
|
|
1621
|
-
var DefaultPayloads = class {
|
|
1622
|
-
constructor(dappArchivist, xyOs, dappName) {
|
|
1623
|
-
this.dappArchivist = dappArchivist;
|
|
1624
|
-
this.xyOs = xyOs;
|
|
1625
|
-
this.dappName = dappName;
|
|
1626
|
-
}
|
|
1627
|
-
async insert() {
|
|
1628
|
-
const insertables = [NodeInfoPayload, SigningKeyPayloads, DappAccessPayloads];
|
|
1629
|
-
const insertPayloads = [];
|
|
1630
|
-
for (const insertable of insertables) {
|
|
1631
|
-
const classInstance = createInsertable(insertable, this.xyOs, this.dappName);
|
|
1632
|
-
const payloads = await classInstance.payloads();
|
|
1633
|
-
insertPayloads.push(...payloads);
|
|
1634
|
-
}
|
|
1635
|
-
for (const payload of insertPayloads) {
|
|
1636
|
-
const [existing] = await this.dappArchivist.get([await PayloadBuilder5.dataHash(payload)]);
|
|
1637
|
-
if (existing) continue;
|
|
1638
|
-
await this.dappArchivist.insert([payload]);
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
};
|
|
1642
|
-
|
|
1643
|
-
// src/classes/node/ExternalModulePermissions/ExternalModulePermissions.ts
|
|
1644
|
-
var ALLOWED_MODULES_FROM_PARENT = ["IntentArchivist", "OsSettingsNode", "OsPubSubNetworkStackNode", "OsXyoPublicNetworkStackNode"];
|
|
1645
|
-
var ExternalModulePermissions = class {
|
|
1646
|
-
constructor(context, dappWindowNode, dappName, externalPermissions) {
|
|
1647
|
-
this.context = context;
|
|
1648
|
-
this.dappWindowNode = dappWindowNode;
|
|
1649
|
-
this.dappName = dappName;
|
|
1650
|
-
this.externalPermissions = externalPermissions;
|
|
1651
|
-
}
|
|
1652
|
-
async permit() {
|
|
1653
|
-
for (const permission of this.externalPermissions ?? []) {
|
|
1654
|
-
await this.permitExternalModule(permission);
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
getExternalModuleName(permission) {
|
|
1658
|
-
return permission.name;
|
|
1659
|
-
}
|
|
1660
|
-
async permitExternalModule(externalPermission) {
|
|
1661
|
-
const externalModuleName = this.getExternalModuleName(externalPermission);
|
|
1662
|
-
if (ALLOWED_MODULES_FROM_PARENT.includes(externalModuleName)) {
|
|
1663
|
-
const mod = await this.resolveExternalModule(externalModuleName);
|
|
1664
|
-
await this.registerAndAttachModule(mod);
|
|
1665
|
-
} else {
|
|
1666
|
-
console.warn(`${this.dappName} requested ${externalModuleName} but it was not fulfilled`);
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1669
|
-
async registerAndAttachModule(mod) {
|
|
1670
|
-
if (mod) {
|
|
1671
|
-
await this.dappWindowNode.register?.(mod);
|
|
1672
|
-
await this.dappWindowNode.attach(mod.address, true);
|
|
1673
|
-
}
|
|
1674
|
-
}
|
|
1675
|
-
async resolveExternalModule(id) {
|
|
1676
|
-
return await this.context.root.resolve(id);
|
|
1677
|
-
}
|
|
1678
|
-
};
|
|
1679
|
-
|
|
1680
|
-
// src/classes/node/Creator.ts
|
|
1681
|
-
var DappContextCreator = class _DappContextCreator {
|
|
1682
|
-
constructor(targetDappManifestParams, dappId, context, rootWallet, externalPermissions, sharedLocator) {
|
|
1683
|
-
this.targetDappManifestParams = targetDappManifestParams;
|
|
1684
|
-
this.dappId = dappId;
|
|
1685
|
-
this.context = context;
|
|
1686
|
-
this.rootWallet = rootWallet;
|
|
1687
|
-
this.externalPermissions = externalPermissions;
|
|
1688
|
-
this.sharedLocator = sharedLocator;
|
|
1689
|
-
}
|
|
1690
|
-
// Designated offset path for the wallet used by windowed dapps. In the future, other offsets could be used for other dapp modes
|
|
1691
|
-
static DAPP_WINDOW_WALLET_PATH = "1";
|
|
1692
|
-
static async create(params, xnsNodeUrl, xnsNetwork) {
|
|
1693
|
-
const {
|
|
1694
|
-
config,
|
|
1695
|
-
locator,
|
|
1696
|
-
context,
|
|
1697
|
-
wallet
|
|
1698
|
-
} = params;
|
|
1699
|
-
const {
|
|
1700
|
-
payload,
|
|
1701
|
-
dappName,
|
|
1702
|
-
publicChildren,
|
|
1703
|
-
privateChildren
|
|
1704
|
-
} = config;
|
|
1705
|
-
const { external, manifestPayload } = this.parseDappPackageManifestPayload(payload, xnsNodeUrl, xnsNetwork);
|
|
1706
|
-
console.debug("[DEBUG] dApp manifest", manifestPayload);
|
|
1707
|
-
const dappWallet = await wallet.derivePath(_DappContextCreator.DAPP_WINDOW_WALLET_PATH);
|
|
1708
|
-
const targetDappManifestParams = [manifestPayload, dappWallet, locator, publicChildren, privateChildren];
|
|
1709
|
-
const instance = new this(targetDappManifestParams, dappName, context, wallet, external?.modules, locator);
|
|
1710
|
-
return instance;
|
|
1711
|
-
}
|
|
1712
|
-
// Add default payloads to the archivist shared between the os and the dapp
|
|
1713
|
-
static async primeDappArchivist(dappContext, osContext, dappName) {
|
|
1714
|
-
const dappCaller = new DappCallerBase(dappContext);
|
|
1715
|
-
const dappArchivist = await dappCaller.getDappArchivist();
|
|
1716
|
-
const defaultPayloads = new DefaultPayloads(dappArchivist, osContext, dappName);
|
|
1717
|
-
await defaultPayloads.insert();
|
|
1718
|
-
}
|
|
1719
|
-
// Reset the dapp archivist to remove all payloads
|
|
1720
|
-
static async resetDappArchivist(context) {
|
|
1721
|
-
const dappModule = await context.root.resolve("DappArchivist");
|
|
1722
|
-
const dappArchivist = assertEx15(asArchivistInstance4(dappModule), () => "resetDappArchivist: DappArchivist not found");
|
|
1723
|
-
await dappArchivist.clear();
|
|
1724
|
-
}
|
|
1725
|
-
static parseDappPackageManifestPayload(payload, xnsNodeUrl, xnsNetwork) {
|
|
1726
|
-
const { external, ...manifestWithoutExternals } = payload;
|
|
1727
|
-
const manifestPayloadRaw = {
|
|
1728
|
-
...manifestWithoutExternals,
|
|
1729
|
-
schema: PackageManifestPayloadSchema
|
|
1730
|
-
};
|
|
1731
|
-
const manifestPayload = ReplaceManifestTokens(manifestPayloadRaw, xnsNodeUrl, xnsNetwork);
|
|
1732
|
-
return { external, manifestPayload };
|
|
1733
|
-
}
|
|
1734
|
-
async loadDappContext(context) {
|
|
1735
|
-
console.log("DappNodesCreator:loadDappContext", this.dappId);
|
|
1736
|
-
const dapp = await context.dappByName(this.dappId) ?? await (async () => {
|
|
1737
|
-
const dapp2 = await context.buildDapp(this.targetDappManifestParams[0], this.dappId);
|
|
1738
|
-
await dapp2.boot(this.rootWallet, this.sharedLocator);
|
|
1739
|
-
return dapp2;
|
|
1740
|
-
})();
|
|
1741
|
-
await this.handleExternalModulePermissions(dapp.root);
|
|
1742
|
-
await _DappContextCreator.primeDappArchivist(dapp, this.context, this.dappId);
|
|
1743
|
-
return dapp;
|
|
1744
|
-
}
|
|
1745
|
-
// try to satisfy the external permissions requested by a dapp
|
|
1746
|
-
async handleExternalModulePermissions(dappWindowNode) {
|
|
1747
|
-
const externalModulePermissions = new ExternalModulePermissions(this.context, dappWindowNode, this.dappId, this.externalPermissions);
|
|
1748
|
-
await externalModulePermissions.permit();
|
|
1749
|
-
}
|
|
1750
|
-
};
|
|
1751
|
-
|
|
1752
|
-
// src/classes/node/createDappContext.ts
|
|
1753
|
-
var GenericPayloadDivinerTags = { "network.xyo.generic.payload.diviner": "GenericPayloadDiviner" };
|
|
1754
|
-
var resolveLocator = (existingLocator) => {
|
|
1755
|
-
const locator = existingLocator ?? new ModuleFactoryLocator2();
|
|
1756
|
-
locator.register(GenericPayloadDiviner, GenericPayloadDivinerTags);
|
|
1757
|
-
return locator;
|
|
1758
|
-
};
|
|
1759
|
-
var createDappContext = async (dapp, context, allowedNames, xnsNodeUrl, xnsNetwork) => {
|
|
1760
|
-
console.log("createNodes");
|
|
1761
|
-
try {
|
|
1762
|
-
const dappSeedPhraseRepository = new DappSeedPhraseRepository(context, allowedNames);
|
|
1763
|
-
const seedPhrase = await dappSeedPhraseRepository.request(dapp.config.walletId);
|
|
1764
|
-
if (!seedPhrase) {
|
|
1765
|
-
throw new Error(`unable to find seed phrase for walletId: ${JSON.stringify(dapp.config, null, 2)}`);
|
|
1766
|
-
}
|
|
1767
|
-
const wallet = await HDWallet3.fromPhrase(seedPhrase);
|
|
1768
|
-
const dappName = dapp.config.name;
|
|
1769
|
-
const { config: dappConfig, params: dappParams } = dapp;
|
|
1770
|
-
const locator = resolveLocator((dappParams.locator ?? new ModuleFactoryLocator2()).merge(context.platformLocator));
|
|
1771
|
-
const params = {
|
|
1772
|
-
config: { dappName, payload: dappConfig.manifest },
|
|
1773
|
-
context,
|
|
1774
|
-
locator,
|
|
1775
|
-
wallet
|
|
1776
|
-
};
|
|
1777
|
-
const dappContextCreator = await DappContextCreator.create(params, xnsNodeUrl, xnsNetwork);
|
|
1778
|
-
const dappContext = await dappContextCreator.loadDappContext(context);
|
|
1779
|
-
return {
|
|
1780
|
-
context: dappContext,
|
|
1781
|
-
dappWallet: wallet
|
|
1782
|
-
};
|
|
1783
|
-
} catch (e) {
|
|
1784
|
-
const error = e;
|
|
1785
|
-
console.error(`Error creating dappWindow node: ${error.message}`);
|
|
1786
|
-
console.error(`Error creating dappWindow node: ${error.stack}`);
|
|
1787
|
-
throw new Error(`Error creating dappWindow node: ${error.message}`);
|
|
1788
|
-
}
|
|
1789
|
-
};
|
|
1790
|
-
|
|
1791
|
-
// src/classes/registration/DappRegistrationService.ts
|
|
1792
|
-
import { forget as forget2 } from "@xylabs/forget";
|
|
1793
|
-
import { fulfilled, rejected } from "@xylabs/promise";
|
|
1794
|
-
import { ModuleFactoryLocator as ModuleFactoryLocator5 } from "@xyo-network/module-factory-locator";
|
|
1795
|
-
import {
|
|
1796
|
-
DappIntentTypes as DappIntentTypes2,
|
|
1797
|
-
DappMode as DappMode3,
|
|
1798
|
-
isRegisteredDappAccessDappSet as isRegisteredDappAccessDappSet2,
|
|
1799
|
-
isRegisteredDappExposedDappSet
|
|
1800
|
-
} from "@xyo-network/os-model";
|
|
1801
|
-
|
|
1802
|
-
// src/event/bus/Connection.ts
|
|
1803
|
-
import { assertEx as assertEx16 } from "@xylabs/assert";
|
|
1804
|
-
import { BaseEmitter } from "@xyo-network/module-abstract";
|
|
1805
|
-
var EventBusConnection = class extends BaseEmitter {
|
|
1806
|
-
_id;
|
|
1807
|
-
description;
|
|
1808
|
-
type;
|
|
1809
|
-
constructor(request) {
|
|
1810
|
-
super({});
|
|
1811
|
-
this.description = request.description;
|
|
1812
|
-
this.type = request.type;
|
|
1813
|
-
}
|
|
1814
|
-
get id() {
|
|
1815
|
-
return assertEx16(this._id, () => "Connection ID not set. Did you forget to call buildConnection()?");
|
|
1816
|
-
}
|
|
1817
|
-
buildConnection(id) {
|
|
1818
|
-
this._id = id;
|
|
1819
|
-
}
|
|
1820
|
-
};
|
|
1821
|
-
|
|
1822
|
-
// src/event/bus/EventBus.ts
|
|
1823
|
-
import { assertEx as assertEx17 } from "@xylabs/assert";
|
|
1824
|
-
import { forget } from "@xylabs/forget";
|
|
1825
|
-
import {
|
|
1826
|
-
asArchivistInstance as asArchivistInstance5,
|
|
1827
|
-
MemoryArchivist,
|
|
1828
|
-
MemoryArchivistConfigSchema
|
|
1829
|
-
} from "@xyo-network/archivist";
|
|
1830
|
-
import {
|
|
1831
|
-
isEventBusEvent,
|
|
1832
|
-
isPubSubConnections
|
|
1833
|
-
} from "@xyo-network/os-model";
|
|
1834
|
-
import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
|
|
1835
|
-
import { Mutex } from "async-mutex";
|
|
1836
|
-
import { v4 as uuid2 } from "uuid";
|
|
1837
|
-
var EventBus = class {
|
|
1838
|
-
// Internal Archivist to store event data
|
|
1839
|
-
_archivist;
|
|
1840
|
-
// Store all connections
|
|
1841
|
-
connections = {};
|
|
1842
|
-
// Store all publisher callbacks for later removal
|
|
1843
|
-
publisherCallbacks = {};
|
|
1844
|
-
startMutex = new Mutex();
|
|
1845
|
-
get archivist() {
|
|
1846
|
-
return asArchivistInstance5(
|
|
1847
|
-
assertEx17(this._archivist, () => "Archivist not found. Did you forget to call start()?"),
|
|
1848
|
-
"not a valid archivist instance"
|
|
1849
|
-
);
|
|
1850
|
-
}
|
|
1851
|
-
addConnection(connection) {
|
|
1852
|
-
const id = uuid2();
|
|
1853
|
-
this.connections[id] = connection;
|
|
1854
|
-
connection.buildConnection(id);
|
|
1855
|
-
if (isPubSubConnections(connection)) {
|
|
1856
|
-
this.handlePublisherAdd(connection);
|
|
1857
|
-
} else {
|
|
1858
|
-
throw new Error("Unsupported connection type. Must be PubSub");
|
|
1859
|
-
}
|
|
1860
|
-
return connection;
|
|
1861
|
-
}
|
|
1862
|
-
removeConnection(connectionId) {
|
|
1863
|
-
const connection = this.connections[connectionId];
|
|
1864
|
-
if (!connection) {
|
|
1865
|
-
throw new Error("Connection not found " + connectionId);
|
|
1866
|
-
}
|
|
1867
|
-
if (connection && isPubSubConnections(connection)) {
|
|
1868
|
-
this.handlePublisherRemove(connection);
|
|
1869
|
-
}
|
|
1870
|
-
delete this.connections[connectionId];
|
|
1500
|
+
delete this.connections[connectionId];
|
|
1871
1501
|
}
|
|
1872
1502
|
async start(storeName = "EventBusArchivist") {
|
|
1873
1503
|
return await this.startMutex.runExclusive(async () => {
|
|
@@ -1900,7 +1530,7 @@ var EventBus = class {
|
|
|
1900
1530
|
const connectionPublisherCallback = async ({ payloads }) => {
|
|
1901
1531
|
const event = { name: eventName, schema: "network.xyo.event.bus.event" };
|
|
1902
1532
|
const eventPayloads = payloads ?? [];
|
|
1903
|
-
event.sources = await
|
|
1533
|
+
event.sources = await PayloadBuilder5.dataHashes(eventPayloads);
|
|
1904
1534
|
try {
|
|
1905
1535
|
await this.archivist.insert([event, ...payloads ?? []]);
|
|
1906
1536
|
} catch (e) {
|
|
@@ -1983,7 +1613,7 @@ var osXyoPublicNetworkConnectionRequest = {
|
|
|
1983
1613
|
var osXyoPublicNetworkReadyConnection = () => new EventBusPubSubConnection(osXyoPublicNetworkConnectionRequest);
|
|
1984
1614
|
|
|
1985
1615
|
// src/XyOsDapp.ts
|
|
1986
|
-
import { assertEx as
|
|
1616
|
+
import { assertEx as assertEx14 } from "@xylabs/assert";
|
|
1987
1617
|
import { ManifestWrapper } from "@xyo-network/manifest-wrapper";
|
|
1988
1618
|
import { ModuleFactoryLocator as ModuleFactoryLocator4 } from "@xyo-network/module-factory-locator";
|
|
1989
1619
|
import { DappPackageManifestPayloadSchema } from "@xyo-network/os-model";
|
|
@@ -2027,7 +1657,7 @@ var dapp_window_manifest_default = {
|
|
|
2027
1657
|
};
|
|
2028
1658
|
|
|
2029
1659
|
// src/XyOsBase.ts
|
|
2030
|
-
import { assertEx as
|
|
1660
|
+
import { assertEx as assertEx13 } from "@xylabs/assert";
|
|
2031
1661
|
import { BaseEmitter as BaseEmitter2 } from "@xyo-network/module-abstract";
|
|
2032
1662
|
import { ModuleFactoryLocator as ModuleFactoryLocator3 } from "@xyo-network/module-factory-locator";
|
|
2033
1663
|
import { Mutex as Mutex2 } from "async-mutex";
|
|
@@ -2039,7 +1669,7 @@ var XyOsContextBase = class extends BaseEmitter2 {
|
|
|
2039
1669
|
return this.kernel?.bios;
|
|
2040
1670
|
}
|
|
2041
1671
|
get eventBus() {
|
|
2042
|
-
return
|
|
1672
|
+
return assertEx13(this.params.eventBus, () => "Missing event bus");
|
|
2043
1673
|
}
|
|
2044
1674
|
get exposedNode() {
|
|
2045
1675
|
throw new Error("Method not implemented. [exposedNode]");
|
|
@@ -2054,7 +1684,7 @@ var XyOsContextBase = class extends BaseEmitter2 {
|
|
|
2054
1684
|
return void 0;
|
|
2055
1685
|
}
|
|
2056
1686
|
get manifest() {
|
|
2057
|
-
return
|
|
1687
|
+
return assertEx13(this.params.manifest, () => "Missing manifest");
|
|
2058
1688
|
}
|
|
2059
1689
|
get platformLocator() {
|
|
2060
1690
|
this._platformLocator = this._platformLocator ?? this.params.platformLocator ?? new ModuleFactoryLocator3();
|
|
@@ -2064,7 +1694,7 @@ var XyOsContextBase = class extends BaseEmitter2 {
|
|
|
2064
1694
|
return this._root;
|
|
2065
1695
|
}
|
|
2066
1696
|
get root() {
|
|
2067
|
-
return
|
|
1697
|
+
return assertEx13(this._root, () => "XyOs root not set (probably not yet booted)");
|
|
2068
1698
|
}
|
|
2069
1699
|
get runningDapps() {
|
|
2070
1700
|
return [];
|
|
@@ -2137,7 +1767,7 @@ var XyOsDapp = class extends XyOsContextBase {
|
|
|
2137
1767
|
* ^^^ I believe we may want this here in that is a dApp requests access to the bios it will optionally be there
|
|
2138
1768
|
*/
|
|
2139
1769
|
get kernel() {
|
|
2140
|
-
return
|
|
1770
|
+
return assertEx14(this.parent.kernel, () => "Missing kernel");
|
|
2141
1771
|
}
|
|
2142
1772
|
get parent() {
|
|
2143
1773
|
return this.params.parent;
|
|
@@ -2151,7 +1781,7 @@ var XyOsDapp = class extends XyOsContextBase {
|
|
|
2151
1781
|
async boot(wallet, locator) {
|
|
2152
1782
|
return await this._bootMutex.runExclusive(async () => {
|
|
2153
1783
|
console.log("XyOsDapp:boot:start", wallet.address, this.dapp.id);
|
|
2154
|
-
|
|
1784
|
+
assertEx14(this._root === void 0, () => "Dapp already booted");
|
|
2155
1785
|
const finalLocator = locator ? (this.params.locator ?? new ModuleFactoryLocator4()).merge(locator) : this.params.locator ?? new ModuleFactoryLocator4();
|
|
2156
1786
|
console.log("XyOsDapp:boot:finalLocator", finalLocator);
|
|
2157
1787
|
const dappNodesWrapper = new ManifestWrapper({ ...this.manifest, schema: DappPackageManifestPayloadSchema }, wallet, finalLocator);
|
|
@@ -2178,24 +1808,24 @@ var XyOsDapp = class extends XyOsContextBase {
|
|
|
2178
1808
|
};
|
|
2179
1809
|
|
|
2180
1810
|
// src/classes/system/ManageSystemDapps.ts
|
|
2181
|
-
import { PayloadBuilder as
|
|
1811
|
+
import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
|
|
2182
1812
|
import semver from "semver";
|
|
2183
1813
|
|
|
2184
1814
|
// src/classes/system/Queries.ts
|
|
2185
|
-
import { PayloadDivinerQuerySchema as
|
|
1815
|
+
import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema8 } from "@xyo-network/diviner-payload-model";
|
|
2186
1816
|
import {
|
|
2187
1817
|
DappConfigSchema,
|
|
2188
1818
|
DappIconSchema,
|
|
2189
1819
|
DappWidgetConfigSchema,
|
|
2190
1820
|
UnregisteredDappAccessSchema
|
|
2191
1821
|
} from "@xyo-network/os-model";
|
|
2192
|
-
import { PayloadBuilder as
|
|
1822
|
+
import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
|
|
2193
1823
|
var SystemDappQueries = {
|
|
2194
1824
|
async getDappAccess(diviner, name, version) {
|
|
2195
1825
|
const accessQuery = {
|
|
2196
1826
|
order: "desc",
|
|
2197
1827
|
registeringDappId: name,
|
|
2198
|
-
schema:
|
|
1828
|
+
schema: PayloadDivinerQuerySchema8,
|
|
2199
1829
|
schemas: [UnregisteredDappAccessSchema],
|
|
2200
1830
|
version
|
|
2201
1831
|
};
|
|
@@ -2206,7 +1836,7 @@ var SystemDappQueries = {
|
|
|
2206
1836
|
limit: 1,
|
|
2207
1837
|
name,
|
|
2208
1838
|
order: "desc",
|
|
2209
|
-
schema:
|
|
1839
|
+
schema: PayloadDivinerQuerySchema8,
|
|
2210
1840
|
schemas: [DappConfigSchema]
|
|
2211
1841
|
};
|
|
2212
1842
|
const [dappConfig] = await diviner.divine([configQuery]);
|
|
@@ -2216,7 +1846,7 @@ var SystemDappQueries = {
|
|
|
2216
1846
|
const iconQuery = {
|
|
2217
1847
|
name,
|
|
2218
1848
|
order: "desc",
|
|
2219
|
-
schema:
|
|
1849
|
+
schema: PayloadDivinerQuerySchema8,
|
|
2220
1850
|
schemas: [DappIconSchema],
|
|
2221
1851
|
version
|
|
2222
1852
|
};
|
|
@@ -2227,14 +1857,14 @@ var SystemDappQueries = {
|
|
|
2227
1857
|
const widgetConfigQuery = {
|
|
2228
1858
|
dappId: name,
|
|
2229
1859
|
order: "desc",
|
|
2230
|
-
schema:
|
|
1860
|
+
schema: PayloadDivinerQuerySchema8,
|
|
2231
1861
|
schemas: [DappWidgetConfigSchema],
|
|
2232
1862
|
version
|
|
2233
1863
|
};
|
|
2234
1864
|
const widgetConfigs = await diviner.divine([widgetConfigQuery]);
|
|
2235
1865
|
const uniqueConfigs = {};
|
|
2236
1866
|
for (const widgetConfig of widgetConfigs) {
|
|
2237
|
-
const hash = await
|
|
1867
|
+
const hash = await PayloadBuilder6.dataHash(widgetConfig);
|
|
2238
1868
|
uniqueConfigs[widgetConfig.mode ?? hash] = widgetConfig;
|
|
2239
1869
|
}
|
|
2240
1870
|
return Object.values(uniqueConfigs);
|
|
@@ -2285,7 +1915,7 @@ var ManageSystemDapps = class extends OsCallerBase {
|
|
|
2285
1915
|
console.error(`${systemDappPayload.version} does not appear to be a valid semver value`, e);
|
|
2286
1916
|
continue;
|
|
2287
1917
|
}
|
|
2288
|
-
const [existing] = await archivist.get([await
|
|
1918
|
+
const [existing] = await archivist.get([await PayloadBuilder7.dataHash(systemDappPayload)]);
|
|
2289
1919
|
if (existing) continue;
|
|
2290
1920
|
await archivist.insert([systemDappPayload]);
|
|
2291
1921
|
}
|
|
@@ -2341,7 +1971,7 @@ var ManageSystemDapps = class extends OsCallerBase {
|
|
|
2341
1971
|
};
|
|
2342
1972
|
|
|
2343
1973
|
// src/classes/registration/DappRegistry.ts
|
|
2344
|
-
import { HDWallet as
|
|
1974
|
+
import { HDWallet as HDWallet4 } from "@xyo-network/account";
|
|
2345
1975
|
import {
|
|
2346
1976
|
DappRegisteredSchema,
|
|
2347
1977
|
DappRegisteredState,
|
|
@@ -2355,7 +1985,7 @@ var isFailedAccessor = isPayloadOfSchemaTypeWithMeta(FailedAccessorSchema);
|
|
|
2355
1985
|
var ValidateDappAccessDivinerConfigSchema = "network.xyo.os.dapp.access.registration.validate";
|
|
2356
1986
|
|
|
2357
1987
|
// src/classes/registration/ValidateDappAccessDiviner/Diviner.ts
|
|
2358
|
-
import { HDWallet as
|
|
1988
|
+
import { HDWallet as HDWallet3 } from "@xyo-network/account";
|
|
2359
1989
|
import { AbstractDiviner } from "@xyo-network/diviner-abstract";
|
|
2360
1990
|
import { ManifestWrapper as ManifestWrapper2, PackageManifestPayloadSchema as PackageManifestPayloadSchema2 } from "@xyo-network/manifest";
|
|
2361
1991
|
import {
|
|
@@ -2363,7 +1993,7 @@ import {
|
|
|
2363
1993
|
isUnregisteredDappAccess,
|
|
2364
1994
|
RegisteredDappAccessSchema as RegisteredDappAccessSchema3
|
|
2365
1995
|
} from "@xyo-network/os-model";
|
|
2366
|
-
import { PayloadBuilder as
|
|
1996
|
+
import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/payload-builder";
|
|
2367
1997
|
var ValidateDappAccessDiviner = class extends AbstractDiviner {
|
|
2368
1998
|
static configSchemas = [ValidateDappAccessDivinerConfigSchema];
|
|
2369
1999
|
async divineHandler(payloads) {
|
|
@@ -2391,14 +2021,14 @@ var ValidateDappAccessDiviner = class extends AbstractDiviner {
|
|
|
2391
2021
|
const interfaceChildren = await getNodeChildren(dappAccessInterface.manifest, dappParams);
|
|
2392
2022
|
const valid = compareChildren(interfaceChildren, dappChildren);
|
|
2393
2023
|
if (valid) {
|
|
2394
|
-
const payload = await
|
|
2024
|
+
const payload = await PayloadBuilder8.build({
|
|
2395
2025
|
...access,
|
|
2396
2026
|
schema: RegisteredDappAccessSchema3,
|
|
2397
2027
|
timestamp: Date.now()
|
|
2398
2028
|
});
|
|
2399
2029
|
registeredAccessors.push(payload);
|
|
2400
2030
|
} else {
|
|
2401
|
-
const failedRegistration = await
|
|
2031
|
+
const failedRegistration = await PayloadBuilder8.build({
|
|
2402
2032
|
accessor: access,
|
|
2403
2033
|
errorMessage: "Invalid dapp access interface",
|
|
2404
2034
|
schema: FailedAccessorSchema
|
|
@@ -2408,7 +2038,7 @@ var ValidateDappAccessDiviner = class extends AbstractDiviner {
|
|
|
2408
2038
|
}
|
|
2409
2039
|
} catch (e) {
|
|
2410
2040
|
failedAccessors.push(
|
|
2411
|
-
await
|
|
2041
|
+
await PayloadBuilder8.build({
|
|
2412
2042
|
accessor: access,
|
|
2413
2043
|
errorMessage: e.message,
|
|
2414
2044
|
schema: FailedAccessorSchema
|
|
@@ -2444,7 +2074,7 @@ var getNodeChildren = async (manifestToTest, dappParams) => {
|
|
|
2444
2074
|
return children;
|
|
2445
2075
|
};
|
|
2446
2076
|
var getNodeToTest = async (manifestToTest, dappParams) => {
|
|
2447
|
-
const dappManifestWrapper = new ManifestWrapper2(manifestToTest, await
|
|
2077
|
+
const dappManifestWrapper = new ManifestWrapper2(manifestToTest, await HDWallet3.random(), dappParams.locator);
|
|
2448
2078
|
return await dappManifestWrapper.loadNodes();
|
|
2449
2079
|
};
|
|
2450
2080
|
|
|
@@ -2505,162 +2135,470 @@ var DappRegistry = class {
|
|
|
2505
2135
|
}
|
|
2506
2136
|
}
|
|
2507
2137
|
/**
|
|
2508
|
-
* Unregister a dapp so it can no longer be launched
|
|
2509
|
-
*
|
|
2510
|
-
* @param dappId
|
|
2138
|
+
* Unregister a dapp so it can no longer be launched
|
|
2139
|
+
*
|
|
2140
|
+
* @param dappId
|
|
2141
|
+
*/
|
|
2142
|
+
unregisterDapp(dappId) {
|
|
2143
|
+
this.dappRegistry.delete(dappId);
|
|
2144
|
+
}
|
|
2145
|
+
extractDappProperties(dapp) {
|
|
2146
|
+
const {
|
|
2147
|
+
params,
|
|
2148
|
+
config,
|
|
2149
|
+
widgetConfigs
|
|
2150
|
+
} = dapp;
|
|
2151
|
+
const {
|
|
2152
|
+
exposedModuleIds,
|
|
2153
|
+
manifest,
|
|
2154
|
+
modes,
|
|
2155
|
+
name,
|
|
2156
|
+
sources,
|
|
2157
|
+
version
|
|
2158
|
+
} = config;
|
|
2159
|
+
return {
|
|
2160
|
+
exposedModuleIds,
|
|
2161
|
+
manifest,
|
|
2162
|
+
modes,
|
|
2163
|
+
name,
|
|
2164
|
+
params,
|
|
2165
|
+
sources,
|
|
2166
|
+
version,
|
|
2167
|
+
widgetConfigs
|
|
2168
|
+
};
|
|
2169
|
+
}
|
|
2170
|
+
async validateDappAccessPayloads(manifest, accessors = [], params) {
|
|
2171
|
+
const validateDappAccess = await ValidateDappAccessDiviner.create({
|
|
2172
|
+
account: await HDWallet4.random(),
|
|
2173
|
+
config: { schema: ValidateDappAccessDivinerConfigSchema },
|
|
2174
|
+
dappParams: params
|
|
2175
|
+
});
|
|
2176
|
+
const payloads = await validateDappAccess.divine([manifest, ...accessors]);
|
|
2177
|
+
const failedAccessors = payloads.filter(isFailedAccessor);
|
|
2178
|
+
const registeredAccessors = payloads.filter(isRegisteredDappAccess2);
|
|
2179
|
+
if (failedAccessors.length > 0) {
|
|
2180
|
+
console.error("Failed to register all dapp accessors", failedAccessors);
|
|
2181
|
+
}
|
|
2182
|
+
return registeredAccessors;
|
|
2183
|
+
}
|
|
2184
|
+
};
|
|
2185
|
+
|
|
2186
|
+
// src/classes/registration/DappRegistrationService.ts
|
|
2187
|
+
var DappRegistrationService = class {
|
|
2188
|
+
constructor(context, params = {
|
|
2189
|
+
dappNames: [],
|
|
2190
|
+
dappParams: {},
|
|
2191
|
+
dappPayloads: []
|
|
2192
|
+
}, locator = new ModuleFactoryLocator5(), developmentMode) {
|
|
2193
|
+
this.context = context;
|
|
2194
|
+
this.params = params;
|
|
2195
|
+
this.locator = locator;
|
|
2196
|
+
this.developmentMode = developmentMode;
|
|
2197
|
+
this.manageSystemDapps = new ManageSystemDapps(
|
|
2198
|
+
context,
|
|
2199
|
+
this.params?.dappNames ?? [],
|
|
2200
|
+
this.params?.dappPayloads ?? [],
|
|
2201
|
+
this.params?.dappParams ?? {},
|
|
2202
|
+
this.locator,
|
|
2203
|
+
this.developmentMode
|
|
2204
|
+
);
|
|
2205
|
+
this.dappSeedPhraseRepository = new DappSeedPhraseRepository(context, this.params?.dappNames ?? []);
|
|
2206
|
+
this.dappRegistry = new DappRegistry(this.dappSeedPhraseRepository);
|
|
2207
|
+
this.addConnectionRequests();
|
|
2208
|
+
}
|
|
2209
|
+
// Dapps that have been built with their own context
|
|
2210
|
+
builtDapps = {};
|
|
2211
|
+
dappRegistry;
|
|
2212
|
+
dappSeedPhraseRepository;
|
|
2213
|
+
manageSystemDapps;
|
|
2214
|
+
// Dapps that have been registered with dappAccessRequests
|
|
2215
|
+
registeredAccessDappSets = /* @__PURE__ */ new Set();
|
|
2216
|
+
// Dapps that have been registered with the dapp registry
|
|
2217
|
+
registeredDappSets = /* @__PURE__ */ new Set();
|
|
2218
|
+
// Dapps that have been registered with exposeDappRequests
|
|
2219
|
+
registeredExposedDappSets = /* @__PURE__ */ new Set();
|
|
2220
|
+
dappAccessRequestConnection = dappAccessRequestConnection();
|
|
2221
|
+
exposeDappRequestConnection = exposeDappRequestConnection();
|
|
2222
|
+
async buildDapp(manifest, dappId = NameTransforms.slug(manifest.nodes[0]?.config.name), name = NameTransforms.moduleName(manifest.nodes[0]?.config.name)) {
|
|
2223
|
+
const dapp = new XyOsDapp({
|
|
2224
|
+
dapp: { id: dappId, name },
|
|
2225
|
+
locator: this.locator,
|
|
2226
|
+
manifest,
|
|
2227
|
+
parent: this.context,
|
|
2228
|
+
user: await this.getUser()
|
|
2229
|
+
});
|
|
2230
|
+
this.builtDapps[dappId] = dapp;
|
|
2231
|
+
return dapp;
|
|
2232
|
+
}
|
|
2233
|
+
getParamsForRegisteredDapp(dappId) {
|
|
2234
|
+
return this.params?.dappParams[dappId];
|
|
2235
|
+
}
|
|
2236
|
+
async start() {
|
|
2237
|
+
const systemDapps = await this.context.monitor(async () => await this.manageSystemDapps.install(), { name: "Install System dApps" });
|
|
2238
|
+
const activeDapps = systemDapps.filter(({ dapp }) => dapp.icon.active === true);
|
|
2239
|
+
const results = await Promise.allSettled(
|
|
2240
|
+
activeDapps.map(async (dappSet) => {
|
|
2241
|
+
const { dapp } = dappSet;
|
|
2242
|
+
const registeredDapp = await this.dappRegistry.registerDapp(dapp);
|
|
2243
|
+
const result = { dapp: registeredDapp, dappIcon: dapp.icon };
|
|
2244
|
+
const forgetHandlers = async () => {
|
|
2245
|
+
try {
|
|
2246
|
+
await this.postRegistrationHandlers(result);
|
|
2247
|
+
} catch (e) {
|
|
2248
|
+
console.error("Error in post registration handlers", e);
|
|
2249
|
+
}
|
|
2250
|
+
};
|
|
2251
|
+
forget2(forgetHandlers());
|
|
2252
|
+
return result;
|
|
2253
|
+
})
|
|
2254
|
+
);
|
|
2255
|
+
const failed = results.filter(rejected).map((result) => result.reason);
|
|
2256
|
+
const succeeded = results.filter(fulfilled).map((result) => result.value);
|
|
2257
|
+
for (const registeredDapp of succeeded) this.registeredDappSets.add(registeredDapp);
|
|
2258
|
+
return { failed, succeeded };
|
|
2259
|
+
}
|
|
2260
|
+
addConnectionRequests() {
|
|
2261
|
+
this.context.eventBus.addConnection(this.dappAccessRequestConnection);
|
|
2262
|
+
this.context.eventBus.addConnection(this.exposeDappRequestConnection);
|
|
2263
|
+
}
|
|
2264
|
+
/**
|
|
2265
|
+
* A method to get the user property from context and eventually modify it before handing it to a dapp
|
|
2266
|
+
* i.e. curating user-approved signers
|
|
2267
|
+
*/
|
|
2268
|
+
getUser() {
|
|
2269
|
+
return this.context.user;
|
|
2270
|
+
}
|
|
2271
|
+
async postRegistrationHandlers(registeredDapp) {
|
|
2272
|
+
if (registeredDapp.dapp) {
|
|
2273
|
+
if (isRegisteredDappExposedDappSet(registeredDapp)) {
|
|
2274
|
+
this.registeredExposedDappSets.add(registeredDapp);
|
|
2275
|
+
const exposeIntent = DappIntentCaller.buildIntent(
|
|
2276
|
+
DappIntentCaller.OsDappName,
|
|
2277
|
+
DappIntentTypes2.Launch,
|
|
2278
|
+
registeredDapp.dapp.config.name,
|
|
2279
|
+
DappMode3.Exposed
|
|
2280
|
+
);
|
|
2281
|
+
await this.exposeDappRequestConnection.emit(ExposeDappRequestEvent, { payloads: [registeredDapp.dapp.config, exposeIntent] });
|
|
2282
|
+
}
|
|
2283
|
+
if (isRegisteredDappAccessDappSet2(registeredDapp)) {
|
|
2284
|
+
this.registeredAccessDappSets.add(registeredDapp);
|
|
2285
|
+
await this.dappAccessRequestConnection.emit(DappAccessRequestEvent, { payloads: registeredDapp.dapp.accessors });
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
};
|
|
2290
|
+
|
|
2291
|
+
// src/classes/settings/badge/Caller.ts
|
|
2292
|
+
import { OsBadgeSchema as OsBadgeSchema2 } from "@xyo-network/os-model";
|
|
2293
|
+
|
|
2294
|
+
// src/classes/settings/CallerBase.ts
|
|
2295
|
+
import { assertEx as assertEx15 } from "@xylabs/assert";
|
|
2296
|
+
import { asArchivistInstance as asArchivistInstance5 } from "@xyo-network/archivist-model";
|
|
2297
|
+
import { asDivinerInstance as asDivinerInstance4 } from "@xyo-network/diviner-model";
|
|
2298
|
+
var OsSettingsArchivistModuleName = "OsSettingsNode:OsSettingsArchivist";
|
|
2299
|
+
var OsSettingsArchivistPayloadDivinerModuleName = "OsSettingsNode:OsSettingsArchivistPayloadDiviner";
|
|
2300
|
+
var OsSettingsCallerBase = class {
|
|
2301
|
+
constructor(context) {
|
|
2302
|
+
this.context = context;
|
|
2303
|
+
}
|
|
2304
|
+
async getOsSettingsArchivist() {
|
|
2305
|
+
const mod = assertEx15(await this.context.root.resolve(OsSettingsArchivistModuleName), () => `${OsSettingsArchivistModuleName} not found`);
|
|
2306
|
+
return asArchivistInstance5(mod, () => `${OsSettingsArchivistModuleName} is not an archivist`);
|
|
2307
|
+
}
|
|
2308
|
+
async getOsSettingsPayloadDiviner() {
|
|
2309
|
+
const mod = assertEx15(
|
|
2310
|
+
await this.context.root.resolve(OsSettingsArchivistPayloadDivinerModuleName),
|
|
2311
|
+
() => `${OsSettingsArchivistPayloadDivinerModuleName} not found`
|
|
2312
|
+
);
|
|
2313
|
+
return asDivinerInstance4(mod, () => `${OsSettingsArchivistPayloadDivinerModuleName} is not a diviner`);
|
|
2314
|
+
}
|
|
2315
|
+
};
|
|
2316
|
+
|
|
2317
|
+
// src/classes/settings/badge/Queries.ts
|
|
2318
|
+
import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema9 } from "@xyo-network/diviner-payload-model";
|
|
2319
|
+
import { OsBadgeSchema } from "@xyo-network/os-model";
|
|
2320
|
+
var OsBadgeQueries = {
|
|
2321
|
+
getBadge: async (achievement, diviner) => {
|
|
2322
|
+
const query = {
|
|
2323
|
+
achievement,
|
|
2324
|
+
limit: 1,
|
|
2325
|
+
order: "desc",
|
|
2326
|
+
schema: PayloadDivinerQuerySchema9,
|
|
2327
|
+
schemas: [OsBadgeSchema]
|
|
2328
|
+
};
|
|
2329
|
+
return await diviner.divine([query]);
|
|
2330
|
+
}
|
|
2331
|
+
};
|
|
2332
|
+
|
|
2333
|
+
// src/classes/settings/badge/Caller.ts
|
|
2334
|
+
var OsBadgeCaller = class extends OsSettingsCallerBase {
|
|
2335
|
+
/**
|
|
2336
|
+
* @param {ValidOsAchievements} achievement
|
|
2337
|
+
*/
|
|
2338
|
+
async getBadge(achievement) {
|
|
2339
|
+
const diviner = await this.getOsSettingsPayloadDiviner();
|
|
2340
|
+
const results = await OsBadgeQueries.getBadge(achievement, diviner);
|
|
2341
|
+
return results[0] ?? null;
|
|
2342
|
+
}
|
|
2343
|
+
/**
|
|
2344
|
+
* @param {ValidOsAchievements} achievement
|
|
2345
|
+
*/
|
|
2346
|
+
async saveBadge(achievement) {
|
|
2347
|
+
const badge = {
|
|
2348
|
+
achievement,
|
|
2349
|
+
schema: OsBadgeSchema2,
|
|
2350
|
+
timestamp: Date.now()
|
|
2351
|
+
};
|
|
2352
|
+
const archivist = await this.getOsSettingsArchivist();
|
|
2353
|
+
return await archivist.insert([badge]);
|
|
2354
|
+
}
|
|
2355
|
+
};
|
|
2356
|
+
|
|
2357
|
+
// src/classes/settings/badge/Resource.ts
|
|
2358
|
+
import { assertEx as assertEx16 } from "@xylabs/assert";
|
|
2359
|
+
import { isBadgeWithMeta } from "@xyo-network/os-model";
|
|
2360
|
+
var OsBadgeResource = class extends OsSettingsCallerBase {
|
|
2361
|
+
static views = ["savedSeedPhrase"];
|
|
2362
|
+
_savedSeedPhrase;
|
|
2363
|
+
constructor(xyOsContext) {
|
|
2364
|
+
super(xyOsContext);
|
|
2365
|
+
}
|
|
2366
|
+
get savedSeedPhrase() {
|
|
2367
|
+
return assertEx16(this._savedSeedPhrase, () => "Saved seed phrase listener not set");
|
|
2368
|
+
}
|
|
2369
|
+
get subscriptions() {
|
|
2370
|
+
return { savedSeedPhrase: (cb) => this.savedSeedPhrase.subscribe(cb) };
|
|
2371
|
+
}
|
|
2372
|
+
get views() {
|
|
2373
|
+
return { savedSeedPhrase: () => this.savedSeedPhrase.latest };
|
|
2374
|
+
}
|
|
2375
|
+
cleanupListeners() {
|
|
2376
|
+
this.savedSeedPhrase.cleanupListeners();
|
|
2377
|
+
}
|
|
2378
|
+
/**
|
|
2379
|
+
* start listeners
|
|
2380
|
+
**/
|
|
2381
|
+
async start() {
|
|
2382
|
+
const diviner = await this.getOsSettingsPayloadDiviner();
|
|
2383
|
+
const archivist = await this.getOsSettingsArchivist();
|
|
2384
|
+
this._savedSeedPhrase = await PayloadStore.create({
|
|
2385
|
+
archivist,
|
|
2386
|
+
getLatest: async () => await OsBadgeQueries.getBadge("savedSeedPhrase", diviner),
|
|
2387
|
+
idFunction: isBadgeWithMeta
|
|
2388
|
+
});
|
|
2389
|
+
}
|
|
2390
|
+
};
|
|
2391
|
+
|
|
2392
|
+
// src/classes/settings/Caller.ts
|
|
2393
|
+
import { assertEx as assertEx17 } from "@xylabs/assert";
|
|
2394
|
+
import { isEqual } from "@xylabs/lodash";
|
|
2395
|
+
|
|
2396
|
+
// src/utils/buildWalletSeedPhrasePayload.ts
|
|
2397
|
+
import { WalletSeedPhraseSchema } from "@xyo-network/os-model";
|
|
2398
|
+
import { PayloadBuilder as PayloadBuilder9 } from "@xyo-network/payload-builder";
|
|
2399
|
+
var language = "english";
|
|
2400
|
+
var standard = "bip-39";
|
|
2401
|
+
var userWalletLabel = "userWallet";
|
|
2402
|
+
var buildWalletSeedPhrasePayload = async (mnemonic, label) => {
|
|
2403
|
+
const fields = {
|
|
2404
|
+
mnemonic: {
|
|
2405
|
+
language,
|
|
2406
|
+
mnemonic: mnemonic.split(" "),
|
|
2407
|
+
standard
|
|
2408
|
+
}
|
|
2409
|
+
};
|
|
2410
|
+
const meta = { label, timestamp: Date.now() };
|
|
2411
|
+
const builder = new PayloadBuilder9({
|
|
2412
|
+
fields,
|
|
2413
|
+
meta,
|
|
2414
|
+
schema: WalletSeedPhraseSchema
|
|
2415
|
+
});
|
|
2416
|
+
const payload = await builder.build();
|
|
2417
|
+
const rootHash = await PayloadBuilder9.hash(payload);
|
|
2418
|
+
return { payload, rootHash };
|
|
2419
|
+
};
|
|
2420
|
+
var buildUserWalletSeedPhrasePayload = (mnemonic) => {
|
|
2421
|
+
return buildWalletSeedPhrasePayload(mnemonic, userWalletLabel);
|
|
2422
|
+
};
|
|
2423
|
+
|
|
2424
|
+
// src/utils/getApiDomain.ts
|
|
2425
|
+
var getApiDomain = (scope, apiDomain) => {
|
|
2426
|
+
if (apiDomain !== void 0) {
|
|
2427
|
+
return apiDomain;
|
|
2428
|
+
}
|
|
2429
|
+
if (scope === "localhost") {
|
|
2430
|
+
return "http://localhost:8080";
|
|
2431
|
+
}
|
|
2432
|
+
if (scope === "beta") {
|
|
2433
|
+
return "https://beta.archivist.xyo.network";
|
|
2434
|
+
}
|
|
2435
|
+
return "https://archivist.xyo.network";
|
|
2436
|
+
};
|
|
2437
|
+
|
|
2438
|
+
// src/utils/renameObjKey.ts
|
|
2439
|
+
var renameObjKey = (oldObj, oldKey, newKey) => {
|
|
2440
|
+
const oldObjKeys = Object.keys(oldObj);
|
|
2441
|
+
const newObj = oldObjKeys.reduce(
|
|
2442
|
+
(acc, val) => {
|
|
2443
|
+
if (val === oldKey) {
|
|
2444
|
+
acc[newKey] = oldObj[oldKey];
|
|
2445
|
+
} else {
|
|
2446
|
+
acc[val] = oldObj[val];
|
|
2447
|
+
}
|
|
2448
|
+
return acc;
|
|
2449
|
+
},
|
|
2450
|
+
{}
|
|
2451
|
+
);
|
|
2452
|
+
return newObj;
|
|
2453
|
+
};
|
|
2454
|
+
|
|
2455
|
+
// src/classes/settings/SettingsQueries.ts
|
|
2456
|
+
import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema10 } from "@xyo-network/diviner-payload-model";
|
|
2457
|
+
import { NodeBackgroundSchema, WalletSeedPhraseSchema as WalletSeedPhraseSchema2 } from "@xyo-network/os-model";
|
|
2458
|
+
var NO_RESULTS2 = [];
|
|
2459
|
+
var OsSettingsQueries = {
|
|
2460
|
+
async getLatestUserWallet(diviner) {
|
|
2461
|
+
const query = {
|
|
2462
|
+
limit: 1,
|
|
2463
|
+
order: "desc",
|
|
2464
|
+
schema: PayloadDivinerQuerySchema10,
|
|
2465
|
+
schemas: [WalletSeedPhraseSchema2]
|
|
2466
|
+
};
|
|
2467
|
+
const results = await diviner.divine([query]);
|
|
2468
|
+
const wallet = results.find((payload) => payload.$meta.label === "userWallet");
|
|
2469
|
+
return wallet ? [wallet] : NO_RESULTS2;
|
|
2470
|
+
},
|
|
2471
|
+
async getNodeBackground(diviner) {
|
|
2472
|
+
const query = {
|
|
2473
|
+
limit: 1,
|
|
2474
|
+
order: "desc",
|
|
2475
|
+
schema: PayloadDivinerQuerySchema10,
|
|
2476
|
+
schemas: [NodeBackgroundSchema]
|
|
2477
|
+
};
|
|
2478
|
+
return await diviner.divine([query]);
|
|
2479
|
+
},
|
|
2480
|
+
async getWallets(diviner) {
|
|
2481
|
+
const query = {
|
|
2482
|
+
order: "desc",
|
|
2483
|
+
schema: PayloadDivinerQuerySchema10,
|
|
2484
|
+
schemas: [WalletSeedPhraseSchema2]
|
|
2485
|
+
};
|
|
2486
|
+
return await diviner.divine([query]);
|
|
2487
|
+
}
|
|
2488
|
+
};
|
|
2489
|
+
|
|
2490
|
+
// src/classes/settings/Caller.ts
|
|
2491
|
+
var OsSettingsCaller = class extends OsSettingsCallerBase {
|
|
2492
|
+
constructor(context) {
|
|
2493
|
+
super(context);
|
|
2494
|
+
}
|
|
2495
|
+
/**
|
|
2496
|
+
* Add a node background to the settings
|
|
2497
|
+
* @param {WithMeta<NodeBackground>} payload
|
|
2511
2498
|
*/
|
|
2512
|
-
|
|
2513
|
-
this.
|
|
2499
|
+
async addNodeBackground(payload) {
|
|
2500
|
+
const archivist = await this.getOsSettingsArchivist();
|
|
2501
|
+
await archivist.insert([payload]);
|
|
2514
2502
|
}
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
modes,
|
|
2525
|
-
name,
|
|
2526
|
-
sources,
|
|
2527
|
-
version
|
|
2528
|
-
} = config;
|
|
2529
|
-
return {
|
|
2530
|
-
exposedModuleIds,
|
|
2531
|
-
manifest,
|
|
2532
|
-
modes,
|
|
2533
|
-
name,
|
|
2534
|
-
params,
|
|
2535
|
-
sources,
|
|
2536
|
-
version,
|
|
2537
|
-
widgetConfigs
|
|
2538
|
-
};
|
|
2503
|
+
/**
|
|
2504
|
+
* Add a wallet seed phrase to the settings
|
|
2505
|
+
* @param {WalletSeedPhrase} payload
|
|
2506
|
+
*/
|
|
2507
|
+
async addWalletSeedPhrase(payload) {
|
|
2508
|
+
const archivist = await this.getOsSettingsArchivist();
|
|
2509
|
+
await archivist.insert([payload]);
|
|
2510
|
+
const phrase = payload.mnemonic.mnemonic.join(" ");
|
|
2511
|
+
await this.context.kernel?.bios?.seedPhraseStore.set("user", phrase);
|
|
2539
2512
|
}
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2513
|
+
/**
|
|
2514
|
+
* Get the latest node background
|
|
2515
|
+
*/
|
|
2516
|
+
async getLatestNodeBackground() {
|
|
2517
|
+
const diviner = await this.getOsSettingsPayloadDiviner();
|
|
2518
|
+
const [result] = await OsSettingsQueries.getNodeBackground(diviner);
|
|
2519
|
+
return result ?? null;
|
|
2520
|
+
}
|
|
2521
|
+
async getLatestUserWallet() {
|
|
2522
|
+
const diviner = await this.getOsSettingsPayloadDiviner();
|
|
2523
|
+
const storedSeedPhrasePayload = (await OsSettingsQueries.getLatestUserWallet(diviner)).pop();
|
|
2524
|
+
const biosWalletSeedPhrase = assertEx17(await this.context.kernel?.bios?.seedPhraseStore.get("user"), () => "No user seed phrase found from BIOS");
|
|
2525
|
+
const biosWalletSeedPhraseParts = biosWalletSeedPhrase.split(" ");
|
|
2526
|
+
if (!storedSeedPhrasePayload?.mnemonic?.mnemonic) {
|
|
2527
|
+
const { payload: biosSeedPhrasePayload } = await buildUserWalletSeedPhrasePayload(biosWalletSeedPhrase);
|
|
2528
|
+
await this.addWalletSeedPhrase(biosSeedPhrasePayload);
|
|
2529
|
+
return biosSeedPhrasePayload;
|
|
2530
|
+
} else if (!isEqual(storedSeedPhrasePayload.mnemonic.mnemonic, biosWalletSeedPhraseParts)) {
|
|
2531
|
+
const updatedBiosSeedPhrase = storedSeedPhrasePayload.mnemonic.mnemonic.join(" ");
|
|
2532
|
+
await this.context.kernel?.bios?.seedPhraseStore.set("user", updatedBiosSeedPhrase);
|
|
2551
2533
|
}
|
|
2552
|
-
return
|
|
2534
|
+
return storedSeedPhrasePayload;
|
|
2553
2535
|
}
|
|
2554
2536
|
};
|
|
2555
2537
|
|
|
2556
|
-
// src/classes/
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
this.locator = locator;
|
|
2566
|
-
this.developmentMode = developmentMode;
|
|
2567
|
-
this.manageSystemDapps = new ManageSystemDapps(
|
|
2568
|
-
context,
|
|
2569
|
-
this.params?.dappNames ?? [],
|
|
2570
|
-
this.params?.dappPayloads ?? [],
|
|
2571
|
-
this.params?.dappParams ?? {},
|
|
2572
|
-
this.locator,
|
|
2573
|
-
this.developmentMode
|
|
2574
|
-
);
|
|
2575
|
-
this.dappSeedPhraseRepository = new DappSeedPhraseRepository(context, this.params?.dappNames ?? []);
|
|
2576
|
-
this.dappRegistry = new DappRegistry(this.dappSeedPhraseRepository);
|
|
2577
|
-
this.addConnectionRequests();
|
|
2538
|
+
// src/classes/settings/Resource.ts
|
|
2539
|
+
import { assertEx as assertEx18 } from "@xylabs/assert";
|
|
2540
|
+
import { isNodeBackground, isWalletSeedPhrase } from "@xyo-network/os-model";
|
|
2541
|
+
var OsSettingsResource = class extends OsSettingsCallerBase {
|
|
2542
|
+
_latestUserWalletListener;
|
|
2543
|
+
_nodeBackgroundListener;
|
|
2544
|
+
_walletsListener;
|
|
2545
|
+
constructor(context) {
|
|
2546
|
+
super(context);
|
|
2578
2547
|
}
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
dappRegistry;
|
|
2582
|
-
dappSeedPhraseRepository;
|
|
2583
|
-
manageSystemDapps;
|
|
2584
|
-
// Dapps that have been registered with dappAccessRequests
|
|
2585
|
-
registeredAccessDappSets = /* @__PURE__ */ new Set();
|
|
2586
|
-
// Dapps that have been registered with the dapp registry
|
|
2587
|
-
registeredDappSets = /* @__PURE__ */ new Set();
|
|
2588
|
-
// Dapps that have been registered with exposeDappRequests
|
|
2589
|
-
registeredExposedDappSets = /* @__PURE__ */ new Set();
|
|
2590
|
-
dappAccessRequestConnection = dappAccessRequestConnection();
|
|
2591
|
-
exposeDappRequestConnection = exposeDappRequestConnection();
|
|
2592
|
-
async buildDapp(manifest, dappId = NameTransforms.slug(manifest.nodes[0]?.config.name), name = NameTransforms.moduleName(manifest.nodes[0]?.config.name)) {
|
|
2593
|
-
const dapp = new XyOsDapp({
|
|
2594
|
-
dapp: { id: dappId, name },
|
|
2595
|
-
locator: this.locator,
|
|
2596
|
-
manifest,
|
|
2597
|
-
parent: this.context,
|
|
2598
|
-
user: await this.getUser()
|
|
2599
|
-
});
|
|
2600
|
-
this.builtDapps[dappId] = dapp;
|
|
2601
|
-
return dapp;
|
|
2548
|
+
get latestUserWalletListener() {
|
|
2549
|
+
return assertEx18(this._latestUserWalletListener, () => "Latest user wallet listener not set");
|
|
2602
2550
|
}
|
|
2603
|
-
|
|
2604
|
-
return this.
|
|
2551
|
+
get nodeBackgroundListener() {
|
|
2552
|
+
return assertEx18(this._nodeBackgroundListener, () => "Node background listener not set");
|
|
2605
2553
|
}
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
const registeredDapp = await this.dappRegistry.registerDapp(dapp);
|
|
2613
|
-
const result = { dapp: registeredDapp, dappIcon: dapp.icon };
|
|
2614
|
-
const forgetHandlers = async () => {
|
|
2615
|
-
try {
|
|
2616
|
-
await this.postRegistrationHandlers(result);
|
|
2617
|
-
} catch (e) {
|
|
2618
|
-
console.error("Error in post registration handlers", e);
|
|
2619
|
-
}
|
|
2620
|
-
};
|
|
2621
|
-
forget2(forgetHandlers());
|
|
2622
|
-
return result;
|
|
2623
|
-
})
|
|
2624
|
-
);
|
|
2625
|
-
const failed = results.filter(rejected).map((result) => result.reason);
|
|
2626
|
-
const succeeded = results.filter(fulfilled).map((result) => result.value);
|
|
2627
|
-
for (const registeredDapp of succeeded) this.registeredDappSets.add(registeredDapp);
|
|
2628
|
-
return { failed, succeeded };
|
|
2554
|
+
get subscriptions() {
|
|
2555
|
+
return {
|
|
2556
|
+
latestUserWallet: (cb) => this.walletsListener.subscribe(cb),
|
|
2557
|
+
nodeBackground: (cb) => this.nodeBackgroundListener.subscribe(cb),
|
|
2558
|
+
wallets: (cb) => this.walletsListener.subscribe(cb)
|
|
2559
|
+
};
|
|
2629
2560
|
}
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2561
|
+
get views() {
|
|
2562
|
+
return {
|
|
2563
|
+
latestUserWallet: () => this.latestUserWalletListener.latest,
|
|
2564
|
+
nodeBackground: () => this.nodeBackgroundListener.latest,
|
|
2565
|
+
wallets: () => this.walletsListener.latest
|
|
2566
|
+
};
|
|
2567
|
+
}
|
|
2568
|
+
get walletsListener() {
|
|
2569
|
+
return assertEx18(this._walletsListener, () => "Wallets listener not set");
|
|
2570
|
+
}
|
|
2571
|
+
cleanupListeners() {
|
|
2572
|
+
this.walletsListener.cleanupListeners();
|
|
2573
|
+
this.latestUserWalletListener.cleanupListeners();
|
|
2633
2574
|
}
|
|
2634
2575
|
/**
|
|
2635
|
-
*
|
|
2636
|
-
* i.e. curating user-approved signers
|
|
2576
|
+
* start listeners
|
|
2637
2577
|
*/
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
}
|
|
2657
|
-
}
|
|
2578
|
+
async start() {
|
|
2579
|
+
const archivist = await this.getOsSettingsArchivist();
|
|
2580
|
+
const diviner = await this.getOsSettingsPayloadDiviner();
|
|
2581
|
+
this._walletsListener = await PayloadStore.create({
|
|
2582
|
+
archivist,
|
|
2583
|
+
getLatest: async () => await OsSettingsQueries.getWallets(diviner),
|
|
2584
|
+
idFunction: isWalletSeedPhrase
|
|
2585
|
+
});
|
|
2586
|
+
this._latestUserWalletListener = await PayloadStore.create({
|
|
2587
|
+
archivist,
|
|
2588
|
+
getLatest: async () => await OsSettingsQueries.getLatestUserWallet(diviner),
|
|
2589
|
+
idFunction: isWalletSeedPhrase
|
|
2590
|
+
});
|
|
2591
|
+
this._nodeBackgroundListener = await PayloadStore.create({
|
|
2592
|
+
archivist,
|
|
2593
|
+
getLatest: async () => await OsSettingsQueries.getNodeBackground(diviner),
|
|
2594
|
+
idFunction: isNodeBackground
|
|
2595
|
+
});
|
|
2658
2596
|
}
|
|
2659
2597
|
};
|
|
2660
2598
|
|
|
2661
2599
|
// src/classes/signer/Signers.ts
|
|
2662
|
-
import { assertEx as
|
|
2663
|
-
import { HDWallet as
|
|
2600
|
+
import { assertEx as assertEx19 } from "@xylabs/assert";
|
|
2601
|
+
import { HDWallet as HDWallet5 } from "@xyo-network/account";
|
|
2664
2602
|
var Signers = class {
|
|
2665
2603
|
_paths;
|
|
2666
2604
|
_signerAccounts;
|
|
@@ -2671,13 +2609,13 @@ var Signers = class {
|
|
|
2671
2609
|
this._signerAccounts = /* @__PURE__ */ new Map();
|
|
2672
2610
|
}
|
|
2673
2611
|
get paths() {
|
|
2674
|
-
return
|
|
2612
|
+
return assertEx19(this._paths, () => "Paths not initialized");
|
|
2675
2613
|
}
|
|
2676
2614
|
get signerAccounts() {
|
|
2677
|
-
return
|
|
2615
|
+
return assertEx19(this._signerAccounts, () => "Signer accounts not initialized");
|
|
2678
2616
|
}
|
|
2679
2617
|
get walletStore() {
|
|
2680
|
-
return
|
|
2618
|
+
return assertEx19(this._walletStore, () => "Wallet store not initialized");
|
|
2681
2619
|
}
|
|
2682
2620
|
getSigner(walletKind, signer) {
|
|
2683
2621
|
return this.signerAccounts.get(walletKind)?.get(signer);
|
|
@@ -2693,12 +2631,12 @@ var Signers = class {
|
|
|
2693
2631
|
}
|
|
2694
2632
|
}
|
|
2695
2633
|
async initializeSigners(walletKindName, signerName, path) {
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
const phrase =
|
|
2634
|
+
assertEx19(signerName, () => "Name not found in signer paths");
|
|
2635
|
+
assertEx19(path, () => "Path not found in signer paths");
|
|
2636
|
+
const phrase = assertEx19(await this.walletStore.get(walletKindName), () => `Wallet not found: ${walletKindName}`);
|
|
2699
2637
|
if (path) {
|
|
2700
2638
|
const signerMap = this.signerAccounts.get(walletKindName) ?? /* @__PURE__ */ new Map();
|
|
2701
|
-
const wallet = await
|
|
2639
|
+
const wallet = await HDWallet5.fromPhrase(phrase);
|
|
2702
2640
|
const derivedWallet = await wallet.derivePath(path);
|
|
2703
2641
|
signerMap.set(signerName, derivedWallet);
|
|
2704
2642
|
this.signerAccounts.set(walletKindName, signerMap);
|
|
@@ -2734,7 +2672,7 @@ var loadOsNode = async (osWallet, locator) => {
|
|
|
2734
2672
|
};
|
|
2735
2673
|
|
|
2736
2674
|
// src/stack/Base.ts
|
|
2737
|
-
import { assertEx as
|
|
2675
|
+
import { assertEx as assertEx20 } from "@xylabs/assert";
|
|
2738
2676
|
import { forget as forget3 } from "@xylabs/forget";
|
|
2739
2677
|
import { BaseEmitter as BaseEmitter3 } from "@xyo-network/module-abstract";
|
|
2740
2678
|
import { isModuleInstance } from "@xyo-network/module-model";
|
|
@@ -2756,20 +2694,20 @@ var StackBase = class extends BaseEmitter3 {
|
|
|
2756
2694
|
constructor(context, adapterSet, stackNodeModuleId) {
|
|
2757
2695
|
super({});
|
|
2758
2696
|
this._context = context;
|
|
2759
|
-
this._adapterSet = adapterSet(
|
|
2697
|
+
this._adapterSet = adapterSet(assertEx20(this.context.kernel, "Kernel access required"));
|
|
2760
2698
|
this._stackNodeModuleId = stackNodeModuleId;
|
|
2761
2699
|
}
|
|
2762
2700
|
get adapterSet() {
|
|
2763
|
-
return
|
|
2701
|
+
return assertEx20(this._adapterSet, () => `${this.stackNodeModuleId} adapters not initialized`);
|
|
2764
2702
|
}
|
|
2765
2703
|
get context() {
|
|
2766
|
-
return
|
|
2704
|
+
return assertEx20(this._context, () => `${this.stackNodeModuleId} stack context not initialized`);
|
|
2767
2705
|
}
|
|
2768
2706
|
get stack() {
|
|
2769
|
-
return
|
|
2707
|
+
return assertEx20(this._stack, () => `${this.stackNodeModuleId} stack node not initialized`);
|
|
2770
2708
|
}
|
|
2771
2709
|
get stackNodeModuleId() {
|
|
2772
|
-
return
|
|
2710
|
+
return assertEx20(this._stackNodeModuleId, () => "Stack node module identifier not initialized");
|
|
2773
2711
|
}
|
|
2774
2712
|
initialize() {
|
|
2775
2713
|
this.assignStack();
|
|
@@ -2828,7 +2766,7 @@ var StackBase = class extends BaseEmitter3 {
|
|
|
2828
2766
|
forget3(assign());
|
|
2829
2767
|
}
|
|
2830
2768
|
async getStackNode() {
|
|
2831
|
-
const mod =
|
|
2769
|
+
const mod = assertEx20(await this.context.root.resolve(this.stackNodeModuleId), () => `${this.stackNodeModuleId} not found`);
|
|
2832
2770
|
return asAttachableNodeInstance(mod, () => `${this.stackNodeModuleId} not a NodeInstance`);
|
|
2833
2771
|
}
|
|
2834
2772
|
async handleDriverReady(node) {
|
|
@@ -2886,7 +2824,7 @@ var StackManager = class {
|
|
|
2886
2824
|
import { ExposedNodeOuterNodeName, PubSubBridgeNodeNodeName } from "@xyo-network/os-model";
|
|
2887
2825
|
|
|
2888
2826
|
// src/adapter/Base.ts
|
|
2889
|
-
import { assertEx as
|
|
2827
|
+
import { assertEx as assertEx21 } from "@xylabs/assert";
|
|
2890
2828
|
import { forget as forget4 } from "@xylabs/forget";
|
|
2891
2829
|
import { asArchivistInstance as asArchivistInstance6 } from "@xyo-network/archivist";
|
|
2892
2830
|
import { BaseEmitter as BaseEmitter4 } from "@xyo-network/module-abstract";
|
|
@@ -2902,7 +2840,7 @@ var NodeAdapterBase = class extends BaseEmitter4 {
|
|
|
2902
2840
|
initialized = false;
|
|
2903
2841
|
_id = "";
|
|
2904
2842
|
get id() {
|
|
2905
|
-
return
|
|
2843
|
+
return assertEx21(this._id, () => "NodeAdapterBase id not initialized");
|
|
2906
2844
|
}
|
|
2907
2845
|
async start() {
|
|
2908
2846
|
try {
|
|
@@ -2932,7 +2870,7 @@ var NodeAdapterBase = class extends BaseEmitter4 {
|
|
|
2932
2870
|
});
|
|
2933
2871
|
}
|
|
2934
2872
|
async getEventsArchivist() {
|
|
2935
|
-
const mod =
|
|
2873
|
+
const mod = assertEx21(await (await this.kernel.getNode()).resolve("KernelNode:ModuleEvents"), () => "KernelNode:ModuleEvents not found");
|
|
2936
2874
|
return asArchivistInstance6(mod, () => `${mod.id} is not an archivist`);
|
|
2937
2875
|
}
|
|
2938
2876
|
validateAndReturnDriver() {
|
|
@@ -3004,7 +2942,7 @@ var OsXyoPublicNetworkAdapters = (kernel) => [
|
|
|
3004
2942
|
];
|
|
3005
2943
|
|
|
3006
2944
|
// src/stack/OsPubSubNetworkStack.ts
|
|
3007
|
-
import { assertEx as
|
|
2945
|
+
import { assertEx as assertEx22 } from "@xylabs/assert";
|
|
3008
2946
|
import { asAttachableNodeInstance as asAttachableNodeInstance3, asNodeInstance as asNodeInstance2 } from "@xyo-network/node-model";
|
|
3009
2947
|
import { ExposedNodeOuterNodeName as ExposedNodeOuterNodeName2, PubSubBridgeNodeNodeName as PubSubBridgeNodeNodeName2 } from "@xyo-network/os-model";
|
|
3010
2948
|
var OsPubSubNetworkStack = class extends StackBase {
|
|
@@ -3026,7 +2964,7 @@ var OsPubSubNetworkStack = class extends StackBase {
|
|
|
3026
2964
|
this.on("initialized", () => this.busConnection.emit(OsPubSubNetworkReadyEvent, {}));
|
|
3027
2965
|
super.on("driverReady", async ({ node }) => {
|
|
3028
2966
|
if (node.id === PubSubBridgeNodeNodeName2) {
|
|
3029
|
-
const httpBridge =
|
|
2967
|
+
const httpBridge = assertEx22(await node.resolve("NsHttpBridge"), () => "HttpBridge not found");
|
|
3030
2968
|
const xnsNode = asNodeInstance2(await httpBridge.resolve("XNS"));
|
|
3031
2969
|
if (xnsNode) {
|
|
3032
2970
|
const initializedXns = await initializeXns(xnsNode);
|
|
@@ -3039,7 +2977,7 @@ var OsPubSubNetworkStack = class extends StackBase {
|
|
|
3039
2977
|
super.on("driverReady", async ({ node }) => {
|
|
3040
2978
|
if (node.id === ExposedNodeOuterNodeName2) {
|
|
3041
2979
|
this._exposedNodeOuter = node;
|
|
3042
|
-
const mod =
|
|
2980
|
+
const mod = assertEx22(await node.resolve("ExposedNode"), () => "ExposedNode not found");
|
|
3043
2981
|
const exposedNode = asAttachableNodeInstance3(mod, () => "ExposedNode is not a node");
|
|
3044
2982
|
this._exposedNode = exposedNode;
|
|
3045
2983
|
}
|
|
@@ -3147,7 +3085,7 @@ var XyOs = class _XyOs extends XyOsContextBase {
|
|
|
3147
3085
|
return getXyOsGlobal();
|
|
3148
3086
|
}
|
|
3149
3087
|
get bios() {
|
|
3150
|
-
return
|
|
3088
|
+
return assertEx23(this.params.kernel?.bios, () => "Missing bios");
|
|
3151
3089
|
}
|
|
3152
3090
|
get exposedNode() {
|
|
3153
3091
|
return this.stackManager.getStack("osPubSubNetworkStack")?.exposedNode;
|
|
@@ -3156,7 +3094,7 @@ var XyOs = class _XyOs extends XyOsContextBase {
|
|
|
3156
3094
|
return this.stackManager.getStack("osPubSubNetworkStack")?.exposedNodeOuter;
|
|
3157
3095
|
}
|
|
3158
3096
|
get kernel() {
|
|
3159
|
-
return
|
|
3097
|
+
return assertEx23(this.params.kernel, () => "Missing kernel");
|
|
3160
3098
|
}
|
|
3161
3099
|
get locator() {
|
|
3162
3100
|
return this._locator;
|
|
@@ -3186,7 +3124,7 @@ var XyOs = class _XyOs extends XyOsContextBase {
|
|
|
3186
3124
|
if (this.kernel?.status !== "booted") {
|
|
3187
3125
|
throw new Error("Kernel not booted");
|
|
3188
3126
|
}
|
|
3189
|
-
|
|
3127
|
+
assertEx23(this._root === void 0, () => "XyOs already booted");
|
|
3190
3128
|
const [root] = await _XyOs.monitor(async () => await loadOsNode(wallet, fullLocator), { name: "Load XyOs" });
|
|
3191
3129
|
this._root = root;
|
|
3192
3130
|
this.stackManager.initialize(this);
|
|
@@ -3203,13 +3141,13 @@ var XyOs = class _XyOs extends XyOsContextBase {
|
|
|
3203
3141
|
return this.dappRegistrationService.getParamsForRegisteredDapp(dappId);
|
|
3204
3142
|
}
|
|
3205
3143
|
getStack(stackName) {
|
|
3206
|
-
return
|
|
3144
|
+
return assertEx23(this.stackManager.getStack(stackName), () => `Stack not found: ${stackName}`);
|
|
3207
3145
|
}
|
|
3208
3146
|
async monitor(fn, eventConfig) {
|
|
3209
3147
|
return await _XyOs.monitor(fn, eventConfig);
|
|
3210
3148
|
}
|
|
3211
3149
|
shutdown() {
|
|
3212
|
-
|
|
3150
|
+
assertEx23(this._root !== void 0, () => "XyOs not booted");
|
|
3213
3151
|
this._root = void 0;
|
|
3214
3152
|
this.stackManager.stop();
|
|
3215
3153
|
}
|
|
@@ -3226,7 +3164,7 @@ var RunningDappCache = class _RunningDappCache {
|
|
|
3226
3164
|
const existingWindowDappSet = _RunningDappCache.get(dappId);
|
|
3227
3165
|
if (existingWindowDappSet) {
|
|
3228
3166
|
console.debug("[DEBUG]", `RunningDappCache, using existing node for ${dappId}`);
|
|
3229
|
-
const existingDappContext =
|
|
3167
|
+
const existingDappContext = assertEx24(existingWindowDappSet.context, () => "No context found in existing dapp node");
|
|
3230
3168
|
await DappContextCreator.primeDappArchivist(existingDappContext, xyOs, dappId);
|
|
3231
3169
|
return existingWindowDappSet;
|
|
3232
3170
|
}
|
|
@@ -3257,7 +3195,7 @@ var AccessNodeQueries = class {
|
|
|
3257
3195
|
this.registeredDappAccess = registeredDappAccess;
|
|
3258
3196
|
}
|
|
3259
3197
|
get nameServiceNamesAccessNode() {
|
|
3260
|
-
return
|
|
3198
|
+
return assertEx25(RunningDappAccessCache.get(this.registeredDappAccess.registeringDappId), () => "No access node found");
|
|
3261
3199
|
}
|
|
3262
3200
|
// Refresh the archivist in the dapp
|
|
3263
3201
|
async refresh() {
|
|
@@ -3273,7 +3211,7 @@ var AccessNodeQueries = class {
|
|
|
3273
3211
|
}
|
|
3274
3212
|
async getArchivistFromDappNode() {
|
|
3275
3213
|
const archivistPath = this.accessRequest?.destinationArchivist || "DappArchivist";
|
|
3276
|
-
const mod =
|
|
3214
|
+
const mod = assertEx25(await this.xyOsContext.root.resolve(archivistPath), () => `Unable to find archivist at ${archivistPath}`);
|
|
3277
3215
|
return asArchivistInstance7(mod, () => `Module at ${archivistPath} is not an archivist`);
|
|
3278
3216
|
}
|
|
3279
3217
|
async getPayloadsFromAccessNode() {
|
|
@@ -3286,7 +3224,7 @@ var AccessNodeQueries = class {
|
|
|
3286
3224
|
await archivist.insert(payloads);
|
|
3287
3225
|
}
|
|
3288
3226
|
async resolveArchivistFromAccessNode() {
|
|
3289
|
-
const archivist =
|
|
3227
|
+
const archivist = assertEx25(
|
|
3290
3228
|
await this.nameServiceNamesAccessNode.resolve("PublicXnsArchivist"),
|
|
3291
3229
|
() => "Unable to find archivist at PublicXnsArchivist"
|
|
3292
3230
|
);
|
|
@@ -3295,7 +3233,7 @@ var AccessNodeQueries = class {
|
|
|
3295
3233
|
};
|
|
3296
3234
|
|
|
3297
3235
|
// src/access-interfaces/registered-names/helpers/resource/AbstractXnsCaller.ts
|
|
3298
|
-
import { assertEx as
|
|
3236
|
+
import { assertEx as assertEx26 } from "@xylabs/assert";
|
|
3299
3237
|
import { asArchivistInstance as asArchivistInstance8 } from "@xyo-network/archivist-model";
|
|
3300
3238
|
import { asDivinerInstance as asDivinerInstance5 } from "@xyo-network/diviner-model";
|
|
3301
3239
|
var XnsArchivistPayloadDivinerModuleName = "XnsArchivistPayloadDiviner";
|
|
@@ -3310,7 +3248,7 @@ var AbstractXnsCaller = class {
|
|
|
3310
3248
|
*/
|
|
3311
3249
|
async getXnsArchivist(pathPrefix) {
|
|
3312
3250
|
const fullyQualifiedPath = pathPrefix ? `${pathPrefix}:${XnsArchivistModuleName}` : XnsArchivistModuleName;
|
|
3313
|
-
const mod =
|
|
3251
|
+
const mod = assertEx26(await this.context.root.resolve(fullyQualifiedPath), () => `${fullyQualifiedPath} not found`);
|
|
3314
3252
|
return asArchivistInstance8(mod, () => `${fullyQualifiedPath} is not an archivist`);
|
|
3315
3253
|
}
|
|
3316
3254
|
/**
|
|
@@ -3318,7 +3256,7 @@ var AbstractXnsCaller = class {
|
|
|
3318
3256
|
*/
|
|
3319
3257
|
async getXnsArchivistPayloadDiviner(pathPrefix) {
|
|
3320
3258
|
const fullyQualifiedPath = pathPrefix ? `${pathPrefix}:${XnsArchivistPayloadDivinerModuleName}` : XnsArchivistPayloadDivinerModuleName;
|
|
3321
|
-
const mod =
|
|
3259
|
+
const mod = assertEx26(await this.context.root.resolve(fullyQualifiedPath), () => `${fullyQualifiedPath} not found`);
|
|
3322
3260
|
return asDivinerInstance5(mod, () => `${fullyQualifiedPath} is not an diviner`);
|
|
3323
3261
|
}
|
|
3324
3262
|
/**
|
|
@@ -3326,13 +3264,13 @@ var AbstractXnsCaller = class {
|
|
|
3326
3264
|
*/
|
|
3327
3265
|
async getXnsRegistrationsArchivist(pathPrefix) {
|
|
3328
3266
|
const fullyQualifiedPath = pathPrefix ? `${pathPrefix}:${XnsRegistrationsArchivistModuleName}` : XnsRegistrationsArchivistModuleName;
|
|
3329
|
-
const mod =
|
|
3267
|
+
const mod = assertEx26(await this.context.root.resolve(fullyQualifiedPath), () => `${fullyQualifiedPath} not found`);
|
|
3330
3268
|
return asArchivistInstance8(mod, () => `${fullyQualifiedPath} is not an archivist`);
|
|
3331
3269
|
}
|
|
3332
3270
|
};
|
|
3333
3271
|
|
|
3334
3272
|
// src/access-interfaces/registered-names/helpers/resource/RegistrationsResource.ts
|
|
3335
|
-
import { assertEx as
|
|
3273
|
+
import { assertEx as assertEx27 } from "@xylabs/assert";
|
|
3336
3274
|
import { isTemporalIndexingDivinerResultIndex } from "@xyo-network/diviner-temporal-indexing-model";
|
|
3337
3275
|
|
|
3338
3276
|
// src/access-interfaces/registered-names/helpers/resource/RegistrationsResourceQueries.ts
|
|
@@ -3361,7 +3299,7 @@ var XnsRegistrationsResource = class extends AbstractXnsCaller {
|
|
|
3361
3299
|
}
|
|
3362
3300
|
_allRegistrations;
|
|
3363
3301
|
get allRegistrations() {
|
|
3364
|
-
return
|
|
3302
|
+
return assertEx27(this._allRegistrations);
|
|
3365
3303
|
}
|
|
3366
3304
|
get subscriptions() {
|
|
3367
3305
|
return { allRegistrations: (cb) => this.allRegistrations.subscribe(cb) };
|
|
@@ -3454,7 +3392,7 @@ var profileModuleEvents = (mod) => {
|
|
|
3454
3392
|
};
|
|
3455
3393
|
|
|
3456
3394
|
// src/PubSubBridgeCaller.ts
|
|
3457
|
-
import { assertEx as
|
|
3395
|
+
import { assertEx as assertEx28 } from "@xylabs/assert";
|
|
3458
3396
|
import { asBridgeInstance } from "@xyo-network/bridge-model";
|
|
3459
3397
|
import { BridgedPubSubModuleName } from "@xyo-network/os-model";
|
|
3460
3398
|
var PubSubBridgeCaller = class {
|
|
@@ -3475,7 +3413,7 @@ var PubSubBridgeCaller = class {
|
|
|
3475
3413
|
}
|
|
3476
3414
|
}
|
|
3477
3415
|
async getPubSubBridge() {
|
|
3478
|
-
const mod =
|
|
3416
|
+
const mod = assertEx28(await this.node.resolve(BridgedPubSubModuleName), () => `${BridgedPubSubModuleName} not found`);
|
|
3479
3417
|
return asBridgeInstance(mod, () => `${BridgedPubSubModuleName} is not a bridge`);
|
|
3480
3418
|
}
|
|
3481
3419
|
};
|