-
Notifications
You must be signed in to change notification settings - Fork 410
Add a custom signer for hardware wallets #682
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Taken from bitcoindevkit/rust-hwi | ||
| FROM ghcr.io/ledgerhq/speculos | ||
|
|
||
| RUN apt-get update | ||
| RUN apt-get install wget -y | ||
| RUN wget "https://github.com/LedgerHQ/speculos/blob/master/apps/nanos%23btc%232.1%231c8db8da.elf?raw=true" -O /speculos/btc.elf | ||
| ADD automation.json /speculos/automation.json | ||
|
|
||
| ENTRYPOINT ["python", "./speculos.py", "--automation", "file:automation.json", "--display", "headless", "--vnc-port", "41000", "btc.elf"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| { | ||
| "version": 1, | ||
| "rules": [ | ||
| { | ||
| "regexp": "Address \\(\\d/\\d\\)|Message hash \\(\\d/\\d\\)|Confirm|Fees|Review|Amount", | ||
| "actions": [ | ||
| [ "button", 2, true ], | ||
| [ "button", 2, false ] | ||
| ] | ||
| }, | ||
| { | ||
| "text": "Sign", | ||
| "conditions": [ | ||
| [ "seen", false ] | ||
| ], | ||
| "actions": [ | ||
| [ "button", 2, true ], | ||
| [ "button", 2, false ], | ||
| [ "setbool", "seen", true ] | ||
| ] | ||
| }, | ||
| { | ||
| "regexp": "Approve|Sign|Accept", | ||
| "actions": [ | ||
| [ "button", 3, true ], | ||
| [ "button", 3, false ] | ||
| ] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Bitcoin Dev Kit | ||
| // Written in 2020 by Alekos Filini <alekos.filini@gmail.com> | ||
| // | ||
| // Copyright (c) 2020-2021 Bitcoin Dev Kit Developers | ||
| // | ||
| // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE | ||
| // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
| // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option. | ||
| // You may not use this file except in accordance with one or both of these | ||
| // licenses. | ||
|
|
||
| //! HWI Signer | ||
| //! | ||
| //! This module contains a simple implementation of a Custom signer for rust-hwi | ||
|
|
||
| use bitcoin::psbt::PartiallySignedTransaction; | ||
| use bitcoin::secp256k1::{All, Secp256k1}; | ||
| use bitcoin::util::bip32::Fingerprint; | ||
|
|
||
| use hwi::error::Error; | ||
| use hwi::types::{HWIChain, HWIDevice}; | ||
| use hwi::HWIClient; | ||
|
|
||
| use crate::signer::{SignerCommon, SignerError, SignerId, TransactionSigner}; | ||
|
|
||
| #[derive(Debug)] | ||
| /// Custom signer for Hardware Wallets | ||
| /// | ||
| /// This ignores `sign_options` and leaves the decisions up to the hardware wallet. | ||
| pub struct HWISigner { | ||
| fingerprint: Fingerprint, | ||
| client: HWIClient, | ||
| } | ||
|
|
||
| impl HWISigner { | ||
| /// Create a instance from the specified device and chain | ||
| pub fn from_device(device: &HWIDevice, chain: HWIChain) -> Result<HWISigner, Error> { | ||
| let client = HWIClient::get_client(device, false, chain)?; | ||
| Ok(HWISigner { | ||
| fingerprint: device.fingerprint, | ||
| client, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl SignerCommon for HWISigner { | ||
| fn id(&self, _secp: &Secp256k1<All>) -> SignerId { | ||
| SignerId::Fingerprint(self.fingerprint) | ||
| } | ||
| } | ||
|
|
||
| /// This implementation ignores `sign_options` | ||
| impl TransactionSigner for HWISigner { | ||
| fn sign_transaction( | ||
| &self, | ||
| psbt: &mut PartiallySignedTransaction, | ||
| _sign_options: &crate::SignOptions, | ||
| _secp: &crate::wallet::utils::SecpCtx, | ||
| ) -> Result<(), SignerError> { | ||
| psbt.combine(self.client.sign_tx(psbt)?.psbt) | ||
| .expect("Failed to combine HW signed psbt with passed PSBT"); | ||
| Ok(()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.