diff --git a/packages/connect/src/api/authenticateDevice.ts b/packages/connect/src/api/authenticateDevice.ts index 5bbe34ed379..20ce595e28a 100644 --- a/packages/connect/src/api/authenticateDevice.ts +++ b/packages/connect/src/api/authenticateDevice.ts @@ -2,7 +2,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod } from '../core/AbstractMethod'; import { UI } from '../events'; -import { getFirmwareRange } from './common/paramsValidator'; import { deviceAuthenticityConfig } from '../data/deviceAuthenticityConfig'; import { AuthenticateDeviceParams } from '../types/api/authenticateDevice'; import { getRandomChallenge, verifyAuthenticityProof } from './firmware/verifyAuthenticityProof'; @@ -16,7 +15,7 @@ export default class AuthenticateDevice extends AbstractMethod< this.allowDeviceMode = [UI.INITIALIZE, UI.SEEDLESS]; this.requiredPermissions = ['management']; this.useDeviceState = false; - this.firmwareRange = getFirmwareRange(this.name, null, this.firmwareRange); + this.setFirmwareRange(this.name, null); const { payload } = this; diff --git a/packages/connect/src/api/authorizeCoinjoin.ts b/packages/connect/src/api/authorizeCoinjoin.ts index 4d1be821cea..fd9c3c7ccf5 100644 --- a/packages/connect/src/api/authorizeCoinjoin.ts +++ b/packages/connect/src/api/authorizeCoinjoin.ts @@ -1,7 +1,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod } from '../core/AbstractMethod'; -import { getFirmwareRange } from './common/paramsValidator'; import { validatePath, getScriptType } from '../utils/pathUtils'; import { getBitcoinNetwork } from '../data/coinInfo'; import { PROTO } from '../constants'; @@ -18,7 +17,7 @@ export default class AuthorizeCoinjoin extends AbstractMethod< const address_n = validatePath(payload.path, 3); const script_type = payload.scriptType || getScriptType(address_n); const coinInfo = getBitcoinNetwork(payload.coin || address_n); - this.firmwareRange = getFirmwareRange(this.name, coinInfo, this.firmwareRange); + this.setFirmwareRange(this.name, coinInfo); this.preauthorized = payload.preauthorized; this.params = { diff --git a/packages/connect/src/api/binance/api/binanceGetAddress.ts b/packages/connect/src/api/binance/api/binanceGetAddress.ts index 7ae967f1ea4..69a1a7a9368 100644 --- a/packages/connect/src/api/binance/api/binanceGetAddress.ts +++ b/packages/connect/src/api/binance/api/binanceGetAddress.ts @@ -3,7 +3,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod, MethodReturnType } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath, fromHardened, getSerializedPath } from '../../../utils/pathUtils'; import { PROTO, ERRORS } from '../../../constants'; @@ -23,7 +22,7 @@ export default class BinanceGetAddress extends AbstractMethod<'binanceGetAddress this.noBackupConfirmationMode = 'always'; this.requiredPermissions = ['read']; this.requiredDeviceCapabilities = ['Capability_Binance']; - this.firmwareRange = getFirmwareRange(this.name, getMiscNetwork('BNB'), this.firmwareRange); + this.setFirmwareRange(this.name, getMiscNetwork('BNB')); // create a bundle with only one batch if bundle doesn't exists this.hasBundle = !!this.payload.bundle; diff --git a/packages/connect/src/api/binance/api/binanceGetPublicKey.ts b/packages/connect/src/api/binance/api/binanceGetPublicKey.ts index c9f15a1eb0b..373285b9bf3 100644 --- a/packages/connect/src/api/binance/api/binanceGetPublicKey.ts +++ b/packages/connect/src/api/binance/api/binanceGetPublicKey.ts @@ -3,7 +3,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod, MethodReturnType } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath, fromHardened, getSerializedPath } from '../../../utils/pathUtils'; import { UI, createUiMessage } from '../../../events'; @@ -19,7 +18,7 @@ export default class BinanceGetPublicKey extends AbstractMethod< init() { this.requiredPermissions = ['read']; this.requiredDeviceCapabilities = ['Capability_Binance']; - this.firmwareRange = getFirmwareRange(this.name, getMiscNetwork('BNB'), this.firmwareRange); + this.setFirmwareRange(this.name, getMiscNetwork('BNB')); // create a bundle with only one batch if bundle doesn't exists this.hasBundle = !!this.payload.bundle; diff --git a/packages/connect/src/api/binance/api/binanceSignTransaction.ts b/packages/connect/src/api/binance/api/binanceSignTransaction.ts index 9b82cb0f509..79598a57ed6 100644 --- a/packages/connect/src/api/binance/api/binanceSignTransaction.ts +++ b/packages/connect/src/api/binance/api/binanceSignTransaction.ts @@ -3,7 +3,6 @@ import { AssertWeak } from '@trezor/schema-utils'; import { AbstractMethod } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath } from '../../../utils/pathUtils'; import * as helper from '../binanceSignTx'; @@ -23,7 +22,7 @@ export default class BinanceSignTransaction extends AbstractMethod< init() { this.requiredPermissions = ['read', 'write']; this.requiredDeviceCapabilities = ['Capability_Binance']; - this.firmwareRange = getFirmwareRange(this.name, getMiscNetwork('BNB'), this.firmwareRange); + this.setFirmwareRange(this.name, getMiscNetwork('BNB')); const { payload } = this; // validate incoming parameters diff --git a/packages/connect/src/api/cancelCoinjoinAuthorization.ts b/packages/connect/src/api/cancelCoinjoinAuthorization.ts index c1f57db01d1..4c317b1d881 100644 --- a/packages/connect/src/api/cancelCoinjoinAuthorization.ts +++ b/packages/connect/src/api/cancelCoinjoinAuthorization.ts @@ -1,7 +1,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod } from '../core/AbstractMethod'; -import { getFirmwareRange } from './common/paramsValidator'; import { PROTO } from '../constants'; import { CancelCoinjoinAuthorization as CancelCoinjoinAuthorizationSchema } from '../types/api/cancelCoinjoinAuthorization'; @@ -14,7 +13,7 @@ export default class CancelCoinjoinAuthorization extends AbstractMethod< Assert(CancelCoinjoinAuthorizationSchema, payload); - this.firmwareRange = getFirmwareRange(this.name, null, this.firmwareRange); + this.setFirmwareRange(this.name, null); this.preauthorized = typeof payload.preauthorized === 'boolean' ? payload.preauthorized : true; } diff --git a/packages/connect/src/api/cardano/api/cardanoGetAddress.ts b/packages/connect/src/api/cardano/api/cardanoGetAddress.ts index e78ade2771a..b8cf73ea65a 100644 --- a/packages/connect/src/api/cardano/api/cardanoGetAddress.ts +++ b/packages/connect/src/api/cardano/api/cardanoGetAddress.ts @@ -3,7 +3,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod, MethodReturnType } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { fromHardened, getSerializedPath } from '../../../utils/pathUtils'; import { @@ -29,11 +28,7 @@ export default class CardanoGetAddress extends AbstractMethod<'cardanoGetAddress this.noBackupConfirmationMode = 'always'; this.requiredPermissions = ['read']; this.requiredDeviceCapabilities = ['Capability_Cardano']; - this.firmwareRange = getFirmwareRange( - this.name, - getMiscNetwork('Cardano'), - this.firmwareRange, - ); + this.setFirmwareRange(this.name, getMiscNetwork('Cardano')); // create a bundle with only one batch if bundle doesn't exists this.hasBundle = !!this.payload.bundle; diff --git a/packages/connect/src/api/cardano/api/cardanoGetNativeScriptHash.ts b/packages/connect/src/api/cardano/api/cardanoGetNativeScriptHash.ts index 57f616642bc..044896859f6 100644 --- a/packages/connect/src/api/cardano/api/cardanoGetNativeScriptHash.ts +++ b/packages/connect/src/api/cardano/api/cardanoGetNativeScriptHash.ts @@ -4,7 +4,6 @@ import { Assert } from '@trezor/schema-utils'; import { PROTO } from '../../../constants'; import { AbstractMethod } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath } from '../../../utils/pathUtils'; import { @@ -19,11 +18,7 @@ export default class CardanoGetNativeScriptHash extends AbstractMethod< init() { this.requiredPermissions = ['read']; this.requiredDeviceCapabilities = ['Capability_Cardano']; - this.firmwareRange = getFirmwareRange( - this.name, - getMiscNetwork('Cardano'), - this.firmwareRange, - ); + this.setFirmwareRange(this.name, getMiscNetwork('Cardano')); const { payload } = this; diff --git a/packages/connect/src/api/cardano/api/cardanoGetPublicKey.ts b/packages/connect/src/api/cardano/api/cardanoGetPublicKey.ts index 78a8fadff90..14dc3cf18f8 100644 --- a/packages/connect/src/api/cardano/api/cardanoGetPublicKey.ts +++ b/packages/connect/src/api/cardano/api/cardanoGetPublicKey.ts @@ -4,7 +4,6 @@ import { Assert } from '@trezor/schema-utils'; import { PROTO } from '../../../constants'; import { AbstractMethod, MethodReturnType } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath, fromHardened, getSerializedPath } from '../../../utils/pathUtils'; import { UI, createUiMessage } from '../../../events'; @@ -21,11 +20,7 @@ export default class CardanoGetPublicKey extends AbstractMethod<'cardanoGetPubli init() { this.requiredPermissions = ['read']; this.requiredDeviceCapabilities = ['Capability_Cardano']; - this.firmwareRange = getFirmwareRange( - this.name, - getMiscNetwork('Cardano'), - this.firmwareRange, - ); + this.setFirmwareRange(this.name, getMiscNetwork('Cardano')); // create a bundle with only one batch if bundle doesn't exists this.hasBundle = !!this.payload.bundle; diff --git a/packages/connect/src/api/cardano/api/cardanoSignTransaction.ts b/packages/connect/src/api/cardano/api/cardanoSignTransaction.ts index c780e77c505..8394cb8c41d 100644 --- a/packages/connect/src/api/cardano/api/cardanoSignTransaction.ts +++ b/packages/connect/src/api/cardano/api/cardanoSignTransaction.ts @@ -7,7 +7,6 @@ import { trezorUtils } from '@fivebinaries/coin-selection'; import { AssertWeak, Type } from '@trezor/schema-utils'; import { AbstractMethod } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath } from '../../../utils/pathUtils'; import { @@ -79,11 +78,7 @@ export default class CardanoSignTransaction extends AbstractMethod< init() { this.requiredPermissions = ['read', 'write']; this.requiredDeviceCapabilities = ['Capability_Cardano']; - this.firmwareRange = getFirmwareRange( - this.name, - getMiscNetwork('Cardano'), - this.firmwareRange, - ); + this.setFirmwareRange(this.name, getMiscNetwork('Cardano')); const { payload } = this; diff --git a/packages/connect/src/api/cipherKeyValue.ts b/packages/connect/src/api/cipherKeyValue.ts index 4a45b211928..953ac9aa27b 100644 --- a/packages/connect/src/api/cipherKeyValue.ts +++ b/packages/connect/src/api/cipherKeyValue.ts @@ -4,7 +4,6 @@ import { Assert } from '@trezor/schema-utils'; import { UI, createUiMessage } from '../events'; import { AbstractMethod } from '../core/AbstractMethod'; -import { getFirmwareRange } from './common/paramsValidator'; import { validatePath } from '../utils/pathUtils'; import type { PROTO } from '../constants'; import { Bundle } from '../types/params'; @@ -18,7 +17,7 @@ export default class CipherKeyValue extends AbstractMethod< init() { this.requiredPermissions = ['read', 'write']; - this.firmwareRange = getFirmwareRange(this.name, null, this.firmwareRange); + this.setFirmwareRange(this.name, null); // create a bundle with only one batch if bundle doesn't exists this.hasBundle = !!this.payload.bundle; diff --git a/packages/connect/src/api/common/__tests__/paramsValidator.test.ts b/packages/connect/src/api/common/__tests__/paramsValidator.test.ts index e79e709f562..950ea8d27c7 100644 --- a/packages/connect/src/api/common/__tests__/paramsValidator.test.ts +++ b/packages/connect/src/api/common/__tests__/paramsValidator.test.ts @@ -17,34 +17,4 @@ describe('helpers/paramsValidator', () => { }); }); }); - - describe('getFirmwareRange', () => { - afterEach(() => { - jest.clearAllMocks(); - }); - fixtures.getFirmwareRange.forEach(f => { - it(f.description, () => { - return new Promise(done => { - jest.resetModules(); - - const mock = f.config; - jest.mock('../../../data/config', () => { - const actualConfig = jest.requireActual('../../../data/config').config; - - return { - __esModule: true, - config: mock || actualConfig, - }; - }); - - import('../paramsValidator').then(({ getFirmwareRange }) => { - // added new capability - // @ts-expect-error - expect(getFirmwareRange(...f.params)).toEqual(f.result); - done(); - }); - }); - }); - }); - }); }); diff --git a/packages/connect/src/api/common/paramsValidator.ts b/packages/connect/src/api/common/paramsValidator.ts index b23a0bc0882..08562d1cb2c 100644 --- a/packages/connect/src/api/common/paramsValidator.ts +++ b/packages/connect/src/api/common/paramsValidator.ts @@ -1,10 +1,8 @@ // origin: https://github.com/trezor/connect/blob/develop/src/js/core/methods/helpers/paramsValidator.js -import { versionUtils } from '@trezor/utils'; import { ERRORS } from '../../constants'; import { fromHardened } from '../../utils/pathUtils'; -import { config } from '../../data/config'; -import type { CoinInfo, FirmwareRange, DeviceModelInternal } from '../../types'; +import type { CoinInfo } from '../../types'; type ParamType = 'string' | 'number' | 'array' | 'array-buffer' | 'boolean' | 'uint' | 'object'; @@ -99,103 +97,3 @@ export const validateCoinPath = (path: number[], coinInfo?: CoinInfo) => { throw invalidParameter('Parameters "path" and "coin" do not match.'); } }; - -export const getFirmwareRange = ( - method: string, - coinInfo: CoinInfo | null | undefined, - currentRange: FirmwareRange, -) => { - const range = JSON.parse(JSON.stringify(currentRange)) as FirmwareRange; - const models = Object.keys(range) as DeviceModelInternal[]; - // set minimum required firmware from coins.json (coinInfo) - if (coinInfo) { - models.forEach(model => { - const supportVersion = coinInfo.support ? coinInfo.support[model] : false; - if (supportVersion === false) { - range[model].min = '0'; - } else if ( - range[model].min !== '0' && - typeof supportVersion === 'string' && - versionUtils.isNewer(supportVersion, range[model].min) - ) { - range[model].min = supportVersion; - } - }); - } - - const coinType = coinInfo?.type; - const shortcut = coinInfo?.shortcut.toLowerCase(); - // find firmware range in config.json - const configRules = config.supportedFirmware - .filter(rule => { - // check if rule applies to requested method - if (rule.methods) { - return rule.methods.includes(method); - } - // check if rule applies to capability - if (rule.capabilities) { - return rule.capabilities.includes(method); - } - - // rule doesn't have specified methods - // it may be a global rule for coin or coinType - return true; - }) - .filter(rule => { - // REF_TODO: there is no coinType in config. possibly obsolete code? - // probably still useful, we just need to define type for config and not infer it. - // @ts-expect-error - if (rule.coinType) { - // rule for coin type - // @ts-expect-error - return rule.coinType === coinType; - } - if (rule.coin) { - // rule for coin shortcut - // @ts-expect-error - return (typeof rule.coin === 'string' ? [rule.coin] : rule.coin).includes(shortcut); - } - - // rule for method - return rule.methods || rule.capabilities; - }); - - configRules.forEach(rule => { - // override defaults - // NOTE: - // 0 may be confusing. means: no-support for "min" and unlimited support for "max" - if (rule.min) { - models.forEach(model => { - const modelMin = (rule.min as Record)[ - model - ]; - if (modelMin) { - if ( - modelMin === '0' || - range[model].min === '0' || - !versionUtils.isNewerOrEqual(range[model].min, modelMin) - ) { - range[model].min = modelMin; - } - } - }); - } - if (rule.max) { - models.forEach(model => { - // @ts-expect-error same issue as in coinType above, config needs to be typed not inferred. - const modelMax = rule.max[model]; - if (modelMax) { - if ( - modelMax === '0' || - range[model].max === '0' || - !versionUtils.isNewerOrEqual(range[model].max, modelMax) - ) { - range[model].max = modelMax; - } - } - }); - } - }); - - return range; -}; diff --git a/packages/connect/src/api/composeTransaction.ts b/packages/connect/src/api/composeTransaction.ts index f72749c222d..fbb148b6526 100644 --- a/packages/connect/src/api/composeTransaction.ts +++ b/packages/connect/src/api/composeTransaction.ts @@ -7,7 +7,7 @@ import { AbstractMethod } from '../core/AbstractMethod'; import { ERRORS } from '../constants'; import { UI, createUiMessage } from '../events'; import { Discovery } from './common/Discovery'; -import { validateParams, getFirmwareRange } from './common/paramsValidator'; +import { validateParams } from './common/paramsValidator'; import * as pathUtils from '../utils/pathUtils'; import { resolveAfter } from '../utils/promiseUtils'; import { formatAmount } from '../utils/formatUtils'; @@ -92,7 +92,7 @@ export default class ComposeTransaction extends AbstractMethod<'composeTransacti isBackendSupported(coinInfo); // set required firmware from coinInfo support - this.firmwareRange = getFirmwareRange(this.name, coinInfo, this.firmwareRange); + this.setFirmwareRange(this.name, coinInfo); // validate each output and transform into @trezor/utxo-lib/compose format const outputs: ComposeOutput[] = []; diff --git a/packages/connect/src/api/eos/api/eosGetPublicKey.ts b/packages/connect/src/api/eos/api/eosGetPublicKey.ts index e4a61d2e140..714ed2320c4 100644 --- a/packages/connect/src/api/eos/api/eosGetPublicKey.ts +++ b/packages/connect/src/api/eos/api/eosGetPublicKey.ts @@ -3,7 +3,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod, MethodReturnType } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath, fromHardened, getSerializedPath } from '../../../utils/pathUtils'; import { UI, createUiMessage } from '../../../events'; @@ -19,7 +18,7 @@ export default class EosGetPublicKey extends AbstractMethod< init() { this.requiredPermissions = ['read']; this.requiredDeviceCapabilities = ['Capability_EOS']; - this.firmwareRange = getFirmwareRange(this.name, getMiscNetwork('EOS'), this.firmwareRange); + this.setFirmwareRange(this.name, getMiscNetwork('EOS')); // create a bundle with only one batch if bundle doesn't exists this.hasBundle = !!this.payload.bundle; diff --git a/packages/connect/src/api/eos/api/eosSignTransaction.ts b/packages/connect/src/api/eos/api/eosSignTransaction.ts index 67d3653764d..4b510f4170c 100644 --- a/packages/connect/src/api/eos/api/eosSignTransaction.ts +++ b/packages/connect/src/api/eos/api/eosSignTransaction.ts @@ -3,7 +3,6 @@ import { AssertWeak } from '@trezor/schema-utils'; import { AbstractMethod } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath } from '../../../utils/pathUtils'; import * as helper from '../eosSignTx'; @@ -22,7 +21,7 @@ export default class EosSignTransaction extends AbstractMethod<'eosSignTransacti init() { this.requiredPermissions = ['read', 'write']; this.requiredDeviceCapabilities = ['Capability_EOS']; - this.firmwareRange = getFirmwareRange(this.name, getMiscNetwork('EOS'), this.firmwareRange); + this.setFirmwareRange(this.name, getMiscNetwork('EOS')); const { payload } = this; // validate incoming parameters diff --git a/packages/connect/src/api/ethereum/api/ethereumGetAddress.ts b/packages/connect/src/api/ethereum/api/ethereumGetAddress.ts index 03c46401a43..a2352fa53b4 100644 --- a/packages/connect/src/api/ethereum/api/ethereumGetAddress.ts +++ b/packages/connect/src/api/ethereum/api/ethereumGetAddress.ts @@ -3,7 +3,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod, MethodReturnType } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { validatePath, getSerializedPath, getSlip44ByPath } from '../../../utils/pathUtils'; import { getNetworkLabel } from '../../../utils/ethereumUtils'; import { getEthereumNetwork, getUniqueNetworks } from '../../../data/coinInfo'; @@ -46,7 +45,7 @@ export default class EthereumGetAddress extends AbstractMethod<'ethereumGetAddre this.params = payload.bundle.map(batch => { const path = validatePath(batch.path, 3); const network = getEthereumNetwork(path); - this.firmwareRange = getFirmwareRange(this.name, network, this.firmwareRange); + this.setFirmwareRange(this.name, network); return { address_n: path, diff --git a/packages/connect/src/api/ethereum/api/ethereumGetPublicKey.ts b/packages/connect/src/api/ethereum/api/ethereumGetPublicKey.ts index f0f7d919bf8..d0651c35c67 100644 --- a/packages/connect/src/api/ethereum/api/ethereumGetPublicKey.ts +++ b/packages/connect/src/api/ethereum/api/ethereumGetPublicKey.ts @@ -3,7 +3,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod, MethodReturnType } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { validatePath } from '../../../utils/pathUtils'; import { getNetworkLabel } from '../../../utils/ethereumUtils'; import { getEthereumNetwork, getUniqueNetworks } from '../../../data/coinInfo'; @@ -35,7 +34,7 @@ export default class EthereumGetPublicKey extends AbstractMethod<'ethereumGetPub this.params = payload.bundle.map(batch => { const path = validatePath(batch.path, 3); const network = getEthereumNetwork(path); - this.firmwareRange = getFirmwareRange(this.name, network, this.firmwareRange); + this.setFirmwareRange(this.name, network); return { address_n: path, diff --git a/packages/connect/src/api/ethereum/api/ethereumSignMessage.ts b/packages/connect/src/api/ethereum/api/ethereumSignMessage.ts index 2b5d9a23437..60559162711 100644 --- a/packages/connect/src/api/ethereum/api/ethereumSignMessage.ts +++ b/packages/connect/src/api/ethereum/api/ethereumSignMessage.ts @@ -4,7 +4,6 @@ import { MessagesSchema } from '@trezor/protobuf'; import { Assert } from '@trezor/schema-utils'; import { AbstractMethod } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getSlip44ByPath, validatePath } from '../../../utils/pathUtils'; import { getEthereumNetwork } from '../../../data/coinInfo'; import { getNetworkLabel } from '../../../utils/ethereumUtils'; @@ -33,7 +32,7 @@ export default class EthereumSignMessage extends AbstractMethod<'ethereumSignMes const path = validatePath(payload.path, 3); const network = getEthereumNetwork(path); - this.firmwareRange = getFirmwareRange(this.name, network, this.firmwareRange); + this.setFirmwareRange(this.name, network); const messageHex = payload.hex ? messageToHex(payload.message) diff --git a/packages/connect/src/api/ethereum/api/ethereumSignTransaction.ts b/packages/connect/src/api/ethereum/api/ethereumSignTransaction.ts index cf1c4e8943f..b305b1719c2 100644 --- a/packages/connect/src/api/ethereum/api/ethereumSignTransaction.ts +++ b/packages/connect/src/api/ethereum/api/ethereumSignTransaction.ts @@ -6,7 +6,6 @@ import { MessagesSchema } from '@trezor/protobuf'; import { Assert } from '@trezor/schema-utils'; import { AbstractMethod } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getSlip44ByPath, validatePath } from '../../../utils/pathUtils'; import { getEthereumNetwork } from '../../../data/coinInfo'; import { getNetworkLabel } from '../../../utils/ethereumUtils'; @@ -73,11 +72,7 @@ export default class EthereumSignTransaction extends AbstractMethod< // get firmware range depending on used transaction type // eip1559 is possible since 2.4.2 - this.firmwareRange = getFirmwareRange( - isEIP1559 ? 'eip1559' : this.name, - network, - this.firmwareRange, - ); + this.setFirmwareRange(isEIP1559 ? 'eip1559' : this.name, network); if (isEIP1559) { this.params = { path, network, type: 'eip1559', tx: strip(tx), chunkify }; diff --git a/packages/connect/src/api/ethereum/api/ethereumSignTypedData.ts b/packages/connect/src/api/ethereum/api/ethereumSignTypedData.ts index ab27f21c2e2..30eae79a810 100644 --- a/packages/connect/src/api/ethereum/api/ethereumSignTypedData.ts +++ b/packages/connect/src/api/ethereum/api/ethereumSignTypedData.ts @@ -4,7 +4,6 @@ import { MessagesSchema } from '@trezor/protobuf'; import { Assert, Type } from '@trezor/schema-utils'; import { AbstractMethod } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getSlip44ByPath, validatePath } from '../../../utils/pathUtils'; import { getEthereumNetwork } from '../../../data/coinInfo'; import { getNetworkLabel } from '../../../utils/ethereumUtils'; @@ -52,7 +51,7 @@ export default class EthereumSignTypedData extends AbstractMethod<'ethereumSignT const path = validatePath(payload.path, 3); const network = getEthereumNetwork(path); - this.firmwareRange = getFirmwareRange(this.name, network, this.firmwareRange); + this.setFirmwareRange(this.name, network); this.params = { address_n: path, @@ -85,11 +84,7 @@ export default class EthereumSignTypedData extends AbstractMethod<'ethereumSignT if (this.params.data.primaryType === 'EIP712Domain') { // Only newer firmwares support this feature // Older firmwares will give wrong results / throw errors - this.firmwareRange = getFirmwareRange( - 'eip712-domain-only', - network, - this.firmwareRange, - ); + this.setFirmwareRange('eip712-domain-only', network); if ('message_hash' in this.params) { throw ERRORS.TypedError( diff --git a/packages/connect/src/api/ethereum/api/ethereumVerifyMessage.ts b/packages/connect/src/api/ethereum/api/ethereumVerifyMessage.ts index ba89fa88e77..8aa359c4678 100644 --- a/packages/connect/src/api/ethereum/api/ethereumVerifyMessage.ts +++ b/packages/connect/src/api/ethereum/api/ethereumVerifyMessage.ts @@ -3,7 +3,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { stripHexPrefix, messageToHex } from '../../../utils/formatUtils'; import type { PROTO } from '../../../constants'; import { EthereumVerifyMessage as EthereumVerifyMessageSchema } from '../../../types'; @@ -14,7 +13,7 @@ export default class EthereumVerifyMessage extends AbstractMethod< > { init() { this.requiredPermissions = ['read', 'write']; - this.firmwareRange = getFirmwareRange(this.name, null, this.firmwareRange); + this.setFirmwareRange(this.name, null); this.requiredDeviceCapabilities = ['Capability_Ethereum']; const { payload } = this; diff --git a/packages/connect/src/api/getAccountDescriptor.ts b/packages/connect/src/api/getAccountDescriptor.ts index 1e5417a4916..a8bb97ff5e6 100644 --- a/packages/connect/src/api/getAccountDescriptor.ts +++ b/packages/connect/src/api/getAccountDescriptor.ts @@ -1,7 +1,6 @@ import { Assert } from '@trezor/schema-utils'; -import { AbstractMethod, MethodReturnType, DEFAULT_FIRMWARE_RANGE } from '../core/AbstractMethod'; -import { getFirmwareRange } from './common/paramsValidator'; +import { AbstractMethod, MethodReturnType } from '../core/AbstractMethod'; import { validatePath, getSerializedPath } from '../utils/pathUtils'; import { getAccountLabel } from '../utils/accountUtils'; import { getCoinInfo } from '../data/coinInfo'; @@ -46,7 +45,7 @@ export default class GetAccountDescriptor extends AbstractMethod< const address_n = validatePath(batch.path, 3); // set firmware range - this.firmwareRange = getFirmwareRange(this.name, coinInfo, this.firmwareRange); + this.setFirmwareRange(this.name, coinInfo); return { ...batch, @@ -110,11 +109,7 @@ export default class GetAccountDescriptor extends AbstractMethod< const invalid = []; for (let i = 0; i < this.params.length; i++) { // set FW range for current batch - this.firmwareRange = getFirmwareRange( - this.name, - this.params[i].coinInfo, - DEFAULT_FIRMWARE_RANGE, - ); + this.setFirmwareRange(this.name, this.params[i].coinInfo); const exception = super.checkFirmwareRange(); if (exception) { invalid.push({ diff --git a/packages/connect/src/api/getAccountInfo.ts b/packages/connect/src/api/getAccountInfo.ts index a59e591287e..12027fecf62 100644 --- a/packages/connect/src/api/getAccountInfo.ts +++ b/packages/connect/src/api/getAccountInfo.ts @@ -1,8 +1,8 @@ // origin: https://github.com/trezor/connect/blob/develop/src/js/core/methods/GetAccountInfo.js -import { AbstractMethod, MethodReturnType, DEFAULT_FIRMWARE_RANGE } from '../core/AbstractMethod'; +import { AbstractMethod, MethodReturnType } from '../core/AbstractMethod'; import { Discovery } from './common/Discovery'; -import { validateParams, getFirmwareRange } from './common/paramsValidator'; +import { validateParams } from './common/paramsValidator'; import { validatePath, getSerializedPath } from '../utils/pathUtils'; import { getAccountLabel, isUtxoBased } from '../utils/accountUtils'; import { resolveAfter } from '../utils/promiseUtils'; @@ -82,7 +82,7 @@ export default class GetAccountInfo extends AbstractMethod<'getAccountInfo', Req } // set firmware range - this.firmwareRange = getFirmwareRange(this.name, coinInfo, this.firmwareRange); + this.setFirmwareRange(this.name, coinInfo); return { ...batch, @@ -165,11 +165,7 @@ export default class GetAccountInfo extends AbstractMethod<'getAccountInfo', Req const invalid = []; for (let i = 0; i < this.params.length; i++) { // set FW range for current batch - this.firmwareRange = getFirmwareRange( - this.name, - this.params[i].coinInfo, - DEFAULT_FIRMWARE_RANGE, - ); + this.setFirmwareRange(this.name, this.params[i].coinInfo); const exception = super.checkFirmwareRange(); if (exception) { invalid.push({ diff --git a/packages/connect/src/api/getAddress.ts b/packages/connect/src/api/getAddress.ts index bdf7140ecb3..68d8d4157df 100644 --- a/packages/connect/src/api/getAddress.ts +++ b/packages/connect/src/api/getAddress.ts @@ -3,7 +3,7 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod, MethodReturnType } from '../core/AbstractMethod'; -import { validateCoinPath, getFirmwareRange } from './common/paramsValidator'; +import { validateCoinPath } from './common/paramsValidator'; import { validatePath, getLabel, getSerializedPath } from '../utils/pathUtils'; import { getBitcoinNetwork, fixCoinInfoNetwork, getUniqueNetworks } from '../data/coinInfo'; import { PROTO, ERRORS } from '../constants'; @@ -59,7 +59,7 @@ export default class GetAddress extends AbstractMethod<'getAddress', Params[]> { throw ERRORS.TypedError('Method_UnknownCoin'); } else if (coinInfo) { // set required firmware from coinInfo support - this.firmwareRange = getFirmwareRange(this.name, coinInfo, this.firmwareRange); + this.setFirmwareRange(this.name, coinInfo); } // fix coinInfo network values (segwit/legacy) diff --git a/packages/connect/src/api/getFirmwareHash.ts b/packages/connect/src/api/getFirmwareHash.ts index 933ba5c4384..32e1f158aaf 100644 --- a/packages/connect/src/api/getFirmwareHash.ts +++ b/packages/connect/src/api/getFirmwareHash.ts @@ -3,7 +3,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod } from '../core/AbstractMethod'; import { PROTO } from '../constants'; import { UI } from '../events'; -import { getFirmwareRange } from './common/paramsValidator'; export default class GetFirmwareHash extends AbstractMethod< 'getFirmwareHash', @@ -19,7 +18,7 @@ export default class GetFirmwareHash extends AbstractMethod< Assert(PROTO.GetFirmwareHash, payload); - this.firmwareRange = getFirmwareRange(this.name, null, this.firmwareRange); + this.setFirmwareRange(this.name, null); this.params = { challenge: payload.challenge, diff --git a/packages/connect/src/api/getOwnershipId.ts b/packages/connect/src/api/getOwnershipId.ts index 440fbea6423..06d17838edf 100644 --- a/packages/connect/src/api/getOwnershipId.ts +++ b/packages/connect/src/api/getOwnershipId.ts @@ -1,7 +1,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod, MethodReturnType } from '../core/AbstractMethod'; -import { getFirmwareRange } from './common/paramsValidator'; import { validatePath, getScriptType, getSerializedPath } from '../utils/pathUtils'; import { getBitcoinNetwork } from '../data/coinInfo'; import { PROTO } from '../constants'; @@ -31,7 +30,7 @@ export default class GetOwnershipId extends AbstractMethod< const address_n = validatePath(batch.path, 1); const coinInfo = getBitcoinNetwork(batch.coin || address_n); const script_type = batch.scriptType || getScriptType(address_n); - this.firmwareRange = getFirmwareRange(this.name, coinInfo, this.firmwareRange); + this.setFirmwareRange(this.name, coinInfo); return { address_n, diff --git a/packages/connect/src/api/getOwnershipProof.ts b/packages/connect/src/api/getOwnershipProof.ts index eb8c4c7a195..8eec049eea7 100644 --- a/packages/connect/src/api/getOwnershipProof.ts +++ b/packages/connect/src/api/getOwnershipProof.ts @@ -1,7 +1,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod, MethodReturnType } from '../core/AbstractMethod'; -import { getFirmwareRange } from './common/paramsValidator'; import { validatePath, getScriptType, getSerializedPath } from '../utils/pathUtils'; import { getBitcoinNetwork } from '../data/coinInfo'; import { PROTO } from '../constants'; @@ -31,7 +30,7 @@ export default class GetOwnershipProof extends AbstractMethod< const address_n = validatePath(batch.path, 1); const coinInfo = getBitcoinNetwork(batch.coin || address_n); const script_type = batch.scriptType || getScriptType(address_n); - this.firmwareRange = getFirmwareRange(this.name, coinInfo, this.firmwareRange); + this.setFirmwareRange(this.name, coinInfo); if (batch.preauthorized) { this.preauthorized = batch.preauthorized; } diff --git a/packages/connect/src/api/getPublicKey.ts b/packages/connect/src/api/getPublicKey.ts index c21b4a0455e..de390f54806 100644 --- a/packages/connect/src/api/getPublicKey.ts +++ b/packages/connect/src/api/getPublicKey.ts @@ -3,7 +3,7 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod, MethodReturnType } from '../core/AbstractMethod'; -import { validateCoinPath, getFirmwareRange } from './common/paramsValidator'; +import { validateCoinPath } from './common/paramsValidator'; import { validatePath } from '../utils/pathUtils'; import { UI, createUiMessage } from '../events'; import { getBitcoinNetwork } from '../data/coinInfo'; @@ -52,7 +52,7 @@ export default class GetPublicKey extends AbstractMethod<'getPublicKey', Params[ } // set required firmware from coinInfo support - this.firmwareRange = getFirmwareRange(this.name, coinInfo, this.firmwareRange); + this.setFirmwareRange(this.name, coinInfo); return { address_n, diff --git a/packages/connect/src/api/loadDevice.ts b/packages/connect/src/api/loadDevice.ts index 53827718a22..3629a4a54d1 100644 --- a/packages/connect/src/api/loadDevice.ts +++ b/packages/connect/src/api/loadDevice.ts @@ -2,7 +2,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod } from '../core/AbstractMethod'; import { UI } from '../events'; -import { getFirmwareRange } from './common/paramsValidator'; import { PROTO } from '../constants'; export default class LoadDevice extends AbstractMethod<'loadDevice', PROTO.LoadDevice> { @@ -10,7 +9,7 @@ export default class LoadDevice extends AbstractMethod<'loadDevice', PROTO.LoadD this.allowDeviceMode = [UI.INITIALIZE]; this.useDeviceState = false; this.requiredPermissions = ['management']; - this.firmwareRange = getFirmwareRange(this.name, null, this.firmwareRange); + this.setFirmwareRange(this.name, null); const { payload } = this; // validate bundle type diff --git a/packages/connect/src/api/nem/api/nemGetAddress.ts b/packages/connect/src/api/nem/api/nemGetAddress.ts index 931aea0c0be..6aa30a69a96 100644 --- a/packages/connect/src/api/nem/api/nemGetAddress.ts +++ b/packages/connect/src/api/nem/api/nemGetAddress.ts @@ -3,7 +3,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod, MethodReturnType } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath, fromHardened, getSerializedPath } from '../../../utils/pathUtils'; import { PROTO, ERRORS } from '../../../constants'; @@ -27,7 +26,7 @@ export default class NEMGetAddress extends AbstractMethod<'nemGetAddress', Param this.noBackupConfirmationMode = 'always'; this.requiredPermissions = ['read']; this.requiredDeviceCapabilities = ['Capability_NEM']; - this.firmwareRange = getFirmwareRange(this.name, getMiscNetwork('NEM'), this.firmwareRange); + this.setFirmwareRange(this.name, getMiscNetwork('NEM')); // create a bundle with only one batch if bundle doesn't exists this.hasBundle = !!this.payload.bundle; diff --git a/packages/connect/src/api/nem/api/nemSignTransaction.ts b/packages/connect/src/api/nem/api/nemSignTransaction.ts index 086371e2b02..c7c481bf884 100644 --- a/packages/connect/src/api/nem/api/nemSignTransaction.ts +++ b/packages/connect/src/api/nem/api/nemSignTransaction.ts @@ -3,7 +3,6 @@ import { AssertWeak } from '@trezor/schema-utils'; import { AbstractMethod } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath } from '../../../utils/pathUtils'; import * as helper from '../nemSignTx'; @@ -17,7 +16,7 @@ export default class NEMSignTransaction extends AbstractMethod< init() { this.requiredPermissions = ['read', 'write']; this.requiredDeviceCapabilities = ['Capability_NEM']; - this.firmwareRange = getFirmwareRange(this.name, getMiscNetwork('NEM'), this.firmwareRange); + this.setFirmwareRange(this.name, getMiscNetwork('NEM')); const { payload } = this; // validate incoming parameters diff --git a/packages/connect/src/api/rebootToBootloader.ts b/packages/connect/src/api/rebootToBootloader.ts index e3f25c3729d..39a18dcfc9b 100644 --- a/packages/connect/src/api/rebootToBootloader.ts +++ b/packages/connect/src/api/rebootToBootloader.ts @@ -3,7 +3,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod } from '../core/AbstractMethod'; -import { getFirmwareRange } from './common/paramsValidator'; import { UI } from '../events'; import { PROTO } from '../constants'; @@ -17,7 +16,7 @@ export default class RebootToBootloader extends AbstractMethod< this.keepSession = false; this.requiredPermissions = ['management']; this.useDeviceState = false; - this.firmwareRange = getFirmwareRange(this.name, null, this.firmwareRange); + this.setFirmwareRange(this.name, null); const { payload } = this; Assert(PROTO.RebootToBootloader, payload); diff --git a/packages/connect/src/api/requestLogin.ts b/packages/connect/src/api/requestLogin.ts index 0dbf2e8d719..5b39b4e3372 100644 --- a/packages/connect/src/api/requestLogin.ts +++ b/packages/connect/src/api/requestLogin.ts @@ -3,7 +3,6 @@ import { Assert, Type } from '@trezor/schema-utils'; import { AbstractMethod } from '../core/AbstractMethod'; -import { getFirmwareRange } from './common/paramsValidator'; import { ERRORS } from '../constants'; import { UI, createUiMessage } from '../events'; import { DataManager } from '../data/DataManager'; @@ -16,7 +15,7 @@ export default class RequestLogin extends AbstractMethod<'requestLogin', PROTO.S init() { this.requiredPermissions = ['read', 'write']; - this.firmwareRange = getFirmwareRange(this.name, null, this.firmwareRange); + this.setFirmwareRange(this.name, null); this.useEmptyPassphrase = true; const { payload } = this; diff --git a/packages/connect/src/api/resetDevice.ts b/packages/connect/src/api/resetDevice.ts index d19f695c271..c68ad8387e7 100644 --- a/packages/connect/src/api/resetDevice.ts +++ b/packages/connect/src/api/resetDevice.ts @@ -4,7 +4,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod } from '../core/AbstractMethod'; import { UI } from '../events'; -import { getFirmwareRange } from './common/paramsValidator'; import { PROTO } from '../constants'; export default class ResetDevice extends AbstractMethod<'resetDevice', PROTO.ResetDevice> { @@ -12,7 +11,7 @@ export default class ResetDevice extends AbstractMethod<'resetDevice', PROTO.Res this.allowDeviceMode = [UI.INITIALIZE, UI.SEEDLESS]; this.useDeviceState = false; this.requiredPermissions = ['management']; - this.firmwareRange = getFirmwareRange(this.name, null, this.firmwareRange); + this.setFirmwareRange(this.name, null); const { payload } = this; // validate bundle type diff --git a/packages/connect/src/api/ripple/api/rippleGetAddress.ts b/packages/connect/src/api/ripple/api/rippleGetAddress.ts index d8ca192d78e..c235b2e9908 100644 --- a/packages/connect/src/api/ripple/api/rippleGetAddress.ts +++ b/packages/connect/src/api/ripple/api/rippleGetAddress.ts @@ -3,7 +3,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod, MethodReturnType } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath, fromHardened, getSerializedPath } from '../../../utils/pathUtils'; import { PROTO, ERRORS } from '../../../constants'; @@ -23,11 +22,7 @@ export default class RippleGetAddress extends AbstractMethod<'rippleGetAddress', this.noBackupConfirmationMode = 'always'; this.requiredPermissions = ['read']; this.requiredDeviceCapabilities = ['Capability_Ripple']; - this.firmwareRange = getFirmwareRange( - this.name, - getMiscNetwork('Ripple'), - this.firmwareRange, - ); + this.setFirmwareRange(this.name, getMiscNetwork('Ripple')); // create a bundle with only one batch if bundle doesn't exists this.hasBundle = !!this.payload.bundle; diff --git a/packages/connect/src/api/ripple/api/rippleSignTransaction.ts b/packages/connect/src/api/ripple/api/rippleSignTransaction.ts index a53e64a3971..7f0a6cd7714 100644 --- a/packages/connect/src/api/ripple/api/rippleSignTransaction.ts +++ b/packages/connect/src/api/ripple/api/rippleSignTransaction.ts @@ -3,7 +3,6 @@ import { AssertWeak } from '@trezor/schema-utils'; import { AbstractMethod } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath } from '../../../utils/pathUtils'; import type { PROTO } from '../../../constants'; @@ -16,11 +15,7 @@ export default class RippleSignTransaction extends AbstractMethod< init() { this.requiredPermissions = ['read', 'write']; this.requiredDeviceCapabilities = ['Capability_Ripple']; - this.firmwareRange = getFirmwareRange( - this.name, - getMiscNetwork('Ripple'), - this.firmwareRange, - ); + this.setFirmwareRange(this.name, getMiscNetwork('Ripple')); const { payload } = this; // validate incoming parameters diff --git a/packages/connect/src/api/setBusy.ts b/packages/connect/src/api/setBusy.ts index 67940bbfedb..be1e7c41e75 100644 --- a/packages/connect/src/api/setBusy.ts +++ b/packages/connect/src/api/setBusy.ts @@ -3,7 +3,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod } from '../core/AbstractMethod'; import { DEVICE, createDeviceMessage } from '../events'; import { PROTO } from '../constants'; -import { getFirmwareRange } from './common/paramsValidator'; export default class SetBusy extends AbstractMethod<'setBusy', PROTO.SetBusy> { init() { @@ -14,7 +13,7 @@ export default class SetBusy extends AbstractMethod<'setBusy', PROTO.SetBusy> { Assert(PROTO.SetBusy, payload); - this.firmwareRange = getFirmwareRange(this.name, undefined, this.firmwareRange); + this.setFirmwareRange(this.name, undefined); this.params = { expiry_ms: payload.expiry_ms, diff --git a/packages/connect/src/api/showDeviceTutorial.ts b/packages/connect/src/api/showDeviceTutorial.ts index 59fc98be5d9..5f6dc962727 100644 --- a/packages/connect/src/api/showDeviceTutorial.ts +++ b/packages/connect/src/api/showDeviceTutorial.ts @@ -1,5 +1,4 @@ import { AbstractMethod } from '../core/AbstractMethod'; -import { getFirmwareRange } from './common/paramsValidator'; import { PROTO } from '../constants'; import { UI } from '../events'; @@ -8,7 +7,7 @@ export default class ShowDeviceTutorial extends AbstractMethod< PROTO.ShowDeviceTutorial > { init() { - this.firmwareRange = getFirmwareRange(this.name, null, this.firmwareRange); + this.setFirmwareRange(this.name, null); this.useEmptyPassphrase = true; this.useDeviceState = false; this.allowDeviceMode = [UI.INITIALIZE]; diff --git a/packages/connect/src/api/signMessage.ts b/packages/connect/src/api/signMessage.ts index d8c9b2eefa7..2c7a11f0bbc 100644 --- a/packages/connect/src/api/signMessage.ts +++ b/packages/connect/src/api/signMessage.ts @@ -3,7 +3,7 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod } from '../core/AbstractMethod'; -import { validateCoinPath, getFirmwareRange } from './common/paramsValidator'; +import { validateCoinPath } from './common/paramsValidator'; import { validatePath, getLabel, getScriptType } from '../utils/pathUtils'; import { getBitcoinNetwork } from '../data/coinInfo'; import { messageToHex } from '../utils/formatUtils'; @@ -31,10 +31,9 @@ export default class SignMessage extends AbstractMethod<'signMessage', PROTO.Sig // firmware range depends on used no_script_type parameter // no_script_type is possible since 1.10.4 / 2.4.3 - this.firmwareRange = getFirmwareRange( + this.setFirmwareRange( payload.no_script_type ? 'signMessageNoScriptType' : this.name, coinInfo, - this.firmwareRange, ); const messageHex = payload.hex diff --git a/packages/connect/src/api/signTransaction.ts b/packages/connect/src/api/signTransaction.ts index b24c6d2e1b9..40f293ac2d8 100644 --- a/packages/connect/src/api/signTransaction.ts +++ b/packages/connect/src/api/signTransaction.ts @@ -3,7 +3,7 @@ import { BigNumber } from '@trezor/utils/src/bigNumber'; import { AbstractMethod } from '../core/AbstractMethod'; -import { validateParams, getFirmwareRange } from './common/paramsValidator'; +import { validateParams } from './common/paramsValidator'; import { getBitcoinNetwork } from '../data/coinInfo'; import { getLabel } from '../utils/pathUtils'; import { PROTO, ERRORS } from '../constants'; @@ -87,7 +87,7 @@ export default class SignTransaction extends AbstractMethod<'signTransaction', P throw ERRORS.TypedError('Method_UnknownCoin'); } // set required firmware from coinInfo support - this.firmwareRange = getFirmwareRange(this.name, coinInfo, this.firmwareRange); + this.setFirmwareRange(this.name, coinInfo); this.preauthorized = payload.preauthorized; const inputs = validateTrezorInputs(payload.inputs, coinInfo); diff --git a/packages/connect/src/api/solana/api/solanaGetAddress.ts b/packages/connect/src/api/solana/api/solanaGetAddress.ts index 793954c9cca..b2a04ee117a 100644 --- a/packages/connect/src/api/solana/api/solanaGetAddress.ts +++ b/packages/connect/src/api/solana/api/solanaGetAddress.ts @@ -2,7 +2,6 @@ import { Assert } from '@trezor/schema-utils'; import { ERRORS, PROTO } from '../../../constants'; import { AbstractMethod, MethodReturnType } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath, fromHardened, getSerializedPath } from '../../../utils/pathUtils'; import { UI, createUiMessage } from '../../../events'; @@ -21,11 +20,7 @@ export default class SolanaGetAddress extends AbstractMethod<'solanaGetAddress', this.noBackupConfirmationMode = 'always'; this.requiredPermissions = ['read']; this.requiredDeviceCapabilities = ['Capability_Solana']; - this.firmwareRange = getFirmwareRange( - this.name, - getMiscNetwork('Solana'), - this.firmwareRange, - ); + this.setFirmwareRange(this.name, getMiscNetwork('Solana')); // create a bundle with only one batch if bundle doesn't exists this.hasBundle = !!this.payload.bundle; diff --git a/packages/connect/src/api/solana/api/solanaGetPublicKey.ts b/packages/connect/src/api/solana/api/solanaGetPublicKey.ts index de1fcc753ec..90d4195efe4 100644 --- a/packages/connect/src/api/solana/api/solanaGetPublicKey.ts +++ b/packages/connect/src/api/solana/api/solanaGetPublicKey.ts @@ -2,7 +2,6 @@ import { Assert } from '@trezor/schema-utils'; import { PROTO } from '../../../constants'; import { AbstractMethod, MethodReturnType } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath, fromHardened, getSerializedPath } from '../../../utils/pathUtils'; import { UI, createUiMessage } from '../../../events'; @@ -18,11 +17,7 @@ export default class SolanaGetPublicKey extends AbstractMethod< this.noBackupConfirmationMode = 'always'; this.requiredPermissions = ['read']; this.requiredDeviceCapabilities = ['Capability_Solana']; - this.firmwareRange = getFirmwareRange( - this.name, - getMiscNetwork('Solana'), - this.firmwareRange, - ); + this.setFirmwareRange(this.name, getMiscNetwork('Solana')); // create a bundle with only one batch if bundle doesn't exists this.hasBundle = !!this.payload.bundle; diff --git a/packages/connect/src/api/solana/api/solanaSignTransaction.ts b/packages/connect/src/api/solana/api/solanaSignTransaction.ts index 26a64d3fb5f..8c53615df64 100644 --- a/packages/connect/src/api/solana/api/solanaSignTransaction.ts +++ b/packages/connect/src/api/solana/api/solanaSignTransaction.ts @@ -2,7 +2,6 @@ import { AssertWeak } from '@trezor/schema-utils'; import { PROTO } from '../../../constants'; import { AbstractMethod } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath } from '../../../utils/pathUtils'; import { transformAdditionalInfo } from '../additionalInfo'; @@ -15,11 +14,7 @@ export default class SolanaSignTransaction extends AbstractMethod< init() { this.requiredPermissions = ['read', 'write']; this.requiredDeviceCapabilities = ['Capability_Solana']; - this.firmwareRange = getFirmwareRange( - this.name, - getMiscNetwork('Solana'), - this.firmwareRange, - ); + this.setFirmwareRange(this.name, getMiscNetwork('Solana')); const { payload } = this; diff --git a/packages/connect/src/api/stellar/api/stellarGetAddress.ts b/packages/connect/src/api/stellar/api/stellarGetAddress.ts index 4cf73a86675..3c0189edd0d 100644 --- a/packages/connect/src/api/stellar/api/stellarGetAddress.ts +++ b/packages/connect/src/api/stellar/api/stellarGetAddress.ts @@ -3,7 +3,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod, MethodReturnType } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath, fromHardened, getSerializedPath } from '../../../utils/pathUtils'; import { PROTO, ERRORS } from '../../../constants'; @@ -23,11 +22,7 @@ export default class StellarGetAddress extends AbstractMethod<'stellarGetAddress this.noBackupConfirmationMode = 'always'; this.requiredPermissions = ['read']; this.requiredDeviceCapabilities = ['Capability_Stellar']; - this.firmwareRange = getFirmwareRange( - this.name, - getMiscNetwork('Stellar'), - this.firmwareRange, - ); + this.setFirmwareRange(this.name, getMiscNetwork('Stellar')); // create a bundle with only one batch if bundle doesn't exists this.hasBundle = !!this.payload.bundle; diff --git a/packages/connect/src/api/stellar/api/stellarSignTransaction.ts b/packages/connect/src/api/stellar/api/stellarSignTransaction.ts index 1bd087a8347..82de577f553 100644 --- a/packages/connect/src/api/stellar/api/stellarSignTransaction.ts +++ b/packages/connect/src/api/stellar/api/stellarSignTransaction.ts @@ -3,7 +3,6 @@ import { AssertWeak } from '@trezor/schema-utils'; import { AbstractMethod } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath } from '../../../utils/pathUtils'; import * as helper from '../stellarSignTx'; @@ -31,11 +30,7 @@ export default class StellarSignTransaction extends AbstractMethod< init() { this.requiredPermissions = ['read', 'write']; this.requiredDeviceCapabilities = ['Capability_Stellar']; - this.firmwareRange = getFirmwareRange( - this.name, - getMiscNetwork('Stellar'), - this.firmwareRange, - ); + this.setFirmwareRange(this.name, getMiscNetwork('Stellar')); const { payload } = this; // validate incoming parameters diff --git a/packages/connect/src/api/tezos/api/tezosGetAddress.ts b/packages/connect/src/api/tezos/api/tezosGetAddress.ts index 07862cfa696..16eeb81dbb1 100644 --- a/packages/connect/src/api/tezos/api/tezosGetAddress.ts +++ b/packages/connect/src/api/tezos/api/tezosGetAddress.ts @@ -3,7 +3,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod, MethodReturnType } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath, fromHardened, getSerializedPath } from '../../../utils/pathUtils'; import { PROTO, ERRORS } from '../../../constants'; @@ -23,11 +22,7 @@ export default class TezosGetAddress extends AbstractMethod<'tezosGetAddress', P this.noBackupConfirmationMode = 'always'; this.requiredPermissions = ['read']; this.requiredDeviceCapabilities = ['Capability_Tezos']; - this.firmwareRange = getFirmwareRange( - this.name, - getMiscNetwork('Tezos'), - this.firmwareRange, - ); + this.setFirmwareRange(this.name, getMiscNetwork('Tezos')); // create a bundle with only one batch if bundle doesn't exists this.hasBundle = !!this.payload.bundle; diff --git a/packages/connect/src/api/tezos/api/tezosGetPublicKey.ts b/packages/connect/src/api/tezos/api/tezosGetPublicKey.ts index beb8a5a1700..a6b70a65d53 100644 --- a/packages/connect/src/api/tezos/api/tezosGetPublicKey.ts +++ b/packages/connect/src/api/tezos/api/tezosGetPublicKey.ts @@ -3,7 +3,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod, MethodReturnType } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath, fromHardened, getSerializedPath } from '../../../utils/pathUtils'; import { UI, createUiMessage } from '../../../events'; @@ -19,11 +18,7 @@ export default class TezosGetPublicKey extends AbstractMethod< init() { this.requiredPermissions = ['read']; this.requiredDeviceCapabilities = ['Capability_Tezos']; - this.firmwareRange = getFirmwareRange( - this.name, - getMiscNetwork('Tezos'), - this.firmwareRange, - ); + this.setFirmwareRange(this.name, getMiscNetwork('Tezos')); // create a bundle with only one batch if bundle doesn't exists this.hasBundle = !!this.payload.bundle; diff --git a/packages/connect/src/api/tezos/api/tezosSignTransaction.ts b/packages/connect/src/api/tezos/api/tezosSignTransaction.ts index f2200be4f1a..a225913bc40 100644 --- a/packages/connect/src/api/tezos/api/tezosSignTransaction.ts +++ b/packages/connect/src/api/tezos/api/tezosSignTransaction.ts @@ -3,7 +3,6 @@ import { AssertWeak } from '@trezor/schema-utils'; import { AbstractMethod } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath } from '../../../utils/pathUtils'; import * as helper from '../tezosSignTx'; @@ -17,11 +16,7 @@ export default class TezosSignTransaction extends AbstractMethod< init() { this.requiredPermissions = ['read', 'write']; this.requiredDeviceCapabilities = ['Capability_Tezos']; - this.firmwareRange = getFirmwareRange( - this.name, - getMiscNetwork('Tezos'), - this.firmwareRange, - ); + this.setFirmwareRange(this.name, getMiscNetwork('Tezos')); const { payload } = this; diff --git a/packages/connect/src/api/unlockPath.ts b/packages/connect/src/api/unlockPath.ts index 89e852f3037..2bfada7f17d 100644 --- a/packages/connect/src/api/unlockPath.ts +++ b/packages/connect/src/api/unlockPath.ts @@ -3,14 +3,13 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod } from '../core/AbstractMethod'; import { PROTO } from '../constants'; import { validatePath } from '../utils/pathUtils'; -import { getFirmwareRange } from './common/paramsValidator'; import { UnlockPathParams } from '../types/api/unlockPath'; export default class UnlockPath extends AbstractMethod<'unlockPath', PROTO.UnlockPath> { init() { this.requiredPermissions = ['read']; this.skipFinalReload = true; - this.firmwareRange = getFirmwareRange(this.name, undefined, this.firmwareRange); + this.setFirmwareRange(this.name, undefined); const { payload } = this; diff --git a/packages/connect/src/api/verifyMessage.ts b/packages/connect/src/api/verifyMessage.ts index 9c6be6ff739..39d79f9d0b6 100644 --- a/packages/connect/src/api/verifyMessage.ts +++ b/packages/connect/src/api/verifyMessage.ts @@ -3,7 +3,6 @@ import { Assert } from '@trezor/schema-utils'; import { AbstractMethod } from '../core/AbstractMethod'; -import { getFirmwareRange } from './common/paramsValidator'; import { getBitcoinNetwork } from '../data/coinInfo'; import { getLabel } from '../utils/pathUtils'; import { messageToHex } from '../utils/formatUtils'; @@ -24,7 +23,7 @@ export default class VerifyMessage extends AbstractMethod<'verifyMessage', PROTO throw ERRORS.TypedError('Method_UnknownCoin'); } else { // check required firmware with coinInfo support - this.firmwareRange = getFirmwareRange(this.name, coinInfo, this.firmwareRange); + this.setFirmwareRange(this.name, coinInfo); } const messageHex = payload.hex ? messageToHex(payload.message) diff --git a/packages/connect/src/api/wipeDevice.ts b/packages/connect/src/api/wipeDevice.ts index 4b8835379ef..048bbb718ec 100644 --- a/packages/connect/src/api/wipeDevice.ts +++ b/packages/connect/src/api/wipeDevice.ts @@ -2,14 +2,13 @@ import { AbstractMethod } from '../core/AbstractMethod'; import { UI, DEVICE } from '../events'; -import { getFirmwareRange } from './common/paramsValidator'; export default class WipeDevice extends AbstractMethod<'wipeDevice'> { init() { this.allowDeviceMode = [UI.INITIALIZE, UI.SEEDLESS, UI.BOOTLOADER]; this.useDeviceState = false; this.requiredPermissions = ['management']; - this.firmwareRange = getFirmwareRange(this.name, null, this.firmwareRange); + this.setFirmwareRange(this.name, null); } get confirmation() { diff --git a/packages/connect/src/core/AbstractMethod.ts b/packages/connect/src/core/AbstractMethod.ts index 95713119a46..70a28fd9078 100644 --- a/packages/connect/src/core/AbstractMethod.ts +++ b/packages/connect/src/core/AbstractMethod.ts @@ -22,6 +22,8 @@ import type { StaticSessionId, DeviceUniquePath, ConnectSettings, + CoinInfo, + DeviceModelInternal, } from '../types'; import { config } from '../data/config'; @@ -361,4 +363,102 @@ export abstract class AbstractMethod>; dispose() {} + + setFirmwareRange(method: string, coinInfo: CoinInfo | null | undefined) { + const range = JSON.parse(JSON.stringify(this.firmwareRange)) as FirmwareRange; + const models = Object.keys(range) as DeviceModelInternal[]; + // set minimum required firmware from coins.json (coinInfo) + if (coinInfo) { + models.forEach(model => { + const supportVersion = coinInfo.support ? coinInfo.support[model] : false; + if (supportVersion === false) { + range[model].min = '0'; + } else if ( + range[model].min !== '0' && + typeof supportVersion === 'string' && + versionUtils.isNewer(supportVersion, range[model].min) + ) { + range[model].min = supportVersion; + } + }); + } + + const coinType = coinInfo?.type; + const shortcut = coinInfo?.shortcut.toLowerCase(); + // find firmware range in config.json + const configRules = config.supportedFirmware + .filter(rule => { + // check if rule applies to requested method + if (rule.methods) { + return rule.methods.includes(method); + } + // check if rule applies to capability + if (rule.capabilities) { + return rule.capabilities.includes(method); + } + + // rule doesn't have specified methods + // it may be a global rule for coin or coinType + return true; + }) + .filter(rule => { + // REF_TODO: there is no coinType in config. possibly obsolete code? + // probably still useful, we just need to define type for config and not infer it. + // @ts-expect-error + if (rule.coinType) { + // rule for coin type + // @ts-expect-error + return rule.coinType === coinType; + } + if (rule.coin) { + // rule for coin shortcut + // @ts-expect-error + return (typeof rule.coin === 'string' ? [rule.coin] : rule.coin).includes( + shortcut, + ); + } + + // rule for method + return rule.methods || rule.capabilities; + }); + + configRules.forEach(rule => { + // override defaults + // NOTE: + // 0 may be confusing. means: no-support for "min" and unlimited support for "max" + if (rule.min) { + models.forEach(model => { + const modelMin = (rule.min as Record)[ + model + ]; + if (modelMin) { + if ( + modelMin === '0' || + range[model].min === '0' || + !versionUtils.isNewerOrEqual(range[model].min, modelMin) + ) { + range[model].min = modelMin; + } + } + }); + } + if (rule.max) { + models.forEach(model => { + // @ts-expect-error same issue as in coinType above, config needs to be typed not inferred. + const modelMax = rule.max[model]; + if (modelMax) { + if ( + modelMax === '0' || + range[model].max === '0' || + !versionUtils.isNewerOrEqual(range[model].max, modelMax) + ) { + range[model].max = modelMax; + } + } + }); + } + }); + + this.firmwareRange = range; + } } diff --git a/packages/connect/src/core/__tests__/AbstractMethod.test.ts b/packages/connect/src/core/__tests__/AbstractMethod.test.ts new file mode 100644 index 00000000000..32fd9402e6c --- /dev/null +++ b/packages/connect/src/core/__tests__/AbstractMethod.test.ts @@ -0,0 +1,365 @@ +import { DeviceModelInternal, FirmwareRange, CoinInfo } from '../../exports'; +import { DEFAULT_FIRMWARE_RANGE as DEFAULT_RANGE } from '../AbstractMethod'; + +const DEFAULT_COIN_INFO: CoinInfo = { + support: { + T1B1: '1.6.2', + T2T1: '2.1.0', + T2B1: '2.6.2', + T3B1: '2.8.2', + T3T1: '2.7.2', + T3W1: '2.7.2', + }, + shortcut: 'btc', + type: 'bitcoin', +} as CoinInfo; + +const EMPTY_CONFIG = { + supportedFirmware: [], +}; + +const rangeFromCoinInfo = ( + Object.entries(DEFAULT_COIN_INFO.support) as [DeviceModelInternal, string][] +).reduce((acc, [model]) => { + acc[model] = { + // @ts-expect-error + min: DEFAULT_COIN_INFO.support[model], + max: '0', + }; + + return acc; +}, {} as FirmwareRange); + +type Fixture = { + description: string; + config?: any; + params: [string, Partial | null]; + result: FirmwareRange; +}; + +const getFirmwareRange: Fixture[] = [ + { + description: 'default range. coinInfo and config.ts data not found', + config: EMPTY_CONFIG, + params: ['signTransaction', null], + result: DEFAULT_RANGE, + }, + { + description: 'range from coinInfo', + config: EMPTY_CONFIG, + params: ['signTransaction', DEFAULT_COIN_INFO], + result: rangeFromCoinInfo, + }, + { + description: 'coinInfo without support', + config: EMPTY_CONFIG, + params: ['signTransaction', { shortcut: 'btc', type: 'bitcoin' }], + result: (Object.keys(DEFAULT_COIN_INFO.support) as DeviceModelInternal[]).reduce( + (acc, model) => { + acc[model] = { min: '0', max: '0' }; + + return acc; + }, + {} as FirmwareRange, + ), + }, + { + description: 'coinInfo without T1B1 support', + config: EMPTY_CONFIG, + params: [ + 'signTransaction', + { + support: { + ...DEFAULT_COIN_INFO.support, + T1B1: false, + }, + shortcut: 'btc', + type: 'bitcoin', + }, + ], + result: ( + Object.entries(DEFAULT_COIN_INFO.support) as [DeviceModelInternal, string][] + ).reduce((acc, [model, min]) => { + acc[model] = { min: model === 'T1B1' ? '0' : min, max: '0' }; + + return acc; + }, {} as FirmwareRange), + }, + { + description: 'coinInfo without T2 support', + config: EMPTY_CONFIG, + params: [ + 'signTransaction', + { + support: { + ...DEFAULT_COIN_INFO.support, + T2T1: false, + T2B1: false, + T3B1: false, + T3T1: false, + T3W1: false, + }, + shortcut: 'btc', + type: 'bitcoin', + }, + ], + result: ( + Object.entries(DEFAULT_COIN_INFO.support) as [DeviceModelInternal, string][] + ).reduce((acc, [model, min]) => { + acc[model] = { min: model === 'T1B1' ? min : '0', max: '0' }; + + return acc; + }, {} as FirmwareRange), + }, + + { + description: 'range from config.ts (by coinType and coin as string)', + config: { + supportedFirmware: [ + // this one is ignored, different excludedMethod + { + coinType: 'bitcoin', + methods: ['showAddress'], + min: { T1B1: '1.12.0', T2T1: '2.6.0' }, + }, + // should merge both of these ranges together, since they both match + { coinType: 'bitcoin', min: { T1B1: '1.10.0', T2T1: '2.5.0' } }, + { coin: 'btc', min: { T1B1: '1.11.0', T2T1: '2.4.0' } }, + ], + }, + params: ['signTransaction', DEFAULT_COIN_INFO], + result: { + ...rangeFromCoinInfo, + T1B1: { min: '1.11.0', max: '0' }, + T2T1: { min: '2.5.0', max: '0' }, + }, + }, + + { + description: 'range from config.ts (by coin as string)', + config: { + supportedFirmware: [ + // this one is ignored, different excludedMethod + { coin: 'btc', methods: ['showAddress'], min: { T1B1: '1.11.0', T2T1: '2.5.0' } }, + { coin: 'btc', min: { T1B1: '1.10.0', T2T1: '2.4.0' } }, + ], + }, + params: ['signTransaction', DEFAULT_COIN_INFO], + result: { + ...rangeFromCoinInfo, + T1B1: { min: '1.10.0', max: '0' }, + T2T1: { min: '2.4.0', max: '0' }, + }, + }, + { + description: 'range from config.ts (by coin as array)', + config: { + supportedFirmware: [ + // this one is ignored, different excludedMethod + { coin: ['btc'], methods: ['showAddress'], min: { T1B1: '1.11.0', T2T1: '2.5.0' } }, + { coin: ['btc'], min: { T1B1: '1.10.0', T2T1: '2.4.0' } }, + ], + }, + params: ['signTransaction', DEFAULT_COIN_INFO], + result: { + ...rangeFromCoinInfo, + T1B1: { min: '1.10.0', max: '0' }, + T2T1: { min: '2.4.0', max: '0' }, + }, + }, + { + description: 'range from config.ts (by methods)', + config: { + supportedFirmware: [ + // this one is ignored, no data + { min: { T1B1: '1.11.0', T2T1: '2.5.0' } }, + // this one is ignored, different excludedMethod + { coin: ['btc'], methods: ['showAddress'], min: { T1B1: '1.11.0', T2T1: '2.5.0' } }, + // this one is ignored because of coin (not btc) + { + coin: ['ltc'], + methods: ['signTransaction'], + min: { T1B1: '1.11.0', T2T1: '2.5.0' }, + }, + // this one is ignored, different excludedMethod + { + coinType: 'bitcoin', + methods: ['showAddress'], + min: { T1B1: '1.11.0', T2T1: '2.5.0' }, + }, + { methods: ['signTransaction'], min: { T1B1: '1.10.0', T2T1: '2.4.0' } }, + ], + }, + params: ['signTransaction', DEFAULT_COIN_INFO], + result: { + ...rangeFromCoinInfo, + T1B1: { min: '1.10.0', max: '0' }, + T2T1: { min: '2.4.0', max: '0' }, + }, + }, + { + description: 'range from config.ts (by capabilities)', + config: { + supportedFirmware: [ + // this one is ignored, no data + { min: { T1B1: '1.11.0', T2T1: '2.5.0' } }, + // this one is ignored, different excludedMethod + { coin: ['btc'], methods: ['showAddress'], min: { T1B1: '1.11.0', T2T1: '2.5.0' } }, + // this one is ignored because of coin (not btc) + { + coin: ['ltc'], + methods: ['signTransaction'], + min: { T1B1: '1.11.0', T2T1: '2.5.0' }, + }, + // this one is ignored, different excludedMethod + { + coinType: 'bitcoin', + methods: ['showAddress'], + min: { T1B1: '1.11.0', T2T1: '2.5.0' }, + }, + { capabilities: ['decreaseOutput'], min: { T1B1: '1.10.0', T2T1: '2.4.0' } }, + ], + }, + params: ['decreaseOutput', DEFAULT_COIN_INFO], + result: { + ...rangeFromCoinInfo, + T1B1: { min: '1.10.0', max: '0' }, + T2T1: { min: '2.4.0', max: '0' }, + }, + }, + { + description: 'range from config.ts is lower than coinInfo', + config: { + supportedFirmware: [ + { methods: ['signTransaction'], min: { T1B1: '1.6.2', T2T1: '2.1.0' } }, + ], + }, + params: [ + 'signTransaction', + { + // @ts-expect-error + support: { T1B1: '1.10.0', T2T1: '2.4.0' }, + shortcut: 'btc', + type: 'bitcoin', + }, + DEFAULT_RANGE, + ], + result: { + ...DEFAULT_RANGE, + T1B1: { min: '1.10.0', max: '0' }, + T2T1: { min: '2.4.0', max: '0' }, + }, + }, + { + description: 'range from config.ts using max', + config: { + supportedFirmware: [ + { methods: ['signTransaction'], max: { T1B1: '1.10.0', T2T1: '2.4.0' } }, + ], + }, + params: ['signTransaction', DEFAULT_COIN_INFO], + result: { + ...rangeFromCoinInfo, + T1B1: { min: '1.6.2', max: '1.10.0' }, + T2T1: { min: '2.1.0', max: '2.4.0' }, + }, + }, + + // real config.ts data + { + description: 'xrp + getAccountInfo: coinInfo range IS replaced by config.ts range', + params: [ + 'getAccountInfo', + { + // @ts-expect-error + support: { T1B1: '1.0.1', T2T1: '2.0.1' }, + shortcut: 'xrp', + type: 'misc', + }, + DEFAULT_RANGE, + ], + result: { + ...DEFAULT_RANGE, + T1B1: { min: '0', max: '0' }, + T2T1: { min: '2.1.0', max: '0' }, + }, + }, + { + description: 'btc + getAccountInfo: coinInfo range IS NOT replaced by config.ts range', + params: ['getAccountInfo', null], + result: DEFAULT_RANGE, + }, + { + description: 'eip1559: coinInfo range is replaced by config.ts range', + params: [ + 'eip1559', + { + support: { + ...DEFAULT_COIN_INFO.support, + T1B1: '1.6.2', + T2T1: '2.1.0', + }, + shortcut: 'eth', + type: 'ethereum', + }, + ], + result: { + ...rangeFromCoinInfo, + T1B1: { min: '1.10.4', max: '0' }, + T2T1: { min: '2.4.2', max: '0' }, + }, + }, + { + description: 'method not available for T1B1 and T2T1, defined by config', + params: ['authenticateDevice', null], + result: { + ...DEFAULT_RANGE, + T1B1: { min: '0', max: '0' }, + T2T1: { min: '0', max: '0' }, + T3T1: { min: '2.8.0', max: '0' }, + }, + }, +]; + +describe('AbstractMethod.setFirmwareRange', () => { + afterEach(() => { + jest.clearAllMocks(); + }); + getFirmwareRange.forEach(f => { + it(f.description, () => { + return new Promise(done => { + jest.resetModules(); + + const mock = f.config; + jest.mock('../../data/config', () => { + const actualConfig = jest.requireActual('../../data/config').config; + + return { + __esModule: true, + config: mock || actualConfig, + }; + }); + + import('../AbstractMethod').then(({ AbstractMethod }) => { + class TestMethod extends AbstractMethod { + init() {} + run(): Promise { + return Promise.resolve(); + } + } + // @ts-expect-error + const method = new TestMethod({ payload: { method: 'signTransaction' } }); + + method.setFirmwareRange( + f.params[0], + // @ts-expect-error + f.params[1], + ); + + expect(method.firmwareRange).toEqual(f.result); + done(); + }); + }); + }); + }); +}); diff --git a/packages/suite/src/actions/suite/__tests__/initAction.test.ts b/packages/suite/src/actions/suite/__tests__/initAction.test.ts index 9f024da2a3b..0dee15be4fc 100644 --- a/packages/suite/src/actions/suite/__tests__/initAction.test.ts +++ b/packages/suite/src/actions/suite/__tests__/initAction.test.ts @@ -260,7 +260,7 @@ describe('Suite init action', () => { const store = initStore(getInitialState(options.initialRun)); if (options?.initialPath) { - // eslint-disable-next-line @typescript-eslint/no-var-requires + require('src/support/history').default.location.pathname = options.initialPath; } diff --git a/packages/suite/src/actions/suite/__tests__/routerActions.test.ts b/packages/suite/src/actions/suite/__tests__/routerActions.test.ts index d3764856667..4b511ffe86f 100644 --- a/packages/suite/src/actions/suite/__tests__/routerActions.test.ts +++ b/packages/suite/src/actions/suite/__tests__/routerActions.test.ts @@ -1,4 +1,4 @@ -/* eslint-disable @typescript-eslint/no-var-requires */ + import { configureStore } from 'src/support/tests/configureStore'; import suiteReducer from 'src/reducers/suite/suiteReducer'; import routerReducer from 'src/reducers/suite/routerReducer'; diff --git a/packages/suite/src/actions/wallet/exportTransactionsActions.ts b/packages/suite/src/actions/wallet/exportTransactionsActions.ts index 4f686f30113..9bef8c37907 100644 --- a/packages/suite/src/actions/wallet/exportTransactionsActions.ts +++ b/packages/suite/src/actions/wallet/exportTransactionsActions.ts @@ -39,10 +39,10 @@ export const exportTransactionsThunk = createThunk( // TODO: this is not nice (copy-paste) // metadata reducer is still not part of trezor-common and I can not import it // here. so either followup, or maybe when I have a moment I'll refactor it before merging this - // eslint-disable-next-line no-restricted-syntax + const provider = getState().metadata?.providers.find( // @ts-expect-error - // eslint-disable-next-line no-restricted-syntax + p => p.clientId === getState().metadata.selectedProvider.labels, ); const metadataKeys = account?.metadata[1]; diff --git a/packages/suite/src/components/suite/FormFractionButtons.tsx b/packages/suite/src/components/suite/FormFractionButtons.tsx index 5a565888fed..bac5840948a 100644 --- a/packages/suite/src/components/suite/FormFractionButtons.tsx +++ b/packages/suite/src/components/suite/FormFractionButtons.tsx @@ -12,7 +12,7 @@ const Flex = styled.div` gap: 4px; `; -// eslint-disable-next-line local-rules/no-override-ds-component + const TinyButton = styled(Button).attrs(props => ({ ...props, variant: 'tertiary', diff --git a/packages/suite/src/components/suite/labeling/MetadataLabeling/withEditable.tsx b/packages/suite/src/components/suite/labeling/MetadataLabeling/withEditable.tsx index e7752c8bbee..54763b64cb9 100644 --- a/packages/suite/src/components/suite/labeling/MetadataLabeling/withEditable.tsx +++ b/packages/suite/src/components/suite/labeling/MetadataLabeling/withEditable.tsx @@ -29,7 +29,7 @@ const IconListWrapper = styled.div` // To inherit everything so the input looks like the text we want to edit // However, we need to reset some properties: for example margin and padding to not duplicate spacings -// eslint-disable-next-line local-rules/no-override-ds-component + const Editable = styled(AutoScalingInput)` all: inherit; margin: 0; diff --git a/packages/suite/src/views/view-only/ViewOnlyPromoContent.tsx b/packages/suite/src/views/view-only/ViewOnlyPromoContent.tsx index 35af050d14e..e91f46105d8 100644 --- a/packages/suite/src/views/view-only/ViewOnlyPromoContent.tsx +++ b/packages/suite/src/views/view-only/ViewOnlyPromoContent.tsx @@ -58,12 +58,12 @@ const DeviceImage = styled(Image)` object-fit: contain; `; -// eslint-disable-next-line local-rules/no-override-ds-component + const SmallDeviceImage = styled(DeviceImage)` width: 18px; `; -// eslint-disable-next-line local-rules/no-override-ds-component + const LargeDeviceImage = styled(DeviceImage)` width: 93px; `; diff --git a/packages/suite/src/views/wallet/staking/components/EthStakingDashboard/components/StakingCard.tsx b/packages/suite/src/views/wallet/staking/components/EthStakingDashboard/components/StakingCard.tsx index f9d14778222..99d877e81f2 100644 --- a/packages/suite/src/views/wallet/staking/components/EthStakingDashboard/components/StakingCard.tsx +++ b/packages/suite/src/views/wallet/staking/components/EthStakingDashboard/components/StakingCard.tsx @@ -56,7 +56,7 @@ const ButtonsWrapper = styled.div` flex-wrap: wrap; `; -// eslint-disable-next-line local-rules/no-override-ds-component + const StyledButton = styled(Button).attrs(props => ({ ...props, variant: 'tertiary',