Merge pull request #7 from ethereumjs/feature/provider-engine
Add provider-engine integration
This commit is contained in:
commit
08d2bfe3ed
12
README.md
12
README.md
|
@ -87,6 +87,18 @@ Instance methods:
|
||||||
* `deriveChild(index)` - derive a node based on a child index
|
* `deriveChild(index)` - derive a node based on a child index
|
||||||
* `getWallet()` - return a `Wallet` instance as seen above
|
* `getWallet()` - return a `Wallet` instance as seen above
|
||||||
|
|
||||||
|
## Provider Engine
|
||||||
|
|
||||||
|
The Wallet can be easily plugged into [provider-engine](https://github.com/metamask/provider-engine) to provide signing:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const WalletSubprovider = require('ethereumjs-wallet/provider-engine')
|
||||||
|
|
||||||
|
<engine>.addProvider(new WalletSubprovider(<wallet instance>))
|
||||||
|
```
|
||||||
|
|
||||||
|
Note it only supports the basic wallet. With a HD Wallet, call `getWallet()` first.
|
||||||
|
|
||||||
### Remarks about `toV3`
|
### Remarks about `toV3`
|
||||||
|
|
||||||
The `options` is an optional object hash, where all the serialization parameters can be fine tuned:
|
The `options` is an optional object hash, where all the serialization parameters can be fine tuned:
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const inherits = require('util').inherits
|
||||||
|
const HookedWalletEthTxSubprovider = require('web3-provider-engine/subproviders/hooked-wallet-ethtx')
|
||||||
|
|
||||||
|
module.exports = WalletSubprovider
|
||||||
|
|
||||||
|
inherits(WalletSubprovider, HookedWalletEthTxSubprovider)
|
||||||
|
|
||||||
|
function WalletSubprovider (wallet, opts) {
|
||||||
|
opts.getAccounts = function (cb) {
|
||||||
|
cb(null, [ wallet.getAddressesString() ])
|
||||||
|
}
|
||||||
|
|
||||||
|
opts.getPrivateKey = function (address, cb) {
|
||||||
|
if (address !== wallet.getAddressString()) {
|
||||||
|
return cb('Account not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
cb(null, wallet.getPrivateKey())
|
||||||
|
}
|
||||||
|
|
||||||
|
WalletSubprovider.super_.call(this, opts)
|
||||||
|
}
|
Loading…
Reference in New Issue