@ibgib/core-gib 0.1.45 → 0.1.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/dist/common/other/ibgib-helper.d.mts +12 -0
  2. package/dist/common/other/ibgib-helper.d.mts.map +1 -1
  3. package/dist/common/other/ibgib-helper.mjs +39 -0
  4. package/dist/common/other/ibgib-helper.mjs.map +1 -1
  5. package/dist/keystone/kdf/kdf-helpers.mjs +2 -2
  6. package/dist/keystone/kdf/kdf-helpers.mjs.map +1 -1
  7. package/dist/keystone/keystone-config-builder.d.mts +2 -1
  8. package/dist/keystone/keystone-config-builder.d.mts.map +1 -1
  9. package/dist/keystone/keystone-config-builder.mjs +8 -2
  10. package/dist/keystone/keystone-config-builder.mjs.map +1 -1
  11. package/dist/keystone/keystone-constants.d.mts +33 -3
  12. package/dist/keystone/keystone-constants.d.mts.map +1 -1
  13. package/dist/keystone/keystone-constants.mjs +31 -1
  14. package/dist/keystone/keystone-constants.mjs.map +1 -1
  15. package/dist/keystone/keystone-helpers.d.mts +16 -1
  16. package/dist/keystone/keystone-helpers.d.mts.map +1 -1
  17. package/dist/keystone/keystone-helpers.mjs +227 -8
  18. package/dist/keystone/keystone-helpers.mjs.map +1 -1
  19. package/dist/keystone/keystone-service-v1.d.mts +4 -1
  20. package/dist/keystone/keystone-service-v1.d.mts.map +1 -1
  21. package/dist/keystone/keystone-service-v1.mjs +6 -1
  22. package/dist/keystone/keystone-service-v1.mjs.map +1 -1
  23. package/dist/keystone/keystone-service-v1.respec.mjs +26 -26
  24. package/dist/keystone/keystone-service-v1.respec.mjs.map +1 -1
  25. package/dist/keystone/keystone-types.d.mts +26 -5
  26. package/dist/keystone/keystone-types.d.mts.map +1 -1
  27. package/dist/keystone/keystone-types.mjs.map +1 -1
  28. package/dist/sync/sync-conflict-adv-multitimelines.respec.mjs +1 -1
  29. package/dist/sync/sync-conflict-adv-multitimelines.respec.mjs.map +1 -1
  30. package/dist/sync/sync-conflict-basic-divergence.respec.mjs +1 -1
  31. package/dist/sync/sync-conflict-basic-divergence.respec.mjs.map +1 -1
  32. package/dist/sync/sync-conflict-basic-multitimelines.respec.mjs +1 -1
  33. package/dist/sync/sync-conflict-basic-multitimelines.respec.mjs.map +1 -1
  34. package/dist/sync/sync-conflict-text-merge.respec.mjs +1 -1
  35. package/dist/sync/sync-conflict-text-merge.respec.mjs.map +1 -1
  36. package/dist/sync/sync-constants.d.mts +47 -1
  37. package/dist/sync/sync-constants.d.mts.map +1 -1
  38. package/dist/sync/sync-constants.mjs +49 -1
  39. package/dist/sync/sync-constants.mjs.map +1 -1
  40. package/dist/sync/sync-innerspace-constants.respec.mjs +1 -1
  41. package/dist/sync/sync-innerspace-constants.respec.mjs.map +1 -1
  42. package/dist/sync/sync-innerspace-deep-updates.respec.mjs +1 -1
  43. package/dist/sync/sync-innerspace-deep-updates.respec.mjs.map +1 -1
  44. package/dist/sync/sync-innerspace-dest-ahead-withid.respec.mjs +33 -19
  45. package/dist/sync/sync-innerspace-dest-ahead-withid.respec.mjs.map +1 -1
  46. package/dist/sync/sync-innerspace-dest-ahead.respec.mjs +1 -1
  47. package/dist/sync/sync-innerspace-dest-ahead.respec.mjs.map +1 -1
  48. package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs +1 -1
  49. package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs.map +1 -1
  50. package/dist/sync/sync-innerspace-partial-update.respec.mjs +1 -1
  51. package/dist/sync/sync-innerspace-partial-update.respec.mjs.map +1 -1
  52. package/dist/sync/sync-innerspace.respec.mjs +1 -1
  53. package/dist/sync/sync-innerspace.respec.mjs.map +1 -1
  54. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts.map +1 -1
  55. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs +5 -0
  56. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs.map +1 -1
  57. package/dist/sync/sync-peer/sync-peer-v1.d.mts +6 -1
  58. package/dist/sync/sync-peer/sync-peer-v1.d.mts.map +1 -1
  59. package/dist/sync/sync-peer/sync-peer-v1.mjs +56 -14
  60. package/dist/sync/sync-peer/sync-peer-v1.mjs.map +1 -1
  61. package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts +7 -3
  62. package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts.map +1 -1
  63. package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs +32 -3
  64. package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs.map +1 -1
  65. package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts +16 -0
  66. package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts.map +1 -1
  67. package/dist/sync/sync-saga-coordinator.d.mts +18 -3
  68. package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
  69. package/dist/sync/sync-saga-coordinator.mjs +243 -56
  70. package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
  71. package/dist/sync/sync-types.d.mts +1 -1
  72. package/dist/sync/sync-types.d.mts.map +1 -1
  73. package/package.json +1 -1
  74. package/src/common/other/ibgib-helper.mts +39 -0
  75. package/src/keystone/kdf/kdf-helpers.mts +2 -2
  76. package/src/keystone/keystone-config-builder.mts +13 -2
  77. package/src/keystone/keystone-constants.mts +33 -2
  78. package/src/keystone/keystone-helpers.mts +237 -8
  79. package/src/keystone/keystone-service-v1.mts +5 -0
  80. package/src/keystone/keystone-service-v1.respec.mts +25 -25
  81. package/src/keystone/keystone-types.mts +31 -8
  82. package/src/sync/sync-conflict-adv-multitimelines.respec.mts +1 -1
  83. package/src/sync/sync-conflict-basic-divergence.respec.mts +1 -1
  84. package/src/sync/sync-conflict-basic-multitimelines.respec.mts +1 -1
  85. package/src/sync/sync-conflict-text-merge.respec.mts +1 -1
  86. package/src/sync/sync-constants.mts +51 -1
  87. package/src/sync/sync-innerspace-constants.respec.mts +1 -1
  88. package/src/sync/sync-innerspace-deep-updates.respec.mts +1 -1
  89. package/src/sync/sync-innerspace-dest-ahead-withid.respec.mts +36 -19
  90. package/src/sync/sync-innerspace-dest-ahead.respec.mts +1 -1
  91. package/src/sync/sync-innerspace-multiple-timelines.respec.mts +1 -1
  92. package/src/sync/sync-innerspace-partial-update.respec.mts +1 -1
  93. package/src/sync/sync-innerspace.respec.mts +1 -1
  94. package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mts +5 -0
  95. package/src/sync/sync-peer/sync-peer-v1.mts +63 -15
  96. package/src/sync/sync-saga-context/sync-saga-context-helpers.mts +52 -4
  97. package/src/sync/sync-saga-context/sync-saga-context-types.mts +17 -0
  98. package/src/sync/sync-saga-coordinator.mts +298 -63
  99. package/src/sync/sync-types.mts +1 -1
@@ -1,4 +1,4 @@
1
- import { extractErrorMsg, hash, pretty } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
1
+ import { extractErrorMsg, hash, HashAlgorithm, pretty } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
2
2
  import { GIB } from "@ibgib/ts-gib/dist/V1/constants.mjs";
3
3
  import { Ib, TransformResult } from "@ibgib/ts-gib/dist/types.mjs";
4
4
  import { getIbAndGib, getIbGibAddr } from "@ibgib/ts-gib/dist/helper.mjs";
@@ -8,18 +8,23 @@ import { Factory_V1 } from "@ibgib/ts-gib/dist/V1/factory.mjs";
8
8
  import { getGib } from "@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs";
9
9
 
10
10
  import { GLOBAL_LOG_A_LOT } from "../core-constants.mjs";
11
- import { KEYSTONE_ATOM } from "./keystone-constants.mjs";
11
+ import { KEYSTONE_ATOM, KEYSTONE_HASH_MAX_ROUNDS, KEYSTONE_POOL_ID_REGEXP, KEYSTONE_SALT_REGEXP } from "./keystone-constants.mjs";
12
12
  import {
13
13
  KeystoneData_V1, KeystoneIbGib_V1, KeystoneIb_V1, KeystoneChallengePool,
14
14
  DeterministicResult, KeystoneProof, KeystonePoolConfig,
15
15
  KeystoneReplenishStrategy, KEYSTONE_REPLENISH_STRATEGY_VALID_VALUES,
16
16
  KeystoneClaim, KeystoneSolution,
17
+ KeystoneChallengeType,
18
+ KEYSTONE_CHALLENGE_TYPE_VALID_VALUES,
19
+ KeystonePoolConfig_HashV1,
17
20
  } from "./keystone-types.mjs";
18
21
  import { MetaspaceService } from "../witness/space/metaspace/metaspace-types.mjs";
19
22
  import { IbGibSpaceAny } from "../witness/space/space-base-v1.mjs";
20
23
  import { KeystoneStrategyFactory } from "./strategy/keystone-strategy-factory.mjs";
21
24
  import { getDependencyGraph } from "../common/other/graph-helper.mjs";
22
- import { getTimelinesGroupedByTjp, splitPerTjpAndOrDna } from "../common/other/ibgib-helper.mjs";
25
+ import { getIbGibsFromCache_fallbackToSpaces, getTimelinesGroupedByTjp, splitPerTjpAndOrDna } from "../common/other/ibgib-helper.mjs";
26
+ import { IbGib_V1, IbGibData_V1, IbGibRel8ns_V1 } from "@ibgib/ts-gib/dist/V1/types.mjs";
27
+ import { getLatestAddrs } from "../witness/space/space-helper.mjs";
23
28
 
24
29
  const logalot = GLOBAL_LOG_A_LOT;
25
30
 
@@ -184,12 +189,14 @@ export function addToBindingMap(
184
189
  const firstChar = challengeId.charAt(0).toLowerCase();
185
190
  // Validate it is hex
186
191
  if (/[0-9a-f]/.test(firstChar)) {
187
- if (!map[firstChar]) map[firstChar] = [];
192
+ if (!map[firstChar]) { map[firstChar] = []; }
188
193
  map[firstChar].push(challengeId);
189
194
 
190
195
  // OPTIONAL: Implement Full Coverage Strategy here?
191
196
  // e.g. map[challengeId[1]].push(challengeId) ...
192
197
  // For V1, we stick to Native/Implicit bucket (Index 0).
198
+ } else {
199
+ throw new Error(`invalid challengeId (${challengeId}). Must start with a hex character. (E: c96ed8460de89e28c801370a0f07f826)`);
193
200
  }
194
201
  }
195
202
 
@@ -519,6 +526,156 @@ export async function solveAndReplenish({
519
526
  }
520
527
  }
521
528
 
529
+ export async function validateChallengePool_typeHashRevealV1({ pool }: {
530
+ pool: KeystoneChallengePool;
531
+ }): Promise<string[]> {
532
+ const lc = `[${validateChallengePool_typeHashRevealV1.name}]`;
533
+ try {
534
+ if (logalot) { console.log(`${lc} starting... (I: e2ffd568b698cc12d8c5e838d73ae726)`); }
535
+
536
+ if (!pool.config) { throw new Error(`(UNEXPECTED) pool.configy falsy? (E: fcde88fe20e8004a58d7e445436bf526)`); }
537
+ if (pool.config.type !== KeystoneChallengeType.hash_reveal_v1) {
538
+ throw new Error(`(UNEXPECTED) pool.config.type !== KeystoneChallengeType.hash_reveal_v1? (E: e205f8872909c37168a624a9df778c26)`);
539
+ }
540
+
541
+ const errors: string[] = [];
542
+
543
+ const { algo, rounds, salt, } = pool.config as KeystonePoolConfig_HashV1;
544
+
545
+ const validAlgos: HashAlgorithm[] = [HashAlgorithm.sha_256];
546
+ if (algo) {
547
+ if (!validAlgos.includes(algo)) {
548
+ errors.push(`${lc} invalid hash algorithm (${algo}). Must be one of ${validAlgos}. (E: a22399ca3a68e63ffcc7507699be5826)`);
549
+ }
550
+ } else {
551
+ errors.push(`${lc} algorithm required. (E: 8cd6bfb0590862b9bae24d98d2cf3826)`)
552
+ }
553
+
554
+ if (rounds && typeof rounds === 'number' && Number.isInteger(rounds)) {
555
+ if (rounds > KEYSTONE_HASH_MAX_ROUNDS) {
556
+ errors.push(`${lc} rounds too high. max rounds: ${KEYSTONE_HASH_MAX_ROUNDS} (E: 31ce082f7fd88d6b58ef08a816458826)`);
557
+ }
558
+ } else {
559
+ errors.push(`${lc} invalid rounds (${rounds}). must be positive integer. (E: 73c643ccda78afaf28d52a6871a9e826)`);
560
+ }
561
+
562
+ if (salt && typeof salt === 'string') {
563
+ // no limits on this? sanity check?
564
+ if (!KEYSTONE_SALT_REGEXP.test(salt)) {
565
+ errors.push(`${lc} invalid salt (${salt.substring(0, 99)}). Must match regexp ${KEYSTONE_SALT_REGEXP}`);
566
+ }
567
+ } else {
568
+ errors.push(`${lc} invalid salt (${salt}). must be truthy string value. (E: 564a4844ec88fc1988197ce89c381426)`);
569
+ }
570
+
571
+ return errors;
572
+
573
+ } catch (error) {
574
+ console.error(`${lc} ${extractErrorMsg(error)}`);
575
+ throw error;
576
+ } finally {
577
+ if (logalot) { console.log(`${lc} complete.`); }
578
+ }
579
+ }
580
+
581
+ export async function validateChallengePool({ pool }: {
582
+ pool: KeystoneChallengePool;
583
+ }): Promise<string[]> {
584
+ const lc = `[${validateChallengePool.name}]`;
585
+ try {
586
+ if (logalot) { console.log(`${lc} starting... (I: 1a0eafc158a83d1ba8fc019d5c979a26)`); }
587
+ const errors: string[] = [];
588
+
589
+ if (pool.config) {
590
+ // first validate common to all pools, regardless of type...
591
+ if (pool.config.id) {
592
+ if (!KEYSTONE_POOL_ID_REGEXP.test(pool.config.id)) {
593
+ // not 100% that this is needed but hey
594
+ errors.push(`${lc} pool.config.id is not formatted correctly. must pass regexp: ${KEYSTONE_POOL_ID_REGEXP.source}`);
595
+ }
596
+ } else {
597
+ errors.push(`${lc} pool.config.id falsy (E: 31d7943d95f877326d5f4ea14463d626)`);
598
+ }
599
+
600
+ if (pool.config.behavior) {
601
+ const { size } = pool.config.behavior;
602
+ if (!size || size === 0) {
603
+ errors.push(`${lc} invalid pool.config.behavior.size (${size}). Must be positive integer. (E: b221e36ec102bdc944552248ce8fe626)`)
604
+ }
605
+ // todo: more behavior checks
606
+ } else {
607
+ errors.push(`${lc} pool.config.behavior falsy (E: bede081c066c39732eefe2f92e296326)`)
608
+ }
609
+
610
+ // ...then do type-specific validation
611
+ const poolType = pool.config.type;
612
+ switch (poolType) {
613
+ case KeystoneChallengeType.hash_reveal_v1:
614
+ const errorsHashRevealV1 = await validateChallengePool_typeHashRevealV1({ pool });
615
+ errorsHashRevealV1.forEach(x => errors.push(x));
616
+ break;
617
+ default:
618
+ throw new Error(`(UNEXPECTED) unknown pool.config.type (${poolType})? We only implement the following at this time: ${KEYSTONE_CHALLENGE_TYPE_VALID_VALUES} (E: cce5285cf7580b8bc82172488eba2826)`);
619
+ }
620
+ } else {
621
+ errors.push(`${lc} pool.config falsy. (E: 8d05c875a1d2c58018a5eaf803977d26)`);
622
+ }
623
+
624
+ return errors;
625
+ } catch (error) {
626
+ console.error(`${lc} ${extractErrorMsg(error)}`);
627
+ throw error;
628
+ } finally {
629
+ if (logalot) { console.log(`${lc} complete.`); }
630
+ }
631
+ }
632
+
633
+
634
+ export async function validateGenesisKeystone({
635
+ keystoneIbGib
636
+ }: {
637
+ keystoneIbGib: KeystoneIbGib_V1;
638
+ }): Promise<string[]> {
639
+ const lc = `[${validateGenesisKeystone.name}]`;
640
+ try {
641
+ if (logalot) { console.log(`${lc} starting... (I: ec6ba82ec848b5ac3d8953e89d8d9826)`); }
642
+
643
+ const errors: string[] = [];
644
+
645
+ const { data, rel8ns } = keystoneIbGib;
646
+
647
+ // no proofs/solutions yet
648
+ if (data.proofs && data.proofs.length > 0) {
649
+ errors.push(`${lc} proofs already exist on genesis keystone. (E: 7a5e15f20918f1bbd8ffb62857dcd526)`);
650
+ }
651
+
652
+ for (const pool of data.challengePools) {
653
+ // validate each pool intrinsically (config, sanity)
654
+ const poolErrors = await validateChallengePool({ pool });
655
+ poolErrors.forEach(x => errors.push(x));
656
+
657
+ // additionally ensure each pool has challenges. This is only on
658
+ // this genesis keystone, as it is valid to have pool without
659
+ // challenges after revocation
660
+ if (!pool.challenges || Object.keys(pool.challenges).length === 0) {
661
+ errors.push(`${lc} invalid pool (${pool.id}). pool.challenges is falsy/empty. (E: 8cd16a5416ae62a058342828be465b26)`);
662
+ }
663
+ }
664
+
665
+ // not stated as revoked already
666
+ if (!!data.revocationInfo) {
667
+ errors.push(`${lc} genesis keystone already has revocationInfo. (E: e11408d0c558d0fa948efbce611ec826)`);
668
+ }
669
+
670
+ return errors;
671
+ } catch (error) {
672
+ console.error(`${lc} ${extractErrorMsg(error)}`);
673
+ throw error;
674
+ } finally {
675
+ if (logalot) { console.log(`${lc} complete.`); }
676
+ }
677
+ }
678
+
522
679
  /**
523
680
  * Validates the transition from Prev -> Curr.
524
681
  * Enforces Cryptography AND Behavioral Policy.
@@ -793,9 +950,17 @@ export async function createKeystoneIbGibImpl({
793
950
 
794
951
  export async function validateKeystoneGraph({
795
952
  keystoneIbGib,
953
+ getLatest,
954
+ invalidIfMoreRecentKeystoneFoundInSpace,
796
955
  space,
797
956
  }: {
798
957
  keystoneIbGib: KeystoneIbGib_V1,
958
+ /**
959
+ * if true, then this will get the latest keystone known in the incoming
960
+ * {@link keystoneIbGib} timeline, as found in {@link space}.
961
+ */
962
+ getLatest: boolean,
963
+ invalidIfMoreRecentKeystoneFoundInSpace: boolean,
799
964
  space: IbGibSpaceAny,
800
965
  }): Promise<string[]> {
801
966
  const lc = `[${validateKeystoneGraph.name}]`;
@@ -807,6 +972,44 @@ export async function validateKeystoneGraph({
807
972
 
808
973
  const errors: string[] = [];
809
974
 
975
+ // first, get the latest if that is the case...
976
+ if (getLatest) {
977
+ const keystoneAddr = getIbGibAddr({ ibGib: keystoneIbGib });
978
+ const resGetLatestAddrs = await getLatestAddrs({
979
+ ibGibs: [keystoneIbGib],
980
+ space,
981
+ });
982
+ if (!resGetLatestAddrs.data) { throw new Error(`(UNEXPECTED) resGetLatestAddrs.data falsy? (E: 3a23b3b420a8da1928219ca8d47b2126)`); }
983
+ if (!resGetLatestAddrs.data.latestAddrsMap) { throw new Error(`(UNEXPECTED) resGetLatestAddrs.data.latestAddrsMap falsy? (E: 93f1180598fb65a4b8d36e08d6c50426)`); }
984
+
985
+ const { latestAddrsMap } = resGetLatestAddrs.data;
986
+ if (Object.keys(latestAddrsMap).length === 0) {
987
+ throw new Error(`(UNEXPECTED) latestAddrsMap truthy but empty? (E: 7142f8f7625b9186281d08251e407826)`);
988
+ }
989
+
990
+ const latestAddr = latestAddrsMap[keystoneAddr];
991
+ if (latestAddr) {
992
+ if (latestAddr !== keystoneAddr) {
993
+ if (invalidIfMoreRecentKeystoneFoundInSpace) {
994
+ errors.push(`${lc} more recent keystone (${latestAddr}) found than the one passed in (${keystoneAddr}) in space (${space.ib}). (E: 64bf48de9448ee5c7528bf03bed2a826)`);
995
+ } else {
996
+ // get the latest ibgib and point the incoming ref to that
997
+ const [latestKeystoneIbGib] = await getIbGibsFromCache_fallbackToSpaces({
998
+ addrs: [latestAddr],
999
+ space,
1000
+ });
1001
+ keystoneIbGib = latestKeystoneIbGib as KeystoneIbGib_V1;
1002
+ }
1003
+ } else {
1004
+ // the incoming ibgib **is** the latest keystone, so nothing more to be done.
1005
+ if (logalot) { console.log(`${lc} incoming keystone (${keystoneAddr}) is the latest in the space (${space.ib}) (I: 8ffbd8d6cbc8a461e5e7f1084bd22a26)`); }
1006
+ }
1007
+ } else {
1008
+ // keystone not found in space?
1009
+ console.warn(`${lc} keystoneIbGib (${keystoneAddr}) not found in space (${space.ib}). I don't know what the implications of this are. (W: 258c88742448db34a585669484771826)`)
1010
+ }
1011
+ }
1012
+
810
1013
  const dependencyGraph = await getDependencyGraph({
811
1014
  ibGib: keystoneIbGib,
812
1015
  space,
@@ -840,14 +1043,39 @@ export async function validateKeystoneGraph({
840
1043
  const keys = Object.keys(orderedKeystonesMap);
841
1044
  if (keys.length === 0) {
842
1045
  throw new Error(`(UNEXPECTED) orderedKeystonesMap empty? (E: d437b80bef58e83a034b28af46278726)`);
843
- } else if (keys.length > 0) {
844
- // keys.length > 0
1046
+ } else if (keys.length > 1) {
1047
+ // keys.length > 1
845
1048
  throw new Error(`(UNEXPECTED) more than one timeline in keystone graph? ATOW (02/19/2026) we are expecting only a single timeline. (E: 66085b14e3887a59c872afd240511f26)`);
846
1049
  }
847
1050
  // happy path: exactly one timeline
848
1051
  const keystoneTjpAddr = keys[0];
849
- const keystoneIbGibs_ordered = orderedKeystonesMap[keystoneTjpAddr];
1052
+ const keystoneIbGibs_ordered = orderedKeystonesMap[keystoneTjpAddr] as KeystoneIbGib_V1[];
1053
+
1054
+ if (keystoneIbGibs_ordered.length === 0) { throw new Error(`(UNEXPECTED) empty keystoneIbGibs_ordered? (E: 4a6b085aa8a76828a8d65367e7e56526)`); }
1055
+
1056
+ const genesisErrors = await validateGenesisKeystone({
1057
+ keystoneIbGib: keystoneIbGibs_ordered[0]
1058
+ });
1059
+ genesisErrors.forEach(x => errors.push(x));
850
1060
 
1061
+ if (keystoneIbGibs_ordered.length === 1) {
1062
+ // only the genesis keystone, which has already been done.
1063
+ } else {
1064
+ // more than 1 keystone, so validate the transitions
1065
+ for (let i = 0; i < keystoneIbGibs_ordered.length - 1; i++) {
1066
+ const prevIbGib = keystoneIbGibs_ordered[i];
1067
+ const currentIbGib = keystoneIbGibs_ordered[i + 1];
1068
+ const transitionErrors = await validateKeystoneTransition({
1069
+ prevIbGib, currentIbGib
1070
+ });
1071
+ if (transitionErrors.length > 0) {
1072
+ errors.push(`${lc} keystone has ${transitionErrors.length} transition errors. i: ${i}. prevIbGib addr: ${getIbGibAddr({ ibGib: prevIbGib })}. currentIbGib addr: ${getIbGibAddr({ ibGib: currentIbGib })}. (E: 3ac17be916141d0c286ca5a87bb1b426)`);
1073
+ transitionErrors.forEach(x => errors.push(x));
1074
+ }
1075
+
1076
+ break; // stop after the first found transition error
1077
+ }
1078
+ }
851
1079
  } else {
852
1080
  // one of the other errors regarding mapWithTjp_YesDna or
853
1081
  // mapWithoutTjps will exist at this point, so we don't need to add
@@ -863,4 +1091,5 @@ export async function validateKeystoneGraph({
863
1091
  } finally {
864
1092
  if (logalot) { console.log(`${lc} complete.`); }
865
1093
  }
866
- }
1094
+ }
1095
+
@@ -31,11 +31,13 @@ export class KeystoneService_V1 {
31
31
  */
32
32
  async genesis({
33
33
  masterSecret,
34
+ frameDetails,
34
35
  configs,
35
36
  metaspace,
36
37
  space,
37
38
  }: {
38
39
  masterSecret: string;
40
+ frameDetails?: any;
39
41
  configs: KeystonePoolConfig[];
40
42
  metaspace: MetaspaceService;
41
43
  space: IbGibSpaceAny;
@@ -81,6 +83,7 @@ export class KeystoneService_V1 {
81
83
  if (challengePools.length === 0) { throw new Error(`No challenge pools created. (E: 38e538530996940e1f16a8b199995825)`); }
82
84
 
83
85
  const data: KeystoneData_V1 = { challengePools, proofs: [] };
86
+ if (frameDetails) { data.frameDetails = frameDetails; }
84
87
  const keystoneIbGib = await createKeystoneIbGibImpl({ data, metaspace, space });
85
88
  return keystoneIbGib;
86
89
  } catch (error) {
@@ -97,6 +100,8 @@ export class KeystoneService_V1 {
97
100
  * Uses a hybrid selection strategy: Mandatory IDs (Alice) + Sequential (FIFO) + Random (Stochastic).
98
101
  *
99
102
  * Supports Delegation via `poolFilter` to find specific foreign pools.
103
+ *
104
+ * todo: wrap this and other entire keystone sign/method implementations in locks on the keystone's tjpGib.
100
105
  */
101
106
  async sign({
102
107
  latestKeystone,
@@ -203,7 +203,7 @@ await respecfully(sir, 'Suite A: Strategy Vectors (HashRevealV1)', async () => {
203
203
 
204
204
  await respecfully(sir, 'Derivation Logic', async () => {
205
205
 
206
- await ifWeMight(sir, 'derivePoolSecret with same inputs returns same output', async () => {
206
+ await ifWe(sir, 'derivePoolSecret with same inputs returns same output', async () => {
207
207
  const strategy = KeystoneStrategyFactory.create({ config });
208
208
 
209
209
  const secretA = await strategy.derivePoolSecret({ masterSecret });
@@ -213,7 +213,7 @@ await respecfully(sir, 'Suite A: Strategy Vectors (HashRevealV1)', async () => {
213
213
  iReckon(sir, secretA).asTo('secret length').isGonnaBeTruthy();
214
214
  });
215
215
 
216
- await ifWeMight(sir, 'derivePoolSecret with different master secret returns different output', async () => {
216
+ await ifWe(sir, 'derivePoolSecret with different master secret returns different output', async () => {
217
217
  const strategy = KeystoneStrategyFactory.create({ config });
218
218
 
219
219
  const secretA = await strategy.derivePoolSecret({ masterSecret });
@@ -222,7 +222,7 @@ await respecfully(sir, 'Suite A: Strategy Vectors (HashRevealV1)', async () => {
222
222
  iReckon(sir, secretA).asTo('secrets differ').not.willEqual(secretB);
223
223
  });
224
224
 
225
- await ifWeMight(sir, 'derivePoolSecret with different salt returns different output', async () => {
225
+ await ifWe(sir, 'derivePoolSecret with different salt returns different output', async () => {
226
226
  // Modify salt in a copy of config
227
227
  const configB = { ...config, salt: "OtherPool" };
228
228
  const strategyA = KeystoneStrategyFactory.create({ config });
@@ -237,7 +237,7 @@ await respecfully(sir, 'Suite A: Strategy Vectors (HashRevealV1)', async () => {
237
237
 
238
238
  await respecfully(sir, 'Challenge/Solution Logic', async () => {
239
239
 
240
- await ifWeMight(sir, 'generateSolution -> generateChallenge -> validateSolution loop works', async () => {
240
+ await ifWe(sir, 'generateSolution -> generateChallenge -> validateSolution loop works', async () => {
241
241
  const strategy = KeystoneStrategyFactory.create({ config });
242
242
  const poolSecret = await strategy.derivePoolSecret({ masterSecret });
243
243
  const challengeId = "a3ff7843552870fc28bef2b"; // arbitrary random challengeId
@@ -256,7 +256,7 @@ await respecfully(sir, 'Suite A: Strategy Vectors (HashRevealV1)', async () => {
256
256
  iReckon(sir, isValid).asTo('valid pair should pass').isGonnaBeTrue();
257
257
  });
258
258
 
259
- await ifWeMight(sir, 'validateSolution fails for mismatched values', async () => {
259
+ await ifWe(sir, 'validateSolution fails for mismatched values', async () => {
260
260
  const strategy = KeystoneStrategyFactory.create({ config });
261
261
  const poolSecret = await strategy.derivePoolSecret({ masterSecret });
262
262
  const challengeId = "8c994f3ed598f150e25513"; // arbitrary random challengeId
@@ -272,7 +272,7 @@ await respecfully(sir, 'Suite A: Strategy Vectors (HashRevealV1)', async () => {
272
272
  iReckon(sir, isValid).asTo('tampered solution should fail').isGonnaBeFalse();
273
273
  });
274
274
 
275
- await ifWeMight(sir, 'validateSolution fails for mismatched challenge hashes', async () => {
275
+ await ifWe(sir, 'validateSolution fails for mismatched challenge hashes', async () => {
276
276
  const strategy = KeystoneStrategyFactory.create({ config });
277
277
  const poolSecret = await strategy.derivePoolSecret({ masterSecret });
278
278
 
@@ -313,7 +313,7 @@ await respecfully(sir, 'Suite B: Service Lifecycle', async () => {
313
313
  });
314
314
 
315
315
  await respecfully(sir, 'Genesis', async () => {
316
- await ifWeMight(sir, 'creates a valid genesis frame and persists it', async () => {
316
+ await ifWe(sir, 'creates a valid genesis frame and persists it', async () => {
317
317
  const config = createStandardPoolConfig({
318
318
  id: POOL_ID_DEFAULT,
319
319
  salt: POOL_ID_DEFAULT,
@@ -344,7 +344,7 @@ await respecfully(sir, 'Suite B: Service Lifecycle', async () => {
344
344
  });
345
345
 
346
346
  await respecfully(sir, 'Signing (Evolution)', async () => {
347
- await ifWeMight(sir, 'evolves the keystone with a valid proof', async () => {
347
+ await ifWe(sir, 'evolves the keystone with a valid proof', async () => {
348
348
  const claim: Partial<KeystoneClaim> = {
349
349
  target: "comment 123^gib",
350
350
  verb: "post"
@@ -374,7 +374,7 @@ await respecfully(sir, 'Suite B: Service Lifecycle', async () => {
374
374
  });
375
375
 
376
376
  await respecfully(sir, 'Validation', async () => {
377
- await ifWeMight(sir, 'validates the genesis->signed transition', async () => {
377
+ await ifWe(sir, 'validates the genesis->signed transition', async () => {
378
378
  const errors = await service.validate({
379
379
  prevIbGib: genesisKeystone,
380
380
  currentIbGib: signedKeystone,
@@ -422,7 +422,7 @@ await respecfully(sir, 'Suite C: Security Vectors', async () => {
422
422
  });
423
423
 
424
424
  await respecfully(sir, 'Wrong Secret (Forgery)', async () => {
425
- await ifWeMight(sir, 'prevents creation of forged frames', async () => {
425
+ await ifWe(sir, 'prevents creation of forged frames', async () => {
426
426
  const claim: Partial<KeystoneClaim> = { target: "comment 123^gib", verb: "post" };
427
427
 
428
428
  let errorCaught = false;
@@ -451,7 +451,7 @@ await respecfully(sir, 'Suite C: Security Vectors', async () => {
451
451
  });
452
452
 
453
453
  await respecfully(sir, 'Policy Violation (Restricted Verbs)', async () => {
454
- await ifWeMight(sir, 'throws error if signing forbidden verb with restricted pool', async () => {
454
+ await ifWe(sir, 'throws error if signing forbidden verb with restricted pool', async () => {
455
455
  // Create a specific restricted pool config manually
456
456
  const restrictedPoolId = "read_only_pool";
457
457
  const restrictedConfig = createStandardPoolConfig({
@@ -529,7 +529,7 @@ await respecfully(sir, 'Suite D: Revocation', async () => {
529
529
  await respecfully(sir, 'Revoke Lifecycle', async () => {
530
530
  let revokedKeystone: KeystoneIbGib_V1;
531
531
 
532
- await ifWeMight(sir, 'successfully creates a revocation frame', async () => {
532
+ await ifWe(sir, 'successfully creates a revocation frame', async () => {
533
533
  revokedKeystone = await service.revoke({
534
534
  latestKeystone: genesisKeystone,
535
535
  masterSecret,
@@ -547,7 +547,7 @@ await respecfully(sir, 'Suite D: Revocation', async () => {
547
547
  iReckon(sir, data.revocationInfo!.proof.claim.verb).willEqual(KEYSTONE_VERB_REVOKE);
548
548
  });
549
549
 
550
- await ifWeMight(sir, 'validates the revocation frame', async () => {
550
+ await ifWe(sir, 'validates the revocation frame', async () => {
551
551
  const errors = await service.validate({
552
552
  prevIbGib: genesisKeystone,
553
553
  currentIbGib: revokedKeystone!,
@@ -558,7 +558,7 @@ await respecfully(sir, 'Suite D: Revocation', async () => {
558
558
  iReckon(sir, errors.length).asTo('no validation errors').willEqual(0);
559
559
  });
560
560
 
561
- await ifWeMight(sir, 'consumed the revocation pool (Scorched Earth)', async () => {
561
+ await ifWe(sir, 'consumed the revocation pool (Scorched Earth)', async () => {
562
562
  const data = revokedKeystone!.data!;
563
563
  const revokePool = data.challengePools.find(p => p.id === POOL_ID_REVOKE);
564
564
 
@@ -635,7 +635,7 @@ await respecfully(sir, 'Suite E: Structural Evolution (addPools)', async () => {
635
635
  });
636
636
 
637
637
  await respecfully(sir, 'Happy Path', async () => {
638
- await ifWeMight(sir, 'authorizes and adds a foreign pool', async () => {
638
+ await ifWe(sir, 'authorizes and adds a foreign pool', async () => {
639
639
  const bobPool = await createForeignPool("pool_bob", ["post"]);
640
640
 
641
641
  const updatedKeystone = await service.addPools({
@@ -674,7 +674,7 @@ await respecfully(sir, 'Suite E: Structural Evolution (addPools)', async () => {
674
674
  });
675
675
 
676
676
  await respecfully(sir, 'Permissions & Logic', async () => {
677
- await ifWeMight(sir, 'fails if no pool allows "manage" verb', async () => {
677
+ await ifWe(sir, 'fails if no pool allows "manage" verb', async () => {
678
678
  // 1. Create a restricted keystone
679
679
  let id = "read_only";
680
680
  const restrictedConfig = createStandardPoolConfig({ id, salt: id });
@@ -707,7 +707,7 @@ await respecfully(sir, 'Suite E: Structural Evolution (addPools)', async () => {
707
707
  iReckon(sir, errorCaught).asTo('permission denied').isGonnaBeTrue();
708
708
  });
709
709
 
710
- await ifWeMight(sir, 'fails on ID collision', async () => {
710
+ await ifWe(sir, 'fails on ID collision', async () => {
711
711
  // Try to add "pool_bob" again (it was added in Happy Path)
712
712
  const duplicatePool = await createForeignPool("pool_bob");
713
713
 
@@ -796,7 +796,7 @@ await respecfully(sir, 'Suite E: Structural Evolution (addPools)', async () => {
796
796
  });
797
797
 
798
798
  await respecfully(sir, 'Happy Path', async () => {
799
- await ifWeMight(sir, 'authorizes and adds a foreign pool', async () => {
799
+ await ifWe(sir, 'authorizes and adds a foreign pool', async () => {
800
800
  const bobPool = await createForeignPool("pool_bob", ["post"]);
801
801
 
802
802
  const updatedKeystone = await service.addPools({
@@ -835,7 +835,7 @@ await respecfully(sir, 'Suite E: Structural Evolution (addPools)', async () => {
835
835
  });
836
836
 
837
837
  await respecfully(sir, 'Permissions & Logic', async () => {
838
- await ifWeMight(sir, 'fails if no pool allows "manage" verb', async () => {
838
+ await ifWe(sir, 'fails if no pool allows "manage" verb', async () => {
839
839
  // 1. Create a restricted keystone (read-only)
840
840
  let id = "read_only";
841
841
  const restrictedConfig = createStandardPoolConfig({ id, salt: id });
@@ -868,7 +868,7 @@ await respecfully(sir, 'Suite E: Structural Evolution (addPools)', async () => {
868
868
  iReckon(sir, errorCaught).asTo('permission denied').isGonnaBeTrue();
869
869
  });
870
870
 
871
- await ifWeMight(sir, 'fails on ID collision', async () => {
871
+ await ifWe(sir, 'fails on ID collision', async () => {
872
872
  // Try to add "pool_bob" again (it was added in Happy Path)
873
873
  const duplicatePool = await createForeignPool("pool_bob");
874
874
 
@@ -930,7 +930,7 @@ await respecfully(sir, 'Suite F: Deep Inspection', async () => {
930
930
 
931
931
  await respecfully(sir, 'Proof Granularity & Math', async () => {
932
932
 
933
- await ifWeMight(sir, 'generates exactly the expected number of solutions', async () => {
933
+ await ifWe(sir, 'generates exactly the expected number of solutions', async () => {
934
934
  signedKeystone = await service.sign({
935
935
  latestKeystone: genesisKeystone,
936
936
  masterSecret: aliceSecret,
@@ -947,7 +947,7 @@ await respecfully(sir, 'Suite F: Deep Inspection', async () => {
947
947
  iReckon(sir, solutions.length).asTo('solution count').willEqual(4);
948
948
  });
949
949
 
950
- await ifWeMight(sir, 'verifies the math manually (White-box Crypto Check)', async () => {
950
+ await ifWe(sir, 'verifies the math manually (White-box Crypto Check)', async () => {
951
951
  const proof = signedKeystone.data!.proofs[0];
952
952
  const poolSnapshot = genesisKeystone.data!.challengePools.find(p => p.id === salt)!;
953
953
 
@@ -976,7 +976,7 @@ await respecfully(sir, 'Suite F: Deep Inspection', async () => {
976
976
  }
977
977
  });
978
978
 
979
- await ifWeMight(sir, 'verifies FIFO logic (Deterministic Selection)', async () => {
979
+ await ifWe(sir, 'verifies FIFO logic (Deterministic Selection)', async () => {
980
980
  const proof = signedKeystone.data!.proofs[0];
981
981
  const poolSnapshot = genesisKeystone.data!.challengePools.find(p => p.id === salt)!;
982
982
 
@@ -998,7 +998,7 @@ await respecfully(sir, 'Suite F: Deep Inspection', async () => {
998
998
 
999
999
  await respecfully(sir, 'DTO & Serialization', async () => {
1000
1000
 
1001
- await ifWeMight(sir, 'survives a clone/JSON-cycle without corruption', async () => {
1001
+ await ifWe(sir, 'survives a clone/JSON-cycle without corruption', async () => {
1002
1002
  // 1. Create a DTO (simulate network transmission/storage)
1003
1003
  // 'clone' does a JSON stringify/parse under the hood (usually) or structured clone.
1004
1004
  const dto = clone(signedKeystone);
@@ -1018,7 +1018,7 @@ await respecfully(sir, 'Suite F: Deep Inspection', async () => {
1018
1018
  iReckon(sir, errors.length).asTo('DTO validation errors').willEqual(0);
1019
1019
  });
1020
1020
 
1021
- await ifWeMight(sir, 'ensures data contains no functions or circular refs', async () => {
1021
+ await ifWe(sir, 'ensures data contains no functions or circular refs', async () => {
1022
1022
  // A crude but effective test: ensure JSON.stringify doesn't throw
1023
1023
  // and the result is equal to the object (if we parsed it back).
1024
1024
 
@@ -1,6 +1,9 @@
1
+ import { HashAlgorithm } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
2
+ import { IbGibAddr } from "@ibgib/ts-gib/dist/types.mjs";
1
3
  import { IbGib_V1, IbGibData_V1, IbGibRel8ns_V1 } from "@ibgib/ts-gib/dist/V1/types.mjs";
2
4
 
3
5
  import { KEYSTONE_ATOM } from "./keystone-constants.mjs";
6
+ import type { KeystoneVerb } from "./keystone-constants.mjs";
4
7
 
5
8
  // #region KeystoneChallengeType
6
9
  export const KEYSTONE_CHALLENGE_TYPE_HASH_REVEAL_V1 = 'hash-reveal-v1';
@@ -140,8 +143,8 @@ export interface KeystonePoolConfigBase {
140
143
  }
141
144
 
142
145
  export interface KeystonePoolConfig_HashV1 extends KeystonePoolConfigBase {
143
- type: 'hash-reveal-v1';
144
- algo: 'SHA-256' | 'SHA-512';
146
+ type: typeof KeystoneChallengeType.hash_reveal_v1;
147
+ algo: HashAlgorithm;
145
148
  rounds: number;
146
149
  }
147
150
 
@@ -157,7 +160,7 @@ export interface KeystoneChallengeBase {
157
160
 
158
161
  export interface KeystoneChallenge_HashV1 extends KeystoneChallengeBase {
159
162
  id: string;
160
- type: 'hash-reveal-v1';
163
+ type: typeof KeystoneChallengeType.hash_reveal_v1;
161
164
  /**
162
165
  * The hash that must be matched by the solution.
163
166
  */
@@ -258,12 +261,29 @@ export interface KeystoneChallengePool {
258
261
  }
259
262
 
260
263
  /**
261
- * Semantic intent.
264
+ * Describes the specific privilege that the evolution of the keystone
265
+ * authorizes.
262
266
  */
263
267
  export interface KeystoneClaim {
264
- target: string; // ibGib address
265
- verb: string; // ibGib address (primitive)
266
- scope?: string; // ibGib address (primitive)
268
+ /**
269
+ * what action/ability does the claim make?
270
+ *
271
+ * @see {@link KeystoneVerb} and all of its members for just a list of some
272
+ * common verbs. But really, this can be any string.
273
+ */
274
+ verb: string;
275
+ /**
276
+ * What specific ibgib does this claim relate to?
277
+ *
278
+ * For example, if we are signing a keystone to witness some specific ibgib
279
+ * itself, similar to the most conventional use of digital signatures, then
280
+ * this will be the address of that ibgib.
281
+ */
282
+ target: IbGibAddr;
283
+ /**
284
+ * What limitations are narrowed down to beyond just target + verb?
285
+ */
286
+ scope?: string;
267
287
  }
268
288
 
269
289
  /**
@@ -336,7 +356,10 @@ export interface KeystoneRel8ns_V1 extends IbGibRel8ns_V1 {
336
356
  // Specific hard-links for composite keystones go here later.
337
357
  }
338
358
 
339
- export interface KeystoneIbGib_V1 extends IbGib_V1<KeystoneData_V1, KeystoneRel8ns_V1> { }
359
+ export interface KeystoneIbGib_V1 extends IbGib_V1<KeystoneData_V1, KeystoneRel8ns_V1> {
360
+ data: KeystoneData_V1;
361
+ rel8ns: KeystoneRel8ns_V1;
362
+ }
340
363
 
341
364
  export interface DeterministicResult {
342
365
  /**
@@ -85,7 +85,7 @@ await respecfully(sir, `Multi-round/timeline permutations`, async () => {
85
85
  async function newTestPeer(): Promise<SyncPeerInnerspace_V1> {
86
86
  const peer = new SyncPeerInnerspace_V1(clone(SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1));
87
87
  await peer.initialized;
88
- await peer.initializeSender({
88
+ await peer.initializeOpts({
89
89
  senderSpace: sourceSpace,
90
90
  receiverSpace: destSpace,
91
91
  receiverCoordinator: receiverCoordinator,
@@ -221,7 +221,7 @@ await respecfully(sir, `Two different fields`, async () => {
221
221
 
222
222
  const peer = new SyncPeerInnerspace_V1(clone(SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1));
223
223
  await peer.initialized;
224
- await peer.initializeSender({
224
+ await peer.initializeOpts({
225
225
  senderSpace: sourceSpace, // "Client"
226
226
  receiverSpace: destSpace, // "Server"
227
227
  receiverCoordinator,
@@ -207,7 +207,7 @@ await respecfully(sir, `Two different fields and rel8d`, async () => {
207
207
 
208
208
  const peer = new SyncPeerInnerspace_V1(clone(SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1));
209
209
  await peer.initialized;
210
- await peer.initializeSender({
210
+ await peer.initializeOpts({
211
211
  senderSpace: sourceSpace, // "Client"
212
212
  receiverSpace: destSpace, // "Server"
213
213
  receiverCoordinator,