mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
add account working
This commit is contained in:
parent
f5f66f59d7
commit
f6b27fa9eb
@ -8,7 +8,7 @@ const keyringType = 'Trezor Hardware'
|
|||||||
const TrezorConnect = require('./trezor-connect.js')
|
const TrezorConnect = require('./trezor-connect.js')
|
||||||
const HDKey = require('hdkey')
|
const HDKey = require('hdkey')
|
||||||
const TREZOR_FIRMWARE_VERSION = '1.4.0'
|
const TREZOR_FIRMWARE_VERSION = '1.4.0'
|
||||||
const log = require('loglevel')
|
//const log = require('loglevel')
|
||||||
|
|
||||||
class TrezorKeyring extends EventEmitter {
|
class TrezorKeyring extends EventEmitter {
|
||||||
constructor (opts = {}) {
|
constructor (opts = {}) {
|
||||||
@ -19,10 +19,11 @@ class TrezorKeyring extends EventEmitter {
|
|||||||
this.deserialize(opts)
|
this.deserialize(opts)
|
||||||
this.page = 0
|
this.page = 0
|
||||||
this.perPage = 5
|
this.perPage = 5
|
||||||
|
this.accountToUnlock = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
serialize () {
|
serialize () {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
hdPath: this.hdPath,
|
hdPath: this.hdPath,
|
||||||
accounts: this.accounts,
|
accounts: this.accounts,
|
||||||
page: this.page,
|
page: this.page,
|
||||||
@ -44,8 +45,6 @@ class TrezorKeyring extends EventEmitter {
|
|||||||
TrezorConnect.getXPubKey(
|
TrezorConnect.getXPubKey(
|
||||||
this.hdPath,
|
this.hdPath,
|
||||||
response => {
|
response => {
|
||||||
log.debug('TREZOR CONNECT RESPONSE: ')
|
|
||||||
log.debug(response)
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
this.hdk.publicKey = new Buffer(response.publicKey, 'hex')
|
this.hdk.publicKey = new Buffer(response.publicKey, 'hex')
|
||||||
this.hdk.chainCode = new Buffer(response.chainCode, 'hex')
|
this.hdk.chainCode = new Buffer(response.chainCode, 'hex')
|
||||||
@ -59,14 +58,18 @@ class TrezorKeyring extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setAccountToUnlock (index) {
|
||||||
|
this.accountToUnlock = parseInt(index, 10)
|
||||||
|
}
|
||||||
|
|
||||||
addAccounts (n = 1) {
|
addAccounts (n = 1) {
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
return this.unlock()
|
return this.unlock()
|
||||||
.then(_ => {
|
.then(_ => {
|
||||||
const pathBase = 'm'
|
const pathBase = 'm'
|
||||||
const from = n
|
const from = this.accountToUnlock
|
||||||
const to = n + 1
|
const to = from + 1
|
||||||
|
|
||||||
this.accounts = []
|
this.accounts = []
|
||||||
|
|
||||||
@ -133,7 +136,7 @@ class TrezorKeyring extends EventEmitter {
|
|||||||
// tx is an instance of the ethereumjs-transaction class.
|
// tx is an instance of the ethereumjs-transaction class.
|
||||||
async signTransaction (address, tx) {
|
async signTransaction (address, tx) {
|
||||||
throw new Error('Not supported on this device')
|
throw new Error('Not supported on this device')
|
||||||
/*
|
/*
|
||||||
await this.lock.acquire()
|
await this.lock.acquire()
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -200,7 +203,7 @@ class TrezorKeyring extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return signature
|
return signature
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
await this.lock.release()
|
await this.lock.release()
|
||||||
} */
|
} */
|
||||||
|
@ -569,6 +569,8 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
throw new Error('MetamaskController - No Trezor Hardware Keyring found')
|
throw new Error('MetamaskController - No Trezor Hardware Keyring found')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keyring.setAccountToUnlock(index)
|
||||||
|
|
||||||
const oldAccounts = await keyringController.getAccounts()
|
const oldAccounts = await keyringController.getAccounts()
|
||||||
const keyState = await keyringController.addNewAccount(keyring)
|
const keyState = await keyringController.addNewAccount(keyring)
|
||||||
const newAccounts = await keyringController.getAccounts()
|
const newAccounts = await keyringController.getAccounts()
|
||||||
|
Loading…
Reference in New Issue
Block a user