Disclaimer: This is a really big PR and I'm happy to make a fork of the crate and maintain it on crates.io if you'd rather not change the API as much as I've done here.
Reworked most of the API surface, removed methods dealing with hex-encoded strings, added LowerHex and UpperHex trait implementations to both Mnemonic and Seed for printing those out as hex. In general, I don't think parsing hex-encoded strings is within the scope of the library.
Added remaining languages.
wordlist now operates on &'static str instead of allocating Strings. When retrieved from Language, it returns a &'static [&'static str] instead of a &'static Vec<String>.
Similarly, WordMap is a newtype wrapping around FxHashMap<&'static str, u16> (which is just a regular HashMap using fast hashing algo from rustc, it's not as secure in terms of collisions as the default, but since we aren't allowing any insertions it shouldn't matter).
Replaced Result<T, Error> with custom Result<T> and switched to using the bail! macro from error_chain to reduce some boiler plate.
Removed bit-vec, bitreader and data-encoding dependencies.
Added benchmarks (rustup run nightly cargo bench) and a bunch new tests when necessary.
Performance:
Validating phrases is now ~6x faster.
Creating a new Mnemonic from entropy is way faster (I don't have the original figures) due to reduced number of allocations (worst case scenario is 2-4 depending on the length of the key).
Generating a new Mnemonic (skipping Seed generation) from random entropy is now 20x+ faster.
test from_entropy ... bench: 418 ns/iter (+/- 229)
test new_mnemonic ... bench: 560 ns/iter (+/- 347)
test new_seed ... bench: 1,404,971 ns/iter (+/- 397,740)
test validate ... bench: 657 ns/iter (+/- 591)
Generating a Seed is obviously most expensive due to the 2048 pbkdf2 rounds.
Disclaimer: This is a really big PR and I'm happy to make a fork of the crate and maintain it on crates.io if you'd rather not change the API as much as I've done here.
LowerHex
andUpperHex
trait implementations to bothMnemonic
andSeed
for printing those out as hex. In general, I don't think parsing hex-encoded strings is within the scope of the library.wordlist
now operates on&'static str
instead of allocatingString
s. When retrieved fromLanguage
, it returns a&'static [&'static str]
instead of a&'static Vec<String>
.WordMap
is a newtype wrapping aroundFxHashMap<&'static str, u16>
(which is just a regularHashMap
using fast hashing algo fromrustc
, it's not as secure in terms of collisions as the default, but since we aren't allowing any insertions it shouldn't matter).Result<T, Error>
with customResult<T>
and switched to using thebail!
macro fromerror_chain
to reduce some boiler plate.bit-vec
,bitreader
anddata-encoding
dependencies.rustup run nightly cargo bench
) and a bunch new tests when necessary.Performance:
Mnemonic
fromentropy
is way faster (I don't have the original figures) due to reduced number of allocations (worst case scenario is 2-4 depending on the length of the key).Mnemonic
(skippingSeed
generation) from random entropy is now 20x+ faster.Generating a
Seed
is obviously most expensive due to the 2048pbkdf2
rounds.