1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
This commit is contained in:
Bruno 2018-06-10 18:48:42 -04:00
parent 8c4d58aa45
commit f5f66f59d7
2 changed files with 15 additions and 8 deletions

View File

@ -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
module.exports = TrezorKeyring

View File

@ -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')