@@ -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 ;
@@ -169,6 +172,8 @@ export const handleHardwareWalletRequests = async (
169172 TrezorConnect . removeAllListeners ( ) ;
170173 // Initialize new device listeners
171174 TrezorConnect . on ( UI_EVENT , ( event ) => {
175+ logger . info ( '[TREZOR-CONNECT] Received UI_EVENT: ' + event . type ) ;
176+
172177 if ( event . type === UI . REQUEST_PASSPHRASE ) {
173178 // ui-request_passphrase
174179 if ( event . payload && event . payload . device ) {
@@ -180,11 +185,20 @@ export const handleHardwareWalletRequests = async (
180185 passphraseOnDevice : true ,
181186 } ,
182187 } ) ;
188+
189+ logger . info (
190+ '[TREZOR-CONNECT] Called TrezorConnect.uiResponse - requested to provide passphrase on device'
191+ ) ;
183192 }
184193 }
185194 } ) ;
186195 TrezorConnect . on ( TRANSPORT_EVENT , ( event ) => {
187196 if ( event . type === TRANSPORT . ERROR ) {
197+ logger . info (
198+ '[TREZOR-CONNECT] Received TRANSPORT_EVENT: transport-error' ,
199+ event . payload
200+ ) ;
201+
188202 // Send Transport error to Renderer
189203 getHardwareWalletConnectionChannel . send (
190204 {
@@ -198,6 +212,8 @@ export const handleHardwareWalletRequests = async (
198212 }
199213 } ) ;
200214 TrezorConnect . on ( DEVICE_EVENT , ( event ) => {
215+ logger . info ( '[TREZOR-CONNECT] Received DEVICE_EVENT: ' + event . type ) ;
216+
201217 const connectionChanged =
202218 event . type === DEVICE . CONNECT ||
203219 event . type === DEVICE . DISCONNECT ||
@@ -250,13 +266,13 @@ export const handleHardwareWalletRequests = async (
250266 getHardwareWalletTransportChannel . onRequest (
251267 async ( request : HardwareWalletTransportDeviceRequest ) => {
252268 const { isTrezor, devicePath } = request ;
253- // @ts -ignore ts-migrate(2345) FIXME: Argument of type 'string' is not assignable to par... Remove this comment to see the full error message
254- logger . info ( '[HW-DEBUG] getHardwareWalletTransportChannel' , devicePath ) ;
269+ logger . info ( '[HW-DEBUG] getHardwareWalletTransportChannel' , {
270+ devicePath,
271+ } ) ;
255272 // Connected Trezor device info
256273 let deviceFeatures ;
257274
258275 if ( isTrezor ) {
259- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
260276 logger . info ( '[HW-DEBUG] getHardwareWalletTransportChannel::TREZOR ' ) ;
261277
262278 try {
@@ -265,10 +281,12 @@ export const handleHardwareWalletRequests = async (
265281 path : devicePath ,
266282 } ,
267283 } ) ;
268- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
269- logger . info ( '[HW-DEBUG] Trezor connect success ' ) ;
284+
285+ logger . info ( '[TREZOR-CONNECT] Called TrezorConnect.getFeatures() ' ) ;
270286
271287 if ( deviceFeatures && deviceFeatures . success ) {
288+ logger . info ( '[HW-DEBUG] Trezor connect success' ) ;
289+
272290 const {
273291 major_version : majorVersion ,
274292 minor_version : minorVersion ,
@@ -291,19 +309,16 @@ export const handleHardwareWalletRequests = async (
291309
292310 throw deviceFeatures . payload ; // Error is in payload
293311 } catch ( e ) {
294- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
295312 logger . info ( '[HW-DEBUG] Trezor connect error' ) ;
296313 throw e ;
297314 }
298315 }
299316
300317 try {
301- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
302318 logger . info ( '[HW-DEBUG] getHardwareWalletTransportChannel:: LEDGER' ) ;
303319 const transportList = await TransportNodeHid . list ( ) ;
304320 let hw ;
305321 let lastConnectedPath ;
306- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
307322 logger . info (
308323 `[HW-DEBUG] getHardwareWalletTransportChannel::transportList=${ JSON . stringify (
309324 transportList
@@ -336,14 +351,12 @@ export const handleHardwareWalletRequests = async (
336351 if ( transportList && ! transportList . length ) {
337352 // Establish connection with last device
338353 try {
339- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
340354 logger . info ( '[HW-DEBUG] INIT NEW transport' ) ;
341355
342356 const { device } = await waitForDevice ( ) ;
343357
344358 await openTransportLayer ( device . path , device ) ;
345359 } catch ( e ) {
346- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
347360 logger . info ( '[HW-DEBUG] INIT NEW transport - ERROR' ) ;
348361 throw e ;
349362 }
@@ -362,7 +375,6 @@ export const handleHardwareWalletRequests = async (
362375 throw new Error ( 'Device not connected!' ) ;
363376 }
364377 } else {
365- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
366378 logger . info ( '[HW-DEBUG] USE CURRENT CONNECTION' ) ;
367379 hw = devicesMemo [ devicePath ] . transport ;
368380 deviceConnection = get ( devicesMemo , [ devicePath , 'AdaConnection' ] ) ;
@@ -394,41 +406,19 @@ export const handleHardwareWalletRequests = async (
394406
395407 throw new Error ( 'Missing device info' ) ;
396408 } catch ( error ) {
397- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
398409 logger . info ( '[HW-DEBUG] ERROR on getHardwareWalletTransportChannel' ) ;
399410 throw error ;
400411 }
401412 }
402413 ) ;
414+
403415 handleInitTrezorConnectChannel . onRequest ( async ( ) => {
404- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
405416 logger . info ( '[HW-DEBUG] INIT TREZOR' ) ;
406417 resetTrezorListeners ( ) ;
407- TrezorConnect . manifest ( {
408- 409- appUrl : 'http://your.application.com' ,
410- } ) ;
411- TrezorConnect . init ( {
412- popup : false ,
413- // render your own UI
414- webusb : false ,
415- // webusb is not supported in electron
416- debug : true ,
417- // see what's going on inside connect
418- // lazyLoad: true, // set to "false" (default) if you want to start communication with bridge on application start (and detect connected device right away)
419- // set it to "true", then trezor-connect will not be initialized until you call some TrezorConnect.method()
420- // this is useful when you don't know if you are dealing with Trezor user
421- manifest : {
422- 423- // @TODO
424- appUrl : 'http://your.application.com' , // @TODO
425- } ,
426- } )
427- . then ( ( ) => { } )
428- . catch ( ( error ) => {
429- throw error ;
430- } ) ;
418+ TrezorConnect . manifest ( manifest ) ;
419+ await initTrezorConnect ( ) ;
431420 } ) ;
421+
432422 handleInitLedgerConnectChannel . onRequest ( async ( ) => {
433423 logger . info ( '[HW-DEBUG] INIT LEDGER' ) ;
434424 observer = new EventObserver ( {
@@ -483,16 +473,17 @@ export const handleHardwareWalletRequests = async (
483473
484474 try {
485475 deviceConnection = get ( devicesMemo , [ devicePath , 'AdaConnection' ] ) ;
486- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
476+
487477 logger . info ( '[HW-DEBUG] DERIVE ADDRESS' ) ;
488478
489479 if ( isTrezor ) {
480+ logger . info (
481+ '[TREZOR-CONNECT] Called TrezorConnect.cardanoGetAddress()'
482+ ) ;
483+
490484 const result = await TrezorConnect . cardanoGetAddress ( {
491- device : {
492- path : devicePath ,
493- // @ts -ignore ts-migrate(2769) FIXME: No overload matches this call.
494- showOnTrezor : true ,
495- } ,
485+ showOnTrezor : true ,
486+ device : buildTrezorDeviceParams ( devicePath ) ,
496487 addressParameters : {
497488 addressType,
498489 path : `m/${ spendingPathStr } ` ,
@@ -548,7 +539,7 @@ export const handleHardwareWalletRequests = async (
548539
549540 try {
550541 deviceConnection = get ( devicesMemo , [ devicePath , 'AdaConnection' ] ) ;
551- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
542+
552543 logger . info ( '[HW-DEBUG] SHOW ADDRESS' ) ;
553544
554545 if ( isTrezor ) {
@@ -641,14 +632,13 @@ export const handleHardwareWalletRequests = async (
641632 } ;
642633 }
643634
644- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
645635 logger . info ( `[HW-DEBUG] GET CARDANO APP path:${ path } ` ) ;
646636 deviceConnection = devicesMemo [ path ] . AdaConnection ;
647637 const { version } = await deviceConnection . getVersion ( ) ;
648- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
638+
649639 logger . info ( '[HW-DEBUG] getCardanoAdaAppChannel:: appVersion' ) ;
650640 const { serialHex } = await deviceConnection . getSerial ( ) ;
651- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
641+
652642 logger . info (
653643 `[HW-DEBUG] getCardanoAdaAppChannel:: deviceSerial: ${ serialHex } `
654644 ) ;
@@ -686,6 +676,12 @@ export const handleHardwareWalletRequests = async (
686676 const hasPathChanged = ! includes ( devicePaths , oldPath ) ;
687677 const newPath = hasPathChanged ? last ( devicePaths ) : oldPath ;
688678
679+ if ( hasPathChanged ) {
680+ logger . info (
681+ `[HW-DEBUG] Device path changed from ${ oldPath } to ${ newPath } `
682+ ) ;
683+ }
684+
689685 if ( ! newPath ) {
690686 logger . info (
691687 '[HW-DEBUG] ERROR in Cardano App (Device paths list is empty)' ,
@@ -749,20 +745,26 @@ export const handleHardwareWalletRequests = async (
749745 getExtendedPublicKeyChannel . onRequest ( async ( params ) => {
750746 // Params example:
751747 // { path: "1852'/1815'/0'", isTrezor: false, devicePath: null }
752- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
748+
753749 logger . info ( '[HW-DEBUG] getExtendedPublicKeyChannel' ) ;
754750 const { path, isTrezor, devicePath } = params ;
755751
756752 try {
757753 if ( isTrezor ) {
758- // Check if Trezor instantiated
754+ // We re-initialize the Trezor Connect session to give the user the chance to provide
755+ // a different passphrase, in case they want to switch to a different
756+ // hidden wallet or just if they provided a wrong one.
757+ await reinitTrezorConnect ( ) ;
758+
759+ logger . info ( '[TREZOR-CONNECT] Calling TrezorConnect.getFeatures()' ) ;
759760 const deviceFeatures = await TrezorConnect . getFeatures ( {
760- device : {
761- path : devicePath ,
762- } ,
761+ device : buildTrezorDeviceParams ( devicePath ) ,
763762 } ) ;
764763
765764 if ( deviceFeatures . success ) {
765+ logger . info (
766+ '[TREZOR-CONNECT] Calling TrezorConnect.cardanoGetPublicKey()'
767+ ) ;
766768 const extendedPublicKeyResponse = await TrezorConnect . cardanoGetPublicKey (
767769 {
768770 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