GitHub,
Ledger Devs Discord,
Developer Portal
@ledgerhq/hw-app-exchange
[!NOTE]
Status: STABLE — Production-ready; API is considered stable.
Ledger Hardware Wallet Exchange app.
API
Table of Contents
- SwapPayloadFieldExceedsLimit
- resolveTransactionType
- OkStatus
- decodePayloadProtobuf
- findSwapPayloadSpecViolation
SwapPayloadFieldExceedsLimit
Extends Error
Thrown when a decoded swap payload field is larger than what the Exchange
device app can store. It lets us surface a precise reason (which field, its
limit and the actual size) instead of the device's generic
DESERIALIZATION_FAILED (0x6a81) status, which is opaque for investigations.
Parameters
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
partnerVersion number?
Returns ExchangeTypes
OkStatus
Those values map the one defined in the app-exchange code (@see protocol.md and swap_errors.h)
Type: number
decodePayloadProtobuf
deprecated use decodeSwapPayload instead
Parameters
Returns Promise\
findSwapPayloadSpecViolation
Decodes a raw swap payload (hex or base64) and returns the first field that
exceeds the Exchange device app's protobuf size limits as a precise
SwapPayloadFieldExceedsLimit, or undefined when everything fits (or the
payload cannot be decoded locally).
This is meant to enrich the device's opaque DESERIALIZATION_FAILED (0x6a81)
with an actionable reason (e.g. an oversized payin_extra_id) — it must never
gate the flow. The device stays the source of truth, so if these (hardcoded)
limits ever drift from the app we simply return undefined and keep the
device's own error.
nanopb reserves one byte for the NUL terminator on string fields, so their
usable content limit is max_size - 1; bytes fields use the full max_size.
Parameters
Returns (SwapPayloadFieldExceedsLimit | undefined)
Integration test
1. Prerequisite
Download latest version of Ledger SDK.
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
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
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:
pnpm ljs:hw-app-exchange test-integ