mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-02-20 00:33:07 +01:00
feat(suite-native): filterInconclusiveAuthenticityChecks also in mobile
This commit is contained in:
committed by
Jiri Zbytovsky
parent
c0d1ef91c3
commit
fbdfdec3b8
@@ -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
|
||||
|
||||
@@ -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 };
|
||||
};
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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<TrezorDevice, 'path'> & { path: '' } => ({
|
||||
const serializeDevice = (device: AcquiredDevice): Omit<AcquiredDevice, 'path'> & { 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),
|
||||
),
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": { "outDir": "libDev" },
|
||||
"references": [
|
||||
{
|
||||
"path": "../../suite-common/firmware-authenticity"
|
||||
},
|
||||
{
|
||||
"path": "../../suite-common/suite-types"
|
||||
},
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user