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
//! # fci4096
//!
//! A BIP39-inspired mnemonic implementation using 4096 Chinese four-character idioms
//! as the wordlist.
//!
//! Each idiom encodes 12 bits of information (2^12 = 4096), providing higher
//! information density compared to BIP39's 2048-word list (11 bits/word) for the
//! same number of words. The checksum is 1/8 of the entropy length.
//!
//! ## Quick Start
//!
//! ```rust,no_run
//! use fci4096::{generate, from_phrase, IdiomMnemonicSize};
//!
//! // Generate a 12-idiom mnemonic (128 bits of entropy)
//! let mnemonic = generate(IdiomMnemonicSize::Idioms12).unwrap();
//! println!("{}", mnemonic.phrase());
//!
//! // Derive the seed
//! let seed = mnemonic.to_seed("my_passphrase");
//! ```
//!
//! ## Feature Flags
//!
//! | Feature | Default | Description |
//! |---------|---------|-------------|
//! | `std` | Yes | Standard library support |
//! | `rand` | Yes | Random number generation (requires `getrandom`) |
//! | `serde` | No | Serialize/Deserialize support |
//! | `wasm` | No | WASM bindings (includes `rand` automatically) |
extern crate std;
extern crate alloc;
/// Entropy encoding/decoding (bit operations and checksum calculation)
/// Error type definitions
/// Idiom wordlist and lookup
/// Core mnemonic types
/// Seed generation (PBKDF2-SHA512)
/// WASM bindings (requires the `wasm` feature)
pub use crate;
pub use crateChineseIdiomList;
pub use crate;
pub use cratePBKDF2_ITERATIONS;
/// Generate a random mnemonic.
///
/// Uses the operating system's cryptographically secure random source.
/// Requires the `rand` feature.
///
/// # Example
///
/// ```rust,no_run
/// use fci4096::{generate, IdiomMnemonicSize};
///
/// let mnemonic = generate(IdiomMnemonicSize::Idioms12).unwrap();
/// assert_eq!(mnemonic.idioms().len(), 12);
/// ```
/// Create a mnemonic from entropy bytes.
///
/// Entropy must be 16/20/24/28/32 bytes (128/160/192/224/256 bits).
///
/// # Example
///
/// ```rust
/// use fci4096::from_entropy;
///
/// let entropy = [0x00u8; 16]; // 128 bits of entropy
/// let mnemonic = from_entropy(&entropy).unwrap();
/// assert_eq!(mnemonic.idioms().len(), 12);
/// ```
/// Parse a mnemonic from an idiom phrase (with checksum validation).
///
/// Idioms are separated by spaces (full-width/half-width spaces and tabs are accepted).
/// Returns `Error::ChecksumMismatch` if the checksum does not match.
///
/// # Example
///
/// ```rust
/// use fci4096::{from_entropy, from_phrase};
///
/// let entropy = [0x00u8; 16];
/// let mnemonic = from_entropy(&entropy).unwrap();
/// let phrase = mnemonic.phrase();
/// let recovered = from_phrase(&phrase).unwrap();
/// assert_eq!(mnemonic, recovered);
/// ```
/// Validate a mnemonic phrase.
///
/// Checks whether all idioms exist in the wordlist and the checksum matches.
///
/// # Example
///
/// ```rust
/// use fci4096::{generate, validate, IdiomMnemonicSize};
///
/// let mnemonic = generate(IdiomMnemonicSize::Idioms12).unwrap();
/// assert!(validate(&mnemonic.phrase()));
/// assert!(!validate("invalid phrase"));
/// ```
/// Look up an idiom's index via binary search.
///
/// Uses binary search over a Unicode codepoint-sorted lookup array.
/// Time complexity O(log N), N = 4096.
///
/// # Example
///
/// ```rust
/// use fci4096::idiom_to_index;
///
/// if let Some(idx) = idiom_to_index("爱屋及乌") {
/// println!("Idiom index: {}", idx);
/// }
/// ```
/// Look up an idiom by its index.
///
/// # Example
///
/// ```rust
/// use fci4096::index_to_idiom;
///
/// if let Some(idiom) = index_to_idiom(0) {
/// println!("First idiom in wordlist: {}", idiom);
/// }
/// ```
/// Get the pinyin of an idiom by index.
///
/// # Example
///
/// ```rust
/// use fci4096::get_pinyin;
///
/// if let Some(pinyin) = get_pinyin(0) {
/// println!("Pinyin: {}", pinyin);
/// }
/// ```
/// Total number of idioms (fixed at 4096)
pub const IDIOM_COUNT: usize = 4096;