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
//! [`ActiveProfile`] — the one active profile, and [`ActiveSwitch`] — what changed when it moved.
use crateProfileIx;
use crateProfileEntry;
/// The one active profile, BORROWED from the registry that vouches for it.
///
/// # What possessing one proves
///
/// Three things at once, none of which needs re-checking by the holder: the entry is PRESENT in the
/// registry, it is [`Shown`](crate::registry::ProfileVisibility::Shown), and it is the ACTIVE one.
/// The registry's invariants are what make all three true, and the only way to obtain this type is
/// [`ProfileRegistry::active`](crate::registry::ProfileRegistry::active).
///
/// Because it borrows the registry immutably, [`set_active`](crate::registry::ProfileRegistry::set_active)
/// — which needs `&mut` — cannot run while one is alive. **A stale active handle does not
/// typecheck**, so there is no window in which a host holds an active profile that the registry has
/// since moved away from.
///
/// This replaces dig-app's `ACTIVE_PROFILES: &[ProfileIx]` plus its
/// `const _: () = assert!(len() == 1)` tripwire (dig_ecosystem#2236). A slice can have a length
/// other than one and therefore needed the tripwire; a scalar field cannot, so the property is
/// structural rather than asserted.
;
/// What changed when the active slot moved.
///
/// # Why this is a value and not a `()`
///
/// A switch re-derives nothing and stores no key — every dig-account key API is
/// index-parameterized and derives per call — but it DOES change three things the user can be
/// surprised by: the receive address, the per-profile DEK, and the identity signing key. Funds at
/// the previous profile's address stay there and stay spendable; they do not follow the switch.
///
/// Rendering that is the HOST's ceremony (`SPEC.md` §1: dig-account draws no UI). This type's job is
/// to make the disclosure unavoidable — `#[must_use]` means a host that silently drops it has to say
/// so in code.
/// What happened to the active slot when a profile ENDED on chain (dig_ecosystem#3067).
///
/// # Why this is not an [`ActiveSwitch`]
///
/// A switch always names a destination, because switching to nothing is not a switch. Ending the
/// account's LAST profile leaves no destination at all, and that state — a real one, reached by
/// deleting an only profile — is exactly what the registry previously had no way to express. Naming
/// the four outcomes separately keeps `ActiveSwitch::to` an honest `ProfileIx` rather than an
/// `Option` every existing caller would have to unwrap for a case that cannot happen to it.