fixing:
error: the item `ToString` is imported redundantly
--> src/lib.rs:48:26
error: the item `Vec` is imported redundantly
--> src/lib.rs:48:44
error: could not compile `bip39` (lib) due to 2 previous errors
Re-exports from `rand` crate shall be used. Otherwise trait bounds in
`Mnemonic::generate_in_with` for `rand::thread_rng` object can get
unsatisfied if crate deps get ouf of sync.
This commit is fixing following errors:
```
error[E0277]: the trait bound `ThreadRng: rand_core::RngCore` is not satisfied
--> /home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bip39-2.0.0/src/lib.rs:292:30
|
292 | Mnemonic::generate_in_with(&mut rand::thread_rng(), language, word_count)
| -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^ the trait `rand_core::RngCore` is not implemented for `ThreadRng`
| |
| required by a bound introduced by this call
|::
= help: the following other types implement trait `rand_core::RngCore`:
...
note: required by a bound in `Mnemonic::generate_in_with`
--> /home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bip39-2.0.0/src/lib.rs:266:6
|
260 | pub fn generate_in_with<R>(
| ---------------- required by a bound in this associated function
...
266 | R: rand_core::RngCore + rand_core::CryptoRng,
| ^^^^^^^^^^^^^^^^^^ required by this bound in `Mnemonic::generate_in_with`
```
```
error[E0277]: the trait bound `ThreadRng: rand_core::CryptoRng` is not satisfied
--> /home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bip39-2.0.0/src/lib.rs:292:30
|
292 | Mnemonic::generate_in_with(&mut rand::thread_rng(), language, word_count)
| -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^ the trait `rand_core::CryptoRng` is not implemented for `ThreadRng`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `rand_core::CryptoRng`:
...
note: required by a bound in `Mnemonic::generate_in_with`
--> /home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bip39-2.0.0/src/lib.rs:266:27
|
260 | pub fn generate_in_with<R>(
| ---------------- required by a bound in this associated function
...
266 | R: rand_core::RngCore + rand_core::CryptoRng,
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `Mnemonic::generate_in_with`
```
Co-authored-by: Tobin C. Harding <me@tobin.cc>
This commit introduces the `alloc` feature.
The alloc feature is intended to use in no-std environments which are allowed to
use alloc. New feature enables:
- the unicode-normalization, and all related methods (parse_in,normalize_utf8_cow,parse,to_seed)
- to_entropy() method as Vec is available in alloc,
To follow the convention for Rust iterators, for example, in `str`
the method for a char iterator is `chars` not `char_iter`.
Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
In some situations, a user can come with mnemonic words himself. In
this case a mnemonic will fail the checksum check.
This pr implements a function to be able to parse a mnemonic without
checksum check
This Display description of the BadWordCount variant incorrectly
complained stated that the word count is not a multiple of 6. The
correct criteria for valid word counts is now that it must be a multiple
of 3 between 12 and 24 inclusive, so the Display impl is fixed to be
more precise.
BIP39 says
> The allowed size of ENT is 128-256 bits.
Once we add the checksum this is 132-264 bits. This is divided by 11 to
get the word count. From the BIP141
```
CS = ENT / 32
MS = (ENT + CS) / 11
| ENT | CS | ENT+CS | MS |
+-------+----+--------+------+
| 128 | 4 | 132 | 12 |
| 160 | 5 | 165 | 15 |
| 192 | 6 | 198 | 18 |
| 224 | 7 | 231 | 21 |
| 256 | 8 | 264 | 24 |
```
Currently we are limiting word count to be a multiple of 6, I do not
know why this is being done but from reading the BIP it seems that 15 is
a valid word count value.
Allow word count of 15 by checking the word count modulo 3 instead of
modulo 6. Since this check appears twice in the code, add a helper
function to reduce code duplication.
Fixes: #15