@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.
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkFirmwareRevision = void 0;
4
+ const versionUtils_1 = require("@trezor/utils/lib/versionUtils");
5
+ const downloadReleasesMetadata_1 = require("../data/downloadReleasesMetadata");
6
+ const device_1 = require("../types/device");
7
+ const calculateRevisionForDevice_1 = require("./calculateRevisionForDevice");
8
+ const getOnlineReleaseMetadata = async ({ firmwareVersion, internalModel, }) => {
9
+ const onlineReleases = await (0, downloadReleasesMetadata_1.downloadReleasesMetadata)({ internal_model: internalModel });
10
+ return onlineReleases.find(onlineRelease => (0, versionUtils_1.isEqual)(onlineRelease.version, firmwareVersion));
11
+ };
12
+ const failFirmwareRevisionCheck = (error) => ({ success: false, error });
13
+ const doRevisionsMatch = ({ deviceRevision, expectedCommitRevision, firmwareVersion, }) => {
14
+ if (deviceRevision === null) {
15
+ return false;
16
+ }
17
+ const adjustedExpected = (0, calculateRevisionForDevice_1.calculateRevisionForDevice)({
18
+ commitRevision: expectedCommitRevision,
19
+ version: firmwareVersion,
20
+ });
21
+ return adjustedExpected === deviceRevision;
22
+ };
23
+ const checkFirmwareRevision = async ({ firmwareVersion, internalModel, deviceRevision, expectedRevision, }) => {
24
+ if (internalModel !== device_1.DeviceModelInternal.T2T1 && internalModel !== device_1.DeviceModelInternal.T1B1) {
25
+ return { success: true };
26
+ }
27
+ if (expectedRevision === undefined) {
28
+ if (firmwareVersion.length !== 3) {
29
+ return failFirmwareRevisionCheck('firmware-version-unknown');
30
+ }
31
+ try {
32
+ const onlineRelease = await getOnlineReleaseMetadata({
33
+ firmwareVersion,
34
+ internalModel,
35
+ });
36
+ if ((onlineRelease === null || onlineRelease === void 0 ? void 0 : onlineRelease.firmware_revision) === undefined) {
37
+ return failFirmwareRevisionCheck('firmware-version-unknown');
38
+ }
39
+ if (!doRevisionsMatch({
40
+ deviceRevision,
41
+ expectedCommitRevision: onlineRelease.firmware_revision,
42
+ firmwareVersion,
43
+ })) {
44
+ return failFirmwareRevisionCheck('revision-mismatch');
45
+ }
46
+ return { success: true };
47
+ }
48
+ catch (e) {
49
+ return {
50
+ success: false,
51
+ error: 'cannot-perform-check-offline',
52
+ };
53
+ }
54
+ }
55
+ if (!doRevisionsMatch({
56
+ deviceRevision,
57
+ expectedCommitRevision: expectedRevision,
58
+ firmwareVersion,
59
+ })) {
60
+ return failFirmwareRevisionCheck('revision-mismatch');
61
+ }
62
+ return { success: true };
63
+ };
64
+ exports.checkFirmwareRevision = checkFirmwareRevision;
65
+ //# sourceMappingURL=checkFirmwareRevision.js.map
@@ -62,6 +62,7 @@ export interface PopupContentScriptLoaded {
62
62
  type: typeof POPUP.CONTENT_SCRIPT_LOADED;
63
63
  payload: {
64
64
  id: string;
65
+ contentScriptVersion: number;
65
66
  };
66
67
  }
67
68
  export interface PopupExtensionUsbPermissions {
@@ -11,6 +11,12 @@ export declare enum FirmwareType {
11
11
  export type UnavailableCapabilities = {
12
12
  [key: string]: UnavailableCapability;
13
13
  };
14
+ export type FirmwareRevisionCheckResult = {
15
+ success: true;
16
+ } | {
17
+ success: false;
18
+ error: 'revision-mismatch' | 'firmware-version-unknown' | 'firmware-version-unknown' | 'cannot-perform-check-offline';
19
+ };
14
20
  export type KnownDevice = {
15
21
  type: 'acquired';
16
22
  id: string | null;
@@ -28,6 +34,9 @@ export type KnownDevice = {
28
34
  features: PROTO.Features;
29
35
  unavailableCapabilities: UnavailableCapabilities;
30
36
  availableTranslations: string[];
37
+ authenticityChecks?: {
38
+ firmwareRevision: FirmwareRevisionCheckResult | null;
39
+ };
31
40
  };
32
41
  export type UnknownDevice = {
33
42
  type: 'unacquired';
@@ -10,6 +10,7 @@ export type FirmwareRelease = {
10
10
  fingerprint: string;
11
11
  changelog: string | string[];
12
12
  changelog_bitcoinonly?: string | string[];
13
+ firmware_revision?: string;
13
14
  version: VersionArray;
14
15
  min_firmware_version: VersionArray;
15
16
  min_bootloader_version: VersionArray;
@@ -1,2 +1,2 @@
1
- export declare const httpRequest: (url: string, type?: 'text' | 'binary' | 'json') => Promise<any>;
1
+ export declare const httpRequest: (url: string, type?: 'text' | 'binary' | 'json', options?: RequestInit) => Promise<any>;
2
2
  //# sourceMappingURL=assets-browser.d.ts.map
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.httpRequest = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const cross_fetch_1 = tslib_1.__importDefault(require("cross-fetch"));
6
- const httpRequest = async (url, type = 'text') => {
7
- const response = await (0, cross_fetch_1.default)(url, { credentials: 'same-origin' });
6
+ const httpRequest = async (url, type = 'text', options) => {
7
+ const init = { ...options, credentials: 'same-origin' };
8
+ const response = await (0, cross_fetch_1.default)(url, init);
8
9
  if (response.ok) {
9
10
  if (type === 'json') {
10
11
  const txt = await response.text();
@@ -1,4 +1,4 @@
1
- export declare function httpRequest(url: string, type: 'text'): Promise<string>;
2
- export declare function httpRequest(url: string, type: 'binary'): Promise<ArrayBuffer>;
3
- export declare function httpRequest(url: string, type: 'json'): Promise<Record<string, any>>;
1
+ export declare function httpRequest(url: string, type: 'text', options?: RequestInit, skipLocalForceDownload?: boolean): Promise<string>;
2
+ export declare function httpRequest(url: string, type: 'binary', options?: RequestInit, skipLocalForceDownload?: boolean): Promise<ArrayBuffer>;
3
+ export declare function httpRequest(url: string, type: 'json', options?: RequestInit, skipLocalForceDownload?: boolean): Promise<Record<string, any>>;
4
4
  //# sourceMappingURL=assets.d.ts.map
@@ -9,10 +9,10 @@ const assetUtils_1 = require("./assetUtils");
9
9
  if (global && typeof global.fetch !== 'function') {
10
10
  global.fetch = cross_fetch_1.default;
11
11
  }
12
- function httpRequest(url, type) {
13
- const asset = (0, assetUtils_1.getAssetByUrl)(url);
12
+ function httpRequest(url, type, options, skipLocalForceDownload) {
13
+ const asset = skipLocalForceDownload ? null : (0, assetUtils_1.getAssetByUrl)(url);
14
14
  if (!asset) {
15
- return /^https?/.test(url) ? (0, assets_browser_1.httpRequest)(url, type) : fs_1.promises.readFile(url);
15
+ return /^https?/.test(url) ? (0, assets_browser_1.httpRequest)(url, type, options) : fs_1.promises.readFile(url);
16
16
  }
17
17
  return asset;
18
18
  }
@@ -44,10 +44,22 @@ const getUnavailableCapabilities = (features, coins) => {
44
44
  return list;
45
45
  const fw = [features.major_version, features.minor_version, features.patch_version].join('.');
46
46
  const key = features.internal_model;
47
+ const duplicatedShortcuts = ['bnb'];
47
48
  const supported = coins.filter(info => {
48
49
  if (!info.support || info.support[key] === false) {
49
- list[info.shortcut.toLowerCase()] = 'no-support';
50
- return false;
50
+ const shortcut = info.shortcut.toLowerCase();
51
+ if (!duplicatedShortcuts.includes(shortcut)) {
52
+ list[shortcut] = 'no-support';
53
+ return false;
54
+ }
55
+ else {
56
+ const occurrences = coins.filter(coin => shortcut == coin.shortcut.toLowerCase());
57
+ const allUnsupported = occurrences.every(info => !info.support || info.support[key] === false);
58
+ if (allUnsupported) {
59
+ list[shortcut] = 'no-support';
60
+ }
61
+ return false;
62
+ }
51
63
  }
52
64
  return true;
53
65
  });
@@ -64,14 +76,18 @@ const getUnavailableCapabilities = (features, coins) => {
64
76
  if (info.type === 'nem') {
65
77
  return !capabilities.includes('Capability_NEM');
66
78
  }
67
- if (info.shortcut === 'BNB')
79
+ if (info.shortcut === 'BNB' && info.type === 'misc') {
68
80
  return !capabilities.includes('Capability_Binance');
69
- if (info.shortcut === 'ADA' || info.shortcut === 'tADA')
81
+ }
82
+ if (info.shortcut === 'ADA' || info.shortcut === 'tADA') {
70
83
  return !capabilities.includes('Capability_Cardano');
71
- if (info.shortcut === 'XRP' || info.shortcut === 'tXRP')
84
+ }
85
+ if (info.shortcut === 'XRP' || info.shortcut === 'tXRP') {
72
86
  return !capabilities.includes('Capability_Ripple');
73
- if (info.shortcut === 'SOL' || info.shortcut === 'DSOL')
87
+ }
88
+ if (info.shortcut === 'SOL' || info.shortcut === 'DSOL') {
74
89
  return !capabilities.includes('Capability_Solana');
90
+ }
75
91
  return !capabilities.includes(`Capability_${info.name}`);
76
92
  });
77
93
  unavailable.forEach(info => {
@@ -1,5 +1,5 @@
1
- export declare const resolveAfter: (msec: number, value?: any) => {
2
- promise: Promise<any>;
3
- timeout: NodeJS.Timeout | undefined;
1
+ export declare const resolveAfter: <T = void>(msec: number, value?: T | undefined) => {
2
+ promise: Promise<T>;
3
+ reject: (e: Error) => void;
4
4
  };
5
5
  //# sourceMappingURL=promiseUtils.d.ts.map
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveAfter = void 0;
4
+ const utils_1 = require("@trezor/utils");
4
5
  const resolveAfter = (msec, value) => {
5
- let timeout;
6
- const promise = new Promise(resolve => {
7
- timeout = setTimeout(resolve, msec, value);
8
- });
9
- return { promise, timeout };
6
+ const { promise, reject, resolve } = (0, utils_1.createDeferred)();
7
+ const timeout = setTimeout(resolve, msec, value);
8
+ return {
9
+ promise: promise.finally(() => clearTimeout(timeout)),
10
+ reject,
11
+ };
10
12
  };
11
13
  exports.resolveAfter = resolveAfter;
12
14
  //# sourceMappingURL=promiseUtils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trezor/connect",
3
- "version": "9.3.1-beta.1",
3
+ "version": "9.3.1-beta.3",
4
4
  "author": "Trezor <info@trezor.io>",
5
5
  "homepage": "https://github.com/trezor/trezor-suite/tree/develop/packages/connect",
6
6
  "description": "High-level javascript interface for Trezor hardware wallet.",
@@ -67,20 +67,20 @@
67
67
  "prepublish": "yarn tsx ../../scripts/prepublish.js"
68
68
  },
69
69
  "dependencies": {
70
- "@babel/preset-typescript": "^7.23.3",
70
+ "@babel/preset-typescript": "^7.24.7",
71
71
  "@ethereumjs/common": "^4.3.0",
72
72
  "@ethereumjs/tx": "^5.3.0",
73
73
  "@fivebinaries/coin-selection": "2.2.1",
74
- "@trezor/blockchain-link": "2.2.1-beta.1",
75
- "@trezor/blockchain-link-types": "1.1.1-beta.1",
76
- "@trezor/connect-analytics": "1.1.0",
77
- "@trezor/connect-common": "0.1.1-beta.1",
78
- "@trezor/protobuf": "1.1.1-beta.1",
79
- "@trezor/protocol": "1.1.0",
80
- "@trezor/schema-utils": "1.1.0",
81
- "@trezor/transport": "1.2.1-beta.1",
82
- "@trezor/utils": "9.1.1-beta.1",
83
- "@trezor/utxo-lib": "2.1.0",
74
+ "@trezor/blockchain-link": "2.2.1-beta.3",
75
+ "@trezor/blockchain-link-types": "1.1.1-beta.3",
76
+ "@trezor/connect-analytics": "1.1.1-beta.1",
77
+ "@trezor/connect-common": "0.1.1-beta.3",
78
+ "@trezor/protobuf": "1.1.1-beta.2",
79
+ "@trezor/protocol": "1.1.1-beta.1",
80
+ "@trezor/schema-utils": "1.1.1-beta.1",
81
+ "@trezor/transport": "1.2.1-beta.3",
82
+ "@trezor/utils": "9.1.1-beta.3",
83
+ "@trezor/utxo-lib": "2.1.1-beta.1",
84
84
  "blakejs": "^1.2.1",
85
85
  "bs58": "^5.0.0",
86
86
  "bs58check": "^3.0.1",
@@ -100,9 +100,9 @@
100
100
  "karma-webpack": "^5.0.1",
101
101
  "node-libs-browser": "^2.2.1",
102
102
  "ts-node": "^10.9.1",
103
- "tsx": "^4.7.0",
104
- "webpack": "^5.90.1",
105
- "ws": "^8.17.1"
103
+ "tsx": "^4.16.3",
104
+ "webpack": "^5.93.0",
105
+ "ws": "^8.18.0"
106
106
  },
107
107
  "peerDependencies": {
108
108
  "tslib": "^2.6.2"