-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
36 lines (33 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const TransportNodeHid = require("@ledgerhq/hw-transport-node-hid").default;
const FetchSubprovider = require("web3-provider-engine/subproviders/fetch");
const ProviderEngine = require("web3-provider-engine");
const createLedgerSubprovider = require("@ledgerhq/web3-subprovider").default;
const defaultOptions = {
networkId: 1,
paths: ["44'/60'/0'/0/0"],
accountsLength: 1,
askConfirm: true,
};
function LedgerWalletProvider(
rpcUrl = "http://127.0.0.1:8545",
options = defaultOptions
) {
const getTransport = async () => {
return TransportNodeHid.create(5000).then((transport) => {
return transport;
});
};
const ledger = createLedgerSubprovider(getTransport, options);
this.engine = new ProviderEngine();
this.engine.addProvider(ledger);
this.engine.addProvider(new FetchSubprovider({ rpcUrl }));
this.engine.start();
return this.engine;
}
LedgerWalletProvider.prototype.sendAsync = function() {
this.engine.sendAsync.apply(this.engine, arguments);
};
LedgerWalletProvider.prototype.send = function() {
return this.engine.send.apply(this.engine, arguments);
};
module.exports = LedgerWalletProvider;