2.8.0 • Published 3 years ago

@cosmic-plus/ledger-wallet v2.8.0

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

ledger-wallet / ReadmeExamplesContributingChangelog

Readme

Licence Dependencies Vulnerabilities Bundle Downloads

Easy Ledger Wallet support for Stellar applications and command line.

(Weekly updates: Reddit, Twitter, Keybase, Telegram)

Introduction

This library is a convenient wrapper around the official Ledger libraries for Stellar:

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.

Installation

NPM/Yarn

  • 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

bower install cosmic-plus-ledger-wallet

In your HTML page:

<script src="./bower_components/cosmic-plus-ledger-wallet/ledger-wallet.js"></script>

CDN

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.

Usage

Functions

await ledgerWallet.connect(account)

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').

ParamTypeDefaultDescription
accountNumber | String1Either an account number (starts at 1) or a derivation path (e.g: m/44'/148'/0').

await ledgerWallet.sign(transaction)

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.

ParamTypeDescription
transactionTransactionA StellarSdk Transaction

await ledgerWallet.disconnect()

Close the connection with the Ledger device, or stop waiting for one in case a connection has not been established yet.

ledgerWallet.newAccount(horizon)

Connects the first unused account.

Note: merged accounts are considered as used.

ParamTypeDefaultDescription
horizonString | Server&quot;https://horizon.stellar.org&quot;The Horizon server where to check for account existence. It can be either an URL or a StellarSdk.Server object.

ledgerWallet.scan(params) ⇒ Array

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").

ParamTypeDefaultDescription
paramsObjectOptional parameters.
params.horizonString | Server&quot;https://horizon.stellar.org&quot;The Horizon server where to check for account existence. It can be either an URL or a StellarSdk.Server object.
params.attemptsNumber3The number of empty accounts before scanning stops.
params.includeMergedBooleanfalseList merged accounts as well.

ledgerWallet.getPublicKeys(start, length) ⇒ Array

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.

ParamTypeDefaultDescription
startNumber1Starting account number
lengthNumber1Number of account to be listed.

Events

ledgerWallet.onConnect : function

Function to execute on each connection.

ledgerWallet.onDisconnect : function

Function to execute on each disconnection.

Members

ledgerWallet.publicKey : String

Public key of the connected account.

ledgerWallet.path : String

Derivation path of the connected account (default: m/44'/148'/0').

ledgerWallet.version : String

Version of the Stellar application installed on the connected device.

ledgerWallet.multiOpsEnabled : Boolean

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.

ledgerWallet.transport : Transport

The Ledger Transport instance. (internal component)

ledgerWallet.application : StellarApp

The Ledger Stellar application instance. (internal component)

Links

Organization: Cosmic.plus | @GitHub | @NPM

Follow: Reddit | Twitter | Medium | Codepen

Talk: Telegram | Keybase

2.8.0

3 years ago

2.7.0

4 years ago

2.6.0

4 years ago

2.5.0

4 years ago

2.4.0

4 years ago

2.3.0

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.20

6 years ago

0.2.19

6 years ago

0.2.18

6 years ago

0.2.17

6 years ago

0.2.16

6 years ago

0.2.15

6 years ago

0.2.14

6 years ago

0.2.13

6 years ago

0.2.12

6 years ago

0.2.11

6 years ago

0.2.10

6 years ago

0.2.9

6 years ago

0.2.8

6 years ago

0.2.7

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago