ledger-wallet / Readme • Examples • Contributing • Changelog
Easy Ledger Wallet support for Stellar applications and command line.
(Weekly updates: Reddit, Twitter, Keybase, Telegram)
This library is a convenient wrapper around the official Ledger libraries for Stellar:
- Stellar app API
- Transport Node HID - Node.js support
- Transport U2F - Browser support
It provides a way to support Ledger Wallets with a few one-liners:
// Step 1: Connect
await ledgerWallet.connect()
// Step 2: Get public key
const pubkey = ledgerWallet.publicKey
// Step 3: Sign transaction
await ledgerWallet.sign(transaction)
// Extra: Event handlers
ledgerWallet.onConnect = connectionHandler
ledgerWallet.onDisconnect = disconnectionHandler
This library is compatible with both Node.js and browser environments.
- NPM:
npm install @cosmic-plus/ledger-wallet
- Yarn:
yarn add @cosmic-plus/ledger-wallet
In your script: const ledgerWallet = require("@cosmic-plus/ledger-wallet")
bower install cosmic-plus-ledger-wallet
In your HTML page:
<script src="./bower_components/cosmic-plus-ledger-wallet/ledger-wallet.js"></script>
In your HTML page:
<script src="https://cdn.cosmic.plus/ledger-wallet@2.x"></script>
Note: For production release it is advised to serve your copy of the library.
Waits for a connection with the Ledger Wallet application for Stellar. If
account is not provided, account 1 is used. The library will stop
listening for a connection if await ledgerWallet.disconnect()
is called.
Once the connection is established, you can use await ledgerWallet.connect(account)
again at any time to ensure the device is
still connected.
When switching to another account, you can await ledgerWallet.connect(new_account)
without prior disconnection.
Note: To stay consistent with the way Trezor numbers accounts, account
starts at 1 (derivation path: m/44'/148'/0'
).
Param | Type | Default | Description |
---|---|---|---|
[account] | Number | String |
1 |
Either an account number (starts at 1) or a derivation path (e.g: m/44'/148'/0' ). |
Prompts the user to accept transaction using the connected account of their Ledger Wallet.
If the user accepts, adds the signature to transaction. Else, throws an error.
Param | Type | Description |
---|---|---|
transaction | Transaction |
A StellarSdk Transaction |
Close the connection with the Ledger device, or stop waiting for one in case a connection has not been established yet.
Connects the first unused account.
Note: merged accounts are considered as used.
Param | Type | Default | Description |
---|---|---|---|
[horizon] | String | Server |
"https://horizon.stellar.org" |
The Horizon server where to check for account existence. It can be either an URL or a StellarSdk.Server object. |
Scans the ledger device for accounts that exist on params.horizon. The scanning stops after encountering params.attempts unused accounts.
Merged accounts are considered as existing accounts and will reset the params.attempts counter when encountered.
Returns an Array of Objects containing account
number, publicKey
,
path
, and state
(either "open"
or "merged"
).
Param | Type | Default | Description |
---|---|---|---|
[params] | Object |
Optional parameters. | |
[params.horizon] | String | Server |
"https://horizon.stellar.org" |
The Horizon server where to check for account existence. It can be either an URL or a StellarSdk.Server object. |
[params.attempts] | Number |
3 |
The number of empty accounts before scanning stops. |
[params.includeMerged] | Boolean |
false |
List merged accounts as well. |
Request multiple public keys from the Ledger device. The request will return length accounts, starting by start (minimum 1).
Returns an Array of Objects with properties account
, publicKey
, and
path
.
Param | Type | Default | Description |
---|---|---|---|
[start] | Number |
1 |
Starting account number |
[length] | Number |
1 |
Number of account to be listed. |
Function to execute on each connection.
Function to execute on each disconnection.
Public key of the connected account.
Derivation path of the connected account (default: m/44'/148'/0'
).
Version of the Stellar application installed on the connected device.
Whether or not the user accepts to sign transactions without checking them on the device first. This allows to sign long transactions (10+ ops) that could normally not be handled by the device memory, but this is insecure.
The Ledger Transport instance. (internal component)
The Ledger Stellar application instance. (internal component)
Organization: Cosmic.plus | @GitHub | @NPM