@ibgib/core-gib 0.1.65 → 0.1.66

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 (21) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/keystone/keystone-service-v1.d.mts +54 -18
  3. package/dist/keystone/keystone-service-v1.d.mts.map +1 -1
  4. package/dist/keystone/keystone-service-v1.mjs +56 -21
  5. package/dist/keystone/keystone-service-v1.mjs.map +1 -1
  6. package/dist/keystone/keystone-service-v1.respec.mjs +744 -471
  7. package/dist/keystone/keystone-service-v1.respec.mjs.map +1 -1
  8. package/dist/keystone/keystone-types.d.mts +9 -1
  9. package/dist/keystone/keystone-types.d.mts.map +1 -1
  10. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.d.mts +27 -4
  11. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.d.mts.map +1 -1
  12. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.mjs +230 -135
  13. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.mjs.map +1 -1
  14. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-sender/sync-peer-websocket-sender-v1.mjs +1 -1
  15. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-sender/sync-peer-websocket-sender-v1.mjs.map +1 -1
  16. package/package.json +1 -1
  17. package/src/keystone/keystone-service-v1.mts +112 -32
  18. package/src/keystone/keystone-service-v1.respec.mts +791 -556
  19. package/src/keystone/keystone-types.mts +9 -1
  20. package/src/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.mts +294 -131
  21. package/src/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-sender/sync-peer-websocket-sender-v1.mts +1 -1
@@ -31,6 +31,7 @@ import { IbGibSpaceAny } from '../witness/space/space-base-v1.mjs';
31
31
  import { MetaspaceService } from '../witness/space/metaspace/metaspace-types.mjs';
32
32
  import { FlatIbGibGraph } from '../common/other/graph-types.mjs';
33
33
  import { getTjpAddr } from '../common/other/ibgib-helper.mjs';
34
+ import { deriveDelegateSecret } from './strategy/hash-reveal-v1/hash-reveal-v1.mjs';
34
35
 
35
36
  const logalot = GLOBAL_LOG_A_LOT;
36
37
 
@@ -1060,19 +1061,19 @@ export class KeystoneService_V1 {
1060
1061
  /**
1061
1062
  * Replaces a challenge pool (such as manage or custodian-manage) with a new pool,
1062
1063
  * authorizing the transition via the specified signing pool.
1063
- *
1064
+ *
1064
1065
  * @param latestKeystone The current tip frame of the keystone timeline.
1065
1066
  * - Visibility: Public (Public Merkle frame, safe for logs/ledger).
1066
1067
  * - Generator: Client/Server (Constructed locally and synced).
1067
- *
1068
+ *
1068
1069
  * @param newPool The fully constructed new pool to place in the next frame.
1069
1070
  * - Visibility: Public (Public configuration and public challenges, safe for ledger).
1070
1071
  * - Generator: Client/Server (Generated dynamically by the party proposing the update).
1071
- *
1072
+ *
1072
1073
  * @param signingSecret The master secret or derived KDF secret of the pool authorizing the change.
1073
1074
  * - Visibility: Private (Confidential secret credential. Must never go over the wire).
1074
1075
  * - Generator: Client/Server (Known only to the signing party).
1075
- *
1076
+ *
1076
1077
  * @param signingPoolId The ID of the pool used to authorize the transition (defaults to 'manage').
1077
1078
  * - Visibility: Public (Non-sensitive configuration string).
1078
1079
  * - Generator: Client/Server (From pool configuration).
@@ -1186,28 +1187,17 @@ export class KeystoneService_V1 {
1186
1187
  /**
1187
1188
  * Evolve the keystone by rotating the primary user manage pool (`manage`) to a new master secret (passphrase).
1188
1189
  * This creates a new frame signed by the specified `signingPoolId` using `signingSecret`.
1189
- *
1190
- * Supports recovery (signing via `custodian-manage` using the custodian secret) and normal rotation
1191
- * (signing via `manage` using the old password).
1192
- *
1193
- * @param latestKeystone The current tip frame of the keystone.
1194
- * - Visibility: Public (Public Merkle frame, safe for ledger).
1195
- * - Generator: Client/Server (Constructed locally and synced).
1196
- *
1197
- * @param newMasterSecret The new passphrase/master secret to set for the user's primary pools.
1198
- * - Visibility: Private (Confidential secret credential. Must never go over the wire).
1199
- * - Generator: Client (From user input in settings).
1200
- *
1201
- * @param signingSecret The secret of the pool authorizing this change (either old passphrase or derived custodian secret).
1202
- * - Visibility: Private (Confidential secret. Must never go over the wire).
1203
- * - Generator: Client/Server (Known only to the signing party).
1204
- *
1205
- * @param signingPoolId The ID of the pool used to authorize the rotation (defaults to 'manage').
1206
- * - Visibility: Public (Non-sensitive ID string).
1207
- * - Generator: Client/Server (From pool configuration).
1190
+ *
1191
+ * Supports recovery (signing via `custodian-manage` using the custodian secret) and normal rotation
1192
+ * (signing via `manage` using the old password). **I DONT THINK THIS IS POSSIBLE. WE WOULD NEED CUSTODIAN MANAGE POOLS ON ALL THE DELEGATES AS WELL**
1193
+ *
1194
+ * @param signingSecret
1195
+ *
1196
+ * @param signingPoolId
1208
1197
  */
1209
1198
  async changePassword({
1210
- latestKeystone,
1199
+ keystoneIbGib,
1200
+ keystoneAddr,
1211
1201
  newMasterSecret,
1212
1202
  signingSecret,
1213
1203
  signingPoolId = POOL_ID_MANAGE,
@@ -1216,21 +1206,82 @@ export class KeystoneService_V1 {
1216
1206
  metaspace,
1217
1207
  space,
1218
1208
  }: {
1219
- latestKeystone: KeystoneIbGib_V1;
1209
+ /**
1210
+ * The keystone IBGIB whose password we are changing. Does NOT have to
1211
+ * be the tip, as we will get the latest keystone in the implementation
1212
+ * of this function.
1213
+ * - Visibility: Public (Public Merkle frame, safe for ledger).
1214
+ * - Generator: Client/Server (Constructed locally and synced).
1215
+ *
1216
+ * NOTE: You can provide {@link keystoneIbGib} or {@link keystoneAddr},
1217
+ * but either way the latest keystone ibgib will be gotten first.
1218
+ */
1219
+ keystoneIbGib?: KeystoneIbGib_V1;
1220
+ /**
1221
+ * The keystone ADDRESS whose password we are changing. Does NOT have to
1222
+ * be the tip, as we will get the latest keystone in the implementation
1223
+ * of this function.
1224
+ * - Visibility: Public (Public Merkle frame, safe for ledger).
1225
+ * - Generator: Client/Server (Constructed locally and synced).
1226
+ *
1227
+ * NOTE: You can provide {@link keystoneIbGib} or {@link keystoneAddr},
1228
+ * but either way the latest keystone ibgib will be gotten first.
1229
+ */
1230
+ keystoneAddr?: IbGibAddr;
1231
+ /**
1232
+ * The new passphrase/master secret to set for the user's primary pools.
1233
+ * - Visibility: Private (Confidential secret credential. Must never go
1234
+ * over the wire).
1235
+ * - Generator: Client (From user input in settings).
1236
+ */
1220
1237
  newMasterSecret: string;
1238
+ /**
1239
+ * The secret of the pool authorizing this change (either old passphrase
1240
+ * or derived custodian secret).
1241
+ * - Visibility: Private (Confidential secret. Never over the wire).
1242
+ * - Generator: Client/Server (Known only to the signing party).
1243
+ */
1221
1244
  signingSecret: string;
1245
+ /**
1246
+ * The ID of the pool used to authorize the rotation. Defaults to
1247
+ * "manage" for user password changes, or if rotating custodian, should
1248
+ * be the custodian's corresponding manage pool.
1249
+ * - Visibility: Public (Non-sensitive ID string).
1250
+ * - Generator: Client/Server (From pool configuration).
1251
+ */
1222
1252
  signingPoolId?: string;
1253
+ /**
1254
+ * If provided, password will only be changed for these pools.
1255
+ * NOTE: **delegate passwords will NOT be changed if poolIds are
1256
+ * explicitly provided.**
1257
+ */
1223
1258
  poolIds?: string[];
1224
1259
  frameDetails?: any;
1225
1260
  metaspace: MetaspaceService;
1226
1261
  space: IbGibSpaceAny;
1227
- }): Promise<KeystoneIbGib_V1> {
1262
+ }): Promise<{ newKeystone: KeystoneIbGib_V1, newDelegates?: KeystoneIbGib_V1[] }> {
1228
1263
  const lc = `${this.lc}[${this.changePassword.name}]`;
1229
1264
  try {
1230
- if (logalot) { console.log(`${lc} starting...`); }
1231
-
1232
- if (!latestKeystone.data) { throw new Error(`latestKeystone.data falsy`); }
1233
- if (latestKeystone.data.revocationInfo) { throw new Error(`Keystone has been revoked. Cannot change password. (E: 8599f8f51c78d722252ddb2894fdbe25)`); }
1265
+ if (logalot) { console.log(`${lc} starting... (I: 9e3ff83ebd74511f9dad784a1020d926)`); }
1266
+
1267
+ if (!keystoneIbGib && !keystoneAddr) { throw new Error(`Either keystoneIbGib or keystoneAddr required. (E: d1b8c8cb75f2c022284e69b8c30af826)`); }
1268
+ if (keystoneIbGib && keystoneAddr) {
1269
+ // double check addr matches ibgib
1270
+ const checkAddr = getIbGibAddr({ ibGib: keystoneIbGib });
1271
+ if (checkAddr !== keystoneAddr) { throw new Error(`(UNEXPECTED) both keystoneIbGib (addr: ${checkAddr}) and keystoneAddr (${keystoneAddr}) provided, but the addrs are unequal? Note that only one is required for this function, but if both are provided the addrs must match exactly. (E: c5574f7e353a48b0bba94a1862af4e26)`); }
1272
+ }
1273
+
1274
+ keystoneAddr ??= getIbGibAddr({ ibGib: keystoneIbGib });
1275
+
1276
+ const latestKeystone = await this.getLatestKeystone({
1277
+ addr: keystoneAddr,
1278
+ metaspace,
1279
+ space,
1280
+ });
1281
+
1282
+ if (!latestKeystone.data) { throw new Error(`latestKeystone.data falsy (E: 22e498eb8308a33e68b812d8d3905826)`); }
1283
+ if (latestKeystone.data.revocationInfo) { throw new Error(`Keystone has been revoked. Cannot change password. (E: 726298617e8508b3c83b5e985a03e826)`); }
1284
+
1234
1285
 
1235
1286
  const prevPools = latestKeystone.data.challengePools;
1236
1287
  const signingPool = prevPools.find(p => p.id === signingPoolId);
@@ -1320,19 +1371,48 @@ export class KeystoneService_V1 {
1320
1371
  proofs: [proof],
1321
1372
  frameDetails,
1322
1373
  checkpointDetails,
1323
- ...(latestKeystone.data.delegates ? { delegates: latestKeystone.data.delegates } : {}),
1374
+ ...(latestKeystone.data.delegates ? { delegates: latestKeystone.data.delegates } : undefined),
1324
1375
  };
1325
1376
 
1326
1377
  // 8. Commit
1327
- return await evolvePersistAndRegisterKeystone({
1378
+ const newKeystoneIbGib = await evolvePersistAndRegisterKeystone({
1328
1379
  prevIbGib: latestKeystone,
1329
1380
  newData,
1330
1381
  metaspace,
1331
1382
  space
1332
1383
  });
1384
+
1385
+ // update delegates' passwords also, **BUT ONLY IF NOT DOING
1386
+ // SPECIFIC POOLS**.
1387
+ const newDelegates: KeystoneIbGib_V1[] = [];
1388
+ if ((poolIds ?? []).length === 0) {
1389
+ const delegateSigningSecret = await deriveDelegateSecret({ masterSecret: signingSecret });
1390
+ const delegateNewMasterSecret = await deriveDelegateSecret({ masterSecret: newMasterSecret });
1391
+ const delegateTjpAddrs = Object.keys(latestKeystone.data.delegates ?? {});
1392
+ for (const delegateTjpAddr of delegateTjpAddrs) {
1393
+ const { newKeystone: newDelegate, newDelegates: newDelegatesSecondOrder } = await this.changePassword({
1394
+ keystoneAddr: delegateTjpAddr,
1395
+ metaspace,
1396
+ space,
1397
+ newMasterSecret: delegateNewMasterSecret,
1398
+ signingSecret: delegateSigningSecret,
1399
+ signingPoolId,
1400
+ poolIds: undefined,
1401
+ frameDetails,
1402
+ });
1403
+ if (newDelegatesSecondOrder && newDelegatesSecondOrder.length > 0) {
1404
+ throw new Error(`(UNEXPECTED) Delegate keystone has its own delegate(s)? ATOW (07/20/2026) second order delegates are not supported. (E: de45a7b7d9b8f61f6e58158269acba26)`);
1405
+ }
1406
+ newDelegates.push(newDelegate);
1407
+ }
1408
+ }
1409
+
1410
+ return { newKeystone: newKeystoneIbGib, newDelegates: newDelegates.length > 0 ? newDelegates : undefined };
1333
1411
  } catch (error) {
1334
1412
  console.error(`${lc} ${extractErrorMsg(error)}`);
1335
1413
  throw error;
1414
+ } finally {
1415
+ if (logalot) { console.log(`${lc} complete.`); }
1336
1416
  }
1337
1417
  }
1338
1418