@@ -27,6 +27,9 @@ import {
2727import { HardwareWalletChannels } from './createHardwareWalletIPCChannels' ;
2828import { Device } from './hardwareWallets/ledger/deviceDetection/types' ;
2929import { DeviceDetectionPayload } from './hardwareWallets/ledger/deviceDetection/deviceDetection' ;
30+ import { initTrezorConnect , reinitTrezorConnect } from '../trezor/connection' ;
31+ import { manifest } from '../trezor/manifest' ;
32+ import { buildTrezorDeviceParams } from '../utils/buildTrezorDeviceParams' ;
3033
3134type ListenerType = {
3235 unsubscribe : ( ...args : Array < any > ) => any ;
@@ -170,6 +173,8 @@ export const handleHardwareWalletRequests = async (
170173 TrezorConnect . removeAllListeners ( ) ;
171174 // Initialize new device listeners
172175 TrezorConnect . on ( UI_EVENT , ( event ) => {
176+ logger . info ( '[TREZOR-CONNECT] Received UI_EVENT: ' + event . type ) ;
177+
173178 if ( event . type === UI . REQUEST_PASSPHRASE ) {
174179 // ui-request_passphrase
175180 if ( event . payload && event . payload . device ) {
@@ -181,11 +186,20 @@ export const handleHardwareWalletRequests = async (
181186 passphraseOnDevice : true ,
182187 } ,
183188 } ) ;
189+
190+ logger . info (
191+ '[TREZOR-CONNECT] Called TrezorConnect.uiResponse - requested to provide passphrase on device'
192+ ) ;
184193 }
185194 }
186195 } ) ;
187196 TrezorConnect . on ( TRANSPORT_EVENT , ( event ) => {
188197 if ( event . type === TRANSPORT . ERROR ) {
198+ logger . info (
199+ '[TREZOR-CONNECT] Received TRANSPORT_EVENT: transport-error' ,
200+ event . payload
201+ ) ;
202+
189203 // Send Transport error to Renderer
190204 getHardwareWalletConnectionChannel . send (
191205 {
@@ -199,6 +213,8 @@ export const handleHardwareWalletRequests = async (
199213 }
200214 } ) ;
201215 TrezorConnect . on ( DEVICE_EVENT , ( event ) => {
216+ logger . info ( '[TREZOR-CONNECT] Received DEVICE_EVENT: ' + event . type ) ;
217+
202218 const connectionChanged =
203219 event . type === DEVICE . CONNECT ||
204220 event . type === DEVICE . DISCONNECT ||
@@ -251,13 +267,13 @@ export const handleHardwareWalletRequests = async (
251267 getHardwareWalletTransportChannel . onRequest (
252268 async ( request : HardwareWalletTransportDeviceRequest ) => {
253269 const { isTrezor, devicePath } = request ;
254- // @ts -ignore ts-migrate(2345) FIXME: Argument of type 'string' is not assignable to par... Remove this comment to see the full error message
255- logger . info ( '[HW-DEBUG] getHardwareWalletTransportChannel' , devicePath ) ;
270+ logger . info ( '[HW-DEBUG] getHardwareWalletTransportChannel' , {
271+ devicePath,
272+ } ) ;
256273 // Connected Trezor device info
257274 let deviceFeatures ;
258275
259276 if ( isTrezor ) {
260- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
261277 logger . info ( '[HW-DEBUG] getHardwareWalletTransportChannel::TREZOR ' ) ;
262278
263279 try {
@@ -266,10 +282,12 @@ export const handleHardwareWalletRequests = async (
266282 path : devicePath ,
267283 } ,
268284 } ) ;
269- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
270- logger . info ( '[HW-DEBUG] Trezor connect success ' ) ;
285+
286+ logger . info ( '[TREZOR-CONNECT] Called TrezorConnect.getFeatures() ' ) ;
271287
272288 if ( deviceFeatures && deviceFeatures . success ) {
289+ logger . info ( '[HW-DEBUG] Trezor connect success' ) ;
290+
273291 const {
274292 major_version : majorVersion ,
275293 minor_version : minorVersion ,
@@ -292,19 +310,16 @@ export const handleHardwareWalletRequests = async (
292310
293311 throw deviceFeatures . payload ; // Error is in payload
294312 } catch ( e ) {
295- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
296313 logger . info ( '[HW-DEBUG] Trezor connect error' ) ;
297314 throw e ;
298315 }
299316 }
300317
301318 try {
302- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
303319 logger . info ( '[HW-DEBUG] getHardwareWalletTransportChannel:: LEDGER' ) ;
304320 const transportList = await TransportNodeHid . list ( ) ;
305321 let hw ;
306322 let lastConnectedPath ;
307- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
308323 logger . info (
309324 `[HW-DEBUG] getHardwareWalletTransportChannel::transportList=${ JSON . stringify (
310325 transportList
@@ -337,14 +352,12 @@ export const handleHardwareWalletRequests = async (
337352 if ( transportList && ! transportList . length ) {
338353 // Establish connection with last device
339354 try {
340- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
341355 logger . info ( '[HW-DEBUG] INIT NEW transport' ) ;
342356
343357 const { device } = await waitForDevice ( ) ;
344358
345359 await openTransportLayer ( device . path , device ) ;
346360 } catch ( e ) {
347- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
348361 logger . info ( '[HW-DEBUG] INIT NEW transport - ERROR' ) ;
349362 throw e ;
350363 }
@@ -363,7 +376,6 @@ export const handleHardwareWalletRequests = async (
363376 throw new Error ( 'Device not connected!' ) ;
364377 }
365378 } else {
366- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
367379 logger . info ( '[HW-DEBUG] USE CURRENT CONNECTION' ) ;
368380 hw = devicesMemo [ devicePath ] . transport ;
369381 deviceConnection = get ( devicesMemo , [ devicePath , 'AdaConnection' ] ) ;
@@ -395,41 +407,19 @@ export const handleHardwareWalletRequests = async (
395407
396408 throw new Error ( 'Missing device info' ) ;
397409 } catch ( error ) {
398- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
399410 logger . info ( '[HW-DEBUG] ERROR on getHardwareWalletTransportChannel' ) ;
400411 throw error ;
401412 }
402413 }
403414 ) ;
415+
404416 handleInitTrezorConnectChannel . onRequest ( async ( ) => {
405- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
406417 logger . info ( '[HW-DEBUG] INIT TREZOR' ) ;
407418 resetTrezorListeners ( ) ;
408- TrezorConnect . manifest ( {
409- 410- appUrl : 'http://your.application.com' ,
411- } ) ;
412- TrezorConnect . init ( {
413- popup : false ,
414- // render your own UI
415- webusb : false ,
416- // webusb is not supported in electron
417- debug : true ,
418- // see what's going on inside connect
419- // lazyLoad: true, // set to "false" (default) if you want to start communication with bridge on application start (and detect connected device right away)
420- // set it to "true", then trezor-connect will not be initialized until you call some TrezorConnect.method()
421- // this is useful when you don't know if you are dealing with Trezor user
422- manifest : {
423- 424- // @TODO
425- appUrl : 'http://your.application.com' , // @TODO
426- } ,
427- } )
428- . then ( ( ) => { } )
429- . catch ( ( error ) => {
430- throw error ;
431- } ) ;
419+ TrezorConnect . manifest ( manifest ) ;
420+ await initTrezorConnect ( ) ;
432421 } ) ;
422+
433423 handleInitLedgerConnectChannel . onRequest ( async ( ) => {
434424 logger . info ( '[HW-DEBUG] INIT LEDGER' ) ;
435425 observer = new EventObserver ( {
@@ -484,16 +474,17 @@ export const handleHardwareWalletRequests = async (
484474
485475 try {
486476 deviceConnection = get ( devicesMemo , [ devicePath , 'AdaConnection' ] ) ;
487- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
477+
488478 logger . info ( '[HW-DEBUG] DERIVE ADDRESS' ) ;
489479
490480 if ( isTrezor ) {
481+ logger . info (
482+ '[TREZOR-CONNECT] Called TrezorConnect.cardanoGetAddress()'
483+ ) ;
484+
491485 const result = await TrezorConnect . cardanoGetAddress ( {
492- device : {
493- path : devicePath ,
494- // @ts -ignore ts-migrate(2769) FIXME: No overload matches this call.
495- showOnTrezor : true ,
496- } ,
486+ showOnTrezor : true ,
487+ device : buildTrezorDeviceParams ( devicePath ) ,
497488 addressParameters : {
498489 addressType,
499490 path : `m/${ spendingPathStr } ` ,
@@ -549,7 +540,7 @@ export const handleHardwareWalletRequests = async (
549540
550541 try {
551542 deviceConnection = get ( devicesMemo , [ devicePath , 'AdaConnection' ] ) ;
552- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
543+
553544 logger . info ( '[HW-DEBUG] SHOW ADDRESS' ) ;
554545
555546 if ( isTrezor ) {
@@ -642,14 +633,13 @@ export const handleHardwareWalletRequests = async (
642633 } ;
643634 }
644635
645- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
646636 logger . info ( `[HW-DEBUG] GET CARDANO APP path:${ path } ` ) ;
647637 deviceConnection = devicesMemo [ path ] . AdaConnection ;
648638 const { version } = await deviceConnection . getVersion ( ) ;
649- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
639+
650640 logger . info ( '[HW-DEBUG] getCardanoAdaAppChannel:: appVersion' ) ;
651641 const { serialHex } = await deviceConnection . getSerial ( ) ;
652- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
642+
653643 logger . info (
654644 `[HW-DEBUG] getCardanoAdaAppChannel:: deviceSerial: ${ serialHex } `
655645 ) ;
@@ -687,6 +677,12 @@ export const handleHardwareWalletRequests = async (
687677 const hasPathChanged = ! includes ( devicePaths , oldPath ) ;
688678 const newPath = hasPathChanged ? last ( devicePaths ) : oldPath ;
689679
680+ if ( hasPathChanged ) {
681+ logger . info (
682+ `[HW-DEBUG] Device path changed from ${ oldPath } to ${ newPath } `
683+ ) ;
684+ }
685+
690686 if ( ! newPath ) {
691687 logger . info (
692688 '[HW-DEBUG] ERROR in Cardano App (Device paths list is empty)' ,
@@ -750,20 +746,26 @@ export const handleHardwareWalletRequests = async (
750746 getExtendedPublicKeyChannel . onRequest ( async ( params ) => {
751747 // Params example:
752748 // { path: "1852'/1815'/0'", isTrezor: false, devicePath: null }
753- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
749+
754750 logger . info ( '[HW-DEBUG] getExtendedPublicKeyChannel' ) ;
755751 const { path, isTrezor, devicePath } = params ;
756752
757753 try {
758754 if ( isTrezor ) {
759- // Check if Trezor instantiated
755+ // We re-initialize the Trezor Connect session to give the user the chance to provide
756+ // a different passphrase, in case they want to switch to a different
757+ // hidden wallet or just if they provided a wrong one.
758+ await reinitTrezorConnect ( ) ;
759+
760+ logger . info ( '[TREZOR-CONNECT] Calling TrezorConnect.getFeatures()' ) ;
760761 const deviceFeatures = await TrezorConnect . getFeatures ( {
761- device : {
762- path : devicePath ,
763- } ,
762+ device : buildTrezorDeviceParams ( devicePath ) ,
764763 } ) ;
765764
766765 if ( deviceFeatures . success ) {
766+ logger . info (
767+ '[TREZOR-CONNECT] Calling TrezorConnect.cardanoGetPublicKey()'
768+ ) ;
767769 const extendedPublicKeyResponse =
768770 await TrezorConnect . cardanoGetPublicKey ( {
769771 path : `m/${ path } ` ,
@@ -774,15 +776,13 @@ export const handleHardwareWalletRequests = async (
774776 throw extendedPublicKeyResponse . payload ;
775777 }
776778
777- const extendedPublicKey = get (
778- extendedPublicKeyResponse ,
779- [ 'payload' , ' node'] ,
780- { }
781- ) ;
779+ const extendedPublicKey = get ( extendedPublicKeyResponse , [
780+ 'payload' ,
781+ ' node',
782+ ] ) ;
783+
782784 return Promise . resolve ( {
783- // @ts -ignore ts-migrate(2339) FIXME: Property 'public_key' does not exist on type '{} |... Remove this comment to see the full error message
784785 publicKeyHex : extendedPublicKey . public_key ,
785- // @ts -ignore ts-migrate(2339) FIXME: Property 'chain_code' does not exist on type '{} |... Remove this comment to see the full error message
786786 chainCodeHex : extendedPublicKey . chain_code ,
787787 } ) ;
788788 }
@@ -791,7 +791,7 @@ export const handleHardwareWalletRequests = async (
791791 }
792792
793793 deviceConnection = get ( devicesMemo , [ devicePath , 'AdaConnection' ] ) ;
794- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
794+
795795 logger . info ( '[HW-DEBUG] EXPORT KEY' ) ;
796796
797797 // Check if Ledger instantiated
@@ -829,7 +829,7 @@ export const handleHardwareWalletRequests = async (
829829 signingMode,
830830 additionalWitnessPaths,
831831 } = params ;
832- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
832+
833833 logger . info ( '[HW-DEBUG] SIGN Ledger transaction' ) ;
834834 deviceConnection = devicePath
835835 ? devicesMemo [ devicePath ] . AdaConnection
@@ -897,19 +897,25 @@ export const handleHardwareWalletRequests = async (
897897 auxiliaryData,
898898 signingMode,
899899 } ;
900+
901+ logger . info (
902+ '[TREZOR-CONNECT] Calling TrezorConnect.cardanoSignTransaction()'
903+ ) ;
904+
900905 // @ts -ignore ts-migrate(2345) FIXME: Argument of type '{ inputs: TrezorSignTransactionI... Remove this comment to see the full error message
901906 const signedTransaction = await TrezorConnect . cardanoSignTransaction ( {
902- device : {
903- path : devicePath ,
904- } ,
907+ device : buildTrezorDeviceParams ( devicePath ) ,
905908 ...dataToSign ,
906909 } ) ;
910+
907911 return Promise . resolve ( signedTransaction ) ;
908912 } catch ( e ) {
909913 throw e ;
910914 }
911915 } ) ;
916+
912917 resetTrezorActionChannel . onRequest ( async ( ) => {
918+ logger . info ( '[TREZOR-CONNECT] Called TrezorConnect.cancel()' ) ;
913919 TrezorConnect . cancel ( 'Method_Cancel' ) ;
914920 } ) ;
915921} ;
0 commit comments