@ibgib/core-gib 0.1.54 → 0.1.55
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/CHANGELOG.md +10 -3
- package/README.md +12 -15
- package/dist/keystone/aggregate-details.respec.d.mts +2 -0
- package/dist/keystone/aggregate-details.respec.d.mts.map +1 -0
- package/dist/keystone/aggregate-details.respec.mjs +118 -0
- package/dist/keystone/aggregate-details.respec.mjs.map +1 -0
- package/dist/keystone/keystone-constants.d.mts +5 -0
- package/dist/keystone/keystone-constants.d.mts.map +1 -1
- package/dist/keystone/keystone-constants.mjs +6 -1
- package/dist/keystone/keystone-constants.mjs.map +1 -1
- package/dist/keystone/keystone-helpers.d.mts +7 -1
- package/dist/keystone/keystone-helpers.d.mts.map +1 -1
- package/dist/keystone/keystone-helpers.mjs +5 -2
- package/dist/keystone/keystone-helpers.mjs.map +1 -1
- package/dist/keystone/keystone-service-v1.d.mts +51 -0
- package/dist/keystone/keystone-service-v1.d.mts.map +1 -1
- package/dist/keystone/keystone-service-v1.mjs +176 -9
- package/dist/keystone/keystone-service-v1.mjs.map +1 -1
- package/dist/keystone/keystone-service-v1.respec.mjs +40 -98
- package/dist/keystone/keystone-service-v1.respec.mjs.map +1 -1
- package/dist/keystone/keystone-types.d.mts +5 -0
- package/dist/keystone/keystone-types.d.mts.map +1 -1
- package/dist/sync/graft-info/graft-info-helpers.respec.mjs +8 -8
- package/dist/sync/graft-info/graft-info-helpers.respec.mjs.map +1 -1
- package/dist/sync/sync-conflict-adv-multitimelines.respec.mjs +26 -30
- package/dist/sync/sync-conflict-adv-multitimelines.respec.mjs.map +1 -1
- package/dist/sync/sync-conflict-basic-divergence.respec.mjs +7 -8
- package/dist/sync/sync-conflict-basic-divergence.respec.mjs.map +1 -1
- package/dist/sync/sync-conflict-basic-multitimelines.respec.mjs +10 -11
- package/dist/sync/sync-conflict-basic-multitimelines.respec.mjs.map +1 -1
- package/dist/sync/sync-conflict-text-merge.respec.mjs +30 -33
- package/dist/sync/sync-conflict-text-merge.respec.mjs.map +1 -1
- package/dist/sync/sync-constants.d.mts +1 -56
- package/dist/sync/sync-constants.d.mts.map +1 -1
- package/dist/sync/sync-constants.mjs +2 -59
- package/dist/sync/sync-constants.mjs.map +1 -1
- package/dist/sync/sync-helpers.d.mts +0 -1
- package/dist/sync/sync-helpers.d.mts.map +1 -1
- package/dist/sync/sync-helpers.mjs +1 -6
- package/dist/sync/sync-helpers.mjs.map +1 -1
- package/dist/sync/sync-innerspace-constants.respec.mjs +5 -9
- package/dist/sync/sync-innerspace-constants.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-deep-updates.respec.mjs +6 -7
- package/dist/sync/sync-innerspace-deep-updates.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-dest-ahead-withid.respec.mjs +22 -22
- package/dist/sync/sync-innerspace-dest-ahead-withid.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-dest-ahead.respec.mjs +8 -9
- package/dist/sync/sync-innerspace-dest-ahead.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs +6 -7
- package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-partial-update.respec.mjs +7 -8
- package/dist/sync/sync-innerspace-partial-update.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace.respec.mjs +8 -11
- package/dist/sync/sync-innerspace.respec.mjs.map +1 -1
- package/dist/sync/sync-peer/sync-peer-http-receiver/sync-http-node-adapter.mjs +10 -5
- package/dist/sync/sync-peer/sync-peer-http-receiver/sync-http-node-adapter.mjs.map +1 -1
- package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-types.d.mts +3 -1
- package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-types.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.d.mts +4 -2
- package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.mjs +37 -6
- package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.mjs.map +1 -1
- package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-types.d.mts +3 -1
- package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-types.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.d.mts +4 -2
- package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.mjs +37 -0
- package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.mjs.map +1 -1
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.d.mts +7 -1
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts +10 -2
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs +50 -38
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs.map +1 -1
- package/dist/sync/sync-peer/sync-peer-types.d.mts +21 -5
- package/dist/sync/sync-peer/sync-peer-types.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-v1.d.mts +30 -5
- package/dist/sync/sync-peer/sync-peer-v1.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-v1.mjs +41 -25
- package/dist/sync/sync-peer/sync-peer-v1.mjs.map +1 -1
- package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts +2 -11
- package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts.map +1 -1
- package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs +7 -51
- package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs.map +1 -1
- package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts +1 -47
- package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts.map +1 -1
- package/dist/sync/sync-saga-coordinator.d.mts +6 -58
- package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
- package/dist/sync/sync-saga-coordinator.mjs +23 -425
- package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
- package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts +2 -2
- package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts.map +1 -1
- package/dist/sync/sync-types.d.mts +2 -19
- package/dist/sync/sync-types.d.mts.map +1 -1
- package/dist/sync/sync-types.mjs.map +1 -1
- package/dist/test/mock-space.mjs +1 -1
- package/dist/test/mock-space.mjs.map +1 -1
- package/dist/test-helpers.d.mts +0 -6
- package/dist/test-helpers.d.mts.map +1 -1
- package/dist/test-helpers.mjs +2 -25
- package/dist/test-helpers.mjs.map +1 -1
- package/package.json +7 -31
- package/src/keystone/aggregate-details.respec.mts +137 -0
- package/src/keystone/docs/architecture.md +16 -0
- package/src/keystone/keystone-constants.mts +6 -1
- package/src/keystone/keystone-helpers.mts +9 -1
- package/src/keystone/keystone-service-v1.mts +216 -8
- package/src/keystone/keystone-service-v1.respec.mts +39 -103
- package/src/keystone/keystone-types.mts +6 -0
- package/src/sync/README.md +18 -0
- package/src/sync/docs/architecture.md +21 -0
- package/src/sync/graft-info/graft-info-helpers.respec.mts +7 -7
- package/src/sync/sync-conflict-adv-multitimelines.respec.mts +25 -29
- package/src/sync/sync-conflict-basic-divergence.respec.mts +6 -7
- package/src/sync/sync-conflict-basic-multitimelines.respec.mts +9 -10
- package/src/sync/sync-conflict-text-merge.respec.mts +29 -32
- package/src/sync/sync-constants.mts +2 -62
- package/src/sync/sync-helpers.mts +1 -8
- package/src/sync/sync-id-testlog.txt +421 -0
- package/src/sync/sync-innerspace-constants.respec.mts +4 -8
- package/src/sync/sync-innerspace-deep-updates.respec.mts +5 -6
- package/src/sync/sync-innerspace-dest-ahead-withid.respec.mts +23 -25
- package/src/sync/sync-innerspace-dest-ahead.respec.mts +7 -8
- package/src/sync/sync-innerspace-multiple-timelines.respec.mts +5 -6
- package/src/sync/sync-innerspace-partial-update.respec.mts +6 -7
- package/src/sync/sync-innerspace.respec.mts +7 -10
- package/src/sync/sync-peer/sync-peer-http-receiver/sync-http-node-adapter.mts +5 -5
- package/src/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-types.mts +5 -1
- package/src/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.mts +30 -9
- package/src/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-types.mts +3 -1
- package/src/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.mts +29 -2
- package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.mts +7 -1
- package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mts +51 -38
- package/src/sync/sync-peer/sync-peer-types.mts +23 -6
- package/src/sync/sync-peer/sync-peer-v1.mts +68 -28
- package/src/sync/sync-saga-context/sync-saga-context-helpers.mts +6 -66
- package/src/sync/sync-saga-context/sync-saga-context-types.mts +1 -48
- package/src/sync/sync-saga-coordinator.mts +12 -552
- package/src/sync/sync-saga-message/sync-saga-message-types.mts +2 -3
- package/src/sync/sync-types.mts +2 -22
- package/src/sync/unused-identity-backup.mts.md +311 -0
- package/src/test/mock-space.mts +1 -1
- package/src/test-helpers.mts +1 -26
- package/test_output.log +0 -0
- package/test_output_utf8.txt +398 -0
- package/.vscode/core-gib-snippets.code-snippets +0 -293
- package/.vscode/launch.json +0 -40
- package/.vscode/settings.json +0 -58
- package/.vscode/tasks.json +0 -37
- package/dist/sync/sync-peer/sync-peer-http.respec.d.mts +0 -2
- package/dist/sync/sync-peer/sync-peer-http.respec.d.mts.map +0 -1
- package/dist/sync/sync-peer/sync-peer-http.respec.mjs +0 -340
- package/dist/sync/sync-peer/sync-peer-http.respec.mjs.map +0 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.d.mts +0 -42
- package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.d.mts.map +0 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.mjs +0 -312
- package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.mjs.map +0 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.d.mts +0 -84
- package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.d.mts.map +0 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.mjs +0 -65
- package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.mjs.map +0 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.d.mts +0 -73
- package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.d.mts.map +0 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.mjs +0 -667
- package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.mjs.map +0 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.d.mts +0 -2
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.d.mts.map +0 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.mjs +0 -67
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.mjs.map +0 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.d.mts +0 -2
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.d.mts.map +0 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.mjs +0 -67
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.mjs.map +0 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.d.mts +0 -2
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.d.mts.map +0 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.mjs +0 -68
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.mjs.map +0 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.d.mts +0 -2
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.d.mts.map +0 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.mjs +0 -69
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.mjs.map +0 -1
- package/src/sync/sync-peer/sync-peer-http.respec.mts +0 -396
- package/src/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.mts +0 -298
- package/src/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.mts +0 -150
- package/src/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.mts +0 -666
- package/src/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.mts +0 -87
- package/src/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.mts +0 -88
- package/src/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.mts +0 -88
- package/src/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.mts +0 -90
|
@@ -5,10 +5,7 @@ import { getIbGibAddr } from "@ibgib/ts-gib/dist/helper.mjs";
|
|
|
5
5
|
import { Factory_V1 } from "@ibgib/ts-gib/dist/V1/factory.mjs";
|
|
6
6
|
import { GLOBAL_LOG_A_LOT } from "../core-constants.mjs";
|
|
7
7
|
import { putInSpace, getLatestAddrs, getFromSpace, registerNewIbGib } from "../witness/space/space-helper.mjs";
|
|
8
|
-
import {
|
|
9
|
-
import { deriveKey } from "../keystone/kdf/kdf-helpers.mjs";
|
|
10
|
-
import { KdfStrategy } from "../keystone/kdf/kdf-constants.mjs";
|
|
11
|
-
import { SyncStage, SYNC_ATOM, SYNC_MSG_REL8N_NAME, SYNC_SAGA_PAYLOAD_ADDRS_DOMAIN, SyncConflictStrategy, SYNC_CONFLICT_STRATEGY_VALID_VALUES, SESSION_IDENTITY_KEYSTONE_SECRET_TRANSITIONPOOL, SESSION_IDENTITY_KEYSTONE_CONFIG_ALGO, SESSION_IDENTITY_KEYSTONE_CONFIG_ROUNDS, SESSION_IDENTITY_KEYSTONE_CONFIG_RANDOM, SESSION_IDENTITY_KEYSTONE_CONFIG_REPLENISH_STRATEGY, SESSION_IDENTITY_KEYSTONE_CONFIG_SEQUENTIAL, SESSION_IDENTITY_KEYSTONE_CONFIG_TARGET_BINDING, SESSION_IDENTITY_KEYSTONE_CONFIG_SIZE, SESSION_IDENTITY_KEYSTONE_TRANSITION_POOL_ID, SESSION_IDENTITY_KEYSTONE_CONFIG_SIZE_TRANSITIONPOOL, SESSION_IDENTITY_KEYSTONE_CONFIG_REPLENISH_STRATEGY_TRANSITIONPOOL, SESSION_IDENTITY_KEYSTONE_CONFIG_RANDOM_TRANSITIONPOOL, SESSION_IDENTITY_KEYSTONE_CONFIG_SEQUENTIAL_TRANSITIONPOOL, SESSION_IDENTITY_KEYSTONE_CONFIG_TARGET_BINDING_TRANSITIONPOOL, SESSION_IDENTITY_KEYSTONE_CONFIG_ALGO_TRANSITIONPOOL, SESSION_IDENTITY_KEYSTONE_CONFIG_ROUNDS_TRANSITIONPOOL, SESSION_IDENTITY_KEYSTONE_CONFIG_VERBS_TRANSITIONPOOL, SESSION_IDENTITY_KEYSTONE_CONFIG_VERBS_DELEGATE, SESSION_IDENTITY_KEYSTONE_DELEGATE_POOL_ID, SESSION_IDENTITY_KEYSTONE_PRIMARY_POOL_ID, } from "./sync-constants.mjs";
|
|
8
|
+
import { SyncStage, SYNC_ATOM, SYNC_MSG_REL8N_NAME, SYNC_SAGA_PAYLOAD_ADDRS_DOMAIN, SyncConflictStrategy, SYNC_CONFLICT_STRATEGY_VALID_VALUES, } from "./sync-constants.mjs";
|
|
12
9
|
import { appendToTimeline, createTimeline, getHistory, getHistoryAddrs } from "../timeline/timeline-api.mjs";
|
|
13
10
|
import { SyncMode, } from "./sync-types.mjs";
|
|
14
11
|
import { getSyncSagaFrameOrigin, getFullSyncSagaHistory, getSyncIb, getTempSpaceName, isPastFrame, putInSpace_dnasThenNonDnas, validateFullSyncSagaHistory, getAllOrphanedAddresses, getFinalConflictsInfo } from "./sync-helpers.mjs";
|
|
@@ -23,11 +20,7 @@ import { fnObs } from "../common/pubsub/observer/observer-helper.mjs";
|
|
|
23
20
|
import { graftTimelines, } from "./graft-info/graft-info-helpers.mjs";
|
|
24
21
|
import { GRAFT_INFO_REL8N_NAME } from "./graft-info/graft-info-constants.mjs";
|
|
25
22
|
import { validateIbGibIntrinsically } from "@ibgib/ts-gib/dist/V1/validate-helper.mjs";
|
|
26
|
-
import { KEYSTONE_VERB_MANAGE, KEYSTONE_VERB_SIGN } from "../keystone/keystone-constants.mjs";
|
|
27
|
-
import { addToBindingMap, generateOpaqueChallengeId, validateGenesisKeystone, validateKeystoneGraph } from "../keystone/keystone-helpers.mjs";
|
|
28
23
|
import { SYNC_SAGA_CONTEXT_ATOM } from "./sync-saga-context/sync-saga-context-constants.mjs";
|
|
29
|
-
import { createStandardPoolConfig } from "../keystone/keystone-config-builder.mjs";
|
|
30
|
-
import { KeystoneStrategyFactory } from "../keystone/strategy/keystone-strategy-factory.mjs";
|
|
31
24
|
const logalot = GLOBAL_LOG_A_LOT;
|
|
32
25
|
const logalotControlDomain = false;
|
|
33
26
|
const lcControlDomain = '[ControlDomain]';
|
|
@@ -41,23 +34,21 @@ const lcControlDomain = '[ControlDomain]';
|
|
|
41
34
|
* * **Sender/Local Node**: The node *initiating* the sync (calling `sync()`).
|
|
42
35
|
* * **Receiver/Remote Node**: The node *accepting* the sync request (the Peer).
|
|
43
36
|
*
|
|
44
|
-
* Note that in a peer-to-peer architecture, "Sender" and "Receiver" are roles
|
|
45
|
-
* to a specific Saga
|
|
37
|
+
* Note that in a peer-to-peer architecture, "Sender" and "Receiver" are roles
|
|
38
|
+
* relative to a specific Saga, not fixed node ids.
|
|
46
39
|
*/
|
|
47
40
|
export class SyncSagaCoordinator {
|
|
48
|
-
keystoneSvc;
|
|
49
41
|
lc = `[${SyncSagaCoordinator.name}]`;
|
|
50
|
-
constructor(
|
|
51
|
-
this.keystoneSvc = keystoneSvc;
|
|
42
|
+
constructor() {
|
|
52
43
|
}
|
|
53
44
|
/**
|
|
54
45
|
* Executes a synchronization saga using the Symmetric Sync Protocol.
|
|
55
46
|
*
|
|
56
47
|
* @remarks
|
|
57
48
|
* **Execution Context**: **Sender (Local)**.
|
|
58
|
-
* This method is the entry point for starting a sync
|
|
49
|
+
* This method is the entry point for starting a sync saga.
|
|
59
50
|
*/
|
|
60
|
-
async sync({ peer, domainIbGibs, conflictStrategy = SyncConflictStrategy.abort,
|
|
51
|
+
async sync({ peer, domainIbGibs, conflictStrategy = SyncConflictStrategy.abort, metaspace, localSpace, }) {
|
|
61
52
|
const lc = `${this.lc}[${this.sync.name}]`;
|
|
62
53
|
if (logalot) {
|
|
63
54
|
console.log(`${lc} starting...`);
|
|
@@ -101,35 +92,11 @@ export class SyncSagaCoordinator {
|
|
|
101
92
|
// Async execution wrapper
|
|
102
93
|
(async () => {
|
|
103
94
|
try {
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
if (useSessionIdentity) {
|
|
107
|
-
if (!identitySecret) {
|
|
108
|
-
throw new Error(`useSessionIdentity is true, but identitySecret is falsy. Must provide a secret if you want to use a session identity. (E: 81915860c4dd3ea4dfd81825fa74c126)`);
|
|
109
|
-
}
|
|
110
|
-
// creates the initial session identity (keystone). the flow
|
|
111
|
-
// (i think) will go: evolve saga frame, then sign keystone,
|
|
112
|
-
// then create/send context.
|
|
113
|
-
const resCreateSessionIdentity = await this.createSessionIdentity({
|
|
114
|
-
sagaId,
|
|
115
|
-
primaryIdentity: identity,
|
|
116
|
-
nonSessionSecret: identitySecret,
|
|
117
|
-
metaspace,
|
|
118
|
-
localSpace
|
|
119
|
-
});
|
|
120
|
-
sessionIdentity = resCreateSessionIdentity.sessionIdentity;
|
|
121
|
-
if (identity) {
|
|
122
|
-
if (!resCreateSessionIdentity.newPrimaryIdentity) {
|
|
123
|
-
throw new Error(`(UNEXPECTED) identity truthy but resCreateSessionIdentity.newPrimaryIdentity falsy? (E: 4f82e88a3cc5bd7e58a40f8d77bda826)`);
|
|
124
|
-
}
|
|
125
|
-
identity = resCreateSessionIdentity.newPrimaryIdentity;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
// if (logalot) { console.log(`${lc} sessionIdentity: ${sessionIdentity ? pretty(sessionIdentity) : 'undefined'} (I: abc01872800b3a66b819a05898bba826)`); }
|
|
95
|
+
// CONNECT PEER (if needed)
|
|
96
|
+
await peer.connect({ sagaId });
|
|
129
97
|
// CREATE INITIAL FRAME (Stage.init)
|
|
130
98
|
const { initFrame, initDomainGraph } = await this.createInitFrame({
|
|
131
99
|
sagaId,
|
|
132
|
-
sessionIdentity,
|
|
133
100
|
domainIbGibs,
|
|
134
101
|
conflictStrategy,
|
|
135
102
|
metaspace, localSpace, tempSpace,
|
|
@@ -138,8 +105,6 @@ export class SyncSagaCoordinator {
|
|
|
138
105
|
await this.executeSagaLoop({
|
|
139
106
|
initFrame, initDomainGraph,
|
|
140
107
|
peer,
|
|
141
|
-
identitySecret,
|
|
142
|
-
sessionIdentity,
|
|
143
108
|
updates$,
|
|
144
109
|
localSpace,
|
|
145
110
|
tempSpace,
|
|
@@ -176,7 +141,7 @@ export class SyncSagaCoordinator {
|
|
|
176
141
|
* @returns next context result if another round, else if commit returns
|
|
177
142
|
* null
|
|
178
143
|
*/
|
|
179
|
-
async continueSync({ sagaContext, mySpace, myTempSpace,
|
|
144
|
+
async continueSync({ sagaContext, mySpace, myTempSpace, metaspace, }) {
|
|
180
145
|
const lc = `${this.lc}[${this.continueSync.name}]`;
|
|
181
146
|
try {
|
|
182
147
|
if (logalot) {
|
|
@@ -186,7 +151,6 @@ export class SyncSagaCoordinator {
|
|
|
186
151
|
sagaContext,
|
|
187
152
|
mySpace,
|
|
188
153
|
myTempSpace,
|
|
189
|
-
identity,
|
|
190
154
|
metaspace,
|
|
191
155
|
});
|
|
192
156
|
if (!contextResult) {
|
|
@@ -214,8 +178,6 @@ export class SyncSagaCoordinator {
|
|
|
214
178
|
sagaFrame: frame,
|
|
215
179
|
localSpace: mySpace,
|
|
216
180
|
payloadIbGibsDomain,
|
|
217
|
-
sessionKeystone: identity,
|
|
218
|
-
sessionSecret: identitySecret,
|
|
219
181
|
metaspace,
|
|
220
182
|
});
|
|
221
183
|
const immediateValidationErrors = await validateContextAndSagaFrame({
|
|
@@ -236,295 +198,6 @@ export class SyncSagaCoordinator {
|
|
|
236
198
|
}
|
|
237
199
|
}
|
|
238
200
|
}
|
|
239
|
-
/**
|
|
240
|
-
* helper that KDFs the given identitySecret, using {@link sagaId} to do so.
|
|
241
|
-
*
|
|
242
|
-
* @returns deterministically derived session secret
|
|
243
|
-
*/
|
|
244
|
-
async deriveSessionSecret({ sagaId, nonSessionSecret, }) {
|
|
245
|
-
const lc = `${this.lc}[${this.deriveSessionSecret.name}]`;
|
|
246
|
-
try {
|
|
247
|
-
if (logalot) {
|
|
248
|
-
console.log(`${lc} starting... (I: 0de03f8dcd3e32f1fca244e8f2a8a826)`);
|
|
249
|
-
}
|
|
250
|
-
// Derive session-specific secret using KDF
|
|
251
|
-
const sessionSecret = await deriveKey({
|
|
252
|
-
masterSecret: nonSessionSecret,
|
|
253
|
-
kdfOpts: {
|
|
254
|
-
strategy: KdfStrategy.recursive_salt_wrap,
|
|
255
|
-
salt: sagaId,
|
|
256
|
-
rounds: 10000,
|
|
257
|
-
algorithm: 'SHA-256'
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
return sessionSecret;
|
|
261
|
-
}
|
|
262
|
-
catch (error) {
|
|
263
|
-
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
264
|
-
throw error;
|
|
265
|
-
}
|
|
266
|
-
finally {
|
|
267
|
-
if (logalot) {
|
|
268
|
-
console.log(`${lc} complete.`);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
async getInitialWeakTransitionSessionSecret({ sagaId, }) {
|
|
273
|
-
const lc = `${this.lc}[${this.getInitialWeakTransitionSessionSecret.name}]`;
|
|
274
|
-
try {
|
|
275
|
-
if (logalot) {
|
|
276
|
-
console.log(`${lc} starting... (I: 872ab81a78827b9f2822b78459203226)`);
|
|
277
|
-
}
|
|
278
|
-
// Create delegate pool bootstrap secret (publicly derivable)
|
|
279
|
-
const initialTransitionSecret = await deriveKey({
|
|
280
|
-
masterSecret: SESSION_IDENTITY_KEYSTONE_SECRET_TRANSITIONPOOL, // Weak, publicly derivable secret
|
|
281
|
-
kdfOpts: {
|
|
282
|
-
strategy: KdfStrategy.recursive_salt_wrap,
|
|
283
|
-
salt: sagaId,
|
|
284
|
-
rounds: 1, // Minimal rounds - this is meant to be weak
|
|
285
|
-
algorithm: 'SHA-256'
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
return initialTransitionSecret;
|
|
289
|
-
}
|
|
290
|
-
catch (error) {
|
|
291
|
-
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
292
|
-
throw error;
|
|
293
|
-
}
|
|
294
|
-
finally {
|
|
295
|
-
if (logalot) {
|
|
296
|
-
console.log(`${lc} complete.`);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
async getTransitionKeystonePool({ sagaId, }) {
|
|
301
|
-
const lc = `${this.lc}[${this.getTransitionKeystonePool.name}]`;
|
|
302
|
-
try {
|
|
303
|
-
if (logalot) {
|
|
304
|
-
console.log(`${lc} starting... (I: 1ec1c8db7438938b08b96559fcee0826)`);
|
|
305
|
-
}
|
|
306
|
-
const config = createStandardPoolConfig({
|
|
307
|
-
salt: sagaId,
|
|
308
|
-
id: SESSION_IDENTITY_KEYSTONE_TRANSITION_POOL_ID,
|
|
309
|
-
type: KeystoneChallengeType.hash_reveal_v1,
|
|
310
|
-
size: SESSION_IDENTITY_KEYSTONE_CONFIG_SIZE_TRANSITIONPOOL,
|
|
311
|
-
replenishStrategy: SESSION_IDENTITY_KEYSTONE_CONFIG_REPLENISH_STRATEGY_TRANSITIONPOOL,
|
|
312
|
-
random: SESSION_IDENTITY_KEYSTONE_CONFIG_RANDOM_TRANSITIONPOOL,
|
|
313
|
-
sequential: SESSION_IDENTITY_KEYSTONE_CONFIG_SEQUENTIAL_TRANSITIONPOOL,
|
|
314
|
-
targetBinding: SESSION_IDENTITY_KEYSTONE_CONFIG_TARGET_BINDING_TRANSITIONPOOL,
|
|
315
|
-
hashAlgorithm: SESSION_IDENTITY_KEYSTONE_CONFIG_ALGO_TRANSITIONPOOL,
|
|
316
|
-
hashRounds: SESSION_IDENTITY_KEYSTONE_CONFIG_ROUNDS_TRANSITIONPOOL,
|
|
317
|
-
verbs: SESSION_IDENTITY_KEYSTONE_CONFIG_VERBS_TRANSITIONPOOL,
|
|
318
|
-
});
|
|
319
|
-
const strategy = KeystoneStrategyFactory.create({ config });
|
|
320
|
-
const poolSecret = await strategy.derivePoolSecret({
|
|
321
|
-
masterSecret: await this.getInitialWeakTransitionSessionSecret({ sagaId }),
|
|
322
|
-
});
|
|
323
|
-
const challenges = {};
|
|
324
|
-
const bindingMap = {};
|
|
325
|
-
const targetSize = config.behavior.size;
|
|
326
|
-
const timestamp = Date.now().toString();
|
|
327
|
-
for (let i = 0; i < targetSize; i++) {
|
|
328
|
-
const challengeId = await generateOpaqueChallengeId({
|
|
329
|
-
salt: config.salt, timestamp, index: i
|
|
330
|
-
});
|
|
331
|
-
const solution = await strategy.generateSolution({
|
|
332
|
-
poolSecret, poolId: config.salt, challengeId,
|
|
333
|
-
});
|
|
334
|
-
const challenge = await strategy.generateChallenge({ solution });
|
|
335
|
-
challenges[challengeId] = challenge;
|
|
336
|
-
// Populate Binding Map
|
|
337
|
-
addToBindingMap(bindingMap, challengeId);
|
|
338
|
-
}
|
|
339
|
-
const transitionPool = {
|
|
340
|
-
id: SESSION_IDENTITY_KEYSTONE_TRANSITION_POOL_ID,
|
|
341
|
-
config,
|
|
342
|
-
challenges,
|
|
343
|
-
bindingMap,
|
|
344
|
-
isForeign: true,
|
|
345
|
-
// metadata: { origin: 'receiver', role: 'delegate' } // don't need metadata since we have the pool id being 'delegate' (i think)
|
|
346
|
-
};
|
|
347
|
-
return transitionPool;
|
|
348
|
-
}
|
|
349
|
-
catch (error) {
|
|
350
|
-
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
351
|
-
throw error;
|
|
352
|
-
}
|
|
353
|
-
finally {
|
|
354
|
-
if (logalot) {
|
|
355
|
-
console.log(`${lc} complete.`);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
async getDelegateKeystonePool({ sagaId, }) {
|
|
360
|
-
const lc = `${this.lc}[${this.getDelegateKeystonePool.name}]`;
|
|
361
|
-
try {
|
|
362
|
-
if (logalot) {
|
|
363
|
-
console.log(`${lc} starting... (I: 6b1d338f8e988e68f8d77e72ed00d526)`);
|
|
364
|
-
}
|
|
365
|
-
// todo: change this to a helper function that does the delegated
|
|
366
|
-
// functionality better. also the f***ing binding map needs better
|
|
367
|
-
// implementation. f***ng glazed over by AI.
|
|
368
|
-
const config = createStandardPoolConfig({
|
|
369
|
-
salt: sagaId,
|
|
370
|
-
id: SESSION_IDENTITY_KEYSTONE_DELEGATE_POOL_ID,
|
|
371
|
-
type: KeystoneChallengeType.hash_reveal_v1,
|
|
372
|
-
size: SESSION_IDENTITY_KEYSTONE_CONFIG_SIZE,
|
|
373
|
-
replenishStrategy: SESSION_IDENTITY_KEYSTONE_CONFIG_REPLENISH_STRATEGY,
|
|
374
|
-
random: SESSION_IDENTITY_KEYSTONE_CONFIG_RANDOM,
|
|
375
|
-
sequential: SESSION_IDENTITY_KEYSTONE_CONFIG_SEQUENTIAL,
|
|
376
|
-
targetBinding: SESSION_IDENTITY_KEYSTONE_CONFIG_TARGET_BINDING,
|
|
377
|
-
hashAlgorithm: SESSION_IDENTITY_KEYSTONE_CONFIG_ALGO,
|
|
378
|
-
hashRounds: SESSION_IDENTITY_KEYSTONE_CONFIG_ROUNDS,
|
|
379
|
-
verbs: SESSION_IDENTITY_KEYSTONE_CONFIG_VERBS_DELEGATE,
|
|
380
|
-
});
|
|
381
|
-
const strategy = KeystoneStrategyFactory.create({ config });
|
|
382
|
-
const poolSecret = await strategy.derivePoolSecret({
|
|
383
|
-
masterSecret: SESSION_IDENTITY_KEYSTONE_SECRET_TRANSITIONPOOL
|
|
384
|
-
});
|
|
385
|
-
const challenges = {};
|
|
386
|
-
const bindingMap = {};
|
|
387
|
-
const targetSize = config.behavior.size;
|
|
388
|
-
const timestamp = Date.now().toString();
|
|
389
|
-
for (let i = 0; i < targetSize; i++) {
|
|
390
|
-
const challengeId = await generateOpaqueChallengeId({
|
|
391
|
-
salt: config.salt, timestamp, index: i
|
|
392
|
-
});
|
|
393
|
-
const solution = await strategy.generateSolution({
|
|
394
|
-
poolSecret, poolId: config.salt, challengeId,
|
|
395
|
-
});
|
|
396
|
-
const challenge = await strategy.generateChallenge({ solution });
|
|
397
|
-
challenges[challengeId] = challenge;
|
|
398
|
-
// Populate Binding Map
|
|
399
|
-
addToBindingMap(bindingMap, challengeId);
|
|
400
|
-
}
|
|
401
|
-
const delegatePool = {
|
|
402
|
-
id: SESSION_IDENTITY_KEYSTONE_DELEGATE_POOL_ID,
|
|
403
|
-
config,
|
|
404
|
-
challenges,
|
|
405
|
-
bindingMap,
|
|
406
|
-
isForeign: true,
|
|
407
|
-
// metadata: { origin: 'receiver', role: 'delegate' } // don't need metadata since we have the pool id being 'delegate' (i think)
|
|
408
|
-
};
|
|
409
|
-
return delegatePool;
|
|
410
|
-
}
|
|
411
|
-
catch (error) {
|
|
412
|
-
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
413
|
-
throw error;
|
|
414
|
-
}
|
|
415
|
-
finally {
|
|
416
|
-
if (logalot) {
|
|
417
|
-
console.log(`${lc} complete.`);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* creates a session identity keystone based off of the given args.
|
|
423
|
-
*
|
|
424
|
-
* Then, if the {@link primaryIdentity} keystone is provided, this also
|
|
425
|
-
* **signs** this keystone pointing to the address of the sess
|
|
426
|
-
* @param param0
|
|
427
|
-
* @returns
|
|
428
|
-
*/
|
|
429
|
-
async createSessionIdentity({ sagaId, primaryIdentity, nonSessionSecret, metaspace, localSpace, }) {
|
|
430
|
-
const lc = `${this.lc}[${this.createSessionIdentity.name}]`;
|
|
431
|
-
try {
|
|
432
|
-
if (logalot) {
|
|
433
|
-
console.log(`${lc} starting... (I: 428392a4ee636b7bd8f7d5d89a87e826)`);
|
|
434
|
-
}
|
|
435
|
-
if (!nonSessionSecret) {
|
|
436
|
-
throw new Error(`(UNEXPECTED) nonSessionSecret falsy? This is expected to be truthy by this point. (E: 8ce053fe59825a6678713128953b9d26)`);
|
|
437
|
-
}
|
|
438
|
-
const primarySessionSecret = await this.deriveSessionSecret({
|
|
439
|
-
sagaId, nonSessionSecret
|
|
440
|
-
});
|
|
441
|
-
// Generate keystone with two initial pools in two steps.
|
|
442
|
-
// 1. Create primary pool with genesis method to correspond to the
|
|
443
|
-
// sender/sender's secret/identity.
|
|
444
|
-
// 2. Create a separate pool and add separately because a
|
|
445
|
-
// different pw + config is used for the transition pool.
|
|
446
|
-
const primaryPoolConfig = {
|
|
447
|
-
allowedVerbs: [KEYSTONE_VERB_MANAGE],
|
|
448
|
-
id: SESSION_IDENTITY_KEYSTONE_PRIMARY_POOL_ID,
|
|
449
|
-
salt: sagaId,
|
|
450
|
-
behavior: {
|
|
451
|
-
size: SESSION_IDENTITY_KEYSTONE_CONFIG_SIZE, // Large pool for many signatures
|
|
452
|
-
replenish: SESSION_IDENTITY_KEYSTONE_CONFIG_REPLENISH_STRATEGY,
|
|
453
|
-
selectSequentially: SESSION_IDENTITY_KEYSTONE_CONFIG_SEQUENTIAL,
|
|
454
|
-
selectRandomly: SESSION_IDENTITY_KEYSTONE_CONFIG_RANDOM,
|
|
455
|
-
targetBindingChars: SESSION_IDENTITY_KEYSTONE_CONFIG_TARGET_BINDING,
|
|
456
|
-
},
|
|
457
|
-
type: KeystoneChallengeType.hash_reveal_v1,
|
|
458
|
-
algo: SESSION_IDENTITY_KEYSTONE_CONFIG_ALGO,
|
|
459
|
-
rounds: SESSION_IDENTITY_KEYSTONE_CONFIG_ROUNDS,
|
|
460
|
-
};
|
|
461
|
-
const sessionIdentity_genesis = await this.keystoneSvc.genesis({
|
|
462
|
-
masterSecret: primarySessionSecret,
|
|
463
|
-
configs: [primaryPoolConfig],
|
|
464
|
-
metaspace,
|
|
465
|
-
space: localSpace,
|
|
466
|
-
});
|
|
467
|
-
// #region sanity validation of genesis keystone
|
|
468
|
-
/**
|
|
469
|
-
* not necessary but since it's a new design, I'm putting in this
|
|
470
|
-
* immediate validation just to put it through its paces. (worth the
|
|
471
|
-
* slight perf hit).
|
|
472
|
-
*/
|
|
473
|
-
const validationErrors = await validateGenesisKeystone({
|
|
474
|
-
keystoneIbGib: sessionIdentity_genesis
|
|
475
|
-
});
|
|
476
|
-
if (validationErrors) {
|
|
477
|
-
throw new Error(`(UNEXPECTED) the sessionIdentity_genesis that we just created already has validation errors just after creation? (E: e9ca08cf0f8858bb1ace8b9fa89f8726)`);
|
|
478
|
-
}
|
|
479
|
-
// #endregion sanity validation of genesis keystone
|
|
480
|
-
const transitionPool = await this.getTransitionKeystonePool({ sagaId });
|
|
481
|
-
/**
|
|
482
|
-
* Note this actually **signs** the initial {@link sessionIdentity_genesis}
|
|
483
|
-
* and requires the use of a pool with management priveleges.
|
|
484
|
-
*/
|
|
485
|
-
const sessionIdentity_withTransitionPool = await this.keystoneSvc.addPools({
|
|
486
|
-
latestKeystone: sessionIdentity_genesis,
|
|
487
|
-
/**
|
|
488
|
-
* this secret does not do the delegate pool challenges,
|
|
489
|
-
* rather, this is the sessionSecret itself to evolve the
|
|
490
|
-
* keystone **to add** the delegate pool in the first place.
|
|
491
|
-
*/
|
|
492
|
-
masterSecret: primarySessionSecret,
|
|
493
|
-
metaspace,
|
|
494
|
-
space: localSpace,
|
|
495
|
-
newPools: [transitionPool],
|
|
496
|
-
});
|
|
497
|
-
let newPrimaryIdentity = undefined;
|
|
498
|
-
if (primaryIdentity) {
|
|
499
|
-
newPrimaryIdentity = await this.keystoneSvc.sign({
|
|
500
|
-
latestKeystone: primaryIdentity,
|
|
501
|
-
poolId: primaryPoolConfig.id,
|
|
502
|
-
claim: {
|
|
503
|
-
verb: KEYSTONE_VERB_SIGN,
|
|
504
|
-
target: getIbGibAddr({ ibGib: sessionIdentity_withTransitionPool }),
|
|
505
|
-
},
|
|
506
|
-
masterSecret: nonSessionSecret,
|
|
507
|
-
metaspace,
|
|
508
|
-
space: localSpace,
|
|
509
|
-
// frameDetails: undefined, // anything to put here?
|
|
510
|
-
// requiredChallengeIds: undefined, // not relevant I think
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
return {
|
|
514
|
-
sessionIdentity: sessionIdentity_withTransitionPool,
|
|
515
|
-
newPrimaryIdentity,
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
catch (error) {
|
|
519
|
-
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
520
|
-
throw error;
|
|
521
|
-
}
|
|
522
|
-
finally {
|
|
523
|
-
if (logalot) {
|
|
524
|
-
console.log(`${lc} complete.`);
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
201
|
/**
|
|
529
202
|
* Drives the FSM loop of the Saga.
|
|
530
203
|
*
|
|
@@ -540,7 +213,7 @@ export class SyncSagaCoordinator {
|
|
|
540
213
|
* the NEXT request context.
|
|
541
214
|
* When the Peer responds with data (in the response context), it is resolved and put into `tempSpace`.
|
|
542
215
|
*/
|
|
543
|
-
async executeSagaLoop({ initFrame, initDomainGraph, peer,
|
|
216
|
+
async executeSagaLoop({ initFrame, initDomainGraph, peer, updates$, localSpace, tempSpace, metaspace }) {
|
|
544
217
|
const lc = `${this.lc}[${this.executeSagaLoop.name}]`;
|
|
545
218
|
/** The current frame we just generated (e.g., Init or Delta Request) */
|
|
546
219
|
let currentFrame = initFrame;
|
|
@@ -589,8 +262,6 @@ export class SyncSagaCoordinator {
|
|
|
589
262
|
// ...create/compose the Request Context itself...
|
|
590
263
|
const requestCtx = await this.createSyncSagaContext({
|
|
591
264
|
sagaFrame: currentFrame,
|
|
592
|
-
sessionKeystone: sessionIdentity,
|
|
593
|
-
sessionSecret: identitySecret,
|
|
594
265
|
/**
|
|
595
266
|
* init frame: empty
|
|
596
267
|
* ack frame: possible push offers
|
|
@@ -614,7 +285,7 @@ export class SyncSagaCoordinator {
|
|
|
614
285
|
// if (logalot) { console.log(`${lc} transmitting... requestCtx: ${pretty(requestCtx)} (I: 8cf20817c66899abdb1e76df50356826)`); }
|
|
615
286
|
updates$.next(requestCtx); // spins off for saga UI updates
|
|
616
287
|
// ...And send the context.
|
|
617
|
-
peer.setOptionalOpts({ localSpace, localTempSpace: tempSpace,
|
|
288
|
+
peer.setOptionalOpts({ localSpace, localTempSpace: tempSpace, });
|
|
618
289
|
const responseCtx = await peer.witness(requestCtx);
|
|
619
290
|
// the send returned, but a peer can return a falsy responseCtx, if
|
|
620
291
|
// we just sent a commit to them and they're done. If so, there will
|
|
@@ -713,10 +384,6 @@ export class SyncSagaCoordinator {
|
|
|
713
384
|
const { frame, payloadIbGibsDomain, } = contextResult.nextFrameInfo;
|
|
714
385
|
currentFrame = frame;
|
|
715
386
|
nextDomainIbGibs = [...(payloadIbGibsDomain || [])];
|
|
716
|
-
// Track identity evolution
|
|
717
|
-
if (responseCtx.signedSessionKeystone) {
|
|
718
|
-
sessionIdentity = responseCtx.signedSessionKeystone;
|
|
719
|
-
}
|
|
720
387
|
// #region Log handler output for next iteration
|
|
721
388
|
if (logalotControlDomain) {
|
|
722
389
|
const handlerDomainAddrs = nextDomainIbGibs.map(p => getIbGibAddr({ ibGib: p }));
|
|
@@ -738,7 +405,7 @@ export class SyncSagaCoordinator {
|
|
|
738
405
|
* the other ibgibs that are related to this context stone should already be
|
|
739
406
|
* put/registered in {@link localSpace}.
|
|
740
407
|
*/
|
|
741
|
-
async createSyncSagaContext({ sagaFrame,
|
|
408
|
+
async createSyncSagaContext({ sagaFrame, payloadIbGibsDomain, metaspace, localSpace, }) {
|
|
742
409
|
const lc = `[${this.createSyncSagaContext.name}]`;
|
|
743
410
|
try {
|
|
744
411
|
if (logalot) {
|
|
@@ -751,9 +418,6 @@ export class SyncSagaCoordinator {
|
|
|
751
418
|
if (!sagaFrame.data.n && sagaFrame.data.n !== 0) {
|
|
752
419
|
throw new Error(`(UNEXPECTED) sagaFrame.data.n falsy and not 0? (E: 45b508da64a8b28428b11765d684b826)`);
|
|
753
420
|
}
|
|
754
|
-
if (sessionKeystone && !sessionSecret) {
|
|
755
|
-
throw new Error(`(UNEXPECTED) sessionKeystone truthy but sessionSecret falsy? (E: 705ecc25038b12df0e94c90c5561e426)`);
|
|
756
|
-
}
|
|
757
421
|
// #endregion sanity/validation
|
|
758
422
|
const date = new Date();
|
|
759
423
|
const timestamp = getTimestamp(date);
|
|
@@ -770,25 +434,10 @@ export class SyncSagaCoordinator {
|
|
|
770
434
|
if (payloadAddrsDomain && payloadAddrsDomain.length > 0) {
|
|
771
435
|
data[SYNC_SAGA_PAYLOAD_ADDRS_DOMAIN] = payloadAddrsDomain;
|
|
772
436
|
}
|
|
773
|
-
// rel8ns should always have saga frame
|
|
437
|
+
// rel8ns should always have saga frame
|
|
774
438
|
const rel8ns = {
|
|
775
439
|
sagaFrame: [getIbGibAddr({ ibGib: sagaFrame })],
|
|
776
440
|
};
|
|
777
|
-
if (sessionKeystone) {
|
|
778
|
-
const keystoneErrors = await validateKeystoneGraph({
|
|
779
|
-
keystoneIbGib: sessionKeystone,
|
|
780
|
-
space: localSpace,
|
|
781
|
-
getLatest: true,
|
|
782
|
-
invalidIfMoreRecentKeystoneFoundInSpace: true,
|
|
783
|
-
});
|
|
784
|
-
if (keystoneErrors.length > 0) {
|
|
785
|
-
throw new Error(`invalid sessionKeystone. errors: ${keystoneErrors} (E: 3881b8caf2d803767a331e1141e84826)`);
|
|
786
|
-
}
|
|
787
|
-
// this addr is BEFORE we sign. So each context ibgib itself will
|
|
788
|
-
// point to the frame of the keystone just before that keystone
|
|
789
|
-
// signs with this context as its target.
|
|
790
|
-
rel8ns.sessionKeystone = [getIbGibAddr({ ibGib: sessionKeystone })];
|
|
791
|
-
}
|
|
792
441
|
// Generate standard ib
|
|
793
442
|
const ib = await getSyncSagaContextIb({ data });
|
|
794
443
|
const contextIbGib = await Factory_V1.stone({
|
|
@@ -810,20 +459,6 @@ export class SyncSagaCoordinator {
|
|
|
810
459
|
if (payloadIbGibsDomain && payloadIbGibsDomain.length > 0) {
|
|
811
460
|
contextIbGib.payloadIbGibsDomain = payloadIbGibsDomain;
|
|
812
461
|
}
|
|
813
|
-
if (sessionKeystone) {
|
|
814
|
-
if (!sessionSecret) {
|
|
815
|
-
throw new Error(`(UNEXPECTED) sessionKeystone truthy but sessionSecret falsy? we should have thrown before now (E: a2b0517a37b559543968b888f2067826)`);
|
|
816
|
-
}
|
|
817
|
-
const contextAddr = getIbGibAddr({ ibGib: contextIbGib });
|
|
818
|
-
contextIbGib.signedSessionKeystone = await this.keystoneSvc.sign({
|
|
819
|
-
latestKeystone: sessionKeystone,
|
|
820
|
-
claim: { target: contextAddr, }, // verb?
|
|
821
|
-
space: localSpace,
|
|
822
|
-
masterSecret: sessionSecret,
|
|
823
|
-
metaspace,
|
|
824
|
-
});
|
|
825
|
-
contextIbGib.fnIdentitySecret = () => Promise.resolve(sessionSecret);
|
|
826
|
-
}
|
|
827
462
|
return contextIbGib;
|
|
828
463
|
}
|
|
829
464
|
catch (error) {
|
|
@@ -921,7 +556,7 @@ export class SyncSagaCoordinator {
|
|
|
921
556
|
* Generates the first frame containing the Knowledge Map of the Local Space.
|
|
922
557
|
* This is sent to the Receiver to begin Gap Analysis.
|
|
923
558
|
*/
|
|
924
|
-
async createInitFrame({ sagaId,
|
|
559
|
+
async createInitFrame({ sagaId, domainIbGibs, conflictStrategy, metaspace, localSpace, tempSpace, }) {
|
|
925
560
|
const lc = `${this.lc}[${this.createInitFrame.name}]`;
|
|
926
561
|
try {
|
|
927
562
|
if (logalot) {
|
|
@@ -944,7 +579,6 @@ export class SyncSagaCoordinator {
|
|
|
944
579
|
sagaId,
|
|
945
580
|
stage: SyncStage.init,
|
|
946
581
|
knowledgeMap: knowledgeMap,
|
|
947
|
-
identity: sessionIdentity, // KeystoneIbGib is already public data
|
|
948
582
|
mode: SyncMode.sync,
|
|
949
583
|
stones: srcStones.map(s => getIbGibAddr({ ibGib: s })),
|
|
950
584
|
};
|
|
@@ -963,7 +597,6 @@ export class SyncSagaCoordinator {
|
|
|
963
597
|
const sagaFrame = await this.evolveSyncSagaIbGib({
|
|
964
598
|
msgStones: [initStone],
|
|
965
599
|
conflictStrategy,
|
|
966
|
-
sessionIdentity,
|
|
967
600
|
metaspace,
|
|
968
601
|
localSpace,
|
|
969
602
|
});
|
|
@@ -1066,7 +699,7 @@ export class SyncSagaCoordinator {
|
|
|
1066
699
|
* receiver, since the sender's {@link executeSagaLoop} is what actually
|
|
1067
700
|
* drives the ping-pong process.
|
|
1068
701
|
*/
|
|
1069
|
-
async handleResponseSagaContext({ sagaContext, initDomainGraph, mySpace, myTempSpace,
|
|
702
|
+
async handleResponseSagaContext({ sagaContext, initDomainGraph, mySpace, myTempSpace, metaspace, }) {
|
|
1070
703
|
const lc = `${this.lc}[${this.handleResponseSagaContext.name}]`;
|
|
1071
704
|
try {
|
|
1072
705
|
if (logalot) {
|
|
@@ -1091,7 +724,6 @@ export class SyncSagaCoordinator {
|
|
|
1091
724
|
sagaIbGib,
|
|
1092
725
|
messageData: messageData,
|
|
1093
726
|
metaspace, mySpace, myTempSpace,
|
|
1094
|
-
identity,
|
|
1095
727
|
});
|
|
1096
728
|
break;
|
|
1097
729
|
case SyncStage.ack:
|
|
@@ -1103,7 +735,6 @@ export class SyncSagaCoordinator {
|
|
|
1103
735
|
sagaIbGib,
|
|
1104
736
|
initDomainGraph,
|
|
1105
737
|
metaspace, mySpace, myTempSpace,
|
|
1106
|
-
identity,
|
|
1107
738
|
});
|
|
1108
739
|
break;
|
|
1109
740
|
case SyncStage.delta:
|
|
@@ -1111,7 +742,6 @@ export class SyncSagaCoordinator {
|
|
|
1111
742
|
sagaContext,
|
|
1112
743
|
sagaIbGib,
|
|
1113
744
|
metaspace, mySpace, myTempSpace,
|
|
1114
|
-
identity,
|
|
1115
745
|
});
|
|
1116
746
|
break;
|
|
1117
747
|
case SyncStage.commit:
|
|
@@ -1121,7 +751,6 @@ export class SyncSagaCoordinator {
|
|
|
1121
751
|
nextFrameInfo = await this.handleCommitFrame({
|
|
1122
752
|
sagaIbGib,
|
|
1123
753
|
metaspace, mySpace, myTempSpace,
|
|
1124
|
-
identity,
|
|
1125
754
|
});
|
|
1126
755
|
break;
|
|
1127
756
|
default:
|
|
@@ -1156,7 +785,7 @@ export class SyncSagaCoordinator {
|
|
|
1156
785
|
* 3. Identifies what Receiver needs (`deltaRequestAddrInfos`).
|
|
1157
786
|
* 4. Returns an `Ack` frame containing these lists.
|
|
1158
787
|
*/
|
|
1159
|
-
async handleInitFrame({ sagaIbGib, messageData, mySpace, myTempSpace, metaspace,
|
|
788
|
+
async handleInitFrame({ sagaIbGib, messageData, mySpace, myTempSpace, metaspace, }) {
|
|
1160
789
|
const lc = `${this.lc}[${this.handleInitFrame.name}]`;
|
|
1161
790
|
try {
|
|
1162
791
|
if (logalot) {
|
|
@@ -1430,7 +1059,6 @@ export class SyncSagaCoordinator {
|
|
|
1430
1059
|
const ackFrame = await this.evolveSyncSagaIbGib({
|
|
1431
1060
|
prevSagaIbGib: sagaIbGib,
|
|
1432
1061
|
msgStones: [ackStone],
|
|
1433
|
-
sessionIdentity: identity,
|
|
1434
1062
|
localSpace: mySpace,
|
|
1435
1063
|
metaspace,
|
|
1436
1064
|
});
|
|
@@ -1525,7 +1153,7 @@ export class SyncSagaCoordinator {
|
|
|
1525
1153
|
*
|
|
1526
1154
|
* Returns a `Delta` frame.
|
|
1527
1155
|
*/
|
|
1528
|
-
async handleAckFrame({ sagaContext, sagaIbGib, initDomainGraph, mySpace, myTempSpace, metaspace,
|
|
1156
|
+
async handleAckFrame({ sagaContext, sagaIbGib, initDomainGraph, mySpace, myTempSpace, metaspace, }) {
|
|
1529
1157
|
const lc = `${this.lc}[${this.handleAckFrame.name}]`;
|
|
1530
1158
|
try {
|
|
1531
1159
|
if (logalot) {
|
|
@@ -1754,16 +1382,14 @@ export class SyncSagaCoordinator {
|
|
|
1754
1382
|
const deltaFrame = await this.evolveSyncSagaIbGib({
|
|
1755
1383
|
prevSagaIbGib: sagaIbGib,
|
|
1756
1384
|
msgStones: [deltaStone],
|
|
1757
|
-
sessionIdentity: identity,
|
|
1758
1385
|
localSpace: mySpace,
|
|
1759
1386
|
metaspace,
|
|
1760
1387
|
});
|
|
1761
1388
|
if (logalot) {
|
|
1762
1389
|
console.log(`${lc} Delta Frame created. Rel8ns: ${JSON.stringify(deltaFrame.rel8ns)}`);
|
|
1763
1390
|
}
|
|
1764
|
-
// Build control payloads: frame + its dependencies (msg stone
|
|
1391
|
+
// Build control payloads: frame + its dependencies (msg stone)
|
|
1765
1392
|
// const payloadIbGibsControl: IbGib_V1[] = [deltaFrame, deltaStone];
|
|
1766
|
-
// if (identity) { payloadIbGibsControl.push(identity); }
|
|
1767
1393
|
return { frame: deltaFrame, payloadIbGibsDomain: outgoingPayloadsDomain_all, };
|
|
1768
1394
|
}
|
|
1769
1395
|
catch (error) {
|
|
@@ -1789,7 +1415,7 @@ export class SyncSagaCoordinator {
|
|
|
1789
1415
|
* we just have the receiver do the merging, since they should have full
|
|
1790
1416
|
* knowledge at that point for most (all?) cases AFAICT.
|
|
1791
1417
|
*/
|
|
1792
|
-
async handleDeltaFrame({ sagaContext, sagaIbGib, mySpace, myTempSpace, metaspace,
|
|
1418
|
+
async handleDeltaFrame({ sagaContext, sagaIbGib, mySpace, myTempSpace, metaspace, }) {
|
|
1793
1419
|
const lc = `${this.lc}[${this.handleDeltaFrame.name}]`;
|
|
1794
1420
|
try {
|
|
1795
1421
|
if (logalot) {
|
|
@@ -1994,7 +1620,6 @@ export class SyncSagaCoordinator {
|
|
|
1994
1620
|
const deltaFrame = await this.evolveSyncSagaIbGib({
|
|
1995
1621
|
prevSagaIbGib: sagaIbGib,
|
|
1996
1622
|
msgStones: [deltaStone],
|
|
1997
|
-
sessionIdentity: identity,
|
|
1998
1623
|
localSpace: mySpace,
|
|
1999
1624
|
metaspace,
|
|
2000
1625
|
});
|
|
@@ -2017,7 +1642,6 @@ export class SyncSagaCoordinator {
|
|
|
2017
1642
|
sagaIbGib,
|
|
2018
1643
|
errors: validationErrors,
|
|
2019
1644
|
metaspace, mySpace,
|
|
2020
|
-
identity,
|
|
2021
1645
|
});
|
|
2022
1646
|
return { frame: errorCommitFrame, }; /* <<<< returns early */
|
|
2023
1647
|
}
|
|
@@ -2033,7 +1657,6 @@ export class SyncSagaCoordinator {
|
|
|
2033
1657
|
errors: undefined,
|
|
2034
1658
|
metaspace,
|
|
2035
1659
|
mySpace,
|
|
2036
|
-
identity,
|
|
2037
1660
|
});
|
|
2038
1661
|
return { frame: commitFrame, };
|
|
2039
1662
|
}
|
|
@@ -2055,7 +1678,6 @@ export class SyncSagaCoordinator {
|
|
|
2055
1678
|
const deltaFrame = await this.evolveSyncSagaIbGib({
|
|
2056
1679
|
prevSagaIbGib: sagaIbGib,
|
|
2057
1680
|
msgStones: [deltaStone],
|
|
2058
|
-
sessionIdentity: identity,
|
|
2059
1681
|
localSpace: mySpace,
|
|
2060
1682
|
metaspace
|
|
2061
1683
|
});
|
|
@@ -2079,20 +1701,11 @@ export class SyncSagaCoordinator {
|
|
|
2079
1701
|
const commitFrame = await this.evolveSyncSagaIbGib({
|
|
2080
1702
|
prevSagaIbGib: deltaFrame, // Build on top of the Delta we just created/persisted
|
|
2081
1703
|
msgStones: [commitStone],
|
|
2082
|
-
sessionIdentity: identity,
|
|
2083
1704
|
localSpace: mySpace,
|
|
2084
1705
|
metaspace
|
|
2085
1706
|
});
|
|
2086
|
-
// Build control payloads for commit
|
|
2087
|
-
const commitCtrlPayloads2 = [commitFrame, commitStone];
|
|
2088
|
-
if (identity) {
|
|
2089
|
-
commitCtrlPayloads2.push(identity);
|
|
2090
|
-
}
|
|
2091
1707
|
return { frame: commitFrame, };
|
|
2092
1708
|
}
|
|
2093
|
-
// Build control payloads for delta propose
|
|
2094
|
-
// const deltaCtrlPayloads: IbGib_V1[] = [deltaFrame, deltaStone];
|
|
2095
|
-
// if (identity) { deltaCtrlPayloads.push(identity); }
|
|
2096
1709
|
return { frame: deltaFrame, payloadIbGibsDomain: outgoingPayload };
|
|
2097
1710
|
}
|
|
2098
1711
|
}
|
|
@@ -2110,7 +1723,7 @@ export class SyncSagaCoordinator {
|
|
|
2110
1723
|
/**
|
|
2111
1724
|
* should throw if fails
|
|
2112
1725
|
*/
|
|
2113
|
-
async executeLocalCommit({ deltaFrame, commitFrame, sagaHistory, metaspace, localSpace, localTempSpace,
|
|
1726
|
+
async executeLocalCommit({ deltaFrame, commitFrame, sagaHistory, metaspace, localSpace, localTempSpace, }) {
|
|
2114
1727
|
const lc = `${this.lc}[${this.executeLocalCommit.name}]`;
|
|
2115
1728
|
try {
|
|
2116
1729
|
if (logalot) {
|
|
@@ -2382,7 +1995,7 @@ export class SyncSagaCoordinator {
|
|
|
2382
1995
|
}
|
|
2383
1996
|
}
|
|
2384
1997
|
}
|
|
2385
|
-
async createCommitFrame({ sagaIbGib, errors, metaspace, mySpace,
|
|
1998
|
+
async createCommitFrame({ sagaIbGib, errors, metaspace, mySpace, }) {
|
|
2386
1999
|
const lc = `[${this.createCommitFrame.name}]`;
|
|
2387
2000
|
try {
|
|
2388
2001
|
if (logalot) {
|
|
@@ -2410,7 +2023,6 @@ export class SyncSagaCoordinator {
|
|
|
2410
2023
|
const commitFrame = await this.evolveSyncSagaIbGib({
|
|
2411
2024
|
prevSagaIbGib: sagaIbGib,
|
|
2412
2025
|
msgStones: [commitStone],
|
|
2413
|
-
sessionIdentity: identity,
|
|
2414
2026
|
localSpace: mySpace,
|
|
2415
2027
|
metaspace,
|
|
2416
2028
|
});
|
|
@@ -2426,7 +2038,7 @@ export class SyncSagaCoordinator {
|
|
|
2426
2038
|
}
|
|
2427
2039
|
}
|
|
2428
2040
|
}
|
|
2429
|
-
async handleCommitFrame({ sagaIbGib, mySpace, myTempSpace, metaspace,
|
|
2041
|
+
async handleCommitFrame({ sagaIbGib, mySpace, myTempSpace, metaspace, }) {
|
|
2430
2042
|
const lc = `${this.lc}[${this.handleCommitFrame.name}]`;
|
|
2431
2043
|
try {
|
|
2432
2044
|
if (logalot) {
|
|
@@ -2461,7 +2073,6 @@ export class SyncSagaCoordinator {
|
|
|
2461
2073
|
sagaIbGib,
|
|
2462
2074
|
metaspace,
|
|
2463
2075
|
mySpace,
|
|
2464
|
-
identity,
|
|
2465
2076
|
errors: validationErrors,
|
|
2466
2077
|
});
|
|
2467
2078
|
return { frame: errorCommitFrame, }; /* <<<< returns early */
|
|
@@ -2491,7 +2102,6 @@ export class SyncSagaCoordinator {
|
|
|
2491
2102
|
errors: [emsg],
|
|
2492
2103
|
metaspace,
|
|
2493
2104
|
mySpace,
|
|
2494
|
-
identity,
|
|
2495
2105
|
});
|
|
2496
2106
|
return { frame: errorCommitFrame };
|
|
2497
2107
|
}
|
|
@@ -2599,7 +2209,7 @@ export class SyncSagaCoordinator {
|
|
|
2599
2209
|
/**
|
|
2600
2210
|
* Evolves the saga timeline with a new frame.
|
|
2601
2211
|
*/
|
|
2602
|
-
async evolveSyncSagaIbGib({ prevSagaIbGib, conflictStrategy, msgStones,
|
|
2212
|
+
async evolveSyncSagaIbGib({ prevSagaIbGib, conflictStrategy, msgStones, localSpace, metaspace, }) {
|
|
2603
2213
|
const lc = `${this.lc}[${this.evolveSyncSagaIbGib.name}]`;
|
|
2604
2214
|
try {
|
|
2605
2215
|
// Validation
|
|
@@ -2622,7 +2232,6 @@ export class SyncSagaCoordinator {
|
|
|
2622
2232
|
throw new Error(`${lc} Mismatched stage in stones. Expected ${stage}, got ${d.stage} (E: d12c6571b0882f762921b60880c3f826)`);
|
|
2623
2233
|
}
|
|
2624
2234
|
}
|
|
2625
|
-
const identityAddr = sessionIdentity ? getIbGibAddr({ ibGib: sessionIdentity }) : undefined;
|
|
2626
2235
|
if (prevSagaIbGib) {
|
|
2627
2236
|
/**
|
|
2628
2237
|
* rel8ns always include the new msg stone(s)
|
|
@@ -2633,10 +2242,6 @@ export class SyncSagaCoordinator {
|
|
|
2633
2242
|
ibGibs: msgStones,
|
|
2634
2243
|
}
|
|
2635
2244
|
];
|
|
2636
|
-
// if we're authenticating/signing, we'll have identity
|
|
2637
|
-
if (sessionIdentity) {
|
|
2638
|
-
rel8nInfos.push({ rel8nName: 'identity', ibGibs: [sessionIdentity], });
|
|
2639
|
-
}
|
|
2640
2245
|
// remove the existing sync msg stones' addrs
|
|
2641
2246
|
if (!prevSagaIbGib.rel8ns) {
|
|
2642
2247
|
throw new Error(`(UNEXPECTED) prevSagaIbGib.rel8ns falsy? (E: 81375841aff85b1e48ea42ca218e6826)`);
|
|
@@ -2676,13 +2281,6 @@ export class SyncSagaCoordinator {
|
|
|
2676
2281
|
// rel8ns
|
|
2677
2282
|
const stoneAddrs = msgStones.map(s => getIbGibAddr({ ibGib: s }));
|
|
2678
2283
|
const rel8ns = { [SYNC_MSG_REL8N_NAME]: stoneAddrs, };
|
|
2679
|
-
if (identityAddr) {
|
|
2680
|
-
rel8ns.identity = [identityAddr];
|
|
2681
|
-
}
|
|
2682
|
-
// Attach session keystone to saga frame via hard rel8n
|
|
2683
|
-
if (sessionIdentity) {
|
|
2684
|
-
rel8ns.sessionKeystone = [getIbGibAddr({ ibGib: sessionIdentity })];
|
|
2685
|
-
}
|
|
2686
2284
|
const resNew = await createTimeline({
|
|
2687
2285
|
space: localSpace,
|
|
2688
2286
|
metaspace,
|