Commit Graph

70 Commits

Author SHA1 Message Date
Christian Reitter cf2daed8e8 Optimize expensive BIP39 seed generation 2025-06-29 19:27:49 +02:00
Michal Kucharczyk 8653fb2775
compilation fix for no-std
Co-authored-by: Tobin C. Harding <me@tobin.cc>
2024-04-08 08:30:16 +02:00
Steven Roose 125abebde6
Release v2.1.0 2024-04-02 12:23:26 +01:00
Steven Roose 8df746dcdd
Add Language::ALL and deprecated Language::all() 2024-04-02 12:23:24 +01:00
Michal Kucharczyk 6ce654b21f
compilation fix
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
2024-03-28 21:30:16 +01:00
Steven Roose a4c57cb84c
Merge pull request #64 from michalkucharczyk/mku-use-reexports-fix
Use rand crate re-exports when available
2024-03-28 19:18:43 +00:00
Michal Kucharczyk 33c3d131ef
Use rand crate re-exports when available
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>
2024-02-10 12:16:03 +01:00
Michal Kucharczyk 86353a5dc8
`alloc` feature added enabling unicode_normalization in no-std
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,
2024-02-10 12:07:55 +01:00
Michal Kucharczyk 09d89c5048
formatting 2024-02-10 12:07:51 +01:00
Steven Roose 5dcdac9c74
Fix MSRV build and tests 2024-02-09 18:30:16 +00:00
Steven Roose b11619d72a
Merge pull request #62 from pezcore/feature/checksum
Add interface to expose the mnemonic checksum
2024-01-30 01:37:21 +07:00
Marko Bencun c02046c031
fix some important std unit tests that were not running due to typo
`#[cfg(features = "std")]` is invalid and always disabled the whole block.
2024-01-29 18:16:49 +00:00
pezcore 778527cd4f feat: add checksum interface for Mnemonic 2024-01-25 21:11:07 -05:00
Jean-Pierre De Jesus DIAZ 0b92d8db6c
Add iterator over word indices.
Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
2023-09-20 13:09:22 +02:00
Jean-Pierre De Jesus DIAZ 73f0c112aa
Add words and deprecate word_iter method
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>
2023-09-20 13:05:20 +02:00
Steven Roose d93a017ec3
Merge pull request #51 from Foundation-Devices/jeandudey/docs
Fix typo and remove extern crate in documentation
2023-08-27 20:31:14 -05:00
pezcore 53090ea50d doc: fix reference to Vec<u8> 2023-03-24 13:26:27 -04:00
pezcore 36fc016a16 Make reference to source BIP a hyperlink 2023-03-24 13:26:10 -04:00
pezcore c7ae12fb64 doc: enable documentation of feature-gated items in docsrs 2023-03-24 13:22:53 -04:00
Jean-Pierre De Jesus DIAZ 795574e73b
Remove extern crate from examples documentation
Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
2023-03-13 12:13:01 +01:00
Jean-Pierre De Jesus DIAZ a0bb29c05e
Fix typo in variable documentation
Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
2023-03-13 12:12:39 +01:00
Steven Roose 8e6ba6de9b
Make rand_core optional and expose rand and rand_core crates 2023-02-27 21:23:57 +00:00
Steven Roose ca53ee34a8
Make serde usable in no_std 2023-02-27 21:16:24 +00:00
Steven Roose d3c96b1448
Rename new method to Mnemonic::parse_in_normalized_without_checksum_check
This is according with the other methods in the API.
2023-02-26 18:36:34 +00:00
Steven Roose 6b79d78c80
Make normalize_utf8_cow public 2023-02-26 18:36:09 +00:00
Ayrat Badykov 38f81b87d7
Parse a mnemonic without checksum check
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
2023-02-26 08:23:52 +02:00
pezcore 593f4767f4 fix: Disply for Error::BadWordCount
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.
2023-01-28 16:26:43 -05:00
pezcore 03dbb973cb Fix Mnemonic documentation for supported wordcounts 2022-10-25 21:57:52 -04:00
Steven Roose 00d628f1a8
Merge pull request #13 from praveenperera/zeroize-support
Add optional zeroize support
2022-06-29 17:44:15 +01:00
trevyn 30290800eb
Remove "We currently don't implement seed generation from the phrase."
This shows up prominently at https://docs.rs/bip39/1.0.1/bip39/index.html , but it appears that seed generation is indeed implemented in the `to_seed()` method.
2022-06-05 11:51:52 -04:00
Praveen Perera e409dc2481
Replace deprecated `zeroize(drop)` with trait 2022-05-13 10:39:49 -04:00
Tobin Harding af958a253a Add unit test for valid word counts
We just enabled word counts of 15, add a unit test that verifies all the
valid word count values.
2021-11-10 09:17:15 +11:00
Tobin Harding 60144920f3 Allow word count multiples of 3 instead of 6
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
2021-11-10 09:17:14 +11:00
Praveen Perera bb0f63298a
Use `zeroize_derive` feature instead of impl zeroize 2021-04-19 12:08:04 -04:00
Praveen Perera a298344178
Add optional zeroize support 2021-04-19 11:49:43 -04:00
Steven Roose 88819a0882
Make Mnemonic::language_of public 2021-04-01 14:57:57 +01:00
Steven Roose 3994ee95b0
Add Mnemonic::language getter 2021-04-01 14:56:25 +01:00
Steven Roose 63d3eab009
Use indices internally instead of &'static str 2021-04-01 14:51:09 +01:00
Steven Roose b8ea0b86bf
Apply rustfmt
Excluding the language files
2021-03-24 22:19:26 +00:00
Steven Roose 04e139ca27
Add generate doctests 2021-03-24 19:25:15 +00:00
Steven Roose 0313e97134
Remove core feature 2021-03-24 19:02:35 +00:00
Steven Roose 5fe9d2b094
Only pass actual mnemonic into pbkdf2 2021-03-24 18:39:43 +00:00
Steven Roose 8b3e901b35
Add a generation method that doesn't need rand 2021-03-24 18:39:40 +00:00
Steven Roose ca454327b2
Differentiate std and core 2021-03-24 18:39:39 +00:00
Steven Roose d41e0722dc
Simplify language selection 2021-03-24 16:39:53 +00:00
Steven Roose 1f1d761930
Add support for `Mnemonic::to_entropy_array` for no-std 2021-03-08 11:18:39 +00:00
Steven Roose 116b508cd3
Add word information to Error::UnknownWord 2021-03-08 11:18:37 +00:00
Steven Roose 7836707810
Fix MIN_NB_WORDS 2021-03-08 11:18:35 +00:00
Steven Roose 125a287a05
Improve Mnemonic::language_of 2021-03-08 11:18:34 +00:00
Steven Roose 7771fd8244
Two typos 2021-03-08 11:18:33 +00:00