Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test bitcoin #72

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ serde = { version = "1.0", default-features = false, features = [ "alloc" ], opt
zeroize = { version = "1.5", features = ["zeroize_derive"], optional = true }

# Unexported dependnecies
bitcoin_hashes = { version = ">=0.12, <=0.13", default-features = false }
bitcoin_hashes = { version = ">=0.12, <=0.14", default-features = false, features = ["alloc"] }
unicode-normalization = { version = "=0.1.22", default-features = false, optional = true }

[dev-dependencies]
# Enabling the "rand" feature by default to run the benches
bip39 = { path = ".", features = ["rand"] }
bitcoin_hashes = ">=0.12,<0.14" # enable default features for test
bitcoin_hashes = ">=0.12,<=0.14" # enable default features for test


[package.metadata.docs.rs]
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ Use the `all-languages` feature to enable all languages.

This crate supports Rust v1.41.1 and up and works with `no_std`.

The `bitcoin_hashes` range dependency effects the MSRV as follows

- `bitcoin_hashes v0.12`: MSRV v1.41.1
- `bitcoin_hashes v0.13`: MSRV v1.48.0
- `bitcoin_hashes v0.14`: MSRV v1.56.1

When using older version of Rust, you might have to pin the version of the
`bitcoin_hashes` crate used as such:
```
Expand Down
1 change: 1 addition & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn from_entropy(b: &mut Bencher) {
});
}

#[cfg(feature = "rand")]
#[bench]
fn new_mnemonic(b: &mut Bencher) {
b.iter(|| {
Expand Down
2 changes: 2 additions & 0 deletions src/internal_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ macro_rules! serde_string_impl {
{
use core::fmt::{self, Formatter};
use core::str::FromStr;
#[cfg(feature = "alloc")]
use alloc::string::String;

struct Visitor;
Expand All @@ -34,6 +35,7 @@ macro_rules! serde_string_impl {
self.visit_str(v)
}

#[cfg(feature = "alloc")]
fn visit_string<E>(self, v: String) -> Result<Self::Value, E>
where
E: $crate::serde::de::Error,
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub extern crate serde;

#[cfg(feature = "alloc")]
use alloc::borrow::Cow;
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::{string::ToString, vec::Vec};
use core::{fmt, str};

/// We support a wide range of dependency versions for `rand` and `rand_core` and not
Expand Down Expand Up @@ -620,13 +622,15 @@ impl Mnemonic {
/// following assertion should hold:
///
/// ```rust
/// # # [cfg(feature = "alloc")] {
/// # use bip39::Mnemonic;
/// # use bitcoin_hashes::{Hash, sha256, hex::FromHex};
/// # let ent = Vec::from_hex("98FE3D0FF6E955A484B0A1D0C9CE10F6").unwrap();
/// # let m = Mnemonic::from_entropy(&ent).unwrap();
/// let checksum_width = m.word_count() / 3;
/// let shift_width = 8 - checksum_width;
/// assert_eq!(sha256::Hash::hash(&m.to_entropy())[0] >> shift_width, m.checksum());
/// # }
/// ```
///
/// Note that since this library constrains initialization of `Mnemonic` instances through an
Expand Down
Loading