@trezor/connect 9.3.1-beta.1 → 9.3.1-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -66,6 +66,11 @@ export declare class DataManager {
66
66
  download: string;
67
67
  update: string;
68
68
  };
69
+ opera: {
70
+ version: number;
71
+ download: string;
72
+ update: string;
73
+ };
69
74
  };
70
75
  supportedFirmware: ({
71
76
  coin: string[];
@@ -54,6 +54,11 @@ export declare const config: {
54
54
  download: string;
55
55
  update: string;
56
56
  };
57
+ opera: {
58
+ version: number;
59
+ download: string;
60
+ update: string;
61
+ };
57
62
  };
58
63
  supportedFirmware: ({
59
64
  coin: string[];
@@ -128,6 +128,11 @@ exports.config = {
128
128
  download: 'https://www.microsoft.com/en-us/edge',
129
129
  update: 'https://www.microsoft.com/en-us/edge',
130
130
  },
131
+ opera: {
132
+ version: 95,
133
+ download: 'https://www.opera.com/download',
134
+ update: 'https://www.opera.com/download',
135
+ },
131
136
  },
132
137
  supportedFirmware: [
133
138
  {
@@ -0,0 +1,7 @@
1
+ import { FirmwareRelease } from '../types';
2
+ type DownloadReleasesMetadataParams = {
3
+ internal_model: string;
4
+ };
5
+ export declare const downloadReleasesMetadata: ({ internal_model, }: DownloadReleasesMetadataParams) => Promise<FirmwareRelease[]>;
6
+ export {};
7
+ //# sourceMappingURL=downloadReleasesMetadata.d.ts.map
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.downloadReleasesMetadata = void 0;
4
+ const assets_1 = require("../utils/assets");
5
+ const firmwareUtils_1 = require("../utils/firmwareUtils");
6
+ const downloadReleasesMetadata = async ({ internal_model, }) => {
7
+ const url = `https://data.trezor.io/firmware/${internal_model.toLowerCase()}/releases.json`;
8
+ const response = (await (0, assets_1.httpRequest)(url, 'json', { signal: AbortSignal.timeout(10000) }, true));
9
+ if ((0, firmwareUtils_1.isValidReleases)(response)) {
10
+ return response;
11
+ }
12
+ return [];
13
+ };
14
+ exports.downloadReleasesMetadata = downloadReleasesMetadata;
15
+ //# sourceMappingURL=downloadReleasesMetadata.js.map
@@ -1,3 +1,4 @@
1
- export declare const VERSION = "9.3.1-beta.1";
1
+ export declare const VERSION = "9.3.1-beta.3";
2
2
  export declare const DEFAULT_DOMAIN: string;
3
+ export declare const CONTENT_SCRIPT_VERSION = 1;
3
4
  //# sourceMappingURL=version.d.ts.map
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_DOMAIN = exports.VERSION = void 0;
4
- exports.VERSION = '9.3.1-beta.1';
3
+ exports.CONTENT_SCRIPT_VERSION = exports.DEFAULT_DOMAIN = exports.VERSION = void 0;
4
+ exports.VERSION = '9.3.1-beta.3';
5
5
  const versionN = exports.VERSION.split('.').map(s => parseInt(s, 10));
6
6
  const isBeta = exports.VERSION.includes('beta');
7
7
  exports.DEFAULT_DOMAIN = isBeta
8
8
  ? `https://connect.trezor.io/${exports.VERSION}/`
9
9
  : `https://connect.trezor.io/${versionN[0]}/`;
10
+ exports.CONTENT_SCRIPT_VERSION = 1;
10
11
  //# sourceMappingURL=version.js.map
@@ -5,7 +5,7 @@ import { DeviceCommands, PassphrasePromptResponse } from './DeviceCommands';
5
5
  import { PROTO, NETWORK } from '../constants';
6
6
  import { DEVICE, DeviceButtonRequestPayload } from '../events';
7
7
  import { type Transport, type Descriptor } from '@trezor/transport';
8
- import { Device as DeviceTyped, DeviceFirmwareStatus, Features, ReleaseInfo, UnavailableCapabilities, FirmwareType } from '../types';
8
+ import { Device as DeviceTyped, DeviceFirmwareStatus, Features, ReleaseInfo, UnavailableCapabilities, FirmwareType, VersionArray, KnownDevice } from '../types';
9
9
  export type RunOptions = {
10
10
  skipFinalReload?: boolean;
11
11
  waiting?: boolean;
@@ -15,6 +15,7 @@ export type RunOptions = {
15
15
  useCardanoDerivation?: boolean;
16
16
  };
17
17
  export declare const GET_FEATURES_TIMEOUT = 3000;
18
+ export declare const GET_FEATURES_TIMEOUT_REACT_NATIVE = 20000;
18
19
  export interface DeviceEvents {
19
20
  [DEVICE.PIN]: (device: Device, b: PROTO.PinMatrixRequestType | undefined, callback: (err: any, pin: string) => void) => void;
20
21
  [DEVICE.WORD]: (device: Device, b: PROTO.WordRequestType, callback: (err: any, word: string) => void) => void;
@@ -51,6 +52,7 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
51
52
  name: string;
52
53
  color?: string;
53
54
  availableTranslations: string[];
55
+ authenticityChecks: NonNullable<KnownDevice['authenticityChecks']>;
54
56
  constructor(transport: Transport, descriptor: Descriptor);
55
57
  static fromDescriptor(transport: Transport, originalDescriptor: Descriptor): Device;
56
58
  static createUnacquired(transport: Transport, descriptor: Descriptor, unreadableError?: string): Device;
@@ -72,6 +74,7 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
72
74
  validateState(preauthorized?: boolean): Promise<string | undefined>;
73
75
  initialize(useCardanoDerivation: boolean): Promise<void>;
74
76
  getFeatures(): Promise<void>;
77
+ checkFirmwareRevision(): Promise<void>;
75
78
  changeLanguage({ language, binary, }: {
76
79
  language?: undefined;
77
80
  binary: ArrayBuffer;
@@ -89,7 +92,7 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
89
92
  isInitialized(): boolean;
90
93
  isSeedless(): boolean;
91
94
  isInconsistent(): boolean;
92
- getVersion(): never[] | [number, number, number];
95
+ getVersion(): VersionArray | [];
93
96
  atLeast(versions: string[] | string): boolean;
94
97
  isUsed(): boolean;
95
98
  isUsedHere(): boolean;
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Device = exports.GET_FEATURES_TIMEOUT = void 0;
3
+ exports.Device = exports.GET_FEATURES_TIMEOUT_REACT_NATIVE = exports.GET_FEATURES_TIMEOUT = void 0;
4
4
  const utils_1 = require("@trezor/utils");
5
5
  const protocol_1 = require("@trezor/protocol");
6
6
  const DeviceCommands_1 = require("./DeviceCommands");
7
7
  const constants_1 = require("../constants");
8
8
  const events_1 = require("../events");
9
9
  const coinInfo_1 = require("../data/coinInfo");
10
+ const DataManager_1 = require("../data/DataManager");
10
11
  const firmwareInfo_1 = require("../data/firmwareInfo");
11
12
  const deviceFeaturesUtils_1 = require("../utils/deviceFeaturesUtils");
12
13
  const debug_1 = require("../utils/debug");
@@ -14,8 +15,10 @@ const transport_1 = require("@trezor/transport");
14
15
  const types_1 = require("../types");
15
16
  const models_1 = require("../data/models");
16
17
  const getLanguage_1 = require("../data/getLanguage");
18
+ const checkFirmwareRevision_1 = require("./checkFirmwareRevision");
17
19
  const _log = (0, debug_1.initLog)('Device');
18
20
  exports.GET_FEATURES_TIMEOUT = 3000;
21
+ exports.GET_FEATURES_TIMEOUT_REACT_NATIVE = 20000;
19
22
  const parseRunOptions = (options) => {
20
23
  if (!options)
21
24
  options = {};
@@ -37,6 +40,9 @@ class Device extends utils_1.TypedEmitter {
37
40
  this.networkTypeState = [];
38
41
  this.name = 'Trezor';
39
42
  this.availableTranslations = [];
43
+ this.authenticityChecks = {
44
+ firmwareRevision: null,
45
+ };
40
46
  if (transport.name === 'BridgeTransport') {
41
47
  this.protocol = protocol_1.bridge;
42
48
  }
@@ -175,14 +181,18 @@ class Device extends utils_1.TypedEmitter {
175
181
  await this.initialize(!!options.useCardanoDerivation);
176
182
  }
177
183
  else {
184
+ const getFeaturesTimeout = DataManager_1.DataManager.getSettings('env') === 'react-native'
185
+ ? exports.GET_FEATURES_TIMEOUT_REACT_NATIVE
186
+ : exports.GET_FEATURES_TIMEOUT;
178
187
  await Promise.race([
179
188
  this.getFeatures(),
180
- new Promise((_resolve, reject) => setTimeout(() => reject(new Error('GetFeatures timeout')), exports.GET_FEATURES_TIMEOUT)),
189
+ new Promise((_resolve, reject) => setTimeout(() => reject(new Error('GetFeatures timeout')), getFeaturesTimeout)),
181
190
  ]);
182
191
  }
183
192
  }
184
193
  catch (error) {
185
- if (!this.inconsistent && error.message === 'GetFeatures timeout') {
194
+ if (!this.inconsistent &&
195
+ (error.message === 'GetFeatures timeout' || error.message === 'Unknown message')) {
186
196
  this.inconsistent = true;
187
197
  return this._runInner(() => Promise.resolve({}), options);
188
198
  }
@@ -191,7 +201,7 @@ class Device extends utils_1.TypedEmitter {
191
201
  }
192
202
  this.inconsistent = true;
193
203
  delete this.runPromise;
194
- return Promise.reject(constants_1.ERRORS.TypedError('Device_InitializeFailed', `Initialize failed: ${error.message} ${error.code ? `, code: ${error.code}` : ''}`));
204
+ return Promise.reject(constants_1.ERRORS.TypedError('Device_InitializeFailed', `Initialize failed: ${error.message}${error.code ? `, code: ${error.code}` : ''}`));
195
205
  }
196
206
  }
197
207
  if (options.keepSession) {
@@ -299,6 +309,11 @@ class Device extends utils_1.TypedEmitter {
299
309
  async getFeatures() {
300
310
  const { message } = await this.getCommands().typedCall('GetFeatures', 'Features', {});
301
311
  this._updateFeatures(message);
312
+ if (this.authenticityChecks.firmwareRevision === null ||
313
+ (this.authenticityChecks.firmwareRevision.success === false &&
314
+ this.authenticityChecks.firmwareRevision.error === 'cannot-perform-check-offline')) {
315
+ await this.checkFirmwareRevision();
316
+ }
302
317
  if (!this.features.language_version_matches &&
303
318
  this.features.language &&
304
319
  this.atLeast('2.7.0')) {
@@ -311,6 +326,25 @@ class Device extends utils_1.TypedEmitter {
311
326
  }
312
327
  }
313
328
  }
329
+ async checkFirmwareRevision() {
330
+ const firmwareVersion = this.getVersion();
331
+ if (firmwareVersion.length === 0 || !this.features) {
332
+ return;
333
+ }
334
+ if (this.features.bootloader_mode === true) {
335
+ return;
336
+ }
337
+ const releases = (0, firmwareInfo_1.getReleases)(this.features.internal_model);
338
+ const release = releases.find(r => firmwareVersion &&
339
+ utils_1.versionUtils.isVersionArray(firmwareVersion) &&
340
+ utils_1.versionUtils.isEqual(r.version, firmwareVersion));
341
+ this.authenticityChecks.firmwareRevision = await (0, checkFirmwareRevision_1.checkFirmwareRevision)({
342
+ internalModel: this.features.internal_model,
343
+ deviceRevision: this.features.revision,
344
+ firmwareVersion,
345
+ expectedRevision: release === null || release === void 0 ? void 0 : release.firmware_revision,
346
+ });
347
+ }
314
348
  async changeLanguage({ language, binary, }) {
315
349
  if (language === 'en-US') {
316
350
  return this._uploadTranslationData(null);
@@ -545,6 +579,7 @@ class Device extends utils_1.TypedEmitter {
545
579
  features: this.features,
546
580
  unavailableCapabilities: this.unavailableCapabilities,
547
581
  availableTranslations: this.availableTranslations,
582
+ authenticityChecks: this.authenticityChecks,
548
583
  };
549
584
  }
550
585
  async legacyForceRelease() {
@@ -230,7 +230,7 @@ class DeviceCommands {
230
230
  await this.transport.receive({
231
231
  session: this.sessionId,
232
232
  protocol: this.device.protocol,
233
- });
233
+ }).promise;
234
234
  throw error;
235
235
  }
236
236
  return response;
@@ -1,5 +1,5 @@
1
1
  import { TypedEmitter } from '@trezor/utils';
2
- import { Transport, TRANSPORT, Descriptor } from '@trezor/transport';
2
+ import { Transport, TRANSPORT } from '@trezor/transport';
3
3
  import { DEVICE, TransportInfo } from '../events';
4
4
  import { Device } from './Device';
5
5
  import type { ConnectSettings, Device as DeviceTyped } from '../types';
@@ -13,28 +13,43 @@ interface DeviceListEvents {
13
13
  [DEVICE.RELEASED]: DeviceTyped;
14
14
  [DEVICE.ACQUIRED]: DeviceTyped;
15
15
  }
16
- export declare class DeviceList extends TypedEmitter<DeviceListEvents> {
17
- transport: Transport;
18
- transports: Transport[];
19
- devices: {
20
- [path: string]: Device;
21
- };
22
- creatingDevicesDescriptors: {
23
- [k: string]: Descriptor;
24
- };
25
- transportStartPending: number;
26
- penalizedDevices: {
27
- [deviceID: string]: number;
28
- };
29
- transportFirstEventPromise: Promise<void> | undefined;
30
- private settings;
31
- constructor({ settings, messages, }: {
32
- settings: ConnectSettings;
33
- messages: Record<string, any>;
34
- });
35
- init(): Promise<void>;
36
- private resolveTransportEvent;
37
- waitForTransportFirstEvent(): Promise<void>;
16
+ export interface IDeviceList {
17
+ isConnected(): this is DeviceList;
18
+ pendingConnection(): Promise<void> | undefined;
19
+ setTransports: DeviceList['setTransports'];
20
+ addAuthPenalty: DeviceList['addAuthPenalty'];
21
+ removeAuthPenalty: DeviceList['removeAuthPenalty'];
22
+ on: DeviceList['on'];
23
+ once: DeviceList['once'];
24
+ init: DeviceList['init'];
25
+ dispose: DeviceList['dispose'];
26
+ }
27
+ export declare const assertDeviceListConnected: (deviceList: IDeviceList) => asserts deviceList is DeviceList;
28
+ type ConstructorParams = Pick<ConnectSettings, 'priority' | 'debug'> & {
29
+ messages: Record<string, any>;
30
+ };
31
+ type InitParams = Pick<ConnectSettings, 'pendingTransportEvent' | 'transportReconnect'>;
32
+ export declare class DeviceList extends TypedEmitter<DeviceListEvents> implements IDeviceList {
33
+ private transport;
34
+ private transports;
35
+ private devices;
36
+ private creatingDevicesDescriptors;
37
+ private readonly authPenaltyManager;
38
+ private initPromise?;
39
+ private rejectPending?;
40
+ private transportCommonArgs;
41
+ isConnected(): this is DeviceList;
42
+ pendingConnection(): Promise<void> | undefined;
43
+ constructor({ messages, priority, debug }: ConstructorParams);
44
+ private createTransport;
45
+ setTransports(transports: ConnectSettings['transports']): void;
46
+ private onTransportUpdate;
47
+ init(initParams?: InitParams): Promise<void>;
48
+ private createInitPromise;
49
+ private createReconnectPromise;
50
+ private selectTransport;
51
+ private initializeTransport;
52
+ private waitForDevices;
38
53
  private _createAndSaveDevice;
39
54
  private _createUnacquiredDevice;
40
55
  private _createUnreadableDevice;
@@ -45,11 +60,10 @@ export declare class DeviceList extends TypedEmitter<DeviceListEvents> {
45
60
  length(): number;
46
61
  transportType(): "BridgeTransport" | "NodeUsbTransport" | "WebUsbTransport" | "UdpTransport";
47
62
  getTransportInfo(): TransportInfo;
48
- dispose(): void;
49
- disconnectDevices(): void;
50
- enumerate(): Promise<void>;
63
+ dispose(): Promise<void>;
64
+ cleanup(): Promise<void>;
65
+ enumerate(transport?: Transport): Promise<void>;
51
66
  addAuthPenalty(device: Device): void;
52
- private getAuthPenalty;
53
67
  removeAuthPenalty(device: Device): void;
54
68
  private handle;
55
69
  private _takeAndCreateDevice;