@trezor/connect 9.1.11 → 9.2.0

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 (114) hide show
  1. package/CHANGELOG.md +92 -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/bitcoin/refTx.js +3 -4
  8. package/lib/api/blockchainGetCurrentFiatRates.d.ts +1 -1
  9. package/lib/api/blockchainGetFiatRatesForTimestamps.d.ts +1 -1
  10. package/lib/api/cardano/cardanoOutputs.d.ts +1 -1
  11. package/lib/api/cardano/cardanoTokenBundle.d.ts +2 -2
  12. package/lib/api/changeLanguage.d.ts +11 -0
  13. package/lib/api/changeLanguage.js +73 -0
  14. package/lib/api/common/paramsValidator.js +4 -5
  15. package/lib/api/eos/eosSignTx.d.ts +57 -57
  16. package/lib/api/ethereum/api/ethereumGetPublicKey.d.ts +6 -6
  17. package/lib/api/ethereum/api/ethereumSignMessage.d.ts +2 -2
  18. package/lib/api/ethereum/api/ethereumSignTransaction.d.ts +2 -2
  19. package/lib/api/ethereum/api/ethereumSignTypedData.d.ts +6 -6
  20. package/lib/api/ethereum/api/ethereumSignTypedData.js +2 -2
  21. package/lib/api/ethereum/ethereumDefinitions.d.ts +2 -2
  22. package/lib/api/ethereum/ethereumSignTx.d.ts +3 -3
  23. package/lib/api/firmware/getBinary.d.ts +1 -1
  24. package/lib/api/firmware/getBinary.js +4 -5
  25. package/lib/api/firmware/modifyFirmware.js +2 -3
  26. package/lib/api/firmware/uploadFirmware.d.ts +2 -2
  27. package/lib/api/firmware/verifyAuthenticityProof.js +3 -3
  28. package/lib/api/getAccountInfo.d.ts +2 -0
  29. package/lib/api/getCoinInfo.d.ts +19 -19
  30. package/lib/api/getFeatures.d.ts +11 -11
  31. package/lib/api/getPublicKey.d.ts +6 -6
  32. package/lib/api/index.d.ts +1 -0
  33. package/lib/api/index.js +3 -1
  34. package/lib/api/nem/nemSignTx.d.ts +14 -14
  35. package/lib/api/rebootToBootloader.d.ts +2 -1
  36. package/lib/api/rebootToBootloader.js +10 -1
  37. package/lib/api/recoveryDevice.d.ts +1 -0
  38. package/lib/api/recoveryDevice.js +3 -0
  39. package/lib/api/stellar/stellarSignTx.d.ts +1 -1
  40. package/lib/api/stellar/stellarSignTx.js +6 -0
  41. package/lib/api/tezos/tezosSignTx.d.ts +18 -18
  42. package/lib/backend/BackendManager.d.ts +5 -2
  43. package/lib/backend/BackendManager.js +54 -20
  44. package/lib/backend/Blockchain.d.ts +8 -8
  45. package/lib/backend/Blockchain.js +37 -27
  46. package/lib/constants/index.d.ts +1 -1
  47. package/lib/constants/index.js +2 -1
  48. package/lib/core/AbstractMethod.d.ts +4 -4
  49. package/lib/core/AbstractMethod.js +23 -22
  50. package/lib/core/index.d.ts +3 -6
  51. package/lib/core/index.js +73 -52
  52. package/lib/core/method.d.ts +1 -3
  53. package/lib/core/method.native.d.ts +1 -3
  54. package/lib/data/DataManager.d.ts +2 -2
  55. package/lib/data/analyticsInfo.d.ts +2 -2
  56. package/lib/data/coinInfo.d.ts +103 -103
  57. package/lib/data/coinInfo.js +6 -6
  58. package/lib/data/config.js +1 -1
  59. package/lib/data/connectSettings.js +3 -0
  60. package/lib/data/deviceAuthenticityConfig.js +7 -1
  61. package/lib/data/firmwareInfo.d.ts +1 -1
  62. package/lib/data/firmwareInfo.js +14 -12
  63. package/lib/data/version.d.ts +1 -1
  64. package/lib/data/version.js +1 -1
  65. package/lib/device/Device.d.ts +7 -6
  66. package/lib/device/Device.js +13 -11
  67. package/lib/device/DeviceCommands.d.ts +7 -7
  68. package/lib/device/DeviceCommands.js +4 -4
  69. package/lib/device/DeviceList.d.ts +1 -1
  70. package/lib/device/DeviceList.js +3 -3
  71. package/lib/events/blockchain.d.ts +10 -2
  72. package/lib/events/blockchain.js +1 -0
  73. package/lib/events/call.d.ts +3 -3
  74. package/lib/events/core.d.ts +12 -10
  75. package/lib/events/iframe.d.ts +1 -1
  76. package/lib/events/popup.d.ts +13 -1
  77. package/lib/events/ui-promise.d.ts +1 -1
  78. package/lib/events/ui-request.d.ts +1 -2
  79. package/lib/events/webextension.d.ts +1 -0
  80. package/lib/events/webextension.js +1 -0
  81. package/lib/factory.js +1 -0
  82. package/lib/index.d.ts +0 -4
  83. package/lib/index.js +23 -40
  84. package/lib/types/api/applySettings.d.ts +6 -6
  85. package/lib/types/api/binance/index.d.ts +10 -10
  86. package/lib/types/api/cardano/index.d.ts +4 -4
  87. package/lib/types/api/changeLanguage.d.ts +15 -0
  88. package/lib/types/api/changeLanguage.js +17 -0
  89. package/lib/types/api/cipherKeyValue.d.ts +2 -2
  90. package/lib/types/api/eos/index.d.ts +3 -3
  91. package/lib/types/api/ethereum/index.d.ts +3 -3
  92. package/lib/types/api/firmwareUpdate.d.ts +1 -1
  93. package/lib/types/api/getAddress.d.ts +5 -5
  94. package/lib/types/api/index.d.ts +2 -0
  95. package/lib/types/api/nem/index.d.ts +7 -7
  96. package/lib/types/api/rebootToBootloader.d.ts +2 -2
  97. package/lib/types/api/recoveryDevice.d.ts +1 -1
  98. package/lib/types/api/stellar/index.d.ts +169 -146
  99. package/lib/types/api/stellar/index.js +13 -1
  100. package/lib/types/device.d.ts +4 -1
  101. package/lib/types/device.js +2 -2
  102. package/lib/types/firmware.d.ts +2 -0
  103. package/lib/types/index.d.ts +1 -1
  104. package/lib/types/settings.d.ts +1 -0
  105. package/lib/utils/assets-browser.d.ts +1 -1
  106. package/lib/utils/assets.d.ts +3 -1
  107. package/lib/utils/assets.js +2 -2
  108. package/lib/utils/deviceFeaturesUtils.js +4 -5
  109. package/lib/utils/firmwareUtils.js +4 -5
  110. package/lib/utils/hdnodeUtils.d.ts +3 -3
  111. package/lib/utils/pathUtils.d.ts +3 -3
  112. package/lib/utils/promiseUtils.d.ts +0 -1
  113. package/lib/utils/urlUtils.js +3 -3
  114. package/package.json +28 -30
@@ -4,46 +4,51 @@ exports.BackendManager = void 0;
4
4
  const DataManager_1 = require("../data/DataManager");
5
5
  const constants_1 = require("../constants");
6
6
  const Blockchain_1 = require("./Blockchain");
7
+ const events_1 = require("../events");
7
8
  class BackendManager {
8
9
  constructor() {
9
10
  this.instances = {};
10
11
  this.custom = {};
11
12
  this.preferred = {};
13
+ this.reconnect = {};
12
14
  }
13
15
  get(shortcut) {
14
16
  var _a;
15
17
  return (_a = this.instances[shortcut]) !== null && _a !== void 0 ? _a : null;
16
18
  }
17
- remove(shortcut) {
18
- delete this.instances[shortcut];
19
- }
20
19
  async getOrConnect(coinInfo, postMessage) {
21
- let backend = this.get(coinInfo.shortcut);
20
+ let backend = this.instances[coinInfo.shortcut];
22
21
  if (!backend) {
23
22
  backend = new Blockchain_1.Blockchain({
24
23
  coinInfo: this.patchCoinInfo(coinInfo),
25
24
  postMessage,
26
25
  debug: DataManager_1.DataManager.getSettings('debug'),
27
26
  proxy: DataManager_1.DataManager.getSettings('proxy'),
28
- onConnected: url => this.setPreferred(coinInfo.shortcut, url),
29
- onDisconnected: () => this.remove(coinInfo.shortcut),
27
+ onDisconnected: this.onDisconnected.bind(this),
30
28
  });
31
- this.instances[coinInfo.shortcut] = backend;
32
- try {
33
- await backend.init();
34
- }
35
- catch (error) {
36
- this.remove(coinInfo.shortcut);
37
- this.removePreferred(coinInfo.shortcut);
38
- throw error;
29
+ this.setInstance(coinInfo.shortcut, backend);
30
+ }
31
+ const reconnect = this.clearReconnect(coinInfo.shortcut);
32
+ try {
33
+ const info = await backend.init();
34
+ this.setPreferred(coinInfo.shortcut, info.url);
35
+ return backend;
36
+ }
37
+ catch (error) {
38
+ this.setInstance(coinInfo.shortcut, undefined);
39
+ this.setPreferred(coinInfo.shortcut, undefined);
40
+ if (reconnect) {
41
+ this.planReconnect(backend.coinInfo, backend.postMessage, reconnect.attempts);
39
42
  }
43
+ throw error;
40
44
  }
41
- return backend;
42
45
  }
43
46
  dispose() {
47
+ Object.keys(this.reconnect).forEach(this.clearReconnect, this);
44
48
  Object.values(this.instances).forEach(i => i.disconnect());
45
49
  }
46
50
  reconnectAll() {
51
+ Object.keys(this.reconnect).forEach(this.clearReconnect, this);
47
52
  const params = Object.values(this.instances).map(i => [i.coinInfo, i.postMessage]);
48
53
  Object.values(this.instances).forEach(i => i.disconnect());
49
54
  return Promise.all(params.map(p => this.getOrConnect(...p)));
@@ -55,18 +60,47 @@ class BackendManager {
55
60
  }
56
61
  }
57
62
  setCustom(shortcut, blockchainLink) {
58
- this.removePreferred(shortcut);
63
+ this.setPreferred(shortcut, undefined);
59
64
  this.custom[shortcut] = blockchainLink;
60
65
  }
61
66
  removeCustom(shortcut) {
62
- this.removePreferred(shortcut);
67
+ this.setPreferred(shortcut, undefined);
63
68
  delete this.custom[shortcut];
64
69
  }
70
+ setInstance(shortcut, instance) {
71
+ if (!instance)
72
+ delete this.instances[shortcut];
73
+ else
74
+ this.instances[shortcut] = instance;
75
+ }
65
76
  setPreferred(shortcut, url) {
66
- this.preferred[shortcut] = url;
77
+ if (!url)
78
+ delete this.preferred[shortcut];
79
+ else
80
+ this.preferred[shortcut] = url;
67
81
  }
68
- removePreferred(shortcut) {
69
- delete this.preferred[shortcut];
82
+ planReconnect(coinInfo, postMessage, attempts) {
83
+ var _a;
84
+ const timeout = Math.min(2500 * attempts, 20000);
85
+ const time = Date.now() + timeout;
86
+ const handle = setTimeout(() => {
87
+ this.getOrConnect(coinInfo, postMessage).catch(() => { });
88
+ }, timeout);
89
+ clearTimeout((_a = this.reconnect[coinInfo.shortcut]) === null || _a === void 0 ? void 0 : _a.handle);
90
+ this.reconnect[coinInfo.shortcut] = { attempts: attempts + 1, handle };
91
+ postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.RECONNECTING, { coin: coinInfo, time }));
92
+ }
93
+ clearReconnect(shortcut) {
94
+ const reconnect = this.reconnect[shortcut];
95
+ clearTimeout(reconnect === null || reconnect === void 0 ? void 0 : reconnect.handle);
96
+ delete this.reconnect[shortcut];
97
+ return reconnect;
98
+ }
99
+ onDisconnected(backend, pendingSubscriptions) {
100
+ this.setInstance(backend.coinInfo.shortcut, undefined);
101
+ if (pendingSubscriptions) {
102
+ this.planReconnect(backend.coinInfo, backend.postMessage, 0);
103
+ }
70
104
  }
71
105
  patchCoinInfo(coinInfo) {
72
106
  var _a, _b;
@@ -1,14 +1,13 @@
1
1
  import BlockchainLink, { ServerInfo, SubscriptionAccountInfo, BlockchainLinkParams, BlockchainLinkResponse } from '@trezor/blockchain-link';
2
- import { PostMessage } from '../events';
2
+ import { CoreEventMessage } from '../events';
3
3
  import { ERRORS } from '../constants';
4
4
  import type { CoinInfo, Proxy } from '../types';
5
5
  export type BlockchainOptions = {
6
6
  coinInfo: CoinInfo;
7
- postMessage: PostMessage;
7
+ postMessage: (message: CoreEventMessage) => void;
8
8
  proxy?: Proxy;
9
9
  debug?: boolean;
10
- onConnected?: (url: string) => void;
11
- onDisconnected?: () => void;
10
+ onDisconnected?: (backend: Blockchain, pendingSubscriptions?: boolean) => void;
12
11
  };
13
12
  export declare class Blockchain {
14
13
  link: BlockchainLink;
@@ -17,11 +16,12 @@ export declare class Blockchain {
17
16
  postMessage: BlockchainOptions['postMessage'];
18
17
  feeForBlock: BlockchainLinkResponse<'estimateFee'>;
19
18
  feeTimestamp: number;
20
- private onConnected;
21
19
  private onDisconnected;
20
+ private initPromise?;
22
21
  constructor(options: BlockchainOptions);
23
22
  onError(error: ERRORS.TrezorError): void;
24
- init(): Promise<void>;
23
+ private initLink;
24
+ init(): Promise<ServerInfo>;
25
25
  getTransactions(txs: string[]): Promise<import("@trezor/blockchain-link").Transaction[]>;
26
26
  getTransactionHexes(txids: string[]): Promise<string[]>;
27
27
  getCurrentFiatRates(params: {
@@ -29,7 +29,7 @@ export declare class Blockchain {
29
29
  token?: string;
30
30
  }): Promise<{
31
31
  ts: number;
32
- rates: import("@trezor/blockchain-link").FiatRates;
32
+ rates: import("@trezor/blockchain-link").FiatRatesLegacy;
33
33
  }>;
34
34
  getFiatRatesForTimestamps(params: {
35
35
  currencies?: string[];
@@ -38,7 +38,7 @@ export declare class Blockchain {
38
38
  }): Promise<{
39
39
  tickers: {
40
40
  ts: number;
41
- rates: import("@trezor/blockchain-link").FiatRates;
41
+ rates: import("@trezor/blockchain-link").FiatRatesLegacy;
42
42
  }[];
43
43
  }>;
44
44
  getAccountBalanceHistory(params: BlockchainLinkParams<'getAccountBalanceHistory'>): Promise<import("@trezor/blockchain-link").AccountBalanceHistory[]>;
@@ -28,7 +28,6 @@ class Blockchain {
28
28
  this.feeTimestamp = 0;
29
29
  this.coinInfo = options.coinInfo;
30
30
  this.postMessage = options.postMessage;
31
- this.onConnected = options.onConnected;
32
31
  this.onDisconnected = options.onDisconnected;
33
32
  const { blockchainLink } = options.coinInfo;
34
33
  if (!blockchainLink) {
@@ -50,43 +49,54 @@ class Blockchain {
50
49
  }
51
50
  onError(error) {
52
51
  var _a;
52
+ const pendingSubscriptions = this.link.listenerCount('block') ||
53
+ this.link.listenerCount('notification') ||
54
+ this.link.listenerCount('fiatRates');
53
55
  this.link.dispose();
54
56
  this.postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.ERROR, {
55
57
  coin: this.coinInfo,
56
58
  error: error.message,
57
59
  code: error.code,
58
60
  }));
59
- (_a = this.onDisconnected) === null || _a === void 0 ? void 0 : _a.call(this);
60
- }
61
- async init() {
62
- this.link.on('connected', async () => {
63
- var _a;
64
- const info = await this.link.getInfo();
65
- this.serverInfo = info;
66
- const shortcut = this.coinInfo.shortcut === 'tXRP' ? 'XRP' : this.coinInfo.shortcut;
67
- if (info.shortcut.toLowerCase() !== shortcut.toLowerCase()) {
68
- this.onError(constants_1.ERRORS.TypedError('Backend_Invalid'));
69
- return;
70
- }
71
- (_a = this.onConnected) === null || _a === void 0 ? void 0 : _a.call(this, info.url);
72
- this.postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.CONNECT, {
73
- coin: this.coinInfo,
74
- ...info,
75
- }));
76
- });
77
- this.link.on('disconnected', () => {
78
- this.onError(constants_1.ERRORS.TypedError('Backend_Disconnected'));
79
- });
80
- this.link.on('error', error => {
81
- this.onError(constants_1.ERRORS.TypedError('Backend_Error', error.message));
82
- });
61
+ (_a = this.onDisconnected) === null || _a === void 0 ? void 0 : _a.call(this, this, !!pendingSubscriptions);
62
+ }
63
+ async initLink() {
64
+ let info;
83
65
  try {
84
66
  await this.link.connect();
67
+ info = await this.link.getInfo();
85
68
  }
86
69
  catch (error) {
87
- this.onError(constants_1.ERRORS.TypedError('Backend_Error', error.message));
88
- throw error;
70
+ throw constants_1.ERRORS.TypedError('Backend_Error', error.message);
71
+ }
72
+ this.serverInfo = info;
73
+ const shortcut = this.coinInfo.shortcut === 'tXRP' ? 'XRP' : this.coinInfo.shortcut;
74
+ if (info.shortcut.toLowerCase() !== shortcut.toLowerCase()) {
75
+ throw constants_1.ERRORS.TypedError('Backend_Invalid');
76
+ }
77
+ this.postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.CONNECT, {
78
+ coin: this.coinInfo,
79
+ ...info,
80
+ }));
81
+ this.link.on('disconnected', () => {
82
+ this.onError(constants_1.ERRORS.TypedError('Backend_Disconnected'));
83
+ });
84
+ return info;
85
+ }
86
+ init() {
87
+ if (!this.initPromise) {
88
+ this.initPromise = this.initLink()
89
+ .then(info => {
90
+ this.initPromise = Promise.resolve(info);
91
+ return info;
92
+ })
93
+ .catch(error => {
94
+ this.initPromise = Promise.reject(error);
95
+ this.link.dispose();
96
+ return this.initPromise;
97
+ });
89
98
  }
99
+ return this.initPromise;
90
100
  }
91
101
  getTransactions(txs) {
92
102
  return Promise.all(txs.map(id => this.link.getTransaction(id)));
@@ -2,5 +2,5 @@ export * as ERRORS from './errors';
2
2
  export * as NETWORK from './network';
3
3
  export * as CARDANO from './cardano';
4
4
  export * as NEM from './nem';
5
- export * as PROTO from '@trezor/protobuf/lib/messages-schema';
5
+ export { MessagesSchema as PROTO } from '@trezor/protobuf';
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -6,5 +6,6 @@ exports.ERRORS = tslib_1.__importStar(require("./errors"));
6
6
  exports.NETWORK = tslib_1.__importStar(require("./network"));
7
7
  exports.CARDANO = tslib_1.__importStar(require("./cardano"));
8
8
  exports.NEM = tslib_1.__importStar(require("./nem"));
9
- exports.PROTO = tslib_1.__importStar(require("@trezor/protobuf/lib/messages-schema"));
9
+ var protobuf_1 = require("@trezor/protobuf");
10
+ Object.defineProperty(exports, "PROTO", { enumerable: true, get: function () { return protobuf_1.MessagesSchema; } });
10
11
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
- import { Deferred } from '@trezor/utils/lib/createDeferred';
1
+ import { Deferred } from '@trezor/utils';
2
2
  import { NETWORK } from '../constants';
3
- import { CallMethodPayload, CallMethodResponse, UiRequestButtonData, UiPromiseCreator, PostMessage } from '../events';
3
+ import { CallMethodPayload, CallMethodResponse, UiRequestButtonData, UiPromiseCreator, CoreEventMessage } from '../events';
4
4
  import type { Device } from '../device/Device';
5
5
  import type { FirmwareRange } from '../types';
6
6
  export type Payload<M> = Extract<CallMethodPayload, {
@@ -40,18 +40,18 @@ export declare abstract class AbstractMethod<Name extends CallMethodPayload['met
40
40
  confirmation?(): Promise<boolean | undefined>;
41
41
  noBackupConfirmation?(allowSuppression?: boolean): Promise<boolean>;
42
42
  getButtonRequestData?(code: string): UiRequestButtonData | undefined;
43
- postMessage: PostMessage;
43
+ postMessage: (message: CoreEventMessage) => void;
44
44
  getPopupPromise: () => Deferred<void>;
45
45
  createUiPromise: UiPromiseCreator;
46
46
  removeUiPromise: (promise: Deferred<any>) => void;
47
47
  initAsync?(): Promise<void>;
48
- initAsyncPromise?: Promise<void>;
49
48
  constructor(message: {
50
49
  id?: number;
51
50
  payload: Payload<Name>;
52
51
  });
53
52
  setDevice(device: Device): void;
54
53
  requestPermissions(): Promise<boolean>;
54
+ private getOriginPermissions;
55
55
  checkPermissions(): void;
56
56
  savePermissions(temporary?: boolean): void;
57
57
  checkFirmwareRange(isUsingPopup?: boolean): Promise<"ui-device_firmware_old" | "ui-device_firmware_unsupported" | "ui-device_firmware_not_compatible" | "ui-device_firmware_not_installed" | undefined>;
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AbstractMethod = exports.DEFAULT_FIRMWARE_RANGE = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const connect_common_1 = require("@trezor/connect-common");
6
- const versionUtils = tslib_1.__importStar(require("@trezor/utils/lib/versionUtils"));
5
+ const utils_1 = require("@trezor/utils");
7
6
  const DataManager_1 = require("../data/DataManager");
8
7
  const constants_1 = require("../constants");
9
8
  const events_1 = require("../events");
@@ -81,47 +80,49 @@ class AbstractMethod {
81
80
  }
82
81
  return false;
83
82
  }
83
+ getOriginPermissions() {
84
+ var _a;
85
+ const origin = DataManager_1.DataManager.getSettings('origin');
86
+ if (!origin) {
87
+ return [];
88
+ }
89
+ return ((_a = connect_common_1.storage.loadForOrigin(origin)) === null || _a === void 0 ? void 0 : _a.permissions) || [];
90
+ }
84
91
  checkPermissions() {
85
- const savedPermissions = connect_common_1.storage.load().permissions;
92
+ const originPermissions = this.getOriginPermissions();
86
93
  let notPermitted = [...this.requiredPermissions];
87
- if (savedPermissions) {
88
- const originPermissions = savedPermissions.filter(p => p.origin === DataManager_1.DataManager.getSettings('origin'));
89
- if (originPermissions.length > 0) {
90
- notPermitted = notPermitted.filter(np => {
91
- const granted = originPermissions.find(p => p.type === np && p.device === this.device.features.device_id);
92
- return !granted;
93
- });
94
- }
94
+ if (originPermissions.length > 0) {
95
+ notPermitted = notPermitted.filter(np => {
96
+ const granted = originPermissions.find(p => p.type === np && p.device === this.device.features.device_id);
97
+ return !granted;
98
+ });
95
99
  }
96
100
  this.requiredPermissions = notPermitted;
97
101
  }
98
102
  savePermissions(temporary = false) {
99
- const savedPermissions = connect_common_1.storage.load(temporary).permissions || [];
103
+ const originPermissions = this.getOriginPermissions();
100
104
  let permissionsToSave = this.requiredPermissions.map(p => ({
101
- origin: DataManager_1.DataManager.getSettings('origin'),
102
105
  type: p,
103
106
  device: this.device.features.device_id || undefined,
104
107
  }));
105
108
  let emitEvent = false;
106
109
  if (this.requiredPermissions.indexOf('read') >= 0) {
107
- const wasAlreadyGranted = savedPermissions.filter(p => p.origin === DataManager_1.DataManager.getSettings('origin') &&
108
- p.type === 'read' &&
109
- p.device === this.device.features.device_id);
110
+ const wasAlreadyGranted = originPermissions.filter(p => p.type === 'read' && p.device === this.device.features.device_id);
110
111
  if (wasAlreadyGranted.length < 1) {
111
112
  emitEvent = true;
112
113
  }
113
114
  }
114
- const originPermissions = savedPermissions.filter(p => p.origin === DataManager_1.DataManager.getSettings('origin'));
115
115
  if (originPermissions.length > 0) {
116
116
  permissionsToSave = permissionsToSave.filter(p2s => {
117
117
  const granted = originPermissions.find(p => p.type === p2s.type && p.device === p2s.device);
118
118
  return !granted;
119
119
  });
120
120
  }
121
- connect_common_1.storage.save(state => ({
121
+ const origin = DataManager_1.DataManager.getSettings('origin');
122
+ connect_common_1.storage.saveForOrigin(state => ({
122
123
  ...state,
123
- permissions: savedPermissions.concat(permissionsToSave),
124
- }), temporary);
124
+ permissions: [...(state.permissions || []), ...permissionsToSave],
125
+ }), origin, temporary);
125
126
  if (emitEvent) {
126
127
  this.postMessage((0, events_1.createDeviceMessage)(events_1.DEVICE.CONNECT, this.device.toMessageObject()));
127
128
  }
@@ -145,10 +146,10 @@ class AbstractMethod {
145
146
  }
146
147
  const version = device.getVersion().join('.');
147
148
  if (device.firmwareStatus === 'required' ||
148
- !versionUtils.isNewerOrEqual(version, range.min)) {
149
+ !utils_1.versionUtils.isNewerOrEqual(version, range.min)) {
149
150
  return events_1.UI.FIRMWARE_OLD;
150
151
  }
151
- if (range.max !== '0' && versionUtils.isNewer(version, range.max)) {
152
+ if (range.max !== '0' && utils_1.versionUtils.isNewer(version, range.max)) {
152
153
  if (isUsingPopup) {
153
154
  await this.getPopupPromise().promise;
154
155
  const uiPromise = this.createUiPromise(events_1.UI.RECEIVE_CONFIRMATION);
@@ -1,18 +1,15 @@
1
1
  /// <reference types="node" />
2
2
  import EventEmitter from 'events';
3
- import { TransportInfo, CoreMessage } from '../events';
3
+ import { TransportInfo, CoreRequestMessage, CoreEventMessage } from '../events';
4
4
  import { AbstractMethod } from './AbstractMethod';
5
5
  import { LogWriter } from '../utils/debug';
6
6
  import type { ConnectSettings } from '../types';
7
- export declare const handleMessage: (message: CoreMessage) => void;
8
- export declare const onCall: (message: CoreMessage) => Promise<void>;
9
7
  export declare class Core extends EventEmitter {
10
- handleMessage(message: any): void;
8
+ handleMessage(message: CoreRequestMessage): void;
11
9
  dispose(): Promise<void>;
12
10
  getCurrentMethod(): Promise<AbstractMethod<any, undefined>>;
13
11
  getTransportInfo(): TransportInfo | undefined;
14
12
  enumerate(): void;
15
13
  }
16
- export declare const initCore: (settings: ConnectSettings, logWriterFactory?: () => LogWriter | undefined) => Promise<Core>;
17
- export declare const initTransport: (settings: ConnectSettings) => Promise<void>;
14
+ export declare const initCore: (settings: ConnectSettings, onCoreEvent: (message: CoreEventMessage) => void, logWriterFactory?: () => LogWriter | undefined) => Promise<Core>;
18
15
  //# sourceMappingURL=index.d.ts.map