@trezor/connect 9.2.2 → 9.2.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.
Files changed (88) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +1 -1
  3. package/lib/api/blockchainDisconnect.d.ts +1 -0
  4. package/lib/api/blockchainDisconnect.js +3 -4
  5. package/lib/api/blockchainEstimateFee.d.ts +1 -0
  6. package/lib/api/blockchainEstimateFee.js +6 -4
  7. package/lib/api/blockchainGetAccountBalanceHistory.d.ts +1 -0
  8. package/lib/api/blockchainGetAccountBalanceHistory.js +3 -1
  9. package/lib/api/blockchainGetCurrentFiatRates.d.ts +1 -0
  10. package/lib/api/blockchainGetCurrentFiatRates.js +3 -1
  11. package/lib/api/blockchainGetFiatRatesForTimestamps.d.ts +1 -0
  12. package/lib/api/blockchainGetFiatRatesForTimestamps.js +3 -1
  13. package/lib/api/blockchainGetTransactions.d.ts +1 -0
  14. package/lib/api/blockchainGetTransactions.js +3 -1
  15. package/lib/api/blockchainSetCustomBackend.js +1 -5
  16. package/lib/api/blockchainSubscribe.d.ts +2 -0
  17. package/lib/api/blockchainSubscribe.js +13 -2
  18. package/lib/api/blockchainSubscribeFiatRates.d.ts +1 -0
  19. package/lib/api/blockchainSubscribeFiatRates.js +3 -1
  20. package/lib/api/blockchainUnsubscribe.d.ts +1 -0
  21. package/lib/api/blockchainUnsubscribe.js +5 -2
  22. package/lib/api/blockchainUnsubscribeFiatRates.d.ts +1 -0
  23. package/lib/api/blockchainUnsubscribeFiatRates.js +6 -2
  24. package/lib/api/changeLanguage.d.ts +0 -1
  25. package/lib/api/changeLanguage.js +7 -44
  26. package/lib/api/composeTransaction.d.ts +2 -0
  27. package/lib/api/composeTransaction.js +10 -5
  28. package/lib/api/eos/eosSignTx.d.ts +3 -3
  29. package/lib/api/ethereum/api/ethereumSignTypedData.d.ts +2 -1
  30. package/lib/api/ethereum/ethereumDefinitions.js +1 -0
  31. package/lib/api/getAccountInfo.js +4 -3
  32. package/lib/api/getCoinInfo.d.ts +3 -0
  33. package/lib/api/pushTransaction.d.ts +1 -0
  34. package/lib/api/pushTransaction.js +2 -1
  35. package/lib/api/resetDevice.d.ts +1 -1
  36. package/lib/api/resetDevice.js +2 -2
  37. package/lib/api/signTransaction.d.ts +1 -0
  38. package/lib/api/signTransaction.js +5 -3
  39. package/lib/backend/BackendManager.d.ts +6 -4
  40. package/lib/backend/BackendManager.js +36 -28
  41. package/lib/backend/Blockchain.d.ts +15 -4
  42. package/lib/backend/Blockchain.js +27 -17
  43. package/lib/backend/BlockchainLink.d.ts +3 -3
  44. package/lib/backend/BlockchainLink.js +3 -3
  45. package/lib/core/AbstractMethod.js +1 -0
  46. package/lib/core/index.js +6 -6
  47. package/lib/data/DataManager.d.ts +22 -0
  48. package/lib/data/DataManager.js +7 -3
  49. package/lib/data/coinInfo.d.ts +14 -0
  50. package/lib/data/config.d.ts +22 -0
  51. package/lib/data/config.js +5 -1
  52. package/lib/data/connectSettings.js +3 -0
  53. package/lib/data/deviceAuthenticityConfig.d.ts +9 -0
  54. package/lib/data/deviceAuthenticityConfig.js +23 -3
  55. package/lib/data/firmwareInfo.js +1 -5
  56. package/lib/data/getLanguage.d.ts +6 -0
  57. package/lib/data/getLanguage.js +10 -0
  58. package/lib/data/models.d.ts +9 -0
  59. package/lib/data/models.js +9 -0
  60. package/lib/data/version.d.ts +1 -1
  61. package/lib/data/version.js +1 -1
  62. package/lib/device/Device.d.ts +12 -1
  63. package/lib/device/Device.js +53 -5
  64. package/lib/device/DeviceCommands.d.ts +1 -1
  65. package/lib/device/DeviceList.js +4 -6
  66. package/lib/events/blockchain.d.ts +3 -0
  67. package/lib/types/api/authenticateDevice.d.ts +9 -0
  68. package/lib/types/api/bitcoin/index.d.ts +1 -0
  69. package/lib/types/api/blockchainSetCustomBackend.d.ts +3 -2
  70. package/lib/types/api/blockchainSubscribe.d.ts +1 -0
  71. package/lib/types/api/composeTransaction.d.ts +2 -0
  72. package/lib/types/api/getAccountInfo.d.ts +1 -0
  73. package/lib/types/api/getCoinInfo.d.ts +4 -2
  74. package/lib/types/api/nemGetAddress.d.ts +11 -4
  75. package/lib/types/api/nemGetAddress.js +9 -0
  76. package/lib/types/api/pushTransaction.d.ts +1 -0
  77. package/lib/types/api/pushTransaction.js +1 -0
  78. package/lib/types/api/resetDevice.d.ts +1 -15
  79. package/lib/types/api/resetDevice.js +0 -9
  80. package/lib/types/api/setBusy.d.ts +2 -2
  81. package/lib/types/coinInfo.d.ts +15 -7
  82. package/lib/types/coinInfo.js +8 -6
  83. package/lib/types/firmware.d.ts +5 -15
  84. package/lib/types/params.d.ts +1 -0
  85. package/lib/types/params.js +1 -2
  86. package/lib/types/settings.d.ts +1 -0
  87. package/lib/utils/assetUtils.js +18 -8
  88. package/package.json +9 -9
@@ -57,10 +57,11 @@ declare const Params: import("@sinclair/typebox").TIntersect<[import("@sinclair/
57
57
  shortcut: import("@sinclair/typebox").TString;
58
58
  slip44: import("@sinclair/typebox").TNumber;
59
59
  support: import("@sinclair/typebox").TObject<{
60
- connect: import("@sinclair/typebox").TBoolean;
61
60
  T1B1: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TLiteral<false>]>;
62
61
  T2T1: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TLiteral<false>]>;
63
62
  T2B1: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TLiteral<false>]>;
63
+ T3T1: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TLiteral<false>]>;
64
+ connect: import("@sinclair/typebox").TBoolean;
64
65
  }>;
65
66
  decimals: import("@sinclair/typebox").TNumber;
66
67
  blockchainLink: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
@@ -102,6 +102,7 @@ const ethereumNetworkInfoFromDefinition = (definition) => ({
102
102
  T1B1: '1.6.2',
103
103
  T2T1: '2.0.7',
104
104
  T2B1: '2.6.1',
105
+ T3T1: '2.7.1',
105
106
  },
106
107
  blockchainLink: undefined,
107
108
  });
@@ -28,6 +28,7 @@ class GetAccountInfo extends AbstractMethod_1.AbstractMethod {
28
28
  this.params = payload.bundle.map(batch => {
29
29
  (0, paramsValidator_1.validateParams)(batch, [
30
30
  { name: 'coin', type: 'string', required: true },
31
+ { name: 'identity', type: 'string' },
31
32
  { name: 'descriptor', type: 'string' },
32
33
  { name: 'path', type: 'string' },
33
34
  { name: 'details', type: 'string' },
@@ -204,7 +205,7 @@ class GetAccountInfo extends AbstractMethod_1.AbstractMethod {
204
205
  if (typeof descriptor !== 'string') {
205
206
  throw constants_1.ERRORS.TypedError('Runtime', 'GetAccountInfo: descriptor not found');
206
207
  }
207
- const blockchain = await (0, BlockchainLink_1.initBlockchain)(request.coinInfo, this.postMessage);
208
+ const blockchain = await (0, BlockchainLink_1.initBlockchain)(request.coinInfo, this.postMessage, request.identity);
208
209
  if (this.disposed)
209
210
  break;
210
211
  const info = await blockchain.getAccountInfo({
@@ -256,8 +257,8 @@ class GetAccountInfo extends AbstractMethod_1.AbstractMethod {
256
257
  return this.hasBundle ? responses : responses[0];
257
258
  }
258
259
  async discover(request) {
259
- const { coinInfo, defaultAccountType } = request;
260
- const blockchain = await (0, BlockchainLink_1.initBlockchain)(coinInfo, this.postMessage);
260
+ const { coinInfo, identity, defaultAccountType } = request;
261
+ const blockchain = await (0, BlockchainLink_1.initBlockchain)(coinInfo, this.postMessage, identity);
261
262
  const dfd = this.createUiPromise(events_1.UI.RECEIVE_ACCOUNT);
262
263
  const discovery = new Discovery_1.Discovery({
263
264
  blockchain,
@@ -21,6 +21,7 @@ export default class GetCoinInfo extends AbstractMethod<'getCoinInfo', Params> {
21
21
  T1B1: string | false;
22
22
  T2T1: string | false;
23
23
  T2B1: string | false;
24
+ T3T1: string | false;
24
25
  connect: boolean;
25
26
  };
26
27
  decimals: number;
@@ -76,6 +77,7 @@ export default class GetCoinInfo extends AbstractMethod<'getCoinInfo', Params> {
76
77
  T1B1: string | false;
77
78
  T2T1: string | false;
78
79
  T2B1: string | false;
80
+ T3T1: string | false;
79
81
  connect: boolean;
80
82
  };
81
83
  decimals: number;
@@ -106,6 +108,7 @@ export default class GetCoinInfo extends AbstractMethod<'getCoinInfo', Params> {
106
108
  T1B1: string | false;
107
109
  T2T1: string | false;
108
110
  T2B1: string | false;
111
+ T3T1: string | false;
109
112
  connect: boolean;
110
113
  };
111
114
  decimals: number;
@@ -3,6 +3,7 @@ import type { CoinInfo } from '../types';
3
3
  type Params = {
4
4
  tx: string;
5
5
  coinInfo: CoinInfo;
6
+ identity?: string;
6
7
  };
7
8
  export default class PushTransaction extends AbstractMethod<'pushTransaction', Params> {
8
9
  init(): void;
@@ -24,10 +24,11 @@ class PushTransaction extends AbstractMethod_1.AbstractMethod {
24
24
  this.params = {
25
25
  tx: payload.tx,
26
26
  coinInfo,
27
+ identity: payload.identity,
27
28
  };
28
29
  }
29
30
  async run() {
30
- const backend = await (0, BlockchainLink_1.initBlockchain)(this.params.coinInfo, this.postMessage);
31
+ const backend = await (0, BlockchainLink_1.initBlockchain)(this.params.coinInfo, this.postMessage, this.params.identity);
31
32
  const txid = await backend.pushTransaction(this.params.tx);
32
33
  return {
33
34
  txid,
@@ -1,5 +1,5 @@
1
1
  import { AbstractMethod } from '../core/AbstractMethod';
2
- import type { PROTO } from '../constants';
2
+ import { PROTO } from '../constants';
3
3
  export default class ResetDevice extends AbstractMethod<'resetDevice', PROTO.ResetDevice> {
4
4
  confirmed?: boolean;
5
5
  init(): void;
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const AbstractMethod_1 = require("../core/AbstractMethod");
4
4
  const events_1 = require("../events");
5
5
  const paramsValidator_1 = require("./common/paramsValidator");
6
+ const constants_1 = require("../constants");
6
7
  const schema_utils_1 = require("@trezor/schema-utils");
7
- const resetDevice_1 = require("../types/api/resetDevice");
8
8
  class ResetDevice extends AbstractMethod_1.AbstractMethod {
9
9
  init() {
10
10
  this.allowDeviceMode = [events_1.UI.INITIALIZE, events_1.UI.SEEDLESS];
@@ -12,7 +12,7 @@ class ResetDevice extends AbstractMethod_1.AbstractMethod {
12
12
  this.requiredPermissions = ['management'];
13
13
  this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, null, this.firmwareRange);
14
14
  const { payload } = this;
15
- (0, schema_utils_1.Assert)(resetDevice_1.ResetDevice, payload);
15
+ (0, schema_utils_1.Assert)(constants_1.PROTO.ResetDevice, payload);
16
16
  this.params = {
17
17
  display_random: payload.display_random,
18
18
  strength: payload.strength || 256,
@@ -11,6 +11,7 @@ type Params = {
11
11
  addresses?: AccountAddresses;
12
12
  options: TransactionOptions;
13
13
  coinInfo: BitcoinNetworkInfo;
14
+ identity?: string;
14
15
  push: boolean;
15
16
  unlockPath?: PROTO.UnlockPath;
16
17
  };
@@ -16,6 +16,7 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
16
16
  const { payload } = this;
17
17
  (0, paramsValidator_1.validateParams)(payload, [
18
18
  { name: 'coin', type: 'string', required: true },
19
+ { name: 'identity', type: 'string' },
19
20
  { name: 'inputs', type: 'array', required: true },
20
21
  { name: 'outputs', type: 'array', required: true },
21
22
  { name: 'paymentRequests', type: 'array', allowEmpty: true },
@@ -90,6 +91,7 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
90
91
  chunkify: typeof payload.chunkify === 'boolean' ? payload.chunkify : false,
91
92
  },
92
93
  coinInfo,
94
+ identity: payload.identity,
93
95
  push: typeof payload.push === 'boolean' ? payload.push : false,
94
96
  unlockPath: payload.unlockPath,
95
97
  };
@@ -114,7 +116,7 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
114
116
  return account.addresses;
115
117
  }
116
118
  async fetchRefTxs(useLegacySignProcess) {
117
- const { params: { inputs, outputs, options, coinInfo, addresses }, } = this;
119
+ const { params: { inputs, outputs, options, coinInfo, identity, addresses }, } = this;
118
120
  const requiredRefTxs = (0, bitcoin_1.requireReferencedTransactions)(inputs, options, coinInfo);
119
121
  const refTxsIds = requiredRefTxs ? (0, bitcoin_1.getReferencedTransactions)(inputs) : [];
120
122
  const origTxsIds = !useLegacySignProcess ? (0, bitcoin_1.getOrigTransactions)(inputs, outputs) : [];
@@ -122,7 +124,7 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
122
124
  return [];
123
125
  }
124
126
  (0, BlockchainLink_1.isBackendSupported)(coinInfo);
125
- const blockchain = await (0, BlockchainLink_1.initBlockchain)(coinInfo, this.postMessage);
127
+ const blockchain = await (0, BlockchainLink_1.initBlockchain)(coinInfo, this.postMessage, identity);
126
128
  const refTxs = !refTxsIds.length
127
129
  ? []
128
130
  : await blockchain
@@ -184,7 +186,7 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
184
186
  }
185
187
  if (params.push) {
186
188
  (0, BlockchainLink_1.isBackendSupported)(params.coinInfo);
187
- const blockchain = await (0, BlockchainLink_1.initBlockchain)(params.coinInfo, this.postMessage);
189
+ const blockchain = await (0, BlockchainLink_1.initBlockchain)(params.coinInfo, this.postMessage, params.identity);
188
190
  const txid = await blockchain.pushTransaction(response.serializedTx);
189
191
  return {
190
192
  ...response,
@@ -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;
@@ -11,6 +11,7 @@ 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() {
package/lib/core/index.js CHANGED
@@ -149,7 +149,8 @@ const initDevice = async (method) => {
149
149
  if (devices.length === 1 &&
150
150
  devices[0].type !== 'unreadable' &&
151
151
  devices[0].features &&
152
- !isWebUsb) {
152
+ !isWebUsb &&
153
+ !useCoreInPopup) {
153
154
  device = _deviceList.getDevice(devices[0].path);
154
155
  }
155
156
  else {
@@ -299,8 +300,8 @@ const onCall = async (message) => {
299
300
  postMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_PASSPHRASE_ON_DEVICE, { device: device.toMessageObject() }));
300
301
  });
301
302
  device.on(events_2.DEVICE.SAVE_STATE, (state) => {
302
- connect_common_1.storage.saveForOrigin(store => {
303
- if (useCoreInPopup && env === 'webextension') {
303
+ if (useCoreInPopup && env === 'webextension') {
304
+ connect_common_1.storage.saveForOrigin(store => {
304
305
  return {
305
306
  ...store,
306
307
  preferredDevice: store.preferredDevice
@@ -311,9 +312,8 @@ const onCall = async (message) => {
311
312
  }
312
313
  : undefined,
313
314
  };
314
- }
315
- return store;
316
- }, origin);
315
+ }, origin);
316
+ }
317
317
  });
318
318
  if (!device.getInternalState() && useCoreInPopup && env === 'webextension') {
319
319
  const { preferredDevice } = connect_common_1.storage.loadForOrigin(origin) || {};