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

BIP39 implementation #607

Closed
wants to merge 10 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
30 changes: 28 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ 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 }
pbkdf2 = { version = "0.10", optional = true }
Copy link
Member

Choose a reason for hiding this comment

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

The MSRV of pbkdf2 is 1.57, ours is 1.56, maybe we should consider implementing our own pbkdf2 as rust-bip39 is doing? @afilini what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Are we still planning on having our own implementation of pbkdf2? If @atalw , does not mind, I can try pick this up?

Copy link
Author

Choose a reason for hiding this comment

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

There is an agreement that pbkdf2 should be implemented within BDK (refer here). And yeah sure, feel free to implement it. I'm caught up with some other work and can only do it after 2 weeks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Go for it @evanlinjin !

Copy link
Member

@evanlinjin evanlinjin Jun 29, 2022

Choose a reason for hiding this comment

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

Thank you @atalw and @vladimirfomene ! I've done the implementation here: #644 . Please let me know what I can improve on!

unicode-normalization = { version = "0.1.19", optional = true }
sha2 = { version = "0.10.2", optional = true }
hmac = { version = "0.12.1", optional = true }
Comment on lines +36 to +39
Copy link
Contributor

Choose a reason for hiding this comment

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

You may want to use rust-bitcoin for sha256, sha512 and Hmac as they are already implemented in the project. As for pbkdf2, maybe you can consider porting the implementation in rust-bip39 while providing the necessary reference following the crate's library.

Copy link
Author

Choose a reason for hiding this comment

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

I tried using them but pbkfd2 wasn't accepting the rust-bitcoin hmac and sha512 traits. Implementing pbkdf2 should fix the issue.

As for porting pbkdf2, we could look into that. My only concern is that it may lead to bloat, especially if we simply copy it without understanding. If there are issues going forward, it will need to be maintained as well. So there's a tradeoff.

Copy link
Member

Choose a reason for hiding this comment

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

I spoke with @afilini and agreed that it's better if we port pbkdf2 into BDK, as rust-bip39 is doing.

Comment on lines +38 to +39
Copy link
Member

Choose a reason for hiding this comment

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

Minimizing dependencies is important, you don't need those two: hmac and sha512 are already implemented in bitcoin_hashes, which is a dependency of BDK (re-exported by rust-bitcoin)

Copy link
Author

Choose a reason for hiding this comment

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

I tried using them but pbkfd2 wasn't accepting the rust-bitcoin hmac and sha512 traits. Implementing pbkdf2 should fix the issue.


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

# Needed by bdk_blockchain_tests macro
Expand All @@ -59,8 +62,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 = ["pbkdf2", "unicode-normalization", "sha2", "hmac"]

# 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
225 changes: 0 additions & 225 deletions src/keys/bip39.rs

This file was deleted.

Loading