forked from MetaMask/web3-provider-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zero.js
81 lines (65 loc) · 2.57 KB
/
zero.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const ProviderEngine = require('./index.js')
const DefaultFixture = require('./subproviders/default-fixture.js')
const NonceTrackerSubprovider = require('./subproviders/nonce-tracker.js')
const CacheSubprovider = require('./subproviders/cache.js')
const FilterSubprovider = require('./subproviders/filters.js')
const InflightCacheSubprovider = require('./subproviders/inflight-cache')
const HookedWalletSubprovider = require('./subproviders/hooked-wallet.js')
const SanitizingSubprovider = require('./subproviders/sanitizer.js')
const RpcSubprovider = require('./subproviders/rpc.js')
const FetchSubprovider = require('./subproviders/fetch.js')
module.exports = ZeroClientProvider
function ZeroClientProvider(opts){
opts = opts || {}
const engine = new ProviderEngine(opts.engineParams)
// static
const staticSubprovider = new DefaultFixture(opts.static)
engine.addProvider(staticSubprovider)
// nonce tracker
engine.addProvider(new NonceTrackerSubprovider())
// sanitization
const sanitizer = new SanitizingSubprovider()
engine.addProvider(sanitizer)
// cache layer
const cacheSubprovider = new CacheSubprovider()
engine.addProvider(cacheSubprovider)
// filters
const filterSubprovider = new FilterSubprovider()
engine.addProvider(filterSubprovider)
// inflight cache
const inflightCache = new InflightCacheSubprovider()
engine.addProvider(inflightCache)
// id mgmt
const idmgmtSubprovider = new HookedWalletSubprovider({
// accounts
getAccounts: opts.getAccounts,
// transactions
processTransaction: opts.processTransaction,
approveTransaction: opts.approveTransaction,
signTransaction: opts.signTransaction,
publishTransaction: opts.publishTransaction,
// messages
// old eth_sign
processMessage: opts.processMessage,
approveMessage: opts.approveMessage,
signMessage: opts.signMessage,
// new personal_sign
processPersonalMessage: opts.processPersonalMessage,
processTypedMessage: opts.processTypedMessage,
approvePersonalMessage: opts.approvePersonalMessage,
approveTypedMessage: opts.approveTypedMessage,
signPersonalMessage: opts.signPersonalMessage,
signTypedMessage: opts.signTypedMessage,
personalRecoverSigner: opts.personalRecoverSigner,
})
engine.addProvider(idmgmtSubprovider)
// data source
const dataSubprovider = opts.dataSubprovider || new FetchSubprovider({
rpcUrl: opts.rpcUrl || 'https://mainnet.infura.io/',
originHttpHeaderKey: opts.originHttpHeaderKey,
})
engine.addProvider(dataSubprovider)
// start polling
engine.start()
return engine
}