From b27e211760fdb67861507abac6d6624545641362 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 25 Mar 2016 00:18:01 +0000 Subject: [PATCH 1/2] Add provider-engine provider supporting signing --- provider-engine.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 provider-engine.js 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) +} From f0b0c8f0fe3808824722fc0c8fb4396a2cc7d38c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 25 Mar 2016 01:09:57 +0000 Subject: [PATCH 2/2] Describe provider-engine in the README --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 4700c9a..aef4431 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,18 @@ Instance methods: * `deriveChild(index)` - derive a node based on a child index * `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') + +.addProvider(new WalletSubprovider()) +``` + +Note it only supports the basic wallet. With a HD Wallet, call `getWallet()` first. + ### Remarks about `toV3` The `options` is an optional object hash, where all the serialization parameters can be fine tuned: