diff --git a/packages/connect/src/api/binance/api/binanceAbstractMethods.ts b/packages/connect/src/api/binance/api/binanceAbstractMethods.ts index 37b4ce1bc13f..b619a3c71f87 100644 --- a/packages/connect/src/api/binance/api/binanceAbstractMethods.ts +++ b/packages/connect/src/api/binance/api/binanceAbstractMethods.ts @@ -14,8 +14,4 @@ export abstract class BinanceAbstractMethod< super(message); this.firmwareRange = getFirmwareRange(this.name, getMiscNetwork('BNB'), this.firmwareRange); } - - // firmwareRangeRequirements could be defined here instead of config.ts - // loading coin-specific protobuf could be done here - // anything else? } diff --git a/packages/connect/src/api/cardano/api/cardanoAbstractMethods.ts b/packages/connect/src/api/cardano/api/cardanoAbstractMethods.ts new file mode 100644 index 000000000000..705ea89927ef --- /dev/null +++ b/packages/connect/src/api/cardano/api/cardanoAbstractMethods.ts @@ -0,0 +1,21 @@ +import { Capability } from '@trezor/protobuf/src/messages-schema'; +import { AbstractMethod, Payload } from '../../../core/AbstractMethod'; +import { CallMethodPayload } from '../../../events'; +import { getFirmwareRange } from '../../common/paramsValidator'; +import { getMiscNetwork } from '../../../data/coinInfo'; + +export abstract class CardanoAbstractMethod< + Name extends CallMethodPayload['method'], + Params = undefined, +> extends AbstractMethod { + requiredDeviceCapabilities = [Capability.Cardano]; + + constructor(message: { id?: number; payload: Payload }) { + super(message); + this.firmwareRange = getFirmwareRange( + this.name, + getMiscNetwork('Cardano'), + this.firmwareRange, + ); + } +} diff --git a/packages/connect/src/api/cardano/api/cardanoGetAddress.ts b/packages/connect/src/api/cardano/api/cardanoGetAddress.ts index e78ade2771a6..4197e44eb9c2 100644 --- a/packages/connect/src/api/cardano/api/cardanoGetAddress.ts +++ b/packages/connect/src/api/cardano/api/cardanoGetAddress.ts @@ -2,9 +2,7 @@ import { Assert } from '@trezor/schema-utils'; -import { AbstractMethod, MethodReturnType } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; -import { getMiscNetwork } from '../../../data/coinInfo'; +import { MethodReturnType } from '../../../core/AbstractMethod'; import { fromHardened, getSerializedPath } from '../../../utils/pathUtils'; import { addressParametersFromProto, @@ -16,24 +14,22 @@ import { PROTO, ERRORS } from '../../../constants'; import { UI, createUiMessage } from '../../../events'; import { Bundle } from '../../../types'; import { CardanoGetAddress as CardanoGetAddressSchema } from '../../../types/api/cardano'; +import { CardanoAbstractMethod } from './cardanoAbstractMethods'; type Params = PROTO.CardanoGetAddress & { address?: string; }; -export default class CardanoGetAddress extends AbstractMethod<'cardanoGetAddress', Params[]> { +export default class CardanoGetAddress extends CardanoAbstractMethod< + 'cardanoGetAddress', + Params[] +> { hasBundle?: boolean; progress = 0; init() { this.noBackupConfirmationMode = 'always'; this.requiredPermissions = ['read']; - this.requiredDeviceCapabilities = ['Capability_Cardano']; - this.firmwareRange = getFirmwareRange( - this.name, - getMiscNetwork('Cardano'), - this.firmwareRange, - ); // 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 57f616642bc5..445a7220ece5 100644 --- a/packages/connect/src/api/cardano/api/cardanoGetNativeScriptHash.ts +++ b/packages/connect/src/api/cardano/api/cardanoGetNativeScriptHash.ts @@ -3,27 +3,20 @@ 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 { CardanoGetNativeScriptHash as CardanoGetNativeScriptHashSchema, CardanoNativeScript, } from '../../../types/api/cardano'; +import { CardanoAbstractMethod } from './cardanoAbstractMethods'; -export default class CardanoGetNativeScriptHash extends AbstractMethod< +export default class CardanoGetNativeScriptHash extends CardanoAbstractMethod< 'cardanoGetNativeScriptHash', PROTO.CardanoGetNativeScriptHash > { init() { this.requiredPermissions = ['read']; - this.requiredDeviceCapabilities = ['Capability_Cardano']; - this.firmwareRange = getFirmwareRange( - this.name, - getMiscNetwork('Cardano'), - this.firmwareRange, - ); const { payload } = this; diff --git a/packages/connect/src/api/cardano/api/cardanoGetPublicKey.ts b/packages/connect/src/api/cardano/api/cardanoGetPublicKey.ts index 78a8fadff908..58d2a27e521d 100644 --- a/packages/connect/src/api/cardano/api/cardanoGetPublicKey.ts +++ b/packages/connect/src/api/cardano/api/cardanoGetPublicKey.ts @@ -3,29 +3,25 @@ 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 { MethodReturnType } from '../../../core/AbstractMethod'; import { validatePath, fromHardened, getSerializedPath } from '../../../utils/pathUtils'; import { UI, createUiMessage } from '../../../events'; import { Bundle } from '../../../types'; import { CardanoGetPublicKey as CardanoGetPublicKeySchema } from '../../../types/api/cardano'; +import { CardanoAbstractMethod } from './cardanoAbstractMethods'; interface Params extends PROTO.CardanoGetPublicKey { suppressBackupWarning?: boolean; } -export default class CardanoGetPublicKey extends AbstractMethod<'cardanoGetPublicKey', Params[]> { +export default class CardanoGetPublicKey extends CardanoAbstractMethod< + 'cardanoGetPublicKey', + Params[] +> { hasBundle?: boolean; init() { this.requiredPermissions = ['read']; - this.requiredDeviceCapabilities = ['Capability_Cardano']; - this.firmwareRange = getFirmwareRange( - this.name, - getMiscNetwork('Cardano'), - this.firmwareRange, - ); // 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 c780e77c5052..4219219281aa 100644 --- a/packages/connect/src/api/cardano/api/cardanoSignTransaction.ts +++ b/packages/connect/src/api/cardano/api/cardanoSignTransaction.ts @@ -6,9 +6,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 { modifyAuxiliaryDataForBackwardsCompatibility, @@ -37,6 +34,7 @@ import { import { gatherWitnessPaths } from '../cardanoWitnesses'; import type { AssetGroupWithTokens } from '../cardanoTokenBundle'; import { tokenBundleToProto } from '../cardanoTokenBundle'; +import { CardanoAbstractMethod } from './cardanoAbstractMethods'; const CardanoSignTransactionFeatures = Object.freeze({ // FW <2.6.0 is not supported by Connect at all @@ -72,18 +70,12 @@ export type CardanoSignTransactionParams = { chunkify?: boolean; }; -export default class CardanoSignTransaction extends AbstractMethod< +export default class CardanoSignTransaction extends CardanoAbstractMethod< 'cardanoSignTransaction', CardanoSignTransactionParams > { init() { this.requiredPermissions = ['read', 'write']; - this.requiredDeviceCapabilities = ['Capability_Cardano']; - this.firmwareRange = getFirmwareRange( - this.name, - getMiscNetwork('Cardano'), - this.firmwareRange, - ); const { payload } = this; diff --git a/packages/connect/src/core/AbstractMethod.ts b/packages/connect/src/core/AbstractMethod.ts index 95713119a462..c50601e18f2d 100644 --- a/packages/connect/src/core/AbstractMethod.ts +++ b/packages/connect/src/core/AbstractMethod.ts @@ -341,6 +341,9 @@ export abstract class AbstractMethod this.device.features.capabilities.includes(capability), );