Skip to content

Commit 8a60d1a

Browse files
authored
Merge branch 'develop' into linting-2
2 parents 361bf8c + d6daf69 commit 8a60d1a

File tree

9 files changed

+167
-165
lines changed

9 files changed

+167
-165
lines changed

main/chains/blocks/index.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ class BlockMonitor extends EventEmitter {
5757

5858
this.latestBlock = '0x0'
5959

60-
this.connection.once('connect', this.start)
61-
this.connection.once('close', this.stop)
60+
this.connection.on('connect', this.start)
61+
this.connection.on('close', this.stop)
6262
}
6363

6464
start() {
65+
log.verbose(`Starting block updates for chain ${parseInt(this.connection.chainId)}`)
66+
6567
this.connection.on('message', this.handleMessage)
6668

6769
// load the latest block first on connect, then start checking for new blocks
@@ -79,9 +81,9 @@ class BlockMonitor extends EventEmitter {
7981
}
8082

8183
stop() {
84+
log.verbose(`Stopping block updates for chain ${parseInt(this.connection.chainId)}`)
85+
8286
this.removeAllListeners()
83-
this.connection.off('connect', this.start)
84-
this.connection.off('close', this.stop)
8587

8688
if (this.subscriptionId) {
8789
this.clearSubscription()
@@ -116,6 +118,10 @@ class BlockMonitor extends EventEmitter {
116118
}
117119

118120
private handleBlock(block: Block) {
121+
log.debug(`Handling block ${parseInt(block.number)} for chain ${parseInt(this.connection.chainId)}`, {
122+
latestBlock: this.latestBlock
123+
})
124+
119125
if (!block) return this.handleError('handleBlock received undefined block')
120126

121127
if (block.number !== this.latestBlock) {

main/chains/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ class ChainConnection extends EventEmitter {
6767

6868
this[priority].provider = provider(target, {
6969
name: priority,
70+
origin: 'frame',
7071
infuraId: '786ade30f36244469480aa5c2bf0743b',
7172
alchemyId: 'NBms1eV9i16RFHpFqQxod56OLdlucIq0'
7273
})
74+
7375
this[priority].blockMonitor = this._createBlockMonitor(this[priority].provider, priority)
7476
}
7577

main/index.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ app.commandLine.appendSwitch('force-color-profile', 'srgb')
3131

3232
const isDev = process.env.NODE_ENV === 'development'
3333
log.transports.console.level = process.env.LOG_LEVEL || (isDev ? 'verbose' : 'info')
34-
log.transports.file.level = ['development', 'test'].includes(process.env.NODE_ENV) ? false : 'verbose'
34+
35+
if (process.env.LOG_LEVEL === 'debug') {
36+
log.transports.file.level = 'debug'
37+
log.transports.file.resolvePath = () => path.join(app.getPath('userData'), 'logs/debug.log')
38+
} else {
39+
log.transports.file.level = ['development', 'test'].includes(process.env.NODE_ENV) ? false : 'verbose'
40+
}
3541

3642
const hasInstanceLock = app.requestSingleInstanceLock()
3743

main/signers/trezor/Trezor/index.ts

+26-19
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import log from 'electron-log'
22
import { hexToInt } from '../../../../resources/utils'
33
import { padToEven, stripHexPrefix, addHexPrefix } from '@ethereumjs/util'
44
import { SignTypedDataVersion, TypedDataUtils } from '@metamask/eth-sig-util'
5-
import type { Device as TrezorDevice } from 'trezor-connect'
5+
import type { Device as TrezorDevice } from '@trezor/connect'
66
import { TypedTransaction } from '@ethereumjs/tx'
77

88
import { v5 as uuid } from 'uuid'
@@ -32,11 +32,11 @@ export const Status = {
3232
ENTERING_PASSPHRASE: 'waiting for input on device'
3333
}
3434

35-
function createErrorMessage(message: string, cause: string = '') {
35+
function createError(message: string, code: string, cause: string = '') {
3636
// the cause may need to be transformed into a more informative message
3737
return cause.toLowerCase().match(/forbidden key path/)
38-
? 'derivation path failed strict safety checks on trezor device'
39-
: message
38+
? new DeviceError('derivation path failed strict safety checks on trezor device', 'SAFETY_CHECKS')
39+
: new DeviceError(message, code)
4040
}
4141

4242
export default class Trezor extends Signer {
@@ -82,10 +82,12 @@ export default class Trezor extends Signer {
8282
// this prompts a login of pin and/or passphrase
8383
await TrezorBridge.getAccountInfo(device, this.getPath(0))
8484
} catch (e) {
85-
const err = e as DeviceError
86-
this.handleError(
87-
new DeviceError(createErrorMessage(Status.NEEDS_RECONNECTION, err.message), 'ACCOUNT_ACCESS_FAILURE')
85+
const deviceError = createError(
86+
Status.NEEDS_RECONNECTION,
87+
'ACCOUNT_ACCESS_FAILURE',
88+
(e as DeviceError).message
8889
)
90+
this.handleError(deviceError)
8991

9092
throw e
9193
}
@@ -130,8 +132,10 @@ export default class Trezor extends Signer {
130132
ADDRESS_NO_MATCH_DEVICE: Status.NEEDS_RECONNECTION,
131133
UNRECOVERABLE: Status.NEEDS_RECONNECTION,
132134
ADDRESS_VERIFICATION_FAILURE: Status.NEEDS_RECONNECTION,
133-
ACCOUNT_ACCESS_FAILURE: Status.NEEDS_RECONNECTION
135+
ACCOUNT_ACCESS_FAILURE: Status.NEEDS_RECONNECTION,
136+
SAFETY_CHECKS: 'derivation path failed strict safety checks on trezor device'
134137
}
138+
135139
const newStatus = errorStatusMap[error.code as keyof typeof errorStatusMap]
136140
if (newStatus) {
137141
this.status = newStatus
@@ -177,12 +181,13 @@ export default class Trezor extends Signer {
177181
const err = e as DeviceError
178182

179183
log.error('error verifying Trezor address', err)
180-
this.handleError(
181-
new DeviceError(
182-
createErrorMessage('could not verify address, reconnect your Trezor', err.message),
183-
'ADDRESS_VERIFICATION_FAILURE'
184-
)
184+
185+
const deviceError = createError(
186+
'could not verify address, reconnect your Trezor',
187+
'ADDRESS_VERIFICATION_FAILURE',
188+
err.message
185189
)
190+
this.handleError(deviceError)
186191

187192
cb(new Error(err.message))
188193
}
@@ -258,28 +263,30 @@ export default class Trezor extends Signer {
258263
if (this.isTrezorOne()) {
259264
// Trezor One requires hashed input
260265
const { types, primaryType, domain, message } = TypedDataUtils.sanitizeData(typedMessage.data)
266+
261267
const domainSeparatorHash = TypedDataUtils.hashStruct(
262268
'EIP712Domain',
263269
domain,
264270
types,
265271
SignTypedDataVersion.V4
266-
).toString('hex')
272+
)
273+
267274
const messageHash = TypedDataUtils.hashStruct(
268275
primaryType as any,
269276
message,
270277
types,
271278
SignTypedDataVersion.V4
272-
).toString('hex')
279+
)
273280

274281
signature = await TrezorBridge.signTypedHash(
275282
this.device,
276283
path,
277-
typedMessage,
278-
domainSeparatorHash,
279-
messageHash
284+
typedMessage.data,
285+
domainSeparatorHash.toString('hex'),
286+
messageHash.toString('hex')
280287
)
281288
} else {
282-
signature = await TrezorBridge.signTypedData(this.device, path, typedMessage)
289+
signature = await TrezorBridge.signTypedData(this.device, path, typedMessage.data)
283290
}
284291

285292
cb(null, addHexPrefix(signature))

main/signers/trezor/adapter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import log from 'electron-log'
22

3-
import type { Device as TrezorDevice } from 'trezor-connect'
3+
import type { Device as TrezorDevice } from '@trezor/connect'
44

55
import { SignerAdapter } from '../adapters'
66
import Trezor, { Status } from './Trezor'

main/signers/trezor/bridge.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import TrezorConnect, {
1010
DEVICE_EVENT,
1111
UI,
1212
UI_EVENT
13-
} from 'trezor-connect'
13+
} from '@trezor/connect'
1414

1515
export class DeviceError extends Error {
1616
readonly code

0 commit comments

Comments
 (0)