<img src="https://user-images.githubusercontent.com/4631227/191834116-59cf590e-25cc-4956-ae5c-812ea464f324.png" height="100" />

[GitHub](https://github.com/LedgerHQ/ledger-live/),
[Ledger Devs Discord](https://developers.ledger.com/discord-pro),
[Developer Portal](https://developers.ledger.com/)

## @ledgerhq/hw-app-exchange

Ledger Hardware Wallet Exchange app.

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

#### Table of Contents

*   [resolveTransactionType](#resolvetransactiontype)
    *   [Parameters](#parameters)
*   [OkStatus](#okstatus)
*   [decodePayloadProtobuf](#decodepayloadprotobuf)
    *   [Parameters](#parameters-1)

### resolveTransactionType

Adapt ExchangeTypes following partner info.
For "legacy" partner, we don't change the provided type.
For new one, we call the new APDU commands (Ng, Next Gen).

#### Parameters

*   `type` **ExchangeTypes**&#x20;
*   `partnerVersion` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**&#x20;

Returns **ExchangeTypes**&#x20;

### OkStatus

Those values map the one defined in the app-exchange code (@see protocol.md and swap\_errors.h)

Type: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)

### decodePayloadProtobuf

deprecated use `decodeSwapPayload` instead

#### Parameters

*   `payload` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<SwapPayload>**&#x20;

## Integration test

### 1. Prerequisite

Download latest version of Ledger SDK.

```sh
docker pull ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest
```

The rest of the documentation is about testing on NanoSP.

### 2. Compile app-exchange

```sh
docker run --privileged -v '<ABSOLUTE_PATH_TO_APP_EXCHANGE_SRC>:/app' -t -d --name ledger-app-dev-tools ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools

docker exec -it ledger-app-dev-tools bash -c 'export BOLOS_SDK="$<NANO_SDK>" && make -j DEBUG=1 TESTING=1 TEST_PUBLIC_KEY=1'
```

With `<NANO_SDK>` possible value:

*   NanoS: `NANOS_SDK`
*   NanoS+: `NANOSP_SDK`
*   NanoX: `NANOX_SDK`
*   Stax: `STAX_SDK`
*   Flex: `FLEX_SDK`

It is important to set the value of `DEBUG` to 1, as we need the fake Ledger private key in our test.

### 3. Launch speculos

You can compile only the `app-exchange`, but it can be useful to compile a coin-app like `app-ethereum`.

In the documentation, we assume the following name for the apps binary:

*   app-exchange: `exchange_nanosp.elf`
*   app-ethereum: `ethereum_nanosp.elf`

```sh
docker run -v '<ABSOLUTE_PATH_TO_ELFS>:/app' -p 5000:5000 -t -d --name speculos ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools

docker exec -it speculos bash -c 'speculos --model "nanosp" /app/exchange_nanosp.elf -l /app/ethereum_nanosp.elf --display headless'
```

### 4. Launch integration tests

From Ledger Live root directory:

```sh
pnpm ljs:hw-app-exchange test-integ
```
