chore(transport): add model to DescriptorApiLevel

This commit is contained in:
Szymon Lesisz
2026-01-27 12:01:45 +01:00
committed by Szymon Lesisz
parent 53bdac4062
commit 45529fd576
7 changed files with 59 additions and 1 deletions

View File

@@ -131,7 +131,7 @@ type DeviceParams = {
export class Device extends TypedEmitter<DeviceEvents> {
public readonly transport: Transport;
private thp: protocolThp.ThpState | undefined;
public readonly descriptor: Pick<Descriptor, 'apiType' | 'id' | 'type' | 'path'>;
public readonly descriptor: Pick<Descriptor, 'apiType' | 'id' | 'type' | 'path' | 'model'>;
private sessionAcquired: Session | null;
// protocol related
@@ -239,6 +239,7 @@ export class Device extends TypedEmitter<DeviceEvents> {
apiType: descriptor.apiType,
type: descriptor.type,
path: descriptor.path,
model: descriptor.model,
// session, sessionOwner are handled separately
// debug, debugSession are not relevant here
};

View File

@@ -6,6 +6,7 @@ import {
import { DEVICE_TYPE } from '@trezor/transport/src/constants';
import * as ERRORS from '@trezor/transport/src/errors';
import { PathInternal } from '@trezor/transport/src/types';
import { getBLEDescriptorModel } from '@trezor/transport/src/utils/descriptor';
import { readMessageBuffer } from '@trezor/transport/src/utils/readMessageBuffer';
import { TrezorBluetooth } from './trezor-bluetooth';
@@ -36,6 +37,7 @@ export class BluetoothApi extends AbstractApi {
type: DEVICE_TYPE.TypeBluetooth,
id: device.id,
apiType: this.type,
model: getBLEDescriptorModel(device.data[2]),
}));
}

View File

@@ -15,6 +15,7 @@ import {
} from '../constants';
import * as ERRORS from '../errors';
import { DescriptorApiLevel, PathInternal } from '../types';
import { getUSBDescriptorModel } from '../utils/descriptor';
interface ConstructorParams extends Omit<AbstractApiConstructorParams, 'type'> {
usbInterface: USB;
@@ -136,6 +137,7 @@ export class UsbApi extends AbstractApi {
vendor: d.device.vendorId,
id: d.device.serialNumber,
apiType: this.type,
model: getUSBDescriptorModel(d.device),
}));
}

View File

@@ -1,6 +1,7 @@
import { Branded } from '@trezor/type-utils';
import { DEVICE_TYPE } from '../constants';
import type { DescriptorModel } from '../utils/descriptor';
export * from './apiCall';
@@ -24,6 +25,8 @@ export type DescriptorApiLevel = {
apiType: ApiType;
/** api level device id. */
id?: string;
/** api level device model */
model?: DescriptorModel;
};
export type Descriptor = Omit<DescriptorApiLevel, 'path'> & {

View File

@@ -65,6 +65,7 @@ export function devices(res: UnknownPayload) {
debugSession: o.debugSession,
id: o.id,
apiType: o.apiType || 'usb', // no other option is implemented at this moment
model: o.model,
}),
),
);

View File

@@ -0,0 +1,47 @@
/**
* references: DeviceModelInternal, MODEL_BLE_CODE
* DeviceModelInternal represented as number
*/
export enum DescriptorModel {
UNKNOWN = 0,
T1B1 = 1,
T2T1 = 2,
T2B1 = 3,
T3B1 = 4,
T3T1 = 5,
T3W1 = 6,
}
/**
* Returns DescriptorModel from USBDevice
*/
export const getUSBDescriptorModel = (device: USBDevice): DescriptorModel => {
if (device.deviceVersionMajor === 1) {
return DescriptorModel.T1B1;
}
if (device.deviceVersionMajor === 2) {
switch (device.productName) {
case 'TREZOR':
return DescriptorModel.T2T1;
case 'Trezor Safe 3':
return DescriptorModel.T3B1; // NOTE: this could be also T2B1
case 'Trezor Safe 5':
return DescriptorModel.T3T1;
case 'Trezor Safe 7':
return DescriptorModel.T3W1;
default:
return DescriptorModel.UNKNOWN;
}
}
return DescriptorModel.UNKNOWN;
};
/**
* Returns DescriptorModel from bluetooth Manufacturer Data [2] byte. see MODEL_BLE_CODE
*/
export const getBLEDescriptorModel = (data: number | undefined): DescriptorModel =>
typeof data === 'number' && Object.values(DescriptorModel).includes(data)
? data
: DescriptorModel.UNKNOWN;

View File

@@ -140,6 +140,7 @@ describe('Usb', () => {
path: '1',
session: null,
type: 1,
model: 0,
product: 21441,
vendor: 4617,
apiType: 'usb',
@@ -149,6 +150,7 @@ describe('Usb', () => {
path: '2',
session: null,
type: 1,
model: 0,
product: 21441,
vendor: 4617,
apiType: 'usb',