@ibgib/core-gib 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-helpers.d.mts +45 -0
- package/dist/agent-helpers.d.mts.map +1 -0
- package/dist/agent-helpers.mjs +36 -0
- package/dist/agent-helpers.mjs.map +1 -0
- package/dist/keystone/keystone-config-builder.respec.d.mts +2 -0
- package/dist/keystone/keystone-config-builder.respec.d.mts.map +1 -0
- package/dist/keystone/keystone-config-builder.respec.mjs +34 -0
- package/dist/keystone/keystone-config-builder.respec.mjs.map +1 -0
- package/dist/keystone/keystone-constants.d.mts +2 -0
- package/dist/keystone/keystone-constants.d.mts.map +1 -1
- package/dist/keystone/keystone-constants.mjs +2 -0
- package/dist/keystone/keystone-constants.mjs.map +1 -1
- package/dist/keystone/keystone-helpers.d.mts +54 -1
- package/dist/keystone/keystone-helpers.d.mts.map +1 -1
- package/dist/keystone/keystone-helpers.mjs +185 -1
- package/dist/keystone/keystone-helpers.mjs.map +1 -1
- package/dist/keystone/keystone-service-v1.d.mts +49 -16
- package/dist/keystone/keystone-service-v1.d.mts.map +1 -1
- package/dist/keystone/keystone-service-v1.mjs +151 -328
- package/dist/keystone/keystone-service-v1.mjs.map +1 -1
- package/dist/keystone/keystone-service-v1.respec.mjs +401 -20
- package/dist/keystone/keystone-service-v1.respec.mjs.map +1 -1
- package/dist/keystone/keystone-types.d.mts +22 -0
- package/dist/keystone/keystone-types.d.mts.map +1 -1
- package/dist/sync/sync-constants.d.mts +17 -0
- package/dist/sync/sync-constants.d.mts.map +1 -0
- package/dist/sync/sync-constants.mjs +16 -0
- package/dist/sync/sync-constants.mjs.map +1 -0
- package/dist/sync/sync-helpers.d.mts +15 -0
- package/dist/sync/sync-helpers.d.mts.map +1 -0
- package/dist/sync/sync-helpers.mjs +46 -0
- package/dist/sync/sync-helpers.mjs.map +1 -0
- package/dist/sync/sync-local-spaces.respec.d.mts +2 -0
- package/dist/sync/sync-local-spaces.respec.d.mts.map +1 -0
- package/dist/sync/sync-local-spaces.respec.mjs +159 -0
- package/dist/sync/sync-local-spaces.respec.mjs.map +1 -0
- package/dist/sync/sync-saga-coordinator.d.mts +118 -0
- package/dist/sync/sync-saga-coordinator.d.mts.map +1 -0
- package/dist/sync/sync-saga-coordinator.mjs +399 -0
- package/dist/sync/sync-saga-coordinator.mjs.map +1 -0
- package/dist/sync/sync-saga-coordinator.respec.d.mts +2 -0
- package/dist/sync/sync-saga-coordinator.respec.d.mts.map +1 -0
- package/dist/sync/sync-saga-coordinator.respec.mjs +40 -0
- package/dist/sync/sync-saga-coordinator.respec.mjs.map +1 -0
- package/dist/sync/sync-types.d.mts +103 -0
- package/dist/sync/sync-types.d.mts.map +1 -0
- package/dist/sync/sync-types.mjs +2 -0
- package/dist/sync/sync-types.mjs.map +1 -0
- package/dist/test/mock-space.d.mts +39 -0
- package/dist/test/mock-space.d.mts.map +1 -0
- package/dist/test/mock-space.mjs +79 -0
- package/dist/test/mock-space.mjs.map +1 -0
- package/dist/witness/space/inner-space/inner-space-v1.respec.mjs +163 -201
- package/dist/witness/space/inner-space/inner-space-v1.respec.mjs.map +1 -1
- package/dist/witness/space/space-helper.d.mts.map +1 -1
- package/dist/witness/space/space-helper.mjs +43 -4
- package/dist/witness/space/space-helper.mjs.map +1 -1
- package/dist/witness/space/space-helper.respec.d.mts +2 -0
- package/dist/witness/space/space-helper.respec.d.mts.map +1 -0
- package/dist/witness/space/space-helper.respec.mjs +30 -0
- package/dist/witness/space/space-helper.respec.mjs.map +1 -0
- package/package.json +2 -2
- package/src/agent-helpers.mts +58 -0
- package/src/keystone/keystone-config-builder.respec.mts +49 -0
- package/src/keystone/keystone-constants.mts +2 -0
- package/src/keystone/keystone-helpers.mts +211 -2
- package/src/keystone/keystone-service-v1.mts +183 -367
- package/src/keystone/keystone-service-v1.respec.mts +484 -21
- package/src/keystone/keystone-types.mts +24 -0
- package/src/sync/sync-constants.mts +24 -0
- package/src/sync/sync-helpers.mts +59 -0
- package/src/sync/sync-local-spaces.respec.mts +200 -0
- package/src/sync/sync-saga-coordinator.mts +477 -0
- package/src/sync/sync-saga-coordinator.respec.mts +52 -0
- package/src/sync/sync-types.mts +120 -0
- package/src/test/mock-space.mts +85 -0
- package/src/witness/space/inner-space/inner-space-v1.respec.mts +181 -228
- package/src/witness/space/space-helper.mts +42 -4
- package/src/witness/space/space-helper.respec.mts +42 -0
- package/tmp.md +11 -0
|
@@ -2,10 +2,13 @@ import { extractErrorMsg, hash, pretty } from "@ibgib/helper-gib/dist/helpers/ut
|
|
|
2
2
|
import { Ib, TransformResult } from "@ibgib/ts-gib/dist/types.mjs";
|
|
3
3
|
import { getIbAndGib, getIbGibAddr } from "@ibgib/ts-gib/dist/helper.mjs";
|
|
4
4
|
import { validateIbGibIntrinsically } from "@ibgib/ts-gib/dist/V1/validate-helper.mjs";
|
|
5
|
+
import { mut8 } from "@ibgib/ts-gib/dist/V1/transforms/mut8.mjs";
|
|
6
|
+
import { Factory_V1 } from "@ibgib/ts-gib/dist/V1/factory.mjs";
|
|
7
|
+
import { getGib } from "@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs";
|
|
5
8
|
|
|
6
9
|
import { GLOBAL_LOG_A_LOT } from "../core-constants.mjs";
|
|
7
10
|
import { KEYSTONE_ATOM } from "./keystone-constants.mjs";
|
|
8
|
-
import { KeystoneData_V1, KeystoneIbGib_V1, KeystoneIbInfo_V1, KeystoneChallengePool, DeterministicResult, KeystoneProof, KeystonePoolConfig, KeystoneReplenishStrategy, KEYSTONE_REPLENISH_STRATEGY_VALID_VALUES } from "./keystone-types.mjs";
|
|
11
|
+
import { KeystoneData_V1, KeystoneIbGib_V1, KeystoneIbInfo_V1, KeystoneChallengePool, DeterministicResult, KeystoneProof, KeystonePoolConfig, KeystoneReplenishStrategy, KEYSTONE_REPLENISH_STRATEGY_VALID_VALUES, KeystoneClaim, KeystoneSolution } from "./keystone-types.mjs";
|
|
9
12
|
import { MetaspaceService } from "../witness/space/metaspace/metaspace-types.mjs";
|
|
10
13
|
import { IbGibSpaceAny } from "../witness/space/space-base-v1.mjs";
|
|
11
14
|
import { KeystoneStrategyFactory } from "./strategy/keystone-strategy-factory.mjs";
|
|
@@ -327,7 +330,7 @@ export function selectChallengeIds({
|
|
|
327
330
|
* Generates an opaque, collision-resistant ID for a challenge.
|
|
328
331
|
* atow (2025/12/22) - Hash(Salt + Timestamp + Index)
|
|
329
332
|
*/
|
|
330
|
-
async function generateOpaqueChallengeId({
|
|
333
|
+
export async function generateOpaqueChallengeId({
|
|
331
334
|
salt,
|
|
332
335
|
timestamp,
|
|
333
336
|
index
|
|
@@ -431,6 +434,81 @@ export async function applyReplenishmentStrategy({
|
|
|
431
434
|
}
|
|
432
435
|
}
|
|
433
436
|
|
|
437
|
+
/**
|
|
438
|
+
* High-level orchestration helper.
|
|
439
|
+
* 1. Instantiates Strategy.
|
|
440
|
+
* 2. Derives Secret.
|
|
441
|
+
* 3. Solves Challenges (Generates Solutions).
|
|
442
|
+
* 4. Replenishes Pool (Calculates the next state of ALL pools).
|
|
443
|
+
* 5. Constructs Proof.
|
|
444
|
+
*
|
|
445
|
+
* @returns The resulting Proof and the full list of Next Pools.
|
|
446
|
+
*/
|
|
447
|
+
export async function solveAndReplenish({
|
|
448
|
+
targetPoolId,
|
|
449
|
+
prevPools,
|
|
450
|
+
masterSecret,
|
|
451
|
+
challengeIds,
|
|
452
|
+
claim,
|
|
453
|
+
requiredChallengeIds,
|
|
454
|
+
}: {
|
|
455
|
+
/**
|
|
456
|
+
* The ID of the pool to use for signing.
|
|
457
|
+
*/
|
|
458
|
+
targetPoolId: string;
|
|
459
|
+
/**
|
|
460
|
+
* The full list of pools from the previous Keystone frame.
|
|
461
|
+
* Required to reconstruct the full state for the next frame.
|
|
462
|
+
*/
|
|
463
|
+
prevPools: KeystoneChallengePool[];
|
|
464
|
+
masterSecret: string;
|
|
465
|
+
challengeIds: string[];
|
|
466
|
+
claim: Partial<KeystoneClaim>;
|
|
467
|
+
requiredChallengeIds?: string[];
|
|
468
|
+
}): Promise<{ proof: KeystoneProof, nextPools: KeystoneChallengePool[] }> {
|
|
469
|
+
const lc = `[solveAndReplenish]`;
|
|
470
|
+
try {
|
|
471
|
+
if (logalot) { console.log(`${lc} starting... poolId: ${targetPoolId}, ids: ${challengeIds.length}`); }
|
|
472
|
+
|
|
473
|
+
const pool = prevPools.find(p => p.id === targetPoolId);
|
|
474
|
+
if (!pool) { throw new Error(`Target pool not found: ${targetPoolId} (E: a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6)`); }
|
|
475
|
+
|
|
476
|
+
const strategy = KeystoneStrategyFactory.create({ config: pool.config });
|
|
477
|
+
const poolSecret = await strategy.derivePoolSecret({ masterSecret });
|
|
478
|
+
const solutions: KeystoneSolution[] = [];
|
|
479
|
+
|
|
480
|
+
// 1. Solve
|
|
481
|
+
for (const id of challengeIds) {
|
|
482
|
+
const solution = await strategy.generateSolution({
|
|
483
|
+
poolSecret, poolId: pool.id, challengeId: id,
|
|
484
|
+
});
|
|
485
|
+
solutions.push(solution);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// 2. Construct Proof
|
|
489
|
+
const proof: KeystoneProof = {
|
|
490
|
+
claim,
|
|
491
|
+
solutions,
|
|
492
|
+
requiredChallengeIds: (requiredChallengeIds && requiredChallengeIds.length > 0) ? requiredChallengeIds : undefined
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
// 3. Replenish
|
|
496
|
+
const nextPools = await applyReplenishmentStrategy({
|
|
497
|
+
prevPools,
|
|
498
|
+
targetPoolId: pool.id,
|
|
499
|
+
consumedIds: challengeIds,
|
|
500
|
+
masterSecret,
|
|
501
|
+
strategy,
|
|
502
|
+
config: pool.config
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
return { proof, nextPools };
|
|
506
|
+
} catch (error) {
|
|
507
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
508
|
+
throw error;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
434
512
|
/**
|
|
435
513
|
* Validates the transition from Prev -> Curr.
|
|
436
514
|
* Enforces Cryptography AND Behavioral Policy.
|
|
@@ -569,3 +647,134 @@ export async function verifyProofAgainstPool({
|
|
|
569
647
|
if (logalot) { console.log(`${lc} complete.`); }
|
|
570
648
|
}
|
|
571
649
|
}
|
|
650
|
+
|
|
651
|
+
export async function evolvePersistAndRegisterKeystone({
|
|
652
|
+
prevIbGib,
|
|
653
|
+
newData,
|
|
654
|
+
metaspace,
|
|
655
|
+
space,
|
|
656
|
+
}: {
|
|
657
|
+
prevIbGib: KeystoneIbGib_V1,
|
|
658
|
+
newData: KeystoneData_V1
|
|
659
|
+
metaspace: MetaspaceService,
|
|
660
|
+
space: IbGibSpaceAny,
|
|
661
|
+
}): Promise<KeystoneIbGib_V1> {
|
|
662
|
+
const lc = `[${evolvePersistAndRegisterKeystone.name}]`;
|
|
663
|
+
try {
|
|
664
|
+
if (logalot) { console.log(`${lc} starting... (I: 8b10e8920f08b7842803665834cf8925)`); }
|
|
665
|
+
|
|
666
|
+
if (!prevIbGib.data) { throw new Error(`(UNEXPECTED) prevIbGib.data falsy? (E: 5e84875bf992c585b979e6c8ed5bf225)`); }
|
|
667
|
+
if (prevIbGib.data.revocationInfo) { throw new Error(`Keystone has already been revoked (prevIbGib.data.revocationInfo truthy), so we cannot evolve the keystone. Keystone addr: ${getIbGibAddr({ ibGib: prevIbGib })} (E: 45d7f846556829de6b2a701838c3f825)`); }
|
|
668
|
+
|
|
669
|
+
const prevData = prevIbGib.data;
|
|
670
|
+
/**
|
|
671
|
+
* we want to completely replace these keys, so we will remove them
|
|
672
|
+
* from the data. This occurs first in the underlying mut8
|
|
673
|
+
* transform.
|
|
674
|
+
* @see {@link mut8}
|
|
675
|
+
*/
|
|
676
|
+
let dataToRemove: Partial<KeystoneData_V1> | undefined = {}
|
|
677
|
+
if (prevData.proofs) { dataToRemove.proofs = []; }
|
|
678
|
+
if (prevData.challengePools) { dataToRemove.challengePools = []; }
|
|
679
|
+
if (prevData.frameDetails) { dataToRemove.frameDetails = {}; }
|
|
680
|
+
if (Object.keys(dataToRemove).length === 0) { dataToRemove = undefined; }
|
|
681
|
+
|
|
682
|
+
const resMut8 = await mut8({
|
|
683
|
+
src: prevIbGib,
|
|
684
|
+
dataToRemove,
|
|
685
|
+
dataToAddOrPatch: newData,
|
|
686
|
+
// dna: false, // explicitly set to false just to show
|
|
687
|
+
nCounter: true,
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
if (!!resMut8.intermediateIbGibs) { throw new Error(`(UNEXPECTED) resMut8.intermediateIbGibs truthy? I'm not sure if we expect there to be intermediateIbGibs, but I feel like we shouldn't. Pretty sure we shouldn't, definitely don't *want* them. (E: ba40d55d7c2d36d438c413886f148625)`); }
|
|
691
|
+
if (!!resMut8.dnas) { throw new Error(`(UNEXPECTED) resMut8.dnas truthy? We do not want dnas with keystones. (E: 49470513d018f97d28024f4e82da3b25)`); }
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
const newKeystoneIbGib = resMut8.newIbGib as KeystoneIbGib_V1;
|
|
695
|
+
|
|
696
|
+
// run validation here
|
|
697
|
+
const errors = await validateKeystoneTransition({
|
|
698
|
+
currentIbGib: newKeystoneIbGib,
|
|
699
|
+
prevIbGib,
|
|
700
|
+
});
|
|
701
|
+
if (errors.length > 0) {
|
|
702
|
+
console.error(`${lc} Validation Failed:\n${errors.join('\n')}`);
|
|
703
|
+
throw new Error(`(UNEXPECTED) invalid keystone after we just evolved it? Errors: ${errors.join('; ')} (E: ae2c58406c1db7687879dfb89fc1f825)`);
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
// save and register
|
|
707
|
+
await metaspace.put({ ibGib: newKeystoneIbGib, space, });
|
|
708
|
+
await metaspace.registerNewIbGib({ ibGib: newKeystoneIbGib, space, });
|
|
709
|
+
|
|
710
|
+
return newKeystoneIbGib;
|
|
711
|
+
} catch (error) {
|
|
712
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
713
|
+
throw error;
|
|
714
|
+
} finally {
|
|
715
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* Creates a new keystone ibgib that has no dna and no past.
|
|
721
|
+
*/
|
|
722
|
+
export async function createKeystoneIbGibImpl({
|
|
723
|
+
data,
|
|
724
|
+
metaspace,
|
|
725
|
+
space,
|
|
726
|
+
}: {
|
|
727
|
+
data: KeystoneData_V1,
|
|
728
|
+
metaspace: MetaspaceService,
|
|
729
|
+
space?: IbGibSpaceAny,
|
|
730
|
+
}): Promise<KeystoneIbGib_V1> {
|
|
731
|
+
const lc = `[${createKeystoneIbGibImpl.name}]`;
|
|
732
|
+
try {
|
|
733
|
+
if (logalot) { console.log(`${lc} starting... (I: 5e32389700e9899e788cbefacef7c825)`); }
|
|
734
|
+
|
|
735
|
+
space ??= await metaspace.getLocalUserSpace({ lock: false });
|
|
736
|
+
if (!space) { throw new Error(`(UNEXPECTED) space was falsy and we couldn't get default local user space from metaspace? (E: 9a6498cf16a8801f19ec376749742225)`); }
|
|
737
|
+
|
|
738
|
+
// create the actual keystoneIbGib
|
|
739
|
+
const resFirstGen = await Factory_V1.firstGen({
|
|
740
|
+
parentIbGib: Factory_V1.primitive({ ib: KEYSTONE_ATOM }),
|
|
741
|
+
ib: await getKeystoneIb({ keystoneData: data }),
|
|
742
|
+
data,
|
|
743
|
+
dna: false,
|
|
744
|
+
nCounter: true,
|
|
745
|
+
tjp: {
|
|
746
|
+
timestamp: true,
|
|
747
|
+
uuid: true,
|
|
748
|
+
},
|
|
749
|
+
}) as TransformResult<KeystoneIbGib_V1>;
|
|
750
|
+
const keystoneIbGib = resFirstGen.newIbGib;
|
|
751
|
+
|
|
752
|
+
if (!keystoneIbGib.data) { throw new Error(`(UNEXPECTED) keystoneIbGib.data falsy? We expect the data to be populated with real keystone data. (E: 38a358facdb89d16d81d48c8520d3d25)`); }
|
|
753
|
+
if (!keystoneIbGib.rel8ns) { throw new Error(`(UNEXPECTED) keystoneIbGib.rel8ns falsy? we expect the rel8ns to have ancestor and past. (E: 20cb7723dc33ae1ef808fe76d1bf4b25)`); }
|
|
754
|
+
if (!keystoneIbGib.rel8ns.past || keystoneIbGib.rel8ns.past.length === 0) {
|
|
755
|
+
throw new Error(`(UNEXPECTED) keystoneIbGib.rel8ns.past falsy or empty? we expect the firstGen call to generate an interstitial ibgib that we will splice out. (E: 0fd8388d045ab9f37834c27d67e78825)`);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// reset n
|
|
759
|
+
keystoneIbGib.data.n = 0;
|
|
760
|
+
// reset tjp
|
|
761
|
+
keystoneIbGib.data.isTjp = true;
|
|
762
|
+
delete keystoneIbGib.rel8ns.tjp;
|
|
763
|
+
// reset past
|
|
764
|
+
delete keystoneIbGib.rel8ns.past;
|
|
765
|
+
|
|
766
|
+
// recalculate gib
|
|
767
|
+
keystoneIbGib.gib = await getGib({ ibGib: keystoneIbGib });
|
|
768
|
+
|
|
769
|
+
// save and register
|
|
770
|
+
await metaspace.put({ ibGib: keystoneIbGib, space, });
|
|
771
|
+
await metaspace.registerNewIbGib({ ibGib: keystoneIbGib, space, });
|
|
772
|
+
|
|
773
|
+
return keystoneIbGib;
|
|
774
|
+
} catch (error) {
|
|
775
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
776
|
+
throw error;
|
|
777
|
+
} finally {
|
|
778
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
779
|
+
}
|
|
780
|
+
}
|