{"_id":"0x-subproviders","_rev":"5-243b542b3a4faff6a3fb492d194d22f9","name":"0x-subproviders","time":{"modified":"2022-04-04T10:08:52.443Z","created":"2017-11-23T06:22:26.939Z","1.0.0":"2017-11-23T06:22:26.939Z","0.0.1":"2017-11-23T06:25:35.746Z","0.0.2":"2017-11-23T06:37:01.205Z"},"maintainers":[{"name":"dekz","email":"jacob@dekz.net"}],"dist-tags":{"latest":"0.0.2"},"description":"A bunch of useful subproviders, including a Ledger Nano subprovider.","readme":"## 0x subproviders\nA bunch of useful subproviders, including a Ledger Nano subprovider.\n\n## Ledger Subprovider for Web3\n\nUsage example as a [Web3 Provider Engine](https://github.com/MetaMask/provider-engine).\n\n```js\n\nimport {\n    LedgerEthConnection,\n    LedgerWallet,\n    LedgerWalletSubprovider,\n    LedgerBrowserCommunicationFactory,\n    wrapWalletSubproviderFactory\n} from '0x-subproviders';\n\nconst networkId = 42;\nconst provider = new ProviderEngine();\n// Browser (U2F) or Node\nconst conn = new LedgerEthConnection(LedgerBrowserCommunicationFactory);\nconst wallet = new LedgerWallet(conn, networkId);\n\nconst ledgerSubProvider = wrapWalletSubproviderFactory(wallet);\n// Hooks in as a HookedWalletSubProvider\n// This takes over all Signing operations in the web3 stack\nprovider.addProvider(ledgerSubProvider);\n// All other operations need to fall through to an underlying provider\n// in this case infura or another JSON RPC endpoint\nprovider.addProvider(new RpcSubprovider(\n    rpcUrl: publicRpcNode,\n));\nprovider.start();\n```\n\n\nOffset the derivation path\n```js\n// Offset the derivation path\nconst conn = new LedgerEthConnection(LedgerBrowserCommunicationFactory);\nconst wallet = new LedgerWallet(conn, networkId);\nwallet.setPathIndex(3);\n```\n\nUse directly rather than as a Web3 Provider\n```js\n// Offset the derivation path\nconst conn = new LedgerEthConnection(LedgerBrowserCommunicationFactory);\nconst wallet = new LedgerWallet(conn, networkId);\nwallet.getAccountsAsync((err, accounts) => { console.log(accounts) });\nwallet.signPersonalMessageAsync(\"Hi There!\", (err, result) => { console.log(result) });\n```\n\nSet the modified provider in 0x.js \n```\nthis.zeroEx = new ZeroEx(provider);\n```\n\nTest the connection before assuming the ledger is present.\n```js\nprovider = new ProviderEngine();\nconst conn = new LedgerEthConnection(LedgerBrowserCommunicationFactory);\nconst wallet = new LedgerWallet(conn, networkId);\nconst timeout = 500;\nwallet.testConnection(timeout, (err, connected) => {\n    if (_.isUndefined(err) && connected) {\n        utils.debug('provider')('ledger');\n        this.ledgerSubProvider = wrapWalletSubproviderFactory(wallet);\n        provider.addProvider(this.ledgerSubProvider);\n    } else {\n        utils.debug('provider')('injected');\n        provider.addProvider(new InjectedWeb3SubProvider(injectedWeb3));\n    }\n    utils.debug('provider')('filter');\n    provider.addProvider(new FilterSubprovider());\n    utils.debug('provider')(publicNodeUrlsIfExistsForNetworkId);\n    provider.addProvider(new RpcSubprovider(\n        rpcUrl: publicRpcNode,\n    ));\n    provider.start();\n});\n```","versions":{"0.0.2":{"name":"0x-subproviders","version":"0.0.2","main":"lib/src/index.js","types":"lib/src/index.d.ts","license":"Apache-2.0","scripts":{"prebuild":"npm run clean","build":"run-p build:umd:dev build:commonjs; exit 0;","clean":"exit 0","build:umd:dev":"webpack","build:umd:prod":"NODE_ENV=production webpack","build:commonjs":"tsc","test:commonjs":"run-s build:commonjs run_mocha","pretest:umd":"run-s clean build:umd:dev build:commonjs","substitute_umd_bundle":"shx mv _bundles/* lib/src","run_mocha":"mocha lib/test/**/*_test.js --timeout 5000 --bail --exit","test":"run-s clean test:commonjs"},"dependencies":{"@0xproject/assert":"^0.0.4","@0xproject/tslint-config":"^0.1.0","@types/lodash":"^4.14.85","@types/node":"^8.0.53","@types/sinon":"^4.0.0","bn.js":"^4.11.8","debug":"^3.1.0","es6-promisify":"^5.0.0","ethereumjs-tx":"^1.3.3","ethereumjs-util":"^5.1.2","ledgerco":"^1.1.3","lodash":"^4.17.4","semaphore-async-await":"^1.5.1","sinon":"^4.1.2","types-bn":"^0.0.1","types-ethereumjs-util":"^0.0.5","typescript":"^2.6.1","web3":"^0.20.2","web3-provider-engine":"^13.3.3","web3-typescript-typings":"^0.7.2"},"devDependencies":{"@types/mocha":"^2.2.44","awesome-typescript-loader":"^3.4.0","chai":"^4.1.2","chai-as-promised":"^7.1.1","chai-as-promised-typescript-typings":"^0.0.3","chai-typescript-typings":"^0.0.1","dirty-chai":"^2.0.1","mocha":"^4.0.1","npm-run-all":"^4.1.2","webpack":"^3.8.1"},"gitHead":"ccf2fed62137a4f75781e66d769218d55b29e29f","description":"A bunch of useful subproviders, including a Ledger Nano subprovider.","_id":"0x-subproviders@0.0.2","_npmVersion":"5.3.0","_nodeVersion":"8.6.0","_npmUser":{"name":"dekz","email":"jacob@dekz.net"},"dist":{"integrity":"sha512-EvAm4I1kz2UNexxyE+VmEKu9Kzv4E3DWe/LEJ9/zqBYeqCIkzCi7gredcGUbHevMWk+ywmAOe1rfjqLMFwePPQ==","shasum":"eedf5b9585c29b594ed793340fbfc619adf07093","tarball":"https://registry.npmjs.org/0x-subproviders/-/0x-subproviders-0.0.2.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDobfW84c9y3dDNuVhWJC5aWsmWhAFtC+xe5hbEol0kpAIgOlDjEkOG6GIZ3edfMXC5AQ5N3HVul7opb332+fRS3zo="}]},"maintainers":[{"name":"dekz","email":"jacob@dekz.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/0x-subproviders-0.0.2.tgz_1511419021035_0.23186186235398054"}}},"license":"Apache-2.0","readmeFilename":"README.md"}