Skip to Content
Ledger Live™ is now Ledger Wallet™ and Ledger hardware wallets are now Ledger signers. Updating all references. Learn more here
DocumentationLedger WalletDiscoverIntegration walkthroughsWallet APIServerExtrasRxJS operators used in Wallet API Server

RxJS operators used in Wallet API Server

WalletAPIServer uses RxJS 7  to handle the stream of messages coming in from Ledger Wallet. This page is a quick reference for the specific operators and subjects the server relies on. If you are new to RxJS, start with the official RxJS guide  before reading further.

map

map transforms each value emitted by an observable before passing it downstream. The server uses it to normalise or reshape incoming message payloads.

Observable

An Observable is a lazy push-based data producer. The server models the incoming message stream as an observable so consumers can react to each message without polling.

BehaviorSubject

A BehaviorSubject is a subject that requires an initial value and immediately emits the current value to any new subscriber. The server uses it to hold stateful permission lists (such as allowed currencies) so that late subscribers always receive the latest snapshot.

import { BehaviorSubject } from "rxjs"; const subject = new BehaviorSubject(123); // Two subscribers receive the initial value immediately. subject.subscribe(console.log); // 123 subject.subscribe(console.log); // 123 // Both receive the new value when it changes. subject.next(456); // 456, 456 // A new subscriber receives the latest value (456), not the initial one. subject.subscribe(console.log); // 456 subject.next(789); // 789, 789, 789 // Output sequence: 123, 123, 456, 456, 456, 789, 789, 789

combineLatest

combineLatest emits a combined value whenever any of its source observables emits, pairing each emission with the most recent value from every other source. The server uses it to compute the list of currencies a dApp is permitted to access, re-evaluating whenever either the full currency list or the dApp’s declared permissions change:

const allowedCurrencies$ = new BehaviorSubject([]); combineLatest( [this.allCurrencies$, this.permissions.currencyIds$], matchCurrencies ).subscribe(allowedCurrencies$);

Here matchCurrencies is the projection function that filters allCurrencies$ to those the dApp has declared. allowedCurrencies$ emits an empty array immediately (from the BehaviorSubject initial value), then re-emits any time either source changes.

firstValueFrom

firstValueFrom converts an observable to a promise by subscribing, waiting for the first emission, and then unsubscribing. The server uses it when a one-shot value is needed from a stream without keeping the subscription open.

import { firstValueFrom } from "rxjs"; const value = await firstValueFrom(someObservable$);
Last updated on
Ledger
Copyright © Ledger SAS. All rights reserved. Ledger, Ledger Stax, Ledger Flex, Ledger Nano, Ledger Nano S, Ledger OS, Ledger Wallet, [LEDGER] (logo), [L] (logo) are trademarks owned by Ledger SAS.