@@ -28,6 +28,9 @@ import {
2828import { HardwareWalletChannels } from './createHardwareWalletIPCChannels' ;
2929import { Device } from './hardwareWallets/ledger/deviceDetection/types' ;
3030import { DeviceDetectionPayload } from './hardwareWallets/ledger/deviceDetection/deviceDetection' ;
31+ import { initTrezorConnect , reinitTrezorConnect } from '../trezor/connection' ;
32+ import { manifest } from '../trezor/manifest' ;
33+ import { buildTrezorDeviceParams } from '../utils/buildTrezorDeviceParams' ;
3134
3235type ListenerType = {
3336 unsubscribe : ( ...args : Array < any > ) => any ;
@@ -175,6 +178,8 @@ export const handleHardwareWalletRequests = async (
175178 TrezorConnect . removeAllListeners ( ) ;
176179 // Initialize new device listeners
177180 TrezorConnect . on ( UI_EVENT , ( event ) => {
181+ logger . info ( '[TREZOR-CONNECT] Received UI_EVENT: ' + event . type ) ;
182+
178183 if ( event . type === UI . REQUEST_PASSPHRASE ) {
179184 // ui-request_passphrase
180185 if ( event . payload && event . payload . device ) {
@@ -186,11 +191,20 @@ export const handleHardwareWalletRequests = async (
186191 passphraseOnDevice : true ,
187192 } ,
188193 } ) ;
194+
195+ logger . info (
196+ '[TREZOR-CONNECT] Called TrezorConnect.uiResponse - requested to provide passphrase on device'
197+ ) ;
189198 }
190199 }
191200 } ) ;
192201 TrezorConnect . on ( TRANSPORT_EVENT , ( event ) => {
193202 if ( event . type === TRANSPORT . ERROR ) {
203+ logger . info (
204+ '[TREZOR-CONNECT] Received TRANSPORT_EVENT: transport-error' ,
205+ event . payload
206+ ) ;
207+
194208 // Send Transport error to Renderer
195209 getHardwareWalletConnectionChannel . send (
196210 {
@@ -204,6 +218,8 @@ export const handleHardwareWalletRequests = async (
204218 }
205219 } ) ;
206220 TrezorConnect . on ( DEVICE_EVENT , ( event ) => {
221+ logger . info ( '[TREZOR-CONNECT] Received DEVICE_EVENT: ' + event . type ) ;
222+
207223 const connectionChanged =
208224 event . type === DEVICE . CONNECT ||
209225 event . type === DEVICE . DISCONNECT ||
@@ -256,13 +272,13 @@ export const handleHardwareWalletRequests = async (
256272 getHardwareWalletTransportChannel . onRequest (
257273 async ( request : HardwareWalletTransportDeviceRequest ) => {
258274 const { isTrezor, devicePath } = request ;
259- // @ts -ignore ts-migrate(2345) FIXME: Argument of type 'string' is not assignable to par... Remove this comment to see the full error message
260- logger . info ( '[HW-DEBUG] getHardwareWalletTransportChannel' , devicePath ) ;
275+ logger . info ( '[HW-DEBUG] getHardwareWalletTransportChannel' , {
276+ devicePath,
277+ } ) ;
261278 // Connected Trezor device info
262279 let deviceFeatures ;
263280
264281 if ( isTrezor ) {
265- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
266282 logger . info ( '[HW-DEBUG] getHardwareWalletTransportChannel::TREZOR ' ) ;
267283
268284 try {
@@ -271,10 +287,12 @@ export const handleHardwareWalletRequests = async (
271287 path : devicePath ,
272288 } ,
273289 } ) ;
274- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
275- logger . info ( '[HW-DEBUG] Trezor connect success ' ) ;
290+
291+ logger . info ( '[TREZOR-CONNECT] Called TrezorConnect.getFeatures() ' ) ;
276292
277293 if ( deviceFeatures && deviceFeatures . success ) {
294+ logger . info ( '[HW-DEBUG] Trezor connect success' ) ;
295+
278296 const {
279297 major_version : majorVersion ,
280298 minor_version : minorVersion ,
@@ -297,19 +315,16 @@ export const handleHardwareWalletRequests = async (
297315
298316 throw deviceFeatures . payload ; // Error is in payload
299317 } catch ( e ) {
300- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
301318 logger . info ( '[HW-DEBUG] Trezor connect error' ) ;
302319 throw e ;
303320 }
304321 }
305322
306323 try {
307- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
308324 logger . info ( '[HW-DEBUG] getHardwareWalletTransportChannel:: LEDGER' ) ;
309325 const transportList = await TransportNodeHid . list ( ) ;
310326 let hw ;
311327 let lastConnectedPath ;
312- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
313328 logger . info (
314329 `[HW-DEBUG] getHardwareWalletTransportChannel::transportList=${ JSON . stringify (
315330 transportList
@@ -342,14 +357,12 @@ export const handleHardwareWalletRequests = async (
342357 if ( transportList && ! transportList . length ) {
343358 // Establish connection with last device
344359 try {
345- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
346360 logger . info ( '[HW-DEBUG] INIT NEW transport' ) ;
347361
348362 const { device } = await waitForDevice ( ) ;
349363
350364 await openTransportLayer ( device . path , device ) ;
351365 } catch ( e ) {
352- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
353366 logger . info ( '[HW-DEBUG] INIT NEW transport - ERROR' ) ;
354367 throw e ;
355368 }
@@ -368,7 +381,6 @@ export const handleHardwareWalletRequests = async (
368381 throw new Error ( 'Device not connected!' ) ;
369382 }
370383 } else {
371- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
372384 logger . info ( '[HW-DEBUG] USE CURRENT CONNECTION' ) ;
373385 hw = devicesMemo [ devicePath ] . transport ;
374386 deviceConnection = get ( devicesMemo , [ devicePath , 'AdaConnection' ] ) ;
@@ -400,41 +412,19 @@ export const handleHardwareWalletRequests = async (
400412
401413 throw new Error ( 'Missing device info' ) ;
402414 } catch ( error ) {
403- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
404415 logger . info ( '[HW-DEBUG] ERROR on getHardwareWalletTransportChannel' ) ;
405416 throw error ;
406417 }
407418 }
408419 ) ;
420+
409421 handleInitTrezorConnectChannel . onRequest ( async ( ) => {
410- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
411422 logger . info ( '[HW-DEBUG] INIT TREZOR' ) ;
412423 resetTrezorListeners ( ) ;
413- TrezorConnect . manifest ( {
414- 415- appUrl : 'http://your.application.com' ,
416- } ) ;
417- TrezorConnect . init ( {
418- popup : false ,
419- // render your own UI
420- webusb : false ,
421- // webusb is not supported in electron
422- debug : true ,
423- // see what's going on inside connect
424- // lazyLoad: true, // set to "false" (default) if you want to start communication with bridge on application start (and detect connected device right away)
425- // set it to "true", then trezor-connect will not be initialized until you call some TrezorConnect.method()
426- // this is useful when you don't know if you are dealing with Trezor user
427- manifest : {
428- 429- // @TODO
430- appUrl : 'http://your.application.com' , // @TODO
431- } ,
432- } )
433- . then ( ( ) => { } )
434- . catch ( ( error ) => {
435- throw error ;
436- } ) ;
424+ TrezorConnect . manifest ( manifest ) ;
425+ await initTrezorConnect ( ) ;
437426 } ) ;
427+
438428 handleInitLedgerConnectChannel . onRequest ( async ( ) => {
439429 logger . info ( '[HW-DEBUG] INIT LEDGER' ) ;
440430 observer = new EventObserver ( {
@@ -489,16 +479,17 @@ export const handleHardwareWalletRequests = async (
489479
490480 try {
491481 deviceConnection = get ( devicesMemo , [ devicePath , 'AdaConnection' ] ) ;
492- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
482+
493483 logger . info ( '[HW-DEBUG] DERIVE ADDRESS' ) ;
494484
495485 if ( isTrezor ) {
486+ logger . info (
487+ '[TREZOR-CONNECT] Called TrezorConnect.cardanoGetAddress()'
488+ ) ;
489+
496490 const result = await TrezorConnect . cardanoGetAddress ( {
497- device : {
498- path : devicePath ,
499- // @ts -ignore ts-migrate(2769) FIXME: No overload matches this call.
500- showOnTrezor : true ,
501- } ,
491+ showOnTrezor : true ,
492+ device : buildTrezorDeviceParams ( devicePath ) ,
502493 addressParameters : {
503494 addressType,
504495 path : `m/${ spendingPathStr } ` ,
@@ -554,7 +545,7 @@ export const handleHardwareWalletRequests = async (
554545
555546 try {
556547 deviceConnection = get ( devicesMemo , [ devicePath , 'AdaConnection' ] ) ;
557- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
548+
558549 logger . info ( '[HW-DEBUG] SHOW ADDRESS' ) ;
559550
560551 if ( isTrezor ) {
@@ -647,14 +638,13 @@ export const handleHardwareWalletRequests = async (
647638 } ;
648639 }
649640
650- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
651641 logger . info ( `[HW-DEBUG] GET CARDANO APP path:${ path } ` ) ;
652642 deviceConnection = devicesMemo [ path ] . AdaConnection ;
653643 const { version } = await deviceConnection . getVersion ( ) ;
654- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
644+
655645 logger . info ( '[HW-DEBUG] getCardanoAdaAppChannel:: appVersion' ) ;
656646 const { serialHex } = await deviceConnection . getSerial ( ) ;
657- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
647+
658648 logger . info (
659649 `[HW-DEBUG] getCardanoAdaAppChannel:: deviceSerial: ${ serialHex } `
660650 ) ;
@@ -692,6 +682,12 @@ export const handleHardwareWalletRequests = async (
692682 const hasPathChanged = ! includes ( devicePaths , oldPath ) ;
693683 const newPath = hasPathChanged ? last ( devicePaths ) : oldPath ;
694684
685+ if ( hasPathChanged ) {
686+ logger . info (
687+ `[HW-DEBUG] Device path changed from ${ oldPath } to ${ newPath } `
688+ ) ;
689+ }
690+
695691 if ( ! newPath ) {
696692 logger . info (
697693 '[HW-DEBUG] ERROR in Cardano App (Device paths list is empty)' ,
@@ -755,20 +751,26 @@ export const handleHardwareWalletRequests = async (
755751 getExtendedPublicKeyChannel . onRequest ( async ( params ) => {
756752 // Params example:
757753 // { path: "1852'/1815'/0'", isTrezor: false, devicePath: null }
758- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
754+
759755 logger . info ( '[HW-DEBUG] getExtendedPublicKeyChannel' ) ;
760756 const { path, isTrezor, devicePath } = params ;
761757
762758 try {
763759 if ( isTrezor ) {
764- // Check if Trezor instantiated
760+ // We re-initialize the Trezor Connect session to give the user the chance to provide
761+ // a different passphrase, in case they want to switch to a different
762+ // hidden wallet or just if they provided a wrong one.
763+ await reinitTrezorConnect ( ) ;
764+
765+ logger . info ( '[TREZOR-CONNECT] Calling TrezorConnect.getFeatures()' ) ;
765766 const deviceFeatures = await TrezorConnect . getFeatures ( {
766- device : {
767- path : devicePath ,
768- } ,
767+ device : buildTrezorDeviceParams ( devicePath ) ,
769768 } ) ;
770769
771770 if ( deviceFeatures . success ) {
771+ logger . info (
772+ '[TREZOR-CONNECT] Calling TrezorConnect.cardanoGetPublicKey()'
773+ ) ;
772774 const extendedPublicKeyResponse = await TrezorConnect . cardanoGetPublicKey (
773775 {
774776 path : `m/${ path } ` ,
@@ -780,15 +782,13 @@ export const handleHardwareWalletRequests = async (
780782 throw extendedPublicKeyResponse . payload ;
781783 }
782784
783- const extendedPublicKey = get (
784- extendedPublicKeyResponse ,
785- [ 'payload' , ' node'] ,
786- { }
787- ) ;
785+ const extendedPublicKey = get ( extendedPublicKeyResponse , [
786+ 'payload' ,
787+ ' node',
788+ ] ) ;
789+
788790 return Promise . resolve ( {
789- // @ts -ignore ts-migrate(2339) FIXME: Property 'public_key' does not exist on type '{} |... Remove this comment to see the full error message
790791 publicKeyHex : extendedPublicKey . public_key ,
791- // @ts -ignore ts-migrate(2339) FIXME: Property 'chain_code' does not exist on type '{} |... Remove this comment to see the full error message
792792 chainCodeHex : extendedPublicKey . chain_code ,
793793 } ) ;
794794 }
@@ -797,7 +797,7 @@ export const handleHardwareWalletRequests = async (
797797 }
798798
799799 deviceConnection = get ( devicesMemo , [ devicePath , 'AdaConnection' ] ) ;
800- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
800+
801801 logger . info ( '[HW-DEBUG] EXPORT KEY' ) ;
802802
803803 // Check if Ledger instantiated
@@ -835,7 +835,7 @@ export const handleHardwareWalletRequests = async (
835835 signingMode,
836836 additionalWitnessPaths,
837837 } = params ;
838- // @ts -ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
838+
839839 logger . info ( '[HW-DEBUG] SIGN Ledger transaction' ) ;
840840 deviceConnection = devicePath
841841 ? devicesMemo [ devicePath ] . AdaConnection
@@ -903,19 +903,25 @@ export const handleHardwareWalletRequests = async (
903903 auxiliaryData,
904904 signingMode,
905905 } ;
906+
907+ logger . info (
908+ '[TREZOR-CONNECT] Calling TrezorConnect.cardanoSignTransaction()'
909+ ) ;
910+
906911 // @ts -ignore ts-migrate(2345) FIXME: Argument of type '{ inputs: TrezorSignTransactionI... Remove this comment to see the full error message
907912 const signedTransaction = await TrezorConnect . cardanoSignTransaction ( {
908- device : {
909- path : devicePath ,
910- } ,
913+ device : buildTrezorDeviceParams ( devicePath ) ,
911914 ...dataToSign ,
912915 } ) ;
916+
913917 return Promise . resolve ( signedTransaction ) ;
914918 } catch ( e ) {
915919 throw e ;
916920 }
917921 } ) ;
922+
918923 resetTrezorActionChannel . onRequest ( async ( ) => {
924+ logger . info ( '[TREZOR-CONNECT] Called TrezorConnect.cancel()' ) ;
919925 TrezorConnect . cancel ( 'Method_Cancel' ) ;
920926 } ) ;
921927} ;
0 commit comments