Skip to content

BIP39 Implementation #644

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

Closed
wants to merge 9 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/code_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Update toolchain
run: rustup update
- name: Test
run: cargo test --features all-keys,compiler,esplora,ureq,compact_filters --no-default-features
run: cargo test --features all-keys,all-languages,compiler,esplora,ureq,compact_filters --no-default-features

- id: coverage
name: Generate coverage
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
features:
- default
- minimal
- all-keys
- all-keys,all-languages
- minimal,use-esplora-ureq
- key-value-db
- electrum
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ Cargo.lock

*.swp
.idea

# IDE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits: .idea is for IntelliJ. I don't know if it is necessary to have that IDE comment.

/.vscode
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
- New MSRV set to `1.56.1`
- Fee sniping discouraging through nLockTime - if the user specifies a `current_height`, we use that as a nlocktime, otherwise we use the last sync height (or 0 if we never synced)
- Introduce own implementation of `bip39`.
- Added feature flags for each `bip39` language (English is always included by default).

## [v0.19.0] - [v0.18.0]

Expand Down
29 changes: 26 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ rocksdb = { version = "0.14", default-features = false, features = ["snappy"], o
cc = { version = ">=1.0.64", optional = true }
socks = { version = "0.3", optional = true }
lazy_static = { version = "1.4", optional = true }
unicode-normalization = { version = "0.1.19", optional = true }

bip39 = { version = "1.0.1", optional = true }
bitcoinconsensus = { version = "0.19.0-3", optional = true }

# Needed by bdk_blockchain_tests macro and the `rpc` feature
Expand All @@ -59,8 +59,31 @@ sqlite-bundled = ["sqlite", "rusqlite/bundled"]
compact_filters = ["rocksdb", "socks", "lazy_static", "cc"]
key-value-db = ["sled"]
all-keys = ["keys-bip39"]
keys-bip39 = ["bip39"]
rpc = ["bitcoincore-rpc"]
keys-bip39 = ["unicode-normalization"]

# Languages for BIP39 mnemonics. English is always included by default
japanese = []
korean = []
spanish = []
chinese_simplified = []
chinese_traditional = []
french = []
italian = []
czech = []
portuguese = []

all-languages = [
"japanese",
"korean",
"spanish",
"chinese_simplified",
"chinese_traditional",
"french",
"italian",
"czech",
"portuguese",
]

# We currently provide mulitple implementations of `Blockchain`, all are
# blocking except for the `EsploraBlockchain` which can be either async or
Expand Down Expand Up @@ -119,6 +142,6 @@ required-features = ["keys-bip39", "key-value-db", "rpc"]
[workspace]
members = ["macros"]
[package.metadata.docs.rs]
features = ["compiler", "electrum", "esplora", "ureq", "compact_filters", "rpc", "key-value-db", "sqlite", "all-keys", "verify"]
features = ["compiler", "electrum", "esplora", "ureq", "compact_filters", "rpc", "key-value-db", "sqlite", "all-keys", "all-languages", "verify"]
# defines the configuration attribute `docsrs`
rustdoc-args = ["--cfg", "docsrs"]
14 changes: 6 additions & 8 deletions examples/rpcwallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use bdk::bitcoincore_rpc::RpcApi;
use bdk::blockchain::rpc::{Auth, RpcBlockchain, RpcConfig};
use bdk::blockchain::ConfigurableBlockchain;

use bdk::keys::bip39::{Language, Mnemonic, WordCount};
use bdk::keys::bip39::MnemonicWithPassphrase;
use bdk::keys::bip39::{Language, WordCount};
use bdk::keys::{DerivableKey, GeneratableKey, GeneratedKey};

use bdk::miniscript::miniscript::Segwitv0;
Expand Down Expand Up @@ -217,13 +218,10 @@ fn main() -> Result<(), Box<dyn Error>> {
// private descriptors can be recreated from it.
fn generate_random_ext_privkey() -> Result<impl DerivableKey<Segwitv0> + Clone, Box<dyn Error>> {
// a Bip39 passphrase can be set optionally
let password = Some("random password".to_string());
let password = "random password";

// Generate a random mnemonic, and use that to create a "DerivableKey"
let mnemonic: GeneratedKey<_, _> = Mnemonic::generate((WordCount::Words12, Language::English))
.map_err(|e| e.expect("Unknown Error"))?;

// `Ok(mnemonic)` would also work if there's no passphrase and it would
// yield the same result as this construct with `password` = `None`.
Ok((mnemonic, password))
let mnemonic_with_passphrase: GeneratedKey<_, _> =
MnemonicWithPassphrase::generate((WordCount::Words12, Language::English, password))?;
Ok(mnemonic_with_passphrase)
Comment on lines +224 to +226
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that there is a change in the examples, I believe this will affect users. Is it possible to implement the BIP in such a way that it doesn't change anything for users.

}
225 changes: 0 additions & 225 deletions src/keys/bip39.rs

This file was deleted.

Loading