The Bytecoin Team has been working on making hardware wallets a storage option for the Bytecoin community for quite some time. We admire the technology and would like to use this space to provide a preview of how Bytecoin can work with one of the most prevalent hardware wallets in the industry, the Ledger Nano S. First we will describe how Ledger devices manage keys, then how to install the Bytecoin app on a Ledger Nano S, and finally show how to use the device to send BCN.

To follow this tutorial you will need:

an initialized Ledger Nano S; Bytecoin Desktop and Bytecoin daemons v3.4.3 and up; a machine running Ubuntu Linux 16.04 x86-64 (it is required to build a Bytecoin app for Ledger from the source code).





Important!

If you have not yet initialized your Ledger Nano S, make sure to follow Ledger’s tutorials to check whether your device is genuine, set it up, and update its firmware to the latest available version.





A preface about working with Ledger

For those not yet familiar with how Ledger devices manage user data we will first describe how they work. Ledger uses a technology called Hierarchical Deterministic wallets (most commonly abbreviated to HD wallets). These wallets allow users to use one piece of initial cryptographic data to create keys for multiple cryptocurrencies and to restore access to all their funds. We will get back to HD wallets shortly.

There are two ways to start working with a Ledger Nano S:

generate a master seed and a mnemonic (most common method, especially for new users); Enter a preexisting mnemonic and generate a corresponding master seed.

Either way, you end up with a mnemonic and a corresponding master seed.

A seed is a cryptographic object that is used to generate private keys for a cryptocurrency.

Mnemonic is a sequence of simple words that can be used to restore your wallet. A 24-word mnemonic looks like this:

brass boss brand brush slush merry supreme kangaroo together promote play public welcome cage dance stable cushion surge roast fire layer twin purchase join





A mnemonic is a very sensitive piece of information and should be:

securely generated; backed up in multiple places; kept secret. If someone were to get someone’s mnemonic, they would be able to get a hold of all their funds stored on a Ledger.





Ledger uses BIP32 protocol to generate corresponding seeds for all currencies you use on the device from your master seeds. So a Ledger wallet is:

Hierarchical - these keys are stored in a predefined tree like structure;

Deterministic - even if you lose your Ledger device you will still be able to restore all your private keys and addresses from your mnemonic and consequently regain access to all your funds.





Building and installing the Bytecoin app on Ledger

Instructions for building a Bytecoin app for Ledger are available in the corresponding repository on GitHub. We will explain what every command does below. Keep in mind that Ubuntu Linux 16.04 x86-64 is required to perform the build.





Instructions should be executed in the command-line utility:





Notice: command sudo asks the adjacent command to be executed from the root user.





sudo apt update

Updates apt’s database. Apt is a software package manager.





sudo apt install gcc-multilib g++-multilib git libusb-1.0-0-dev python python-pip libudev-dev

Installs the packages after the install keyword. These are required in the process.





mkdir -p ~/bolos-devenv

Creates a bolos-devenv folder in the Home directory.





cd ~/bolos-devenv

Changes working directory to newly created bolos-devenv.





git clone https://github.com/LedgerHQ/nanos-secure-sdk.git

Clones Ledger’s nanos-secure-sdk repository from GitHub to local machine.





wget https://launchpad.net/gcc-arm-embedded/5.0/5-2016-q1-update/+download/gcc-arm-none-eabi-5_3-2016q1-20160330-linux.tar.bz2

Downloads GNU Compiler Collection for ARM processors. It is a compiler system for different programming languages.





wget http://releases.llvm.org/4.0.0/clang+llvm-4.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz

Downloads the Clang, a tooling infrastructure for C-family languages.





tar xvfj gcc-arm-none-eabi-5_3-2016q1-20160330-linux.tar.bz2

tar xvfJ clang+llvm-4.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz

These commands unpack the downloaded packages.





mv clang+llvm-4.0.0-x86_64-linux-gnu-ubuntu-16.04 clang-arm-fropi

This command moves a folder for convenience.





pip install --user ledgerblue

Uses Python package manager to install a collection of Ledger’s scripts.





echo "SUBSYSTEMS==\"usb\", ATTRS{idVendor}==\"2c97\", ATTRS{idProduct}==\"0001\", MODE=\"0660\", GROUP=\"plugdev\"" | sudo tee -a /etc/udev/rules.d/20-hw1.rules

Edits Linux’s permission file to allow interacting with a Ledger Nano S





sudo udevadm trigger

sudo udevadm control --reload-rules

These finalize changes made in the previous command.





cd ~

Changes active directory to Home.





git clone https://github.com/bcndev/ledger-app-bytecoin

Clones Bytecoin’s repository with Ledger app source code to the local machine.





make BOLOS_ENV=~/bolos-devenv BOLOS_SDK=~/bolos-devenv/nanos-secure-sdk load

Builds Bytecoin’s app and sends it to Ledger Nano S.





Then the following sequence of affirmative inputs from Ledger will be required:





Ledger will ask you whether you allow unknown manager, since we’re uploading an app from command line rather than Ledger Live software. This will change once the Bytecoin app gets reviewed by Ledger.









You will be prompted to enter your pincode. Ledger will ask you whether you want the app to be installed, showing miscellaneous info about the Bytecoin app.









After it is done you can launch the Bytecoin app:









Since the Bytecoin app has not yet been reviewed by Ledger, you need to confirm the launch of a non-genuine app (an app that comes from outside the Ledger Live software):









And the Bytecoin app opens:











Creating a wallet file

Before users are able to create a Ledger wallet in the Bytecoin Desktop interface we have to use Bytecoin daemons to create a wallet file. This step can be performed on any major OS: WIndows, Mac OS or Linux. You will need:

an initialized Ledger Nano S with the Bytecoin app we just installed; Bytecoin daemons v3.4.3 and up, which you can get for all major OSes on the official GitHub.

A Bytecoin daemon is Bytecoin software that runs in the command line. The familiar Bytecoin Desktop app uses these same daemons.

For a change we will use Mac OS, but instructions are identical for all operating systems except for commands that work with file paths on Windows (they use backslashes (\) instead of forward slashes (/) ).

Instructions go as follows:

Open a folder with Bytecoin daemons. You will see two programs: bytecoind (responsible for working with Bytecoin blockchain) and walletd (responsible for working with Bytecoin wallets). Open a command line utility of choice. We will use the default Terminal app.



We need to point our command-line utility to the location where the daemons reside. For that we will use the cd command (which stands for change directory).



Type cd and then the location with the daemons and hit Enter.



Hint: You can also type cd + <space> and then drag the folder with the daemons into the command-line utility



The Terminal responds:







Now we will ask the walletd daemon to create a hardware wallet for us. Open the Bytecoin app on Ledger and let it stay open for 15 seconds to let the Ledger OS process it. Then run the following command:



./walletd --create-wallet --wallet-file=<path-to-your-wallet-file>/<wallet-name>.wallet --wallet-type=hardware --import-view-key



Here is what each element of the command does:



./walletd - calls walletd to the current location

--create-wallet - parameter that initiates wallet construction

--wallet-file=... - indicates the path and name of the wallet to be created

--wallet-type=hardware - indicates that a hardware wallet file is needed

--import-view-key - puts the private view key in the wallet file



When asked for a password, just hit Enter. A hardware wallet serves as a security measure, rather than a password:







During this operation, you will need to confirm the corresponding prompts on Ledger:



















The operation is finished:







Important!

Why do we instruct walletd to put a private view key into the wallet file? Bytecoin uses more complex cryptographic technology than Bitcoin to facilitate anonymity. Unlike Bitcoin, in order to find user’s funds in the synced blocks Bytecoin performs multiple computation-intensive cryptographic operations.

If we avoid embedding a private view key into the wallet file, Bytecoin would need to ask Ledger to perform this operation with the private view key with every block it syncs, which would result in noticeably longer sync times.

Private view key should not be confused with private spend key. Private view key cannot be used to spend funds.



Now we can open our wallet file with Bytecoin Desktop. When asked for a password, just hit Enter, like the previous time. Make sure your Ledger is connected and your Bytecoin app is open:







Bytecoin Desktop will download the blockchain and look for your funds with your private view key embedded in the wallet file. At this point you can send BCN to your newly created wallet.

Sending BCN with Ledger Nano S

For this part of the tutorial you will require Bytecoin Desktop v3.4.3 and up.

Sending BCN with Ledger Nano S is as straightforward as it gets: