@trezor/connect 9.2.1 → 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 (115) hide show
  1. package/CHANGELOG.md +90 -0
  2. package/README.md +1 -1
  3. package/lib/api/binance/api/binanceSignTransaction.d.ts +1 -1
  4. package/lib/api/binance/binanceSignTx.d.ts +1 -1
  5. package/lib/api/bitcoin/Fees.d.ts +2 -2
  6. package/lib/api/bitcoin/TransactionComposer.d.ts +2 -2
  7. package/lib/api/blockchainDisconnect.d.ts +1 -0
  8. package/lib/api/blockchainDisconnect.js +3 -4
  9. package/lib/api/blockchainEstimateFee.d.ts +1 -0
  10. package/lib/api/blockchainEstimateFee.js +7 -4
  11. package/lib/api/blockchainGetAccountBalanceHistory.d.ts +1 -0
  12. package/lib/api/blockchainGetAccountBalanceHistory.js +3 -1
  13. package/lib/api/blockchainGetCurrentFiatRates.d.ts +1 -0
  14. package/lib/api/blockchainGetCurrentFiatRates.js +3 -1
  15. package/lib/api/blockchainGetFiatRatesForTimestamps.d.ts +1 -0
  16. package/lib/api/blockchainGetFiatRatesForTimestamps.js +3 -1
  17. package/lib/api/blockchainGetTransactions.d.ts +1 -0
  18. package/lib/api/blockchainGetTransactions.js +3 -1
  19. package/lib/api/blockchainSetCustomBackend.js +1 -5
  20. package/lib/api/blockchainSubscribe.d.ts +2 -0
  21. package/lib/api/blockchainSubscribe.js +13 -2
  22. package/lib/api/blockchainSubscribeFiatRates.d.ts +1 -0
  23. package/lib/api/blockchainSubscribeFiatRates.js +3 -1
  24. package/lib/api/blockchainUnsubscribe.d.ts +1 -0
  25. package/lib/api/blockchainUnsubscribe.js +5 -2
  26. package/lib/api/blockchainUnsubscribeFiatRates.d.ts +1 -0
  27. package/lib/api/blockchainUnsubscribeFiatRates.js +6 -2
  28. package/lib/api/changeLanguage.d.ts +0 -1
  29. package/lib/api/changeLanguage.js +8 -39
  30. package/lib/api/composeTransaction.d.ts +2 -0
  31. package/lib/api/composeTransaction.js +10 -5
  32. package/lib/api/eos/eosSignTx.d.ts +58 -58
  33. package/lib/api/ethereum/api/ethereumGetPublicKey.d.ts +6 -6
  34. package/lib/api/ethereum/api/ethereumSignTypedData.d.ts +2 -1
  35. package/lib/api/ethereum/ethereumDefinitions.js +1 -0
  36. package/lib/api/getAccountInfo.js +4 -3
  37. package/lib/api/getCoinInfo.d.ts +25 -22
  38. package/lib/api/getFeatures.d.ts +10 -10
  39. package/lib/api/getPublicKey.d.ts +6 -6
  40. package/lib/api/nem/nemSignTx.d.ts +13 -13
  41. package/lib/api/pushTransaction.d.ts +1 -0
  42. package/lib/api/pushTransaction.js +2 -1
  43. package/lib/api/resetDevice.d.ts +1 -1
  44. package/lib/api/resetDevice.js +2 -2
  45. package/lib/api/signTransaction.d.ts +1 -0
  46. package/lib/api/signTransaction.js +5 -3
  47. package/lib/api/stellar/stellarSignTx.d.ts +1 -1
  48. package/lib/api/tezos/tezosSignTx.d.ts +18 -18
  49. package/lib/backend/BackendManager.d.ts +6 -4
  50. package/lib/backend/BackendManager.js +36 -28
  51. package/lib/backend/Blockchain.d.ts +15 -4
  52. package/lib/backend/Blockchain.js +27 -17
  53. package/lib/backend/BlockchainLink.d.ts +3 -3
  54. package/lib/backend/BlockchainLink.js +3 -3
  55. package/lib/core/AbstractMethod.js +1 -0
  56. package/lib/core/index.js +34 -5
  57. package/lib/data/DataManager.d.ts +22 -0
  58. package/lib/data/DataManager.js +7 -3
  59. package/lib/data/coinInfo.d.ts +131 -117
  60. package/lib/data/config.d.ts +22 -0
  61. package/lib/data/config.js +19 -1
  62. package/lib/data/connectSettings.js +3 -0
  63. package/lib/data/defaultFeeLevels.js +9 -1
  64. package/lib/data/deviceAuthenticityConfig.d.ts +9 -0
  65. package/lib/data/deviceAuthenticityConfig.js +26 -3
  66. package/lib/data/firmwareInfo.d.ts +1 -1
  67. package/lib/data/firmwareInfo.js +1 -5
  68. package/lib/data/getLanguage.d.ts +6 -0
  69. package/lib/data/getLanguage.js +10 -0
  70. package/lib/data/models.d.ts +9 -0
  71. package/lib/data/models.js +9 -0
  72. package/lib/data/version.d.ts +1 -1
  73. package/lib/data/version.js +1 -1
  74. package/lib/device/Device.d.ts +15 -3
  75. package/lib/device/Device.js +55 -6
  76. package/lib/device/DeviceCommands.d.ts +8 -8
  77. package/lib/device/DeviceList.js +4 -6
  78. package/lib/device/resolveDescriptorForTaproot.js +21 -16
  79. package/lib/events/blockchain.d.ts +3 -0
  80. package/lib/events/device.d.ts +1 -0
  81. package/lib/events/device.js +1 -0
  82. package/lib/types/api/applySettings.d.ts +6 -6
  83. package/lib/types/api/authenticateDevice.d.ts +9 -0
  84. package/lib/types/api/bitcoin/index.d.ts +1 -0
  85. package/lib/types/api/blockchainSetCustomBackend.d.ts +3 -2
  86. package/lib/types/api/blockchainSubscribe.d.ts +1 -0
  87. package/lib/types/api/composeTransaction.d.ts +2 -0
  88. package/lib/types/api/getAccountInfo.d.ts +1 -0
  89. package/lib/types/api/getAddress.d.ts +5 -5
  90. package/lib/types/api/getCoinInfo.d.ts +4 -2
  91. package/lib/types/api/getPublicKey.js +4 -1
  92. package/lib/types/api/nemGetAddress.d.ts +11 -4
  93. package/lib/types/api/nemGetAddress.js +9 -0
  94. package/lib/types/api/pushTransaction.d.ts +1 -0
  95. package/lib/types/api/pushTransaction.js +1 -0
  96. package/lib/types/api/recoveryDevice.d.ts +1 -1
  97. package/lib/types/api/resetDevice.d.ts +1 -15
  98. package/lib/types/api/resetDevice.js +0 -9
  99. package/lib/types/api/setBusy.d.ts +2 -2
  100. package/lib/types/coinInfo.d.ts +15 -7
  101. package/lib/types/coinInfo.js +8 -6
  102. package/lib/types/firmware.d.ts +5 -15
  103. package/lib/types/params.d.ts +1 -0
  104. package/lib/types/params.js +5 -2
  105. package/lib/types/settings.d.ts +1 -0
  106. package/lib/utils/assetUtils.js +18 -8
  107. package/lib/utils/{assets-native.d.ts → assets.native.d.ts} +1 -1
  108. package/lib/utils/{assets-native.js → assets.native.js} +1 -1
  109. package/lib/utils/debug.d.ts +5 -31
  110. package/lib/utils/debug.js +8 -110
  111. package/lib/utils/hdnodeUtils.d.ts +3 -3
  112. package/lib/utils/pathUtils.d.ts +3 -3
  113. package/lib/workers/{workers-react-native.d.ts → workers.native.d.ts} +1 -1
  114. package/lib/workers/{workers-react-native.js → workers.native.js} +1 -1
  115. package/package.json +40 -20
@@ -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,7 +1,7 @@
1
1
  import type { TypedCall } from '../../device/DeviceCommands';
2
2
  import { StellarTransaction } from '../../types/api/stellar';
3
3
  export declare const stellarSignTx: (typedCall: TypedCall, address_n: number[], networkPassphrase: string, tx: StellarTransaction) => Promise<{
4
- public_key: string;
5
4
  signature: string;
5
+ public_key: string;
6
6
  }>;
7
7
  //# sourceMappingURL=stellarSignTx.d.ts.map
@@ -18,31 +18,20 @@ export declare const createTx: (address_n: number[], branch: string, operation:
18
18
  source: Uint8Array;
19
19
  amount: string | number;
20
20
  fee: string | number;
21
- gas_limit: number;
22
21
  destination: {
23
22
  hash: Uint8Array;
24
23
  tag: number;
25
24
  };
26
25
  counter: number;
26
+ gas_limit: number;
27
27
  storage_limit: number;
28
28
  } | undefined;
29
- proposal?: {
30
- source: string;
31
- period: number;
32
- proposals: string[];
33
- } | undefined;
34
- ballot?: {
35
- source: string;
36
- period: number;
37
- proposal: string;
38
- ballot: PROTO.TezosBallotType;
39
- } | undefined;
40
29
  reveal?: {
41
- public_key: Uint8Array;
42
30
  source: Uint8Array;
31
+ public_key: Uint8Array;
43
32
  fee: string | number;
44
- gas_limit: number;
45
33
  counter: number;
34
+ gas_limit: number;
46
35
  storage_limit: number;
47
36
  } | undefined;
48
37
  origination?: {
@@ -51,20 +40,31 @@ export declare const createTx: (address_n: number[], branch: string, operation:
51
40
  spendable?: boolean | undefined;
52
41
  delegatable?: boolean | undefined;
53
42
  source: Uint8Array;
54
- script: string | number[];
55
43
  fee: string | number;
56
- gas_limit: number;
44
+ script: string | number[];
57
45
  counter: number;
46
+ gas_limit: number;
58
47
  storage_limit: number;
59
48
  balance: number;
60
49
  } | undefined;
61
50
  delegation?: {
62
51
  source: Uint8Array;
63
52
  fee: string | number;
64
- delegate: Uint8Array;
65
- gas_limit: number;
66
53
  counter: number;
54
+ gas_limit: number;
67
55
  storage_limit: number;
56
+ delegate: Uint8Array;
57
+ } | undefined;
58
+ proposal?: {
59
+ source: string;
60
+ period: number;
61
+ proposals: string[];
62
+ } | undefined;
63
+ ballot?: {
64
+ source: string;
65
+ period: number;
66
+ proposal: string;
67
+ ballot: PROTO.TezosBallotType;
68
68
  } | undefined;
69
69
  address_n: number[];
70
70
  branch: Uint8Array;
@@ -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
@@ -114,6 +114,7 @@ const initDevice = async (method) => {
114
114
  let showDeviceSelection = isWebUsb;
115
115
  const isUsingPopup = DataManager_1.DataManager.getSettings('popup');
116
116
  const origin = DataManager_1.DataManager.getSettings('origin');
117
+ const useCoreInPopup = DataManager_1.DataManager.getSettings('useCoreInPopup');
117
118
  const { preferredDevice } = connect_common_1.storage.load().origin[origin] || {};
118
119
  const preferredDeviceInList = preferredDevice && _deviceList.getDevice(preferredDevice.path);
119
120
  if (preferredDevice && !preferredDeviceInList) {
@@ -129,9 +130,10 @@ const initDevice = async (method) => {
129
130
  }
130
131
  else {
131
132
  const devices = _deviceList.asArray();
132
- if (devices.length === 1 && !isWebUsb) {
133
+ if (devices.length === 1 && (!isWebUsb || !isUsingPopup)) {
133
134
  device = _deviceList.getDevice(devices[0].path);
134
- showDeviceSelection = !!(device === null || device === void 0 ? void 0 : device.unreadableError) || device.isUnacquired();
135
+ showDeviceSelection =
136
+ !!(device === null || device === void 0 ? void 0 : device.unreadableError) || device.isUnacquired() || !!useCoreInPopup;
135
137
  }
136
138
  else {
137
139
  showDeviceSelection = true;
@@ -147,7 +149,8 @@ const initDevice = async (method) => {
147
149
  if (devices.length === 1 &&
148
150
  devices[0].type !== 'unreadable' &&
149
151
  devices[0].features &&
150
- !isWebUsb) {
152
+ !isWebUsb &&
153
+ !useCoreInPopup) {
151
154
  device = _deviceList.getDevice(devices[0].path);
152
155
  }
153
156
  else {
@@ -159,11 +162,11 @@ const initDevice = async (method) => {
159
162
  if (uiPromise) {
160
163
  const { payload } = await uiPromise.promise;
161
164
  if (payload.remember) {
162
- const { path, state } = payload.device;
165
+ const { label, path, state } = payload.device;
163
166
  connect_common_1.storage.save(store => {
164
167
  store.origin[origin] = {
165
168
  ...store.origin[origin],
166
- preferredDevice: { path, state },
169
+ preferredDevice: { label, path, state },
167
170
  };
168
171
  return store;
169
172
  });
@@ -186,6 +189,8 @@ const onCall = async (message) => {
186
189
  const trustedHost = DataManager_1.DataManager.getSettings('trustedHost');
187
190
  const isUsingPopup = DataManager_1.DataManager.getSettings('popup');
188
191
  const origin = DataManager_1.DataManager.getSettings('origin');
192
+ const env = DataManager_1.DataManager.getSettings('env');
193
+ const useCoreInPopup = DataManager_1.DataManager.getSettings('useCoreInPopup');
189
194
  const { preferredDevice } = connect_common_1.storage.loadForOrigin(origin) || {};
190
195
  if (preferredDevice && !message.payload.device) {
191
196
  message.payload.device = preferredDevice;
@@ -294,6 +299,30 @@ const onCall = async (message) => {
294
299
  device.on(events_2.DEVICE.PASSPHRASE_ON_DEVICE, () => {
295
300
  postMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_PASSPHRASE_ON_DEVICE, { device: device.toMessageObject() }));
296
301
  });
302
+ device.on(events_2.DEVICE.SAVE_STATE, (state) => {
303
+ if (useCoreInPopup && env === 'webextension') {
304
+ connect_common_1.storage.saveForOrigin(store => {
305
+ return {
306
+ ...store,
307
+ preferredDevice: store.preferredDevice
308
+ ? {
309
+ ...store.preferredDevice,
310
+ internalState: state,
311
+ internalStateExpiration: Date.now() + 1000 * 60 * 15,
312
+ }
313
+ : undefined,
314
+ };
315
+ }, origin);
316
+ }
317
+ });
318
+ if (!device.getInternalState() && useCoreInPopup && env === 'webextension') {
319
+ const { preferredDevice } = connect_common_1.storage.loadForOrigin(origin) || {};
320
+ if ((preferredDevice === null || preferredDevice === void 0 ? void 0 : preferredDevice.internalState) &&
321
+ (preferredDevice === null || preferredDevice === void 0 ? void 0 : preferredDevice.internalStateExpiration) &&
322
+ preferredDevice.internalStateExpiration > new Date().getTime()) {
323
+ device.setInternalState(preferredDevice.internalState);
324
+ }
325
+ }
297
326
  try {
298
327
  let PIN_TRIES = 1;
299
328
  const MAX_PIN_TRIES = 3;
@@ -64,6 +64,7 @@ export declare class DataManager {
64
64
  T1B1: string;
65
65
  T2T1: string;
66
66
  T2B1?: undefined;
67
+ T3T1?: undefined;
67
68
  };
68
69
  max: undefined;
69
70
  comment: string[];
@@ -74,6 +75,7 @@ export declare class DataManager {
74
75
  T1B1: string;
75
76
  T2T1: string;
76
77
  T2B1?: undefined;
78
+ T3T1?: undefined;
77
79
  };
78
80
  comment: string[];
79
81
  methods?: undefined;
@@ -85,6 +87,7 @@ export declare class DataManager {
85
87
  T1B1: string;
86
88
  T2T1: string;
87
89
  T2B1?: undefined;
90
+ T3T1?: undefined;
88
91
  };
89
92
  comment: string[];
90
93
  coin?: undefined;
@@ -96,6 +99,7 @@ export declare class DataManager {
96
99
  T1B1: string;
97
100
  T2T1: string;
98
101
  T2B1?: undefined;
102
+ T3T1?: undefined;
99
103
  };
100
104
  comment: string[];
101
105
  coin?: undefined;
@@ -108,6 +112,7 @@ export declare class DataManager {
108
112
  T1B1: string;
109
113
  T2T1: string;
110
114
  T2B1?: undefined;
115
+ T3T1?: undefined;
111
116
  };
112
117
  comment: string[];
113
118
  max?: undefined;
@@ -119,6 +124,7 @@ export declare class DataManager {
119
124
  T1B1: string;
120
125
  T2T1: string;
121
126
  T2B1?: undefined;
127
+ T3T1?: undefined;
122
128
  };
123
129
  coin?: undefined;
124
130
  max?: undefined;
@@ -129,6 +135,7 @@ export declare class DataManager {
129
135
  T1B1: string;
130
136
  T2T1: string;
131
137
  T2B1: string;
138
+ T3T1?: undefined;
132
139
  };
133
140
  comment: string[];
134
141
  coin?: undefined;
@@ -140,6 +147,7 @@ export declare class DataManager {
140
147
  T1B1: string;
141
148
  T2T1: string;
142
149
  T2B1?: undefined;
150
+ T3T1?: undefined;
143
151
  };
144
152
  coin?: undefined;
145
153
  max?: undefined;
@@ -151,6 +159,7 @@ export declare class DataManager {
151
159
  T1B1: string;
152
160
  T2T1: string;
153
161
  T2B1: string;
162
+ T3T1?: undefined;
154
163
  };
155
164
  coin?: undefined;
156
165
  max?: undefined;
@@ -162,11 +171,24 @@ export declare class DataManager {
162
171
  T1B1: string;
163
172
  T2T1: string;
164
173
  T2B1: string;
174
+ T3T1?: undefined;
165
175
  };
166
176
  comment: string[];
167
177
  coin?: undefined;
168
178
  methods?: undefined;
169
179
  max?: undefined;
180
+ } | {
181
+ methods: string[];
182
+ min: {
183
+ T1B1: string;
184
+ T2T1: string;
185
+ T2B1: string;
186
+ T3T1: string;
187
+ };
188
+ coin?: undefined;
189
+ max?: undefined;
190
+ comment?: undefined;
191
+ capabilities?: undefined;
170
192
  })[];
171
193
  };
172
194
  }