diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/lib/trezorKeyring.js | 16 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 7 |
2 files changed, 15 insertions, 8 deletions
diff --git a/app/scripts/lib/trezorKeyring.js b/app/scripts/lib/trezorKeyring.js index d99f384f2..83787f3d2 100644 --- a/app/scripts/lib/trezorKeyring.js +++ b/app/scripts/lib/trezorKeyring.js @@ -1,10 +1,9 @@ const { EventEmitter } = require('events') const ethUtil = require('ethereumjs-util') // const sigUtil = require('eth-sig-util') -//const { Lock } = require('semaphore-async-await') const hdPathString = `m/44'/60'/0'/0` -const keyringType = 'Trezor Hardware Keyring' +const keyringType = 'Trezor Hardware' const TrezorConnect = require('./trezor-connect.js') const HDKey = require('hdkey') @@ -15,7 +14,6 @@ class TrezorKeyring extends EventEmitter { constructor (opts = {}) { super() this.type = keyringType - //this.lock = new Lock() this.accounts = [] this.hdk = new HDKey() this.deserialize(opts) @@ -24,16 +22,22 @@ class TrezorKeyring extends EventEmitter { } serialize () { - return Promise.resolve({ hdPath: this.hdPath, accounts: this.accounts }) + return Promise.resolve({ + hdPath: this.hdPath, + accounts: this.accounts, + page: this.page, + }) } deserialize (opts = {}) { this.hdPath = opts.hdPath || hdPathString this.accounts = opts.accounts || [] + this.page = opts.page || 0 return Promise.resolve() } unlock () { + if (this.hdk.publicKey) return Promise.resolve() return new Promise((resolve, reject) => { @@ -56,6 +60,7 @@ class TrezorKeyring extends EventEmitter { } addAccounts (n = 1) { + return new Promise((resolve, reject) => { return this.unlock() .then(_ => { @@ -82,6 +87,7 @@ class TrezorKeyring extends EventEmitter { } async getPage () { + return new Promise((resolve, reject) => { return this.unlock() .then(_ => { @@ -252,4 +258,4 @@ class TrezorKeyring extends EventEmitter { } TrezorKeyring.type = keyringType -module.exports = TrezorKeyring
\ No newline at end of file +module.exports = TrezorKeyring diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index dd5a5616f..081c2e2db 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -48,7 +48,7 @@ const seedPhraseVerifier = require('./lib/seed-phrase-verifier') const cleanErrorStack = require('./lib/cleanErrorStack') const DiagnosticsReporter = require('./lib/diagnostics-reporter') const log = require('loglevel') -const TrezorKeyring = require("./lib/trezorKeyring"); +const TrezorKeyring = require('./lib/trezorKeyring') module.exports = class MetamaskController extends EventEmitter { @@ -540,9 +540,10 @@ module.exports = class MetamaskController extends EventEmitter { * @returns [] accounts */ async connectHardware (deviceName, page) { + const keyringController = this.keyringController const keyring = await keyringController.getKeyringsByType( - 'Trezor Hardware Keyring' + 'Trezor Hardware' )[0] if (!keyring) { throw new Error('MetamaskController - No Trezor Hardware Keyring found') @@ -562,7 +563,7 @@ module.exports = class MetamaskController extends EventEmitter { async unlockTrezorAccount (index) { const keyringController = this.keyringController const keyring = await keyringController.getKeyringsByType( - 'Trezor Hardware Keyring' + 'Trezor Hardware' )[0] if (!keyring) { throw new Error('MetamaskController - No Trezor Hardware Keyring found') |