@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.
- package/CHANGELOG.md +92 -0
- package/README.md +1 -1
- package/lib/api/binance/api/binanceSignTransaction.d.ts +1 -1
- package/lib/api/binance/binanceSignTx.d.ts +1 -1
- package/lib/api/bitcoin/Fees.d.ts +2 -2
- package/lib/api/bitcoin/TransactionComposer.d.ts +2 -2
- package/lib/api/bitcoin/refTx.js +3 -4
- package/lib/api/blockchainGetCurrentFiatRates.d.ts +1 -1
- package/lib/api/blockchainGetFiatRatesForTimestamps.d.ts +1 -1
- package/lib/api/cardano/cardanoOutputs.d.ts +1 -1
- package/lib/api/cardano/cardanoTokenBundle.d.ts +2 -2
- package/lib/api/changeLanguage.d.ts +11 -0
- package/lib/api/changeLanguage.js +73 -0
- package/lib/api/common/paramsValidator.js +4 -5
- package/lib/api/eos/eosSignTx.d.ts +57 -57
- package/lib/api/ethereum/api/ethereumGetPublicKey.d.ts +6 -6
- package/lib/api/ethereum/api/ethereumSignMessage.d.ts +2 -2
- package/lib/api/ethereum/api/ethereumSignTransaction.d.ts +2 -2
- package/lib/api/ethereum/api/ethereumSignTypedData.d.ts +6 -6
- package/lib/api/ethereum/api/ethereumSignTypedData.js +2 -2
- package/lib/api/ethereum/ethereumDefinitions.d.ts +2 -2
- package/lib/api/ethereum/ethereumSignTx.d.ts +3 -3
- package/lib/api/firmware/getBinary.d.ts +1 -1
- package/lib/api/firmware/getBinary.js +4 -5
- package/lib/api/firmware/modifyFirmware.js +2 -3
- package/lib/api/firmware/uploadFirmware.d.ts +2 -2
- package/lib/api/firmware/verifyAuthenticityProof.js +3 -3
- package/lib/api/getAccountInfo.d.ts +2 -0
- package/lib/api/getCoinInfo.d.ts +19 -19
- package/lib/api/getFeatures.d.ts +11 -11
- package/lib/api/getPublicKey.d.ts +6 -6
- package/lib/api/index.d.ts +1 -0
- package/lib/api/index.js +3 -1
- package/lib/api/nem/nemSignTx.d.ts +14 -14
- package/lib/api/rebootToBootloader.d.ts +2 -1
- package/lib/api/rebootToBootloader.js +10 -1
- package/lib/api/recoveryDevice.d.ts +1 -0
- package/lib/api/recoveryDevice.js +3 -0
- package/lib/api/stellar/stellarSignTx.d.ts +1 -1
- package/lib/api/stellar/stellarSignTx.js +6 -0
- package/lib/api/tezos/tezosSignTx.d.ts +18 -18
- package/lib/backend/BackendManager.d.ts +5 -2
- package/lib/backend/BackendManager.js +54 -20
- package/lib/backend/Blockchain.d.ts +8 -8
- package/lib/backend/Blockchain.js +37 -27
- package/lib/constants/index.d.ts +1 -1
- package/lib/constants/index.js +2 -1
- package/lib/core/AbstractMethod.d.ts +4 -4
- package/lib/core/AbstractMethod.js +23 -22
- package/lib/core/index.d.ts +3 -6
- package/lib/core/index.js +73 -52
- package/lib/core/method.d.ts +1 -3
- package/lib/core/method.native.d.ts +1 -3
- package/lib/data/DataManager.d.ts +2 -2
- package/lib/data/analyticsInfo.d.ts +2 -2
- package/lib/data/coinInfo.d.ts +103 -103
- package/lib/data/coinInfo.js +6 -6
- package/lib/data/config.js +1 -1
- package/lib/data/connectSettings.js +3 -0
- package/lib/data/deviceAuthenticityConfig.js +7 -1
- package/lib/data/firmwareInfo.d.ts +1 -1
- package/lib/data/firmwareInfo.js +14 -12
- package/lib/data/version.d.ts +1 -1
- package/lib/data/version.js +1 -1
- package/lib/device/Device.d.ts +7 -6
- package/lib/device/Device.js +13 -11
- package/lib/device/DeviceCommands.d.ts +7 -7
- package/lib/device/DeviceCommands.js +4 -4
- package/lib/device/DeviceList.d.ts +1 -1
- package/lib/device/DeviceList.js +3 -3
- package/lib/events/blockchain.d.ts +10 -2
- package/lib/events/blockchain.js +1 -0
- package/lib/events/call.d.ts +3 -3
- package/lib/events/core.d.ts +12 -10
- package/lib/events/iframe.d.ts +1 -1
- package/lib/events/popup.d.ts +13 -1
- package/lib/events/ui-promise.d.ts +1 -1
- package/lib/events/ui-request.d.ts +1 -2
- package/lib/events/webextension.d.ts +1 -0
- package/lib/events/webextension.js +1 -0
- package/lib/factory.js +1 -0
- package/lib/index.d.ts +0 -4
- package/lib/index.js +23 -40
- package/lib/types/api/applySettings.d.ts +6 -6
- package/lib/types/api/binance/index.d.ts +10 -10
- package/lib/types/api/cardano/index.d.ts +4 -4
- package/lib/types/api/changeLanguage.d.ts +15 -0
- package/lib/types/api/changeLanguage.js +17 -0
- package/lib/types/api/cipherKeyValue.d.ts +2 -2
- package/lib/types/api/eos/index.d.ts +3 -3
- package/lib/types/api/ethereum/index.d.ts +3 -3
- package/lib/types/api/firmwareUpdate.d.ts +1 -1
- package/lib/types/api/getAddress.d.ts +5 -5
- package/lib/types/api/index.d.ts +2 -0
- package/lib/types/api/nem/index.d.ts +7 -7
- package/lib/types/api/rebootToBootloader.d.ts +2 -2
- package/lib/types/api/recoveryDevice.d.ts +1 -1
- package/lib/types/api/stellar/index.d.ts +169 -146
- package/lib/types/api/stellar/index.js +13 -1
- package/lib/types/device.d.ts +4 -1
- package/lib/types/device.js +2 -2
- package/lib/types/firmware.d.ts +2 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/settings.d.ts +1 -0
- package/lib/utils/assets-browser.d.ts +1 -1
- package/lib/utils/assets.d.ts +3 -1
- package/lib/utils/assets.js +2 -2
- package/lib/utils/deviceFeaturesUtils.js +4 -5
- package/lib/utils/firmwareUtils.js +4 -5
- package/lib/utils/hdnodeUtils.d.ts +3 -3
- package/lib/utils/pathUtils.d.ts +3 -3
- package/lib/utils/promiseUtils.d.ts +0 -1
- package/lib/utils/urlUtils.js +3 -3
- 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.
|
|
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
|
-
|
|
29
|
-
onDisconnected: () => this.remove(coinInfo.shortcut),
|
|
27
|
+
onDisconnected: this.onDisconnected.bind(this),
|
|
30
28
|
});
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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.
|
|
63
|
+
this.setPreferred(shortcut, undefined);
|
|
59
64
|
this.custom[shortcut] = blockchainLink;
|
|
60
65
|
}
|
|
61
66
|
removeCustom(shortcut) {
|
|
62
|
-
this.
|
|
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
|
-
|
|
77
|
+
if (!url)
|
|
78
|
+
delete this.preferred[shortcut];
|
|
79
|
+
else
|
|
80
|
+
this.preferred[shortcut] = url;
|
|
67
81
|
}
|
|
68
|
-
|
|
69
|
-
|
|
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 {
|
|
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:
|
|
7
|
+
postMessage: (message: CoreEventMessage) => void;
|
|
8
8
|
proxy?: Proxy;
|
|
9
9
|
debug?: boolean;
|
|
10
|
-
|
|
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
|
-
|
|
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").
|
|
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").
|
|
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
|
|
62
|
-
|
|
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
|
-
|
|
88
|
-
|
|
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)));
|
package/lib/constants/index.d.ts
CHANGED
|
@@ -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
|
|
5
|
+
export { MessagesSchema as PROTO } from '@trezor/protobuf';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/constants/index.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
1
|
+
import { Deferred } from '@trezor/utils';
|
|
2
2
|
import { NETWORK } from '../constants';
|
|
3
|
-
import { CallMethodPayload, CallMethodResponse, UiRequestButtonData, UiPromiseCreator,
|
|
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:
|
|
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
|
|
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
|
|
92
|
+
const originPermissions = this.getOriginPermissions();
|
|
86
93
|
let notPermitted = [...this.requiredPermissions];
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
|
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 =
|
|
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
|
-
|
|
121
|
+
const origin = DataManager_1.DataManager.getSettings('origin');
|
|
122
|
+
connect_common_1.storage.saveForOrigin(state => ({
|
|
122
123
|
...state,
|
|
123
|
-
permissions:
|
|
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);
|
package/lib/core/index.d.ts
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import EventEmitter from 'events';
|
|
3
|
-
import { TransportInfo,
|
|
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:
|
|
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
|