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
//! VRC (Verifiable Relationship Credential) trust-graph
//! storage — Phase 4 M4.5. Spec §5.4 + §6.1.
//!
//! ## What this module owns
//!
//! - The `relationships:` keyspace: one row per VRC, keyed by
//! `relationships:<uuid>`. The row stores the verified VC
//! JSON-LD body verbatim plus metadata for list / revoke
//! surfaces.
//! - The `relationships_by_did:` secondary-index keyspace: one
//! row per (DID, VRC-id) pair, written for BOTH the issuer
//! and the subject so per-DID list queries are O(prefix-scan)
//! instead of O(full-table). Keys are
//! `relationships_by_did:<did>:<vrc-id>` so a `prefix_iter`
//! on `relationships_by_did:<did>:` returns just that DID's
//! edges.
//!
//! ## Why two keyspaces
//!
//! The natural per-DID query is "list all VRCs where I'm
//! issuer OR subject". A single keyspace + filter would walk
//! every row. The secondary index keeps the per-DID list
//! pageable in O(matched-rows) — the same trade-off the
//! audit log uses for its actor index.
//!
//! Writes are CAS-paired: store the primary row, then both
//! secondary-index rows. Delete is the inverse. A crash
//! between the primary write and the index writes is
//! self-healing on the next list-for-did call (it walks the
//! index and the primary is fjall-durable; the index entries
//! are tolerant of an orphan). A crash between the index
//! writes is similarly recoverable — list-for-did returns
//! whatever index entries are present + the route layer
//! deals with the primary-row absent case (404 on subsequent
//! ops).
//!
//! ## Issuer = the member, not the community
//!
//! Per planning-review D1, the VTC never *mints* VRCs. The
//! issuer of every stored row is a current community member
//! (the route layer verifies caller-DID == VC.issuer + the
//! VC's data-integrity proof verifies against the member's
//! `#key-0`). The community signer is uninvolved.
//!
//! The same holds for the optional [`PersonaAnnotation`]: the
//! VPC is self-issued by the member under a persona DID, and the
//! VTC only verifies and stores it.
//!
//! ## The row is not the whole edge
//!
//! A stored row is evidence that a VRC was published and passed the ingress
//! checks of the day. It is **not** the answer to "is this edge in force",
//! because a VRC can be suspended, superseded or withdrawn after publication
//! and because its own `validUntil` may since have passed. Every consumer asks
//! [`Relationship::in_force_at`] rather than treating the row's existence as
//! the answer; the precedence rule it applies lives in
//! [`crate::credentials::lifecycle`] and is stated once there.
use ;
use ;
use Value as JsonValue;
use Uuid;
pub use crate;
pub use ;
/// A stored, verified VRC. Field order matches the spec §5.4
/// surface (issuer/subject DIDs + the credential body).
/// A Verifiable Persona Credential (VPC) attached to one edge.
///
/// The VPC is issued by the *edge issuer* under a persona DID
/// (P-DID) and names the edge's counterparty as its subject. It
/// is the sanctioned mechanism for deliberate correlation: a
/// member who wants several of their pairwise edges to be
/// recognisable as one party asserts the same P-DID on each,
/// without ever putting their membership DID in a credential.
///
/// See `docs/05-design-notes/vpc-persona-annotation.md` for how
/// the annotation is bound to the edge, and for what upstream
/// (trustoverip/dtgwg-cred-spec#9) has not yet settled.