Skip to content

Commit

Permalink
feat: introduce internal_model UNKNOWN, add support for it in the Suite
Browse files Browse the repository at this point in the history
wip(suite): implement UNKNOWN internal model
  • Loading branch information
mroz22 authored and peter-sanderson committed Dec 9, 2024
1 parent c5b661d commit d3aec49
Show file tree
Hide file tree
Showing 33 changed files with 94 additions and 21 deletions.
9 changes: 9 additions & 0 deletions packages/components/src/components/Image/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const SVG_IMAGES = {
UNI_SUCCESS: 'uni-success.svg',
UNI_WARNING: 'uni-warning.svg',
BRIDGE_CHECK_TREZOR_T2T1: 'bridge-check-trezor-t2t1.svg',
DEVICE_CONFIRM_TREZOR_UNKNOWN: 'device-confirm-trezor-unknown.svg',
DEVICE_CONFIRM_TREZOR_T1B1: 'device-confirm-trezor-t1b1.svg',
DEVICE_CONFIRM_TREZOR_T2T1: 'device-confirm-trezor-t2t1.svg',
DEVICE_CONFIRM_TREZOR_T2B1: 'device-confirm-trezor-t3b1.svg',
Expand Down Expand Up @@ -81,6 +82,8 @@ export const PNG_IMAGES = {
UNDERSTAND_2x: '[email protected]',
WALLET: 'wallet.png',
WALLET_2x: '[email protected]',
DONT_DISCONNECT_TREZOR_UNKNOWN: 'dont-disconnect-trezor-unknown.png',
DONT_DISCONNECT_TREZOR_UNKNOWN_2x: '[email protected]',
DONT_DISCONNECT_TREZOR_T2T1: 'dont-disconnect-trezor-t2t1.png',
DONT_DISCONNECT_TREZOR_T2T1_2x: '[email protected]',
DONT_DISCONNECT_TREZOR_T1B1: 'dont-disconnect-trezor-t1b1.png',
Expand All @@ -93,6 +96,8 @@ export const PNG_IMAGES = {
DONT_DISCONNECT_TREZOR_T3T1_2x: '[email protected]',
DONT_DISCONNECT_TREZOR_T3W1: 'dont-disconnect-trezor-t3w1.png',
DONT_DISCONNECT_TREZOR_T3W1_2x: '[email protected]',
TREZOR_UNKNOWN: 'trezor-unknown.png',
TREZOR_UNKNOWN_2x: '[email protected]',
TREZOR_T1B1: 'trezor-t1b1.png',
TREZOR_T1B1_2x: '[email protected]',
TREZOR_T2T1: 'trezor-t2t1.png',
Expand All @@ -105,6 +110,8 @@ export const PNG_IMAGES = {
TREZOR_T3T1_2x: '[email protected]',
TREZOR_T3W1: 'trezor-t3w1.png',
TREZOR_T3W1_2x: '[email protected]',
TREZOR_UNKNOWN_LARGE: 'trezor-unknown-large.png',
TREZOR_UNKNOWN_LARGE_2x: '[email protected]',
TREZOR_T1B1_LARGE: 'trezor-t1b1-large.png',
TREZOR_T1B1_LARGE_2x: '[email protected]',
TREZOR_T2T1_LARGE: 'trezor-t2t1-large.png',
Expand All @@ -117,6 +124,8 @@ export const PNG_IMAGES = {
TREZOR_T3T1_LARGE_2x: '[email protected]',
TREZOR_T3W1_LARGE: 'trezor-t3w1-large.png',
TREZOR_T3W1_LARGE_2x: '[email protected]',
TREZOR_UNKNOWN_GHOST: 'trezor-unknown-ghost.png',
TREZOR_UNKNOWN_GHOST_2x: '[email protected]',
TREZOR_T1B1_GHOST: 'trezor-t1b1-ghost.png',
TREZOR_T1B1_GHOST_2x: '[email protected]',
TREZOR_T2T1_GHOST: 'trezor-t2t1-ghost.png',
Expand Down
10 changes: 8 additions & 2 deletions packages/connect/src/api/common/__fixtures__/paramsValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ export const validateParams = [
},
];

const DEFAULT_RANGE = {
const DEFAULT_RANGE: FirmwareRange = {
UNKNOWN: { min: '0', max: '0' },
T1B1: { min: '1.0.0', max: '0' },
T2T1: { min: '2.0.0', max: '0' },
T2B1: { min: '2.0.0', max: '0' },
Expand All @@ -179,8 +180,13 @@ const DEFAULT_RANGE = {
T3W1: { min: '2.0.0', max: '0' },
};

const DEFAULT_COIN_INFO = {
const DEFAULT_COIN_INFO: {
support: Record<DeviceModelInternal, string>;
shortcut: string;
type: string;
} = {
support: {
UNKNOWN: '0.0.0',
T1B1: '1.6.2',
T2T1: '2.1.0',
T2B1: '2.0.0',
Expand Down
1 change: 1 addition & 0 deletions packages/connect/src/api/ethereum/ethereumDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export const ethereumNetworkInfoFromDefinition = (
T3B1: '2.0.0',
T3T1: '2.0.0',
T3W1: '2.0.0',
UNKNOWN: '0.0.0',
},
blockchainLink: undefined,
});
1 change: 1 addition & 0 deletions packages/connect/src/core/AbstractMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface MethodInfo {
}

export const DEFAULT_FIRMWARE_RANGE: FirmwareRange = {
UNKNOWN: { min: '1.0.0', max: '0' },
T1B1: { min: '1.0.0', max: '0' },
T2T1: { min: '2.0.0', max: '0' },
T2B1: { min: '2.6.1', max: '0' },
Expand Down
4 changes: 2 additions & 2 deletions packages/connect/src/data/deviceAuthenticityConfigTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ type ModelPubKeys = Static<typeof ModelPubKeys>;

const ModelsWithKeys = Type.Exclude(
Type.KeyOfEnum(PROTO.DeviceModelInternal),
Type.Union([Type.Literal('T1B1'), Type.Literal('T2T1')]),
Type.Union([Type.Literal('T1B1'), Type.Literal('T2T1'), Type.Literal('UNKNOWN')]),
);

const ModelsWithoutKeys = Type.Extract(
Type.KeyOfEnum(PROTO.DeviceModelInternal),
Type.Union([Type.Literal('T1B1'), Type.Literal('T2T1')]),
Type.Union([Type.Literal('T1B1'), Type.Literal('T2T1'), Type.Literal('UNKNOWN')]),
);

const ModelPubKeys = Type.Intersect([
Expand Down
4 changes: 4 additions & 0 deletions packages/connect/src/data/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const safe3Model: ModelConfig = {
};

export const models: Record<DeviceModelInternal, ModelConfig> = {
UNKNOWN: {
name: 'Unknown',
colors: safe3Model.colors, // just in case
},
T1B1: {
name: 'Trezor Model One',
colors: {},
Expand Down
8 changes: 7 additions & 1 deletion packages/connect/src/device/Device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
FirmwareHashCheckResult,
FirmwareHashCheckError,
DeviceUniquePath,
DeviceModelInternal,
} from '../types';
import { models } from '../data/models';
import { getLanguage } from '../data/getLanguage';
Expand Down Expand Up @@ -960,13 +961,18 @@ export class Device extends TypedEmitter<DeviceEvents> {
const revision = parseRevision(feat);
feat.revision = revision;

feat.model = 'maow';
// @ts-expect-error // Todo: dont forget to remove it
feat.internal_model = 'brambora';

// Fix missing model and internal_model in older fw, model has to be fixed first
// 1. - old T1B1 is missing features.model
if (!feat.model && feat.major_version === 1) {
feat.model = '1';
}
// 2. - old fw does not include internal_model. T1B1 does not report it yet, T2T1 starts in 2.6.0
if (!feat.internal_model) {
// - or reported internal_model is not known to connect
if (!feat.internal_model || !DeviceModelInternal[feat.internal_model]) {
feat.internal_model = ensureInternalModelFeature(feat.model);
}

Expand Down
1 change: 1 addition & 0 deletions packages/connect/src/utils/assetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const isDeviceModel = (model: string): model is DeviceModelInternal =>
isArrayMember(model, Object.values(DeviceModelInternal));

export const firmwareAssets: Record<DeviceModelInternal, NodeRequire> = {
[DeviceModelInternal.UNKNOWN]: {} as NodeRequire,
[DeviceModelInternal.T1B1]: require('@trezor/connect-common/files/firmware/t1b1/releases.json'),
[DeviceModelInternal.T2T1]: require('@trezor/connect-common/files/firmware/t2t1/releases.json'),
[DeviceModelInternal.T2B1]: require('@trezor/connect-common/files/firmware/t2b1/releases.json'),
Expand Down
3 changes: 2 additions & 1 deletion packages/connect/src/utils/deviceFeaturesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ export const ensureInternalModelFeature = (model: Features['model']): DeviceMode
case 'T':
return DeviceModelInternal.T2T1;
case '1':
default:
return DeviceModelInternal.T1B1;
default:
return DeviceModelInternal.UNKNOWN;
}
};
2 changes: 1 addition & 1 deletion packages/product-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export {
export { SearchAsset } from './components/SelectAssetModal/SearchAsset';
export { PassphraseTypeCard } from './components/PassphraseTypeCard/PassphraseTypeCard';
export { ConfirmOnDevice } from './components/ConfirmOnDevice/ConfirmOnDevice';
export { mapTrezorModelToIcon } from './utils/mapTrezorModelToIcon';
export { mapTrezorModelToIcon, mapTrezorModelToIconFilled } from './utils/mapTrezorModelToIcon';
export { RotateDeviceImage } from './components/RotateDeviceImage/RotateDeviceImage';
export { TrezorLogo } from './components/TrezorLogo/TrezorLogo';
export { PasswordStrengthIndicator } from './components/PasswordStrengthIndicator/PasswordStrengthIndicator';
Expand Down
15 changes: 14 additions & 1 deletion packages/product-components/src/utils/mapTrezorModelToIcon.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import { IconName } from '@trezor/components';
import { DeviceModelInternal } from '@trezor/connect';

export const mapTrezorModelToIcon: Record<DeviceModelInternal, IconName> = {
export const mapTrezorModelToIconFilled: Record<DeviceModelInternal, IconName> = {
[DeviceModelInternal.T1B1]: 'trezorModelOneFilled',
[DeviceModelInternal.T2T1]: 'trezorModelTFilled',
[DeviceModelInternal.T2B1]: 'trezorSafe3Filled',
[DeviceModelInternal.T3B1]: 'trezorSafe3Filled',
[DeviceModelInternal.T3T1]: 'trezorSafe5Filled',
[DeviceModelInternal.T3W1]: 'trezorSafe7Filled',

[DeviceModelInternal.UNKNOWN]: 'trezorModelOneFilled', // Just to provide something that wont break UI
};

export const mapTrezorModelToIcon: Record<DeviceModelInternal, IconName> = {
[DeviceModelInternal.T1B1]: 'trezorT1B1',
[DeviceModelInternal.T2T1]: 'trezorT2T1',
[DeviceModelInternal.T2B1]: 'trezorT2B1',
[DeviceModelInternal.T3B1]: 'trezorT3B1',
[DeviceModelInternal.T3T1]: 'trezorT3T1',
[DeviceModelInternal.T3W1]: 'trezorT3W1',

[DeviceModelInternal.UNKNOWN]: 'trezorT1B1', // Just to provide something that wont break UI
};
1 change: 1 addition & 0 deletions packages/protobuf/scripts/protobuf-patches/customTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export enum DeviceModelInternal {
T3B1 = 'T3B1',
T3T1 = 'T3T1',
T3W1 = 'T3W1',
UNKNOWN = 'UNKNOWN',
}
1 change: 1 addition & 0 deletions packages/protobuf/src/messages-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum DeviceModelInternal {
T3B1 = 'T3B1',
T3T1 = 'T3T1',
T3W1 = 'T3W1',
UNKNOWN = 'UNKNOWN',
}

export type EnumDeviceModelInternal = Static<typeof EnumDeviceModelInternal>;
Expand Down
1 change: 1 addition & 0 deletions packages/protobuf/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export enum DeviceModelInternal {
T3B1 = 'T3B1',
T3T1 = 'T3T1',
T3W1 = 'T3W1',
UNKNOWN = 'UNKNOWN',
}

export type BinanceGetAddress = {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ export const ReconnectDevicePrompt = ({ onClose, onSuccess }: ReconnectDevicePro

const deviceFwVersion = getFirmwareVersion(uiEvent?.payload.device);
const switchToBootloaderMap: Record<DeviceModelInternal, TranslationKey> = {
// just to have something, I assume new models will have touch screen
[DeviceModelInternal.UNKNOWN]: 'TR_SWITCH_TO_BOOTLOADER_SWIPE_YOUR_FINGERS',

[DeviceModelInternal.T1B1]:
semver.valid(deviceFwVersion) && semver.satisfies(deviceFwVersion, '<1.8.0')
? 'TR_SWITCH_TO_BOOTLOADER_HOLD_BOTH_BUTTONS'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import styled, { css, DefaultTheme, useTheme } from 'styled-components';
import { ComponentWithSubIcon, getIconSize, Icon, IconSize, iconSizes } from '@trezor/components';
import { borders, Color, CSSColor } from '@trezor/theme';
import { isDesktop } from '@trezor/env-utils';
import { mapTrezorModelToIcon } from '@trezor/product-components';
import { mapTrezorModelToIconFilled } from '@trezor/product-components';

import { useDevice } from '../../../../../../../hooks/suite';
import { QuickActionButton } from '../QuickActionButton';
Expand Down Expand Up @@ -110,7 +110,7 @@ const DeviceUpdateIcon = ({ iconSize, updateStatus, variant }: DeviceUpdateIconP
<Highlighted $isHighlighted={updateStatus !== 'up-to-date'}>
<Relative $size={iconSize}>
<Icon
name={mapTrezorModelToIcon[device.features.internal_model]}
name={mapTrezorModelToIconFilled[device.features.internal_model]}
size={iconSizes.medium}
variant={variant}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { spacings } from '@trezor/theme';
import { TranslationKey } from '@suite-common/intl-types';
import { getFirmwareVersion } from '@trezor/device-utils';
import { isDesktop } from '@trezor/env-utils';
import { mapTrezorModelToIcon } from '@trezor/product-components';
import { mapTrezorModelToIconFilled } from '@trezor/product-components';

import { Translation } from '../../../../../Translation';
import {
Expand Down Expand Up @@ -59,7 +59,7 @@ const DeviceRow = ({ updateStatus, onClick }: DeviceRowProps) => {
onClick={onClick}
leftItem={
<Icon
name={mapTrezorModelToIcon[device.features.internal_model]}
name={mapTrezorModelToIconFilled[device.features.internal_model]}
size={iconSizes.medium}
/>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '@trezor/components';
import type { Deferred } from '@trezor/utils';
import { spacings } from '@trezor/theme';
import { mapTrezorModelToIcon } from '@trezor/product-components';

import { Translation } from 'src/components/suite';
import { useDevice } from 'src/hooks/suite';
Expand Down Expand Up @@ -90,7 +91,7 @@ export const CoinmarketTermsModal = ({
<List.Item
bulletComponent={
<IconCircle
name={`trezor${device.features.internal_model}`}
name={mapTrezorModelToIcon[device.features.internal_model]}
{...iconProps}
/>
}
Expand Down
6 changes: 6 additions & 0 deletions packages/suite/src/constants/suite/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const DEFAULT_PASSPHRASE_PROTECTION = true;
export const DEFAULT_SKIP_BACKUP = true;

export const DEFAULT_STRENGTH: Record<DeviceModelInternal, number> = {
[DeviceModelInternal.UNKNOWN]: 128, // just to have something
[DeviceModelInternal.T1B1]: 256,
[DeviceModelInternal.T2T1]: 128,
[DeviceModelInternal.T2B1]: 128,
Expand All @@ -14,6 +15,7 @@ export const DEFAULT_STRENGTH: Record<DeviceModelInternal, number> = {
};

export const MAX_ROWS_PER_PAGE: Record<DeviceModelInternal, number> = {
[DeviceModelInternal.UNKNOWN]: 7, // just to have something
[DeviceModelInternal.T1B1]: 4,
[DeviceModelInternal.T2T1]: 5,
[DeviceModelInternal.T2B1]: 4,
Expand All @@ -23,6 +25,7 @@ export const MAX_ROWS_PER_PAGE: Record<DeviceModelInternal, number> = {
};

export const MAX_CHARACTERS_ON_ROW: Record<DeviceModelInternal, number> = {
[DeviceModelInternal.UNKNOWN]: 18, // just to have something
[DeviceModelInternal.T1B1]: 21,
[DeviceModelInternal.T2T1]: 17, // -1 for the space for the scrollbar (Trezor T only)
[DeviceModelInternal.T2B1]: 18,
Expand All @@ -32,6 +35,7 @@ export const MAX_CHARACTERS_ON_ROW: Record<DeviceModelInternal, number> = {
};

export const CHARACTER_OFFSET_FOR_CONTINUES_ARROW: Record<DeviceModelInternal, number> = {
[DeviceModelInternal.UNKNOWN]: 4, // just to have something
[DeviceModelInternal.T1B1]: 3,
[DeviceModelInternal.T2T1]: 4,
[DeviceModelInternal.T2B1]: 2,
Expand All @@ -41,6 +45,7 @@ export const CHARACTER_OFFSET_FOR_CONTINUES_ARROW: Record<DeviceModelInternal, n
};

export const CHARACTER_OFFSET_FOR_NEXT_ARROW: Record<DeviceModelInternal, number> = {
[DeviceModelInternal.UNKNOWN]: 4, // just to have something
[DeviceModelInternal.T1B1]: 0,
[DeviceModelInternal.T2T1]: 4,
[DeviceModelInternal.T2B1]: 2,
Expand All @@ -50,6 +55,7 @@ export const CHARACTER_OFFSET_FOR_NEXT_ARROW: Record<DeviceModelInternal, number
};

export const HAS_MONOCHROME_SCREEN: Record<DeviceModelInternal, boolean> = {
[DeviceModelInternal.UNKNOWN]: false, // just to have something
[DeviceModelInternal.T1B1]: true,
[DeviceModelInternal.T2T1]: false,
[DeviceModelInternal.T2B1]: true,
Expand Down
4 changes: 4 additions & 0 deletions packages/suite/src/constants/suite/homescreens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const safe3Homescreens = [

// original trezor images has to be first as they are send to device as '0' and the default image from fw is used
export const getHomescreens = (isBitcoinOnlyFirmware: boolean) => ({
[DeviceModelInternal.UNKNOWN]: [
isBitcoinOnlyFirmware ? 'orange' : 'green', // just to have something
isBitcoinOnlyFirmware ? 'green' : 'orange',
],
[DeviceModelInternal.T1B1]: [
'original_t1b1', // note - has to be first
'blank',
Expand Down
1 change: 1 addition & 0 deletions packages/suite/src/utils/suite/homescreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const deviceModelInformation: Record<
DeviceModelInternal,
{ width: number; height: number; supports: Array<'png' | 'jpeg'> }
> = {
[DeviceModelInternal.UNKNOWN]: { width: 280, height: 520, supports: ['jpeg'] }, // just to have something
[DeviceModelInternal.T1B1]: { width: 128, height: 64, supports: ['png', 'jpeg'] },
[DeviceModelInternal.T2T1]: { width: 240, height: 240, supports: ['jpeg'] },
[DeviceModelInternal.T2B1]: safe3Information,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const SHAMIR_TYPES: BackupType[] = ['shamir-single', 'shamir-advanced'];
export const isShamirBackupType = (type: BackupType) => SHAMIR_TYPES.includes(type);

export const defaultBackupTypeMap: Record<DeviceModelInternal, BackupType> = {
[DeviceModelInternal.UNKNOWN]: '12-words', // just to have something
[DeviceModelInternal.T1B1]: '24-words',
[DeviceModelInternal.T2T1]: '12-words',
[DeviceModelInternal.T2B1]: 'shamir-single',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ReactNode } from 'react';

import { Button, Tooltip } from '@trezor/components';
import { DeviceModelInternal } from '@trezor/connect';
import { mapTrezorModelToIcon } from '@trezor/product-components';

interface DeviceButtonProps {
isDisabled?: boolean;
Expand All @@ -25,7 +26,7 @@ export const DeviceButton = ({
isDisabled={isDisabled}
isLoading={isLoading}
onClick={onClick}
icon={`trezor${deviceModelInternal}`}
icon={mapTrezorModelToIcon[deviceModelInternal]}
>
{children}
</Button>
Expand Down
1 change: 1 addition & 0 deletions suite-common/suite-constants/src/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DeviceModelInternal } from '@trezor/connect';
export const DEFAULT_FLAGSHIP_MODEL = DeviceModelInternal.T3T1;

export const SUPPORTS_DEVICE_AUTHENTICITY_CHECK: Record<DeviceModelInternal, boolean> = {
[DeviceModelInternal.UNKNOWN]: true, // We must require device authenticity check so it cannot be used as and exploit to bypass it
[DeviceModelInternal.T1B1]: false,
[DeviceModelInternal.T2T1]: false,
[DeviceModelInternal.T2B1]: true,
Expand Down
Loading

0 comments on commit d3aec49

Please sign in to comment.