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
use ;
use Error;
use util;
use crate::;
/// Parse a `Mnemonic` from a string.
///
/// # Safety
/// - `s` must be valid for reads up until and including the first NUL (`'\0'`) byte.
/// - `mnemonic` must be valid for writes according to the [*Rust* pointer rules]
/// - if this method returns anything other than [`Error::Ok`],
/// then the contents of `mnemonic` are undefined and must not be used or inspected.
/// - `mnemonic` must only be freed via [`hedera_mnemonic_free`].
/// Notably this means that it *must not* be freed with `free`.
///
/// # Errors
/// - [`Error::MnemonicParse`] if the mnemonic has an invalid length.
/// - [`Error::MnemonicParse`] if the mnemonic uses invalid words.
/// - [`Error::MnemonicParse`] if the mnemonic has an invalid checksum.
///
/// [*Rust* pointer rules]: https://doc.rust-lang.org/std/ptr/index.html#safety
pub unsafe extern "C"
/// Generate a new 24 word mnemonic.
///
/// # Safety
/// This function is safe. However, there are invariants that must be upheld on the result.
///
/// - The returned mnemonic must only be freed via [`hedera_mnemonic_free`].
/// Notably this means that it *must not* be freed with `free`.
pub extern "C"
/// Generate a new 12 word mnemonic.
///
/// # Safety
/// This function is safe. However, there are invariants that must be upheld on the result.
///
/// - The returned mnemonic must only be freed via [`hedera_mnemonic_free`].
/// Notably this means that it *must not* be freed with `free`.
pub extern "C"
/// Returns `true` if `mnemonic` is a legacy mnemonic.
///
/// # Safety
/// - `mnemonic` must be valid for reads according to the [*Rust* pointer rules].
///
/// [*Rust* pointer rules]: https://doc.rust-lang.org/std/ptr/index.html#safety
pub unsafe extern "C"
/// Recover a [`PrivateKey`] from `mnemonic`.
///
/// # Safety
/// - `mnemonic` must be valid for reads according to the [*Rust* pointer rules].
/// - `passphrase` must be valid for reads up until and including the first NUL (`'\0'`) byte.
/// - `private_key` must be valid for writes according to the [*Rust* pointer rules].
/// - if this method returns anything other than [`Error::Ok`],
/// then the contents of `private_key` are undefined and must not be used or inspected.
/// - `private_key` must only be freed via `hedera_private_key_free`.
/// Notably, this means that it *must not* be freed with `free`.
///
/// # Errors
/// - [`Error::MnemonicEntropy`] if this is a legacy private key, and the passphrase isn't empty.
/// - [`Error::MnemonicEntropy`] if this is a legacy private key,
/// and the `Mnemonic`'s checksum doesn't match up with the computed one.
///
/// [*Rust* pointer rules]: https://doc.rust-lang.org/std/ptr/index.html#safety
pub unsafe extern "C"
/// Recover a [`PrivateKey`] from `mnemonic`.
///
/// # Safety
/// - `mnemonic` must be valid for reads according to the [*Rust* pointer rules].
/// - `private_key` must be valid for writes according to the [*Rust* pointer rules].
/// - if this method returns anything other than [`Error::Ok`],
/// then the contents of `private_key` are undefined and must not be used or inspected.
/// - `private_key` must only be freed via `hedera_private_key_free`.
/// Notably, this means that it *must not* be freed with `free`.
///
/// # Errors
/// - [`Error::MnemonicEntropy`] if the computed checksum doesn't match the actual checksum.
/// - [`Error::MnemonicEntropy`] if this is a v2 legacy mnemonic and doesn't have `24` words.
///
/// [*Rust* pointer rules]: https://doc.rust-lang.org/std/ptr/index.html#safety
pub unsafe extern "C"
/// Format `mnemonic` as a string.
///
/// # Safety
/// - `mnemonic` must be valid for reads according to the [*Rust* pointer rules].
///
/// [*Rust* pointer rules]: https://doc.rust-lang.org/std/ptr/index.html#safety
pub unsafe extern "C"
/// Free `mnemonic` and release all resources associated with it.
///
/// # Safety
/// - `mnemonic` must be valid for reads and writes according to the [*Rust* pointer rules].
/// - `mnemonic` must not be used at all after this function is called.
///
/// [*Rust* pointer rules]: https://doc.rust-lang.org/std/ptr/index.html#safety
pub unsafe extern "C"