@ibgib/space-gib 0.0.19 → 0.0.21

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,6 +1,6 @@
1
1
  // src/server/server.mts
2
2
  import { createServer } from "node:http";
3
- import { join as join10, dirname } from "node:path";
3
+ import { join as join11, dirname } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
 
6
6
  // ../../libs/helper-gib/dist/constants.mjs
@@ -247,10 +247,10 @@ function isExpired({ expirationTimestampUTC }) {
247
247
  function unique(arr) {
248
248
  return Array.from(new Set(arr));
249
249
  }
250
- function patchObject({ obj, value, path: path7, pathDelimiter, logalot: logalot74 }) {
250
+ function patchObject({ obj, value, path: path8, pathDelimiter, logalot: logalot75 }) {
251
251
  const lc2 = `[${patchObject.name}]`;
252
252
  try {
253
- if (logalot74) {
253
+ if (logalot75) {
254
254
  console.log(`${lc2} starting...`);
255
255
  }
256
256
  if (!obj) {
@@ -259,12 +259,12 @@ function patchObject({ obj, value, path: path7, pathDelimiter, logalot: logalot7
259
259
  if (typeof obj !== "object") {
260
260
  throw new Error(`obj must be type 'object' (E: 66fdc289b32c06492bd95f5d266e6a22)`);
261
261
  }
262
- if (!path7) {
262
+ if (!path8) {
263
263
  throw new Error(`path required (at the very least should be the key in the root obj.) (E: fc779e7794ead8a0b44e5f2e776b0e22)`);
264
264
  }
265
265
  pathDelimiter = pathDelimiter || DEFAULT_DATA_PATH_DELIMITER;
266
266
  let targetObj = obj;
267
- const pathPieces = path7.split(pathDelimiter).filter((x) => !!x);
267
+ const pathPieces = path8.split(pathDelimiter).filter((x) => !!x);
268
268
  const key = pathPieces.pop();
269
269
  pathPieces.forEach((piece) => {
270
270
  let currentValue = targetObj[piece];
@@ -282,7 +282,7 @@ function patchObject({ obj, value, path: path7, pathDelimiter, logalot: logalot7
282
282
  console.error(`${lc2} ${error.message}`);
283
283
  throw error;
284
284
  } finally {
285
- if (logalot74) {
285
+ if (logalot75) {
286
286
  console.log(`${lc2} complete.`);
287
287
  }
288
288
  }
@@ -1149,18 +1149,18 @@ function validateRawPath(rawPath) {
1149
1149
  }
1150
1150
  }
1151
1151
  }
1152
- function isSafePath(path7) {
1153
- const errors = validateRawPath(path7);
1152
+ function isSafePath(path8) {
1153
+ const errors = validateRawPath(path8);
1154
1154
  return errors.length === 0;
1155
1155
  }
1156
- function validateStaticPath(path7) {
1156
+ function validateStaticPath(path8) {
1157
1157
  const lc2 = `[${validateStaticPath.name}]`;
1158
1158
  try {
1159
1159
  if (logalot3) {
1160
1160
  console.log(`${lc2} starting... (I: 4f9cf8ffd528c7dd88324529528eeb26)`);
1161
1161
  }
1162
1162
  const errors = [];
1163
- if (!VALID_STATIC_PATH_REGEX.test(path7)) {
1163
+ if (!VALID_STATIC_PATH_REGEX.test(path8)) {
1164
1164
  errors.push(`static path fails to match VALID_STATIC_PATH_REGEX of ${VALID_STATIC_PATH_REGEX} (E: dfdf38a0439d4d09186e6fa81ab66826) `);
1165
1165
  }
1166
1166
  return errors;
@@ -1172,11 +1172,11 @@ function validateStaticPath(path7) {
1172
1172
  }
1173
1173
  }
1174
1174
  }
1175
- function isValidStaticPath(path7) {
1176
- if (!isSafePath(path7)) {
1175
+ function isValidStaticPath(path8) {
1176
+ if (!isSafePath(path8)) {
1177
1177
  return false;
1178
1178
  }
1179
- const errors = validateStaticPath(path7);
1179
+ const errors = validateStaticPath(path8);
1180
1180
  return errors.length === 0;
1181
1181
  }
1182
1182
  function validateAddressSegment(encodedAddr) {
@@ -9408,17 +9408,17 @@ var B2TFS_DEFAULT_ENCODINGS_TO_TRY = [
9408
9408
 
9409
9409
  // ../../libs/node-gib/dist/witness/space/node-filesystem-space/node-filesystem-space-helper.mjs
9410
9410
  var logalot15 = GLOBAL_LOG_A_LOT3;
9411
- async function tryRead({ path: path7, directory, encoding }) {
9411
+ async function tryRead({ path: path8, directory, encoding }) {
9412
9412
  const lc2 = `[${tryRead.name}]`;
9413
9413
  try {
9414
9414
  if (logalot15) {
9415
9415
  console.log(`${lc2} starting...`);
9416
9416
  console.log(`${lc2} cwd: ${cwd()}`);
9417
- if (path7.includes("bootstrap^gib")) {
9417
+ if (path8.includes("bootstrap^gib")) {
9418
9418
  console.log(`${lc2} trying bootstrap^gib... (I: dacfdbe5a2d640ab947a7c17e3c56f78)`);
9419
9419
  }
9420
9420
  }
9421
- const fullPath = pathUtils.join(directory, path7);
9421
+ const fullPath = pathUtils.join(directory, path8);
9422
9422
  if (logalot15) {
9423
9423
  console.log(`${lc2} fullPath: ${fullPath} (I: 459b416ac32c711bfbab54177839b323)`);
9424
9424
  }
@@ -9432,7 +9432,7 @@ async function tryRead({ path: path7, directory, encoding }) {
9432
9432
  return resRead;
9433
9433
  } catch (error) {
9434
9434
  if (logalot15) {
9435
- console.log(`${lc2} fullPath not found from directory (${directory}) and path (${path7})
9435
+ console.log(`${lc2} fullPath not found from directory (${directory}) and path (${path8})
9436
9436
  error:
9437
9437
  ${extractErrorMsg(error)} (I: 1fde689d29aa47fcb589b3e7dac8929b)`);
9438
9438
  }
@@ -9443,17 +9443,17 @@ ${extractErrorMsg(error)} (I: 1fde689d29aa47fcb589b3e7dac8929b)`);
9443
9443
  }
9444
9444
  }
9445
9445
  }
9446
- async function tryRead_bin({ path: path7, directory, encoding }) {
9446
+ async function tryRead_bin({ path: path8, directory, encoding }) {
9447
9447
  const lc2 = `[${tryRead_bin.name}]`;
9448
9448
  try {
9449
9449
  if (logalot15) {
9450
9450
  console.log(`${lc2} starting...`);
9451
9451
  console.log(`${lc2} cwd: ${cwd()}`);
9452
- if (path7.includes("bootstrap^gib")) {
9452
+ if (path8.includes("bootstrap^gib")) {
9453
9453
  console.log(`${lc2} trying bootstrap^gib... (I: 5eb010444b814addb1a6bbe18ca3dbfa)`);
9454
9454
  }
9455
9455
  }
9456
- const fullPath = pathUtils.join(directory, path7);
9456
+ const fullPath = pathUtils.join(directory, path8);
9457
9457
  if (logalot15) {
9458
9458
  console.log(`${lc2} fullPath: ${fullPath} (I: c342bf56df354e9ab2653855a458b99d)`);
9459
9459
  }
@@ -9483,7 +9483,7 @@ async function tryRead_bin({ path: path7, directory, encoding }) {
9483
9483
  };
9484
9484
  } catch (error) {
9485
9485
  if (logalot15) {
9486
- console.log(`${lc2} fullPath not found from directory (${directory}) and path (${path7})
9486
+ console.log(`${lc2} fullPath not found from directory (${directory}) and path (${path8})
9487
9487
  error:
9488
9488
  ${extractErrorMsg(error)} (I: 882e54f079024c94864bdaa74979b397)`);
9489
9489
  }
@@ -9692,23 +9692,23 @@ var NodeFilesystemSpace_V1 = class _NodeFilesystemSpace_V1 extends FilesystemSpa
9692
9692
  }
9693
9693
  ;
9694
9694
  const thisData = this.data;
9695
- let path7 = "";
9695
+ let path8 = "";
9696
9696
  let data = "";
9697
9697
  const addr = getIbGibAddr({ ibGib });
9698
9698
  const isBin = isBinary({ addr });
9699
- path7 = await this.buildPath({
9699
+ path8 = await this.buildPath({
9700
9700
  addr,
9701
9701
  isDna: isDna2 ?? false,
9702
9702
  isBin,
9703
9703
  ensureMetaStonePaths: true
9704
9704
  });
9705
- await this.ensureDirsImpl([pathUtils2.dirname(path7)]);
9706
- let fullPath = pathUtils2.join(thisData.baseDir, path7);
9705
+ await this.ensureDirsImpl([pathUtils2.dirname(path8)]);
9706
+ let fullPath = pathUtils2.join(thisData.baseDir, path8);
9707
9707
  if (logalot16) {
9708
9708
  console.log(`${lc2} fullPath: ${fullPath} (I: 2441a896f7e6418db57c0341d5c65ef2)`);
9709
9709
  }
9710
9710
  if (logalot16) {
9711
- console.log(`${lc2} path: ${path7}, directory: ${thisData.baseDir}, thisData.encoding: ${thisData.encoding} (I: d4440ececbe6c859f8fcf6d7ece12522)`);
9711
+ console.log(`${lc2} path: ${path8}, directory: ${thisData.baseDir}, thisData.encoding: ${thisData.encoding} (I: d4440ececbe6c859f8fcf6d7ece12522)`);
9712
9712
  }
9713
9713
  let encoding;
9714
9714
  if (!isBin) {
@@ -9744,15 +9744,15 @@ var NodeFilesystemSpace_V1 = class _NodeFilesystemSpace_V1 extends FilesystemSpa
9744
9744
  throw new Error(`this.data required (E: 27e1f5206d96d635e617f5ba69141423)`);
9745
9745
  }
9746
9746
  const data = this.data;
9747
- let path7 = "";
9747
+ let path8 = "";
9748
9748
  if (!isBinary({ addr })) {
9749
- path7 = await this.buildPath({
9749
+ path8 = await this.buildPath({
9750
9750
  addr,
9751
9751
  isDna: isDna2 ?? false,
9752
9752
  ensureMetaStonePaths: true
9753
9753
  });
9754
9754
  } else {
9755
- path7 = await this.buildPath({
9755
+ path8 = await this.buildPath({
9756
9756
  addr,
9757
9757
  isDna: false,
9758
9758
  isBin: true,
@@ -9760,12 +9760,12 @@ var NodeFilesystemSpace_V1 = class _NodeFilesystemSpace_V1 extends FilesystemSpa
9760
9760
  });
9761
9761
  }
9762
9762
  if (logalot16) {
9763
- console.log(`${lc2} path: ${path7}, directory: ${data.baseDir}`);
9763
+ console.log(`${lc2} path: ${path8}, directory: ${data.baseDir}`);
9764
9764
  }
9765
- const fullPath = pathUtils2.join(this.data.baseDir, path7);
9765
+ const fullPath = pathUtils2.join(this.data.baseDir, path8);
9766
9766
  await rm(fullPath, { force: true });
9767
9767
  if (logalot16) {
9768
- console.log(`${lc2} deleted. path: ${path7}`);
9768
+ console.log(`${lc2} deleted. path: ${path8}`);
9769
9769
  }
9770
9770
  result.success = true;
9771
9771
  } catch (error) {
@@ -9967,10 +9967,10 @@ var NodeFilesystemSpace_V1 = class _NodeFilesystemSpace_V1 extends FilesystemSpa
9967
9967
  return;
9968
9968
  }
9969
9969
  for (let i = 0; i < paths.length; i++) {
9970
- const path7 = paths[i];
9971
- const lc22 = `${lc2}[(path: ${path7}, directory: ${directory})]`;
9972
- const fullPath = pathUtils2.join(directory, path7);
9973
- const pathExistsKey = getPathKey(path7);
9970
+ const path8 = paths[i];
9971
+ const lc22 = `${lc2}[(path: ${path8}, directory: ${directory})]`;
9972
+ const fullPath = pathUtils2.join(directory, path8);
9973
+ const pathExistsKey = getPathKey(path8);
9974
9974
  let exists = this.pathExistsMap[pathExistsKey] || false;
9975
9975
  if (!exists) {
9976
9976
  try {
@@ -12316,19 +12316,19 @@ var DynamicFormFactoryBase = class _DynamicFormFactoryBase extends WitnessFactor
12316
12316
  }
12317
12317
  for (let i = 0; i < items.length; i++) {
12318
12318
  const item = items[i];
12319
- const path7 = contextPath ? contextPath + pathDelimiter + item.name : item.name;
12319
+ const path8 = contextPath ? contextPath + pathDelimiter + item.name : item.name;
12320
12320
  if (!item.items) {
12321
12321
  patchObject({
12322
12322
  obj: data,
12323
12323
  value: item.value,
12324
- path: path7,
12324
+ path: path8,
12325
12325
  logalot: logalot21,
12326
12326
  pathDelimiter
12327
12327
  });
12328
12328
  } else if (item.items.length > 0) {
12329
12329
  this.patchDataFromItems({
12330
12330
  data,
12331
- contextPath: path7,
12331
+ contextPath: path8,
12332
12332
  items: item.items,
12333
12333
  pathDelimiter
12334
12334
  });
@@ -17609,28 +17609,41 @@ var IdentityIndexService = class _IdentityIndexService {
17609
17609
  * Throws `duplicate_identity_409` error if email is already registered.
17610
17610
  */
17611
17611
  async registerEmailIndex({ email, tjpAddr, primaryTjpAddr }) {
17612
- const targetAddr = tjpAddr || primaryTjpAddr;
17613
- if (!targetAddr) {
17614
- throw new Error("Either tjpAddr or primaryTjpAddr must be provided. (E: 62f15851b9a8c8d718279ab84e426826)");
17615
- }
17616
- const emailHash = await getIdentityEmailHash({ email, salt: this.salt });
17617
- const { folderPath, filePath } = getShardedIndexPath({
17618
- baseDir: this.baseDir,
17619
- emailHash
17620
- });
17621
- await fs.mkdir(folderPath, { recursive: true });
17622
- const record = {
17623
- tjpAddr: targetAddr,
17624
- createdAt: Date.now()
17625
- };
17612
+ const lc2 = `${this.lc}[${this.registerEmailIndex.name}]`;
17626
17613
  try {
17627
- await fs.writeFile(filePath, JSON.stringify(record, null, 2), { flag: "wx" });
17628
- return { emailHash, filePath, record };
17629
- } catch (error) {
17630
- if (error.code === "EEXIST") {
17631
- throw new Error(`Email is already registered (E: duplicate_identity_409)`);
17614
+ if (logalot38) {
17615
+ console.log(`${lc2} starting... (I: 5d1728a955657616a8cf6ce8b5afa226)`);
17616
+ }
17617
+ const targetAddr = tjpAddr || primaryTjpAddr;
17618
+ if (!targetAddr) {
17619
+ throw new Error("Either tjpAddr or primaryTjpAddr must be provided. (E: 62f15851b9a8c8d718279ab84e426826)");
17620
+ }
17621
+ const emailHash = await getIdentityEmailHash({ email, salt: this.salt });
17622
+ const { folderPath, filePath } = getShardedIndexPath({
17623
+ baseDir: this.baseDir,
17624
+ emailHash
17625
+ });
17626
+ await fs.mkdir(folderPath, { recursive: true });
17627
+ const record = {
17628
+ tjpAddr: targetAddr,
17629
+ createdAt: Date.now()
17630
+ };
17631
+ try {
17632
+ await fs.writeFile(filePath, JSON.stringify(record, null, 2), { flag: "wx" });
17633
+ return { emailHash, filePath, record };
17634
+ } catch (error) {
17635
+ if (error.code === "EEXIST") {
17636
+ throw new Error(`Email is already registered (E: duplicate_identity_409)`);
17637
+ }
17638
+ throw error;
17632
17639
  }
17640
+ } catch (error) {
17641
+ console.error(`${lc2} ${extractErrorMsg(error)}`);
17633
17642
  throw error;
17643
+ } finally {
17644
+ if (logalot38) {
17645
+ console.log(`${lc2} complete.`);
17646
+ }
17634
17647
  }
17635
17648
  }
17636
17649
  /**
@@ -18123,6 +18136,9 @@ var StaticFileHandler = class _StaticFileHandler extends ServeGibHandlerBase {
18123
18136
  if (existsSync3(filePath) && statSync(filePath).isDirectory()) {
18124
18137
  filePath = join6(filePath, "index.html");
18125
18138
  }
18139
+ if (!existsSync3(filePath) && existsSync3(filePath + ".html")) {
18140
+ filePath = filePath + ".html";
18141
+ }
18126
18142
  if (!existsSync3(filePath)) {
18127
18143
  filePath = join6(this.clientDir, "index.html");
18128
18144
  }
@@ -19239,6 +19255,7 @@ var KeystoneProfileBuilder = class _KeystoneProfileBuilder {
19239
19255
  };
19240
19256
 
19241
19257
  // ../../libs/core-gib/dist/keystone/delegate/delegate-constants.mjs
19258
+ var KEYSTONE_ROLE_CUSTODIAL_SYNC = "custodial-sync";
19242
19259
  var DEFAULT_DELEGATE_TTL_SECONDS = 30 * 24 * 60 * 60;
19243
19260
  var CUSTODIAN_POOL_ID_PREFIX = "custodian-manage-";
19244
19261
 
@@ -19264,6 +19281,9 @@ function isKeystoneExpired({ keystone, nowUTC }) {
19264
19281
  return currentMs > expirationMs;
19265
19282
  }
19266
19283
  function isDelegateExpired({ delegateInfo, delegateKeystone, nowUTC }) {
19284
+ if (!delegateInfo && !delegateKeystone) {
19285
+ throw new Error(`either delegateInfo or delegateKeystone required. (E: d1baa55ca8d23b26f8562a28179d2126)`);
19286
+ }
19267
19287
  if (delegateKeystone) {
19268
19288
  return isKeystoneExpired({ keystone: delegateKeystone, nowUTC });
19269
19289
  }
@@ -19277,6 +19297,35 @@ function isDelegateExpired({ delegateInfo, delegateKeystone, nowUTC }) {
19277
19297
  const currentMs = nowUTC !== void 0 ? typeof nowUTC === "number" ? nowUTC : nowUTC instanceof Date ? nowUTC.getTime() : Date.parse(nowUTC) : Date.now();
19278
19298
  return currentMs > expirationMs;
19279
19299
  }
19300
+ function isCustodialDelegate({ delegateInfo, delegateKeystone, providerId }) {
19301
+ if (!delegateInfo && !delegateKeystone) {
19302
+ return false;
19303
+ }
19304
+ const role = delegateInfo?.role || delegateKeystone?.data?.frameDetails?.role;
19305
+ const deviceName = delegateInfo?.deviceName || delegateKeystone?.data?.frameDetails?.deviceTag;
19306
+ const metadataProvider = delegateInfo?.metadata?.provider || delegateKeystone?.data?.frameDetails?.custodianProvider || delegateKeystone?.data?.frameDetails?.metadata?.provider;
19307
+ const isExplicitCustodialRole = role === KEYSTONE_ROLE_CUSTODIAL_SYNC || role === "custodial-sync";
19308
+ if (metadataProvider) {
19309
+ if (providerId) {
19310
+ return String(metadataProvider).toLowerCase() === String(providerId).toLowerCase();
19311
+ }
19312
+ return true;
19313
+ }
19314
+ if (deviceName) {
19315
+ const lowerDevice = deviceName.toLowerCase();
19316
+ if (providerId) {
19317
+ const lowerProvider = String(providerId).toLowerCase();
19318
+ return lowerDevice.includes(lowerProvider) || isExplicitCustodialRole && lowerDevice.includes("custodian");
19319
+ }
19320
+ if (lowerDevice.includes("custodian") || lowerDevice.includes("oauth2") || lowerDevice.includes("google") || lowerDevice.includes("github") || lowerDevice.startsWith("email-") || lowerDevice.includes("@")) {
19321
+ return true;
19322
+ }
19323
+ }
19324
+ if (!providerId && isExplicitCustodialRole) {
19325
+ return true;
19326
+ }
19327
+ return false;
19328
+ }
19280
19329
 
19281
19330
  // ../../libs/core-gib/dist/keystone/strategy/hash-reveal-v1/hash-reveal-v1.mjs
19282
19331
  var KeystoneStrategy_HashRevealV1 = class _KeystoneStrategy_HashRevealV1 extends KeystoneStrategy {
@@ -20437,7 +20486,7 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
20437
20486
  /**
20438
20487
  * Creates a brand new Keystone Identity Timeline.
20439
20488
  */
20440
- async genesis({ masterSecret, emails, frameDetails, configs, metaspace, space, isPrimary }) {
20489
+ async genesis({ masterSecret, emails, frameDetails, credentialIds, dataToPatch, configs, metaspace, space, isPrimary }) {
20441
20490
  const lc2 = `${this.lc}[${this.genesis.name}]`;
20442
20491
  try {
20443
20492
  if (logalot46) {
@@ -20462,12 +20511,18 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
20462
20511
  if (emails && emails.length > 0) {
20463
20512
  data.emails = [...emails];
20464
20513
  }
20514
+ if (credentialIds && credentialIds.length > 0) {
20515
+ data.credentialIds = [...credentialIds];
20516
+ }
20465
20517
  if (frameDetails || isPrimary !== void 0) {
20466
20518
  data.frameDetails = { ...frameDetails || {} };
20467
20519
  if (isPrimary !== void 0) {
20468
20520
  data.frameDetails.isPrimary = isPrimary;
20469
20521
  }
20470
20522
  }
20523
+ if (dataToPatch) {
20524
+ Object.assign(data, dataToPatch);
20525
+ }
20471
20526
  const keystoneIbGib = await createKeystoneIbGibImpl({ data, metaspace, space });
20472
20527
  return keystoneIbGib;
20473
20528
  } catch (error) {
@@ -20580,12 +20635,15 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
20580
20635
  * to the parent's `delegates` map. This operation is signed using the parent's `manage` pool.
20581
20636
  * Validates the delegate keystone's entire graph/timeline before registering.
20582
20637
  */
20583
- async registerDelegate({ parentKeystone, delegateKeystone, masterSecret, frameDetails, metaspace, space, allowedVerbs, deviceName, expirationUTC, ttlSeconds }) {
20638
+ async registerDelegate({ parentKeystone, delegateKeystone, masterSecret, signingPoolId, frameDetails, metaspace, space, allowedVerbs, deviceName, expirationUTC, ttlSeconds }) {
20584
20639
  const lc2 = `${this.lc}[${this.registerDelegate.name}]`;
20585
20640
  try {
20586
20641
  if (logalot46) {
20587
20642
  console.log(`${lc2} starting...`);
20588
20643
  }
20644
+ if (!signingPoolId) {
20645
+ throw new Error(`signingPoolId is required (E: a1b2c3d4e5f6818fa8ab28c9b60e6899)`);
20646
+ }
20589
20647
  const validationErrors = await validateKeystoneGraph({
20590
20648
  keystoneIbGib: delegateKeystone,
20591
20649
  getLatest: true,
@@ -20596,9 +20654,14 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
20596
20654
  throw new Error(`Delegate keystone validation failed: ${validationErrors.join(", ")} (E: 88fa8ab28c9b60e68994511a5825)`);
20597
20655
  }
20598
20656
  const prevData = parentKeystone.data;
20599
- const hasManagePool = prevData.challengePools.some((p) => p.id === POOL_ID_MANAGE);
20600
- if (!hasManagePool) {
20601
- throw new Error(`Parent keystone does not support delegation. Manage pool is required. (E: 818fa8ab28c9b60e68994511a5825)`);
20657
+ const signingPool = prevData.challengePools.find((p) => p.id === signingPoolId);
20658
+ if (!signingPool) {
20659
+ throw new Error(`Parent keystone does not contain signing pool: ${signingPoolId} (E: 818fa8ab28c9b60e68994511a5825)`);
20660
+ }
20661
+ if (signingPool.config.allowedVerbs && signingPool.config.allowedVerbs.length > 0) {
20662
+ if (!signingPool.config.allowedVerbs.includes(KEYSTONE_VERB_MANAGE)) {
20663
+ throw new Error(`Signing pool ${signingPoolId} is not authorized for verb: ${KEYSTONE_VERB_MANAGE} (E: 918fa8ab28c9b60e68994511a5825)`);
20664
+ }
20602
20665
  }
20603
20666
  const delegateTjpAddr = getTjpAddr({ ibGib: delegateKeystone });
20604
20667
  if (!delegateTjpAddr) {
@@ -20618,13 +20681,14 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
20618
20681
  deviceName,
20619
20682
  allowedVerbs,
20620
20683
  spaceId,
20621
- expirationUTC: effectiveExpirationUTC
20684
+ expirationUTC: effectiveExpirationUTC,
20685
+ role: delegateKeystone.data?.frameDetails?.role
20622
20686
  };
20623
20687
  const evolved = await this.sign({
20624
20688
  latestKeystone: parentKeystone,
20625
20689
  masterSecret,
20626
20690
  claim,
20627
- poolId: POOL_ID_MANAGE,
20691
+ poolId: signingPoolId,
20628
20692
  frameDetails,
20629
20693
  metaspace,
20630
20694
  space,
@@ -20644,18 +20708,26 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
20644
20708
  }
20645
20709
  /**
20646
20710
  * Unregisters a delegate keystone from the parent keystone by removing its entry
20647
- * from the parent's `delegates` map. This operation is signed using the parent's `manage` pool.
20711
+ * from the parent's `delegates` map.
20648
20712
  */
20649
- async unregisterDelegate({ parentKeystone, delegateTjpAddr, masterSecret, frameDetails, metaspace, space }) {
20713
+ async unregisterDelegate({ parentKeystone, delegateTjpAddr, masterSecret, signingPoolId, frameDetails, metaspace, space }) {
20650
20714
  const lc2 = `${this.lc}[${this.unregisterDelegate.name}]`;
20651
20715
  try {
20652
20716
  if (logalot46) {
20653
20717
  console.log(`${lc2} starting...`);
20654
20718
  }
20719
+ if (!signingPoolId) {
20720
+ throw new Error(`signingPoolId is required (E: b2c3d4e5f6a13889f8ab28c9b60e6899)`);
20721
+ }
20655
20722
  const prevData = parentKeystone.data;
20656
- const hasManagePool = prevData.challengePools.some((p) => p.id === POOL_ID_MANAGE);
20657
- if (!hasManagePool) {
20658
- throw new Error(`Parent keystone does not support delegation. Manage pool is required. (E: 3889f8ab28c9b60e68994511a5825)`);
20723
+ const signingPool = prevData.challengePools.find((p) => p.id === signingPoolId);
20724
+ if (!signingPool) {
20725
+ throw new Error(`Parent keystone does not contain signing pool: ${signingPoolId} (E: 3889f8ab28c9b60e68994511a5825)`);
20726
+ }
20727
+ if (signingPool.config.allowedVerbs && signingPool.config.allowedVerbs.length > 0) {
20728
+ if (!signingPool.config.allowedVerbs.includes(KEYSTONE_VERB_MANAGE)) {
20729
+ throw new Error(`Signing pool ${signingPoolId} is not authorized for verb: ${KEYSTONE_VERB_MANAGE} (E: 4889f8ab28c9b60e68994511a5825)`);
20730
+ }
20659
20731
  }
20660
20732
  const claim = {
20661
20733
  target: delegateTjpAddr,
@@ -20670,7 +20742,7 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
20670
20742
  latestKeystone: parentKeystone,
20671
20743
  masterSecret,
20672
20744
  claim,
20673
- poolId: POOL_ID_MANAGE,
20745
+ poolId: signingPoolId,
20674
20746
  frameDetails,
20675
20747
  metaspace,
20676
20748
  space,
@@ -20753,7 +20825,7 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
20753
20825
  if (logalot46) {
20754
20826
  console.log(`${lc2} starting...`);
20755
20827
  }
20756
- const latestAddr = await metaspace.getLatestAddr({ tjpAddr: addr, space });
20828
+ const latestAddr = await metaspace.getLatestAddr({ addr, space });
20757
20829
  if (!latestAddr) {
20758
20830
  throw new Error(`could not find latest addr for ${addr}`);
20759
20831
  }
@@ -20891,7 +20963,7 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
20891
20963
  * Requires the Master Secret to authorize the change via a pool containing
20892
20964
  * the 'manage' verb.
20893
20965
  */
20894
- async addPools({ latestKeystone, masterSecret, newPools, metaspace, space }) {
20966
+ async addPools({ latestKeystone, masterSecret, signingPoolId, newPools, frameDetails, dataToPatch, metaspace, space }) {
20895
20967
  const lc2 = `${this.lc}[${this.addPools.name}]`;
20896
20968
  try {
20897
20969
  if (logalot46) {
@@ -20909,6 +20981,7 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
20909
20981
  }
20910
20982
  const adminPool = resolveTargetPool({
20911
20983
  pools: prevData.challengePools,
20984
+ poolId: signingPoolId,
20912
20985
  verb: KEYSTONE_VERB_MANAGE
20913
20986
  });
20914
20987
  if (logalot46) {
@@ -20947,7 +21020,7 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
20947
21020
  if (n % KEYSTONE_CHECKPOINT_FREQUENCY === 0) {
20948
21021
  const currentFrameView = {
20949
21022
  ...latestKeystone,
20950
- data: { ...prevData, challengePools: finalPools }
21023
+ data: { ...prevData, challengePools: finalPools, frameDetails }
20951
21024
  };
20952
21025
  checkpointDetails = await this.getAggregateDetails({
20953
21026
  latestKeystone: currentFrameView,
@@ -20959,8 +21032,10 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
20959
21032
  challengePools: finalPools,
20960
21033
  proofs: [proof],
20961
21034
  // The proof authorizes the structure change
21035
+ frameDetails,
20962
21036
  checkpointDetails,
20963
- ...prevData.delegates ? { delegates: prevData.delegates } : {}
21037
+ ...prevData.delegates ? { delegates: prevData.delegates } : {},
21038
+ ...dataToPatch
20964
21039
  };
20965
21040
  const newKeystone = await evolvePersistAndRegisterKeystone({
20966
21041
  prevIbGib: latestKeystone,
@@ -20986,7 +21061,7 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
20986
21061
  * Requires the Master Secret to authorize the change via a pool containing
20987
21062
  * the 'manage' verb (the administrative manage pool).
20988
21063
  */
20989
- async removePools({ latestKeystone, masterSecret, poolIds, metaspace, space }) {
21064
+ async removePools({ latestKeystone, masterSecret, signingPoolId, poolIds, frameDetails, dataToPatch, metaspace, space }) {
20990
21065
  const lc2 = `${this.lc}[${this.removePools.name}]`;
20991
21066
  try {
20992
21067
  if (logalot46) {
@@ -21004,6 +21079,7 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
21004
21079
  }
21005
21080
  const adminPool = resolveTargetPool({
21006
21081
  pools: prevData.challengePools,
21082
+ poolId: signingPoolId,
21007
21083
  verb: KEYSTONE_VERB_MANAGE
21008
21084
  });
21009
21085
  if (logalot46) {
@@ -21040,7 +21116,7 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
21040
21116
  if (n % KEYSTONE_CHECKPOINT_FREQUENCY === 0) {
21041
21117
  const currentFrameView = {
21042
21118
  ...latestKeystone,
21043
- data: { ...prevData, challengePools: finalPools }
21119
+ data: { ...prevData, challengePools: finalPools, frameDetails }
21044
21120
  };
21045
21121
  checkpointDetails = await this.getAggregateDetails({
21046
21122
  latestKeystone: currentFrameView,
@@ -21051,8 +21127,10 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
21051
21127
  const newData = {
21052
21128
  challengePools: finalPools,
21053
21129
  proofs: [proof],
21130
+ frameDetails,
21054
21131
  checkpointDetails,
21055
- ...prevData.delegates ? { delegates: prevData.delegates } : {}
21132
+ ...prevData.delegates ? { delegates: prevData.delegates } : {},
21133
+ ...dataToPatch
21056
21134
  };
21057
21135
  const newKeystone = await evolvePersistAndRegisterKeystone({
21058
21136
  prevIbGib: latestKeystone,
@@ -21104,10 +21182,12 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
21104
21182
  }
21105
21183
  const res = await metaspace.get({ addr: prevAddr, space });
21106
21184
  if (!res.success || !res.ibGibs || res.ibGibs.length === 0) {
21107
- throw new Error(`Could not find previous keystone frame at ${prevAddr} (E: e3d069b22e11e550e58844889ddb5325)`);
21185
+ console.warn(`${lc2} Could not find previous keystone frame at ${prevAddr} (W: e3d069b22e11e550e58844889ddb5325). Returning aggregated details collected so far.`);
21186
+ break;
21108
21187
  }
21109
21188
  current = res.ibGibs[0];
21110
21189
  }
21190
+ this.pruneTombstoneNulls(aggregated);
21111
21191
  return aggregated;
21112
21192
  } catch (error) {
21113
21193
  console.error(`${lc2} ${extractErrorMsg(error)}`);
@@ -21397,22 +21477,32 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
21397
21477
  if ((poolIds ?? []).length === 0) {
21398
21478
  const delegateSigningSecret = await deriveDelegateSecret({ masterSecret: signingSecret });
21399
21479
  const delegateNewMasterSecret = await deriveDelegateSecret({ masterSecret: newMasterSecret });
21400
- const delegateTjpAddrs = Object.keys(latestKeystone.data.delegates ?? {});
21401
- for (const delegateTjpAddr of delegateTjpAddrs) {
21402
- const { newKeystone: newDelegate, newDelegates: newDelegatesSecondOrder } = await this.changePassword({
21403
- keystoneAddr: delegateTjpAddr,
21404
- metaspace,
21405
- space,
21406
- newMasterSecret: delegateNewMasterSecret,
21407
- signingSecret: delegateSigningSecret,
21408
- signingPoolId,
21409
- poolIds: void 0,
21410
- frameDetails
21411
- });
21412
- if (newDelegatesSecondOrder && newDelegatesSecondOrder.length > 0) {
21413
- throw new Error(`(UNEXPECTED) Delegate keystone has its own delegate(s)? ATOW (07/20/2026) second order delegates are not supported. (E: de45a7b7d9b8f61f6e58158269acba26)`);
21480
+ const delegatesMap = latestKeystone.data.delegates ?? {};
21481
+ for (const [delegateTjpAddr, delegateInfo] of Object.entries(delegatesMap)) {
21482
+ if (isCustodialDelegate({ delegateInfo })) {
21483
+ if (logalot46) {
21484
+ console.log(`${lc2} Skipping custodial delegate rotation for ${delegateTjpAddr} (${delegateInfo.deviceName})`);
21485
+ }
21486
+ continue;
21487
+ }
21488
+ try {
21489
+ const { newKeystone: newDelegate, newDelegates: newDelegatesSecondOrder } = await this.changePassword({
21490
+ keystoneAddr: delegateTjpAddr,
21491
+ metaspace,
21492
+ space,
21493
+ newMasterSecret: delegateNewMasterSecret,
21494
+ signingSecret: delegateSigningSecret,
21495
+ signingPoolId,
21496
+ poolIds: void 0,
21497
+ frameDetails
21498
+ });
21499
+ if (newDelegatesSecondOrder && newDelegatesSecondOrder.length > 0) {
21500
+ throw new Error(`(UNEXPECTED) Delegate keystone has its own delegate(s)? ATOW (07/20/2026) second order delegates are not supported. (E: de45a7b7d9b8f61f6e58158269acba26)`);
21501
+ }
21502
+ newDelegates.push(newDelegate);
21503
+ } catch (delegateErr) {
21504
+ console.warn(`${lc2} Error rotating user delegate ${delegateTjpAddr}: ${extractErrorMsg(delegateErr)}. Continuing.`);
21414
21505
  }
21415
- newDelegates.push(newDelegate);
21416
21506
  }
21417
21507
  }
21418
21508
  return { newKeystone: newKeystoneIbGib, newDelegates: newDelegates.length > 0 ? newDelegates : void 0 };
@@ -21429,20 +21519,55 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
21429
21519
  * Verifies if a candidate signing secret (password) is correct for a specific challenge pool.
21430
21520
  * Does not mutate any state.
21431
21521
  */
21432
- async verifySigningSecret({ keystoneIbGib, signingSecret, poolId }) {
21522
+ /**
21523
+ * Verifies if a given secret successfully solves challenges in the specified pool
21524
+ * (or any candidate manage pool if poolId is omitted).
21525
+ */
21526
+ async verifySigningSecret({ keystoneIbGib, signingSecret, poolId, verb = KEYSTONE_VERB_MANAGE }) {
21433
21527
  const lc2 = `${this.lc}[${this.verifySigningSecret.name}]`;
21434
21528
  try {
21435
21529
  if (!keystoneIbGib.data)
21436
21530
  return false;
21437
- const pool = keystoneIbGib.data.challengePools.find((p) => p.id === poolId);
21438
- if (!pool)
21439
- return false;
21440
- return await verifyPoolSecret({ pool, signingSecret });
21531
+ const pools = keystoneIbGib.data.challengePools;
21532
+ if (poolId) {
21533
+ const pool = pools.find((p) => p.id === poolId);
21534
+ if (!pool)
21535
+ return false;
21536
+ return await verifyPoolSecret({ pool, signingSecret });
21537
+ }
21538
+ const candidatePools = pools.filter((p) => p.id === "manage" || p.id.startsWith("passkey-manage-") || p.config.allowedVerbs && verb && p.config.allowedVerbs.includes(verb));
21539
+ for (const candidate of candidatePools) {
21540
+ const isValid = await verifyPoolSecret({ pool: candidate, signingSecret });
21541
+ if (isValid) {
21542
+ return true;
21543
+ }
21544
+ }
21545
+ return false;
21441
21546
  } catch (error) {
21442
21547
  console.warn(`${lc2} Exception during verification: ${extractErrorMsg(error)}`);
21443
21548
  return false;
21444
21549
  }
21445
21550
  }
21551
+ /**
21552
+ * Recursively prunes keys whose value is strictly `null` (tombstone records)
21553
+ * from aggregated detail maps/arrays.
21554
+ */
21555
+ pruneTombstoneNulls(obj) {
21556
+ if (!obj || typeof obj !== "object") {
21557
+ return obj;
21558
+ }
21559
+ if (Array.isArray(obj)) {
21560
+ return obj.filter((item) => item !== null).map((item) => this.pruneTombstoneNulls(item));
21561
+ }
21562
+ for (const key of Object.keys(obj)) {
21563
+ if (obj[key] === null) {
21564
+ delete obj[key];
21565
+ } else if (typeof obj[key] === "object") {
21566
+ this.pruneTombstoneNulls(obj[key]);
21567
+ }
21568
+ }
21569
+ return obj;
21570
+ }
21446
21571
  };
21447
21572
 
21448
21573
  // ../../libs/node-gib/dist/email/verify/email-verify-helpers.mjs
@@ -21811,16 +21936,20 @@ function generateVerificationCode() {
21811
21936
  const codeNum = Math.floor(1e5 + Math.random() * 9e5);
21812
21937
  return codeNum.toString();
21813
21938
  }
21814
- async function savePendingCodeRecord({ pendingDir, code, maxAttempts = 5, ttlMs = DEFAULT_MAGIC_LINK_TTL_MS }) {
21939
+ async function savePendingCodeRecord({ pendingDir, code, maxAttempts = 5, ttlMs = DEFAULT_MAGIC_LINK_TTL_MS, resendCount = 0, attempts = 0 }) {
21815
21940
  const codeHash = await hash({ s: `verificationcode${code}` });
21816
21941
  const record = {
21817
21942
  codeHash,
21818
- attempts: 0,
21943
+ rawCode: code,
21944
+ attempts,
21819
21945
  maxAttempts,
21820
- expiresAt: Date.now() + ttlMs
21946
+ expiresAt: Date.now() + ttlMs,
21947
+ dispatchedAt: Date.now(),
21948
+ resendCount
21821
21949
  };
21822
21950
  const codeFilePath = path4.join(pendingDir, "code.json");
21823
21951
  await fs2.writeFile(codeFilePath, JSON.stringify(record, null, 2), "utf-8");
21952
+ return record;
21824
21953
  }
21825
21954
  function createDefaultEmailSender() {
21826
21955
  const rawMode = process.env.EMAIL_MODE;
@@ -22493,6 +22622,7 @@ function loadSsoServerConfig() {
22493
22622
 
22494
22623
  // ../../libs/node-gib/dist/identity/sso/sso-custodian-service.mjs
22495
22624
  import { createPublicKey, verify } from "node:crypto";
22625
+ var logalot49 = GLOBAL_LOG_A_LOT || true;
22496
22626
  var SsoCustodianService = class _SsoCustodianService {
22497
22627
  config;
22498
22628
  lc = `[${_SsoCustodianService.name}]`;
@@ -22524,25 +22654,37 @@ var SsoCustodianService = class _SsoCustodianService {
22524
22654
  * - Generator: Client/Server (Derived from environmental configuration and sent by client).
22525
22655
  */
22526
22656
  async getOAuthUserInfo(providerId, code, redirectUri) {
22527
- const lc2 = `${this.lc}[${this.getOAuthUserInfo.name}]`;
22528
- const providerConfig = this.config.providers[providerId];
22529
- if (!providerConfig) {
22530
- throw new Error(`Provider '${providerId}' is not configured on this server. (E: c28900abfefd23e89cf23f12)`);
22531
- }
22532
- console.log(`${lc2} Exchanging code for provider: ${providerId}`);
22533
- const tokens = await this.exchangeCodeForTokens(providerConfig, code, redirectUri);
22534
- if (providerId === "google") {
22535
- if (!tokens.id_token) {
22536
- throw new Error(`Google token exchange did not return id_token. (E: e28900abfefd23e89cf45f23)`);
22657
+ const lc2 = `[${this.getOAuthUserInfo.name}]`;
22658
+ try {
22659
+ if (logalot49) {
22660
+ console.log(`${lc2} starting... (I: 3ad578b5065ec6d5517469571a4da826)`);
22661
+ }
22662
+ const providerConfig = this.config.providers[providerId];
22663
+ if (!providerConfig) {
22664
+ throw new Error(`Provider '${providerId}' is not configured on this server. (E: c28900abfefd23e89cf23f12)`);
22665
+ }
22666
+ console.log(`${lc2} Exchanging code for provider: ${providerId}`);
22667
+ const tokens = await this.exchangeCodeForTokens(providerConfig, code, redirectUri);
22668
+ if (providerId === "google") {
22669
+ if (!tokens.id_token) {
22670
+ throw new Error(`Google token exchange did not return id_token. (E: e28900abfefd23e89cf45f23)`);
22671
+ }
22672
+ return this.verifyAndNormalizeGoogleToken(tokens.id_token);
22673
+ } else if (providerId === "github") {
22674
+ if (!tokens.access_token) {
22675
+ throw new Error(`GitHub token exchange did not return access_token. (E: a28900abfefd23e89cf56f34)`);
22676
+ }
22677
+ return this.fetchAndNormalizeGithubUser(providerConfig, tokens.access_token);
22537
22678
  }
22538
- return this.verifyAndNormalizeGoogleToken(tokens.id_token);
22539
- } else if (providerId === "github") {
22540
- if (!tokens.access_token) {
22541
- throw new Error(`GitHub token exchange did not return access_token. (E: a28900abfefd23e89cf56f34)`);
22679
+ throw new Error(`Unsupported provider: ${providerId}. (E: d28900abfefd23e89cf67f45)`);
22680
+ } catch (error) {
22681
+ console.error(`${lc2} ${extractErrorMsg(error)}`);
22682
+ throw error;
22683
+ } finally {
22684
+ if (logalot49) {
22685
+ console.log(`${lc2} complete.`);
22542
22686
  }
22543
- return this.fetchAndNormalizeGithubUser(providerConfig, tokens.access_token);
22544
22687
  }
22545
- throw new Error(`Unsupported provider: ${providerId}. (E: d28900abfefd23e89cf67f45)`);
22546
22688
  }
22547
22689
  /**
22548
22690
  * Directly validates a Google ID Token (JWT) locally and returns normalized user info.
@@ -22799,62 +22941,75 @@ var SsoCustodianService = class _SsoCustodianService {
22799
22941
  * - Generator: Client (Generated on user's device).
22800
22942
  */
22801
22943
  async createCustodianChallengePool({ providerId, providerKey, userNonce, keystoneAddr, metaspace, space }) {
22802
- const keystoneService = new KeystoneService_V1();
22803
- const targetKeystone = await keystoneService.getLatestKeystone({
22804
- addr: keystoneAddr,
22805
- metaspace,
22806
- space
22807
- });
22808
- if (!targetKeystone) {
22809
- throw new Error(`Keystone not found for address: ${keystoneAddr} (E: 8a9c2b1d3e5f6a7b8c9d0e1f2a3b4c5d)`);
22810
- }
22811
- const userManagePool = targetKeystone.data?.challengePools.find((p) => p.id === POOL_ID_MANAGE);
22812
- if (!userManagePool) {
22813
- throw new Error(`Keystone manage pool not found. Custodian manage pool must match the user manage pool's security config. (E: 7c4e5f6a7b8c9d0e1f2a3b4c5e6f7a8b)`);
22814
- }
22815
- if (!providerId || !KEYSTONE_POOL_ID_REGEXP.test(providerId)) {
22816
- throw new Error(`Invalid providerId: "${providerId}". Must match ${KEYSTONE_POOL_ID_REGEXP} (E: 3a2c4e5f6a7b8c9d0e1f2a3b4c5e6f)`);
22817
- }
22818
- const poolId = `custodian-manage-${providerId}`;
22819
- const custodianSecret = await this.deriveServerDelegateSecret(providerKey, userNonce);
22820
- const poolSalt = await hash({
22821
- s: `${providerKey}:${userNonce}:salt`,
22822
- algorithm: HashAlgorithm.sha_256
22823
- });
22824
- const poolSaltShort = poolSalt.substring(0, 16);
22825
- const config = {
22826
- ...userManagePool.config,
22827
- id: poolId,
22828
- salt: poolSaltShort,
22829
- allowedVerbs: [KEYSTONE_VERB_MANAGE, KEYSTONE_VERB_REVOKE]
22830
- };
22831
- const strategy = KeystoneStrategyFactory.create({ config });
22832
- const poolSecret = await strategy.derivePoolSecret({ masterSecret: custodianSecret });
22833
- const challenges = {};
22834
- const timestamp = Date.now().toString();
22835
- for (let i = 0; i < config.behavior.size; i++) {
22836
- const challengeId = await generateOpaqueChallengeId({
22837
- salt: config.salt,
22838
- timestamp,
22839
- index: i
22944
+ const lc2 = `[${this.createCustodianChallengePool.name}]`;
22945
+ try {
22946
+ if (logalot49) {
22947
+ console.log(`${lc2} starting... (I: 4238580990ff19dd2815d5186ffa0826)`);
22948
+ }
22949
+ const keystoneService = new KeystoneService_V1();
22950
+ const targetKeystone = await keystoneService.getLatestKeystone({
22951
+ addr: keystoneAddr,
22952
+ metaspace,
22953
+ space
22840
22954
  });
22841
- const solution = await strategy.generateSolution({
22842
- poolSecret,
22843
- poolId: config.id,
22844
- challengeId
22955
+ if (!targetKeystone) {
22956
+ throw new Error(`Keystone not found for address: ${keystoneAddr} (E: 8a9c2b1d3e5f6a7b8c9d0e1f2a3b4c5d)`);
22957
+ }
22958
+ const userManagePool = targetKeystone.data?.challengePools.find((p) => p.id === POOL_ID_MANAGE);
22959
+ if (!userManagePool) {
22960
+ throw new Error(`Keystone manage pool not found. Custodian manage pool must match the user manage pool's security config. (E: 7c4e5f6a7b8c9d0e1f2a3b4c5e6f7a8b)`);
22961
+ }
22962
+ if (!providerId || !KEYSTONE_POOL_ID_REGEXP.test(providerId)) {
22963
+ throw new Error(`Invalid providerId: "${providerId}". Must match ${KEYSTONE_POOL_ID_REGEXP} (E: 3a2c4e5f6a7b8c9d0e1f2a3b4c5e6f)`);
22964
+ }
22965
+ const poolId = `custodian-manage-${providerId}`;
22966
+ const custodianSecret = await this.deriveServerDelegateSecret(providerKey, userNonce);
22967
+ const poolSalt = await hash({
22968
+ s: `${providerKey}:${userNonce}:salt`,
22969
+ algorithm: HashAlgorithm.sha_256
22845
22970
  });
22846
- challenges[challengeId] = await strategy.generateChallenge({ solution });
22847
- }
22848
- return {
22849
- id: poolId,
22850
- config,
22851
- challenges,
22852
- isForeign: true,
22853
- metadata: {
22854
- owner: "custodian",
22855
- providerKey
22971
+ const poolSaltShort = poolSalt.substring(0, 16);
22972
+ const config = {
22973
+ ...userManagePool.config,
22974
+ id: poolId,
22975
+ salt: poolSaltShort,
22976
+ allowedVerbs: [KEYSTONE_VERB_MANAGE, KEYSTONE_VERB_REVOKE]
22977
+ };
22978
+ const strategy = KeystoneStrategyFactory.create({ config });
22979
+ const poolSecret = await strategy.derivePoolSecret({ masterSecret: custodianSecret });
22980
+ const challenges = {};
22981
+ const timestamp = Date.now().toString();
22982
+ for (let i = 0; i < config.behavior.size; i++) {
22983
+ const challengeId = await generateOpaqueChallengeId({
22984
+ salt: config.salt,
22985
+ timestamp,
22986
+ index: i
22987
+ });
22988
+ const solution = await strategy.generateSolution({
22989
+ poolSecret,
22990
+ poolId: config.id,
22991
+ challengeId
22992
+ });
22993
+ challenges[challengeId] = await strategy.generateChallenge({ solution });
22856
22994
  }
22857
- };
22995
+ return {
22996
+ id: poolId,
22997
+ config,
22998
+ challenges,
22999
+ isForeign: true,
23000
+ metadata: {
23001
+ owner: "custodian",
23002
+ providerKey
23003
+ }
23004
+ };
23005
+ } catch (error) {
23006
+ console.error(`${lc2} ${extractErrorMsg(error)}`);
23007
+ throw error;
23008
+ } finally {
23009
+ if (logalot49) {
23010
+ console.log(`${lc2} complete.`);
23011
+ }
23012
+ }
22858
23013
  }
22859
23014
  /**
22860
23015
  * Maps private server configuration to safe public client configurations.
@@ -22930,9 +23085,17 @@ var SsoCustodianService = class _SsoCustodianService {
22930
23085
  }
22931
23086
  }
22932
23087
  };
23088
+ var ssoCustodianService;
23089
+ function getSsoCustodianService() {
23090
+ if (!ssoCustodianService) {
23091
+ const config = loadSsoServerConfig();
23092
+ ssoCustodianService = new SsoCustodianService(config);
23093
+ }
23094
+ return ssoCustodianService;
23095
+ }
22933
23096
 
22934
23097
  // ../../libs/node-gib/dist/serve-gib/handlers/api/keystone/keystone-evolve.handler.mjs
22935
- var logalot49 = GLOBAL_LOG_A_LOT;
23098
+ var logalot50 = GLOBAL_LOG_A_LOT;
22936
23099
  var KeystoneEvolveHandler = class _KeystoneEvolveHandler extends ServeGibHandlerWithMetaspaceBase {
22937
23100
  lc = `[${_KeystoneEvolveHandler.name}]`;
22938
23101
  method = "PUT";
@@ -22942,7 +23105,11 @@ var KeystoneEvolveHandler = class _KeystoneEvolveHandler extends ServeGibHandler
22942
23105
  if (match && match.length >= 3) {
22943
23106
  const domainIb = decodeURIComponent(match[1]);
22944
23107
  const domainGib = decodeURIComponent(match[2]);
22945
- const domainAddr = getIbGibAddr({ ib: domainIb, gib: domainGib });
23108
+ let domainAddr = getIbGibAddr({ ib: domainIb, gib: domainGib });
23109
+ const { tjpGib } = getGibInfo({ ibGibAddr: domainAddr });
23110
+ if (tjpGib && domainIb) {
23111
+ domainAddr = `${domainIb}^${tjpGib}`;
23112
+ }
22946
23113
  return {
22947
23114
  domainAddr,
22948
23115
  domainInfo: this.getDomainInfo({ domainAddr })
@@ -22957,7 +23124,7 @@ var KeystoneEvolveHandler = class _KeystoneEvolveHandler extends ServeGibHandler
22957
23124
  async handleRouteImpl(reqCtx) {
22958
23125
  const lc2 = `${this.lc}[handleRouteImpl]`;
22959
23126
  try {
22960
- if (logalot49) {
23127
+ if (logalot50) {
22961
23128
  console.log(`${lc2} starting...`);
22962
23129
  }
22963
23130
  if (!reqCtx.params) {
@@ -23028,7 +23195,7 @@ var KeystoneEvolveHandler = class _KeystoneEvolveHandler extends ServeGibHandler
23028
23195
  const removeInfo = claim.details.info;
23029
23196
  if (removeInfo && Array.isArray(removeInfo.remove)) {
23030
23197
  const config = loadSsoServerConfig();
23031
- const custodian5 = new SsoCustodianService(config);
23198
+ const custodian = new SsoCustodianService(config);
23032
23199
  for (const poolId of removeInfo.remove) {
23033
23200
  if (poolId.startsWith("custodian-manage-")) {
23034
23201
  const providerId = poolId.replace("custodian-manage-", "");
@@ -23036,7 +23203,7 @@ var KeystoneEvolveHandler = class _KeystoneEvolveHandler extends ServeGibHandler
23036
23203
  const token = parsed.revokeTokens?.[providerId];
23037
23204
  if (token) {
23038
23205
  try {
23039
- await custodian5.revokeToken(providerId, token);
23206
+ await custodian.revokeToken(providerId, token);
23040
23207
  } catch (e) {
23041
23208
  console.warn(`${lc2} Failed to revoke token for provider ${providerId}: ${extractErrorMsg(e)}`);
23042
23209
  }
@@ -23054,7 +23221,7 @@ var KeystoneEvolveHandler = class _KeystoneEvolveHandler extends ServeGibHandler
23054
23221
  console.error(`${lc2} ${extractErrorMsg(error)}`);
23055
23222
  return this.error(422, `Evolve validation/persistence failed: ${extractErrorMsg(error)}`);
23056
23223
  } finally {
23057
- if (logalot49) {
23224
+ if (logalot50) {
23058
23225
  console.log(`${lc2} complete.`);
23059
23226
  }
23060
23227
  }
@@ -23062,7 +23229,7 @@ var KeystoneEvolveHandler = class _KeystoneEvolveHandler extends ServeGibHandler
23062
23229
  };
23063
23230
 
23064
23231
  // ../../libs/node-gib/dist/serve-gib/handlers/api/keystone/keystone-post.handler.mjs
23065
- var logalot50 = GLOBAL_LOG_A_LOT;
23232
+ var logalot51 = GLOBAL_LOG_A_LOT;
23066
23233
  var KeystonePostHandler = class _KeystonePostHandler extends ServeGibHandlerWithMetaspaceBase {
23067
23234
  lc = `[${_KeystonePostHandler.name}]`;
23068
23235
  method = "POST";
@@ -23092,7 +23259,7 @@ var KeystonePostHandler = class _KeystonePostHandler extends ServeGibHandlerWith
23092
23259
  async handleRouteImpl(reqCtx) {
23093
23260
  const lc2 = `[${this.handleRouteImpl.name}]`;
23094
23261
  try {
23095
- if (logalot50) {
23262
+ if (logalot51) {
23096
23263
  console.log(`${lc2} starting... (I: 63bab8214834cb6e383e0fc364ee8826)`);
23097
23264
  }
23098
23265
  const { metaspace } = reqCtx;
@@ -23117,7 +23284,7 @@ var KeystonePostHandler = class _KeystonePostHandler extends ServeGibHandlerWith
23117
23284
  console.error(emsg);
23118
23285
  return this.error(500, emsg);
23119
23286
  } finally {
23120
- if (logalot50) {
23287
+ if (logalot51) {
23121
23288
  console.log(`${lc2} complete.`);
23122
23289
  }
23123
23290
  }
@@ -23125,7 +23292,7 @@ var KeystonePostHandler = class _KeystonePostHandler extends ServeGibHandlerWith
23125
23292
  };
23126
23293
 
23127
23294
  // ../../libs/node-gib/dist/serve-gib/handlers/api/keystone/keystone-get.handler.mjs
23128
- var logalot51 = GLOBAL_LOG_A_LOT;
23295
+ var logalot52 = GLOBAL_LOG_A_LOT;
23129
23296
  var KeystoneGetHandler = class _KeystoneGetHandler extends ServeGibHandlerWithMetaspaceBase {
23130
23297
  lc = `[${_KeystoneGetHandler.name}]`;
23131
23298
  method = "GET";
@@ -23133,7 +23300,7 @@ var KeystoneGetHandler = class _KeystoneGetHandler extends ServeGibHandlerWithMe
23133
23300
  async parseParamsImpl(reqCtx) {
23134
23301
  const lc2 = `${this.lc}[${this.parseParamsImpl.name}]`;
23135
23302
  try {
23136
- if (logalot51) {
23303
+ if (logalot52) {
23137
23304
  console.log(`${lc2} starting...`);
23138
23305
  }
23139
23306
  const match = reqCtx.pathname.match(this.regex);
@@ -23150,7 +23317,7 @@ var KeystoneGetHandler = class _KeystoneGetHandler extends ServeGibHandlerWithMe
23150
23317
  console.error(`${lc2} ${extractErrorMsg(error)}`);
23151
23318
  throw error;
23152
23319
  } finally {
23153
- if (logalot51) {
23320
+ if (logalot52) {
23154
23321
  console.log(`${lc2} complete.`);
23155
23322
  }
23156
23323
  }
@@ -23158,7 +23325,7 @@ var KeystoneGetHandler = class _KeystoneGetHandler extends ServeGibHandlerWithMe
23158
23325
  async validateQueryParams({ queryParams }) {
23159
23326
  const lc2 = `${this.lc}[${this.validateQueryParams.name}]`;
23160
23327
  try {
23161
- if (logalot51) {
23328
+ if (logalot52) {
23162
23329
  console.log(`${lc2} starting... (I: f619e8121988498cd8e8928986663826)`);
23163
23330
  }
23164
23331
  const errors = [];
@@ -23183,7 +23350,7 @@ var KeystoneGetHandler = class _KeystoneGetHandler extends ServeGibHandlerWithMe
23183
23350
  console.error(`${lc2} ${extractErrorMsg(error)}`);
23184
23351
  throw error;
23185
23352
  } finally {
23186
- if (logalot51) {
23353
+ if (logalot52) {
23187
23354
  console.log(`${lc2} complete.`);
23188
23355
  }
23189
23356
  }
@@ -23191,7 +23358,7 @@ var KeystoneGetHandler = class _KeystoneGetHandler extends ServeGibHandlerWithMe
23191
23358
  async handleRouteImpl(reqCtx) {
23192
23359
  const lc2 = `[${this.handleRouteImpl.name}]`;
23193
23360
  try {
23194
- if (logalot51) {
23361
+ if (logalot52) {
23195
23362
  console.log(`${lc2} starting...`);
23196
23363
  }
23197
23364
  const { metaspace } = reqCtx;
@@ -23203,7 +23370,7 @@ var KeystoneGetHandler = class _KeystoneGetHandler extends ServeGibHandlerWithMe
23203
23370
  throw new Error(`(UNEXPECTED) reqCtx.params.domainInfo falsy? at this point, we've passed canHandleRoute so this should be truthy (E: 5d3e96d9f8d8f65258d530af0e223826)`);
23204
23371
  }
23205
23372
  const { addr: domainAddr } = domainInfo;
23206
- if (logalot51) {
23373
+ if (logalot52) {
23207
23374
  console.log(`${lc2} domainAddr: ${domainAddr} (I: ea08786359e85481a89c77d84e8f0826)`);
23208
23375
  }
23209
23376
  const queryParams = {
@@ -23261,7 +23428,7 @@ var KeystoneGetHandler = class _KeystoneGetHandler extends ServeGibHandlerWithMe
23261
23428
  console.error(emsg);
23262
23429
  return this.error(500, emsg);
23263
23430
  } finally {
23264
- if (logalot51) {
23431
+ if (logalot52) {
23265
23432
  console.log(`${lc2} complete.`);
23266
23433
  }
23267
23434
  }
@@ -23269,7 +23436,7 @@ var KeystoneGetHandler = class _KeystoneGetHandler extends ServeGibHandlerWithMe
23269
23436
  };
23270
23437
 
23271
23438
  // ../../libs/node-gib/dist/serve-gib/handlers/api/keystone/keystone-lookup.handler.mjs
23272
- var logalot52 = GLOBAL_LOG_A_LOT2 || true;
23439
+ var logalot53 = GLOBAL_LOG_A_LOT2 || true;
23273
23440
  var KeystoneLookupHandler = class _KeystoneLookupHandler extends ServeGibHandlerBase {
23274
23441
  lc = `[${_KeystoneLookupHandler.name}]`;
23275
23442
  method = "POST";
@@ -23292,11 +23459,11 @@ var KeystoneLookupHandler = class _KeystoneLookupHandler extends ServeGibHandler
23292
23459
  return this.error(400, "Identifier is required");
23293
23460
  }
23294
23461
  const indexService = getIdentityIndexService();
23295
- if (logalot52) {
23462
+ if (logalot53) {
23296
23463
  console.log(`${lc2} identifier: ${identifier} (I: 1c417812d9781c5888090ae8d18d0826)`);
23297
23464
  }
23298
23465
  const record = await indexService.getEmailIndex({ email: identifier });
23299
- if (logalot52) {
23466
+ if (logalot53) {
23300
23467
  console.log(`${lc2} record: ${record ? pretty(record) : "undefined"} (I: 7c6ce86b3ad8e3a138991211b5ec5826)`);
23301
23468
  }
23302
23469
  if (!record) {
@@ -23368,15 +23535,7 @@ var KeystoneCheckEmailHandler = class _KeystoneCheckEmailHandler extends ServeGi
23368
23535
  };
23369
23536
 
23370
23537
  // ../../libs/node-gib/dist/serve-gib/handlers/api/keystone/sso-config.handler.mjs
23371
- var logalot53 = GLOBAL_LOG_A_LOT;
23372
- var custodian;
23373
- function getCustodian() {
23374
- if (!custodian) {
23375
- const config = loadSsoServerConfig();
23376
- custodian = new SsoCustodianService(config);
23377
- }
23378
- return custodian;
23379
- }
23538
+ var logalot54 = GLOBAL_LOG_A_LOT;
23380
23539
  var SsoConfigHandler = class _SsoConfigHandler extends ServeGibHandlerBase {
23381
23540
  lc = `[${_SsoConfigHandler.name}]`;
23382
23541
  method = "GET";
@@ -23395,10 +23554,10 @@ var SsoConfigHandler = class _SsoConfigHandler extends ServeGibHandlerBase {
23395
23554
  async handleRouteImpl(reqCtx) {
23396
23555
  const lc2 = `${this.lc}[${this.handleRouteImpl.name}]`;
23397
23556
  try {
23398
- if (logalot53) {
23557
+ if (logalot54) {
23399
23558
  console.log(`${lc2} starting...`);
23400
23559
  }
23401
- const service = getCustodian();
23560
+ const service = getSsoCustodianService();
23402
23561
  const hostUrl = `${reqCtx.protocol}://${reqCtx.headers.host}`;
23403
23562
  const providers = service.getSsoClientConfigs(hostUrl);
23404
23563
  return this.ok({
@@ -23410,7 +23569,7 @@ var SsoConfigHandler = class _SsoConfigHandler extends ServeGibHandlerBase {
23410
23569
  console.error(`${lc2} Fetching SSO config failed: ${emsg}`);
23411
23570
  return this.error(500, `SSO configuration retrieval failed: ${emsg}`);
23412
23571
  } finally {
23413
- if (logalot53) {
23572
+ if (logalot54) {
23414
23573
  console.log(`${lc2} complete.`);
23415
23574
  }
23416
23575
  }
@@ -23425,43 +23584,133 @@ function isSsoProviderLinked({ keystone, providerId }) {
23425
23584
  return keystone.data.challengePools.some((p) => p.id === targetPoolId);
23426
23585
  }
23427
23586
 
23428
- // ../../libs/node-gib/dist/serve-gib/handlers/api/keystone/sso-link.handler.mjs
23429
- var logalot54 = GLOBAL_LOG_A_LOT;
23430
- var custodian2;
23431
- function getCustodian2() {
23432
- if (!custodian2) {
23433
- const config = loadSsoServerConfig();
23434
- custodian2 = new SsoCustodianService(config);
23587
+ // ../../libs/node-gib/dist/identity/sso/custodian-auth-helpers.mjs
23588
+ async function deriveCustodianAuthCode({ custodianReqsOmitAuthCode, serverSecret }) {
23589
+ const lc2 = `[${deriveCustodianAuthCode.name}]`;
23590
+ try {
23591
+ if (!serverSecret) {
23592
+ throw new Error("serverSecret required for custodian auth code derivation (E: a1b2c3d4e5f67890123456789abcdef0)");
23593
+ }
23594
+ const salt = await hash({
23595
+ s: JSON.stringify(custodianReqsOmitAuthCode),
23596
+ algorithm: HashAlgorithm.sha_512
23597
+ });
23598
+ return await kdf_recursiveSaltWrap({
23599
+ masterSecret: serverSecret,
23600
+ salt,
23601
+ rounds: 1e3,
23602
+ algorithm: HashAlgorithm.sha_512
23603
+ });
23604
+ } catch (error) {
23605
+ console.error(`${lc2} ${extractErrorMsg(error)}`);
23606
+ throw error;
23435
23607
  }
23436
- return custodian2;
23437
23608
  }
23438
- var SsoLinkHandler = class _SsoLinkHandler extends ServeGibHandlerWithMetaspaceBase {
23439
- lc = `[${_SsoLinkHandler.name}]`;
23440
- method = "POST";
23441
- regex = API_PATH_REGEXES.IDENTITY_SSO_LINK;
23442
- async parseParamsImpl(reqCtx) {
23443
- let parsed;
23444
- try {
23445
- parsed = JSON.parse(reqCtx.body);
23446
- } catch {
23447
- return void 0;
23609
+ async function generateCustodianRequirements({ primaryTjpAddr, ttlMs = 15 * 60 * 1e3, allowedVerbs = [KEYSTONE_VERB_SYNC, KEYSTONE_VERB_CONNECT], serverSecret }) {
23610
+ const lc2 = `[${generateCustodianRequirements.name}]`;
23611
+ try {
23612
+ if (!primaryTjpAddr) {
23613
+ throw new Error("primaryTjpAddr is required to generate custodian requirements (E: b2c3d4e5f67890123456789abcdef01)");
23448
23614
  }
23449
- const parentTjpAddr = parsed?.parentTjpAddr;
23450
- if (!parentTjpAddr) {
23451
- return void 0;
23615
+ if (!serverSecret) {
23616
+ throw new Error("serverSecret is required to generate custodian requirements (E: c3d4e5f67890123456789abcdef012)");
23452
23617
  }
23618
+ const nonce = await getUUID();
23619
+ const expiresAt = Date.now() + ttlMs;
23620
+ const custodianReqsOmitAuthCode = {
23621
+ primaryTjpAddr,
23622
+ nonce,
23623
+ expiresAt,
23624
+ allowedVerbs
23625
+ };
23626
+ const authCode = await deriveCustodianAuthCode({
23627
+ custodianReqsOmitAuthCode,
23628
+ serverSecret
23629
+ });
23453
23630
  return {
23454
- parentTjpAddr,
23455
- domainInfo: this.getDomainInfo({ domainAddr: parentTjpAddr })
23631
+ ...custodianReqsOmitAuthCode,
23632
+ authCode
23456
23633
  };
23634
+ } catch (error) {
23635
+ console.error(`${lc2} ${extractErrorMsg(error)}`);
23636
+ throw error;
23457
23637
  }
23458
- async validateQueryParams({ queryParams }) {
23459
- return [];
23460
- }
23461
- async handleRouteImpl(reqCtx) {
23462
- const lc2 = `${this.lc}[${this.handleRouteImpl.name}]`;
23463
- try {
23464
- if (logalot54) {
23638
+ }
23639
+ async function getAuthCustodianIndex({ custodianReqs }) {
23640
+ return await hash({
23641
+ s: JSON.stringify(custodianReqs),
23642
+ algorithm: HashAlgorithm.sha_256
23643
+ });
23644
+ }
23645
+ async function verifyCustodianRequirements({ custodianReqs, serverSecret }) {
23646
+ try {
23647
+ if (!custodianReqs || !custodianReqs.authCode || !custodianReqs.nonce || !custodianReqs.expiresAt || !custodianReqs.primaryTjpAddr) {
23648
+ return { valid: false, error: "Malformed custodian requirements structure. (E: d4e5f67890123456789abcdef0123)" };
23649
+ }
23650
+ if (Date.now() > custodianReqs.expiresAt) {
23651
+ return { valid: false, error: "Custodian requirements have expired. (E: e5f67890123456789abcdef01234)" };
23652
+ }
23653
+ const { authCode, ...custodianReqsOmitAuthCode } = custodianReqs;
23654
+ const expectedAuthCode = await deriveCustodianAuthCode({
23655
+ custodianReqsOmitAuthCode,
23656
+ serverSecret
23657
+ });
23658
+ if (authCode !== expectedAuthCode) {
23659
+ return { valid: false, error: "Cryptographic authCode mismatch. Requirement payload tampered or invalid. (E: f67890123456789abcdef012345)" };
23660
+ }
23661
+ return { valid: true };
23662
+ } catch (error) {
23663
+ return { valid: false, error: `Verification failed: ${extractErrorMsg(error)} (E: 7890123456789abcdef0123456)` };
23664
+ }
23665
+ }
23666
+
23667
+ // ../../libs/node-gib/dist/serve-gib/handlers/api/keystone/sso-link.handler.mjs
23668
+ var logalot55 = GLOBAL_LOG_A_LOT || true;
23669
+ var SsoLinkHandler = class _SsoLinkHandler extends ServeGibHandlerWithMetaspaceBase {
23670
+ lc = `[${_SsoLinkHandler.name}]`;
23671
+ method = "POST";
23672
+ regex = API_PATH_REGEXES.IDENTITY_SSO_LINK;
23673
+ async parseParamsImpl(reqCtx) {
23674
+ const lc2 = `${this.lc}[${this.parseParamsImpl.name}]`;
23675
+ try {
23676
+ if (logalot55) {
23677
+ console.log(`${lc2} starting... (I: a38f2cee647c127b48ec6ad1e8d1e826)`);
23678
+ }
23679
+ let parsed;
23680
+ try {
23681
+ parsed = JSON.parse(reqCtx.body);
23682
+ } catch {
23683
+ return void 0;
23684
+ }
23685
+ let parentTjpAddr = parsed?.parentTjpAddr;
23686
+ if (!parentTjpAddr) {
23687
+ return void 0;
23688
+ }
23689
+ const { ib } = getIbAndGib({ ibGibAddr: parentTjpAddr });
23690
+ const { tjpGib } = getGibInfo({ ibGibAddr: parentTjpAddr });
23691
+ if (tjpGib && ib) {
23692
+ parentTjpAddr = `${ib}^${tjpGib}`;
23693
+ }
23694
+ return {
23695
+ parentTjpAddr,
23696
+ domainInfo: this.getDomainInfo({ domainAddr: parentTjpAddr })
23697
+ };
23698
+ } catch (error) {
23699
+ console.error(`${lc2} ${extractErrorMsg(error)}`);
23700
+ throw error;
23701
+ } finally {
23702
+ if (logalot55) {
23703
+ console.log(`${lc2} complete.`);
23704
+ }
23705
+ }
23706
+ }
23707
+ async validateQueryParams({ queryParams }) {
23708
+ return [];
23709
+ }
23710
+ async handleRouteImpl(reqCtx) {
23711
+ const lc2 = `${this.lc}[${this.handleRouteImpl.name}]`;
23712
+ try {
23713
+ if (logalot55) {
23465
23714
  console.log(`${lc2} starting... (I: 8a4c1f930e7b2d5a6c1e9f8a3b5c7d1e)`);
23466
23715
  }
23467
23716
  if (!reqCtx.params) {
@@ -23476,10 +23725,18 @@ var SsoLinkHandler = class _SsoLinkHandler extends ServeGibHandlerWithMetaspaceB
23476
23725
  } catch {
23477
23726
  return this.error(400, "Request body must be valid JSON (E: e1b2c3d4e5f67890a1b2c3d4e5f67890)");
23478
23727
  }
23479
- const { code, providerId, parentTjpAddr, userNonce, redirectUri } = parsed;
23728
+ let { code, providerId, parentTjpAddr, userNonce, redirectUri } = parsed;
23480
23729
  if (!code || !providerId || !parentTjpAddr || !userNonce || !redirectUri) {
23481
23730
  return this.error(400, "Body missing required parameters (code, providerId, parentTjpAddr, userNonce, redirectUri) (E: f2c3d4e5f6789012a3b4c5d6e7f89012)");
23482
23731
  }
23732
+ if (logalot55) {
23733
+ console.log(`${lc2} LinkBody parsed (I: 7525b8bd29c8504e989e918825d4e826)`);
23734
+ }
23735
+ const { ib } = getIbAndGib({ ibGibAddr: parentTjpAddr });
23736
+ const { tjpGib } = getGibInfo({ ibGibAddr: parentTjpAddr });
23737
+ if (tjpGib && ib) {
23738
+ parentTjpAddr = `${ib}^${tjpGib}`;
23739
+ }
23483
23740
  const space = await reqCtx.metaspace.getLocalUserSpace({ lock: false });
23484
23741
  if (!space) {
23485
23742
  return this.error(500, "No local user space found in domain metaspace (E: 03d4e5f678901234b5c6d7e8f9012345)");
@@ -23493,10 +23750,20 @@ var SsoLinkHandler = class _SsoLinkHandler extends ServeGibHandlerWithMetaspaceB
23493
23750
  if (!targetKeystone) {
23494
23751
  return this.error(400, `Keystone not found for address: ${parentTjpAddr} (E: 14e5f67890123456c7d8e9f012345678)`);
23495
23752
  }
23496
- if (isSsoProviderLinked({ keystone: targetKeystone, providerId })) {
23753
+ if (logalot55) {
23754
+ console.log(`${lc2} targetKeystone gotten. addr: ${getIbGibAddr({ ibGib: targetKeystone })}, pools: ${JSON.stringify(targetKeystone.data?.challengePools?.map((p) => p.id))}, frameDetails: ${JSON.stringify(targetKeystone.data?.frameDetails)} (I: 3d2068e16cb4da0428d601a7a74e3826)`);
23755
+ }
23756
+ const isLinked = isSsoProviderLinked({ keystone: targetKeystone, providerId });
23757
+ if (logalot55) {
23758
+ console.log(`${lc2} isSsoProviderLinked for ${providerId}: ${isLinked}`);
23759
+ }
23760
+ if (isLinked) {
23497
23761
  return this.error(400, `SSO provider "${providerId}" is already linked to this keystone. (E: 25f6789012345678d9e0f12345678901)`);
23498
23762
  }
23499
- const service = getCustodian2();
23763
+ const service = getSsoCustodianService();
23764
+ if (logalot55) {
23765
+ console.log(`${lc2} getSsoCustodianService returned (I: f7e0b290ed2a2dcde807ff2853016226)`);
23766
+ }
23500
23767
  const userInfo = await service.getOAuthUserInfo(providerId, code, redirectUri);
23501
23768
  if (userInfo.email) {
23502
23769
  try {
@@ -23518,112 +23785,31 @@ var SsoLinkHandler = class _SsoLinkHandler extends ServeGibHandlerWithMetaspaceB
23518
23785
  space
23519
23786
  });
23520
23787
  console.log(`${lc2} created custodian pool for: ${userInfo.providerKey} (I: 4718901234567890f1a2b34567890123)`);
23788
+ const ssoConfig = loadSsoServerConfig();
23789
+ const serverSecret = ssoConfig.ssoServerKdfSecret;
23790
+ const custodianReqs = await generateCustodianRequirements({
23791
+ primaryTjpAddr: parentTjpAddr,
23792
+ serverSecret
23793
+ });
23521
23794
  return this.ok({
23522
23795
  success: true,
23523
- custodianPool
23796
+ custodianPool,
23797
+ custodianReqs
23524
23798
  }, 200);
23525
23799
  } catch (error) {
23526
23800
  const emsg = extractErrorMsg(error);
23527
23801
  console.error(`${lc2} Link failed: ${emsg} (E: 5829012345678901a2b3c45678901234)`);
23528
23802
  return this.error(500, `Link failed: ${emsg} (E: 693a012345678901b2c3d45678901234)`);
23529
23803
  } finally {
23530
- if (logalot54) {
23804
+ if (logalot55) {
23531
23805
  console.log(`${lc2} complete. (I: 7a4b123456789012c3d4e56789012345)`);
23532
23806
  }
23533
23807
  }
23534
23808
  }
23535
23809
  };
23536
23810
 
23537
- // ../../libs/node-gib/dist/identity/sso/custodian-auth-helpers.mjs
23538
- async function deriveCustodianAuthCode({ custodianReqsOmitAuthCode, serverSecret }) {
23539
- const lc2 = `[${deriveCustodianAuthCode.name}]`;
23540
- try {
23541
- if (!serverSecret) {
23542
- throw new Error("serverSecret required for custodian auth code derivation (E: a1b2c3d4e5f67890123456789abcdef0)");
23543
- }
23544
- const salt = await hash({
23545
- s: JSON.stringify(custodianReqsOmitAuthCode),
23546
- algorithm: HashAlgorithm.sha_512
23547
- });
23548
- return await kdf_recursiveSaltWrap({
23549
- masterSecret: serverSecret,
23550
- salt,
23551
- rounds: 1e3,
23552
- algorithm: HashAlgorithm.sha_512
23553
- });
23554
- } catch (error) {
23555
- console.error(`${lc2} ${extractErrorMsg(error)}`);
23556
- throw error;
23557
- }
23558
- }
23559
- async function generateCustodianRequirements({ primaryTjpAddr, ttlMs = 15 * 60 * 1e3, allowedVerbs = [KEYSTONE_VERB_SYNC, KEYSTONE_VERB_CONNECT], serverSecret }) {
23560
- const lc2 = `[${generateCustodianRequirements.name}]`;
23561
- try {
23562
- if (!primaryTjpAddr) {
23563
- throw new Error("primaryTjpAddr is required to generate custodian requirements (E: b2c3d4e5f67890123456789abcdef01)");
23564
- }
23565
- if (!serverSecret) {
23566
- throw new Error("serverSecret is required to generate custodian requirements (E: c3d4e5f67890123456789abcdef012)");
23567
- }
23568
- const nonce = await getUUID();
23569
- const expiresAt = Date.now() + ttlMs;
23570
- const custodianReqsOmitAuthCode = {
23571
- primaryTjpAddr,
23572
- nonce,
23573
- expiresAt,
23574
- allowedVerbs
23575
- };
23576
- const authCode = await deriveCustodianAuthCode({
23577
- custodianReqsOmitAuthCode,
23578
- serverSecret
23579
- });
23580
- return {
23581
- ...custodianReqsOmitAuthCode,
23582
- authCode
23583
- };
23584
- } catch (error) {
23585
- console.error(`${lc2} ${extractErrorMsg(error)}`);
23586
- throw error;
23587
- }
23588
- }
23589
- async function getAuthCustodianIndex({ custodianReqs }) {
23590
- return await hash({
23591
- s: JSON.stringify(custodianReqs),
23592
- algorithm: HashAlgorithm.sha_256
23593
- });
23594
- }
23595
- async function verifyCustodianRequirements({ custodianReqs, serverSecret }) {
23596
- try {
23597
- if (!custodianReqs || !custodianReqs.authCode || !custodianReqs.nonce || !custodianReqs.expiresAt || !custodianReqs.primaryTjpAddr) {
23598
- return { valid: false, error: "Malformed custodian requirements structure. (E: d4e5f67890123456789abcdef0123)" };
23599
- }
23600
- if (Date.now() > custodianReqs.expiresAt) {
23601
- return { valid: false, error: "Custodian requirements have expired. (E: e5f67890123456789abcdef01234)" };
23602
- }
23603
- const { authCode, ...custodianReqsOmitAuthCode } = custodianReqs;
23604
- const expectedAuthCode = await deriveCustodianAuthCode({
23605
- custodianReqsOmitAuthCode,
23606
- serverSecret
23607
- });
23608
- if (authCode !== expectedAuthCode) {
23609
- return { valid: false, error: "Cryptographic authCode mismatch. Requirement payload tampered or invalid. (E: f67890123456789abcdef012345)" };
23610
- }
23611
- return { valid: true };
23612
- } catch (error) {
23613
- return { valid: false, error: `Verification failed: ${extractErrorMsg(error)} (E: 7890123456789abcdef0123456)` };
23614
- }
23615
- }
23616
-
23617
23811
  // ../../libs/node-gib/dist/serve-gib/handlers/api/keystone/sso-login.handler.mjs
23618
- var logalot55 = GLOBAL_LOG_A_LOT;
23619
- var custodian3;
23620
- function getCustodian3() {
23621
- if (!custodian3) {
23622
- const config = loadSsoServerConfig();
23623
- custodian3 = new SsoCustodianService(config);
23624
- }
23625
- return custodian3;
23626
- }
23812
+ var logalot56 = GLOBAL_LOG_A_LOT;
23627
23813
  var SsoLoginHandler = class _SsoLoginHandler extends ServeGibHandlerBase {
23628
23814
  lc = `[${_SsoLoginHandler.name}]`;
23629
23815
  method = "POST";
@@ -23637,7 +23823,7 @@ var SsoLoginHandler = class _SsoLoginHandler extends ServeGibHandlerBase {
23637
23823
  async handleRouteImpl(reqCtx) {
23638
23824
  const lc2 = `${this.lc}[${this.handleRouteImpl.name}]`;
23639
23825
  try {
23640
- if (logalot55) {
23826
+ if (logalot56) {
23641
23827
  console.log(`${lc2} starting... (I: 9b5d2a3c4e5f67890a1b2c3d4e5f6789)`);
23642
23828
  }
23643
23829
  if (reqCtx.method !== "POST") {
@@ -23656,7 +23842,7 @@ var SsoLoginHandler = class _SsoLoginHandler extends ServeGibHandlerBase {
23656
23842
  if (!code || !providerId || !redirectUri) {
23657
23843
  return this.error(400, "Body missing required parameters (code, providerId, redirectUri) (E: 2b2c3d4e5f678901b2c3d4e5f6789012)");
23658
23844
  }
23659
- const service = getCustodian3();
23845
+ const service = getSsoCustodianService();
23660
23846
  const userInfo = await service.getOAuthUserInfo(providerId, code, redirectUri);
23661
23847
  if (!userInfo || !userInfo.email) {
23662
23848
  return this.error(400, `No email address returned from SSO provider ${providerId} (E: 3c3d4e5f67890123c4d5e6f789012345)`);
@@ -23738,7 +23924,7 @@ var SsoLoginHandler = class _SsoLoginHandler extends ServeGibHandlerBase {
23738
23924
  console.error(`${lc2} SSO login failed: ${emsg} (E: 4d5e6f7890123456e7f8901234567890)`);
23739
23925
  return this.error(500, `SSO login failed: ${emsg}`);
23740
23926
  } finally {
23741
- if (logalot55) {
23927
+ if (logalot56) {
23742
23928
  console.log(`${lc2} complete.`);
23743
23929
  }
23744
23930
  }
@@ -23747,7 +23933,7 @@ var SsoLoginHandler = class _SsoLoginHandler extends ServeGibHandlerBase {
23747
23933
 
23748
23934
  // ../../libs/node-gib/dist/serve-gib/handlers/api/identity/keystone-custodian-genesis.handler.mjs
23749
23935
  import * as fs3 from "node:fs/promises";
23750
- var logalot56 = GLOBAL_LOG_A_LOT || true;
23936
+ var logalot57 = GLOBAL_LOG_A_LOT || true;
23751
23937
  var KeystoneCustodianGenesisHandler = class _KeystoneCustodianGenesisHandler extends ServeGibHandlerBase {
23752
23938
  lc = `[${_KeystoneCustodianGenesisHandler.name}]`;
23753
23939
  method = "POST";
@@ -23755,7 +23941,7 @@ var KeystoneCustodianGenesisHandler = class _KeystoneCustodianGenesisHandler ext
23755
23941
  async handleRouteImpl(reqCtx) {
23756
23942
  const lc2 = `${this.lc}[${this.handleRouteImpl.name}]`;
23757
23943
  try {
23758
- if (logalot56) {
23944
+ if (logalot57) {
23759
23945
  console.log(`${lc2} starting... (I: a123456789abcdef0123456789b0001)`);
23760
23946
  }
23761
23947
  if (reqCtx.method !== "POST") {
@@ -23894,7 +24080,7 @@ var KeystoneCustodianGenesisHandler = class _KeystoneCustodianGenesisHandler ext
23894
24080
  console.error(`${lc2} ${emsg}`);
23895
24081
  return this.error(500, emsg);
23896
24082
  } finally {
23897
- if (logalot56) {
24083
+ if (logalot57) {
23898
24084
  console.log(`${lc2} complete.`);
23899
24085
  }
23900
24086
  }
@@ -23904,7 +24090,7 @@ var KeystoneCustodianGenesisHandler = class _KeystoneCustodianGenesisHandler ext
23904
24090
  // ../../libs/node-gib/dist/serve-gib/handlers/api/identity/keystone-custodian-register-delegate.handler.mjs
23905
24091
  import * as fs4 from "fs/promises";
23906
24092
  import * as path5 from "path";
23907
- var logalot57 = GLOBAL_LOG_A_LOT || true;
24093
+ var logalot58 = GLOBAL_LOG_A_LOT || true;
23908
24094
  var KeystoneCustodianRegisterDelegateHandler = class _KeystoneCustodianRegisterDelegateHandler extends ServeGibHandlerBase {
23909
24095
  lc = `[${_KeystoneCustodianRegisterDelegateHandler.name}]`;
23910
24096
  method = "POST";
@@ -23913,7 +24099,7 @@ var KeystoneCustodianRegisterDelegateHandler = class _KeystoneCustodianRegisterD
23913
24099
  const lc2 = `${this.lc}[${this.handleRouteImpl.name}]`;
23914
24100
  let authFilePathToClean;
23915
24101
  try {
23916
- if (logalot57) {
24102
+ if (logalot58) {
23917
24103
  console.log(`${lc2} starting... (I: a23456789abcdef0123456789c0001)`);
23918
24104
  }
23919
24105
  if (reqCtx.method !== "POST") {
@@ -23991,14 +24177,16 @@ var KeystoneCustodianRegisterDelegateHandler = class _KeystoneCustodianRegisterD
23991
24177
  return this.error(500, `Could not determine primary email for identity ${custodianReqs.primaryTjpAddr}`);
23992
24178
  }
23993
24179
  const primarySecret = await hash({ s: `${serverSecret}_custodian_${primaryEmail}` });
24180
+ const delegateDeviceName = delegateKeystone.data?.frameDetails?.deviceTag || frameDetails?.deviceTag || "client-delegate";
23994
24181
  const evolvedPrimaryKeystone = await keystoneService.registerDelegate({
23995
24182
  parentKeystone,
23996
24183
  delegateKeystone,
23997
24184
  masterSecret: primarySecret,
24185
+ signingPoolId: "manage",
23998
24186
  metaspace,
23999
24187
  space,
24000
24188
  allowedVerbs: custodianReqs.allowedVerbs || [KEYSTONE_VERB_SYNC, KEYSTONE_VERB_CONNECT],
24001
- deviceName: frameDetails?.deviceTag || "client-delegate"
24189
+ deviceName: delegateDeviceName
24002
24190
  });
24003
24191
  await metaspace.put({ ibGibs: [delegateKeystone], space });
24004
24192
  await metaspace.registerNewIbGib({ ibGib: delegateKeystone, space });
@@ -24026,7 +24214,7 @@ var KeystoneCustodianRegisterDelegateHandler = class _KeystoneCustodianRegisterD
24026
24214
  } catch {
24027
24215
  }
24028
24216
  }
24029
- if (logalot57) {
24217
+ if (logalot58) {
24030
24218
  console.log(`${lc2} complete.`);
24031
24219
  }
24032
24220
  }
@@ -24034,15 +24222,7 @@ var KeystoneCustodianRegisterDelegateHandler = class _KeystoneCustodianRegisterD
24034
24222
  };
24035
24223
 
24036
24224
  // ../../libs/node-gib/dist/serve-gib/handlers/api/identity/keystone-custodian-add-master-password.handler.mjs
24037
- var logalot58 = GLOBAL_LOG_A_LOT || true;
24038
- var custodian4;
24039
- function getCustodian4() {
24040
- if (!custodian4) {
24041
- const config = loadSsoServerConfig();
24042
- custodian4 = new SsoCustodianService(config);
24043
- }
24044
- return custodian4;
24045
- }
24225
+ var logalot59 = GLOBAL_LOG_A_LOT || true;
24046
24226
  var KeystoneCustodianAddMasterPasswordHandler = class _KeystoneCustodianAddMasterPasswordHandler extends ServeGibHandlerBase {
24047
24227
  lc = `[${_KeystoneCustodianAddMasterPasswordHandler.name}]`;
24048
24228
  method = "POST";
@@ -24050,7 +24230,7 @@ var KeystoneCustodianAddMasterPasswordHandler = class _KeystoneCustodianAddMaste
24050
24230
  async handleRouteImpl(reqCtx) {
24051
24231
  const lc2 = `${this.lc}[${this.handleRouteImpl.name}]`;
24052
24232
  try {
24053
- if (logalot58) {
24233
+ if (logalot59) {
24054
24234
  console.log(`${lc2} starting... (I: 8a1b2c3d4e5f67890a1b2c3d4e5f6790)`);
24055
24235
  }
24056
24236
  if (reqCtx.method !== "POST") {
@@ -24078,7 +24258,7 @@ var KeystoneCustodianAddMasterPasswordHandler = class _KeystoneCustodianAddMaste
24078
24258
  let verifiedEmail;
24079
24259
  let effectiveProvider = providerId || "email";
24080
24260
  if (providerId && code && redirectUri) {
24081
- const service = getCustodian4();
24261
+ const service = getSsoCustodianService();
24082
24262
  const userInfo = await service.getOAuthUserInfo(providerId, code, redirectUri);
24083
24263
  if (!userInfo || !userInfo.email) {
24084
24264
  return this.error(401, `Failed to authenticate with SSO provider ${providerId} (E: 8a1b2c3d4e5f67890a1b2c3d4e5f6796)`);
@@ -24090,7 +24270,11 @@ var KeystoneCustodianAddMasterPasswordHandler = class _KeystoneCustodianAddMaste
24090
24270
  }
24091
24271
  verifiedEmail = normalizeEmail(email);
24092
24272
  const tjpHash = await getPendingTjpHash(primaryTjpAddr);
24093
- const pendingInfo = reqCtx.dataDir && tjpHash ? await getPendingStagingDir({ dataDir: reqCtx.dataDir, tjpHash }) : void 0;
24273
+ let pendingInfo = reqCtx.dataDir && tjpHash ? await getPendingStagingDir({ dataDir: reqCtx.dataDir, tjpHash }) : void 0;
24274
+ if (!pendingInfo) {
24275
+ const emailTjpHash = await getPendingTjpHash(`pending:${verifiedEmail}`);
24276
+ pendingInfo = reqCtx.dataDir && emailTjpHash ? await getPendingStagingDir({ dataDir: reqCtx.dataDir, tjpHash: emailTjpHash }) : void 0;
24277
+ }
24094
24278
  if (!pendingInfo || pendingInfo.isExpired) {
24095
24279
  return this.error(400, "Verification record missing or expired. Please request a new verification code. (E: 8a1b2c3d4e5f67890a1b2c3d4e5f6798)");
24096
24280
  }
@@ -24171,10 +24355,16 @@ var KeystoneCustodianAddMasterPasswordHandler = class _KeystoneCustodianAddMaste
24171
24355
  });
24172
24356
  await metaspace.put({ ibGibs: [evolvedKeystone], space });
24173
24357
  await metaspace.registerNewIbGib({ ibGib: evolvedKeystone, space });
24358
+ const primaryGraph = await getDependencyGraph({
24359
+ ibGib: evolvedKeystone,
24360
+ space,
24361
+ live: false
24362
+ });
24174
24363
  const response = {
24175
24364
  success: true,
24176
24365
  primaryTjpAddr,
24177
24366
  primaryKeystone: evolvedKeystone,
24367
+ primaryGraph,
24178
24368
  message: "Successfully elevated identity to sovereign master password"
24179
24369
  };
24180
24370
  return this.ok(response);
@@ -24364,7 +24554,10 @@ var EmailOutboundHandler = class _EmailOutboundHandler extends ServeGibHandlerBa
24364
24554
  };
24365
24555
 
24366
24556
  // ../../libs/node-gib/dist/serve-gib/handlers/api/email/email-verification-code.handler.mjs
24367
- var logalot59 = GLOBAL_LOG_A_LOT || true;
24557
+ import * as path6 from "node:path";
24558
+ import * as fs5 from "node:fs/promises";
24559
+ import { existsSync as existsSync6 } from "node:fs";
24560
+ var logalot60 = GLOBAL_LOG_A_LOT || true;
24368
24561
  var EmailVerificationCodeHandler = class _EmailVerificationCodeHandler extends ServeGibHandlerBase {
24369
24562
  lc = `[${_EmailVerificationCodeHandler.name}]`;
24370
24563
  method = "POST";
@@ -24378,10 +24571,10 @@ var EmailVerificationCodeHandler = class _EmailVerificationCodeHandler extends S
24378
24571
  const lc2 = `${this.lc}[${this.handleRouteImpl.name}]`;
24379
24572
  const timestampUUID = `${lc2}[${(await getUUID()).substring(0, 8)}]`;
24380
24573
  try {
24381
- if (logalot59) {
24574
+ if (logalot60) {
24382
24575
  console.log(`${lc2} starting... (I: f123456789abcdef0123456789a0001)`);
24383
24576
  }
24384
- if (logalot59) {
24577
+ if (logalot60) {
24385
24578
  console.time(timestampUUID);
24386
24579
  }
24387
24580
  if (reqCtx.method !== "POST") {
@@ -24396,17 +24589,18 @@ var EmailVerificationCodeHandler = class _EmailVerificationCodeHandler extends S
24396
24589
  } catch {
24397
24590
  return this.error(400, "Request body must be valid JSON (E: d2e3f4a5b67890123456789abcdef01)");
24398
24591
  }
24399
- if (logalot59) {
24592
+ if (logalot60) {
24400
24593
  console.timeLog(timestampUUID, "parse complete");
24401
24594
  }
24402
24595
  const { email, primaryTjpAddr } = body;
24403
24596
  if (!email || !validateEmail3(email)) {
24404
24597
  return this.error(400, "Invalid email address format (E: e3f4a5b67890123456789abcdef012)");
24405
24598
  }
24599
+ await delay(1e3 + Math.random() * 500);
24406
24600
  const normEmail = normalizeEmail(email);
24407
24601
  const effectivePrimaryTjpAddr = primaryTjpAddr || `pending:${normEmail}`;
24408
24602
  const tjpHash = await getPendingTjpHash(effectivePrimaryTjpAddr);
24409
- const code = generateVerificationCode();
24603
+ let code = generateVerificationCode();
24410
24604
  if (reqCtx.dataDir && tjpHash) {
24411
24605
  let info = await getPendingStagingDir({ dataDir: reqCtx.dataDir, tjpHash });
24412
24606
  if (!info) {
@@ -24418,9 +24612,44 @@ var EmailVerificationCodeHandler = class _EmailVerificationCodeHandler extends S
24418
24612
  info = await getPendingStagingDir({ dataDir: reqCtx.dataDir, tjpHash });
24419
24613
  }
24420
24614
  if (info) {
24421
- await savePendingCodeRecord({ pendingDir: info.pendingDir, code });
24422
- if (logalot59) {
24423
- console.timeLog(timestampUUID, "code record saved to pending staging");
24615
+ const codeFilePath = path6.join(info.pendingDir, "code.json");
24616
+ let existingRecord;
24617
+ if (existsSync6(codeFilePath)) {
24618
+ try {
24619
+ existingRecord = JSON.parse(await fs5.readFile(codeFilePath, "utf-8"));
24620
+ } catch {
24621
+ }
24622
+ }
24623
+ const now = Date.now();
24624
+ if (existingRecord) {
24625
+ const elapsedMs = now - (existingRecord.dispatchedAt || 0);
24626
+ if (elapsedMs < 3e4) {
24627
+ const remainingSecs = Math.ceil((3e4 - elapsedMs) / 1e3);
24628
+ return this.error(429, `Please wait ${remainingSecs}s before requesting another verification code.`);
24629
+ }
24630
+ if (existingRecord.resendCount >= 5 && now < existingRecord.expiresAt) {
24631
+ return this.error(429, "Too many verification code requests. Please wait 15 minutes before trying again.");
24632
+ }
24633
+ if (existingRecord.rawCode && now < existingRecord.expiresAt && existingRecord.attempts < existingRecord.maxAttempts) {
24634
+ code = existingRecord.rawCode;
24635
+ existingRecord.dispatchedAt = now;
24636
+ existingRecord.resendCount = (existingRecord.resendCount || 0) + 1;
24637
+ await fs5.writeFile(codeFilePath, JSON.stringify(existingRecord, null, 2), "utf-8");
24638
+ } else {
24639
+ code = generateVerificationCode();
24640
+ await savePendingCodeRecord({
24641
+ pendingDir: info.pendingDir,
24642
+ code,
24643
+ resendCount: (existingRecord.resendCount || 0) + 1,
24644
+ attempts: 0
24645
+ });
24646
+ }
24647
+ } else {
24648
+ code = generateVerificationCode();
24649
+ await savePendingCodeRecord({ pendingDir: info.pendingDir, code, resendCount: 0, attempts: 0 });
24650
+ }
24651
+ if (logalot60) {
24652
+ console.timeLog(timestampUUID, "code record processed in pending staging");
24424
24653
  }
24425
24654
  } else {
24426
24655
  console.warn(`${lc2} Failed to create or access pending staging directory for tjpHash ${tjpHash}`);
@@ -24447,7 +24676,7 @@ If you did not request this, please ignore this email.`,
24447
24676
  </div>`
24448
24677
  };
24449
24678
  const sendResult = await this.sender.sendEmail(outboundEmail);
24450
- if (logalot59) {
24679
+ if (logalot60) {
24451
24680
  console.timeLog(timestampUUID, "email send complete");
24452
24681
  }
24453
24682
  if (sendResult.success) {
@@ -24467,7 +24696,7 @@ If you did not request this, please ignore this email.`,
24467
24696
  console.error(`${lc2} Magic link dispatch error: ${emsg} (E: 67890123456789abcdef0123456789a)`);
24468
24697
  return this.error(500, `Magic link dispatch error: ${emsg}`);
24469
24698
  } finally {
24470
- if (logalot59) {
24699
+ if (logalot60) {
24471
24700
  console.log(`${lc2} complete.`);
24472
24701
  console.timeEnd(timestampUUID);
24473
24702
  }
@@ -24476,10 +24705,10 @@ If you did not request this, please ignore this email.`,
24476
24705
  };
24477
24706
 
24478
24707
  // ../../libs/node-gib/dist/serve-gib/handlers/api/email/email-verify-code-onetime.handler.mjs
24479
- import * as fs5 from "node:fs/promises";
24480
- import { existsSync as existsSync6 } from "node:fs";
24481
- import * as path6 from "node:path";
24482
- var logalot60 = GLOBAL_LOG_A_LOT || true;
24708
+ import * as fs6 from "node:fs/promises";
24709
+ import { existsSync as existsSync7 } from "node:fs";
24710
+ import * as path7 from "node:path";
24711
+ var logalot61 = GLOBAL_LOG_A_LOT || true;
24483
24712
  var EmailVerifyCodeOnetimeHandler = class _EmailVerifyCodeOnetimeHandler extends ServeGibHandlerBase {
24484
24713
  lc = `[${_EmailVerifyCodeOnetimeHandler.name}]`;
24485
24714
  method = "POST";
@@ -24488,10 +24717,10 @@ var EmailVerifyCodeOnetimeHandler = class _EmailVerifyCodeOnetimeHandler extends
24488
24717
  const lc2 = `${this.lc}[${this.handleRouteImpl.name}]`;
24489
24718
  const timestampUUID = `${lc2}[${(await getUUID()).substring(0, 8)}]`;
24490
24719
  try {
24491
- if (logalot60) {
24720
+ if (logalot61) {
24492
24721
  console.log(`${lc2} starting... (I: e123456789abcdef0123456789a0001)`);
24493
24722
  }
24494
- if (logalot60) {
24723
+ if (logalot61) {
24495
24724
  console.time(timestampUUID);
24496
24725
  }
24497
24726
  if (reqCtx.method !== "POST") {
@@ -24506,7 +24735,7 @@ var EmailVerifyCodeOnetimeHandler = class _EmailVerifyCodeOnetimeHandler extends
24506
24735
  } catch {
24507
24736
  return this.error(400, "Request body must be valid JSON (E: 123456789abcdef0123456789a0002)");
24508
24737
  }
24509
- if (logalot60) {
24738
+ if (logalot61) {
24510
24739
  console.timeLog(timestampUUID, "parse complete");
24511
24740
  }
24512
24741
  const { email, primaryTjpAddr, code } = body;
@@ -24528,7 +24757,7 @@ var EmailVerifyCodeOnetimeHandler = class _EmailVerifyCodeOnetimeHandler extends
24528
24757
  dataDir: reqCtx.dataDir,
24529
24758
  tjpHash
24530
24759
  });
24531
- if (logalot60) {
24760
+ if (logalot61) {
24532
24761
  console.timeLog(timestampUUID, "pending staging lookup complete");
24533
24762
  }
24534
24763
  if (!pendingInfo || pendingInfo.isExpired) {
@@ -24550,7 +24779,7 @@ var EmailVerifyCodeOnetimeHandler = class _EmailVerifyCodeOnetimeHandler extends
24550
24779
  pendingDir,
24551
24780
  code
24552
24781
  });
24553
- if (logalot60) {
24782
+ if (logalot61) {
24554
24783
  console.timeLog(timestampUUID, "code verification check complete");
24555
24784
  }
24556
24785
  if (!codeVerifyResult.valid) {
@@ -24559,20 +24788,20 @@ var EmailVerifyCodeOnetimeHandler = class _EmailVerifyCodeOnetimeHandler extends
24559
24788
  console.error(`${lc2} Code verification failed for ${normEmail}: ${codeVerifyResult.error} (E: 123456789abcdef0123456789a0008)`);
24560
24789
  return this.error(statusCode, codeVerifyResult.error || "Incorrect verification code.");
24561
24790
  }
24562
- const emailsDir = path6.join(pendingDir, "emails");
24791
+ const emailsDir = path7.join(pendingDir, "emails");
24563
24792
  const emailHash = await hash({ s: `emailindex${normEmail}` });
24564
- const emailMetaPath = path6.join(emailsDir, `${emailHash}.json`);
24565
- await fs5.writeFile(emailMetaPath, JSON.stringify({ email: normEmail, verified: true, verifiedAt: Date.now() }, null, 2), "utf-8");
24566
- if (logalot60) {
24793
+ const emailMetaPath = path7.join(emailsDir, `${emailHash}.json`);
24794
+ await fs6.writeFile(emailMetaPath, JSON.stringify({ email: normEmail, verified: true, verifiedAt: Date.now() }, null, 2), "utf-8");
24795
+ if (logalot61) {
24567
24796
  console.timeLog(timestampUUID, "email metadata marked verified");
24568
24797
  }
24569
- const emailFiles = await fs5.readdir(emailsDir);
24798
+ const emailFiles = await fs6.readdir(emailsDir);
24570
24799
  const verifiedEmails = [];
24571
24800
  let allVerified = true;
24572
24801
  for (const file of emailFiles) {
24573
24802
  if (file.endsWith(".json")) {
24574
24803
  try {
24575
- const content = await fs5.readFile(path6.join(emailsDir, file), "utf-8");
24804
+ const content = await fs6.readFile(path7.join(emailsDir, file), "utf-8");
24576
24805
  const meta = JSON.parse(content);
24577
24806
  if (meta.verified === true && meta.email) {
24578
24807
  verifiedEmails.push(meta.email);
@@ -24585,14 +24814,14 @@ var EmailVerifyCodeOnetimeHandler = class _EmailVerifyCodeOnetimeHandler extends
24585
24814
  }
24586
24815
  }
24587
24816
  if (allVerified) {
24588
- const keystonePath = path6.join(pendingDir, "keystone.json");
24589
- if (existsSync6(keystonePath)) {
24817
+ const keystonePath = path7.join(pendingDir, "keystone.json");
24818
+ if (existsSync7(keystonePath)) {
24590
24819
  try {
24591
- const keystoneContent = await fs5.readFile(keystonePath, "utf-8");
24820
+ const keystoneContent = await fs6.readFile(keystonePath, "utf-8");
24592
24821
  const keystone = JSON.parse(keystoneContent);
24593
24822
  const addr = getIbGibAddr({ ibGib: keystone });
24594
24823
  const metaspace = await bootstrapDomainMetaspace(addr, reqCtx.dataDir);
24595
- if (logalot60) {
24824
+ if (logalot61) {
24596
24825
  console.timeLog(timestampUUID, "domain metaspace bootstrap complete");
24597
24826
  }
24598
24827
  const space = await metaspace.getLocalUserSpace({ lock: false });
@@ -24600,7 +24829,7 @@ var EmailVerifyCodeOnetimeHandler = class _EmailVerifyCodeOnetimeHandler extends
24600
24829
  await metaspace.put({ ibGibs: [keystone], space });
24601
24830
  await metaspace.registerNewIbGib({ ibGib: keystone, space });
24602
24831
  }
24603
- if (logalot60) {
24832
+ if (logalot61) {
24604
24833
  console.timeLog(timestampUUID, "keystone promoted to domain space");
24605
24834
  }
24606
24835
  } catch (promoErr) {
@@ -24619,14 +24848,14 @@ var EmailVerifyCodeOnetimeHandler = class _EmailVerifyCodeOnetimeHandler extends
24619
24848
  }
24620
24849
  }
24621
24850
  }
24622
- if (logalot60) {
24851
+ if (logalot61) {
24623
24852
  console.timeLog(timestampUUID, "official email indices registered");
24624
24853
  }
24625
24854
  try {
24626
- await fs5.rm(pendingDir, { recursive: true, force: true });
24855
+ await fs6.rm(pendingDir, { recursive: true, force: true });
24627
24856
  } catch {
24628
24857
  }
24629
- if (logalot60) {
24858
+ if (logalot61) {
24630
24859
  console.timeLog(timestampUUID, "pending staging directory cleaned");
24631
24860
  }
24632
24861
  console.log(`${lc2} 100% verification achieved via 6-digit code. Promoted identity & registered indices for ${primaryTjpAddr} (I: 123456789abcdef0123456789a0011)`);
@@ -24647,7 +24876,7 @@ var EmailVerifyCodeOnetimeHandler = class _EmailVerifyCodeOnetimeHandler extends
24647
24876
  console.error(`${lc2} Error verifying code: ${emsg} (E: 123456789abcdef0123456789a0012)`);
24648
24877
  return this.error(500, `Code verification error: ${emsg}`);
24649
24878
  } finally {
24650
- if (logalot60) {
24879
+ if (logalot61) {
24651
24880
  console.log(`${lc2} complete.`);
24652
24881
  console.timeEnd(timestampUUID);
24653
24882
  }
@@ -24793,7 +25022,7 @@ var WebSocketFrameDecoder = class {
24793
25022
  };
24794
25023
 
24795
25024
  // ../../libs/node-gib/dist/serve-gib/handlers/api/debug/ws-echo.handler.mjs
24796
- var logalot61 = GLOBAL_LOG_A_LOT;
25025
+ var logalot62 = GLOBAL_LOG_A_LOT;
24797
25026
  var lc = `[WsEchoHandler]`;
24798
25027
  function canHandleWsUpgrade(req) {
24799
25028
  const pathname = new URL(req.url ?? "/", "http://localhost").pathname;
@@ -24802,7 +25031,7 @@ function canHandleWsUpgrade(req) {
24802
25031
  function handleWsEchoUpgrade(req, socket, head) {
24803
25032
  const lc_fn = `${lc}[handleWsEchoUpgrade]`;
24804
25033
  try {
24805
- if (logalot61) {
25034
+ if (logalot62) {
24806
25035
  console.log(`${lc_fn} starting...`);
24807
25036
  }
24808
25037
  const ok = performConnect(req, socket);
@@ -24816,7 +25045,7 @@ function handleWsEchoUpgrade(req, socket, head) {
24816
25045
  decoder.addChunk(data);
24817
25046
  let frameText = decoder.nextFrame();
24818
25047
  while (frameText !== null) {
24819
- if (logalot61) {
25048
+ if (logalot62) {
24820
25049
  console.log(`${lc_fn} echo: ${frameText}`);
24821
25050
  }
24822
25051
  socket.write(encodeTextFrame(JSON.stringify({ echo: frameText })));
@@ -24832,7 +25061,7 @@ function handleWsEchoUpgrade(req, socket, head) {
24832
25061
  console.error(`${lc_fn} socket error: ${extractErrorMsg(error)}`);
24833
25062
  });
24834
25063
  socket.on("close", () => {
24835
- if (logalot61) {
25064
+ if (logalot62) {
24836
25065
  console.log(`${lc_fn} socket closed.`);
24837
25066
  }
24838
25067
  });
@@ -24840,7 +25069,7 @@ function handleWsEchoUpgrade(req, socket, head) {
24840
25069
  console.error(`${lc_fn} ${extractErrorMsg(error)}`);
24841
25070
  socket.destroy();
24842
25071
  } finally {
24843
- if (logalot61) {
25072
+ if (logalot62) {
24844
25073
  console.log(`${lc_fn} complete.`);
24845
25074
  }
24846
25075
  }
@@ -24944,7 +25173,7 @@ var MergeTextStrategy = {
24944
25173
  var MERGE_TEXT_STRATEGY_VALID_VALUES = Object.values(MergeTextStrategy);
24945
25174
 
24946
25175
  // ../../libs/core-gib/dist/sync/graft-info/graft-info-helpers.mjs
24947
- var logalot62 = GLOBAL_LOG_A_LOT3;
25176
+ var logalot63 = GLOBAL_LOG_A_LOT3;
24948
25177
  async function getGraftInfoIb({ data }) {
24949
25178
  if (!data.conflictStrategy) {
24950
25179
  throw new Error(`(UNEXPECTED) data.conflictStrategy required for GraftInfoIb (E: 2c0968a0dac8d0ab3d67da9756d6df26)`);
@@ -24960,7 +25189,7 @@ async function getGraftInfoIb({ data }) {
24960
25189
  async function createGraftInfo({ conflictStrategy, details, addlGraftDetails, latestCommonFrameAddr, baseAddrsSinceLCA, orphanAddrsSinceLCA, dnaAddrsApplied }) {
24961
25190
  const lc2 = `[${createGraftInfo.name}]`;
24962
25191
  try {
24963
- if (logalot62) {
25192
+ if (logalot63) {
24964
25193
  console.log(`${lc2} starting... (I: 0030f62cbae28cf5882f87981edc3826)`);
24965
25194
  }
24966
25195
  if (baseAddrsSinceLCA.length === 0) {
@@ -24995,7 +25224,7 @@ async function createGraftInfo({ conflictStrategy, details, addlGraftDetails, la
24995
25224
  console.error(`${lc2} ${extractErrorMsg(error)}`);
24996
25225
  throw error;
24997
25226
  } finally {
24998
- if (logalot62) {
25227
+ if (logalot63) {
24999
25228
  console.log(`${lc2} complete.`);
25000
25229
  }
25001
25230
  }
@@ -25070,7 +25299,7 @@ async function mergeTextByLongestCommonSubsequence({ textA, textB }) {
25070
25299
  function isGraftInfo(ibGib) {
25071
25300
  const lc2 = `[${isGraftInfo.name}]`;
25072
25301
  try {
25073
- if (logalot62) {
25302
+ if (logalot63) {
25074
25303
  console.log(`${lc2} starting... (I: fe9adfe1a3175d87982507c8851f5826)`);
25075
25304
  }
25076
25305
  if (!ibGib) {
@@ -25084,19 +25313,19 @@ function isGraftInfo(ibGib) {
25084
25313
  }
25085
25314
  return true;
25086
25315
  } catch (error) {
25087
- if (logalot62) {
25316
+ if (logalot63) {
25088
25317
  console.error(`${lc2} ${extractErrorMsg(error)}`);
25089
25318
  }
25090
25319
  return false;
25091
25320
  } finally {
25092
- if (logalot62) {
25321
+ if (logalot63) {
25093
25322
  console.log(`${lc2} complete.`);
25094
25323
  }
25095
25324
  }
25096
25325
  }
25097
25326
 
25098
25327
  // ../../libs/core-gib/dist/sync/sync-helpers.mjs
25099
- var logalot63 = GLOBAL_LOG_A_LOT3;
25328
+ var logalot64 = GLOBAL_LOG_A_LOT3;
25100
25329
  async function getSyncIb({ data }) {
25101
25330
  const lc2 = `[${getSyncIb.name}]`;
25102
25331
  try {
@@ -25117,7 +25346,7 @@ async function getTempSpaceName() {
25117
25346
  async function isPastFrame({ olderAddr, newerAddr, space }) {
25118
25347
  const lc2 = `[${isPastFrame.name}]`;
25119
25348
  try {
25120
- if (logalot63) {
25349
+ if (logalot64) {
25121
25350
  console.log(`${lc2} starting... (I: 4b3548cbc9a2eb749f447ed82fdcf826)`);
25122
25351
  }
25123
25352
  if (olderAddr === newerAddr) {
@@ -25152,7 +25381,7 @@ async function isPastFrame({ olderAddr, newerAddr, space }) {
25152
25381
  console.error(`${lc2} ${extractErrorMsg(error)}`);
25153
25382
  throw error;
25154
25383
  } finally {
25155
- if (logalot63) {
25384
+ if (logalot64) {
25156
25385
  console.log(`${lc2} complete.`);
25157
25386
  }
25158
25387
  }
@@ -25185,7 +25414,7 @@ async function getSyncSagaFrameDependencyGraph({ sagaIbGib, localSpace }) {
25185
25414
  async function getFullSyncSagaHistory({ sagaIbGib, space }) {
25186
25415
  const lc2 = `[${getFullSyncSagaHistory.name}]`;
25187
25416
  try {
25188
- if (logalot63) {
25417
+ if (logalot64) {
25189
25418
  console.log(`${lc2} starting... (I: 1ea3f804dd07d1e917a2afaaad497826)`);
25190
25419
  }
25191
25420
  if (!sagaIbGib.data) {
@@ -25203,7 +25432,7 @@ async function getFullSyncSagaHistory({ sagaIbGib, space }) {
25203
25432
  if (resGet.success && resGet.ibGibs && resGet.ibGibs.length === 1) {
25204
25433
  sagaFrame = resGet.ibGibs[0];
25205
25434
  } else {
25206
- if (logalot63) {
25435
+ if (logalot64) {
25207
25436
  console.log(`${lc2} failed getting full history of sagaIbGib:
25208
25437
  ${pretty(sagaIbGib)} (I: 2a35685bfe038f63182c7db39b44c826)`);
25209
25438
  }
@@ -25220,7 +25449,7 @@ ${pretty(sagaIbGib)} (I: 2a35685bfe038f63182c7db39b44c826)`);
25220
25449
  console.error(`${lc2} ${extractErrorMsg(error)}`);
25221
25450
  throw error;
25222
25451
  } finally {
25223
- if (logalot63) {
25452
+ if (logalot64) {
25224
25453
  console.log(`${lc2} complete.`);
25225
25454
  }
25226
25455
  }
@@ -25228,7 +25457,7 @@ ${pretty(sagaIbGib)} (I: 2a35685bfe038f63182c7db39b44c826)`);
25228
25457
  async function validateSyncSagaFrame({ sagaIbGib }) {
25229
25458
  const lc2 = `[${validateSyncSagaFrame.name}]`;
25230
25459
  try {
25231
- if (logalot63) {
25460
+ if (logalot64) {
25232
25461
  console.log(`${lc2} starting... (I: dac978e9ec5820f128fbbff817b82826)`);
25233
25462
  }
25234
25463
  const errors = await validateIbGibIntrinsically({ ibGib: sagaIbGib }) ?? [];
@@ -25279,7 +25508,7 @@ async function validateSyncSagaFrame({ sagaIbGib }) {
25279
25508
  console.error(`${lc2} ${extractErrorMsg(error)}`);
25280
25509
  throw error;
25281
25510
  } finally {
25282
- if (logalot63) {
25511
+ if (logalot64) {
25283
25512
  console.log(`${lc2} complete.`);
25284
25513
  }
25285
25514
  }
@@ -25287,7 +25516,7 @@ async function validateSyncSagaFrame({ sagaIbGib }) {
25287
25516
  async function validateFullSyncSagaHistory({ history }) {
25288
25517
  const lc2 = `[${validateFullSyncSagaHistory.name}]`;
25289
25518
  try {
25290
- if (logalot63) {
25519
+ if (logalot64) {
25291
25520
  console.log(`${lc2} starting... (I: df02b802f6989096b8d8f728e2c0a526)`);
25292
25521
  }
25293
25522
  console.error(`${lc2} NAG ERROR (NOT THROWN) need to implement more validation on full saga history. (E: 9bfcc9247a1c783fd361a4a8216fef26)`);
@@ -25296,7 +25525,7 @@ async function validateFullSyncSagaHistory({ history }) {
25296
25525
  console.error(`${lc2} ${extractErrorMsg(error)}`);
25297
25526
  throw error;
25298
25527
  } finally {
25299
- if (logalot63) {
25528
+ if (logalot64) {
25300
25529
  console.log(`${lc2} complete.`);
25301
25530
  }
25302
25531
  }
@@ -25304,7 +25533,7 @@ async function validateFullSyncSagaHistory({ history }) {
25304
25533
  async function putInSpace_dnasThenNonDnas({ ibGibs, space }) {
25305
25534
  const lc2 = `[${putInSpace_dnasThenNonDnas.name}]`;
25306
25535
  try {
25307
- if (logalot63) {
25536
+ if (logalot64) {
25308
25537
  console.log(`${lc2} starting... (I: aa3ab828402836b3914800a8ffa1b826)`);
25309
25538
  }
25310
25539
  const payload_Dnas = [];
@@ -25330,7 +25559,7 @@ async function putInSpace_dnasThenNonDnas({ ibGibs, space }) {
25330
25559
  console.error(`${lc2} ${extractErrorMsg(error)}`);
25331
25560
  throw error;
25332
25561
  } finally {
25333
- if (logalot63) {
25562
+ if (logalot64) {
25334
25563
  console.log(`${lc2} complete.`);
25335
25564
  }
25336
25565
  }
@@ -25338,7 +25567,7 @@ async function putInSpace_dnasThenNonDnas({ ibGibs, space }) {
25338
25567
  function getSyncSagaFrameOrigin({ sagaFrame }) {
25339
25568
  const lc2 = `[${getSyncSagaFrameOrigin.name}]`;
25340
25569
  try {
25341
- if (logalot63) {
25570
+ if (logalot64) {
25342
25571
  console.log(`${lc2} starting... (I: 93521332d0dd2f5e88398b7db95e8126)`);
25343
25572
  }
25344
25573
  if (!sagaFrame) {
@@ -25362,7 +25591,7 @@ function getSyncSagaFrameOrigin({ sagaFrame }) {
25362
25591
  console.error(`${lc2} ${extractErrorMsg(error)}`);
25363
25592
  throw error;
25364
25593
  } finally {
25365
- if (logalot63) {
25594
+ if (logalot64) {
25366
25595
  console.log(`${lc2} complete.`);
25367
25596
  }
25368
25597
  }
@@ -25370,7 +25599,7 @@ function getSyncSagaFrameOrigin({ sagaFrame }) {
25370
25599
  async function getFinalConflictsInfo({ sagaHistory }) {
25371
25600
  const lc2 = `[${getFinalConflictsInfo.name}]`;
25372
25601
  try {
25373
- if (logalot63) {
25602
+ if (logalot64) {
25374
25603
  console.log(`${lc2} starting... (I: fe93a8f29e5d8ab2c8bd0e08e56f7826)`);
25375
25604
  }
25376
25605
  const lastDeltaHistorySlice = sagaHistory.findLast((x) => x.msgStones.some((msgStone) => msgStone.data.stage === SyncStage.delta));
@@ -25387,7 +25616,7 @@ async function getFinalConflictsInfo({ sagaHistory }) {
25387
25616
  console.error(`${lc2} ${extractErrorMsg(error)}`);
25388
25617
  throw error;
25389
25618
  } finally {
25390
- if (logalot63) {
25619
+ if (logalot64) {
25391
25620
  console.log(`${lc2} complete.`);
25392
25621
  }
25393
25622
  }
@@ -25395,12 +25624,12 @@ async function getFinalConflictsInfo({ sagaHistory }) {
25395
25624
  async function getAllOrphanedAddresses({ sagaHistory, myTempSpace }) {
25396
25625
  const lc2 = `[${getAllOrphanedAddresses.name}]`;
25397
25626
  try {
25398
- if (logalot63) {
25627
+ if (logalot64) {
25399
25628
  console.log(`${lc2} starting... (I: b755627e99c9a221566d86a81b0da526)`);
25400
25629
  }
25401
25630
  const conflicts = await getFinalConflictsInfo({ sagaHistory });
25402
25631
  if (!conflicts || conflicts.length === 0) {
25403
- if (logalot63) {
25632
+ if (logalot64) {
25404
25633
  console.log(`${lc2} no conflicts found. returning empty array (I: 5dce98010128a284c8ec92cd466a3826)`);
25405
25634
  }
25406
25635
  return [];
@@ -25435,7 +25664,7 @@ async function getAllOrphanedAddresses({ sagaHistory, myTempSpace }) {
25435
25664
  console.error(`${lc2} ${extractErrorMsg(error)}`);
25436
25665
  throw error;
25437
25666
  } finally {
25438
- if (logalot63) {
25667
+ if (logalot64) {
25439
25668
  console.log(`${lc2} complete.`);
25440
25669
  }
25441
25670
  }
@@ -25443,7 +25672,7 @@ async function getAllOrphanedAddresses({ sagaHistory, myTempSpace }) {
25443
25672
  async function deriveSessionSecret({ senderSecret, sagaId }) {
25444
25673
  const lc2 = `[${deriveSessionSecret.name}]`;
25445
25674
  try {
25446
- if (logalot63) {
25675
+ if (logalot64) {
25447
25676
  console.log(`${lc2} starting... (I: 0de03f8dcd3e32f1fca244e8f2a8a826)`);
25448
25677
  }
25449
25678
  if (!senderSecret) {
@@ -25466,14 +25695,14 @@ async function deriveSessionSecret({ senderSecret, sagaId }) {
25466
25695
  console.error(`${lc2} ${extractErrorMsg(error)}`);
25467
25696
  throw error;
25468
25697
  } finally {
25469
- if (logalot63) {
25698
+ if (logalot64) {
25470
25699
  console.log(`${lc2} complete.`);
25471
25700
  }
25472
25701
  }
25473
25702
  }
25474
25703
 
25475
25704
  // ../../libs/core-gib/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs
25476
- var logalot64 = GLOBAL_LOG_A_LOT3;
25705
+ var logalot65 = GLOBAL_LOG_A_LOT3;
25477
25706
  async function getSyncSagaContextIb({ data }) {
25478
25707
  const lc2 = `[${getSyncSagaContextIb.name}]`;
25479
25708
  try {
@@ -25495,7 +25724,7 @@ async function getSyncSagaContextIb({ data }) {
25495
25724
  async function validateContextAndSagaFrame({ context }) {
25496
25725
  const lc2 = `[${validateContextAndSagaFrame.name}]`;
25497
25726
  try {
25498
- if (logalot64) {
25727
+ if (logalot65) {
25499
25728
  console.log(`${lc2} starting... (I: 7797f8294bd8f7e5089cb722ad468226)`);
25500
25729
  }
25501
25730
  const errors = [];
@@ -25535,7 +25764,7 @@ async function validateContextAndSagaFrame({ context }) {
25535
25764
  console.error(`${lc2} ${extractErrorMsg(error)}`);
25536
25765
  throw error;
25537
25766
  } finally {
25538
- if (logalot64) {
25767
+ if (logalot65) {
25539
25768
  console.log(`${lc2} complete.`);
25540
25769
  }
25541
25770
  }
@@ -25547,7 +25776,7 @@ async function authenticateContextIntrinsically({
25547
25776
  }) {
25548
25777
  const lc2 = `[${authenticateContextIntrinsically.name}]`;
25549
25778
  try {
25550
- if (logalot64) {
25779
+ if (logalot65) {
25551
25780
  console.log(`${lc2} starting... (I: 3c34e8f1d6ef965f98725c88459ea926)`);
25552
25781
  }
25553
25782
  const errors = [];
@@ -25570,7 +25799,7 @@ async function authenticateContextIntrinsically({
25570
25799
  errors.push("Context has no signed session identity, but context.rel8ns.sessionIdentity is truthy. (E: 96a04a8a6c88ea8bf88118f89ad8e326)");
25571
25800
  return errors;
25572
25801
  } else {
25573
- if (logalot64) {
25802
+ if (logalot65) {
25574
25803
  console.log(`${lc2} context has no signedSessionIdentity and sync saga frame doesn't state there should be session identity. So nothing further to authenticate - returning early with no authentication errors. (I: d708735f9a2899ee98f762b8a09ed826)`);
25575
25804
  }
25576
25805
  return [];
@@ -25725,14 +25954,14 @@ async function authenticateContextIntrinsically({
25725
25954
  console.error(emsg);
25726
25955
  return [`authentication produced an error: ${emsg} (E: 45e014b82af81993d936611ca6fc4d26)`];
25727
25956
  } finally {
25728
- if (logalot64) {
25957
+ if (logalot65) {
25729
25958
  console.log(`${lc2} complete.`);
25730
25959
  }
25731
25960
  }
25732
25961
  }
25733
25962
 
25734
25963
  // ../../libs/core-gib/dist/sync/sync-peer/sync-peer-v1.mjs
25735
- var logalot65 = GLOBAL_LOG_A_LOT3;
25964
+ var logalot66 = GLOBAL_LOG_A_LOT3;
25736
25965
  var SyncPeer_V1 = class _SyncPeer_V1 extends LightWitnessBase_V1 {
25737
25966
  lc = `[${_SyncPeer_V1.name}]`;
25738
25967
  opts;
@@ -25845,7 +26074,7 @@ var SyncPeer_V1 = class _SyncPeer_V1 extends LightWitnessBase_V1 {
25845
26074
  async connect(opts) {
25846
26075
  const lc2 = `${this.lc}[${this.connect.name}]`;
25847
26076
  try {
25848
- if (logalot65) {
26077
+ if (logalot66) {
25849
26078
  console.log(`${lc2} starting... (I: ad89d8137351662fb8a30114a1fa4826)`);
25850
26079
  }
25851
26080
  await this.preConnectCheck(opts);
@@ -25854,7 +26083,7 @@ var SyncPeer_V1 = class _SyncPeer_V1 extends LightWitnessBase_V1 {
25854
26083
  console.error(`${lc2} ${extractErrorMsg(error)}`);
25855
26084
  throw error;
25856
26085
  } finally {
25857
- if (logalot65) {
26086
+ if (logalot66) {
25858
26087
  console.log(`${lc2} complete.`);
25859
26088
  }
25860
26089
  }
@@ -25879,7 +26108,7 @@ var SyncPeer_V1 = class _SyncPeer_V1 extends LightWitnessBase_V1 {
25879
26108
  async establishSessionIdentity() {
25880
26109
  const lc2 = `${this.lc}[${this.establishSessionIdentity.name}]`;
25881
26110
  try {
25882
- if (logalot65) {
26111
+ if (logalot66) {
25883
26112
  console.log(`${lc2} starting... (I: f2a1b3c4d5e6f7a8b9c0d1e2f3a4b526)`);
25884
26113
  }
25885
26114
  if (!this.opts) {
@@ -25887,7 +26116,7 @@ var SyncPeer_V1 = class _SyncPeer_V1 extends LightWitnessBase_V1 {
25887
26116
  }
25888
26117
  const { senderIdentity, fnSenderSecret, senderDomainAddr, sagaId, localMetaspace, localSpace } = this.opts;
25889
26118
  if (!senderIdentity || !fnSenderSecret) {
25890
- if (logalot65) {
26119
+ if (logalot66) {
25891
26120
  console.log(`${lc2} no senderIdentity/fnSenderSecret \u2014 skipping establish (I: f29348a77d1542326d14043ea4b69126)`);
25892
26121
  }
25893
26122
  return void 0;
@@ -25946,7 +26175,7 @@ var SyncPeer_V1 = class _SyncPeer_V1 extends LightWitnessBase_V1 {
25946
26175
  console.error(`${lc2} ${extractErrorMsg(error)}`);
25947
26176
  throw error;
25948
26177
  } finally {
25949
- if (logalot65) {
26178
+ if (logalot66) {
25950
26179
  console.log(`${lc2} complete.`);
25951
26180
  }
25952
26181
  }
@@ -25962,7 +26191,7 @@ var SyncPeer_V1 = class _SyncPeer_V1 extends LightWitnessBase_V1 {
25962
26191
  async initializeOpts(opts) {
25963
26192
  const lc2 = `${this.lc}[${this.initializeOpts.name}]`;
25964
26193
  try {
25965
- if (logalot65) {
26194
+ if (logalot66) {
25966
26195
  console.log(`${lc2} starting... (I: 31bd5fda37c89fa37fbaf14daf5fe726)`);
25967
26196
  }
25968
26197
  this.opts = opts;
@@ -25970,7 +26199,7 @@ var SyncPeer_V1 = class _SyncPeer_V1 extends LightWitnessBase_V1 {
25970
26199
  console.error(`${lc2} ${extractErrorMsg(error)}`);
25971
26200
  throw error;
25972
26201
  } finally {
25973
- if (logalot65) {
26202
+ if (logalot66) {
25974
26203
  console.log(`${lc2} complete.`);
25975
26204
  }
25976
26205
  }
@@ -25978,13 +26207,13 @@ var SyncPeer_V1 = class _SyncPeer_V1 extends LightWitnessBase_V1 {
25978
26207
  setOptionalOpts(arg) {
25979
26208
  const lc2 = `${this.lc}[${this.setOptionalOpts.name}]`;
25980
26209
  try {
25981
- if (logalot65) {
26210
+ if (logalot66) {
25982
26211
  console.log(`${lc2} starting... (I: ae5ddbd3577db267f84743175a736626)`);
25983
26212
  }
25984
26213
  if (!this.opts) {
25985
26214
  throw new Error(`(UNEXPECTED) this.opts falsy? (E: 0dd4d6080a6e2f31d86cf4d86e11b826)`);
25986
26215
  }
25987
- if (logalot65) {
26216
+ if (logalot66) {
25988
26217
  console.log(`${lc2} updating opts. arg keys: ${Object.keys(arg)} (I: 452d78a558f8fc3468c8e2e68c70b226)`);
25989
26218
  }
25990
26219
  this.opts = { ...this.opts, ...arg };
@@ -25992,7 +26221,7 @@ var SyncPeer_V1 = class _SyncPeer_V1 extends LightWitnessBase_V1 {
25992
26221
  console.error(`${lc2} ${extractErrorMsg(error)}`);
25993
26222
  throw error;
25994
26223
  } finally {
25995
- if (logalot65) {
26224
+ if (logalot66) {
25996
26225
  console.log(`${lc2} complete.`);
25997
26226
  }
25998
26227
  }
@@ -26017,7 +26246,7 @@ var SyncPeer_V1 = class _SyncPeer_V1 extends LightWitnessBase_V1 {
26017
26246
  async authenticateAndValidate({ context }) {
26018
26247
  const lc2 = `${this.lc}[${this.authenticateAndValidate.name}]`;
26019
26248
  try {
26020
- if (logalot65) {
26249
+ if (logalot66) {
26021
26250
  console.log(`${lc2} starting... (I: add238055cd84a222c5b8c89913af526)`);
26022
26251
  }
26023
26252
  if (!this.opts) {
@@ -26039,7 +26268,7 @@ var SyncPeer_V1 = class _SyncPeer_V1 extends LightWitnessBase_V1 {
26039
26268
  console.error(`${lc2} ${extractErrorMsg(error)}`);
26040
26269
  throw error;
26041
26270
  } finally {
26042
- if (logalot65) {
26271
+ if (logalot66) {
26043
26272
  console.log(`${lc2} complete.`);
26044
26273
  }
26045
26274
  }
@@ -26056,7 +26285,7 @@ var SyncPeer_V1 = class _SyncPeer_V1 extends LightWitnessBase_V1 {
26056
26285
  async witness(context) {
26057
26286
  const lc2 = `${this.lc}[${this.witness.name}]`;
26058
26287
  try {
26059
- if (logalot65) {
26288
+ if (logalot66) {
26060
26289
  console.log(`${lc2} starting...`);
26061
26290
  }
26062
26291
  if (!this.opts) {
@@ -26074,7 +26303,7 @@ var SyncPeer_V1 = class _SyncPeer_V1 extends LightWitnessBase_V1 {
26074
26303
  });
26075
26304
  return response;
26076
26305
  } else {
26077
- if (logalot65) {
26306
+ if (logalot66) {
26078
26307
  console.log(`${lc2} No response from peer. this may be normal if we just sent the very last commit frame. (I: 1855b7728c8898e1f9c001f8170ba826)`);
26079
26308
  }
26080
26309
  return void 0;
@@ -26083,7 +26312,7 @@ var SyncPeer_V1 = class _SyncPeer_V1 extends LightWitnessBase_V1 {
26083
26312
  console.error(`${lc2} ${extractErrorMsg(error)}`);
26084
26313
  throw error;
26085
26314
  } finally {
26086
- if (logalot65) {
26315
+ if (logalot66) {
26087
26316
  console.log(`${lc2} complete.`);
26088
26317
  }
26089
26318
  }
@@ -26097,7 +26326,7 @@ var SyncPeer_V1 = class _SyncPeer_V1 extends LightWitnessBase_V1 {
26097
26326
  async getLocalIbGib(addr) {
26098
26327
  const lc2 = `${this.lc}[${this.getLocalIbGib.name}]`;
26099
26328
  try {
26100
- if (logalot65) {
26329
+ if (logalot66) {
26101
26330
  console.log(`${lc2} starting... (I: 27b248cb9801eeb2386b71485389a826)`);
26102
26331
  }
26103
26332
  console.warn(`${lc2} possibly a bottleneck here, getLocalIbGib only gets a single ibgib... (W: 2fd448a435480e6b128f6b8bcbef4826)`);
@@ -26115,7 +26344,7 @@ var SyncPeer_V1 = class _SyncPeer_V1 extends LightWitnessBase_V1 {
26115
26344
  console.error(`${lc2} ${extractErrorMsg(error)}`);
26116
26345
  throw error;
26117
26346
  } finally {
26118
- if (logalot65) {
26347
+ if (logalot66) {
26119
26348
  console.log(`${lc2} complete.`);
26120
26349
  }
26121
26350
  }
@@ -26164,7 +26393,7 @@ var SyncWebSocketMsgType = {
26164
26393
  var SYNC_WEB_SOCKET_MSG_TYPE_VALID_VALUES = Object.values(SyncWebSocketMsgType);
26165
26394
 
26166
26395
  // ../../libs/core-gib/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-peer-websocket-receiver-v1.mjs
26167
- var logalot66 = GLOBAL_LOG_A_LOT3;
26396
+ var logalot67 = GLOBAL_LOG_A_LOT3;
26168
26397
  var SyncPeerWebSocketReceiver_V1 = class _SyncPeerWebSocketReceiver_V1 extends SyncPeer_V1 {
26169
26398
  lc = `[${_SyncPeerWebSocketReceiver_V1.name}]`;
26170
26399
  get classname() {
@@ -26241,7 +26470,7 @@ var SyncPeerWebSocketReceiver_V1 = class _SyncPeerWebSocketReceiver_V1 extends S
26241
26470
  allowCancel: false,
26242
26471
  spaceName: tempSpaceName,
26243
26472
  getFnPrompt: localMetaspace.getFnPrompt,
26244
- logalot: logalot66
26473
+ logalot: logalot67
26245
26474
  }
26246
26475
  });
26247
26476
  if (!localTempSpace) {
@@ -26266,7 +26495,7 @@ var SyncPeerWebSocketReceiver_V1 = class _SyncPeerWebSocketReceiver_V1 extends S
26266
26495
  throw new Error(`WebSocket wrapper not bound to receiver peer (E: ad4c5838d1b87259586b21a89b2c7726)`);
26267
26496
  }
26268
26497
  const msg = JSON.parse(messageText);
26269
- if (logalot66) {
26498
+ if (logalot67) {
26270
26499
  console.log(`${lc2} received frame: ${msg.type}`);
26271
26500
  }
26272
26501
  if (!this.isAuthenticated) {
@@ -26367,7 +26596,7 @@ var SyncPeerWebSocketReceiver_V1 = class _SyncPeerWebSocketReceiver_V1 extends S
26367
26596
  const space = this.opts.localSpace;
26368
26597
  if (msg.type === SyncWebSocketMsgType.auth_init) {
26369
26598
  const { sAddr } = msg;
26370
- if (logalot66) {
26599
+ if (logalot67) {
26371
26600
  console.log(`${lc2} auth-init for ${sAddr}`);
26372
26601
  }
26373
26602
  const authorizedS = await this.getSessionKeystone(sAddr);
@@ -26386,7 +26615,7 @@ var SyncPeerWebSocketReceiver_V1 = class _SyncPeerWebSocketReceiver_V1 extends S
26386
26615
  }));
26387
26616
  } else if (msg.type === SyncWebSocketMsgType.auth_proof) {
26388
26617
  const { proofFrame } = msg;
26389
- if (logalot66) {
26618
+ if (logalot67) {
26390
26619
  console.log(`${lc2} verifying auth-proof...`);
26391
26620
  }
26392
26621
  if (!this.sessionS_tjpAddr) {
@@ -26405,7 +26634,7 @@ var SyncPeerWebSocketReceiver_V1 = class _SyncPeerWebSocketReceiver_V1 extends S
26405
26634
  });
26406
26635
  await metaspace.put({ ibGibs: [proofFrame], space });
26407
26636
  await metaspace.registerNewIbGib({ ibGib: proofFrame, space });
26408
- if (logalot66) {
26637
+ if (logalot67) {
26409
26638
  console.log(`${lc2} connect validation successful! Connection upgraded to active sync session.`);
26410
26639
  }
26411
26640
  this.isAuthenticated = true;
@@ -26422,7 +26651,7 @@ var SyncPeerWebSocketReceiver_V1 = class _SyncPeerWebSocketReceiver_V1 extends S
26422
26651
  async executeIncomingSyncRequestAndRespond({ context }) {
26423
26652
  const lc2 = `${this.lc}[${this.executeIncomingSyncRequestAndRespond.name}]`;
26424
26653
  try {
26425
- if (logalot66) {
26654
+ if (logalot67) {
26426
26655
  console.log(`${lc2} executing incoming sync turn...`);
26427
26656
  }
26428
26657
  if (!this.opts) {
@@ -26446,7 +26675,7 @@ var SyncPeerWebSocketReceiver_V1 = class _SyncPeerWebSocketReceiver_V1 extends S
26446
26675
  context: responseCtx
26447
26676
  }));
26448
26677
  } else {
26449
- if (logalot66) {
26678
+ if (logalot67) {
26450
26679
  console.log(`${lc2} synchronization session completed successfully.`);
26451
26680
  }
26452
26681
  }
@@ -26466,11 +26695,11 @@ var GraftPreference;
26466
26695
  })(GraftPreference || (GraftPreference = {}));
26467
26696
 
26468
26697
  // ../../libs/core-gib/dist/timeline/timeline-api.mjs
26469
- var logalot67 = GLOBAL_LOG_A_LOT3;
26698
+ var logalot68 = GLOBAL_LOG_A_LOT3;
26470
26699
  async function getLockScope({ timeline }) {
26471
26700
  const lc2 = `[${getLockScope.name}]`;
26472
26701
  try {
26473
- if (logalot67) {
26702
+ if (logalot68) {
26474
26703
  console.log(`${lc2} starting...`);
26475
26704
  }
26476
26705
  if (isPrimitive({ ibGib: timeline })) {
@@ -26488,7 +26717,7 @@ async function getLockScope({ timeline }) {
26488
26717
  console.error(`${lc2} ${extractErrorMsg(error)}`);
26489
26718
  throw error;
26490
26719
  } finally {
26491
- if (logalot67) {
26720
+ if (logalot68) {
26492
26721
  console.log(`${lc2} complete.`);
26493
26722
  }
26494
26723
  }
@@ -26496,7 +26725,7 @@ async function getLockScope({ timeline }) {
26496
26725
  async function appendToTimeline({ timeline, rel8nInfos, rel8nRemovalInfos, timelineIndexInfo, metaspace, space, skipLock, noDna }) {
26497
26726
  const lc2 = `[${appendToTimeline.name}]`;
26498
26727
  try {
26499
- if (logalot67) {
26728
+ if (logalot68) {
26500
26729
  console.log(`${lc2} starting... (I: fcdff10832215068019355265f4cbc25)`);
26501
26730
  }
26502
26731
  space ??= await metaspace.getLocalUserSpace({ lock: false });
@@ -26592,7 +26821,7 @@ async function appendToTimeline({ timeline, rel8nInfos, rel8nRemovalInfos, timel
26592
26821
  console.error(`${lc2} ${extractErrorMsg(error)}`);
26593
26822
  throw error;
26594
26823
  } finally {
26595
- if (logalot67) {
26824
+ if (logalot68) {
26596
26825
  console.log(`${lc2} complete.`);
26597
26826
  }
26598
26827
  }
@@ -26600,7 +26829,7 @@ async function appendToTimeline({ timeline, rel8nInfos, rel8nRemovalInfos, timel
26600
26829
  async function updateSpecialIndex({ type, rel8nInfos, dataToAddOrPatch, metaspace, space, skipLock }) {
26601
26830
  const lc2 = `[${updateSpecialIndex.name}]`;
26602
26831
  try {
26603
- if (logalot67) {
26832
+ if (logalot68) {
26604
26833
  console.log(`${lc2} starting... (I: 6e7d05fe916d813b71766e2eaa747c25)`);
26605
26834
  }
26606
26835
  if (type === "latest") {
@@ -26698,7 +26927,7 @@ async function updateSpecialIndex({ type, rel8nInfos, dataToAddOrPatch, metaspac
26698
26927
  console.error(`${lc2} ${extractErrorMsg(error)}`);
26699
26928
  throw error;
26700
26929
  } finally {
26701
- if (logalot67) {
26930
+ if (logalot68) {
26702
26931
  console.log(`${lc2} complete.`);
26703
26932
  }
26704
26933
  }
@@ -26706,7 +26935,7 @@ async function updateSpecialIndex({ type, rel8nInfos, dataToAddOrPatch, metaspac
26706
26935
  async function getLatestTimelineIbGibDto_nonLocking({ timeline, timelineAddr, metaspace, space }) {
26707
26936
  const lc2 = `[${getLatestTimelineIbGibDto_nonLocking.name}]`;
26708
26937
  try {
26709
- if (logalot67) {
26938
+ if (logalot68) {
26710
26939
  console.log(`${lc2} starting... (I: f2b605361368e1956f6db878dbfeb825)`);
26711
26940
  }
26712
26941
  if (!timeline && !timelineAddr) {
@@ -26748,7 +26977,7 @@ async function getLatestTimelineIbGibDto_nonLocking({ timeline, timelineAddr, me
26748
26977
  console.error(`${lc2} ${extractErrorMsg(error)}`);
26749
26978
  throw error;
26750
26979
  } finally {
26751
- if (logalot67) {
26980
+ if (logalot68) {
26752
26981
  console.log(`${lc2} complete.`);
26753
26982
  }
26754
26983
  }
@@ -26756,7 +26985,7 @@ async function getLatestTimelineIbGibDto_nonLocking({ timeline, timelineAddr, me
26756
26985
  async function createTimeline({ ib, data, rel8ns, noDna, parentIb, parentIbGib, metaspace, space }) {
26757
26986
  const lc2 = `[${createTimeline.name}]`;
26758
26987
  try {
26759
- if (logalot67) {
26988
+ if (logalot68) {
26760
26989
  console.log(`${lc2} starting...`);
26761
26990
  }
26762
26991
  space ??= await metaspace.getLocalUserSpace({ lock: false });
@@ -26800,7 +27029,7 @@ async function createTimeline({ ib, data, rel8ns, noDna, parentIb, parentIbGib,
26800
27029
  async function getDna({ ibGib, metaspace, space }) {
26801
27030
  const lc2 = `[${getDna.name}]`;
26802
27031
  try {
26803
- if (logalot67) {
27032
+ if (logalot68) {
26804
27033
  console.log(`${lc2} starting...`);
26805
27034
  }
26806
27035
  space ??= await metaspace.getLocalUserSpace({ lock: false });
@@ -26825,7 +27054,7 @@ async function getDna({ ibGib, metaspace, space }) {
26825
27054
  async function getHistory({ timeline, getLatest, includeDna, metaspace, space }) {
26826
27055
  const lc2 = `[${getHistory.name}]`;
26827
27056
  try {
26828
- if (logalot67) {
27057
+ if (logalot68) {
26829
27058
  console.log(`${lc2} starting... (I: 7fbc442a27e8f9fda8ac4228ded84825)`);
26830
27059
  }
26831
27060
  space ??= await metaspace.getLocalUserSpace({ lock: false });
@@ -26871,7 +27100,7 @@ async function getHistory({ timeline, getLatest, includeDna, metaspace, space })
26871
27100
  console.error(`${lc2} ${extractErrorMsg(error)}`);
26872
27101
  throw error;
26873
27102
  } finally {
26874
- if (logalot67) {
27103
+ if (logalot68) {
26875
27104
  console.log(`${lc2} complete.`);
26876
27105
  }
26877
27106
  }
@@ -26879,7 +27108,7 @@ async function getHistory({ timeline, getLatest, includeDna, metaspace, space })
26879
27108
  async function getHistoryAddrs({ timeline, getLatest, metaspace, space }) {
26880
27109
  const lc2 = `[${getHistoryAddrs.name}]`;
26881
27110
  try {
26882
- if (logalot67) {
27111
+ if (logalot68) {
26883
27112
  console.log(`${lc2} starting... (I: c7a328b14018642138ebb47870c15626)`);
26884
27113
  }
26885
27114
  const historyInfo = await getHistory({
@@ -26895,7 +27124,7 @@ async function getHistoryAddrs({ timeline, getLatest, metaspace, space }) {
26895
27124
  console.error(`${lc2} ${extractErrorMsg(error)}`);
26896
27125
  throw error;
26897
27126
  } finally {
26898
- if (logalot67) {
27127
+ if (logalot68) {
26899
27128
  console.log(`${lc2} complete.`);
26900
27129
  }
26901
27130
  }
@@ -26942,11 +27171,11 @@ async function getSyncSagaMessageFromFrame({ frameIbGib, space }) {
26942
27171
  }
26943
27172
 
26944
27173
  // ../../libs/core-gib/dist/witness/space/reconciliation-space/reconciliation-space-helper.mjs
26945
- var logalot68 = GLOBAL_LOG_A_LOT3;
27174
+ var logalot69 = GLOBAL_LOG_A_LOT3;
26946
27175
  function getUniqueDnas({ base, extended, throwIfExtendedDoesntContainBase }) {
26947
27176
  const lc2 = `[${getUniqueDnas.name}]`;
26948
27177
  try {
26949
- if (logalot68) {
27178
+ if (logalot69) {
26950
27179
  console.log(`${lc2} starting... (I: 00d70d79a0249165c2a230389c962526)`);
26951
27180
  }
26952
27181
  let baseIsStartingSubsetOfExtended = true;
@@ -26975,7 +27204,7 @@ function getUniqueDnas({ base, extended, throwIfExtendedDoesntContainBase }) {
26975
27204
  console.error(`${lc2} ${extractErrorMsg(error)}`);
26976
27205
  throw error;
26977
27206
  } finally {
26978
- if (logalot68) {
27207
+ if (logalot69) {
26979
27208
  console.log(`${lc2} complete.`);
26980
27209
  }
26981
27210
  }
@@ -27037,7 +27266,7 @@ async function applyTransforms({ src, createdIbGibs_Running, dnaAddrsToApplyToSt
27037
27266
  }
27038
27267
 
27039
27268
  // ../../libs/core-gib/dist/sync/graft-info/graft-merge-strategy-base-v1.mjs
27040
- var logalot69 = GLOBAL_LOG_A_LOT3;
27269
+ var logalot70 = GLOBAL_LOG_A_LOT3;
27041
27270
  var GraftMergeStrategyBase_V1 = class {
27042
27271
  defaultGraftPreference;
27043
27272
  constructor(opts) {
@@ -27094,7 +27323,7 @@ var GraftMergeStrategyBase_V1 = class {
27094
27323
  async applyTransformAndRegister({ resTransform, space, newGraftDnaIbGibs, newGraftedIntermediateIbGibs_ordered }) {
27095
27324
  const lc2 = `[${this.constructor.name}][${this.applyTransformAndRegister.name}]`;
27096
27325
  try {
27097
- if (logalot69) {
27326
+ if (logalot70) {
27098
27327
  console.log(`${lc2} starting... (I: 2e8a1d7f6c4342138901a1b2c3d4e5f6)`);
27099
27328
  }
27100
27329
  if (!resTransform) {
@@ -27119,7 +27348,7 @@ var GraftMergeStrategyBase_V1 = class {
27119
27348
  console.error(`${lc2} ${extractErrorMsg(error)} (E: d2384a8b792e42429bc7891234567826)`);
27120
27349
  throw error;
27121
27350
  } finally {
27122
- if (logalot69) {
27351
+ if (logalot70) {
27123
27352
  console.log(`${lc2} complete.`);
27124
27353
  }
27125
27354
  }
@@ -27127,7 +27356,7 @@ var GraftMergeStrategyBase_V1 = class {
27127
27356
  };
27128
27357
 
27129
27358
  // ../../libs/core-gib/dist/sync/graft-info/strategies/default-dna-replay-graft-strategy.mjs
27130
- var logalot70 = GLOBAL_LOG_A_LOT3;
27359
+ var logalot71 = GLOBAL_LOG_A_LOT3;
27131
27360
  var DefaultDnaReplayGraftStrategy = class extends GraftMergeStrategyBase_V1 {
27132
27361
  strategyId = "DefaultDnaReplayGraftStrategy";
27133
27362
  canGraft(context) {
@@ -27157,7 +27386,7 @@ var DefaultDnaReplayGraftStrategy = class extends GraftMergeStrategyBase_V1 {
27157
27386
  }
27158
27387
  };
27159
27388
  var throwIfUnexpected = throwIfUnexpected2;
27160
- if (logalot70) {
27389
+ if (logalot71) {
27161
27390
  console.log(`${lc2} starting default DNA replay graft... (I: 8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d)`);
27162
27391
  }
27163
27392
  const { conflictStrategy, timelineAddrsA, timelineAddrsB, latestCommonFrameAddr, ibGibReadCache, space, graftPreference } = context;
@@ -27198,10 +27427,10 @@ var DefaultDnaReplayGraftStrategy = class extends GraftMergeStrategyBase_V1 {
27198
27427
  const baseBranchAddrs = baseBranch.map((x) => getIbGibAddr({ ibGib: x }));
27199
27428
  const orphanTipAddr = getIbGibAddr({ ibGib: orphanTip });
27200
27429
  const orphanBranchAddrs = orphanBranch.map((x) => getIbGibAddr({ ibGib: x }));
27201
- if (logalot70) {
27430
+ if (logalot71) {
27202
27431
  console.log(`${lc2} baseTipAddr: ${baseTipAddr} (I: 93353d9b9b68b17088f57958df85e826)`);
27203
27432
  }
27204
- if (logalot70) {
27433
+ if (logalot71) {
27205
27434
  console.log(`${lc2} orphanTipAddr: ${orphanTipAddr} (I: 14df8867adc5dab97ff3c1e989b40e26)`);
27206
27435
  }
27207
27436
  const [latestCommonFrameIbGib] = await getIbGibsFromCache_fallbackToSpaces({
@@ -27324,7 +27553,7 @@ var DefaultDnaReplayGraftStrategy = class extends GraftMergeStrategyBase_V1 {
27324
27553
  console.error(`${lc2} ${extractErrorMsg(error)} (E: 7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f)`);
27325
27554
  throw error;
27326
27555
  } finally {
27327
- if (logalot70) {
27556
+ if (logalot71) {
27328
27557
  console.log(`${lc2} complete.`);
27329
27558
  }
27330
27559
  }
@@ -27332,7 +27561,7 @@ var DefaultDnaReplayGraftStrategy = class extends GraftMergeStrategyBase_V1 {
27332
27561
  };
27333
27562
 
27334
27563
  // ../../libs/core-gib/dist/sync/graft-info/graft-strategy-service.mjs
27335
- var logalot71 = GLOBAL_LOG_A_LOT3;
27564
+ var logalot72 = GLOBAL_LOG_A_LOT3;
27336
27565
  var lcFile = `[graft-strategy-service]`;
27337
27566
  var GraftStrategyService = class _GraftStrategyService {
27338
27567
  static _instance;
@@ -27354,7 +27583,7 @@ var GraftStrategyService = class _GraftStrategyService {
27354
27583
  throw new Error(`(UNEXPECTED) strategy falsy (E: 7c8b9a0d1e2f3a4b5c6d7e8f9a0b1c2d)`);
27355
27584
  }
27356
27585
  if (!this._registeredStrategies.some((s) => s.strategyId === strategy.strategyId)) {
27357
- if (logalot71) {
27586
+ if (logalot72) {
27358
27587
  console.log(`${lc2} registering strategy ${strategy.strategyId} (I: 8b9a0c1d2e3f4a5b6c7d8e9f0a1b2c3d)`);
27359
27588
  }
27360
27589
  this._registeredStrategies.push(strategy);
@@ -27368,7 +27597,7 @@ var GraftStrategyService = class _GraftStrategyService {
27368
27597
  if (!strategy) {
27369
27598
  throw new Error(`(UNEXPECTED) fallback strategy falsy (E: 9c0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c)`);
27370
27599
  }
27371
- if (logalot71) {
27600
+ if (logalot72) {
27372
27601
  console.log(`${lc2} setting fallback strategy ${strategy.strategyId} (I: 0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d)`);
27373
27602
  }
27374
27603
  this._fallbackStrategy = strategy;
@@ -27384,7 +27613,7 @@ var GraftStrategyService = class _GraftStrategyService {
27384
27613
  */
27385
27614
  reset() {
27386
27615
  const lc2 = `${lcFile}[${this.reset.name}]`;
27387
- if (logalot71) {
27616
+ if (logalot72) {
27388
27617
  console.log(`${lc2} resetting strategies to default fallback... (I: 1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d)`);
27389
27618
  }
27390
27619
  this._registeredStrategies = [];
@@ -27400,7 +27629,7 @@ var GraftStrategyService = class _GraftStrategyService {
27400
27629
  async graftTimelines({ timelineAddrsA, timelineAddrsB, latestCommonFrameAddr, conflictStrategy, ibGibReadCache, space, graftPreference }) {
27401
27630
  const lc2 = `[${this.graftTimelines.name}]`;
27402
27631
  try {
27403
- if (logalot71) {
27632
+ if (logalot72) {
27404
27633
  console.log(`${lc2} starting... (I: 3b4c3e8e59c883d9d3c352efd6380826)`);
27405
27634
  }
27406
27635
  if (timelineAddrsA.length === 0) {
@@ -27453,7 +27682,7 @@ var GraftStrategyService = class _GraftStrategyService {
27453
27682
  }
27454
27683
  let resGraft = void 0;
27455
27684
  for (const strategy of strategyPipeline) {
27456
- if (logalot71) {
27685
+ if (logalot72) {
27457
27686
  console.log(`${lc2} executing graft strategy ${strategy.strategyId} (I: 5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f)`);
27458
27687
  }
27459
27688
  resGraft = await strategy.graft(context);
@@ -27469,7 +27698,7 @@ var GraftStrategyService = class _GraftStrategyService {
27469
27698
  console.error(`${lc2} ${extractErrorMsg(error)} (E: 9a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d)`);
27470
27699
  throw error;
27471
27700
  } finally {
27472
- if (logalot71) {
27701
+ if (logalot72) {
27473
27702
  console.log(`${lc2} complete.`);
27474
27703
  }
27475
27704
  }
@@ -27477,7 +27706,7 @@ var GraftStrategyService = class _GraftStrategyService {
27477
27706
  };
27478
27707
 
27479
27708
  // ../../libs/core-gib/dist/sync/sync-saga-coordinator.mjs
27480
- var logalot72 = GLOBAL_LOG_A_LOT3;
27709
+ var logalot73 = GLOBAL_LOG_A_LOT3;
27481
27710
  var logalotControlDomain = false;
27482
27711
  var lcControlDomain = "[ControlDomain]";
27483
27712
  var SyncSagaCoordinator = class _SyncSagaCoordinator {
@@ -27531,7 +27760,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
27531
27760
  */
27532
27761
  async sync({ peer, domainIbGibs, senderIdentityInfo, fnSenderSecret, conflictStrategy = SyncConflictStrategy.abort, graftPreference, metaspace, localSpace }) {
27533
27762
  const lc2 = `${this.lc}[${this.sync.name}]`;
27534
- if (logalot72) {
27763
+ if (logalot73) {
27535
27764
  console.log(`${lc2} starting...`);
27536
27765
  }
27537
27766
  if (!localSpace) {
@@ -27571,7 +27800,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
27571
27800
  allowCancel: false,
27572
27801
  spaceName: tempSpaceName,
27573
27802
  getFnPrompt: metaspace.getFnPrompt,
27574
- logalot: logalot72
27803
+ logalot: logalot73
27575
27804
  }
27576
27805
  });
27577
27806
  if (!tempSpace) {
@@ -27645,7 +27874,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
27645
27874
  async continueSync({ sagaContext, mySpace, myTempSpace, metaspace, peer }) {
27646
27875
  const lc2 = `${this.lc}[${this.continueSync.name}]`;
27647
27876
  try {
27648
- if (logalot72) {
27877
+ if (logalot73) {
27649
27878
  console.log(`${lc2} starting... (I: f64e08bf77d1425378601f380384ec26)`);
27650
27879
  }
27651
27880
  const contextResult = await this.handleResponseSagaContext({
@@ -27655,7 +27884,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
27655
27884
  metaspace
27656
27885
  });
27657
27886
  if (!contextResult) {
27658
- if (logalot72) {
27887
+ if (logalot73) {
27659
27888
  console.log(`${lc2} Handler returned null (Saga End). (I: 43da8bb6c846b1fe7766332643be0e26)`);
27660
27889
  }
27661
27890
  return null;
@@ -27688,7 +27917,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
27688
27917
  console.error(`${lc2} ${extractErrorMsg(error)}`);
27689
27918
  throw error;
27690
27919
  } finally {
27691
- if (logalot72) {
27920
+ if (logalot73) {
27692
27921
  console.log(`${lc2} complete.`);
27693
27922
  }
27694
27923
  }
@@ -27717,7 +27946,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
27717
27946
  const sublc = `${lc2}[peer.payloadIbGibsDomainReceived$]`;
27718
27947
  const subscription = await peer.payloadIbGibsDomainReceived$.subscribe(fnObs({
27719
27948
  next: async (ibgib) => {
27720
- if (logalot72) {
27949
+ if (logalot73) {
27721
27950
  console.log(`${sublc} next fired. (I: 2b4bdf502a38a90ba33d9711e7cb7826)`);
27722
27951
  }
27723
27952
  const addr = getIbGibAddr({ ibGib: ibgib });
@@ -27735,7 +27964,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
27735
27964
  }
27736
27965
  },
27737
27966
  complete: async () => {
27738
- if (logalot72) {
27967
+ if (logalot73) {
27739
27968
  console.log(`${sublc} complete fired. (I: a47218aa9e4433fdb97c068880a45826)`);
27740
27969
  }
27741
27970
  await subscription.unsubscribe();
@@ -27770,7 +27999,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
27770
27999
  if (currentFrame) {
27771
28000
  const msg = await getSyncSagaMessageFromFrame({ frameIbGib: currentFrame, space: localSpace });
27772
28001
  if (msg?.data?.stage === SyncStage.commit) {
27773
- if (logalot72) {
28002
+ if (logalot73) {
27774
28003
  console.log(`${lc2} Sender sent Commit. Peer returned no response. Saga Complete. (I: 26f9ee073858ca78b8284753368b5226)`);
27775
28004
  }
27776
28005
  currentFrame = null;
@@ -27830,7 +28059,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
27830
28059
  console.error(`${lc2} NAG ERROR (DOES NOT THROW): does this ever hit now? (E: e04d02efc2a8e72a88b79f1f0f95ca26)`);
27831
28060
  break;
27832
28061
  } else if (contextResult.nextFrameInfo?.sagaComplete) {
27833
- if (logalot72) {
28062
+ if (logalot73) {
27834
28063
  console.log(`${lc2} Handler returned null (Saga End). (I: 123bf9e7dca8886de72553a8d4f29e26)`);
27835
28064
  }
27836
28065
  break;
@@ -27868,7 +28097,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
27868
28097
  async createSyncSagaContext({ sagaFrame, payloadIbGibsDomain, metaspace, localSpace, sessionIdentityAddr, peer, skipSign }) {
27869
28098
  const lc2 = `[${this.createSyncSagaContext.name}]`;
27870
28099
  try {
27871
- if (logalot72) {
28100
+ if (logalot73) {
27872
28101
  console.log(`${lc2} starting... (I: 6b87bee313e811d1d2fc90e87fbec826)`);
27873
28102
  }
27874
28103
  if (!sagaFrame.data) {
@@ -27942,7 +28171,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
27942
28171
  console.error(`${lc2} ${extractErrorMsg(error)}`);
27943
28172
  throw error;
27944
28173
  } finally {
27945
- if (logalot72) {
28174
+ if (logalot73) {
27946
28175
  console.log(`${lc2} complete.`);
27947
28176
  }
27948
28177
  }
@@ -27954,7 +28183,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
27954
28183
  async getKnowledgeMap({ space, metaspace, domainIbGibs, tjpAddrs }) {
27955
28184
  const lc2 = `${this.lc}[${this.getKnowledgeMap.name}]`;
27956
28185
  try {
27957
- if (logalot72) {
28186
+ if (logalot73) {
27958
28187
  console.log(`${lc2} starting... (I: e184f8a7818666febfbbd2d841ed3826)`);
27959
28188
  }
27960
28189
  if (!(domainIbGibs && domainIbGibs.length > 0) && !(tjpAddrs && tjpAddrs.length > 0)) {
@@ -27987,7 +28216,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
27987
28216
  console.error(`${lc2} ${extractErrorMsg(error)}`);
27988
28217
  throw error;
27989
28218
  } finally {
27990
- if (logalot72) {
28219
+ if (logalot73) {
27991
28220
  console.log(`${lc2} complete.`);
27992
28221
  }
27993
28222
  }
@@ -28003,7 +28232,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28003
28232
  space
28004
28233
  });
28005
28234
  const graphIsValid = fullGraph && Object.keys(fullGraph).length > 0;
28006
- if (logalot72) {
28235
+ if (logalot73) {
28007
28236
  console.log(`${lc2} graph generated. nodes: ${graphIsValid ? Object.keys(fullGraph).length : 0}`);
28008
28237
  }
28009
28238
  const srcIbGibs = graphIsValid ? Object.values(fullGraph) : [];
@@ -28026,7 +28255,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28026
28255
  async createInitFrame({ sagaId, domainIbGibs, conflictStrategy, graftPreference, metaspace, localSpace, tempSpace, peer }) {
28027
28256
  const lc2 = `${this.lc}[${this.createInitFrame.name}]`;
28028
28257
  try {
28029
- if (logalot72) {
28258
+ if (logalot73) {
28030
28259
  console.log(`${lc2} starting... (I: 551af8b411ae9be712ce3358d43ee726)`);
28031
28260
  }
28032
28261
  const analysis = await this.analyzeDomainIbGibs({ domainIbGibs, space: localSpace });
@@ -28045,7 +28274,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28045
28274
  mode: SyncMode.sync,
28046
28275
  stones: srcStones.map((s) => getIbGibAddr({ ibGib: s }))
28047
28276
  };
28048
- if (logalot72) {
28277
+ if (logalot73) {
28049
28278
  console.log(`${lc2} SyncStage.init: ${SyncStage.init}, SyncStage.commit: ${SyncStage.commit}`);
28050
28279
  console.log(`${lc2} initData.stage: ${initData.stage}`);
28051
28280
  }
@@ -28062,7 +28291,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28062
28291
  localSpace,
28063
28292
  sessionIdentity: peer.currentSessionIdentity
28064
28293
  });
28065
- if (logalot72) {
28294
+ if (logalot73) {
28066
28295
  console.log(`${lc2} sagaFrame (init): ${pretty(sagaFrame)} (I: b3d6a8be69248f18713cc3073cb08626)`);
28067
28296
  }
28068
28297
  return { initFrame: sagaFrame, initDomainGraph: fullGraph };
@@ -28070,7 +28299,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28070
28299
  console.error(`${lc2} ${extractErrorMsg(error)}`);
28071
28300
  throw error;
28072
28301
  } finally {
28073
- if (logalot72) {
28302
+ if (logalot73) {
28074
28303
  console.log(`${lc2} complete.`);
28075
28304
  }
28076
28305
  }
@@ -28111,7 +28340,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28111
28340
  } catch (error) {
28112
28341
  errors.push(`Error during validateReturnContext: ${extractErrorMsg(error)} (E: da878e1239aa88ee27bdfca005c28226)`);
28113
28342
  }
28114
- if (logalot72 && errors.length > 0) {
28343
+ if (logalot73 && errors.length > 0) {
28115
28344
  console.log(`${lc2} errors: ${errors.join("\n")} (I: cbc119df45aa13daa9009de392c4b226)`);
28116
28345
  }
28117
28346
  return errors;
@@ -28125,7 +28354,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28125
28354
  async pollForDomainPayloads({ expectedAddrs, pollIntervalMs, domainPayloadsMap, tempSpace }) {
28126
28355
  const lc2 = `${this.lc}[${this.pollForDomainPayloads.name}]`;
28127
28356
  try {
28128
- if (logalot72) {
28357
+ if (logalot73) {
28129
28358
  console.log(`${lc2} starting... (I: 26dce86bfca572939885798802d6e926)`);
28130
28359
  }
28131
28360
  let resultDomainPayloads = [];
@@ -28164,7 +28393,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28164
28393
  console.error(`${lc2} ${extractErrorMsg(error)}`);
28165
28394
  throw error;
28166
28395
  } finally {
28167
- if (logalot72) {
28396
+ if (logalot73) {
28168
28397
  console.log(`${lc2} complete.`);
28169
28398
  }
28170
28399
  }
@@ -28198,18 +28427,18 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28198
28427
  async handleResponseSagaContext({ sagaContext, initDomainGraph, mySpace, myTempSpace, metaspace }) {
28199
28428
  const lc2 = `${this.lc}[${this.handleResponseSagaContext.name}]`;
28200
28429
  try {
28201
- if (logalot72) {
28430
+ if (logalot73) {
28202
28431
  console.log(`${lc2} starting... (I: 5deec8a1f7a6d263c88cd458ad990826)`);
28203
28432
  }
28204
28433
  const sagaIbGib = sagaContext.sagaFrame;
28205
28434
  if (!sagaIbGib.data) {
28206
28435
  throw new Error(`(UNEXPECTED) sagaIbGib.data falsy? (E: 71b938adf1d87c2527bfd4f86dfd0826)`);
28207
28436
  }
28208
- if (logalot72) {
28437
+ if (logalot73) {
28209
28438
  console.log(`${lc2} sagaIbGib: ${pretty(sagaIbGib)} (I: 1b99d87d262e9d18d8a607a80b1a0126)`);
28210
28439
  }
28211
28440
  const { stage, messageData } = await this.getStageAndPayloadFromFrame({ sagaFrame: sagaIbGib, space: mySpace });
28212
- if (logalot72) {
28441
+ if (logalot73) {
28213
28442
  console.log(`${lc2} handling frame stage: ${stage}`);
28214
28443
  }
28215
28444
  let nextFrameInfo;
@@ -28246,7 +28475,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28246
28475
  });
28247
28476
  break;
28248
28477
  case SyncStage.commit:
28249
- if (logalot72) {
28478
+ if (logalot73) {
28250
28479
  console.log(`${lc2}[${getSyncSagaFrameOrigin({ sagaFrame: sagaIbGib })}] mySpace.ib: ${mySpace.ib} (I: 5b270996d848907238d817fffa64a126)`);
28251
28480
  }
28252
28481
  nextFrameInfo = await this.handleCommitFrame({
@@ -28259,7 +28488,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28259
28488
  default:
28260
28489
  throw new Error(`${lc2} (UNEXPECTED) Unknown sync stage: ${stage} (E: 9c2b4c8a6d34469f8263544710183355)`);
28261
28490
  }
28262
- if (logalot72) {
28491
+ if (logalot73) {
28263
28492
  console.log(`${lc2} nextFrameInfo: ${nextFrameInfo ? pretty(nextFrameInfo) : "undefined"} (I: a8ad281ca8e89385686d18327a105726)`);
28264
28493
  }
28265
28494
  return { errorMsg: void 0, nextFrameInfo };
@@ -28268,7 +28497,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28268
28497
  console.error(errorMsg);
28269
28498
  return { errorMsg };
28270
28499
  } finally {
28271
- if (logalot72) {
28500
+ if (logalot73) {
28272
28501
  console.log(`${lc2} complete.`);
28273
28502
  }
28274
28503
  }
@@ -28289,10 +28518,10 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28289
28518
  async handleInitFrame({ sagaIbGib, messageData, mySpace, myTempSpace, metaspace }) {
28290
28519
  const lc2 = `${this.lc}[${this.handleInitFrame.name}]`;
28291
28520
  try {
28292
- if (logalot72) {
28521
+ if (logalot73) {
28293
28522
  console.log(`${lc2} starting... (I: 9d88dcad0408c029e898a4bcf3b08426)`);
28294
28523
  }
28295
- if (logalot72) {
28524
+ if (logalot73) {
28296
28525
  console.log(`${lc2} [TEST DEBUG] Receiver mySpace: ${mySpace.ib}`);
28297
28526
  }
28298
28527
  const initData = messageData;
@@ -28308,7 +28537,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28308
28537
  const pushOfferInfos = [];
28309
28538
  const stones = initData.stones || [];
28310
28539
  if (stones.length > 0) {
28311
- if (logalot72) {
28540
+ if (logalot73) {
28312
28541
  console.log(`${lc2} processing stones: ${stones.length}`);
28313
28542
  }
28314
28543
  const resStones = await getFromSpace({ space: mySpace, addrs: stones });
@@ -28318,7 +28547,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28318
28547
  }
28319
28548
  const addrsNotFound = rawResultIbGib.data.addrsNotFound;
28320
28549
  if (addrsNotFound && addrsNotFound.length > 0) {
28321
- if (logalot72) {
28550
+ if (logalot73) {
28322
28551
  console.log(`${lc2} stones missing (requesting): ${addrsNotFound.length}`);
28323
28552
  }
28324
28553
  addrsNotFound.forEach((addr) => {
@@ -28329,14 +28558,14 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28329
28558
  }
28330
28559
  }
28331
28560
  const senderKnowledge = initData.knowledgeMap;
28332
- if (logalot72) {
28561
+ if (logalot73) {
28333
28562
  console.log(`${lc2} senderKnowledge: ${pretty(senderKnowledge)} (I: 9f957862356dfeae183c200854e86e26)`);
28334
28563
  }
28335
28564
  const senderTjpAddrs = Object.keys(senderKnowledge);
28336
- if (logalot72) {
28565
+ if (logalot73) {
28337
28566
  console.log(`${lc2} [TEST DEBUG] senderTjpAddrs: ${JSON.stringify(senderTjpAddrs)}`);
28338
28567
  }
28339
- if (logalot72) {
28568
+ if (logalot73) {
28340
28569
  console.log(`${lc2} senderTjpAddrs: ${pretty(senderTjpAddrs)} (I: 86ea4c53db0dc184c8b253386c402126)`);
28341
28570
  }
28342
28571
  let receiverLatestAddrsMap = {};
@@ -28353,10 +28582,10 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28353
28582
  throw new Error(`(UNEXPECTED) resGetLatestAddrs.data.latestAddrsMap falsy? (E: 16bc386dd51d0ff53a49620b1e641826)`);
28354
28583
  }
28355
28584
  receiverLatestAddrsMap = resGetLatestAddrs.data.latestAddrsMap;
28356
- if (logalot72) {
28585
+ if (logalot73) {
28357
28586
  console.log(`${lc2} [TEST DEBUG] receiverLatestAddrsMap: ${JSON.stringify(receiverLatestAddrsMap)}`);
28358
28587
  }
28359
- if (logalot72) {
28588
+ if (logalot73) {
28360
28589
  console.log(`${lc2} receiverLatestAddrsMap: ${pretty(receiverLatestAddrsMap)} (I: 980975642cbccd8018cf0cd808d30826)`);
28361
28590
  }
28362
28591
  }
@@ -28364,7 +28593,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28364
28593
  const senderTipAddr = senderKnowledge[tjpAddr];
28365
28594
  const receiverTipAddr = receiverLatestAddrsMap[tjpAddr];
28366
28595
  if (!receiverTipAddr) {
28367
- if (logalot72) {
28596
+ if (logalot73) {
28368
28597
  console.log(`${lc2} [TEST DEBUG] Missing receiver timeline for TJP: ${tjpAddr}. Requesting remoteAddr: ${senderTipAddr}`);
28369
28598
  }
28370
28599
  deltaRequestAddrInfos.push({
@@ -28376,12 +28605,12 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28376
28605
  continue;
28377
28606
  }
28378
28607
  if (receiverTipAddr === senderTipAddr) {
28379
- if (logalot72) {
28608
+ if (logalot73) {
28380
28609
  console.log(`${lc2} [TEST DEBUG] TJP ${tjpAddr}: Synced (receiverTipAddr === remoteAddr)`);
28381
28610
  }
28382
28611
  continue;
28383
28612
  }
28384
- if (logalot72) {
28613
+ if (logalot73) {
28385
28614
  console.log(`${lc2} [TEST DEBUG] TJP ${tjpAddr}: receiverTipAddr=${receiverTipAddr}, remoteAddr=${senderTipAddr} - checking for divergence...`);
28386
28615
  }
28387
28616
  let remoteIsInPast;
@@ -28396,7 +28625,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28396
28625
  remoteIsInPast = false;
28397
28626
  }
28398
28627
  if (remoteIsInPast) {
28399
- if (logalot72) {
28628
+ if (logalot73) {
28400
28629
  console.log(`${lc2} [TEST DEBUG] TJP ${tjpAddr}: Remote (sender) is in past - offering push`);
28401
28630
  }
28402
28631
  const deltaGraph = await getDeltaDependencyGraph({
@@ -28416,12 +28645,12 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28416
28645
  space: mySpace
28417
28646
  });
28418
28647
  } catch (error) {
28419
- if (logalot72) {
28648
+ if (logalot73) {
28420
28649
  console.log(`${lc2} isPastFrame just threw, but is an expected error if we don't have remote. verbose logging error though: ${extractErrorMsg(error)} (I: 47ea08d0b418cf4aa8a502a7bcb80826)`);
28421
28650
  }
28422
28651
  }
28423
28652
  if (receiverIsInPast) {
28424
- if (logalot72) {
28653
+ if (logalot73) {
28425
28654
  console.log(`${lc2} [TEST DEBUG] TJP ${tjpAddr}: receiver is in past - requesting delta`);
28426
28655
  }
28427
28656
  deltaRequestAddrInfos.push({
@@ -28430,7 +28659,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28430
28659
  latestAddrAlreadyHave: receiverTipAddr
28431
28660
  });
28432
28661
  } else {
28433
- if (logalot72) {
28662
+ if (logalot73) {
28434
28663
  console.log(`${lc2} [TEST DEBUG] TJP ${tjpAddr}: DIVERGENCE DETECTED! conflictStrategy=${conflictStrategy}`);
28435
28664
  }
28436
28665
  if (conflictStrategy === "abort") {
@@ -28470,7 +28699,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28470
28699
  }
28471
28700
  const hasTerminalConflicts = conflicts.some((c) => c.terminal);
28472
28701
  if (hasTerminalConflicts) {
28473
- if (logalot72) {
28702
+ if (logalot73) {
28474
28703
  console.warn(`${lc2} ABORTING Sync Saga due to terminal conflicts: ${JSON.stringify(conflicts)}`);
28475
28704
  }
28476
28705
  throw new Error(`the saga has terminal conflicts. conflicts: ${JSON.stringify(conflicts)} (E: f2edbe93cc07a63b38bfc013d2213b26)`);
@@ -28493,7 +28722,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28493
28722
  localSpace: mySpace,
28494
28723
  metaspace
28495
28724
  });
28496
- if (logalot72) {
28725
+ if (logalot73) {
28497
28726
  console.log(`${lc2} ackStone created: ${pretty(ackStone)} (I: 313708132dd53ff946befb7833657826)`);
28498
28727
  }
28499
28728
  const ackFrame = await this.evolveSyncSagaIbGib({
@@ -28536,7 +28765,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28536
28765
  domainAddrs.forEach((x) => searchSecondSpaceAddrs.push(x));
28537
28766
  }
28538
28767
  if (searchSecondSpaceAddrs.length > 0) {
28539
- if (logalot72) {
28768
+ if (logalot73) {
28540
28769
  console.log(`${lc2} couldn't get all addrs in mySpace (${mySpace.ib}). searchSecondSpaceAddrs: ${searchSecondSpaceAddrs} (I: 233fd954dbd84e51bca02fa8eed5f826)`);
28541
28770
  }
28542
28771
  const resGet2 = await getFromSpace({ addrs: searchSecondSpaceAddrs, space: myTempSpace });
@@ -28557,7 +28786,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28557
28786
  console.error(`${lc2} ${extractErrorMsg(error)}`);
28558
28787
  throw error;
28559
28788
  } finally {
28560
- if (logalot72) {
28789
+ if (logalot73) {
28561
28790
  console.log(`${lc2} complete.`);
28562
28791
  }
28563
28792
  }
@@ -28580,7 +28809,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28580
28809
  async handleAckFrame({ sagaContext, sagaIbGib, initDomainGraph, mySpace, myTempSpace, metaspace }) {
28581
28810
  const lc2 = `${this.lc}[${this.handleAckFrame.name}]`;
28582
28811
  try {
28583
- if (logalot72) {
28812
+ if (logalot73) {
28584
28813
  console.log(`${lc2} starting... (I: 605b6860e898267a5b50c6d85704be26)`);
28585
28814
  }
28586
28815
  const { messageData } = await this.getStageAndPayloadFromFrame({ sagaFrame: sagaIbGib, space: mySpace });
@@ -28592,22 +28821,22 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28592
28821
  if (ackData.stage !== SyncStage.ack) {
28593
28822
  throw new Error(`${lc2} Invalid ack frame: ackData.stage !== SyncStage.ack (E: 2e8b0a94b5954a66a6a1a7a0b3f5b7a1)`);
28594
28823
  }
28595
- if (logalot72) {
28824
+ if (logalot73) {
28596
28825
  console.log(`${lc2} ackData: ${pretty(ackData)} (I: b817c5571c5e916fe8f90b892b3e8e26)`);
28597
28826
  }
28598
28827
  if (!sagaIbGib.data) {
28599
28828
  throw new Error(`(UNEXPECTED) sagaIbGib.data falsy? (E: e3f2e8f162484859787651b85c011826)`);
28600
28829
  }
28601
28830
  const conflicts = ackData.conflicts ? clone(ackData.conflicts) : [];
28602
- if (logalot72) {
28831
+ if (logalot73) {
28603
28832
  console.log(`${lc2} [CONFLICT DEBUG] Received conflicts from Ack: ${conflicts.length}`);
28604
28833
  }
28605
- if (logalot72 && conflicts.length > 0) {
28834
+ if (logalot73 && conflicts.length > 0) {
28606
28835
  console.log(`${lc2} [CONFLICT DEBUG] Conflicts detail: ${JSON.stringify(conflicts, null, 2)}`);
28607
28836
  }
28608
28837
  const terminalConflicts = conflicts.filter((c) => c.terminal);
28609
28838
  if (terminalConflicts.length > 0) {
28610
- if (logalot72) {
28839
+ if (logalot73) {
28611
28840
  console.warn(`${lc2} Received terminal conflicts from Ack: ${JSON.stringify(terminalConflicts)}`);
28612
28841
  }
28613
28842
  throw new Error(`${lc2} Peer reported terminal conflicts. (E: 23a0096ee05a2ccfa89334e8f156b426)`);
@@ -28615,7 +28844,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28615
28844
  const outgoingPayloadIbGibsDomain_conflicts = [];
28616
28845
  const activeConflicts = [];
28617
28846
  if (conflicts.length > 0) {
28618
- if (logalot72) {
28847
+ if (logalot73) {
28619
28848
  console.log(`${lc2} [CONFLICT DEBUG] Processing ${conflicts.length} non-terminal conflicts`);
28620
28849
  }
28621
28850
  for (const conflict of conflicts) {
@@ -28678,7 +28907,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28678
28907
  });
28679
28908
  const isFastForward = latestCommonFrameAddr === receiverTipAddr;
28680
28909
  if (isFastForward) {
28681
- if (logalot72) {
28910
+ if (logalot73) {
28682
28911
  console.log(`${lc2} [CONFLICT DEBUG] TJP ${tjpAddr}: Fast-forward detected (receiver behind sender). Excluding from active conflicts and sending delta payload.`);
28683
28912
  }
28684
28913
  } else {
@@ -28694,11 +28923,11 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28694
28923
  } else {
28695
28924
  proposeCommit = true;
28696
28925
  }
28697
- if (logalot72) {
28926
+ if (logalot73) {
28698
28927
  console.log(`${lc2} [CONFLICT DEBUG] Finished processing ${conflicts.length} conflicts. Active (divergent) conflicts: ${activeConflicts.length}. outgoingPayloadIbGibsDomain_conflicts.length (total outgoing payload ibgibs for ALL conflicts): ${outgoingPayloadIbGibsDomain_conflicts.length}`);
28699
28928
  }
28700
28929
  } else {
28701
- if (logalot72) {
28930
+ if (logalot73) {
28702
28931
  console.log(`${lc2} [CONFLICT DEBUG] No optimistic conflicts to process`);
28703
28932
  }
28704
28933
  }
@@ -28749,7 +28978,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28749
28978
  proposeCommit
28750
28979
  };
28751
28980
  let rel8ns = void 0;
28752
- if (logalot72) {
28981
+ if (logalot73) {
28753
28982
  console.log(`${lc2} Creating Delta Stone. Data stage: ${deltaData.stage}`);
28754
28983
  }
28755
28984
  const deltaStone = await this.createSyncMsgStone({
@@ -28764,7 +28993,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28764
28993
  localSpace: mySpace,
28765
28994
  metaspace
28766
28995
  });
28767
- if (logalot72) {
28996
+ if (logalot73) {
28768
28997
  console.log(`${lc2} Delta Frame created. Rel8ns: ${JSON.stringify(deltaFrame.rel8ns)}`);
28769
28998
  }
28770
28999
  return { frame: deltaFrame, payloadIbGibsDomain: outgoingPayloadsDomain_all };
@@ -28772,7 +29001,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28772
29001
  console.error(`${lc2} ${extractErrorMsg(error)}`);
28773
29002
  throw error;
28774
29003
  } finally {
28775
- if (logalot72) {
29004
+ if (logalot73) {
28776
29005
  console.log(`${lc2} complete.`);
28777
29006
  }
28778
29007
  }
@@ -28793,7 +29022,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28793
29022
  async handleDeltaFrame({ sagaContext, sagaIbGib, mySpace, myTempSpace, metaspace }) {
28794
29023
  const lc2 = `${this.lc}[${this.handleDeltaFrame.name}]`;
28795
29024
  try {
28796
- if (logalot72) {
29025
+ if (logalot73) {
28797
29026
  console.log(`${lc2} starting... (I: a1d0a85eb4189466f86dfd61e3df2626)`);
28798
29027
  }
28799
29028
  const { messageData } = await this.getStageAndPayloadFromFrame({ sagaFrame: sagaIbGib, space: mySpace });
@@ -28810,24 +29039,24 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
28810
29039
  if (deltaData.stage !== SyncStage.delta) {
28811
29040
  throw new Error(`${lc2} Invalid delta frame: deltaData.stage !== SyncStage.delta (E: 0c28c8d8f08a4421b8344e6727271421)`);
28812
29041
  }
28813
- if (logalot72) {
29042
+ if (logalot73) {
28814
29043
  console.log(`${lc2} deltaData: ${pretty(deltaData)} (I: a76008681df458cfbcdc4848f825a826)`);
28815
29044
  }
28816
- if (logalot72) {
29045
+ if (logalot73) {
28817
29046
  console.log(`${lc2} [CONFLICT DEBUG] deltaData.payloadAddrsDomain count: ${deltaData.payloadAddrsDomain?.length || 0}`);
28818
29047
  }
28819
29048
  const { conflictStrategy, graftPreference } = sagaIbGib.data;
28820
29049
  const { deltaRequestAddrInfos, payloadAddrsDomain, proposeCommit } = deltaData;
28821
29050
  const peerProposesCommit = deltaData.proposeCommit ?? false;
28822
29051
  const receivedPayloadIbGibs = sagaContext.payloadIbGibsDomain ?? [];
28823
- if (logalot72) {
29052
+ if (logalot73) {
28824
29053
  console.log(`${lc2} [CONFLICT DEBUG] Fulfilling ${(deltaData.deltaRequestAddrInfos || []).length} peer requests`);
28825
29054
  }
28826
29055
  const outgoingPayload = await this.getPayloadsForRequestedInfos({
28827
29056
  deltaRequestAddrInfos: deltaData.deltaRequestAddrInfos || [],
28828
29057
  mySpace
28829
29058
  });
28830
- if (logalot72) {
29059
+ if (logalot73) {
28831
29060
  console.log(`${lc2} [CONFLICT DEBUG] Outgoing payload size (with deps): ${outgoingPayload.length}`);
28832
29061
  }
28833
29062
  const conflicts = deltaData.conflicts ? clone(deltaData.conflicts) : [];
@@ -29028,7 +29257,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29028
29257
  metaspace
29029
29258
  });
29030
29259
  if (deltaData.proposeCommit) {
29031
- if (logalot72) {
29260
+ if (logalot73) {
29032
29261
  console.log(`${lc2} Peer proposed commit. Accepting & Committing.`);
29033
29262
  }
29034
29263
  const commitData = {
@@ -29057,7 +29286,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29057
29286
  console.error(`${lc2} ${extractErrorMsg(error)}`);
29058
29287
  throw error;
29059
29288
  } finally {
29060
- if (logalot72) {
29289
+ if (logalot73) {
29061
29290
  console.log(`${lc2} complete.`);
29062
29291
  }
29063
29292
  }
@@ -29068,7 +29297,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29068
29297
  async executeLocalCommit({ deltaFrame, commitFrame, sagaHistory, metaspace, localSpace, localTempSpace }) {
29069
29298
  const lc2 = `${this.lc}[${this.executeLocalCommit.name}]`;
29070
29299
  try {
29071
- if (logalot72) {
29300
+ if (logalot73) {
29072
29301
  console.log(`${lc2} starting... (I: 6734980446b86a63c1af6e2e206de826)`);
29073
29302
  }
29074
29303
  if (!deltaFrame && !commitFrame) {
@@ -29082,7 +29311,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29082
29311
  throw new Error(`(UNEXPECTED) !currentFrame? something wrong with my logic. (E: 4ec0ce6625cc1d677bc902c839ca1a26)`);
29083
29312
  }
29084
29313
  const currentFrameOrigin = getSyncSagaFrameOrigin({ sagaFrame: currentFrame });
29085
- if (logalot72) {
29314
+ if (logalot73) {
29086
29315
  console.log(`${lc2} currentFrameOrigin: ${currentFrameOrigin} (I: 3add8f8390c89743ae554bd3cc60b826)`);
29087
29316
  }
29088
29317
  if (!currentFrame.data) {
@@ -29125,7 +29354,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29125
29354
  }
29126
29355
  });
29127
29356
  });
29128
- if (logalot72) {
29357
+ if (logalot73) {
29129
29358
  console.log(`${lc2}[${currentFrameOrigin}] allPayloadAddrsDomainTransferred: ${allPayloadAddrsDomainReceived.length > 0 ? allPayloadAddrsDomainReceived.join(", ") : "none"} (I: a1950eb3ca95bdc9ec18a4b8823e9826)`);
29130
29359
  }
29131
29360
  let allPayloadIbGibsDomainTransferred = [];
@@ -29164,7 +29393,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29164
29393
  throw new Error(`(UNEXPECTED) finalConflict.createdDnaAddrs falsy/empty? (E: 9689f8be5bd19650b8d4a058b65db826)`);
29165
29394
  }
29166
29395
  if (!replayedDnaAddrs || replayedDnaAddrs.length === 0) {
29167
- if (logalot72) {
29396
+ if (logalot73) {
29168
29397
  console.log(`${lc2} finalConflict.replayedDnaAddrs falsy/empty (I: e88eb8a76b5815e07f10cbb2fa2ab826)`);
29169
29398
  }
29170
29399
  }
@@ -29182,21 +29411,21 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29182
29411
  allPayloadIbGibsDomainTransferred.forEach((x) => allTransferredOrCreatedFromGraftIbGibs.push(x));
29183
29412
  createdFromConflictGraftsIbGibs.forEach((x) => allTransferredOrCreatedFromGraftIbGibs.push(x));
29184
29413
  if (allTransferredOrCreatedFromGraftIbGibs.length === 0) {
29185
- if (logalot72) {
29414
+ if (logalot73) {
29186
29415
  console.log(`${lc2}[${currentFrameOrigin}] no changes on this end (I: fa30d18e83a87ee9e8487fbb5d632b26)`);
29187
29416
  }
29188
29417
  } else {
29189
- if (logalot72) {
29418
+ if (logalot73) {
29190
29419
  console.log(`${lc2}[${currentFrameOrigin}] ${allTransferredOrCreatedFromGraftIbGibs.length} changes detected (I: fa30d18e83a87ee9e8487fbb5d632b26)`);
29191
29420
  }
29192
- if (logalot72) {
29421
+ if (logalot73) {
29193
29422
  console.log(`${lc2} put all into localSpace (${localSpace.ib}) starting... (I: d5e0d9870e380b61e80c729660058826)`);
29194
29423
  }
29195
29424
  const { payload_Dnas, payload_NonDnas } = await putInSpace_dnasThenNonDnas({
29196
29425
  ibGibs: allTransferredOrCreatedFromGraftIbGibs,
29197
29426
  space: localSpace
29198
29427
  });
29199
- if (logalot72) {
29428
+ if (logalot73) {
29200
29429
  console.log(`${lc2} put all into localSpace (${localSpace.ib}) complete. (I: d5e0d9870e380b61e80c729660058826)`);
29201
29430
  }
29202
29431
  const orphanedAddresses = await getAllOrphanedAddresses({
@@ -29207,12 +29436,12 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29207
29436
  myTempSpace: localTempSpace
29208
29437
  });
29209
29438
  const { mapWithTjp_NoDna, mapWithTjp_YesDna, mapWithoutTjps } = splitPerTjpAndOrDna({ ibGibs: payload_NonDnas, filterPrimitives: true });
29210
- if (logalot72) {
29439
+ if (logalot73) {
29211
29440
  console.log(`${lc2} register mapWithoutTjps starting... (I: 2b84d8f8dda85adde88696d8419bf726)`);
29212
29441
  }
29213
29442
  const nonTjpIbGibs = Object.values(mapWithoutTjps);
29214
29443
  for (const nontjp of nonTjpIbGibs) {
29215
- if (logalot72) {
29444
+ if (logalot73) {
29216
29445
  console.log(`${lc2} registering ${getIbGibAddr({ ibGib: nontjp })} (I: 4647b4f42d27cffe0fbfce8846755826)`);
29217
29446
  }
29218
29447
  await metaspace.registerNewIbGib({
@@ -29220,10 +29449,10 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29220
29449
  space: localSpace
29221
29450
  });
29222
29451
  }
29223
- if (logalot72) {
29452
+ if (logalot73) {
29224
29453
  console.log(`${lc2} mapWithoutTjps complete. (I: 2b84d8f8dda85adde88696d8419bf726)`);
29225
29454
  }
29226
- if (logalot72) {
29455
+ if (logalot73) {
29227
29456
  console.log(`${lc2} register mapWithTjp_NoDna starting... (I: 96e648e4db382499b8bfaa1b37c24826)`);
29228
29457
  }
29229
29458
  const timelinesByTjpAddr_NoDna = getTimelinesGroupedByTjp({ ibGibs: Object.values(mapWithTjp_NoDna) });
@@ -29237,10 +29466,10 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29237
29466
  });
29238
29467
  }
29239
29468
  }
29240
- if (logalot72) {
29469
+ if (logalot73) {
29241
29470
  console.log(`${lc2} register mapWithTjp_NoDna complete. (I: 96e648e4db382499b8bfaa1b37c24826)`);
29242
29471
  }
29243
- if (logalot72) {
29472
+ if (logalot73) {
29244
29473
  console.log(`${lc2} register mapWithTjp_YesDna starting... (I: d54a820e9442dee4681f6228a6795926)`);
29245
29474
  }
29246
29475
  const timelinesByTjpAddr_YesDna = getTimelinesGroupedByTjp({ ibGibs: Object.values(mapWithTjp_YesDna) });
@@ -29256,7 +29485,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29256
29485
  }
29257
29486
  }
29258
29487
  }
29259
- if (logalot72) {
29488
+ if (logalot73) {
29260
29489
  console.log(`${lc2} register mapWithTjp_YesDna complete. (I: d54a820e9442dee4681f6228a6795926)`);
29261
29490
  }
29262
29491
  }
@@ -29264,7 +29493,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29264
29493
  console.error(`${lc2} ${extractErrorMsg(error)}`);
29265
29494
  throw error;
29266
29495
  } finally {
29267
- if (logalot72) {
29496
+ if (logalot73) {
29268
29497
  console.log(`${lc2} complete.`);
29269
29498
  }
29270
29499
  }
@@ -29272,7 +29501,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29272
29501
  async createCommitFrame({ sagaIbGib, errors, metaspace, mySpace }) {
29273
29502
  const lc2 = `[${this.createCommitFrame.name}]`;
29274
29503
  try {
29275
- if (logalot72) {
29504
+ if (logalot73) {
29276
29505
  console.log(`${lc2} starting... (I: 48fc57c023f80122135a284855757526)`);
29277
29506
  }
29278
29507
  const commitData = errors && errors.length > 0 ? {
@@ -29303,7 +29532,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29303
29532
  console.error(`${lc2} ${extractErrorMsg(error)}`);
29304
29533
  throw error;
29305
29534
  } finally {
29306
- if (logalot72) {
29535
+ if (logalot73) {
29307
29536
  console.log(`${lc2} complete.`);
29308
29537
  }
29309
29538
  }
@@ -29311,7 +29540,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29311
29540
  async handleCommitFrame({ sagaIbGib, mySpace, myTempSpace, metaspace }) {
29312
29541
  const lc2 = `${this.lc}[${this.handleCommitFrame.name}]`;
29313
29542
  try {
29314
- if (logalot72) {
29543
+ if (logalot73) {
29315
29544
  console.log(`${lc2} starting... (I: e179573bdd881202f8ba3168da1c3826)`);
29316
29545
  }
29317
29546
  if (!sagaIbGib.data) {
@@ -29344,7 +29573,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29344
29573
  metaspace
29345
29574
  });
29346
29575
  console.error(`${lc2} NAG ERROR (NOT THROWN): implement cleanup logic, including add a cleanup method to the peer (E: 3a9a24befb98a981a88fbdbf52920e26)`);
29347
- if (logalot72) {
29576
+ if (logalot73) {
29348
29577
  console.log(`${lc2} Peer committed. Finalizing saga locally. Saga Complete.`);
29349
29578
  }
29350
29579
  return { sagaComplete: true };
@@ -29360,7 +29589,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29360
29589
  });
29361
29590
  return { frame: errorCommitFrame };
29362
29591
  } finally {
29363
- if (logalot72) {
29592
+ if (logalot73) {
29364
29593
  console.log(`${lc2} complete.`);
29365
29594
  }
29366
29595
  }
@@ -29369,7 +29598,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29369
29598
  async createSyncMsgStone({ data, rel8ns, localSpace, metaspace }) {
29370
29599
  const lc2 = `${this.lc}[${this.createSyncMsgStone.name}]`;
29371
29600
  try {
29372
- if (logalot72) {
29601
+ if (logalot73) {
29373
29602
  console.log(`${lc2} starting... (I: 5f7f98e8ff980364f7191fcee4531e26)`);
29374
29603
  }
29375
29604
  const ib = await getSyncSagaMessageIb({ data });
@@ -29381,7 +29610,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29381
29610
  uuid: true
29382
29611
  // we want the stone to have its own uniqueness
29383
29612
  });
29384
- if (logalot72) {
29613
+ if (logalot73) {
29385
29614
  console.log(`${lc2} Created stone: ${getIbGibAddr({ ibGib: stone })}`);
29386
29615
  }
29387
29616
  await metaspace.put({ ibGib: stone, space: localSpace });
@@ -29391,7 +29620,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29391
29620
  console.error(`${lc2} ${extractErrorMsg(error)}`);
29392
29621
  throw error;
29393
29622
  } finally {
29394
- if (logalot72) {
29623
+ if (logalot73) {
29395
29624
  console.log(`${lc2} complete.`);
29396
29625
  }
29397
29626
  }
@@ -29399,7 +29628,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29399
29628
  async getPayloadsForRequestedInfos({ deltaRequestAddrInfos, mySpace }) {
29400
29629
  const lc2 = `${this.lc}[${this.getPayloadsForRequestedInfos.name}]`;
29401
29630
  try {
29402
- if (logalot72) {
29631
+ if (logalot73) {
29403
29632
  console.log(`${lc2} starting... (I: 4fe13d0d80050f20a8b74ba80cee5826)`);
29404
29633
  }
29405
29634
  const outgoingPayloadIbGibsDomainGraph = {};
@@ -29434,7 +29663,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29434
29663
  console.error(`${lc2} ${extractErrorMsg(error)}`);
29435
29664
  throw error;
29436
29665
  } finally {
29437
- if (logalot72) {
29666
+ if (logalot73) {
29438
29667
  console.log(`${lc2} complete.`);
29439
29668
  }
29440
29669
  }
@@ -29537,7 +29766,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29537
29766
  async getStageAndPayloadFromFrame({ sagaFrame, space }) {
29538
29767
  const lc2 = `${this.lc}[${this.getStageAndPayloadFromFrame.name}]`;
29539
29768
  try {
29540
- if (logalot72) {
29769
+ if (logalot73) {
29541
29770
  console.log(`${lc2} starting... (I: fddc287bd4d55253dc50e519fd352226)`);
29542
29771
  }
29543
29772
  if (!sagaFrame.rel8ns) {
@@ -29566,7 +29795,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29566
29795
  console.error(`${lc2} ${extractErrorMsg(error)}`);
29567
29796
  throw error;
29568
29797
  } finally {
29569
- if (logalot72) {
29798
+ if (logalot73) {
29570
29799
  console.log(`${lc2} complete.`);
29571
29800
  }
29572
29801
  }
@@ -29626,7 +29855,7 @@ var SyncSagaCoordinator = class _SyncSagaCoordinator {
29626
29855
  };
29627
29856
 
29628
29857
  // ../../libs/node-gib/dist/serve-gib/handlers/ws/sync-upgrade-handler-base.mjs
29629
- var logalot73 = GLOBAL_LOG_A_LOT;
29858
+ var logalot74 = GLOBAL_LOG_A_LOT;
29630
29859
  var SyncUpgradeHandlerBase = class _SyncUpgradeHandlerBase extends ServeGibHandlerWithMetaspaceBase {
29631
29860
  lc = `[${_SyncUpgradeHandlerBase.name}]`;
29632
29861
  method = "GET";
@@ -29637,7 +29866,7 @@ var SyncUpgradeHandlerBase = class _SyncUpgradeHandlerBase extends ServeGibHandl
29637
29866
  async handleUpgrade(reqCtx, socket, head) {
29638
29867
  const lc_fn = `${this.lc}[handleUpgrade]`;
29639
29868
  try {
29640
- if (logalot73) {
29869
+ if (logalot74) {
29641
29870
  console.log(`${lc_fn} starting...`);
29642
29871
  }
29643
29872
  if (!this.canHandleRoute(reqCtx)) {
@@ -29675,7 +29904,7 @@ var SyncUpgradeHandlerBase = class _SyncUpgradeHandlerBase extends ServeGibHandl
29675
29904
  // Resolved dynamically inside runtime turns
29676
29905
  });
29677
29906
  socket.on("error", (err) => {
29678
- if (logalot73) {
29907
+ if (logalot74) {
29679
29908
  console.warn(`[SyncUpgradeHandlerBase] Socket error: ${extractErrorMsg(err)}`);
29680
29909
  }
29681
29910
  try {
@@ -29689,7 +29918,7 @@ var SyncUpgradeHandlerBase = class _SyncUpgradeHandlerBase extends ServeGibHandl
29689
29918
  try {
29690
29919
  socket.write(encodeTextFrame(data));
29691
29920
  } catch (e) {
29692
- if (logalot73) {
29921
+ if (logalot74) {
29693
29922
  console.warn(`[SyncUpgradeHandlerBase] failed to write message frame: ${extractErrorMsg(e)}`);
29694
29923
  }
29695
29924
  }
@@ -29706,7 +29935,7 @@ var SyncUpgradeHandlerBase = class _SyncUpgradeHandlerBase extends ServeGibHandl
29706
29935
  frameText = decoder.nextFrame();
29707
29936
  }
29708
29937
  } catch (error) {
29709
- if (logalot73) {
29938
+ if (logalot74) {
29710
29939
  console.warn(`[SyncUpgradeHandlerBase] closing connection due to decoder error: ${extractErrorMsg(error)}`);
29711
29940
  }
29712
29941
  if (socket.writable) {
@@ -29843,8 +30072,8 @@ function getStandardServeGibHandlers(opts = {}) {
29843
30072
  // src/server/server.mts
29844
30073
  var __dirname = dirname(fileURLToPath(import.meta.url));
29845
30074
  var PORT = parseInt(process.env.PORT ?? "3000", 10);
29846
- var DATA_DIR = process.env.DATA_DIR ?? join10(__dirname, "../../.data/ibgib-space");
29847
- var CLIENT_DIR = join10(__dirname, "../client");
30075
+ var DATA_DIR = process.env.DATA_DIR ?? join11(__dirname, "../../.data/ibgib-space");
30076
+ var CLIENT_DIR = join11(__dirname, "../client");
29848
30077
  async function main() {
29849
30078
  const lc2 = "[space-gib server]";
29850
30079
  try {