bitcoindevkit / bdk-cli

A CLI wallet library and REPL tool to demo and test the BDK library
Other
108 stars 64 forks source link

adding hardware signers #135

Closed ulrichard closed 1 year ago

ulrichard commented 1 year ago

Description

Adding hardware signers, so that hardware wallets can be used to sign transactions.

Notes to the reviewers

~~It doesn't work 100% yet for me. I am using the following wallet: https://github.com/RCasatta/electrum2descriptors/blob/main/tests/wallets2descriptors.rs#L89 https://github.com/RCasatta/electrum2descriptors/blob/main/tests/wallets/multisig_hw_segwit I can create and sign a transaction with this version of bdk-cli. It displays the details on the Trezor and everything looks good so far. But in the CLI output of bdk-cli it says "is_finalized= false" and when I open the supposedly signed tx in Electrum, it aslo says "Status: Unsigned". So, something must still be missing.~~

Initially I had some dependency problems, so I deleted Cargo.lock. That solved the dependency problems, but that's the reason for the large diff on that file.

Changelog notice

Added hardware signers through the use of HWI

Checklists

All Submissions:

New Features:

rajarshimaitra commented 1 year ago

Concept ACK.. Thanks for adding this.. I was just thinking about this the other day.. Could be useful if anyone wanna use bdk-cli with mainnet (still not recommended)..

I can create and sign a transaction with this version of bdk-cli. It displays the details on the Trezor and everything looks good so far. But in the CLI output of bdk-cli it says "is_finalized= false" and when I open the supposedly signed tx in Electrum, it aslo says "Status: Unsigned".

From an initial glance, it looks like all the wallets you are using are watch-only? It has Xpubs and addresses only.. Such wallets in bdk can't sign for transactions as they don't have the private key.. and is_finalised=false means the resulting psbt doesn't have signatures.

PS: We should throw an error in those cases if use asks to sign a bdk-cli with watch only descriptors.

Can you try testing with a single sig wallet, with keys generated from bdk-cli itself?? If the HWI part is working properly that should work..

I will also try to test this out in an emulator..

rajarshimaitra commented 1 year ago

I think the elctrum error you are seeing is also part of our lack of error handling in unsigned psbts and should be fixed with https://github.com/bitcoindevkit/bdk-cli/pull/128.

But it only handles it while broadcast.. I will try to see how the watch-only case can be captured in signing also..

ulrichard commented 1 year ago

I tested with single sig hw wallets now. With the Trezor everything works nicely. With the Ledger, I got the descriptors, but when I tried to sign, I got an IO error "failed to open device". Anyway, since it works with the Trezor, I'm sure it has nothing to do with the bdk-cli integration.

notmandatory commented 1 year ago

@ulrichard we made some CI changes and bumped the bdk and bdk-reserves versions, please rebase after #143 is merged and then this should be ready to go. Thanks!