@ibgib/core-gib 0.1.61 → 0.1.63

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 (100) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/keystone/keystone-constants.d.mts +0 -1
  3. package/dist/keystone/keystone-constants.d.mts.map +1 -1
  4. package/dist/keystone/keystone-constants.mjs +0 -1
  5. package/dist/keystone/keystone-constants.mjs.map +1 -1
  6. package/dist/keystone/keystone-helpers.d.mts +23 -1
  7. package/dist/keystone/keystone-helpers.d.mts.map +1 -1
  8. package/dist/keystone/keystone-helpers.mjs +98 -5
  9. package/dist/keystone/keystone-helpers.mjs.map +1 -1
  10. package/dist/keystone/keystone-service-v1.d.mts +39 -2
  11. package/dist/keystone/keystone-service-v1.d.mts.map +1 -1
  12. package/dist/keystone/keystone-service-v1.mjs +175 -3
  13. package/dist/keystone/keystone-service-v1.mjs.map +1 -1
  14. package/dist/keystone/keystone-service-v1.respec.mjs +397 -42
  15. package/dist/keystone/keystone-service-v1.respec.mjs.map +1 -1
  16. package/dist/keystone/keystone-types.d.mts +54 -0
  17. package/dist/keystone/keystone-types.d.mts.map +1 -1
  18. package/dist/keystone/policy/keystone-profile-builder.d.mts +1 -1
  19. package/dist/keystone/policy/keystone-profile-builder.d.mts.map +1 -1
  20. package/dist/keystone/policy/keystone-profile-builder.mjs +8 -0
  21. package/dist/keystone/policy/keystone-profile-builder.mjs.map +1 -1
  22. package/dist/keystone/policy/profiles/profile-domain.json +84 -0
  23. package/dist/keystone/policy/profiles/profile-sync.json +84 -0
  24. package/dist/keystone/strategy/hash-reveal-v1/hash-reveal-v1.d.mts +8 -0
  25. package/dist/keystone/strategy/hash-reveal-v1/hash-reveal-v1.d.mts.map +1 -1
  26. package/dist/keystone/strategy/hash-reveal-v1/hash-reveal-v1.mjs +15 -1
  27. package/dist/keystone/strategy/hash-reveal-v1/hash-reveal-v1.mjs.map +1 -1
  28. package/dist/sync/sync-conflict-adv-multitimelines.withid.respec.mjs +16 -4
  29. package/dist/sync/sync-conflict-adv-multitimelines.withid.respec.mjs.map +1 -1
  30. package/dist/sync/sync-conflict-basic-divergence.withid.respec.mjs +4 -1
  31. package/dist/sync/sync-conflict-basic-divergence.withid.respec.mjs.map +1 -1
  32. package/dist/sync/sync-conflict-basic-multitimelines.withid.respec.mjs +4 -1
  33. package/dist/sync/sync-conflict-basic-multitimelines.withid.respec.mjs.map +1 -1
  34. package/dist/sync/sync-conflict-text-merge.withid.respec.mjs +10 -4
  35. package/dist/sync/sync-conflict-text-merge.withid.respec.mjs.map +1 -1
  36. package/dist/sync/sync-innerspace-constants.withid.respec.mjs +12 -3
  37. package/dist/sync/sync-innerspace-constants.withid.respec.mjs.map +1 -1
  38. package/dist/sync/sync-innerspace-deep-updates.withid.respec.mjs +4 -1
  39. package/dist/sync/sync-innerspace-deep-updates.withid.respec.mjs.map +1 -1
  40. package/dist/sync/sync-innerspace-dest-ahead.withid.respec.mjs +4 -1
  41. package/dist/sync/sync-innerspace-dest-ahead.withid.respec.mjs.map +1 -1
  42. package/dist/sync/sync-innerspace-multiple-timelines.withid.respec.mjs +4 -1
  43. package/dist/sync/sync-innerspace-multiple-timelines.withid.respec.mjs.map +1 -1
  44. package/dist/sync/sync-innerspace-partial-update.withid.respec.mjs +4 -1
  45. package/dist/sync/sync-innerspace-partial-update.withid.respec.mjs.map +1 -1
  46. package/dist/sync/sync-innerspace.withid.respec.mjs +4 -1
  47. package/dist/sync/sync-innerspace.withid.respec.mjs.map +1 -1
  48. package/dist/sync/sync-peer/sync-peer-types.d.mts +4 -0
  49. package/dist/sync/sync-peer/sync-peer-types.d.mts.map +1 -1
  50. package/dist/sync/sync-peer/sync-peer-v1.d.mts.map +1 -1
  51. package/dist/sync/sync-peer/sync-peer-v1.mjs +4 -1
  52. package/dist/sync/sync-peer/sync-peer-v1.mjs.map +1 -1
  53. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.d.mts.map +1 -1
  54. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.mjs +90 -22
  55. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.mjs.map +1 -1
  56. package/dist/sync/sync-saga-coordinator.d.mts +7 -10
  57. package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
  58. package/dist/sync/sync-saga-coordinator.mjs +14 -5
  59. package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
  60. package/dist/sync/sync-types.d.mts +5 -0
  61. package/dist/sync/sync-types.d.mts.map +1 -1
  62. package/dist/sync/sync-types.mjs.map +1 -1
  63. package/dist/sync/sync-withid.connect.respec.mjs +4 -1
  64. package/dist/sync/sync-withid.connect.respec.mjs.map +1 -1
  65. package/dist/sync/sync-withid.establish.respec.mjs +4 -1
  66. package/dist/sync/sync-withid.establish.respec.mjs.map +1 -1
  67. package/dist/sync/sync-withid.pingpong.respec.mjs +4 -1
  68. package/dist/sync/sync-withid.pingpong.respec.mjs.map +1 -1
  69. package/package.json +1 -1
  70. package/src/keystone/README.md +15 -2
  71. package/src/keystone/docs/architecture.md +21 -2
  72. package/src/keystone/docs/delegation.md +57 -0
  73. package/src/keystone/keystone-constants.mts +0 -1
  74. package/src/keystone/keystone-helpers.mts +131 -5
  75. package/src/keystone/keystone-service-v1.mts +223 -2
  76. package/src/keystone/keystone-service-v1.respec.mts +436 -40
  77. package/src/keystone/keystone-types.mts +55 -0
  78. package/src/keystone/policy/keystone-profile-builder.mts +9 -1
  79. package/src/keystone/policy/profiles/profile-domain.json +84 -0
  80. package/src/keystone/policy/profiles/profile-sync.json +84 -0
  81. package/src/keystone/strategy/hash-reveal-v1/hash-reveal-v1.mts +20 -1
  82. package/src/sync/sync-conflict-adv-multitimelines.withid.respec.mts +16 -4
  83. package/src/sync/sync-conflict-basic-divergence.withid.respec.mts +4 -1
  84. package/src/sync/sync-conflict-basic-multitimelines.withid.respec.mts +4 -1
  85. package/src/sync/sync-conflict-text-merge.withid.respec.mts +10 -4
  86. package/src/sync/sync-innerspace-constants.withid.respec.mts +12 -3
  87. package/src/sync/sync-innerspace-deep-updates.withid.respec.mts +4 -1
  88. package/src/sync/sync-innerspace-dest-ahead.withid.respec.mts +4 -1
  89. package/src/sync/sync-innerspace-multiple-timelines.withid.respec.mts +4 -1
  90. package/src/sync/sync-innerspace-partial-update.withid.respec.mts +4 -1
  91. package/src/sync/sync-innerspace.withid.respec.mts +4 -1
  92. package/src/sync/sync-peer/sync-peer-types.mts +4 -0
  93. package/src/sync/sync-peer/sync-peer-v1.mts +5 -1
  94. package/src/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.mts +96 -22
  95. package/src/sync/sync-saga-coordinator.mts +17 -12
  96. package/src/sync/sync-types.mts +6 -0
  97. package/src/sync/sync-withid.connect.respec.mts +5 -2
  98. package/src/sync/sync-withid.establish.respec.mts +4 -1
  99. package/src/sync/sync-withid.pingpong.respec.mts +4 -1
  100. package/src/sync/unused-identity-backup.mts.md +0 -311
@@ -1,22 +1,30 @@
1
1
  import { extractErrorMsg, mergeMapsOrArrays_Naive } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
2
- import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
2
+ import { getIbGibAddr, getIbAndGib } from '@ibgib/ts-gib/dist/helper.mjs';
3
+ import { IbGibAddr } from '@ibgib/ts-gib/dist/types.mjs';
4
+ import { IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
3
5
 
4
6
  import { GLOBAL_LOG_A_LOT } from '../core-constants.mjs';
5
7
  import {
6
8
  KeystoneData_V1, KeystoneIbGib_V1, KeystonePoolConfig, KeystoneClaim,
7
9
  KeystoneChallengePool, KeystoneReplenishStrategy, KeystoneRevocationInfo,
10
+ DelegateKeystoneStatus,
8
11
  } from './keystone-types.mjs';
9
12
  import { KeystoneStrategyFactory } from './strategy/keystone-strategy-factory.mjs';
10
- import { POOL_ID_REVOKE, KEYSTONE_VERB_REVOKE, KEYSTONE_VERB_MANAGE, KEYSTONE_CHECKPOINT_FREQUENCY } from './keystone-constants.mjs';
13
+ import {
14
+ POOL_ID_REVOKE, KEYSTONE_VERB_REVOKE, KEYSTONE_VERB_MANAGE,
15
+ KEYSTONE_CHECKPOINT_FREQUENCY, POOL_ID_MANAGE, KEYSTONE_VERB_SYNC
16
+ } from './keystone-constants.mjs';
11
17
  import {
12
18
  createKeystoneIbGibImpl, evolvePersistAndRegisterKeystone,
13
19
  generateOpaqueChallengeId, resolveTargetPool, selectChallengeIds,
14
20
  solveAndReplenish, validateKeystoneTransition,
15
21
  validateGenesisKeystone, validateKeystoneGraph
16
22
  } from './keystone-helpers.mjs';
23
+ import { getLatestAddrs } from '../witness/space/space-helper.mjs';
17
24
  import { IbGibSpaceAny } from '../witness/space/space-base-v1.mjs';
18
25
  import { MetaspaceService } from '../witness/space/metaspace/metaspace-types.mjs';
19
26
  import { FlatIbGibGraph } from '../common/other/graph-types.mjs';
27
+ import { getTjpAddr } from '../common/other/ibgib-helper.mjs';
20
28
 
21
29
  const logalot = GLOBAL_LOG_A_LOT;
22
30
 
@@ -110,6 +118,7 @@ export class KeystoneService_V1 {
110
118
  frameDetails,
111
119
  metaspace,
112
120
  space,
121
+ dataToPatch,
113
122
  }: {
114
123
  latestKeystone: KeystoneIbGib_V1;
115
124
  /**
@@ -133,6 +142,7 @@ export class KeystoneService_V1 {
133
142
  frameDetails?: any;
134
143
  metaspace: MetaspaceService;
135
144
  space: IbGibSpaceAny;
145
+ dataToPatch?: Partial<KeystoneData_V1>;
136
146
  }): Promise<KeystoneIbGib_V1> {
137
147
  const lc = `${this.lc}[${this.sign.name}]`;
138
148
  try {
@@ -193,6 +203,8 @@ export class KeystoneService_V1 {
193
203
  proofs: [proof],
194
204
  frameDetails,
195
205
  checkpointDetails,
206
+ ...(prevData.delegates ? { delegates: prevData.delegates } : {}),
207
+ ...dataToPatch,
196
208
  };
197
209
 
198
210
  // 5. Commit (Evolve, Persist, Register)
@@ -236,6 +248,213 @@ export class KeystoneService_V1 {
236
248
  return errors;
237
249
  }
238
250
 
251
+ /**
252
+ * Registers a delegate keystone on the parent keystone by appending its information
253
+ * to the parent's `delegates` map. This operation is signed using the parent's `manage` pool.
254
+ * Validates the delegate keystone's entire graph/timeline before registering.
255
+ */
256
+ async registerDelegate({
257
+ parentKeystone,
258
+ delegateKeystone,
259
+ masterSecret,
260
+ frameDetails,
261
+ metaspace,
262
+ space,
263
+ allowedVerbs,
264
+ }: {
265
+ parentKeystone: KeystoneIbGib_V1;
266
+ delegateKeystone: KeystoneIbGib_V1;
267
+ masterSecret: string;
268
+ frameDetails?: any;
269
+ metaspace: MetaspaceService;
270
+ space: IbGibSpaceAny;
271
+ allowedVerbs: string[];
272
+ }): Promise<KeystoneIbGib_V1> {
273
+ const lc = `${this.lc}[${this.registerDelegate.name}]`;
274
+ try {
275
+ if (logalot) { console.log(`${lc} starting...`); }
276
+
277
+ // 1. Validate the delegate keystone's entire graph/timeline
278
+ const validationErrors = await validateKeystoneGraph({
279
+ keystoneIbGib: delegateKeystone,
280
+ getLatest: true,
281
+ invalidIfMoreRecentKeystoneFoundInSpace: false,
282
+ space,
283
+ });
284
+ if (validationErrors.length > 0) {
285
+ throw new Error(`Delegate keystone validation failed: ${validationErrors.join(', ')} (E: 88fa8ab28c9b60e68994511a5825)`);
286
+ }
287
+
288
+ // 2. Verify that parent contains POOL_ID_MANAGE pool configuration
289
+ const prevData = parentKeystone.data!;
290
+ const hasManagePool = prevData.challengePools.some(p => p.id === POOL_ID_MANAGE);
291
+ if (!hasManagePool) {
292
+ throw new Error(`Parent keystone does not support delegation. Manage pool is required. (E: 818fa8ab28c9b60e68994511a5825)`);
293
+ }
294
+
295
+ const delegateTjpAddr = getTjpAddr({ ibGib: delegateKeystone });
296
+ if (!delegateTjpAddr) { throw new Error(`(UNEXPECTED) delegateTjpAddr falsy? (E: d4d6e8ad03c8925d4838b9a87b8f2826)`); }
297
+
298
+ // 3. Prepare the claim
299
+ const claim: Partial<KeystoneClaim> = {
300
+ target: delegateTjpAddr,
301
+ verb: KEYSTONE_VERB_MANAGE,
302
+ };
303
+
304
+ // 4. Update the delegates map
305
+ const currentDelegates = prevData.delegates ? { ...prevData.delegates } : {};
306
+ currentDelegates[delegateTjpAddr] = {
307
+ delegateTjpAddr,
308
+ delegateAddr: getIbGibAddr({ ibGib: delegateKeystone }),
309
+ thisAddr: getIbGibAddr({ ibGib: parentKeystone }),
310
+ // allowedVerbs: allowedVerbs ?? [KEYSTONE_VERB_SYNC], // NO! We cannot default to sync just to get things to work right now
311
+ allowedVerbs,
312
+ };
313
+
314
+ // 5. Sign & evolve parent keystone using the 'manage' pool
315
+ const evolved = await this.sign({
316
+ latestKeystone: parentKeystone,
317
+ masterSecret,
318
+ claim,
319
+ poolId: POOL_ID_MANAGE,
320
+ frameDetails,
321
+ metaspace,
322
+ space,
323
+ dataToPatch: {
324
+ delegates: currentDelegates
325
+ }
326
+ });
327
+
328
+ return evolved;
329
+ } catch (error) {
330
+ console.error(`${lc} ${extractErrorMsg(error)}`);
331
+ throw error;
332
+ } finally {
333
+ if (logalot) { console.log(`${lc} complete.`); }
334
+ }
335
+ }
336
+
337
+ /**
338
+ * Unregisters a delegate keystone from the parent keystone by removing its entry
339
+ * from the parent's `delegates` map. This operation is signed using the parent's `manage` pool.
340
+ */
341
+ async unregisterDelegate({
342
+ parentKeystone,
343
+ delegateTjpAddr,
344
+ masterSecret,
345
+ frameDetails,
346
+ metaspace,
347
+ space,
348
+ }: {
349
+ parentKeystone: KeystoneIbGib_V1;
350
+ delegateTjpAddr: IbGibAddr;
351
+ masterSecret: string;
352
+ frameDetails?: any;
353
+ metaspace: MetaspaceService;
354
+ space: IbGibSpaceAny;
355
+ }): Promise<KeystoneIbGib_V1> {
356
+ const lc = `${this.lc}[${this.unregisterDelegate.name}]`;
357
+ try {
358
+ if (logalot) { console.log(`${lc} starting...`); }
359
+
360
+ // 1. Verify that parent contains POOL_ID_MANAGE pool configuration
361
+ const prevData = parentKeystone.data!;
362
+ const hasManagePool = prevData.challengePools.some(p => p.id === POOL_ID_MANAGE);
363
+ if (!hasManagePool) {
364
+ throw new Error(`Parent keystone does not support delegation. Manage pool is required. (E: 3889f8ab28c9b60e68994511a5825)`);
365
+ }
366
+
367
+ // 2. Prepare the claim
368
+ const claim: Partial<KeystoneClaim> = {
369
+ target: delegateTjpAddr,
370
+ verb: KEYSTONE_VERB_MANAGE,
371
+ };
372
+
373
+ // 3. Update the delegates map
374
+ const currentDelegates = prevData.delegates ? { ...prevData.delegates } : {};
375
+ if (!currentDelegates[delegateTjpAddr]) {
376
+ throw new Error(`Delegate ${delegateTjpAddr} is not registered on this parent. (E: 81d9f8ab28c9b60e68994511a5825)`);
377
+ }
378
+ delete currentDelegates[delegateTjpAddr];
379
+
380
+ // 4. Sign & evolve parent keystone using the 'manage' pool
381
+ const evolved = await this.sign({
382
+ latestKeystone: parentKeystone,
383
+ masterSecret,
384
+ claim,
385
+ poolId: POOL_ID_MANAGE,
386
+ frameDetails,
387
+ metaspace,
388
+ space,
389
+ dataToPatch: {
390
+ delegates: currentDelegates
391
+ }
392
+ });
393
+
394
+ return evolved;
395
+ } catch (error) {
396
+ console.error(`${lc} ${extractErrorMsg(error)}`);
397
+ throw error;
398
+ } finally {
399
+ if (logalot) { console.log(`${lc} complete.`); }
400
+ }
401
+ }
402
+
403
+ /**
404
+ * Gets the registration status of a delegate keystone from the parent's latest tip frame.
405
+ */
406
+ async getDelegateStatus({
407
+ parentTjpAddr,
408
+ delegateTjpAddr,
409
+ metaspace,
410
+ space,
411
+ }: {
412
+ parentTjpAddr: IbGibAddr;
413
+ delegateTjpAddr: IbGibAddr;
414
+ metaspace: MetaspaceService;
415
+ space: IbGibSpaceAny;
416
+ }): Promise<DelegateKeystoneStatus> {
417
+ const lc = `${this.lc}[${this.getDelegateStatus.name}]`;
418
+ try {
419
+ if (logalot) { console.log(`${lc} starting...`); }
420
+
421
+ const { ib, gib } = getIbAndGib({ ibGibAddr: parentTjpAddr });
422
+ const parentIbGib: IbGib_V1 = { ib, gib };
423
+ const resGetLatest = await getLatestAddrs({
424
+ ibGibs: [parentIbGib],
425
+ space,
426
+ });
427
+
428
+ if (!resGetLatest.data?.latestAddrsMap) {
429
+ return { registered: false };
430
+ }
431
+
432
+ const latestAddr = resGetLatest.data.latestAddrsMap[parentTjpAddr];
433
+ if (!latestAddr) {
434
+ return { registered: false };
435
+ }
436
+
437
+ const resGet = await metaspace.get({ addr: latestAddr, space });
438
+ const latestParent = resGet.ibGibs?.at(0) as KeystoneIbGib_V1;
439
+ if (!latestParent || !latestParent.data) {
440
+ return { registered: false };
441
+ }
442
+
443
+ const delegates = latestParent.data.delegates || {};
444
+ const delegateInfo = delegates[delegateTjpAddr];
445
+
446
+ return {
447
+ registered: !!delegateInfo,
448
+ delegateInfo,
449
+ };
450
+ } catch (error) {
451
+ console.error(`${lc} ${extractErrorMsg(error)}`);
452
+ throw error;
453
+ } finally {
454
+ if (logalot) { console.log(`${lc} complete.`); }
455
+ }
456
+ }
457
+
239
458
  /**
240
459
  * Validates a genesis keystone.
241
460
  *
@@ -429,6 +648,7 @@ export class KeystoneService_V1 {
429
648
  revocationInfo,
430
649
  frameDetails,
431
650
  checkpointDetails,
651
+ ...(prevData.delegates ? { delegates: prevData.delegates } : {}),
432
652
  };
433
653
 
434
654
  // 7. Commit
@@ -555,6 +775,7 @@ export class KeystoneService_V1 {
555
775
  challengePools: finalPools,
556
776
  proofs: [proof], // The proof authorizes the structure change
557
777
  checkpointDetails,
778
+ ...(prevData.delegates ? { delegates: prevData.delegates } : {}),
558
779
  };
559
780
 
560
781
  // 7. Commit