@ibgib/core-gib 0.1.60 → 0.1.62

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 (181) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/common/other/graph-helper.d.mts.map +1 -1
  3. package/dist/common/other/graph-helper.mjs +7 -6
  4. package/dist/common/other/graph-helper.mjs.map +1 -1
  5. package/dist/keystone/keystone-config-builder.d.mts +1 -2
  6. package/dist/keystone/keystone-config-builder.d.mts.map +1 -1
  7. package/dist/keystone/keystone-config-builder.mjs +4 -19
  8. package/dist/keystone/keystone-config-builder.mjs.map +1 -1
  9. package/dist/keystone/keystone-constants.d.mts +2 -1
  10. package/dist/keystone/keystone-constants.d.mts.map +1 -1
  11. package/dist/keystone/keystone-constants.mjs +2 -1
  12. package/dist/keystone/keystone-constants.mjs.map +1 -1
  13. package/dist/keystone/keystone-helpers.d.mts +28 -16
  14. package/dist/keystone/keystone-helpers.d.mts.map +1 -1
  15. package/dist/keystone/keystone-helpers.mjs +155 -76
  16. package/dist/keystone/keystone-helpers.mjs.map +1 -1
  17. package/dist/keystone/keystone-policy-types.d.mts +6 -4
  18. package/dist/keystone/keystone-policy-types.d.mts.map +1 -1
  19. package/dist/keystone/keystone-service-v1.d.mts +38 -2
  20. package/dist/keystone/keystone-service-v1.d.mts.map +1 -1
  21. package/dist/keystone/keystone-service-v1.mjs +177 -11
  22. package/dist/keystone/keystone-service-v1.mjs.map +1 -1
  23. package/dist/keystone/keystone-service-v1.respec.mjs +527 -41
  24. package/dist/keystone/keystone-service-v1.respec.mjs.map +1 -1
  25. package/dist/keystone/keystone-types.d.mts +53 -11
  26. package/dist/keystone/keystone-types.d.mts.map +1 -1
  27. package/dist/keystone/policy/keystone-profile-builder.d.mts +25 -0
  28. package/dist/keystone/policy/keystone-profile-builder.d.mts.map +1 -0
  29. package/dist/keystone/policy/keystone-profile-builder.mjs +117 -0
  30. package/dist/keystone/policy/keystone-profile-builder.mjs.map +1 -0
  31. package/dist/keystone/policy/profiles/profile-high.json +84 -0
  32. package/dist/keystone/policy/profiles/profile-low.json +84 -0
  33. package/dist/keystone/policy/profiles/profile-medium.json +84 -0
  34. package/dist/keystone/policy/profiles/profile-session.json +84 -0
  35. package/dist/keystone/policy/profiles/profile-test.json +84 -0
  36. package/dist/keystone/policy/schemas/connect-pool.high.schema.json +23 -0
  37. package/dist/keystone/policy/schemas/connect-pool.low.schema.json +23 -0
  38. package/dist/keystone/policy/schemas/connect-pool.medium.schema.json +23 -0
  39. package/dist/keystone/policy/schemas/keystone.high.schema.json +26 -0
  40. package/dist/keystone/policy/schemas/keystone.low.schema.json +26 -0
  41. package/dist/keystone/policy/schemas/keystone.medium.schema.json +26 -0
  42. package/dist/keystone/policy/schemas/manage-pool.high.schema.json +23 -0
  43. package/dist/keystone/policy/schemas/manage-pool.low.schema.json +23 -0
  44. package/dist/keystone/policy/schemas/manage-pool.medium.schema.json +23 -0
  45. package/dist/keystone/policy/schemas/revoke-pool.high.schema.json +23 -0
  46. package/dist/keystone/policy/schemas/revoke-pool.low.schema.json +23 -0
  47. package/dist/keystone/policy/schemas/revoke-pool.medium.schema.json +23 -0
  48. package/dist/keystone/policy/schemas/sign-pool.high.schema.json +23 -0
  49. package/dist/keystone/policy/schemas/sign-pool.low.schema.json +23 -0
  50. package/dist/keystone/policy/schemas/sign-pool.medium.schema.json +23 -0
  51. package/dist/keystone/policy/schemas/sync-pool.high.schema.json +23 -0
  52. package/dist/keystone/policy/schemas/sync-pool.low.schema.json +23 -0
  53. package/dist/keystone/policy/schemas/sync-pool.medium.schema.json +23 -0
  54. package/dist/sync/sync-conflict-adv-multitimelines.withid.respec.d.mts +8 -0
  55. package/dist/sync/sync-conflict-adv-multitimelines.withid.respec.d.mts.map +1 -0
  56. package/dist/sync/sync-conflict-adv-multitimelines.withid.respec.mjs +582 -0
  57. package/dist/sync/sync-conflict-adv-multitimelines.withid.respec.mjs.map +1 -0
  58. package/dist/sync/sync-conflict-basic-divergence.withid.respec.d.mts +7 -0
  59. package/dist/sync/sync-conflict-basic-divergence.withid.respec.d.mts.map +1 -0
  60. package/dist/sync/sync-conflict-basic-divergence.withid.respec.mjs +274 -0
  61. package/dist/sync/sync-conflict-basic-divergence.withid.respec.mjs.map +1 -0
  62. package/dist/sync/sync-conflict-basic-multitimelines.withid.respec.d.mts +8 -0
  63. package/dist/sync/sync-conflict-basic-multitimelines.withid.respec.d.mts.map +1 -0
  64. package/dist/sync/sync-conflict-basic-multitimelines.withid.respec.mjs +322 -0
  65. package/dist/sync/sync-conflict-basic-multitimelines.withid.respec.mjs.map +1 -0
  66. package/dist/sync/sync-conflict-text-merge.withid.respec.d.mts +7 -0
  67. package/dist/sync/sync-conflict-text-merge.withid.respec.d.mts.map +1 -0
  68. package/dist/sync/sync-conflict-text-merge.withid.respec.mjs +307 -0
  69. package/dist/sync/sync-conflict-text-merge.withid.respec.mjs.map +1 -0
  70. package/dist/sync/sync-innerspace-constants.withid.respec.d.mts +8 -0
  71. package/dist/sync/sync-innerspace-constants.withid.respec.d.mts.map +1 -0
  72. package/dist/sync/sync-innerspace-constants.withid.respec.mjs +233 -0
  73. package/dist/sync/sync-innerspace-constants.withid.respec.mjs.map +1 -0
  74. package/dist/sync/sync-innerspace-deep-updates.withid.respec.d.mts +7 -0
  75. package/dist/sync/sync-innerspace-deep-updates.withid.respec.d.mts.map +1 -0
  76. package/dist/sync/sync-innerspace-deep-updates.withid.respec.mjs +233 -0
  77. package/dist/sync/sync-innerspace-deep-updates.withid.respec.mjs.map +1 -0
  78. package/dist/sync/sync-innerspace-dest-ahead.withid.respec.d.mts +7 -0
  79. package/dist/sync/sync-innerspace-dest-ahead.withid.respec.d.mts.map +1 -0
  80. package/dist/sync/sync-innerspace-dest-ahead.withid.respec.mjs +225 -0
  81. package/dist/sync/sync-innerspace-dest-ahead.withid.respec.mjs.map +1 -0
  82. package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs.map +1 -1
  83. package/dist/sync/sync-innerspace-multiple-timelines.withid.respec.d.mts +7 -0
  84. package/dist/sync/sync-innerspace-multiple-timelines.withid.respec.d.mts.map +1 -0
  85. package/dist/sync/sync-innerspace-multiple-timelines.withid.respec.mjs +235 -0
  86. package/dist/sync/sync-innerspace-multiple-timelines.withid.respec.mjs.map +1 -0
  87. package/dist/sync/sync-innerspace-partial-update.withid.respec.d.mts +7 -0
  88. package/dist/sync/sync-innerspace-partial-update.withid.respec.d.mts.map +1 -0
  89. package/dist/sync/sync-innerspace-partial-update.withid.respec.mjs +211 -0
  90. package/dist/sync/sync-innerspace-partial-update.withid.respec.mjs.map +1 -0
  91. package/dist/sync/sync-innerspace.withid.respec.d.mts +8 -0
  92. package/dist/sync/sync-innerspace.withid.respec.d.mts.map +1 -0
  93. package/dist/sync/sync-innerspace.withid.respec.mjs +260 -0
  94. package/dist/sync/sync-innerspace.withid.respec.mjs.map +1 -0
  95. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-peer-websocket-receiver-v1.d.mts +1 -0
  96. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-peer-websocket-receiver-v1.d.mts.map +1 -1
  97. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-peer-websocket-receiver-v1.mjs +13 -4
  98. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-peer-websocket-receiver-v1.mjs.map +1 -1
  99. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.d.mts +1 -1
  100. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.d.mts.map +1 -1
  101. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.mjs +5 -3
  102. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.mjs.map +1 -1
  103. package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
  104. package/dist/sync/sync-saga-coordinator.mjs +165 -145
  105. package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
  106. package/dist/sync/sync-withid.pingpong.respec.mjs +8 -8
  107. package/dist/sync/sync-withid.pingpong.respec.mjs.map +1 -1
  108. package/dist/timeline/timeline-api.d.mts.map +1 -1
  109. package/dist/timeline/timeline-api.mjs +1 -14
  110. package/dist/timeline/timeline-api.mjs.map +1 -1
  111. package/dist/witness/space/reconciliation-space/reconciliation-space-base.d.mts.map +1 -1
  112. package/dist/witness/space/reconciliation-space/reconciliation-space-base.mjs +0 -40
  113. package/dist/witness/space/reconciliation-space/reconciliation-space-base.mjs.map +1 -1
  114. package/dist/witness/space/reconciliation-space/reconciliation-space-helper.d.mts.map +1 -1
  115. package/dist/witness/space/reconciliation-space/reconciliation-space-helper.mjs +6 -6
  116. package/dist/witness/space/reconciliation-space/reconciliation-space-helper.mjs.map +1 -1
  117. package/ibgib-foundations.md +2 -1
  118. package/package.json +1 -1
  119. package/src/common/other/graph-helper.mts +7 -6
  120. package/src/keystone/README.md +34 -17
  121. package/src/keystone/docs/CRYPTANALYSIS.md +185 -0
  122. package/src/keystone/docs/architecture.md +45 -3
  123. package/src/keystone/docs/delegation.md +57 -0
  124. package/src/keystone/docs/profiles.md +124 -0
  125. package/src/keystone/keystone-config-builder.mts +3 -21
  126. package/src/keystone/keystone-constants.mts +2 -1
  127. package/src/keystone/keystone-helpers.mts +204 -81
  128. package/src/keystone/keystone-policy-types.mts +6 -4
  129. package/src/keystone/keystone-service-v1.mts +223 -11
  130. package/src/keystone/keystone-service-v1.respec.mts +596 -39
  131. package/src/keystone/keystone-types.mts +55 -9
  132. package/src/keystone/policy/IMPLEMENTATION.md +60 -0
  133. package/src/keystone/policy/README.md +94 -0
  134. package/src/keystone/policy/keystone-profile-builder.mts +131 -0
  135. package/src/keystone/policy/profiles/profile-high.json +84 -0
  136. package/src/keystone/policy/profiles/profile-low.json +84 -0
  137. package/src/keystone/policy/profiles/profile-medium.json +84 -0
  138. package/src/keystone/policy/profiles/profile-session.json +84 -0
  139. package/src/keystone/policy/profiles/profile-test.json +84 -0
  140. package/src/keystone/policy/schemas/connect-pool.high.schema.json +23 -0
  141. package/src/keystone/policy/schemas/connect-pool.low.schema.json +23 -0
  142. package/src/keystone/policy/schemas/connect-pool.medium.schema.json +23 -0
  143. package/src/keystone/policy/schemas/keystone.high.schema.json +26 -0
  144. package/src/keystone/policy/schemas/keystone.low.schema.json +26 -0
  145. package/src/keystone/policy/schemas/keystone.medium.schema.json +26 -0
  146. package/src/keystone/policy/schemas/manage-pool.high.schema.json +23 -0
  147. package/src/keystone/policy/schemas/manage-pool.low.schema.json +23 -0
  148. package/src/keystone/policy/schemas/manage-pool.medium.schema.json +23 -0
  149. package/src/keystone/policy/schemas/revoke-pool.high.schema.json +23 -0
  150. package/src/keystone/policy/schemas/revoke-pool.low.schema.json +23 -0
  151. package/src/keystone/policy/schemas/revoke-pool.medium.schema.json +23 -0
  152. package/src/keystone/policy/schemas/sign-pool.high.schema.json +23 -0
  153. package/src/keystone/policy/schemas/sign-pool.low.schema.json +23 -0
  154. package/src/keystone/policy/schemas/sign-pool.medium.schema.json +23 -0
  155. package/src/keystone/policy/schemas/sync-pool.high.schema.json +23 -0
  156. package/src/keystone/policy/schemas/sync-pool.low.schema.json +23 -0
  157. package/src/keystone/policy/schemas/sync-pool.medium.schema.json +23 -0
  158. package/src/sync/docs/security.md +54 -21
  159. package/src/sync/sync-conflict-adv-multitimelines.withid.respec.mts +706 -0
  160. package/src/sync/sync-conflict-basic-divergence.withid.respec.mts +321 -0
  161. package/src/sync/sync-conflict-basic-multitimelines.withid.respec.mts +374 -0
  162. package/src/sync/sync-conflict-text-merge.withid.respec.mts +347 -0
  163. package/src/sync/sync-innerspace-constants.withid.respec.mts +264 -0
  164. package/src/sync/sync-innerspace-deep-updates.withid.respec.mts +272 -0
  165. package/src/sync/sync-innerspace-dest-ahead.withid.respec.mts +266 -0
  166. package/src/sync/sync-innerspace-multiple-timelines.respec.mts +0 -1
  167. package/src/sync/sync-innerspace-multiple-timelines.withid.respec.mts +273 -0
  168. package/src/sync/sync-innerspace-partial-update.withid.respec.mts +249 -0
  169. package/src/sync/sync-innerspace.withid.respec.mts +265 -0
  170. package/src/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-peer-websocket-receiver-v1.mts +12 -4
  171. package/src/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.mts +5 -3
  172. package/src/sync/sync-saga-coordinator.mts +159 -143
  173. package/src/sync/sync-withid.pingpong.respec.mts +8 -8
  174. package/src/timeline/timeline-api.mts +1 -15
  175. package/src/timeline/timeline-api.respec.mts +3 -3
  176. package/src/witness/space/reconciliation-space/reconciliation-space-base.mts +0 -46
  177. package/src/witness/space/reconciliation-space/reconciliation-space-helper.mts +6 -5
  178. package/tsconfig.json +6 -1
  179. package/src/keystone/keystone-policy.schema.json +0 -51
  180. package/src/witness/space/reconciliation-space/reconciliation-space-base.mts.OLD.md +0 -884
  181. package/src/witness/space/reconciliation-space/reconciliation-space-helper.mts.OLD.md +0 -125
@@ -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';
11
13
  import {
12
- addToBindingMap, createKeystoneIbGibImpl, evolvePersistAndRegisterKeystone,
14
+ POOL_ID_REVOKE, KEYSTONE_VERB_REVOKE, KEYSTONE_VERB_MANAGE,
15
+ KEYSTONE_CHECKPOINT_FREQUENCY, POOL_ID_MANAGE
16
+ } from './keystone-constants.mjs';
17
+ import {
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
 
@@ -54,7 +62,6 @@ export class KeystoneService_V1 {
54
62
  const strategy = KeystoneStrategyFactory.create({ config });
55
63
  const poolSecret = await strategy.derivePoolSecret({ masterSecret });
56
64
  const challenges: { [id: string]: any } = {};
57
- const bindingMap: { [char: string]: string[] } = {};
58
65
 
59
66
  const targetSize = config.behavior.size;
60
67
  const timestamp = Date.now().toString();
@@ -69,16 +76,12 @@ export class KeystoneService_V1 {
69
76
  });
70
77
  const challenge = await strategy.generateChallenge({ solution });
71
78
  challenges[challengeId] = challenge;
72
-
73
- // Populate Binding Map
74
- addToBindingMap(bindingMap, challengeId);
75
79
  }
76
80
 
77
81
  challengePools.push({
78
82
  id: config.id,
79
83
  config,
80
84
  challenges,
81
- bindingMap
82
85
  });
83
86
  }
84
87
 
@@ -115,6 +118,7 @@ export class KeystoneService_V1 {
115
118
  frameDetails,
116
119
  metaspace,
117
120
  space,
121
+ dataToPatch,
118
122
  }: {
119
123
  latestKeystone: KeystoneIbGib_V1;
120
124
  /**
@@ -138,6 +142,7 @@ export class KeystoneService_V1 {
138
142
  frameDetails?: any;
139
143
  metaspace: MetaspaceService;
140
144
  space: IbGibSpaceAny;
145
+ dataToPatch?: Partial<KeystoneData_V1>;
141
146
  }): Promise<KeystoneIbGib_V1> {
142
147
  const lc = `${this.lc}[${this.sign.name}]`;
143
148
  try {
@@ -158,7 +163,7 @@ export class KeystoneService_V1 {
158
163
  if (logalot) { console.log(`${lc} Selected pool: ${pool.id} (size: ${Object.keys(pool.challenges).length}) (I: 6b26d6f4aad18380f2b3a0989b592826)`); }
159
164
 
160
165
  // 2. Calculate Costs (Select IDs)
161
- const idsToSolve = selectChallengeIds({
166
+ const idsToSolve = await selectChallengeIds({
162
167
  pool,
163
168
  targetAddr: claim.target,
164
169
  requiredChallengeIds
@@ -198,6 +203,8 @@ export class KeystoneService_V1 {
198
203
  proofs: [proof],
199
204
  frameDetails,
200
205
  checkpointDetails,
206
+ ...(prevData.delegates ? { delegates: prevData.delegates } : {}),
207
+ ...dataToPatch,
201
208
  };
202
209
 
203
210
  // 5. Commit (Evolve, Persist, Register)
@@ -241,6 +248,209 @@ export class KeystoneService_V1 {
241
248
  return errors;
242
249
  }
243
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
+ }: {
264
+ parentKeystone: KeystoneIbGib_V1;
265
+ delegateKeystone: KeystoneIbGib_V1;
266
+ masterSecret: string;
267
+ frameDetails?: any;
268
+ metaspace: MetaspaceService;
269
+ space: IbGibSpaceAny;
270
+ }): Promise<KeystoneIbGib_V1> {
271
+ const lc = `${this.lc}[${this.registerDelegate.name}]`;
272
+ try {
273
+ if (logalot) { console.log(`${lc} starting...`); }
274
+
275
+ // 1. Validate the delegate keystone's entire graph/timeline
276
+ const validationErrors = await validateKeystoneGraph({
277
+ keystoneIbGib: delegateKeystone,
278
+ getLatest: true,
279
+ invalidIfMoreRecentKeystoneFoundInSpace: false,
280
+ space,
281
+ });
282
+ if (validationErrors.length > 0) {
283
+ throw new Error(`Delegate keystone validation failed: ${validationErrors.join(', ')} (E: 88fa8ab28c9b60e68994511a5825)`);
284
+ }
285
+
286
+ // 2. Verify that parent contains POOL_ID_MANAGE pool configuration
287
+ const prevData = parentKeystone.data!;
288
+ const hasManagePool = prevData.challengePools.some(p => p.id === POOL_ID_MANAGE);
289
+ if (!hasManagePool) {
290
+ throw new Error(`Parent keystone does not support delegation. Manage pool is required. (E: 818fa8ab28c9b60e68994511a5825)`);
291
+ }
292
+
293
+ const delegateTjpAddr = getTjpAddr({ ibGib: delegateKeystone });
294
+ if (!delegateTjpAddr) { throw new Error(`(UNEXPECTED) delegateTjpAddr falsy? (E: d4d6e8ad03c8925d4838b9a87b8f2826)`); }
295
+
296
+ // 3. Prepare the claim
297
+ const claim: Partial<KeystoneClaim> = {
298
+ target: delegateTjpAddr,
299
+ verb: KEYSTONE_VERB_MANAGE,
300
+ };
301
+
302
+ // 4. Update the delegates map
303
+ const currentDelegates = prevData.delegates ? { ...prevData.delegates } : {};
304
+ currentDelegates[delegateTjpAddr] = {
305
+ delegateTjpAddr,
306
+ delegateAddr: getIbGibAddr({ ibGib: delegateKeystone }),
307
+ thisAddr: getIbGibAddr({ ibGib: parentKeystone }),
308
+ };
309
+
310
+ // 5. Sign & evolve parent keystone using the 'manage' pool
311
+ const evolved = await this.sign({
312
+ latestKeystone: parentKeystone,
313
+ masterSecret,
314
+ claim,
315
+ poolId: POOL_ID_MANAGE,
316
+ frameDetails,
317
+ metaspace,
318
+ space,
319
+ dataToPatch: {
320
+ delegates: currentDelegates
321
+ }
322
+ });
323
+
324
+ return evolved;
325
+ } catch (error) {
326
+ console.error(`${lc} ${extractErrorMsg(error)}`);
327
+ throw error;
328
+ } finally {
329
+ if (logalot) { console.log(`${lc} complete.`); }
330
+ }
331
+ }
332
+
333
+ /**
334
+ * Unregisters a delegate keystone from the parent keystone by removing its entry
335
+ * from the parent's `delegates` map. This operation is signed using the parent's `manage` pool.
336
+ */
337
+ async unregisterDelegate({
338
+ parentKeystone,
339
+ delegateTjpAddr,
340
+ masterSecret,
341
+ frameDetails,
342
+ metaspace,
343
+ space,
344
+ }: {
345
+ parentKeystone: KeystoneIbGib_V1;
346
+ delegateTjpAddr: IbGibAddr;
347
+ masterSecret: string;
348
+ frameDetails?: any;
349
+ metaspace: MetaspaceService;
350
+ space: IbGibSpaceAny;
351
+ }): Promise<KeystoneIbGib_V1> {
352
+ const lc = `${this.lc}[${this.unregisterDelegate.name}]`;
353
+ try {
354
+ if (logalot) { console.log(`${lc} starting...`); }
355
+
356
+ // 1. Verify that parent contains POOL_ID_MANAGE pool configuration
357
+ const prevData = parentKeystone.data!;
358
+ const hasManagePool = prevData.challengePools.some(p => p.id === POOL_ID_MANAGE);
359
+ if (!hasManagePool) {
360
+ throw new Error(`Parent keystone does not support delegation. Manage pool is required. (E: 3889f8ab28c9b60e68994511a5825)`);
361
+ }
362
+
363
+ // 2. Prepare the claim
364
+ const claim: Partial<KeystoneClaim> = {
365
+ target: delegateTjpAddr,
366
+ verb: KEYSTONE_VERB_MANAGE,
367
+ };
368
+
369
+ // 3. Update the delegates map
370
+ const currentDelegates = prevData.delegates ? { ...prevData.delegates } : {};
371
+ if (!currentDelegates[delegateTjpAddr]) {
372
+ throw new Error(`Delegate ${delegateTjpAddr} is not registered on this parent. (E: 81d9f8ab28c9b60e68994511a5825)`);
373
+ }
374
+ delete currentDelegates[delegateTjpAddr];
375
+
376
+ // 4. Sign & evolve parent keystone using the 'manage' pool
377
+ const evolved = await this.sign({
378
+ latestKeystone: parentKeystone,
379
+ masterSecret,
380
+ claim,
381
+ poolId: POOL_ID_MANAGE,
382
+ frameDetails,
383
+ metaspace,
384
+ space,
385
+ dataToPatch: {
386
+ delegates: currentDelegates
387
+ }
388
+ });
389
+
390
+ return evolved;
391
+ } catch (error) {
392
+ console.error(`${lc} ${extractErrorMsg(error)}`);
393
+ throw error;
394
+ } finally {
395
+ if (logalot) { console.log(`${lc} complete.`); }
396
+ }
397
+ }
398
+
399
+ /**
400
+ * Gets the registration status of a delegate keystone from the parent's latest tip frame.
401
+ */
402
+ async getDelegateStatus({
403
+ parentTjpAddr,
404
+ delegateTjpAddr,
405
+ metaspace,
406
+ space,
407
+ }: {
408
+ parentTjpAddr: IbGibAddr;
409
+ delegateTjpAddr: IbGibAddr;
410
+ metaspace: MetaspaceService;
411
+ space: IbGibSpaceAny;
412
+ }): Promise<DelegateKeystoneStatus> {
413
+ const lc = `${this.lc}[${this.getDelegateStatus.name}]`;
414
+ try {
415
+ if (logalot) { console.log(`${lc} starting...`); }
416
+
417
+ const { ib, gib } = getIbAndGib({ ibGibAddr: parentTjpAddr });
418
+ const parentIbGib: IbGib_V1 = { ib, gib };
419
+ const resGetLatest = await getLatestAddrs({
420
+ ibGibs: [parentIbGib],
421
+ space,
422
+ });
423
+
424
+ if (!resGetLatest.data?.latestAddrsMap) {
425
+ return { registered: false };
426
+ }
427
+
428
+ const latestAddr = resGetLatest.data.latestAddrsMap[parentTjpAddr];
429
+ if (!latestAddr) {
430
+ return { registered: false };
431
+ }
432
+
433
+ const resGet = await metaspace.get({ addr: latestAddr, space });
434
+ const latestParent = resGet.ibGibs?.at(0) as KeystoneIbGib_V1;
435
+ if (!latestParent || !latestParent.data) {
436
+ return { registered: false };
437
+ }
438
+
439
+ const delegates = latestParent.data.delegates || {};
440
+ const delegateInfo = delegates[delegateTjpAddr];
441
+
442
+ return {
443
+ registered: !!delegateInfo,
444
+ delegateInfo,
445
+ };
446
+ } catch (error) {
447
+ console.error(`${lc} ${extractErrorMsg(error)}`);
448
+ throw error;
449
+ } finally {
450
+ if (logalot) { console.log(`${lc} complete.`); }
451
+ }
452
+ }
453
+
244
454
  /**
245
455
  * Validates a genesis keystone.
246
456
  *
@@ -384,7 +594,7 @@ export class KeystoneService_V1 {
384
594
  };
385
595
 
386
596
  // 3. Calculate Costs
387
- const idsToSolve = selectChallengeIds({
597
+ const idsToSolve = await selectChallengeIds({
388
598
  pool,
389
599
  targetAddr: claim.target,
390
600
  requiredChallengeIds: []
@@ -434,6 +644,7 @@ export class KeystoneService_V1 {
434
644
  revocationInfo,
435
645
  frameDetails,
436
646
  checkpointDetails,
647
+ ...(prevData.delegates ? { delegates: prevData.delegates } : {}),
437
648
  };
438
649
 
439
650
  // 7. Commit
@@ -515,7 +726,7 @@ export class KeystoneService_V1 {
515
726
  };
516
727
 
517
728
  // 3. Calculate Costs
518
- const idsToSolve = selectChallengeIds({
729
+ const idsToSolve = await selectChallengeIds({
519
730
  pool: adminPool,
520
731
  targetAddr: target
521
732
  });
@@ -560,6 +771,7 @@ export class KeystoneService_V1 {
560
771
  challengePools: finalPools,
561
772
  proofs: [proof], // The proof authorizes the structure change
562
773
  checkpointDetails,
774
+ ...(prevData.delegates ? { delegates: prevData.delegates } : {}),
563
775
  };
564
776
 
565
777
  // 7. Commit