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

feat: ledger key manager interface #5644

Merged
merged 12 commits into from Mar 26, 2024

Conversation

brianp
Copy link
Contributor

@brianp brianp commented Aug 16, 2023

Description

This PR expands the console wallet and key manager interfaces to support hardware wallets. It does not introduce functionality to communicate with the hardware wallet, simply the interface to support it. Another PR will be opened swapping out the placeholder software key manager for the hardware key manager where appropriate.

Motivation and Context

So people can use their most excellent hardware wallets with the MinoTari console wallet.

How Has This Been Tested?

Manually on osx

What process can a PR reviewer use to test or verify this change?

Breaking Changes

  • None
  • Requires data directory on base node to be deleted
  • Requires hard fork
  • Other - Please specify

@ghpbot-tari-project ghpbot-tari-project added the CR-too_long Changes Requested - Your PR is too long label Aug 16, 2023
@github-actions
Copy link

github-actions bot commented Aug 16, 2023

Test Results (CI)

    3 files    120 suites   34m 16s ⏱️
1 269 tests 1 269 ✅ 0 💤 0 ❌
3 799 runs  3 799 ✅ 0 💤 0 ❌

Results for commit 85d8b85.

♻️ This comment has been updated with latest results.

@ghpbot-tari-project ghpbot-tari-project added P-acks_required Process - Requires more ACKs or utACKs P-reviews_required Process - Requires a review from a lead maintainer to be merged labels Aug 16, 2023
@github-actions
Copy link

github-actions bot commented Aug 16, 2023

Test Results (Integration tests)

 2 files  11 suites   41m 12s ⏱️
32 tests 31 ✅ 0 💤 1 ❌
34 runs  31 ✅ 0 💤 3 ❌

For more details on these failures, see this check.

Results for commit 85d8b85.

♻️ This comment has been updated with latest results.

@brianp
Copy link
Contributor Author

brianp commented Aug 16, 2023

This PR was previously tracked on #5609 but stopped updating when new commits were pushed. This is the same PR but updated against development and with fixes in the test suite which is now green.

@hansieodendaal
Copy link
Contributor

I added a fix for the failing cucumber test - see #5645

@SWvheerden SWvheerden changed the base branch from development to feat-hardware-support August 17, 2023 11:41
chrono = { version = "0.4.19", default-features = false }
clap = { version = "3.2", features = ["derive", "env"] }
config = "0.13.0"
crossterm = { version = "0.25.0" }
digest = "0.10"
futures = { version = "^0.3.16", default-features = false, features = ["alloc"] }
log4rs = { git = "https://github.com/tari-project/log4rs.git", default_features = false, features = ["config_parsing", "threshold_filter", "yaml_format", "console_appender", "rolling_file_appender", "compound_policy", "size_trigger", "fixed_window_roller", "delete_roller"] }
ledger-transport-hid = { git = "https://github.com/Zondax/ledger-rs" }
Copy link
Collaborator

Choose a reason for hiding this comment

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

lock to a commit

@brianp brianp mentioned this pull request Aug 17, 2023
4 tasks
Copy link
Contributor

@hansieodendaal hansieodendaal left a comment

Choose a reason for hiding this comment

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

Hi @brianp, I can appreciate that this was a lot of work, however, I am not a fan of this approach.

In this PR we create a lot of scaffolding just to be able to create a ledger-specific or software-specific transaction key manager. My recommendations:

  • Initial startup

    • Add a command line switch to force the use of the ledger hardware wallet - if the ledger is not attached and the app not started panic with the error message - if attached and app started ok.
    • If the ledger is attached but the wallet is started without the switch, ask the user if this should be a hardware console wallet, if yes follow the logic as if the command line switch was present.
    • When started ok, earmark the console wallet as a ledger-only console wallet - consecutive startups without the ledger attached and the app started must panic.
  • Key manager

    • We should not differentiate outside of the key manager if we have a ledger or not, so no ledger_key_manager.
    • The key manager should be aware if a hardware wallet should be used and if it is a ledger and later on perhaps a trezor if that is added.
    • Inside the key manager whenever we have to use a secret key, for example inside inner/get_receiver_partial_metadata_signature(..), the appropriate software or hardware branch is called. There are not that many places where this branching will be necessary. All ledger-specific code can go into key_manager/ledger.rs, and later on we can add key_manager/trezor.rs.
  • Private keys to be managed

    • Both spend and script private keys should be managed by the ledger, but with the difference that the spend private key should be returned from the ledger to be used inside the key manager where needed and the script private key should never leave the ledger.
    • This will mean that range-proof bulletproofs can be constructed outside the ledger but not without it, and script signatures will be wholly constructed inside the ledger.
    • The same index must be used to obtain the matching set of spend and script private keys, as is currently the case with the software key manager.
  • Spending scripts

    • If both spend and script private keys are managed by the ledger, a hardware wallet will be able to receive an interactive transaction with any type of script, and will not be able to be sussed out as a hardware wallet by penny/poking transactions.

@brianp brianp requested a review from sdbondi August 18, 2023 10:13
@SWvheerden
Copy link
Collaborator

The ledger implementation very much follows this RFC: tari-project/rfcs#98
This means spend keys should be managed by the software wallet, not the hardware wallet aka ledger in this first implementation.

As per the RFC, this allows us to receive transactions without the hardware wallet being online, allowing it to be a cold storage wallet.

@brianp brianp force-pushed the ledger-key-manager branch 2 times, most recently from eacace9 to 41934fb Compare March 11, 2024 09:53
@brianp brianp requested review from a team as code owners March 11, 2024 09:53
Copy link
Contributor

@leet4tari leet4tari left a comment

Choose a reason for hiding this comment

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

utACK - scripts/install_ubuntu_dependencies.sh

Copy link
Contributor

@hansieodendaal hansieodendaal left a comment

Choose a reason for hiding this comment

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

Nice so far, just one comment for now, apart form the CI/clippy errors.

Comment on lines 832 to 835
Ok(_) => {
println!("Device found.");
let account = prompt_ledger_account().expect("An account value");
Some(WalletType::Ledger(account))
Copy link
Contributor

Choose a reason for hiding this comment

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

The TRANSPORT lazy static should be assigned a value

Suggested change
Ok(_) => {
println!("Device found.");
let account = prompt_ledger_account().expect("An account value");
Some(WalletType::Ledger(account))
Ok(transport) => {
*TRANSPORT.lock().expect("lock exists") = Some(transport);
println!("Device found.");
let account = prompt_ledger_account().expect("An account value");
Some(WalletType::Ledger(account))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This actually sent me on a wild goose chase trying to find where the code had previously been removed.

But, we don't actually need to assign this here. We check to make sure the ledger is present to see if we should create a ledger backed wallet. But the ledger could be unplugged anytime between this prompt, and performing a transaction. It doesn't need to be plugged in at all times. We need to check to see if it's present again, only during script and meta data sig generation for send transactions.

@brianp brianp force-pushed the ledger-key-manager branch 2 times, most recently from ac183a1 to 2618697 Compare March 13, 2024 15:57
@SWvheerden SWvheerden changed the base branch from feat-hardware-support to development March 14, 2024 06:07
hansieodendaal
hansieodendaal previously approved these changes Mar 14, 2024
Copy link
Contributor

@hansieodendaal hansieodendaal left a comment

Choose a reason for hiding this comment

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

utACK

@@ -429,6 +443,40 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
// Transaction input section (transactions > transaction_components > transaction_input)
// -----------------------------------------------------------------------------------------------------------------

pub async fn get_script_private_key(&self, script_key_id: &TariKeyId) -> Result<PrivateKey, TransactionError> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is fine for now, but in the actual implementation we should ver get this script key out of the ledger, we should ask the ledger to sign the script signature for us and we should get that out

@SWvheerden SWvheerden merged commit 0d66126 into tari-project:development Mar 26, 2024
14 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CR-too_long Changes Requested - Your PR is too long P-acks_required Process - Requires more ACKs or utACKs P-reviews_required Process - Requires a review from a lead maintainer to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants