Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Bluetooth components for onboarding #15514

Draft
wants to merge 18 commits into
base: feat/rust-bluetooth
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/packages/suite-desktop.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ Available flags:

`appimage-run ./Trezor-Suite.AppImage --log-level=debug`

#### Windows

`"C:\Users\[user-name]\AppData\Local\Programs\Trezor Suite\Trezor Suite.exe" --log-level=debug`

## Extract application

#### MacOS
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/NewModal/types.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UIVariant, UISize, UIHorizontalAlignment, UIVerticalAlignment } from '../../config/types';

export const newModalVariants = ['primary', 'warning', 'destructive'] as const;
export const newModalVariants = ['primary', 'warning', 'destructive', 'info'] as const;
export type NewModalVariant = Extract<UIVariant, (typeof newModalVariants)[number]>;

export const newModalSizes = ['huge', 'large', 'medium', 'small', 'tiny'] as const;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled, { css } from 'styled-components';

import { Elevation, borders, mapElevationToBackground } from '@trezor/theme';
import { Elevation, borders, mapElevationToBackground, nextElevation } from '@trezor/theme';

Check failure on line 3 in packages/components/src/components/skeletons/SkeletonRectangle.tsx

View workflow job for this annotation

GitHub Actions / Linting and formatting

'nextElevation' is defined but never used. Allowed unused vars must match /^_/u

import { SkeletonBaseProps } from './types';
import { getValue, shimmerEffect } from './utils';
Expand All @@ -18,7 +18,12 @@
>`
width: ${({ $width }) => getValue($width) ?? '80px'};
height: ${({ $height }) => getValue($height) ?? '20px'};
background: ${({ $background, ...props }) => $background ?? mapElevationToBackground(props)};
background: ${({ $background, ...props }) =>
$background ??
mapElevationToBackground({
theme: props.theme,
$elevation: props.$elevation,
})};
border-radius: ${({ $borderRadius }) => getValue($borderRadius) ?? borders.radii.xs};
background-size: 200%;

Expand Down
26 changes: 26 additions & 0 deletions packages/connect/src/api/eraseBonds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// origin: https://github.com/trezor/connect/blob/develop/src/js/core/methods/ApplyFlags.js

import { AbstractMethod } from '../core/AbstractMethod';
import { UI } from '../events';
import { PROTO } from '../constants';

Check warning on line 5 in packages/connect/src/api/eraseBonds.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

There should be at least one empty line between import groups
import { Assert } from '@trezor/schema-utils';

Check warning on line 6 in packages/connect/src/api/eraseBonds.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

`@trezor/schema-utils` import should occur before import of `../core/AbstractMethod`

export default class EraseBonds extends AbstractMethod<'eraseBonds', PROTO.ApplyFlags> {
init() {
this.allowDeviceMode = [UI.INITIALIZE, UI.SEEDLESS];
this.requiredPermissions = ['management'];
this.useDeviceState = false;
this.skipFinalReload = true;

const { payload } = this;

Assert(PROTO.EraseBonds, payload);
}

async run() {
const cmd = this.device.getCommands();
const response = await cmd.typedCall('EraseBonds', 'Success', {});

return response.message;
}
}
1 change: 1 addition & 0 deletions packages/connect/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export { default as cipherKeyValue } from './cipherKeyValue';
export { default as composeTransaction } from './composeTransaction';
// export { default as disableWebUSB } from './disableWebUSB';
// export { default as dispose } from './dispose';
export { default as eraseBonds } from './eraseBonds';
export { default as getAccountDescriptor } from './getAccountDescriptor';
export { default as getAccountInfo } from './getAccountInfo';
export { default as getAddress } from './getAddress';
Expand Down
11 changes: 9 additions & 2 deletions packages/connect/src/data/models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
const safe3Model = {
import { DeviceModelInternal } from '@trezor/protobuf';

type ModelConfig = {
name: string;
colors: Record<string, string>;
};

const safe3Model: ModelConfig = {
name: 'Trezor Safe 3',
colors: {
'1': 'Cosmic Black',
Expand All @@ -9,7 +16,7 @@ const safe3Model = {
},
};

export const models = {
export const models: Record<DeviceModelInternal, ModelConfig> = {
T1B1: {
name: 'Trezor Model One',
colors: {},
Expand Down
2 changes: 2 additions & 0 deletions packages/connect/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export const factory = <

composeTransaction: params => call({ ...params, method: 'composeTransaction' }),

eraseBonds: params => call({ ...params, method: 'eraseBonds' }),

ethereumGetAddress: params =>
call({
...params,
Expand Down
4 changes: 4 additions & 0 deletions packages/connect/src/types/api/eraseBonds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { PROTO } from '../../constants';
import type { Params, Response } from '../params';

export declare function eraseBonds(params: Params<PROTO.EraseBonds>): Response<PROTO.Success>;
4 changes: 4 additions & 0 deletions packages/connect/src/types/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { ethereumSignMessage } from './ethereumSignMessage';
import { ethereumSignTransaction } from './ethereumSignTransaction';
import { ethereumSignTypedData } from './ethereumSignTypedData';
import { ethereumVerifyMessage } from './ethereumVerifyMessage';
import { eraseBonds } from './eraseBonds';
import { firmwareUpdate } from './firmwareUpdate';
import { getAccountDescriptor } from './getAccountDescriptor';
import { getAccountInfo } from './getAccountInfo';
Expand Down Expand Up @@ -210,6 +211,9 @@ export interface TrezorConnect {
// https://connect.trezor.io/9/methods/ethereum/ethereumVerifyMessage/
ethereumVerifyMessage: typeof ethereumVerifyMessage;

// https://connect.trezor.io/9/methods/device/eraseBonds/
eraseBonds: typeof eraseBonds;

// https://connect.trezor.io/9/methods/device/firmwareUpdate/
firmwareUpdate: typeof firmwareUpdate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ export const RotateDeviceImage = ({

const isDeviceImageRotating =
deviceModel &&
[DeviceModelInternal.T2B1, DeviceModelInternal.T3B1, DeviceModelInternal.T3T1].includes(
deviceModel,
);
[
DeviceModelInternal.T2B1,
DeviceModelInternal.T3B1,
DeviceModelInternal.T3T1,
DeviceModelInternal.T3W1,
].includes(deviceModel);

return (
<>
Expand Down
4 changes: 4 additions & 0 deletions packages/protobuf/messages.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"nested": {
"EraseBonds": {
"fields": {}
},
"BinanceGetAddress": {
"fields": {
"address_n": {
Expand Down Expand Up @@ -6863,6 +6866,7 @@
"BinanceOrderMsg": 707,
"BinanceCancelMsg": 708,
"BinanceSignedTx": 709,
"EraseBonds": 8006,
"SolanaGetPublicKey": 900,
"SolanaPublicKey": 901,
"SolanaGetAddress": 902,
Expand Down
4 changes: 4 additions & 0 deletions packages/protobuf/src/messages-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2424,6 +2424,9 @@ export const ApplyFlags = Type.Object(
{ $id: 'ApplyFlags' },
);

export type EraseBonds = Static<typeof EraseBonds>;
export const EraseBonds = Type.Object({});

export type ChangePin = Static<typeof ChangePin>;
export const ChangePin = Type.Object(
{
Expand Down Expand Up @@ -3487,6 +3490,7 @@ export const TezosSignedTx = Type.Object(
export type MessageType = Static<typeof MessageType>;
export const MessageType = Type.Object(
{
EraseBonds,
BinanceGetAddress,
BinanceAddress,
BinanceGetPublicKey,
Expand Down
3 changes: 3 additions & 0 deletions packages/protobuf/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export enum DeviceModelInternal {
T3W1 = 'T3W1',
}

export type EraseBonds = {};

export type BinanceGetAddress = {
address_n: number[];
show_display?: boolean;
Expand Down Expand Up @@ -2256,6 +2258,7 @@ export type TezosSignedTx = {

// custom connect definitions
export type MessageType = {
EraseBonds: EraseBonds;
BinanceGetAddress: BinanceGetAddress;
BinanceAddress: BinanceAddress;
BinanceGetPublicKey: BinanceGetPublicKey;
Expand Down
27 changes: 27 additions & 0 deletions packages/suite-build/configs/desktop.webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,33 @@ const config: webpack.Configuration = {
to: path.join(baseDir, 'build/static/bin/firmware'),
},
])
// include bluetooth binaries from @trezor/transport-bluetooth
.concat([
{
from: path.join(__dirname, '../../', 'transport-bluetooth/bin/linux'),
to: path.join(baseDir, 'build/static/bin/bluetooth/linux-x64'),
},
{
from: path.join(__dirname, '../../', 'transport-bluetooth/bin/linux'),
to: path.join(baseDir, 'build/static/bin/bluetooth/linux-arm64'),
},
{
from: path.join(__dirname, '../../', 'transport-bluetooth/bin/macos'),
to: path.join(baseDir, 'build/static/bin/bluetooth/mac-x64'),
},
{
from: path.join(__dirname, '../../', 'transport-bluetooth/bin/macos'),
to: path.join(baseDir, 'build/static/bin/bluetooth/mac-arm64'),
},
{
from: path.join(__dirname, '../../', 'transport-bluetooth/bin/windows'),
to: path.join(baseDir, 'build/static/bin/bluetooth/win-x64'),
},
{
from: path.join(__dirname, '../../', 'transport-bluetooth/bin/windows'),
to: path.join(baseDir, 'build/static/bin/bluetooth/win-arm64'),
},
])
.concat(
isCodesignBuild
? []
Expand Down
18 changes: 17 additions & 1 deletion packages/suite-desktop-api/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Status,
BridgeSettings,
TorSettings,
TraySettings,
TraySettings, ElectronBluetoothDevice
} from './messages';

// Event messages from renderer to main process
Expand All @@ -37,6 +37,7 @@ export interface MainChannels {
'update/download': void;
'update/install': void;
'logger/config': LoggerConfig;
'bluetooth/request-device': void;
}

// Event messages from main to renderer process
Expand Down Expand Up @@ -72,6 +73,11 @@ export interface RendererChannels {
'tray/settings': TraySettings;

'handshake/event': HandshakeEvent;
'bluetooth/event': any;
'bluetooth/adapter-event': boolean;
'bluetooth/select-device-event': ElectronBluetoothDevice[];
'bluetooth/pair-device-event': { paired: boolean; pin: string };
'bluetooth/connect-device-event': any;
}

// Invocation from renderer process
Expand Down Expand Up @@ -99,6 +105,11 @@ export interface InvokeChannels {
'app/auto-start/is-enabled': () => InvokeResult<boolean>;
'tray/change-settings': (payload: TraySettings) => InvokeResult;
'tray/get-settings': () => InvokeResult<TraySettings>;
'bluetooth/open-settings': () => InvokeResult;
'bluetooth/start-scan': () => InvokeResult;
'bluetooth/stop-scan': () => InvokeResult;
'bluetooth/connect-device': (uuid: string) => InvokeResult;
'bluetooth/forget-device': (uuid: string) => InvokeResult;
}

type DesktopApiListener = ListenerMethod<RendererChannels>;
Expand Down Expand Up @@ -161,4 +172,9 @@ export interface DesktopApi {
// Tray
changeTraySettings: DesktopApiInvoke<'tray/change-settings'>;
getTraySettings: DesktopApiInvoke<'tray/get-settings'>;
bluetoothOpenSettings: DesktopApiInvoke<'bluetooth/open-settings'>;
bluetoothStartScan: DesktopApiInvoke<'bluetooth/start-scan'>;
bluetoothStopScan: DesktopApiInvoke<'bluetooth/stop-scan'>;
bluetoothConnectDevice: DesktopApiInvoke<'bluetooth/connect-device'>;
bluetoothRequestDevice: DesktopApiSend<'bluetooth/request-device'>;
}
5 changes: 5 additions & 0 deletions packages/suite-desktop-api/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,10 @@ export const factory = <R extends StrictIpcRenderer<any, IpcRendererEvent>>(
return Promise.resolve({ success: false, error: 'invalid params' });
},
getTraySettings: () => ipcRenderer.invoke('tray/get-settings'),
bluetoothOpenSettings: () => ipcRenderer.invoke('bluetooth/open-settings'),
bluetoothStartScan: () => ipcRenderer.invoke('bluetooth/start-scan'),
bluetoothStopScan: () => ipcRenderer.invoke('bluetooth/stop-scan'),
bluetoothConnectDevice: uuid => ipcRenderer.invoke('bluetooth/connect-device', uuid),
bluetoothRequestDevice: () => ipcRenderer.send('bluetooth/request-device'), // TODO: invoke
};
};
1 change: 1 addition & 0 deletions packages/suite-desktop-api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type {
BootstrapTorEvent,
TorStatusEvent,
HandshakeTorModule,
ElectronBluetoothDevice,
} from './messages';

export { TorStatus } from './enums';
11 changes: 11 additions & 0 deletions packages/suite-desktop-api/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,14 @@ export type InvokeResult<Payload = undefined> =
ExtractUndefined<Payload> extends undefined
? { success: true; payload?: Payload } | { success: false; error: string; code?: string }
: { success: true; payload: Payload } | { success: false; error: string; code?: string };

export interface ElectronBluetoothDevice {
uuid: string;
name: string;
paired: boolean;
connected: boolean;
timestamp: number;
rssi: number;
model: string;
color: string;
}
5 changes: 5 additions & 0 deletions packages/suite-desktop-api/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,10 @@ const validChannels: Array<keyof RendererChannels> = [
'bridge/status',
'bridge/settings',
'tray/settings',
'bluetooth/event',
'bluetooth/adapter-event',
'bluetooth/select-device-event',
'bluetooth/pair-device-event',
'bluetooth/connect-device-event',
];
export const isValidChannel = (channel: any) => validChannels.includes(channel);
1 change: 1 addition & 0 deletions packages/suite-desktop-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@trezor/node-utils": "workspace:*",
"@trezor/request-manager": "workspace:*",
"@trezor/suite-desktop-api": "workspace:*",
"@trezor/transport-bluetooth": "workspace:*",
"@trezor/transport-bridge": "workspace:*",
"@trezor/urls": "workspace:*",
"@trezor/utils": "workspace:*",
Expand Down
13 changes: 11 additions & 2 deletions packages/suite-desktop-core/src/libs/processes/BaseProcess.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { app } from 'electron';
import path from 'path';
import { spawn, ChildProcess } from 'child_process';
import { spawn, ChildProcess, IOType } from 'child_process';

import { b2t } from '../utils';

Expand All @@ -18,6 +18,7 @@ export type Options = {
startupCooldown?: number;
stopKillWait?: number;
autoRestart?: number;
stdio?: [IOType, IOType, IOType];
};

const defaultOptions: Options = {
Expand Down Expand Up @@ -144,10 +145,18 @@ export abstract class BaseProcess {
this.process = spawn(processPath, params, {
cwd: processDir,
env: processEnv,
stdio: ['ignore', 'ignore', 'ignore'],
stdio: this.options.stdio || ['ignore', 'ignore', 'ignore'],
});
this.process.on('error', err => this.onError(err));
this.process.on('exit', code => this.onExit(code));
// if (this.options.stdio) {
// this.process.stdout?.on('data', d => {
// console.warn('STDOUT DATA', d.toString());
// });
// this.process.stderr?.on('data', d => {
// console.warn('STDERR DATA', d.toString());
// });
// }

if (this.options.autoRestart && this.options.autoRestart > 0) {
// When process runs with `autoRestart`, restarting the process is managed by BaseProcess.
Expand Down
Loading
Loading