Convert TREZOR to use enclave class like Ledger.
This commit is contained in:
parent
1bdfd568c1
commit
512062114c
|
@ -1,12 +1,13 @@
|
|||
import { makeEnclaveWallet } from './enclave';
|
||||
import { WalletTypes } from 'shared/enclave/client';
|
||||
import { LedgerWallet as LedgerWalletWeb } from './ledger';
|
||||
import { TrezorWallet as TrezorWalletWeb } from './trezor';
|
||||
|
||||
function enclaveOrWallet<T>(type: WalletTypes, lib: T) {
|
||||
return process.env.BUILD_ELECTRON ? makeEnclaveWallet(type) : lib;
|
||||
}
|
||||
|
||||
export * from './mnemonic';
|
||||
export * from './trezor';
|
||||
export * from './hardware';
|
||||
export const LedgerWallet = enclaveOrWallet(WalletTypes.LEDGER, LedgerWalletWeb);
|
||||
export const TrezorWallet = enclaveOrWallet(WalletTypes.TREZOR, TrezorWalletWeb);
|
||||
|
|
|
@ -7,19 +7,11 @@ import { HardwareWallet, ChainCodeResponse } from './hardware';
|
|||
import { getTransactionFields } from 'libs/transaction';
|
||||
import mapValues from 'lodash/mapValues';
|
||||
import { translateRaw } from 'translations';
|
||||
import EnclaveAPI, { WalletTypes } from 'shared/enclave/client';
|
||||
|
||||
export const TREZOR_MINIMUM_FIRMWARE = '1.5.2';
|
||||
|
||||
export class TrezorWallet extends HardwareWallet {
|
||||
public static getChainCode(dpath: string): Promise<ChainCodeResponse> {
|
||||
if (process.env.BUILD_ELECTRON) {
|
||||
return EnclaveAPI.getChainCode({
|
||||
walletType: WalletTypes.TREZOR,
|
||||
dpath
|
||||
});
|
||||
}
|
||||
|
||||
return new Promise(resolve => {
|
||||
TrezorConnect.getXPubKey(
|
||||
dpath,
|
||||
|
@ -40,24 +32,8 @@ export class TrezorWallet extends HardwareWallet {
|
|||
|
||||
public signRawTransaction(tx: EthTx): Promise<Buffer> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const txFields = getTransactionFields(tx);
|
||||
|
||||
if (process.env.BUILD_ELECTRON) {
|
||||
return EnclaveAPI.signTransaction({
|
||||
walletType: WalletTypes.TREZOR,
|
||||
transaction: txFields,
|
||||
path: this.getPath()
|
||||
})
|
||||
.then(res => {
|
||||
resolve(new EthTx(res.signedTransaction).serialize());
|
||||
})
|
||||
.catch(err => {
|
||||
reject(Error(err));
|
||||
});
|
||||
}
|
||||
|
||||
const { chainId, ...strTx } = getTransactionFields(tx);
|
||||
// stripHexPrefixAndLower identical to ethFuncs.getNakedAddress
|
||||
const { chainId, ...strTx } = txFields;
|
||||
const cleanedTx = mapValues(mapValues(strTx, stripHexPrefixAndLower), padLeftEven);
|
||||
|
||||
TrezorConnect.ethereumSignTx(
|
||||
|
@ -96,21 +72,10 @@ export class TrezorWallet extends HardwareWallet {
|
|||
return Promise.reject(new Error('Signing via Trezor not yet supported.'));
|
||||
}
|
||||
|
||||
public displayAddress(): Promise<any> {
|
||||
const path = this.dPath + '/' + this.index;
|
||||
|
||||
if (process.env.BUILD_ELECTRON) {
|
||||
return EnclaveAPI.displayAddress({
|
||||
walletType: WalletTypes.TREZOR,
|
||||
path
|
||||
})
|
||||
.then(res => res.success)
|
||||
.catch(() => false);
|
||||
}
|
||||
|
||||
public displayAddress(): Promise<boolean> {
|
||||
return new Promise(resolve => {
|
||||
TrezorConnect.ethereumGetAddress(
|
||||
this.dPath + '/' + this.index,
|
||||
`${this.dPath}/${this.index}`,
|
||||
res => {
|
||||
if (res.error) {
|
||||
resolve(false);
|
||||
|
|
|
@ -91,7 +91,6 @@
|
|||
"@types/webpack-env": "1.13.4",
|
||||
"@types/zxcvbn": "4.4.0",
|
||||
"autodll-webpack-plugin": "0.3.9",
|
||||
"bchaddrjs": "0.2.1",
|
||||
"check-node-version": "3.2.0",
|
||||
"concurrently": "3.5.1",
|
||||
"copy-webpack-plugin": "4.5.1",
|
||||
|
|
|
@ -5,7 +5,7 @@ import { addHexPrefix } from 'ethereumjs-util';
|
|||
import EthTx from 'ethereumjs-tx';
|
||||
import { stripHexPrefixAndLower, padLeftEven } from 'libs/values';
|
||||
import { WalletLib } from 'shared/enclave/types';
|
||||
const deviceList = new DeviceList();
|
||||
const deviceList = new DeviceList({ debug: false });
|
||||
|
||||
// Keep session in memory so that we're not constantly re-acquiring
|
||||
// Null it out if session is grabbed somewhere else first
|
||||
|
|
Loading…
Reference in New Issue