1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
//! Central registry of the VTA's keyspace names.
//!
//! Every `store.keyspace(..)` call in the VTA (`vta-service` server, offline
//! CLIs, backup, tests) names its keyspace through a `const` here rather than a
//! bare string literal. This is the single source of truth that killed the
//! `"imported"` / `"imported_secrets"` test-vs-production divergence (a test
//! opened a *different*, empty keyspace than the one production writes). The
//! `no_bare_keyspace_literals` guard in `vta-service` keeps it that way by
//! scanning that crate's source for bare `.keyspace("…")` literals.
//!
//! Keyspace *names* live here; per-keyspace *key formats* (the `key:`, `seed:`,
//! `path_counter:` … record families inside a keyspace) are a separate concern
//! and are not yet centralised.
//!
//! A near-leaf crate: it holds the shared keyspace vocabulary (the name
//! constants) plus the [`Keyspaces`] handle bundle, so that every VTA subsystem
//! crate can name and pass keyspaces without depending on `vta-service`. Its
//! only dependency is `vti-common` (for `KeyspaceHandle`).
use KeyspaceHandle;
/// Shared bundle of borrowed keyspace handles passed to operations that need
/// several keyspaces at once.
///
/// The struct is a pure field bundle — the constructors that borrow it from a
/// concrete `AppState` / `VtaState` live in `vta-service` (they know those
/// types), so this stays free of any `vta-service` dependency.
/// Master seed + key records (`key:`, `seed:`, `path_counter:`,
/// `active_seed_id`, `imported_kek_salt`, …) and the backup import sentinel.
pub const KEYS: &str = "keys";
/// Auth sessions + challenges.
pub const SESSIONS: &str = "sessions";
/// ACL entries + the seal record + the integrity-anchor root.
pub const ACL: &str = "acl";
/// Trust contexts (the BIP-32 key hierarchy roots).
pub const CONTEXTS: &str = "contexts";
/// Stored DID templates (global + context-scoped).
pub const DID_TEMPLATES: &str = "did_templates";
/// Audit log.
pub const AUDIT: &str = "audit";
/// The keyed-hash keys the audit log commits actor and target identifiers
/// under, and their history.
///
/// Separate from [`AUDIT`] because the two have opposite lifetimes: entries
/// are erased when their retention expires, and a key must outlive every entry
/// that references it or those entries stop being checkable against a
/// candidate identifier.
pub const AUDIT_KEY: &str = "audit_key";
/// Imported secret material (KEK-wrapped). Named `imported_secrets`, **not**
/// `imported` — the latter was a long-standing test-only typo that operated on
/// an empty keyspace disjoint from production. Always reference this const.
pub const IMPORTED_SECRETS: &str = "imported_secrets";
/// Non-extractable internal signing keys.
///
/// Deliberately **not** [`IMPORTED_SECRETS`]: that keyspace wraps its contents
/// under a KEK derived from the BIP-39 master seed, so anything stored there is
/// reconstructible by whoever holds the mnemonic. Internal keys exist precisely
/// to have no such path — their material is generated from the system CSPRNG,
/// never derived, and lives here instead.
///
/// In [`EXCLUDED_FROM_BACKUP`] by design, not by omission. A backup containing
/// this keyspace would be an export of keys the VTA promises never to export.
pub const INTERNAL_KEYS: &str = "internal_keys";
/// Ephemeral cache (resolver/auth caches).
pub const CACHE: &str = "cache";
/// Holder credential vault (third-party secrets stored on this VTA).
pub const VAULT: &str = "vault";
/// Persistent runtime service-enable state (`operations::protocol::runtime_state`).
pub const SERVICE_STATE: &str = "service_state";
/// Sealed-bootstrap anti-replay nonce log.
pub const SEALED_NONCES: &str = "sealed_nonces";
/// In-flight backup-bundle control-plane records.
pub const BACKUP_BUNDLES: &str = "backup_bundles";
/// WebVH DID records + `did.jsonl` state.
pub const WEBVH: &str = "webvh";
/// In-flight passkey-as-verificationMethod enrolment state.
pub const PASSKEY_VMS: &str = "passkey_vms";
/// Persisted protocol-management drain set.
pub const DRAINS: &str = "drains";
/// Per-kind previous-config snapshots for fail-forward rollback.
/// (Historically `operations::protocol::snapshot::KEYSPACE_NAME`.)
pub const SNAPSHOT: &str = "service_prev_config";
/// KMS-protected, unencrypted boot keyspace (TEE integrity manifest, etc.).
pub const BOOTSTRAP: &str = "bootstrap";
/// Inbound-messaging consent: durable grants + TTL'd pending requests
/// (`vti_common::consent`). The VTA is the first gate for bridged conversations.
pub const CONSENT: &str = "consent";
/// Per-(platform, context) approver bindings — who decides consent and how the
/// prompt routes (`vti_common::consent::ApproverBinding`).
pub const CONSENT_APPROVERS: &str = "consent_approvers";
/// VTA-issued credentials (minted by `vta/credentials/issue/0.1`, revoked by
/// `vta/credentials/revoke/0.1`). One record per credential keyed `cred:<id>`;
/// revocation is a tombstone (`revokedAt` set in place), not a delete. Distinct
/// from [`VAULT`] (which stores credentials the holder *holds*).
pub const ISSUED_CREDENTIALS: &str = "issued_credentials";
/// Per-context key/value store for AI-agent memory (`vta/memory/{put,list,
/// delete}/0.1`). One record per `(contextId, key)` pair, keyed
/// `mem:<contextId>:<key>`; `list` is a `mem:<contextId>:` prefix scan. Durable
/// user data → in [`BACKED_UP`].
pub const MEMORY: &str = "memory";
/// A member's MLS group state for each data room they belong to
/// (`rooms/keys/{welcome,commit,open}`), keyed `room-group:<roomId>`.
///
/// **This holds group secrets.** Whoever reads a row can decrypt every record
/// the group could, up to its epoch — the same class of material as [`KEYS`],
/// and it inherits the same protection: the KMS storage key in a TEE
/// deployment, and a trusted data directory outside one.
///
/// In [`BACKED_UP`], and that is a decision rather than a default. A member who
/// restores a VTA without their room groups has lost the ability to read every
/// sealed room they belong to, with no way to recover it — the group cannot be
/// re-derived, and rejoining means a fresh invitation from every owner. The
/// backup already carries the credential vault and the master seed; group state
/// belongs with them.
pub const ROOM_GROUPS: &str = "room_groups";
/// Invitation credentials this VTA has consumed by joining a room
/// (`rooms/keys/welcome`), keyed `room-vic:<credentialId>`.
///
/// Separate from [`ROOM_GROUPS`] because it outlives them: a member who leaves a
/// room discards the group, and the consumed-invitation record must survive that
/// or the same invitation would let them be re-added without a fresh one. Single
/// use means single use.
pub const ROOM_INVITATIONS: &str = "room_invitations";
/// The holder's identity attributes, profiles, bindings and contacts
/// (`persona/*`) — the fourth store, beside [`VAULT`] (secrets and
/// credentials), [`MEMORY`] (agent memory) and [`APP_STATE`] (uninterpreted
/// application JSON).
///
/// It is a distinct store because disclosure control is its point, and a
/// maintainer that cannot read a record cannot decide which of its members may
/// leave, cannot audit which ones did, and cannot answer "what have I shared
/// with whom". [`APP_STATE`] promises never to interpret its records, so it
/// cannot host this; and a namespace there is collision avoidance rather than a
/// trust boundary, so a compromised application sharing a context could remove
/// the holder's identity data.
///
/// **Two scopes share the keyspace, and the split is a security control rather
/// than a filing decision.** The pool and profiles are *agent-scoped* — above
/// every context — so that the correlation index can see the risk it most needs
/// to report: the same value presented by two personas in two different
/// contexts, which a per-context index cannot see by construction. Bindings,
/// contacts and disclosure records are context-scoped, because a persona lives
/// in a context and so do its counterparties.
///
/// Nothing inside a context may read the agent-scoped prefixes. The holder
/// pushes a materialised projection down; a context never pulls. That is
/// enforced at dispatch, not here, but the prefix split is what makes the
/// enforcement expressible.
///
/// Agent-scoped:
///
/// - `pa:<attributeId>` — one attribute of the pool.
/// - `pp:<profileId>` — one profile.
/// - `pxi:<hmac>` — correlation index, keyed by a keyed hash of the value so
/// exact-match lookup works with no plaintext index over personal data.
/// - `pxr:<attributeId>:<profileId>` — attribute → profile reverse index, so a
/// delete can name its referring profiles without scanning every profile.
///
/// Context-scoped:
///
/// - `pb:<contextId>:<personaDid>` — binding of a profile to a persona DID.
/// - `pc:<contextId>:<contactId>` — a contact's current revision.
/// - `pcr:<contextId>:<contactId>:<rev>` — superseded contact revisions,
/// reference-counted rather than reaped on a flat TTL: a revision behind a
/// disclosure record is evidence the holder can still be asked to account for.
/// - `pd:<contextId>:<seq:020>` — append-only disclosure record.
/// - `plp:<contextId>:<profileId>` — context-local profile (inline entries
/// only). A *separate prefix*, not a flag on `pp:`, so a context-scoped list
/// scans a space that structurally cannot contain a pool profile — a filter
/// bug there would be the same one-line leak the authorization rule exists to
/// remove.
/// - `plb:<contextId>:<personaDid>` — binding of a local profile.
///
/// The holder's identity is the account → in [`BACKED_UP`]. A restored agent
/// that came back without it would be an agent that no longer knows who its
/// holder is.
pub const PERSONA: &str = "persona";
/// Versioned, namespaced application state (`vta/app-state/{get,put,list,
/// delete,get-many,put-many}/1.0`) — the third store, beside [`VAULT`] (secrets
/// and credentials) and [`MEMORY`] (agent memory), for JSON an application owns
/// and the VTA does not interpret.
///
/// Four record shapes share the keyspace, distinguished by prefix:
///
/// - `app:<contextId>:<namespace>:<key>` — the record itself. `list` in
/// snapshot mode is an `app:<contextId>:<namespace>:` prefix scan.
/// - `appv:<contextId>:<namespace>:<version:020}>` — version index, mapping a
/// zero-padded counter value to its record key. Change-feed `list` scans this
/// so it can return changes in version order and paginate over a stable
/// storage key; a scan-and-sort over the records could do neither.
/// - `appc:<contextId>:<namespace>` — the namespace's monotonic write counter.
/// - `appt:<contextId>:<namespace>` — the oldest version still covered by a
/// retained tombstone, which is what `sinceVersion` is checked against.
///
/// Deliberately **not** [`MEMORY`]: clearing an agent's memory has to stay a
/// safe thing for a user to ask, which it cannot be if account state lives
/// there. Durable user data — an account's recoverability depends on it — so it
/// is in [`BACKED_UP`], and a restore that came back without it would defeat
/// the point of the feature.
pub const APP_STATE: &str = "app_state";
/// Rego policy modules for the Policy Decision Point (`policy/{upsert,list,
/// delete,evaluate}`). One `policy::PolicyModule` per id, keyed `policy:<id>`;
/// the active set is every enabled row, priority-ordered. Durable operator
/// security config → in [`BACKED_UP`] (a lost policy set would silently drop
/// enforcement on restore).
pub const POLICY: &str = "policy";
/// Task-execution consent for the PDP's `requireConsent` disposition: pending
/// approvals keyed by payload digest, and granted consents a re-submitted task
/// consumes. Distinct from [`CONSENT`] (messaging-bridge conversation consent).
/// One `policy::consent::PendingTaskConsent` per `pending:<digest>` and
/// `policy::consent::TaskConsentGrant` per `grant:<digest>:<requester>`.
/// Durable operator-facing security state → [`BACKED_UP`].
pub const TASK_CONSENT: &str = "task_consent";
/// Durable reliable-messaging outbox backing `vti_common::outbox_store::`
/// `VtiOutboxStore` for the delivery-layer `MessagingService` (D2 P2a
/// cut-over). Holds `Guaranteed`-delivery outbox entries; dormant in P2a (all
/// current sends are `BestEffort`) but wired so the drain/confirmation loops
/// persist across restarts once P2b adds guaranteed VTA pushes. Runtime state,
/// not backed up.
pub const OUTBOX: &str = "outbox";
/// Idempotency records for keyed Trust Tasks — one row per
/// `(actor, idempotency-key)`, holding the request digest and, for tasks whose
/// response may be replayed, the original response. Lets a client's retry of a
/// lost reply converge on the first execution instead of producing a second
/// durable effect.
///
/// Persistent rather than in-memory (unlike the `(actor, envelope-id)` replay
/// cache it sits beside) because the window that matters is exactly the one a
/// restart falls inside: the VTA processed the request, the reply was lost, and
/// the client is still retrying. Swept on TTL by
/// `vta_sweepers::idempotency_sweeper`. Runtime state, not backed up.
pub const IDEMPOTENCY: &str = "idempotency";
/// Durable TSP relationship state, backing the SDK's `RelationshipStore` for the
/// TSP transport. One record per facet per `(our_vid, their_vid)` pair — the
/// relationship FSM state, thread digests, reply path and learned capability.
///
/// Persistent because Rev 3 §7.2.2 has an endpoint silently drop application
/// traffic from a VID it holds no relationship with: an in-memory store wiped on
/// restart makes every established peer's messages vanish until each
/// re-handshakes. Persisting the state turns a restart transparent (design note
/// `docs/05-design-notes/tsp-relationship-recovery.md`, D1). Runtime state, not
/// backed up — a relationship is re-establishable (D2/D3), and like [`SESSIONS`]
/// it is scoped to this VTA's DIDs, so a restore re-drives it rather than
/// carrying it.
pub const RELATIONSHIPS: &str = "relationships";
/// Every production keyspace. Partitioned by [`BACKED_UP`] +
/// [`EXCLUDED_FROM_BACKUP`]; the [`tests::backup_partition_is_total`] guard
/// asserts the partition stays exhaustive so a newly-added keyspace can't be
/// silently omitted from the backup decision.
pub const ALL: & = &;
/// Keyspaces a backup carries, **every row of each**, as a raw dump.
///
/// A backup exists to bring an agent back, so the rule is inclusion: a
/// keyspace is here unless there is a reason on [`EXCLUDED_FROM_BACKUP`] for
/// leaving it out. Within a carried keyspace the only rows left behind are the
/// few that belong to one *deployment* rather than to the agent — see
/// [`is_environment_bound`] — and the restore re-creates those for the target.
///
/// Every name here is exported by `vta_backup::ops::export_backup` without a
/// per-keyspace code path: it walks this list. `every_backed_up_keyspace_
/// survives_a_round_trip` in `vta-backup` writes a row into each and asserts
/// it comes back, so a keyspace cannot be listed here and silently skipped —
/// which is exactly what happened to ten of them while export was a set of
/// hand-written collectors.
pub const BACKED_UP: & = &;
/// Keyspaces deliberately **not** in a backup, each for a stated reason.
pub const EXCLUDED_FROM_BACKUP: & = &;
/// Rows inside a [`BACKED_UP`] keyspace that belong to the **deployment**, not
/// to the agent, as `(keyspace, key prefix)`.
///
/// A backup moves between a plain VTA, a hardened one and a Nitro enclave in
/// any direction. These rows only mean something in the environment that wrote
/// them, or are derived from that environment's storage key, so copying one
/// would be wrong on the target: the restore leaves them out and re-creates
/// what the target needs.
pub const ENVIRONMENT_BOUND_ROWS: & = &;
/// Whether `key` in `keyspace` is an [`ENVIRONMENT_BOUND_ROWS`] row.
// ---------------------------------------------------------------------------
// What a DID deletion means for each keyspace
// ---------------------------------------------------------------------------
/// What happens to a keyspace's DID-keyed contents when that DID is deleted.
///
/// Deleting a DID is not one cleanup. It is four different relationships, and
/// treating them alike gets one of them wrong in a way nobody notices until it
/// matters:
///
/// * things the DID **owns** go with it;
/// * things that **name it as a subject of authorization** must go with it, or
/// they become authority for an identity that no longer resolves;
/// * things that **depend on it to function** must *stop* the deletion, because
/// cascading would silently break them;
/// * credentials the VTA **issued** cannot be deleted at all — copies exist
/// elsewhere — so the only honest action is revocation.
///
/// # Why this is an enum and not a list in a function
///
/// The failure mode is not getting today's answers wrong. It is a keyspace
/// added next quarter that nobody classifies, whose rows then quietly outlive
/// the DID they belong to. [`ALL`] is already pinned by a census test for the
/// backup partition, for exactly the same reason; this rides the same rail, so
/// "we forgot" is a red test rather than an orphan found months later in a log.
///
/// The classifications below are judgements and several are arguable. That is
/// fine — the point of the census is to force the question to be asked, not to
/// claim these answers are the last word.
/// The effect a DID deletion has on `keyspace`, or `None` if the name is not a
/// keyspace this build knows.
///
/// Every entry in [`ALL`] is classified — see `did_delete_census` in this
/// module's tests.
pub const