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
// SPDX-License-Identifier: Apache-2.0
//! # multi-key
//!
//! Self-describing cryptographic key implementation supporting multiple key types
//! and formats including public keys, private keys, encrypted keys, and threshold keys.
//!
//! ## Overview
//!
//! This crate provides multikey functionality for creating and managing self-describing
//! cryptographic keys with support for:
//! - Ed25519, Secp256k1, and BLS12-381 key schemes
//! - Public and private key pairs
//! - Key encryption and decryption
//! - Threshold key sharing (Shamir Secret Sharing)
//! - SSH key format conversion
//! - View creation through the fluent `ViewBuilder`, including
//! local-codec factories for custom protocol keys
//! - Nonce generation
//!
//! ## Quick Start
//!
//! ### Generating a Key Pair
//!
//! ```rust
//! use multi_key::Builder;
//! use multi_codec::Codec;
//!
//! let mut rng = rand::rng();
//! let multikey = Builder::new_from_random_bytes(Codec::Ed25519Priv, &mut rng)
//! .unwrap()
//! .try_build()
//! .unwrap();
//! ```
//!
//! ### Encoding and Decoding
//!
//! ```rust
//! use multi_key::{Builder, Multikey};
//! use multi_codec::Codec;
//!
//! let mut rng = rand::rng();
//! let mk1 = Builder::new_from_random_bytes(Codec::Ed25519Priv, &mut rng)
//! .unwrap()
//! .try_build()
//! .unwrap();
//!
//! // Encode to bytes
//! let bytes: Vec<u8> = mk1.clone().into();
//!
//! // Decode from bytes
//! let mk2 = Multikey::try_from(bytes.as_ref()).unwrap();
//! assert_eq!(mk1, mk2);
//! ```
//!
//! ### Creating Views
//!
//! Views are created with [`ViewBuilder`]: select one view kind with a
//! fluent selector, then build it. Standard codecs dispatch to the built-in
//! views; custom protocol keys (the `Codec::Identity` codec carrying the
//! `AlgorithmName`/`KeyType` attributes) have no built-in views and
//! dispatch to caller-supplied local-codec factories registered with
//! `with_local_codec`. The `cipher` and `kdf` kinds additionally attach the
//! second key, for example
//! `ViewBuilder::new(&mk).cipher(&cipher_key).build()`.
//!
//! ```rust
//! use multi_key::{Builder, ViewBuilder};
//! use multi_codec::Codec;
//!
//! let mut rng = rand::rng();
//! let mk = Builder::new_from_random_bytes(Codec::Ed25519Priv, &mut rng)
//! .unwrap()
//! .try_build()
//! .unwrap();
//!
//! let signer = ViewBuilder::new(&mk).sign().build().unwrap();
//! let sig = signer.sign(b"message", false, None).unwrap();
//!
//! let verifier = ViewBuilder::new(&mk).verify().build().unwrap();
//! verifier.verify(&sig, Some(b"message")).unwrap();
//! ```
//!
//! ## Features
//!
//! - **`serde`** (default): Enables serde serialization
//! - **`wasm`**: Enables WebAssembly support with getrandom/js
//! - **`legacy_chacha20_fallback`** (default off): Enables the legacy bare-ChaCha20
//! fallback on ChaCha20Poly1305 decryption failure for keys encrypted before
//! AEAD was added. Disabled by default — AEAD failure is a hard error so
//! unauthenticated ciphertext is never returned as if it were valid. Enable
//! only to migrate pre-AEAD keystores; a warning is emitted on every fallback.
//! - **`deprecated`** (default off): Enables the deprecated Classic McEliece
//! support (see the Deprecations section below).
//!
//! ## Deprecations
//!
//! Classic McEliece (the `Mceliece348864Pub`/`Priv` codecs and the
//! `X25519-McEliece-348864` hybrid) is deprecated. Key-recovery attacks now
//! solve the TII McEliece challenges; see
//! <https://github.com/mjosaarinen/tii-solved> for the recovered keys. The
//! McEliece views compile only with the `deprecated` feature. Stored
//! McEliece multikeys still decode in default builds, but key generation
//! fails with `UnsupportedCodec`.
//!
//! The `Views` extension trait (and its impl for `Multikey`) is deprecated
//! since 2.1.0. It stays as a source-compatible delegating shim that calls
//! the same dispatch core [`ViewBuilder`] uses; construct views with
//! [`ViewBuilder`] instead. Note that `multi_sig::Views` is a different,
//! unrelated trait.
//!
//! ## Security
//!
//! - Private keys are automatically zeroized on drop
//! - Debug output redacts sensitive key material
//! - Thread-safe for concurrent operations
//!
//! ## Supported Key Types
//!
//! See [`KEY_CODECS`] for the complete list of supported key algorithms.
// Pedantic/nursery lints are enabled at the workspace level via
// `[lints.clippy]` in Cargo.toml. The following allows suppress stylistic
// lints that would require large-scale churn for minimal security benefit.
/// Errors produced by this library
pub use Error;
/// Multikey attribute IDs
pub use AttrId;
/// Cipher function builder
/// Key derivation function builder
/// Key views
pub use Views;
pub use ;
pub use ;
pub use ;
pub use ;
/// Key splitting / recombination (verifiable threshold shares)
/// Multikey type and functions
pub use ;
pub use ;
/// Nonce type
pub use ;
// Re-export EncodingInfo for consumers of Nonce who need the encoding() method
pub use EncodingInfo;
/// Type-safe wrappers for key components
pub use ;
/// Serde serialization
/// Commonly used items
///
/// ```
/// use multi_key::prelude::*;
///
/// let mut rng = rand::rng();
/// let mk = Builder::new_from_random_bytes(Codec::Ed25519Priv, &mut rng)
/// .unwrap()
/// .try_build()
/// .unwrap();
/// ```