aboutsummaryrefslogtreecommitdiffstats
path: root/packages/migrations/src/utils/provider_factory.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/migrations/src/utils/provider_factory.ts')
-rw-r--r--packages/migrations/src/utils/provider_factory.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/packages/migrations/src/utils/provider_factory.ts b/packages/migrations/src/utils/provider_factory.ts
new file mode 100644
index 000000000..7a217b1e0
--- /dev/null
+++ b/packages/migrations/src/utils/provider_factory.ts
@@ -0,0 +1,33 @@
+import { LedgerEthereumClient, LedgerSubprovider } from '@0xproject/subproviders';
+import Eth from '@ledgerhq/hw-app-eth';
+// tslint:disable:no-implicit-dependencies
+import TransportNodeHid from '@ledgerhq/hw-transport-node-hid';
+import { Provider } from 'ethereum-types';
+import ProviderEngine = require('web3-provider-engine');
+import RpcSubprovider = require('web3-provider-engine/subproviders/rpc');
+
+import { constants } from './constants';
+
+async function ledgerEthereumNodeJsClientFactoryAsync(): Promise<LedgerEthereumClient> {
+ const ledgerConnection = await TransportNodeHid.create();
+ const ledgerEthClient = new Eth(ledgerConnection);
+ return ledgerEthClient;
+}
+export const providerFactory = {
+ async getLedgerProviderAsync(): Promise<Provider> {
+ const provider = new ProviderEngine();
+ const ledgerWalletConfigs = {
+ networkId: constants.KOVAN_NETWORK_ID,
+ ledgerEthereumClientFactoryAsync: ledgerEthereumNodeJsClientFactoryAsync,
+ };
+ const ledgerSubprovider = new LedgerSubprovider(ledgerWalletConfigs);
+ provider.addProvider(ledgerSubprovider);
+ provider.addProvider(
+ new RpcSubprovider({
+ rpcUrl: constants.RPC_URL,
+ }),
+ );
+ provider.start();
+ return provider;
+ },
+};