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: update ledger instructions #6406

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading