@xyo-network/os-runtime 3.0.14 → 3.0.16

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.
@@ -1,5 +1,5 @@
1
1
  // src/access-interfaces/registered-names/helpers/AccessNodeQueries.ts
2
- import { assertEx as assertEx26 } from "@xylabs/assert";
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 assertEx25 } from "@xylabs/assert";
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 assertEx24 } from "@xylabs/assert";
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";
@@ -524,15 +524,13 @@ import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder"
524
524
 
525
525
  // src/Caller.ts
526
526
  import { assertEx as assertEx8 } from "@xylabs/assert";
527
- import { Account } from "@xyo-network/account";
528
527
  import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema4 } from "@xyo-network/diviner-payload-model";
529
528
  import {
530
529
  DappAccessRequestSchema as DappAccessRequestSchema2,
531
530
  DappInjectableParamsSchema as DappInjectableParamsSchema2,
532
531
  DappIntentTypes,
533
532
  DappMode as DappMode2,
534
- RegisteredDappAccessSchema as RegisteredDappAccessSchema2,
535
- SigningKeySchema
533
+ RegisteredDappAccessSchema as RegisteredDappAccessSchema2
536
534
  } from "@xyo-network/os-model";
537
535
  import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
538
536
 
@@ -723,25 +721,9 @@ var DappCaller = class extends DappCallerBase {
723
721
  /**
724
722
  * Get the user wallet
725
723
  */
726
- async getUserAccount(dappName, useSigners) {
727
- const diviner = await this.getDappArchivistPayloadDiviner();
728
- const query = {
729
- dappName,
730
- limit: 1,
731
- order: "desc",
732
- schema: PayloadDivinerQuerySchema4,
733
- schemas: [SigningKeySchema]
734
- };
735
- const [payload] = assertEx8(await diviner.divine([query]), () => "Unable to find user wallet");
736
- if (payload) {
737
- console.log("*** old implementation address", await Account.fromPrivateKey(payload.privateKey));
738
- if (!useSigners) return await Account.fromPrivateKey(payload.privateKey);
739
- } else {
740
- throw new Error("Unable to find user wallet");
741
- }
742
- const account = this.context.user.signers?.get("Name Service");
724
+ getUserAccount(dappName) {
725
+ const account = this.context.user.signers?.get(dappName);
743
726
  if (account) {
744
- console.log("*** new implementation address", account);
745
727
  return account;
746
728
  } else {
747
729
  throw new Error("Unable to find user wallet");
@@ -750,19 +732,8 @@ var DappCaller = class extends DappCallerBase {
750
732
  /**
751
733
  * Get all wallets for the user
752
734
  */
753
- async getUserAccountsAll() {
754
- const diviner = await this.getDappArchivistPayloadDiviner();
755
- const query = {
756
- order: "desc",
757
- schema: PayloadDivinerQuerySchema4,
758
- schemas: [SigningKeySchema]
759
- };
760
- const payloads = assertEx8(await diviner.divine([query]), () => "Unable to find user wallet");
761
- if (payloads?.length) {
762
- return payloads;
763
- } else {
764
- throw new Error("Unable to find user wallet");
765
- }
735
+ getUserAccountsAll() {
736
+ return [...this.context.user.signers?.values() ?? []];
766
737
  }
767
738
  /**
768
739
  * Make Dapp Access Request
@@ -1007,7 +978,7 @@ var DappMenuResource = class extends DappCaller {
1007
978
  };
1008
979
 
1009
980
  // src/classes/node/createDappContext.ts
1010
- import { HDWallet as HDWallet3 } from "@xyo-network/account";
981
+ import { HDWallet as HDWallet2 } from "@xyo-network/account";
1011
982
  import { GenericPayloadDiviner } from "@xyo-network/diviner-payload-generic";
1012
983
  import { ModuleFactoryLocator as ModuleFactoryLocator2 } from "@xyo-network/module-factory-locator";
1013
984
 
@@ -1090,8 +1061,8 @@ var DappSeedPhraseRepository = class extends OsCallerBase {
1090
1061
  };
1091
1062
 
1092
1063
  // src/classes/node/Creator.ts
1093
- import { assertEx as assertEx15 } from "@xylabs/assert";
1094
- import { asArchivistInstance as asArchivistInstance4 } from "@xyo-network/archivist-model";
1064
+ import { assertEx as assertEx10 } from "@xylabs/assert";
1065
+ import { asArchivistInstance as asArchivistInstance3 } from "@xyo-network/archivist-model";
1095
1066
  import { PackageManifestPayloadSchema } from "@xyo-network/manifest";
1096
1067
 
1097
1068
  // src/manifest/ManifestReplaceableTokens.ts
@@ -1240,7 +1211,7 @@ var os_node_manifest_default = {
1240
1211
  };
1241
1212
 
1242
1213
  // src/classes/node/DefaultPayloads/DefaultPayloads.ts
1243
- import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
1214
+ import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
1244
1215
 
1245
1216
  // src/classes/node/DefaultPayloads/DappAccessPayloads.ts
1246
1217
  var DappAccessPayloads = class {
@@ -1276,917 +1247,559 @@ var NodeInfoPayload = class {
1276
1247
  }
1277
1248
  };
1278
1249
 
1279
- // src/classes/node/DefaultPayloads/SigningKeyPayloads.ts
1280
- import { assertEx as assertEx14 } from "@xylabs/assert";
1281
- import { hexFrom } from "@xylabs/hex";
1282
- import { HDWallet as HDWallet2 } from "@xyo-network/account";
1283
- import { mnemonicArrayToString, SigningKeySchema as SigningKeySchema2 } from "@xyo-network/os-model";
1284
- import { isAnyPayload as isAnyPayload2 } from "@xyo-network/payload-model";
1285
-
1286
- // src/classes/settings/badge/Caller.ts
1287
- import { OsBadgeSchema as OsBadgeSchema2 } from "@xyo-network/os-model";
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
+ };
1288
1272
 
1289
- // src/classes/settings/CallerBase.ts
1290
- import { assertEx as assertEx10 } from "@xylabs/assert";
1291
- import { asArchivistInstance as asArchivistInstance3 } from "@xyo-network/archivist-model";
1292
- import { asDivinerInstance as asDivinerInstance4 } from "@xyo-network/diviner-model";
1293
- var OsSettingsArchivistModuleName = "OsSettingsNode:OsSettingsArchivist";
1294
- var OsSettingsArchivistPayloadDivinerModuleName = "OsSettingsNode:OsSettingsArchivistPayloadDiviner";
1295
- var OsSettingsCallerBase = class {
1296
- 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) {
1297
1277
  this.context = context;
1278
+ this.dappWindowNode = dappWindowNode;
1279
+ this.dappName = dappName;
1280
+ this.externalPermissions = externalPermissions;
1298
1281
  }
1299
- async getOsSettingsArchivist() {
1300
- const mod = assertEx10(await this.context.root.resolve(OsSettingsArchivistModuleName), () => `${OsSettingsArchivistModuleName} not found`);
1301
- return asArchivistInstance3(mod, () => `${OsSettingsArchivistModuleName} is not an archivist`);
1282
+ async permit() {
1283
+ for (const permission of this.externalPermissions ?? []) {
1284
+ await this.permitExternalModule(permission);
1285
+ }
1302
1286
  }
1303
- async getOsSettingsPayloadDiviner() {
1304
- const mod = assertEx10(
1305
- await this.context.root.resolve(OsSettingsArchivistPayloadDivinerModuleName),
1306
- () => `${OsSettingsArchivistPayloadDivinerModuleName} not found`
1307
- );
1308
- return asDivinerInstance4(mod, () => `${OsSettingsArchivistPayloadDivinerModuleName} is not a diviner`);
1287
+ getExternalModuleName(permission) {
1288
+ return permission.name;
1309
1289
  }
1310
- };
1311
-
1312
- // src/classes/settings/badge/Queries.ts
1313
- import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema8 } from "@xyo-network/diviner-payload-model";
1314
- import { OsBadgeSchema } from "@xyo-network/os-model";
1315
- var OsBadgeQueries = {
1316
- getBadge: async (achievement, diviner) => {
1317
- const query = {
1318
- achievement,
1319
- limit: 1,
1320
- order: "desc",
1321
- schema: PayloadDivinerQuerySchema8,
1322
- schemas: [OsBadgeSchema]
1323
- };
1324
- 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
+ }
1325
1298
  }
1326
- };
1327
-
1328
- // src/classes/settings/badge/Caller.ts
1329
- var OsBadgeCaller = class extends OsSettingsCallerBase {
1330
- /**
1331
- * @param {ValidOsAchievements} achievement
1332
- */
1333
- async getBadge(achievement) {
1334
- const diviner = await this.getOsSettingsPayloadDiviner();
1335
- const results = await OsBadgeQueries.getBadge(achievement, diviner);
1336
- 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
+ }
1337
1304
  }
1338
- /**
1339
- * @param {ValidOsAchievements} achievement
1340
- */
1341
- async saveBadge(achievement) {
1342
- const badge = {
1343
- achievement,
1344
- schema: OsBadgeSchema2,
1345
- timestamp: Date.now()
1346
- };
1347
- const archivist = await this.getOsSettingsArchivist();
1348
- return await archivist.insert([badge]);
1305
+ async resolveExternalModule(id) {
1306
+ return await this.context.root.resolve(id);
1349
1307
  }
1350
1308
  };
1351
1309
 
1352
- // src/classes/settings/badge/Resource.ts
1353
- import { assertEx as assertEx11 } from "@xylabs/assert";
1354
- import { isBadgeWithMeta } from "@xyo-network/os-model";
1355
- var OsBadgeResource = class extends OsSettingsCallerBase {
1356
- static views = ["savedSeedPhrase"];
1357
- _savedSeedPhrase;
1358
- constructor(xyOsContext) {
1359
- super(xyOsContext);
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;
1360
1319
  }
1361
- get savedSeedPhrase() {
1362
- return assertEx11(this._savedSeedPhrase, () => "Saved seed phrase listener not set");
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;
1363
1341
  }
1364
- get subscriptions() {
1365
- return { savedSeedPhrase: (cb) => this.savedSeedPhrase.subscribe(cb) };
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();
1366
1348
  }
1367
- get views() {
1368
- return { savedSeedPhrase: () => this.savedSeedPhrase.latest };
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();
1369
1354
  }
1370
- cleanupListeners() {
1371
- this.savedSeedPhrase.cleanupListeners();
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 };
1372
1363
  }
1373
- /**
1374
- * start listeners
1375
- **/
1376
- async start() {
1377
- const diviner = await this.getOsSettingsPayloadDiviner();
1378
- const archivist = await this.getOsSettingsArchivist();
1379
- this._savedSeedPhrase = await PayloadStore.create({
1380
- archivist,
1381
- getLatest: async () => await OsBadgeQueries.getBadge("savedSeedPhrase", diviner),
1382
- idFunction: isBadgeWithMeta
1383
- });
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;
1374
+ }
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();
1384
1379
  }
1385
1380
  };
1386
1381
 
1387
- // src/classes/settings/Caller.ts
1388
- import { assertEx as assertEx12 } from "@xylabs/assert";
1389
- import { isEqual } from "@xylabs/lodash";
1390
-
1391
- // src/utils/buildWalletSeedPhrasePayload.ts
1392
- import { WalletSeedPhraseSchema } from "@xyo-network/os-model";
1393
- import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
1394
- var language = "english";
1395
- var standard = "bip-39";
1396
- var userWalletLabel = "userWallet";
1397
- var buildWalletSeedPhrasePayload = async (mnemonic, label) => {
1398
- const fields = {
1399
- mnemonic: {
1400
- language,
1401
- mnemonic: mnemonic.split(" "),
1402
- standard
1403
- }
1404
- };
1405
- const meta = { label, timestamp: Date.now() };
1406
- const builder = new PayloadBuilder4({
1407
- fields,
1408
- meta,
1409
- schema: WalletSeedPhraseSchema
1410
- });
1411
- const payload = await builder.build();
1412
- const rootHash = await PayloadBuilder4.hash(payload);
1413
- return { payload, rootHash };
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;
1414
1388
  };
1415
- var buildUserWalletSeedPhrasePayload = (mnemonic) => {
1416
- return buildWalletSeedPhrasePayload(mnemonic, userWalletLabel);
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
1406
+ };
1407
+ const dappContextCreator = await DappContextCreator.create(params, xnsNodeUrl, xnsNetwork);
1408
+ const dappContext = await dappContextCreator.loadDappContext(context);
1409
+ return {
1410
+ context: dappContext,
1411
+ dappWallet: wallet
1412
+ };
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}`);
1418
+ }
1417
1419
  };
1418
1420
 
1419
- // src/utils/getApiDomain.ts
1420
- var getApiDomain = (scope, apiDomain) => {
1421
- if (apiDomain !== void 0) {
1422
- return apiDomain;
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";
1431
+
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;
1423
1443
  }
1424
- if (scope === "localhost") {
1425
- return "http://localhost:8080";
1444
+ get id() {
1445
+ return assertEx11(this._id, () => "Connection ID not set. Did you forget to call buildConnection()?");
1426
1446
  }
1427
- if (scope === "beta") {
1428
- return "https://beta.archivist.xyo.network";
1447
+ buildConnection(id) {
1448
+ this._id = id;
1429
1449
  }
1430
- return "https://archivist.xyo.network";
1431
1450
  };
1432
1451
 
1433
- // src/utils/renameObjKey.ts
1434
- var renameObjKey = (oldObj, oldKey, newKey) => {
1435
- const oldObjKeys = Object.keys(oldObj);
1436
- const newObj = oldObjKeys.reduce(
1437
- (acc, val) => {
1438
- if (val === oldKey) {
1439
- acc[newKey] = oldObj[oldKey];
1440
- } else {
1441
- acc[val] = oldObj[val];
1442
- }
1443
- return acc;
1444
- },
1445
- {}
1446
- );
1447
- return newObj;
1448
- };
1449
-
1450
- // src/classes/settings/SettingsQueries.ts
1451
- import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema9 } from "@xyo-network/diviner-payload-model";
1452
- import { NodeBackgroundSchema, WalletSeedPhraseSchema as WalletSeedPhraseSchema2 } from "@xyo-network/os-model";
1453
- var NO_RESULTS2 = [];
1454
- var OsSettingsQueries = {
1455
- async getLatestUserWallet(diviner) {
1456
- const query = {
1457
- limit: 1,
1458
- order: "desc",
1459
- schema: PayloadDivinerQuerySchema9,
1460
- schemas: [WalletSeedPhraseSchema2]
1461
- };
1462
- const results = await diviner.divine([query]);
1463
- const wallet = results.find((payload) => payload.$meta.label === "userWallet");
1464
- return wallet ? [wallet] : NO_RESULTS2;
1465
- },
1466
- async getNodeBackground(diviner) {
1467
- const query = {
1468
- limit: 1,
1469
- order: "desc",
1470
- schema: PayloadDivinerQuerySchema9,
1471
- schemas: [NodeBackgroundSchema]
1472
- };
1473
- return await diviner.divine([query]);
1474
- },
1475
- async getWallets(diviner) {
1476
- const query = {
1477
- order: "desc",
1478
- schema: PayloadDivinerQuerySchema9,
1479
- schemas: [WalletSeedPhraseSchema2]
1480
- };
1481
- return await diviner.divine([query]);
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
+ );
1482
1480
  }
1483
- };
1484
-
1485
- // src/classes/settings/Caller.ts
1486
- var OsSettingsCaller = class extends OsSettingsCallerBase {
1487
- constructor(context) {
1488
- super(context);
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");
1489
+ }
1490
+ return connection;
1489
1491
  }
1490
- /**
1491
- * Add a node background to the settings
1492
- * @param {WithMeta<NodeBackground>} payload
1493
- */
1494
- async addNodeBackground(payload) {
1495
- const archivist = await this.getOsSettingsArchivist();
1496
- await archivist.insert([payload]);
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);
1499
+ }
1500
+ delete this.connections[connectionId];
1497
1501
  }
1498
- /**
1499
- * Add a wallet seed phrase to the settings
1500
- * @param {WalletSeedPhrase} payload
1501
- */
1502
- async addWalletSeedPhrase(payload) {
1503
- const archivist = await this.getOsSettingsArchivist();
1504
- await archivist.insert([payload]);
1505
- const phrase = payload.mnemonic.mnemonic.join(" ");
1506
- await this.context.kernel?.bios?.seedPhraseStore.set("user", phrase);
1502
+ async start(storeName = "EventBusArchivist") {
1503
+ return await this.startMutex.runExclusive(async () => {
1504
+ if (this._archivist) {
1505
+ console.warn("EventBus already started");
1506
+ return this;
1507
+ }
1508
+ this._archivist = await MemoryArchivist.create({ config: { name: storeName, schema: MemoryArchivistConfigSchema } });
1509
+ this.archivist.on("inserted", ({ payloads }) => {
1510
+ const eventBusEvent = payloads.find(isEventBusEvent);
1511
+ if (!eventBusEvent) return;
1512
+ for (const connectionId in this.connections) {
1513
+ const connection = this.connections[connectionId];
1514
+ if (isPubSubConnections(connection) && connection.subscribableEvents) {
1515
+ for (const [eventName, callback] of connection.subscribableEvents.entries()) {
1516
+ if (eventName !== eventBusEvent.name) continue;
1517
+ if (callback) {
1518
+ const forgettable = async () => await callback({ payloads });
1519
+ forget(forgettable());
1520
+ }
1521
+ }
1522
+ }
1523
+ }
1524
+ });
1525
+ return this;
1526
+ });
1507
1527
  }
1508
- /**
1509
- * Get the latest node background
1510
- */
1511
- async getLatestNodeBackground() {
1512
- const diviner = await this.getOsSettingsPayloadDiviner();
1513
- const [result] = await OsSettingsQueries.getNodeBackground(diviner);
1514
- return result ?? null;
1528
+ handlePublisherAdd(connection) {
1529
+ for (const eventName of connection.publishableEvents ?? []) {
1530
+ const connectionPublisherCallback = async ({ payloads }) => {
1531
+ const event = { name: eventName, schema: "network.xyo.event.bus.event" };
1532
+ const eventPayloads = payloads ?? [];
1533
+ event.sources = await PayloadBuilder5.dataHashes(eventPayloads);
1534
+ try {
1535
+ await this.archivist.insert([event, ...payloads ?? []]);
1536
+ } catch (e) {
1537
+ console.error("Error inserting event into archivist", e);
1538
+ }
1539
+ };
1540
+ connection.on(eventName, connectionPublisherCallback);
1541
+ const callbackId = connection.id + eventName;
1542
+ this.publisherCallbacks[callbackId] = connectionPublisherCallback;
1543
+ }
1515
1544
  }
1516
- async getLatestUserWallet() {
1517
- const diviner = await this.getOsSettingsPayloadDiviner();
1518
- const storedSeedPhrasePayload = (await OsSettingsQueries.getLatestUserWallet(diviner)).pop();
1519
- const biosWalletSeedPhrase = assertEx12(await this.context.kernel?.bios?.seedPhraseStore.get("user"), () => "No user seed phrase found from BIOS");
1520
- const biosWalletSeedPhraseParts = biosWalletSeedPhrase.split(" ");
1521
- if (!storedSeedPhrasePayload?.mnemonic?.mnemonic) {
1522
- const { payload: biosSeedPhrasePayload } = await buildUserWalletSeedPhrasePayload(biosWalletSeedPhrase);
1523
- await this.addWalletSeedPhrase(biosSeedPhrasePayload);
1524
- return biosSeedPhrasePayload;
1525
- } else if (!isEqual(storedSeedPhrasePayload.mnemonic.mnemonic, biosWalletSeedPhraseParts)) {
1526
- const updatedBiosSeedPhrase = storedSeedPhrasePayload.mnemonic.mnemonic.join(" ");
1527
- await this.context.kernel?.bios?.seedPhraseStore.set("user", updatedBiosSeedPhrase);
1545
+ handlePublisherRemove(connection) {
1546
+ for (const [, event] of connection.publishableEvents?.entries() ?? []) {
1547
+ const id = connection.id + event;
1548
+ const callback = this.publisherCallbacks[id];
1549
+ if (callback) connection.off(event, callback);
1528
1550
  }
1529
- return storedSeedPhrasePayload;
1530
1551
  }
1531
1552
  };
1532
1553
 
1533
- // src/classes/settings/Resource.ts
1534
- import { assertEx as assertEx13 } from "@xylabs/assert";
1535
- import { isNodeBackground, isWalletSeedPhrase } from "@xyo-network/os-model";
1536
- var OsSettingsResource = class extends OsSettingsCallerBase {
1537
- _latestUserWalletListener;
1538
- _nodeBackgroundListener;
1539
- _walletsListener;
1540
- constructor(context) {
1541
- super(context);
1542
- }
1543
- get latestUserWalletListener() {
1544
- return assertEx13(this._latestUserWalletListener, () => "Latest user wallet listener not set");
1545
- }
1546
- get nodeBackgroundListener() {
1547
- return assertEx13(this._nodeBackgroundListener, () => "Node background listener not set");
1554
+ // src/event/bus/PubSubConnection.ts
1555
+ var EventBusPubSubConnection = class extends EventBusConnection {
1556
+ publishableEvents;
1557
+ subscribableEvents;
1558
+ constructor(request) {
1559
+ super(request);
1560
+ if (request.type !== "PubSub") {
1561
+ throw new Error("Invalid connection type. Must be PubSub");
1562
+ }
1563
+ this.publishableEvents = request.publishableEvents;
1564
+ this.subscribableEvents = request.subscribableEvents;
1548
1565
  }
1549
- get subscriptions() {
1550
- return {
1551
- latestUserWallet: (cb) => this.walletsListener.subscribe(cb),
1552
- nodeBackground: (cb) => this.nodeBackgroundListener.subscribe(cb),
1553
- wallets: (cb) => this.walletsListener.subscribe(cb)
1554
- };
1566
+ };
1567
+
1568
+ // src/event/connections/DappAccessRequest.ts
1569
+ var DappAccessRequestEvent = "dappAccessRequest";
1570
+ var dappAccessRequestConnectionRequest = {
1571
+ publishableEvents: [DappAccessRequestEvent],
1572
+ type: "PubSub"
1573
+ };
1574
+ var dappAccessRequestConnection = () => new EventBusPubSubConnection(dappAccessRequestConnectionRequest);
1575
+
1576
+ // src/event/connections/DappsReady.ts
1577
+ var dappsReadyConnectionRequest = {
1578
+ publishableEvents: ["dappsReady"],
1579
+ type: "PubSub"
1580
+ };
1581
+ var dappsReadyConnection = () => new EventBusPubSubConnection(dappsReadyConnectionRequest);
1582
+
1583
+ // src/event/connections/ExposeDappRequest.ts
1584
+ var ExposeDappRequestEvent = "exposeDappRequest";
1585
+ var exposeDappConnectionRequest = {
1586
+ publishableEvents: [ExposeDappRequestEvent],
1587
+ type: "PubSub"
1588
+ };
1589
+ var exposeDappRequestConnection = () => new EventBusPubSubConnection(exposeDappConnectionRequest);
1590
+
1591
+ // src/event/connections/OsPubSubNetworkReady.ts
1592
+ var OsPubSubNetworkReadyEvent = "osPubSubNetworkReady";
1593
+ var osPubSubNetworkConnectionRequest = {
1594
+ publishableEvents: [OsPubSubNetworkReadyEvent],
1595
+ type: "PubSub"
1596
+ };
1597
+ var osPubSubNetworkReadyConnection = () => new EventBusPubSubConnection(osPubSubNetworkConnectionRequest);
1598
+
1599
+ // src/event/connections/OsSettingsReady.ts
1600
+ var OsSettingsReadyEvent = "osSettingsReady";
1601
+ var osSettingsConnectionRequest = {
1602
+ publishableEvents: [OsSettingsReadyEvent],
1603
+ type: "PubSub"
1604
+ };
1605
+ var osSettingsReadyConnection = () => new EventBusPubSubConnection(osSettingsConnectionRequest);
1606
+
1607
+ // src/event/connections/OsXyoPublicReady.ts
1608
+ var OsXyoPublicNetworkReadyEvent = "osXyoPublicNetworkReady";
1609
+ var osXyoPublicNetworkConnectionRequest = {
1610
+ publishableEvents: [OsXyoPublicNetworkReadyEvent],
1611
+ type: "PubSub"
1612
+ };
1613
+ var osXyoPublicNetworkReadyConnection = () => new EventBusPubSubConnection(osXyoPublicNetworkConnectionRequest);
1614
+
1615
+ // src/XyOsDapp.ts
1616
+ import { assertEx as assertEx14 } from "@xylabs/assert";
1617
+ import { ManifestWrapper } from "@xyo-network/manifest-wrapper";
1618
+ import { ModuleFactoryLocator as ModuleFactoryLocator4 } from "@xyo-network/module-factory-locator";
1619
+ import { DappPackageManifestPayloadSchema } from "@xyo-network/os-model";
1620
+
1621
+ // src/manifests/dapp-window.manifest.json
1622
+ var dapp_window_manifest_default = {
1623
+ $schema: "https://raw.githubusercontent.com/XYOracleNetwork/sdk-xyo-client-js/main/packages/manifest/src/compilations/dapp-package-manifest-schema.json",
1624
+ nodes: [
1625
+ {
1626
+ config: {
1627
+ accountPath: "0'",
1628
+ name: "Dapp",
1629
+ schema: "network.xyo.node.config"
1630
+ },
1631
+ modules: {
1632
+ private: [],
1633
+ public: [
1634
+ {
1635
+ config: {
1636
+ accountPath: "0'/0'",
1637
+ name: "DappArchivist",
1638
+ schema: "network.xyo.archivist.memory.config"
1639
+ }
1640
+ },
1641
+ {
1642
+ config: {
1643
+ accountPath: "0'/1'",
1644
+ archivist: "DappArchivist",
1645
+ labels: {
1646
+ "network.xyo.generic.payload.diviner": "GenericPayloadDiviner"
1647
+ },
1648
+ name: "DappArchivistPayloadDiviner",
1649
+ schema: "network.xyo.diviner.payload.config"
1650
+ }
1651
+ }
1652
+ ]
1653
+ }
1654
+ }
1655
+ ],
1656
+ schema: "network.xyo.manifest.package.dapp"
1657
+ };
1658
+
1659
+ // src/XyOsBase.ts
1660
+ import { assertEx as assertEx13 } from "@xylabs/assert";
1661
+ import { BaseEmitter as BaseEmitter2 } from "@xyo-network/module-abstract";
1662
+ import { ModuleFactoryLocator as ModuleFactoryLocator3 } from "@xyo-network/module-factory-locator";
1663
+ import { Mutex as Mutex2 } from "async-mutex";
1664
+ var XyOsContextBase = class extends BaseEmitter2 {
1665
+ _bootMutex = new Mutex2();
1666
+ _platformLocator;
1667
+ _root;
1668
+ get bios() {
1669
+ return this.kernel?.bios;
1555
1670
  }
1556
- get views() {
1557
- return {
1558
- latestUserWallet: () => this.latestUserWalletListener.latest,
1559
- nodeBackground: () => this.nodeBackgroundListener.latest,
1560
- wallets: () => this.walletsListener.latest
1561
- };
1671
+ get eventBus() {
1672
+ return assertEx13(this.params.eventBus, () => "Missing event bus");
1562
1673
  }
1563
- get walletsListener() {
1564
- return assertEx13(this._walletsListener, () => "Wallets listener not set");
1674
+ get exposedNode() {
1675
+ throw new Error("Method not implemented. [exposedNode]");
1565
1676
  }
1566
- cleanupListeners() {
1567
- this.walletsListener.cleanupListeners();
1568
- this.latestUserWalletListener.cleanupListeners();
1677
+ get exposedNodeOuter() {
1678
+ throw new Error("Method not implemented. [exposedNodeOuter]");
1569
1679
  }
1570
- /**
1571
- * start listeners
1572
- */
1573
- async start() {
1574
- const archivist = await this.getOsSettingsArchivist();
1575
- const diviner = await this.getOsSettingsPayloadDiviner();
1576
- this._walletsListener = await PayloadStore.create({
1577
- archivist,
1578
- getLatest: async () => await OsSettingsQueries.getWallets(diviner),
1579
- idFunction: isWalletSeedPhrase
1580
- });
1581
- this._latestUserWalletListener = await PayloadStore.create({
1582
- archivist,
1583
- getLatest: async () => await OsSettingsQueries.getLatestUserWallet(diviner),
1584
- idFunction: isWalletSeedPhrase
1585
- });
1586
- this._nodeBackgroundListener = await PayloadStore.create({
1587
- archivist,
1588
- getLatest: async () => await OsSettingsQueries.getNodeBackground(diviner),
1589
- idFunction: isNodeBackground
1590
- });
1680
+ get installedDapps() {
1681
+ return [];
1591
1682
  }
1592
- };
1593
-
1594
- // src/classes/node/DefaultPayloads/SigningKeyPayloads.ts
1595
- var DappsWithAdditionalPayloads = /* @__PURE__ */ new Set(["Profile"]);
1596
- var DefaultName = "Name Service";
1597
- var DEFAULT_DAPP_ACCOUNT_PATHS = { [DefaultName]: "1'/1" };
1598
- var ADDITIONAL_DAPP_ACCOUNT_PATHS = { ["Profile"]: { [DefaultName]: DEFAULT_DAPP_ACCOUNT_PATHS[DefaultName] } };
1599
- var SigningKeyPayloads = class {
1600
- constructor(context, dappName) {
1601
- this.context = context;
1602
- this.dappName = dappName;
1683
+ get kernel() {
1684
+ return void 0;
1603
1685
  }
1604
- async payloads() {
1605
- const wallet = await this.resolveUserWallet();
1606
- const defaultDappAccountSigningKeyPayloads = await this.signingKeyPayload(wallet, this.dappName, DEFAULT_DAPP_ACCOUNT_PATHS[this.dappName]);
1607
- const additionalDappAccountSigningKeyPayloads = [];
1608
- for (const [dappName, accountPaths] of Object.entries(ADDITIONAL_DAPP_ACCOUNT_PATHS)) {
1609
- if (dappName !== this.dappName || !DappsWithAdditionalPayloads.has(dappName)) continue;
1610
- for (const additionalDappAccountName of Object.keys(accountPaths)) {
1611
- const signingKeyPayload = await this.signingKeyPayload(wallet, additionalDappAccountName, accountPaths[additionalDappAccountName]);
1612
- additionalDappAccountSigningKeyPayloads.push(signingKeyPayload);
1613
- }
1614
- }
1615
- return [...additionalDappAccountSigningKeyPayloads, defaultDappAccountSigningKeyPayloads].filter(isAnyPayload2);
1686
+ get manifest() {
1687
+ return assertEx13(this.params.manifest, () => "Missing manifest");
1616
1688
  }
1617
- async resolveUserWallet() {
1618
- const settingsCaller = new OsSettingsCaller(this.context);
1619
- const latestWallet = await settingsCaller.getLatestUserWallet();
1620
- const phrase = mnemonicArrayToString(latestWallet.mnemonic.mnemonic);
1621
- const assertedPhrase = assertEx14(phrase, () => "No phrase found in latest wallet");
1622
- return await HDWallet2.fromPhrase(assertedPhrase);
1689
+ get platformLocator() {
1690
+ this._platformLocator = this._platformLocator ?? this.params.platformLocator ?? new ModuleFactoryLocator3();
1691
+ return this._platformLocator;
1623
1692
  }
1624
- async signingKeyPayload(wallet, name, path) {
1625
- if (path) {
1626
- const subAccount = await wallet.derivePath(path);
1627
- const privateKey = hexFrom(subAccount.privateKey, { prefix: false });
1628
- return {
1629
- dappName: name,
1630
- privateKey,
1631
- schema: SigningKeySchema2
1632
- };
1633
- }
1693
+ get possibleRoot() {
1694
+ return this._root;
1634
1695
  }
1635
- };
1636
-
1637
- // src/classes/node/DefaultPayloads/DefaultPayloads.ts
1638
- var DefaultPayloads = class {
1639
- constructor(dappArchivist, xyOs, dappName) {
1640
- this.dappArchivist = dappArchivist;
1641
- this.xyOs = xyOs;
1642
- this.dappName = dappName;
1696
+ get root() {
1697
+ return assertEx13(this._root, () => "XyOs root not set (probably not yet booted)");
1643
1698
  }
1644
- async insert() {
1645
- const insertables = [NodeInfoPayload, SigningKeyPayloads, DappAccessPayloads];
1646
- const insertPayloads = [];
1647
- for (const insertable of insertables) {
1648
- const classInstance = createInsertable(insertable, this.xyOs, this.dappName);
1649
- const payloads = await classInstance.payloads();
1650
- insertPayloads.push(...payloads);
1651
- }
1652
- for (const payload of insertPayloads) {
1653
- const [existing] = await this.dappArchivist.get([await PayloadBuilder5.dataHash(payload)]);
1654
- if (existing) continue;
1655
- await this.dappArchivist.insert([payload]);
1656
- }
1699
+ get runningDapps() {
1700
+ return [];
1657
1701
  }
1658
- };
1659
-
1660
- // src/classes/node/ExternalModulePermissions/ExternalModulePermissions.ts
1661
- var ALLOWED_MODULES_FROM_PARENT = ["IntentArchivist", "OsSettingsNode", "OsPubSubNetworkStackNode", "OsXyoPublicNetworkStackNode"];
1662
- var ExternalModulePermissions = class {
1663
- constructor(context, dappWindowNode, dappName, externalPermissions) {
1664
- this.context = context;
1665
- this.dappWindowNode = dappWindowNode;
1666
- this.dappName = dappName;
1667
- this.externalPermissions = externalPermissions;
1702
+ get signerPaths() {
1703
+ return this.params.signerPaths;
1668
1704
  }
1669
- async permit() {
1670
- for (const permission of this.externalPermissions ?? []) {
1671
- await this.permitExternalModule(permission);
1672
- }
1705
+ get state() {
1706
+ return this._root ? "running" : "stopped";
1673
1707
  }
1674
- getExternalModuleName(permission) {
1675
- return permission.name;
1708
+ get user() {
1709
+ throw new Error("Method not implemented. [user]");
1676
1710
  }
1677
- async permitExternalModule(externalPermission) {
1678
- const externalModuleName = this.getExternalModuleName(externalPermission);
1679
- if (ALLOWED_MODULES_FROM_PARENT.includes(externalModuleName)) {
1680
- const mod = await this.resolveExternalModule(externalModuleName);
1681
- await this.registerAndAttachModule(mod);
1682
- } else {
1683
- console.warn(`${this.dappName} requested ${externalModuleName} but it was not fulfilled`);
1684
- }
1711
+ boot(_wallet, _locator) {
1712
+ throw new Error("Method not implemented. [boot]");
1685
1713
  }
1686
- async registerAndAttachModule(mod) {
1687
- if (mod) {
1688
- await this.dappWindowNode.register?.(mod);
1689
- await this.dappWindowNode.attach(mod.address, true);
1690
- }
1714
+ buildDapp(_manifest, _dappId) {
1715
+ throw new Error("Method not implemented. [buildDapp]");
1691
1716
  }
1692
- async resolveExternalModule(id) {
1693
- return await this.context.root.resolve(id);
1717
+ dappByName(_dappId) {
1718
+ throw new Error("Method not implemented. [runningDapp]");
1694
1719
  }
1695
- };
1696
-
1697
- // src/classes/node/Creator.ts
1698
- var DappContextCreator = class _DappContextCreator {
1699
- constructor(targetDappManifestParams, dappId, context, rootWallet, externalPermissions, sharedLocator) {
1700
- this.targetDappManifestParams = targetDappManifestParams;
1701
- this.dappId = dappId;
1702
- this.context = context;
1703
- this.rootWallet = rootWallet;
1704
- this.externalPermissions = externalPermissions;
1705
- this.sharedLocator = sharedLocator;
1720
+ getDappParams(_dappId) {
1721
+ throw new Error("Method not implemented. [getDappParams]");
1706
1722
  }
1707
- // Designated offset path for the wallet used by windowed dapps. In the future, other offsets could be used for other dapp modes
1708
- static DAPP_WINDOW_WALLET_PATH = "1";
1709
- static async create(params, xnsNodeUrl, xnsNetwork) {
1710
- const {
1711
- config,
1712
- locator,
1713
- context,
1714
- wallet
1715
- } = params;
1716
- const {
1717
- payload,
1718
- dappName,
1719
- publicChildren,
1720
- privateChildren
1721
- } = config;
1722
- const { external, manifestPayload } = this.parseDappPackageManifestPayload(payload, xnsNodeUrl, xnsNetwork);
1723
- console.debug("[DEBUG] dApp manifest", manifestPayload);
1724
- const dappWallet = await wallet.derivePath(_DappContextCreator.DAPP_WINDOW_WALLET_PATH);
1725
- const targetDappManifestParams = [manifestPayload, dappWallet, locator, publicChildren, privateChildren];
1726
- const instance = new this(targetDappManifestParams, dappName, context, wallet, external?.modules, locator);
1727
- return instance;
1723
+ getStack(_stackName) {
1724
+ throw new Error("Method not implemented. [getStack]");
1728
1725
  }
1729
- // Add default payloads to the archivist shared between the os and the dapp
1730
- static async primeDappArchivist(dappContext, osContext, dappName) {
1731
- const dappCaller = new DappCallerBase(dappContext);
1732
- const dappArchivist = await dappCaller.getDappArchivist();
1733
- const defaultPayloads = new DefaultPayloads(dappArchivist, osContext, dappName);
1734
- await defaultPayloads.insert();
1726
+ installDapp(_dappId) {
1727
+ throw new Error("Method not implemented. [installDapp]");
1735
1728
  }
1736
- // Reset the dapp archivist to remove all payloads
1737
- static async resetDappArchivist(context) {
1738
- const dappModule = await context.root.resolve("DappArchivist");
1739
- const dappArchivist = assertEx15(asArchivistInstance4(dappModule), () => "resetDappArchivist: DappArchivist not found");
1740
- await dappArchivist.clear();
1729
+ monitor(_fn, _eventConfig) {
1730
+ throw new Error("Method not implemented. [monitor]");
1741
1731
  }
1742
- static parseDappPackageManifestPayload(payload, xnsNodeUrl, xnsNetwork) {
1743
- const { external, ...manifestWithoutExternals } = payload;
1744
- const manifestPayloadRaw = {
1745
- ...manifestWithoutExternals,
1746
- schema: PackageManifestPayloadSchema
1747
- };
1748
- const manifestPayload = ReplaceManifestTokens(manifestPayloadRaw, xnsNodeUrl, xnsNetwork);
1749
- return { external, manifestPayload };
1732
+ shutdown() {
1733
+ throw new Error("Method not implemented. [shutdown]");
1750
1734
  }
1751
- async loadDappContext(context) {
1752
- console.log("DappNodesCreator:loadDappContext", this.dappId);
1753
- const dapp = await context.dappByName(this.dappId) ?? await (async () => {
1754
- const dapp2 = await context.buildDapp(this.targetDappManifestParams[0], this.dappId);
1755
- await dapp2.boot(this.rootWallet, this.sharedLocator);
1756
- return dapp2;
1757
- })();
1758
- await this.handleExternalModulePermissions(dapp.root);
1759
- await _DappContextCreator.primeDappArchivist(dapp, this.context, this.dappId);
1760
- return dapp;
1735
+ startDapp(_dappId) {
1736
+ throw new Error("Method not implemented. [startDapp]");
1761
1737
  }
1762
- // try to satisfy the external permissions requested by a dapp
1763
- async handleExternalModulePermissions(dappWindowNode) {
1764
- const externalModulePermissions = new ExternalModulePermissions(this.context, dappWindowNode, this.dappId, this.externalPermissions);
1765
- await externalModulePermissions.permit();
1738
+ stopDapp(_dappId) {
1739
+ throw new Error("Method not implemented. [stopDapp]");
1766
1740
  }
1767
- };
1768
-
1769
- // src/classes/node/createDappContext.ts
1770
- var GenericPayloadDivinerTags = { "network.xyo.generic.payload.diviner": "GenericPayloadDiviner" };
1771
- var resolveLocator = (existingLocator) => {
1772
- const locator = existingLocator ?? new ModuleFactoryLocator2();
1773
- locator.register(GenericPayloadDiviner, GenericPayloadDivinerTags);
1774
- return locator;
1775
- };
1776
- var createDappContext = async (dapp, context, allowedNames, xnsNodeUrl, xnsNetwork) => {
1777
- console.log("createNodes");
1778
- try {
1779
- const dappSeedPhraseRepository = new DappSeedPhraseRepository(context, allowedNames);
1780
- const seedPhrase = await dappSeedPhraseRepository.request(dapp.config.walletId);
1781
- if (!seedPhrase) {
1782
- throw new Error(`unable to find seed phrase for walletId: ${JSON.stringify(dapp.config, null, 2)}`);
1783
- }
1784
- const wallet = await HDWallet3.fromPhrase(seedPhrase);
1785
- const dappName = dapp.config.name;
1786
- const { config: dappConfig, params: dappParams } = dapp;
1787
- const locator = resolveLocator((dappParams.locator ?? new ModuleFactoryLocator2()).merge(context.platformLocator));
1788
- const params = {
1789
- config: { dappName, payload: dappConfig.manifest },
1790
- context,
1791
- locator,
1792
- wallet
1793
- };
1794
- const dappContextCreator = await DappContextCreator.create(params, xnsNodeUrl, xnsNetwork);
1795
- const dappContext = await dappContextCreator.loadDappContext(context);
1796
- return {
1797
- context: dappContext,
1798
- dappWallet: wallet
1799
- };
1800
- } catch (e) {
1801
- const error = e;
1802
- console.error(`Error creating dappWindow node: ${error.message}`);
1803
- console.error(`Error creating dappWindow node: ${error.stack}`);
1804
- throw new Error(`Error creating dappWindow node: ${error.message}`);
1741
+ uninstallDapp(_dappId) {
1742
+ throw new Error("Method not implemented. [uninstallDapp]");
1805
1743
  }
1806
1744
  };
1807
1745
 
1808
- // src/classes/registration/DappRegistrationService.ts
1809
- import { forget as forget2 } from "@xylabs/forget";
1810
- import { fulfilled, rejected } from "@xylabs/promise";
1811
- import { ModuleFactoryLocator as ModuleFactoryLocator5 } from "@xyo-network/module-factory-locator";
1812
- import {
1813
- DappIntentTypes as DappIntentTypes2,
1814
- DappMode as DappMode3,
1815
- isRegisteredDappAccessDappSet as isRegisteredDappAccessDappSet2,
1816
- isRegisteredDappExposedDappSet
1817
- } from "@xyo-network/os-model";
1818
-
1819
- // src/event/bus/Connection.ts
1820
- import { assertEx as assertEx16 } from "@xylabs/assert";
1821
- import { BaseEmitter } from "@xyo-network/module-abstract";
1822
- var EventBusConnection = class extends BaseEmitter {
1823
- _id;
1824
- description;
1825
- type;
1826
- constructor(request) {
1827
- super({});
1828
- this.description = request.description;
1829
- this.type = request.type;
1746
+ // src/XyOsDapp.ts
1747
+ var XyOsDapp = class extends XyOsContextBase {
1748
+ dapp;
1749
+ constructor(params) {
1750
+ super(params);
1751
+ this.dapp = { ...params.dapp };
1830
1752
  }
1831
- get id() {
1832
- return assertEx16(this._id, () => "Connection ID not set. Did you forget to call buildConnection()?");
1753
+ get eventBus() {
1754
+ return this.parent.eventBus;
1833
1755
  }
1834
- buildConnection(id) {
1835
- this._id = id;
1756
+ get exposedNode() {
1757
+ return this.parent.exposedNode;
1836
1758
  }
1837
- };
1838
-
1839
- // src/event/bus/EventBus.ts
1840
- import { assertEx as assertEx17 } from "@xylabs/assert";
1841
- import { forget } from "@xylabs/forget";
1842
- import {
1843
- asArchivistInstance as asArchivistInstance5,
1844
- MemoryArchivist,
1845
- MemoryArchivistConfigSchema
1846
- } from "@xyo-network/archivist";
1847
- import {
1848
- isEventBusEvent,
1849
- isPubSubConnections
1850
- } from "@xyo-network/os-model";
1851
- import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
1852
- import { Mutex } from "async-mutex";
1853
- import { v4 as uuid2 } from "uuid";
1854
- var EventBus = class {
1855
- // Internal Archivist to store event data
1856
- _archivist;
1857
- // Store all connections
1858
- connections = {};
1859
- // Store all publisher callbacks for later removal
1860
- publisherCallbacks = {};
1861
- startMutex = new Mutex();
1862
- get archivist() {
1863
- return asArchivistInstance5(
1864
- assertEx17(this._archivist, () => "Archivist not found. Did you forget to call start()?"),
1865
- "not a valid archivist instance"
1866
- );
1759
+ get exposedNodeOuter() {
1760
+ return this.parent.exposedNodeOuter;
1867
1761
  }
1868
- addConnection(connection) {
1869
- const id = uuid2();
1870
- this.connections[id] = connection;
1871
- connection.buildConnection(id);
1872
- if (isPubSubConnections(connection)) {
1873
- this.handlePublisherAdd(connection);
1874
- } else {
1875
- throw new Error("Unsupported connection type. Must be PubSub");
1876
- }
1877
- return connection;
1762
+ /**
1763
+ * @deprecated Dapps should not have access to the bios. This is done for the
1764
+ * settings dapp, but should be refactored out. Bios could possibly be an
1765
+ * optional property of the parent context passed in for dapps that require
1766
+ * elevated permissions.
1767
+ * ^^^ I believe we may want this here in that is a dApp requests access to the bios it will optionally be there
1768
+ */
1769
+ get kernel() {
1770
+ return assertEx14(this.parent.kernel, () => "Missing kernel");
1878
1771
  }
1879
- removeConnection(connectionId) {
1880
- const connection = this.connections[connectionId];
1881
- if (!connection) {
1882
- throw new Error("Connection not found " + connectionId);
1883
- }
1884
- if (connection && isPubSubConnections(connection)) {
1885
- this.handlePublisherRemove(connection);
1886
- }
1887
- delete this.connections[connectionId];
1772
+ get parent() {
1773
+ return this.params.parent;
1888
1774
  }
1889
- async start(storeName = "EventBusArchivist") {
1890
- return await this.startMutex.runExclusive(async () => {
1891
- if (this._archivist) {
1892
- console.warn("EventBus already started");
1893
- return this;
1775
+ get stacks() {
1776
+ return [];
1777
+ }
1778
+ get user() {
1779
+ return this.params.user;
1780
+ }
1781
+ async boot(wallet, locator) {
1782
+ return await this._bootMutex.runExclusive(async () => {
1783
+ console.log("XyOsDapp:boot:start", wallet.address, this.dapp.id);
1784
+ assertEx14(this._root === void 0, () => "Dapp already booted");
1785
+ const finalLocator = locator ? (this.params.locator ?? new ModuleFactoryLocator4()).merge(locator) : this.params.locator ?? new ModuleFactoryLocator4();
1786
+ console.log("XyOsDapp:boot:finalLocator", finalLocator);
1787
+ const dappNodesWrapper = new ManifestWrapper({ ...this.manifest, schema: DappPackageManifestPayloadSchema }, wallet, finalLocator);
1788
+ const dappNodes = await dappNodesWrapper.loadNodes();
1789
+ const dappManifestWallet = await wallet.derivePath("99999");
1790
+ dapp_window_manifest_default.nodes[0].config.name = this.dapp.name + "Root";
1791
+ const wrapper = new ManifestWrapper(
1792
+ { ...dapp_window_manifest_default, schema: DappPackageManifestPayloadSchema },
1793
+ dappManifestWallet,
1794
+ finalLocator
1795
+ );
1796
+ const node = await wrapper.loadNodeFromIndex(0);
1797
+ for (const dappNode of dappNodes) {
1798
+ await node.register(dappNode);
1799
+ await node.attach(dappNode.address, true);
1894
1800
  }
1895
- this._archivist = await MemoryArchivist.create({ config: { name: storeName, schema: MemoryArchivistConfigSchema } });
1896
- this.archivist.on("inserted", ({ payloads }) => {
1897
- const eventBusEvent = payloads.find(isEventBusEvent);
1898
- if (!eventBusEvent) return;
1899
- for (const connectionId in this.connections) {
1900
- const connection = this.connections[connectionId];
1901
- if (isPubSubConnections(connection) && connection.subscribableEvents) {
1902
- for (const [eventName, callback] of connection.subscribableEvents.entries()) {
1903
- if (eventName !== eventBusEvent.name) continue;
1904
- if (callback) {
1905
- const forgettable = async () => await callback({ payloads });
1906
- forget(forgettable());
1907
- }
1908
- }
1909
- }
1910
- }
1911
- });
1912
- return this;
1913
- });
1914
- }
1915
- handlePublisherAdd(connection) {
1916
- for (const eventName of connection.publishableEvents ?? []) {
1917
- const connectionPublisherCallback = async ({ payloads }) => {
1918
- const event = { name: eventName, schema: "network.xyo.event.bus.event" };
1919
- const eventPayloads = payloads ?? [];
1920
- event.sources = await PayloadBuilder6.dataHashes(eventPayloads);
1921
- try {
1922
- await this.archivist.insert([event, ...payloads ?? []]);
1923
- } catch (e) {
1924
- console.error("Error inserting event into archivist", e);
1925
- }
1926
- };
1927
- connection.on(eventName, connectionPublisherCallback);
1928
- const callbackId = connection.id + eventName;
1929
- this.publisherCallbacks[callbackId] = connectionPublisherCallback;
1930
- }
1931
- }
1932
- handlePublisherRemove(connection) {
1933
- for (const [, event] of connection.publishableEvents?.entries() ?? []) {
1934
- const id = connection.id + event;
1935
- const callback = this.publisherCallbacks[id];
1936
- if (callback) connection.off(event, callback);
1937
- }
1938
- }
1939
- };
1940
-
1941
- // src/event/bus/PubSubConnection.ts
1942
- var EventBusPubSubConnection = class extends EventBusConnection {
1943
- publishableEvents;
1944
- subscribableEvents;
1945
- constructor(request) {
1946
- super(request);
1947
- if (request.type !== "PubSub") {
1948
- throw new Error("Invalid connection type. Must be PubSub");
1949
- }
1950
- this.publishableEvents = request.publishableEvents;
1951
- this.subscribableEvents = request.subscribableEvents;
1952
- }
1953
- };
1954
-
1955
- // src/event/connections/DappAccessRequest.ts
1956
- var DappAccessRequestEvent = "dappAccessRequest";
1957
- var dappAccessRequestConnectionRequest = {
1958
- publishableEvents: [DappAccessRequestEvent],
1959
- type: "PubSub"
1960
- };
1961
- var dappAccessRequestConnection = () => new EventBusPubSubConnection(dappAccessRequestConnectionRequest);
1962
-
1963
- // src/event/connections/DappsReady.ts
1964
- var dappsReadyConnectionRequest = {
1965
- publishableEvents: ["dappsReady"],
1966
- type: "PubSub"
1967
- };
1968
- var dappsReadyConnection = () => new EventBusPubSubConnection(dappsReadyConnectionRequest);
1969
-
1970
- // src/event/connections/ExposeDappRequest.ts
1971
- var ExposeDappRequestEvent = "exposeDappRequest";
1972
- var exposeDappConnectionRequest = {
1973
- publishableEvents: [ExposeDappRequestEvent],
1974
- type: "PubSub"
1975
- };
1976
- var exposeDappRequestConnection = () => new EventBusPubSubConnection(exposeDappConnectionRequest);
1977
-
1978
- // src/event/connections/OsPubSubNetworkReady.ts
1979
- var OsPubSubNetworkReadyEvent = "osPubSubNetworkReady";
1980
- var osPubSubNetworkConnectionRequest = {
1981
- publishableEvents: [OsPubSubNetworkReadyEvent],
1982
- type: "PubSub"
1983
- };
1984
- var osPubSubNetworkReadyConnection = () => new EventBusPubSubConnection(osPubSubNetworkConnectionRequest);
1985
-
1986
- // src/event/connections/OsSettingsReady.ts
1987
- var OsSettingsReadyEvent = "osSettingsReady";
1988
- var osSettingsConnectionRequest = {
1989
- publishableEvents: [OsSettingsReadyEvent],
1990
- type: "PubSub"
1991
- };
1992
- var osSettingsReadyConnection = () => new EventBusPubSubConnection(osSettingsConnectionRequest);
1993
-
1994
- // src/event/connections/OsXyoPublicReady.ts
1995
- var OsXyoPublicNetworkReadyEvent = "osXyoPublicNetworkReady";
1996
- var osXyoPublicNetworkConnectionRequest = {
1997
- publishableEvents: [OsXyoPublicNetworkReadyEvent],
1998
- type: "PubSub"
1999
- };
2000
- var osXyoPublicNetworkReadyConnection = () => new EventBusPubSubConnection(osXyoPublicNetworkConnectionRequest);
2001
-
2002
- // src/XyOsDapp.ts
2003
- import { assertEx as assertEx19 } from "@xylabs/assert";
2004
- import { ManifestWrapper } from "@xyo-network/manifest-wrapper";
2005
- import { ModuleFactoryLocator as ModuleFactoryLocator4 } from "@xyo-network/module-factory-locator";
2006
- import { DappPackageManifestPayloadSchema } from "@xyo-network/os-model";
2007
-
2008
- // src/manifests/dapp-window.manifest.json
2009
- var dapp_window_manifest_default = {
2010
- $schema: "https://raw.githubusercontent.com/XYOracleNetwork/sdk-xyo-client-js/main/packages/manifest/src/compilations/dapp-package-manifest-schema.json",
2011
- nodes: [
2012
- {
2013
- config: {
2014
- accountPath: "0'",
2015
- name: "Dapp",
2016
- schema: "network.xyo.node.config"
2017
- },
2018
- modules: {
2019
- private: [],
2020
- public: [
2021
- {
2022
- config: {
2023
- accountPath: "0'/0'",
2024
- name: "DappArchivist",
2025
- schema: "network.xyo.archivist.memory.config"
2026
- }
2027
- },
2028
- {
2029
- config: {
2030
- accountPath: "0'/1'",
2031
- archivist: "DappArchivist",
2032
- labels: {
2033
- "network.xyo.generic.payload.diviner": "GenericPayloadDiviner"
2034
- },
2035
- name: "DappArchivistPayloadDiviner",
2036
- schema: "network.xyo.diviner.payload.config"
2037
- }
2038
- }
2039
- ]
2040
- }
2041
- }
2042
- ],
2043
- schema: "network.xyo.manifest.package.dapp"
2044
- };
2045
-
2046
- // src/XyOsBase.ts
2047
- import { assertEx as assertEx18 } from "@xylabs/assert";
2048
- import { BaseEmitter as BaseEmitter2 } from "@xyo-network/module-abstract";
2049
- import { ModuleFactoryLocator as ModuleFactoryLocator3 } from "@xyo-network/module-factory-locator";
2050
- import { Mutex as Mutex2 } from "async-mutex";
2051
- var XyOsContextBase = class extends BaseEmitter2 {
2052
- _bootMutex = new Mutex2();
2053
- _platformLocator;
2054
- _root;
2055
- get bios() {
2056
- return this.kernel?.bios;
2057
- }
2058
- get eventBus() {
2059
- return assertEx18(this.params.eventBus, () => "Missing event bus");
2060
- }
2061
- get exposedNode() {
2062
- throw new Error("Method not implemented. [exposedNode]");
2063
- }
2064
- get exposedNodeOuter() {
2065
- throw new Error("Method not implemented. [exposedNodeOuter]");
2066
- }
2067
- get installedDapps() {
2068
- return [];
2069
- }
2070
- get kernel() {
2071
- return void 0;
2072
- }
2073
- get manifest() {
2074
- return assertEx18(this.params.manifest, () => "Missing manifest");
2075
- }
2076
- get platformLocator() {
2077
- this._platformLocator = this._platformLocator ?? this.params.platformLocator ?? new ModuleFactoryLocator3();
2078
- return this._platformLocator;
2079
- }
2080
- get possibleRoot() {
2081
- return this._root;
2082
- }
2083
- get root() {
2084
- return assertEx18(this._root, () => "XyOs root not set (probably not yet booted)");
2085
- }
2086
- get runningDapps() {
2087
- return [];
2088
- }
2089
- get signerPaths() {
2090
- return this.params.signerPaths;
2091
- }
2092
- get state() {
2093
- return this._root ? "running" : "stopped";
2094
- }
2095
- get user() {
2096
- throw new Error("Method not implemented. [user]");
2097
- }
2098
- boot(_wallet, _locator) {
2099
- throw new Error("Method not implemented. [boot]");
2100
- }
2101
- buildDapp(_manifest, _dappId) {
2102
- throw new Error("Method not implemented. [buildDapp]");
2103
- }
2104
- dappByName(_dappId) {
2105
- throw new Error("Method not implemented. [runningDapp]");
2106
- }
2107
- getDappParams(_dappId) {
2108
- throw new Error("Method not implemented. [getDappParams]");
2109
- }
2110
- getStack(_stackName) {
2111
- throw new Error("Method not implemented. [getStack]");
2112
- }
2113
- installDapp(_dappId) {
2114
- throw new Error("Method not implemented. [installDapp]");
2115
- }
2116
- monitor(_fn, _eventConfig) {
2117
- throw new Error("Method not implemented. [monitor]");
2118
- }
2119
- shutdown() {
2120
- throw new Error("Method not implemented. [shutdown]");
2121
- }
2122
- startDapp(_dappId) {
2123
- throw new Error("Method not implemented. [startDapp]");
2124
- }
2125
- stopDapp(_dappId) {
2126
- throw new Error("Method not implemented. [stopDapp]");
2127
- }
2128
- uninstallDapp(_dappId) {
2129
- throw new Error("Method not implemented. [uninstallDapp]");
2130
- }
2131
- };
2132
-
2133
- // src/XyOsDapp.ts
2134
- var XyOsDapp = class extends XyOsContextBase {
2135
- dapp;
2136
- constructor(params) {
2137
- super(params);
2138
- this.dapp = { ...params.dapp };
2139
- }
2140
- get eventBus() {
2141
- return this.parent.eventBus;
2142
- }
2143
- get exposedNode() {
2144
- return this.parent.exposedNode;
2145
- }
2146
- get exposedNodeOuter() {
2147
- return this.parent.exposedNodeOuter;
2148
- }
2149
- /**
2150
- * @deprecated Dapps should not have access to the bios. This is done for the
2151
- * settings dapp, but should be refactored out. Bios could possibly be an
2152
- * optional property of the parent context passed in for dapps that require
2153
- * elevated permissions.
2154
- * ^^^ I believe we may want this here in that is a dApp requests access to the bios it will optionally be there
2155
- */
2156
- get kernel() {
2157
- return assertEx19(this.parent.kernel, () => "Missing kernel");
2158
- }
2159
- get parent() {
2160
- return this.params.parent;
2161
- }
2162
- get stacks() {
2163
- return [];
2164
- }
2165
- get user() {
2166
- return this.params.user;
2167
- }
2168
- async boot(wallet, locator) {
2169
- return await this._bootMutex.runExclusive(async () => {
2170
- console.log("XyOsDapp:boot:start", wallet.address, this.dapp.id);
2171
- assertEx19(this._root === void 0, () => "Dapp already booted");
2172
- const finalLocator = locator ? (this.params.locator ?? new ModuleFactoryLocator4()).merge(locator) : this.params.locator ?? new ModuleFactoryLocator4();
2173
- console.log("XyOsDapp:boot:finalLocator", finalLocator);
2174
- const dappNodesWrapper = new ManifestWrapper({ ...this.manifest, schema: DappPackageManifestPayloadSchema }, wallet, finalLocator);
2175
- const dappNodes = await dappNodesWrapper.loadNodes();
2176
- const dappManifestWallet = await wallet.derivePath("99999");
2177
- dapp_window_manifest_default.nodes[0].config.name = this.dapp.name + "Root";
2178
- const wrapper = new ManifestWrapper(
2179
- { ...dapp_window_manifest_default, schema: DappPackageManifestPayloadSchema },
2180
- dappManifestWallet,
2181
- finalLocator
2182
- );
2183
- const node = await wrapper.loadNodeFromIndex(0);
2184
- for (const dappNode of dappNodes) {
2185
- await node.register(dappNode);
2186
- await node.attach(dappNode.address, true);
2187
- }
2188
- this._root = node;
2189
- console.log("XyOsDapp:boot:finish", wallet.address, this.dapp.id);
1801
+ this._root = node;
1802
+ console.log("XyOsDapp:boot:finish", wallet.address, this.dapp.id);
2190
1803
  });
2191
1804
  }
2192
1805
  getStack(stackName) {
@@ -2195,24 +1808,24 @@ var XyOsDapp = class extends XyOsContextBase {
2195
1808
  };
2196
1809
 
2197
1810
  // src/classes/system/ManageSystemDapps.ts
2198
- import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/payload-builder";
1811
+ import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
2199
1812
  import semver from "semver";
2200
1813
 
2201
1814
  // src/classes/system/Queries.ts
2202
- import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema10 } from "@xyo-network/diviner-payload-model";
1815
+ import { PayloadDivinerQuerySchema as PayloadDivinerQuerySchema8 } from "@xyo-network/diviner-payload-model";
2203
1816
  import {
2204
1817
  DappConfigSchema,
2205
1818
  DappIconSchema,
2206
1819
  DappWidgetConfigSchema,
2207
1820
  UnregisteredDappAccessSchema
2208
1821
  } from "@xyo-network/os-model";
2209
- import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
1822
+ import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
2210
1823
  var SystemDappQueries = {
2211
1824
  async getDappAccess(diviner, name, version) {
2212
1825
  const accessQuery = {
2213
1826
  order: "desc",
2214
1827
  registeringDappId: name,
2215
- schema: PayloadDivinerQuerySchema10,
1828
+ schema: PayloadDivinerQuerySchema8,
2216
1829
  schemas: [UnregisteredDappAccessSchema],
2217
1830
  version
2218
1831
  };
@@ -2223,7 +1836,7 @@ var SystemDappQueries = {
2223
1836
  limit: 1,
2224
1837
  name,
2225
1838
  order: "desc",
2226
- schema: PayloadDivinerQuerySchema10,
1839
+ schema: PayloadDivinerQuerySchema8,
2227
1840
  schemas: [DappConfigSchema]
2228
1841
  };
2229
1842
  const [dappConfig] = await diviner.divine([configQuery]);
@@ -2233,7 +1846,7 @@ var SystemDappQueries = {
2233
1846
  const iconQuery = {
2234
1847
  name,
2235
1848
  order: "desc",
2236
- schema: PayloadDivinerQuerySchema10,
1849
+ schema: PayloadDivinerQuerySchema8,
2237
1850
  schemas: [DappIconSchema],
2238
1851
  version
2239
1852
  };
@@ -2244,14 +1857,14 @@ var SystemDappQueries = {
2244
1857
  const widgetConfigQuery = {
2245
1858
  dappId: name,
2246
1859
  order: "desc",
2247
- schema: PayloadDivinerQuerySchema10,
1860
+ schema: PayloadDivinerQuerySchema8,
2248
1861
  schemas: [DappWidgetConfigSchema],
2249
1862
  version
2250
1863
  };
2251
1864
  const widgetConfigs = await diviner.divine([widgetConfigQuery]);
2252
1865
  const uniqueConfigs = {};
2253
1866
  for (const widgetConfig of widgetConfigs) {
2254
- const hash = await PayloadBuilder7.dataHash(widgetConfig);
1867
+ const hash = await PayloadBuilder6.dataHash(widgetConfig);
2255
1868
  uniqueConfigs[widgetConfig.mode ?? hash] = widgetConfig;
2256
1869
  }
2257
1870
  return Object.values(uniqueConfigs);
@@ -2302,7 +1915,7 @@ var ManageSystemDapps = class extends OsCallerBase {
2302
1915
  console.error(`${systemDappPayload.version} does not appear to be a valid semver value`, e);
2303
1916
  continue;
2304
1917
  }
2305
- const [existing] = await archivist.get([await PayloadBuilder8.dataHash(systemDappPayload)]);
1918
+ const [existing] = await archivist.get([await PayloadBuilder7.dataHash(systemDappPayload)]);
2306
1919
  if (existing) continue;
2307
1920
  await archivist.insert([systemDappPayload]);
2308
1921
  }
@@ -2358,7 +1971,7 @@ var ManageSystemDapps = class extends OsCallerBase {
2358
1971
  };
2359
1972
 
2360
1973
  // src/classes/registration/DappRegistry.ts
2361
- import { HDWallet as HDWallet5 } from "@xyo-network/account";
1974
+ import { HDWallet as HDWallet4 } from "@xyo-network/account";
2362
1975
  import {
2363
1976
  DappRegisteredSchema,
2364
1977
  DappRegisteredState,
@@ -2372,7 +1985,7 @@ var isFailedAccessor = isPayloadOfSchemaTypeWithMeta(FailedAccessorSchema);
2372
1985
  var ValidateDappAccessDivinerConfigSchema = "network.xyo.os.dapp.access.registration.validate";
2373
1986
 
2374
1987
  // src/classes/registration/ValidateDappAccessDiviner/Diviner.ts
2375
- import { HDWallet as HDWallet4 } from "@xyo-network/account";
1988
+ import { HDWallet as HDWallet3 } from "@xyo-network/account";
2376
1989
  import { AbstractDiviner } from "@xyo-network/diviner-abstract";
2377
1990
  import { ManifestWrapper as ManifestWrapper2, PackageManifestPayloadSchema as PackageManifestPayloadSchema2 } from "@xyo-network/manifest";
2378
1991
  import {
@@ -2380,7 +1993,7 @@ import {
2380
1993
  isUnregisteredDappAccess,
2381
1994
  RegisteredDappAccessSchema as RegisteredDappAccessSchema3
2382
1995
  } from "@xyo-network/os-model";
2383
- import { PayloadBuilder as PayloadBuilder9 } from "@xyo-network/payload-builder";
1996
+ import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/payload-builder";
2384
1997
  var ValidateDappAccessDiviner = class extends AbstractDiviner {
2385
1998
  static configSchemas = [ValidateDappAccessDivinerConfigSchema];
2386
1999
  async divineHandler(payloads) {
@@ -2408,14 +2021,14 @@ var ValidateDappAccessDiviner = class extends AbstractDiviner {
2408
2021
  const interfaceChildren = await getNodeChildren(dappAccessInterface.manifest, dappParams);
2409
2022
  const valid = compareChildren(interfaceChildren, dappChildren);
2410
2023
  if (valid) {
2411
- const payload = await PayloadBuilder9.build({
2024
+ const payload = await PayloadBuilder8.build({
2412
2025
  ...access,
2413
2026
  schema: RegisteredDappAccessSchema3,
2414
2027
  timestamp: Date.now()
2415
2028
  });
2416
2029
  registeredAccessors.push(payload);
2417
2030
  } else {
2418
- const failedRegistration = await PayloadBuilder9.build({
2031
+ const failedRegistration = await PayloadBuilder8.build({
2419
2032
  accessor: access,
2420
2033
  errorMessage: "Invalid dapp access interface",
2421
2034
  schema: FailedAccessorSchema
@@ -2425,7 +2038,7 @@ var ValidateDappAccessDiviner = class extends AbstractDiviner {
2425
2038
  }
2426
2039
  } catch (e) {
2427
2040
  failedAccessors.push(
2428
- await PayloadBuilder9.build({
2041
+ await PayloadBuilder8.build({
2429
2042
  accessor: access,
2430
2043
  errorMessage: e.message,
2431
2044
  schema: FailedAccessorSchema
@@ -2433,251 +2046,559 @@ var ValidateDappAccessDiviner = class extends AbstractDiviner {
2433
2046
  );
2434
2047
  }
2435
2048
  }
2436
- return [...registeredAccessors, ...failedAccessors];
2049
+ return [...registeredAccessors, ...failedAccessors];
2050
+ }
2051
+ };
2052
+ var compareChildren = (interfaceChildren, dappChildren) => {
2053
+ return interfaceChildren.every((interfaceChild) => Object.values(interfaceChild).every((interfaceChildName) => dappChildren.some((dappChild) => Object.values(dappChild).includes(interfaceChildName))));
2054
+ };
2055
+ var dappPackageManifestToPackageManifest = (dappPackageManifest) => {
2056
+ return {
2057
+ ...dappPackageManifest,
2058
+ schema: PackageManifestPayloadSchema2
2059
+ };
2060
+ };
2061
+ var getChildrenFromNode = async (node) => {
2062
+ const nodeManifest = (await node.state())?.[0];
2063
+ return nodeManifest.status?.children;
2064
+ };
2065
+ var getNodeChildren = async (manifestToTest, dappParams) => {
2066
+ const testNodes = await getNodeToTest(manifestToTest, dappParams);
2067
+ const children = [];
2068
+ for (const node of testNodes) {
2069
+ const nodeChildren = await getChildrenFromNode(node);
2070
+ if (nodeChildren) {
2071
+ children.push(nodeChildren);
2072
+ }
2073
+ }
2074
+ return children;
2075
+ };
2076
+ var getNodeToTest = async (manifestToTest, dappParams) => {
2077
+ const dappManifestWrapper = new ManifestWrapper2(manifestToTest, await HDWallet3.random(), dappParams.locator);
2078
+ return await dappManifestWrapper.loadNodes();
2079
+ };
2080
+
2081
+ // src/classes/registration/DappRegistry.ts
2082
+ var DappRegistry = class {
2083
+ constructor(dappSeedPhraseRepository) {
2084
+ this.dappSeedPhraseRepository = dappSeedPhraseRepository;
2085
+ }
2086
+ dappRegistry = /* @__PURE__ */ new Map();
2087
+ /**
2088
+ * Register a Dapp with window manager and if successful, return its id
2089
+ *
2090
+ * @param {UnregisteredDapp} dapp Manifest and UI of the Dapp to register
2091
+ * @returns {RegisteredDapp} dapp with registration fields
2092
+ **/
2093
+ async registerDapp(dapp) {
2094
+ if (dapp) {
2095
+ const {
2096
+ exposedModuleIds,
2097
+ manifest,
2098
+ modes,
2099
+ name,
2100
+ version,
2101
+ params,
2102
+ widgetConfigs
2103
+ } = this.extractDappProperties(dapp);
2104
+ try {
2105
+ const walletId = await this.dappSeedPhraseRepository.findOrCreate(name);
2106
+ const registeredAccessors = await this.validateDappAccessPayloads(manifest, dapp.accessors, params);
2107
+ const registeredDapp = {
2108
+ accessors: registeredAccessors,
2109
+ config: {
2110
+ exposedModuleIds,
2111
+ manifest,
2112
+ modes,
2113
+ name,
2114
+ schema: DappRegisteredSchema,
2115
+ state: DappRegisteredState.Registered,
2116
+ version,
2117
+ // attach the walletId to a registered dapp so it can request it back in the future
2118
+ walletId
2119
+ },
2120
+ params,
2121
+ widgetConfigs
2122
+ };
2123
+ if (this.dappRegistry.get(name)) {
2124
+ console.warn("tried to register two dapps with the same name", name);
2125
+ return null;
2126
+ }
2127
+ this.dappRegistry.set(name, registeredDapp);
2128
+ return registeredDapp;
2129
+ } catch (e) {
2130
+ console.error("Error registeringDapp", e);
2131
+ return null;
2132
+ }
2133
+ } else {
2134
+ return null;
2135
+ }
2136
+ }
2137
+ /**
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
+ }
2437
2288
  }
2438
2289
  };
2439
- var compareChildren = (interfaceChildren, dappChildren) => {
2440
- return interfaceChildren.every((interfaceChild) => Object.values(interfaceChild).every((interfaceChildName) => dappChildren.some((dappChild) => Object.values(dappChild).includes(interfaceChildName))));
2441
- };
2442
- var dappPackageManifestToPackageManifest = (dappPackageManifest) => {
2443
- return {
2444
- ...dappPackageManifest,
2445
- schema: PackageManifestPayloadSchema2
2446
- };
2447
- };
2448
- var getChildrenFromNode = async (node) => {
2449
- const nodeManifest = (await node.state())?.[0];
2450
- return nodeManifest.status?.children;
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
+ }
2451
2315
  };
2452
- var getNodeChildren = async (manifestToTest, dappParams) => {
2453
- const testNodes = await getNodeToTest(manifestToTest, dappParams);
2454
- const children = [];
2455
- for (const node of testNodes) {
2456
- const nodeChildren = await getChildrenFromNode(node);
2457
- if (nodeChildren) {
2458
- children.push(nodeChildren);
2459
- }
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]);
2460
2330
  }
2461
- return children;
2462
2331
  };
2463
- var getNodeToTest = async (manifestToTest, dappParams) => {
2464
- const dappManifestWrapper = new ManifestWrapper2(manifestToTest, await HDWallet4.random(), dappParams.locator);
2465
- return await dappManifestWrapper.loadNodes();
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
+ }
2466
2355
  };
2467
2356
 
2468
- // src/classes/registration/DappRegistry.ts
2469
- var DappRegistry = class {
2470
- constructor(dappSeedPhraseRepository) {
2471
- this.dappSeedPhraseRepository = dappSeedPhraseRepository;
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();
2472
2377
  }
2473
- dappRegistry = /* @__PURE__ */ new Map();
2474
2378
  /**
2475
- * Register a Dapp with window manager and if successful, return its id
2476
- *
2477
- * @param {UnregisteredDapp} dapp Manifest and UI of the Dapp to register
2478
- * @returns {RegisteredDapp} dapp with registration fields
2379
+ * start listeners
2479
2380
  **/
2480
- async registerDapp(dapp) {
2481
- if (dapp) {
2482
- const {
2483
- exposedModuleIds,
2484
- manifest,
2485
- modes,
2486
- name,
2487
- version,
2488
- params,
2489
- widgetConfigs
2490
- } = this.extractDappProperties(dapp);
2491
- try {
2492
- const walletId = await this.dappSeedPhraseRepository.findOrCreate(name);
2493
- const registeredAccessors = await this.validateDappAccessPayloads(manifest, dapp.accessors, params);
2494
- const registeredDapp = {
2495
- accessors: registeredAccessors,
2496
- config: {
2497
- exposedModuleIds,
2498
- manifest,
2499
- modes,
2500
- name,
2501
- schema: DappRegisteredSchema,
2502
- state: DappRegisteredState.Registered,
2503
- version,
2504
- // attach the walletId to a registered dapp so it can request it back in the future
2505
- walletId
2506
- },
2507
- params,
2508
- widgetConfigs
2509
- };
2510
- if (this.dappRegistry.get(name)) {
2511
- console.warn("tried to register two dapps with the same name", name);
2512
- return null;
2513
- }
2514
- this.dappRegistry.set(name, registeredDapp);
2515
- return registeredDapp;
2516
- } catch (e) {
2517
- console.error("Error registeringDapp", e);
2518
- return null;
2519
- }
2520
- } else {
2521
- return null;
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
2522
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);
2523
2494
  }
2524
2495
  /**
2525
- * Unregister a dapp so it can no longer be launched
2526
- *
2527
- * @param dappId
2496
+ * Add a node background to the settings
2497
+ * @param {WithMeta<NodeBackground>} payload
2528
2498
  */
2529
- unregisterDapp(dappId) {
2530
- this.dappRegistry.delete(dappId);
2499
+ async addNodeBackground(payload) {
2500
+ const archivist = await this.getOsSettingsArchivist();
2501
+ await archivist.insert([payload]);
2531
2502
  }
2532
- extractDappProperties(dapp) {
2533
- const {
2534
- params,
2535
- config,
2536
- widgetConfigs
2537
- } = dapp;
2538
- const {
2539
- exposedModuleIds,
2540
- manifest,
2541
- modes,
2542
- name,
2543
- sources,
2544
- version
2545
- } = config;
2546
- return {
2547
- exposedModuleIds,
2548
- manifest,
2549
- modes,
2550
- name,
2551
- params,
2552
- sources,
2553
- version,
2554
- widgetConfigs
2555
- };
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);
2556
2512
  }
2557
- async validateDappAccessPayloads(manifest, accessors = [], params) {
2558
- const validateDappAccess = await ValidateDappAccessDiviner.create({
2559
- account: await HDWallet5.random(),
2560
- config: { schema: ValidateDappAccessDivinerConfigSchema },
2561
- dappParams: params
2562
- });
2563
- const payloads = await validateDappAccess.divine([manifest, ...accessors]);
2564
- const failedAccessors = payloads.filter(isFailedAccessor);
2565
- const registeredAccessors = payloads.filter(isRegisteredDappAccess2);
2566
- if (failedAccessors.length > 0) {
2567
- console.error("Failed to register all dapp accessors", failedAccessors);
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);
2568
2533
  }
2569
- return registeredAccessors;
2534
+ return storedSeedPhrasePayload;
2570
2535
  }
2571
2536
  };
2572
2537
 
2573
- // src/classes/registration/DappRegistrationService.ts
2574
- var DappRegistrationService = class {
2575
- constructor(context, params = {
2576
- dappNames: [],
2577
- dappParams: {},
2578
- dappPayloads: []
2579
- }, locator = new ModuleFactoryLocator5(), developmentMode) {
2580
- this.context = context;
2581
- this.params = params;
2582
- this.locator = locator;
2583
- this.developmentMode = developmentMode;
2584
- this.manageSystemDapps = new ManageSystemDapps(
2585
- context,
2586
- this.params?.dappNames ?? [],
2587
- this.params?.dappPayloads ?? [],
2588
- this.params?.dappParams ?? {},
2589
- this.locator,
2590
- this.developmentMode
2591
- );
2592
- this.dappSeedPhraseRepository = new DappSeedPhraseRepository(context, this.params?.dappNames ?? []);
2593
- this.dappRegistry = new DappRegistry(this.dappSeedPhraseRepository);
2594
- 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);
2595
2547
  }
2596
- // Dapps that have been built with their own context
2597
- builtDapps = {};
2598
- dappRegistry;
2599
- dappSeedPhraseRepository;
2600
- manageSystemDapps;
2601
- // Dapps that have been registered with dappAccessRequests
2602
- registeredAccessDappSets = /* @__PURE__ */ new Set();
2603
- // Dapps that have been registered with the dapp registry
2604
- registeredDappSets = /* @__PURE__ */ new Set();
2605
- // Dapps that have been registered with exposeDappRequests
2606
- registeredExposedDappSets = /* @__PURE__ */ new Set();
2607
- dappAccessRequestConnection = dappAccessRequestConnection();
2608
- exposeDappRequestConnection = exposeDappRequestConnection();
2609
- async buildDapp(manifest, dappId = NameTransforms.slug(manifest.nodes[0]?.config.name), name = NameTransforms.moduleName(manifest.nodes[0]?.config.name)) {
2610
- const dapp = new XyOsDapp({
2611
- dapp: { id: dappId, name },
2612
- locator: this.locator,
2613
- manifest,
2614
- parent: this.context,
2615
- user: await this.getUser()
2616
- });
2617
- this.builtDapps[dappId] = dapp;
2618
- return dapp;
2548
+ get latestUserWalletListener() {
2549
+ return assertEx18(this._latestUserWalletListener, () => "Latest user wallet listener not set");
2619
2550
  }
2620
- getParamsForRegisteredDapp(dappId) {
2621
- return this.params?.dappParams[dappId];
2551
+ get nodeBackgroundListener() {
2552
+ return assertEx18(this._nodeBackgroundListener, () => "Node background listener not set");
2622
2553
  }
2623
- async start() {
2624
- const systemDapps = await this.context.monitor(async () => await this.manageSystemDapps.install(), { name: "Install System dApps" });
2625
- const activeDapps = systemDapps.filter(({ dapp }) => dapp.icon.active === true);
2626
- const results = await Promise.allSettled(
2627
- activeDapps.map(async (dappSet) => {
2628
- const { dapp } = dappSet;
2629
- const registeredDapp = await this.dappRegistry.registerDapp(dapp);
2630
- const result = { dapp: registeredDapp, dappIcon: dapp.icon };
2631
- const forgetHandlers = async () => {
2632
- try {
2633
- await this.postRegistrationHandlers(result);
2634
- } catch (e) {
2635
- console.error("Error in post registration handlers", e);
2636
- }
2637
- };
2638
- forget2(forgetHandlers());
2639
- return result;
2640
- })
2641
- );
2642
- const failed = results.filter(rejected).map((result) => result.reason);
2643
- const succeeded = results.filter(fulfilled).map((result) => result.value);
2644
- for (const registeredDapp of succeeded) this.registeredDappSets.add(registeredDapp);
2645
- 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
+ };
2646
2560
  }
2647
- addConnectionRequests() {
2648
- this.context.eventBus.addConnection(this.dappAccessRequestConnection);
2649
- this.context.eventBus.addConnection(this.exposeDappRequestConnection);
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();
2650
2574
  }
2651
2575
  /**
2652
- * A method to get the user property from context and eventually modify it before handing it to a dapp
2653
- * i.e. curating user-approved signers
2576
+ * start listeners
2654
2577
  */
2655
- getUser() {
2656
- return this.context.user;
2657
- }
2658
- async postRegistrationHandlers(registeredDapp) {
2659
- if (registeredDapp.dapp) {
2660
- if (isRegisteredDappExposedDappSet(registeredDapp)) {
2661
- this.registeredExposedDappSets.add(registeredDapp);
2662
- const exposeIntent = DappIntentCaller.buildIntent(
2663
- DappIntentCaller.OsDappName,
2664
- DappIntentTypes2.Launch,
2665
- registeredDapp.dapp.config.name,
2666
- DappMode3.Exposed
2667
- );
2668
- await this.exposeDappRequestConnection.emit(ExposeDappRequestEvent, { payloads: [registeredDapp.dapp.config, exposeIntent] });
2669
- }
2670
- if (isRegisteredDappAccessDappSet2(registeredDapp)) {
2671
- this.registeredAccessDappSets.add(registeredDapp);
2672
- await this.dappAccessRequestConnection.emit(DappAccessRequestEvent, { payloads: registeredDapp.dapp.accessors });
2673
- }
2674
- }
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
+ });
2675
2596
  }
2676
2597
  };
2677
2598
 
2678
2599
  // src/classes/signer/Signers.ts
2679
- import { assertEx as assertEx20 } from "@xylabs/assert";
2680
- import { HDWallet as HDWallet6 } from "@xyo-network/account";
2600
+ import { assertEx as assertEx19 } from "@xylabs/assert";
2601
+ import { HDWallet as HDWallet5 } from "@xyo-network/account";
2681
2602
  var Signers = class {
2682
2603
  _paths;
2683
2604
  _signerAccounts;
@@ -2688,13 +2609,13 @@ var Signers = class {
2688
2609
  this._signerAccounts = /* @__PURE__ */ new Map();
2689
2610
  }
2690
2611
  get paths() {
2691
- return assertEx20(this._paths, () => "Paths not initialized");
2612
+ return assertEx19(this._paths, () => "Paths not initialized");
2692
2613
  }
2693
2614
  get signerAccounts() {
2694
- return assertEx20(this._signerAccounts, () => "Signer accounts not initialized");
2615
+ return assertEx19(this._signerAccounts, () => "Signer accounts not initialized");
2695
2616
  }
2696
2617
  get walletStore() {
2697
- return assertEx20(this._walletStore, () => "Wallet store not initialized");
2618
+ return assertEx19(this._walletStore, () => "Wallet store not initialized");
2698
2619
  }
2699
2620
  getSigner(walletKind, signer) {
2700
2621
  return this.signerAccounts.get(walletKind)?.get(signer);
@@ -2710,12 +2631,12 @@ var Signers = class {
2710
2631
  }
2711
2632
  }
2712
2633
  async initializeSigners(walletKindName, signerName, path) {
2713
- assertEx20(signerName, () => "Name not found in signer paths");
2714
- assertEx20(path, () => "Path not found in signer paths");
2715
- const phrase = assertEx20(await this.walletStore.get(walletKindName), () => `Wallet not found: ${walletKindName}`);
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}`);
2716
2637
  if (path) {
2717
2638
  const signerMap = this.signerAccounts.get(walletKindName) ?? /* @__PURE__ */ new Map();
2718
- const wallet = await HDWallet6.fromPhrase(phrase);
2639
+ const wallet = await HDWallet5.fromPhrase(phrase);
2719
2640
  const derivedWallet = await wallet.derivePath(path);
2720
2641
  signerMap.set(signerName, derivedWallet);
2721
2642
  this.signerAccounts.set(walletKindName, signerMap);
@@ -2751,7 +2672,7 @@ var loadOsNode = async (osWallet, locator) => {
2751
2672
  };
2752
2673
 
2753
2674
  // src/stack/Base.ts
2754
- import { assertEx as assertEx21 } from "@xylabs/assert";
2675
+ import { assertEx as assertEx20 } from "@xylabs/assert";
2755
2676
  import { forget as forget3 } from "@xylabs/forget";
2756
2677
  import { BaseEmitter as BaseEmitter3 } from "@xyo-network/module-abstract";
2757
2678
  import { isModuleInstance } from "@xyo-network/module-model";
@@ -2773,20 +2694,20 @@ var StackBase = class extends BaseEmitter3 {
2773
2694
  constructor(context, adapterSet, stackNodeModuleId) {
2774
2695
  super({});
2775
2696
  this._context = context;
2776
- this._adapterSet = adapterSet(assertEx21(this.context.kernel, "Kernel access required"));
2697
+ this._adapterSet = adapterSet(assertEx20(this.context.kernel, "Kernel access required"));
2777
2698
  this._stackNodeModuleId = stackNodeModuleId;
2778
2699
  }
2779
2700
  get adapterSet() {
2780
- return assertEx21(this._adapterSet, () => `${this.stackNodeModuleId} adapters not initialized`);
2701
+ return assertEx20(this._adapterSet, () => `${this.stackNodeModuleId} adapters not initialized`);
2781
2702
  }
2782
2703
  get context() {
2783
- return assertEx21(this._context, () => `${this.stackNodeModuleId} stack context not initialized`);
2704
+ return assertEx20(this._context, () => `${this.stackNodeModuleId} stack context not initialized`);
2784
2705
  }
2785
2706
  get stack() {
2786
- return assertEx21(this._stack, () => `${this.stackNodeModuleId} stack node not initialized`);
2707
+ return assertEx20(this._stack, () => `${this.stackNodeModuleId} stack node not initialized`);
2787
2708
  }
2788
2709
  get stackNodeModuleId() {
2789
- return assertEx21(this._stackNodeModuleId, () => "Stack node module identifier not initialized");
2710
+ return assertEx20(this._stackNodeModuleId, () => "Stack node module identifier not initialized");
2790
2711
  }
2791
2712
  initialize() {
2792
2713
  this.assignStack();
@@ -2845,7 +2766,7 @@ var StackBase = class extends BaseEmitter3 {
2845
2766
  forget3(assign());
2846
2767
  }
2847
2768
  async getStackNode() {
2848
- const mod = assertEx21(await this.context.root.resolve(this.stackNodeModuleId), () => `${this.stackNodeModuleId} not found`);
2769
+ const mod = assertEx20(await this.context.root.resolve(this.stackNodeModuleId), () => `${this.stackNodeModuleId} not found`);
2849
2770
  return asAttachableNodeInstance(mod, () => `${this.stackNodeModuleId} not a NodeInstance`);
2850
2771
  }
2851
2772
  async handleDriverReady(node) {
@@ -2903,7 +2824,7 @@ var StackManager = class {
2903
2824
  import { ExposedNodeOuterNodeName, PubSubBridgeNodeNodeName } from "@xyo-network/os-model";
2904
2825
 
2905
2826
  // src/adapter/Base.ts
2906
- import { assertEx as assertEx22 } from "@xylabs/assert";
2827
+ import { assertEx as assertEx21 } from "@xylabs/assert";
2907
2828
  import { forget as forget4 } from "@xylabs/forget";
2908
2829
  import { asArchivistInstance as asArchivistInstance6 } from "@xyo-network/archivist";
2909
2830
  import { BaseEmitter as BaseEmitter4 } from "@xyo-network/module-abstract";
@@ -2919,7 +2840,7 @@ var NodeAdapterBase = class extends BaseEmitter4 {
2919
2840
  initialized = false;
2920
2841
  _id = "";
2921
2842
  get id() {
2922
- return assertEx22(this._id, () => "NodeAdapterBase id not initialized");
2843
+ return assertEx21(this._id, () => "NodeAdapterBase id not initialized");
2923
2844
  }
2924
2845
  async start() {
2925
2846
  try {
@@ -2949,7 +2870,7 @@ var NodeAdapterBase = class extends BaseEmitter4 {
2949
2870
  });
2950
2871
  }
2951
2872
  async getEventsArchivist() {
2952
- const mod = assertEx22(await (await this.kernel.getNode()).resolve("KernelNode:ModuleEvents"), () => "KernelNode:ModuleEvents not found");
2873
+ const mod = assertEx21(await (await this.kernel.getNode()).resolve("KernelNode:ModuleEvents"), () => "KernelNode:ModuleEvents not found");
2953
2874
  return asArchivistInstance6(mod, () => `${mod.id} is not an archivist`);
2954
2875
  }
2955
2876
  validateAndReturnDriver() {
@@ -3021,7 +2942,7 @@ var OsXyoPublicNetworkAdapters = (kernel) => [
3021
2942
  ];
3022
2943
 
3023
2944
  // src/stack/OsPubSubNetworkStack.ts
3024
- import { assertEx as assertEx23 } from "@xylabs/assert";
2945
+ import { assertEx as assertEx22 } from "@xylabs/assert";
3025
2946
  import { asAttachableNodeInstance as asAttachableNodeInstance3, asNodeInstance as asNodeInstance2 } from "@xyo-network/node-model";
3026
2947
  import { ExposedNodeOuterNodeName as ExposedNodeOuterNodeName2, PubSubBridgeNodeNodeName as PubSubBridgeNodeNodeName2 } from "@xyo-network/os-model";
3027
2948
  var OsPubSubNetworkStack = class extends StackBase {
@@ -3043,7 +2964,7 @@ var OsPubSubNetworkStack = class extends StackBase {
3043
2964
  this.on("initialized", () => this.busConnection.emit(OsPubSubNetworkReadyEvent, {}));
3044
2965
  super.on("driverReady", async ({ node }) => {
3045
2966
  if (node.id === PubSubBridgeNodeNodeName2) {
3046
- const httpBridge = assertEx23(await node.resolve("NsHttpBridge"), () => "HttpBridge not found");
2967
+ const httpBridge = assertEx22(await node.resolve("NsHttpBridge"), () => "HttpBridge not found");
3047
2968
  const xnsNode = asNodeInstance2(await httpBridge.resolve("XNS"));
3048
2969
  if (xnsNode) {
3049
2970
  const initializedXns = await initializeXns(xnsNode);
@@ -3056,7 +2977,7 @@ var OsPubSubNetworkStack = class extends StackBase {
3056
2977
  super.on("driverReady", async ({ node }) => {
3057
2978
  if (node.id === ExposedNodeOuterNodeName2) {
3058
2979
  this._exposedNodeOuter = node;
3059
- const mod = assertEx23(await node.resolve("ExposedNode"), () => "ExposedNode not found");
2980
+ const mod = assertEx22(await node.resolve("ExposedNode"), () => "ExposedNode not found");
3060
2981
  const exposedNode = asAttachableNodeInstance3(mod, () => "ExposedNode is not a node");
3061
2982
  this._exposedNode = exposedNode;
3062
2983
  }
@@ -3164,7 +3085,7 @@ var XyOs = class _XyOs extends XyOsContextBase {
3164
3085
  return getXyOsGlobal();
3165
3086
  }
3166
3087
  get bios() {
3167
- return assertEx24(this.params.kernel?.bios, () => "Missing bios");
3088
+ return assertEx23(this.params.kernel?.bios, () => "Missing bios");
3168
3089
  }
3169
3090
  get exposedNode() {
3170
3091
  return this.stackManager.getStack("osPubSubNetworkStack")?.exposedNode;
@@ -3173,7 +3094,7 @@ var XyOs = class _XyOs extends XyOsContextBase {
3173
3094
  return this.stackManager.getStack("osPubSubNetworkStack")?.exposedNodeOuter;
3174
3095
  }
3175
3096
  get kernel() {
3176
- return assertEx24(this.params.kernel, () => "Missing kernel");
3097
+ return assertEx23(this.params.kernel, () => "Missing kernel");
3177
3098
  }
3178
3099
  get locator() {
3179
3100
  return this._locator;
@@ -3203,7 +3124,7 @@ var XyOs = class _XyOs extends XyOsContextBase {
3203
3124
  if (this.kernel?.status !== "booted") {
3204
3125
  throw new Error("Kernel not booted");
3205
3126
  }
3206
- assertEx24(this._root === void 0, () => "XyOs already booted");
3127
+ assertEx23(this._root === void 0, () => "XyOs already booted");
3207
3128
  const [root] = await _XyOs.monitor(async () => await loadOsNode(wallet, fullLocator), { name: "Load XyOs" });
3208
3129
  this._root = root;
3209
3130
  this.stackManager.initialize(this);
@@ -3220,13 +3141,13 @@ var XyOs = class _XyOs extends XyOsContextBase {
3220
3141
  return this.dappRegistrationService.getParamsForRegisteredDapp(dappId);
3221
3142
  }
3222
3143
  getStack(stackName) {
3223
- return assertEx24(this.stackManager.getStack(stackName), () => `Stack not found: ${stackName}`);
3144
+ return assertEx23(this.stackManager.getStack(stackName), () => `Stack not found: ${stackName}`);
3224
3145
  }
3225
3146
  async monitor(fn, eventConfig) {
3226
3147
  return await _XyOs.monitor(fn, eventConfig);
3227
3148
  }
3228
3149
  shutdown() {
3229
- assertEx24(this._root !== void 0, () => "XyOs not booted");
3150
+ assertEx23(this._root !== void 0, () => "XyOs not booted");
3230
3151
  this._root = void 0;
3231
3152
  this.stackManager.stop();
3232
3153
  }
@@ -3243,7 +3164,7 @@ var RunningDappCache = class _RunningDappCache {
3243
3164
  const existingWindowDappSet = _RunningDappCache.get(dappId);
3244
3165
  if (existingWindowDappSet) {
3245
3166
  console.debug("[DEBUG]", `RunningDappCache, using existing node for ${dappId}`);
3246
- const existingDappContext = assertEx25(existingWindowDappSet.context, () => "No context found in existing dapp node");
3167
+ const existingDappContext = assertEx24(existingWindowDappSet.context, () => "No context found in existing dapp node");
3247
3168
  await DappContextCreator.primeDappArchivist(existingDappContext, xyOs, dappId);
3248
3169
  return existingWindowDappSet;
3249
3170
  }
@@ -3274,7 +3195,7 @@ var AccessNodeQueries = class {
3274
3195
  this.registeredDappAccess = registeredDappAccess;
3275
3196
  }
3276
3197
  get nameServiceNamesAccessNode() {
3277
- return assertEx26(RunningDappAccessCache.get(this.registeredDappAccess.registeringDappId), () => "No access node found");
3198
+ return assertEx25(RunningDappAccessCache.get(this.registeredDappAccess.registeringDappId), () => "No access node found");
3278
3199
  }
3279
3200
  // Refresh the archivist in the dapp
3280
3201
  async refresh() {
@@ -3290,7 +3211,7 @@ var AccessNodeQueries = class {
3290
3211
  }
3291
3212
  async getArchivistFromDappNode() {
3292
3213
  const archivistPath = this.accessRequest?.destinationArchivist || "DappArchivist";
3293
- const mod = assertEx26(await this.xyOsContext.root.resolve(archivistPath), () => `Unable to find archivist at ${archivistPath}`);
3214
+ const mod = assertEx25(await this.xyOsContext.root.resolve(archivistPath), () => `Unable to find archivist at ${archivistPath}`);
3294
3215
  return asArchivistInstance7(mod, () => `Module at ${archivistPath} is not an archivist`);
3295
3216
  }
3296
3217
  async getPayloadsFromAccessNode() {
@@ -3303,7 +3224,7 @@ var AccessNodeQueries = class {
3303
3224
  await archivist.insert(payloads);
3304
3225
  }
3305
3226
  async resolveArchivistFromAccessNode() {
3306
- const archivist = assertEx26(
3227
+ const archivist = assertEx25(
3307
3228
  await this.nameServiceNamesAccessNode.resolve("PublicXnsArchivist"),
3308
3229
  () => "Unable to find archivist at PublicXnsArchivist"
3309
3230
  );
@@ -3312,7 +3233,7 @@ var AccessNodeQueries = class {
3312
3233
  };
3313
3234
 
3314
3235
  // src/access-interfaces/registered-names/helpers/resource/AbstractXnsCaller.ts
3315
- import { assertEx as assertEx27 } from "@xylabs/assert";
3236
+ import { assertEx as assertEx26 } from "@xylabs/assert";
3316
3237
  import { asArchivistInstance as asArchivistInstance8 } from "@xyo-network/archivist-model";
3317
3238
  import { asDivinerInstance as asDivinerInstance5 } from "@xyo-network/diviner-model";
3318
3239
  var XnsArchivistPayloadDivinerModuleName = "XnsArchivistPayloadDiviner";
@@ -3327,7 +3248,7 @@ var AbstractXnsCaller = class {
3327
3248
  */
3328
3249
  async getXnsArchivist(pathPrefix) {
3329
3250
  const fullyQualifiedPath = pathPrefix ? `${pathPrefix}:${XnsArchivistModuleName}` : XnsArchivistModuleName;
3330
- const mod = assertEx27(await this.context.root.resolve(fullyQualifiedPath), () => `${fullyQualifiedPath} not found`);
3251
+ const mod = assertEx26(await this.context.root.resolve(fullyQualifiedPath), () => `${fullyQualifiedPath} not found`);
3331
3252
  return asArchivistInstance8(mod, () => `${fullyQualifiedPath} is not an archivist`);
3332
3253
  }
3333
3254
  /**
@@ -3335,7 +3256,7 @@ var AbstractXnsCaller = class {
3335
3256
  */
3336
3257
  async getXnsArchivistPayloadDiviner(pathPrefix) {
3337
3258
  const fullyQualifiedPath = pathPrefix ? `${pathPrefix}:${XnsArchivistPayloadDivinerModuleName}` : XnsArchivistPayloadDivinerModuleName;
3338
- const mod = assertEx27(await this.context.root.resolve(fullyQualifiedPath), () => `${fullyQualifiedPath} not found`);
3259
+ const mod = assertEx26(await this.context.root.resolve(fullyQualifiedPath), () => `${fullyQualifiedPath} not found`);
3339
3260
  return asDivinerInstance5(mod, () => `${fullyQualifiedPath} is not an diviner`);
3340
3261
  }
3341
3262
  /**
@@ -3343,13 +3264,13 @@ var AbstractXnsCaller = class {
3343
3264
  */
3344
3265
  async getXnsRegistrationsArchivist(pathPrefix) {
3345
3266
  const fullyQualifiedPath = pathPrefix ? `${pathPrefix}:${XnsRegistrationsArchivistModuleName}` : XnsRegistrationsArchivistModuleName;
3346
- const mod = assertEx27(await this.context.root.resolve(fullyQualifiedPath), () => `${fullyQualifiedPath} not found`);
3267
+ const mod = assertEx26(await this.context.root.resolve(fullyQualifiedPath), () => `${fullyQualifiedPath} not found`);
3347
3268
  return asArchivistInstance8(mod, () => `${fullyQualifiedPath} is not an archivist`);
3348
3269
  }
3349
3270
  };
3350
3271
 
3351
3272
  // src/access-interfaces/registered-names/helpers/resource/RegistrationsResource.ts
3352
- import { assertEx as assertEx28 } from "@xylabs/assert";
3273
+ import { assertEx as assertEx27 } from "@xylabs/assert";
3353
3274
  import { isTemporalIndexingDivinerResultIndex } from "@xyo-network/diviner-temporal-indexing-model";
3354
3275
 
3355
3276
  // src/access-interfaces/registered-names/helpers/resource/RegistrationsResourceQueries.ts
@@ -3378,7 +3299,7 @@ var XnsRegistrationsResource = class extends AbstractXnsCaller {
3378
3299
  }
3379
3300
  _allRegistrations;
3380
3301
  get allRegistrations() {
3381
- return assertEx28(this._allRegistrations);
3302
+ return assertEx27(this._allRegistrations);
3382
3303
  }
3383
3304
  get subscriptions() {
3384
3305
  return { allRegistrations: (cb) => this.allRegistrations.subscribe(cb) };
@@ -3471,7 +3392,7 @@ var profileModuleEvents = (mod) => {
3471
3392
  };
3472
3393
 
3473
3394
  // src/PubSubBridgeCaller.ts
3474
- import { assertEx as assertEx29 } from "@xylabs/assert";
3395
+ import { assertEx as assertEx28 } from "@xylabs/assert";
3475
3396
  import { asBridgeInstance } from "@xyo-network/bridge-model";
3476
3397
  import { BridgedPubSubModuleName } from "@xyo-network/os-model";
3477
3398
  var PubSubBridgeCaller = class {
@@ -3492,7 +3413,7 @@ var PubSubBridgeCaller = class {
3492
3413
  }
3493
3414
  }
3494
3415
  async getPubSubBridge() {
3495
- const mod = assertEx29(await this.node.resolve(BridgedPubSubModuleName), () => `${BridgedPubSubModuleName} not found`);
3416
+ const mod = assertEx28(await this.node.resolve(BridgedPubSubModuleName), () => `${BridgedPubSubModuleName} not found`);
3496
3417
  return asBridgeInstance(mod, () => `${BridgedPubSubModuleName} is not a bridge`);
3497
3418
  }
3498
3419
  };