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
//! The unlocked-key handle and the signing primitive it injects.
use Arc;
use ;
use KeyScheme;
use SignerHandle;
use Hkdf;
use Sha256;
use Zeroizing;
// The DEK-derivation constants (`DEK_SALT`, `IDENTITY_IKM_VERSION`,
// `SYMMETRIC_KEY_LEN`, and `PROFILE_DEK_LABEL` mentioned below) live in
// dig-constants as the single source of truth for this frozen at-rest byte
// contract (dig_ecosystem §5.1/§4.1/NC-5) — dig-app's
// `dig-app-core/src/keystore/secrets.rs` and this crate both consume them from
// there, so they can never drift apart. See dig-constants' `lib.rs` "Profile
// DEK at-rest byte contract" section for the authoritative definition.
/// A scheme-parameterized signing primitive: a plain callable that maps a
/// message to a signature and carries no dig-session or dig-identity type.
///
/// This is the shape [`UnlockedIdentity::inject_into`] hands to a consumer, so
/// the consumer's API surface mentions only `&[u8]` in and `K::Signature`
/// (a `chia_bls::Signature` for the BLS schemes) out — never a session or
/// identity type. That is what keeps a consumer such as `dig-wallet-backend`
/// identity-agnostic (see dig_ecosystem #908).
pub type SigningFn<K> = ;
/// A live, in-memory identity whose secret key has been decrypted and is ready
/// to sign.
///
/// Obtained from [`crate::Session::unlock`] or [`crate::Session::enroll_identity`].
/// The secret bytes live inside the wrapped [`SignerHandle`], which stores them
/// in a `Zeroizing` buffer and wipes them when this value is dropped — so the
/// decrypted key never lingers in freed memory. The type deliberately does not
/// implement `Clone` and its `Debug` impl redacts the secret, so an
/// `UnlockedIdentity` cannot be duplicated into a log line or a debug dump.
///
/// # Boundaries
///
/// An `UnlockedIdentity` must never cross an IPC boundary: it holds raw key
/// material and belongs solely to the user-app process that owns the identity
/// (dig_ecosystem #908). Hand a downstream a [`SigningFn`] via
/// [`inject_into`](Self::inject_into) instead of the handle itself.
/// Derive a per-profile symmetric key (DEK) from a raw 32-byte identity scalar,
/// bound to `label`.
///
/// This is the single, frozen HKDF construction shared by every unlock path
/// (the identity-scalar path via [`UnlockedIdentity::derive_symmetric_key`] and
/// the master-seed path via [`crate::UnlockedMasterSeed::derive_symmetric_key`],
/// which re-derives the SAME identity scalar from the seed first). Keeping ONE
/// implementation is what guarantees both paths produce a byte-identical DEK for
/// the same underlying identity (§5.1 at-rest back-compat):
///
/// - IKM: `IDENTITY_IKM_VERSION || identity_scalar` (the 33-byte versioned
/// layout dig-app feeds to HKDF via `to_sealed_bytes()`);
/// - salt: [`dig_constants::DEK_SALT`];
/// - hash: HKDF-SHA256 (RFC 5869);
/// - info: `label` verbatim;
/// - output: [`dig_constants::SYMMETRIC_KEY_LEN`] bytes.
///
/// The IKM buffer and the returned key are wrapped in [`Zeroizing`] and wiped on
/// drop; `scalar` is borrowed and never copied except into the zeroizing IKM.
pub
/// Redacting `Debug`: shows the type name only, never the secret (or even the
/// public key, to avoid accidental correlation in logs).