# 0x-subproviders

> A bunch of useful subproviders, including a Ledger Nano subprovider.

Latest version **0.0.2** (published 2017-11-23) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install 0x-subproviders
pnpm add 0x-subproviders
yarn add 0x-subproviders
bun add 0x-subproviders
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2017-11-23 |
| First published | 2017-11-23 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 20 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | dekz |

## Links

- npm: https://www.npmjs.com/package/0x-subproviders
- npm.io page: https://npm.io/package/0x-subproviders

## Dependencies (20)

- [web3](https://npm.io/package/web3.md) ^0.20.2
- [bn.js](https://npm.io/package/bn.js.md) ^4.11.8
- [debug](https://npm.io/package/debug.md) ^3.1.0
- [sinon](https://npm.io/package/sinon.md) ^4.1.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [ledgerco](https://npm.io/package/ledgerco.md) ^1.1.3
- [types-bn](https://npm.io/package/types-bn.md) ^0.0.1
- [typescript](https://npm.io/package/typescript.md) ^2.6.1
- [@types/node](https://npm.io/package/@types/node.md) ^8.0.53
- [@types/sinon](https://npm.io/package/@types/sinon.md) ^4.0.0
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.85
- [es6-promisify](https://npm.io/package/es6-promisify.md) ^5.0.0
- [ethereumjs-tx](https://npm.io/package/ethereumjs-tx.md) ^1.3.3
- [ethereumjs-util](https://npm.io/package/ethereumjs-util.md) ^5.1.2
- [@0xproject/assert](https://npm.io/package/@0xproject/assert.md) ^0.0.4
- [web3-provider-engine](https://npm.io/package/web3-provider-engine.md) ^13.3.3
- [semaphore-async-await](https://npm.io/package/semaphore-async-await.md) ^1.5.1
- [types-ethereumjs-util](https://npm.io/package/types-ethereumjs-util.md) ^0.0.5
- [web3-typescript-typings](https://npm.io/package/web3-typescript-typings.md) ^0.7.2
- [@0xproject/tslint-config](https://npm.io/package/@0xproject/tslint-config.md) ^0.1.0

## Recent versions

- 0.0.2 (latest) — 2017-11-23

## README

## 0x subproviders
A bunch of useful subproviders, including a Ledger Nano subprovider.

## Ledger Subprovider for Web3

Usage example as a [Web3 Provider Engine](https://github.com/MetaMask/provider-engine).

```js

import {
    LedgerEthConnection,
    LedgerWallet,
    LedgerWalletSubprovider,
    LedgerBrowserCommunicationFactory,
    wrapWalletSubproviderFactory
} from '0x-subproviders';

const networkId = 42;
const provider = new ProviderEngine();
// Browser (U2F) or Node
const conn = new LedgerEthConnection(LedgerBrowserCommunicationFactory);
const wallet = new LedgerWallet(conn, networkId);

const ledgerSubProvider = wrapWalletSubproviderFactory(wallet);
// Hooks in as a HookedWalletSubProvider
// This takes over all Signing operations in the web3 stack
provider.addProvider(ledgerSubProvider);
// All other operations need to fall through to an underlying provider
// in this case infura or another JSON RPC endpoint
provider.addProvider(new RpcSubprovider(
    rpcUrl: publicRpcNode,
));
provider.start();
```


Offset the derivation path
```js
// Offset the derivation path
const conn = new LedgerEthConnection(LedgerBrowserCommunicationFactory);
const wallet = new LedgerWallet(conn, networkId);
wallet.setPathIndex(3);
```

Use directly rather than as a Web3 Provider
```js
// Offset the derivation path
const conn = new LedgerEthConnection(LedgerBrowserCommunicationFactory);
const wallet = new LedgerWallet(conn, networkId);
wallet.getAccountsAsync((err, accounts) => { console.log(accounts) });
wallet.signPersonalMessageAsync("Hi There!", (err, result) => { console.log(result) });
```

Set the modified provider in 0x.js 
```
this.zeroEx = new ZeroEx(provider);
```

Test the connection before assuming the ledger is present.
```js
provider = new ProviderEngine();
const conn = new LedgerEthConnection(LedgerBrowserCommunicationFactory);
const wallet = new LedgerWallet(conn, networkId);
const timeout = 500;
wallet.testConnection(timeout, (err, connected) => {
    if (_.isUndefined(err) && connected) {
        utils.debug('provider')('ledger');
        this.ledgerSubProvider = wrapWalletSubproviderFactory(wallet);
        provider.addProvider(this.ledgerSubProvider);
    } else {
        utils.debug('provider')('injected');
        provider.addProvider(new InjectedWeb3SubProvider(injectedWeb3));
    }
    utils.debug('provider')('filter');
    provider.addProvider(new FilterSubprovider());
    utils.debug('provider')(publicNodeUrlsIfExistsForNetworkId);
    provider.addProvider(new RpcSubprovider(
        rpcUrl: publicRpcNode,
    ));
    provider.start();
});
```

---
_Source: https://npm.io/package/0x-subproviders · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
