@tangle-network/agent-app 0.60.267 → 0.60.269

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.
@@ -47,8 +47,20 @@ export interface DelegatedTurnKey {
47
47
  /** Parked before this turn: a revoked or expired refusal of it means mint inline (`delegatedKeyFallbackFetch`). */
48
48
  preminted: boolean;
49
49
  }
50
- export type DelegatedTurnKeyEvent = {
51
- type: 'claimed' | 'missed' | 'parked' | 'park_kept';
50
+ export interface DelegatedTurnKeyClaimTiming {
51
+ digestMs: number;
52
+ storeMs: number;
53
+ decryptMs?: number;
54
+ }
55
+ export type DelegatedTurnKeyEvent =
56
+ /** `timing` splits the claim on the turn's path: the scope digest, the slot's `DELETE … RETURNING` round trip, and
57
+ * (claimed only) the decrypt. */
58
+ {
59
+ type: 'claimed' | 'missed';
60
+ slot: string;
61
+ timing?: DelegatedTurnKeyClaimTiming;
62
+ } | {
63
+ type: 'parked' | 'park_kept';
52
64
  slot: string;
53
65
  }
54
66
  /** `keyId` names a child minted but not parked (retired best effort); never its key. */
@@ -1194,14 +1194,21 @@ function createDelegatedTurnKeys(options) {
1194
1194
  } } : {}
1195
1195
  }).catch(() => null);
1196
1196
  }
1197
- async function claim(input) {
1197
+ async function claim(input, timing) {
1198
1198
  if (!db) return null;
1199
1199
  const { slot, scope } = input;
1200
+ let at = Date.now();
1201
+ const digest = await scopeDigest(scope);
1202
+ timing.digestMs = Date.now() - at;
1203
+ at = Date.now();
1200
1204
  const row = await db.prepare(`DELETE FROM ${table} WHERE slot = ?1 AND scope = ?2 AND expires_at > ?3
1201
- RETURNING turn_id, key_id, key_encrypted, expires_at`).bind(slot, await scopeDigest(scope), now() + minRemainingMs).first();
1205
+ RETURNING turn_id, key_id, key_encrypted, expires_at`).bind(slot, digest, now() + minRemainingMs).first();
1206
+ timing.storeMs = Date.now() - at;
1202
1207
  if (!row) return null;
1203
1208
  try {
1209
+ at = Date.now();
1204
1210
  const key = await options.crypto.decrypt(row.key_encrypted);
1211
+ timing.decryptMs = Date.now() - at;
1205
1212
  return { key, id: row.key_id, turnId: row.turn_id, expiresAt: new Date(row.expires_at), preminted: true };
1206
1213
  } catch {
1207
1214
  await retire(input, row.key_id);
@@ -1254,7 +1261,8 @@ VALUES (?1, ?2, ?3, ?4, ?5, ?6) ON CONFLICT(slot) DO NOTHING RETURNING slot`).bi
1254
1261
  }
1255
1262
  return {
1256
1263
  async forTurn(input) {
1257
- const claimed = await claim(input).catch(() => null);
1264
+ const timing = {};
1265
+ const claimed = await claim(input, timing).catch(() => null);
1258
1266
  if (db) {
1259
1267
  const next = park({
1260
1268
  slot: input.slot,
@@ -1265,7 +1273,11 @@ VALUES (?1, ?2, ?3, ?4, ?5, ?6) ON CONFLICT(slot) DO NOTHING RETURNING slot`).bi
1265
1273
  });
1266
1274
  input.waitUntil?.(next);
1267
1275
  }
1268
- emit({ type: claimed ? "claimed" : "missed", slot: input.slot });
1276
+ emit({
1277
+ type: claimed ? "claimed" : "missed",
1278
+ slot: input.slot,
1279
+ ...timing.digestMs !== void 0 && timing.storeMs !== void 0 ? { timing } : {}
1280
+ });
1269
1281
  return claimed ? { succeeded: true, value: claimed } : mint(input, false);
1270
1282
  },
1271
1283
  park,