diff --git a/provider-engine.js b/provider-engine.js new file mode 100644 index 0000000..974a8b6 --- /dev/null +++ b/provider-engine.js @@ -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) +}