Skip to content

Commit

Permalink
Merge pull request #53 from obsidiansystems/eac-install-manifest
Browse files Browse the repository at this point in the history
Install with manifest
  • Loading branch information
3noch authored Feb 28, 2019
2 parents 35c927b + 4a6d5b7 commit 3654344
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 59 deletions.
39 changes: 7 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,34 +372,12 @@ as you continue. You may want to read the rest of these instructions before you
begin installing, as you will need to confirm and verify a few things during the
process.

Still within the virtualenv, run the `./install.sh` command. This script is in
the root directory of this very repo, which means that in order to have it, you
must clone this repo and `cd` into the resulting directory:
Still within the virtualenv, run the `./install.sh` command included in the `release.tar.gz`
that you downloaded.

```
$ git clone https://github.com/obsidiansystems/ledger-app-tezos.git
$ cd ledger-app-tezos/
```

This `./install.sh` script takes two parameters, the first of which is
the *name* of the application you are installing, and the second is the
path to the `app.hex` file. (Up to date `app.hex` files can be found in
the releases for this repo, and can be unpacked in the same directory that
contains `./install.sh`):

* If you are installing the baking app, we recommend using the name "Tezos
Baking".

```
$ ./install.sh "Tezos Baking" baking.hex
```

* If you are installing the transaction app, we recommend using the name "Tezos
Wallet".

```
$ ./install.sh "Tezos Wallet" wallet.hex
```
This `./install.sh` script takes the path to an app directory. Two such directories
were included in the downloaded `release.tar.gz`.
Install both apps like this: `./install.sh wallet baking`.

The first thing that should come up in your terminal is a message that looks
like this:
Expand Down Expand Up @@ -441,10 +419,7 @@ If you'd like to remove your app, you can do this. In the virtualenv
described in the last sections, run this command:

```
$ python \
-m ledgerblue.deleteApp \
--targetId 0x31100004 \
--appName "Tezos"
$ python -m ledgerblue.deleteApp --targetId 0x31100004 --appName 'Tezos Wallet'
```

Replace the `appName` parameter "Tezos" with whatever app name you used when you
Expand All @@ -455,7 +430,7 @@ Then follow the prompts on the Ledger Nano S screen.
### Confirming the Installation Worked

You should now have two apps, `Tezos Baking` and `Tezos Wallet`. The `Tezos
Baking` app should display also a `0` on the screen, which is the highest block
Baking` app should display a `0` on the screen, which is the highest block
level baked so far (`0` in case of no blocks). The `Tezos Wallet` app will just
display `Tezos`.

Expand Down
41 changes: 33 additions & 8 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let
fhs = pkgs.callPackage nix/fhs.nix {};
bolosEnv = pkgs.callPackage nix/bolos-env.nix {};
bolosSdk = fetchThunk nix/dep/nanos-secure-sdk;
src = pkgs.lib.sources.cleanSource ./.;
src = pkgs.lib.sources.sourceFilesBySuffices (pkgs.lib.sources.cleanSource ./.) [".c" ".h" ".gif" "Makefile"];

app = bakingApp: pkgs.runCommand "ledger-app-tezos-${if bakingApp then "baking" else "wallet"}" {} ''
set -Eeuo pipefail
Expand All @@ -37,15 +37,40 @@ let
echo ">>>> Application size: <<<<"
'${pkgs.binutils-unwrapped}/bin/size' "$out/bin/app.elf"
'';
in rec {
wallet = app false;
baking = app true;
release = pkgs.runCommand "release.tar.gz" {} ''
cp '${wallet}/bin/app.hex' wallet.hex
cp '${baking}/bin/app.hex' baking.hex
tar czf "$out" wallet.hex baking.hex

mkRelease = short_name: name: appDir: pkgs.runCommand "${short_name}-release-dir" {} ''
mkdir -p "$out"
cp '${appDir + /bin/app.hex}' "$out/app.hex"
cat > "$out/app.manifest" <<EOF
name='${name}'
nvram_size=$(grep _nvram_data_size '${appDir + /debug/app.map}' | tr -s ' ' | cut -f2 -d' ')
target_id=0x31100004
version=$(echo '${commit}' | cut -f1 -d- | cut -f2 -dv)
EOF
cp '${dist/icon.hex}' "$out/icon.hex"
'';

walletApp = app false;
bakingApp = app true;
in {
wallet = walletApp;
baking = bakingApp;

release = rec {
wallet = mkRelease "wallet" "Tezos Wallet" walletApp;
baking = mkRelease "baking" "Tezos Baking" bakingApp;
all = pkgs.runCommand "release.tar.gz" {} ''
cp -r '${wallet}' wallet
cp -r '${baking}' baking
cp '${./release-installer.sh}' install.sh
chmod +x install.sh
tar czf "$out" install.sh wallet baking
'';
};

# Script that places you in the environment to run `make`, etc.
env-shell = pkgs.writeScriptBin "env-shell" ''
#!${pkgs.stdenv.shell}
Expand Down
1 change: 0 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ else
version="$3"
fi


set -x
python -m ledgerblue.loadApp \
--appFlags 0x00 \
Expand Down
2 changes: 1 addition & 1 deletion nix/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ set -Eeuo pipefail

# Override package set by passing --arg pkgs

commit=$(git describe --abbrev=8 --always 2>/dev/null)
commit=$(git describe --tags --abbrev=8 --always 2>/dev/null)
echo >&2 "Git commit: $commit"
exec nix-build --no-out-link --argstr commit "$commit" "$@"
2 changes: 1 addition & 1 deletion nix/env.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

commit=$(git describe --abbrev=8 --always 2>/dev/null)
commit=$(git describe --tags --abbrev=8 --always 2>/dev/null)
echo >&2 "Git commit: $commit"
shell_dir="$(nix-build -A env-shell --no-out-link --argstr commit "$commit" "${NIX_BUILD_ARGS:-}")"
shell="$shell_dir/bin/env-shell"
Expand Down
25 changes: 9 additions & 16 deletions nix/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,22 @@ set -Eeuo pipefail

root="$(git rev-parse --show-toplevel)"

: "${VERSION:=${2:-"$(git -C "$root" describe --tags | cut -f1 -d- | cut -f2 -dv)"}}"

install-wallet() {
"$root/install.sh" 'Tezos Wallet' "$("$root/nix/build.sh" -A wallet)" "$VERSION"
}
install-baking() {
"$root/install.sh" 'Tezos Baking' "$("$root/nix/build.sh" -A baking)" "$VERSION"
install() {
local release_file
release_file=$("$root/nix/build.sh" -A "release.$1")
bash "$root/release-installer.sh" "$release_file"
}

export root
export VERSION
export -f install-wallet
export -f install-baking
export -f install

nix-shell "$root/nix/ledgerblue.nix" -A shell --run "$(cat <<EOF
set -Eeuo pipefail
if [ "${1:-}" = "wallet" ]; then
install-wallet
elif [ "${1:-}" = "baking" ]; then
install-baking
if [ $# -eq 0 ]; then
install wallet
install baking
else
install-wallet
install-baking
install "${1:-}"
fi
EOF
)"
38 changes: 38 additions & 0 deletions release-installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -Eeuo pipefail
: "${1:?Please specify one or more directories or .tar.gz files; they should contain an 'app.manifest'}"

for arg in "$@"; do
echo

app_dir=""
if [ -d "$arg" ]; then
app_dir="$arg"
else
app_dir=$(tmp_dir=$(mktemp -d) && tar xf "$arg" -C "$tmp_dir" && echo "$tmp_dir")
echo "App for $arg unpacked in $app_dir"
fi

source "$app_dir/app.manifest"

echo "Installing ${name:?manifest file is missing field}" \
"version ${version:?manifest file is missing field}"
echo

set -x
python -m ledgerblue.loadApp \
--appFlags 0x00 \
--dataSize "${nvram_size:?manifest file is missing field}" \
--tlv \
--curve ed25519 \
--curve secp256k1 \
--curve prime256r1 \
--targetId "${target_id:?manifest file is missing field}" \
--delete \
--path 44"'"/1729"'" \
--fileName "$app_dir/app.hex" \
--appName "$name" \
--appVersion "$version" \
--icon "$(cat "$app_dir/icon.hex")" \
--targetVersion ""
done

0 comments on commit 3654344

Please sign in to comment.