0.1.2 • Published 2 years ago

@amra-finance/ding-plugin-ledger-web v0.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

ding-plugin-ledger-web

A Ding.js plugin for using Ledger in a browser environment.

Example usage

import LedgerPlugin from '@amra-finance/ding-plugin-ledger-web';
import Amra from '@amra-finance/ding';

const amra = await Amra.create('http', {
  plugins: [LedgerPlugin],
  accounts: {
    myLedger1: { type: 'ledger' }
  }
});

// this will not resolve until the Ledger account is set up
await amra.authenticate();

// or you can defer setting the account up until later
await amra.addAccount('myLedger2', { type: 'ledger' });

Options

  • accountsLength: Set this to the number of accounts to fetch. Must also set choose if greater than 1; see below. (Default: 1)
  • accountsOffset: Set this to the index offset number to fetch accounts from (Default: 0)
  • path: Set this to the derivation path to use. (Default: "44'/60'/0'/0/0")
  • legacy: Set this to use the old Ledger address derivation method. More info

Listing multiple accounts

await amra.addAccount('myLedger', {
  type: 'ledger',
  accountsLength: 10,
  choose: (addresses, callback) => {
    // show the list of addresses in your UI and have the user pick one; then
    // call the callback with the chosen address. `addAccount` will not resolve
    // until the callback is called. if you pass an error object as the first
    // argument, `addAccount` will throw it.
    setTimeout(() => callback(null, addresses[7]), 20000);
  }
});

Try the demo app

You can find an example of this plugin being used in an app here.

Publishing to NPM

yarn
// version bump on package.json
yarn build
cd /dist
npm publish