forked from Piterden/truffle-ledger-provider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (27 loc) · 1.04 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
const Web3 = require('web3')
const TransportU2F = require('@ledgerhq/hw-transport-node-hid').default
const ProviderEngine = require('web3-provider-engine')
const ProviderSubprovider = require('web3-provider-engine/subproviders/provider.js')
const FiltersSubprovider = require('web3-provider-engine/subproviders/filters.js')
const createLedgerSubprovider = require('@ledgerhq/web3-subprovider').default
class LedgerProvider {
constructor(options, url) {
const getTransport = () => TransportU2F.create()
const ledger = createLedgerSubprovider(getTransport, options)
this.engine = new ProviderEngine()
this.engine.addProvider(ledger)
this.engine.addProvider(new FiltersSubprovider())
this.engine.addProvider(new ProviderSubprovider(new Web3.providers.HttpProvider(url)))
this.engine.start()
}
sendAsync(...args) {
this.engine.sendAsync.apply(this.engine, ...args)
}
send(...args) {
return this.engine.send.apply(this.engine, ...args)
}
getAddress() {
return this.address
}
}
module.exports = LedgerProvider