@ibgib/core-gib 0.1.53 → 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.
Files changed (189) hide show
  1. package/CHANGELOG.md +16 -2
  2. package/README.md +12 -15
  3. package/dist/keystone/aggregate-details.respec.d.mts +2 -0
  4. package/dist/keystone/aggregate-details.respec.d.mts.map +1 -0
  5. package/dist/keystone/aggregate-details.respec.mjs +118 -0
  6. package/dist/keystone/aggregate-details.respec.mjs.map +1 -0
  7. package/dist/keystone/keystone-constants.d.mts +5 -0
  8. package/dist/keystone/keystone-constants.d.mts.map +1 -1
  9. package/dist/keystone/keystone-constants.mjs +6 -1
  10. package/dist/keystone/keystone-constants.mjs.map +1 -1
  11. package/dist/keystone/keystone-helpers.d.mts +7 -1
  12. package/dist/keystone/keystone-helpers.d.mts.map +1 -1
  13. package/dist/keystone/keystone-helpers.mjs +5 -2
  14. package/dist/keystone/keystone-helpers.mjs.map +1 -1
  15. package/dist/keystone/keystone-service-v1.d.mts +51 -0
  16. package/dist/keystone/keystone-service-v1.d.mts.map +1 -1
  17. package/dist/keystone/keystone-service-v1.mjs +176 -9
  18. package/dist/keystone/keystone-service-v1.mjs.map +1 -1
  19. package/dist/keystone/keystone-service-v1.respec.mjs +40 -98
  20. package/dist/keystone/keystone-service-v1.respec.mjs.map +1 -1
  21. package/dist/keystone/keystone-types.d.mts +5 -0
  22. package/dist/keystone/keystone-types.d.mts.map +1 -1
  23. package/dist/sync/graft-info/graft-info-helpers.respec.mjs +8 -8
  24. package/dist/sync/graft-info/graft-info-helpers.respec.mjs.map +1 -1
  25. package/dist/sync/sync-conflict-adv-multitimelines.respec.mjs +26 -30
  26. package/dist/sync/sync-conflict-adv-multitimelines.respec.mjs.map +1 -1
  27. package/dist/sync/sync-conflict-basic-divergence.respec.mjs +7 -8
  28. package/dist/sync/sync-conflict-basic-divergence.respec.mjs.map +1 -1
  29. package/dist/sync/sync-conflict-basic-multitimelines.respec.mjs +10 -11
  30. package/dist/sync/sync-conflict-basic-multitimelines.respec.mjs.map +1 -1
  31. package/dist/sync/sync-conflict-text-merge.respec.mjs +30 -33
  32. package/dist/sync/sync-conflict-text-merge.respec.mjs.map +1 -1
  33. package/dist/sync/sync-constants.d.mts +1 -56
  34. package/dist/sync/sync-constants.d.mts.map +1 -1
  35. package/dist/sync/sync-constants.mjs +2 -59
  36. package/dist/sync/sync-constants.mjs.map +1 -1
  37. package/dist/sync/sync-helpers.d.mts +0 -1
  38. package/dist/sync/sync-helpers.d.mts.map +1 -1
  39. package/dist/sync/sync-helpers.mjs +1 -6
  40. package/dist/sync/sync-helpers.mjs.map +1 -1
  41. package/dist/sync/sync-innerspace-constants.respec.mjs +5 -9
  42. package/dist/sync/sync-innerspace-constants.respec.mjs.map +1 -1
  43. package/dist/sync/sync-innerspace-deep-updates.respec.mjs +6 -7
  44. package/dist/sync/sync-innerspace-deep-updates.respec.mjs.map +1 -1
  45. package/dist/sync/sync-innerspace-dest-ahead-withid.respec.mjs +22 -22
  46. package/dist/sync/sync-innerspace-dest-ahead-withid.respec.mjs.map +1 -1
  47. package/dist/sync/sync-innerspace-dest-ahead.respec.mjs +8 -9
  48. package/dist/sync/sync-innerspace-dest-ahead.respec.mjs.map +1 -1
  49. package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs +6 -7
  50. package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs.map +1 -1
  51. package/dist/sync/sync-innerspace-partial-update.respec.mjs +7 -8
  52. package/dist/sync/sync-innerspace-partial-update.respec.mjs.map +1 -1
  53. package/dist/sync/sync-innerspace.respec.mjs +8 -11
  54. package/dist/sync/sync-innerspace.respec.mjs.map +1 -1
  55. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-http-node-adapter.mjs +10 -5
  56. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-http-node-adapter.mjs.map +1 -1
  57. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-types.d.mts +3 -1
  58. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-types.d.mts.map +1 -1
  59. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.d.mts +4 -2
  60. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.d.mts.map +1 -1
  61. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.mjs +37 -6
  62. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.mjs.map +1 -1
  63. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-types.d.mts +3 -1
  64. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-types.d.mts.map +1 -1
  65. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.d.mts +4 -2
  66. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.d.mts.map +1 -1
  67. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.mjs +37 -0
  68. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.mjs.map +1 -1
  69. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.d.mts +7 -1
  70. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.d.mts.map +1 -1
  71. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts +10 -2
  72. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts.map +1 -1
  73. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs +50 -38
  74. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs.map +1 -1
  75. package/dist/sync/sync-peer/sync-peer-types.d.mts +21 -5
  76. package/dist/sync/sync-peer/sync-peer-types.d.mts.map +1 -1
  77. package/dist/sync/sync-peer/sync-peer-v1.d.mts +30 -5
  78. package/dist/sync/sync-peer/sync-peer-v1.d.mts.map +1 -1
  79. package/dist/sync/sync-peer/sync-peer-v1.mjs +41 -25
  80. package/dist/sync/sync-peer/sync-peer-v1.mjs.map +1 -1
  81. package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts +2 -11
  82. package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts.map +1 -1
  83. package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs +7 -51
  84. package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs.map +1 -1
  85. package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts +1 -47
  86. package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts.map +1 -1
  87. package/dist/sync/sync-saga-coordinator.d.mts +6 -58
  88. package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
  89. package/dist/sync/sync-saga-coordinator.mjs +23 -425
  90. package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
  91. package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts +2 -2
  92. package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts.map +1 -1
  93. package/dist/sync/sync-types.d.mts +2 -19
  94. package/dist/sync/sync-types.d.mts.map +1 -1
  95. package/dist/sync/sync-types.mjs.map +1 -1
  96. package/dist/test/mock-space.mjs +1 -1
  97. package/dist/test/mock-space.mjs.map +1 -1
  98. package/dist/test-helpers.d.mts +0 -6
  99. package/dist/test-helpers.d.mts.map +1 -1
  100. package/dist/test-helpers.mjs +2 -25
  101. package/dist/test-helpers.mjs.map +1 -1
  102. package/package.json +10 -34
  103. package/src/keystone/aggregate-details.respec.mts +137 -0
  104. package/src/keystone/docs/architecture.md +16 -0
  105. package/src/keystone/keystone-constants.mts +6 -1
  106. package/src/keystone/keystone-helpers.mts +9 -1
  107. package/src/keystone/keystone-service-v1.mts +216 -8
  108. package/src/keystone/keystone-service-v1.respec.mts +39 -103
  109. package/src/keystone/keystone-types.mts +6 -0
  110. package/src/sync/README.md +18 -0
  111. package/src/sync/docs/architecture.md +21 -0
  112. package/src/sync/graft-info/graft-info-helpers.respec.mts +7 -7
  113. package/src/sync/sync-conflict-adv-multitimelines.respec.mts +25 -29
  114. package/src/sync/sync-conflict-basic-divergence.respec.mts +6 -7
  115. package/src/sync/sync-conflict-basic-multitimelines.respec.mts +9 -10
  116. package/src/sync/sync-conflict-text-merge.respec.mts +29 -32
  117. package/src/sync/sync-constants.mts +2 -62
  118. package/src/sync/sync-helpers.mts +1 -8
  119. package/src/sync/sync-id-testlog.txt +421 -0
  120. package/src/sync/sync-innerspace-constants.respec.mts +4 -8
  121. package/src/sync/sync-innerspace-deep-updates.respec.mts +5 -6
  122. package/src/sync/sync-innerspace-dest-ahead-withid.respec.mts +23 -25
  123. package/src/sync/sync-innerspace-dest-ahead.respec.mts +7 -8
  124. package/src/sync/sync-innerspace-multiple-timelines.respec.mts +5 -6
  125. package/src/sync/sync-innerspace-partial-update.respec.mts +6 -7
  126. package/src/sync/sync-innerspace.respec.mts +7 -10
  127. package/src/sync/sync-peer/sync-peer-http-receiver/sync-http-node-adapter.mts +5 -5
  128. package/src/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-types.mts +5 -1
  129. package/src/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.mts +30 -9
  130. package/src/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-types.mts +3 -1
  131. package/src/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.mts +29 -2
  132. package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.mts +7 -1
  133. package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mts +51 -38
  134. package/src/sync/sync-peer/sync-peer-types.mts +23 -6
  135. package/src/sync/sync-peer/sync-peer-v1.mts +68 -28
  136. package/src/sync/sync-saga-context/sync-saga-context-helpers.mts +6 -66
  137. package/src/sync/sync-saga-context/sync-saga-context-types.mts +1 -48
  138. package/src/sync/sync-saga-coordinator.mts +12 -552
  139. package/src/sync/sync-saga-message/sync-saga-message-types.mts +2 -3
  140. package/src/sync/sync-types.mts +2 -22
  141. package/src/sync/unused-identity-backup.mts.md +311 -0
  142. package/src/test/mock-space.mts +1 -1
  143. package/src/test-helpers.mts +1 -26
  144. package/test_output.log +0 -0
  145. package/test_output_utf8.txt +398 -0
  146. package/.vscode/core-gib-snippets.code-snippets +0 -293
  147. package/.vscode/launch.json +0 -40
  148. package/.vscode/settings.json +0 -58
  149. package/.vscode/tasks.json +0 -37
  150. package/dist/sync/sync-peer/sync-peer-http.respec.d.mts +0 -2
  151. package/dist/sync/sync-peer/sync-peer-http.respec.d.mts.map +0 -1
  152. package/dist/sync/sync-peer/sync-peer-http.respec.mjs +0 -340
  153. package/dist/sync/sync-peer/sync-peer-http.respec.mjs.map +0 -1
  154. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.d.mts +0 -42
  155. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.d.mts.map +0 -1
  156. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.mjs +0 -312
  157. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.mjs.map +0 -1
  158. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.d.mts +0 -84
  159. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.d.mts.map +0 -1
  160. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.mjs +0 -65
  161. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.mjs.map +0 -1
  162. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.d.mts +0 -73
  163. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.d.mts.map +0 -1
  164. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.mjs +0 -667
  165. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.mjs.map +0 -1
  166. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.d.mts +0 -2
  167. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.d.mts.map +0 -1
  168. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.mjs +0 -67
  169. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.mjs.map +0 -1
  170. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.d.mts +0 -2
  171. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.d.mts.map +0 -1
  172. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.mjs +0 -67
  173. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.mjs.map +0 -1
  174. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.d.mts +0 -2
  175. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.d.mts.map +0 -1
  176. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.mjs +0 -68
  177. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.mjs.map +0 -1
  178. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.d.mts +0 -2
  179. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.d.mts.map +0 -1
  180. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.mjs +0 -69
  181. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.mjs.map +0 -1
  182. package/src/sync/sync-peer/sync-peer-http.respec.mts +0 -396
  183. package/src/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.mts +0 -298
  184. package/src/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.mts +0 -150
  185. package/src/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.mts +0 -666
  186. package/src/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.mts +0 -87
  187. package/src/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.mts +0 -88
  188. package/src/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.mts +0 -88
  189. package/src/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.mts +0 -90
@@ -1,7 +1,6 @@
1
1
  import { IbGib_V1, IbGibData_V1, IbGibRel8ns_V1 } from "@ibgib/ts-gib/dist/V1/types.mjs";
2
2
  import { IbGibAddr } from "@ibgib/ts-gib/dist/types.mjs";
3
3
 
4
- import { KeystoneIbGib_V1 } from "../../keystone/keystone-types.mjs";
5
4
  import { SyncStage } from "../sync-constants.mjs";
6
5
  import { SyncMode, } from "../sync-types.mjs";
7
6
  import { SyncConflictStrategy, } from "../sync-constants.mjs";
@@ -17,7 +16,7 @@ export interface SyncSagaMessageIb_V1 {
17
16
 
18
17
  export interface SyncSagaMessageData_V1 extends IbGibData_V1 {
19
18
  /**
20
- * Unique ID for the synchronization session (saga).
19
+ * Unique ID for the synchronization saga.
21
20
  */
22
21
  sagaId: string;
23
22
 
@@ -299,7 +298,7 @@ export interface SyncSagaMessageDeltaData_V1 extends SyncSagaMessageData_V1 {
299
298
  export interface SyncSagaMessageCommitData_V1 extends SyncSagaMessageData_V1 {
300
299
  stage: typeof SyncStage.commit;
301
300
  /**
302
- * True if the session completed successfully from the sender's perspective.
301
+ * True if the saga completed successfully from the sender's perspective.
303
302
  */
304
303
  success: boolean;
305
304
  /**
@@ -3,7 +3,6 @@ import { IbGib_V1, IbGibData_V1, IbGibRel8ns_V1 } from "@ibgib/ts-gib/dist/V1/ty
3
3
 
4
4
  import { SubjectWitness } from "../common/pubsub/subject/subject-types.mjs";
5
5
  import { SyncSagaContextIbGib_V1 } from "./sync-saga-context/sync-saga-context-types.mjs";
6
- import { KeystoneIbGib_V1, } from "../keystone/keystone-types.mjs";
7
6
  import { SYNC_ATOM, SYNC_MSG_REL8N_NAME, SyncConflictStrategy, } from "./sync-constants.mjs";
8
7
  import { IbGibSpaceAny } from "../witness/space/space-base-v1.mjs";
9
8
  import { MetaspaceService } from "../witness/space/metaspace/metaspace-types.mjs";
@@ -125,9 +124,7 @@ export interface SyncSagaInfo {
125
124
 
126
125
  export interface SyncSagaFrameDependencyGraph {
127
126
  sagaIbGib: SyncIbGib_V1;
128
- // msgStones: IbGib_V1[];
129
127
  msgStones: SyncSagaMessageIbGib_V1[];
130
- identities: KeystoneIbGib_V1[];
131
128
  }
132
129
 
133
130
  /**
@@ -160,7 +157,8 @@ export interface SyncIb_V1 {
160
157
 
161
158
  export interface SyncData_V1 extends IbGibData_V1 {
162
159
  /**
163
- * Unique ID for this synchronization session.
160
+ * Unique ID for this sync saga. This should correspond to sagaId.
161
+ *
164
162
  * Corresponds to `uuid` in standard IbGibData.
165
163
  */
166
164
  uuid: string;
@@ -189,24 +187,6 @@ export interface SyncData_V1 extends IbGibData_V1 {
189
187
  }
190
188
 
191
189
  export interface SyncRel8ns_V1 extends IbGibRel8ns_V1 {
192
- /**
193
- * Link to the Keystone Identity performing this step.
194
- * This MUST point to the specific Keystone Frame that authorizes this sync frame.
195
- */
196
- identity?: string[];
197
-
198
- /**
199
- * Session keystones used for signing saga frames.
200
- *
201
- * Array contains addresses of keystone evolution chain:
202
- * - Index 0: Genesis keystone (dual-pool architecture)
203
- * - Index N: Latest evolved keystone after signing operations
204
- *
205
- * Each sync endpoint retrieves the session keystone from this rel8n
206
- * rather than searching spaces. Keystones are stored in durable spaces.
207
- */
208
- sessionKeystone?: IbGibAddr[];
209
-
210
190
  /**
211
191
  * The message stone that contains the information about the particular
212
192
  * stage of the sync process we are in.
@@ -0,0 +1,311 @@
1
+ I am removing ALL identity/session/identities/keystone-related code from sync
2
+ and starting over, now that I have a clearer idea of the requirements.
3
+
4
+ This is code that I thought would be reusable with minimal adjustments later.
5
+
6
+ TODO: I have mangled some of the hits for these terms by adding a space after
7
+ the first letter. After i am done, need to go back through and search for "k
8
+ eystone", "i dentity" "s ession" for these mangled terms.
9
+
10
+ ```typescript
11
+ import { KeystoneIbGib_V1, } from "../keystone/keystone-types.mjs";
12
+ import { KeystoneService_V1 } from '../../keystone/keystone-service-v1.mjs';
13
+ import { validateKeystoneGraph, validateKeystoneTransition } from '../../keystone/keystone-helpers.mjs';
14
+
15
+ /**
16
+ * creates a session identity keystone based off of the given args.
17
+ *
18
+ * Then, if the {@link primaryIdentity} keystone is provided, this also
19
+ * **signs** this keystone pointing to the address of the sess
20
+ */
21
+ public async createSessionIdentity({
22
+ sagaId,
23
+ primaryIdentity,
24
+ nonSessionSecret,
25
+ metaspace,
26
+ localSpace,
27
+ }: {
28
+ /**
29
+ * unique to any one particular saga.
30
+ */
31
+ sagaId: string,
32
+ /**
33
+ * optional main identity, e.g., Alice's keystone
34
+ */
35
+ primaryIdentity: KeystoneIbGib_V1 | undefined,
36
+ /**
37
+ * driving secret behind the sync operation. usually, this will be the
38
+ * secret corresponding to a primary identity keystone. But this can
39
+ * also just be a one-time secret just to have more security in the
40
+ * transmission intrinsically.
41
+ */
42
+ nonSessionSecret: string,
43
+ metaspace: MetaspaceService,
44
+ localSpace: IbGibSpaceAny,
45
+ }): Promise<{
46
+ sessionIdentity: KeystoneIbGib_V1,
47
+ sessionSecret: string,
48
+ /**
49
+ * if truthy, this evolved from the incoming {@link primaryIdentity} and
50
+ * has already persisted/registered in the incoming {@link localSpace}.
51
+ */
52
+ newPrimaryIdentity: KeystoneIbGib_V1 | undefined
53
+ }> {
54
+ const lc = `${this.lc}[${this.createSessionIdentity.name}]`;
55
+ try {
56
+ if (logalot) { console.log(`${lc} starting... (I: 428392a4ee636b7bd8f7d5d89a87e826)`); }
57
+
58
+ if (!nonSessionSecret) { throw new Error(`(UNEXPECTED) nonSessionSecret falsy? This is expected to be truthy by this point. (E: 8ce053fe59825a6678713128953b9d26)`); }
59
+
60
+ debugger; // step through create session id
61
+ const sessionSecret = await this.deriveSessionSecret({
62
+ sagaId, nonSessionSecret
63
+ });
64
+
65
+ // Generate keystone with two initial pools in two steps.
66
+ // 1. Create primary pool with genesis method to correspond to the
67
+ // sender/sender's secret/identity.
68
+ // 2. Create a separate pool and add separately because a
69
+ // different pw + config is used for the transition pool.
70
+
71
+ if (!this.sessionKeystonePoolConfig) { throw new Error(`this.sessionKeystonePoolConfig falsy. createSessionIdentity requires the coordinator to have this config set. (E: d65bb868d5e3e72c585d64d594e2b826)`); }
72
+ const sessionIdentity_genesis = await this.keystoneSvc.genesis({
73
+ masterSecret: sessionSecret,
74
+ configs: [this.sessionKeystonePoolConfig],
75
+ metaspace,
76
+ space: localSpace,
77
+ });
78
+
79
+ // #region sanity validation of genesis keystone
80
+ /**
81
+ * not necessary but since it's a new design, I'm putting in this
82
+ * immediate validation just to put it through its paces. (worth the
83
+ * slight perf hit).
84
+ */
85
+ const validationErrors = await validateGenesisKeystone({
86
+ keystoneIbGib: sessionIdentity_genesis
87
+ });
88
+ if (validationErrors && validationErrors.length > 0) { throw new Error(`(UNEXPECTED) the sessionIdentity_genesis that we just created already has validation errors just after creation? errors: ${validationErrors} (E: e9ca08cf0f8858bb1ace8b9fa89f8726)`); }
89
+ // #endregion sanity validation of genesis keystone
90
+
91
+ let newPrimaryIdentity: KeystoneIbGib_V1 | undefined = undefined;
92
+ if (primaryIdentity) {
93
+ newPrimaryIdentity = await this.keystoneSvc.sign({
94
+ latestKeystone: primaryIdentity,
95
+ poolId: this.sessionKeystonePoolConfig.id,
96
+ claim: {
97
+ verb: KEYSTONE_VERB_SIGN,
98
+ target: getIbGibAddr({ ibGib: sessionIdentity_genesis }),
99
+ },
100
+ masterSecret: nonSessionSecret,
101
+ metaspace,
102
+ space: localSpace,
103
+ // frameDetails: undefined, // anything to put here?
104
+ // requiredChallengeIds: undefined, // not relevant I think
105
+ });
106
+ }
107
+
108
+ // --- IMMEDIATE PERSISTENCE (Audit Trail Rule) ---
109
+ // The initial session keystone is trusted locally and must be stored
110
+ // in the durable space immediately so the FSM and validation steps
111
+ // can use it to sign outgoing contexts.
112
+ const identityIbGibs: IbGib_V1[] = [
113
+ sessionIdentity_genesis
114
+ ];
115
+ if (newPrimaryIdentity) {
116
+ identityIbGibs.push(newPrimaryIdentity);
117
+ }
118
+
119
+ // identity ibgibs are single framed without dna, so we only have to
120
+ // worry about each individual frame (i.e. no dependency graph)
121
+ await metaspace.put({
122
+ ibGibs: identityIbGibs,
123
+ space: localSpace,
124
+ });
125
+ for (const identityIbGib of identityIbGibs) {
126
+ await registerNewIbGib({
127
+ ibGib: identityIbGib,
128
+ space: localSpace,
129
+ fnBroadcast: undefined,
130
+ });
131
+ }
132
+ // ------------------------------------------------
133
+
134
+ return {
135
+ sessionIdentity: sessionIdentity_genesis,
136
+ sessionSecret,
137
+ newPrimaryIdentity,
138
+ }
139
+ } catch (error) {
140
+ console.error(`${lc} ${extractErrorMsg(error)}`);
141
+ throw error;
142
+ } finally {
143
+ if (logalot) { console.log(`${lc} complete.`); }
144
+ }
145
+ }
146
+
147
+ /**
148
+ * helper that KDFs the given identitySecret, using {@link sagaId} to do so.
149
+ *
150
+ * @returns deterministically derived session secret
151
+ */
152
+ private async deriveSessionSecret({
153
+ sagaId,
154
+ nonSessionSecret,
155
+ }: {
156
+ sagaId: string,
157
+ /**
158
+ * driving secret behind the sync operation. usually, this will be the
159
+ * secret corresponding to a primary identity keystone. But this can
160
+ * also just be a one-time secret just to have more security in the
161
+ * transmission intrinsically.
162
+ */
163
+ nonSessionSecret: string,
164
+ }): Promise<string> {
165
+ const lc = `${this.lc}[${this.deriveSessionSecret.name}]`;
166
+ try {
167
+ if (logalot) { console.log(`${lc} starting... (I: 0de03f8dcd3e32f1fca244e8f2a8a826)`); }
168
+
169
+ // Derive session-specific secret using KDF
170
+ const sessionSecret = await deriveKey({
171
+ masterSecret: nonSessionSecret,
172
+ kdfOpts: {
173
+ strategy: KdfStrategy.recursive_salt_wrap,
174
+ salt: sagaId,
175
+ rounds: 10000,
176
+ algorithm: 'SHA-256'
177
+ }
178
+ });
179
+
180
+ return sessionSecret;
181
+ } catch (error) {
182
+ console.error(`${lc} ${extractErrorMsg(error)}`);
183
+ throw error;
184
+ } finally {
185
+ if (logalot) { console.log(`${lc} complete.`); }
186
+ }
187
+ }
188
+
189
+
190
+
191
+ /**
192
+ * move to sync-peer-helpers.mts as a pure function?
193
+ */
194
+ export async function authenticateContext({
195
+ context,
196
+ space,
197
+ keystoneSvc,
198
+ }: {
199
+ context: SyncSagaContextIbGib_V1,
200
+ space: IbGibSpaceAny,
201
+ keystoneSvc?: KeystoneService_V1,
202
+ }): Promise<string[]> {
203
+ const lc = `[${authenticateContext.name}]`;
204
+ try {
205
+ if (logalot) { console.log(`${lc} starting... (I: 2677a482dfa873dcd1aa04a3031ff826)`); }
206
+
207
+ const errors: string[] = [];
208
+ if (!keystoneSvc) {
209
+ if (logalot) { console.warn(`${lc} No keystoneSvc provided. Skipping context authentication. (W: d34b8ad93d84a1ba8d8f7facd288826)`); }
210
+ return errors;
211
+ }
212
+
213
+ // Bill Architecture: We only sign at the context level.
214
+ // If the context refers to a session keystone, we must have a signedSessionKeystone
215
+ // as well to verify the most recent turn.
216
+ const { sessionKeystone: prevKeystoneAddrs } = context.rel8ns || {};
217
+ const { signedSessionKeystone: currKeystone } = context;
218
+
219
+ if (prevKeystoneAddrs && prevKeystoneAddrs.length > 0) {
220
+ if (!currKeystone) {
221
+ errors.push(`context.rel8ns.sessionKeystone present but context.signedSessionKeystone falsy. (E: b6e5a8ad93d84260a8d8e7facd288826)`);
222
+ return errors;
223
+ }
224
+
225
+ // Retrieve the previous keystone frame from space
226
+ const prevKeystoneAddr = prevKeystoneAddrs[0];
227
+ const getPrevRes = await getFromSpace({ addr: prevKeystoneAddr, space });
228
+ if (!getPrevRes.success || !getPrevRes.ibGibs || getPrevRes.ibGibs.length === 0) {
229
+ errors.push(`couldn't find previous session keystone (${prevKeystoneAddr}) in space (${space.ib}). (E: 7c34b8ad94d84a9ba8cbe7facd288826)`);
230
+ return errors;
231
+ }
232
+ const prevKeystone = getPrevRes.ibGibs[0] as KeystoneIbGib_V1;
233
+
234
+ // 1. Validate the transition (API replay of evolution + intrinsic validation)
235
+ const transitionErrors = await keystoneSvc.validate({
236
+ currentIbGib: currKeystone,
237
+ prevIbGib: prevKeystone,
238
+ });
239
+ if (transitionErrors.length > 0) {
240
+ errors.push(`Invalid session keystone transition: ${transitionErrors.join(', ')} (E: d34b8ad95d84b90a8d8ef7facd288826)`);
241
+ }
242
+
243
+ // 2. Verify that the signature in current keystone actually targets this context
244
+ const contextAddr = getIbGibAddr({ ibGib: context });
245
+ const proofTargetsThisContext = currKeystone.data?.proofs.some(p => p.claim.target === contextAddr);
246
+ if (!proofTargetsThisContext) {
247
+ errors.push(`Session keystone signature does not target the current context ibgib (${contextAddr}). (E: f3e5a8ad96d84c1ba8d8f7facd288826)`);
248
+ }
249
+ }
250
+
251
+ return errors;
252
+ } catch (error) {
253
+ console.error(`${lc} ${extractErrorMsg(error)}`);
254
+ throw error;
255
+ } finally {
256
+ if (logalot) { console.log(`${lc} complete.`); }
257
+ }
258
+ }
259
+
260
+
261
+
262
+ // #region this sync peer innerspace sendContextRequest
263
+
264
+ // Bill architecture: Keystone identity transportation.
265
+ // On each turn, the sender must include the current signed session
266
+ // keystone. If it's the first turn (Init), we include the entire
267
+ // keystone graph to ensure the receiver has the primary-to-session
268
+ // authorized link.
269
+ const identityIbGibs: IbGib_V1[] = [];
270
+ const { signedSessionKeystone } = context;
271
+ if (signedSessionKeystone) {
272
+ if (msg.data.stage === SyncStage.init) {
273
+ // transmit full keystone graph on the first handshake
274
+ const keystoneGraph = await getDependencyGraph({
275
+ ibGib: signedSessionKeystone,
276
+ space: localSpace,
277
+ });
278
+ identityIbGibs.push(...Object.values(keystoneGraph));
279
+ } else {
280
+ // transmit only the latest evolution for subsequent turns
281
+ identityIbGibs.push(signedSessionKeystone);
282
+ }
283
+ }
284
+
285
+ // #endregion this sync peer innerspace sendContextRequest
286
+
287
+
288
+ // #region SyncSagaContextRel8ns_V1
289
+
290
+ /**
291
+ * The Ephemeral Session Keystone Identity used for this saga. Required for
292
+ * validating the saga frame and this context.
293
+ *
294
+ * WARNING!!!: THIS DOES NOT POINT TO THE CURRENT SESSION KEYSTONE IN
295
+ * {@link SyncSagaContextIbGib_V1.signedSessionKeystone}. This points to the
296
+ * PREVIOUS FRAME (immediate past) of that frame. That session keystone
297
+ * signs with THIS context's frame as its target, so it is logically
298
+ * impossible because the hash would be different.
299
+ *
300
+ * ## notes
301
+ *
302
+ * ATOW (02/18/2026), this is a single address that will have a primary pool
303
+ * for the sender and a delegated pool for the receiver.
304
+ *
305
+ * @see {@link SyncSagaContextIbGib_V1.signedSessionKeystone}
306
+ */
307
+ sessionKeystone?: IbGibAddr[];
308
+
309
+ // #endregion SyncSagaContextRel8ns_V1
310
+
311
+ ```
@@ -29,7 +29,7 @@
29
29
  // const ibGibs: IbGib_V1[] = [];
30
30
  // for (const addr of addrs) {
31
31
  // const ig = await this.get({ addr });
32
- // if (ig) ibGibs.push(ig);
32
+ // if (ig) { ibGibs.push(ig); }
33
33
  // }
34
34
  // return { ibGibs };
35
35
  // }
@@ -11,7 +11,6 @@ import { IbGib_V1, IbGibRel8ns_V1, IbGibData_V1 } from '@ibgib/ts-gib/dist/V1/ty
11
11
  import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
12
12
 
13
13
  import { GLOBAL_LOG_A_LOT } from './core-constants.mjs';
14
- import { KeystoneService_V1 } from './keystone/keystone-service-v1.mjs';
15
14
  import { IbGibSpaceAny } from './witness/space/space-base-v1.mjs';
16
15
  import { Factory_V1 } from '@ibgib/ts-gib/dist/V1/factory.mjs';
17
16
  import { createTimeline, mut8Timeline, appendToTimeline } from './timeline/timeline-api.mjs';
@@ -126,30 +125,6 @@ export async function createTimelineRootTestHelper<TData extends IbGibData_V1 =
126
125
  }
127
126
  }
128
127
 
129
- /**
130
- * Creates a valid, mock Keystone Service for testing purposes.
131
- * This mocks the identity and signing logic needed for Sync operations.
132
- */
133
- export async function getTestKeystoneServiceHelper(): Promise<KeystoneService_V1> {
134
- class MockKeystoneService extends KeystoneService_V1 {
135
- async getIdentity(): Promise<any> {
136
- // Return a dummy identity
137
- // We use the Factory directly here to just get *something* that looks like an ibgib
138
- const res = await Factory_V1.firstGen({
139
- parentIbGib: Factory_V1.primitive({ ib: 'identity' }),
140
- ib: 'identity',
141
- data: { uuid: await getUUID() },
142
- dna: true,
143
- });
144
- return res.newIbGib;
145
- }
146
- // Implement other methods as no-ops or simple mocks
147
- async sign(args: any): Promise<any> { return args.latestKeystone; /* minimal mock */ }
148
- async verify(args: any): Promise<any> { return []; /* no errors */ }
149
- }
150
- return new MockKeystoneService() as unknown as KeystoneService_V1;
151
- }
152
-
153
128
  export interface TestIbGibIb {
154
129
  /**
155
130
  * @example alpha, beta, gamma, etc.
@@ -263,7 +238,7 @@ function getNewTestIb({
263
238
  const lc = `[${getNewTestIb.name}]`;
264
239
  try {
265
240
  if (logalot) { console.log(`${lc} starting... (I: 60aebdb828f72bbfbcbf401e7af09826)`); }
266
- if (!atom) throw new Error(`atom required (E: dc041852cdd88d692a8c2168ae4c7626)`);
241
+ if (!atom) { throw new Error(`atom required (E: dc041852cdd88d692a8c2168ae4c7626)`); }
267
242
 
268
243
  let ib = [
269
244
  atom,
Binary file