@ibgib/core-gib 0.1.47 → 0.1.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/common/other/ibgib-helper.d.mts +12 -0
  2. package/dist/common/other/ibgib-helper.d.mts.map +1 -1
  3. package/dist/common/other/ibgib-helper.mjs +39 -0
  4. package/dist/common/other/ibgib-helper.mjs.map +1 -1
  5. package/dist/keystone/kdf/kdf-helpers.mjs +2 -2
  6. package/dist/keystone/kdf/kdf-helpers.mjs.map +1 -1
  7. package/dist/keystone/keystone-config-builder.d.mts +2 -1
  8. package/dist/keystone/keystone-config-builder.d.mts.map +1 -1
  9. package/dist/keystone/keystone-config-builder.mjs +8 -2
  10. package/dist/keystone/keystone-config-builder.mjs.map +1 -1
  11. package/dist/keystone/keystone-constants.d.mts +24 -3
  12. package/dist/keystone/keystone-constants.d.mts.map +1 -1
  13. package/dist/keystone/keystone-constants.mjs +22 -1
  14. package/dist/keystone/keystone-constants.mjs.map +1 -1
  15. package/dist/keystone/keystone-helpers.d.mts.map +1 -1
  16. package/dist/keystone/keystone-helpers.mjs +7 -9
  17. package/dist/keystone/keystone-helpers.mjs.map +1 -1
  18. package/dist/keystone/keystone-service-v1.d.mts +4 -1
  19. package/dist/keystone/keystone-service-v1.d.mts.map +1 -1
  20. package/dist/keystone/keystone-service-v1.mjs +6 -1
  21. package/dist/keystone/keystone-service-v1.mjs.map +1 -1
  22. package/dist/keystone/keystone-service-v1.respec.mjs +26 -26
  23. package/dist/keystone/keystone-service-v1.respec.mjs.map +1 -1
  24. package/dist/keystone/keystone-types.d.mts +24 -5
  25. package/dist/keystone/keystone-types.d.mts.map +1 -1
  26. package/dist/keystone/keystone-types.mjs.map +1 -1
  27. package/dist/sync/sync-conflict-adv-multitimelines.respec.mjs +1 -1
  28. package/dist/sync/sync-conflict-adv-multitimelines.respec.mjs.map +1 -1
  29. package/dist/sync/sync-conflict-basic-divergence.respec.mjs +1 -1
  30. package/dist/sync/sync-conflict-basic-divergence.respec.mjs.map +1 -1
  31. package/dist/sync/sync-conflict-basic-multitimelines.respec.mjs +1 -1
  32. package/dist/sync/sync-conflict-basic-multitimelines.respec.mjs.map +1 -1
  33. package/dist/sync/sync-conflict-text-merge.respec.mjs +1 -1
  34. package/dist/sync/sync-conflict-text-merge.respec.mjs.map +1 -1
  35. package/dist/sync/sync-constants.d.mts +47 -1
  36. package/dist/sync/sync-constants.d.mts.map +1 -1
  37. package/dist/sync/sync-constants.mjs +49 -1
  38. package/dist/sync/sync-constants.mjs.map +1 -1
  39. package/dist/sync/sync-innerspace-constants.respec.mjs +1 -1
  40. package/dist/sync/sync-innerspace-constants.respec.mjs.map +1 -1
  41. package/dist/sync/sync-innerspace-deep-updates.respec.mjs +1 -1
  42. package/dist/sync/sync-innerspace-deep-updates.respec.mjs.map +1 -1
  43. package/dist/sync/sync-innerspace-dest-ahead-withid.respec.mjs +33 -19
  44. package/dist/sync/sync-innerspace-dest-ahead-withid.respec.mjs.map +1 -1
  45. package/dist/sync/sync-innerspace-dest-ahead.respec.mjs +1 -1
  46. package/dist/sync/sync-innerspace-dest-ahead.respec.mjs.map +1 -1
  47. package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs +1 -1
  48. package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs.map +1 -1
  49. package/dist/sync/sync-innerspace-partial-update.respec.mjs +1 -1
  50. package/dist/sync/sync-innerspace-partial-update.respec.mjs.map +1 -1
  51. package/dist/sync/sync-innerspace.respec.mjs +1 -1
  52. package/dist/sync/sync-innerspace.respec.mjs.map +1 -1
  53. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts.map +1 -1
  54. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs +5 -0
  55. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs.map +1 -1
  56. package/dist/sync/sync-peer/sync-peer-v1.d.mts +6 -1
  57. package/dist/sync/sync-peer/sync-peer-v1.d.mts.map +1 -1
  58. package/dist/sync/sync-peer/sync-peer-v1.mjs +56 -23
  59. package/dist/sync/sync-peer/sync-peer-v1.mjs.map +1 -1
  60. package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts +7 -3
  61. package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts.map +1 -1
  62. package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs +32 -3
  63. package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs.map +1 -1
  64. package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts +16 -0
  65. package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts.map +1 -1
  66. package/dist/sync/sync-saga-coordinator.d.mts +18 -3
  67. package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
  68. package/dist/sync/sync-saga-coordinator.mjs +240 -55
  69. package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
  70. package/dist/sync/sync-types.d.mts +1 -1
  71. package/dist/sync/sync-types.d.mts.map +1 -1
  72. package/package.json +1 -1
  73. package/src/common/other/ibgib-helper.mts +39 -0
  74. package/src/keystone/kdf/kdf-helpers.mts +2 -2
  75. package/src/keystone/keystone-config-builder.mts +13 -2
  76. package/src/keystone/keystone-constants.mts +24 -2
  77. package/src/keystone/keystone-helpers.mts +5 -10
  78. package/src/keystone/keystone-service-v1.mts +5 -0
  79. package/src/keystone/keystone-service-v1.respec.mts +25 -25
  80. package/src/keystone/keystone-types.mts +27 -7
  81. package/src/sync/sync-conflict-adv-multitimelines.respec.mts +1 -1
  82. package/src/sync/sync-conflict-basic-divergence.respec.mts +1 -1
  83. package/src/sync/sync-conflict-basic-multitimelines.respec.mts +1 -1
  84. package/src/sync/sync-conflict-text-merge.respec.mts +1 -1
  85. package/src/sync/sync-constants.mts +51 -1
  86. package/src/sync/sync-innerspace-constants.respec.mts +1 -1
  87. package/src/sync/sync-innerspace-deep-updates.respec.mts +1 -1
  88. package/src/sync/sync-innerspace-dest-ahead-withid.respec.mts +36 -19
  89. package/src/sync/sync-innerspace-dest-ahead.respec.mts +1 -1
  90. package/src/sync/sync-innerspace-multiple-timelines.respec.mts +1 -1
  91. package/src/sync/sync-innerspace-partial-update.respec.mts +1 -1
  92. package/src/sync/sync-innerspace.respec.mts +1 -1
  93. package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mts +5 -0
  94. package/src/sync/sync-peer/sync-peer-v1.mts +63 -25
  95. package/src/sync/sync-saga-context/sync-saga-context-helpers.mts +52 -4
  96. package/src/sync/sync-saga-context/sync-saga-context-types.mts +17 -0
  97. package/src/sync/sync-saga-coordinator.mts +295 -62
  98. package/src/sync/sync-types.mts +1 -1
@@ -198,11 +198,16 @@ export class SyncPeerInnerspace_V1 extends SyncPeer_V1<InitializeSyncPeerInnersp
198
198
  // the payload ibgibs. so the receiver coordinator should be ready
199
199
  // to do its thing.
200
200
 
201
+ const identitySecret = context.fnIdentitySecret ?
202
+ await context.fnIdentitySecret() :
203
+ undefined;
201
204
  const responseCtx = await receiverCoordinator.continueSync({
202
205
  sagaContext: context,
203
206
  metaspace: receiverMetaspace,
204
207
  mySpace: receiverSpace,
205
208
  myTempSpace: receiverTempSpace,
209
+ identity: context.signedSessionKeystone,
210
+ identitySecret,
206
211
  });
207
212
 
208
213
  if (logalot) { console.log(`${lc} receiverCoordinator.continueSync responseCtx: ${responseCtx ? pretty(responseCtx) : 'undefined'} (I: fb2831decde1f2b3589021f85ab19126)`); }
@@ -20,11 +20,14 @@ import { IbGibSpaceAny } from '../../witness/space/space-base-v1.mjs';
20
20
  import { newupSubject } from '../../common/pubsub/subject/subject-helper.mjs';
21
21
  import { authenticateContext, authorizeContext, validateContextAndSagaFrame } from '../sync-saga-context/sync-saga-context-helpers.mjs';
22
22
  import { getFromSpace } from '../../witness/space/space-helper.mjs';
23
+ import { getFullSyncSagaHistory } from '../sync-helpers.mjs';
24
+ import { SyncSagaFrameDependencyGraph } from '../sync-types.mjs';
23
25
 
24
26
  const logalot = GLOBAL_LOG_A_LOT;
25
27
  const logalotControlDomain = false;
26
28
  const lcControlDomain = '[ControlDomain]';
27
29
 
30
+
28
31
  /**
29
32
  * Abstract witness for talking to a Sync Peer (e.g. Remote Node or Local Simulator).
30
33
  *
@@ -66,8 +69,8 @@ export abstract class SyncPeer_V1<TInitializeOpts extends InitializeSyncPeerOpts
66
69
  *
67
70
  * @see {@link SyncPeerWitness.opts}
68
71
  */
69
- public async initializeSender(opts: TInitializeOpts): Promise<void> {
70
- const lc = `${this.lc}[${this.initializeSender.name}]`;
72
+ public async initializeOpts(opts: TInitializeOpts): Promise<void> {
73
+ const lc = `${this.lc}[${this.initializeOpts.name}]`;
71
74
  try {
72
75
  if (logalot) { console.log(`${lc} starting... (I: 31bd5fda37c89fa37fbaf14daf5fe726)`); }
73
76
  this.opts = opts;
@@ -117,6 +120,42 @@ export abstract class SyncPeer_V1<TInitializeOpts extends InitializeSyncPeerOpts
117
120
 
118
121
  protected abstract ensureReceiverTempSpace(): Promise<IbGibSpaceAny>;
119
122
 
123
+ protected async authenticateValidateAuthorize({
124
+ context,
125
+ fullSagaHistory,
126
+ }: {
127
+ context: SyncSagaContextIbGib_V1,
128
+ fullSagaHistory: SyncSagaFrameDependencyGraph[],
129
+ }): Promise<void> {
130
+ const lc = `${this.lc}[${this.authenticateValidateAuthorize.name}]`;
131
+ try {
132
+ if (logalot) { console.log(`${lc} starting... (I: add238055cd84a222c5b8c89913af526)`); }
133
+
134
+ // first authenticate, because invalid identity is a non-starter
135
+ const authenticationErrors = await authenticateContext({ context, fullSagaHistory });
136
+ if (authenticationErrors.length > 0) {
137
+ throw new Error(`invalid context authentication. authenticationErrors: ${authenticationErrors} (E: da89da5ee1269aeb78952d475d607526)`);
138
+ }
139
+ // next, we have a valid keystone, which should point to the
140
+ // context. But is that context and the saga data it contains valid?
141
+ // Does the keystone actually point to this context?
142
+ const validationErrors = await validateContextAndSagaFrame({ context, });
143
+ if (validationErrors.length > 0) {
144
+ throw new Error(`invalid context received. validationErrors: ${validationErrors} (E: 8b34c875c968af29bc433138e57a7826)`);
145
+ }
146
+ // we have a valid keystone that points to a valid context, but what
147
+ // exactly does the keystone authorize?
148
+ const authorizationErrors = await authorizeContext({ context, fullSagaHistory });
149
+ if (authorizationErrors.length > 0) {
150
+ throw new Error(`invalid context authorization. authorizationErrors: ${authorizationErrors} (E: 8ddc284a758cf10ba829334c1babb826)`);
151
+ }
152
+ } catch (error) {
153
+ console.error(`${lc} ${extractErrorMsg(error)}`);
154
+ throw error;
155
+ } finally {
156
+ if (logalot) { console.log(`${lc} complete.`); }
157
+ }
158
+ }
120
159
  /**
121
160
  * Witness the synchronization context (Send/Receive).
122
161
  *
@@ -133,16 +172,6 @@ export abstract class SyncPeer_V1<TInitializeOpts extends InitializeSyncPeerOpts
133
172
 
134
173
  if (!this.opts) { throw new Error(`(UNEXPECTED) this.opts falsy? Concrete class should have initialized sender opts by now. (E: 0b9e28287318fdf8bf9f5a6886a24826)`); }
135
174
 
136
- // #region leaving off here
137
- // NOTES: the context ibgib now has a reference to the signed
138
- // keystone. the signed keystone targets the context ibgib, and the
139
- // context ibgib itself points to the previous frame of the
140
- // keystone. I've started on creating a validateKeystone function,
141
- // whcih I need to at least add the validate transitions to. I
142
- // _think_ I need to also fill in some authentication here in this
143
- // peer at the very least, then I can move on to other layers.
144
- // #endregion leaving off here
145
-
146
175
  // NOTE: There are three basic types of peers:
147
176
  // * local-only
148
177
  // * this peer is both sender/receiver peer
@@ -183,19 +212,19 @@ export abstract class SyncPeer_V1<TInitializeOpts extends InitializeSyncPeerOpts
183
212
  // when all domain ibgibs are pulled, publish complete to the observable
184
213
  // return resulting context ibgib (which the caller should get BEFORE the domain ibgibs observable completes)
185
214
 
186
- // validate, authenticate, and authorize the context, sagaFrame, and identity(s)
187
- const validationErrors = await validateContextAndSagaFrame({ context });
188
- if (validationErrors.length > 0) {
189
- throw new Error(`invalid context received. validationErrors: ${validationErrors} (E: 8b34c875c968af29bc433138e57a7826)`);
190
- }
191
- const authenticationErrors = await authenticateContext({ context });
192
- if (authenticationErrors.length > 0) {
193
- throw new Error(`invalid context authentication. authenticationErrors: ${authenticationErrors} (E: da89da5ee1269aeb78952d475d607526)`);
194
- }
195
- const authorizationErrors = await authorizeContext({ context });
196
- if (authorizationErrors.length > 0) {
197
- throw new Error(`invalid context authorization. authorizationErrors: ${authorizationErrors} (E: 8ddc284a758cf10ba829334c1babb826)`);
198
- }
215
+ if (!context.sagaFrame) { throw new Error(`context.sagaFrame falsy. (E: a33dd88aa108e2bad9e885885731ce26)`); }
216
+
217
+ // this is not just happening on the client, but this peer may be
218
+ // the one receiving the context as well.
219
+
220
+ const sagaHistory_beforeSend = await getFullSyncSagaHistory({
221
+ sagaIbGib: context.sagaFrame,
222
+ space: this.opts.senderSpace
223
+ });
224
+
225
+ await this.authenticateValidateAuthorize({
226
+ context, fullSagaHistory: sagaHistory_beforeSend,
227
+ });
199
228
 
200
229
  // at this point, we have a valid, authenticated, authorized context
201
230
 
@@ -213,6 +242,15 @@ export abstract class SyncPeer_V1<TInitializeOpts extends InitializeSyncPeerOpts
213
242
  // receive, they may still be transferring. These will be published
214
243
  // to this.payloadIbGibsDomainReceived$
215
244
 
245
+ const sagaHistory_afterSend = await getFullSyncSagaHistory({
246
+ sagaIbGib: context.sagaFrame,
247
+ space: this.opts.senderSpace
248
+ });
249
+
250
+ await this.authenticateValidateAuthorize({
251
+ context, fullSagaHistory: sagaHistory_afterSend,
252
+ });
253
+
216
254
  return response;
217
255
  } else {
218
256
  // response falsy. we could be done, or this could be an error.
@@ -18,11 +18,12 @@ import {
18
18
  } from './sync-saga-context-types.mjs';
19
19
  import { IbGibSpaceAny } from '../../witness/space/space-base-v1.mjs';
20
20
  import { putInSpace, registerNewIbGib } from '../../witness/space/space-helper.mjs';
21
- import { SyncIbGib_V1 } from '../sync-types.mjs';
21
+ import { SyncIbGib_V1, SyncSagaFrameDependencyGraph } from '../sync-types.mjs';
22
22
  import { validateSyncSagaFrame } from '../sync-helpers.mjs';
23
23
  import { validateKeystoneGraph, validateKeystoneTransition } from '../../keystone/keystone-helpers.mjs';
24
24
  import { KeystoneService_V1 } from '../../keystone/keystone-service-v1.mjs';
25
25
  import { KeystoneIbGib_V1 } from '../../keystone/keystone-types.mjs';
26
+ import { isIbGibWithAtom } from '../../common/other/ibgib-helper.mjs';
26
27
 
27
28
  const logalot = GLOBAL_LOG_A_LOT;
28
29
 
@@ -96,6 +97,24 @@ export async function parseSyncSagaContextIb({
96
97
  }
97
98
  }
98
99
 
100
+ export function isSyncSagaContextIbGib(x: any): x is SyncSagaContextIbGib_V1 {
101
+ const lc = `[${isSyncSagaContextIbGib.name}]`;
102
+ try {
103
+ if (logalot) { console.log(`${lc} starting... (I: 2bfa7f3cf5984b0c78aced881ce95226)`); }
104
+
105
+ const hasAtom = isIbGibWithAtom<SyncSagaContextIbGib_V1>(x, SYNC_SAGA_CONTEXT_ATOM);
106
+
107
+ // should be good enough in V1
108
+
109
+ return hasAtom;
110
+ } catch (error) {
111
+ console.error(`${lc} ${extractErrorMsg(error)}`);
112
+ throw error;
113
+ } finally {
114
+ if (logalot) { console.log(`${lc} complete.`); }
115
+ }
116
+ }
117
+
99
118
 
100
119
  /**
101
120
  * Validates ONLY the {@link context} ibgib itself and saga frame/msg stone(s)
@@ -109,7 +128,11 @@ export async function parseSyncSagaContextIb({
109
128
  *
110
129
  * @returns empty array if valid, else validation errors
111
130
  */
112
- export async function validateContextAndSagaFrame({ context }: { context: SyncSagaContextIbGib_V1 }): Promise<string[]> {
131
+ export async function validateContextAndSagaFrame({
132
+ context,
133
+ }: {
134
+ context: SyncSagaContextIbGib_V1,
135
+ }): Promise<string[]> {
113
136
  const lc = `[${validateContextAndSagaFrame.name}]`;
114
137
  try {
115
138
  if (logalot) { console.log(`${lc} starting... (I: 7797f8294bd8f7e5089cb722ad468226)`); }
@@ -178,13 +201,32 @@ export async function validateContextDomainPayloadIbGibs({ context }: { context:
178
201
  /**
179
202
  * move to sync-peer-helpers.mts as a pure function?
180
203
  */
181
- export async function authenticateContext({ context }: { context: SyncSagaContextIbGib_V1 }): Promise<string[]> {
204
+ export async function authenticateContext({
205
+ context,
206
+ fullSagaHistory
207
+ }: {
208
+ context: SyncSagaContextIbGib_V1,
209
+ fullSagaHistory: SyncSagaFrameDependencyGraph[],
210
+ }): Promise<string[]> {
182
211
  const lc = `[${authenticateContext.name}]`;
183
212
  try {
184
213
  if (logalot) { console.log(`${lc} starting... (I: 2677a482dfa873dcd1aa04a3031ff826)`); }
185
214
 
186
215
  console.error(`${lc} NAG ERROR (NOT THROWN): not implemented. // todo: authenticate (v1 must have this after we get merge logic workflow going) (E: bc3a78f2dab18ab64c36d055a4b50526)`);
187
216
 
217
+ // ensure the same identity rel8n timeline is in the first saga ibgib.
218
+
219
+ for (const sagaFrameDepGraph of fullSagaHistory) {
220
+ sagaFrameDepGraph.identities
221
+ }
222
+
223
+
224
+ // each saga ibgib should be updated with a new identity rel8n. each
225
+ // rel8n should correspond to each evolution of the keystone.
226
+
227
+ // if (context.sagaFrame.rel8ns?.sessionKeystone)
228
+ // context.signedSessionKeystone
229
+
188
230
  return [];
189
231
  } catch (error) {
190
232
  console.error(`${lc} ${extractErrorMsg(error)}`);
@@ -197,7 +239,13 @@ export async function authenticateContext({ context }: { context: SyncSagaContex
197
239
  /**
198
240
  * move to sync-peer-helpers.mts as a pure function?
199
241
  */
200
- export async function authorizeContext({ context }: { context: SyncSagaContextIbGib_V1 }): Promise<string[]> {
242
+ export async function authorizeContext({
243
+ context,
244
+ fullSagaHistory
245
+ }: {
246
+ context: SyncSagaContextIbGib_V1,
247
+ fullSagaHistory: SyncSagaFrameDependencyGraph[],
248
+ }): Promise<string[]> {
201
249
  const lc = `[${authorizeContext.name}]`;
202
250
  try {
203
251
  if (logalot) { console.log(`${lc} starting... (I: 48c918b41ceec0cd489ca3b8819e6826)`); }
@@ -100,4 +100,21 @@ export interface SyncSagaContextIbGib_V1 extends IbGib_V1<SyncSagaContextData_V1
100
100
  * previous frame of the keystone.
101
101
  */
102
102
  signedSessionKeystone?: KeystoneIbGib_V1;
103
+
104
+ /**
105
+ * If identity is used in the sync transaction, this should be provided. It
106
+ * will drive both primary identity keystone evolution (to create session
107
+ * keystone), as well as signing the session keystone itself.
108
+ *
109
+ * when a peer transmits the context ibgib, this does not need to be
110
+ * transmitted. Note, however, that if sync is occuring between two remote
111
+ * peers and the peer design is not a proxy-based one, then the receiver
112
+ * should assign this with their own provider function.
113
+ *
114
+ * @returns the identity secret when needed to sign/evolve keystone
115
+ *
116
+ * NOTE: Not 100% sure where I'm putting this so this may end up being
117
+ * unused and should thus be removed. Right now, I think this will work.
118
+ */
119
+ fnIdentitySecret?: () => Promise<string>;
103
120
  }