Skip to content

Commit

Permalink
Merge branch 'main' into Blockchain-Update
Browse files Browse the repository at this point in the history
  • Loading branch information
cfranceschi-ledger authored Sep 24, 2024
2 parents 8a1881e + f71797a commit 50c8453
Show file tree
Hide file tree
Showing 46 changed files with 911 additions and 1,684 deletions.
37 changes: 32 additions & 5 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,11 @@ module.exports = {
destination: '/docs/connectivity/ledgerJS/tutorials/tutorial-4-cosmos-webapp',
permanent: true,
},
{
source: '/docs/clear-signing/eip7730',
destination: '/docs/clear-signing/erc7730',
permanent: true,
},
{
source: '/docs/transport/clear-signing',
destination: '/docs/clear-signing/eip712',
Expand Down Expand Up @@ -1273,34 +1278,56 @@ module.exports = {
},
{
source: '/docs/token/faq',
destination: '/docs/tokens/integrating-tokens/faq',
destination: '/docs/tokens/faq',
permanent: true,
},

{
source: '/docs/tokens/integrating-tokens/faq',
destination: '/docs/tokens/faq',
permanent: true,
},
{
source: '/docs/token/erc20-bep20',
destination: '/docs/tokens/integrating-tokens/evm-chains-tokens',
destination: '/docs/tokens/evm-chains-tokens',
permanent: true,
},
{
source: '/docs/token/erc20',
destination: '/docs/tokens/integrating-tokens/evm-chains-tokens',
destination: '/docs/tokens/evm-chains-tokens',
permanent: true,
},
{
source: '/docs/token/evm-chains-tokens',
destination: '/docs/tokens/integrating-tokens/evm-chains-tokens',
destination: '/docs/tokens/evm-chains-tokens',
permanent: true,
},

{
source: '/docs/tokens/integrating-tokens/evm-chains-tokens',
destination: '/docs/tokens/evm-chains-tokens',
permanent: true,
},
{
source: '/docs/tokens/integrating-tokens/asa',
destination: '/docs/tokens/asa',
permanent: true,
},
{
source: '/docs/token/asa',
destination: '/docs/tokens/integrating-tokens/asa',
destination: '/docs/tokens/asa',
permanent: true,
},
{
source: '/docs/token/trc',
destination: '/docs/tokens/integrating-tokens/trc',
permanent: true,
},
{
source: '/docs/tokens/integrating-tokens/trcc',
destination: '/docs/tokens/trc',
permanent: true,
},
{
source: '/docs/token/eip712-messages',
destination: '/docs/clear-signing/nft',
Expand Down
15 changes: 11 additions & 4 deletions pages/docs/blockchain/coding.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,35 @@ This time line shows the relative time of the steps (XS, S, M and L) you will go
<Card
image
arrow
title="Address derivation"
title="Create Coin Module"
href="./coding/create-module">
<>![Coin Module](/blockchain/wallet-api.png)</>
</Card>
<Card
image
arrow
title="A - Address derivation"
href="./coding/address-derivation">
<>![Address derivation](/blockchain/address-derivation.png)</>
</Card>
<Card
image
arrow
title="Add accounts: light sync"
title="B - Add accounts: light sync"
href="./coding/light-sync">
<>![Add accounts: light sync](/blockchain/sync-light.png)</>
</Card>
<Card
image
arrow
title="Add accounts: full sync"
title="C - Add accounts: full sync"
href="./coding/sync">
<>![Add accounts: full sync](/blockchain/sync-full.png)</>
</Card>
<Card
image
arrow
title="Send"
title="D - Send"
href="./coding/send">
<>![Send](/blockchain/send.png)</>
</Card>
Expand Down
1 change: 1 addition & 0 deletions pages/docs/blockchain/coding/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"send": "6 - Send",
"desktop-mobile": "7 - Ledger Live Desktop and Mobile",
"wallet-api": "8 - Wallet API",
"create-module": "X - Create Coin Module",
"bugs-troubleshooting": "Ledger Live common bugs"
}
10 changes: 3 additions & 7 deletions pages/docs/blockchain/coding/address-derivation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ title: Address derivation

# 3 - Address derivation

From step 3 to step 6, you work will be implemented in the [Ledger Live repository](https://github.com/LedgerHQ/ledger-live/tree/develop/libs/ledger-live-common).

### Derive Address from device

Before starting this step, make sure [you have setup your environment](../setup-build) to work with `ledger-live`.

First define the signer interface, which will reflect your [embedded app js binding](./js-bindings):
First define the signer interface in dedicated `libs/coin-module/coin-mycoin/src/types/signer.ts` file, which will reflect your [embedded app js binding](./js-bindings):

```ts copy
export type MyCoinAddress = {
Expand All @@ -30,7 +26,7 @@ export interface MyCoinSigner {

Then get an address from the device for <i>MyCoin</i>, by creating the `hw-getAddress.ts` Resolver:

`libs/coin-mycoin/src/hw-getAddress.js`:
`libs/coin-module/coin-mycoin/src/signer/getAddress.ts`:

```ts copy
import type { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
Expand All @@ -44,7 +40,7 @@ const resolver = (
return async (deviceId: string, { path, verify }: GetAddressOptions) => {
const address = (await signerContext(deviceId, signer =>
signer.getAddress(path, verify),
)) as PolkadotAddress;
)) as MyCoinAddress;
return {
address: address.address,
publicKey: address.pubKey,
Expand Down
35 changes: 35 additions & 0 deletions pages/docs/blockchain/coding/create-module.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: "Add accounts: light sync"
description: An account represents a wallet where a user detains crypto assets for a given crypto currency. Ledger Live model is essentially an array of Account because many accounts can be created, even within a same crypto currency.
---

# 3 - Create Coin Module

## Organization

All CoinModules are located in [libs/coin-modules](https://github.com/LedgerHQ/ledger-live/tree/develop/libs/coin-modules).

A CoinModule has the following directories/modules:
- `api` (optional): interface for exposing the CoinModule to a backend service (cf. (TODO))
- `bridge`: implementation of Bridges interface (cf. [Bridge](light-sync))
- `logic`: contains all core logic of the blockchain. The code here is agnostic of all external interface (i.e. Bridge or Api) and relies only on external libs and `network` directory
- `network`: communication logic with explorer/index/node (cf. [How to wrap you api](light-sync#wrap-your-api))
- `signer`: defines the interface definition to the Embedded App and the logic to retrieve [derive address](addrss-derivation)

## Some architectural decision
For consistency among all the CoinModule, please consider the following principles:
- Always use an `index.ts` file in each directory. The goal is to "control" what is exposed from the module and allow to be used from outside.
- The `index.ts` in the root of the CoinModule should only expose:
- Bridge interface
- Bridge type
- bot test
- ...
- Inside CoinModule, the dependency between module is only one direction (avoid cyclic dependency or mutual ones). Example: From the `logic` module, it is forbidden to use some functions declared in `bridge`.

<img src="/blockchain/coin-module-inner-dependency.png" alt="Coin Module inner dependency" />

## ...

The following steps (3-A to 3-D), your work will have some impact on the [Ledger Live repository](https://github.com/LedgerHQ/ledger-live/tree/develop/libs/ledger-live-common).

Therefore, make sure [you have setup your environment](../setup-build) to work with `ledger-live`.
82 changes: 82 additions & 0 deletions pages/docs/blockchain/coding/desktop-mobile.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,88 @@ description: Adding your currency in Ledger Live Desktop and Mobile.
1. Fork [github.com/LedgerHQ/ledger-live](https://github.com/LedgerHQ/ledger-live)
2. Clone the repo

## Ledger Live Common

Ledger Live Common is the repo where all the common logic and setup (between desktop and mobile) is done.

Even if CoinModules are made with Ledger Live as first class citizen user, it is not the only Ledger product that relies on.
Therefore, some setup is required to allow LLD and LLM to use your CoinModule.

For a dedicated CoinModule (i.e. MyCoin), all those setup files will be in `libs/ledger-live-common/src/families/mycoin` directory.

### Setup

The setup file (`libs/ledger-live-common/src/families/mycoin/setup.ts`) is responsible for the instanciation of the CoinModule.
It injects all required elements.

Some helpers function exist in LLC (`libs/ledger-live-common/src/bridge/setup.ts`), to avoid too much boilerplate.

```ts copy
import {
MyCoinAccount,
TransactionStatus,
createBridges,
type Transaction,
} from "@ledgerhq/coin-mycoin";
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
import Transport from "@ledgerhq/hw-transport";
import MyCoin from "@ledgerhq/hw-app-mycoin";
import type { Bridge } from "@ledgerhq/types-live";
import { MyCoinCoinConfig } from "@ledgerhq/coin-mycoin/config";
import myCoinResolver from "@ledgerhq/coin-mycoin/signer/index";
import makeCliTools, { type CliTools } from "@ledgerhq/coin-mycoin/test/cli";
import { createResolver, executeWithSigner, type CreateSigner } from "../../bridge/setup";
import { Resolver } from "../../hw/getAddress/types";
import { getCurrencyConfiguration } from "../../config";

const createSigner: CreateSigner<MyCoin> = (transport: Transport) => {
return new MyCoin(transport);
};

const myCoin = getCryptoCurrencyById("myCoin");
// Closure that will load dynamically the current config linked to this coin. The config may change during LLD and LLM lifecyle.
const getCurrencyConfig = (): MyCoinCoinConfig => getCurrencyConfiguration(myCoin);

const bridge: Bridge<Transaction, MyCoinAccount, TransactionStatus> = createBridges(
executeWithSigner(createSigner),
getCurrencyConfig,
);

const resolver: Resolver = createResolver(createSigner, myCoinResolver);

const cliTools: CliTools = makeCliTools();

export { bridge, cliTools, resolver };

```

### Config

Ledger Live use a dynamic configuration for some parts of its logic. CoinModules use this tool to seamlessly update some key elements.

The `status` element of the following object is mandatory. The other properties are depending on your needs in the CoinModule.
`libs/ledger-live-common/src/bridge/config.ts`:

```ts copy
import { ConfigInfo } from "@ledgerhq/live-config/LiveConfig";
import { getEnv } from "@ledgerhq/live-env";

export const myCoinConfig: Record<string, ConfigInfo> = {
config_currency_mycoin: {
type: "object",
default: {
status: {
type: "active",
},
node: {
url: getEnv("API_MYCOIN_NODE"),
},
},
},
};

```

## Ledger Live Desktop

### Adding the crypto in LLD
Expand Down
Loading

0 comments on commit 50c8453

Please sign in to comment.