mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
clean up
This commit is contained in:
parent
8c4d58aa45
commit
f5f66f59d7
@ -1,10 +1,9 @@
|
|||||||
const { EventEmitter } = require('events')
|
const { EventEmitter } = require('events')
|
||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
// const sigUtil = require('eth-sig-util')
|
// const sigUtil = require('eth-sig-util')
|
||||||
//const { Lock } = require('semaphore-async-await')
|
|
||||||
|
|
||||||
const hdPathString = `m/44'/60'/0'/0`
|
const hdPathString = `m/44'/60'/0'/0`
|
||||||
const keyringType = 'Trezor Hardware Keyring'
|
const keyringType = 'Trezor Hardware'
|
||||||
|
|
||||||
const TrezorConnect = require('./trezor-connect.js')
|
const TrezorConnect = require('./trezor-connect.js')
|
||||||
const HDKey = require('hdkey')
|
const HDKey = require('hdkey')
|
||||||
@ -15,7 +14,6 @@ class TrezorKeyring extends EventEmitter {
|
|||||||
constructor (opts = {}) {
|
constructor (opts = {}) {
|
||||||
super()
|
super()
|
||||||
this.type = keyringType
|
this.type = keyringType
|
||||||
//this.lock = new Lock()
|
|
||||||
this.accounts = []
|
this.accounts = []
|
||||||
this.hdk = new HDKey()
|
this.hdk = new HDKey()
|
||||||
this.deserialize(opts)
|
this.deserialize(opts)
|
||||||
@ -24,16 +22,22 @@ class TrezorKeyring extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
serialize () {
|
serialize () {
|
||||||
return Promise.resolve({ hdPath: this.hdPath, accounts: this.accounts })
|
return Promise.resolve({
|
||||||
|
hdPath: this.hdPath,
|
||||||
|
accounts: this.accounts,
|
||||||
|
page: this.page,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
deserialize (opts = {}) {
|
deserialize (opts = {}) {
|
||||||
this.hdPath = opts.hdPath || hdPathString
|
this.hdPath = opts.hdPath || hdPathString
|
||||||
this.accounts = opts.accounts || []
|
this.accounts = opts.accounts || []
|
||||||
|
this.page = opts.page || 0
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
unlock () {
|
unlock () {
|
||||||
|
|
||||||
if (this.hdk.publicKey) return Promise.resolve()
|
if (this.hdk.publicKey) return Promise.resolve()
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -56,6 +60,7 @@ class TrezorKeyring extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addAccounts (n = 1) {
|
addAccounts (n = 1) {
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
return this.unlock()
|
return this.unlock()
|
||||||
.then(_ => {
|
.then(_ => {
|
||||||
@ -82,6 +87,7 @@ class TrezorKeyring extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getPage () {
|
async getPage () {
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
return this.unlock()
|
return this.unlock()
|
||||||
.then(_ => {
|
.then(_ => {
|
||||||
|
@ -48,7 +48,7 @@ const seedPhraseVerifier = require('./lib/seed-phrase-verifier')
|
|||||||
const cleanErrorStack = require('./lib/cleanErrorStack')
|
const cleanErrorStack = require('./lib/cleanErrorStack')
|
||||||
const DiagnosticsReporter = require('./lib/diagnostics-reporter')
|
const DiagnosticsReporter = require('./lib/diagnostics-reporter')
|
||||||
const log = require('loglevel')
|
const log = require('loglevel')
|
||||||
const TrezorKeyring = require("./lib/trezorKeyring");
|
const TrezorKeyring = require('./lib/trezorKeyring')
|
||||||
|
|
||||||
module.exports = class MetamaskController extends EventEmitter {
|
module.exports = class MetamaskController extends EventEmitter {
|
||||||
|
|
||||||
@ -540,9 +540,10 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
* @returns [] accounts
|
* @returns [] accounts
|
||||||
*/
|
*/
|
||||||
async connectHardware (deviceName, page) {
|
async connectHardware (deviceName, page) {
|
||||||
|
|
||||||
const keyringController = this.keyringController
|
const keyringController = this.keyringController
|
||||||
const keyring = await keyringController.getKeyringsByType(
|
const keyring = await keyringController.getKeyringsByType(
|
||||||
'Trezor Hardware Keyring'
|
'Trezor Hardware'
|
||||||
)[0]
|
)[0]
|
||||||
if (!keyring) {
|
if (!keyring) {
|
||||||
throw new Error('MetamaskController - No Trezor Hardware Keyring found')
|
throw new Error('MetamaskController - No Trezor Hardware Keyring found')
|
||||||
@ -562,7 +563,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
async unlockTrezorAccount (index) {
|
async unlockTrezorAccount (index) {
|
||||||
const keyringController = this.keyringController
|
const keyringController = this.keyringController
|
||||||
const keyring = await keyringController.getKeyringsByType(
|
const keyring = await keyringController.getKeyringsByType(
|
||||||
'Trezor Hardware Keyring'
|
'Trezor Hardware'
|
||||||
)[0]
|
)[0]
|
||||||
if (!keyring) {
|
if (!keyring) {
|
||||||
throw new Error('MetamaskController - No Trezor Hardware Keyring found')
|
throw new Error('MetamaskController - No Trezor Hardware Keyring found')
|
||||||
|
Loading…
Reference in New Issue
Block a user