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

Add a custom signer for hardware wallets #682

Merged
merged 3 commits into from
Aug 29, 2022

Conversation

wszdexdrf
Copy link
Contributor

@wszdexdrf wszdexdrf commented Jul 25, 2022

Also adds a new test in CI for building and testing on a virtual
hardware wallet.

Description

This PR would enable BDK users to sign transactions using a hardware wallet. It is just the beginning hence there are no complex features, but I hope not for long.
I have added a test in CI for building a ledger emulator and running the new test on it. The test is similar to the one on bitcoindevkit/rust-hwi.

Notes to the reviewers

The PR is incomplete (and wouldn't work, as the rust-hwi in cargo.toml is pointing to a local crate, temporarily) as a small change is required in rust-hwi (bitcoindevkit/rust-hwi#42).

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature
  • I've updated CHANGELOG.md

@evanlinjin
Copy link
Member

This is exciting that rust-hwi is finally getting integrated into BDK :)

I'm wondering whether "Hardware Wallet" is the best name since we have a struct named Wallet, and there is also a portion of the Bitcoin community wary of the term "Hardware Wallet" anyway. The proposed alternative term is "Hardware Signer" and since our signing traits are already called {}Signers, I think this may be a better term.

@wszdexdrf
Copy link
Contributor Author

I'm wondering whether "Hardware Wallet" is the best name since we have a struct named Wallet

Now that you say it, it makes sense. This isn't anywhere close to the Wallet struct in terms of functionality... so maybe Hardware Signer is better...

Copy link
Member

@danielabrozzoni danielabrozzoni left a comment

Choose a reason for hiding this comment

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

Sorry for the early review, I was just too excited to leave this PR alone 😁

This is looking great! I'd split this in multiple commits, at least once for the actual code and one for the CI.

Cargo.toml Outdated Show resolved Hide resolved
src/hardwarewallet/signer.rs Outdated Show resolved Hide resolved
@wszdexdrf wszdexdrf force-pushed the hardwarewallet branch 2 times, most recently from 1d99858 to 3e5ea35 Compare July 25, 2022 18:42
@wszdexdrf wszdexdrf force-pushed the hardwarewallet branch 4 times, most recently from 8cd2442 to 41c8d95 Compare July 31, 2022 11:29
@wszdexdrf wszdexdrf marked this pull request as ready for review July 31, 2022 11:29
src/hardwaresigner/mod.rs Outdated Show resolved Hide resolved
}

#[test]
fn test_create_signer() {
Copy link
Member

Choose a reason for hiding this comment

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

In BDK we have two different types of tests:

  • unit tests
  • integration tests, which use blockchain backends

This should probably be a unit test, and should have the same structure as the other ones. See, for example, test_sign_single_xprv in src/wallet/mod.rs: there's no blockchain backend being created, only the transaction creation/signing part is tested. This test should also probably be moved in src/wallet/mod.rs.

Then, integration tests could be useful as well. To write one, you should modify the bdk_blockchain_tests in src/testutils/blockchain_tests.rs. Those tests will be run against every backend we support.

@wszdexdrf wszdexdrf force-pushed the hardwarewallet branch 3 times, most recently from 9a859bd to a114eeb Compare August 2, 2022 15:08
@danielabrozzoni
Copy link
Member

I've just published hwi 0.2.1 btw :)

@danielabrozzoni
Copy link
Member

Btw, I don't like that much having the hw module under src/hardwaresigner, it feels out of place... I'd say it should be either in src/wallet/signer.rs, or maybe you could make signer.rs a module and put the hardwaresigner in src/wallet/signer/hardwaresigner.rs, as you wish

src/database/memory.rs Outdated Show resolved Hide resolved
src/wallet/mod.rs Outdated Show resolved Hide resolved
src/wallet/mod.rs Outdated Show resolved Hide resolved
src/wallet/signer.rs Outdated Show resolved Hide resolved
src/wallet/hardwaresigner/signer.rs Outdated Show resolved Hide resolved
src/wallet/hardwaresigner/signer.rs Outdated Show resolved Hide resolved
src/wallet/hardwaresigner/signer.rs Outdated Show resolved Hide resolved
src/wallet/hardwaresigner/signer.rs Outdated Show resolved Hide resolved
src/wallet/signer.rs Outdated Show resolved Hide resolved
src/wallet/mod.rs Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
@wszdexdrf wszdexdrf force-pushed the hardwarewallet branch 2 times, most recently from 1dae8bd to 6f1d8d1 Compare August 18, 2022 05:13
CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Contributor

@vladimirfomene vladimirfomene left a comment

Choose a reason for hiding this comment

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

utACK

Copy link
Contributor

@rajarshimaitra rajarshimaitra left a comment

Choose a reason for hiding this comment

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

Review ACK.. This is really exciting.. Very much pumped for BDK HWI integration. Thanks for working on this.. Below I have few comments..

src/database/memory.rs Outdated Show resolved Hide resolved
src/wallet/hardwaresigner/mod.rs Outdated Show resolved Hide resolved
src/wallet/mod.rs Outdated Show resolved Hide resolved
ci/Dockerfile.ledger Show resolved Hide resolved
Copy link
Contributor

@rajarshimaitra rajarshimaitra left a comment

Choose a reason for hiding this comment

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

tACK 2860c41

Copy link
Contributor

@rajarshimaitra rajarshimaitra left a comment

Choose a reason for hiding this comment

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

Thanks for the quick update.. Few more comments..

src/wallet/mod.rs Outdated Show resolved Hide resolved
src/wallet/mod.rs Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@wszdexdrf wszdexdrf force-pushed the hardwarewallet branch 4 times, most recently from 6561592 to ab9711b Compare August 22, 2022 13:37
src/wallet/mod.rs Outdated Show resolved Hide resolved
src/wallet/mod.rs Outdated Show resolved Hide resolved
src/wallet/mod.rs Outdated Show resolved Hide resolved
src/wallet/hardwaresigner.rs Outdated Show resolved Hide resolved
src/wallet/hardwaresigner.rs Outdated Show resolved Hide resolved
Copy link
Member

@danielabrozzoni danielabrozzoni left a comment

Choose a reason for hiding this comment

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

ACK 86c1a75 - thanks for taking care of this!

Copy link
Contributor

@rajarshimaitra rajarshimaitra left a comment

Choose a reason for hiding this comment

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

tACK 86c1a75

Copy link
Member

@afilini afilini left a comment

Choose a reason for hiding this comment

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

ACK 138acc3

@afilini afilini merged commit 061f15a into bitcoindevkit:master Aug 29, 2022
@danielabrozzoni danielabrozzoni added the Optech Make Me Famous! 🤩 For anything of interest to Optech newsletter label Aug 30, 2022
@afilini afilini mentioned this pull request Sep 8, 2022
21 tasks
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Optech Make Me Famous! 🤩 For anything of interest to Optech newsletter
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants