Skip to content

Commit

Permalink
feat: update ledger instructions (tari-project#6406)
Browse files Browse the repository at this point in the history
Description
---
- Updated ledger instructions to build natively or via docker.
- Fixed compile errors.

Motivation and Context
---
See above.

How Has This Been Tested?
---
Performed a native build and install of the ledger app on Windows.

What process can a PR reviewer use to test or verify this change?
---
Physical build and install the ledger app.

<!-- Checklist -->
<!-- 1. Is the title of your PR in the form that would make nice release
notes? The title, excluding the conventional commit
tag, will be included exactly as is in the CHANGELOG, so please think
about it carefully. -->


Breaking Changes
---

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

<!-- Does this include a breaking change? If so, include this line as a
footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a
database, resync the chain -->
  • Loading branch information
hansieodendaal authored Jul 16, 2024
1 parent 8c6ea82 commit cc74845
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
1 change: 1 addition & 0 deletions applications/minotari_ledger_wallet/wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ curve = ["ed25519"]
flags = "0"
path = ["44'/535348'"]
name = "MinoTari Wallet"
api_level = "1"

[package.metadata.ledger.nanos]
icon = "key.gif"
Expand Down
60 changes: 58 additions & 2 deletions applications/minotari_ledger_wallet/wallet/README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -24,6 +44,41 @@ ledgerctl install-ca <NAME>

## 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:
Expand All @@ -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

Expand All @@ -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

Expand Down
3 changes: 0 additions & 3 deletions applications/minotari_ledger_wallet/wallet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -177,7 +176,6 @@ impl TryFrom<ApduHeader> 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),
Expand Down Expand Up @@ -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),
}
Expand Down

0 comments on commit cc74845

Please sign in to comment.