This repository was archived by the owner on Oct 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,18 @@ Instance methods:
87
87
* ` deriveChild(index) ` - derive a node based on a child index
88
88
* ` getWallet() ` - return a ` Wallet ` instance as seen above
89
89
90
+ ## Provider Engine
91
+
92
+ The Wallet can be easily plugged into [ provider-engine] ( https://github.com/metamask/provider-engine ) to provide signing:
93
+
94
+ ``` js
95
+ const WalletSubprovider = require (' ethereumjs-wallet/provider-engine' )
96
+
97
+ < engine> .addProvider (new WalletSubprovider (< wallet instance> ))
98
+ ```
99
+
100
+ Note it only supports the basic wallet. With a HD Wallet, call ` getWallet() ` first.
101
+
90
102
### Remarks about ` toV3 `
91
103
92
104
The ` options ` is an optional object hash, where all the serialization parameters can be fine tuned:
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const inherits = require ( 'util' ) . inherits
4
+ const HookedWalletEthTxSubprovider = require ( 'web3-provider-engine/subproviders/hooked-wallet-ethtx' )
5
+
6
+ module . exports = WalletSubprovider
7
+
8
+ inherits ( WalletSubprovider , HookedWalletEthTxSubprovider )
9
+
10
+ function WalletSubprovider ( wallet , opts ) {
11
+ opts . getAccounts = function ( cb ) {
12
+ cb ( null , [ wallet . getAddressesString ( ) ] )
13
+ }
14
+
15
+ opts . getPrivateKey = function ( address , cb ) {
16
+ if ( address !== wallet . getAddressString ( ) ) {
17
+ return cb ( 'Account not found' )
18
+ }
19
+
20
+ cb ( null , wallet . getPrivateKey ( ) )
21
+ }
22
+
23
+ WalletSubprovider . super_ . call ( this , opts )
24
+ }
You can’t perform that action at this time.
0 commit comments