aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/keyring-controller.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-02-22 06:25:47 +0800
committerDan Finlay <dan@danfinlay.com>2017-02-22 06:25:47 +0800
commit0584988688a471698e9b3ad05cb0597f0270ea9e (patch)
treebdcbb009636dcdea67abcc28238023dd8bf7e882 /app/scripts/keyring-controller.js
parent29f07238f443007a03c968349af4d3fca7e10522 (diff)
downloadtangerine-wallet-browser-0584988688a471698e9b3ad05cb0597f0270ea9e.tar.gz
tangerine-wallet-browser-0584988688a471698e9b3ad05cb0597f0270ea9e.tar.zst
tangerine-wallet-browser-0584988688a471698e9b3ad05cb0597f0270ea9e.zip
Move sigUtil and keyrings to external modules
These external modules now have their own test coverage and build enforcement. This allowed me to somewhat more easily add good tests around our personalSign strategy (held now in [eth-sig-util](https://github.com/flyswatter/eth-sig-util), and allow each of the keyrings to import that, etc.
Diffstat (limited to 'app/scripts/keyring-controller.js')
-rw-r--r--app/scripts/keyring-controller.js35
1 files changed, 32 insertions, 3 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index b30161003..8c379b5b9 100644
--- a/app/scripts/keyring-controller.js
+++ b/app/scripts/keyring-controller.js
@@ -5,10 +5,10 @@ const EventEmitter = require('events').EventEmitter
const ObservableStore = require('obs-store')
const filter = require('promise-filter')
const encryptor = require('browser-passworder')
-const normalizeAddress = require('./lib/sig-util').normalize
+const normalizeAddress = require('eth-sig-util').normalize
// Keyrings:
-const SimpleKeyring = require('./keyrings/simple')
-const HdKeyring = require('./keyrings/hd')
+const SimpleKeyring = require('eth-simple-keyring')
+const HdKeyring = require('eth-hd-keyring')
const keyringTypes = [
SimpleKeyring,
HdKeyring,
@@ -262,6 +262,35 @@ class KeyringController extends EventEmitter {
})
}
+ // Sign Personal Message
+ // @object msgParams
+ //
+ // returns Promise(@buffer rawSig)
+ //
+ // Attempts to sign the provided @object msgParams.
+ // Prefixes the hash before signing as per the new geth behavior.
+ signPersonalMessage (msgParams) {
+ const address = normalizeAddress(msgParams.from)
+ return this.getKeyringForAccount(address)
+ .then((keyring) => {
+ return keyring.signPersonalMessage(address, msgParams.data)
+ })
+ }
+
+ // Recover Personal Message
+ // @object msgParams
+ //
+ // returns Promise(@buffer signer)
+ //
+ // recovers a signature of the prefixed-style personalMessage signature.
+ recoverPersonalMessage (msgParams) {
+ const address = normalizeAddress(msgParams.from)
+ return this.getKeyringForAccount(address)
+ .then((keyring) => {
+ return keyring.recoverPersonalMessage(address, msgParams.data)
+ })
+ }
+
// PRIVATE METHODS
//
// THESE METHODS ARE ONLY USED INTERNALLY TO THE KEYRING-CONTROLLER