Documentation
Setup and build

Requirements and installation

Introduction

All the JavaScript code related to the Ledger Live applications is in the ledger-live monorepository. The work to integrate a Blockchain in Ledger Live will all happen in this monorepository.

Ledger Live Common (./libs/ledger-live-common) is the shared core library used by Ledger Live Desktop and Mobile, that also includes a CLI for testing purpose or for using Ledger Live features directly from a terminal (in a limited way).

This library is built upon a pretty standard ES6 + Typescript stack and relies on a bunch of ledgerjs (opens in a new tab) packages, RxJS 6.x (opens in a new tab), bignumber.js (opens in a new tab) and React (opens in a new tab) + Redux (opens in a new tab) for some front-end utilities and hooks.

It is designed to have very generic models and mechanics (for currencies, accounts, storage, synchronisation, events...) that also facilitates new blockchain integrations through flexibility. All integrated coins are implemented in their own package in the libs directory, following the naming convention. To be fully integrated, a libs/ledger-live-common/src/families dedicated folder needs to contain a few "glue" files - that can be shared by multiple crypto-assets that use the same implementation (i.e. Bitcoin-like coins share the same bitcoin family).

This document only concerns new blockchain integrations using Typescript - we will use an imaginary coin named MyCoin as a walkthrough.

Setup

Requirements

Development tools (used or required)

Hardware prerequisites

  • A physical device (Ledger Nano S, S Plus, X or a Stax)
  • MyCoin app installed on device

Installation

Structure

Your whole implementation of MyCoin must reside in a mycoin folder in libs/ledger-live-common/src/families/ with the exception of some changes to apply in shared code.

Here is a typical family folder structure (TS integration):

./libs
β”œβ”€β”€ coin-mycoin/src
β”‚   β”œβ”€β”€ api
β”‚   β”‚   β”œβ”€β”€ cache.ts
β”‚   β”‚   └── index.ts
β”‚   β”œβ”€β”€ bridge
β”‚   β”‚   └── js.ts
β”‚   β”œβ”€β”€ account.ts
β”‚   β”œβ”€β”€ bridge.integration.test.ts
β”‚   β”œβ”€β”€ buildTransaction.ts
β”‚   β”œβ”€β”€ cli-transaction.ts
β”‚   β”œβ”€β”€ deviceTransactionConfig.ts
β”‚   β”œβ”€β”€ errors.ts
β”‚   β”œβ”€β”€ hw-getAddress.ts
β”‚   β”œβ”€β”€ js-broadcast.ts
β”‚   β”œβ”€β”€ js-createTransaction.ts
β”‚   β”œβ”€β”€ js-estimateMaxSpendable.ts
β”‚   β”œβ”€β”€ js-getFeesForTransaction.ts
β”‚   β”œβ”€β”€ js-getTransactionStatus.ts
β”‚   β”œβ”€β”€ js-prepareTransaction.ts
β”‚   β”œβ”€β”€ js-signOperation.ts
β”‚   β”œβ”€β”€ js-synchronization.ts
β”‚   β”œβ”€β”€ logic.ts
β”‚   β”œβ”€β”€ serialization.ts
β”‚   β”œβ”€β”€ signer.ts
β”‚   β”œβ”€β”€ specs.ts
β”‚   β”œβ”€β”€ speculos-deviceActions.ts
β”‚   β”œβ”€β”€ transaction.ts
β”‚   └── types.ts
β”œβ”€β”€ ledger-live-common/src/families/mycoin
β”‚   β”œβ”€β”€ bridge.integration.test.ts
β”‚   β”œβ”€β”€ logic.ts
β”‚   β”œβ”€β”€ react.ts
β”‚   β”œβ”€β”€ setup.ts
β”‚   └── types.ts
└── ledgerjs/packages/hw-app-mycoin/src
    └── MyCoin.ts
ℹ️

You can refer to existing implementations to complete given examples, like Polkadot integration.

Coin-module

  • src/api directory: Contains all the logic to send requests to the explorer.
  • src/bridge/js.ts file: Entry point of Ledger Live integration of the coin-module. This file lists BridgeCurrency and BridgeAccount implementation.
  • src/hw-getAddress.ts file: Logic on how to interact with device-app to retrieve addresses.
  • src/js-* files: Split of BridgeCurrency and BridgeAccount logic in dedicated files.
  • src/signer.ts file: Interface definition of the ledger device-app related to this coin.
  • src/specs.ts file: Definition of tests to be run on the bot.

Ledger live-common

  • src/logic.ts: Lists coin specific business logic.
  • src/react.ts: Defines and lists coin specfic react hooks for UI.
  • src/setup.ts: Glue file for coin integration.
  • src/types.ts: Lists coin specific types.

LedgerJS

All files related to communication with the device-app.

Ledger
Copyright Β© Ledger SAS. All rights reserved. Ledger, Ledger Nano S, Ledger Vault, Bolos are registered trademarks of Ledger SAS