Skip to content

Commit 0ab543a

Browse files
committed
Allow greater minor and patch versions for ledger app
1 parent bbd100b commit 0ab543a

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ See the [FAQ](FAQ.md) for more details about common questions.
1212

1313
This wallet uses [Subresource Integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity). Current bundle hashes:
1414

15-
* Main bundle: `bundle.js -> sha256-9MTcW6OMeplVCmoKrOTSEqu0s/VRzh+j1P644oSFQpc=`
16-
* Optional Ledger bundle: `bundle-ledger.js -> sha256-F0NhZGZyPEb86ccx71+TYxoryxpYFXQTqOqgTuL582o=`
15+
* Main bundle: `bundle.js -> sha256-FR2Caux0Qij79Jj47G0xbU8WYknbNmxxtWbKEim2cUw=`
16+
* Optional Ledger bundle: `bundle-ledger.js -> sha256-m5wcEVEXFVmOal5a4P2F9Sum8c8jgGxVUg0d4k3G5MQ=`
1717

1818
Advanced users can verify the source integrity by comparing the hashes in their page source to these values.
1919

src/consts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ export const PLACEHOLDER_MNEMONIC =
2929

3030
export const HIGH_VALUE_THRESHOLD = '25000000000000000000' // 25 cusd - threshold balance for a "high-value" wallet
3131

32-
export const CELO_LEDGER_APP_VERSION = '1.0.3' // Only allow latest ledger app version
32+
export const CELO_LEDGER_APP_MIN_VERSION = '1.0.3' // Only allow this ledger app versions or newer

src/features/ledger/LedgerSigner.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import TransportU2F from '@ledgerhq/hw-transport-u2f'
55
import TransportWebUSB from '@ledgerhq/hw-transport-webusb'
66
import { BigNumber, providers, Signer, utils } from 'ethers'
77
import { config } from 'src/config'
8-
import { CELO_LEDGER_APP_VERSION } from 'src/consts'
8+
import { CELO_LEDGER_APP_MIN_VERSION } from 'src/consts'
99
import { CeloLedgerApp } from 'src/features/ledger/CeloLedgerApp'
1010
import { getTokenData } from 'src/features/ledger/tokenData'
1111
import { 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

Comments
 (0)