diff --git a/packages/suite/src/utils/suite/storage.ts b/packages/suite/src/utils/suite/storage.ts index 94591c08db..90dc6a0c75 100644 --- a/packages/suite/src/utils/suite/storage.ts +++ b/packages/suite/src/utils/suite/storage.ts @@ -1,34 +1,10 @@ import { connectInitThunk } from '@suite-common/connect-init'; -import { - hashCheckErrorScenarios, - revisionCheckErrorScenarios, -} from '@suite-common/firmware-authenticity'; +import { filterInconclusiveAuthenticityChecks } from '@suite-common/firmware-authenticity'; import { DeviceWithEmptyPath } from '@suite-common/suite-types'; import { AcquiredDevice } from 'src/types/suite'; import { CoinjoinAccount } from 'src/types/wallet/coinjoin'; -type AuthenticityChecks = AcquiredDevice['authenticityChecks']; -const filterInconclusiveAuthenticityChecks = (checks: AuthenticityChecks): AuthenticityChecks => { - let { firmwareRevision, firmwareHash } = checks; - if ( - firmwareRevision && - !firmwareRevision.success && - revisionCheckErrorScenarios[firmwareRevision.error].isConclusive === false - ) { - firmwareRevision = null; - } - if ( - firmwareHash && - !firmwareHash.success && - hashCheckErrorScenarios[firmwareHash.error].isConclusive === false - ) { - firmwareHash = null; - } - - return { firmwareRevision, firmwareHash }; -}; - /** * Strip fields from Device * @param {AcquiredDevice} device diff --git a/suite-common/firmware-authenticity/src/utils.ts b/suite-common/firmware-authenticity/src/utils.ts index be9d428c8e..8ea3a24821 100644 --- a/suite-common/firmware-authenticity/src/utils.ts +++ b/suite-common/firmware-authenticity/src/utils.ts @@ -1,3 +1,4 @@ +import { AcquiredDevice } from '@suite-common/suite-types'; import { FirmwareHashCheckError, FirmwareRevisionCheckError } from '@trezor/connect'; import type { FilterPropertiesByType } from '@trezor/type-utils'; @@ -47,3 +48,27 @@ export const isHashCheckErrorWithNotification = ( ): error is HashCheckErrorWithNotification => // @ts-expect-error if this no longer gives error, then TODO hash check notifications must be implemented hashCheckErrorScenarios[error].shouldNotify === true; + +type AuthenticityChecks = AcquiredDevice['authenticityChecks']; + +export const filterInconclusiveAuthenticityChecks = ( + checks: AuthenticityChecks, +): AuthenticityChecks => { + let { firmwareRevision, firmwareHash } = checks; + if ( + firmwareRevision && + !firmwareRevision.success && + revisionCheckErrorScenarios[firmwareRevision.error].isConclusive === false + ) { + firmwareRevision = null; + } + if ( + firmwareHash && + !firmwareHash.success && + hashCheckErrorScenarios[firmwareHash.error].isConclusive === false + ) { + firmwareHash = null; + } + + return { firmwareRevision, firmwareHash }; +}; diff --git a/suite-native/storage/package.json b/suite-native/storage/package.json index 63f6aae6b9..4e90436335 100644 --- a/suite-native/storage/package.json +++ b/suite-native/storage/package.json @@ -14,6 +14,7 @@ "@mobily/ts-belt": "^3.13.1", "@reduxjs/toolkit": "2.8.2", "@sentry/react-native": "6.20.0", + "@suite-common/firmware-authenticity": "workspace:*", "@suite-common/suite-types": "workspace:*", "@suite-common/wallet-core": "workspace:*", "bs58": "^6.0.0", diff --git a/suite-native/storage/src/transforms/deviceTransforms.ts b/suite-native/storage/src/transforms/deviceTransforms.ts index bf4a085a83..f2a7f8646a 100644 --- a/suite-native/storage/src/transforms/deviceTransforms.ts +++ b/suite-native/storage/src/transforms/deviceTransforms.ts @@ -1,15 +1,18 @@ import { A, pipe } from '@mobily/ts-belt'; import { createTransform } from 'redux-persist'; -import { TrezorDevice } from '@suite-common/suite-types'; +import { filterInconclusiveAuthenticityChecks } from '@suite-common/firmware-authenticity'; +import { AcquiredDevice, TrezorDevice } from '@suite-common/suite-types'; +import { isDeviceAcquired } from '@suite-common/suite-utils'; -const serializeDevice = (device: TrezorDevice): Omit & { path: '' } => ({ +const serializeDevice = (device: AcquiredDevice): Omit & { path: '' } => ({ ...device, path: '', remember: true, temporaryRemember: false, connected: false, buttonRequests: [], + authenticityChecks: filterInconclusiveAuthenticityChecks(device.authenticityChecks), }); export const devicePersistTransform = createTransform< @@ -19,6 +22,8 @@ export const devicePersistTransform = createTransform< inboundState => pipe( inboundState, + // only for type-narrowing; this is already projected into device.remember in `shouldDeviceBeRemembered` + A.filter(isDeviceAcquired), A.filter(device => !!device.remember && device.temporaryRemember !== true), A.map(serializeDevice), ), diff --git a/suite-native/storage/tsconfig.json b/suite-native/storage/tsconfig.json index 835d7ac919..f346fa84f8 100644 --- a/suite-native/storage/tsconfig.json +++ b/suite-native/storage/tsconfig.json @@ -2,6 +2,9 @@ "extends": "../../tsconfig.base.json", "compilerOptions": { "outDir": "libDev" }, "references": [ + { + "path": "../../suite-common/firmware-authenticity" + }, { "path": "../../suite-common/suite-types" }, diff --git a/yarn.lock b/yarn.lock index e81358be91..92fca798e2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11443,6 +11443,7 @@ __metadata: "@mobily/ts-belt": "npm:^3.13.1" "@reduxjs/toolkit": "npm:2.8.2" "@sentry/react-native": "npm:6.20.0" + "@suite-common/firmware-authenticity": "workspace:*" "@suite-common/suite-types": "workspace:*" "@suite-common/wallet-core": "workspace:*" bs58: "npm:^6.0.0"