Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Plugin for using Ledger with dai.js in a browser environment.

License

Notifications You must be signed in to change notification settings

makerdao/dai-plugin-ledger-web

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dai-plugin-ledger-web

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

Example usage

import LedgerPlugin from '@makerdao/dai-plugin-ledger-web';
import Maker from '@makerdao/dai';

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

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

// or you can defer setting the account up until later
await maker.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 maker.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

About

Plugin for using Ledger with dai.js in a browser environment.

Resources

License

Stars

Watchers

Forks

Packages

No packages published