From ced36eb20186b0f1bf0c744ac31a5b7804120065 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 21 Nov 2016 19:40:30 -0800 Subject: Improve Keyring organization Separated public & private methods. (Fixes #845) Made class method `type()` into a simple property. (Fixes #846) --- app/scripts/keyrings/simple.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'app/scripts/keyrings/simple.js') diff --git a/app/scripts/keyrings/simple.js b/app/scripts/keyrings/simple.js index ee743bc03..4fdccc4f7 100644 --- a/app/scripts/keyrings/simple.js +++ b/app/scripts/keyrings/simple.js @@ -4,7 +4,9 @@ const ethUtil = require('ethereumjs-util') const type = 'Simple Key Pair' const sigUtil = require('../lib/sig-util') -module.exports = class SimpleKeyring extends EventEmitter { +class SimpleKeyring extends EventEmitter { + + /* PUBLIC METHODS */ static type () { return type @@ -44,7 +46,7 @@ module.exports = class SimpleKeyring extends EventEmitter { // tx is an instance of the ethereumjs-transaction class. signTransaction (address, tx) { - const wallet = this.getWalletForAccount(address) + const wallet = this._getWalletForAccount(address) var privKey = wallet.getPrivateKey() tx.sign(privKey) return tx @@ -52,7 +54,7 @@ module.exports = class SimpleKeyring extends EventEmitter { // For eth_sign, we need to sign transactions: signMessage (withAccount, data) { - const wallet = this.getWalletForAccount(withAccount) + const wallet = this._getWalletForAccount(withAccount) const message = ethUtil.removeHexPrefix(data) var privKey = wallet.getPrivateKey() var msgSig = ethUtil.ecsign(new Buffer(message, 'hex'), privKey) @@ -60,8 +62,19 @@ module.exports = class SimpleKeyring extends EventEmitter { return rawMsgSig } - getWalletForAccount (account) { + exportAccount (address) { + const wallet = this._getWalletForAccount(address) + return wallet.getPrivateKey().toString('hex') + } + + + /* PRIVATE METHODS */ + + _getWalletForAccount (account) { return this.wallets.find(w => w.getAddress().toString('hex') === account) } } + +SimpleKeyring.type = type +module.exports = SimpleKeyring -- cgit