Skip to content

Commit e793d60

Browse files
authored
Merge pull request #600 from InjectiveLabs/chore/update-trezor
Chore/update trezor
2 parents c5a548f + a129349 commit e793d60

File tree

5 files changed

+4555
-10860
lines changed

5 files changed

+4555
-10860
lines changed

packages/wallets/wallet-trezor/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
"lint": "eslint . --ext .ts,.js"
5757
},
5858
"dependencies": {
59-
"@bangjelkoski/trezor-connect-web": "^9.4.7-beta.1",
59+
"@trezor/connect-web": "^9.6.4",
60+
"@trezor/connect": "^9.6.4",
6061
"@injectivelabs/exceptions": "workspace:*",
6162
"@injectivelabs/sdk-ts": "workspace:*",
6263
"@injectivelabs/ts-types": "workspace:*",

packages/wallets/wallet-trezor/src/strategy/Base.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ export default class TrezorBase
185185
address: AccountAddress,
186186
): Promise<string> {
187187
const TrezorConnect = await loadTrezorConnect()
188+
console.log('🪵Address:', address)
188189

189190
const object = JSON.parse(eip712json)
190191
const compatibleObject = {
@@ -206,8 +207,14 @@ export default class TrezorBase
206207
} = dataWithHashes
207208

208209
try {
210+
console.log('🪵Signing EIP-712 typed data with Trezor...')
209211
await this.trezor.connect()
210-
const { derivationPath } = await this.getWalletForAddress(address)
212+
console.log('🪵Connected to Trezor...')
213+
// const { derivationPath } = await this.getWalletForAddress(address)
214+
// Hardcoded for testint purposes, otherwise use above
215+
const derivationPath = "m/44'/60'/0'/0/0"
216+
console.log('🪵Derivation path:', derivationPath)
217+
console.log('Signing EIP-712 typed data with Trezor...')
211218
const response = await TrezorConnect.ethereumSignTypedData({
212219
path: derivationPath,
213220
data: {
@@ -221,6 +228,8 @@ export default class TrezorBase
221228
metamask_v4_compat: true,
222229
})
223230

231+
console.log('🪵response', response)
232+
224233
if (!response.success) {
225234
// noinspection ExceptionCaughtLocallyJS
226235
throw new Error(

packages/wallets/wallet-trezor/src/strategy/hw/transport/base.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1-
import { loadTrezorConnect } from '../../lib.js'
21
import AccountManager from '../AccountManager.js'
2+
import { loadTrezorConnect, type Manifest } from '../../lib.js'
33

44
const TREZOR_CONNECT_MANIFEST = {
55
email: 'contact@injectivelabs.org',
66
appUrl: 'https://injectivelabs.org',
7-
}
7+
appName: 'Injective Labs',
8+
} as Manifest
89

910
export default class BaseTrezorTransport {
1011
private accountManager: AccountManager | null = null
1112

1213
async connect() {
1314
const TrezorConnect = await loadTrezorConnect()
14-
1515
const settings = await TrezorConnect.getSettings()
1616

1717
if (!settings.success) {
18-
TrezorConnect.init({
18+
console.log('🪵Initializing TrezorConnect...')
19+
await TrezorConnect.init({
1920
lazyLoad: true,
2021
manifest: TREZOR_CONNECT_MANIFEST,
22+
debug: true,
23+
// 'auto', 'popup', 'iframe'
24+
coreMode: 'popup',
2125
})
2226
}
2327

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,61 @@
1-
type TrezorConnectType =
2-
typeof import('@bangjelkoski/trezor-connect-web').TrezorConnect
1+
// We avoid importing types from @trezor/connect because it triggers a syntax error
2+
// in the underlying @trezor/connect type definitions (there's a typo: comma instead of space).
3+
// Instead, we define the minimal types we need inline.
34

4-
let TrezorConnect: TrezorConnectType
5+
type Manifest = {
6+
appName: string
7+
appIcon?: string
8+
appUrl: string
9+
email: string
10+
}
511

6-
export async function loadTrezorConnect(): Promise<TrezorConnectType> {
7-
if (!TrezorConnect) {
8-
const module = await import('@bangjelkoski/trezor-connect-web')
12+
type ConnectSettingsWeb = {
13+
hostLabel?: string
14+
coreMode?: 'auto' | 'popup' | 'iframe'
15+
}
916

10-
TrezorConnect = (module.TrezorConnect ||
11-
(module as any).default.TrezorConnect) as TrezorConnectType
17+
type ConnectSettingsPublic = {
18+
manifest?: Manifest
19+
connectSrc?: string
20+
debug?: boolean
21+
popup?: boolean
22+
transportReconnect?: boolean
23+
transports?: Array<'BridgeTransport' | 'WebUsbTransport' | 'NodeUsbTransport'>
24+
pendingTransportEvent?: boolean
25+
lazyLoad?: boolean
26+
interactionTimeout?: number
27+
trustedHost: boolean
28+
binFilesBaseUrl?: string
29+
enableFirmwareHashCheck?: boolean
30+
firmwareHashCheckTimeouts?: Record<string, number>
31+
thp?: {
32+
hostName?: string
33+
appName?: string
34+
staticKey?: string
35+
knownCredentials?: unknown[]
36+
pairingMethods: unknown[]
1237
}
38+
}
39+
40+
// Reconstruct the init settings type without importing from @trezor/connect
41+
type InitSettingsWithWeb = {
42+
manifest: Manifest
43+
} & Partial<Omit<ConnectSettingsPublic, 'manifest'> & ConnectSettingsWeb>
44+
45+
// Export Manifest type so it can be used in other files
46+
export type { Manifest }
47+
48+
// Define the return type without referencing TrezorConnectType to avoid triggering
49+
// TypeScript to parse the broken type definition in @trezor/connect
50+
export type TrezorConnectWithWebSettings = {
51+
init: (settings: InitSettingsWithWeb) => Promise<void>
52+
// Add other methods as needed, or use a more permissive type
53+
[key: string]: any
54+
}
55+
56+
export async function loadTrezorConnect(): Promise<TrezorConnectWithWebSettings> {
57+
const module = await import('@trezor/connect-web')
1358

14-
return TrezorConnect
59+
return (module as any).default
60+
.default as unknown as TrezorConnectWithWebSettings
1561
}

0 commit comments

Comments
 (0)