@trezor/connect 9.2.2 → 9.2.4-beta.1

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.
Files changed (174) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/README.md +1 -1
  3. package/lib/api/applyFlags.d.ts +8 -1
  4. package/lib/api/applyFlags.js +3 -8
  5. package/lib/api/applySettings.d.ts +8 -1
  6. package/lib/api/applySettings.js +3 -8
  7. package/lib/api/backupDevice.d.ts +10 -2
  8. package/lib/api/backupDevice.js +12 -9
  9. package/lib/api/binance/api/binanceGetAddress.d.ts +4 -3
  10. package/lib/api/binance/api/binanceGetAddress.js +8 -22
  11. package/lib/api/binance/api/binanceGetPublicKey.d.ts +4 -2
  12. package/lib/api/binance/api/binanceGetPublicKey.js +6 -18
  13. package/lib/api/blockchainDisconnect.d.ts +1 -0
  14. package/lib/api/blockchainDisconnect.js +3 -4
  15. package/lib/api/blockchainEstimateFee.d.ts +1 -0
  16. package/lib/api/blockchainEstimateFee.js +6 -4
  17. package/lib/api/blockchainGetAccountBalanceHistory.d.ts +1 -0
  18. package/lib/api/blockchainGetAccountBalanceHistory.js +3 -1
  19. package/lib/api/blockchainGetCurrentFiatRates.d.ts +1 -0
  20. package/lib/api/blockchainGetCurrentFiatRates.js +3 -1
  21. package/lib/api/blockchainGetFiatRatesForTimestamps.d.ts +1 -0
  22. package/lib/api/blockchainGetFiatRatesForTimestamps.js +3 -1
  23. package/lib/api/blockchainGetTransactions.d.ts +1 -0
  24. package/lib/api/blockchainGetTransactions.js +3 -1
  25. package/lib/api/blockchainSetCustomBackend.js +1 -5
  26. package/lib/api/blockchainSubscribe.d.ts +2 -0
  27. package/lib/api/blockchainSubscribe.js +13 -2
  28. package/lib/api/blockchainSubscribeFiatRates.d.ts +1 -0
  29. package/lib/api/blockchainSubscribeFiatRates.js +3 -1
  30. package/lib/api/blockchainUnsubscribe.d.ts +1 -0
  31. package/lib/api/blockchainUnsubscribe.js +5 -2
  32. package/lib/api/blockchainUnsubscribeFiatRates.d.ts +1 -0
  33. package/lib/api/blockchainUnsubscribeFiatRates.js +6 -2
  34. package/lib/api/cardano/api/cardanoGetAddress.d.ts +4 -3
  35. package/lib/api/cardano/api/cardanoGetAddress.js +8 -22
  36. package/lib/api/cardano/api/cardanoGetPublicKey.d.ts +4 -3
  37. package/lib/api/cardano/api/cardanoGetPublicKey.js +9 -31
  38. package/lib/api/changeLanguage.d.ts +8 -2
  39. package/lib/api/changeLanguage.js +10 -51
  40. package/lib/api/composeTransaction.d.ts +2 -0
  41. package/lib/api/composeTransaction.js +10 -5
  42. package/lib/api/eos/api/eosGetPublicKey.d.ts +4 -2
  43. package/lib/api/eos/api/eosGetPublicKey.js +6 -18
  44. package/lib/api/eos/eosSignTx.d.ts +3 -3
  45. package/lib/api/ethereum/api/ethereumGetAddress.d.ts +4 -3
  46. package/lib/api/ethereum/api/ethereumGetAddress.js +4 -20
  47. package/lib/api/ethereum/api/ethereumGetPublicKey.d.ts +4 -2
  48. package/lib/api/ethereum/api/ethereumGetPublicKey.js +3 -10
  49. package/lib/api/ethereum/api/ethereumSignTypedData.d.ts +2 -1
  50. package/lib/api/ethereum/ethereumDefinitions.js +1 -0
  51. package/lib/api/firmware/index.d.ts +2 -0
  52. package/lib/api/firmware/index.js +5 -1
  53. package/lib/api/firmware/parseFirmwareHeaders.d.ts +5 -0
  54. package/lib/api/firmware/parseFirmwareHeaders.js +35 -0
  55. package/lib/api/firmware/uploadFirmware.d.ts +1 -1
  56. package/lib/api/firmware/uploadFirmware.js +9 -1
  57. package/lib/api/getAccountDescriptor.d.ts +5 -3
  58. package/lib/api/getAccountDescriptor.js +8 -21
  59. package/lib/api/getAccountInfo.d.ts +23 -7
  60. package/lib/api/getAccountInfo.js +16 -28
  61. package/lib/api/getAddress.d.ts +4 -3
  62. package/lib/api/getAddress.js +8 -22
  63. package/lib/api/getCoinInfo.d.ts +3 -0
  64. package/lib/api/getFeatures.d.ts +1 -0
  65. package/lib/api/getOwnershipId.d.ts +4 -2
  66. package/lib/api/getOwnershipId.js +4 -15
  67. package/lib/api/getOwnershipProof.d.ts +4 -2
  68. package/lib/api/getOwnershipProof.js +4 -15
  69. package/lib/api/getPublicKey.d.ts +5 -4
  70. package/lib/api/getPublicKey.js +12 -35
  71. package/lib/api/index.d.ts +0 -1
  72. package/lib/api/index.js +1 -3
  73. package/lib/api/nem/api/nemGetAddress.d.ts +4 -3
  74. package/lib/api/nem/api/nemGetAddress.js +4 -20
  75. package/lib/api/pushTransaction.d.ts +1 -0
  76. package/lib/api/pushTransaction.js +2 -1
  77. package/lib/api/rebootToBootloader.d.ts +8 -2
  78. package/lib/api/rebootToBootloader.js +3 -10
  79. package/lib/api/recoveryDevice.d.ts +8 -1
  80. package/lib/api/recoveryDevice.js +3 -7
  81. package/lib/api/resetDevice.d.ts +5 -3
  82. package/lib/api/resetDevice.js +5 -12
  83. package/lib/api/ripple/api/rippleGetAddress.d.ts +4 -3
  84. package/lib/api/ripple/api/rippleGetAddress.js +4 -20
  85. package/lib/api/signTransaction.d.ts +1 -0
  86. package/lib/api/signTransaction.js +5 -3
  87. package/lib/api/solana/api/solanaGetAddress.d.ts +4 -3
  88. package/lib/api/solana/api/solanaGetAddress.js +7 -28
  89. package/lib/api/solana/api/solanaGetPublicKey.d.ts +4 -3
  90. package/lib/api/solana/api/solanaGetPublicKey.js +7 -27
  91. package/lib/api/stellar/api/stellarGetAddress.d.ts +4 -3
  92. package/lib/api/stellar/api/stellarGetAddress.js +4 -20
  93. package/lib/api/tezos/api/tezosGetAddress.d.ts +4 -3
  94. package/lib/api/tezos/api/tezosGetAddress.js +4 -20
  95. package/lib/api/tezos/api/tezosGetPublicKey.d.ts +4 -2
  96. package/lib/api/tezos/api/tezosGetPublicKey.js +6 -18
  97. package/lib/api/wipeDevice.d.ts +8 -2
  98. package/lib/api/wipeDevice.js +3 -10
  99. package/lib/backend/BackendManager.d.ts +6 -4
  100. package/lib/backend/BackendManager.js +36 -28
  101. package/lib/backend/Blockchain.d.ts +15 -4
  102. package/lib/backend/Blockchain.js +27 -17
  103. package/lib/backend/BlockchainLink.d.ts +3 -3
  104. package/lib/backend/BlockchainLink.js +3 -3
  105. package/lib/constants/errors.d.ts +1 -0
  106. package/lib/constants/errors.js +1 -0
  107. package/lib/core/AbstractMethod.d.ts +4 -8
  108. package/lib/core/AbstractMethod.js +7 -28
  109. package/lib/core/index.d.ts +2 -1
  110. package/lib/core/index.js +260 -231
  111. package/lib/core/onCallFirmwareUpdate.d.ts +31 -0
  112. package/lib/core/onCallFirmwareUpdate.js +259 -0
  113. package/lib/data/DataManager.d.ts +22 -0
  114. package/lib/data/DataManager.js +7 -3
  115. package/lib/data/analyticsInfo.d.ts +2 -2
  116. package/lib/data/analyticsInfo.js +6 -7
  117. package/lib/data/coinInfo.d.ts +14 -0
  118. package/lib/data/config.d.ts +22 -0
  119. package/lib/data/config.js +5 -1
  120. package/lib/data/connectSettings.js +3 -0
  121. package/lib/data/deviceAuthenticityConfig.d.ts +9 -0
  122. package/lib/data/deviceAuthenticityConfig.js +27 -3
  123. package/lib/data/firmwareInfo.js +2 -6
  124. package/lib/data/getLanguage.d.ts +6 -0
  125. package/lib/data/getLanguage.js +10 -0
  126. package/lib/data/models.d.ts +9 -0
  127. package/lib/data/models.js +9 -0
  128. package/lib/data/version.d.ts +1 -1
  129. package/lib/data/version.js +1 -1
  130. package/lib/device/Device.d.ts +13 -2
  131. package/lib/device/Device.js +55 -7
  132. package/lib/device/DeviceCommands.d.ts +3 -15
  133. package/lib/device/DeviceCommands.js +1 -43
  134. package/lib/device/DeviceList.d.ts +1 -1
  135. package/lib/device/DeviceList.js +22 -19
  136. package/lib/events/blockchain.d.ts +3 -0
  137. package/lib/events/index.d.ts +1 -0
  138. package/lib/events/ui-request.d.ts +13 -1
  139. package/lib/events/ui-request.js +1 -0
  140. package/lib/index.js +2 -2
  141. package/lib/types/api/authenticateDevice.d.ts +9 -0
  142. package/lib/types/api/backupDevice.d.ts +2 -2
  143. package/lib/types/api/bitcoin/index.d.ts +1 -0
  144. package/lib/types/api/blockchainSetCustomBackend.d.ts +3 -2
  145. package/lib/types/api/blockchainSubscribe.d.ts +1 -0
  146. package/lib/types/api/composeTransaction.d.ts +2 -0
  147. package/lib/types/api/dispose.d.ts +1 -1
  148. package/lib/types/api/firmwareUpdate.d.ts +7 -6
  149. package/lib/types/api/firmwareUpdate.js +1 -3
  150. package/lib/types/api/getAccountInfo.d.ts +1 -0
  151. package/lib/types/api/getCoinInfo.d.ts +4 -2
  152. package/lib/types/api/nemGetAddress.d.ts +11 -4
  153. package/lib/types/api/nemGetAddress.js +9 -0
  154. package/lib/types/api/pushTransaction.d.ts +1 -0
  155. package/lib/types/api/pushTransaction.js +1 -0
  156. package/lib/types/api/resetDevice.d.ts +1 -15
  157. package/lib/types/api/resetDevice.js +0 -9
  158. package/lib/types/api/setBusy.d.ts +2 -2
  159. package/lib/types/coinInfo.d.ts +15 -7
  160. package/lib/types/coinInfo.js +8 -6
  161. package/lib/types/firmware.d.ts +5 -15
  162. package/lib/types/params.d.ts +1 -0
  163. package/lib/types/params.js +1 -2
  164. package/lib/types/settings.d.ts +1 -0
  165. package/lib/utils/assetUtils.js +18 -8
  166. package/lib/utils/popupPromiseManager.d.ts +8 -0
  167. package/lib/utils/popupPromiseManager.js +21 -0
  168. package/lib/utils/uiPromiseManager.d.ts +38 -0
  169. package/lib/utils/uiPromiseManager.js +47 -0
  170. package/lib/workers/workers-browser.d.ts +3 -1
  171. package/lib/workers/workers-browser.js +2 -2
  172. package/package.json +10 -10
  173. package/lib/api/firmwareUpdate.d.ts +0 -19
  174. package/lib/api/firmwareUpdate.js +0 -78
@@ -15,6 +15,7 @@ class TezosGetAddress extends AbstractMethod_1.AbstractMethod {
15
15
  this.progress = 0;
16
16
  }
17
17
  init() {
18
+ this.noBackupConfirmationMode = 'always';
18
19
  this.requiredPermissions = ['read'];
19
20
  this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, (0, coinInfo_1.getMiscNetwork)('Tezos'), this.firmwareRange);
20
21
  this.hasBundle = !!this.payload.bundle;
@@ -35,7 +36,6 @@ class TezosGetAddress extends AbstractMethod_1.AbstractMethod {
35
36
  this.params.length === 1 &&
36
37
  typeof this.params[0].address === 'string' &&
37
38
  this.params[0].show_display;
38
- this.confirmed = useEventListener;
39
39
  this.useUi = !useEventListener;
40
40
  }
41
41
  get info() {
@@ -53,27 +53,11 @@ class TezosGetAddress extends AbstractMethod_1.AbstractMethod {
53
53
  };
54
54
  }
55
55
  }
56
- async confirmation() {
57
- if (this.confirmed)
58
- return true;
59
- await this.getPopupPromise().promise;
60
- const uiPromise = this.createUiPromise(events_1.UI.RECEIVE_CONFIRMATION);
61
- this.postMessage((0, events_1.createUiMessage)(events_1.UI.REQUEST_CONFIRMATION, {
56
+ get confirmation() {
57
+ return {
62
58
  view: 'export-address',
63
59
  label: this.info,
64
- }));
65
- const uiResp = await uiPromise.promise;
66
- this.confirmed = uiResp.payload;
67
- return this.confirmed;
68
- }
69
- async noBackupConfirmation() {
70
- await this.getPopupPromise().promise;
71
- const uiPromise = this.createUiPromise(events_1.UI.RECEIVE_CONFIRMATION);
72
- this.postMessage((0, events_1.createUiMessage)(events_1.UI.REQUEST_CONFIRMATION, {
73
- view: 'no-backup',
74
- }));
75
- const uiResp = await uiPromise.promise;
76
- return uiResp.payload;
60
+ };
77
61
  }
78
62
  async _call({ address_n, show_display, chunkify }) {
79
63
  const cmd = this.device.getCommands();
@@ -2,10 +2,12 @@ import { AbstractMethod } from '../../../core/AbstractMethod';
2
2
  import type { PROTO } from '../../../constants';
3
3
  export default class TezosGetPublicKey extends AbstractMethod<'tezosGetPublicKey', PROTO.TezosGetPublicKey[]> {
4
4
  hasBundle?: boolean;
5
- confirmed?: boolean;
6
5
  init(): void;
7
6
  get info(): string;
8
- confirmation(): Promise<boolean>;
7
+ get confirmation(): {
8
+ view: "export-address";
9
+ label: string;
10
+ };
9
11
  run(): Promise<{
10
12
  path: number[];
11
13
  publicKey: string;
@@ -28,25 +28,13 @@ class TezosGetPublicKey extends AbstractMethod_1.AbstractMethod {
28
28
  get info() {
29
29
  return 'Export Tezos public key';
30
30
  }
31
- async confirmation() {
32
- if (this.confirmed)
33
- return true;
34
- await this.getPopupPromise().promise;
35
- const uiPromise = this.createUiPromise(events_1.UI.RECEIVE_CONFIRMATION);
36
- let label;
37
- if (this.params.length > 1) {
38
- label = 'Export multiple Tezos public keys';
39
- }
40
- else {
41
- label = `Export Tezos public key for account #${(0, pathUtils_1.fromHardened)(this.params[0].address_n[2]) + 1}`;
42
- }
43
- this.postMessage((0, events_1.createUiMessage)(events_1.UI.REQUEST_CONFIRMATION, {
31
+ get confirmation() {
32
+ return {
44
33
  view: 'export-address',
45
- label,
46
- }));
47
- const uiResp = await uiPromise.promise;
48
- this.confirmed = uiResp.payload;
49
- return this.confirmed;
34
+ label: this.params.length > 1
35
+ ? 'Export multiple Tezos public keys'
36
+ : `Export Tezos public key for account #${(0, pathUtils_1.fromHardened)(this.params[0].address_n[2]) + 1}`,
37
+ };
50
38
  }
51
39
  async run() {
52
40
  const responses = [];
@@ -1,8 +1,14 @@
1
1
  import { AbstractMethod } from '../core/AbstractMethod';
2
2
  export default class WipeDevice extends AbstractMethod<'wipeDevice'> {
3
- confirmed?: boolean;
4
3
  init(): void;
5
- confirmation(): Promise<boolean>;
4
+ get confirmation(): {
5
+ view: "device-management";
6
+ customConfirmButton: {
7
+ className: string;
8
+ label: string;
9
+ };
10
+ label: string;
11
+ };
6
12
  get info(): string;
7
13
  run(): Promise<{
8
14
  message: string;
@@ -10,22 +10,15 @@ class WipeDevice extends AbstractMethod_1.AbstractMethod {
10
10
  this.requiredPermissions = ['management'];
11
11
  this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, null, this.firmwareRange);
12
12
  }
13
- async confirmation() {
14
- if (this.confirmed)
15
- return true;
16
- await this.getPopupPromise().promise;
17
- const uiPromise = this.createUiPromise(events_1.UI.RECEIVE_CONFIRMATION);
18
- this.postMessage((0, events_1.createUiMessage)(events_1.UI.REQUEST_CONFIRMATION, {
13
+ get confirmation() {
14
+ return {
19
15
  view: 'device-management',
20
16
  customConfirmButton: {
21
17
  className: 'wipe',
22
18
  label: `Wipe ${this.device.toMessageObject().label}`,
23
19
  },
24
20
  label: 'Are you sure you want to wipe your device?',
25
- }));
26
- const uiResp = await uiPromise.promise;
27
- this.confirmed = uiResp.payload;
28
- return this.confirmed;
21
+ };
29
22
  }
30
23
  get info() {
31
24
  return 'Wipe device';
@@ -1,15 +1,16 @@
1
1
  import { Blockchain, BlockchainOptions } from './Blockchain';
2
2
  import type { CoinInfo, BlockchainLink } from '../types';
3
3
  type CoinShortcut = CoinInfo['shortcut'];
4
+ type BackendParams = Pick<BlockchainOptions, 'coinInfo' | 'postMessage' | 'identity'>;
4
5
  export declare class BackendManager {
5
6
  private readonly instances;
7
+ private readonly reconnect;
6
8
  private readonly custom;
7
9
  private readonly preferred;
8
- private readonly reconnect;
9
- get(shortcut: CoinShortcut): Blockchain | null;
10
- getOrConnect(coinInfo: CoinInfo, postMessage: BlockchainOptions['postMessage']): Promise<Blockchain>;
10
+ get(shortcut: CoinShortcut, identity?: string): Blockchain | null;
11
+ getOrConnect({ coinInfo, postMessage, identity }: BackendParams): Promise<Blockchain>;
11
12
  dispose(): void;
12
- reconnectAll(): Promise<Blockchain[]>;
13
+ reconnectAll(coin?: CoinInfo): Promise<Blockchain[]>;
13
14
  isSupported(coinInfo: CoinInfo): void;
14
15
  setCustom(shortcut: CoinShortcut, blockchainLink: BlockchainLink): void;
15
16
  removeCustom(shortcut: CoinShortcut): void;
@@ -18,6 +19,7 @@ export declare class BackendManager {
18
19
  private onDisconnect;
19
20
  private clearReconnect;
20
21
  private patchCoinInfo;
22
+ private getReconnectFilter;
21
23
  }
22
24
  export {};
23
25
  //# sourceMappingURL=BackendManager.d.ts.map
@@ -5,52 +5,56 @@ const DataManager_1 = require("../data/DataManager");
5
5
  const constants_1 = require("../constants");
6
6
  const Blockchain_1 = require("./Blockchain");
7
7
  const events_1 = require("../events");
8
+ const DEFAULT_IDENTITY = 'default';
8
9
  class BackendManager {
9
10
  constructor() {
10
11
  this.instances = {};
12
+ this.reconnect = {};
11
13
  this.custom = {};
12
14
  this.preferred = {};
13
- this.reconnect = {};
14
15
  }
15
- get(shortcut) {
16
+ get(shortcut, identity = DEFAULT_IDENTITY) {
16
17
  var _a;
17
- return (_a = this.instances[shortcut]) !== null && _a !== void 0 ? _a : null;
18
+ return (_a = this.instances[`${shortcut}/${identity}`]) !== null && _a !== void 0 ? _a : null;
18
19
  }
19
- async getOrConnect(coinInfo, postMessage) {
20
- let backend = this.instances[coinInfo.shortcut];
20
+ async getOrConnect({ coinInfo, postMessage, identity }) {
21
+ const coinIdentity = `${coinInfo.shortcut}/${identity !== null && identity !== void 0 ? identity : DEFAULT_IDENTITY}`;
22
+ let backend = this.instances[coinIdentity];
21
23
  if (!backend) {
22
24
  backend = new Blockchain_1.Blockchain({
23
25
  coinInfo: this.patchCoinInfo(coinInfo),
24
- postMessage,
26
+ identity,
25
27
  debug: DataManager_1.DataManager.getSettings('debug'),
26
28
  proxy: DataManager_1.DataManager.getSettings('proxy'),
29
+ postMessage,
27
30
  onDisconnected: pendingSubscriptions => {
28
31
  const reconnectAttempts = pendingSubscriptions ? 0 : undefined;
29
- this.onDisconnect(coinInfo, postMessage, reconnectAttempts);
32
+ this.onDisconnect({ coinInfo, postMessage, identity }, reconnectAttempts);
30
33
  },
31
34
  });
32
- this.setInstance(coinInfo.shortcut, backend);
35
+ this.setInstance(coinIdentity, backend);
33
36
  }
34
- const reconnect = this.clearReconnect(coinInfo.shortcut);
37
+ const reconnect = this.clearReconnect(coinIdentity);
35
38
  try {
36
39
  const info = await backend.init();
37
40
  this.setPreferred(coinInfo.shortcut, info.url);
38
41
  return backend;
39
42
  }
40
43
  catch (error) {
41
- this.onDisconnect(coinInfo, postMessage, reconnect === null || reconnect === void 0 ? void 0 : reconnect.attempts);
44
+ this.onDisconnect({ coinInfo, postMessage, identity }, reconnect === null || reconnect === void 0 ? void 0 : reconnect.attempts);
42
45
  throw error;
43
46
  }
44
47
  }
45
48
  dispose() {
46
- Object.keys(this.reconnect).forEach(this.clearReconnect, this);
49
+ Object.keys(this.reconnect)
50
+ .filter(this.getReconnectFilter())
51
+ .forEach(this.clearReconnect, this);
47
52
  Object.values(this.instances).forEach(i => i.disconnect());
48
53
  }
49
- reconnectAll() {
50
- Object.keys(this.reconnect).forEach(this.clearReconnect, this);
51
- const params = Object.values(this.instances).map(i => [i.coinInfo, i.postMessage]);
52
- Object.values(this.instances).forEach(i => i.disconnect());
53
- return Promise.all(params.map(p => this.getOrConnect(...p)));
54
+ reconnectAll(coin) {
55
+ const backends = Object.values(this.instances).filter(backend => !coin || coin.shortcut === backend.coinInfo.shortcut);
56
+ backends.forEach(i => i.disconnect());
57
+ return Promise.all(backends.map(this.getOrConnect, this));
54
58
  }
55
59
  isSupported(coinInfo) {
56
60
  const info = this.custom[coinInfo.shortcut] || coinInfo.blockchainLink;
@@ -66,11 +70,11 @@ class BackendManager {
66
70
  this.setPreferred(shortcut, undefined);
67
71
  delete this.custom[shortcut];
68
72
  }
69
- setInstance(shortcut, instance) {
73
+ setInstance(coinIdentity, instance) {
70
74
  if (!instance)
71
- delete this.instances[shortcut];
75
+ delete this.instances[coinIdentity];
72
76
  else
73
- this.instances[shortcut] = instance;
77
+ this.instances[coinIdentity] = instance;
74
78
  }
75
79
  setPreferred(shortcut, url) {
76
80
  if (!url)
@@ -78,9 +82,10 @@ class BackendManager {
78
82
  else
79
83
  this.preferred[shortcut] = url;
80
84
  }
81
- onDisconnect(coinInfo, postMessage, reconnectAttempt) {
85
+ onDisconnect({ coinInfo, postMessage, identity }, reconnectAttempt) {
82
86
  var _a;
83
- this.setInstance(coinInfo.shortcut, undefined);
87
+ const coinIdentity = `${coinInfo.shortcut}/${identity !== null && identity !== void 0 ? identity : DEFAULT_IDENTITY}`;
88
+ this.setInstance(coinIdentity, undefined);
84
89
  if (reconnectAttempt === undefined || reconnectAttempt === 4) {
85
90
  this.setPreferred(coinInfo.shortcut, undefined);
86
91
  }
@@ -90,16 +95,16 @@ class BackendManager {
90
95
  const timeout = Math.min(2500 * reconnectAttempt, 20000);
91
96
  const time = Date.now() + timeout;
92
97
  const handle = setTimeout(() => {
93
- this.getOrConnect(coinInfo, postMessage).catch(() => { });
98
+ this.getOrConnect({ coinInfo, postMessage, identity }).catch(() => { });
94
99
  }, timeout);
95
- clearTimeout((_a = this.reconnect[coinInfo.shortcut]) === null || _a === void 0 ? void 0 : _a.handle);
96
- this.reconnect[coinInfo.shortcut] = { attempts: reconnectAttempt + 1, handle };
97
- postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.RECONNECTING, { coin: coinInfo, time }));
100
+ clearTimeout((_a = this.reconnect[coinIdentity]) === null || _a === void 0 ? void 0 : _a.handle);
101
+ this.reconnect[coinIdentity] = { attempts: reconnectAttempt + 1, handle };
102
+ postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.RECONNECTING, { coin: coinInfo, identity, time }));
98
103
  }
99
- clearReconnect(shortcut) {
100
- const reconnect = this.reconnect[shortcut];
104
+ clearReconnect(coinIdentity) {
105
+ const reconnect = this.reconnect[coinIdentity];
101
106
  clearTimeout(reconnect === null || reconnect === void 0 ? void 0 : reconnect.handle);
102
- delete this.reconnect[shortcut];
107
+ delete this.reconnect[coinIdentity];
103
108
  return reconnect;
104
109
  }
105
110
  patchCoinInfo(coinInfo) {
@@ -116,6 +121,9 @@ class BackendManager {
116
121
  },
117
122
  };
118
123
  }
124
+ getReconnectFilter(coinInfo) {
125
+ return (key) => !coinInfo || key.startsWith(`${coinInfo.shortcut}/`);
126
+ }
119
127
  }
120
128
  exports.BackendManager = BackendManager;
121
129
  //# sourceMappingURL=BackendManager.js.map
@@ -7,13 +7,15 @@ export type BlockchainOptions = {
7
7
  postMessage: (message: CoreEventMessage) => void;
8
8
  proxy?: Proxy;
9
9
  debug?: boolean;
10
+ identity?: string;
10
11
  onDisconnected?: (pendingSubscriptions?: boolean) => void;
11
12
  };
12
13
  export declare class Blockchain {
13
14
  link: BlockchainLink;
14
15
  serverInfo?: ServerInfo;
15
- coinInfo: BlockchainOptions['coinInfo'];
16
- postMessage: BlockchainOptions['postMessage'];
16
+ readonly identity?: string;
17
+ readonly coinInfo: BlockchainOptions['coinInfo'];
18
+ readonly postMessage: BlockchainOptions['postMessage'];
17
19
  feeForBlock: BlockchainLinkResponse<'estimateFee'>;
18
20
  feeTimestamp: number;
19
21
  private onDisconnected;
@@ -50,18 +52,27 @@ export declare class Blockchain {
50
52
  feePerTx?: string | undefined;
51
53
  feeLimit?: string | undefined;
52
54
  }[]>;
53
- subscribe(accounts?: SubscriptionAccountInfo[]): Promise<{
55
+ subscribeBlocks(): Promise<{
56
+ subscribed: boolean;
57
+ }>;
58
+ subscribeAccounts(accounts: SubscriptionAccountInfo[]): Promise<{
54
59
  subscribed: boolean;
55
60
  }>;
56
61
  subscribeFiatRates(_currency?: string): Promise<{
57
62
  subscribed: boolean;
58
63
  }>;
59
- unsubscribe(accounts?: SubscriptionAccountInfo[]): Promise<{
64
+ unsubscribeBlocks(): Promise<{
65
+ subscribed: boolean;
66
+ }>;
67
+ unsubscribeAccounts(accounts: SubscriptionAccountInfo[]): Promise<{
60
68
  subscribed: boolean;
61
69
  }>;
62
70
  unsubscribeFiatRates(): Promise<{
63
71
  subscribed: boolean;
64
72
  }>;
73
+ unsubscribeAll(): Promise<{
74
+ subscribed: boolean;
75
+ }>;
65
76
  pushTransaction(tx: string): Promise<string>;
66
77
  disconnect(): void;
67
78
  }
@@ -26,6 +26,7 @@ class Blockchain {
26
26
  constructor(options) {
27
27
  this.feeForBlock = [];
28
28
  this.feeTimestamp = 0;
29
+ this.identity = options.identity;
29
30
  this.coinInfo = options.coinInfo;
30
31
  this.postMessage = options.postMessage;
31
32
  this.onDisconnected = options.onDisconnected;
@@ -55,6 +56,7 @@ class Blockchain {
55
56
  this.link.dispose();
56
57
  this.postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.ERROR, {
57
58
  coin: this.coinInfo,
59
+ identity: this.identity,
58
60
  error: error.message,
59
61
  code: error.code,
60
62
  }));
@@ -74,10 +76,6 @@ class Blockchain {
74
76
  if (info.shortcut.toLowerCase() !== shortcut.toLowerCase()) {
75
77
  throw constants_1.ERRORS.TypedError('Backend_Invalid');
76
78
  }
77
- this.postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.CONNECT, {
78
- coin: this.coinInfo,
79
- ...info,
80
- }));
81
79
  this.link.on('disconnected', () => {
82
80
  this.onError(constants_1.ERRORS.TypedError('Backend_Disconnected'));
83
81
  });
@@ -87,10 +85,21 @@ class Blockchain {
87
85
  if (!this.initPromise) {
88
86
  this.initPromise = this.initLink()
89
87
  .then(info => {
88
+ this.postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.CONNECT, {
89
+ coin: this.coinInfo,
90
+ identity: this.identity,
91
+ ...info,
92
+ }));
90
93
  this.initPromise = Promise.resolve(info);
91
94
  return info;
92
95
  })
93
96
  .catch(error => {
97
+ this.postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.ERROR, {
98
+ coin: this.coinInfo,
99
+ identity: this.identity,
100
+ error: error.message,
101
+ code: error.code,
102
+ }));
94
103
  this.initPromise = Promise.reject(error);
95
104
  this.link.dispose();
96
105
  return this.initPromise;
@@ -143,7 +152,7 @@ class Blockchain {
143
152
  }
144
153
  return this.link.estimateFee(request);
145
154
  }
146
- async subscribe(accounts) {
155
+ subscribeBlocks() {
147
156
  if (this.link.listenerCount('block') === 0) {
148
157
  this.link.on('block', block => {
149
158
  this.postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.BLOCK, {
@@ -152,6 +161,9 @@ class Blockchain {
152
161
  }));
153
162
  });
154
163
  }
164
+ return this.link.subscribe({ type: 'block' });
165
+ }
166
+ subscribeAccounts(accounts) {
155
167
  if (this.link.listenerCount('notification') === 0) {
156
168
  this.link.on('notification', notification => {
157
169
  this.postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.NOTIFICATION, {
@@ -160,10 +172,6 @@ class Blockchain {
160
172
  }));
161
173
  });
162
174
  }
163
- const blockSubscription = await this.link.subscribe({ type: 'block' });
164
- if (!accounts) {
165
- return blockSubscription;
166
- }
167
175
  return this.link.subscribe({
168
176
  type: 'accounts',
169
177
  accounts,
@@ -182,20 +190,22 @@ class Blockchain {
182
190
  type: 'fiatRates',
183
191
  });
184
192
  }
185
- async unsubscribe(accounts) {
186
- if (!accounts) {
187
- this.link.removeAllListeners('block');
188
- this.link.removeAllListeners('fiatRates');
189
- this.link.removeAllListeners('notification');
190
- await this.link.unsubscribe({ type: 'fiatRates' });
191
- return this.link.unsubscribe({ type: 'block' });
192
- }
193
+ unsubscribeBlocks() {
194
+ this.link.removeAllListeners('block');
195
+ return this.link.unsubscribe({ type: 'block' });
196
+ }
197
+ unsubscribeAccounts(accounts) {
193
198
  return this.link.unsubscribe({ type: 'accounts', accounts });
194
199
  }
195
200
  unsubscribeFiatRates() {
196
201
  this.link.removeAllListeners('fiatRates');
197
202
  return this.link.unsubscribe({ type: 'fiatRates' });
198
203
  }
204
+ async unsubscribeAll() {
205
+ this.link.removeAllListeners('notification');
206
+ await this.unsubscribeFiatRates();
207
+ return this.unsubscribeBlocks();
208
+ }
199
209
  pushTransaction(tx) {
200
210
  return this.link.pushTransaction(tx);
201
211
  }
@@ -1,10 +1,10 @@
1
1
  import type { BlockchainOptions as Options } from './Blockchain';
2
2
  import type { CoinInfo } from '../types';
3
3
  export { Blockchain } from './Blockchain';
4
- export declare const findBackend: (coin: string) => import("./Blockchain").Blockchain | null;
4
+ export declare const findBackend: (coin: string, identity?: string) => import("./Blockchain").Blockchain | null;
5
5
  export declare const setCustomBackend: (coinInfo: CoinInfo, blockchainLink: CoinInfo['blockchainLink']) => void;
6
6
  export declare const isBackendSupported: (coinInfo: CoinInfo) => void;
7
- export declare const initBlockchain: (coinInfo: CoinInfo, postMessage: Options['postMessage']) => Promise<import("./Blockchain").Blockchain>;
8
- export declare const reconnectAllBackends: () => Promise<import("./Blockchain").Blockchain[]>;
7
+ export declare const initBlockchain: (coinInfo: CoinInfo, postMessage: Options['postMessage'], identity?: string) => Promise<import("./Blockchain").Blockchain>;
8
+ export declare const reconnectAllBackends: (coinInfo?: CoinInfo) => Promise<import("./Blockchain").Blockchain[]>;
9
9
  export declare const dispose: () => void;
10
10
  //# sourceMappingURL=BlockchainLink.d.ts.map
@@ -5,7 +5,7 @@ const BackendManager_1 = require("./BackendManager");
5
5
  var Blockchain_1 = require("./Blockchain");
6
6
  Object.defineProperty(exports, "Blockchain", { enumerable: true, get: function () { return Blockchain_1.Blockchain; } });
7
7
  const backends = new BackendManager_1.BackendManager();
8
- const findBackend = (coin) => backends.get(coin);
8
+ const findBackend = (coin, identity) => backends.get(coin, identity);
9
9
  exports.findBackend = findBackend;
10
10
  const setCustomBackend = (coinInfo, blockchainLink) => (blockchainLink === null || blockchainLink === void 0 ? void 0 : blockchainLink.url.length)
11
11
  ? backends.setCustom(coinInfo.shortcut, blockchainLink)
@@ -13,9 +13,9 @@ const setCustomBackend = (coinInfo, blockchainLink) => (blockchainLink === null
13
13
  exports.setCustomBackend = setCustomBackend;
14
14
  const isBackendSupported = (coinInfo) => backends.isSupported(coinInfo);
15
15
  exports.isBackendSupported = isBackendSupported;
16
- const initBlockchain = (coinInfo, postMessage) => backends.getOrConnect(coinInfo, postMessage);
16
+ const initBlockchain = (coinInfo, postMessage, identity) => backends.getOrConnect({ coinInfo, identity, postMessage });
17
17
  exports.initBlockchain = initBlockchain;
18
- const reconnectAllBackends = () => backends.reconnectAll();
18
+ const reconnectAllBackends = (coinInfo) => backends.reconnectAll(coinInfo);
19
19
  exports.reconnectAllBackends = reconnectAllBackends;
20
20
  const dispose = () => backends.dispose();
21
21
  exports.dispose = dispose;
@@ -33,6 +33,7 @@ export declare const ERROR_CODES: {
33
33
  Device_UsedElsewhere: string;
34
34
  Device_InvalidState: string;
35
35
  Device_CallInProgress: string;
36
+ Device_MultipleNotSupported: string;
36
37
  };
37
38
  export declare class TrezorError extends Error {
38
39
  code: string;
@@ -36,6 +36,7 @@ exports.ERROR_CODES = {
36
36
  Device_UsedElsewhere: 'Device is used in another window',
37
37
  Device_InvalidState: 'Passphrase is incorrect',
38
38
  Device_CallInProgress: 'Device call in progress',
39
+ Device_MultipleNotSupported: 'Multiple devices are not supported',
39
40
  };
40
41
  class TrezorError extends Error {
41
42
  constructor(code, message) {
@@ -1,6 +1,5 @@
1
- import { Deferred } from '@trezor/utils';
2
1
  import { NETWORK } from '../constants';
3
- import { CallMethodPayload, CallMethodResponse, UiRequestButtonData, UiPromiseCreator, CoreEventMessage } from '../events';
2
+ import { CallMethodPayload, CallMethodResponse, UiRequestButtonData, UiPromiseCreator, CoreEventMessage, UiRequestConfirmation } from '../events';
4
3
  import type { Device } from '../device/Device';
5
4
  import type { FirmwareRange } from '../types';
6
5
  export type Payload<M> = Extract<CallMethodPayload, {
@@ -25,6 +24,7 @@ export declare abstract class AbstractMethod<Name extends CallMethodPayload['met
25
24
  name: Name;
26
25
  payload: Payload<Name>;
27
26
  get info(): string;
27
+ get confirmation(): UiRequestConfirmation['payload'] | undefined;
28
28
  useUi: boolean;
29
29
  useDevice: boolean;
30
30
  useDeviceState: boolean;
@@ -37,24 +37,20 @@ export declare abstract class AbstractMethod<Name extends CallMethodPayload['met
37
37
  requireDeviceMode: string[];
38
38
  network: NETWORK.NetworkType;
39
39
  useCardanoDerivation: boolean;
40
- confirmation?(): Promise<boolean | undefined>;
41
- noBackupConfirmation?(allowSuppression?: boolean): Promise<boolean>;
40
+ noBackupConfirmationMode: 'never' | 'always' | 'popup-only';
42
41
  getButtonRequestData?(code: string): UiRequestButtonData | undefined;
43
42
  postMessage: (message: CoreEventMessage) => void;
44
- getPopupPromise: () => Deferred<void>;
45
43
  createUiPromise: UiPromiseCreator;
46
- removeUiPromise: (promise: Deferred<any>) => void;
47
44
  initAsync?(): Promise<void>;
48
45
  constructor(message: {
49
46
  id?: number;
50
47
  payload: Payload<Name>;
51
48
  });
52
49
  setDevice(device: Device): void;
53
- requestPermissions(): Promise<boolean>;
54
50
  private getOriginPermissions;
55
51
  checkPermissions(): void;
56
52
  savePermissions(temporary?: boolean): void;
57
- checkFirmwareRange(isUsingPopup?: boolean): Promise<"ui-device_firmware_old" | "ui-device_firmware_unsupported" | "ui-device_firmware_not_compatible" | "ui-device_firmware_not_installed" | undefined>;
53
+ checkFirmwareRange(): "ui-device_firmware_old" | "ui-device_firmware_unsupported" | "ui-device_firmware_not_compatible" | "ui-device_firmware_not_installed" | undefined;
58
54
  isManagementRestricted(): boolean | undefined;
59
55
  abstract init(): void;
60
56
  abstract run(): Promise<MethodReturnType<Name>>;
@@ -11,11 +11,15 @@ exports.DEFAULT_FIRMWARE_RANGE = {
11
11
  T1B1: { min: '1.0.0', max: '0' },
12
12
  T2T1: { min: '2.0.0', max: '0' },
13
13
  T2B1: { min: '2.6.1', max: '0' },
14
+ T3T1: { min: '2.7.1', max: '0' },
14
15
  };
15
16
  class AbstractMethod {
16
17
  get info() {
17
18
  return '';
18
19
  }
20
+ get confirmation() {
21
+ return undefined;
22
+ }
19
23
  constructor(message) {
20
24
  var _a, _b;
21
25
  const { payload } = message;
@@ -58,6 +62,7 @@ class AbstractMethod {
58
62
  typeof payload.useCardanoDerivation === 'boolean'
59
63
  ? payload.useCardanoDerivation
60
64
  : payload.method.startsWith('cardano');
65
+ this.noBackupConfirmationMode = 'never';
61
66
  }
62
67
  setDevice(device) {
63
68
  this.device = device;
@@ -65,21 +70,6 @@ class AbstractMethod {
65
70
  const originalFn = this.createUiPromise;
66
71
  this.createUiPromise = (t, d) => originalFn(t, d || device);
67
72
  }
68
- async requestPermissions() {
69
- await this.getPopupPromise().promise;
70
- const uiPromise = this.createUiPromise(events_1.UI.RECEIVE_PERMISSION);
71
- this.postMessage((0, events_1.createUiMessage)(events_1.UI.REQUEST_PERMISSION, {
72
- permissions: this.requiredPermissions,
73
- device: this.device.toMessageObject(),
74
- }));
75
- const uiResp = await uiPromise.promise;
76
- const { granted, remember } = uiResp.payload;
77
- if (granted) {
78
- this.savePermissions(!remember);
79
- return true;
80
- }
81
- return false;
82
- }
83
73
  getOriginPermissions() {
84
74
  var _a;
85
75
  const origin = DataManager_1.DataManager.getSettings('origin');
@@ -127,7 +117,7 @@ class AbstractMethod {
127
117
  this.postMessage((0, events_1.createDeviceMessage)(events_1.DEVICE.CONNECT, this.device.toMessageObject()));
128
118
  }
129
119
  }
130
- async checkFirmwareRange(isUsingPopup) {
120
+ checkFirmwareRange() {
131
121
  if (this.skipFirmwareCheck) {
132
122
  return;
133
123
  }
@@ -150,18 +140,7 @@ class AbstractMethod {
150
140
  return events_1.UI.FIRMWARE_OLD;
151
141
  }
152
142
  if (range.max !== '0' && utils_1.versionUtils.isNewer(version, range.max)) {
153
- if (isUsingPopup) {
154
- await this.getPopupPromise().promise;
155
- const uiPromise = this.createUiPromise(events_1.UI.RECEIVE_CONFIRMATION);
156
- this.postMessage((0, events_1.createUiMessage)(events_1.UI.FIRMWARE_NOT_COMPATIBLE, device.toMessageObject()));
157
- const uiResp = await uiPromise.promise;
158
- if (!uiResp.payload) {
159
- throw constants_1.ERRORS.TypedError('Method_PermissionsNotGranted');
160
- }
161
- }
162
- else {
163
- return events_1.UI.FIRMWARE_NOT_COMPATIBLE;
164
- }
143
+ return events_1.UI.FIRMWARE_NOT_COMPATIBLE;
165
144
  }
166
145
  }
167
146
  isManagementRestricted() {
@@ -5,8 +5,9 @@ import { AbstractMethod } from './AbstractMethod';
5
5
  import { LogWriter } from '../utils/debug';
6
6
  import type { ConnectSettings } from '../types';
7
7
  export declare class Core extends EventEmitter {
8
+ abortController: AbortController;
8
9
  handleMessage(message: CoreRequestMessage): void;
9
- dispose(): Promise<void>;
10
+ dispose(): void;
10
11
  getCurrentMethod(): Promise<AbstractMethod<any, undefined>>;
11
12
  getTransportInfo(): TransportInfo | undefined;
12
13
  enumerate(): void;