From 24dde18c0444bffdd5b4f03c70c14a533ce21846 Mon Sep 17 00:00:00 2001 From: Hansie Odendaal Date: Mon, 15 Jul 2024 15:58:23 +0200 Subject: [PATCH] Update ledger instructions --- .../minotari_ledger_wallet/wallet/Cargo.toml | 1 + .../minotari_ledger_wallet/wallet/README.md | 60 ++++++++++++++++++- .../minotari_ledger_wallet/wallet/src/main.rs | 3 - 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/applications/minotari_ledger_wallet/wallet/Cargo.toml b/applications/minotari_ledger_wallet/wallet/Cargo.toml index 30f80b4cfd..1c4839ab69 100644 --- a/applications/minotari_ledger_wallet/wallet/Cargo.toml +++ b/applications/minotari_ledger_wallet/wallet/Cargo.toml @@ -40,6 +40,7 @@ curve = ["ed25519"] flags = "0" path = ["44'/535348'"] name = "MinoTari Wallet" +api_level = "1" [package.metadata.ledger.nanos] icon = "key.gif" diff --git a/applications/minotari_ledger_wallet/wallet/README.md b/applications/minotari_ledger_wallet/wallet/README.md index cec55ac991..5583dc0672 100644 --- a/applications/minotari_ledger_wallet/wallet/README.md +++ b/applications/minotari_ledger_wallet/wallet/README.md @@ -1,5 +1,25 @@ # Instructions +## Setup + +Ledger does not build with the standard library, so we need to install `rust-src`. This can be done with: +``` +rustup component add rust-src --toolchain nightly +``` + +For loading a BOLOS application to a Ledger device, Ledger has actually written a command, called +[Cargo Ledger](https://github.com/LedgerHQ/cargo-ledger). This we need to install with: +``` +cargo install --git https://github.com/LedgerHQ/cargo-ledger cargo-ledger +``` + +As per the [Cargo Ledger setup instructions](https://github.com/LedgerHQ/cargo-ledger#setup) run the following to add +new build targets for the current rust toolchain: + +``` +cargo ledger setup +``` + To control ledger devices we use the ledgerctl library. We install the supporting Python libraries from Ledger to control Ledger devices, [LedgerCTL](https://github.com/LedgerHQ/ledgerctl). This we do with: @@ -24,6 +44,41 @@ ledgerctl install-ca ## Building +### Native + +Open a terminal in the subfolder `./applications/minotari_ledger_wallet/wallet` + +_**Note:** Windows users should start a "x64 Native Tools Command Prompt for VS 2019" to have the build tools available +and then start a python shell within that terminal to have the Python libraries available._ + +#### Build `ledger` + +This must be run from a Python shell (`pip3 --version` should work). + +To build, run + +``` +cargo ledger build {TARGET} -- "-Zbuild-std=std,alloc" +``` + +where TARGET = nanosplus, nanos, etc. + +#### Build and install `ledger` + +To build and load, run + +``` +cargo ledger build {TARGET} --load -- "-Zbuild-std=std,alloc" +``` + +where TARGET = nanosplus, nanos, etc. + +**Errors** + +If the auto-load does not work, try to do a manual installation. + +### Using Docker + Ledger does not easily compile locally and it is easiest to compile via docker using their provided [ledger-app-builder](https://github.com/LedgerHQ/ledger-app-builder/). See their readme for setup. Once installed you can build the Tari Wallet for ledger by navigating to `./applications/minotari_ledger_wallet` and running the docker command: @@ -41,7 +96,7 @@ cargo ledger build {TARGET} Please note docker has no access to usb devices on MacOS. So the use of `cargo ledger build {TARGET} --load` will fail. -### Install `ledger` +### Manual installation - First delete the application if it was already installed @@ -54,8 +109,9 @@ Please note docker has no access to usb devices on MacOS. So the use of `cargo l ``` `ledgerctl install app_nanosplus.json` ``` + **Note:** In some cases the `cargo ledger build` action will invalidate `app_nanosplus.json` by setting the first line -to `"apiLevel": "0",` - ensure it is set to `"apiLevel": "1",` +to something other than `"apiLevel": "1",` - ensure it is set to `"apiLevel": "1",` ### Running the ledger application diff --git a/applications/minotari_ledger_wallet/wallet/src/main.rs b/applications/minotari_ledger_wallet/wallet/src/main.rs index 19e37ef3d1..4eda1cdd54 100644 --- a/applications/minotari_ledger_wallet/wallet/src/main.rs +++ b/applications/minotari_ledger_wallet/wallet/src/main.rs @@ -35,7 +35,6 @@ use handlers::{ get_public_key::handler_get_public_key, get_script_offset::{handler_get_script_offset, ScriptOffsetCtx}, get_script_signature::handler_get_script_signature, - get_script_signature_from_challenge::handler_get_script_signature_from_challenge, get_version::handler_get_version, get_view_key::handler_get_view_key, }; @@ -177,7 +176,6 @@ impl TryFrom for Instruction { more: value.p2 == P2_MORE, }), (0x07, 0, 0) => Ok(Instruction::GetMetadataSignature), - (0x08, 0, 0) => Ok(Instruction::GetScriptSignatureFromChallenge), (0x09, 0, 0) => Ok(Instruction::GetViewKey), (0x10, 0, 0) => Ok(Instruction::GetDHSharedSecret), (0x06, _, _) => Err(AppSW::WrongP1P2), @@ -226,7 +224,6 @@ fn handle_apdu(comm: &mut Comm, ins: Instruction, offset_ctx: &mut ScriptOffsetC Instruction::GetScriptSignature => handler_get_script_signature(comm), Instruction::GetScriptOffset { chunk, more } => handler_get_script_offset(comm, chunk, more, offset_ctx), Instruction::GetMetadataSignature => handler_get_metadata_signature(comm), - Instruction::GetScriptSignatureFromChallenge => handler_get_script_signature_from_challenge(comm), Instruction::GetViewKey => handler_get_view_key(comm), Instruction::GetDHSharedSecret => handler_get_dh_shared_secret(comm), }