@@ -5,7 +5,7 @@ import TransportU2F from '@ledgerhq/hw-transport-u2f'
55import TransportWebUSB from '@ledgerhq/hw-transport-webusb'
66import { BigNumber , providers , Signer , utils } from 'ethers'
77import { config } from 'src/config'
8- import { CELO_LEDGER_APP_VERSION } from 'src/consts'
8+ import { CELO_LEDGER_APP_MIN_VERSION } from 'src/consts'
99import { CeloLedgerApp } from 'src/features/ledger/CeloLedgerApp'
1010import { getTokenData } from 'src/features/ledger/tokenData'
1111import { areAddressesEqual , ensureLeading0x , trimLeading0x } from 'src/utils/addresses'
@@ -46,16 +46,25 @@ export class LedgerSigner extends Signer {
4646
4747 private async validateCeloAppVersion ( ) {
4848 const appConfiguration = await this . perform ( ( celoApp ) => celoApp . getAppConfiguration ( ) )
49+ if ( ! appConfiguration ) throw new Error ( 'Unable to retrieve Ledger app configuration' )
50+ if ( ! appConfiguration . version ) throw new Error ( 'Ledger app configuration missing version info' )
4951
50- if ( appConfiguration ?. version !== CELO_LEDGER_APP_VERSION ) {
51- throw new Error ( `Unsupported Ledger app version, must be ${ CELO_LEDGER_APP_VERSION } ` )
52- }
52+ const version : string = appConfiguration . version
53+ const versionSegments = version . split ( '.' ) . map ( ( s ) => parseInt ( s ) )
54+ const minVersionSegments = CELO_LEDGER_APP_MIN_VERSION . split ( '.' ) . map ( ( s ) => parseInt ( s ) )
5355
54- if ( ! appConfiguration ?. arbitraryDataEnabled ) {
56+ if ( versionSegments . length !== 3 ) throw new Error ( 'Invalid Ledger app version segments' )
57+ if ( versionSegments [ 0 ] !== minVersionSegments [ 0 ] )
58+ throw new Error ( `Unsupported Ledger app major version, must be ${ minVersionSegments [ 0 ] } ` )
59+ if ( versionSegments [ 1 ] < minVersionSegments [ 1 ] || versionSegments [ 2 ] < minVersionSegments [ 2 ] )
60+ throw new Error (
61+ `Unsupported Ledger app version, must be at least ${ CELO_LEDGER_APP_MIN_VERSION } `
62+ )
63+
64+ if ( ! appConfiguration ?. arbitraryDataEnabled )
5565 throw new Error (
5666 'Ledger does not allow contract data. Required for safe token transfers. Enable it from the ledger app settings.'
5767 )
58- }
5968 }
6069
6170 async populateTransaction ( transaction : utils . Deferrable < CeloTransactionRequest > ) : Promise < any > {
0 commit comments