import { extractErrorMsg, getUUID, getTimestamp } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs'; import { Factory_V1 as factory } from '@ibgib/ts-gib/dist/V1/factory.mjs'; import { ROOT } from '@ibgib/ts-gib/dist/V1/constants.mjs'; import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs'; import { KeystoneIbGib_V1 } from '@ibgib/core-gib/dist/keystone/keystone-types.mjs'; import { KeystoneService_V1 } from '@ibgib/core-gib/dist/keystone/keystone-service-v1.mjs'; import { getGlobalMetaspace_waitIfNeeded } from "@ibgib/web-gib/dist/helpers.mjs"; import { mut8Timeline } from '@ibgib/core-gib/dist/timeline/timeline-api.mjs'; import { graphsAreEquivalent } from '@ibgib/core-gib/dist/common/other/graph-helper.mjs'; import { SyncPeerWebSocketSender_V1 } from '@ibgib/core-gib/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-sender/sync-peer-websocket-sender-v1.mjs'; import { SyncSagaCoordinator } from '@ibgib/core-gib/dist/sync/sync-saga-coordinator.mjs'; import { SyncConflictStrategy } from '@ibgib/core-gib/dist/sync/sync-constants.mjs'; import { SESSION_KEYSTONE_POLICY, getSpaceGibPoolConfig } from "../../common/keystone-policies.mjs"; import { SpaceGibApiBridge } from '../api/space-gib-api-bridge.mjs'; import { debugState, devLog, lc, performPhaseSetup, performPhaseSync } from './common.mjs'; export function init4_1bSetupButton(): void { const btn = document.getElementById('btn-4-1b-setup') as HTMLButtonElement | null; if (!btn) { return; } btn.addEventListener('click', () => { performPhaseSetup({ phaseText: '4.1B', btnId: 'btn-4-1b-setup', nextBtnId: 'btn-4-1b-sync', masterSecret: 'test-sender-secret-phase4-1', syncSalt: 'senderidentitysyncsaltphase4-1', manageSalt: 'senderidentitymanagesaltphase4-1', ib: 'test data 4.1b', data: { hello: 'world4_1', random: Math.random() } }); }); } export function init4_1bSyncButton(): void { const btn = document.getElementById('btn-4-1b-sync') as HTMLButtonElement | null; if (!btn) { return; } btn.addEventListener('click', () => { performPhaseSync({ phaseText: '4.1B', btnId: 'btn-4-1b-sync', nextBtnId: 'btn-4-1b-check' }); }); } export function init4_1bCheckButton(): void { const lc_fn = `${lc}[init4_1bCheckButton]`; const btn = document.getElementById('btn-4-1b-check') as HTMLButtonElement | null; if (!btn) { return; } btn.addEventListener('click', async () => { try { devLog('4.1B Check: Asserting cryptographic and WebSocket state expectations...'); const metaspace = await getGlobalMetaspace_waitIfNeeded(); const space = await metaspace.getLocalUserSpace({}); if (!space) { throw new Error("No default space."); } const domainI = debugState.domainI!; const targetX = debugState.targetX!; const xAddr = getIbGibAddr({ ibGib: targetX }); const domainAddr = getIbGibAddr({ ibGib: domainI }); // 1. Assert Target X exists locally (with evolved timeline) and get latest local graph const latestLocalXAddr = await metaspace.getLatestAddr({ addr: xAddr, space }); if (!latestLocalXAddr) { devLog('✗ Check: Evolved target X NOT found in local space!'); return; } devLog(`✓ Check: Evolved target X found locally at: ${latestLocalXAddr}`); const localXGraph = await metaspace.getDependencyGraph({ ibGibAddr: latestLocalXAddr, space }); if (!localXGraph || Object.keys(localXGraph).length === 0) { devLog('✗ Check: Failed to load target X dependency graph locally.'); return; } devLog(`✓ Check: Target X local graph loaded (${Object.keys(localXGraph).length} nodes).`); // 2. Fetch server's Target X graph via API bridge const apiBridge = new SpaceGibApiBridge(); const serverGetRes = await apiBridge.getIbGibGraph(domainAddr, xAddr, true); if (!serverGetRes.success || !serverGetRes.graph) { devLog(`✗ Check: Failed to fetch target X graph from server: ${serverGetRes.message}`); return; } const serverXGraph = serverGetRes.graph; devLog(`✓ Check: Target X server graph loaded (${Object.keys(serverXGraph).length} nodes).`); // 3. Verify graphs are equivalent using graphsAreEquivalent const equal = graphsAreEquivalent({ graphA: localXGraph, graphB: serverXGraph }); if (equal) { devLog('✓ Check: Target X dependency graphs are equivalent on client and server.'); } else { devLog('✗ Check: Target X dependency graphs mismatch between client and server!'); return; } // 4. Assert evolved sender identity I1 exists locally and on server const latestLocalIAddr = await metaspace.getLatestAddr({ addr: domainAddr, space }); if (!latestLocalIAddr) { devLog('✗ Check: Evolved domain keystone tip I1 NOT found in local space!'); return; } devLog(`✓ Check: Evolved Domain Keystone (I1) exists locally.`); const getRes = await metaspace.get({ addrs: [latestLocalIAddr], space }); const localI = getRes.ibGibs?.[0] as KeystoneIbGib_V1 | undefined; if (!localI) { devLog('✗ Check: Failed to load I1 from local space.'); return; } const syncProof = localI.data?.proofs?.find(p => p.claim?.verb === 'sync'); const sessionIdentityTjpAddr = syncProof?.claim?.target; if (!sessionIdentityTjpAddr) { devLog('✗ Check: I1 sync claim does not target a session keystone.'); return; } const serverIGetRes = await apiBridge.getIbGib(domainAddr, latestLocalIAddr); if (!serverIGetRes.success || !serverIGetRes.ibGib) { devLog(`✗ Check: Evolved Domain Keystone (I1) NOT found on server!`); return; } devLog(`✓ Check: Evolved Domain Keystone (I1) exists on server.`); // 5. Assert session identity S tip exists locally and on server const latestLocalSAddr = await metaspace.getLatestAddr({ addr: sessionIdentityTjpAddr, space }); if (!latestLocalSAddr) { devLog('✗ Check: Latest Session Keystone (S) NOT found in local space.'); return; } devLog(`✓ Check: Found latest session keystone (S) locally: ${latestLocalSAddr}`); const localSRes = await metaspace.get({ addrs: [latestLocalSAddr], space }); const sessionS = localSRes.ibGibs?.[0] as KeystoneIbGib_V1 | undefined; if (!sessionS) { devLog('✗ Check: Failed to load latest Session Keystone (S) locally.'); return; } // Verify S evolved to correct n (n === 3 or 4) const n = sessionS.data?.n; devLog(`✓ Check: S tip evolved to n = ${n}.`); if (n !== 3 && n !== 4) { devLog(`⚠ Check: Expected S to evolve to n = 3 or 4, got n = ${n}. Continuing anyway...`); } const serverSGetRes = await apiBridge.getIbGib(domainAddr, latestLocalSAddr); if (!serverSGetRes.success || !serverSGetRes.ibGib) { devLog(`✗ Check: Latest Session Keystone (S) NOT found on server!`); return; } devLog(`✓ Check: Latest Session Keystone (S) exists on server.`); // 6. Assert S graph is identical on client and server const localSGraph = await metaspace.getDependencyGraph({ ibGibAddr: latestLocalSAddr, space }); const serverSGetGraphRes = await apiBridge.getIbGibGraph(domainAddr, sessionIdentityTjpAddr, true); if (!serverSGetGraphRes.success || !serverSGetGraphRes.graph) { devLog(`✗ Check: Failed to fetch session S graph from server: ${serverSGetGraphRes.message}`); return; } const serverSGraph = serverSGetGraphRes.graph; const sGraphsEqual = graphsAreEquivalent({ graphA: localSGraph, graphB: serverSGraph }); if (sGraphsEqual) { devLog('✓ Check: Session Keystone (S) dependency graphs are equivalent on client and server.'); } else { devLog('✗ Check: Session Keystone (S) dependency graphs mismatch between client and server!'); return; } devLog('🎉 ALL PHASE 4.1B TRANSACTION SYNC CHECKS PASSED FLAWLESSLY! ✓'); btn.textContent = '✓ 4.1B All Passed'; } catch (error) { devLog(`✗ 4.1B Check FAILED: ${extractErrorMsg(error)}`); console.error(`${lc_fn} 4.1B Check error:`, error); } }); } export function init4_2bSetupButton(): void { const btn = document.getElementById('btn-4-2b-setup') as HTMLButtonElement | null; if (!btn) { return; } btn.addEventListener('click', () => { performPhaseSetup({ phaseText: '4.2B', btnId: 'btn-4-2b-setup', nextBtnId: 'btn-4-2b-sync', masterSecret: 'test-sender-secret-phase4-2', syncSalt: 'senderidentitysyncsaltphase4-2', manageSalt: 'senderidentitymanagesaltphase4-2', ib: 'dummy target 4.2b', data: { hello: 'dummy' } }); }); } async function performPhaseSync4_2b(): Promise { const lc_fn = `${lc}[performPhaseSync4_2b]`; const btn = document.getElementById('btn-4-2b-sync') as HTMLButtonElement | null; if (!btn) { return; } try { btn.disabled = true; devLog(`4.2B Sync: Creating Constants and executing three-pass WebSocket Sync...`); const domainI = debugState.domainI; if (!domainI) { devLog(`⚠ 4.2B Sync: Missing setup state. Please run Setup first.`); btn.disabled = false; return; } const domainAddr = getIbGibAddr({ ibGib: domainI }); const metaspace = await getGlobalMetaspace_waitIfNeeded(); const space = await metaspace.getLocalUserSpace({}); if (!space) { throw new Error("No default space."); } // 1. Create Constant C1 locally const c1 = await factory.constant({ parentPrimitiveIb: 'root', ib: 'constant_c1_' + (await getUUID()).slice(0, 8), data: { some: 'data_4_2b', random: Math.random() }, }); const addrC1 = getIbGibAddr({ ibGib: c1 }); await metaspace.put({ ibGib: c1, space }); await metaspace.registerNewIbGib({ ibGib: c1 }); debugState.targetC1 = c1; devLog(`4.2B Sync: ✓ Constant C1 created: ${addrC1}`); // --- Sync 1: C1 First Pass --- devLog(`4.2B Sync: Starting Pass 1 (Sync C1)...`); const protocol = location.protocol === 'https:' ? 'wss:' : 'ws:'; let senderPeer = new SyncPeerWebSocketSender_V1({ classname: 'SyncPeerWebSocketSender_V1', httpEvolveUrl: `${location.protocol}//${location.host}/api/keystone/evolve/${encodeURIComponent(domainAddr)}`, wsUrl: `${protocol}//${location.host}/api/sync/ws/${encodeURIComponent(domainAddr)}` }); let coordinator = new SyncSagaCoordinator(); let sagaId = await getUUID(); debugState.sagaId = sagaId; debugState.senderPeer = senderPeer; await senderPeer.initializeOpts({ localMetaspace: metaspace, localSpace: space, senderIdentity: domainI, senderDomainAddr: domainAddr, fnSenderSecret: async () => debugState.domainIMasterSecret!, sagaId, sessionConnectPoolConfig: SESSION_KEYSTONE_POLICY.CONNECT_POOL as any, sessionSyncPoolConfig: SESSION_KEYSTONE_POLICY.DEFAULT_POOL as any, targetAddrs: [domainAddr] }); let syncSaga = await coordinator.sync({ domainIbGibs: [c1], senderIdentityInfo: { senderIdentity: domainI, senderDomainAddr: domainAddr, }, fnSenderSecret: async () => debugState.domainIMasterSecret!, peer: senderPeer, localSpace: space, metaspace, conflictStrategy: SyncConflictStrategy.optimisticWithLCS, }); await syncSaga.done; devLog(`4.2B Sync: ✓ Pass 1 Complete.`); const latestSenderAddr1 = await metaspace.getLatestAddr({ addr: getIbGibAddr({ ibGib: domainI }), space, }); const resGetLatestI1 = await metaspace.get({ addrs: [latestSenderAddr1!], space }); const senderIdentityEvolved1 = resGetLatestI1.ibGibs![0] as KeystoneIbGib_V1; // --- Sync 2: C1 Second Pass (Idempotent check) --- devLog(`4.2B Sync: Starting Pass 2 (Sync C1 - Idempotent)...`); senderPeer = new SyncPeerWebSocketSender_V1({ classname: 'SyncPeerWebSocketSender_V1', httpEvolveUrl: `${location.protocol}//${location.host}/api/keystone/evolve/${encodeURIComponent(domainAddr)}`, wsUrl: `${protocol}//${location.host}/api/sync/ws/${encodeURIComponent(domainAddr)}` }); coordinator = new SyncSagaCoordinator(); sagaId = await getUUID(); debugState.sagaId = sagaId; debugState.senderPeer = senderPeer; await senderPeer.initializeOpts({ localMetaspace: metaspace, localSpace: space, senderIdentity: senderIdentityEvolved1, senderDomainAddr: domainAddr, fnSenderSecret: async () => debugState.domainIMasterSecret!, sagaId, sessionConnectPoolConfig: SESSION_KEYSTONE_POLICY.CONNECT_POOL as any, sessionSyncPoolConfig: SESSION_KEYSTONE_POLICY.DEFAULT_POOL as any, targetAddrs: [domainAddr] }); syncSaga = await coordinator.sync({ domainIbGibs: [c1], senderIdentityInfo: { senderIdentity: senderIdentityEvolved1, senderDomainAddr: domainAddr, }, fnSenderSecret: async () => debugState.domainIMasterSecret!, peer: senderPeer, localSpace: space, metaspace, conflictStrategy: SyncConflictStrategy.optimisticWithLCS, }); await syncSaga.done; devLog(`4.2B Sync: ✓ Pass 2 Complete.`); const latestSenderAddr2 = await metaspace.getLatestAddr({ addr: getIbGibAddr({ ibGib: domainI }), space, }); const resGetLatestI2 = await metaspace.get({ addrs: [latestSenderAddr2!], space }); const senderIdentityEvolved2 = resGetLatestI2.ibGibs![0] as KeystoneIbGib_V1; // 2. Create Constant C2 locally linking to C1 const c2 = await factory.constant({ ib: 'constant_c2_' + (await getUUID()).slice(0, 8), parentPrimitiveIb: 'root', rel8ns: { link: [addrC1], }, }); const addrC2 = getIbGibAddr({ ibGib: c2 }); await metaspace.put({ ibGib: c2, space }); await metaspace.registerNewIbGib({ ibGib: c2 }); debugState.targetC2 = c2; devLog(`4.2B Sync: ✓ Constant C2 created linking to C1: ${addrC2}`); // --- Sync 3: C2 Pass --- devLog(`4.2B Sync: Starting Pass 3 (Sync C2)...`); senderPeer = new SyncPeerWebSocketSender_V1({ classname: 'SyncPeerWebSocketSender_V1', httpEvolveUrl: `${location.protocol}//${location.host}/api/keystone/evolve/${encodeURIComponent(domainAddr)}`, wsUrl: `${protocol}//${location.host}/api/sync/ws/${encodeURIComponent(domainAddr)}` }); coordinator = new SyncSagaCoordinator(); sagaId = await getUUID(); debugState.sagaId = sagaId; debugState.senderPeer = senderPeer; await senderPeer.initializeOpts({ localMetaspace: metaspace, localSpace: space, senderIdentity: senderIdentityEvolved2, senderDomainAddr: domainAddr, fnSenderSecret: async () => debugState.domainIMasterSecret!, sagaId, sessionConnectPoolConfig: SESSION_KEYSTONE_POLICY.CONNECT_POOL as any, sessionSyncPoolConfig: SESSION_KEYSTONE_POLICY.DEFAULT_POOL as any, targetAddrs: [domainAddr] }); syncSaga = await coordinator.sync({ domainIbGibs: [c2], senderIdentityInfo: { senderIdentity: senderIdentityEvolved2, senderDomainAddr: domainAddr, }, fnSenderSecret: async () => debugState.domainIMasterSecret!, peer: senderPeer, localSpace: space, metaspace, conflictStrategy: SyncConflictStrategy.optimisticWithLCS, }); await syncSaga.done; devLog(`4.2B Sync: ✓ Pass 3 Complete.`); devLog(`✓ 4.2B Sync Sequence Complete! Ready for State Checks.`); btn.textContent = `✓ 4.2B Sync Run`; const checkBtn = document.getElementById('btn-4-2b-check') as HTMLButtonElement | null; if (checkBtn) { checkBtn.disabled = false; } } catch (error) { devLog(`✗ 4.2B Sync FAILED: ${extractErrorMsg(error)}`); console.error(`${lc_fn} 4.2B Sync error:`, error); btn.disabled = false; } } export function init4_2bSyncButton(): void { const btn = document.getElementById('btn-4-2b-sync') as HTMLButtonElement | null; if (!btn) { return; } btn.addEventListener('click', () => { performPhaseSync4_2b(); }); } export function init4_2bCheckButton(): void { const lc_fn = `${lc}[init4_2bCheckButton]`; const btn = document.getElementById('btn-4-2b-check') as HTMLButtonElement | null; if (!btn) { return; } btn.addEventListener('click', async () => { try { devLog('4.2B Check: Asserting cryptographic and WebSocket state expectations...'); const metaspace = await getGlobalMetaspace_waitIfNeeded(); const space = await metaspace.getLocalUserSpace({}); if (!space) { throw new Error("No default space."); } const domainI = debugState.domainI!; const targetC1 = debugState.targetC1!; const targetC2 = debugState.targetC2!; const c1Addr = getIbGibAddr({ ibGib: targetC1 }); const c2Addr = getIbGibAddr({ ibGib: targetC2 }); const domainAddr = getIbGibAddr({ ibGib: domainI }); // 1. Verify C1 and C2 exist locally const localC1Res = await metaspace.get({ addrs: [c1Addr], space }); const localC2Res = await metaspace.get({ addrs: [c2Addr], space }); if (!localC1Res.success || !localC1Res.ibGibs?.[0]) { devLog('✗ Check: Constant C1 NOT found locally.'); return; } if (!localC2Res.success || !localC2Res.ibGibs?.[0]) { devLog('✗ Check: Constant C2 NOT found locally.'); return; } devLog(`✓ Check: Constants C1 and C2 exist locally.`); // 2. Fetch server's graphs for C1 and C2 const apiBridge = new SpaceGibApiBridge(); const serverC1Res = await apiBridge.getIbGib(domainAddr, c1Addr); const serverC2Res = await apiBridge.getIbGib(domainAddr, c2Addr); if (!serverC1Res.success || !serverC1Res.ibGib) { devLog(`✗ Check: Constant C1 NOT found on server: ${serverC1Res.message}`); return; } if (!serverC2Res.success || !serverC2Res.ibGib) { devLog(`✗ Check: Constant C2 NOT found on server: ${serverC2Res.message}`); return; } devLog(`✓ Check: Constants C1 and C2 exist on server.`); const localC2Graph = await metaspace.getDependencyGraph({ ibGibAddr: c2Addr, space }); const serverC2GetGraphRes = await apiBridge.getIbGibGraph(domainAddr, c2Addr, true); if (!serverC2GetGraphRes.success || !serverC2GetGraphRes.graph) { devLog(`✗ Check: Failed to fetch C2 graph from server: ${serverC2GetGraphRes.message}`); return; } const serverC2Graph = serverC2GetGraphRes.graph; const c2GraphsEqual = graphsAreEquivalent({ graphA: localC2Graph, graphB: serverC2Graph }); if (c2GraphsEqual) { devLog('✓ Check: C2 dependency graphs are equivalent on client and server.'); } else { devLog('✗ Check: C2 dependency graphs mismatch between client and server!'); return; } // 3. Verify evolved sender identity I exists locally and on server, n = 3 const latestLocalIAddr = await metaspace.getLatestAddr({ addr: domainAddr, space }); if (!latestLocalIAddr) { devLog('✗ Check: Evolved domain keystone tip I3 NOT found in local space!'); return; } const localIRes = await metaspace.get({ addrs: [latestLocalIAddr], space }); const localI = localIRes.ibGibs?.[0] as KeystoneIbGib_V1 | undefined; if (!localI) { devLog('✗ Check: Failed to load evolved I from local space.'); return; } devLog(`✓ Check: Evolved Domain Keystone exists locally: ${latestLocalIAddr}`); const nI = localI.data?.n; devLog(`✓ Check: Evolved I tip is at n = ${nI}.`); if (nI !== 3) { devLog(`✗ Check: Expected I to evolve to n = 3, got n = ${nI}.`); return; } const serverIGetRes = await apiBridge.getIbGib(domainAddr, latestLocalIAddr); if (!serverIGetRes.success || !serverIGetRes.ibGib) { devLog(`✗ Check: Evolved Domain Keystone tip NOT found on server!`); return; } devLog(`✓ Check: Evolved Domain Keystone tip exists on server.`); // 4. Verify session identity S tip exists locally and on server const syncProof = localI.data?.proofs?.find(p => p.claim?.verb === 'sync'); const sessionIdentityTjpAddr = syncProof?.claim?.target; if (!sessionIdentityTjpAddr) { devLog('✗ Check: Evolved I sync claim does not target a session keystone.'); return; } const latestLocalSAddr = await metaspace.getLatestAddr({ addr: sessionIdentityTjpAddr, space }); if (!latestLocalSAddr) { devLog('✗ Check: Latest Session Keystone (S) NOT found in local space.'); return; } devLog(`✓ Check: Found latest session keystone (S) locally: ${latestLocalSAddr}`); const localSRes = await metaspace.get({ addrs: [latestLocalSAddr], space }); const sessionS = localSRes.ibGibs?.[0] as KeystoneIbGib_V1 | undefined; if (!sessionS) { devLog('✗ Check: Failed to load latest Session Keystone (S) locally.'); return; } const nS = sessionS.data?.n; devLog(`✓ Check: Latest session S tip evolved to n = ${nS}.`); if (nS !== 3) { devLog(`✗ Check: Expected latest session S to evolve to n = 3, got n = ${nS}.`); return; } const serverSGetRes = await apiBridge.getIbGib(domainAddr, latestLocalSAddr); if (!serverSGetRes.success || !serverSGetRes.ibGib) { devLog(`✗ Check: Latest Session Keystone (S) NOT found on server!`); return; } devLog(`✓ Check: Latest Session Keystone (S) exists on server.`); // 5. Assert S graph is identical on client and server const localSGraph = await metaspace.getDependencyGraph({ ibGibAddr: latestLocalSAddr, space }); const serverSGetGraphRes = await apiBridge.getIbGibGraph(domainAddr, sessionIdentityTjpAddr, true); if (!serverSGetGraphRes.success || !serverSGetGraphRes.graph) { devLog(`✗ Check: Failed to fetch session S graph from server: ${serverSGetGraphRes.message}`); return; } const serverSGraph = serverSGetGraphRes.graph; const sGraphsEqual = graphsAreEquivalent({ graphA: localSGraph, graphB: serverSGraph }); if (sGraphsEqual) { devLog('✓ Check: Session Keystone (S) dependency graphs are equivalent on client and server.'); } else { devLog('✗ Check: Session Keystone (S) dependency graphs mismatch between client and server!'); return; } devLog('🎉 ALL PHASE 4.2B TRANSACTION SYNC CHECKS PASSED FLAWLESSLY! ✓'); btn.textContent = '✓ 4.2B All Passed'; } catch (error) { devLog(`✗ 4.2B Check FAILED: ${extractErrorMsg(error)}`); console.error(`${lc_fn} 4.2B Check error:`, error); } }); } export function init4_3bSetupButton(): void { const btn = document.getElementById('btn-4-3b-setup') as HTMLButtonElement | null; if (!btn) { return; } btn.addEventListener('click', async () => { try { btn.disabled = true; devLog('4.3B Setup: Generating Domain Keystone (I) and Target timeline V0 -> V1...'); const metaspace = await getGlobalMetaspace_waitIfNeeded(); const space = await metaspace.getLocalUserSpace({}); if (!space) { throw new Error("No default space."); } const keystoneService = new KeystoneService_V1(); const domainI = await keystoneService.genesis({ masterSecret: 'test-sender-secret-phase4-3', configs: [ getSpaceGibPoolConfig('sync', 'senderidentitysyncsaltphase4-3'), getSpaceGibPoolConfig('manage', 'senderidentitymanagesaltphase4-3'), ], metaspace, space, frameDetails: { client: 'space-gib-web-dev', timestamp: getTimestamp() } }); debugState.domainI = domainI; debugState.domainIMasterSecret = 'test-sender-secret-phase4-3'; devLog(`4.3B Setup: ✓ Domain Keystone (I) created locally: ${getIbGibAddr({ ibGib: domainI })}`); const apiBridge = new SpaceGibApiBridge(); const resGenesis = await apiBridge.postGenesisKeystone(domainI); if (resGenesis.success) { devLog(`4.3B Setup: ✓ Domain Keystone registered on server.`); } else { throw new Error(`Server rejected genesis domain keystone: ${resGenesis.message}`); } const resV0 = await factory.firstGen({ parentIbGib: ROOT, ib: 'timeline_root_partial_4_3b', data: { type: 'root', label: 'Root4_3b', random: Math.random() }, dna: true, nCounter: true, tjp: { uuid: true, timestamp: true } }); const r1_v0 = resV0.newIbGib; await metaspace.persistTransformResult({ resTransform: resV0, space }); await metaspace.registerNewIbGib({ ibGib: r1_v0 }); const r1_v1 = await mut8Timeline({ timeline: r1_v0, mut8Opts: { dataToAddOrPatch: { type: 'comment', label: 'V1_4_3b' } }, metaspace, space, }); debugState.targetC1 = r1_v1; debugState.targetX = r1_v1; devLog(`4.3B Setup: ✓ Timeline V0 -> V1 created and stored locally. V1: ${getIbGibAddr({ ibGib: r1_v1 })}`); devLog('✓ 4.3B Setup Complete! Ready for 4.3B Sync.'); btn.textContent = '✓ 4.3B Setup Complete'; const syncBtn = document.getElementById('btn-4-3b-sync') as HTMLButtonElement | null; if (syncBtn) { syncBtn.disabled = false; } } catch (error) { devLog(`✗ 4.3B Setup FAILED: ${extractErrorMsg(error)}`); console.error(error); btn.disabled = false; } }); } async function performPhaseSync4_3b(): Promise { const lc_fn = `${lc}[performPhaseSync4_3b]`; const btn = document.getElementById('btn-4-3b-sync') as HTMLButtonElement | null; if (!btn) { return; } try { btn.disabled = true; devLog(`4.3B Sync: Starting Pass 1 (Sync V1 to server)...`); const domainI = debugState.domainI; const targetV1 = debugState.targetX; if (!domainI || !targetV1) { devLog(`⚠ 4.3B Sync: Missing setup state. Please run Setup first.`); btn.disabled = false; return; } const domainAddr = getIbGibAddr({ ibGib: domainI }); const metaspace = await getGlobalMetaspace_waitIfNeeded(); const space = await metaspace.getLocalUserSpace({}); if (!space) { throw new Error("No default space."); } const protocol = location.protocol === 'https:' ? 'wss:' : 'ws:'; let senderPeer = new SyncPeerWebSocketSender_V1({ classname: 'SyncPeerWebSocketSender_V1', httpEvolveUrl: `${location.protocol}//${location.host}/api/keystone/evolve/${encodeURIComponent(domainAddr)}`, wsUrl: `${protocol}//${location.host}/api/sync/ws/${encodeURIComponent(domainAddr)}` }); let coordinator = new SyncSagaCoordinator(); let sagaId = await getUUID(); debugState.sagaId = sagaId; debugState.senderPeer = senderPeer; await senderPeer.initializeOpts({ localMetaspace: metaspace, localSpace: space, senderIdentity: domainI, senderDomainAddr: domainAddr, fnSenderSecret: async () => debugState.domainIMasterSecret!, sagaId, sessionConnectPoolConfig: SESSION_KEYSTONE_POLICY.CONNECT_POOL as any, sessionSyncPoolConfig: SESSION_KEYSTONE_POLICY.DEFAULT_POOL as any, targetAddrs: [domainAddr] }); let syncSaga = await coordinator.sync({ domainIbGibs: [targetV1], senderIdentityInfo: { senderIdentity: domainI, senderDomainAddr: domainAddr, }, fnSenderSecret: async () => debugState.domainIMasterSecret!, peer: senderPeer, localSpace: space, metaspace, conflictStrategy: SyncConflictStrategy.optimisticWithLCS, }); await syncSaga.done; devLog(`4.3B Sync: ✓ Pass 1 Complete (V1 synced).`); const latestSenderAddr1 = await metaspace.getLatestAddr({ addr: getIbGibAddr({ ibGib: domainI }), space, }); const resGetLatestI1 = await metaspace.get({ addrs: [latestSenderAddr1!], space }); const senderIdentityEvolved1 = resGetLatestI1.ibGibs![0] as KeystoneIbGib_V1; devLog(`4.3B Sync: Mutating V1 to V2 locally...`); const r1_v2 = await mut8Timeline({ timeline: targetV1, mut8Opts: { dataToAddOrPatch: { type: 'comment', label: 'V2_4_3b' } }, metaspace, space, }); debugState.targetX = r1_v2; devLog(`4.3B Sync: ✓ V2 created locally: ${getIbGibAddr({ ibGib: r1_v2 })}`); devLog(`4.3B Sync: Starting Pass 2 (Sync V2 delta to server)...`); senderPeer = new SyncPeerWebSocketSender_V1({ classname: 'SyncPeerWebSocketSender_V1', httpEvolveUrl: `${location.protocol}//${location.host}/api/keystone/evolve/${encodeURIComponent(domainAddr)}`, wsUrl: `${protocol}//${location.host}/api/sync/ws/${encodeURIComponent(domainAddr)}` }); coordinator = new SyncSagaCoordinator(); sagaId = await getUUID(); debugState.sagaId = sagaId; debugState.senderPeer = senderPeer; await senderPeer.initializeOpts({ localMetaspace: metaspace, localSpace: space, senderIdentity: senderIdentityEvolved1, senderDomainAddr: domainAddr, fnSenderSecret: async () => debugState.domainIMasterSecret!, sagaId, sessionConnectPoolConfig: SESSION_KEYSTONE_POLICY.CONNECT_POOL as any, sessionSyncPoolConfig: SESSION_KEYSTONE_POLICY.DEFAULT_POOL as any, targetAddrs: [domainAddr] }); syncSaga = await coordinator.sync({ domainIbGibs: [r1_v2], senderIdentityInfo: { senderIdentity: senderIdentityEvolved1, senderDomainAddr: domainAddr, }, fnSenderSecret: async () => debugState.domainIMasterSecret!, peer: senderPeer, localSpace: space, metaspace, conflictStrategy: SyncConflictStrategy.optimisticWithLCS, }); await syncSaga.done; devLog(`4.3B Sync: ✓ Pass 2 Complete (V2 synced).`); devLog(`✓ 4.3B Sync Sequence Complete! Ready for State Checks.`); btn.textContent = `✓ 4.3B Sync Run`; const checkBtn = document.getElementById('btn-4-3b-check') as HTMLButtonElement | null; if (checkBtn) { checkBtn.disabled = false; } } catch (error) { devLog(`✗ 4.3B Sync FAILED: ${extractErrorMsg(error)}`); console.error(error); btn.disabled = false; } } export function init4_3bSyncButton(): void { const btn = document.getElementById('btn-4-3b-sync') as HTMLButtonElement | null; if (!btn) { return; } btn.addEventListener('click', () => { performPhaseSync4_3b(); }); } export function init4_3bCheckButton(): void { const lc_fn = `${lc}[init4_3bCheckButton]`; const btn = document.getElementById('btn-4-3b-check') as HTMLButtonElement | null; if (!btn) { return; } btn.addEventListener('click', async () => { try { devLog('4.3B Check: Asserting cryptographic and WebSocket state expectations...'); const metaspace = await getGlobalMetaspace_waitIfNeeded(); const space = await metaspace.getLocalUserSpace({}); if (!space) { throw new Error("No default space."); } const domainI = debugState.domainI!; const targetV1 = debugState.targetC1!; const targetV2 = debugState.targetX!; const v1Addr = getIbGibAddr({ ibGib: targetV1 }); const v2Addr = getIbGibAddr({ ibGib: targetV2 }); const domainAddr = getIbGibAddr({ ibGib: domainI }); // 1. Verify V1 and V2 exist locally const localV1Res = await metaspace.get({ addrs: [v1Addr], space }); const localV2Res = await metaspace.get({ addrs: [v2Addr], space }); if (!localV1Res.success || !localV1Res.ibGibs?.[0]) { devLog('✗ Check: Timeline frame V1 NOT found locally.'); return; } if (!localV2Res.success || !localV2Res.ibGibs?.[0]) { devLog('✗ Check: Timeline frame V2 NOT found locally.'); return; } devLog(`✓ Check: Timeline frames V1 and V2 exist locally.`); // 2. Fetch server's graphs for V2 const apiBridge = new SpaceGibApiBridge(); const serverV2Res = await apiBridge.getIbGib(domainAddr, v2Addr); if (!serverV2Res.success || !serverV2Res.ibGib) { devLog(`✗ Check: Timeline frame V2 NOT found on server: ${serverV2Res.message}`); return; } devLog(`✓ Check: Timeline frame V2 exists on server.`); const serverV2IbGib = serverV2Res.ibGib; const pastAddr = serverV2IbGib.rel8ns?.past?.at(-1); if (pastAddr === v1Addr) { devLog('✓ Check: Server V2 correctly references V1 in its past relation.'); } else { devLog(`✗ Check: Server V2 does not reference V1 in past relation! got: ${pastAddr}`); return; } const localV2Graph = await metaspace.getDependencyGraph({ ibGibAddr: v2Addr, space }); const serverV2GetGraphRes = await apiBridge.getIbGibGraph(domainAddr, v2Addr, true); if (!serverV2GetGraphRes.success || !serverV2GetGraphRes.graph) { devLog(`✗ Check: Failed to fetch V2 graph from server: ${serverV2GetGraphRes.message}`); return; } const serverV2Graph = serverV2GetGraphRes.graph; const v2GraphsEqual = graphsAreEquivalent({ graphA: localV2Graph, graphB: serverV2Graph }); if (v2GraphsEqual) { devLog('✓ Check: V2 timeline dependency graphs are equivalent on client and server.'); } else { devLog('✗ Check: V2 timeline dependency graphs mismatch between client and server!'); return; } // 3. Verify evolved sender identity I exists locally and on server, n = 2 const latestLocalIAddr = await metaspace.getLatestAddr({ addr: domainAddr, space }); if (!latestLocalIAddr) { devLog('✗ Check: Evolved domain keystone tip NOT found in local space!'); return; } const localIRes = await metaspace.get({ addrs: [latestLocalIAddr], space }); const localI = localIRes.ibGibs?.[0] as KeystoneIbGib_V1 | undefined; if (!localI) { devLog('✗ Check: Failed to load evolved I from local space.'); return; } devLog(`✓ Check: Evolved Domain Keystone exists locally: ${latestLocalIAddr}`); const nI = localI.data?.n; devLog(`✓ Check: Evolved I tip is at n = ${nI}.`); if (nI !== 2) { devLog(`✗ Check: Expected I to evolve to n = 2, got n = ${nI}.`); return; } const serverIGetRes = await apiBridge.getIbGib(domainAddr, latestLocalIAddr); if (!serverIGetRes.success || !serverIGetRes.ibGib) { devLog(`✗ Check: Evolved Domain Keystone tip NOT found on server!`); return; } devLog(`✓ Check: Evolved Domain Keystone tip exists on server.`); // 4. Verify session identity S tip exists locally and on server, n = 3 const syncProof = localI.data?.proofs?.find(p => p.claim?.verb === 'sync'); const sessionIdentityTjpAddr = syncProof?.claim?.target; if (!sessionIdentityTjpAddr) { devLog('✗ Check: Evolved I sync claim does not target a session keystone.'); return; } const latestLocalSAddr = await metaspace.getLatestAddr({ addr: sessionIdentityTjpAddr, space }); if (!latestLocalSAddr) { devLog('✗ Check: Latest Session Keystone (S) NOT found in local space.'); return; } devLog(`✓ Check: Found latest session keystone (S) locally: ${latestLocalSAddr}`); const localSRes = await metaspace.get({ addrs: [latestLocalSAddr], space }); const sessionS = localSRes.ibGibs?.[0] as KeystoneIbGib_V1 | undefined; if (!sessionS) { devLog('✗ Check: Failed to load latest Session Keystone (S) locally.'); return; } const nS = sessionS.data?.n; devLog(`✓ Check: Latest session S tip evolved to n = ${nS}.`); if (nS !== 3) { devLog(`✗ Check: Expected latest session S to evolve to n = 3, got n = ${nS}.`); return; } const serverSGetRes = await apiBridge.getIbGib(domainAddr, latestLocalSAddr); if (!serverSGetRes.success || !serverSGetRes.ibGib) { devLog(`✗ Check: Latest Session Keystone (S) NOT found on server!`); return; } devLog(`✓ Check: Latest Session Keystone (S) exists on server.`); // 5. Assert S graph is identical on client and server const localSGraph = await metaspace.getDependencyGraph({ ibGibAddr: latestLocalSAddr, space }); const serverSGetGraphRes = await apiBridge.getIbGibGraph(domainAddr, sessionIdentityTjpAddr, true); if (!serverSGetGraphRes.success || !serverSGetGraphRes.graph) { devLog(`✗ Check: Failed to fetch session S graph from server: ${serverSGetGraphRes.message}`); return; } const serverSGraph = serverSGetGraphRes.graph; const sGraphsEqual = graphsAreEquivalent({ graphA: localSGraph, graphB: serverSGraph }); if (sGraphsEqual) { devLog('✓ Check: Session Keystone (S) dependency graphs are equivalent on client and server.'); } else { devLog('✗ Check: Session Keystone (S) dependency graphs mismatch between client and server!'); return; } devLog('🎉 ALL PHASE 4.3B TRANSACTION SYNC CHECKS PASSED FLAWLESSLY! ✓'); btn.textContent = '✓ 4.3B All Passed'; } catch (error) { devLog(`✗ 4.3B Check FAILED: ${extractErrorMsg(error)}`); console.error(`${lc_fn} 4.3B Check error:`, error); } }); } export function init4_4bSetupButton(): void { const btn = document.getElementById('btn-4-4b-setup') as HTMLButtonElement | null; if (!btn) { return; } btn.addEventListener('click', async () => { try { btn.disabled = true; devLog('4.4B Setup: Generating Domain Keystone (I) and Target timeline V0 -> V1 -> V2...'); const metaspace = await getGlobalMetaspace_waitIfNeeded(); const space = await metaspace.getLocalUserSpace({}); if (!space) { throw new Error("No default space."); } const keystoneService = new KeystoneService_V1(); const domainI = await keystoneService.genesis({ masterSecret: 'test-sender-secret-phase4-4', configs: [ getSpaceGibPoolConfig('sync', 'senderidentitysyncsaltphase4-4'), getSpaceGibPoolConfig('manage', 'senderidentitymanagesaltphase4-4'), ], metaspace, space, frameDetails: { client: 'space-gib-web-dev', timestamp: getTimestamp() } }); debugState.domainI = domainI; debugState.domainIMasterSecret = 'test-sender-secret-phase4-4'; devLog(`4.4B Setup: ✓ Domain Keystone (I) created locally: ${getIbGibAddr({ ibGib: domainI })}`); const apiBridge = new SpaceGibApiBridge(); const resGenesis = await apiBridge.postGenesisKeystone(domainI); if (resGenesis.success) { devLog(`4.4B Setup: ✓ Domain Keystone registered on server.`); } else { throw new Error(`Server rejected genesis domain keystone: ${resGenesis.message}`); } // Create V0 (Root) const resV0 = await factory.firstGen({ parentIbGib: ROOT, ib: 'timeline_root_deep_4_4b', data: { type: 'root', label: 'Root4_4b', random: Math.random() }, dna: true, nCounter: true, tjp: { uuid: true, timestamp: true } }); const r1_v0 = resV0.newIbGib; await metaspace.persistTransformResult({ resTransform: resV0, space }); await metaspace.registerNewIbGib({ ibGib: r1_v0 }); debugState.targetC1 = r1_v0; // V0 // Create V1 const r1_v1 = await mut8Timeline({ timeline: r1_v0, mut8Opts: { dataToAddOrPatch: { type: 'comment', label: 'V1_4_4b' } }, metaspace, space, }); debugState.targetC2 = r1_v1; // V1 // Create V2 const r1_v2 = await mut8Timeline({ timeline: r1_v1, mut8Opts: { dataToAddOrPatch: { type: 'comment', label: 'V2_4_4b' } }, metaspace, space, }); debugState.targetX = r1_v2; // V2 (Tip) devLog(`4.4B Setup: ✓ Timeline V0 -> V1 -> V2 created locally. V2 Tip: ${getIbGibAddr({ ibGib: r1_v2 })}`); devLog('✓ 4.4B Setup Complete! Ready for 4.4B Sync.'); btn.textContent = '✓ 4.4B Setup Complete'; const syncBtn = document.getElementById('btn-4-4b-sync') as HTMLButtonElement | null; if (syncBtn) { syncBtn.disabled = false; } } catch (error) { devLog(`✗ 4.4B Setup FAILED: ${extractErrorMsg(error)}`); console.error(error); btn.disabled = false; } }); } async function performPhaseSync4_4b(): Promise { const lc_fn = `${lc}[performPhaseSync4_4b]`; const btn = document.getElementById('btn-4-4b-sync') as HTMLButtonElement | null; if (!btn) { return; } try { btn.disabled = true; devLog(`4.4B Sync: Initiating WebSocket Sync of V2 Tip...`); const domainI = debugState.domainI; const targetV2 = debugState.targetX; if (!domainI || !targetV2) { devLog(`⚠ 4.4B Sync: Missing setup state. Please run Setup first.`); btn.disabled = false; return; } const domainAddr = getIbGibAddr({ ibGib: domainI }); const metaspace = await getGlobalMetaspace_waitIfNeeded(); const space = await metaspace.getLocalUserSpace({}); if (!space) { throw new Error("No default space."); } const protocol = location.protocol === 'https:' ? 'wss:' : 'ws:'; const senderPeer = new SyncPeerWebSocketSender_V1({ classname: 'SyncPeerWebSocketSender_V1', httpEvolveUrl: `${location.protocol}//${location.host}/api/keystone/evolve/${encodeURIComponent(domainAddr)}`, wsUrl: `${protocol}//${location.host}/api/sync/ws/${encodeURIComponent(domainAddr)}` }); const coordinator = new SyncSagaCoordinator(); const sagaId = await getUUID(); debugState.sagaId = sagaId; debugState.senderPeer = senderPeer; await senderPeer.initializeOpts({ localMetaspace: metaspace, localSpace: space, senderIdentity: domainI, senderDomainAddr: domainAddr, fnSenderSecret: async () => debugState.domainIMasterSecret!, sagaId, sessionConnectPoolConfig: SESSION_KEYSTONE_POLICY.CONNECT_POOL as any, sessionSyncPoolConfig: SESSION_KEYSTONE_POLICY.DEFAULT_POOL as any, targetAddrs: [domainAddr] }); const syncSaga = await coordinator.sync({ domainIbGibs: [targetV2], senderIdentityInfo: { senderIdentity: domainI, senderDomainAddr: domainAddr, }, fnSenderSecret: async () => debugState.domainIMasterSecret!, peer: senderPeer, localSpace: space, metaspace, conflictStrategy: SyncConflictStrategy.optimisticWithLCS, }); await syncSaga.done; devLog(`4.4B Sync: ✓ WebSocket Sync completed.`); devLog(`✓ 4.4B Sync Sequence Complete! Ready for State Checks.`); btn.textContent = `✓ 4.4B Sync Run`; const checkBtn = document.getElementById('btn-4-4b-check') as HTMLButtonElement | null; if (checkBtn) { checkBtn.disabled = false; } } catch (error) { devLog(`✗ 4.4B Sync FAILED: ${extractErrorMsg(error)}`); console.error(error); btn.disabled = false; } } export function init4_4bSyncButton(): void { const btn = document.getElementById('btn-4-4b-sync') as HTMLButtonElement | null; if (!btn) { return; } btn.addEventListener('click', () => { performPhaseSync4_4b(); }); } export function init4_4bCheckButton(): void { const lc_fn = `${lc}[init4_4bCheckButton]`; const btn = document.getElementById('btn-4-4b-check') as HTMLButtonElement | null; if (!btn) { return; } btn.addEventListener('click', async () => { try { devLog('4.4B Check: Asserting cryptographic and WebSocket state expectations...'); const metaspace = await getGlobalMetaspace_waitIfNeeded(); const space = await metaspace.getLocalUserSpace({}); if (!space) { throw new Error("No default space."); } const domainI = debugState.domainI!; const targetV0 = debugState.targetC1!; const targetV1 = debugState.targetC2!; const targetV2 = debugState.targetX!; const v0Addr = getIbGibAddr({ ibGib: targetV0 }); const v1Addr = getIbGibAddr({ ibGib: targetV1 }); const v2Addr = getIbGibAddr({ ibGib: targetV2 }); const domainAddr = getIbGibAddr({ ibGib: domainI }); // 1. Verify V0, V1, and V2 exist locally const localV0Res = await metaspace.get({ addrs: [v0Addr], space }); const localV1Res = await metaspace.get({ addrs: [v1Addr], space }); const localV2Res = await metaspace.get({ addrs: [v2Addr], space }); if (!localV0Res.success || !localV0Res.ibGibs?.[0]) { devLog('✗ Check: Timeline frame V0 NOT found locally.'); return; } if (!localV1Res.success || !localV1Res.ibGibs?.[0]) { devLog('✗ Check: Timeline frame V1 NOT found locally.'); return; } if (!localV2Res.success || !localV2Res.ibGibs?.[0]) { devLog('✗ Check: Timeline frame V2 NOT found locally.'); return; } devLog(`✓ Check: Timeline frames V0, V1, and V2 exist locally.`); // 2. Fetch server's V2, V1, and V0 const apiBridge = new SpaceGibApiBridge(); const serverV2Res = await apiBridge.getIbGib(domainAddr, v2Addr); if (!serverV2Res.success || !serverV2Res.ibGib) { devLog(`✗ Check: Timeline frame V2 NOT found on server: ${serverV2Res.message}`); return; } devLog(`✓ Check: Timeline frame V2 exists on server.`); const serverV2IbGib = serverV2Res.ibGib; const pastAddrV2 = serverV2IbGib.rel8ns?.past?.at(-1); if (pastAddrV2 === v1Addr) { devLog('✓ Check: Server V2 correctly references V1 in its past relation.'); } else { devLog(`✗ Check: Server V2 does not reference V1 in past relation! got: ${pastAddrV2}`); return; } const serverV1Res = await apiBridge.getIbGib(domainAddr, v1Addr); if (!serverV1Res.success || !serverV1Res.ibGib) { devLog(`✗ Check: Timeline frame V1 NOT found on server: ${serverV1Res.message}`); return; } devLog(`✓ Check: Timeline frame V1 exists on server.`); const serverV1IbGib = serverV1Res.ibGib; const pastAddrV1 = serverV1IbGib.rel8ns?.past?.at(-1); if (pastAddrV1 === v0Addr) { devLog('✓ Check: Server V1 correctly references V0 in its past relation.'); } else { devLog(`✗ Check: Server V1 does not reference V0 in past relation! got: ${pastAddrV1}`); return; } const localV2Graph = await metaspace.getDependencyGraph({ ibGibAddr: v2Addr, space }); const serverV2GetGraphRes = await apiBridge.getIbGibGraph(domainAddr, v2Addr, true); if (!serverV2GetGraphRes.success || !serverV2GetGraphRes.graph) { devLog(`✗ Check: Failed to fetch V2 graph from server: ${serverV2GetGraphRes.message}`); return; } const serverV2Graph = serverV2GetGraphRes.graph; const v2GraphsEqual = graphsAreEquivalent({ graphA: localV2Graph, graphB: serverV2Graph }); if (v2GraphsEqual) { devLog('✓ Check: V2 timeline dependency graphs are equivalent on client and server.'); } else { devLog('✗ Check: V2 timeline dependency graphs mismatch between client and server!'); return; } // 3. Verify evolved sender identity I exists locally and on server, n = 1 (1 connect/sync handshake) const latestLocalIAddr = await metaspace.getLatestAddr({ addr: domainAddr, space }); if (!latestLocalIAddr) { devLog('✗ Check: Evolved domain keystone tip NOT found in local space!'); return; } const localIRes = await metaspace.get({ addrs: [latestLocalIAddr], space }); const localI = localIRes.ibGibs?.[0] as KeystoneIbGib_V1 | undefined; if (!localI) { devLog('✗ Check: Failed to load evolved I from local space.'); return; } devLog(`✓ Check: Evolved Domain Keystone exists locally: ${latestLocalIAddr}`); const nI = localI.data?.n; devLog(`✓ Check: Evolved I tip is at n = ${nI}.`); if (nI !== 1) { devLog(`✗ Check: Expected I to evolve to n = 1, got n = ${nI}.`); return; } const serverIGetRes = await apiBridge.getIbGib(domainAddr, latestLocalIAddr); if (!serverIGetRes.success || !serverIGetRes.ibGib) { devLog(`✗ Check: Evolved Domain Keystone tip NOT found on server!`); return; } devLog(`✓ Check: Evolved Domain Keystone tip exists on server.`); // 4. Verify session identity S tip exists locally and on server, n = 2 const syncProof = localI.data?.proofs?.find(p => p.claim?.verb === 'sync'); const sessionIdentityTjpAddr = syncProof?.claim?.target; if (!sessionIdentityTjpAddr) { devLog('✗ Check: Evolved I sync claim does not target a session keystone.'); return; } const latestLocalSAddr = await metaspace.getLatestAddr({ addr: sessionIdentityTjpAddr, space }); if (!latestLocalSAddr) { devLog('✗ Check: Latest Session Keystone (S) NOT found in local space.'); return; } devLog(`✓ Check: Found latest session keystone (S) locally: ${latestLocalSAddr}`); const localSRes = await metaspace.get({ addrs: [latestLocalSAddr], space }); const sessionS = localSRes.ibGibs?.[0] as KeystoneIbGib_V1 | undefined; if (!sessionS) { devLog('✗ Check: Failed to load latest Session Keystone (S) locally.'); return; } const nS = sessionS.data?.n; devLog(`✓ Check: Latest session S tip evolved to n = ${nS}.`); if (nS !== 2) { devLog(`✗ Check: Expected latest session S to evolve to n = 2, got n = ${nS}.`); return; } const serverSGetRes = await apiBridge.getIbGib(domainAddr, latestLocalSAddr); if (!serverSGetRes.success || !serverSGetRes.ibGib) { devLog(`✗ Check: Latest Session Keystone (S) NOT found on server!`); return; } devLog(`✓ Check: Latest Session Keystone (S) exists on server.`); // 5. Assert S graph is identical on client and server const localSGraph = await metaspace.getDependencyGraph({ ibGibAddr: latestLocalSAddr, space }); const serverSGetGraphRes = await apiBridge.getIbGibGraph(domainAddr, sessionIdentityTjpAddr, true); if (!serverSGetGraphRes.success || !serverSGetGraphRes.graph) { devLog(`✗ Check: Failed to fetch session S graph from server: ${serverSGetGraphRes.message}`); return; } const serverSGraph = serverSGetGraphRes.graph; const sGraphsEqual = graphsAreEquivalent({ graphA: localSGraph, graphB: serverSGraph }); if (sGraphsEqual) { devLog('✓ Check: Session Keystone (S) dependency graphs are equivalent on client and server.'); } else { devLog('✗ Check: Session Keystone (S) dependency graphs mismatch between client and server!'); return; } devLog('🎉 ALL PHASE 4.4B TRANSACTION SYNC CHECKS PASSED FLAWLESSLY! ✓'); btn.textContent = '✓ 4.4B All Passed'; } catch (error) { devLog(`✗ 4.4B Check FAILED: ${extractErrorMsg(error)}`); console.error(`${lc_fn} 4.4B Check error:`, error); } }); }