@trezor/connect 9.0.4 → 9.0.6
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 +74 -0
- package/README.md +1 -1
- package/lib/api/binanceGetAddress.d.ts +1 -1
- package/lib/api/binanceSignTransaction.d.ts +1 -1
- package/lib/api/bitcoin/Fees.d.ts +1 -1
- package/lib/api/bitcoin/TransactionComposer.d.ts +1 -1
- package/lib/api/bitcoin/refTx.js +1 -1
- package/lib/api/bitcoin/signtxVerify.d.ts +1 -1
- package/lib/api/blockchainDisconnect.d.ts +1 -1
- package/lib/api/blockchainEstimateFee.d.ts +1 -1
- package/lib/api/blockchainGetAccountBalanceHistory.d.ts +1 -1
- package/lib/api/blockchainGetCurrentFiatRates.d.ts +1 -1
- package/lib/api/blockchainGetFiatRatesForTimestamps.d.ts +1 -1
- package/lib/api/blockchainGetTransactions.d.ts +1 -1
- package/lib/api/blockchainSetCustomBackend.d.ts +1 -1
- package/lib/api/blockchainSubscribe.d.ts +1 -1
- package/lib/api/blockchainSubscribeFiatRates.d.ts +1 -1
- package/lib/api/blockchainUnsubscribe.d.ts +1 -1
- package/lib/api/blockchainUnsubscribeFiatRates.d.ts +1 -1
- package/lib/api/cardano/cardanoCertificate.d.ts +2 -2
- package/lib/api/cardano/cardanoInputs.d.ts +3 -3
- package/lib/api/cardano/cardanoOutputs.d.ts +1 -1
- package/lib/api/cardano/cardanoTokenBundle.d.ts +1 -1
- package/lib/api/cardanoGetAddress.d.ts +1 -1
- package/lib/api/cardanoSignTransaction.d.ts +1 -1
- package/lib/api/checkFirmwareAuthenticity.js +3 -1
- package/lib/api/common/Discovery.d.ts +2 -2
- package/lib/api/common/paramsValidator.d.ts +2 -2
- package/lib/api/composeTransaction.d.ts +1 -1
- package/lib/api/eos/eosSignTx.js +1 -1
- package/lib/api/eosSignTransaction.d.ts +1 -1
- package/lib/api/ethereumGetAddress.d.ts +1 -1
- package/lib/api/ethereumGetPublicKey.d.ts +1 -1
- package/lib/api/ethereumSignTransaction.d.ts +1 -1
- package/lib/api/ethereumSignTypedData.d.ts +1 -1
- package/lib/api/firmware/uploadFirmware.d.ts +2 -2
- package/lib/api/firmwareUpdate.d.ts +1 -1
- package/lib/api/firmwareUpdate.js +1 -1
- package/lib/api/getAccountInfo.d.ts +1 -1
- package/lib/api/getAddress.d.ts +1 -1
- package/lib/api/getCoinInfo.d.ts +2 -2
- package/lib/api/getPublicKey.d.ts +1 -1
- package/lib/api/nemGetAddress.d.ts +1 -1
- package/lib/api/pushTransaction.d.ts +1 -1
- package/lib/api/rippleGetAddress.d.ts +1 -1
- package/lib/api/setBusy.js +5 -1
- package/lib/api/setProxy.js +3 -4
- package/lib/api/signTransaction.d.ts +3 -1
- package/lib/api/signTransaction.js +41 -38
- package/lib/api/stellarGetAddress.d.ts +1 -1
- package/lib/api/stellarSignTransaction.d.ts +1 -1
- package/lib/api/tezosGetAddress.d.ts +1 -1
- package/lib/backend/BackendManager.d.ts +1 -1
- package/lib/backend/BackendManager.js +0 -4
- package/lib/backend/Blockchain.d.ts +3 -9
- package/lib/backend/Blockchain.js +2 -17
- package/lib/constants/network.d.ts +1 -1
- package/lib/core/AbstractMethod.d.ts +4 -4
- package/lib/core/AbstractMethod.js +7 -5
- package/lib/core/index.d.ts +1 -1
- package/lib/core/index.js +9 -5
- package/lib/data/DataManager.d.ts +1 -1
- package/lib/data/analyticsInfo.d.ts +6 -0
- package/lib/data/analyticsInfo.js +37 -0
- package/lib/data/config.js +2 -5
- package/lib/data/version.d.ts +1 -1
- package/lib/data/version.js +1 -1
- package/lib/device/AbortController.d.ts +1 -1
- package/lib/device/DescriptorStream.d.ts +1 -1
- package/lib/device/Device.d.ts +3 -3
- package/lib/device/Device.js +13 -6
- package/lib/device/DeviceCommands.d.ts +7 -7
- package/lib/device/DeviceCommands.js +3 -1
- package/lib/device/DeviceList.d.ts +2 -2
- package/lib/device/DeviceList.js +2 -2
- package/lib/events/blockchain.d.ts +4 -5
- package/lib/events/call.d.ts +10 -10
- package/lib/events/core.d.ts +3 -2
- package/lib/events/device.d.ts +3 -3
- package/lib/events/iframe.d.ts +2 -2
- package/lib/events/popup.d.ts +2 -2
- package/lib/events/transport.d.ts +8 -4
- package/lib/events/transport.js +1 -1
- package/lib/events/ui-promise.d.ts +2 -2
- package/lib/events/ui-request.d.ts +9 -7
- package/lib/events/ui-response.d.ts +2 -2
- package/lib/factory.d.ts +2 -1
- package/lib/factory.js +2 -1
- package/lib/index-browser.js +1 -0
- package/lib/index.js +6 -2
- package/lib/types/account.d.ts +2 -2
- package/lib/types/api/binance/index.d.ts +1 -1
- package/lib/types/api/bitcoin/index.d.ts +2 -2
- package/lib/types/api/blockchainGetTransactions.d.ts +1 -1
- package/lib/types/api/blockchainSetCustomBackend.d.ts +1 -1
- package/lib/types/api/blockchainSubscribe.d.ts +1 -1
- package/lib/types/api/blockchainSubscribeFiatRates.d.ts +1 -1
- package/lib/types/api/cardano/index.d.ts +2 -2
- package/lib/types/api/composeTransaction.d.ts +3 -3
- package/lib/types/api/dispose.d.ts +1 -1
- package/lib/types/api/eos/index.d.ts +1 -1
- package/lib/types/api/getAddress.d.ts +1 -1
- package/lib/types/api/index.d.ts +2 -0
- package/lib/types/api/nem/index.d.ts +9 -9
- package/lib/types/api/off.d.ts +2 -2
- package/lib/types/api/on.d.ts +2 -2
- package/lib/types/api/pushTransaction.d.ts +1 -1
- package/lib/types/api/requestWebUSBDevice.d.ts +2 -0
- package/lib/types/api/requestWebUSBDevice.js +3 -0
- package/lib/types/api/setProxy.d.ts +1 -2
- package/lib/types/api/stellar/index.d.ts +2 -2
- package/lib/types/coinInfo.d.ts +3 -3
- package/lib/types/device.d.ts +13 -13
- package/lib/types/firmware.d.ts +3 -3
- package/lib/types/params.d.ts +3 -3
- package/lib/types/settings.d.ts +1 -2
- package/lib/types/utils.d.ts +2 -2
- package/lib/utils/accountUtils.d.ts +1 -1
- package/lib/utils/browserUtils.d.ts +2 -2
- package/lib/utils/debug.d.ts +1 -1
- package/lib/utils/deferred.d.ts +2 -2
- package/lib/utils/interactionTimeout.d.ts +1 -1
- package/lib/workers/RNUsbPlugin.d.ts +1 -1
- package/lib/workers/workers.d.ts +1 -1
- package/package.json +84 -80
|
@@ -85,46 +85,49 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
|
85
85
|
};
|
|
86
86
|
this.params.options = (0, bitcoin_1.enhanceSignTx)(this.params.options, coinInfo);
|
|
87
87
|
}
|
|
88
|
-
async
|
|
89
|
-
const { device, params } = this;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const requiredRefTxs = (0, bitcoin_1.requireReferencedTransactions)(params.inputs, params.options, params.coinInfo);
|
|
94
|
-
const refTxsIds = (0, bitcoin_1.getReferencedTransactions)(params.inputs);
|
|
95
|
-
if (requiredRefTxs && refTxsIds.length > 0) {
|
|
96
|
-
(0, BlockchainLink_1.isBackendSupported)(params.coinInfo);
|
|
97
|
-
const blockchain = await (0, BlockchainLink_1.initBlockchain)(params.coinInfo, this.postMessage);
|
|
98
|
-
const rawTxs = await blockchain.getTransactions(refTxsIds);
|
|
99
|
-
(0, bitcoin_1.enhanceTrezorInputs)(this.params.inputs, rawTxs);
|
|
100
|
-
refTxs = (0, bitcoin_1.transformReferencedTransactions)(rawTxs, params.coinInfo);
|
|
101
|
-
const origTxsIds = (0, bitcoin_1.getOrigTransactions)(params.inputs, params.outputs);
|
|
102
|
-
if (!useLegacySignProcess && origTxsIds.length > 0) {
|
|
103
|
-
const rawOrigTxs = await blockchain.getTransactions(origTxsIds);
|
|
104
|
-
let { addresses } = params;
|
|
105
|
-
if (!addresses) {
|
|
106
|
-
const accountPath = params.inputs.find(i => i.address_n);
|
|
107
|
-
if (!accountPath || !accountPath.address_n) {
|
|
108
|
-
throw constants_1.ERRORS.TypedError('Runtime', 'Account not found');
|
|
109
|
-
}
|
|
110
|
-
const address_n = accountPath.address_n.slice(0, 3);
|
|
111
|
-
const node = await device
|
|
112
|
-
.getCommands()
|
|
113
|
-
.getHDNode({ address_n }, { coinInfo: params.coinInfo });
|
|
114
|
-
const account = await blockchain.getAccountInfo({
|
|
115
|
-
descriptor: node.xpubSegwit || node.xpub,
|
|
116
|
-
details: 'tokens',
|
|
117
|
-
});
|
|
118
|
-
addresses = account.addresses;
|
|
119
|
-
}
|
|
120
|
-
const origRefTxs = (0, bitcoin_1.transformOrigTransactions)(rawOrigTxs, params.coinInfo, addresses);
|
|
121
|
-
refTxs = refTxs.concat(origRefTxs);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
88
|
+
async fetchAddresses(blockchain) {
|
|
89
|
+
const { device, params: { inputs, coinInfo }, } = this;
|
|
90
|
+
const accountPath = inputs.find(i => i.address_n);
|
|
91
|
+
if (!accountPath || !accountPath.address_n) {
|
|
92
|
+
throw constants_1.ERRORS.TypedError('Runtime', 'Account not found');
|
|
124
93
|
}
|
|
125
|
-
|
|
126
|
-
|
|
94
|
+
const address_n = accountPath.address_n.slice(0, 3);
|
|
95
|
+
const node = await device.getCommands().getHDNode({ address_n }, { coinInfo });
|
|
96
|
+
const account = await blockchain.getAccountInfo({
|
|
97
|
+
descriptor: node.xpubSegwit || node.xpub,
|
|
98
|
+
details: 'tokens',
|
|
99
|
+
});
|
|
100
|
+
return account.addresses;
|
|
101
|
+
}
|
|
102
|
+
async fetchRefTxs(useLegacySignProcess) {
|
|
103
|
+
const { params: { inputs, outputs, options, coinInfo, addresses }, } = this;
|
|
104
|
+
const requiredRefTxs = (0, bitcoin_1.requireReferencedTransactions)(inputs, options, coinInfo);
|
|
105
|
+
const refTxsIds = requiredRefTxs ? (0, bitcoin_1.getReferencedTransactions)(inputs) : [];
|
|
106
|
+
const origTxsIds = !useLegacySignProcess ? (0, bitcoin_1.getOrigTransactions)(inputs, outputs) : [];
|
|
107
|
+
if (!refTxsIds.length && !origTxsIds.length) {
|
|
108
|
+
return [];
|
|
127
109
|
}
|
|
110
|
+
(0, BlockchainLink_1.isBackendSupported)(coinInfo);
|
|
111
|
+
const blockchain = await (0, BlockchainLink_1.initBlockchain)(coinInfo, this.postMessage);
|
|
112
|
+
const refTxs = !refTxsIds.length
|
|
113
|
+
? []
|
|
114
|
+
: await blockchain.getTransactions(refTxsIds).then(rawTxs => {
|
|
115
|
+
(0, bitcoin_1.enhanceTrezorInputs)(this.params.inputs, rawTxs);
|
|
116
|
+
return (0, bitcoin_1.transformReferencedTransactions)(rawTxs, coinInfo);
|
|
117
|
+
});
|
|
118
|
+
const origTxs = !origTxsIds.length
|
|
119
|
+
? []
|
|
120
|
+
: await blockchain.getTransactions(origTxsIds).then(async (rawOrigTxs) => {
|
|
121
|
+
const accountAddresses = addresses !== null && addresses !== void 0 ? addresses : (await this.fetchAddresses(blockchain));
|
|
122
|
+
return (0, bitcoin_1.transformOrigTransactions)(rawOrigTxs, coinInfo, accountAddresses);
|
|
123
|
+
});
|
|
124
|
+
return refTxs.concat(origTxs);
|
|
125
|
+
}
|
|
126
|
+
async run() {
|
|
127
|
+
var _a;
|
|
128
|
+
const { device, params } = this;
|
|
129
|
+
const useLegacySignProcess = !!device.unavailableCapabilities.replaceTransaction;
|
|
130
|
+
const refTxs = (_a = params.refTxs) !== null && _a !== void 0 ? _a : (await this.fetchRefTxs(useLegacySignProcess));
|
|
128
131
|
if (this.preauthorized) {
|
|
129
132
|
await device.getCommands().preauthorize(true);
|
|
130
133
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AbstractMethod } from '../core/AbstractMethod';
|
|
2
2
|
import { PROTO } from '../constants';
|
|
3
|
-
|
|
3
|
+
type Params = PROTO.StellarGetAddress & {
|
|
4
4
|
address?: string;
|
|
5
5
|
};
|
|
6
6
|
export default class StellarGetAddress extends AbstractMethod<'stellarGetAddress', Params[]> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AbstractMethod } from '../core/AbstractMethod';
|
|
2
2
|
import { PROTO } from '../constants';
|
|
3
|
-
|
|
3
|
+
type Params = PROTO.TezosGetAddress & {
|
|
4
4
|
address?: string;
|
|
5
5
|
};
|
|
6
6
|
export default class TezosGetAddress extends AbstractMethod<'tezosGetAddress', Params[]> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Blockchain, BlockchainOptions } from './Blockchain';
|
|
2
2
|
import type { CoinInfo, BlockchainLink } from '../types';
|
|
3
|
-
|
|
3
|
+
type CoinShortcut = CoinInfo['shortcut'];
|
|
4
4
|
export declare class BackendManager {
|
|
5
5
|
private readonly instances;
|
|
6
6
|
private readonly custom;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BackendManager = void 0;
|
|
4
|
-
const config_1 = require("../data/config");
|
|
5
4
|
const DataManager_1 = require("../data/DataManager");
|
|
6
5
|
const constants_1 = require("../constants");
|
|
7
6
|
const Blockchain_1 = require("./Blockchain");
|
|
@@ -26,9 +25,6 @@ class BackendManager {
|
|
|
26
25
|
postMessage,
|
|
27
26
|
debug: DataManager_1.DataManager.getSettings('debug'),
|
|
28
27
|
proxy: DataManager_1.DataManager.getSettings('proxy'),
|
|
29
|
-
onionDomains: DataManager_1.DataManager.getSettings('useOnionLinks') && !this.custom[coinInfo.shortcut]
|
|
30
|
-
? config_1.config.onionDomains
|
|
31
|
-
: undefined,
|
|
32
28
|
onConnected: url => this.setPreferred(coinInfo.shortcut, url),
|
|
33
29
|
onDisconnected: () => this.remove(coinInfo.shortcut),
|
|
34
30
|
});
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import BlockchainLink, { ServerInfo, SubscriptionAccountInfo, BlockchainLinkParams, BlockchainLinkResponse } from '@trezor/blockchain-link';
|
|
2
|
+
import { PostMessage } from '../events';
|
|
2
3
|
import { ERRORS } from '../constants';
|
|
3
4
|
import type { CoinInfo, Proxy } from '../types';
|
|
4
|
-
|
|
5
|
-
export declare type BlockchainOptions = {
|
|
5
|
+
export type BlockchainOptions = {
|
|
6
6
|
coinInfo: CoinInfo;
|
|
7
|
-
postMessage:
|
|
7
|
+
postMessage: PostMessage;
|
|
8
8
|
proxy?: Proxy;
|
|
9
|
-
onionDomains?: {
|
|
10
|
-
[domain: string]: string;
|
|
11
|
-
};
|
|
12
9
|
debug?: boolean;
|
|
13
10
|
onConnected?: (url: string) => void;
|
|
14
11
|
onDisconnected?: () => void;
|
|
@@ -17,9 +14,6 @@ export declare class Blockchain {
|
|
|
17
14
|
link: BlockchainLink;
|
|
18
15
|
serverInfo?: ServerInfo;
|
|
19
16
|
coinInfo: BlockchainOptions['coinInfo'];
|
|
20
|
-
onionDomains: {
|
|
21
|
-
[onion: string]: string;
|
|
22
|
-
};
|
|
23
17
|
postMessage: BlockchainOptions['postMessage'];
|
|
24
18
|
feeForBlock: BlockchainLinkResponse<'estimateFee'>;
|
|
25
19
|
feeTimestamp: number;
|
|
@@ -5,7 +5,6 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const blockchain_link_1 = tslib_1.__importDefault(require("@trezor/blockchain-link"));
|
|
6
6
|
const events_1 = require("../events");
|
|
7
7
|
const constants_1 = require("../constants");
|
|
8
|
-
const urlUtils_1 = require("../utils/urlUtils");
|
|
9
8
|
const workers_1 = require("../workers/workers");
|
|
10
9
|
const getWorker = (type) => {
|
|
11
10
|
switch (type) {
|
|
@@ -37,19 +36,7 @@ class Blockchain {
|
|
|
37
36
|
if (!worker) {
|
|
38
37
|
throw constants_1.ERRORS.TypedError('Backend_WorkerMissing', `BlockchainLink worker not found ${blockchainLink.type}`);
|
|
39
38
|
}
|
|
40
|
-
const
|
|
41
|
-
this.onionDomains = onionDomains
|
|
42
|
-
? blockchainLink.url.reduce((a, url) => {
|
|
43
|
-
const onion = (0, urlUtils_1.getOnionDomain)(url, onionDomains);
|
|
44
|
-
if (onion !== url) {
|
|
45
|
-
a[onion] = url;
|
|
46
|
-
}
|
|
47
|
-
return a;
|
|
48
|
-
}, {})
|
|
49
|
-
: {};
|
|
50
|
-
const server = Object.keys(this.onionDomains).length
|
|
51
|
-
? Object.keys(this.onionDomains)
|
|
52
|
-
: blockchainLink.url;
|
|
39
|
+
const server = blockchainLink.url;
|
|
53
40
|
this.link = new blockchain_link_1.default({
|
|
54
41
|
name: this.coinInfo.shortcut,
|
|
55
42
|
worker,
|
|
@@ -78,12 +65,10 @@ class Blockchain {
|
|
|
78
65
|
this.onError(constants_1.ERRORS.TypedError('Backend_Invalid'));
|
|
79
66
|
return;
|
|
80
67
|
}
|
|
81
|
-
|
|
82
|
-
(_a = this.onConnected) === null || _a === void 0 ? void 0 : _a.call(this, cleanUrl || info.url);
|
|
68
|
+
(_a = this.onConnected) === null || _a === void 0 ? void 0 : _a.call(this, info.url);
|
|
83
69
|
this.postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.CONNECT, {
|
|
84
70
|
coin: this.coinInfo,
|
|
85
71
|
...info,
|
|
86
|
-
cleanUrl,
|
|
87
72
|
}));
|
|
88
73
|
});
|
|
89
74
|
this.link.on('disconnected', () => {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { NETWORK } from '../constants';
|
|
2
|
-
import { CallMethodPayload, CallMethodResponse,
|
|
2
|
+
import { CallMethodPayload, CallMethodResponse, UiRequestButtonData, UiPromise, UiPromiseResponse, PostMessage } from '../events';
|
|
3
3
|
import { Deferred } from '../utils/deferred';
|
|
4
4
|
import type { Device } from '../device/Device';
|
|
5
5
|
import type { FirmwareRange } from '../types';
|
|
6
|
-
export
|
|
6
|
+
export type Payload<M> = Extract<CallMethodPayload, {
|
|
7
7
|
method: M;
|
|
8
8
|
}> & {
|
|
9
9
|
override?: boolean;
|
|
10
10
|
};
|
|
11
|
-
export
|
|
11
|
+
export type MethodReturnType<M extends CallMethodPayload['method']> = CallMethodResponse<M>;
|
|
12
12
|
export declare abstract class AbstractMethod<Name extends CallMethodPayload['method'], Params = undefined> {
|
|
13
13
|
responseID: number;
|
|
14
14
|
device: Device;
|
|
@@ -39,7 +39,7 @@ export declare abstract class AbstractMethod<Name extends CallMethodPayload['met
|
|
|
39
39
|
confirmation?(): Promise<boolean | undefined>;
|
|
40
40
|
noBackupConfirmation?(): Promise<boolean>;
|
|
41
41
|
getButtonRequestData?(code: string): UiRequestButtonData | undefined;
|
|
42
|
-
postMessage:
|
|
42
|
+
postMessage: PostMessage;
|
|
43
43
|
getPopupPromise: () => Deferred<void>;
|
|
44
44
|
createUiPromise: <T extends UiPromiseResponse['type']>(promiseId: T, device?: Device) => UiPromise<T>;
|
|
45
45
|
removeUiPromise: (promise: Deferred<any>) => void;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AbstractMethod = void 0;
|
|
4
|
-
const
|
|
5
|
-
const storage = tslib_1.__importStar(require("@trezor/connect-common/lib/storage"));
|
|
4
|
+
const connect_common_1 = require("@trezor/connect-common");
|
|
6
5
|
const DataManager_1 = require("../data/DataManager");
|
|
7
6
|
const constants_1 = require("../constants");
|
|
8
7
|
const events_1 = require("../events");
|
|
@@ -77,7 +76,7 @@ class AbstractMethod {
|
|
|
77
76
|
return false;
|
|
78
77
|
}
|
|
79
78
|
checkPermissions() {
|
|
80
|
-
const savedPermissions = storage.load(
|
|
79
|
+
const savedPermissions = connect_common_1.storage.load().permissions;
|
|
81
80
|
let notPermitted = [...this.requiredPermissions];
|
|
82
81
|
if (savedPermissions) {
|
|
83
82
|
const originPermissions = savedPermissions.filter(p => p.origin === DataManager_1.DataManager.getSettings('origin'));
|
|
@@ -91,7 +90,7 @@ class AbstractMethod {
|
|
|
91
90
|
this.requiredPermissions = notPermitted;
|
|
92
91
|
}
|
|
93
92
|
savePermissions(temporary = false) {
|
|
94
|
-
const savedPermissions = storage.load(
|
|
93
|
+
const savedPermissions = connect_common_1.storage.load(temporary).permissions || [];
|
|
95
94
|
let permissionsToSave = this.requiredPermissions.map(p => ({
|
|
96
95
|
origin: DataManager_1.DataManager.getSettings('origin'),
|
|
97
96
|
type: p,
|
|
@@ -113,7 +112,10 @@ class AbstractMethod {
|
|
|
113
112
|
return !granted;
|
|
114
113
|
});
|
|
115
114
|
}
|
|
116
|
-
storage.save(
|
|
115
|
+
connect_common_1.storage.save(state => ({
|
|
116
|
+
...state,
|
|
117
|
+
permissions: savedPermissions.concat(permissionsToSave),
|
|
118
|
+
}), temporary);
|
|
117
119
|
if (emitEvent) {
|
|
118
120
|
this.postMessage((0, events_1.createDeviceMessage)(events_1.DEVICE.CONNECT, this.device.toMessageObject()));
|
|
119
121
|
}
|
package/lib/core/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const handleMessage: (message: CoreMessage, isTrustedOrigin?: boo
|
|
|
6
6
|
export declare const onCall: (message: CoreMessage) => Promise<void>;
|
|
7
7
|
export declare class Core extends EventEmitter {
|
|
8
8
|
handleMessage(message: any, isTrustedOrigin: boolean): void;
|
|
9
|
-
dispose(): void
|
|
9
|
+
dispose(): Promise<void>;
|
|
10
10
|
getCurrentMethod(): (import("../api").applyFlags | import("../api").applySettings | import("../api").authorizeCoinJoin | import("../api").backupDevice | import("../api").binanceGetAddress | import("../api").binanceGetPublicKey | import("../api").binanceSignTransaction | import("../api").blockchainDisconnect | import("../api").blockchainEstimateFee | import("../api").blockchainGetAccountBalanceHistory | import("../api").blockchainGetCurrentFiatRates | import("../api").blockchainGetFiatRatesForTimestamps | import("../api").blockchainGetTransactions | import("../api").blockchainSetCustomBackend | import("../api").blockchainSubscribe | import("../api").blockchainSubscribeFiatRates | import("../api").blockchainUnsubscribe | import("../api").blockchainUnsubscribeFiatRates | import("../api").cardanoGetAddress | import("../api").cardanoGetNativeScriptHash | import("../api").cardanoGetPublicKey | import("../api").cardanoSignTransaction | import("../api").changePin | import("../api").cipherKeyValue | import("../api").composeTransaction | import("../api").eosGetPublicKey | import("../api").eosSignTransaction | import("../api").ethereumGetAddress | import("../api").ethereumGetPublicKey | import("../api").ethereumSignMessage | import("../api").ethereumSignTransaction | import("../api").ethereumSignTypedData | import("../api").ethereumVerifyMessage | import("../api").firmwareUpdate | import("../api").getAccountInfo | import("../api").getAddress | import("../api").getCoinInfo | import("../api").getDeviceState | import("../api").getFeatures | import("../api").getFirmwareHash | import("../api").getOwnershipId | import("../api").getOwnershipProof | import("../api").getPublicKey | import("../api").getSettings | import("../api").nemGetAddress | import("../api").nemSignTransaction | import("../api").pushTransaction | import("../api").rebootToBootloader | import("../api").recoveryDevice | import("../api").requestLogin | import("../api").resetDevice | import("../api").rippleGetAddress | import("../api").rippleSignTransaction | import("../api").setBusy | import("../api").setProxy | import("../api").signMessage | import("../api").signTransaction | import("../api").stellarGetAddress | import("../api").stellarSignTransaction | import("../api").tezosGetAddress | import("../api").tezosGetPublicKey | import("../api").tezosSignTransaction | import("../api").unlockPath | import("../api").verifyMessage | import("../api").wipeDevice | import("../api").checkFirmwareAuthenticity)[];
|
|
11
11
|
getTransportInfo(): TransportInfo;
|
|
12
12
|
}
|
package/lib/core/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const events_1 = tslib_1.__importDefault(require("events"));
|
|
6
6
|
const DataManager_1 = require("../data/DataManager");
|
|
7
7
|
const DeviceList_1 = require("../device/DeviceList");
|
|
8
|
+
const analyticsInfo_1 = require("../data/analyticsInfo");
|
|
8
9
|
const constants_1 = require("../constants");
|
|
9
10
|
const events_2 = require("../events");
|
|
10
11
|
const method_1 = require("./method");
|
|
@@ -73,6 +74,8 @@ const handleMessage = (message, isTrustedOrigin = false) => {
|
|
|
73
74
|
case events_2.TRANSPORT.DISABLE_WEBUSB:
|
|
74
75
|
disableWebUSBTransport();
|
|
75
76
|
break;
|
|
77
|
+
case events_2.TRANSPORT.REQUEST_DEVICE:
|
|
78
|
+
break;
|
|
76
79
|
case events_2.UI.RECEIVE_DEVICE:
|
|
77
80
|
case events_2.UI.RECEIVE_CONFIRMATION:
|
|
78
81
|
case events_2.UI.RECEIVE_PERMISSION:
|
|
@@ -216,6 +219,7 @@ const onCall = async (message) => {
|
|
|
216
219
|
postMessage((0, events_2.createResponseMessage)(responseID, false, { error }));
|
|
217
220
|
throw error;
|
|
218
221
|
}
|
|
222
|
+
method.postMessage = (message) => (0, analyticsInfo_1.enhancePostMessageWithAnalytics)(postMessage, message, { device: device.toMessageObject() });
|
|
219
223
|
method.setDevice(device);
|
|
220
224
|
const previousCall = _callMethods.filter(call => call && call !== method && call.devicePath === method.devicePath);
|
|
221
225
|
if (previousCall.length > 0 && method.overridePreviousCall) {
|
|
@@ -585,12 +589,12 @@ class Core extends events_1.default {
|
|
|
585
589
|
handleMessage(message, isTrustedOrigin) {
|
|
586
590
|
(0, exports.handleMessage)(message, isTrustedOrigin);
|
|
587
591
|
}
|
|
588
|
-
dispose() {
|
|
589
|
-
if (_deviceList) {
|
|
590
|
-
_deviceList.dispose();
|
|
591
|
-
}
|
|
592
|
+
async dispose() {
|
|
592
593
|
(0, BlockchainLink_1.dispose)();
|
|
593
594
|
this.removeAllListeners();
|
|
595
|
+
if (_deviceList) {
|
|
596
|
+
await _deviceList.dispose();
|
|
597
|
+
}
|
|
594
598
|
}
|
|
595
599
|
getCurrentMethod() {
|
|
596
600
|
return _callMethods;
|
|
@@ -649,7 +653,7 @@ const disableWebUSBTransport = async () => {
|
|
|
649
653
|
const settings = DataManager_1.DataManager.getSettings();
|
|
650
654
|
settings.webusb = false;
|
|
651
655
|
try {
|
|
652
|
-
_deviceList.dispose();
|
|
656
|
+
await _deviceList.dispose();
|
|
653
657
|
await initDeviceList(settings);
|
|
654
658
|
}
|
|
655
659
|
catch (error) {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CoreMessage, PostMessage } from '../events';
|
|
2
|
+
import type { Device } from '../types';
|
|
3
|
+
export declare const enhancePostMessageWithAnalytics: (callback: PostMessage, message: CoreMessage, data: {
|
|
4
|
+
device?: Device;
|
|
5
|
+
}) => void;
|
|
6
|
+
//# sourceMappingURL=analyticsInfo.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enhancePostMessageWithAnalytics = void 0;
|
|
4
|
+
const events_1 = require("../events");
|
|
5
|
+
const enhancePostMessageWithAnalytics = (callback, message, data) => {
|
|
6
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
7
|
+
switch (message.type) {
|
|
8
|
+
case events_1.UI_REQUEST.REQUEST_CONFIRMATION:
|
|
9
|
+
const { device } = data;
|
|
10
|
+
callback({
|
|
11
|
+
...message,
|
|
12
|
+
payload: {
|
|
13
|
+
...message.payload,
|
|
14
|
+
analytics: {
|
|
15
|
+
type: 'device/selected',
|
|
16
|
+
payload: {
|
|
17
|
+
mode: (device === null || device === void 0 ? void 0 : device.mode) || '',
|
|
18
|
+
pinProtection: ((_a = device === null || device === void 0 ? void 0 : device.features) === null || _a === void 0 ? void 0 : _a.pin_protection) || '',
|
|
19
|
+
passphraseProtection: ((_b = device === null || device === void 0 ? void 0 : device.features) === null || _b === void 0 ? void 0 : _b.passphrase_protection) || '',
|
|
20
|
+
backupType: ((_c = device === null || device === void 0 ? void 0 : device.features) === null || _c === void 0 ? void 0 : _c.backup_type) || 'Bip39',
|
|
21
|
+
language: ((_d = device === null || device === void 0 ? void 0 : device.features) === null || _d === void 0 ? void 0 : _d.language) || '',
|
|
22
|
+
model: ((_e = device === null || device === void 0 ? void 0 : device.features) === null || _e === void 0 ? void 0 : _e.model) || '',
|
|
23
|
+
vendor: ((_f = device === null || device === void 0 ? void 0 : device.features) === null || _f === void 0 ? void 0 : _f.vendor) || '',
|
|
24
|
+
firmwareRevision: ((_g = device === null || device === void 0 ? void 0 : device.features) === null || _g === void 0 ? void 0 : _g.revision) || '',
|
|
25
|
+
firmwareType: (device === null || device === void 0 ? void 0 : device.firmwareType) || '',
|
|
26
|
+
bootloaderHash: ((_h = device === null || device === void 0 ? void 0 : device.features) === null || _h === void 0 ? void 0 : _h.bootloader_hash) || '',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
break;
|
|
32
|
+
default:
|
|
33
|
+
callback(message);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.enhancePostMessageWithAnalytics = enhancePostMessageWithAnalytics;
|
|
37
|
+
//# sourceMappingURL=analyticsInfo.js.map
|
package/lib/data/config.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.config = void 0;
|
|
4
|
+
const transport_1 = require("@trezor/transport");
|
|
4
5
|
exports.config = {
|
|
5
|
-
webusb:
|
|
6
|
-
{ vendorId: 0x534c, productId: 0x0001 },
|
|
7
|
-
{ vendorId: 0x1209, productId: 0x53c0 },
|
|
8
|
-
{ vendorId: 0x1209, productId: 0x53c1 },
|
|
9
|
-
],
|
|
6
|
+
webusb: transport_1.TREZOR_DESCS,
|
|
10
7
|
whitelist: [
|
|
11
8
|
{ origin: 'chrome-extension://imloifkgjagghnncjkhggdhalmcnfklk', priority: 1 },
|
|
12
9
|
{ origin: 'chrome-extension://niebkpllfhmpfbffbfifagfgoamhpflf', priority: 1 },
|
package/lib/data/version.d.ts
CHANGED
package/lib/data/version.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_DOMAIN = exports.VERSION = void 0;
|
|
4
|
-
exports.VERSION = '9.0.
|
|
4
|
+
exports.VERSION = '9.0.6';
|
|
5
5
|
const versionN = exports.VERSION.split('.').map(s => parseInt(s, 10));
|
|
6
6
|
exports.DEFAULT_DOMAIN = `https://connect.trezor.io/${versionN[0]}/`;
|
|
7
7
|
//# sourceMappingURL=version.js.map
|
|
@@ -15,7 +15,7 @@ declare class AbortControllerFallback {
|
|
|
15
15
|
abort(): void;
|
|
16
16
|
toString(): string;
|
|
17
17
|
}
|
|
18
|
-
export
|
|
18
|
+
export type Controller = AbortController | AbortControllerFallback;
|
|
19
19
|
export declare const getAbortController: () => AbortControllerFallback | AbortController;
|
|
20
20
|
export {};
|
|
21
21
|
//# sourceMappingURL=AbortController.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import EventEmitter from 'events';
|
|
3
3
|
import type { Transport, TrezorDeviceInfoWithSession as DeviceDescriptor } from '@trezor/transport';
|
|
4
|
-
export
|
|
4
|
+
export type DeviceDescriptorDiff = {
|
|
5
5
|
didUpdate: boolean;
|
|
6
6
|
connected: DeviceDescriptor[];
|
|
7
7
|
disconnected: DeviceDescriptor[];
|
package/lib/device/Device.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { DEVICE, DeviceButtonRequestPayload } from '../events';
|
|
|
6
6
|
import { Deferred } from '../utils/deferred';
|
|
7
7
|
import type { Transport, TrezorDeviceInfoWithSession as DeviceDescriptor } from '@trezor/transport';
|
|
8
8
|
import type { Device as DeviceTyped, DeviceFirmwareStatus, Features, ReleaseInfo, UnavailableCapabilities } from '../types';
|
|
9
|
-
export
|
|
9
|
+
export type RunOptions = {
|
|
10
10
|
skipFinalReload?: boolean;
|
|
11
11
|
waiting?: boolean;
|
|
12
12
|
onlyOneActivity?: boolean;
|
|
@@ -44,7 +44,7 @@ export declare class Device extends EventEmitter {
|
|
|
44
44
|
inconsistent: boolean;
|
|
45
45
|
firstRunPromise: Deferred<boolean>;
|
|
46
46
|
activitySessionID?: string | null;
|
|
47
|
-
commands
|
|
47
|
+
commands?: DeviceCommands;
|
|
48
48
|
keepSession: boolean;
|
|
49
49
|
instance: number;
|
|
50
50
|
internalState: string[];
|
|
@@ -93,7 +93,7 @@ export declare class Device extends EventEmitter {
|
|
|
93
93
|
getDevicePath(): string;
|
|
94
94
|
isT1(): boolean;
|
|
95
95
|
hasUnexpectedMode(allow: string[], require: string[]): "ui-device_bootloader_mode" | "ui-device_not_in_bootloader_mode" | "ui-device_not_initialized" | "ui-device_seedless" | null;
|
|
96
|
-
dispose(): void;
|
|
96
|
+
dispose(): Promise<void> | undefined;
|
|
97
97
|
getMode(): "normal" | "bootloader" | "initialize" | "seedless";
|
|
98
98
|
toMessageObject(): DeviceTyped;
|
|
99
99
|
_getNetworkTypeState(): "bitcoin" | "ethereum" | "nem" | "eos" | "stellar" | "cardano" | "ripple" | "tezos" | "binance";
|
package/lib/device/Device.js
CHANGED
|
@@ -152,7 +152,8 @@ class Device extends events_1.default {
|
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
async _runInner(fn, options) {
|
|
155
|
-
|
|
155
|
+
var _a;
|
|
156
|
+
if (!this.isUsedHere() || ((_a = this.commands) === null || _a === void 0 ? void 0 : _a.disposed) || !this.getExternalState()) {
|
|
156
157
|
await this.acquire();
|
|
157
158
|
try {
|
|
158
159
|
if (fn) {
|
|
@@ -201,6 +202,9 @@ class Device extends events_1.default {
|
|
|
201
202
|
}
|
|
202
203
|
}
|
|
203
204
|
getCommands() {
|
|
205
|
+
if (!this.commands) {
|
|
206
|
+
throw constants_1.ERRORS.TypedError('Runtime', `Device: commands not defined`);
|
|
207
|
+
}
|
|
204
208
|
return this.commands;
|
|
205
209
|
}
|
|
206
210
|
setInstance(instance = 0) {
|
|
@@ -245,13 +249,13 @@ class Device extends events_1.default {
|
|
|
245
249
|
if (!this.features)
|
|
246
250
|
return;
|
|
247
251
|
if (!this.features.unlocked && preauthorized) {
|
|
248
|
-
if (await this.
|
|
252
|
+
if (await this.getCommands().preauthorize(false)) {
|
|
249
253
|
return;
|
|
250
254
|
}
|
|
251
255
|
}
|
|
252
256
|
const altMode = this._altModeChange(networkType);
|
|
253
257
|
const expectedState = altMode ? undefined : this.getExternalState();
|
|
254
|
-
const state = await this.
|
|
258
|
+
const state = await this.getCommands().getDeviceState(networkType);
|
|
255
259
|
const uniqueState = `${state}@${this.features.device_id || 'device_id'}:${this.instance}`;
|
|
256
260
|
if (!this.useLegacyPassphrase() && this.features.session_id) {
|
|
257
261
|
this.setInternalState(this.features.session_id);
|
|
@@ -284,11 +288,11 @@ class Device extends events_1.default {
|
|
|
284
288
|
}
|
|
285
289
|
}
|
|
286
290
|
}
|
|
287
|
-
const { message } = await this.
|
|
291
|
+
const { message } = await this.getCommands().typedCall('Initialize', 'Features', payload);
|
|
288
292
|
this._updateFeatures(message);
|
|
289
293
|
}
|
|
290
294
|
async getFeatures() {
|
|
291
|
-
const { message } = await this.
|
|
295
|
+
const { message } = await this.getCommands().typedCall('GetFeatures', 'Features', {});
|
|
292
296
|
this._updateFeatures(message);
|
|
293
297
|
}
|
|
294
298
|
_updateFeatures(feat) {
|
|
@@ -310,6 +314,9 @@ class Device extends events_1.default {
|
|
|
310
314
|
feat.unlocked = (_a = feat.unlocked) !== null && _a !== void 0 ? _a : true;
|
|
311
315
|
const revision = (0, deviceFeaturesUtils_1.parseRevision)(feat);
|
|
312
316
|
feat.revision = revision;
|
|
317
|
+
if (!feat.model && feat.major_version === 1) {
|
|
318
|
+
feat.model = '1';
|
|
319
|
+
}
|
|
313
320
|
this.features = feat;
|
|
314
321
|
this.featuresNeedsReload = false;
|
|
315
322
|
this.firmwareType =
|
|
@@ -449,7 +456,7 @@ class Device extends events_1.default {
|
|
|
449
456
|
if (this.commands) {
|
|
450
457
|
this.commands.cancel();
|
|
451
458
|
}
|
|
452
|
-
this.transport.release(this.activitySessionID, true
|
|
459
|
+
return this.transport.release(this.activitySessionID, true);
|
|
453
460
|
}
|
|
454
461
|
catch (err) {
|
|
455
462
|
}
|
|
@@ -2,17 +2,17 @@ import { Transport, Messages } from '@trezor/transport';
|
|
|
2
2
|
import type { Device } from './Device';
|
|
3
3
|
import type { CoinInfo, BitcoinNetworkInfo } from '../types';
|
|
4
4
|
import type { HDNodeResponse } from '../types/api/getPublicKey';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
5
|
+
type MessageType = Messages.MessageType;
|
|
6
|
+
type MessageKey = keyof MessageType;
|
|
7
|
+
export type TypedResponseMessage<T extends MessageKey> = {
|
|
8
8
|
type: T;
|
|
9
9
|
message: MessageType[T];
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
type TypedCallResponseMap = {
|
|
12
12
|
[K in keyof MessageType]: TypedResponseMessage<K>;
|
|
13
13
|
};
|
|
14
|
-
export
|
|
15
|
-
export
|
|
14
|
+
export type DefaultMessageResponse = TypedCallResponseMap[keyof MessageType];
|
|
15
|
+
export type PassphrasePromptResponse = {
|
|
16
16
|
passphrase?: string;
|
|
17
17
|
passphraseOnDevice?: boolean;
|
|
18
18
|
cache?: boolean;
|
|
@@ -64,6 +64,6 @@ export declare class DeviceCommands {
|
|
|
64
64
|
}>;
|
|
65
65
|
cancel(): Promise<void>;
|
|
66
66
|
}
|
|
67
|
-
export
|
|
67
|
+
export type TypedCall = DeviceCommands['typedCall'];
|
|
68
68
|
export {};
|
|
69
69
|
//# sourceMappingURL=DeviceCommands.d.ts.map
|
|
@@ -113,7 +113,9 @@ class DeviceCommands {
|
|
|
113
113
|
response.xpub = hdnodeUtils.convertXpub(publicKey.xpub, network, coinInfo.network);
|
|
114
114
|
}
|
|
115
115
|
if ((0, pathUtils_1.isTaprootPath)(path)) {
|
|
116
|
-
const fingerprint = Number(publicKey.root_fingerprint || 0)
|
|
116
|
+
const fingerprint = Number(publicKey.root_fingerprint || 0)
|
|
117
|
+
.toString(16)
|
|
118
|
+
.padStart(8, '0');
|
|
117
119
|
const descriptorPath = `${fingerprint}${response.serializedPath.substring(1)}`;
|
|
118
120
|
response.xpubSegwit = `tr([${descriptorPath}]${response.xpub}/<0;1>/*)`;
|
|
119
121
|
}
|
|
@@ -6,7 +6,7 @@ import { DescriptorStream } from './DescriptorStream';
|
|
|
6
6
|
import { Device } from './Device';
|
|
7
7
|
import type { Device as DeviceTyped } from '../types';
|
|
8
8
|
import type { Controller } from './AbortController';
|
|
9
|
-
|
|
9
|
+
type LowLevelPlugin = {
|
|
10
10
|
name: 'WebUsbPlugin' | 'ReactNativePlugin';
|
|
11
11
|
unreadableHidDeviceChange: {
|
|
12
12
|
on: (event: string, fn: any) => void;
|
|
@@ -60,7 +60,7 @@ export declare class DeviceList extends EventEmitter {
|
|
|
60
60
|
length(): number;
|
|
61
61
|
transportType(): string;
|
|
62
62
|
getTransportInfo(): TransportInfo;
|
|
63
|
-
dispose(): void
|
|
63
|
+
dispose(): Promise<void>;
|
|
64
64
|
disconnectDevices(): void;
|
|
65
65
|
enumerate(): void;
|
|
66
66
|
addAuthPenalty(device: Device): void;
|